mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-11-22 18:54:02 +01: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.
llvm-svn: 80138
This commit is contained in:
parent
830005b778
commit
f6b832774f
@ -171,26 +171,28 @@ add a set of optimizations to run. The code looks like this:</p>
|
||||
|
||||
<div class="doc_code">
|
||||
<pre>
|
||||
ExistingModuleProvider OurModuleProvider(TheModule);
|
||||
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()));
|
||||
// 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());
|
||||
ExistingModuleProvider *OurModuleProvider =
|
||||
new ExistingModuleProvider(TheModule);
|
||||
|
||||
// Set the global so the code gen can use this.
|
||||
TheFPM = &OurFPM;
|
||||
FunctionPassManager OurFPM(OurModuleProvider);
|
||||
|
||||
// Run the main "interpreter loop" now.
|
||||
MainLoop();
|
||||
// Set up the optimizer pipeline. Start with registering info about how the
|
||||
// target lays out data structures.
|
||||
OurFPM.add(new TargetData(*TheExecutionEngine->getTargetData()));
|
||||
// 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());
|
||||
|
||||
// Set the global so the code gen can use this.
|
||||
TheFPM = &OurFPM;
|
||||
|
||||
// Run the main "interpreter loop" now.
|
||||
MainLoop();
|
||||
</pre>
|
||||
</div>
|
||||
|
||||
@ -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>
|
||||
@ -1076,38 +1078,38 @@ 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(TheModule);
|
||||
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()));
|
||||
// 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());
|
||||
ExistingModuleProvider *OurModuleProvider =
|
||||
new ExistingModuleProvider(TheModule);
|
||||
|
||||
// Set the global so the code gen can use this.
|
||||
TheFPM = &OurFPM;
|
||||
// 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()));
|
||||
// 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());
|
||||
|
||||
// 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();
|
||||
|
||||
// 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;
|
||||
}
|
||||
</pre>
|
||||
|
@ -1710,37 +1710,38 @@ 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(TheModule);
|
||||
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()));
|
||||
// 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());
|
||||
// Set the global so the code gen can use this.
|
||||
TheFPM = &OurFPM;
|
||||
ExistingModuleProvider *OurModuleProvider =
|
||||
new ExistingModuleProvider(TheModule);
|
||||
|
||||
// Run the main "interpreter loop" now.
|
||||
MainLoop();
|
||||
|
||||
TheFPM = 0;
|
||||
// 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()));
|
||||
// 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());
|
||||
|
||||
// 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();
|
||||
|
||||
// Print out all of the generated code.
|
||||
TheModule->dump();
|
||||
} // Free module provider (and thus the module) and pass manager.
|
||||
|
||||
return 0;
|
||||
}
|
||||
</pre>
|
||||
|
@ -1749,37 +1749,38 @@ 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(TheModule);
|
||||
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()));
|
||||
// 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());
|
||||
// Set the global so the code gen can use this.
|
||||
TheFPM = &OurFPM;
|
||||
ExistingModuleProvider *OurModuleProvider =
|
||||
new ExistingModuleProvider(TheModule);
|
||||
|
||||
// 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()));
|
||||
// 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());
|
||||
|
||||
// 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();
|
||||
|
||||
// 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;
|
||||
}
|
||||
</pre>
|
||||
|
@ -2101,41 +2101,38 @@ 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(TheModule);
|
||||
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());
|
||||
ExistingModuleProvider *OurModuleProvider =
|
||||
new ExistingModuleProvider(TheModule);
|
||||
|
||||
// Set the global so the code gen can use this.
|
||||
TheFPM = &OurFPM;
|
||||
// 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()));
|
||||
// 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());
|
||||
|
||||
// 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();
|
||||
|
||||
// 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;
|
||||
}
|
||||
</pre>
|
||||
|
@ -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());
|
||||
FunctionPassManager OurFPM(OurModuleProvider);
|
||||
|
||||
OurFPM.doInitialization();
|
||||
// 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());
|
||||
|
||||
// Set the global so the code gen can use this.
|
||||
TheFPM = &OurFPM;
|
||||
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();
|
||||
|
||||
// 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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user