mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-11-26 04:32:44 +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:
parent
ce7343d964
commit
ef5afb1b16
@ -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.
|
||||
///
|
@ -18,3 +18,4 @@ add_subdirectory(AsmParser)
|
||||
add_subdirectory(LineEditor)
|
||||
add_subdirectory(ProfileData)
|
||||
add_subdirectory(Fuzzer)
|
||||
add_subdirectory(Passes)
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
6
lib/Passes/CMakeLists.txt
Normal file
6
lib/Passes/CMakeLists.txt
Normal 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
22
lib/Passes/LLVMBuild.txt
Normal 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
14
lib/Passes/Makefile
Normal 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
|
@ -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,
|
||||
bool PassBuilder::parseFunctionPassPipeline(FunctionPassManager &FPM,
|
||||
StringRef &PipelineText,
|
||||
bool VerifyEachPass, bool DebugLogging) {
|
||||
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,
|
||||
bool PassBuilder::parseCGSCCPassPipeline(CGSCCPassManager &CGPM,
|
||||
StringRef &PipelineText,
|
||||
bool VerifyEachPass, bool DebugLogging) {
|
||||
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,
|
||||
bool PassBuilder::parseModulePassPipeline(ModulePassManager &MPM,
|
||||
StringRef &PipelineText,
|
||||
bool VerifyEachPass, bool DebugLogging) {
|
||||
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.
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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,7 +63,7 @@ bool llvm::runPassPipeline(StringRef Arg0, LLVMContext &Context, Module &M,
|
||||
if (VK > VK_NoVerifier)
|
||||
MPM.addPass(VerifierPass());
|
||||
|
||||
if (!P.parsePassPipeline(MPM, PassPipeline, VK == VK_VerifyEachPass,
|
||||
if (!PB.parsePassPipeline(MPM, PassPipeline, VK == VK_VerifyEachPass,
|
||||
DebugPM)) {
|
||||
errs() << Arg0 << ": unable to parse pass pipeline description.\n";
|
||||
return false;
|
||||
|
Loading…
Reference in New Issue
Block a user