comparison gen/toobj.cpp @ 1170:e40c65bd8c5d

Allow specific optimization passes to be requested from the command line. Now you can run "`ldc test.d -c -mem2reg -simplifycfg`" if you feel the urge. The -O<N> options are still supported, and are inserted in the passes list in the position where they appear on the command line. (so -simplifycfg -O1 -instcombine does the "right thing") One small change: -inline is renamed to -enable-inlining due to a naming conflict with the option to add the -inline pass. -inline now inserts the inlining pass in the position specified, not in the middle of -O<N>. (ldmd has been updated to translate -inline to -enable-inlining)
author Frits van Bommel <fvbommel wxs.nl>
date Sun, 29 Mar 2009 15:46:55 +0200
parents ea52660f828b
children a6dbd571d417
comparison
equal deleted inserted replaced
1169:2bff538fa3b9 1170:e40c65bd8c5d
47 #include "gen/functions.h" 47 #include "gen/functions.h"
48 #include "gen/todebug.h" 48 #include "gen/todebug.h"
49 #include "gen/runtime.h" 49 #include "gen/runtime.h"
50 #include "gen/abi.h" 50 #include "gen/abi.h"
51 #include "gen/cl_options.h" 51 #include "gen/cl_options.h"
52 #include "gen/optimizer.h"
52 53
53 #include "ir/irvar.h" 54 #include "ir/irvar.h"
54 #include "ir/irmodule.h" 55 #include "ir/irmodule.h"
55 56
56 ////////////////////////////////////////////////////////////////////////////////////////// 57 //////////////////////////////////////////////////////////////////////////////////////////
58 static llvm::cl::opt<bool> noVerify("noverify", 59 static llvm::cl::opt<bool> noVerify("noverify",
59 llvm::cl::desc("Do not run the validation pass before writing bitcode"), 60 llvm::cl::desc("Do not run the validation pass before writing bitcode"),
60 llvm::cl::ZeroOrMore); 61 llvm::cl::ZeroOrMore);
61 62
62 ////////////////////////////////////////////////////////////////////////////////////////// 63 //////////////////////////////////////////////////////////////////////////////////////////
63
64 // in gen/optimize.cpp
65 void ldc_optimize_module(llvm::Module* m, char lvl, bool doinline);
66 64
67 // fwd decl 65 // fwd decl
68 void write_asm_to_file(llvm::TargetMachine &Target, llvm::Module& m, llvm::raw_fd_ostream& Out); 66 void write_asm_to_file(llvm::TargetMachine &Target, llvm::Module& m, llvm::raw_fd_ostream& Out);
69 void assemble(const llvm::sys::Path& asmpath, const llvm::sys::Path& objpath); 67 void assemble(const llvm::sys::Path& asmpath, const llvm::sys::Path& objpath);
70 68
187 } 185 }
188 186
189 void writeModule(llvm::Module* m, std::string filename) 187 void writeModule(llvm::Module* m, std::string filename)
190 { 188 {
191 // run optimizer 189 // run optimizer
192 ldc_optimize_module(m, global.params.optimizeLevel, global.params.llvmInline); 190 bool reverify = ldc_optimize_module(m);
193 191
194 // verify the llvm 192 // verify the llvm
195 if (!noVerify && (global.params.optimizeLevel >= 0 || global.params.llvmInline)) { 193 if (!noVerify && reverify) {
196 std::string verifyErr; 194 std::string verifyErr;
197 Logger::println("Verifying module... again..."); 195 Logger::println("Verifying module... again...");
198 LOG_SCOPE; 196 LOG_SCOPE;
199 if (llvm::verifyModule(*m,llvm::ReturnStatusAction,&verifyErr)) 197 if (llvm::verifyModule(*m,llvm::ReturnStatusAction,&verifyErr))
200 { 198 {