Mercurial > projects > ldc
comparison gen/optimizer.cpp @ 1287:6c8af78364f5
There's an issue with LLVM metadata support; it triggers an assert when trying
to generate asm for code with metadata globals.
This new pass is used as a workaround: it strips metadata from the module before
it reaches the code generator.
Obviously, this is disabled if LLVM doesn't support metadata.
author | Frits van Bommel <fvbommel wxs.nl> |
---|---|
date | Sat, 02 May 2009 12:19:43 +0200 |
parents | 91d9386d4a5a |
children | e109e4031e8a |
comparison
equal
deleted
inserted
replaced
1286:23b23b74e326 | 1287:6c8af78364f5 |
---|---|
48 static cl::opt<bool> | 48 static cl::opt<bool> |
49 disableGCToStack("disable-gc2stack", | 49 disableGCToStack("disable-gc2stack", |
50 cl::desc("Disable promotion of GC allocations to stack memory in -O<N>"), | 50 cl::desc("Disable promotion of GC allocations to stack memory in -O<N>"), |
51 cl::ZeroOrMore); | 51 cl::ZeroOrMore); |
52 | 52 |
53 // Not recommended; metadata currently triggers an assert in the backend... | |
54 static cl::opt<bool> | |
55 disableStripMetaData("disable-strip-metadata", | |
56 cl::desc("Disable default metadata stripping (not recommended)"), | |
57 cl::ZeroOrMore); | |
58 | |
53 static cl::opt<opts::BoolOrDefaultAdapter, false, opts::FlagParser> | 59 static cl::opt<opts::BoolOrDefaultAdapter, false, opts::FlagParser> |
54 enableInlining("inlining", | 60 enableInlining("inlining", |
55 cl::desc("(*) Enable function inlining in -O<N>"), | 61 cl::desc("(*) Enable function inlining in -O<N>"), |
56 cl::ZeroOrMore); | 62 cl::ZeroOrMore); |
57 | 63 |
135 pm.add(createScalarReplAggregatesPass()); | 141 pm.add(createScalarReplAggregatesPass()); |
136 pm.add(createInstructionCombiningPass()); | 142 pm.add(createInstructionCombiningPass()); |
137 pm.add(createCFGSimplificationPass()); | 143 pm.add(createCFGSimplificationPass()); |
138 } | 144 } |
139 } | 145 } |
146 #ifdef USE_METADATA | |
147 if (!disableStripMetaData) { | |
148 // This one is purposely not disabled by disableLangSpecificPasses | |
149 // because the code generator will assert if it's not used. | |
150 pm.add(createStripMetaData()); | |
151 } | |
152 #endif | |
140 | 153 |
141 // -O3 | 154 // -O3 |
142 if (optimizeLevel >= 3) | 155 if (optimizeLevel >= 3) |
143 { | 156 { |
144 pm.add(createArgumentPromotionPass()); | 157 pm.add(createArgumentPromotionPass()); |
179 ////////////////////////////////////////////////////////////////////////////////////////// | 192 ////////////////////////////////////////////////////////////////////////////////////////// |
180 // This function runs optimization passes based on command line arguments. | 193 // This function runs optimization passes based on command line arguments. |
181 // Returns true if any optimization passes were invoked. | 194 // Returns true if any optimization passes were invoked. |
182 bool ldc_optimize_module(llvm::Module* m) | 195 bool ldc_optimize_module(llvm::Module* m) |
183 { | 196 { |
184 if (!optimize()) | 197 if (!optimize()) { |
198 #ifdef USE_METADATA | |
199 if (!disableStripMetaData) { | |
200 // This one always needs to run if metadata is generated, because | |
201 // the code generator will assert if it's not used. | |
202 ModulePass* stripMD = createStripMetaData(); | |
203 stripMD->runOnModule(*m); | |
204 delete stripMD; | |
205 } | |
206 #endif | |
185 return false; | 207 return false; |
208 } | |
186 | 209 |
187 PassManager pm; | 210 PassManager pm; |
188 pm.add(new TargetData(m)); | 211 pm.add(new TargetData(m)); |
189 | 212 |
190 bool optimize = optimizeLevel != 0 || doInline(); | 213 bool optimize = optimizeLevel != 0 || doInline(); |