Skip to content

Commit f93228a

Browse files
committed
[RegAlloc][NewPM] Plug Greedy RA in codegen pipeline
1 parent 516482f commit f93228a

File tree

15 files changed

+71
-14
lines changed

15 files changed

+71
-14
lines changed

llvm/include/llvm/Passes/CodeGenPassBuilder.h

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1059,7 +1059,7 @@ void CodeGenPassBuilder<Derived, TargetMachineT>::addMachineSSAOptimization(
10591059
///
10601060
/// A target that uses the standard regalloc pass order for fast or optimized
10611061
/// allocation may still override this for per-target regalloc
1062-
/// selection. But -regalloc=... always takes precedence.
1062+
/// selection. But -regalloc-npm=... always takes precedence.
10631063
template <typename Derived, typename TargetMachineT>
10641064
void CodeGenPassBuilder<Derived, TargetMachineT>::addTargetRegisterAllocator(
10651065
AddMachinePass &addPass, bool Optimized) const {
@@ -1076,6 +1076,22 @@ template <typename Derived, typename TargetMachineT>
10761076
void CodeGenPassBuilder<Derived, TargetMachineT>::addRegAllocPass(
10771077
AddMachinePass &addPass, bool Optimized) const {
10781078
// TODO: Parse Opt.RegAlloc to add register allocator.
1079+
// Use the specified -regalloc-npm={basic|greedy|fast|pbqp}
1080+
if (Opt.RegAlloc > RegAllocType::Default) {
1081+
switch (Opt.RegAlloc) {
1082+
case RegAllocType::Fast:
1083+
addPass(RegAllocFastPass());
1084+
break;
1085+
case RegAllocType::Greedy:
1086+
addPass(RAGreedyPass());
1087+
break;
1088+
default:
1089+
llvm_unreachable("Register allocator not supported yet.");
1090+
}
1091+
return;
1092+
}
1093+
// -regalloc=default or unspecified, so pick based on the optimization level.
1094+
derived().addTargetRegisterAllocator(addPass, Optimized);
10791095
}
10801096

10811097
template <typename Derived, typename TargetMachineT>

llvm/include/llvm/Passes/MachinePassRegistry.def

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,12 +188,12 @@ MACHINE_FUNCTION_PASS_WITH_PARAMS(
188188
},
189189
"filter=reg-filter;no-clear-vregs")
190190

191+
// 'all' is the default filter
191192
MACHINE_FUNCTION_PASS_WITH_PARAMS(
192193
"regallocgreedy", "RAGreedyPass",
193194
[](RAGreedyPass::Options Opts) { return RAGreedyPass(Opts); },
194195
[PB = this](StringRef Params) {
195-
// TODO: parseRegAllocGreedyFilterFunc(*PB, Params);
196-
return Expected<RAGreedyPass::Options>(RAGreedyPass::Options{});
196+
return parseRegAllocGreedyFilterFunc(*PB, Params);
197197
}, "reg-filter"
198198
)
199199
#undef MACHINE_FUNCTION_PASS_WITH_PARAMS

llvm/include/llvm/Target/CGPassBuilderOption.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ struct CGPassBuilderOption {
5353
bool RequiresCodeGenSCCOrder = false;
5454

5555
RunOutliner EnableMachineOutliner = RunOutliner::TargetDefault;
56-
StringRef RegAlloc = "default";
56+
RegAllocType RegAlloc = RegAllocType::Default;
5757
std::optional<GlobalISelAbortMode> EnableGlobalISelAbort;
5858
std::string FSProfileFile;
5959
std::string FSRemappingFile;

llvm/lib/Passes/PassBuilder.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1315,6 +1315,19 @@ parseBoundsCheckingOptions(StringRef Params) {
13151315
return Mode;
13161316
}
13171317

1318+
Expected<RAGreedyPass::Options> parseRegAllocGreedyFilterFunc(PassBuilder &PB, StringRef Params) {
1319+
if (Params.empty() || Params == "all") {
1320+
return RAGreedyPass::Options();
1321+
}
1322+
std::optional<RegAllocFilterFunc> Filter = PB.parseRegAllocFilter(Params);
1323+
if (!Filter) {
1324+
return make_error<StringError>(
1325+
formatv("invalid regallocgreedy register filter '{0}' ", Params).str(),
1326+
inconvertibleErrorCode());
1327+
}
1328+
return RAGreedyPass::Options{*Filter, Params};
1329+
}
1330+
13181331
} // namespace
13191332

13201333
/// Tests whether a pass name starts with a valid prefix for a default pipeline

llvm/test/CodeGen/AArch64/implicit-def-remat-requires-impdef-check.mir

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py UTC_ARGS: --version 4
22
# RUN: llc -mtriple=arm64-apple-macosx -mcpu=apple-m1 -stress-regalloc=4 -verify-regalloc -run-pass=greedy -o - %s | FileCheck %s
3+
# RUN: llc -mtriple=arm64-apple-macosx -mcpu=apple-m1 -stress-regalloc=4 -verify-regalloc -passes=regallocgreedy -o - %s | FileCheck %s
34

45
--- |
56
define void @inst_stores_to_dead_spill_implicit_def_impdef() {

llvm/test/CodeGen/AArch64/implicit-def-with-impdef-greedy-assert.mir

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py UTC_ARGS: --version 3
22
# RUN: llc -mtriple=arm64-apple-ios -run-pass=greedy -o - %s | FileCheck %s
3+
# RUN: llc -mtriple=arm64-apple-ios -passes=regallocgreedy -o - %s | FileCheck %s
34

45
---
56
name: widget

llvm/test/CodeGen/AArch64/pr51516.mir

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# RUN: llc -mtriple=aarch64-unknown-fuchsia -run-pass=greedy -verify-machineinstrs -o - %s | FileCheck %s
2+
# RUN: llc -mtriple=aarch64-unknown-fuchsia -passes=regallocgreedy -verify-machineinstrs -o - %s | FileCheck %s
23

34
# Check that we spill %31 and do not rematerialize it since the use operand
45
# of ADDXri is killed by the STRXui in this block.

llvm/test/CodeGen/AArch64/spill-fold.mir

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# RUN: llc -mtriple=aarch64-none-linux-gnu -run-pass greedy -verify-machineinstrs -o - %s | FileCheck %s
22
# RUN: llc -mtriple=aarch64_be-none-linux-gnu -run-pass greedy -verify-machineinstrs -o - %s | FileCheck %s
3+
# RUN: llc -mtriple=aarch64-none-linux-gnu -passes=regallocgreedy -o - %s | FileCheck %s
4+
# RUN: llc -mtriple=aarch64_be-none-linux-gnu -passes=regallocgreedy -o - %s | FileCheck %s
35
--- |
46
define i64 @test_subreg_spill_fold() { ret i64 0 }
57
define i64 @test_subreg_spill_fold2() { ret i64 0 }

llvm/test/CodeGen/AMDGPU/extend-phi-subrange-not-in-parent.mir

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py
22
# RUN: llc -mtriple=amdgcn-amd-amdhsa -mcpu=gfx90a -verify-regalloc -run-pass=greedy -o - %s | FileCheck %s
3+
# RUN: llc -mtriple=amdgcn-amd-amdhsa -mcpu=gfx90a -verify-regalloc -passes=regallocgreedy -o - %s | FileCheck %s
34

45
# Initially %2 starts out with 2 subranges (one for sub0, and one for
56
# the rest of the lanes). After %2 is split, after refineSubRanges the

llvm/test/CodeGen/MIR/Generic/runPass.mir

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# RUN: llc -run-pass=regallocbasic -debug-pass=Arguments -o - %s | FileCheck %s
33
# RUN: llc -run-pass=regallocfast -debug-pass=Arguments -o - %s | FileCheck %s
44
# RUN: llc -passes=regallocfast -o - %s | FileCheck %s
5+
# RUN: llc -passes=regallocgreedy -o - %s | FileCheck %s
56

67
# Check that passes are initialized correctly, so that it's possible to
78
# use -run-pass.

0 commit comments

Comments
 (0)