1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-22 18:54:02 +01:00

[PM] Create a separate library for high-level pass management code.

This will provide the analogous replacements for the PassManagerBuilder
and other code long term. This code is extracted from the opt tool
currently, and I plan to extend it as I build up support for using the
new pass manager in Clang and other places.

Mailing this out for review in part to let folks comment on the terrible names
here. A brief word about why I chose the names I did.

The library is called "Passes" to try and make it clear that it is a high-level
utility and where *all* of the passes come together and are registered in
a common library. I didn't want it to be *limited* to a registry though, the
registry is just one component.

The class is a "PassBuilder" but this name I'm less happy with. It doesn't
build passes in any traditional sense and isn't a Builder-style API at all. The
class is a PassRegisterer or PassAdder, but neither of those really make a lot
of sense. This class is responsible for constructing passes for registry in an
analysis manager or for population of a pass pipeline. If anyone has a better
name, I would love to hear it. The other candidate I looked at was
PassRegistrar, but that doesn't really fit either. There is no register of all
the passes in use, and so I think continuing the "registry" analog outside of
the registry of pass *names* and *types* is a mistake. The objects themselves
are just objects with the new pass manager.

Differential Revision: http://reviews.llvm.org/D8054

llvm-svn: 231556
This commit is contained in:
Chandler Carruth 2015-03-07 09:02:36 +00:00
parent ce7343d964
commit ef5afb1b16
13 changed files with 90 additions and 41 deletions

View File

