summaryrefslogtreecommitdiffstats
path: root/llvm/examples
diff options
context:
space:
mode:
authorRafael Espindola <rafael.espindola@gmail.com>2014-08-19 04:04:25 +0000
committerRafael Espindola <rafael.espindola@gmail.com>2014-08-19 04:04:25 +0000
commit2a8a2795ee8edb8120d10c3c2af397f429b13c57 (patch)
treef77e8ceaf358640f215dc0207854cb9d00975e08 /llvm/examples
parent687744d0114c46529def899ee6c67428cbdf3d92 (diff)
downloadbcm5719-llvm-2a8a2795ee8edb8120d10c3c2af397f429b13c57.tar.gz
bcm5719-llvm-2a8a2795ee8edb8120d10c3c2af397f429b13c57.zip
Make it explicit that ExecutionEngine takes ownership of the modules.
llvm-svn: 215967
Diffstat (limited to 'llvm/examples')
-rw-r--r--llvm/examples/BrainF/BrainFDriver.cpp14
-rw-r--r--llvm/examples/ExceptionDemo/ExceptionDemo.cpp6
-rw-r--r--llvm/examples/Fibonacci/fibonacci.cpp7
-rw-r--r--llvm/examples/HowToUseJIT/HowToUseJIT.cpp5
-rw-r--r--llvm/examples/Kaleidoscope/Chapter4/toy.cpp6
-rw-r--r--llvm/examples/Kaleidoscope/Chapter5/toy.cpp6
-rw-r--r--llvm/examples/Kaleidoscope/Chapter6/toy.cpp6
-rw-r--r--llvm/examples/Kaleidoscope/Chapter7/toy.cpp6
-rw-r--r--llvm/examples/ParallelJIT/ParallelJIT.cpp5
9 files changed, 37 insertions, 24 deletions
diff --git a/llvm/examples/BrainF/BrainFDriver.cpp b/llvm/examples/BrainF/BrainFDriver.cpp
index e2de6bc58d7..9b1f0d3f118 100644
--- a/llvm/examples/BrainF/BrainFDriver.cpp
+++ b/llvm/examples/BrainF/BrainFDriver.cpp
@@ -125,13 +125,13 @@ int main(int argc, char **argv) {
//Read the BrainF program
BrainF bf;
- Module *mod = bf.parse(in, 65536, cf, Context); //64 KiB
+ std::unique_ptr<Module> Mod(bf.parse(in, 65536, cf, Context)); // 64 KiB
if (in != &std::cin)
delete in;
- addMainFunction(mod);
+ addMainFunction(Mod.get());
//Verify generated code
- if (verifyModule(*mod)) {
+ if (verifyModule(*Mod)) {
errs() << "Error: module failed verification. This shouldn't happen.\n";
abort();
}
@@ -141,18 +141,18 @@ int main(int argc, char **argv) {
InitializeNativeTarget();
outs() << "------- Running JIT -------\n";
- ExecutionEngine *ee = EngineBuilder(mod).create();
+ Module &M = *Mod;
+ ExecutionEngine *ee = EngineBuilder(std::move(Mod)).create();
std::vector<GenericValue> args;
- Function *brainf_func = mod->getFunction("brainf");
+ Function *brainf_func = M.getFunction("brainf");
GenericValue gv = ee->runFunction(brainf_func, args);
} else {
- WriteBitcodeToFile(mod, *out);
+ WriteBitcodeToFile(Mod.get(), *out);
}
//Clean up
if (out != &outs())
delete out;
- delete mod;
llvm_shutdown();
diff --git a/llvm/examples/ExceptionDemo/ExceptionDemo.cpp b/llvm/examples/ExceptionDemo/ExceptionDemo.cpp
index 24e538cacf2..21d290e4356 100644
--- a/llvm/examples/ExceptionDemo/ExceptionDemo.cpp
+++ b/llvm/examples/ExceptionDemo/ExceptionDemo.cpp
@@ -1957,12 +1957,14 @@ int main(int argc, char *argv[]) {
llvm::IRBuilder<> theBuilder(context);
// Make the module, which holds all the code.
- llvm::Module *module = new llvm::Module("my cool jit", context);
+ std::unique_ptr<llvm::Module> Owner =
+ llvm::make_unique<llvm::Module>("my cool jit", context);
+ llvm::Module *module = Owner.get();
llvm::RTDyldMemoryManager *MemMgr = new llvm::SectionMemoryManager();
// Build engine with JIT
- llvm::EngineBuilder factory(module);
+ llvm::EngineBuilder factory(std::move(Owner));
factory.setEngineKind(llvm::EngineKind::JIT);
factory.setAllocateGVsWithCode(false);
factory.setTargetOptions(Opts);
diff --git a/llvm/examples/Fibonacci/fibonacci.cpp b/llvm/examples/Fibonacci/fibonacci.cpp
index ba8e95342fa..fd9b4564945 100644
--- a/llvm/examples/Fibonacci/fibonacci.cpp
+++ b/llvm/examples/Fibonacci/fibonacci.cpp
@@ -96,15 +96,16 @@ int main(int argc, char **argv) {
LLVMContext Context;
// Create some module to put our function into it.
- std::unique_ptr<Module> M(new Module("test", Context));
+ std::unique_ptr<Module> Owner(new Module("test", Context));
+ Module *M = Owner.get();
// We are about to create the "fib" function:
- Function *FibF = CreateFibFunction(M.get(), Context);
+ Function *FibF = CreateFibFunction(M, Context);
// Now we going to create JIT
std::string errStr;
ExecutionEngine *EE =
- EngineBuilder(M.get())
+ EngineBuilder(std::move(Owner))
.setErrorStr(&errStr)
.setEngineKind(EngineKind::JIT)
.create();
diff --git a/llvm/examples/HowToUseJIT/HowToUseJIT.cpp b/llvm/examples/HowToUseJIT/HowToUseJIT.cpp
index 7125a156104..4474bfec9c9 100644
--- a/llvm/examples/HowToUseJIT/HowToUseJIT.cpp
+++ b/llvm/examples/HowToUseJIT/HowToUseJIT.cpp
@@ -56,7 +56,8 @@ int main() {
LLVMContext Context;
// Create some module to put our function into it.
- Module *M = new Module("test", Context);
+ std::unique_ptr<Module> Owner = make_unique<Module>("test", Context);
+ Module *M = Owner.get();
// Create the add1 function entry and insert this entry into module M. The
// function will have a return type of "int" and take an argument of "int".
@@ -114,7 +115,7 @@ int main() {
builder.CreateRet(Add1CallRes);
// Now we create the JIT.
- ExecutionEngine* EE = EngineBuilder(M).create();
+ ExecutionEngine* EE = EngineBuilder(std::move(Owner)).create();
outs() << "We just constructed this LLVM module:\n\n" << *M;
outs() << "\n\nRunning foo: ";
diff --git a/llvm/examples/Kaleidoscope/Chapter4/toy.cpp b/llvm/examples/Kaleidoscope/Chapter4/toy.cpp
index a8f59428c0d..ff352f56ad0 100644
--- a/llvm/examples/Kaleidoscope/Chapter4/toy.cpp
+++ b/llvm/examples/Kaleidoscope/Chapter4/toy.cpp
@@ -572,11 +572,13 @@ int main() {
getNextToken();
// Make the module, which holds all the code.
- TheModule = new Module("my cool jit", Context);
+ std::unique_ptr<Module> Owner = make_unique<Module>("my cool jit", Context);
+ TheModule = Owner.get();
// Create the JIT. This takes ownership of the module.
std::string ErrStr;
- TheExecutionEngine = EngineBuilder(TheModule).setErrorStr(&ErrStr).create();
+ TheExecutionEngine =
+ EngineBuilder(std::move(Owner)).setErrorStr(&ErrStr).create();
if (!TheExecutionEngine) {
fprintf(stderr, "Could not create ExecutionEngine: %s\n", ErrStr.c_str());
exit(1);
diff --git a/llvm/examples/Kaleidoscope/Chapter5/toy.cpp b/llvm/examples/Kaleidoscope/Chapter5/toy.cpp
index a31b5b4792a..550504259ee 100644
--- a/llvm/examples/Kaleidoscope/Chapter5/toy.cpp
+++ b/llvm/examples/Kaleidoscope/Chapter5/toy.cpp
@@ -817,11 +817,13 @@ int main() {
getNextToken();
// Make the module, which holds all the code.
- TheModule = new Module("my cool jit", Context);
+ std::unique_ptr<Module> Owner = make_unique<Module>("my cool jit", Context);
+ TheModule = Owner.get();
// Create the JIT. This takes ownership of the module.
std::string ErrStr;
- TheExecutionEngine = EngineBuilder(TheModule).setErrorStr(&ErrStr).create();
+ TheExecutionEngine =
+ EngineBuilder(std::move(Owner)).setErrorStr(&ErrStr).create();
if (!TheExecutionEngine) {
fprintf(stderr, "Could not create ExecutionEngine: %s\n", ErrStr.c_str());
exit(1);
diff --git a/llvm/examples/Kaleidoscope/Chapter6/toy.cpp b/llvm/examples/Kaleidoscope/Chapter6/toy.cpp
index 5a3bd2e3147..d782395fdaa 100644
--- a/llvm/examples/Kaleidoscope/Chapter6/toy.cpp
+++ b/llvm/examples/Kaleidoscope/Chapter6/toy.cpp
@@ -935,11 +935,13 @@ int main() {
getNextToken();
// Make the module, which holds all the code.
- TheModule = new Module("my cool jit", Context);
+ std::unique_ptr<Module> Owner = make_unique<Module>("my cool jit", Context);
+ TheModule = Owner.get();
// Create the JIT. This takes ownership of the module.
std::string ErrStr;
- TheExecutionEngine = EngineBuilder(TheModule).setErrorStr(&ErrStr).create();
+ TheExecutionEngine =
+ EngineBuilder(std::move(Owner)).setErrorStr(&ErrStr).create();
if (!TheExecutionEngine) {
fprintf(stderr, "Could not create ExecutionEngine: %s\n", ErrStr.c_str());
exit(1);
diff --git a/llvm/examples/Kaleidoscope/Chapter7/toy.cpp b/llvm/examples/Kaleidoscope/Chapter7/toy.cpp
index c2c337c9008..89e8368a14d 100644
--- a/llvm/examples/Kaleidoscope/Chapter7/toy.cpp
+++ b/llvm/examples/Kaleidoscope/Chapter7/toy.cpp
@@ -1099,11 +1099,13 @@ int main() {
getNextToken();
// Make the module, which holds all the code.
- TheModule = new Module("my cool jit", Context);
+ std::unique_ptr<Module> Owner = make_unique<Module>("my cool jit", Context);
+ TheModule = Owner.get();
// Create the JIT. This takes ownership of the module.
std::string ErrStr;
- TheExecutionEngine = EngineBuilder(TheModule).setErrorStr(&ErrStr).create();
+ TheExecutionEngine =
+ EngineBuilder(std::move(Owner)).setErrorStr(&ErrStr).create();
if (!TheExecutionEngine) {
fprintf(stderr, "Could not create ExecutionEngine: %s\n", ErrStr.c_str());
exit(1);
diff --git a/llvm/examples/ParallelJIT/ParallelJIT.cpp b/llvm/examples/ParallelJIT/ParallelJIT.cpp
index 2aa63d91ffb..b05e518ec41 100644
--- a/llvm/examples/ParallelJIT/ParallelJIT.cpp
+++ b/llvm/examples/ParallelJIT/ParallelJIT.cpp
@@ -243,13 +243,14 @@ int main() {
LLVMContext Context;
// Create some module to put our function into it.
- Module *M = new Module("test", Context);
+ std::unique_ptr<Module> Owner = make_unique<Module>("test", Context);
+ Module *M = Owner.get();
Function* add1F = createAdd1( M );
Function* fibF = CreateFibFunction( M );
// Now we create the JIT.
- ExecutionEngine* EE = EngineBuilder(M).create();
+ ExecutionEngine* EE = EngineBuilder(std::move(Owner)).create();
//~ std::cout << "We just constructed this LLVM module:\n\n" << *M;
//~ std::cout << "\n\nRunning foo: " << std::flush;
OpenPOWER on IntegriCloud