Mercurial > projects > ldc
annotate gen/optimizer.cpp @ 1492:ef76f6e1693c
Add some passes that `opt` runs to the default pass list.
author | Frits van Bommel <fvbommel wxs.nl> |
---|---|
date | Thu, 11 Jun 2009 16:57:45 +0200 |
parents | 9ed0695cb93c |
children | 76936858d1c6 |
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()); |
125 | 138 } |
139 | |
131 | 140 // -inline |
1175
cc1efa23030a
Enable inlining by default for -O3+.
Frits van Bommel <fvbommel wxs.nl>
parents:
1172
diff
changeset
|
141 if (doInline()) { |
1296
79b201533cf8
Add -verify-each option to ease debugging
Frits van Bommel <fvbommel wxs.nl>
parents:
1294
diff
changeset
|
142 addPass(pm, createFunctionInliningPass()); |
1288
e109e4031e8a
Fix build when USE_METADATA is off.
Matti Niemenmaa <matti.niemenmaa+hg@iki.fi>
parents:
1287
diff
changeset
|
143 |
1219
a0844cc67840
Tweak some optimizations.
Frits van Bommel <fvbommel wxs.nl>
parents:
1175
diff
changeset
|
144 if (optimizeLevel >= 2) { |
a0844cc67840
Tweak some optimizations.
Frits van Bommel <fvbommel wxs.nl>
parents:
1175
diff
changeset
|
145 // 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
|
146 addPass(pm, createScalarReplAggregatesPass()); |
79b201533cf8
Add -verify-each option to ease debugging
Frits van Bommel <fvbommel wxs.nl>
parents:
1294
diff
changeset
|
147 addPass(pm, createInstructionCombiningPass()); |
1288
e109e4031e8a
Fix build when USE_METADATA is off.
Matti Niemenmaa <matti.niemenmaa+hg@iki.fi>
parents:
1287
diff
changeset
|
148 |
1219
a0844cc67840
Tweak some optimizations.
Frits van Bommel <fvbommel wxs.nl>
parents:
1175
diff
changeset
|
149 // Inline again, to catch things like foreach delegates |
1220 | 150 // passed to inlined opApply's where the function wasn't |
1219
a0844cc67840
Tweak some optimizations.
Frits van Bommel <fvbommel wxs.nl>
parents:
1175
diff
changeset
|
151 // 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
|
152 addPass(pm, createFunctionInliningPass()); |
1288
e109e4031e8a
Fix build when USE_METADATA is off.
Matti Niemenmaa <matti.niemenmaa+hg@iki.fi>
parents:
1287
diff
changeset
|
153 |
1219
a0844cc67840
Tweak some optimizations.
Frits van Bommel <fvbommel wxs.nl>
parents:
1175
diff
changeset
|
154 // Run clean-up again. |
1296
79b201533cf8
Add -verify-each option to ease debugging
Frits van Bommel <fvbommel wxs.nl>
parents:
1294
diff
changeset
|
155 addPass(pm, createScalarReplAggregatesPass()); |
79b201533cf8
Add -verify-each option to ease debugging
Frits van Bommel <fvbommel wxs.nl>
parents:
1294
diff
changeset
|
156 addPass(pm, createInstructionCombiningPass()); |
1219
a0844cc67840
Tweak some optimizations.
Frits van Bommel <fvbommel wxs.nl>
parents:
1175
diff
changeset
|
157 } |
125 | 158 } |
159 | |
1285
91d9386d4a5a
Implement another D-specific pass: -dgc2stack
Frits van Bommel <fvbommel wxs.nl>
parents:
1281
diff
changeset
|
160 if (optimizeLevel >= 2 && !disableLangSpecificPasses) { |
91d9386d4a5a
Implement another D-specific pass: -dgc2stack
Frits van Bommel <fvbommel wxs.nl>
parents:
1281
diff
changeset
|
161 if (!disableSimplifyRuntimeCalls) |
1296
79b201533cf8
Add -verify-each option to ease debugging
Frits van Bommel <fvbommel wxs.nl>
parents:
1294
diff
changeset
|
162 addPass(pm, createSimplifyDRuntimeCalls()); |
1288
e109e4031e8a
Fix build when USE_METADATA is off.
Matti Niemenmaa <matti.niemenmaa+hg@iki.fi>
parents:
1287
diff
changeset
|
163 |
e109e4031e8a
Fix build when USE_METADATA is off.
Matti Niemenmaa <matti.niemenmaa+hg@iki.fi>
parents:
1287
diff
changeset
|
164 #ifdef USE_METADATA |
1285
91d9386d4a5a
Implement another D-specific pass: -dgc2stack
Frits van Bommel <fvbommel wxs.nl>
parents:
1281
diff
changeset
|
165 if (!disableGCToStack) { |
1486
9ed0695cb93c
Teach `-dgc2stack` to promote GC allocations in simple loops to stack
Frits van Bommel <fvbommel wxs.nl>
parents:
1483
diff
changeset
|
166 addPass(pm, createGarbageCollect2Stack()); |
9ed0695cb93c
Teach `-dgc2stack` to promote GC allocations in simple loops to stack
Frits van Bommel <fvbommel wxs.nl>
parents:
1483
diff
changeset
|
167 // Run some clean-up |
9ed0695cb93c
Teach `-dgc2stack` to promote GC allocations in simple loops to stack
Frits van Bommel <fvbommel wxs.nl>
parents:
1483
diff
changeset
|
168 addPass(pm, createInstructionCombiningPass()); |
1296
79b201533cf8
Add -verify-each option to ease debugging
Frits van Bommel <fvbommel wxs.nl>
parents:
1294
diff
changeset
|
169 addPass(pm, createScalarReplAggregatesPass()); |
79b201533cf8
Add -verify-each option to ease debugging
Frits van Bommel <fvbommel wxs.nl>
parents:
1294
diff
changeset
|
170 addPass(pm, createCFGSimplificationPass()); |
1285
91d9386d4a5a
Implement another D-specific pass: -dgc2stack
Frits van Bommel <fvbommel wxs.nl>
parents:
1281
diff
changeset
|
171 } |
1288
e109e4031e8a
Fix build when USE_METADATA is off.
Matti Niemenmaa <matti.niemenmaa+hg@iki.fi>
parents:
1287
diff
changeset
|
172 #endif |
1275
bedf0bfb8fdb
Implement first D-specific optimization pass: -simplify-drtcalls.
Frits van Bommel <fvbommel wxs.nl>
parents:
1268
diff
changeset
|
173 } |
bedf0bfb8fdb
Implement first D-specific optimization pass: -simplify-drtcalls.
Frits van Bommel <fvbommel wxs.nl>
parents:
1268
diff
changeset
|
174 |
131 | 175 // -O3 |
1170
e40c65bd8c5d
Allow specific optimization passes to be requested from the command line.
Frits van Bommel <fvbommel wxs.nl>
parents:
663
diff
changeset
|
176 if (optimizeLevel >= 3) |
125 | 177 { |
1296
79b201533cf8
Add -verify-each option to ease debugging
Frits van Bommel <fvbommel wxs.nl>
parents:
1294
diff
changeset
|
178 addPass(pm, createArgumentPromotionPass()); |
79b201533cf8
Add -verify-each option to ease debugging
Frits van Bommel <fvbommel wxs.nl>
parents:
1294
diff
changeset
|
179 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
|
180 addPass(pm, createSimplifyLibCallsPass()); |
1296
79b201533cf8
Add -verify-each option to ease debugging
Frits van Bommel <fvbommel wxs.nl>
parents:
1294
diff
changeset
|
181 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
|
182 addPass(pm, createJumpThreadingPass()); |
1296
79b201533cf8
Add -verify-each option to ease debugging
Frits van Bommel <fvbommel wxs.nl>
parents:
1294
diff
changeset
|
183 addPass(pm, createCFGSimplificationPass()); |
79b201533cf8
Add -verify-each option to ease debugging
Frits van Bommel <fvbommel wxs.nl>
parents:
1294
diff
changeset
|
184 addPass(pm, createScalarReplAggregatesPass()); |
79b201533cf8
Add -verify-each option to ease debugging
Frits van Bommel <fvbommel wxs.nl>
parents:
1294
diff
changeset
|
185 addPass(pm, createInstructionCombiningPass()); |
79b201533cf8
Add -verify-each option to ease debugging
Frits van Bommel <fvbommel wxs.nl>
parents:
1294
diff
changeset
|
186 addPass(pm, createCondPropagationPass()); |
125 | 187 |
1296
79b201533cf8
Add -verify-each option to ease debugging
Frits van Bommel <fvbommel wxs.nl>
parents:
1294
diff
changeset
|
188 addPass(pm, createReassociatePass()); |
79b201533cf8
Add -verify-each option to ease debugging
Frits van Bommel <fvbommel wxs.nl>
parents:
1294
diff
changeset
|
189 addPass(pm, createLoopRotatePass()); |
79b201533cf8
Add -verify-each option to ease debugging
Frits van Bommel <fvbommel wxs.nl>
parents:
1294
diff
changeset
|
190 addPass(pm, createLICMPass()); |
79b201533cf8
Add -verify-each option to ease debugging
Frits van Bommel <fvbommel wxs.nl>
parents:
1294
diff
changeset
|
191 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
|
192 addPass(pm, createLoopIndexSplitPass()); |
1296
79b201533cf8
Add -verify-each option to ease debugging
Frits van Bommel <fvbommel wxs.nl>
parents:
1294
diff
changeset
|
193 addPass(pm, createInstructionCombiningPass()); |
79b201533cf8
Add -verify-each option to ease debugging
Frits van Bommel <fvbommel wxs.nl>
parents:
1294
diff
changeset
|
194 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
|
195 addPass(pm, createLoopDeletionPass()); |
1296
79b201533cf8
Add -verify-each option to ease debugging
Frits van Bommel <fvbommel wxs.nl>
parents:
1294
diff
changeset
|
196 addPass(pm, createLoopUnrollPass()); |
79b201533cf8
Add -verify-each option to ease debugging
Frits van Bommel <fvbommel wxs.nl>
parents:
1294
diff
changeset
|
197 addPass(pm, createInstructionCombiningPass()); |
79b201533cf8
Add -verify-each option to ease debugging
Frits van Bommel <fvbommel wxs.nl>
parents:
1294
diff
changeset
|
198 addPass(pm, createGVNPass()); |
1481
e0f03e11cdf8
Add `-memcpyopt` to the optimization pass list.
Frits van Bommel <fvbommel wxs.nl>
parents:
1472
diff
changeset
|
199 addPass(pm, createMemCpyOptPass()); |
1296
79b201533cf8
Add -verify-each option to ease debugging
Frits van Bommel <fvbommel wxs.nl>
parents:
1294
diff
changeset
|
200 addPass(pm, createSCCPPass()); |
125 | 201 |
1296
79b201533cf8
Add -verify-each option to ease debugging
Frits van Bommel <fvbommel wxs.nl>
parents:
1294
diff
changeset
|
202 addPass(pm, createInstructionCombiningPass()); |
79b201533cf8
Add -verify-each option to ease debugging
Frits van Bommel <fvbommel wxs.nl>
parents:
1294
diff
changeset
|
203 addPass(pm, createCondPropagationPass()); |
125 | 204 |
1296
79b201533cf8
Add -verify-each option to ease debugging
Frits van Bommel <fvbommel wxs.nl>
parents:
1294
diff
changeset
|
205 addPass(pm, createDeadStoreEliminationPass()); |
79b201533cf8
Add -verify-each option to ease debugging
Frits van Bommel <fvbommel wxs.nl>
parents:
1294
diff
changeset
|
206 addPass(pm, createAggressiveDCEPass()); |
79b201533cf8
Add -verify-each option to ease debugging
Frits van Bommel <fvbommel wxs.nl>
parents:
1294
diff
changeset
|
207 addPass(pm, createCFGSimplificationPass()); |
79b201533cf8
Add -verify-each option to ease debugging
Frits van Bommel <fvbommel wxs.nl>
parents:
1294
diff
changeset
|
208 addPass(pm, createDeadTypeEliminationPass()); |
79b201533cf8
Add -verify-each option to ease debugging
Frits van Bommel <fvbommel wxs.nl>
parents:
1294
diff
changeset
|
209 addPass(pm, createConstantMergePass()); |
125 | 210 } |
211 | |
1482
d9c5f5a43403
Run `semantic3` on imported modules, and emit new symbols with
Frits van Bommel <fvbommel wxs.nl>
parents:
1481
diff
changeset
|
212 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
|
213 #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
|
214 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
|
215 #endif |
1482
d9c5f5a43403
Run `semantic3` on imported modules, and emit new symbols with
Frits van Bommel <fvbommel wxs.nl>
parents:
1481
diff
changeset
|
216 addPass(pm, createGlobalDCEPass()); |
d9c5f5a43403
Run `semantic3` on imported modules, and emit new symbols with
Frits van Bommel <fvbommel wxs.nl>
parents:
1481
diff
changeset
|
217 } |
d9c5f5a43403
Run `semantic3` on imported modules, and emit new symbols with
Frits van Bommel <fvbommel wxs.nl>
parents:
1481
diff
changeset
|
218 |
131 | 219 // 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
|
220 } |
e40c65bd8c5d
Allow specific optimization passes to be requested from the command line.
Frits van Bommel <fvbommel wxs.nl>
parents:
663
diff
changeset
|
221 |
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 // 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
|
224 // 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
|
225 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
|
226 { |
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
|
227 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
|
228 #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
|
229 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
|
230 // 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
|
231 // 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
|
232 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
|
233 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
|
234 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
|
235 } |
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 #endif |
1170
e40c65bd8c5d
Allow specific optimization passes to be requested from the command line.
Frits van Bommel <fvbommel wxs.nl>
parents:
663
diff
changeset
|
237 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
|
238 } |
1170
e40c65bd8c5d
Allow specific optimization passes to be requested from the command line.
Frits van Bommel <fvbommel wxs.nl>
parents:
663
diff
changeset
|
239 |
e40c65bd8c5d
Allow specific optimization passes to be requested from the command line.
Frits van Bommel <fvbommel wxs.nl>
parents:
663
diff
changeset
|
240 PassManager pm; |
1296
79b201533cf8
Add -verify-each option to ease debugging
Frits van Bommel <fvbommel wxs.nl>
parents:
1294
diff
changeset
|
241 |
79b201533cf8
Add -verify-each option to ease debugging
Frits van Bommel <fvbommel wxs.nl>
parents:
1294
diff
changeset
|
242 if (verifyEach) pm.add(createVerifierPass()); |
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 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
|
245 |
1175
cc1efa23030a
Enable inlining by default for -O3+.
Frits van Bommel <fvbommel wxs.nl>
parents:
1172
diff
changeset
|
246 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
|
247 |
1171
461a85f0db31
Change meaning of optimization levels: -O0 now means 'no optimization' like with
Frits van Bommel <fvbommel wxs.nl>
parents:
1170
diff
changeset
|
248 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
|
249 ? optimizeLevel.getPosition() |
e40c65bd8c5d
Allow specific optimization passes to be requested from the command line.
Frits van Bommel <fvbommel wxs.nl>
parents:
663
diff
changeset
|
250 : enableInlining.getPosition(); |
e40c65bd8c5d
Allow specific optimization passes to be requested from the command line.
Frits van Bommel <fvbommel wxs.nl>
parents:
663
diff
changeset
|
251 |
e40c65bd8c5d
Allow specific optimization passes to be requested from the command line.
Frits van Bommel <fvbommel wxs.nl>
parents:
663
diff
changeset
|
252 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
|
253 // 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
|
254 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
|
255 addPassesForOptLevel(pm); |
e40c65bd8c5d
Allow specific optimization passes to be requested from the command line.
Frits van Bommel <fvbommel wxs.nl>
parents:
663
diff
changeset
|
256 optimize = false; |
e40c65bd8c5d
Allow specific optimization passes to be requested from the command line.
Frits van Bommel <fvbommel wxs.nl>
parents:
663
diff
changeset
|
257 } |
e40c65bd8c5d
Allow specific optimization passes to be requested from the command line.
Frits van Bommel <fvbommel wxs.nl>
parents:
663
diff
changeset
|
258 |
e40c65bd8c5d
Allow specific optimization passes to be requested from the command line.
Frits van Bommel <fvbommel wxs.nl>
parents:
663
diff
changeset
|
259 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
|
260 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
|
261 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
|
262 } else { |
e40c65bd8c5d
Allow specific optimization passes to be requested from the command line.
Frits van Bommel <fvbommel wxs.nl>
parents:
663
diff
changeset
|
263 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
|
264 if (arg) |
e40c65bd8c5d
Allow specific optimization passes to be requested from the command line.
Frits van Bommel <fvbommel wxs.nl>
parents:
663
diff
changeset
|
265 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
|
266 else |
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)", pass->getPassName()); |
1172
b3887714b735
Small cleanup: remove mars.h #include
Frits van Bommel <fvbommel wxs.nl>
parents:
1171
diff
changeset
|
268 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
|
269 } |
e40c65bd8c5d
Allow specific optimization passes to be requested from the command line.
Frits van Bommel <fvbommel wxs.nl>
parents:
663
diff
changeset
|
270 } |
e40c65bd8c5d
Allow specific optimization passes to be requested from the command line.
Frits van Bommel <fvbommel wxs.nl>
parents:
663
diff
changeset
|
271 // 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
|
272 if (optimize) |
e40c65bd8c5d
Allow specific optimization passes to be requested from the command line.
Frits van Bommel <fvbommel wxs.nl>
parents:
663
diff
changeset
|
273 addPassesForOptLevel(pm); |
125 | 274 |
1294
dd84ec4353ce
Strip metadata even when addPassesForOptLevel() isn't called, for instance when
Frits van Bommel <fvbommel wxs.nl>
parents:
1288
diff
changeset
|
275 #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
|
276 if (!disableStripMetaData) { |
dd84ec4353ce
Strip metadata even when addPassesForOptLevel() isn't called, for instance when
Frits van Bommel <fvbommel wxs.nl>
parents:
1288
diff
changeset
|
277 // 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
|
278 // 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
|
279 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
|
280 } |
dd84ec4353ce
Strip metadata even when addPassesForOptLevel() isn't called, for instance when
Frits van Bommel <fvbommel wxs.nl>
parents:
1288
diff
changeset
|
281 #endif |
dd84ec4353ce
Strip metadata even when addPassesForOptLevel() isn't called, for instance when
Frits van Bommel <fvbommel wxs.nl>
parents:
1288
diff
changeset
|
282 |
131 | 283 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
|
284 return true; |
125 | 285 } |