Skip to content

Commit d5e295e

Browse files
committed
AS, allow only RA passes
1 parent 8edc1e3 commit d5e295e

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
@@ -611,7 +611,7 @@ Error CodeGenPassBuilder<Derived, TargetMachineT>::buildPipeline(
611611

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

617617
return verifyStartStop(*StartStopInfo);
@@ -1126,8 +1126,7 @@ bool CodeGenPassBuilder<Derived, TargetMachineT>::addRegAllocPassFromOpt(
11261126
StringRef PassOpt;
11271127
std::tie(PassOpt, Opt.RegAllocPipeline) = Opt.RegAllocPipeline.split(',');
11281128
// Reuse the registered parser to parse the pass name.
1129-
#define MACHINE_FUNCTION_PASS_WITH_PARAMS(NAME, CLASS, CREATE_PASS, PARSER, \
1130-
PARAMS) \
1129+
#define RA_PASS_WITH_PARAMS(NAME, CLASS, CREATE_PASS, PARSER, PARAMS) \
11311130
if (PB.checkParametrizedPassName(PassOpt, NAME)) { \
11321131
auto Params = PB.parsePassParameters(PARSER, PassOpt, NAME, \
11331132
const_cast<const PassBuilder &>(PB)); \
@@ -1137,17 +1136,17 @@ bool CodeGenPassBuilder<Derived, TargetMachineT>::addRegAllocPassFromOpt(
11371136
} \
11381137
if (!MatchPassTo.empty()) { \
11391138
if (MatchPassTo != CLASS) \
1140-
report_fatal_error("Expected " + \
1139+
report_fatal_error("expected " + \
11411140
PIC->getPassNameForClassName(MatchPassTo) + \
1142-
" in option -regalloc-npm", \
1141+
" in option --regalloc-npm", \
11431142
false); \
11441143
} \
11451144
addPass(CREATE_PASS(Params.get())); \
11461145
return true; \
11471146
}
11481147
#include "llvm/Passes/MachinePassRegistry.def"
11491148
if (PassOpt != "default") {
1150-
report_fatal_error("Unknown register allocator pass: " + PassOpt, false);
1149+
report_fatal_error("unknown register allocator pass: " + PassOpt, false);
11511150
}
11521151
}
11531152
// 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
@@ -241,7 +241,15 @@ MACHINE_FUNCTION_PASS_WITH_PARAMS(
241241
},
242242
parseMachineSinkingPassOptions, "enable-sink-fold")
243243

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

252260
// 'all' is the default filter.
253-
MACHINE_FUNCTION_PASS_WITH_PARAMS(
261+
RA_PASS_WITH_PARAMS(
254262
"greedy", "RAGreedyPass",
255263
[](RAGreedyPass::Options Opts) { return RAGreedyPass(Opts); },
256264
[](StringRef Params, const PassBuilder &PB) {
257265
return parseRegAllocGreedyFilterFunc(PB, Params);
258-
}, "reg-filter"
259-
)
266+
},
267+
"reg-filter")
268+
269+
#undef RA_PASS_WITH_PARAMS
260270
#undef MACHINE_FUNCTION_PASS_WITH_PARAMS
261271

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