Changeset 1170:e40c65bd8c5d
- Timestamp:
- 03/29/09 09:46:55 (3 years ago)
- Files:
-
- bin/ldmd (modified) (1 diff)
- dmd/mars.h (modified) (2 diffs)
- dmd2/mars.h (modified) (2 diffs)
- gen/cl_options.cpp (modified) (2 diffs)
- gen/linker.cpp (modified) (3 diffs)
- gen/main.cpp (modified) (1 diff)
- gen/optimizer.cpp (modified) (5 diffs)
- gen/toobj.cpp (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
bin/ldmd
r1060 r1170 18 18 for arg; do 19 19 case "$arg" in 20 -C*) 21 # turn -Cfoo into -foo. 22 # Useful for passing -inline to ldc, for instance. 23 arg="-${arg:2}" 24 ;; 20 25 -debug|-debug=*|-version=*) 21 26 arg="-d$arg" 27 ;; 28 -inline) 29 arg="-enable-inlining" 22 30 ;; 23 31 -fPIC) dmd/mars.h
r1124 r1170 139 139 bool verbose; // verbose compile 140 140 char symdebug; // insert debug symbolic information 141 #if !IN_LLVM 142 // LDC uses a different mechanism 141 143 bool optimize; // run optimizer 142 144 char optimizeLevel; // optimization level 145 #endif 143 146 ARCH cpu; // target CPU 144 147 OS os; // target OS … … 211 214 OUTPUTFLAG output_s; 212 215 OUTPUTFLAG output_o; 213 bool llvmInline;214 216 bool llvmAnnotate; 215 217 bool useInlineAsm; dmd2/mars.h
r1064 r1170 74 74 bool verbose; // verbose compile 75 75 char symdebug; // insert debug symbolic information 76 #if !IN_LLVM 77 // LDC uses a different mechanism 76 78 bool optimize; // run optimizer 77 79 char optimizeLevel; // optimization level 80 #endif 78 81 ARCH cpu; // target CPU 79 82 OS os; // target OS … … 146 149 OUTPUTFLAG output_s; 147 150 OUTPUTFLAG output_o; 148 bool llvmInline;149 151 bool llvmAnnotate; 150 152 bool useInlineAsm; gen/cl_options.cpp
r1067 r1170 19 19 cl::Positional, 20 20 cl::PositionalEatsArgs); 21 22 23 24 // TODO: Replace this with a proper PassNameParser-based solution25 static cl::opt<bool, true> doInline("inline",26 cl::desc("Do function inlining"),27 cl::location(global.params.llvmInline),28 cl::ZeroOrMore,29 cl::init(false));30 31 21 32 22 … … 59 49 cl::ZeroOrMore, 60 50 cl::location(global.params.warnings)); 61 62 63 static cl::opt<char, true> optimizeLevel(64 cl::desc("Setting the optimization level:"),65 cl::ZeroOrMore,66 cl::values(67 clEnumValN(2, "O", "Equivalent to -O2"),68 clEnumValN(0, "O0", "Trivial optimizations only"),69 clEnumValN(1, "O1", "Simple optimizations"),70 clEnumValN(2, "O2", "Good optimizations"),71 clEnumValN(3, "O3", "Aggressive optimizations"),72 clEnumValN(4, "O4", "Link-time optimization"), // not implemented?73 clEnumValN(5, "O5", "Link-time optimization"), // not implemented?74 clEnumValEnd),75 cl::location(global.params.optimizeLevel),76 cl::init(-1));77 51 78 52 static cl::opt<char, true> debugInfo( gen/linker.cpp
r1026 r1170 14 14 #include "gen/logger.h" 15 15 #include "gen/cl_options.h" 16 #include "gen/optimizer.h" 16 17 17 18 ////////////////////////////////////////////////////////////////////////////// … … 112 113 113 114 // optimization level 114 if (! global.params.optimize)115 if (!optimize()) 115 116 args.push_back("-disable-opt"); 116 117 else 117 118 { 118 119 const char* s = 0; 119 switch( global.params.optimizeLevel)120 switch(optLevel()) 120 121 { 121 122 case 0: … … 139 140 140 141 // inlining 141 if (!(global.params.useInline || global.params.llvmInline))142 if (!(global.params.useInline || doInline())) 142 143 { 143 144 args.push_back("-disable-inlining"); gen/main.cpp
r1149 r1170 192 192 cl::SetVersionPrinter(&printVersion); 193 193 cl::ParseCommandLineOptions(final_args.size(), (char**)&final_args[0], "LLVM-based D Compiler\n", true); 194 195 global.params.optimize = (global.params.optimizeLevel >= 0);196 194 197 195 // Negated options gen/optimizer.cpp
r663 r1170 1 #include "gen/optimizer.h" 2 1 3 #include "llvm/PassManager.h" 2 4 #include "llvm/LinkAllPasses.h" 3 5 #include "llvm/Analysis/LoopPass.h" 4 6 #include "llvm/Target/TargetData.h" 7 #include "llvm/Support/CommandLine.h" 8 #include "llvm/Support/PassNameParser.h" 9 10 #include "root.h" // error() & fatal() 11 #include "mars.h" // global flags 5 12 6 13 using namespace llvm; 7 14 8 ////////////////////////////////////////////////////////////////////////////////////////// 15 // Allow the user to specify specific optimizations to run. 16 static cl::list<const PassInfo*, bool, PassNameParser> 17 passList( 18 cl::desc("Running specific optimizations:"), 19 cl::Hidden // to clean up --help output 20 ); 9 21 10 // this function runs some or all of the std-compile-opts passes depending on the 22 static cl::opt<char> optimizeLevel( 23 cl::desc("Setting the optimization level:"), 24 cl::ZeroOrMore, 25 cl::values( 26 clEnumValN(2, "O", "Equivalent to -O2"), 27 clEnumValN(0, "O0", "Trivial optimizations only"), 28 clEnumValN(1, "O1", "Simple optimizations"), 29 clEnumValN(2, "O2", "Good optimizations"), 30 clEnumValN(3, "O3", "Aggressive optimizations"), 31 clEnumValN(4, "O4", "Link-time optimization"), // not implemented? 32 clEnumValN(5, "O5", "Link-time optimization"), // not implemented? 33 clEnumValEnd), 34 cl::init(-1)); 35 36 static cl::opt<bool> enableInlining("enable-inlining", 37 cl::desc("Enable function inlining (in -O<N>, if given)"), 38 cl::ZeroOrMore, 39 cl::init(false)); 40 41 // Some accessors for the linker: (llvm-ld version only, currently unused?) 42 bool doInline() { 43 return enableInlining; 44 } 45 46 int optLevel() { 47 return optimizeLevel; 48 } 49 50 bool optimize() { 51 return (optimizeLevel != -1) || enableInlining || passList.empty(); 52 } 53 54 // this function inserts some or all of the std-compile-opts passes depending on the 11 55 // optimization level given. 12 13 void ldc_optimize_module(Module* m, char lvl, bool doinline) 14 { 15 if (!doinline && lvl < 0) 16 return; 17 18 PassManager pm; 19 pm.add(new TargetData(m)); 20 56 static void addPassesForOptLevel(PassManager& pm) { 21 57 // -O0 22 if ( lvl >= 0)58 if (optimizeLevel >= 0) 23 59 { 24 60 //pm.add(createStripDeadPrototypesPass()); … … 27 63 28 64 // -O1 29 if ( lvl >= 1)65 if (optimizeLevel >= 1) 30 66 { 31 67 pm.add(createRaiseAllocationsPass()); … … 37 73 38 74 // -O2 39 if ( lvl >= 2)75 if (optimizeLevel >= 2) 40 76 { 41 77 pm.add(createIPConstantPropagationPass()); … … 47 83 48 84 // -inline 49 if ( doinline) {85 if (enableInlining) { 50 86 pm.add(createFunctionInliningPass()); 51 87 } 52 88 53 89 // -O3 54 if ( lvl >= 3)90 if (optimizeLevel >= 3) 55 91 { 56 92 pm.add(createArgumentPromotionPass()); … … 87 123 88 124 // level -O4 and -O5 are linktime optimizations 125 } 126 127 ////////////////////////////////////////////////////////////////////////////////////////// 128 // This function runs optimization passes based on command line arguments. 129 // Returns true if any optimization passes were invoked. 130 bool ldc_optimize_module(llvm::Module* m) 131 { 132 if (!enableInlining && optimizeLevel == -1 && passList.empty()) 133 return false; 134 135 PassManager pm; 136 pm.add(new TargetData(m)); 137 138 bool optimize = (optimizeLevel != -1) || enableInlining; 139 140 unsigned optPos = optimizeLevel != -1 141 ? optimizeLevel.getPosition() 142 : enableInlining.getPosition(); 143 144 for (size_t i = 0; i < passList.size(); i++) { 145 // insert -O<N> / -enable-inlining in right position 146 if (optimize && optPos < passList.getPosition(i)) { 147 addPassesForOptLevel(pm); 148 optimize = false; 149 } 150 151 const PassInfo* pass = passList[i]; 152 if (PassInfo::NormalCtor_t ctor = pass->getNormalCtor()) { 153 pm.add(ctor()); 154 } else { 155 const char* arg = pass->getPassArgument(); // may return null 156 if (arg) 157 error("Can't create pass '-%s' (%s)", arg, pass->getPassName()); 158 else 159 error("Can't create pass (%s)", pass->getPassName()); 160 fatal(); 161 } 162 } 163 // insert -O<N> / -enable-inlining if specified at the end, 164 if (optimize) 165 addPassesForOptLevel(pm); 89 166 90 167 pm.run(*m); 168 return true; 91 169 } gen/toobj.cpp
r1163 r1170 50 50 #include "gen/abi.h" 51 51 #include "gen/cl_options.h" 52 #include "gen/optimizer.h" 52 53 53 54 #include "ir/irvar.h" … … 61 62 62 63 ////////////////////////////////////////////////////////////////////////////////////////// 63 64 // in gen/optimize.cpp65 void ldc_optimize_module(llvm::Module* m, char lvl, bool doinline);66 64 67 65 // fwd decl … … 190 188 { 191 189 // run optimizer 192 ldc_optimize_module(m, global.params.optimizeLevel, global.params.llvmInline);190 bool reverify = ldc_optimize_module(m); 193 191 194 192 // verify the llvm 195 if (!noVerify && (global.params.optimizeLevel >= 0 || global.params.llvmInline)) {193 if (!noVerify && reverify) { 196 194 std::string verifyErr; 197 195 Logger::println("Verifying module... again...");

