diff options
Diffstat (limited to 'tools/opt/opt.cpp')
-rw-r--r-- | tools/opt/opt.cpp | 101 |
1 files changed, 25 insertions, 76 deletions
diff --git a/tools/opt/opt.cpp b/tools/opt/opt.cpp index 6ba6340..cdd22e4 100644 --- a/tools/opt/opt.cpp +++ b/tools/opt/opt.cpp @@ -109,14 +109,6 @@ DisableOptimizations("disable-opt", cl::desc("Do not run any optimization passes")); static cl::opt<bool> -DisableInternalize("disable-internalize", - cl::desc("Do not mark all symbols as internal")); - -static cl::opt<bool> -StandardCompileOpts("std-compile-opts", - cl::desc("Include the standard compile time optimizations")); - -static cl::opt<bool> StandardLinkOpts("std-link-opts", cl::desc("Include the standard link time optimizations")); @@ -145,7 +137,7 @@ TargetTriple("mtriple", cl::desc("Override target triple for module")); static cl::opt<bool> UnitAtATime("funit-at-a-time", - cl::desc("Enable IPO. This is same as llvm-gcc's -funit-at-a-time"), + cl::desc("Enable IPO. This corresponds to gcc's -funit-at-a-time"), cl::init(true)); static cl::opt<bool> @@ -198,9 +190,8 @@ static inline void addPass(PassManagerBase &PM, Pass *P) { } } -/// AddOptimizationPasses - This routine adds optimization passes -/// based on selected optimization level, OptLevel. This routine -/// duplicates llvm-gcc behaviour. +/// This routine adds optimization passes based on selected optimization level, +/// OptLevel. /// /// OptLevel - Optimization Level static void AddOptimizationPasses(PassManagerBase &MPM,FunctionPassManager &FPM, @@ -238,41 +229,16 @@ static void AddOptimizationPasses(PassManagerBase &MPM,FunctionPassManager &FPM, Builder.populateModulePassManager(MPM); } -static void AddStandardCompilePasses(PassManagerBase &PM) { - PM.add(createVerifierPass()); // Verify that input is correct - - // If the -strip-debug command line option was specified, do it. - if (StripDebug) - addPass(PM, createStripSymbolsPass(true)); - - // Verify debug info only after it's (possibly) stripped. - PM.add(createDebugInfoVerifierPass()); - - if (DisableOptimizations) return; - - // -std-compile-opts adds the same module passes as -O3. +static void AddStandardLinkPasses(PassManagerBase &PM) { PassManagerBuilder Builder; + Builder.VerifyInput = true; + Builder.StripDebug = StripDebug; + if (DisableOptimizations) + Builder.OptLevel = 0; + if (!DisableInline) Builder.Inliner = createFunctionInliningPass(); - Builder.OptLevel = 3; - Builder.populateModulePassManager(PM); -} - -static void AddStandardLinkPasses(PassManagerBase &PM) { - PM.add(createVerifierPass()); // Verify that input is correct - - // If the -strip-debug command line option was specified, do it. - if (StripDebug) - addPass(PM, createStripSymbolsPass(true)); - - // Verify debug info only after it's (possibly) stripped. - PM.add(createDebugInfoVerifierPass()); - - if (DisableOptimizations) return; - - PassManagerBuilder Builder; - Builder.populateLTOPassManager(PM, /*Internalize=*/ !DisableInternalize, - /*RunInliner=*/ !DisableInline); + Builder.populateLTOPassManager(PM); } //===----------------------------------------------------------------------===// @@ -355,7 +321,8 @@ int main(int argc, char **argv) { // For codegen passes, only passes that do IR to IR transformation are // supported. initializeCodeGenPreparePass(Registry); - initializeAtomicExpandLoadLinkedPass(Registry); + initializeAtomicExpandPass(Registry); + initializeRewriteSymbolsPass(Registry); #ifdef LINK_POLLY_INTO_TOOLS polly::initializePollyPasses(Registry); @@ -372,8 +339,7 @@ int main(int argc, char **argv) { SMDiagnostic Err; // Load the input module... - std::unique_ptr<Module> M; - M.reset(ParseIRFile(InputFilename, Err, Context)); + std::unique_ptr<Module> M = parseIRFile(InputFilename, Err, Context); if (!M.get()) { Err.print(argv[0], errs()); @@ -395,11 +361,10 @@ int main(int argc, char **argv) { if (OutputFilename.empty()) OutputFilename = "-"; - std::string ErrorInfo; - Out.reset(new tool_output_file(OutputFilename.c_str(), ErrorInfo, - sys::fs::F_None)); - if (!ErrorInfo.empty()) { - errs() << ErrorInfo << '\n'; + std::error_code EC; + Out.reset(new tool_output_file(OutputFilename, EC, sys::fs::F_None)); + if (EC) { + errs() << EC.message() << '\n'; return 1; } } @@ -452,7 +417,7 @@ int main(int argc, char **argv) { } if (DL) - Passes.add(new DataLayoutPass(M.get())); + Passes.add(new DataLayoutPass()); Triple ModuleTriple(M->getTargetTriple()); TargetMachine *Machine = nullptr; @@ -468,7 +433,7 @@ int main(int argc, char **argv) { if (OptLevelO1 || OptLevelO2 || OptLevelOs || OptLevelOz || OptLevelO3) { FPasses.reset(new FunctionPassManager(M.get())); if (DL) - FPasses->add(new DataLayoutPass(M.get())); + FPasses->add(new DataLayoutPass()); if (TM.get()) TM->addAnalysisPasses(*FPasses); @@ -480,11 +445,10 @@ int main(int argc, char **argv) { if (OutputFilename.empty()) OutputFilename = "-"; - std::string ErrorInfo; - Out.reset(new tool_output_file(OutputFilename.c_str(), ErrorInfo, - sys::fs::F_None)); - if (!ErrorInfo.empty()) { - errs() << ErrorInfo << '\n'; + std::error_code EC; + Out.reset(new tool_output_file(OutputFilename, EC, sys::fs::F_None)); + if (EC) { + errs() << EC.message() << '\n'; return 1; } } @@ -492,21 +456,12 @@ int main(int argc, char **argv) { NoOutput = true; } - // If the -strip-debug command line option was specified, add it. If - // -std-compile-opts was also specified, it will handle StripDebug. - if (StripDebug && !StandardCompileOpts) + // If the -strip-debug command line option was specified, add it. + if (StripDebug) addPass(Passes, createStripSymbolsPass(true)); // Create a new optimization pass for each one specified on the command line for (unsigned i = 0; i < PassList.size(); ++i) { - // Check to see if -std-compile-opts was specified before this option. If - // so, handle it. - if (StandardCompileOpts && - StandardCompileOpts.getPosition() < PassList.getPosition(i)) { - AddStandardCompilePasses(Passes); - StandardCompileOpts = false; - } - if (StandardLinkOpts && StandardLinkOpts.getPosition() < PassList.getPosition(i)) { AddStandardLinkPasses(Passes); @@ -579,12 +534,6 @@ int main(int argc, char **argv) { Passes.add(createPrintModulePass(errs())); } - // If -std-compile-opts was specified at the end of the pass list, add them. - if (StandardCompileOpts) { - AddStandardCompilePasses(Passes); - StandardCompileOpts = false; - } - if (StandardLinkOpts) { AddStandardLinkPasses(Passes); StandardLinkOpts = false; |