Skip to content

Commit b50f3c6

Browse files
committed
AS, allow only RA passes
1 parent 61993c0 commit b50f3c6

File tree

5 files changed

+39
-37
lines changed

5 files changed

+39
-37
lines changed

llvm/include/llvm/Passes/CodeGenPassBuilder.h

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -614,7 +614,7 @@ Error CodeGenPassBuilder<Derived, TargetMachineT>::buildPipeline(
614614

615615
if (!Opt.RegAllocPipeline.empty())
616616
return make_error<StringError>(
617-
"Extra passes in regalloc pipeline: " + Opt.RegAllocPipeline,
617+
"extra passes in regalloc pipeline: " + Opt.RegAllocPipeline,
618618
std::make_error_code(std::errc::invalid_argument));
619619

620620
return verifyStartStop(*StartStopInfo);
@@ -1129,8 +1129,7 @@ bool CodeGenPassBuilder<Derived, TargetMachineT>::addRegAllocPassFromOpt(
11291129
StringRef PassOpt;
11301130
std::tie(PassOpt, Opt.RegAllocPipeline) = Opt.RegAllocPipeline.split(',');
11311131
// Reuse the registered parser to parse the pass name.
1132-
#define MACHINE_FUNCTION_PASS_WITH_PARAMS(NAME, CLASS, CREATE_PASS, PARSER, \
1133-
PARAMS) \
1132+
#define RA_PASS_WITH_PARAMS(NAME, CLASS, CREATE_PASS, PARSER, PARAMS) \
11341133
if (PB.checkParametrizedPassName(PassOpt, NAME)) { \
11351134
auto Params = PB.parsePassParameters(PARSER, PassOpt, NAME, \
11361135
const_cast<const PassBuilder &>(PB)); \
@@ -1140,17 +1139,17 @@ bool CodeGenPassBuilder<Derived, TargetMachineT>::addRegAllocPassFromOpt(
11401139
} \
11411140
if (!MatchPassTo.empty()) { \
11421141
if (MatchPassTo != CLASS) \
1143-
report_fatal_error("Expected " + \
1142+
report_fatal_error("expected " + \
11441143
PIC->getPassNameForClassName(MatchPassTo) + \
1145-
" in option -regalloc-npm", \
1144+
" in option --regalloc-npm", \
11461145
false); \
11471146
} \
11481147
addPass(CREATE_PASS(Params.get())); \
11491148
return true; \
11501149
}
11511150
#include "llvm/Passes/MachinePassRegistry.def"
11521151
if (PassOpt != "default") {
1153-
report_fatal_error("Unknown register allocator pass: " + PassOpt, false);
1152+
report_fatal_error("unknown register allocator pass: " + PassOpt, false);
11541153
}
11551154
}
11561155
// If user did not give a specific pass, use the default provided.

llvm/include/llvm/Passes/MachinePassRegistry.def

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,19 @@ MACHINE_FUNCTION_PASS_WITH_PARAMS(
247247
parseMachineSinkingPassOptions, "enable-sink-fold")
248248

249249
MACHINE_FUNCTION_PASS_WITH_PARAMS(
250+
"virt-reg-rewriter", "VirtRegRewriterPass",
251+
[](bool ClearVirtRegs) { return VirtRegRewriterPass(ClearVirtRegs); },
252+
parseVirtRegRewriterPassOptions, "no-clear-vregs;clear-vregs")
253+
254+
#ifndef RA_PASS_WITH_PARAMS
255+
// Define MachineFunction passes that are register allocators.
256+
// This is to differentiate them from other MachineFunction passes
257+
// to be used in the --regalloc-npm option.
258+
#define RA_PASS_WITH_PARAMS(NAME, CLASS, CREATE_PASS, PARSER, PARAMS) \
259+
MACHINE_FUNCTION_PASS_WITH_PARAMS(NAME, CLASS, CREATE_PASS, PARSER, PARAMS)
260+
#endif
261+
262+
RA_PASS_WITH_PARAMS(
250263
"regallocfast", "RegAllocFastPass",
251264
[](RegAllocFastPass::Options Opts) { return RegAllocFastPass(Opts); },
252265
[](StringRef Params, const PassBuilder &PB) {
@@ -255,19 +268,15 @@ MACHINE_FUNCTION_PASS_WITH_PARAMS(
255268
"filter=reg-filter;no-clear-vregs")
256269

257270
// 'all' is the default filter.
258-
MACHINE_FUNCTION_PASS_WITH_PARAMS(
271+
RA_PASS_WITH_PARAMS(
259272
"greedy", "RAGreedyPass",
260273
[](RAGreedyPass::Options Opts) { return RAGreedyPass(Opts); },
261274
[](StringRef Params, const PassBuilder &PB) {
262275
return parseRegAllocGreedyFilterFunc(PB, Params);
263-
}, "reg-filter"
264-
)
265-
266-
MACHINE_FUNCTION_PASS_WITH_PARAMS(
267-
"virt-reg-rewriter", "VirtRegRewriterPass",
268-
[](bool ClearVirtRegs) { return VirtRegRewriterPass(ClearVirtRegs); },
269-
parseVirtRegRewriterPassOptions, "no-clear-vregs;clear-vregs")
276+
},
277+
"reg-filter")
270278

279+
#undef RA_PASS_WITH_PARAMS
271280
#undef MACHINE_FUNCTION_PASS_WITH_PARAMS
272281

273282
// After a pass is converted to new pass manager, its entry should be moved from

llvm/include/llvm/Target/CGPassBuilderOption.h

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -21,22 +21,6 @@
2121
namespace llvm {
2222

2323
enum class RunOutliner { TargetDefault, AlwaysOutline, NeverOutline };
24-
enum class RegAllocType { Unset, Default, Basic, Fast, Greedy, PBQP };
25-
26-
class RegAllocTypeParser : public cl::parser<RegAllocType> {
27-
public:
28-
RegAllocTypeParser(cl::Option &O) : cl::parser<RegAllocType>(O) {}
29-
void initialize() {
30-
cl::parser<RegAllocType>::initialize();
31-
addLiteralOption("default", RegAllocType::Default,
32-
"Default register allocator");
33-
addLiteralOption("pbqp", RegAllocType::PBQP, "PBQP register allocator");
34-
addLiteralOption("fast", RegAllocType::Fast, "Fast register allocator");
35-
addLiteralOption("basic", RegAllocType::Basic, "Basic register allocator");
36-
addLiteralOption("greedy", RegAllocType::Greedy,
37-
"Greedy register allocator");
38-
}
39-
};
4024

4125
// Not one-on-one but mostly corresponding to commandline options in
4226
// TargetPassConfig.cpp.

llvm/test/tools/llc/new-pm/x86_64-regalloc-pipeline.mir

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,18 @@
1111
# attempts to insert an extraneous pass.
1212
# RUN: not llc -mtriple=x86_64-unknown-linux-gnu -enable-new-pm -O3 -regalloc-npm='default,default,basic' 2>&1 | FileCheck %s --check-prefix=CHECK-ERROR
1313

14-
# RUN: not llc -mtriple=x86_64-unknown-linux-gnu -enable-new-pm -O3 -regalloc-npm='invalidpass' -print-pipeline-passes %s -o - 2>&1 | FileCheck %s --check-prefix=CHECK-INVALID
14+
# RUN: not llc -mtriple=x86_64-unknown-linux-gnu -enable-new-pm -O3 -regalloc-npm='machine-cp' -print-pipeline-passes %s -o - 2>&1 | FileCheck %s --check-prefix=CHECK-INVALID
15+
# RUN: not llc -mtriple=x86_64-unknown-linux-gnu -enable-new-pm -passes='machine-sink' -regalloc-npm='greedy' -print-pipeline-passes %s -o - 2>&1 | FileCheck %s --check-prefix=CHECK-BOTH-INVALID
16+
17+
# RUN: not llc -mtriple=x86_64-unknown-linux-gnu -enable-new-pm -O0 -regalloc-npm='greedy' -print-pipeline-passes %s -o - 2>&1 | FileCheck %s --check-prefix=CHECK-ONLY-FAST
1518

1619
# CHECK: greedy<tile-reg>
1720
# CHECK: greedy<all>
1821

1922
# CHECK-FAST: regallocfast
2023
# CHECK-GREEDY: greedy<all>
2124
# CHECK-GREEDY-FILTER: greedy<tile-reg>
22-
# CHECK-ERROR: Extra passes in regalloc pipeline: basic
23-
# CHECK-INVALID: Unknown register allocator pass: invalidpass
25+
# CHECK-ERROR: extra passes in regalloc pipeline: basic
26+
# CHECK-INVALID: unknown register allocator pass: machine-cp
27+
# CHECK-BOTH-INVALID: --passes and --regalloc-npm cannot be used together
28+
# CHECK-ONLY-FAST: expected regallocfast in option --regalloc-npm

llvm/tools/llc/NewPMDriver.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,9 @@
4949
using namespace llvm;
5050

5151
static cl::opt<std::string>
52-
RegAlloc("regalloc-npm",
53-
cl::desc("Register allocator to use for new pass manager"),
54-
cl::Hidden);
52+
RegAllocPasses("regalloc-npm",
53+
cl::desc("Register allocator to use for new pass manager"),
54+
cl::Hidden);
5555

5656
static cl::opt<bool>
5757
DebugPM("debug-pass-manager", cl::Hidden,
@@ -98,14 +98,19 @@ int llvm::compileModuleWithNewPM(
9898
<< TargetPassConfig::getLimitedCodeGenPipelineReason() << ".\n";
9999
return 1;
100100
}
101+
if (!PassPipeline.empty() && !RegAllocPasses.empty()) {
102+
WithColor::error(errs(), Arg0)
103+
<< "--passes and --regalloc-npm cannot be used together.\n";
104+
return 1;
105+
}
101106

102107
raw_pwrite_stream *OS = &Out->os();
103108

104109
// Fetch options from TargetPassConfig
105110
CGPassBuilderOption Opt = getCGPassBuilderOption();
106111
Opt.DisableVerify = VK != VerifierKind::InputOutput;
107112
Opt.DebugPM = DebugPM;
108-
Opt.RegAllocPipeline = RegAlloc;
113+
Opt.RegAllocPipeline = RegAllocPasses;
109114

110115
MachineModuleInfo MMI(Target.get());
111116

0 commit comments

Comments
 (0)