mirror of
				https://github.com/c64scene-ar/llvm-6502.git
				synced 2025-10-30 16:17:05 +00:00 
			
		
		
		
	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
This commit is contained in:
		| @@ -171,8 +171,10 @@ add a set of optimizations to run.  The code looks like this:</p> | ||||
|  | ||||
| <div class="doc_code"> | ||||
| <pre> | ||||
|     ExistingModuleProvider OurModuleProvider(TheModule); | ||||
|     FunctionPassManager OurFPM(&OurModuleProvider); | ||||
|   ExistingModuleProvider *OurModuleProvider = | ||||
|       new ExistingModuleProvider(TheModule); | ||||
|  | ||||
|   FunctionPassManager OurFPM(OurModuleProvider); | ||||
|  | ||||
|   // Set up the optimizer pipeline.  Start with registering info about how the | ||||
|   // target lays out data structures. | ||||
| @@ -298,8 +300,8 @@ by adding a global variable and a call in <tt>main</tt>:</p> | ||||
| ... | ||||
| int main() { | ||||
|   .. | ||||
|   <b>// Create the JIT. | ||||
|     TheExecutionEngine = EngineBuilder(TheModule).create();</b> | ||||
|   <b>// Create the JIT.  This takes ownership of the module and module provider. | ||||
|   TheExecutionEngine = EngineBuilder(OurModuleProvider).create();</b> | ||||
|   .. | ||||
| } | ||||
| </pre> | ||||
| @@ -1077,12 +1079,13 @@ int main() { | ||||
|   // Make the module, which holds all the code. | ||||
|   TheModule = new Module("my cool jit", getGlobalContext()); | ||||
|  | ||||
|   // Create the JIT. | ||||
|   TheExecutionEngine = EngineBuilder(TheModule).create(); | ||||
|   ExistingModuleProvider *OurModuleProvider = | ||||
|       new ExistingModuleProvider(TheModule); | ||||
|  | ||||
|   { | ||||
|     ExistingModuleProvider OurModuleProvider(TheModule); | ||||
|     FunctionPassManager OurFPM(&OurModuleProvider); | ||||
|   // 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. | ||||
| @@ -1106,7 +1109,6 @@ int main() { | ||||
|  | ||||
|   // Print out all of the generated code. | ||||
|   TheModule->dump(); | ||||
|   }  // Free module provider (and thus the module) and pass manager. | ||||
|  | ||||
|   return 0; | ||||
| } | ||||
|   | ||||
| @@ -1711,12 +1711,13 @@ int main() { | ||||
|   // Make the module, which holds all the code. | ||||
|   TheModule = new Module("my cool jit", getGlobalContext()); | ||||
|  | ||||
|   // Create the JIT. | ||||
|   TheExecutionEngine = EngineBuilder(TheModule).create(); | ||||
|   ExistingModuleProvider *OurModuleProvider = | ||||
|       new ExistingModuleProvider(TheModule); | ||||
|  | ||||
|   { | ||||
|     ExistingModuleProvider OurModuleProvider(TheModule); | ||||
|     FunctionPassManager OurFPM(&OurModuleProvider); | ||||
|   // 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. | ||||
| @@ -1729,6 +1730,7 @@ int main() { | ||||
|   OurFPM.add(createGVNPass()); | ||||
|   // Simplify the control flow graph (deleting unreachable blocks, etc). | ||||
|   OurFPM.add(createCFGSimplificationPass()); | ||||
|  | ||||
|   // Set the global so the code gen can use this. | ||||
|   TheFPM = &OurFPM; | ||||
|  | ||||
| @@ -1739,7 +1741,6 @@ int main() { | ||||
|  | ||||
|   // Print out all of the generated code. | ||||
|   TheModule->dump(); | ||||
|   }  // Free module provider (and thus the module) and pass manager. | ||||
|  | ||||
|   return 0; | ||||
| } | ||||
|   | ||||
| @@ -1750,12 +1750,13 @@ int main() { | ||||
|   // Make the module, which holds all the code. | ||||
|   TheModule = new Module("my cool jit", getGlobalContext()); | ||||
|  | ||||
|   // Create the JIT. | ||||
|   TheExecutionEngine = EngineBuilder(TheModule).create(); | ||||
|   ExistingModuleProvider *OurModuleProvider = | ||||
|       new ExistingModuleProvider(TheModule); | ||||
|  | ||||
|   { | ||||
|     ExistingModuleProvider OurModuleProvider(TheModule); | ||||
|     FunctionPassManager OurFPM(&OurModuleProvider); | ||||
|   // 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. | ||||
| @@ -1768,6 +1769,7 @@ int main() { | ||||
|   OurFPM.add(createGVNPass()); | ||||
|   // Simplify the control flow graph (deleting unreachable blocks, etc). | ||||
|   OurFPM.add(createCFGSimplificationPass()); | ||||
|  | ||||
|   // Set the global so the code gen can use this. | ||||
|   TheFPM = &OurFPM; | ||||
|  | ||||
| @@ -1778,7 +1780,6 @@ int main() { | ||||
|  | ||||
|   // Print out all of the generated code. | ||||
|   TheModule->dump(); | ||||
|   }  // Free module provider (and thus the module) and pass manager. | ||||
|  | ||||
|   return 0; | ||||
| } | ||||
|   | ||||
| @@ -2102,18 +2102,17 @@ int main() { | ||||
|   // Make the module, which holds all the code. | ||||
|   TheModule = new Module("my cool jit", getGlobalContext()); | ||||
|  | ||||
|   // Create the JIT. | ||||
|   TheExecutionEngine = EngineBuilder(TheModule).create(); | ||||
|   ExistingModuleProvider *OurModuleProvider = | ||||
|       new ExistingModuleProvider(TheModule); | ||||
|  | ||||
|   { | ||||
|     ExistingModuleProvider OurModuleProvider(TheModule); | ||||
|     FunctionPassManager OurFPM(&OurModuleProvider); | ||||
|   // 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. | ||||
| @@ -2134,8 +2133,6 @@ int main() { | ||||
|   // Print out all of the generated code. | ||||
|   TheModule->dump(); | ||||
|  | ||||
|   }  // Free module provider (and thus the module) and pass manager. | ||||
|    | ||||
|   return 0; | ||||
| } | ||||
| </pre> | ||||
|   | ||||
| @@ -1108,13 +1108,13 @@ 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); | ||||
|   FunctionPassManager OurFPM(OurModuleProvider); | ||||
|  | ||||
|   // Set up the optimizer pipeline.  Start with registering info about how the | ||||
|   // target lays out data structures. | ||||
| @@ -1143,7 +1143,5 @@ int main() { | ||||
|   // Print out all of the generated code. | ||||
|   TheModule->dump(); | ||||
|  | ||||
|   }  // Free module provider (and thus the module) and pass manager. | ||||
|    | ||||
|   return 0; | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user