Mercurial > projects > ldc
annotate gen/optimizer.cpp @ 1518:26d061e61b02
Initialize LLVM target and asmprinter for the native and extra targets.
Uses some CMake hackery to get the native LLVM target name, since it only
provides a conveniance function for initializing the native target and not the
native asmprinter.
author | Christian Kamm <kamm incasoftware de> |
---|---|
date | Fri, 26 Jun 2009 21:02:23 +0200 |
parents | f86fd3b77285 |
children | c88b16d4a13c |
rev | line source |
---|---|
1170
e40c65bd8c5d
Allow specific optimization passes to be requested from the command line.
Frits van Bommel <fvbommel wxs.nl>
parents:
663
diff
changeset
|
1 #include "gen/optimizer.h" |
1175
cc1efa23030a
Enable inlining by default for -O3+.
Frits van Bommel <fvbommel wxs.nl>
parents:
1172
diff
changeset
|
2 #include "gen/cl_helpers.h" |
1170
e40c65bd8c5d
Allow specific optimization passes to be requested from the command line.
Frits van Bommel <fvbommel wxs.nl>
parents:
663
diff
changeset
|
3 |
1275
bedf0bfb8fdb
Implement first D-specific optimization pass: -simplify-drtcalls.
Frits van Bommel <fvbommel wxs.nl>
parents:
1268
diff
changeset
|
4 #include "gen/passes/Passes.h" |
bedf0bfb8fdb
Implement first D-specific optimization pass: -simplify-drtcalls.
Frits van Bommel <fvbommel wxs.nl>
parents:
1268
diff
changeset
|
5 |
125 | 6 #include "llvm/PassManager.h" |
7 #include "llvm/LinkAllPasses.h" | |
8 #include "llvm/Analysis/LoopPass.h" | |
1296
79b201533cf8
Add -verify-each option to ease debugging
Frits van Bommel <fvbommel wxs.nl>
parents:
1294
diff
changeset
|
9 #include "llvm/Analysis/Verifier.h" |
125 | 10 #include "llvm/Target/TargetData.h" |
1170
e40c65bd8c5d
Allow specific optimization passes to be requested from the command line.
Frits van Bommel <fvbommel wxs.nl>
parents:
663
diff
changeset
|
11 #include "llvm/Support/CommandLine.h" |
e40c65bd8c5d
Allow specific optimization passes to be requested from the command line.
Frits van Bommel <fvbommel wxs.nl>
parents:
663
diff
changeset
|
12 #include "llvm/Support/PassNameParser.h" |
e40c65bd8c5d
Allow specific optimization passes to be requested from the command line.
Frits van Bommel <fvbommel wxs.nl>
parents:
663
diff
changeset
|
13 |
1172
b3887714b735
Small cleanup: remove mars.h #include
Frits van Bommel <fvbommel wxs.nl>
parents:
1171
diff
changeset
|
14 #include "root.h" // error() |
1482
d9c5f5a43403
Run `semantic3` on imported modules, and emit new symbols with
Frits van Bommel <fvbommel wxs.nl>
parents:
1481
diff
changeset
|
15 #include <cstring> // strcmp(); |
125 | 16 |
17 using namespace llvm; | |
18 | |
1170
e40c65bd8c5d
Allow specific optimization passes to be requested from the command line.
Frits van Bommel <fvbommel wxs.nl>
parents:
663
diff
changeset
|
19 // Allow the user to specify specific optimizations to run. |
e40c65bd8c5d
Allow specific optimization passes to be requested from the command line.
Frits van Bommel <fvbommel wxs.nl>
parents:
663
diff
changeset
|
20 static cl::list<const PassInfo*, bool, PassNameParser> |
e40c65bd8c5d
Allow specific optimization passes to be requested from the command line.
Frits van Bommel <fvbommel wxs.nl>
parents:
663
diff
changeset
|
21 passList( |
e40c65bd8c5d
Allow specific optimization passes to be requested from the command line.
Frits van Bommel <fvbommel wxs.nl>
parents:
663
diff
changeset
|
22 cl::desc("Running specific optimizations:"), |
e40c65bd8c5d
Allow specific optimization passes to be requested from the command line.
Frits van Bommel <fvbommel wxs.nl>
parents:
663
diff
changeset
|
23 cl::Hidden // to clean up --help output |
e40c65bd8c5d
Allow specific optimization passes to be requested from the command line.
Frits van Bommel <fvbommel wxs.nl>
parents:
663
diff
changeset
|
24 ); |
125 | 25 |
1281
29d3861aa2da
Make sure this still compiles after LLVM r70437, which introduces a
Frits van Bommel <fvbommel wxs.nl>
parents:
1275
diff
changeset
|
26 static cl::opt<unsigned char> optimizeLevel( |
1170
e40c65bd8c5d
Allow specific optimization passes to be requested from the command line.
Frits van Bommel <fvbommel wxs.nl>
parents:
663
diff
changeset
|
27 cl::desc("Setting the optimization level:"), |
e40c65bd8c5d
Allow specific optimization passes to be requested from the command line.
Frits van Bommel <fvbommel wxs.nl>
parents:
663
diff
changeset
|
28 cl::ZeroOrMore, |
e40c65bd8c5d
Allow specific optimization passes to be requested from the command line.
Frits van Bommel <fvbommel wxs.nl>
parents:
663
diff
changeset
|
29 cl::values( |
e40c65bd8c5d
Allow specific optimization passes to be requested from the command line.
Frits van Bommel <fvbommel wxs.nl>
parents:
663
diff
changeset
|
30 clEnumValN(2, "O", "Equivalent to -O2"), |
1171
461a85f0db31
Change meaning of optimization levels: -O0 now means 'no optimization' like with
Frits van Bommel <fvbommel wxs.nl>
parents:
1170
diff
changeset
|
31 clEnumValN(0, "O0", "No optimizations (default)"), |
1170
e40c65bd8c5d
Allow specific optimization passes to be requested from the command line.
Frits van Bommel <fvbommel wxs.nl>
parents:
663
diff
changeset
|
32 clEnumValN(1, "O1", "Simple optimizations"), |
e40c65bd8c5d
Allow specific optimization passes to be requested from the command line.
Frits van Bommel <fvbommel wxs.nl>
parents:
663
diff
changeset
|
33 clEnumValN(2, "O2", "Good optimizations"), |
e40c65bd8c5d
Allow specific optimization passes to be requested from the command line.
Frits van Bommel <fvbommel wxs.nl>
parents:
663
diff
changeset
|
34 clEnumValN(3, "O3", "Aggressive optimizations"), |
e40c65bd8c5d
Allow specific optimization passes to be requested from the command line.
Frits van Bommel <fvbommel wxs.nl>
parents:
663
diff
changeset
|
35 clEnumValN(4, "O4", "Link-time optimization"), // not implemented? |
e40c65bd8c5d
Allow specific optimization passes to be requested from the command line.
Frits van Bommel <fvbommel wxs.nl>
parents:
663
diff
changeset
|
36 clEnumValN(5, "O5", "Link-time optimization"), // not implemented? |
e40c65bd8c5d
Allow specific optimization passes to be requested from the command line.
Frits van Bommel <fvbommel wxs.nl>
parents:
663
diff
changeset
|
37 clEnumValEnd), |
1171
461a85f0db31
Change meaning of optimization levels: -O0 now means 'no optimization' like with
Frits van Bommel <fvbommel wxs.nl>
parents:
1170
diff
changeset
|
38 cl::init(0)); |
125 | 39 |
1275
bedf0bfb8fdb
Implement first D-specific optimization pass: -simplify-drtcalls.
Frits van Bommel <fvbommel wxs.nl>
parents:
1268
diff
changeset
|
40 static cl::opt<bool> |
1296
79b201533cf8
Add -verify-each option to ease debugging
Frits van Bommel <fvbommel wxs.nl>
parents:
1294
diff
changeset
|
41 verifyEach("verify-each", |
79b201533cf8
Add -verify-each option to ease debugging
Frits van Bommel <fvbommel wxs.nl>
parents:
1294
diff
changeset
|
42 cl::desc("Run verifier after each optimization pass"), |
79b201533cf8
Add -verify-each option to ease debugging
Frits van Bommel <fvbommel wxs.nl>
parents:
1294
diff
changeset
|
43 cl::Hidden, |
79b201533cf8
Add -verify-each option to ease debugging
Frits van Bommel <fvbommel wxs.nl>
parents:
1294
diff
changeset
|
44 cl::ZeroOrMore); |
79b201533cf8
Add -verify-each option to ease debugging
Frits van Bommel <fvbommel wxs.nl>
parents:
1294
diff
changeset
|
45 |
79b201533cf8
Add -verify-each option to ease debugging
Frits van Bommel <fvbommel wxs.nl>
parents:
1294
diff
changeset
|
46 static cl::opt<bool> |
1275
bedf0bfb8fdb
Implement first D-specific optimization pass: -simplify-drtcalls.
Frits van Bommel <fvbommel wxs.nl>
parents:
1268
diff
changeset
|
47 disableLangSpecificPasses("disable-d-passes", |
bedf0bfb8fdb
Implement first D-specific optimization pass: -simplify-drtcalls.
Frits van Bommel <fvbommel wxs.nl>
parents:
1268
diff
changeset
|
48 cl::desc("Disable D-specific passes in -O<N>"), |
bedf0bfb8fdb
Implement first D-specific optimization pass: -simplify-drtcalls.
Frits van Bommel <fvbommel wxs.nl>
parents:
1268
diff
changeset
|
49 cl::ZeroOrMore); |
bedf0bfb8fdb
Implement first D-specific optimization pass: -simplify-drtcalls.
Frits van Bommel <fvbommel wxs.nl>
parents:
1268
diff
changeset
|
50 |
bedf0bfb8fdb
Implement first D-specific optimization pass: -simplify-drtcalls.
Frits van Bommel <fvbommel wxs.nl>
parents:
1268
diff
changeset
|
51 static cl::opt<bool> |
bedf0bfb8fdb
Implement first D-specific optimization pass: -simplify-drtcalls.
Frits van Bommel <fvbommel wxs.nl>
parents:
1268
diff
changeset
|
52 disableSimplifyRuntimeCalls("disable-simplify-drtcalls", |
bedf0bfb8fdb
Implement first D-specific optimization pass: -simplify-drtcalls.
Frits van Bommel <fvbommel wxs.nl>
parents:
1268
diff
changeset
|
53 cl::desc("Disable simplification of runtime calls in -O<N>"), |
bedf0bfb8fdb
Implement first D-specific optimization pass: -simplify-drtcalls.
Frits van Bommel <fvbommel wxs.nl>
parents:
1268
diff
changeset
|
54 cl::ZeroOrMore); |
bedf0bfb8fdb
Implement first D-specific optimization pass: -simplify-drtcalls.
Frits van Bommel <fvbommel wxs.nl>
parents:
1268
diff
changeset
|
55 |
1288
e109e4031e8a
Fix build when USE_METADATA is off.
Matti Niemenmaa <matti.niemenmaa+hg@iki.fi>
parents:
1287
diff
changeset
|
56 #ifdef USE_METADATA |
1285
91d9386d4a5a
Implement another D-specific pass: -dgc2stack
Frits van Bommel <fvbommel wxs.nl>
parents:
1281
diff
changeset
|
57 static cl::opt<bool> |
91d9386d4a5a
Implement another D-specific pass: -dgc2stack
Frits van Bommel <fvbommel wxs.nl>
parents:
1281
diff
changeset
|
58 disableGCToStack("disable-gc2stack", |
91d9386d4a5a
Implement another D-specific pass: -dgc2stack
Frits van Bommel <fvbommel wxs.nl>
parents:
1281
diff
changeset
|
59 cl::desc("Disable promotion of GC allocations to stack memory in -O<N>"), |
91d9386d4a5a
Implement another D-specific pass: -dgc2stack
Frits van Bommel <fvbommel wxs.nl>
parents:
1281
diff
changeset
|
60 cl::ZeroOrMore); |
91d9386d4a5a
Implement another D-specific pass: -dgc2stack
Frits van Bommel <fvbommel wxs.nl>
parents:
1281
diff
changeset
|
61 |
1287
6c8af78364f5
There's an issue with LLVM metadata support; it triggers an assert when trying
Frits van Bommel <fvbommel wxs.nl>
parents:
1285
diff
changeset
|
62 // Not recommended; metadata currently triggers an assert in the backend... |
6c8af78364f5
There's an issue with LLVM metadata support; it triggers an assert when trying
Frits van Bommel <fvbommel wxs.nl>
parents:
1285
diff
changeset
|
63 static cl::opt<bool> |
6c8af78364f5
There's an issue with LLVM metadata support; it triggers an assert when trying
Frits van Bommel <fvbommel wxs.nl>
parents:
1285
diff
changeset
|
64 disableStripMetaData("disable-strip-metadata", |
6c8af78364f5
There's an issue with LLVM metadata support; it triggers an assert when trying
Frits van Bommel <fvbommel wxs.nl>
parents:
1285
diff
changeset
|
65 cl::desc("Disable default metadata stripping (not recommended)"), |
6c8af78364f5
There's an issue with LLVM metadata support; it triggers an assert when trying
Frits van Bommel <fvbommel wxs.nl>
parents:
1285
diff
changeset
|
66 cl::ZeroOrMore); |
1288
e109e4031e8a
Fix build when USE_METADATA is off.
Matti Niemenmaa <matti.niemenmaa+hg@iki.fi>
parents:
1287
diff
changeset
|
67 #endif |
1287
6c8af78364f5
There's an issue with LLVM metadata support; it triggers an assert when trying
Frits van Bommel <fvbommel wxs.nl>
parents:
1285
diff
changeset
|
68 |
1175
cc1efa23030a
Enable inlining by default for -O3+.
Frits van Bommel <fvbommel wxs.nl>
parents:
1172
diff
changeset
|
69 static cl::opt<opts::BoolOrDefaultAdapter, false, opts::FlagParser> |
cc1efa23030a
Enable inlining by default for -O3+.
Frits van Bommel <fvbommel wxs.nl>
parents:
1172
diff
changeset
|
70 enableInlining("inlining", |
1275
bedf0bfb8fdb
Implement first D-specific optimization pass: -simplify-drtcalls.
Frits van Bommel <fvbommel wxs.nl>
parents:
1268
diff
changeset
|
71 cl::desc("(*) Enable function inlining in -O<N>"), |
1175
cc1efa23030a
Enable inlining by default for -O3+.
Frits van Bommel <fvbommel wxs.nl>
parents:
1172
diff
changeset
|
72 cl::ZeroOrMore); |
1170
e40c65bd8c5d
Allow specific optimization passes to be requested from the command line.
Frits van Bommel <fvbommel wxs.nl>
parents:
663
diff
changeset
|
73 |
1175
cc1efa23030a
Enable inlining by default for -O3+.
Frits van Bommel <fvbommel wxs.nl>
parents:
1172
diff
changeset
|
74 // Determine whether or not to run the inliner as part of the default list of |
cc1efa23030a
Enable inlining by default for -O3+.
Frits van Bommel <fvbommel wxs.nl>
parents:
1172
diff
changeset
|
75 // optimization passes. |
cc1efa23030a
Enable inlining by default for -O3+.
Frits van Bommel <fvbommel wxs.nl>
parents:
1172
diff
changeset
|
76 // If not explicitly specified, treat as false for -O0-2, and true for -O3. |
1170
e40c65bd8c5d
Allow specific optimization passes to be requested from the command line.
Frits van Bommel <fvbommel wxs.nl>
parents:
663
diff
changeset
|
77 bool doInline() { |
1175
cc1efa23030a
Enable inlining by default for -O3+.
Frits van Bommel <fvbommel wxs.nl>
parents:
1172
diff
changeset
|
78 return enableInlining == cl::BOU_TRUE |
cc1efa23030a
Enable inlining by default for -O3+.
Frits van Bommel <fvbommel wxs.nl>
parents:
1172
diff
changeset
|
79 || (enableInlining == cl::BOU_UNSET && optimizeLevel >= 3); |
1170
e40c65bd8c5d
Allow specific optimization passes to be requested from the command line.
Frits van Bommel <fvbommel wxs.nl>
parents:
663
diff
changeset
|
80 } |
131 | 81 |
1482
d9c5f5a43403
Run `semantic3` on imported modules, and emit new symbols with
Frits van Bommel <fvbommel wxs.nl>
parents:
1481
diff
changeset
|
82 // Determine whether the inliner will be run. |
d9c5f5a43403
Run `semantic3` on imported modules, and emit new symbols with
Frits van Bommel <fvbommel wxs.nl>
parents:
1481
diff
changeset
|
83 bool willInline() { |
d9c5f5a43403
Run `semantic3` on imported modules, and emit new symbols with
Frits van Bommel <fvbommel wxs.nl>
parents:
1481
diff
changeset
|
84 if (doInline()) |
d9c5f5a43403
Run `semantic3` on imported modules, and emit new symbols with
Frits van Bommel <fvbommel wxs.nl>
parents:
1481
diff
changeset
|
85 return true; |
d9c5f5a43403
Run `semantic3` on imported modules, and emit new symbols with
Frits van Bommel <fvbommel wxs.nl>
parents:
1481
diff
changeset
|
86 // It may also have been specified explicitly on the command line as an explicit pass |
d9c5f5a43403
Run `semantic3` on imported modules, and emit new symbols with
Frits van Bommel <fvbommel wxs.nl>
parents:
1481
diff
changeset
|
87 typedef cl::list<const PassInfo*, bool, PassNameParser> PL; |
d9c5f5a43403
Run `semantic3` on imported modules, and emit new symbols with
Frits van Bommel <fvbommel wxs.nl>
parents:
1481
diff
changeset
|
88 for (PL::iterator I = passList.begin(), E = passList.end(); I != E; ++I) { |
d9c5f5a43403
Run `semantic3` on imported modules, and emit new symbols with
Frits van Bommel <fvbommel wxs.nl>
parents:
1481
diff
changeset
|
89 if (!std::strcmp((*I)->getPassArgument(), "inline")) |
d9c5f5a43403
Run `semantic3` on imported modules, and emit new symbols with
Frits van Bommel <fvbommel wxs.nl>
parents:
1481
diff
changeset
|
90 return true; |
d9c5f5a43403
Run `semantic3` on imported modules, and emit new symbols with
Frits van Bommel <fvbommel wxs.nl>
parents:
1481
diff
changeset
|
91 } |
d9c5f5a43403
Run `semantic3` on imported modules, and emit new symbols with
Frits van Bommel <fvbommel wxs.nl>
parents:
1481
diff
changeset
|
92 return false; |
d9c5f5a43403
Run `semantic3` on imported modules, and emit new symbols with
Frits van Bommel <fvbommel wxs.nl>
parents:
1481
diff
changeset
|
93 } |
d9c5f5a43403
Run `semantic3` on imported modules, and emit new symbols with
Frits van Bommel <fvbommel wxs.nl>
parents:
1481
diff
changeset
|
94 |
1175
cc1efa23030a
Enable inlining by default for -O3+.
Frits van Bommel <fvbommel wxs.nl>
parents:
1172
diff
changeset
|
95 // Some extra accessors for the linker: (llvm-ld version only, currently unused?) |
1170
e40c65bd8c5d
Allow specific optimization passes to be requested from the command line.
Frits van Bommel <fvbommel wxs.nl>
parents:
663
diff
changeset
|
96 int optLevel() { |
e40c65bd8c5d
Allow specific optimization passes to be requested from the command line.
Frits van Bommel <fvbommel wxs.nl>
parents:
663
diff
changeset
|
97 return optimizeLevel; |
e40c65bd8c5d
Allow specific optimization passes to be requested from the command line.
Frits van Bommel <fvbommel wxs.nl>
parents:
663
diff
changeset
|
98 } |
125 | 99 |
1170
e40c65bd8c5d
Allow specific optimization passes to be requested from the command line.
Frits van Bommel <fvbommel wxs.nl>
parents:
663
diff
changeset
|
100 bool optimize() { |
1267 | 101 return optimizeLevel || doInline() || !passList.empty(); |
1170
e40c65bd8c5d
Allow specific optimization passes to be requested from the command line.
Frits van Bommel <fvbommel wxs.nl>
parents:
663
diff
changeset
|
102 } |
e40c65bd8c5d
Allow specific optimization passes to be requested from the command line.
Frits van Bommel <fvbommel wxs.nl>
parents:
663
diff
changeset
|
103 |
1296
79b201533cf8
Add -verify-each option to ease debugging
Frits van Bommel <fvbommel wxs.nl>
parents:
1294
diff
changeset
|
104 static void addPass(PassManager& pm, Pass* pass) { |
79b201533cf8
Add -verify-each option to ease debugging
Frits van Bommel <fvbommel wxs.nl>
parents:
1294
diff
changeset
|
105 pm.add(pass); |
79b201533cf8
Add -verify-each option to ease debugging
Frits van Bommel <fvbommel wxs.nl>
parents:
1294
diff
changeset
|
106 |
79b201533cf8
Add -verify-each option to ease debugging
Frits van Bommel <fvbommel wxs.nl>
parents:
1294
diff
changeset
|
107 if (verifyEach) pm.add(createVerifierPass()); |
79b201533cf8
Add -verify-each option to ease debugging
Frits van Bommel <fvbommel wxs.nl>
parents:
1294
diff
changeset
|
108 } |
79b201533cf8
Add -verify-each option to ease debugging
Frits van Bommel <fvbommel wxs.nl>
parents:
1294
diff
changeset
|
109 |
1170
e40c65bd8c5d
Allow specific optimization passes to be requested from the command line.
Frits van Bommel <fvbommel wxs.nl>
parents:
663
diff
changeset
|
110 // this function inserts some or all of the std-compile-opts passes depending on the |
e40c65bd8c5d
Allow specific optimization passes to be requested from the command line.
Frits van Bommel <fvbommel wxs.nl>
parents:
663
diff
changeset
|
111 // optimization level given. |
e40c65bd8c5d
Allow specific optimization passes to be requested from the command line.
Frits van Bommel <fvbommel wxs.nl>
parents:
663
diff
changeset
|
112 static void addPassesForOptLevel(PassManager& pm) { |
1171
461a85f0db31
Change meaning of optimization levels: -O0 now means 'no optimization' like with
Frits van Bommel <fvbommel wxs.nl>
parents:
1170
diff
changeset
|
113 // -O1 |
461a85f0db31
Change meaning of optimization levels: -O0 now means 'no optimization' like with
Frits van Bommel <fvbommel wxs.nl>
parents:
1170
diff
changeset
|
114 if (optimizeLevel >= 1) |
131 | 115 { |
1296
79b201533cf8
Add -verify-each option to ease debugging
Frits van Bommel <fvbommel wxs.nl>
parents:
1294
diff
changeset
|
116 //addPass(pm, createStripDeadPrototypesPass()); |
79b201533cf8
Add -verify-each option to ease debugging
Frits van Bommel <fvbommel wxs.nl>
parents:
1294
diff
changeset
|
117 addPass(pm, createGlobalDCEPass()); |
79b201533cf8
Add -verify-each option to ease debugging
Frits van Bommel <fvbommel wxs.nl>
parents:
1294
diff
changeset
|
118 addPass(pm, createRaiseAllocationsPass()); |
79b201533cf8
Add -verify-each option to ease debugging
Frits van Bommel <fvbommel wxs.nl>
parents:
1294
diff
changeset
|
119 addPass(pm, createCFGSimplificationPass()); |
1219
a0844cc67840
Tweak some optimizations.
Frits van Bommel <fvbommel wxs.nl>
parents:
1175
diff
changeset
|
120 if (optimizeLevel == 1) |
1296
79b201533cf8
Add -verify-each option to ease debugging
Frits van Bommel <fvbommel wxs.nl>
parents:
1294
diff
changeset
|
121 addPass(pm, createPromoteMemoryToRegisterPass()); |
1219
a0844cc67840
Tweak some optimizations.
Frits van Bommel <fvbommel wxs.nl>
parents:
1175
diff
changeset
|
122 else |
1296
79b201533cf8
Add -verify-each option to ease debugging
Frits van Bommel <fvbommel wxs.nl>
parents:
1294
diff
changeset
|
123 addPass(pm, createScalarReplAggregatesPass()); |
79b201533cf8
Add -verify-each option to ease debugging
Frits van Bommel <fvbommel wxs.nl>
parents:
1294
diff
changeset
|
124 addPass(pm, createGlobalOptimizerPass()); |
125 | 125 } |
126 | |
131 | 127 // -O2 |
1170
e40c65bd8c5d
Allow specific optimization passes to be requested from the command line.
Frits van Bommel <fvbommel wxs.nl>
parents:
663
diff
changeset
|
128 if (optimizeLevel >= 2) |
125 | 129 { |
1296
79b201533cf8
Add -verify-each option to ease debugging
Frits van Bommel <fvbommel wxs.nl>
parents:
1294
diff
changeset
|
130 addPass(pm, createIPConstantPropagationPass()); |
79b201533cf8
Add -verify-each option to ease debugging
Frits van Bommel <fvbommel wxs.nl>
parents:
1294
diff
changeset
|
131 addPass(pm, createDeadArgEliminationPass()); |
79b201533cf8
Add -verify-each option to ease debugging
Frits van Bommel <fvbommel wxs.nl>
parents:
1294
diff
changeset
|
132 addPass(pm, createInstructionCombiningPass()); |
79b201533cf8
Add -verify-each option to ease debugging
Frits van Bommel <fvbommel wxs.nl>
parents:
1294
diff
changeset
|
133 addPass(pm, createCFGSimplificationPass()); |
79b201533cf8
Add -verify-each option to ease debugging
Frits van Bommel <fvbommel wxs.nl>
parents:
1294
diff
changeset
|
134 addPass(pm, createPruneEHPass()); |
1423
42bd767ec5a4
* Add -functionattrs to default pass list so -dgc2stack is more effective
Frits van Bommel <fvbommel wxs.nl>
parents:
1296
diff
changeset
|
135 addPass(pm, createFunctionAttrsPass()); |
1472
a28953f1eb43
Move `-tailcallelim` to a place in the optimization sequence where it seems to
Frits van Bommel <fvbommel wxs.nl>
parents:
1423
diff
changeset
|
136 addPass(pm, createTailCallEliminationPass()); |
a28953f1eb43
Move `-tailcallelim` to a place in the optimization sequence where it seems to
Frits van Bommel <fvbommel wxs.nl>
parents:
1423
diff
changeset
|
137 addPass(pm, createCFGSimplificationPass()); |
1506
76936858d1c6
Return `void*` from _d_allocclass so LLVM doesn't do weird things with it...
Frits van Bommel <fvbommel wxs.nl>
parents:
1492
diff
changeset
|
138 addPass(pm, createGVNPass()); |
125 | 139 } |
140 | |
131 | 141 // -inline |
1175
cc1efa23030a
Enable inlining by default for -O3+.
Frits van Bommel <fvbommel wxs.nl>
parents:
1172
diff
changeset
|
142 if (doInline()) { |
1296
79b201533cf8
Add -verify-each option to ease debugging
Frits van Bommel <fvbommel wxs.nl>
parents:
1294
diff
changeset
|
143 addPass(pm, createFunctionInliningPass()); |
1288
e109e4031e8a
Fix build when USE_METADATA is off.
Matti Niemenmaa <matti.niemenmaa+hg@iki.fi>
parents:
1287
diff
changeset
|
144 |
1219
a0844cc67840
Tweak some optimizations.
Frits van Bommel <fvbommel wxs.nl>
parents:
1175
diff
changeset
|
145 if (optimizeLevel >= 2) { |
a0844cc67840
Tweak some optimizations.
Frits van Bommel <fvbommel wxs.nl>
parents:
1175
diff
changeset
|
146 // Run some optimizations to clean up after inlining. |
1296
79b201533cf8
Add -verify-each option to ease debugging
Frits van Bommel <fvbommel wxs.nl>
parents:
1294
diff
changeset
|
147 addPass(pm, createScalarReplAggregatesPass()); |
79b201533cf8
Add -verify-each option to ease debugging
Frits van Bommel <fvbommel wxs.nl>
parents:
1294
diff
changeset
|
148 addPass(pm, createInstructionCombiningPass()); |
1506
76936858d1c6
Return `void*` from _d_allocclass so LLVM doesn't do weird things with it...
Frits van Bommel <fvbommel wxs.nl>
parents:
1492
diff
changeset
|
149 // -instcombine + gvn == devirtualization :) |
76936858d1c6
Return `void*` from _d_allocclass so LLVM doesn't do weird things with it...
Frits van Bommel <fvbommel wxs.nl>
parents:
1492
diff
changeset
|
150 addPass(pm, createGVNPass()); |
1288
e109e4031e8a
Fix build when USE_METADATA is off.
Matti Niemenmaa <matti.niemenmaa+hg@iki.fi>
parents:
1287
diff
changeset
|
151 |
1506
76936858d1c6
Return `void*` from _d_allocclass so LLVM doesn't do weird things with it...
Frits van Bommel <fvbommel wxs.nl>
parents:
1492
diff
changeset
|
152 // Inline again, to catch things like now nonvirtual |
76936858d1c6
Return `void*` from _d_allocclass so LLVM doesn't do weird things with it...
Frits van Bommel <fvbommel wxs.nl>
parents:
1492
diff
changeset
|
153 // function calls, foreach delegates passed to inlined |
76936858d1c6
Return `void*` from _d_allocclass so LLVM doesn't do weird things with it...
Frits van Bommel <fvbommel wxs.nl>
parents:
1492
diff
changeset
|
154 // opApply's, etc. where the actual function being called |
76936858d1c6
Return `void*` from _d_allocclass so LLVM doesn't do weird things with it...
Frits van Bommel <fvbommel wxs.nl>
parents:
1492
diff
changeset
|
155 // wasn't known during the first inliner pass. |
1296
79b201533cf8
Add -verify-each option to ease debugging
Frits van Bommel <fvbommel wxs.nl>
parents:
1294
diff
changeset
|
156 addPass(pm, createFunctionInliningPass()); |
1219
a0844cc67840
Tweak some optimizations.
Frits van Bommel <fvbommel wxs.nl>
parents:
1175
diff
changeset
|
157 } |
125 | 158 } |
159 | |
1507
f86fd3b77285
Eliminate comparisons between GC allocations and constants. This removes some
Frits van Bommel <fvbommel wxs.nl>
parents:
1506
diff
changeset
|
160 if (optimizeLevel >= 2) { |
f86fd3b77285
Eliminate comparisons between GC allocations and constants. This removes some
Frits van Bommel <fvbommel wxs.nl>
parents:
1506
diff
changeset
|
161 if (!disableLangSpecificPasses) { |
f86fd3b77285
Eliminate comparisons between GC allocations and constants. This removes some
Frits van Bommel <fvbommel wxs.nl>
parents:
1506
diff
changeset
|
162 if (!disableSimplifyRuntimeCalls) |
f86fd3b77285
Eliminate comparisons between GC allocations and constants. This removes some
Frits van Bommel <fvbommel wxs.nl>
parents:
1506
diff
changeset
|
163 addPass(pm, createSimplifyDRuntimeCalls()); |
f86fd3b77285
Eliminate comparisons between GC allocations and constants. This removes some
Frits van Bommel <fvbommel wxs.nl>
parents:
1506
diff
changeset
|
164 |
1288
e109e4031e8a
Fix build when USE_METADATA is off.
Matti Niemenmaa <matti.niemenmaa+hg@iki.fi>
parents:
1287
diff
changeset
|
165 #ifdef USE_METADATA |
1507
f86fd3b77285
Eliminate comparisons between GC allocations and constants. This removes some
Frits van Bommel <fvbommel wxs.nl>
parents:
1506
diff
changeset
|
166 if (!disableGCToStack) |
f86fd3b77285
Eliminate comparisons between GC allocations and constants. This removes some
Frits van Bommel <fvbommel wxs.nl>
parents:
1506
diff
changeset
|
167 addPass(pm, createGarbageCollect2Stack()); |
f86fd3b77285
Eliminate comparisons between GC allocations and constants. This removes some
Frits van Bommel <fvbommel wxs.nl>
parents:
1506
diff
changeset
|
168 #endif |
1285
91d9386d4a5a
Implement another D-specific pass: -dgc2stack
Frits van Bommel <fvbommel wxs.nl>
parents:
1281
diff
changeset
|
169 } |
1507
f86fd3b77285
Eliminate comparisons between GC allocations and constants. This removes some
Frits van Bommel <fvbommel wxs.nl>
parents:
1506
diff
changeset
|
170 // Run some clean-up passes |
f86fd3b77285
Eliminate comparisons between GC allocations and constants. This removes some
Frits van Bommel <fvbommel wxs.nl>
parents:
1506
diff
changeset
|
171 addPass(pm, createInstructionCombiningPass()); |
f86fd3b77285
Eliminate comparisons between GC allocations and constants. This removes some
Frits van Bommel <fvbommel wxs.nl>
parents:
1506
diff
changeset
|
172 addPass(pm, createScalarReplAggregatesPass()); |
f86fd3b77285
Eliminate comparisons between GC allocations and constants. This removes some
Frits van Bommel <fvbommel wxs.nl>
parents:
1506
diff
changeset
|
173 addPass(pm, createCFGSimplificationPass()); |
f86fd3b77285
Eliminate comparisons between GC allocations and constants. This removes some
Frits van Bommel <fvbommel wxs.nl>
parents:
1506
diff
changeset
|
174 addPass(pm, createInstructionCombiningPass()); |
1275
bedf0bfb8fdb
Implement first D-specific optimization pass: -simplify-drtcalls.
Frits van Bommel <fvbommel wxs.nl>
parents:
1268
diff
changeset
|
175 } |
1507
f86fd3b77285
Eliminate comparisons between GC allocations and constants. This removes some
Frits van Bommel <fvbommel wxs.nl>
parents:
1506
diff
changeset
|
176 |
131 | 177 // -O3 |
1170
e40c65bd8c5d
Allow specific optimization passes to be requested from the command line.
Frits van Bommel <fvbommel wxs.nl>
parents:
663
diff
changeset
|
178 if (optimizeLevel >= 3) |
125 | 179 { |
1296
79b201533cf8
Add -verify-each option to ease debugging
Frits van Bommel <fvbommel wxs.nl>
parents:
1294
diff
changeset
|
180 addPass(pm, createArgumentPromotionPass()); |
79b201533cf8
Add -verify-each option to ease debugging
Frits van Bommel <fvbommel wxs.nl>
parents:
1294
diff
changeset
|
181 addPass(pm, createTailDuplicationPass()); |
1492
ef76f6e1693c
Add some passes that `opt` runs to the default pass list.
Frits van Bommel <fvbommel wxs.nl>
parents:
1486
diff
changeset
|
182 addPass(pm, createSimplifyLibCallsPass()); |
1296
79b201533cf8
Add -verify-each option to ease debugging
Frits van Bommel <fvbommel wxs.nl>
parents:
1294
diff
changeset
|
183 addPass(pm, createInstructionCombiningPass()); |
1492
ef76f6e1693c
Add some passes that `opt` runs to the default pass list.
Frits van Bommel <fvbommel wxs.nl>
parents:
1486
diff
changeset
|
184 addPass(pm, createJumpThreadingPass()); |
1296
79b201533cf8
Add -verify-each option to ease debugging
Frits van Bommel <fvbommel wxs.nl>
parents:
1294
diff
changeset
|
185 addPass(pm, createCFGSimplificationPass()); |
79b201533cf8
Add -verify-each option to ease debugging
Frits van Bommel <fvbommel wxs.nl>
parents:
1294
diff
changeset
|
186 addPass(pm, createScalarReplAggregatesPass()); |
79b201533cf8
Add -verify-each option to ease debugging
Frits van Bommel <fvbommel wxs.nl>
parents:
1294
diff
changeset
|
187 addPass(pm, createInstructionCombiningPass()); |
79b201533cf8
Add -verify-each option to ease debugging
Frits van Bommel <fvbommel wxs.nl>
parents:
1294
diff
changeset
|
188 addPass(pm, createCondPropagationPass()); |
125 | 189 |
1296
79b201533cf8
Add -verify-each option to ease debugging
Frits van Bommel <fvbommel wxs.nl>
parents:
1294
diff
changeset
|
190 addPass(pm, createReassociatePass()); |
79b201533cf8
Add -verify-each option to ease debugging
Frits van Bommel <fvbommel wxs.nl>
parents:
1294
diff
changeset
|
191 addPass(pm, createLoopRotatePass()); |
79b201533cf8
Add -verify-each option to ease debugging
Frits van Bommel <fvbommel wxs.nl>
parents:
1294
diff
changeset
|
192 addPass(pm, createLICMPass()); |
79b201533cf8
Add -verify-each option to ease debugging
Frits van Bommel <fvbommel wxs.nl>
parents:
1294
diff
changeset
|
193 addPass(pm, createLoopUnswitchPass()); |
1492
ef76f6e1693c
Add some passes that `opt` runs to the default pass list.
Frits van Bommel <fvbommel wxs.nl>
parents:
1486
diff
changeset
|
194 addPass(pm, createLoopIndexSplitPass()); |
1296
79b201533cf8
Add -verify-each option to ease debugging
Frits van Bommel <fvbommel wxs.nl>
parents:
1294
diff
changeset
|
195 addPass(pm, createInstructionCombiningPass()); |
79b201533cf8
Add -verify-each option to ease debugging
Frits van Bommel <fvbommel wxs.nl>
parents:
1294
diff
changeset
|
196 addPass(pm, createIndVarSimplifyPass()); |
1492
ef76f6e1693c
Add some passes that `opt` runs to the default pass list.
Frits van Bommel <fvbommel wxs.nl>
parents:
1486
diff
changeset
|
197 addPass(pm, createLoopDeletionPass()); |
1296
79b201533cf8
Add -verify-each option to ease debugging
Frits van Bommel <fvbommel wxs.nl>
parents:
1294
diff
changeset
|
198 addPass(pm, createLoopUnrollPass()); |
79b201533cf8
Add -verify-each option to ease debugging
Frits van Bommel <fvbommel wxs.nl>
parents:
1294
diff
changeset
|
199 addPass(pm, createInstructionCombiningPass()); |
79b201533cf8
Add -verify-each option to ease debugging
Frits van Bommel <fvbommel wxs.nl>
parents:
1294
diff
changeset
|
200 addPass(pm, createGVNPass()); |
1481
e0f03e11cdf8
Add `-memcpyopt` to the optimization pass list.
Frits van Bommel <fvbommel wxs.nl>
parents:
1472
diff
changeset
|
201 addPass(pm, createMemCpyOptPass()); |
1296
79b201533cf8
Add -verify-each option to ease debugging
Frits van Bommel <fvbommel wxs.nl>
parents:
1294
diff
changeset
|
202 addPass(pm, createSCCPPass()); |
125 | 203 |
1296
79b201533cf8
Add -verify-each option to ease debugging
Frits van Bommel <fvbommel wxs.nl>
parents:
1294
diff
changeset
|
204 addPass(pm, createInstructionCombiningPass()); |
79b201533cf8
Add -verify-each option to ease debugging
Frits van Bommel <fvbommel wxs.nl>
parents:
1294
diff
changeset
|
205 addPass(pm, createCondPropagationPass()); |
125 | 206 |
1296
79b201533cf8
Add -verify-each option to ease debugging
Frits van Bommel <fvbommel wxs.nl>
parents:
1294
diff
changeset
|
207 addPass(pm, createDeadStoreEliminationPass()); |
79b201533cf8
Add -verify-each option to ease debugging
Frits van Bommel <fvbommel wxs.nl>
parents:
1294
diff
changeset
|
208 addPass(pm, createAggressiveDCEPass()); |
79b201533cf8
Add -verify-each option to ease debugging
Frits van Bommel <fvbommel wxs.nl>
parents:
1294
diff
changeset
|
209 addPass(pm, createCFGSimplificationPass()); |
79b201533cf8
Add -verify-each option to ease debugging
Frits van Bommel <fvbommel wxs.nl>
parents:
1294
diff
changeset
|
210 addPass(pm, createDeadTypeEliminationPass()); |
79b201533cf8
Add -verify-each option to ease debugging
Frits van Bommel <fvbommel wxs.nl>
parents:
1294
diff
changeset
|
211 addPass(pm, createConstantMergePass()); |
125 | 212 } |
213 | |
1482
d9c5f5a43403
Run `semantic3` on imported modules, and emit new symbols with
Frits van Bommel <fvbommel wxs.nl>
parents:
1481
diff
changeset
|
214 if (optimizeLevel >= 1) { |
1483
defafbabbe32
Add a pass to strip the bodies of `available_externally` functions so string
Frits van Bommel <fvbommel wxs.nl>
parents:
1482
diff
changeset
|
215 #if LLVM_REV >= 68940 |
defafbabbe32
Add a pass to strip the bodies of `available_externally` functions so string
Frits van Bommel <fvbommel wxs.nl>
parents:
1482
diff
changeset
|
216 addPass(pm, createStripExternalsPass()); |
defafbabbe32
Add a pass to strip the bodies of `available_externally` functions so string
Frits van Bommel <fvbommel wxs.nl>
parents:
1482
diff
changeset
|
217 #endif |
1482
d9c5f5a43403
Run `semantic3` on imported modules, and emit new symbols with
Frits van Bommel <fvbommel wxs.nl>
parents:
1481
diff
changeset
|
218 addPass(pm, createGlobalDCEPass()); |
d9c5f5a43403
Run `semantic3` on imported modules, and emit new symbols with
Frits van Bommel <fvbommel wxs.nl>
parents:
1481
diff
changeset
|
219 } |
d9c5f5a43403
Run `semantic3` on imported modules, and emit new symbols with
Frits van Bommel <fvbommel wxs.nl>
parents:
1481
diff
changeset
|
220 |
131 | 221 // level -O4 and -O5 are linktime optimizations |
1170
e40c65bd8c5d
Allow specific optimization passes to be requested from the command line.
Frits van Bommel <fvbommel wxs.nl>
parents:
663
diff
changeset
|
222 } |
e40c65bd8c5d
Allow specific optimization passes to be requested from the command line.
Frits van Bommel <fvbommel wxs.nl>
parents:
663
diff
changeset
|
223 |
e40c65bd8c5d
Allow specific optimization passes to be requested from the command line.
Frits van Bommel <fvbommel wxs.nl>
parents:
663
diff
changeset
|
224 ////////////////////////////////////////////////////////////////////////////////////////// |
e40c65bd8c5d
Allow specific optimization passes to be requested from the command line.
Frits van Bommel <fvbommel wxs.nl>
parents:
663
diff
changeset
|
225 // This function runs optimization passes based on command line arguments. |
e40c65bd8c5d
Allow specific optimization passes to be requested from the command line.
Frits van Bommel <fvbommel wxs.nl>
parents:
663
diff
changeset
|
226 // Returns true if any optimization passes were invoked. |
e40c65bd8c5d
Allow specific optimization passes to be requested from the command line.
Frits van Bommel <fvbommel wxs.nl>
parents:
663
diff
changeset
|
227 bool ldc_optimize_module(llvm::Module* m) |
e40c65bd8c5d
Allow specific optimization passes to be requested from the command line.
Frits van Bommel <fvbommel wxs.nl>
parents:
663
diff
changeset
|
228 { |
1287
6c8af78364f5
There's an issue with LLVM metadata support; it triggers an assert when trying
Frits van Bommel <fvbommel wxs.nl>
parents:
1285
diff
changeset
|
229 if (!optimize()) { |
6c8af78364f5
There's an issue with LLVM metadata support; it triggers an assert when trying
Frits van Bommel <fvbommel wxs.nl>
parents:
1285
diff
changeset
|
230 #ifdef USE_METADATA |
6c8af78364f5
There's an issue with LLVM metadata support; it triggers an assert when trying
Frits van Bommel <fvbommel wxs.nl>
parents:
1285
diff
changeset
|
231 if (!disableStripMetaData) { |
6c8af78364f5
There's an issue with LLVM metadata support; it triggers an assert when trying
Frits van Bommel <fvbommel wxs.nl>
parents:
1285
diff
changeset
|
232 // This one always needs to run if metadata is generated, because |
6c8af78364f5
There's an issue with LLVM metadata support; it triggers an assert when trying
Frits van Bommel <fvbommel wxs.nl>
parents:
1285
diff
changeset
|
233 // the code generator will assert if it's not used. |
6c8af78364f5
There's an issue with LLVM metadata support; it triggers an assert when trying
Frits van Bommel <fvbommel wxs.nl>
parents:
1285
diff
changeset
|
234 ModulePass* stripMD = createStripMetaData(); |
6c8af78364f5
There's an issue with LLVM metadata support; it triggers an assert when trying
Frits van Bommel <fvbommel wxs.nl>
parents:
1285
diff
changeset
|
235 stripMD->runOnModule(*m); |
6c8af78364f5
There's an issue with LLVM metadata support; it triggers an assert when trying
Frits van Bommel <fvbommel wxs.nl>
parents:
1285
diff
changeset
|
236 delete stripMD; |
6c8af78364f5
There's an issue with LLVM metadata support; it triggers an assert when trying
Frits van Bommel <fvbommel wxs.nl>
parents:
1285
diff
changeset
|
237 } |
6c8af78364f5
There's an issue with LLVM metadata support; it triggers an assert when trying
Frits van Bommel <fvbommel wxs.nl>
parents:
1285
diff
changeset
|
238 #endif |
1170
e40c65bd8c5d
Allow specific optimization passes to be requested from the command line.
Frits van Bommel <fvbommel wxs.nl>
parents:
663
diff
changeset
|
239 return false; |
1287
6c8af78364f5
There's an issue with LLVM metadata support; it triggers an assert when trying
Frits van Bommel <fvbommel wxs.nl>
parents:
1285
diff
changeset
|
240 } |
1170
e40c65bd8c5d
Allow specific optimization passes to be requested from the command line.
Frits van Bommel <fvbommel wxs.nl>
parents:
663
diff
changeset
|
241 |
e40c65bd8c5d
Allow specific optimization passes to be requested from the command line.
Frits van Bommel <fvbommel wxs.nl>
parents:
663
diff
changeset
|
242 PassManager pm; |
1296
79b201533cf8
Add -verify-each option to ease debugging
Frits van Bommel <fvbommel wxs.nl>
parents:
1294
diff
changeset
|
243 |
79b201533cf8
Add -verify-each option to ease debugging
Frits van Bommel <fvbommel wxs.nl>
parents:
1294
diff
changeset
|
244 if (verifyEach) pm.add(createVerifierPass()); |
79b201533cf8
Add -verify-each option to ease debugging
Frits van Bommel <fvbommel wxs.nl>
parents:
1294
diff
changeset
|
245 |
79b201533cf8
Add -verify-each option to ease debugging
Frits van Bommel <fvbommel wxs.nl>
parents:
1294
diff
changeset
|
246 addPass(pm, new TargetData(m)); |
1170
e40c65bd8c5d
Allow specific optimization passes to be requested from the command line.
Frits van Bommel <fvbommel wxs.nl>
parents:
663
diff
changeset
|
247 |
1175
cc1efa23030a
Enable inlining by default for -O3+.
Frits van Bommel <fvbommel wxs.nl>
parents:
1172
diff
changeset
|
248 bool optimize = optimizeLevel != 0 || doInline(); |
1170
e40c65bd8c5d
Allow specific optimization passes to be requested from the command line.
Frits van Bommel <fvbommel wxs.nl>
parents:
663
diff
changeset
|
249 |
1171
461a85f0db31
Change meaning of optimization levels: -O0 now means 'no optimization' like with
Frits van Bommel <fvbommel wxs.nl>
parents:
1170
diff
changeset
|
250 unsigned optPos = optimizeLevel != 0 |
1170
e40c65bd8c5d
Allow specific optimization passes to be requested from the command line.
Frits van Bommel <fvbommel wxs.nl>
parents:
663
diff
changeset
|
251 ? optimizeLevel.getPosition() |
e40c65bd8c5d
Allow specific optimization passes to be requested from the command line.
Frits van Bommel <fvbommel wxs.nl>
parents:
663
diff
changeset
|
252 : enableInlining.getPosition(); |
e40c65bd8c5d
Allow specific optimization passes to be requested from the command line.
Frits van Bommel <fvbommel wxs.nl>
parents:
663
diff
changeset
|
253 |
e40c65bd8c5d
Allow specific optimization passes to be requested from the command line.
Frits van Bommel <fvbommel wxs.nl>
parents:
663
diff
changeset
|
254 for (size_t i = 0; i < passList.size(); i++) { |
e40c65bd8c5d
Allow specific optimization passes to be requested from the command line.
Frits van Bommel <fvbommel wxs.nl>
parents:
663
diff
changeset
|
255 // insert -O<N> / -enable-inlining in right position |
e40c65bd8c5d
Allow specific optimization passes to be requested from the command line.
Frits van Bommel <fvbommel wxs.nl>
parents:
663
diff
changeset
|
256 if (optimize && optPos < passList.getPosition(i)) { |
e40c65bd8c5d
Allow specific optimization passes to be requested from the command line.
Frits van Bommel <fvbommel wxs.nl>
parents:
663
diff
changeset
|
257 addPassesForOptLevel(pm); |
e40c65bd8c5d
Allow specific optimization passes to be requested from the command line.
Frits van Bommel <fvbommel wxs.nl>
parents:
663
diff
changeset
|
258 optimize = false; |
e40c65bd8c5d
Allow specific optimization passes to be requested from the command line.
Frits van Bommel <fvbommel wxs.nl>
parents:
663
diff
changeset
|
259 } |
e40c65bd8c5d
Allow specific optimization passes to be requested from the command line.
Frits van Bommel <fvbommel wxs.nl>
parents:
663
diff
changeset
|
260 |
e40c65bd8c5d
Allow specific optimization passes to be requested from the command line.
Frits van Bommel <fvbommel wxs.nl>
parents:
663
diff
changeset
|
261 const PassInfo* pass = passList[i]; |
e40c65bd8c5d
Allow specific optimization passes to be requested from the command line.
Frits van Bommel <fvbommel wxs.nl>
parents:
663
diff
changeset
|
262 if (PassInfo::NormalCtor_t ctor = pass->getNormalCtor()) { |
1296
79b201533cf8
Add -verify-each option to ease debugging
Frits van Bommel <fvbommel wxs.nl>
parents:
1294
diff
changeset
|
263 addPass(pm, ctor()); |
1170
e40c65bd8c5d
Allow specific optimization passes to be requested from the command line.
Frits van Bommel <fvbommel wxs.nl>
parents:
663
diff
changeset
|
264 } else { |
e40c65bd8c5d
Allow specific optimization passes to be requested from the command line.
Frits van Bommel <fvbommel wxs.nl>
parents:
663
diff
changeset
|
265 const char* arg = pass->getPassArgument(); // may return null |
e40c65bd8c5d
Allow specific optimization passes to be requested from the command line.
Frits van Bommel <fvbommel wxs.nl>
parents:
663
diff
changeset
|
266 if (arg) |
e40c65bd8c5d
Allow specific optimization passes to be requested from the command line.
Frits van Bommel <fvbommel wxs.nl>
parents:
663
diff
changeset
|
267 error("Can't create pass '-%s' (%s)", arg, pass->getPassName()); |
e40c65bd8c5d
Allow specific optimization passes to be requested from the command line.
Frits van Bommel <fvbommel wxs.nl>
parents:
663
diff
changeset
|
268 else |
e40c65bd8c5d
Allow specific optimization passes to be requested from the command line.
Frits van Bommel <fvbommel wxs.nl>
parents:
663
diff
changeset
|
269 error("Can't create pass (%s)", pass->getPassName()); |
1172
b3887714b735
Small cleanup: remove mars.h #include
Frits van Bommel <fvbommel wxs.nl>
parents:
1171
diff
changeset
|
270 assert(0); // Should be unreachable; root.h:error() calls exit() |
1170
e40c65bd8c5d
Allow specific optimization passes to be requested from the command line.
Frits van Bommel <fvbommel wxs.nl>
parents:
663
diff
changeset
|
271 } |
e40c65bd8c5d
Allow specific optimization passes to be requested from the command line.
Frits van Bommel <fvbommel wxs.nl>
parents:
663
diff
changeset
|
272 } |
e40c65bd8c5d
Allow specific optimization passes to be requested from the command line.
Frits van Bommel <fvbommel wxs.nl>
parents:
663
diff
changeset
|
273 // insert -O<N> / -enable-inlining if specified at the end, |
e40c65bd8c5d
Allow specific optimization passes to be requested from the command line.
Frits van Bommel <fvbommel wxs.nl>
parents:
663
diff
changeset
|
274 if (optimize) |
e40c65bd8c5d
Allow specific optimization passes to be requested from the command line.
Frits van Bommel <fvbommel wxs.nl>
parents:
663
diff
changeset
|
275 addPassesForOptLevel(pm); |
125 | 276 |
1294
dd84ec4353ce
Strip metadata even when addPassesForOptLevel() isn't called, for instance when
Frits van Bommel <fvbommel wxs.nl>
parents:
1288
diff
changeset
|
277 #ifdef USE_METADATA |
dd84ec4353ce
Strip metadata even when addPassesForOptLevel() isn't called, for instance when
Frits van Bommel <fvbommel wxs.nl>
parents:
1288
diff
changeset
|
278 if (!disableStripMetaData) { |
dd84ec4353ce
Strip metadata even when addPassesForOptLevel() isn't called, for instance when
Frits van Bommel <fvbommel wxs.nl>
parents:
1288
diff
changeset
|
279 // This one is purposely not disabled by disableLangSpecificPasses |
dd84ec4353ce
Strip metadata even when addPassesForOptLevel() isn't called, for instance when
Frits van Bommel <fvbommel wxs.nl>
parents:
1288
diff
changeset
|
280 // because the code generator will assert if it's not used. |
1296
79b201533cf8
Add -verify-each option to ease debugging
Frits van Bommel <fvbommel wxs.nl>
parents:
1294
diff
changeset
|
281 addPass(pm, createStripMetaData()); |
1294
dd84ec4353ce
Strip metadata even when addPassesForOptLevel() isn't called, for instance when
Frits van Bommel <fvbommel wxs.nl>
parents:
1288
diff
changeset
|
282 } |
dd84ec4353ce
Strip metadata even when addPassesForOptLevel() isn't called, for instance when
Frits van Bommel <fvbommel wxs.nl>
parents:
1288
diff
changeset
|
283 #endif |
dd84ec4353ce
Strip metadata even when addPassesForOptLevel() isn't called, for instance when
Frits van Bommel <fvbommel wxs.nl>
parents:
1288
diff
changeset
|
284 |
131 | 285 pm.run(*m); |
1170
e40c65bd8c5d
Allow specific optimization passes to be requested from the command line.
Frits van Bommel <fvbommel wxs.nl>
parents:
663
diff
changeset
|
286 return true; |
125 | 287 } |