diff --git a/include/llvm/Transforms/IPO/PassManagerBuilder.h b/include/llvm/Transforms/IPO/PassManagerBuilder.h index 56a8f76d63a..0cf346acebb 100644 --- a/include/llvm/Transforms/IPO/PassManagerBuilder.h +++ b/include/llvm/Transforms/IPO/PassManagerBuilder.h @@ -20,6 +20,7 @@ namespace llvm { class Pass; class TargetLibraryInfo; +class TargetMachine; // The old pass manager infrastructure is hidden in a legacy namespace now. namespace legacy { @@ -119,6 +120,9 @@ public: bool RerollLoops; bool LoadCombine; bool DisableGVNLoadPRE; + bool VerifyInput; + bool VerifyOutput; + bool StripDebug; private: /// ExtensionList - This is list of all of the extensions that are registered. @@ -136,6 +140,7 @@ public: private: void addExtensionsToPM(ExtensionPointTy ETy, PassManagerBase &PM) const; void addInitialAliasAnalysisPasses(PassManagerBase &PM) const; + void addLTOOptimizationPasses(PassManagerBase &PM); public: /// populateFunctionPassManager - This fills in the function pass manager, @@ -145,7 +150,7 @@ public: /// populateModulePassManager - This sets up the primary pass manager. void populateModulePassManager(PassManagerBase &MPM); - void populateLTOPassManager(PassManagerBase &PM); + void populateLTOPassManager(PassManagerBase &PM, TargetMachine *TM = nullptr); }; /// Registers a function for adding a standard set of passes. This should be diff --git a/lib/LTO/LTOCodeGenerator.cpp b/lib/LTO/LTOCodeGenerator.cpp index 80aa48e0fbc..34cd79c2a6e 100644 --- a/lib/LTO/LTOCodeGenerator.cpp +++ b/lib/LTO/LTOCodeGenerator.cpp @@ -458,32 +458,21 @@ bool LTOCodeGenerator::generateObjectFile(raw_ostream &out, // Instantiate the pass manager to organize the passes. PassManager passes; - // Start off with a verification pass. - passes.add(createVerifierPass()); - passes.add(createDebugInfoVerifierPass()); - // Add an appropriate DataLayout instance for this module... mergedModule->setDataLayout(TargetMach->getSubtargetImpl()->getDataLayout()); - passes.add(new DataLayoutPass(mergedModule)); - - TargetMach->addAnalysisPasses(passes); Triple TargetTriple(TargetMach->getTargetTriple()); - // Enabling internalize here would use its AllButMain variant. It - // keeps only main if it exists and does nothing for libraries. Instead - // we create the pass ourselves with the symbol list provided by the linker. - if (!DisableOpt) { - PassManagerBuilder PMB; - PMB.DisableGVNLoadPRE = DisableGVNLoadPRE; - if (!DisableInline) - PMB.Inliner = createFunctionInliningPass(); - PMB.LibraryInfo = new TargetLibraryInfo(TargetTriple); - PMB.populateLTOPassManager(passes); - } + PassManagerBuilder PMB; + PMB.DisableGVNLoadPRE = DisableGVNLoadPRE; + if (!DisableInline) + PMB.Inliner = createFunctionInliningPass(); + PMB.LibraryInfo = new TargetLibraryInfo(TargetTriple); + if (DisableOpt) + PMB.OptLevel = 0; + PMB.VerifyInput = true; + PMB.VerifyOutput = true; - // Make sure everything is still good. - passes.add(createVerifierPass()); - passes.add(createDebugInfoVerifierPass()); + PMB.populateLTOPassManager(passes, TargetMach); PassManager codeGenPasses; diff --git a/lib/Transforms/IPO/PassManagerBuilder.cpp b/lib/Transforms/IPO/PassManagerBuilder.cpp index b76f3486e5f..f5c5b065f11 100644 --- a/lib/Transforms/IPO/PassManagerBuilder.cpp +++ b/lib/Transforms/IPO/PassManagerBuilder.cpp @@ -17,11 +17,14 @@ #include "llvm-c/Transforms/PassManagerBuilder.h" #include "llvm/ADT/SmallVector.h" #include "llvm/Analysis/Passes.h" +#include "llvm/IR/DataLayout.h" #include "llvm/IR/Verifier.h" #include "llvm/PassManager.h" #include "llvm/Support/CommandLine.h" #include "llvm/Support/ManagedStatic.h" #include "llvm/Target/TargetLibraryInfo.h" +#include "llvm/Target/TargetMachine.h" +#include "llvm/Target/TargetSubtargetInfo.h" #include "llvm/Transforms/IPO.h" #include "llvm/Transforms/Scalar.h" #include "llvm/Transforms/Vectorize.h" @@ -78,6 +81,9 @@ PassManagerBuilder::PassManagerBuilder() { RerollLoops = RunLoopRerolling; LoadCombine = RunLoadCombine; DisableGVNLoadPRE = false; + VerifyInput = false; + VerifyOutput = false; + StripDebug = false; } PassManagerBuilder::~PassManagerBuilder() { @@ -313,11 +319,7 @@ void PassManagerBuilder::populateModulePassManager(PassManagerBase &MPM) { addExtensionsToPM(EP_OptimizerLast, MPM); } -void PassManagerBuilder::populateLTOPassManager(PassManagerBase &PM) { - // Add LibraryInfo if we have some. - if (LibraryInfo) - PM.add(new TargetLibraryInfo(*LibraryInfo)); - +void PassManagerBuilder::addLTOOptimizationPasses(PassManagerBase &PM) { // Provide AliasAnalysis services for optimizations. addInitialAliasAnalysisPasses(PM); @@ -408,6 +410,35 @@ void PassManagerBuilder::populateLTOPassManager(PassManagerBase &PM) { PM.add(createGlobalDCEPass()); } +void PassManagerBuilder::populateLTOPassManager(PassManagerBase &PM, + TargetMachine *TM) { + if (TM) { + const DataLayout *DL = TM->getSubtargetImpl()->getDataLayout(); + PM.add(new DataLayoutPass(*DL)); + TM->addAnalysisPasses(PM); + } + + if (LibraryInfo) + PM.add(new TargetLibraryInfo(*LibraryInfo)); + + if (VerifyInput) + PM.add(createVerifierPass()); + + if (StripDebug) + PM.add(createStripSymbolsPass(true)); + + if (VerifyInput) + PM.add(createDebugInfoVerifierPass()); + + if (OptLevel != 0) + addLTOOptimizationPasses(PM); + + if (VerifyOutput) { + PM.add(createVerifierPass()); + PM.add(createDebugInfoVerifierPass()); + } +} + inline PassManagerBuilder *unwrap(LLVMPassManagerBuilderRef P) { return reinterpret_cast(P); } diff --git a/tools/opt/opt.cpp b/tools/opt/opt.cpp index 65250b67da1..9a0c9a42089 100644 --- a/tools/opt/opt.cpp +++ b/tools/opt/opt.cpp @@ -254,18 +254,12 @@ static void AddStandardCompilePasses(PassManagerBase &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.VerifyInput = true; + Builder.StripDebug = StripDebug; + if (DisableOptimizations) + Builder.OptLevel = 0; + if (!DisableInline) Builder.Inliner = createFunctionInliningPass(); Builder.populateLTOPassManager(PM);