Skip to content

Commit

Permalink
Error out on AMDGPU for regalloc-npm flag
Browse files Browse the repository at this point in the history
  • Loading branch information
optimisan committed Dec 19, 2024
1 parent f93228a commit 20eede6
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 16 deletions.
29 changes: 16 additions & 13 deletions llvm/include/llvm/Passes/CodeGenPassBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -1086,7 +1086,7 @@ void CodeGenPassBuilder<Derived, TargetMachineT>::addRegAllocPass(
addPass(RAGreedyPass());
break;
default:
llvm_unreachable("Register allocator not supported yet.");
report_fatal_error("Register allocator not supported yet.", false);
}
return;
}
Expand Down Expand Up @@ -1162,20 +1162,23 @@ void CodeGenPassBuilder<Derived, TargetMachineT>::addOptimizedRegAlloc(
// PreRA instruction scheduling.
addPass(MachineSchedulerPass());

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

// Copy propagate to forward register uses and try to eliminate COPYs that
// were not coalesced.
addPass(MachineCopyPropagationPass());
// Copy propagate to forward register uses and try to eliminate COPYs that
// were not coalesced.
addPass(MachineCopyPropagationPass());

// Run post-ra machine LICM to hoist reloads / remats.
//
// FIXME: can this move into MachineLateOptimization?
addPass(MachineLICMPass());
}
// Run post-ra machine LICM to hoist reloads / remats.
//
// FIXME: can this move into MachineLateOptimization?
addPass(MachineLICMPass());
}

//===---------------------------------------------------------------------===//
Expand Down
4 changes: 2 additions & 2 deletions llvm/include/llvm/Target/CGPassBuilderOption.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
namespace llvm {

enum class RunOutliner { TargetDefault, AlwaysOutline, NeverOutline };
enum class RegAllocType { Default, Basic, Fast, Greedy, PBQP };
enum class RegAllocType { Unset, Default, Basic, Fast, Greedy, PBQP };

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

RunOutliner EnableMachineOutliner = RunOutliner::TargetDefault;
RegAllocType RegAlloc = RegAllocType::Default;
RegAllocType RegAlloc = RegAllocType::Unset;
std::optional<GlobalISelAbortMode> EnableGlobalISelAbort;
std::string FSProfileFile;
std::string FSRemappingFile;
Expand Down
23 changes: 23 additions & 0 deletions llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
#include "llvm/MC/TargetRegistry.h"
#include "llvm/Passes/PassBuilder.h"
#include "llvm/Support/FormatVariadic.h"
#include "llvm/Target/CGPassBuilderOption.h"
#include "llvm/Transforms/HipStdPar/HipStdPar.h"
#include "llvm/Transforms/IPO.h"
#include "llvm/Transforms/IPO/AlwaysInliner.h"
Expand Down Expand Up @@ -2099,6 +2100,28 @@ void AMDGPUCodeGenPassBuilder::addMachineSSAOptimization(
addPass(SIShrinkInstructionsPass());
}

static const char RegAllocNPMNotSupportedMessage[] =
"-regalloc-npm not supported with amdgcn. Use -sgpr-regalloc-npm, "
"-wwm-regalloc-npm, and -vgpr-regalloc-npm";

Error AMDGPUCodeGenPassBuilder::addRegAssignmentOptimized(
AddMachinePass &addPass) const {
if (Opt.RegAlloc != RegAllocType::Unset)
report_fatal_error(RegAllocNPMNotSupportedMessage, false);

return make_error<StringError>("not implemented yet",
inconvertibleErrorCode());
}

Error AMDGPUCodeGenPassBuilder::addRegAssignmentFast(
AddMachinePass &addPass) const {
if (Opt.RegAlloc != RegAllocType::Unset)
report_fatal_error(RegAllocNPMNotSupportedMessage, false);

return make_error<StringError>("not implemented yet",
inconvertibleErrorCode());
}

bool AMDGPUCodeGenPassBuilder::isPassEnabled(const cl::opt<bool> &Opt,
CodeGenOptLevel Level) const {
if (Opt.getNumOccurrences())
Expand Down
2 changes: 2 additions & 0 deletions llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.h
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,8 @@ class AMDGPUCodeGenPassBuilder
void addAsmPrinter(AddMachinePass &, CreateMCStreamer) const;
Error addInstSelector(AddMachinePass &) const;
void addMachineSSAOptimization(AddMachinePass &) const;
Error addRegAssignmentOptimized(AddMachinePass &) const;
Error addRegAssignmentFast(AddMachinePass &) const;

/// Check if a pass is enabled given \p Opt option. The option always
/// overrides defaults if explicitly used. Otherwise its default will be used
Expand Down
3 changes: 3 additions & 0 deletions llvm/test/CodeGen/AMDGPU/sgpr-regalloc-flags.ll
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,11 @@
; 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
; 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

; 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
; 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

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

; DEFAULT: Greedy Register Allocator
; DEFAULT-NEXT: Virtual Register Rewriter
Expand Down
2 changes: 1 addition & 1 deletion llvm/tools/llc/NewPMDriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ using namespace llvm;
// create option for RegAllocType enum
static cl::opt<RegAllocType> RegAlloc(
"regalloc-npm", cl::desc("Register allocator to use for new pass manager"),
cl::Hidden, cl::init(RegAllocType::Default),
cl::Hidden, cl::init(RegAllocType::Unset),
cl::values(
clEnumValN(RegAllocType::Default, "default",
"Default register allocator"),
Expand Down

0 comments on commit 20eede6

Please sign in to comment.