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