Skip to content

Commit 20eede6

Browse files
committed
Error out on AMDGPU for regalloc-npm flag
1 parent f93228a commit 20eede6

File tree

6 files changed

+47
-16
lines changed

6 files changed

+47
-16
lines changed

llvm/include/llvm/Passes/CodeGenPassBuilder.h

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1086,7 +1086,7 @@ void CodeGenPassBuilder<Derived, TargetMachineT>::addRegAllocPass(
10861086
addPass(RAGreedyPass());
10871087
break;
10881088
default:
1089-
llvm_unreachable("Register allocator not supported yet.");
1089+
report_fatal_error("Register allocator not supported yet.", false);
10901090
}
10911091
return;
10921092
}
@@ -1162,20 +1162,23 @@ void CodeGenPassBuilder<Derived, TargetMachineT>::addOptimizedRegAlloc(
11621162
// PreRA instruction scheduling.
11631163
addPass(MachineSchedulerPass());
11641164

1165-
if (derived().addRegAssignmentOptimized(addPass)) {
1166-
// Allow targets to expand pseudo instructions depending on the choice of
1167-
// registers before MachineCopyPropagation.
1168-
derived().addPostRewrite(addPass);
1165+
if (auto E = derived().addRegAssignmentOptimized(addPass)) {
1166+
// addRegAssignmentOptimized did not add a reg alloc pass, so do nothing.
1167+
// FIXME: This is not really an error.
1168+
return;
1169+
}
1170+
// Allow targets to expand pseudo instructions depending on the choice of
1171+
// registers before MachineCopyPropagation.
1172+
derived().addPostRewrite(addPass);
11691173

1170-
// Copy propagate to forward register uses and try to eliminate COPYs that
1171-
// were not coalesced.
1172-
addPass(MachineCopyPropagationPass());
1174+
// Copy propagate to forward register uses and try to eliminate COPYs that
1175+
// were not coalesced.
1176+
addPass(MachineCopyPropagationPass());
11731177

1174-
// Run post-ra machine LICM to hoist reloads / remats.
1175-
//
1176-
// FIXME: can this move into MachineLateOptimization?
1177-
addPass(MachineLICMPass());
1178-
}
1178+
// Run post-ra machine LICM to hoist reloads / remats.
1179+
//
1180+
// FIXME: can this move into MachineLateOptimization?
1181+
addPass(MachineLICMPass());
11791182
}
11801183

11811184
//===---------------------------------------------------------------------===//

