diff options
author | Reid Kleckner <reid@kleckner.net> | 2009-08-26 20:58:25 +0000 |
---|---|---|
committer | Reid Kleckner <reid@kleckner.net> | 2009-08-26 20:58:25 +0000 |
commit | 60130f0e90d69dc3022878bfe4508dae81f911eb (patch) | |
tree | 7f667606954d5f6ee86387749d1adada52d0758d /examples/Kaleidoscope | |
parent | 7309be6735666143bd9835b275dc8501617a2591 (diff) | |
download | external_llvm-60130f0e90d69dc3022878bfe4508dae81f911eb.zip external_llvm-60130f0e90d69dc3022878bfe4508dae81f911eb.tar.gz external_llvm-60130f0e90d69dc3022878bfe4508dae81f911eb.tar.bz2 |
Allocate the module provider in the Kaleidoscope code on the heap, not the stack, so that it can be properly deleted. Also update the tutorial with the new code. This fixes PR4762, hopefully better than the last time.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@80138 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'examples/Kaleidoscope')
-rw-r--r-- | examples/Kaleidoscope/toy.cpp | 68 |
1 files changed, 33 insertions, 35 deletions
diff --git a/examples/Kaleidoscope/toy.cpp b/examples/Kaleidoscope/toy.cpp index 6b0560a..8e02e9a 100644 --- a/examples/Kaleidoscope/toy.cpp +++ b/examples/Kaleidoscope/toy.cpp @@ -1108,42 +1108,40 @@ int main() { // Make the module, which holds all the code. TheModule = new Module("my cool jit", Context); - { - ExistingModuleProvider OurModuleProvider(TheModule); + ExistingModuleProvider *OurModuleProvider = + new ExistingModuleProvider(TheModule); - // Create the JIT. - TheExecutionEngine = EngineBuilder(&OurModuleProvider).create(); + // Create the JIT. This takes ownership of the module and module provider. + TheExecutionEngine = EngineBuilder(OurModuleProvider).create(); + + FunctionPassManager OurFPM(OurModuleProvider); + + // Set up the optimizer pipeline. Start with registering info about how the + // target lays out data structures. + OurFPM.add(new TargetData(*TheExecutionEngine->getTargetData())); + // Promote allocas to registers. + OurFPM.add(createPromoteMemoryToRegisterPass()); + // Do simple "peephole" optimizations and bit-twiddling optzns. + OurFPM.add(createInstructionCombiningPass()); + // Reassociate expressions. + OurFPM.add(createReassociatePass()); + // Eliminate Common SubExpressions. + OurFPM.add(createGVNPass()); + // Simplify the control flow graph (deleting unreachable blocks, etc). + OurFPM.add(createCFGSimplificationPass()); + + OurFPM.doInitialization(); + + // Set the global so the code gen can use this. + TheFPM = &OurFPM; + + // Run the main "interpreter loop" now. + MainLoop(); + + TheFPM = 0; + + // Print out all of the generated code. + TheModule->dump(); - FunctionPassManager OurFPM(&OurModuleProvider); - - // Set up the optimizer pipeline. Start with registering info about how the - // target lays out data structures. - OurFPM.add(new TargetData(*TheExecutionEngine->getTargetData())); - // Promote allocas to registers. - OurFPM.add(createPromoteMemoryToRegisterPass()); - // Do simple "peephole" optimizations and bit-twiddling optzns. - OurFPM.add(createInstructionCombiningPass()); - // Reassociate expressions. - OurFPM.add(createReassociatePass()); - // Eliminate Common SubExpressions. - OurFPM.add(createGVNPass()); - // Simplify the control flow graph (deleting unreachable blocks, etc). - OurFPM.add(createCFGSimplificationPass()); - - OurFPM.doInitialization(); - - // Set the global so the code gen can use this. - TheFPM = &OurFPM; - - // Run the main "interpreter loop" now. - MainLoop(); - - TheFPM = 0; - - // Print out all of the generated code. - TheModule->dump(); - - } // Free module provider (and thus the module) and pass manager. - return 0; } |