Index: include/llvm/Passes/PassBuilder.h =================================================================== --- include/llvm/Passes/PassBuilder.h +++ 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. /// Index: lib/CMakeLists.txt =================================================================== --- lib/CMakeLists.txt +++ lib/CMakeLists.txt @@ -18,3 +18,4 @@ add_subdirectory(LineEditor) add_subdirectory(ProfileData) add_subdirectory(Fuzzer) +add_subdirectory(Passes) Index: lib/LLVMBuild.txt =================================================================== --- lib/LLVMBuild.txt +++ 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 Index: lib/Makefile =================================================================== --- lib/Makefile +++ lib/Makefile @@ -12,6 +12,6 @@ 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 Index: lib/Passes/CMakeLists.txt =================================================================== --- /dev/null +++ lib/Passes/CMakeLists.txt @@ -0,0 +1,6 @@ +add_llvm_library(LLVMPasses + PassBuilder.cpp + + ADDITIONAL_HEADER_DIRS + ${LLVM_MAIN_INCLUDE_DIR}/llvm/Passes + ) Index: lib/Passes/LLVMBuild.txt =================================================================== --- lib/Passes/LLVMBuild.txt +++ lib/Passes/LLVMBuild.txt @@ -1,4 +1,4 @@ -;===- ./tools/opt/LLVMBuild.txt --------------------------------*- Conf -*--===; +;===- ./lib/Passes/LLVMBuild.txt -------------------------------*- Conf -*--===; ; ; The LLVM Compiler Infrastructure ; @@ -16,7 +16,8 @@ ;===------------------------------------------------------------------------===; [component_0] -type = Tool -name = opt -parent = Tools -required_libraries = AsmParser BitReader BitWriter CodeGen IRReader IPO Instrumentation Scalar ObjCARC all-targets +type = Library +name = Passes +parent = Libraries +library_name = passes +required_libraries = Analysis Core IPA IPO InstCombine Scalar Support TransformUtils Vectorize Index: lib/Passes/Makefile =================================================================== --- /dev/null +++ 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 Index: lib/Passes/PassBuilder.cpp =================================================================== --- lib/Passes/PassBuilder.cpp +++ 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 @@ } // 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 @@ 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 @@ 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 @@ 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 @@ 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::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::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 @@ // 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. Index: tools/opt/CMakeLists.txt =================================================================== --- tools/opt/CMakeLists.txt +++ tools/opt/CMakeLists.txt @@ -16,6 +16,7 @@ Target TransformUtils Vectorize + Passes ) # Support plugins. @@ -26,7 +27,6 @@ BreakpointPrinter.cpp GraphPrinters.cpp NewPMDriver.cpp - Passes.cpp PassPrinters.cpp PrintSCC.cpp opt.cpp Index: tools/opt/LLVMBuild.txt =================================================================== --- tools/opt/LLVMBuild.txt +++ 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 Index: tools/opt/NewPMDriver.cpp =================================================================== --- tools/opt/NewPMDriver.cpp +++ 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 @@ 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 @@ 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; } Index: tools/opt/PassRegistry.def =================================================================== --- /dev/null +++ tools/opt/PassRegistry.def @@ -1,77 +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()) -MODULE_ANALYSIS("targetlibinfo", TargetLibraryAnalysis()) -#undef MODULE_ANALYSIS - -#ifndef MODULE_PASS -#define MODULE_PASS(NAME, CREATE_PASS) -#endif -MODULE_PASS("invalidate", 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", InvalidateAllAnalysesPass()) -CGSCC_PASS("no-op-cgscc", NoOpCGSCCPass()) -#undef CGSCC_PASS - -#ifndef FUNCTION_ANALYSIS -#define FUNCTION_ANALYSIS(NAME, CREATE_PASS) -#endif -FUNCTION_ANALYSIS("assumptions", AssumptionAnalysis()) -FUNCTION_ANALYSIS("domtree", DominatorTreeAnalysis()) -FUNCTION_ANALYSIS("loops", LoopAnalysis()) -FUNCTION_ANALYSIS("no-op-function", NoOpFunctionAnalysis()) -FUNCTION_ANALYSIS("targetlibinfo", TargetLibraryAnalysis()) -FUNCTION_ANALYSIS("targetir", - TM ? TM->getTargetIRAnalysis() : TargetIRAnalysis()) -#undef FUNCTION_ANALYSIS - -#ifndef FUNCTION_PASS -#define FUNCTION_PASS(NAME, CREATE_PASS) -#endif -FUNCTION_PASS("early-cse", EarlyCSEPass()) -FUNCTION_PASS("instcombine", InstCombinePass()) -FUNCTION_PASS("invalidate", InvalidateAllAnalysesPass()) -FUNCTION_PASS("no-op-function", NoOpFunctionPass()) -FUNCTION_PASS("lower-expect", LowerExpectIntrinsicPass()) -FUNCTION_PASS("print", PrintFunctionPass(dbgs())) -FUNCTION_PASS("print", AssumptionPrinterPass(dbgs())) -FUNCTION_PASS("print", DominatorTreePrinterPass(dbgs())) -FUNCTION_PASS("print", LoopPrinterPass(dbgs())) -FUNCTION_PASS("simplify-cfg", SimplifyCFGPass()) -FUNCTION_PASS("verify", VerifierPass()) -FUNCTION_PASS("verify", DominatorTreeVerifierPass()) -#undef FUNCTION_PASS