From adc82888b5be1d43caa94e9247f19927ef70f621 Mon Sep 17 00:00:00 2001 From: Daniel Dunbar Date: Fri, 17 Jul 2009 18:09:39 +0000 Subject: [PATCH] opt: Add -std-link-opts argument, matches llvm-ld's optimizations. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@76199 91177308-0d34-0410-b5e6-96231b3b80d8 --- tools/opt/opt.cpp | 45 +++++++++++++++++++++++++++++++++++++++------ 1 file changed, 39 insertions(+), 6 deletions(-) diff --git a/tools/opt/opt.cpp b/tools/opt/opt.cpp index abfeace376b..b962ad95576 100644 --- a/tools/opt/opt.cpp +++ b/tools/opt/opt.cpp @@ -81,10 +81,18 @@ static cl::opt DisableOptimizations("disable-opt", cl::desc("Do not run any optimization passes")); +static cl::opt +DisableInternalize("disable-internalize", + cl::desc("Do not mark all symbols as internal")); + static cl::opt StandardCompileOpts("std-compile-opts", cl::desc("Include the standard compile time optimizations")); +static cl::opt +StandardLinkOpts("std-link-opts", + cl::desc("Include the standard link time optimizations")); + static cl::opt OptLevelO1("O1", cl::desc("Optimization level 1. Similar to llvm-gcc -O1")); @@ -311,6 +319,20 @@ void AddStandardCompilePasses(PassManager &PM) { InliningPass); } +void AddStandardLinkPasses(PassManager &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)); + + if (DisableOptimizations) return; + + createStandardLTOPasses(&PM, /*Internalize=*/ !DisableInternalize, + /*RunInliner=*/ !DisableInline, + /*VerifyEach=*/ VerifyEach); +} + } // anonymous namespace @@ -404,6 +426,12 @@ int main(int argc, char **argv) { StandardCompileOpts = false; } + if (StandardLinkOpts && + StandardLinkOpts.getPosition() < PassList.getPosition(i)) { + AddStandardLinkPasses(Passes); + StandardLinkOpts = false; + } + if (OptLevelO1 && OptLevelO1.getPosition() < PassList.getPosition(i)) { AddOptimizationPasses(Passes, *FPasses, 1); OptLevelO1 = false; @@ -458,17 +486,22 @@ int main(int argc, char **argv) { StandardCompileOpts = false; } + if (StandardLinkOpts) { + AddStandardLinkPasses(Passes); + StandardLinkOpts = false; + } + if (OptLevelO1) { - AddOptimizationPasses(Passes, *FPasses, 1); - } + AddOptimizationPasses(Passes, *FPasses, 1); + } if (OptLevelO2) { - AddOptimizationPasses(Passes, *FPasses, 2); - } + AddOptimizationPasses(Passes, *FPasses, 2); + } if (OptLevelO3) { - AddOptimizationPasses(Passes, *FPasses, 3); - } + AddOptimizationPasses(Passes, *FPasses, 3); + } if (OptLevelO1 || OptLevelO2 || OptLevelO3) { for (Module::iterator I = M.get()->begin(), E = M.get()->end(); -- 2.34.1