@ -1,4 +1,4 @@
//===- Passes.h - Utilities for manipulating all passes ---------*- C++ -*-===// //===- Parsing, selection, and construction of pass pipelines --*- C++ -*--===//
// //
// The LLVM Compiler Infrastructure // The LLVM Compiler Infrastructure
// //
@ -8,13 +8,13 @@
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
/// \file /// \file
/// ///
/// Interfaces for registering passes, producing common pass manager /// Interfaces for registering analysis passes, producing common pass manager
/// configurations, and parsing of pass pipelines. /// configurations, and parsing of pass pipelines.
/// ///
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
#ifndef LLVM_TOOLS_OPT_PASSES_H #ifndef LLVM_PASSES_PASSBUILDER_H
#define LLVM_TOOLS_OPT_PASSES_H #define LLVM_PASSES_PASSBUILDER_H
#include "llvm/ADT/StringRef.h" #include "llvm/ADT/StringRef.h"
#include "llvm/Analysis/CGSCCPassManager.h" #include "llvm/Analysis/CGSCCPassManager.h"
@ -23,17 +23,17 @@
namespace llvm { namespace llvm {
class TargetMachine; 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 /// It's members provide the baseline state available to passes during their
/// construction. The \c PassRegistry.def file specifies how to construct all /// construction. The \c PassRegistry.def file specifies how to construct all
/// of the built-in passes, and those may reference these members during /// of the built-in passes, and those may reference these members during
/// construction. /// construction.
class Passes { class PassBuilder {
TargetMachine *TM; TargetMachine *TM;
public: public:
explicit Passes(TargetMachine *TM = nullptr) : TM(TM) {} explicit PassBuilder(TargetMachine *TM = nullptr) : TM(TM) {}
/// \brief Registers all available module analysis passes. /// \brief Registers all available module analysis passes.
/// ///

View File

@ -18,3 +18,4 @@ add_subdirectory(AsmParser)
add_subdirectory(LineEditor) add_subdirectory(LineEditor)
add_subdirectory(ProfileData) add_subdirectory(ProfileData)
add_subdirectory(Fuzzer) add_subdirectory(Fuzzer)
add_subdirectory(Passes)

View File

@ -16,7 +16,7 @@
;===------------------------------------------------------------------------===; ;===------------------------------------------------------------------------===;
[common] [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] [component_0]
type = Group type = Group

View File

@ -12,6 +12,6 @@ include $(LEVEL)/Makefile.config
PARALLEL_DIRS := IR AsmParser Bitcode Analysis Transforms CodeGen Target \ PARALLEL_DIRS := IR AsmParser Bitcode Analysis Transforms CodeGen Target \
ExecutionEngine Linker LTO MC Object Option DebugInfo \ ExecutionEngine Linker LTO MC Object Option DebugInfo \
IRReader LineEditor ProfileData IRReader LineEditor ProfileData Passes
include $(LEVEL)/Makefile.common include $(LEVEL)/Makefile.common

View File

@ -0,0 +1,6 @@
add_llvm_library(LLVMPasses
PassBuilder.cpp
ADDITIONAL_HEADER_DIRS
${LLVM_MAIN_INCLUDE_DIR}/llvm/Passes
)

22
lib/Passes/LLVMBuild.txt Normal file
View File

@ -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

14
lib/Passes/Makefile Normal file
View File

@ -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

View File

@ -1,4 +1,4 @@
//===- Passes.cpp - Parsing, selection, and running of passes -------------===// //===- Parsing, selection, and construction of pass pipelines -------------===//
// //
// The LLVM Compiler Infrastructure // The LLVM Compiler Infrastructure
// //
@ -8,13 +8,14 @@
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
/// \file /// \file
/// ///
/// This file provides the infrastructure to parse and build a custom pass /// This file provides the implementation of the PassBuilder based on our
/// manager based on a commandline flag. It also provides helpers to aid in /// static pass registry as well as related functionality. It also provides
/// analyzing, debugging, and testing pass structures. /// 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/AssumptionCache.h"
#include "llvm/Analysis/CGSCCPassManager.h" #include "llvm/Analysis/CGSCCPassManager.h"
#include "llvm/Analysis/LazyCallGraph.h" #include "llvm/Analysis/LazyCallGraph.h"
@ -94,19 +95,19 @@ char NoOpFunctionAnalysis::PassID;
} // End anonymous namespace. } // End anonymous namespace.
void Passes::registerModuleAnalyses(ModuleAnalysisManager &MAM) { void PassBuilder::registerModuleAnalyses(ModuleAnalysisManager &MAM) {
#define MODULE_ANALYSIS(NAME, CREATE_PASS) \ #define MODULE_ANALYSIS(NAME, CREATE_PASS) \
MAM.registerPass(CREATE_PASS); MAM.registerPass(CREATE_PASS);
#include "PassRegistry.def" #include "PassRegistry.def"
} }
void Passes::registerCGSCCAnalyses(CGSCCAnalysisManager &CGAM) { void PassBuilder::registerCGSCCAnalyses(CGSCCAnalysisManager &CGAM) {
#define CGSCC_ANALYSIS(NAME, CREATE_PASS) \ #define CGSCC_ANALYSIS(NAME, CREATE_PASS) \
CGAM.registerPass(CREATE_PASS); CGAM.registerPass(CREATE_PASS);
#include "PassRegistry.def" #include "PassRegistry.def"
} }
void Passes::registerFunctionAnalyses(FunctionAnalysisManager &FAM) { void PassBuilder::registerFunctionAnalyses(FunctionAnalysisManager &FAM) {
#define FUNCTION_ANALYSIS(NAME, CREATE_PASS) \ #define FUNCTION_ANALYSIS(NAME, CREATE_PASS) \
FAM.registerPass(CREATE_PASS); FAM.registerPass(CREATE_PASS);
#include "PassRegistry.def" #include "PassRegistry.def"
@ -144,7 +145,7 @@ static bool isFunctionPassName(StringRef Name) {
return false; return false;
} }
bool Passes::parseModulePassName(ModulePassManager &MPM, StringRef Name) { bool PassBuilder::parseModulePassName(ModulePassManager &MPM, StringRef Name) {
#define MODULE_PASS(NAME, CREATE_PASS) \ #define MODULE_PASS(NAME, CREATE_PASS) \
if (Name == NAME) { \ if (Name == NAME) { \
MPM.addPass(CREATE_PASS); \ MPM.addPass(CREATE_PASS); \
@ -164,7 +165,7 @@ bool Passes::parseModulePassName(ModulePassManager &MPM, StringRef Name) {
return false; return false;
} }
bool Passes::parseCGSCCPassName(CGSCCPassManager &CGPM, StringRef Name) { bool PassBuilder::parseCGSCCPassName(CGSCCPassManager &CGPM, StringRef Name) {
#define CGSCC_PASS(NAME, CREATE_PASS) \ #define CGSCC_PASS(NAME, CREATE_PASS) \
if (Name == NAME) { \ if (Name == NAME) { \
CGPM.addPass(CREATE_PASS); \ CGPM.addPass(CREATE_PASS); \
@ -184,7 +185,8 @@ bool Passes::parseCGSCCPassName(CGSCCPassManager &CGPM, StringRef Name) {
return false; return false;
} }
bool Passes::parseFunctionPassName(FunctionPassManager &FPM, StringRef Name) { bool PassBuilder::parseFunctionPassName(FunctionPassManager &FPM,
StringRef Name) {
#define FUNCTION_PASS(NAME, CREATE_PASS) \ #define FUNCTION_PASS(NAME, CREATE_PASS) \
if (Name == NAME) { \ if (Name == NAME) { \
FPM.addPass(CREATE_PASS); \ FPM.addPass(CREATE_PASS); \
@ -204,9 +206,10 @@ bool Passes::parseFunctionPassName(FunctionPassManager &FPM, StringRef Name) {
return false; return false;
} }
bool Passes::parseFunctionPassPipeline(FunctionPassManager &FPM, bool PassBuilder::parseFunctionPassPipeline(FunctionPassManager &FPM,
StringRef &PipelineText, StringRef &PipelineText,
bool VerifyEachPass, bool DebugLogging) { bool VerifyEachPass,
bool DebugLogging) {
for (;;) { for (;;) {
// Parse nested pass managers by recursing. // Parse nested pass managers by recursing.
if (PipelineText.startswith("function(")) { if (PipelineText.startswith("function(")) {
@ -242,9 +245,10 @@ bool Passes::parseFunctionPassPipeline(FunctionPassManager &FPM,
} }
} }
bool Passes::parseCGSCCPassPipeline(CGSCCPassManager &CGPM, bool PassBuilder::parseCGSCCPassPipeline(CGSCCPassManager &CGPM,
StringRef &PipelineText, StringRef &PipelineText,
bool VerifyEachPass, bool DebugLogging) { bool VerifyEachPass,
bool DebugLogging) {
for (;;) { for (;;) {
// Parse nested pass managers by recursing. // Parse nested pass managers by recursing.
if (PipelineText.startswith("cgscc(")) { if (PipelineText.startswith("cgscc(")) {
@ -293,9 +297,10 @@ bool Passes::parseCGSCCPassPipeline(CGSCCPassManager &CGPM,
} }
} }
bool Passes::parseModulePassPipeline(ModulePassManager &MPM, bool PassBuilder::parseModulePassPipeline(ModulePassManager &MPM,
StringRef &PipelineText, StringRef &PipelineText,
bool VerifyEachPass, bool DebugLogging) { bool VerifyEachPass,
bool DebugLogging) {
for (;;) { for (;;) {
// Parse nested pass managers by recursing. // Parse nested pass managers by recursing.
if (PipelineText.startswith("module(")) { if (PipelineText.startswith("module(")) {
@ -363,8 +368,9 @@ bool Passes::parseModulePassPipeline(ModulePassManager &MPM,
// Primary pass pipeline description parsing routine. // Primary pass pipeline description parsing routine.
// FIXME: Should this routine accept a TargetMachine or require the caller to // FIXME: Should this routine accept a TargetMachine or require the caller to
// pre-populate the analysis managers with target-specific stuff? // pre-populate the analysis managers with target-specific stuff?
bool Passes::parsePassPipeline(ModulePassManager &MPM, StringRef PipelineText, bool PassBuilder::parsePassPipeline(ModulePassManager &MPM,
bool VerifyEachPass, bool DebugLogging) { StringRef PipelineText, bool VerifyEachPass,
bool DebugLogging) {
// By default, try to parse the pipeline as-if it were within an implicit // 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 // 'module(...)' pass pipeline. If this will parse at all, it needs to
// consume the entire string. // consume the entire string.

View File

@ -16,6 +16,7 @@ set(LLVM_LINK_COMPONENTS
Target Target
TransformUtils TransformUtils
Vectorize Vectorize
Passes
) )
# Support plugins. # Support plugins.
@ -26,7 +27,6 @@ add_llvm_tool(opt
BreakpointPrinter.cpp BreakpointPrinter.cpp
GraphPrinters.cpp GraphPrinters.cpp
NewPMDriver.cpp NewPMDriver.cpp
Passes.cpp
PassPrinters.cpp PassPrinters.cpp
PrintSCC.cpp PrintSCC.cpp
opt.cpp opt.cpp

View File

@ -19,4 +19,4 @@
type = Tool type = Tool
name = opt name = opt
parent = Tools 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

View File

@ -9,7 +9,7 @@
LEVEL := ../.. LEVEL := ../..
TOOLNAME := opt 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. # Support plugins.
NO_DEAD_STRIP := 1 NO_DEAD_STRIP := 1

View File

@ -14,7 +14,6 @@
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
#include "NewPMDriver.h" #include "NewPMDriver.h"
#include "Passes.h"
#include "llvm/ADT/StringRef.h" #include "llvm/ADT/StringRef.h"
#include "llvm/Analysis/CGSCCPassManager.h" #include "llvm/Analysis/CGSCCPassManager.h"
#include "llvm/Bitcode/BitcodeWriterPass.h" #include "llvm/Bitcode/BitcodeWriterPass.h"
@ -24,6 +23,7 @@
#include "llvm/IR/Module.h" #include "llvm/IR/Module.h"
#include "llvm/IR/PassManager.h" #include "llvm/IR/PassManager.h"
#include "llvm/IR/Verifier.h" #include "llvm/IR/Verifier.h"
#include "llvm/Passes/PassBuilder.h"
#include "llvm/Support/CommandLine.h" #include "llvm/Support/CommandLine.h"
#include "llvm/Support/ErrorHandling.h" #include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/ToolOutputFile.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, TargetMachine *TM, tool_output_file *Out,
StringRef PassPipeline, OutputKind OK, StringRef PassPipeline, OutputKind OK,
VerifierKind VK) { VerifierKind VK) {
Passes P(TM); PassBuilder PB(TM);
FunctionAnalysisManager FAM(DebugPM); FunctionAnalysisManager FAM(DebugPM);
CGSCCAnalysisManager CGAM(DebugPM); CGSCCAnalysisManager CGAM(DebugPM);
ModuleAnalysisManager MAM(DebugPM); ModuleAnalysisManager MAM(DebugPM);
// Register all the basic analyses with the managers. // Register all the basic analyses with the managers.
P.registerModuleAnalyses(MAM); PB.registerModuleAnalyses(MAM);
P.registerCGSCCAnalyses(CGAM); PB.registerCGSCCAnalyses(CGAM);
P.registerFunctionAnalyses(FAM); PB.registerFunctionAnalyses(FAM);
// Cross register the analysis managers through their proxies. // Cross register the analysis managers through their proxies.
MAM.registerPass(FunctionAnalysisManagerModuleProxy(FAM)); MAM.registerPass(FunctionAnalysisManagerModuleProxy(FAM));
@ -63,8 +63,8 @@ bool llvm::runPassPipeline(StringRef Arg0, LLVMContext &Context, Module &M,
if (VK > VK_NoVerifier) if (VK > VK_NoVerifier)
MPM.addPass(VerifierPass()); MPM.addPass(VerifierPass());
if (!P.parsePassPipeline(MPM, PassPipeline, VK == VK_VerifyEachPass, if (!PB.parsePassPipeline(MPM, PassPipeline, VK == VK_VerifyEachPass,
DebugPM)) { DebugPM)) {
errs() << Arg0 << ": unable to parse pass pipeline description.\n"; errs() << Arg0 << ": unable to parse pass pipeline description.\n";
return false; return false;
} }