Skip to content

Commit adabf4e

Browse files
committed
AS, allow only RA passes
1 parent a0c2223 commit adabf4e

File tree

5 files changed

+36
-33
lines changed

5 files changed

+36
-33
lines changed

llvm/include/llvm/Passes/CodeGenPassBuilder.h

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

611611
if (!Opt.RegAllocPipeline.empty())
612612
return make_error<StringError>(
613-
"Extra passes in regalloc pipeline: " + Opt.RegAllocPipeline,
613+
"extra passes in regalloc pipeline: " + Opt.RegAllocPipeline,
614614
std::make_error_code(std::errc::invalid_argument));
615615

616616
return verifyStartStop(*StartStopInfo);
@@ -1125,8 +1125,7 @@ bool CodeGenPassBuilder<Derived, TargetMachineT>::addRegAllocPassFromOpt(
11251125
StringRef PassOpt;
11261126
std::tie(PassOpt, Opt.RegAllocPipeline) = Opt.RegAllocPipeline.split(',');
11271127
// Reuse the registered parser to parse the pass name.
1128-
#define MACHINE_FUNCTION_PASS_WITH_PARAMS(NAME, CLASS, CREATE_PASS, PARSER, \
1129-
PARAMS) \
1128+
#define RA_PASS_WITH_PARAMS(NAME, CLASS, CREATE_PASS, PARSER, PARAMS) \
11301129
if (PB.checkParametrizedPassName(PassOpt, NAME)) { \
11311130
auto Params = PB.parsePassParameters(PARSER, PassOpt, NAME, \
11321131
const_cast<const PassBuilder &>(PB)); \
@@ -1136,17 +1135,17 @@ bool CodeGenPassBuilder<Derived, TargetMachineT>::addRegAllocPassFromOpt(
11361135
} \
11371136
if (!MatchPassTo.empty()) { \
11381137
if (MatchPassTo != CLASS) \
1139-
report_fatal_error("Expected " + \
1138+
report_fatal_error("expected " + \
11401139
PIC->getPassNameForClassName(MatchPassTo) + \
1141-
" in option -regalloc-npm", \
1140+
" in option --regalloc-npm", \
11421141
false); \
11431142
} \
11441143
addPass(CREATE_PASS(Params.get())); \
11451144
return true; \
11461145
}
11471146
#include "llvm/Passes/MachinePassRegistry.def"
11481147
if (PassOpt != "default") {
1149-
report_fatal_error("Unknown register allocator pass: " + PassOpt, false);
1148+
report_fatal_error("unknown register allocator pass: " + PassOpt, false);
11501149
}
11511150
}
11521151
// If user did not give a specific pass, use the default provided.

llvm/include/llvm/Passes/MachinePassRegistry.def

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,15 @@ MACHINE_FUNCTION_PASS_WITH_PARAMS(
239239
},
240240
parseMachineSinkingPassOptions, "enable-sink-fold")
241241

242-
MACHINE_FUNCTION_PASS_WITH_PARAMS(
242+
#ifndef RA_PASS_WITH_PARAMS
243+
// Define MachineFunction passes that are register allocators.
244+
// This is to differentiate them from other MachineFunction passes
245+
// to be used in the --regalloc-npm option.
246+
#define RA_PASS_WITH_PARAMS(NAME, CLASS, CREATE_PASS, PARSER, PARAMS) \
247+
MACHINE_FUNCTION_PASS_WITH_PARAMS(NAME, CLASS, CREATE_PASS, PARSER, PARAMS)
248+
#endif
249+
250+
RA_PASS_WITH_PARAMS(
243251
"regallocfast", "RegAllocFastPass",
244252
[](RegAllocFastPass::Options Opts) { return RegAllocFastPass(Opts); },
245253
[](StringRef Params, const PassBuilder &PB) {
@@ -248,13 +256,15 @@ MACHINE_FUNCTION_PASS_WITH_PARAMS(
248256
"filter=reg-filter;no-clear-vregs")
249257

250258
// 'all' is the default filter.
251-
MACHINE_FUNCTION_PASS_WITH_PARAMS(
259+
RA_PASS_WITH_PARAMS(
252260
"greedy", "RAGreedyPass",
253261
[](RAGreedyPass::Options Opts) { return RAGreedyPass(Opts); },
254262
[](StringRef Params, const PassBuilder &PB) {
255263
return parseRegAllocGreedyFilterFunc(PB, Params);
256-
}, "reg-filter"
257-
)
264+
},
265+
"reg-filter")
266+
267+
#undef RA_PASS_WITH_PARAMS
258268
#undef MACHINE_FUNCTION_PASS_WITH_PARAMS
259269

260270
// 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)