diff options
Diffstat (limited to 'contrib/llvm/tools/opt/opt.cpp')
-rw-r--r-- | contrib/llvm/tools/opt/opt.cpp | 121 |
1 files changed, 35 insertions, 86 deletions
diff --git a/contrib/llvm/tools/opt/opt.cpp b/contrib/llvm/tools/opt/opt.cpp index 6ba6340..9867589 100644 --- a/contrib/llvm/tools/opt/opt.cpp +++ b/contrib/llvm/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); } //===----------------------------------------------------------------------===// @@ -341,7 +307,6 @@ int main(int argc, char **argv) { // Initialize passes PassRegistry &Registry = *PassRegistry::getPassRegistry(); initializeCore(Registry); - initializeDebugIRPass(Registry); initializeScalarOpts(Registry); initializeObjCARCOpts(Registry); initializeVectorization(Registry); @@ -355,7 +320,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,10 +338,9 @@ 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()) { + if (!M) { Err.print(argv[0], errs()); return 1; } @@ -395,11 +360,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; } } @@ -425,7 +389,7 @@ int main(int argc, char **argv) { // The user has asked to use the new pass manager and provided a pipeline // string. Hand off the rest of the functionality to the new code for that // layer. - return runPassPipeline(argv[0], Context, *M.get(), Out.get(), PassPipeline, + return runPassPipeline(argv[0], Context, *M, Out.get(), PassPipeline, OK, VK) ? 0 : 1; @@ -445,14 +409,14 @@ int main(int argc, char **argv) { Passes.add(TLI); // Add an appropriate DataLayout instance for this module. - const DataLayout *DL = M.get()->getDataLayout(); + const DataLayout *DL = M->getDataLayout(); if (!DL && !DefaultDataLayout.empty()) { M->setDataLayout(DefaultDataLayout); - DL = M.get()->getDataLayout(); + DL = M->getDataLayout(); } if (DL) - Passes.add(new DataLayoutPass(M.get())); + Passes.add(new DataLayoutPass()); Triple ModuleTriple(M->getTargetTriple()); TargetMachine *Machine = nullptr; @@ -461,15 +425,15 @@ int main(int argc, char **argv) { std::unique_ptr<TargetMachine> TM(Machine); // Add internal analysis passes from the target machine. - if (TM.get()) + if (TM) TM->addAnalysisPasses(Passes); std::unique_ptr<FunctionPassManager> FPasses; if (OptLevelO1 || OptLevelO2 || OptLevelOs || OptLevelOz || OptLevelO3) { FPasses.reset(new FunctionPassManager(M.get())); if (DL) - FPasses->add(new DataLayoutPass(M.get())); - if (TM.get()) + FPasses->add(new DataLayoutPass()); + if (TM) TM->addAnalysisPasses(*FPasses); } @@ -480,11 +444,11 @@ 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 = llvm::make_unique<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; @@ -607,8 +556,8 @@ int main(int argc, char **argv) { if (OptLevelO1 || OptLevelO2 || OptLevelOs || OptLevelOz || OptLevelO3) { FPasses->doInitialization(); - for (Module::iterator F = M->begin(), E = M->end(); F != E; ++F) - FPasses->run(*F); + for (Function &F : *M) + FPasses->run(F); FPasses->doFinalization(); } @@ -630,7 +579,7 @@ int main(int argc, char **argv) { cl::PrintOptionValues(); // Now that we have all of the passes ready, run them. - Passes.run(*M.get()); + Passes.run(*M); // Declare success. if (!NoOutput || PrintBreakpoints) |