mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-07-26 05:25:47 +00:00
[PM] Refactor the analysis registration and pass pipeline parsing to
live in a class. While this isn't really significant right now, I need to expose some state to the pass construction expressions, and making them get evaluated within a class context is a nice way to collect members that they may need to access. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@227715 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -38,14 +38,16 @@ static cl::opt<bool>
|
|||||||
bool llvm::runPassPipeline(StringRef Arg0, LLVMContext &Context, Module &M,
|
bool llvm::runPassPipeline(StringRef Arg0, LLVMContext &Context, Module &M,
|
||||||
tool_output_file *Out, StringRef PassPipeline,
|
tool_output_file *Out, StringRef PassPipeline,
|
||||||
OutputKind OK, VerifierKind VK) {
|
OutputKind OK, VerifierKind VK) {
|
||||||
|
Passes P;
|
||||||
|
|
||||||
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.
|
||||||
registerModuleAnalyses(MAM);
|
P.registerModuleAnalyses(MAM);
|
||||||
registerCGSCCAnalyses(CGAM);
|
P.registerCGSCCAnalyses(CGAM);
|
||||||
registerFunctionAnalyses(FAM);
|
P.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));
|
||||||
@@ -59,7 +61,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 (!parsePassPipeline(MPM, PassPipeline, VK == VK_VerifyEachPass, DebugPM)) {
|
if (!P.parsePassPipeline(MPM, PassPipeline, VK == VK_VerifyEachPass,
|
||||||
|
DebugPM)) {
|
||||||
errs() << Arg0 << ": unable to parse pass pipeline description.\n";
|
errs() << Arg0 << ": unable to parse pass pipeline description.\n";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@@ -90,19 +90,19 @@ char NoOpFunctionAnalysis::PassID;
|
|||||||
|
|
||||||
} // End anonymous namespace.
|
} // End anonymous namespace.
|
||||||
|
|
||||||
void llvm::registerModuleAnalyses(ModuleAnalysisManager &MAM) {
|
void Passes::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 llvm::registerCGSCCAnalyses(CGSCCAnalysisManager &CGAM) {
|
void Passes::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 llvm::registerFunctionAnalyses(FunctionAnalysisManager &FAM) {
|
void Passes::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"
|
||||||
@@ -140,7 +140,7 @@ static bool isFunctionPassName(StringRef Name) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool parseModulePassName(ModulePassManager &MPM, StringRef Name) {
|
bool Passes::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); \
|
||||||
@@ -160,7 +160,7 @@ static bool parseModulePassName(ModulePassManager &MPM, StringRef Name) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool parseCGSCCPassName(CGSCCPassManager &CGPM, StringRef Name) {
|
bool Passes::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); \
|
||||||
@@ -180,7 +180,7 @@ static bool parseCGSCCPassName(CGSCCPassManager &CGPM, StringRef Name) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool parseFunctionPassName(FunctionPassManager &FPM, StringRef Name) {
|
bool Passes::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); \
|
||||||
@@ -200,9 +200,9 @@ static bool parseFunctionPassName(FunctionPassManager &FPM, StringRef Name) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool parseFunctionPassPipeline(FunctionPassManager &FPM,
|
bool Passes::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(")) {
|
||||||
@@ -238,9 +238,9 @@ static bool parseFunctionPassPipeline(FunctionPassManager &FPM,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool parseCGSCCPassPipeline(CGSCCPassManager &CGPM,
|
bool Passes::parseCGSCCPassPipeline(CGSCCPassManager &CGPM,
|
||||||
StringRef &PipelineText, bool VerifyEachPass,
|
StringRef &PipelineText,
|
||||||
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(")) {
|
||||||
@@ -289,9 +289,9 @@ static bool parseCGSCCPassPipeline(CGSCCPassManager &CGPM,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool parseModulePassPipeline(ModulePassManager &MPM,
|
bool Passes::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(")) {
|
||||||
@@ -359,8 +359,8 @@ static bool 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 llvm::parsePassPipeline(ModulePassManager &MPM, StringRef PipelineText,
|
bool Passes::parsePassPipeline(ModulePassManager &MPM, StringRef PipelineText,
|
||||||
bool VerifyEachPass, bool DebugLogging) {
|
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.
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
//===- Passes.h - Parsing, selection, and running of passes -----*- C++ -*-===//
|
//===- Passes.h - Utilities for manipulating all passes ---------*- C++ -*-===//
|
||||||
//
|
//
|
||||||
// The LLVM Compiler Infrastructure
|
// The LLVM Compiler Infrastructure
|
||||||
//
|
//
|
||||||
@@ -8,8 +8,8 @@
|
|||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
/// \file
|
/// \file
|
||||||
///
|
///
|
||||||
/// Interfaces for producing common pass manager configurations and parsing
|
/// Interfaces for registering passes, producing common pass manager
|
||||||
/// textual pass specifications.
|
/// configurations, and parsing of pass pipelines.
|
||||||
///
|
///
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
@@ -22,57 +22,79 @@
|
|||||||
|
|
||||||
namespace llvm {
|
namespace llvm {
|
||||||
|
|
||||||
/// \brief Registers all available module analysis passes.
|
/// \brief This class provides access to all of LLVM's passes.
|
||||||
///
|
///
|
||||||
/// This is an interface that can be used to populate a \c
|
/// It's members provide the baseline state available to passes during their
|
||||||
/// ModuleAnalysisManager with all registered module analyses. Callers can
|
/// construction. The \c PassRegistry.def file specifies how to construct all
|
||||||
/// still manually register any additional analyses.
|
/// of the built-in passes, and those may reference these members during
|
||||||
void registerModuleAnalyses(ModuleAnalysisManager &MAM);
|
/// construction.
|
||||||
|
class Passes {
|
||||||
|
public:
|
||||||
|
/// \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.
|
/// \brief Registers all available CGSCC analysis passes.
|
||||||
///
|
///
|
||||||
/// This is an interface that can be used to populate a \c CGSCCAnalysisManager
|
/// This is an interface that can be used to populate a \c CGSCCAnalysisManager
|
||||||
/// with all registered CGSCC analyses. Callers can still manually register any
|
/// with all registered CGSCC analyses. Callers can still manually register any
|
||||||
/// additional analyses.
|
/// additional analyses.
|
||||||
void registerCGSCCAnalyses(CGSCCAnalysisManager &CGAM);
|
void registerCGSCCAnalyses(CGSCCAnalysisManager &CGAM);
|
||||||
|
|
||||||
/// \brief Registers all available function analysis passes.
|
/// \brief Registers all available function analysis passes.
|
||||||
///
|
///
|
||||||
/// This is an interface that can be used to populate a \c
|
/// This is an interface that can be used to populate a \c
|
||||||
/// FunctionAnalysisManager with all registered function analyses. Callers can
|
/// FunctionAnalysisManager with all registered function analyses. Callers can
|
||||||
/// still manually register any additional analyses.
|
/// still manually register any additional analyses.
|
||||||
void registerFunctionAnalyses(FunctionAnalysisManager &FAM);
|
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);
|
||||||
|
|
||||||
|
private:
|
||||||
|
bool parseModulePassName(ModulePassManager &MPM, StringRef Name);
|
||||||
|
bool parseCGSCCPassName(CGSCCPassManager &CGPM, StringRef Name);
|
||||||
|
bool parseFunctionPassName(FunctionPassManager &FPM, StringRef Name);
|
||||||
|
bool parseFunctionPassPipeline(FunctionPassManager &FPM,
|
||||||
|
StringRef &PipelineText, bool VerifyEachPass,
|
||||||
|
bool DebugLogging);
|
||||||
|
bool parseCGSCCPassPipeline(CGSCCPassManager &CGPM, StringRef &PipelineText,
|
||||||
|
bool VerifyEachPass, bool DebugLogging);
|
||||||
|
bool parseModulePassPipeline(ModulePassManager &MPM, StringRef &PipelineText,
|
||||||
|
bool VerifyEachPass, bool DebugLogging);
|
||||||
|
};
|
||||||
|
|
||||||
/// \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
|
#endif
|
||||||
|
Reference in New Issue
Block a user