llvm/include/llvm/Target/CGPassBuilderOption.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
namespace llvm {
2121

2222
enum class RunOutliner { TargetDefault, AlwaysOutline, NeverOutline };
23-
enum class RegAllocType { Default, Basic, Fast, Greedy, PBQP };
23+
enum class RegAllocType { Unset, Default, Basic, Fast, Greedy, PBQP };
2424

2525
// Not one-on-one but mostly corresponding to commandline options in
2626
// TargetPassConfig.cpp.
@@ -53,7 +53,7 @@ struct CGPassBuilderOption {
5353
bool RequiresCodeGenSCCOrder = false;
5454

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

llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@
6868
#include "llvm/MC/TargetRegistry.h"
6969
#include "llvm/Passes/PassBuilder.h"
7070
#include "llvm/Support/FormatVariadic.h"
71+
#include "llvm/Target/CGPassBuilderOption.h"
7172
#include "llvm/Transforms/HipStdPar/HipStdPar.h"
7273
#include "llvm/Transforms/IPO.h"
7374
#include "llvm/Transforms/IPO/AlwaysInliner.h"
@@ -2099,6 +2100,28 @@ void AMDGPUCodeGenPassBuilder::addMachineSSAOptimization(
20992100
addPass(SIShrinkInstructionsPass());
21002101
}
21012102

2103+
static const char RegAllocNPMNotSupportedMessage[] =
2104+
"-regalloc-npm not supported with amdgcn. Use -sgpr-regalloc-npm, "
2105+
"-wwm-regalloc-npm, and -vgpr-regalloc-npm";
2106+
2107+
Error AMDGPUCodeGenPassBuilder::addRegAssignmentOptimized(
2108+
AddMachinePass &addPass) const {
2109+
if (Opt.RegAlloc != RegAllocType::Unset)
2110+
report_fatal_error(RegAllocNPMNotSupportedMessage, false);
2111+
2112+
return make_error<StringError>("not implemented yet",
2113+
inconvertibleErrorCode());
2114+
}
2115+
2116+
Error AMDGPUCodeGenPassBuilder::addRegAssignmentFast(
2117+
AddMachinePass &addPass) const {
2118+
if (Opt.RegAlloc != RegAllocType::Unset)
2119+
report_fatal_error(RegAllocNPMNotSupportedMessage, false);
2120+
2121+
return make_error<StringError>("not implemented yet",
2122+
inconvertibleErrorCode());
2123+
}
2124+
21022125
bool AMDGPUCodeGenPassBuilder::isPassEnabled(const cl::opt<bool> &Opt,
21032126
CodeGenOptLevel Level) const {
21042127
if (Opt.getNumOccurrences())

llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,8 @@ class AMDGPUCodeGenPassBuilder
176176
void addAsmPrinter(AddMachinePass &, CreateMCStreamer) const;
177177
Error addInstSelector(AddMachinePass &) const;
178178
void addMachineSSAOptimization(AddMachinePass &) const;
179+
Error addRegAssignmentOptimized(AddMachinePass &) const;
180+
Error addRegAssignmentFast(AddMachinePass &) const;
179181

180182
/// Check if a pass is enabled given \p Opt option. The option always
181183
/// overrides defaults if explicitly used. Otherwise its default will be used

llvm/test/CodeGen/AMDGPU/sgpr-regalloc-flags.ll

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,11 @@
1212
; RUN: not --crash llc -verify-machineinstrs=0 -regalloc=basic -mtriple=amdgcn-amd-amdhsa -debug-pass=Structure -o /dev/null %s 2>&1 | FileCheck -check-prefix=REGALLOC %s
1313
; RUN: not --crash llc -verify-machineinstrs=0 -regalloc=fast -O0 -mtriple=amdgcn-amd-amdhsa -debug-pass=Structure -o /dev/null %s 2>&1 | FileCheck -check-prefix=REGALLOC %s
1414

15+
; RUN: not llc -enable-new-pm -verify-machineinstrs=0 -regalloc-npm=fast -O0 -mtriple=amdgcn-amd-amdhsa -o /dev/null %s 2>&1 | FileCheck -check-prefix=REGALLOC-NPM %s
16+
; RUN: not llc -enable-new-pm -verify-machineinstrs=0 -regalloc-npm=basic -O3 -mtriple=amdgcn-amd-amdhsa -o /dev/null %s 2>&1 | FileCheck -check-prefix=REGALLOC-NPM %s
1517

1618
; REGALLOC: -regalloc not supported with amdgcn. Use -sgpr-regalloc, -wwm-regalloc, and -vgpr-regalloc
19+
; REGALLOC-NPM: -regalloc-npm not supported with amdgcn. Use -sgpr-regalloc-npm, -wwm-regalloc-npm, and -vgpr-regalloc-npm
1720

1821
; DEFAULT: Greedy Register Allocator
1922
; DEFAULT-NEXT: Virtual Register Rewriter

llvm/tools/llc/NewPMDriver.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ using namespace llvm;
5656
// create option for RegAllocType enum
5757
static cl::opt<RegAllocType> RegAlloc(
5858
"regalloc-npm", cl::desc("Register allocator to use for new pass manager"),
59-
cl::Hidden, cl::init(RegAllocType::Default),
59+
cl::Hidden, cl::init(RegAllocType::Unset),
6060
cl::values(
6161
clEnumValN(RegAllocType::Default, "default",
6262
"Default register allocator"),

0 commit comments

Comments
 (0)