diff --git a/tools/opt/Passes.h b/include/llvm/Passes/PassBuilder.h similarity index 91% rename from tools/opt/Passes.h rename to include/llvm/Passes/PassBuilder.h index d3cb628469b..1e605e37417 100644 --- a/tools/opt/Passes.h +++ b/include/llvm/Passes/PassBuilder.h @@ -1,4 +1,4 @@ -//===- Passes.h - Utilities for manipulating all passes ---------*- C++ -*-===// +//===- Parsing, selection, and construction of pass pipelines --*- C++ -*--===// // // The LLVM Compiler Infrastructure // @@ -8,13 +8,13 @@ //===----------------------------------------------------------------------===// /// \file /// -/// Interfaces for registering passes, producing common pass manager +/// Interfaces for registering analysis passes, producing common pass manager /// configurations, and parsing of pass pipelines. /// //===----------------------------------------------------------------------===// -#ifndef LLVM_TOOLS_OPT_PASSES_H -#define LLVM_TOOLS_OPT_PASSES_H +#ifndef LLVM_PASSES_PASSBUILDER_H +#define LLVM_PASSES_PASSBUILDER_H #include "llvm/ADT/StringRef.h" #include "llvm/Analysis/CGSCCPassManager.h" @@ -23,17 +23,17 @@ namespace llvm { class TargetMachine; -/// \brief This class provides access to all of LLVM's passes. +/// \brief This class provides access to building LLVM's passes. /// /// It's members provide the baseline state available to passes during their /// construction. The \c PassRegistry.def file specifies how to construct all /// of the built-in passes, and those may reference these members during /// construction. -class Passes { +class PassBuilder { TargetMachine *TM; public: - explicit Passes(TargetMachine *TM = nullptr) : TM(TM) {} + explicit PassBuilder(TargetMachine *TM = nullptr) : TM(TM) {} /// \brief Registers all available module analysis passes. /// diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index 8ab2d6e9de7..ce10998768d 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -18,3 +18,4 @@ add_subdirectory(AsmParser) add_subdirectory(LineEditor) add_subdirectory(ProfileData) add_subdirectory(Fuzzer) +add_subdirectory(Passes) diff --git a/lib/LLVMBuild.txt b/lib/LLVMBuild.txt index ad5b22b914e..bc2448da0ed 100644 --- a/lib/LLVMBuild.txt +++ b/lib/LLVMBuild.txt @@ -16,7 +16,7 @@ ;===------------------------------------------------------------------------===; [common] -subdirectories = Analysis AsmParser Bitcode CodeGen DebugInfo ExecutionEngine LineEditor Linker IR IRReader LTO MC Object Option ProfileData Support TableGen Target Transforms +subdirectories = Analysis AsmParser Bitcode CodeGen DebugInfo ExecutionEngine LineEditor Linker IR IRReader LTO MC Object Option Passes ProfileData Support TableGen Target Transforms [component_0] type = Group diff --git a/lib/Makefile b/lib/Makefile index 52fdaaf7e0f..f75ca584dbe 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -12,6 +12,6 @@ include $(LEVEL)/Makefile.config PARALLEL_DIRS := IR AsmParser Bitcode Analysis Transforms CodeGen Target \ ExecutionEngine Linker LTO MC Object Option DebugInfo \ - IRReader LineEditor ProfileData + IRReader LineEditor ProfileData Passes include $(LEVEL)/Makefile.common diff --git a/lib/Passes/CMakeLists.txt b/lib/Passes/CMakeLists.txt new file mode 100644 index 00000000000..3d6b3fbf3c7 --- /dev/null +++ b/lib/Passes/CMakeLists.txt @@ -0,0 +1,6 @@ +add_llvm_library(LLVMPasses + PassBuilder.cpp + + ADDITIONAL_HEADER_DIRS + ${LLVM_MAIN_INCLUDE_DIR}/llvm/Passes + ) diff --git a/lib/Passes/LLVMBuild.txt b/lib/Passes/LLVMBuild.txt new file mode 100644 index 00000000000..3063fe3e5da --- /dev/null +++ b/lib/Passes/LLVMBuild.txt @@ -0,0 +1,22 @@ +;===- ./lib/Passes/LLVMBuild.txt -------------------------------*- Conf -*--===; +; +; The LLVM Compiler Infrastructure +; +; This file is distributed under the University of Illinois Open Source +; License. See LICENSE.TXT for details. +; +;===------------------------------------------------------------------------===; +; +; This is an LLVMBuild description file for the components in this subdirectory. +; +; For more information on the LLVMBuild system, please see: +; +; http://llvm.org/docs/LLVMBuild.html +; +;===------------------------------------------------------------------------===; + +[component_0] +type = Library +name = Passes +parent = Libraries +required_libraries = Analysis Core IPA IPO InstCombine Scalar Support TransformUtils Vectorize diff --git a/lib/Passes/Makefile b/lib/Passes/Makefile new file mode 100644 index 00000000000..413dc5cf485 --- /dev/null +++ b/lib/Passes/Makefile @@ -0,0 +1,14 @@ +##===- lib/Passes/Makefile ---------------------------------*- Makefile -*-===## +# +# The LLVM Compiler Infrastructure +# +# This file is distributed under the University of Illinois Open Source +# License. See LICENSE.TXT for details. +# +##===----------------------------------------------------------------------===## + +LEVEL = ../.. +LIBRARYNAME = LLVMPasses +BUILD_ARCHIVE := 1 + +include $(LEVEL)/Makefile.common diff --git a/tools/opt/Passes.cpp b/lib/Passes/PassBuilder.cpp similarity index 88% rename from tools/opt/Passes.cpp rename to lib/Passes/PassBuilder.cpp index e5ad5c06644..ba7132050e9 100644 --- a/tools/opt/Passes.cpp +++ b/lib/Passes/PassBuilder.cpp @@ -1,4 +1,4 @@ -//===- Passes.cpp - Parsing, selection, and running of passes -------------===// +//===- Parsing, selection, and construction of pass pipelines -------------===// // // The LLVM Compiler Infrastructure // @@ -8,13 +8,14 @@ //===----------------------------------------------------------------------===// /// \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. +/// This file provides the implementation of the PassBuilder based on our +/// static pass registry as well as related functionality. It also provides +/// helpers to aid in analyzing, debugging, and testing passes and pass +/// pipelines. /// //===----------------------------------------------------------------------===// -#include "Passes.h" +#include "llvm/Passes/PassBuilder.h" #include "llvm/Analysis/AssumptionCache.h" #include "llvm/Analysis/CGSCCPassManager.h" #include "llvm/Analysis/LazyCallGraph.h" @@ -94,19 +95,19 @@ char NoOpFunctionAnalysis::PassID; } // End anonymous namespace. -void Passes::registerModuleAnalyses(ModuleAnalysisManager &MAM) { +void PassBuilder::registerModuleAnalyses(ModuleAnalysisManager &MAM) { #define MODULE_ANALYSIS(NAME, CREATE_PASS) \ MAM.registerPass(CREATE_PASS); #include "PassRegistry.def" } -void Passes::registerCGSCCAnalyses(CGSCCAnalysisManager &CGAM) { +void PassBuilder::registerCGSCCAnalyses(CGSCCAnalysisManager &CGAM) { #define CGSCC_ANALYSIS(NAME, CREATE_PASS) \ CGAM.registerPass(CREATE_PASS); #include "PassRegistry.def" } -void Passes::registerFunctionAnalyses(FunctionAnalysisManager &FAM) { +void PassBuilder::registerFunctionAnalyses(FunctionAnalysisManager &FAM) { #define FUNCTION_ANALYSIS(NAME, CREATE_PASS) \ FAM.registerPass(CREATE_PASS); #include "PassRegistry.def" @@ -144,7 +145,7 @@ static bool isFunctionPassName(StringRef Name) { return false; } -bool Passes::parseModulePassName(ModulePassManager &MPM, StringRef Name) { +bool PassBuilder::parseModulePassName(ModulePassManager &MPM, StringRef Name) { #define MODULE_PASS(NAME, CREATE_PASS) \ if (Name == NAME) { \ MPM.addPass(CREATE_PASS); \ @@ -164,7 +165,7 @@ bool Passes::parseModulePassName(ModulePassManager &MPM, StringRef Name) { return false; } -bool Passes::parseCGSCCPassName(CGSCCPassManager &CGPM, StringRef Name) { +bool PassBuilder::parseCGSCCPassName(CGSCCPassManager &CGPM, StringRef Name) { #define CGSCC_PASS(NAME, CREATE_PASS) \ if (Name == NAME) { \ CGPM.addPass(CREATE_PASS); \ @@ -184,7 +185,8 @@ bool Passes::parseCGSCCPassName(CGSCCPassManager &CGPM, StringRef Name) { return false; } -bool Passes::parseFunctionPassName(FunctionPassManager &FPM, StringRef Name) { +bool PassBuilder::parseFunctionPassName(FunctionPassManager &FPM, + StringRef Name) { #define FUNCTION_PASS(NAME, CREATE_PASS) \ if (Name == NAME) { \ FPM.addPass(CREATE_PASS); \ @@ -204,9 +206,10 @@ bool Passes::parseFunctionPassName(FunctionPassManager &FPM, StringRef Name) { return false; } -bool Passes::parseFunctionPassPipeline(FunctionPassManager &FPM, - StringRef &PipelineText, - bool VerifyEachPass, bool DebugLogging) { +bool PassBuilder::parseFunctionPassPipeline(FunctionPassManager &FPM, + StringRef &PipelineText, + bool VerifyEachPass, + bool DebugLogging) { for (;;) { // Parse nested pass managers by recursing. if (PipelineText.startswith("function(")) { @@ -242,9 +245,10 @@ bool Passes::parseFunctionPassPipeline(FunctionPassManager &FPM, } } -bool Passes::parseCGSCCPassPipeline(CGSCCPassManager &CGPM, - StringRef &PipelineText, - bool VerifyEachPass, bool DebugLogging) { +bool PassBuilder::parseCGSCCPassPipeline(CGSCCPassManager &CGPM, + StringRef &PipelineText, + bool VerifyEachPass, + bool DebugLogging) { for (;;) { // Parse nested pass managers by recursing. if (PipelineText.startswith("cgscc(")) { @@ -293,9 +297,10 @@ bool Passes::parseCGSCCPassPipeline(CGSCCPassManager &CGPM, } } -bool Passes::parseModulePassPipeline(ModulePassManager &MPM, - StringRef &PipelineText, - bool VerifyEachPass, bool DebugLogging) { +bool PassBuilder::parseModulePassPipeline(ModulePassManager &MPM, + StringRef &PipelineText, + bool VerifyEachPass, + bool DebugLogging) { for (;;) { // Parse nested pass managers by recursing. if (PipelineText.startswith("module(")) { @@ -363,8 +368,9 @@ bool Passes::parseModulePassPipeline(ModulePassManager &MPM, // 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 Passes::parsePassPipeline(ModulePassManager &MPM, StringRef PipelineText, - bool VerifyEachPass, bool DebugLogging) { +bool PassBuilder::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. diff --git a/tools/opt/PassRegistry.def b/lib/Passes/PassRegistry.def similarity index 100% rename from tools/opt/PassRegistry.def rename to lib/Passes/PassRegistry.def diff --git a/tools/opt/CMakeLists.txt b/tools/opt/CMakeLists.txt index 1d3f08db7d2..12dc4f0a9f5 100644 --- a/tools/opt/CMakeLists.txt +++ b/tools/opt/CMakeLists.txt @@ -16,6 +16,7 @@ set(LLVM_LINK_COMPONENTS Target TransformUtils Vectorize + Passes ) # Support plugins. @@ -26,7 +27,6 @@ add_llvm_tool(opt BreakpointPrinter.cpp GraphPrinters.cpp NewPMDriver.cpp - Passes.cpp PassPrinters.cpp PrintSCC.cpp opt.cpp diff --git a/tools/opt/LLVMBuild.txt b/tools/opt/LLVMBuild.txt index b3589f854ff..b162ab6cfe9 100644 --- a/tools/opt/LLVMBuild.txt +++ b/tools/opt/LLVMBuild.txt @@ -19,4 +19,4 @@ type = Tool name = opt parent = Tools -required_libraries = AsmParser BitReader BitWriter CodeGen IRReader IPO Instrumentation Scalar ObjCARC all-targets +required_libraries = AsmParser BitReader BitWriter CodeGen IRReader IPO Instrumentation Scalar ObjCARC Passes all-targets diff --git a/tools/opt/Makefile b/tools/opt/Makefile index cfa9c31cb95..2422eb4e405 100644 --- a/tools/opt/Makefile +++ b/tools/opt/Makefile @@ -9,7 +9,7 @@ LEVEL := ../.. TOOLNAME := opt -LINK_COMPONENTS := bitreader bitwriter asmparser irreader instrumentation scalaropts objcarcopts ipo vectorize all-targets codegen +LINK_COMPONENTS := bitreader bitwriter asmparser irreader instrumentation scalaropts objcarcopts ipo vectorize all-targets codegen passes # Support plugins. NO_DEAD_STRIP := 1 diff --git a/tools/opt/NewPMDriver.cpp b/tools/opt/NewPMDriver.cpp index a73750dd492..9216d5c939a 100644 --- a/tools/opt/NewPMDriver.cpp +++ b/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,6 +23,7 @@ #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" @@ -40,16 +40,16 @@ bool llvm::runPassPipeline(StringRef Arg0, LLVMContext &Context, Module &M, TargetMachine *TM, tool_output_file *Out, StringRef PassPipeline, OutputKind OK, VerifierKind VK) { - Passes P(TM); + PassBuilder PB(TM); FunctionAnalysisManager FAM(DebugPM); CGSCCAnalysisManager CGAM(DebugPM); ModuleAnalysisManager MAM(DebugPM); // Register all the basic analyses with the managers. - P.registerModuleAnalyses(MAM); - P.registerCGSCCAnalyses(CGAM); - P.registerFunctionAnalyses(FAM); + PB.registerModuleAnalyses(MAM); + PB.registerCGSCCAnalyses(CGAM); + PB.registerFunctionAnalyses(FAM); // Cross register the analysis managers through their proxies. MAM.registerPass(FunctionAnalysisManagerModuleProxy(FAM)); @@ -63,8 +63,8 @@ bool llvm::runPassPipeline(StringRef Arg0, LLVMContext &Context, Module &M, if (VK > VK_NoVerifier) MPM.addPass(VerifierPass()); - if (!P.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; }