comparison gen/optimizer.cpp @ 1171:461a85f0db31

Change meaning of optimization levels: -O0 now means 'no optimization' like with other compilers.
author Frits van Bommel <fvbommel wxs.nl>
date Sun, 29 Mar 2009 15:51:14 +0200
parents e40c65bd8c5d
children b3887714b735
comparison
equal deleted inserted replaced
1170:e40c65bd8c5d 1171:461a85f0db31
22 static cl::opt<char> optimizeLevel( 22 static cl::opt<char> optimizeLevel(
23 cl::desc("Setting the optimization level:"), 23 cl::desc("Setting the optimization level:"),
24 cl::ZeroOrMore, 24 cl::ZeroOrMore,
25 cl::values( 25 cl::values(
26 clEnumValN(2, "O", "Equivalent to -O2"), 26 clEnumValN(2, "O", "Equivalent to -O2"),
27 clEnumValN(0, "O0", "Trivial optimizations only"), 27 clEnumValN(0, "O0", "No optimizations (default)"),
28 clEnumValN(1, "O1", "Simple optimizations"), 28 clEnumValN(1, "O1", "Simple optimizations"),
29 clEnumValN(2, "O2", "Good optimizations"), 29 clEnumValN(2, "O2", "Good optimizations"),
30 clEnumValN(3, "O3", "Aggressive optimizations"), 30 clEnumValN(3, "O3", "Aggressive optimizations"),
31 clEnumValN(4, "O4", "Link-time optimization"), // not implemented? 31 clEnumValN(4, "O4", "Link-time optimization"), // not implemented?
32 clEnumValN(5, "O5", "Link-time optimization"), // not implemented? 32 clEnumValN(5, "O5", "Link-time optimization"), // not implemented?
33 clEnumValEnd), 33 clEnumValEnd),
34 cl::init(-1)); 34 cl::init(0));
35 35
36 static cl::opt<bool> enableInlining("enable-inlining", 36 static cl::opt<bool> enableInlining("enable-inlining",
37 cl::desc("Enable function inlining (in -O<N>, if given)"), 37 cl::desc("Enable function inlining (in -O<N>, if given)"),
38 cl::ZeroOrMore, 38 cl::ZeroOrMore,
39 cl::init(false)); 39 cl::init(false));
46 int optLevel() { 46 int optLevel() {
47 return optimizeLevel; 47 return optimizeLevel;
48 } 48 }
49 49
50 bool optimize() { 50 bool optimize() {
51 return (optimizeLevel != -1) || enableInlining || passList.empty(); 51 return optimizeLevel || enableInlining || passList.empty();
52 } 52 }
53 53
54 // this function inserts some or all of the std-compile-opts passes depending on the 54 // this function inserts some or all of the std-compile-opts passes depending on the
55 // optimization level given. 55 // optimization level given.
56 static void addPassesForOptLevel(PassManager& pm) { 56 static void addPassesForOptLevel(PassManager& pm) {
57 // -O0 57 // -O1
58 if (optimizeLevel >= 0) 58 if (optimizeLevel >= 1)
59 { 59 {
60 //pm.add(createStripDeadPrototypesPass()); 60 //pm.add(createStripDeadPrototypesPass());
61 pm.add(createGlobalDCEPass()); 61 pm.add(createGlobalDCEPass());
62 }
63
64 // -O1
65 if (optimizeLevel >= 1)
66 {
67 pm.add(createRaiseAllocationsPass()); 62 pm.add(createRaiseAllocationsPass());
68 pm.add(createCFGSimplificationPass()); 63 pm.add(createCFGSimplificationPass());
69 pm.add(createPromoteMemoryToRegisterPass()); 64 pm.add(createPromoteMemoryToRegisterPass());
70 pm.add(createGlobalOptimizerPass()); 65 pm.add(createGlobalOptimizerPass());
71 pm.add(createGlobalDCEPass()); 66 pm.add(createGlobalDCEPass());
127 ////////////////////////////////////////////////////////////////////////////////////////// 122 //////////////////////////////////////////////////////////////////////////////////////////
128 // This function runs optimization passes based on command line arguments. 123 // This function runs optimization passes based on command line arguments.
129 // Returns true if any optimization passes were invoked. 124 // Returns true if any optimization passes were invoked.
130 bool ldc_optimize_module(llvm::Module* m) 125 bool ldc_optimize_module(llvm::Module* m)
131 { 126 {
132 if (!enableInlining && optimizeLevel == -1 && passList.empty()) 127 if (!enableInlining && optimizeLevel == 0 && passList.empty())
133 return false; 128 return false;
134 129
135 PassManager pm; 130 PassManager pm;
136 pm.add(new TargetData(m)); 131 pm.add(new TargetData(m));
137 132
138 bool optimize = (optimizeLevel != -1) || enableInlining; 133 bool optimize = optimizeLevel != 0 || enableInlining;
139 134
140 unsigned optPos = optimizeLevel != -1 135 unsigned optPos = optimizeLevel != 0
141 ? optimizeLevel.getPosition() 136 ? optimizeLevel.getPosition()
142 : enableInlining.getPosition(); 137 : enableInlining.getPosition();
143 138
144 for (size_t i = 0; i < passList.size(); i++) { 139 for (size_t i = 0; i < passList.size(); i++) {
145 // insert -O<N> / -enable-inlining in right position 140 // insert -O<N> / -enable-inlining in right position