diff options
Diffstat (limited to 'contrib/llvm/tools/opt')
-rw-r--r-- | contrib/llvm/tools/opt/BreakpointPrinter.cpp | 28 | ||||
-rw-r--r-- | contrib/llvm/tools/opt/NewPMDriver.cpp | 27 | ||||
-rw-r--r-- | contrib/llvm/tools/opt/NewPMDriver.h | 8 | ||||
-rw-r--r-- | contrib/llvm/tools/opt/PassRegistry.def | 65 | ||||
-rw-r--r-- | contrib/llvm/tools/opt/Passes.cpp | 397 | ||||
-rw-r--r-- | contrib/llvm/tools/opt/Passes.h | 78 | ||||
-rw-r--r-- | contrib/llvm/tools/opt/opt.cpp | 139 |
7 files changed, 114 insertions, 628 deletions
diff --git a/contrib/llvm/tools/opt/BreakpointPrinter.cpp b/contrib/llvm/tools/opt/BreakpointPrinter.cpp index 3cbc0ae..363a7cd 100644 --- a/contrib/llvm/tools/opt/BreakpointPrinter.cpp +++ b/contrib/llvm/tools/opt/BreakpointPrinter.cpp @@ -29,18 +29,16 @@ struct BreakpointPrinter : public ModulePass { BreakpointPrinter(raw_ostream &out) : ModulePass(ID), Out(out) {} - void getContextName(DIDescriptor Context, std::string &N) { - if (Context.isNameSpace()) { - DINameSpace NS(Context); - if (!NS.getName().empty()) { - getContextName(NS.getContext(), N); - N = N + NS.getName().str() + "::"; + void getContextName(const DIScope *Context, std::string &N) { + if (auto *NS = dyn_cast<DINamespace>(Context)) { + if (!NS->getName().empty()) { + getContextName(NS->getScope(), N); + N = N + NS->getName().str() + "::"; } - } else if (Context.isType()) { - DIType TY(Context); - if (!TY.getName().empty()) { - getContextName(TY.getContext().resolve(TypeIdentifierMap), N); - N = N + TY.getName().str() + "::"; + } else if (auto *TY = dyn_cast<DIType>(Context)) { + if (!TY->getName().empty()) { + getContextName(TY->getScope().resolve(TypeIdentifierMap), N); + N = N + TY->getName().str() + "::"; } } } @@ -55,13 +53,11 @@ struct BreakpointPrinter : public ModulePass { if (NamedMDNode *NMD = M.getNamedMetadata("llvm.dbg.sp")) for (unsigned i = 0, e = NMD->getNumOperands(); i != e; ++i) { std::string Name; - DISubprogram SP(NMD->getOperand(i)); - assert((!SP || SP.isSubprogram()) && - "A MDNode in llvm.dbg.sp should be null or a DISubprogram."); + auto *SP = cast_or_null<DISubprogram>(NMD->getOperand(i)); if (!SP) continue; - getContextName(SP.getContext().resolve(TypeIdentifierMap), Name); - Name = Name + SP.getDisplayName().str(); + getContextName(SP->getScope().resolve(TypeIdentifierMap), Name); + Name = Name + SP->getDisplayName().str(); if (!Name.empty() && Processed.insert(Name).second) { Out << Name << "\n"; } diff --git a/contrib/llvm/tools/opt/NewPMDriver.cpp b/contrib/llvm/tools/opt/NewPMDriver.cpp index f215c77..3030d65 100644 --- a/contrib/llvm/tools/opt/NewPMDriver.cpp +++ b/contrib/llvm/tools/opt/NewPMDriver.cpp @@ -14,7 +14,6 @@ //===----------------------------------------------------------------------===// #include "NewPMDriver.h" -#include "Passes.h" #include "llvm/ADT/StringRef.h" #include "llvm/Analysis/CGSCCPassManager.h" #include "llvm/Bitcode/BitcodeWriterPass.h" @@ -24,9 +23,11 @@ #include "llvm/IR/Module.h" #include "llvm/IR/PassManager.h" #include "llvm/IR/Verifier.h" +#include "llvm/Passes/PassBuilder.h" #include "llvm/Support/CommandLine.h" #include "llvm/Support/ErrorHandling.h" #include "llvm/Support/ToolOutputFile.h" +#include "llvm/Target/TargetMachine.h" using namespace llvm; using namespace opt_tool; @@ -36,16 +37,21 @@ static cl::opt<bool> cl::desc("Print pass management debugging information")); bool llvm::runPassPipeline(StringRef Arg0, LLVMContext &Context, Module &M, - tool_output_file *Out, StringRef PassPipeline, - OutputKind OK, VerifierKind VK) { + TargetMachine *TM, tool_output_file *Out, + StringRef PassPipeline, OutputKind OK, + VerifierKind VK, + bool ShouldPreserveAssemblyUseListOrder, + bool ShouldPreserveBitcodeUseListOrder) { + PassBuilder PB(TM); + FunctionAnalysisManager FAM(DebugPM); CGSCCAnalysisManager CGAM(DebugPM); ModuleAnalysisManager MAM(DebugPM); // Register all the basic analyses with the managers. - registerModuleAnalyses(MAM); - registerCGSCCAnalyses(CGAM); - registerFunctionAnalyses(FAM); + PB.registerModuleAnalyses(MAM); + PB.registerCGSCCAnalyses(CGAM); + PB.registerFunctionAnalyses(FAM); // Cross register the analysis managers through their proxies. MAM.registerPass(FunctionAnalysisManagerModuleProxy(FAM)); @@ -59,7 +65,8 @@ bool llvm::runPassPipeline(StringRef Arg0, LLVMContext &Context, Module &M, if (VK > VK_NoVerifier) MPM.addPass(VerifierPass()); - if (!parsePassPipeline(MPM, PassPipeline, VK == VK_VerifyEachPass, DebugPM)) { + if (!PB.parsePassPipeline(MPM, PassPipeline, VK == VK_VerifyEachPass, + DebugPM)) { errs() << Arg0 << ": unable to parse pass pipeline description.\n"; return false; } @@ -72,10 +79,12 @@ bool llvm::runPassPipeline(StringRef Arg0, LLVMContext &Context, Module &M, case OK_NoOutput: break; // No output pass needed. case OK_OutputAssembly: - MPM.addPass(PrintModulePass(Out->os())); + MPM.addPass( + PrintModulePass(Out->os(), "", ShouldPreserveAssemblyUseListOrder)); break; case OK_OutputBitcode: - MPM.addPass(BitcodeWriterPass(Out->os())); + MPM.addPass( + BitcodeWriterPass(Out->os(), ShouldPreserveBitcodeUseListOrder)); break; } diff --git a/contrib/llvm/tools/opt/NewPMDriver.h b/contrib/llvm/tools/opt/NewPMDriver.h index f977bac..349a7b1 100644 --- a/contrib/llvm/tools/opt/NewPMDriver.h +++ b/contrib/llvm/tools/opt/NewPMDriver.h @@ -26,6 +26,7 @@ namespace llvm { class LLVMContext; class Module; +class TargetMachine; class tool_output_file; namespace opt_tool { @@ -48,8 +49,11 @@ enum VerifierKind { /// file. It's interface is consequentially somewhat ad-hoc, but will go away /// when the transition finishes. bool runPassPipeline(StringRef Arg0, LLVMContext &Context, Module &M, - tool_output_file *Out, StringRef PassPipeline, - opt_tool::OutputKind OK, opt_tool::VerifierKind VK); + TargetMachine *TM, tool_output_file *Out, + StringRef PassPipeline, opt_tool::OutputKind OK, + opt_tool::VerifierKind VK, + bool ShouldPreserveAssemblyUseListOrder, + bool ShouldPreserveBitcodeUseListOrder); } #endif diff --git a/contrib/llvm/tools/opt/PassRegistry.def b/contrib/llvm/tools/opt/PassRegistry.def deleted file mode 100644 index c98de60..0000000 --- a/contrib/llvm/tools/opt/PassRegistry.def +++ /dev/null @@ -1,65 +0,0 @@ -//===- PassRegistry.def - Registry of passes --------------------*- C++ -*-===// -// -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// -// -// This file is used as the registry of passes that are part of the core LLVM -// libraries. This file describes both transformation passes and analyses -// Analyses are registered while transformation passes have names registered -// that can be used when providing a textual pass pipeline. -// -//===----------------------------------------------------------------------===// - -// NOTE: NO INCLUDE GUARD DESIRED! - -#ifndef MODULE_ANALYSIS -#define MODULE_ANALYSIS(NAME, CREATE_PASS) -#endif -MODULE_ANALYSIS("lcg", LazyCallGraphAnalysis()) -MODULE_ANALYSIS("no-op-module", NoOpModuleAnalysis()) -#undef MODULE_ANALYSIS - -#ifndef MODULE_PASS -#define MODULE_PASS(NAME, CREATE_PASS) -#endif -MODULE_PASS("invalidate<all>", InvalidateAllAnalysesPass()) -MODULE_PASS("no-op-module", NoOpModulePass()) -MODULE_PASS("print", PrintModulePass(dbgs())) -MODULE_PASS("print-cg", LazyCallGraphPrinterPass(dbgs())) -MODULE_PASS("verify", VerifierPass()) -#undef MODULE_PASS - -#ifndef CGSCC_ANALYSIS -#define CGSCC_ANALYSIS(NAME, CREATE_PASS) -#endif -CGSCC_ANALYSIS("no-op-cgscc", NoOpCGSCCAnalysis()) -#undef CGSCC_ANALYSIS - -#ifndef CGSCC_PASS -#define CGSCC_PASS(NAME, CREATE_PASS) -#endif -CGSCC_PASS("invalidate<all>", InvalidateAllAnalysesPass()) -CGSCC_PASS("no-op-cgscc", NoOpCGSCCPass()) -#undef CGSCC_PASS - -#ifndef FUNCTION_ANALYSIS -#define FUNCTION_ANALYSIS(NAME, CREATE_PASS) -#endif -FUNCTION_ANALYSIS("domtree", DominatorTreeAnalysis()) -FUNCTION_ANALYSIS("no-op-function", NoOpFunctionAnalysis()) -#undef FUNCTION_ANALYSIS - -#ifndef FUNCTION_PASS -#define FUNCTION_PASS(NAME, CREATE_PASS) -#endif -FUNCTION_PASS("invalidate<all>", InvalidateAllAnalysesPass()) -FUNCTION_PASS("no-op-function", NoOpFunctionPass()) -FUNCTION_PASS("print", PrintFunctionPass(dbgs())) -FUNCTION_PASS("print<domtree>", DominatorTreePrinterPass(dbgs())) -FUNCTION_PASS("verify", VerifierPass()) -FUNCTION_PASS("verify<domtree>", DominatorTreeVerifierPass()) -#undef FUNCTION_PASS diff --git a/contrib/llvm/tools/opt/Passes.cpp b/contrib/llvm/tools/opt/Passes.cpp deleted file mode 100644 index 518112a..0000000 --- a/contrib/llvm/tools/opt/Passes.cpp +++ /dev/null @@ -1,397 +0,0 @@ -//===- Passes.cpp - Parsing, selection, and running of passes -------------===// -// -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// -/// \file -/// -/// This file provides the infrastructure to parse and build a custom pass -/// manager based on a commandline flag. It also provides helpers to aid in -/// analyzing, debugging, and testing pass structures. -/// -//===----------------------------------------------------------------------===// - -#include "Passes.h" -#include "llvm/Analysis/CGSCCPassManager.h" -#include "llvm/Analysis/LazyCallGraph.h" -#include "llvm/IR/Dominators.h" -#include "llvm/IR/IRPrintingPasses.h" -#include "llvm/IR/PassManager.h" -#include "llvm/IR/Verifier.h" -#include "llvm/Support/Debug.h" - -using namespace llvm; - -namespace { - -/// \brief No-op module pass which does nothing. -struct NoOpModulePass { - PreservedAnalyses run(Module &M) { return PreservedAnalyses::all(); } - static StringRef name() { return "NoOpModulePass"; } -}; - -/// \brief No-op module analysis. -struct NoOpModuleAnalysis { - struct Result {}; - Result run(Module &) { return Result(); } - static StringRef name() { return "NoOpModuleAnalysis"; } - static void *ID() { return (void *)&PassID; } -private: - static char PassID; -}; - -char NoOpModuleAnalysis::PassID; - -/// \brief No-op CGSCC pass which does nothing. -struct NoOpCGSCCPass { - PreservedAnalyses run(LazyCallGraph::SCC &C) { - return PreservedAnalyses::all(); - } - static StringRef name() { return "NoOpCGSCCPass"; } -}; - -/// \brief No-op CGSCC analysis. -struct NoOpCGSCCAnalysis { - struct Result {}; - Result run(LazyCallGraph::SCC &) { return Result(); } - static StringRef name() { return "NoOpCGSCCAnalysis"; } - static void *ID() { return (void *)&PassID; } -private: - static char PassID; -}; - -char NoOpCGSCCAnalysis::PassID; - -/// \brief No-op function pass which does nothing. -struct NoOpFunctionPass { - PreservedAnalyses run(Function &F) { return PreservedAnalyses::all(); } - static StringRef name() { return "NoOpFunctionPass"; } -}; - -/// \brief No-op function analysis. -struct NoOpFunctionAnalysis { - struct Result {}; - Result run(Function &) { return Result(); } - static StringRef name() { return "NoOpFunctionAnalysis"; } - static void *ID() { return (void *)&PassID; } -private: - static char PassID; -}; - -char NoOpFunctionAnalysis::PassID; - -} // End anonymous namespace. - -void llvm::registerModuleAnalyses(ModuleAnalysisManager &MAM) { -#define MODULE_ANALYSIS(NAME, CREATE_PASS) \ - MAM.registerPass(CREATE_PASS); -#include "PassRegistry.def" -} - -void llvm::registerCGSCCAnalyses(CGSCCAnalysisManager &CGAM) { -#define CGSCC_ANALYSIS(NAME, CREATE_PASS) \ - CGAM.registerPass(CREATE_PASS); -#include "PassRegistry.def" -} - -void llvm::registerFunctionAnalyses(FunctionAnalysisManager &FAM) { -#define FUNCTION_ANALYSIS(NAME, CREATE_PASS) \ - FAM.registerPass(CREATE_PASS); -#include "PassRegistry.def" -} - -#ifndef NDEBUG -static bool isModulePassName(StringRef Name) { -#define MODULE_PASS(NAME, CREATE_PASS) if (Name == NAME) return true; -#define MODULE_ANALYSIS(NAME, CREATE_PASS) \ - if (Name == "require<" NAME ">" || Name == "invalidate<" NAME ">") \ - return true; -#include "PassRegistry.def" - - return false; -} -#endif - -static bool isCGSCCPassName(StringRef Name) { -#define CGSCC_PASS(NAME, CREATE_PASS) if (Name == NAME) return true; -#define CGSCC_ANALYSIS(NAME, CREATE_PASS) \ - if (Name == "require<" NAME ">" || Name == "invalidate<" NAME ">") \ - return true; -#include "PassRegistry.def" - - return false; -} - -static bool isFunctionPassName(StringRef Name) { -#define FUNCTION_PASS(NAME, CREATE_PASS) if (Name == NAME) return true; -#define FUNCTION_ANALYSIS(NAME, CREATE_PASS) \ - if (Name == "require<" NAME ">" || Name == "invalidate<" NAME ">") \ - return true; -#include "PassRegistry.def" - - return false; -} - -static bool parseModulePassName(ModulePassManager &MPM, StringRef Name) { -#define MODULE_PASS(NAME, CREATE_PASS) \ - if (Name == NAME) { \ - MPM.addPass(CREATE_PASS); \ - return true; \ - } -#define MODULE_ANALYSIS(NAME, CREATE_PASS) \ - if (Name == "require<" NAME ">") { \ - MPM.addPass(RequireAnalysisPass<decltype(CREATE_PASS)>()); \ - return true; \ - } \ - if (Name == "invalidate<" NAME ">") { \ - MPM.addPass(InvalidateAnalysisPass<decltype(CREATE_PASS)>()); \ - return true; \ - } -#include "PassRegistry.def" - - return false; -} - -static bool parseCGSCCPassName(CGSCCPassManager &CGPM, StringRef Name) { -#define CGSCC_PASS(NAME, CREATE_PASS) \ - if (Name == NAME) { \ - CGPM.addPass(CREATE_PASS); \ - return true; \ - } -#define CGSCC_ANALYSIS(NAME, CREATE_PASS) \ - if (Name == "require<" NAME ">") { \ - CGPM.addPass(RequireAnalysisPass<decltype(CREATE_PASS)>()); \ - return true; \ - } \ - if (Name == "invalidate<" NAME ">") { \ - CGPM.addPass(InvalidateAnalysisPass<decltype(CREATE_PASS)>()); \ - return true; \ - } -#include "PassRegistry.def" - - return false; -} - -static bool parseFunctionPassName(FunctionPassManager &FPM, StringRef Name) { -#define FUNCTION_PASS(NAME, CREATE_PASS) \ - if (Name == NAME) { \ - FPM.addPass(CREATE_PASS); \ - return true; \ - } -#define FUNCTION_ANALYSIS(NAME, CREATE_PASS) \ - if (Name == "require<" NAME ">") { \ - FPM.addPass(RequireAnalysisPass<decltype(CREATE_PASS)>()); \ - return true; \ - } \ - if (Name == "invalidate<" NAME ">") { \ - FPM.addPass(InvalidateAnalysisPass<decltype(CREATE_PASS)>()); \ - return true; \ - } -#include "PassRegistry.def" - - return false; -} - -static bool parseFunctionPassPipeline(FunctionPassManager &FPM, - StringRef &PipelineText, - bool VerifyEachPass, bool DebugLogging) { - for (;;) { - // Parse nested pass managers by recursing. - if (PipelineText.startswith("function(")) { - FunctionPassManager NestedFPM(DebugLogging); - - // Parse the inner pipeline inte the nested manager. - PipelineText = PipelineText.substr(strlen("function(")); - if (!parseFunctionPassPipeline(NestedFPM, PipelineText, VerifyEachPass, - DebugLogging) || - PipelineText.empty()) - return false; - assert(PipelineText[0] == ')'); - PipelineText = PipelineText.substr(1); - - // Add the nested pass manager with the appropriate adaptor. - FPM.addPass(std::move(NestedFPM)); - } else { - // Otherwise try to parse a pass name. - size_t End = PipelineText.find_first_of(",)"); - if (!parseFunctionPassName(FPM, PipelineText.substr(0, End))) - return false; - if (VerifyEachPass) - FPM.addPass(VerifierPass()); - - PipelineText = PipelineText.substr(End); - } - - if (PipelineText.empty() || PipelineText[0] == ')') - return true; - - assert(PipelineText[0] == ','); - PipelineText = PipelineText.substr(1); - } -} - -static bool parseCGSCCPassPipeline(CGSCCPassManager &CGPM, - StringRef &PipelineText, bool VerifyEachPass, - bool DebugLogging) { - for (;;) { - // Parse nested pass managers by recursing. - if (PipelineText.startswith("cgscc(")) { - CGSCCPassManager NestedCGPM(DebugLogging); - - // Parse the inner pipeline into the nested manager. - PipelineText = PipelineText.substr(strlen("cgscc(")); - if (!parseCGSCCPassPipeline(NestedCGPM, PipelineText, VerifyEachPass, - DebugLogging) || - PipelineText.empty()) - return false; - assert(PipelineText[0] == ')'); - PipelineText = PipelineText.substr(1); - - // Add the nested pass manager with the appropriate adaptor. - CGPM.addPass(std::move(NestedCGPM)); - } else if (PipelineText.startswith("function(")) { - FunctionPassManager NestedFPM(DebugLogging); - - // Parse the inner pipeline inte the nested manager. - PipelineText = PipelineText.substr(strlen("function(")); - if (!parseFunctionPassPipeline(NestedFPM, PipelineText, VerifyEachPass, - DebugLogging) || - PipelineText.empty()) - return false; - assert(PipelineText[0] == ')'); - PipelineText = PipelineText.substr(1); - - // Add the nested pass manager with the appropriate adaptor. - CGPM.addPass(createCGSCCToFunctionPassAdaptor(std::move(NestedFPM))); - } else { - // Otherwise try to parse a pass name. - size_t End = PipelineText.find_first_of(",)"); - if (!parseCGSCCPassName(CGPM, PipelineText.substr(0, End))) - return false; - // FIXME: No verifier support for CGSCC passes! - - PipelineText = PipelineText.substr(End); - } - - if (PipelineText.empty() || PipelineText[0] == ')') - return true; - - assert(PipelineText[0] == ','); - PipelineText = PipelineText.substr(1); - } -} - -static bool parseModulePassPipeline(ModulePassManager &MPM, - StringRef &PipelineText, - bool VerifyEachPass, bool DebugLogging) { - for (;;) { - // Parse nested pass managers by recursing. - if (PipelineText.startswith("module(")) { - ModulePassManager NestedMPM(DebugLogging); - - // Parse the inner pipeline into the nested manager. - PipelineText = PipelineText.substr(strlen("module(")); - if (!parseModulePassPipeline(NestedMPM, PipelineText, VerifyEachPass, - DebugLogging) || - PipelineText.empty()) - return false; - assert(PipelineText[0] == ')'); - PipelineText = PipelineText.substr(1); - - // Now add the nested manager as a module pass. - MPM.addPass(std::move(NestedMPM)); - } else if (PipelineText.startswith("cgscc(")) { - CGSCCPassManager NestedCGPM(DebugLogging); - - // Parse the inner pipeline inte the nested manager. - PipelineText = PipelineText.substr(strlen("cgscc(")); - if (!parseCGSCCPassPipeline(NestedCGPM, PipelineText, VerifyEachPass, - DebugLogging) || - PipelineText.empty()) - return false; - assert(PipelineText[0] == ')'); - PipelineText = PipelineText.substr(1); - - // Add the nested pass manager with the appropriate adaptor. - MPM.addPass( - createModuleToPostOrderCGSCCPassAdaptor(std::move(NestedCGPM))); - } else if (PipelineText.startswith("function(")) { - FunctionPassManager NestedFPM(DebugLogging); - - // Parse the inner pipeline inte the nested manager. - PipelineText = PipelineText.substr(strlen("function(")); - if (!parseFunctionPassPipeline(NestedFPM, PipelineText, VerifyEachPass, - DebugLogging) || - PipelineText.empty()) - return false; - assert(PipelineText[0] == ')'); - PipelineText = PipelineText.substr(1); - - // Add the nested pass manager with the appropriate adaptor. - MPM.addPass(createModuleToFunctionPassAdaptor(std::move(NestedFPM))); - } else { - // Otherwise try to parse a pass name. - size_t End = PipelineText.find_first_of(",)"); - if (!parseModulePassName(MPM, PipelineText.substr(0, End))) - return false; - if (VerifyEachPass) - MPM.addPass(VerifierPass()); - - PipelineText = PipelineText.substr(End); - } - - if (PipelineText.empty() || PipelineText[0] == ')') - return true; - - assert(PipelineText[0] == ','); - PipelineText = PipelineText.substr(1); - } -} - -// Primary pass pipeline description parsing routine. -// FIXME: Should this routine accept a TargetMachine or require the caller to -// pre-populate the analysis managers with target-specific stuff? -bool llvm::parsePassPipeline(ModulePassManager &MPM, StringRef PipelineText, - bool VerifyEachPass, bool DebugLogging) { - // By default, try to parse the pipeline as-if it were within an implicit - // 'module(...)' pass pipeline. If this will parse at all, it needs to - // consume the entire string. - if (parseModulePassPipeline(MPM, PipelineText, VerifyEachPass, DebugLogging)) - return PipelineText.empty(); - - // This isn't parsable as a module pipeline, look for the end of a pass name - // and directly drop down to that layer. - StringRef FirstName = - PipelineText.substr(0, PipelineText.find_first_of(",)")); - assert(!isModulePassName(FirstName) && - "Already handled all module pipeline options."); - - // If this looks like a CGSCC pass, parse the whole thing as a CGSCC - // pipeline. - if (isCGSCCPassName(FirstName)) { - CGSCCPassManager CGPM(DebugLogging); - if (!parseCGSCCPassPipeline(CGPM, PipelineText, VerifyEachPass, - DebugLogging) || - !PipelineText.empty()) - return false; - MPM.addPass(createModuleToPostOrderCGSCCPassAdaptor(std::move(CGPM))); - return true; - } - - // Similarly, if this looks like a Function pass, parse the whole thing as - // a Function pipelien. - if (isFunctionPassName(FirstName)) { - FunctionPassManager FPM(DebugLogging); - if (!parseFunctionPassPipeline(FPM, PipelineText, VerifyEachPass, - DebugLogging) || - !PipelineText.empty()) - return false; - MPM.addPass(createModuleToFunctionPassAdaptor(std::move(FPM))); - return true; - } - - return false; -} diff --git a/contrib/llvm/tools/opt/Passes.h b/contrib/llvm/tools/opt/Passes.h deleted file mode 100644 index 623da9f..0000000 --- a/contrib/llvm/tools/opt/Passes.h +++ /dev/null @@ -1,78 +0,0 @@ -//===- Passes.h - Parsing, selection, and running of passes -----*- C++ -*-===// -// -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// -/// \file -/// -/// Interfaces for producing common pass manager configurations and parsing -/// textual pass specifications. -/// -//===----------------------------------------------------------------------===// - -#ifndef LLVM_TOOLS_OPT_PASSES_H -#define LLVM_TOOLS_OPT_PASSES_H - -#include "llvm/ADT/StringRef.h" -#include "llvm/Analysis/CGSCCPassManager.h" -#include "llvm/IR/PassManager.h" - -namespace llvm { - -/// \brief Registers all available module analysis passes. -/// -/// This is an interface that can be used to populate a \c -/// ModuleAnalysisManager with all registered module analyses. Callers can -/// still manually register any additional analyses. -void registerModuleAnalyses(ModuleAnalysisManager &MAM); - -/// \brief Registers all available CGSCC analysis passes. -/// -/// This is an interface that can be used to populate a \c CGSCCAnalysisManager -/// with all registered CGSCC analyses. Callers can still manually register any -/// additional analyses. -void registerCGSCCAnalyses(CGSCCAnalysisManager &CGAM); - -/// \brief Registers all available function analysis passes. -/// -/// This is an interface that can be used to populate a \c -/// FunctionAnalysisManager with all registered function analyses. Callers can -/// still manually register any additional analyses. -void registerFunctionAnalyses(FunctionAnalysisManager &FAM); - -/// \brief Parse a textual pass pipeline description into a \c ModulePassManager. -/// -/// The format of the textual pass pipeline description looks something like: -/// -/// module(function(instcombine,sroa),dce,cgscc(inliner,function(...)),...) -/// -/// Pass managers have ()s describing the nest structure of passes. All passes -/// are comma separated. As a special shortcut, if the very first pass is not -/// a module pass (as a module pass manager is), this will automatically form -/// the shortest stack of pass managers that allow inserting that first pass. -/// So, assuming function passes 'fpassN', CGSCC passes 'cgpassN', and loop passes -/// 'lpassN', all of these are valid: -/// -/// fpass1,fpass2,fpass3 -/// cgpass1,cgpass2,cgpass3 -/// lpass1,lpass2,lpass3 -/// -/// And they are equivalent to the following (resp.): -/// -/// module(function(fpass1,fpass2,fpass3)) -/// module(cgscc(cgpass1,cgpass2,cgpass3)) -/// module(function(loop(lpass1,lpass2,lpass3))) -/// -/// This shortcut is especially useful for debugging and testing small pass -/// combinations. Note that these shortcuts don't introduce any other magic. If -/// the sequence of passes aren't all the exact same kind of pass, it will be -/// an error. You cannot mix different levels implicitly, you must explicitly -/// form a pass manager in which to nest passes. -bool parsePassPipeline(ModulePassManager &MPM, StringRef PipelineText, - bool VerifyEachPass = true, bool DebugLogging = false); -} - -#endif diff --git a/contrib/llvm/tools/opt/opt.cpp b/contrib/llvm/tools/opt/opt.cpp index 9867589..55426e7 100644 --- a/contrib/llvm/tools/opt/opt.cpp +++ b/contrib/llvm/tools/opt/opt.cpp @@ -20,9 +20,12 @@ #include "llvm/Analysis/CallGraphSCCPass.h" #include "llvm/Analysis/LoopPass.h" #include "llvm/Analysis/RegionPass.h" +#include "llvm/Analysis/TargetLibraryInfo.h" +#include "llvm/Analysis/TargetTransformInfo.h" #include "llvm/Bitcode/BitcodeWriterPass.h" #include "llvm/CodeGen/CommandFlags.h" #include "llvm/IR/DataLayout.h" +#include "llvm/IR/DebugInfo.h" #include "llvm/IR/IRPrintingPasses.h" #include "llvm/IR/LLVMContext.h" #include "llvm/IR/LegacyPassNameParser.h" @@ -33,9 +36,10 @@ #include "llvm/LinkAllIR.h" #include "llvm/LinkAllPasses.h" #include "llvm/MC/SubtargetFeature.h" -#include "llvm/PassManager.h" +#include "llvm/IR/LegacyPassManager.h" #include "llvm/Support/Debug.h" #include "llvm/Support/FileSystem.h" +#include "llvm/Support/Host.h" #include "llvm/Support/ManagedStatic.h" #include "llvm/Support/PluginLoader.h" #include "llvm/Support/PrettyStackTrace.h" @@ -45,7 +49,6 @@ #include "llvm/Support/TargetRegistry.h" #include "llvm/Support/TargetSelect.h" #include "llvm/Support/ToolOutputFile.h" -#include "llvm/Target/TargetLibraryInfo.h" #include "llvm/Target/TargetMachine.h" #include "llvm/Transforms/IPO/PassManagerBuilder.h" #include <algorithm> @@ -177,27 +180,33 @@ DefaultDataLayout("default-data-layout", cl::desc("data layout string to use if not specified by module"), cl::value_desc("layout-string"), cl::init("")); +static cl::opt<bool> PreserveBitcodeUseListOrder( + "preserve-bc-uselistorder", + cl::desc("Preserve use-list order when writing LLVM bitcode."), + cl::init(true), cl::Hidden); +static cl::opt<bool> PreserveAssemblyUseListOrder( + "preserve-ll-uselistorder", + cl::desc("Preserve use-list order when writing LLVM assembly."), + cl::init(false), cl::Hidden); -static inline void addPass(PassManagerBase &PM, Pass *P) { +static inline void addPass(legacy::PassManagerBase &PM, Pass *P) { // Add the pass to the pass manager... PM.add(P); // If we are verifying all of the intermediate steps, add the verifier... - if (VerifyEach) { + if (VerifyEach) PM.add(createVerifierPass()); - PM.add(createDebugInfoVerifierPass()); - } } /// This routine adds optimization passes based on selected optimization level, /// OptLevel. /// /// OptLevel - Optimization Level -static void AddOptimizationPasses(PassManagerBase &MPM,FunctionPassManager &FPM, +static void AddOptimizationPasses(legacy::PassManagerBase &MPM, + legacy::FunctionPassManager &FPM, unsigned OptLevel, unsigned SizeLevel) { - FPM.add(createVerifierPass()); // Verify that input is correct - MPM.add(createDebugInfoVerifierPass()); // Verify that debug info is correct + FPM.add(createVerifierPass()); // Verify that input is correct PassManagerBuilder Builder; Builder.OptLevel = OptLevel; @@ -229,10 +238,9 @@ static void AddOptimizationPasses(PassManagerBase &MPM,FunctionPassManager &FPM, Builder.populateModulePassManager(MPM); } -static void AddStandardLinkPasses(PassManagerBase &PM) { +static void AddStandardLinkPasses(legacy::PassManagerBase &PM) { PassManagerBuilder Builder; Builder.VerifyInput = true; - Builder.StripDebug = StripDebug; if (DisableOptimizations) Builder.OptLevel = 0; @@ -245,7 +253,7 @@ static void AddStandardLinkPasses(PassManagerBase &PM) { // CodeGen-related helper functions. // -CodeGenOpt::Level GetCodeGenOptLevel() { +static CodeGenOpt::Level GetCodeGenOptLevel() { if (OptLevelO1) return CodeGenOpt::Less; if (OptLevelO2) @@ -256,7 +264,9 @@ CodeGenOpt::Level GetCodeGenOptLevel() { } // Returns the TargetMachine instance or zero if no triple is provided. -static TargetMachine* GetTargetMachine(Triple TheTriple) { +static TargetMachine* GetTargetMachine(Triple TheTriple, StringRef CPUStr, + StringRef FeaturesStr, + const TargetOptions &Options) { std::string Error; const Target *TheTarget = TargetRegistry::lookupTarget(MArch, TheTriple, Error); @@ -265,18 +275,8 @@ static TargetMachine* GetTargetMachine(Triple TheTriple) { return nullptr; } - // Package up features to be passed to target/subtarget - std::string FeaturesStr; - if (MAttrs.size()) { - SubtargetFeatures Features; - for (unsigned i = 0; i != MAttrs.size(); ++i) - Features.AddFeature(MAttrs[i]); - FeaturesStr = Features.getString(); - } - return TheTarget->createTargetMachine(TheTriple.getTriple(), - MCPU, FeaturesStr, - InitTargetOptionsFromCodeGenFlags(), + CPUStr, FeaturesStr, Options, RelocModel, CMModel, GetCodeGenOptLevel()); } @@ -322,6 +322,8 @@ int main(int argc, char **argv) { initializeCodeGenPreparePass(Registry); initializeAtomicExpandPass(Registry); initializeRewriteSymbolsPass(Registry); + initializeWinEHPreparePass(Registry); + initializeDwarfEHPreparePass(Registry); #ifdef LINK_POLLY_INTO_TOOLS polly::initializePollyPasses(Registry); @@ -345,6 +347,19 @@ int main(int argc, char **argv) { return 1; } + // Strip debug info before running the verifier. + if (StripDebug) + StripDebugInfo(*M); + + // Immediately run the verifier to catch any problems before starting up the + // pass pipelines. Otherwise we can crash on broken code during + // doInitialization(). + if (!NoVerify && verifyModule(*M, &errs())) { + errs() << argv[0] << ": " << InputFilename + << ": error: input module is broken!\n"; + return 1; + } + // If we are supposed to override the target triple, do so now. if (!TargetTriple.empty()) M->setTargetTriple(Triple::normalize(TargetTriple)); @@ -368,6 +383,23 @@ int main(int argc, char **argv) { } } + Triple ModuleTriple(M->getTargetTriple()); + std::string CPUStr, FeaturesStr; + TargetMachine *Machine = nullptr; + const TargetOptions Options = InitTargetOptionsFromCodeGenFlags(); + + if (ModuleTriple.getArch()) { + CPUStr = getCPUStr(); + FeaturesStr = getFeaturesStr(); + Machine = GetTargetMachine(ModuleTriple, CPUStr, FeaturesStr, Options); + } + + std::unique_ptr<TargetMachine> TM(Machine); + + // Override function attributes based on CPUStr, FeaturesStr, and command line + // flags. + setFunctionAttributes(CPUStr, FeaturesStr, *M); + // If the output is set to be emitted to standard out, and standard out is a // console, print out a warning message and refuse to do it. We don't // impress anyone by spewing tons of binary goo to a terminal. @@ -389,8 +421,9 @@ 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, Out.get(), PassPipeline, - OK, VK) + return runPassPipeline(argv[0], Context, *M, TM.get(), Out.get(), + PassPipeline, OK, VK, PreserveAssemblyUseListOrder, + PreserveBitcodeUseListOrder) ? 0 : 1; } @@ -398,44 +431,31 @@ int main(int argc, char **argv) { // Create a PassManager to hold and optimize the collection of passes we are // about to build. // - PassManager Passes; + legacy::PassManager Passes; // Add an appropriate TargetLibraryInfo pass for the module's triple. - TargetLibraryInfo *TLI = new TargetLibraryInfo(Triple(M->getTargetTriple())); + TargetLibraryInfoImpl TLII(ModuleTriple); // The -disable-simplify-libcalls flag actually disables all builtin optzns. if (DisableSimplifyLibCalls) - TLI->disableAllFunctions(); - Passes.add(TLI); + TLII.disableAllFunctions(); + Passes.add(new TargetLibraryInfoWrapperPass(TLII)); // Add an appropriate DataLayout instance for this module. - const DataLayout *DL = M->getDataLayout(); - if (!DL && !DefaultDataLayout.empty()) { + const DataLayout &DL = M->getDataLayout(); + if (DL.isDefault() && !DefaultDataLayout.empty()) { M->setDataLayout(DefaultDataLayout); - DL = M->getDataLayout(); } - if (DL) - Passes.add(new DataLayoutPass()); - - Triple ModuleTriple(M->getTargetTriple()); - TargetMachine *Machine = nullptr; - if (ModuleTriple.getArch()) - Machine = GetTargetMachine(Triple(ModuleTriple)); - std::unique_ptr<TargetMachine> TM(Machine); - // Add internal analysis passes from the target machine. - if (TM) - TM->addAnalysisPasses(Passes); + Passes.add(createTargetTransformInfoWrapperPass(TM ? TM->getTargetIRAnalysis() + : TargetIRAnalysis())); - std::unique_ptr<FunctionPassManager> FPasses; + std::unique_ptr<legacy::FunctionPassManager> FPasses; if (OptLevelO1 || OptLevelO2 || OptLevelOs || OptLevelOz || OptLevelO3) { - FPasses.reset(new FunctionPassManager(M.get())); - if (DL) - FPasses->add(new DataLayoutPass()); - if (TM) - TM->addAnalysisPasses(*FPasses); - + FPasses.reset(new legacy::FunctionPassManager(M.get())); + FPasses->add(createTargetTransformInfoWrapperPass( + TM ? TM->getTargetIRAnalysis() : TargetIRAnalysis())); } if (PrintBreakpoints) { @@ -456,10 +476,6 @@ int main(int argc, char **argv) { NoOutput = true; } - // 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) { if (StandardLinkOpts && @@ -531,7 +547,8 @@ int main(int argc, char **argv) { } if (PrintEachXForm) - Passes.add(createPrintModulePass(errs())); + Passes.add( + createPrintModulePass(errs(), "", PreserveAssemblyUseListOrder)); } if (StandardLinkOpts) { @@ -562,17 +579,17 @@ int main(int argc, char **argv) { } // Check that the module is well formed on completion of optimization - if (!NoVerify && !VerifyEach) { + if (!NoVerify && !VerifyEach) Passes.add(createVerifierPass()); - Passes.add(createDebugInfoVerifierPass()); - } // Write bitcode or assembly to the output as the last step... if (!NoOutput && !AnalyzeOnly) { if (OutputAssembly) - Passes.add(createPrintModulePass(Out->os())); + Passes.add( + createPrintModulePass(Out->os(), "", PreserveAssemblyUseListOrder)); else - Passes.add(createBitcodeWriterPass(Out->os())); + Passes.add( + createBitcodeWriterPass(Out->os(), PreserveBitcodeUseListOrder)); } // Before executing passes, print the final values of the LLVM options. |