Skip to content
This repository

Use PassManagerBuilder. #157

Closed
wants to merge 2 commits into from

2 participants

Kai Nacke David Nadlinger
Kai Nacke
Owner

Replaces the pass setup with the pre-factored PassManagerBuilder. Removes not implemented optimization levels (-O4, -O5) and introduces new levels -Os and -Oz (optimization for size).

New command line options:

  • -disable-inlining (prevents running the inliner pass)
  • -unit-at-a-time (enables IPO, run by default)
  • -strip-debug (strip debugger symbol info)

Removed command line options:

  • -enable-inlinig (implicit set by -O1/2/3)
  • -vectorize (option from PassManagerBuilder used instead)

A first examination of the generated object code showed that more functions get inlined. (I used -O3 -vectorize as options for my compare.)

Kai Nacke redstar Use PassManagerBuilder.
Replaces the pass setup with the pre-factored PassManagerBuilder. Removes not implemented optimization levels and introduces new levels -Os and -Oz (optimization for size).

New command line options:
- disable-inlinig (prevents running the inliner pass)
- unit-at-a-time (enables IPO, run by default)
- strip-debug (strip debugger symbol info)

Removed command line options:
- enable-inlinig (implicit set by -O1/2/3)
- vectorize (option from PassManagerBuilder used instead)
65d93dc
gen/optimizer.cpp
((79 lines not shown))
306 259
  260 + if (doOptimize)
  261 + addOptimizationPasses(pm, *fpm, optLevel(), sizeLevel());
  262 +
  263 + if (optimize()) {
  264 + fpm->doInitialization();
  265 +#if _MSC_VER >= 1700
  266 + // With a recent C++ Standard Library this is the way to go
  267 + for_each(m->begin(), m->end(), bind(&FunctionPassManager::run, &(*fpm), std::placeholders::_1));
1
David Nadlinger Owner

Please don't. It just increases code complexity (now there are two branches to maintain) for no benefit – or did I miss a behavioral difference here?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
David Nadlinger klickverbot commented on the diff
gen/optimizer.cpp
((6 lines not shown))
30 38 cl::desc("Setting the optimization level:"),
31 39 cl::ZeroOrMore,
32 40 cl::values(
33   - clEnumValN(2, "O", "Equivalent to -O2"),
34   - clEnumValN(0, "O0", "No optimizations (default)"),
35   - clEnumValN(1, "O1", "Simple optimizations"),
36   - clEnumValN(2, "O2", "Good optimizations"),
37   - clEnumValN(3, "O3", "Aggressive optimizations"),
38   - clEnumValN(4, "O4", "Link-time optimization"), // not implemented?
39   - clEnumValN(5, "O5", "Link-time optimization"), // not implemented?
1
David Nadlinger Owner

I don't think we should hard-remove -O<4-5> at this point – we would needlessly break many people's build scripts. Better just hide it, or add a not-implemented note or warning to it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Kai Nacke redstar Integrated comments:
- Optimiation level 4 and 5 are present again
- STL code for MSVC removed
d1f5e78
Kai Nacke
Owner

I integrated your comments. I simply re-activated the -O<4-5> and mapped them silently to -O3.

David Nadlinger klickverbot commented on the diff
gen/optimizer.cpp
((79 lines not shown))
306 257
  258 + if (doOptimize)
  259 + addOptimizationPasses(pm, *fpm, optLevel(), sizeLevel());
  260 +
  261 + if (optimize()) {
  262 + fpm->doInitialization();
  263 + // With a recent C++ Standard Library this is the way to go
1
David Nadlinger Owner

With an even more recent one, it's for (auto &f : m) fpm->run(f); or something like that ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
David Nadlinger
Owner

Sorry for keeping this open so long. There are a few issues remaining with this, which I originally thought I could fix quickly, and I didn't want to bother you with figuring out what I want if I'm quicker making the changes myself. However, the time I can spend on LDC is pretty limited right now, and I've been sidetracked by all the test suite stuff (which is coming together nicely, by the way).

So, two things (that's what I could remember right now, I'll see if I can find my notes):

  • Please don't remove -enable-inlining, i.e. the ability to enable inlining separate from other optimization passes. The reason for this is that it also changes frontend behavior (additional semantic passes are run on imported functions), and thus I found it occasionally useful to be able to enable it without running any of the other passes.
  • -disable-simplify-drtcalls is not meant to disable the LLVM runtime call simplification pass, but instead our own one for druntime functions. The docs on this should be made clearer, though.
David Nadlinger
Owner

I'm getting this in shape right now.

David Nadlinger klickverbot referenced this pull request from a commit
Commit has since been removed from the repository and is no longer available.
David Nadlinger klickverbot referenced this pull request from a commit
Commit has since been removed from the repository and is no longer available.
David Nadlinger klickverbot referenced this pull request from a commit in klickverbot/ldc
David Nadlinger klickverbot Use llvm::PassManagerBuilder for optimization scheduling.
This commit is based on Kai's pull request #157.
2f78dc6
Kai Nacke
Owner

Thanks. :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 2 unique commits by 1 author.

Sep 08, 2012
Kai Nacke redstar Use PassManagerBuilder.
Replaces the pass setup with the pre-factored PassManagerBuilder. Removes not implemented optimization levels and introduces new levels -Os and -Oz (optimization for size).

New command line options:
- disable-inlinig (prevents running the inliner pass)
- unit-at-a-time (enables IPO, run by default)
- strip-debug (strip debugger symbol info)

Removed command line options:
- enable-inlinig (implicit set by -O1/2/3)
- vectorize (option from PassManagerBuilder used instead)
65d93dc
Sep 09, 2012
Kai Nacke redstar Integrated comments:
- Optimiation level 4 and 5 are present again
- STL code for MSVC removed
d1f5e78
This page is out of date. Refresh to see the latest.

Showing 3 changed files with 145 additions and 174 deletions. Show diff stats Hide diff stats

  1. +2 1  driver/ldmd.cpp
  2. +142 172 gen/optimizer.cpp
  3. +1 1  gen/optimizer.h
3  driver/ldmd.cpp
@@ -760,7 +760,8 @@ void buildCommandLine(std::vector<const char*>& r, const Params& p)
760 760 if (p.jsonName) r.push_back(concat("-Xf=", p.jsonName));
761 761 if (p.ignoreUnsupportedPragmas) r.push_back("-ignore");
762 762 if (p.enforcePropertySyntax) r.push_back("-property");
763   - if (p.enableInline) r.push_back("-enable-inlining");
  763 + // LDC2 performs inlining as part of optimization
  764 + //if (p.enableInline) r.push_back("-enable-inlining");
764 765 if (p.emitStaticLib) r.push_back("-lib");
765 766 if (p.noFloat) warning("-nofloat is ignored by LDC.");
766 767 if (p.quiet) r.push_back("-quiet"); // Undocumented.
314 gen/optimizer.cpp
... ... @@ -1,21 +1,24 @@
1 1 #include "gen/optimizer.h"
2 2 #include "gen/cl_helpers.h"
  3 +#include "gen/irstate.h"
3 4 #include "gen/logger.h"
4 5
5 6 #include "gen/passes/Passes.h"
6 7
7 8 #include "llvm/PassManager.h"
8 9 #include "llvm/LinkAllPasses.h"
9   -#include "llvm/Analysis/LoopPass.h"
  10 +#include "llvm/Module.h"
  11 +#include "llvm/ADT/OwningPtr.h"
  12 +#include "llvm/ADT/Triple.h"
10 13 #include "llvm/Analysis/Verifier.h"
11   -#include "llvm/Target/TargetData.h"
  14 +#include "llvm/Target/TargetLibraryInfo.h"
  15 +#include "llvm/Target/TargetMachine.h"
12 16 #include "llvm/Support/CommandLine.h"
13 17 #include "llvm/Support/PassNameParser.h"
14 18 #include "llvm/Transforms/IPO.h"
  19 +#include "llvm/Transforms/IPO/PassManagerBuilder.h"
15 20
16 21 #include "mars.h" // error()
17   -#include "root.h"
18   -#include <cstring> // strcmp();
19 22
20 23 using namespace llvm;
21 24
@@ -26,17 +29,19 @@ static cl::list<const PassInfo*, bool, PassNameParser>
26 29 cl::Hidden // to clean up --help output
27 30 );
28 31
29   -static cl::opt<unsigned char> optimizeLevel(
  32 +static cl::opt<signed char> optimizeLevel(
30 33 cl::desc("Setting the optimization level:"),
31 34 cl::ZeroOrMore,
32 35 cl::values(
33   - clEnumValN(2, "O", "Equivalent to -O2"),
34   - clEnumValN(0, "O0", "No optimizations (default)"),
35   - clEnumValN(1, "O1", "Simple optimizations"),
36   - clEnumValN(2, "O2", "Good optimizations"),
37   - clEnumValN(3, "O3", "Aggressive optimizations"),
38   - clEnumValN(4, "O4", "Link-time optimization"), // not implemented?
39   - clEnumValN(5, "O5", "Link-time optimization"), // not implemented?
  36 + clEnumValN( 2, "O", "Equivalent to -O2"),
  37 + clEnumValN( 0, "O0", "No optimizations (default)"),
  38 + clEnumValN( 1, "O1", "Simple optimizations"),
  39 + clEnumValN( 2, "O2", "Good optimizations"),
  40 + clEnumValN( 3, "O3", "Aggressive optimizations"),
  41 + clEnumValN( 4, "O4", "Link-time optimization"), // not implemented?
  42 + clEnumValN( 5, "O5", "Link-time optimization"), // not implemented?
  43 + clEnumValN(-1, "Os", "Like -O2 with extra optimizations for size"),
  44 + clEnumValN(-2, "Oz", "Like -Os but reduces code size further"),
40 45 clEnumValEnd),
41 46 cl::init(0));
42 47
@@ -66,45 +71,38 @@ disableGCToStack("disable-gc2stack",
66 71 cl::desc("Disable promotion of GC allocations to stack memory in -O<N>"),
67 72 cl::ZeroOrMore);
68 73
69   -static cl::opt<opts::BoolOrDefaultAdapter, false, opts::FlagParser>
70   -enableInlining("inlining",
71   - cl::desc("(*) Enable function inlining in -O<N>"),
72   - cl::ZeroOrMore);
  74 +static cl::opt<bool>
  75 +disableInlining("disable-inlining", cl::desc("Do not run the inliner pass"));
73 76
74   -#if LDC_LLVM_VER >= 301
75 77 static cl::opt<bool>
76   -runVectorization("vectorize", cl::desc("Run vectorization passes"));
  78 +unitAtATime("unit-at-a-time",
  79 + cl::desc("Enable IPO"),
  80 + cl::init(true));
77 81
78 82 static cl::opt<bool>
79   -useGVNAfterVectorization("use-gvn-after-vectorization",
80   - cl::init(false), cl::Hidden,
81   - cl::desc("Run GVN instead of Early CSE after vectorization passes"));
82   -#endif
  83 +stripDebug("strip-debug",
  84 + cl::desc("Strip debugger symbol info from translation unit"));
83 85
84 86 // Determine whether or not to run the inliner as part of the default list of
85 87 // optimization passes.
86 88 // If not explicitly specified, treat as false for -O0-2, and true for -O3.
87 89 bool doInline() {
88   - return enableInlining == cl::BOU_TRUE
89   - || (enableInlining == cl::BOU_UNSET && optimizeLevel >= 3);
  90 + return !disableInlining && optLevel() > 1;
90 91 }
91 92
92 93 // Determine whether the inliner will be run.
93 94 bool willInline() {
94   - if (doInline())
95   - return true;
96   - // It may also have been specified explicitly on the command line as an explicit pass
97   - typedef cl::list<const PassInfo*, bool, PassNameParser> PL;
98   - for (PL::iterator I = passList.begin(), E = passList.end(); I != E; ++I) {
99   - if (!std::strcmp((*I)->getPassArgument(), "inline"))
100   - return true;
101   - }
102   - return false;
  95 + return !disableInlining && optLevel() > 1;
103 96 }
104 97
105 98 // Some extra accessors for the linker: (llvm-ld version only, currently unused?)
106   -int optLevel() {
107   - return optimizeLevel;
  99 +unsigned optLevel() {
  100 + // Level 4,5 are not implement
  101 + return optimizeLevel >= 0 ? (optimizeLevel > 3 ? 3 : optimizeLevel) : 2;
  102 +}
  103 +
  104 +unsigned sizeLevel() {
  105 + return optimizeLevel < 0 ? -optimizeLevel : 0;
108 106 }
109 107
110 108 bool optimize() {
@@ -127,138 +125,73 @@ llvm::CodeGenOpt::Level codeGenOptLevel() {
127 125 #endif
128 126 }
129 127
130   -static void addPass(PassManager& pm, Pass* pass) {
  128 +static inline void addPass(PassManagerBase& pm, Pass* pass) {
131 129 pm.add(pass);
132 130
133 131 if (verifyEach) pm.add(createVerifierPass());
134 132 }
135 133
136   -// this function inserts some or all of the std-compile-opts passes depending on the
137   -// optimization level given.
138   -static void addPassesForOptLevel(PassManager& pm) {
139   - // -O1
140   - if (optimizeLevel >= 1)
141   - {
142   - // Add alias analysis passes.
143   - // This is at least required for FunctionAttrs pass.
144   - addPass(pm, createTypeBasedAliasAnalysisPass());
145   - addPass(pm, createBasicAliasAnalysisPass());
146   - //addPass(pm, createStripDeadPrototypesPass());
147   - addPass(pm, createGlobalDCEPass());
148   - addPass(pm, createPromoteMemoryToRegisterPass());
149   - addPass(pm, createCFGSimplificationPass());
150   - if (optimizeLevel == 1)
151   - addPass(pm, createPromoteMemoryToRegisterPass());
152   - else
153   - addPass(pm, createScalarReplAggregatesPass());
154   - addPass(pm, createGlobalOptimizerPass());
155   - }
156   -
157   - // -O2
158   - if (optimizeLevel >= 2)
159   - {
160   - addPass(pm, createIPConstantPropagationPass());
161   - addPass(pm, createDeadArgEliminationPass());
162   - addPass(pm, createInstructionCombiningPass());
163   - addPass(pm, createCFGSimplificationPass());
164   - addPass(pm, createPruneEHPass());
  134 +static void addStripExternalsPass(const PassManagerBuilder &builder, PassManagerBase &pm) {
  135 + if (builder.OptLevel >= 1)
  136 + addPass(pm, createStripExternalsPass());
  137 +}
165 138
166   - addPass(pm, createFunctionAttrsPass());
  139 +static void addSimplifyDRuntimeCallsPass(const PassManagerBuilder &builder, PassManagerBase &pm) {
  140 + if (builder.OptLevel >= 2 && builder.SizeLevel == 0)
  141 + addPass(pm, createSimplifyDRuntimeCalls());
  142 +}
167 143
168   - addPass(pm, createTailCallEliminationPass());
169   - addPass(pm, createCFGSimplificationPass());
170   - addPass(pm, createGVNPass());
171   - }
  144 +#if USE_METADATA
  145 +static void addGarbageCollect2StackPass(const PassManagerBuilder &builder, PassManagerBase &pm) {
  146 + if (builder.OptLevel >= 2 && builder.SizeLevel == 0)
  147 + addPass(pm, createGarbageCollect2Stack());
  148 +}
  149 +#endif
172 150
173   - // -inline
174   - if (doInline()) {
175   - addPass(pm, createFunctionInliningPass());
176   -
177   - if (optimizeLevel >= 2) {
178   - // Run some optimizations to clean up after inlining.
179   - addPass(pm, createScalarReplAggregatesPass());
180   - addPass(pm, createInstructionCombiningPass());
181   - // -instcombine + gvn == devirtualization :)
182   - addPass(pm, createGVNPass());
183   -
184   - // Inline again, to catch things like now nonvirtual
185   - // function calls, foreach delegates passed to inlined
186   - // opApply's, etc. where the actual function being called
187   - // wasn't known during the first inliner pass.
188   - addPass(pm, createFunctionInliningPass());
189   - }
  151 +/// AddOptimizationPasses - This routine adds optimization passes
  152 +/// based on selected optimization level, OptLevel. This routine
  153 +/// duplicates llvm-gcc behaviour.
  154 +///
  155 +/// OptLevel - Optimization Level
  156 +static void addOptimizationPasses(PassManagerBase &mpm,FunctionPassManager &fpm,
  157 + unsigned optLevel, unsigned sizeLevel) {
  158 + fpm.add(createVerifierPass()); // Verify that input is correct
  159 +
  160 + PassManagerBuilder builder;
  161 + builder.OptLevel = optLevel;
  162 + builder.SizeLevel = sizeLevel;
  163 +
  164 + if (disableInlining) {
  165 + // No inlining pass
  166 + } else if (optLevel > 1) {
  167 + unsigned threshold = 225;
  168 + if (sizeLevel == 1) // -Os
  169 + threshold = 75;
  170 + else if (sizeLevel == 2) // -Oz
  171 + threshold = 25;
  172 + if (optLevel > 2)
  173 + threshold = 275;
  174 + builder.Inliner = createFunctionInliningPass(threshold);
  175 + } else {
  176 + builder.Inliner = createAlwaysInlinerPass();
190 177 }
  178 + builder.DisableUnitAtATime = !unitAtATime;
  179 + builder.DisableUnrollLoops = optLevel == 0;
  180 + builder.DisableSimplifyLibCalls = disableSimplifyRuntimeCalls;
  181 + /* builder.Vectorize is set in ctor from command line switch */
191 182
192   - if (optimizeLevel >= 2) {
193   - if (!disableLangSpecificPasses) {
194   - if (!disableSimplifyRuntimeCalls)
195   - addPass(pm, createSimplifyDRuntimeCalls());
  183 + if (!disableLangSpecificPasses) {
  184 + if (!disableSimplifyRuntimeCalls)
  185 + builder.addExtension(PassManagerBuilder::EP_LoopOptimizerEnd, addSimplifyDRuntimeCallsPass);
196 186
197 187 #if USE_METADATA
198   - if (!disableGCToStack)
199   - addPass(pm, createGarbageCollect2Stack());
  188 + Builder.addExtension(PassManagerBuilder::EP_LoopOptimizerEnd, addGarbageCollect2StackPass);
200 189 #endif // USE_METADATA
201   - }
202   - // Run some clean-up passes
203   - addPass(pm, createInstructionCombiningPass());
204   - addPass(pm, createScalarReplAggregatesPass());
205   - addPass(pm, createCFGSimplificationPass());
206   - addPass(pm, createInstructionCombiningPass());
207 190 }
  191 + builder.addExtension(PassManagerBuilder::EP_OptimizerLast, addStripExternalsPass);
208 192
209   - // -O3
210   - if (optimizeLevel >= 3)
211   - {
212   - addPass(pm, createArgumentPromotionPass());
213   - addPass(pm, createSimplifyLibCallsPass());
214   - addPass(pm, createInstructionCombiningPass());
215   - addPass(pm, createJumpThreadingPass());
216   - addPass(pm, createCFGSimplificationPass());
217   - addPass(pm, createScalarReplAggregatesPass());
218   - addPass(pm, createInstructionCombiningPass());
219   - addPass(pm, createConstantPropagationPass());
220   -
221   - addPass(pm, createReassociatePass());
222   - addPass(pm, createLoopRotatePass());
223   - addPass(pm, createLICMPass());
224   - addPass(pm, createLoopUnswitchPass());
225   - addPass(pm, createInstructionCombiningPass());
226   - addPass(pm, createIndVarSimplifyPass());
227   - addPass(pm, createLoopDeletionPass());
228   - addPass(pm, createLoopUnrollPass());
229   - addPass(pm, createInstructionCombiningPass());
230   - addPass(pm, createGVNPass());
231   - addPass(pm, createMemCpyOptPass());
232   - addPass(pm, createSCCPPass());
233   -
234   - addPass(pm, createInstructionCombiningPass());
235   - addPass(pm, createConstantPropagationPass());
236   -
237   - addPass(pm, createDeadStoreEliminationPass());
238   - addPass(pm, createAggressiveDCEPass());
239   - addPass(pm, createCFGSimplificationPass());
240   - addPass(pm, createConstantMergePass());
241   - }
242   -
243   -#if LDC_LLVM_VER >= 301
244   - // -vectorize
245   - if (runVectorization)
246   - {
247   - addPass(pm, createBBVectorizePass());
248   - addPass(pm, createInstructionCombiningPass());
249   - if (optimizeLevel > 1 && useGVNAfterVectorization)
250   - addPass(pm, createGVNPass()); // Remove redundancies
251   - else
252   - addPass(pm, createEarlyCSEPass()); // Catch trivial redundancies
253   - }
254   -#endif
255   -
256   - if (optimizeLevel >= 1) {
257   - addPass(pm, createStripExternalsPass());
258   - addPass(pm, createGlobalDCEPass());
259   - }
260   -
261   - // level -O4 and -O5 are linktime optimizations
  193 + builder.populateFunctionPassManager(fpm);
  194 + builder.populateModulePassManager(mpm);
262 195 }
263 196
264 197 //////////////////////////////////////////////////////////////////////////////////////////
@@ -266,48 +199,85 @@ static void addPassesForOptLevel(PassManager& pm) {
266 199 // Returns true if any optimization passes were invoked.
267 200 bool ldc_optimize_module(llvm::Module* m)
268 201 {
  202 + // Early exit if no optimization requested
269 203 if (!optimize())
270 204 return false;
271 205
  206 + // Create a PassManager to hold and optimize the collection of passes we are
  207 + // about to build.
272 208 PassManager pm;
273 209
274   - if (verifyEach) pm.add(createVerifierPass());
  210 + // Add an appropriate TargetLibraryInfo pass for the module's triple.
  211 + TargetLibraryInfo *tli = new TargetLibraryInfo(Triple(m->getTargetTriple()));
275 212
276   - addPass(pm, new TargetData(m));
  213 + // The -disable-simplify-libcalls flag actually disables all builtin optzns.
  214 + if (disableSimplifyRuntimeCalls)
  215 + tli->disableAllFunctions();
  216 + pm.add(tli);
277 217
278   - bool optimize = optimizeLevel != 0 || doInline();
  218 + // Add an appropriate TargetData instance for this module.
  219 + if (gTargetData)
  220 + pm.add(new TargetData(*gTargetData));
279 221
280   - unsigned optPos = optimizeLevel != 0
281   - ? optimizeLevel.getPosition()
282   - : enableInlining.getPosition();
  222 + OwningPtr<FunctionPassManager> fpm;
  223 + if (optimize()) {
  224 + fpm.reset(new FunctionPassManager(m));
  225 + if (gTargetData)
  226 + fpm->add(new TargetData(*gTargetData));
  227 + }
  228 +
  229 + // If the -strip-debug command line option was specified, add it. If
  230 + if (stripDebug)
  231 + addPass(pm, createStripSymbolsPass(true));
283 232
284   - for (size_t i = 0; i < passList.size(); i++) {
285   - // insert -O<N> / -enable-inlining in right position
286   - if (optimize && optPos < passList.getPosition(i)) {
287   - addPassesForOptLevel(pm);
288   - optimize = false;
  233 + bool doOptimize = true;
  234 + // Create a new optimization pass for each one specified on the command line
  235 + for (unsigned i = 0; i < passList.size(); ++i) {
  236 + if (optimizeLevel && optimizeLevel.getPosition() < passList.getPosition(i)) {
  237 + addOptimizationPasses(pm, *fpm, optLevel(), sizeLevel());
  238 + doOptimize = false;
289 239 }
290 240
291   - const PassInfo* pass = passList[i];
292   - if (PassInfo::NormalCtor_t ctor = pass->getNormalCtor()) {
293   - addPass(pm, ctor());
294   - } else {
295   - const char* arg = pass->getPassArgument(); // may return null
  241 + const PassInfo *passInf = passList[i];
  242 + Pass *pass = 0;
  243 + if (passInf->getNormalCtor())
  244 + pass = passInf->getNormalCtor()();
  245 + else {
  246 + const char* arg = passInf->getPassArgument(); // may return null
296 247 if (arg)
297 248 error("Can't create pass '-%s' (%s)", arg, pass->getPassName());
298 249 else
299 250 error("Can't create pass (%s)", pass->getPassName());
300   - assert(0); // Should be unreachable; root.h:error() calls exit()
  251 + llvm_unreachable("pass creation failed");
  252 + }
  253 + if (pass) {
  254 + addPass(pm, pass);
301 255 }
302 256 }
303   - // insert -O<N> / -enable-inlining if specified at the end,
304   - if (optimize)
305   - addPassesForOptLevel(pm);
306 257
  258 + if (doOptimize)
  259 + addOptimizationPasses(pm, *fpm, optLevel(), sizeLevel());
  260 +
  261 + if (optimize()) {
  262 + fpm->doInitialization();
  263 + // With a recent C++ Standard Library this is the way to go
  264 + //for_each(m->begin(), m->end(), bind(&FunctionPassManager::run, &(*fpm), std::placeholders::_1));
  265 + for (llvm::Module::iterator F = m->begin(), E = m->end(); F != E; ++F)
  266 + fpm->run(*F);
  267 + fpm->doFinalization();
  268 + }
  269 +
  270 + // Check that the module is well formed on completion of optimization
  271 + if (!noVerify && !verifyEach)
  272 + pm.add(createVerifierPass());
  273 +
  274 + // Now that we have all of the passes ready, run them.
307 275 pm.run(*m);
308 276
  277 + // Verify module again.
309 278 verifyModule(m);
310 279
  280 + // Report that we run some passes.
311 281 return true;
312 282 }
313 283
2  gen/optimizer.h
@@ -17,7 +17,7 @@ bool doInline();
17 17 // Determines whether the inliner will be run at all.
18 18 bool willInline();
19 19
20   -int optLevel();
  20 +unsigned optLevel();
21 21
22 22 bool optimize();
23 23

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.