diff options
Diffstat (limited to 'tools/opt')
-rw-r--r-- | tools/opt/AnalysisWrappers.cpp | 20 | ||||
-rw-r--r-- | tools/opt/BreakpointPrinter.cpp | 10 | ||||
-rw-r--r-- | tools/opt/Makefile | 17 | ||||
-rw-r--r-- | tools/opt/NewPMDriver.cpp | 35 | ||||
-rw-r--r-- | tools/opt/NewPMDriver.h | 3 | ||||
-rw-r--r-- | tools/opt/opt.cpp | 98 |
6 files changed, 104 insertions, 79 deletions
diff --git a/tools/opt/AnalysisWrappers.cpp b/tools/opt/AnalysisWrappers.cpp index 4bdc268f8d75..cfdd2cf1582b 100644 --- a/tools/opt/AnalysisWrappers.cpp +++ b/tools/opt/AnalysisWrappers.cpp @@ -71,23 +71,3 @@ char ExternalFunctionsPassedConstants::ID = 0; static RegisterPass<ExternalFunctionsPassedConstants> P1("print-externalfnconstants", "Print external fn callsites passed constants"); - -namespace { - struct CallGraphPrinter : public ModulePass { - static char ID; // Pass ID, replacement for typeid - CallGraphPrinter() : ModulePass(ID) {} - - void getAnalysisUsage(AnalysisUsage &AU) const override { - AU.setPreservesAll(); - AU.addRequiredTransitive<CallGraphWrapperPass>(); - } - bool runOnModule(Module &M) override { - getAnalysis<CallGraphWrapperPass>().print(errs(), &M); - return false; - } - }; -} - -char CallGraphPrinter::ID = 0; -static RegisterPass<CallGraphPrinter> - P2("print-callgraph", "Print a call graph"); diff --git a/tools/opt/BreakpointPrinter.cpp b/tools/opt/BreakpointPrinter.cpp index 363a7cd80074..33b3edcd1237 100644 --- a/tools/opt/BreakpointPrinter.cpp +++ b/tools/opt/BreakpointPrinter.cpp @@ -25,7 +25,6 @@ namespace { struct BreakpointPrinter : public ModulePass { raw_ostream &Out; static char ID; - DITypeIdentifierMap TypeIdentifierMap; BreakpointPrinter(raw_ostream &out) : ModulePass(ID), Out(out) {} @@ -37,18 +36,13 @@ struct BreakpointPrinter : public ModulePass { } } else if (auto *TY = dyn_cast<DIType>(Context)) { if (!TY->getName().empty()) { - getContextName(TY->getScope().resolve(TypeIdentifierMap), N); + getContextName(TY->getScope().resolve(), N); N = N + TY->getName().str() + "::"; } } } bool runOnModule(Module &M) override { - TypeIdentifierMap.clear(); - NamedMDNode *CU_Nodes = M.getNamedMetadata("llvm.dbg.cu"); - if (CU_Nodes) - TypeIdentifierMap = generateDITypeIdentifierMap(CU_Nodes); - StringSet<> Processed; if (NamedMDNode *NMD = M.getNamedMetadata("llvm.dbg.sp")) for (unsigned i = 0, e = NMD->getNumOperands(); i != e; ++i) { @@ -56,7 +50,7 @@ struct BreakpointPrinter : public ModulePass { auto *SP = cast_or_null<DISubprogram>(NMD->getOperand(i)); if (!SP) continue; - getContextName(SP->getScope().resolve(TypeIdentifierMap), Name); + getContextName(SP->getScope().resolve(), Name); Name = Name + SP->getDisplayName().str(); if (!Name.empty() && Processed.insert(Name).second) { Out << Name << "\n"; diff --git a/tools/opt/Makefile b/tools/opt/Makefile deleted file mode 100644 index 2422eb4e4056..000000000000 --- a/tools/opt/Makefile +++ /dev/null @@ -1,17 +0,0 @@ -##===- tools/opt/Makefile ----------------------------------*- Makefile -*-===## -# -# The LLVM Compiler Infrastructure -# -# This file is distributed under the University of Illinois Open Source -# License. See LICENSE.TXT for details. -# -##===----------------------------------------------------------------------===## - -LEVEL := ../.. -TOOLNAME := opt -LINK_COMPONENTS := bitreader bitwriter asmparser irreader instrumentation scalaropts objcarcopts ipo vectorize all-targets codegen passes - -# Support plugins. -NO_DEAD_STRIP := 1 - -include $(LEVEL)/Makefile.common diff --git a/tools/opt/NewPMDriver.cpp b/tools/opt/NewPMDriver.cpp index 3030d65743af..f7b2f18d09d9 100644 --- a/tools/opt/NewPMDriver.cpp +++ b/tools/opt/NewPMDriver.cpp @@ -15,7 +15,9 @@ #include "NewPMDriver.h" #include "llvm/ADT/StringRef.h" +#include "llvm/Analysis/AliasAnalysis.h" #include "llvm/Analysis/CGSCCPassManager.h" +#include "llvm/Analysis/LoopPassManager.h" #include "llvm/Bitcode/BitcodeWriterPass.h" #include "llvm/IR/Dominators.h" #include "llvm/IR/IRPrintingPasses.h" @@ -36,6 +38,15 @@ static cl::opt<bool> DebugPM("debug-pass-manager", cl::Hidden, cl::desc("Print pass management debugging information")); +// This flag specifies a textual description of the alias analysis pipeline to +// use when querying for aliasing information. It only works in concert with +// the "passes" flag above. +static cl::opt<std::string> + AAPipeline("aa-pipeline", + cl::desc("A textual description of the alias analysis " + "pipeline for handling managed aliasing queries"), + cl::Hidden); + bool llvm::runPassPipeline(StringRef Arg0, LLVMContext &Context, Module &M, TargetMachine *TM, tool_output_file *Out, StringRef PassPipeline, OutputKind OK, @@ -44,22 +55,28 @@ bool llvm::runPassPipeline(StringRef Arg0, LLVMContext &Context, Module &M, bool ShouldPreserveBitcodeUseListOrder) { PassBuilder PB(TM); + // Specially handle the alias analysis manager so that we can register + // a custom pipeline of AA passes with it. + AAManager AA; + if (!PB.parseAAPipeline(AA, AAPipeline)) { + errs() << Arg0 << ": unable to parse AA pipeline description.\n"; + return false; + } + + LoopAnalysisManager LAM(DebugPM); FunctionAnalysisManager FAM(DebugPM); CGSCCAnalysisManager CGAM(DebugPM); ModuleAnalysisManager MAM(DebugPM); + // Register the AA manager first so that our version is the one used. + FAM.registerPass([&] { return std::move(AA); }); + // Register all the basic analyses with the managers. PB.registerModuleAnalyses(MAM); PB.registerCGSCCAnalyses(CGAM); PB.registerFunctionAnalyses(FAM); - - // Cross register the analysis managers through their proxies. - MAM.registerPass(FunctionAnalysisManagerModuleProxy(FAM)); - MAM.registerPass(CGSCCAnalysisManagerModuleProxy(CGAM)); - CGAM.registerPass(FunctionAnalysisManagerCGSCCProxy(FAM)); - CGAM.registerPass(ModuleAnalysisManagerCGSCCProxy(MAM)); - FAM.registerPass(CGSCCAnalysisManagerFunctionProxy(CGAM)); - FAM.registerPass(ModuleAnalysisManagerFunctionProxy(MAM)); + PB.registerLoopAnalyses(LAM); + PB.crossRegisterProxies(LAM, FAM, CGAM, MAM); ModulePassManager MPM(DebugPM); if (VK > VK_NoVerifier) @@ -92,7 +109,7 @@ bool llvm::runPassPipeline(StringRef Arg0, LLVMContext &Context, Module &M, cl::PrintOptionValues(); // Now that we have all of the passes ready, run them. - MPM.run(M, &MAM); + MPM.run(M, MAM); // Declare success. if (OK != OK_NoOutput) diff --git a/tools/opt/NewPMDriver.h b/tools/opt/NewPMDriver.h index 349a7b1267f8..66a470d49ba8 100644 --- a/tools/opt/NewPMDriver.h +++ b/tools/opt/NewPMDriver.h @@ -21,9 +21,8 @@ #ifndef LLVM_TOOLS_OPT_NEWPMDRIVER_H #define LLVM_TOOLS_OPT_NEWPMDRIVER_H -#include "llvm/ADT/StringRef.h" - namespace llvm { +class StringRef; class LLVMContext; class Module; class TargetMachine; diff --git a/tools/opt/opt.cpp b/tools/opt/opt.cpp index fe1605aa8436..0a4ce1dfe8ef 100644 --- a/tools/opt/opt.cpp +++ b/tools/opt/opt.cpp @@ -96,12 +96,16 @@ static cl::opt<bool> OutputAssembly("S", cl::desc("Write output as LLVM assembly")); static cl::opt<bool> -NoVerify("disable-verify", cl::desc("Do not verify result module"), cl::Hidden); +NoVerify("disable-verify", cl::desc("Do not run the verifier"), cl::Hidden); static cl::opt<bool> VerifyEach("verify-each", cl::desc("Verify after each transform")); static cl::opt<bool> + DisableDITypeMap("disable-debug-info-type-map", + cl::desc("Don't use a uniquing type map for debug info")); + +static cl::opt<bool> StripDebug("strip-debug", cl::desc("Strip debugger symbol info from translation unit")); @@ -136,6 +140,10 @@ static cl::opt<bool> OptLevelO3("O3", cl::desc("Optimization level 3. Similar to clang -O3")); +static cl::opt<unsigned> +CodeGenOptLevel("codegen-opt-level", + cl::desc("Override optimization level for codegen hooks")); + static cl::opt<std::string> TargetTriple("mtriple", cl::desc("Override target triple for module")); @@ -158,6 +166,12 @@ DisableSLPVectorization("disable-slp-vectorization", cl::desc("Disable the slp vectorization pass"), cl::init(false)); +static cl::opt<bool> EmitSummaryIndex("module-summary", + cl::desc("Emit module summary index"), + cl::init(false)); + +static cl::opt<bool> EmitModuleHash("module-hash", cl::desc("Emit module hash"), + cl::init(false)); static cl::opt<bool> DisableSimplifyLibCalls("disable-simplify-libcalls", @@ -196,6 +210,16 @@ static cl::opt<bool> cl::desc("Run all passes twice, re-using the same pass manager."), cl::init(false), cl::Hidden); +static cl::opt<bool> DiscardValueNames( + "discard-value-names", + cl::desc("Discard names from Value (other than GlobalValue)."), + cl::init(false), cl::Hidden); + +static cl::opt<bool> PassRemarksWithHotness( + "pass-remarks-with-hotness", + cl::desc("With PGO, include profile count in optimization remarks"), + cl::Hidden); + static inline void addPass(legacy::PassManagerBase &PM, Pass *P) { // Add the pass to the pass manager... PM.add(P); @@ -211,8 +235,10 @@ static inline void addPass(legacy::PassManagerBase &PM, Pass *P) { /// OptLevel - Optimization Level static void AddOptimizationPasses(legacy::PassManagerBase &MPM, legacy::FunctionPassManager &FPM, - unsigned OptLevel, unsigned SizeLevel) { - FPM.add(createVerifierPass()); // Verify that input is correct + TargetMachine *TM, unsigned OptLevel, + unsigned SizeLevel) { + if (!NoVerify || VerifyEach) + FPM.add(createVerifierPass()); // Verify that input is correct PassManagerBuilder Builder; Builder.OptLevel = OptLevel; @@ -240,6 +266,14 @@ static void AddOptimizationPasses(legacy::PassManagerBase &MPM, Builder.SLPVectorize = DisableSLPVectorization ? false : OptLevel > 1 && SizeLevel < 2; + // Add target-specific passes that need to run as early as possible. + if (TM) + Builder.addExtension( + PassManagerBuilder::EP_EarlyAsPossible, + [&](const PassManagerBuilder &, legacy::PassManagerBase &PM) { + TM->addEarlyAsPossiblePasses(PM); + }); + Builder.populateFunctionPassManager(FPM); Builder.populateModulePassManager(MPM); } @@ -260,6 +294,8 @@ static void AddStandardLinkPasses(legacy::PassManagerBase &PM) { // static CodeGenOpt::Level GetCodeGenOptLevel() { + if (CodeGenOptLevel.getNumOccurrences()) + return static_cast<CodeGenOpt::Level>(unsigned(CodeGenOptLevel)); if (OptLevelO1) return CodeGenOpt::Less; if (OptLevelO2) @@ -281,10 +317,9 @@ static TargetMachine* GetTargetMachine(Triple TheTriple, StringRef CPUStr, return nullptr; } - return TheTarget->createTargetMachine(TheTriple.getTriple(), - CPUStr, FeaturesStr, Options, - RelocModel, CMModel, - GetCodeGenOptLevel()); + return TheTarget->createTargetMachine(TheTriple.getTriple(), CPUStr, + FeaturesStr, Options, getRelocModel(), + CMModel, GetCodeGenOptLevel()); } #ifdef LINK_POLLY_INTO_TOOLS @@ -297,14 +332,14 @@ void initializePollyPasses(llvm::PassRegistry &Registry); // main for opt // int main(int argc, char **argv) { - sys::PrintStackTraceOnErrorSignal(); + sys::PrintStackTraceOnErrorSignal(argv[0]); llvm::PrettyStackTraceProgram X(argc, argv); // Enable debug stream buffering. EnableDebugBuffering = true; llvm_shutdown_obj Y; // Call llvm_shutdown() on exit. - LLVMContext &Context = getGlobalContext(); + LLVMContext Context; InitializeAllTargets(); InitializeAllTargetMCs(); @@ -329,7 +364,12 @@ int main(int argc, char **argv) { initializeRewriteSymbolsPass(Registry); initializeWinEHPreparePass(Registry); initializeDwarfEHPreparePass(Registry); + initializeSafeStackPass(Registry); initializeSjLjEHPreparePass(Registry); + initializePreISelIntrinsicLoweringLegacyPassPass(Registry); + initializeGlobalMergePass(Registry); + initializeInterleavedAccessPass(Registry); + initializeUnreachableBlockElimLegacyPassPass(Registry); #ifdef LINK_POLLY_INTO_TOOLS polly::initializePollyPasses(Registry); @@ -345,6 +385,13 @@ int main(int argc, char **argv) { SMDiagnostic Err; + Context.setDiscardValueNames(DiscardValueNames); + if (!DisableDITypeMap) + Context.enableDebugTypeODRUniquing(); + + if (PassRemarksWithHotness) + Context.setDiagnosticHotnessRequested(true); + // Load the input module... std::unique_ptr<Module> M = parseIRFile(InputFilename, Err, Context); @@ -491,27 +538,27 @@ int main(int argc, char **argv) { } if (OptLevelO1 && OptLevelO1.getPosition() < PassList.getPosition(i)) { - AddOptimizationPasses(Passes, *FPasses, 1, 0); + AddOptimizationPasses(Passes, *FPasses, TM.get(), 1, 0); OptLevelO1 = false; } if (OptLevelO2 && OptLevelO2.getPosition() < PassList.getPosition(i)) { - AddOptimizationPasses(Passes, *FPasses, 2, 0); + AddOptimizationPasses(Passes, *FPasses, TM.get(), 2, 0); OptLevelO2 = false; } if (OptLevelOs && OptLevelOs.getPosition() < PassList.getPosition(i)) { - AddOptimizationPasses(Passes, *FPasses, 2, 1); + AddOptimizationPasses(Passes, *FPasses, TM.get(), 2, 1); OptLevelOs = false; } if (OptLevelOz && OptLevelOz.getPosition() < PassList.getPosition(i)) { - AddOptimizationPasses(Passes, *FPasses, 2, 2); + AddOptimizationPasses(Passes, *FPasses, TM.get(), 2, 2); OptLevelOz = false; } if (OptLevelO3 && OptLevelO3.getPosition() < PassList.getPosition(i)) { - AddOptimizationPasses(Passes, *FPasses, 3, 0); + AddOptimizationPasses(Passes, *FPasses, TM.get(), 3, 0); OptLevelO3 = false; } @@ -563,21 +610,21 @@ int main(int argc, char **argv) { } if (OptLevelO1) - AddOptimizationPasses(Passes, *FPasses, 1, 0); + AddOptimizationPasses(Passes, *FPasses, TM.get(), 1, 0); if (OptLevelO2) - AddOptimizationPasses(Passes, *FPasses, 2, 0); + AddOptimizationPasses(Passes, *FPasses, TM.get(), 2, 0); if (OptLevelOs) - AddOptimizationPasses(Passes, *FPasses, 2, 1); + AddOptimizationPasses(Passes, *FPasses, TM.get(), 2, 1); if (OptLevelOz) - AddOptimizationPasses(Passes, *FPasses, 2, 2); + AddOptimizationPasses(Passes, *FPasses, TM.get(), 2, 2); if (OptLevelO3) - AddOptimizationPasses(Passes, *FPasses, 3, 0); + AddOptimizationPasses(Passes, *FPasses, TM.get(), 3, 0); - if (OptLevelO1 || OptLevelO2 || OptLevelOs || OptLevelOz || OptLevelO3) { + if (FPasses) { FPasses->doInitialization(); for (Function &F : *M) FPasses->run(F); @@ -605,10 +652,15 @@ int main(int argc, char **argv) { BOS = make_unique<raw_svector_ostream>(Buffer); OS = BOS.get(); } - if (OutputAssembly) + if (OutputAssembly) { + if (EmitSummaryIndex) + report_fatal_error("Text output is incompatible with -module-summary"); + if (EmitModuleHash) + report_fatal_error("Text output is incompatible with -module-hash"); Passes.add(createPrintModulePass(*OS, "", PreserveAssemblyUseListOrder)); - else - Passes.add(createBitcodeWriterPass(*OS, PreserveBitcodeUseListOrder)); + } else + Passes.add(createBitcodeWriterPass(*OS, PreserveBitcodeUseListOrder, + EmitSummaryIndex, EmitModuleHash)); } // Before executing passes, print the final values of the LLVM options. |