llvm.org GIT mirror llvm / 60130f0
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 Reid Kleckner 11 years ago
5 changed file(s) with 187 addition(s) and 188 deletion(s). Raw diff Collapse all Expand all
170170
171171
172172

                  
                
173 ExistingModuleProvider OurModuleProvider(TheModule);
174 FunctionPassManager OurFPM(&OurModuleProvider);
175
176 // Set up the optimizer pipeline. Start with registering info about how the
177 // target lays out data structures.
178 OurFPM.add(new TargetData(*TheExecutionEngine->getTargetData()));
179 // Do simple "peephole" optimizations and bit-twiddling optzns.
180 OurFPM.add(createInstructionCombiningPass());
181 // Reassociate expressions.
182 OurFPM.add(createReassociatePass());
183 // Eliminate Common SubExpressions.
184 OurFPM.add(createGVNPass());
185 // Simplify the control flow graph (deleting unreachable blocks, etc).
186 OurFPM.add(createCFGSimplificationPass());
187
188 // Set the global so the code gen can use this.
189 TheFPM = &OurFPM;
190
191 // Run the main "interpreter loop" now.
192 MainLoop();
173 ExistingModuleProvider *OurModuleProvider =
174 new ExistingModuleProvider(TheModule);
175
176 FunctionPassManager OurFPM(OurModuleProvider);
177
178 // Set up the optimizer pipeline. Start with registering info about how the
179 // target lays out data structures.
180 OurFPM.add(new TargetData(*TheExecutionEngine->getTargetData()));
181 // Do simple "peephole" optimizations and bit-twiddling optzns.
182 OurFPM.add(createInstructionCombiningPass());
183 // Reassociate expressions.
184 OurFPM.add(createReassociatePass());
185 // Eliminate Common SubExpressions.
186 OurFPM.add(createGVNPass());
187 // Simplify the control flow graph (deleting unreachable blocks, etc).
188 OurFPM.add(createCFGSimplificationPass());
189
190 // Set the global so the code gen can use this.
191 TheFPM = &OurFPM;
192
193 // Run the main "interpreter loop" now.
194 MainLoop();
193195
194196
195197
297299 ...
298300 int main() {
299301 ..
300 // Create the JIT.
301 TheExecutionEngine = EngineBuilder(TheModule).create();
302 // Create the JIT. This takes ownership of the module and module provider.
303 TheExecutionEngine = EngineBuilder(OurModuleProvider).create();
302304 ..
303305 }
304306
10751077
10761078 // Make the module, which holds all the code.
10771079 TheModule = new Module("my cool jit", getGlobalContext());
1078
1079 // Create the JIT.
1080 TheExecutionEngine = EngineBuilder(TheModule).create();
1081
1082 {
1083 ExistingModuleProvider OurModuleProvider(TheModule);
1084 FunctionPassManager OurFPM(&OurModuleProvider);
1085
1086 // Set up the optimizer pipeline. Start with registering info about how the
1087 // target lays out data structures.
1088 OurFPM.add(new TargetData(*TheExecutionEngine->getTargetData()));
1089 // Do simple "peephole" optimizations and bit-twiddling optzns.
1090 OurFPM.add(createInstructionCombiningPass());
1091 // Reassociate expressions.
1092 OurFPM.add(createReassociatePass());
1093 // Eliminate Common SubExpressions.
1094 OurFPM.add(createGVNPass());
1095 // Simplify the control flow graph (deleting unreachable blocks, etc).
1096 OurFPM.add(createCFGSimplificationPass());
1097
1098 // Set the global so the code gen can use this.
1099 TheFPM = &OurFPM;
1100
1101 // Run the main "interpreter loop" now.
1102 MainLoop();
1103
1104 TheFPM = 0;
1105
1106 // Print out all of the generated code.
1107 TheModule->dump();
1108 } // Free module provider (and thus the module) and pass manager.
1109
1080
1081 ExistingModuleProvider *OurModuleProvider =
1082 new ExistingModuleProvider(TheModule);
1083
1084 // Create the JIT. This takes ownership of the module and module provider.
1085 TheExecutionEngine = EngineBuilder(OurModuleProvider).create();
1086
1087 FunctionPassManager OurFPM(OurModuleProvider);
1088
1089 // Set up the optimizer pipeline. Start with registering info about how the
1090 // target lays out data structures.
1091 OurFPM.add(new TargetData(*TheExecutionEngine->getTargetData()));
1092 // Do simple "peephole" optimizations and bit-twiddling optzns.
1093 OurFPM.add(createInstructionCombiningPass());
1094 // Reassociate expressions.
1095 OurFPM.add(createReassociatePass());
1096 // Eliminate Common SubExpressions.
1097 OurFPM.add(createGVNPass());
1098 // Simplify the control flow graph (deleting unreachable blocks, etc).
1099 OurFPM.add(createCFGSimplificationPass());
1100
1101 // Set the global so the code gen can use this.
1102 TheFPM = &OurFPM;
1103
1104 // Run the main "interpreter loop" now.
1105 MainLoop();
1106
1107 TheFPM = 0;
1108
1109 // Print out all of the generated code.
1110 TheModule->dump();
1111
11101112 return 0;
11111113 }
11121114
17091709
17101710 // Make the module, which holds all the code.
17111711 TheModule = new Module("my cool jit", getGlobalContext());
1712
1713 // Create the JIT.
1714 TheExecutionEngine = EngineBuilder(TheModule).create();
1715
1716 {
1717 ExistingModuleProvider OurModuleProvider(TheModule);
1718 FunctionPassManager OurFPM(&OurModuleProvider);
1719
1720 // Set up the optimizer pipeline. Start with registering info about how the
1721 // target lays out data structures.
1722 OurFPM.add(new TargetData(*TheExecutionEngine->getTargetData()));
1723 // Do simple "peephole" optimizations and bit-twiddling optzns.
1724 OurFPM.add(createInstructionCombiningPass());
1725 // Reassociate expressions.
1726 OurFPM.add(createReassociatePass());
1727 // Eliminate Common SubExpressions.
1728 OurFPM.add(createGVNPass());
1729 // Simplify the control flow graph (deleting unreachable blocks, etc).
1730 OurFPM.add(createCFGSimplificationPass());
1731 // Set the global so the code gen can use this.
1732 TheFPM = &OurFPM;
1733
1734 // Run the main "interpreter loop" now.
1735 MainLoop();
1736
1737 TheFPM = 0;
1738
1739 // Print out all of the generated code.
1740 TheModule->dump();
1741 } // Free module provider (and thus the module) and pass manager.
1742
1712
1713 ExistingModuleProvider *OurModuleProvider =
1714 new ExistingModuleProvider(TheModule);
1715
1716 // Create the JIT. This takes ownership of the module and module provider.
1717 TheExecutionEngine = EngineBuilder(OurModuleProvider).create();
1718
1719 FunctionPassManager OurFPM(OurModuleProvider);
1720
1721 // Set up the optimizer pipeline. Start with registering info about how the
1722 // target lays out data structures.
1723 OurFPM.add(new TargetData(*TheExecutionEngine->getTargetData()));
1724 // Do simple "peephole" optimizations and bit-twiddling optzns.
1725 OurFPM.add(createInstructionCombiningPass());
1726 // Reassociate expressions.
1727 OurFPM.add(createReassociatePass());
1728 // Eliminate Common SubExpressions.
1729 OurFPM.add(createGVNPass());
1730 // Simplify the control flow graph (deleting unreachable blocks, etc).
1731 OurFPM.add(createCFGSimplificationPass());
1732
1733 // Set the global so the code gen can use this.
1734 TheFPM = &OurFPM;
1735
1736 // Run the main "interpreter loop" now.
1737 MainLoop();
1738
1739 TheFPM = 0;
1740
1741 // Print out all of the generated code.
1742 TheModule->dump();
1743
17431744 return 0;
17441745 }
17451746
17481748
17491749 // Make the module, which holds all the code.
17501750 TheModule = new Module("my cool jit", getGlobalContext());
1751
1752 // Create the JIT.
1753 TheExecutionEngine = EngineBuilder(TheModule).create();
1754
1755 {
1756 ExistingModuleProvider OurModuleProvider(TheModule);
1757 FunctionPassManager OurFPM(&OurModuleProvider);
1758
1759 // Set up the optimizer pipeline. Start with registering info about how the
1760 // target lays out data structures.
1761 OurFPM.add(new TargetData(*TheExecutionEngine->getTargetData()));
1762 // Do simple "peephole" optimizations and bit-twiddling optzns.
1763 OurFPM.add(createInstructionCombiningPass());
1764 // Reassociate expressions.
1765 OurFPM.add(createReassociatePass());
1766 // Eliminate Common SubExpressions.
1767 OurFPM.add(createGVNPass());
1768 // Simplify the control flow graph (deleting unreachable blocks, etc).
1769 OurFPM.add(createCFGSimplificationPass());
1770 // Set the global so the code gen can use this.
1771 TheFPM = &OurFPM;
1772
1773 // Run the main "interpreter loop" now.
1774 MainLoop();
1775
1776 TheFPM = 0;
1777
1778 // Print out all of the generated code.
1779 TheModule->dump();
1780 } // Free module provider (and thus the module) and pass manager.
1781
1751
1752 ExistingModuleProvider *OurModuleProvider =
1753 new ExistingModuleProvider(TheModule);
1754
1755 // Create the JIT. This takes ownership of the module and module provider.
1756 TheExecutionEngine = EngineBuilder(OurModuleProvider).create();
1757
1758 FunctionPassManager OurFPM(OurModuleProvider);
1759
1760 // Set up the optimizer pipeline. Start with registering info about how the
1761 // target lays out data structures.
1762 OurFPM.add(new TargetData(*TheExecutionEngine->getTargetData()));
1763 // Do simple "peephole" optimizations and bit-twiddling optzns.
1764 OurFPM.add(createInstructionCombiningPass());
1765 // Reassociate expressions.
1766 OurFPM.add(createReassociatePass());
1767 // Eliminate Common SubExpressions.
1768 OurFPM.add(createGVNPass());
1769 // Simplify the control flow graph (deleting unreachable blocks, etc).
1770 OurFPM.add(createCFGSimplificationPass());
1771
1772 // Set the global so the code gen can use this.
1773 TheFPM = &OurFPM;
1774
1775 // Run the main "interpreter loop" now.
1776 MainLoop();
1777
1778 TheFPM = 0;
1779
1780 // Print out all of the generated code.
1781 TheModule->dump();
1782
17821783 return 0;
17831784 }
17841785
21002100
21012101 // Make the module, which holds all the code.
21022102 TheModule = new Module("my cool jit", getGlobalContext());
2103
2104 // Create the JIT.
2105 TheExecutionEngine = EngineBuilder(TheModule).create();
2106
2107 {
2108 ExistingModuleProvider OurModuleProvider(TheModule);
2109 FunctionPassManager OurFPM(&OurModuleProvider);
2110
2111 // Set up the optimizer pipeline. Start with registering info about how the
2112 // target lays out data structures.
2113 OurFPM.add(new TargetData(*TheExecutionEngine->getTargetData()));
2114 // Promote allocas to registers.
2115 OurFPM.add(createPromoteMemoryToRegisterPass());
2116 // Do simple "peephole" optimizations and bit-twiddling optzns.
2117 OurFPM.add(createInstructionCombiningPass());
2118 // Reassociate expressions.
2119 OurFPM.add(createReassociatePass());
2120 // Eliminate Common SubExpressions.
2121 OurFPM.add(createGVNPass());
2122 // Simplify the control flow graph (deleting unreachable blocks, etc).
2123 OurFPM.add(createCFGSimplificationPass());
2124
2125 // Set the global so the code gen can use this.
2126 TheFPM = &OurFPM;
2127
2128 // Run the main "interpreter loop" now.
2129 MainLoop();
2130
2131 TheFPM = 0;
2132
2133 // Print out all of the generated code.
2134 TheModule->dump();
2135
2136 } // Free module provider (and thus the module) and pass manager.
2137
2103
2104 ExistingModuleProvider *OurModuleProvider =
2105 new ExistingModuleProvider(TheModule);
2106
2107 // Create the JIT. This takes ownership of the module and module provider.
2108 TheExecutionEngine = EngineBuilder(OurModuleProvider).create();
2109
2110 FunctionPassManager OurFPM(OurModuleProvider);
2111
2112 // Set up the optimizer pipeline. Start with registering info about how the
2113 // target lays out data structures.
2114 OurFPM.add(new TargetData(*TheExecutionEngine->getTargetData()));
2115 // Do simple "peephole" optimizations and bit-twiddling optzns.
2116 OurFPM.add(createInstructionCombiningPass());
2117 // Reassociate expressions.
2118 OurFPM.add(createReassociatePass());
2119 // Eliminate Common SubExpressions.
2120 OurFPM.add(createGVNPass());
2121 // Simplify the control flow graph (deleting unreachable blocks, etc).
2122 OurFPM.add(createCFGSimplificationPass());
2123
2124 // Set the global so the code gen can use this.
2125 TheFPM = &OurFPM;
2126
2127 // Run the main "interpreter loop" now.
2128 MainLoop();
2129
2130 TheFPM = 0;
2131
2132 // Print out all of the generated code.
2133 TheModule->dump();
2134
21382135 return 0;
21392136 }
21402137
11071107 // Make the module, which holds all the code.
11081108 TheModule = new Module("my cool jit", Context);
11091109
1110 {
1111 ExistingModuleProvider OurModuleProvider(TheModule);
1112
1113 // Create the JIT.
1114 TheExecutionEngine = EngineBuilder(&OurModuleProvider).create();
1115
1116 FunctionPassManager OurFPM(&OurModuleProvider);
1117
1118 // Set up the optimizer pipeline. Start with registering info about how the
1119 // target lays out data structures.
1120 OurFPM.add(new TargetData(*TheExecutionEngine->getTargetData()));
1121 // Promote allocas to registers.
1122 OurFPM.add(createPromoteMemoryToRegisterPass());
1123 // Do simple "peephole" optimizations and bit-twiddling optzns.
1124 OurFPM.add(createInstructionCombiningPass());
1125 // Reassociate expressions.
1126 OurFPM.add(createReassociatePass());
1127 // Eliminate Common SubExpressions.
1128 OurFPM.add(createGVNPass());
1129 // Simplify the control flow graph (deleting unreachable blocks, etc).
1130 OurFPM.add(createCFGSimplificationPass());
1131
1132 OurFPM.doInitialization();
1133
1134 // Set the global so the code gen can use this.
1135 TheFPM = &OurFPM;
1136
1137 // Run the main "interpreter loop" now.
1138 MainLoop();
1139
1140 TheFPM = 0;
1141
1142 // Print out all of the generated code.
1143 TheModule->dump();
1144
1145 } // Free module provider (and thus the module) and pass manager.
1146
1110 ExistingModuleProvider *OurModuleProvider =
1111 new ExistingModuleProvider(TheModule);
1112
1113 // Create the JIT. This takes ownership of the module and module provider.
1114 TheExecutionEngine = EngineBuilder(OurModuleProvider).create();
1115
1116 FunctionPassManager OurFPM(OurModuleProvider);
1117
1118 // Set up the optimizer pipeline. Start with registering info about how the
1119 // target lays out data structures.
1120 OurFPM.add(new TargetData(*TheExecutionEngine->getTargetData()));
1121 // Promote allocas to registers.
1122 OurFPM.add(createPromoteMemoryToRegisterPass());
1123 // Do simple "peephole" optimizations and bit-twiddling optzns.
1124 OurFPM.add(createInstructionCombiningPass());
1125 // Reassociate expressions.
1126 OurFPM.add(createReassociatePass());
1127 // Eliminate Common SubExpressions.
1128 OurFPM.add(createGVNPass());
1129 // Simplify the control flow graph (deleting unreachable blocks, etc).
1130 OurFPM.add(createCFGSimplificationPass());
1131
1132 OurFPM.doInitialization();
1133
1134 // Set the global so the code gen can use this.
1135 TheFPM = &OurFPM;
1136
1137 // Run the main "interpreter loop" now.
1138 MainLoop();
1139
1140 TheFPM = 0;
1141
1142 // Print out all of the generated code.
1143 TheModule->dump();
1144
11471145 return 0;
11481146 }