comparison gen/optimizer.cpp @ 1175:cc1efa23030a

Enable inlining by default for -O3+.
author Frits van Bommel <fvbommel wxs.nl>
date Sun, 29 Mar 2009 19:38:59 +0200
parents b3887714b735
children a0844cc67840
comparison
equal deleted inserted replaced
1173:b0f9652f31de 1175:cc1efa23030a
1 #include "gen/optimizer.h" 1 #include "gen/optimizer.h"
2 #include "gen/cl_helpers.h"
2 3
3 #include "llvm/PassManager.h" 4 #include "llvm/PassManager.h"
4 #include "llvm/LinkAllPasses.h" 5 #include "llvm/LinkAllPasses.h"
5 #include "llvm/Analysis/LoopPass.h" 6 #include "llvm/Analysis/LoopPass.h"
6 #include "llvm/Target/TargetData.h" 7 #include "llvm/Target/TargetData.h"
30 clEnumValN(4, "O4", "Link-time optimization"), // not implemented? 31 clEnumValN(4, "O4", "Link-time optimization"), // not implemented?
31 clEnumValN(5, "O5", "Link-time optimization"), // not implemented? 32 clEnumValN(5, "O5", "Link-time optimization"), // not implemented?
32 clEnumValEnd), 33 clEnumValEnd),
33 cl::init(0)); 34 cl::init(0));
34 35
35 static cl::opt<bool> enableInlining("enable-inlining", 36 static cl::opt<opts::BoolOrDefaultAdapter, false, opts::FlagParser>
36 cl::desc("Enable function inlining (in -O<N>, if given)"), 37 enableInlining("inlining",
37 cl::ZeroOrMore, 38 cl::desc("(*) Enable function inlining (in -O<N>, if given)"),
38 cl::init(false)); 39 cl::ZeroOrMore);
39 40
40 // Some accessors for the linker: (llvm-ld version only, currently unused?) 41 // Determine whether or not to run the inliner as part of the default list of
42 // optimization passes.
43 // If not explicitly specified, treat as false for -O0-2, and true for -O3.
41 bool doInline() { 44 bool doInline() {
42 return enableInlining; 45 return enableInlining == cl::BOU_TRUE
46 || (enableInlining == cl::BOU_UNSET && optimizeLevel >= 3);
43 } 47 }
44 48
49 // Some extra accessors for the linker: (llvm-ld version only, currently unused?)
45 int optLevel() { 50 int optLevel() {
46 return optimizeLevel; 51 return optimizeLevel;
47 } 52 }
48 53
49 bool optimize() { 54 bool optimize() {
50 return optimizeLevel || enableInlining || passList.empty(); 55 return optimizeLevel || doInline() || passList.empty();
51 } 56 }
52 57
53 // this function inserts some or all of the std-compile-opts passes depending on the 58 // this function inserts some or all of the std-compile-opts passes depending on the
54 // optimization level given. 59 // optimization level given.
55 static void addPassesForOptLevel(PassManager& pm) { 60 static void addPassesForOptLevel(PassManager& pm) {
74 pm.add(createCFGSimplificationPass()); 79 pm.add(createCFGSimplificationPass());
75 pm.add(createPruneEHPass()); 80 pm.add(createPruneEHPass());
76 } 81 }
77 82
78 // -inline 83 // -inline
79 if (enableInlining) { 84 if (doInline()) {
80 pm.add(createFunctionInliningPass()); 85 pm.add(createFunctionInliningPass());
81 } 86 }
82 87
83 // -O3 88 // -O3
84 if (optimizeLevel >= 3) 89 if (optimizeLevel >= 3)
121 ////////////////////////////////////////////////////////////////////////////////////////// 126 //////////////////////////////////////////////////////////////////////////////////////////
122 // This function runs optimization passes based on command line arguments. 127 // This function runs optimization passes based on command line arguments.
123 // Returns true if any optimization passes were invoked. 128 // Returns true if any optimization passes were invoked.
124 bool ldc_optimize_module(llvm::Module* m) 129 bool ldc_optimize_module(llvm::Module* m)
125 { 130 {
126 if (!enableInlining && optimizeLevel == 0 && passList.empty()) 131 if (!doInline() && optimizeLevel == 0 && passList.empty())
127 return false; 132 return false;
128 133
129 PassManager pm; 134 PassManager pm;
130 pm.add(new TargetData(m)); 135 pm.add(new TargetData(m));
131 136
132 bool optimize = optimizeLevel != 0 || enableInlining; 137 bool optimize = optimizeLevel != 0 || doInline();
133 138
134 unsigned optPos = optimizeLevel != 0 139 unsigned optPos = optimizeLevel != 0
135 ? optimizeLevel.getPosition() 140 ? optimizeLevel.getPosition()
136 : enableInlining.getPosition(); 141 : enableInlining.getPosition();
137 142