Skip to content

Commit 1ff7724

Browse files
committedMar 7, 2015
[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
1 parent bede80a commit 1ff7724

13 files changed

+90
-41
lines changed
 

‎llvm/tools/opt/Passes.h ‎llvm/include/llvm/Passes/PassBuilder.h

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//===- Passes.h - Utilities for manipulating all passes ---------*- C++ -*-===//
1+
//===- Parsing, selection, and construction of pass pipelines --*- C++ -*--===//
22
//
33
// The LLVM Compiler Infrastructure
44
//
@@ -8,13 +8,13 @@
88
//===----------------------------------------------------------------------===//
99
/// \file
1010
///
11-
/// Interfaces for registering passes, producing common pass manager
11+
/// Interfaces for registering analysis passes, producing common pass manager
1212
/// configurations, and parsing of pass pipelines.
1313
///
1414
//===----------------------------------------------------------------------===//
1515

16-
#ifndef LLVM_TOOLS_OPT_PASSES_H
17-
#define LLVM_TOOLS_OPT_PASSES_H
16+
#ifndef LLVM_PASSES_PASSBUILDER_H
17+
#define LLVM_PASSES_PASSBUILDER_H
1818

1919
#include "llvm/ADT/StringRef.h"
2020
#include "llvm/Analysis/CGSCCPassManager.h"
@@ -23,17 +23,17 @@
2323
namespace llvm {
2424
class TargetMachine;
2525

26-
/// \brief This class provides access to all of LLVM's passes.
26+
/// \brief This class provides access to building LLVM's passes.
2727
///
2828
/// It's members provide the baseline state available to passes during their
2929
/// construction. The \c PassRegistry.def file specifies how to construct all
3030
/// of the built-in passes, and those may reference these members during
3131
/// construction.
32-
class Passes {
32+
class PassBuilder {
3333
TargetMachine *TM;
3434

3535
public:
36-
explicit Passes(TargetMachine *TM = nullptr) : TM(TM) {}
36+
explicit PassBuilder(TargetMachine *TM = nullptr) : TM(TM) {}
3737

3838
/// \brief Registers all available module analysis passes.
3939
///

‎llvm/lib/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,4 @@ add_subdirectory(AsmParser)
1818
add_subdirectory(LineEditor)
1919
add_subdirectory(ProfileData)
2020
add_subdirectory(Fuzzer)
21+
add_subdirectory(Passes)

‎llvm/lib/LLVMBuild.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
;===------------------------------------------------------------------------===;
1717

1818
[common]
19-
subdirectories = Analysis AsmParser Bitcode CodeGen DebugInfo ExecutionEngine LineEditor Linker IR IRReader LTO MC Object Option ProfileData Support TableGen Target Transforms
19+
subdirectories = Analysis AsmParser Bitcode CodeGen DebugInfo ExecutionEngine LineEditor Linker IR IRReader LTO MC Object Option Passes ProfileData Support TableGen Target Transforms
2020

2121
[component_0]
2222
type = Group

‎llvm/lib/Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@ include $(LEVEL)/Makefile.config
1212

1313
PARALLEL_DIRS := IR AsmParser Bitcode Analysis Transforms CodeGen Target \
1414
ExecutionEngine Linker LTO MC Object Option DebugInfo \
15-
IRReader LineEditor ProfileData
15+
IRReader LineEditor ProfileData Passes
1616

1717
include $(LEVEL)/Makefile.common

‎llvm/lib/Passes/CMakeLists.txt

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
add_llvm_library(LLVMPasses
2+
PassBuilder.cpp
3+
4+
ADDITIONAL_HEADER_DIRS
5+
${LLVM_MAIN_INCLUDE_DIR}/llvm/Passes
6+
)

‎llvm/lib/Passes/LLVMBuild.txt

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
;===- ./lib/Passes/LLVMBuild.txt -------------------------------*- Conf -*--===;
2+
;
3+
; The LLVM Compiler Infrastructure
4+
;
5+
; This file is distributed under the University of Illinois Open Source
6+
; License. See LICENSE.TXT for details.
7+
;
8+
;===------------------------------------------------------------------------===;
9+
;
10+
; This is an LLVMBuild description file for the components in this subdirectory.
11+
;
12+
; For more information on the LLVMBuild system, please see:
13+
;
14+
; http://llvm.org/docs/LLVMBuild.html
15+
;
16+
;===------------------------------------------------------------------------===;
17+
18+
[component_0]
19+
type = Library
20+
name = Passes
21+
parent = Libraries
22+
required_libraries = Analysis Core IPA IPO InstCombine Scalar Support TransformUtils Vectorize

‎llvm/lib/Passes/Makefile

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
##===- lib/Passes/Makefile ---------------------------------*- Makefile -*-===##
2+
#
3+
# The LLVM Compiler Infrastructure
4+
#
5+
# This file is distributed under the University of Illinois Open Source
6+
# License. See LICENSE.TXT for details.
7+
#
8+
##===----------------------------------------------------------------------===##
9+
10+
LEVEL = ../..
11+
LIBRARYNAME = LLVMPasses
12+
BUILD_ARCHIVE := 1
13+
14+
include $(LEVEL)/Makefile.common

‎llvm/tools/opt/Passes.cpp ‎llvm/lib/Passes/PassBuilder.cpp

+28-22
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//===- Passes.cpp - Parsing, selection, and running of passes -------------===//
1+
//===- Parsing, selection, and construction of pass pipelines -------------===//
22
//
33
// The LLVM Compiler Infrastructure
44
//
@@ -8,13 +8,14 @@
88
//===----------------------------------------------------------------------===//
99
/// \file
1010
///
11-
/// This file provides the infrastructure to parse and build a custom pass
12-
/// manager based on a commandline flag. It also provides helpers to aid in
13-
/// analyzing, debugging, and testing pass structures.
11+
/// This file provides the implementation of the PassBuilder based on our
12+
/// static pass registry as well as related functionality. It also provides
13+
/// helpers to aid in analyzing, debugging, and testing passes and pass
14+
/// pipelines.
1415
///
1516
//===----------------------------------------------------------------------===//
1617

17-
#include "Passes.h"
18+
#include "llvm/Passes/PassBuilder.h"
1819
#include "llvm/Analysis/AssumptionCache.h"
1920
#include "llvm/Analysis/CGSCCPassManager.h"
2021
#include "llvm/Analysis/LazyCallGraph.h"
@@ -94,19 +95,19 @@ char NoOpFunctionAnalysis::PassID;
9495

9596
} // End anonymous namespace.
9697

97-
void Passes::registerModuleAnalyses(ModuleAnalysisManager &MAM) {
98+
void PassBuilder::registerModuleAnalyses(ModuleAnalysisManager &MAM) {
9899
#define MODULE_ANALYSIS(NAME, CREATE_PASS) \
99100
MAM.registerPass(CREATE_PASS);
100101
#include "PassRegistry.def"
101102
}
102103

103-
void Passes::registerCGSCCAnalyses(CGSCCAnalysisManager &CGAM) {
104+
void PassBuilder::registerCGSCCAnalyses(CGSCCAnalysisManager &CGAM) {
104105
#define CGSCC_ANALYSIS(NAME, CREATE_PASS) \
105106
CGAM.registerPass(CREATE_PASS);
106107
#include "PassRegistry.def"
107108
}
108109

109-
void Passes::registerFunctionAnalyses(FunctionAnalysisManager &FAM) {
110+
void PassBuilder::registerFunctionAnalyses(FunctionAnalysisManager &FAM) {
110111
#define FUNCTION_ANALYSIS(NAME, CREATE_PASS) \
111112
FAM.registerPass(CREATE_PASS);
112113
#include "PassRegistry.def"
@@ -144,7 +145,7 @@ static bool isFunctionPassName(StringRef Name) {
144145
return false;
145146
}
146147

147-
bool Passes::parseModulePassName(ModulePassManager &MPM, StringRef Name) {
148+
bool PassBuilder::parseModulePassName(ModulePassManager &MPM, StringRef Name) {
148149
#define MODULE_PASS(NAME, CREATE_PASS) \
149150
if (Name == NAME) { \
150151
MPM.addPass(CREATE_PASS); \
@@ -164,7 +165,7 @@ bool Passes::parseModulePassName(ModulePassManager &MPM, StringRef Name) {
164165
return false;
165166
}
166167

167-
bool Passes::parseCGSCCPassName(CGSCCPassManager &CGPM, StringRef Name) {
168+
bool PassBuilder::parseCGSCCPassName(CGSCCPassManager &CGPM, StringRef Name) {
168169
#define CGSCC_PASS(NAME, CREATE_PASS) \
169170
if (Name == NAME) { \
170171
CGPM.addPass(CREATE_PASS); \
@@ -184,7 +185,8 @@ bool Passes::parseCGSCCPassName(CGSCCPassManager &CGPM, StringRef Name) {
184185
return false;
185186
}
186187

187-
bool Passes::parseFunctionPassName(FunctionPassManager &FPM, StringRef Name) {
188+
bool PassBuilder::parseFunctionPassName(FunctionPassManager &FPM,
189+
StringRef Name) {
188190
#define FUNCTION_PASS(NAME, CREATE_PASS) \
189191
if (Name == NAME) { \
190192
FPM.addPass(CREATE_PASS); \
@@ -204,9 +206,10 @@ bool Passes::parseFunctionPassName(FunctionPassManager &FPM, StringRef Name) {
204206
return false;
205207
}
206208

207-
bool Passes::parseFunctionPassPipeline(FunctionPassManager &FPM,
208-
StringRef &PipelineText,
209-
bool VerifyEachPass, bool DebugLogging) {
209+
bool PassBuilder::parseFunctionPassPipeline(FunctionPassManager &FPM,
210+
StringRef &PipelineText,
211+
bool VerifyEachPass,
212+
bool DebugLogging) {
210213
for (;;) {
211214
// Parse nested pass managers by recursing.
212215
if (PipelineText.startswith("function(")) {
@@ -242,9 +245,10 @@ bool Passes::parseFunctionPassPipeline(FunctionPassManager &FPM,
242245
}
243246
}
244247

245-
bool Passes::parseCGSCCPassPipeline(CGSCCPassManager &CGPM,
246-
StringRef &PipelineText,
247-
bool VerifyEachPass, bool DebugLogging) {
248+
bool PassBuilder::parseCGSCCPassPipeline(CGSCCPassManager &CGPM,
249+
StringRef &PipelineText,
250+
bool VerifyEachPass,
251+
bool DebugLogging) {
248252
for (;;) {
249253
// Parse nested pass managers by recursing.
250254
if (PipelineText.startswith("cgscc(")) {
@@ -293,9 +297,10 @@ bool Passes::parseCGSCCPassPipeline(CGSCCPassManager &CGPM,
293297
}
294298
}
295299

296-
bool Passes::parseModulePassPipeline(ModulePassManager &MPM,
297-
StringRef &PipelineText,
298-
bool VerifyEachPass, bool DebugLogging) {
300+
bool PassBuilder::parseModulePassPipeline(ModulePassManager &MPM,
301+
StringRef &PipelineText,
302+
bool VerifyEachPass,
303+
bool DebugLogging) {
299304
for (;;) {
300305
// Parse nested pass managers by recursing.
301306
if (PipelineText.startswith("module(")) {
@@ -363,8 +368,9 @@ bool Passes::parseModulePassPipeline(ModulePassManager &MPM,
363368
// Primary pass pipeline description parsing routine.
364369
// FIXME: Should this routine accept a TargetMachine or require the caller to
365370
// pre-populate the analysis managers with target-specific stuff?
366-
bool Passes::parsePassPipeline(ModulePassManager &MPM, StringRef PipelineText,
367-
bool VerifyEachPass, bool DebugLogging) {
371+
bool PassBuilder::parsePassPipeline(ModulePassManager &MPM,
372+
StringRef PipelineText, bool VerifyEachPass,
373+
bool DebugLogging) {
368374
// By default, try to parse the pipeline as-if it were within an implicit
369375
// 'module(...)' pass pipeline. If this will parse at all, it needs to
370376
// consume the entire string.
File renamed without changes.

‎llvm/tools/opt/CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ set(LLVM_LINK_COMPONENTS
1616
Target
1717
TransformUtils
1818
Vectorize
19+
Passes
1920
)
2021

2122
# Support plugins.
@@ -26,7 +27,6 @@ add_llvm_tool(opt
2627
BreakpointPrinter.cpp
2728
GraphPrinters.cpp
2829
NewPMDriver.cpp
29-
Passes.cpp
3030
PassPrinters.cpp
3131
PrintSCC.cpp
3232
opt.cpp

‎llvm/tools/opt/LLVMBuild.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,4 @@
1919
type = Tool
2020
name = opt
2121
parent = Tools
22-
required_libraries = AsmParser BitReader BitWriter CodeGen IRReader IPO Instrumentation Scalar ObjCARC all-targets
22+
required_libraries = AsmParser BitReader BitWriter CodeGen IRReader IPO Instrumentation Scalar ObjCARC Passes all-targets

‎llvm/tools/opt/Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
LEVEL := ../..
1111
TOOLNAME := opt
12-
LINK_COMPONENTS := bitreader bitwriter asmparser irreader instrumentation scalaropts objcarcopts ipo vectorize all-targets codegen
12+
LINK_COMPONENTS := bitreader bitwriter asmparser irreader instrumentation scalaropts objcarcopts ipo vectorize all-targets codegen passes
1313

1414
# Support plugins.
1515
NO_DEAD_STRIP := 1

‎llvm/tools/opt/NewPMDriver.cpp

+7-7
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
//===----------------------------------------------------------------------===//
1515

1616
#include "NewPMDriver.h"
17-
#include "Passes.h"
1817
#include "llvm/ADT/StringRef.h"
1918
#include "llvm/Analysis/CGSCCPassManager.h"
2019
#include "llvm/Bitcode/BitcodeWriterPass.h"
@@ -24,6 +23,7 @@
2423
#include "llvm/IR/Module.h"
2524
#include "llvm/IR/PassManager.h"
2625
#include "llvm/IR/Verifier.h"
26+
#include "llvm/Passes/PassBuilder.h"
2727
#include "llvm/Support/CommandLine.h"
2828
#include "llvm/Support/ErrorHandling.h"
2929
#include "llvm/Support/ToolOutputFile.h"
@@ -40,16 +40,16 @@ bool llvm::runPassPipeline(StringRef Arg0, LLVMContext &Context, Module &M,
4040
TargetMachine *TM, tool_output_file *Out,
4141
StringRef PassPipeline, OutputKind OK,
4242
VerifierKind VK) {
43-
Passes P(TM);
43+
PassBuilder PB(TM);
4444

4545
FunctionAnalysisManager FAM(DebugPM);
4646
CGSCCAnalysisManager CGAM(DebugPM);
4747
ModuleAnalysisManager MAM(DebugPM);
4848

4949
// Register all the basic analyses with the managers.
50-
P.registerModuleAnalyses(MAM);
51-
P.registerCGSCCAnalyses(CGAM);
52-
P.registerFunctionAnalyses(FAM);
50+
PB.registerModuleAnalyses(MAM);
51+
PB.registerCGSCCAnalyses(CGAM);
52+
PB.registerFunctionAnalyses(FAM);
5353

5454
// Cross register the analysis managers through their proxies.
5555
MAM.registerPass(FunctionAnalysisManagerModuleProxy(FAM));
@@ -63,8 +63,8 @@ bool llvm::runPassPipeline(StringRef Arg0, LLVMContext &Context, Module &M,
6363
if (VK > VK_NoVerifier)
6464
MPM.addPass(VerifierPass());
6565

66-
if (!P.parsePassPipeline(MPM, PassPipeline, VK == VK_VerifyEachPass,
67-
DebugPM)) {
66+
if (!PB.parsePassPipeline(MPM, PassPipeline, VK == VK_VerifyEachPass,
67+
DebugPM)) {
6868
errs() << Arg0 << ": unable to parse pass pipeline description.\n";
6969
return false;
7070
}

0 commit comments

Comments
 (0)
Please sign in to comment.