[AMDGPU] Support function attribute to override postRA scheduling direction (#147708)

This patch adds support for controlling the post-RA machine scheduler
direction
(topdown, bottomup, bidirectional) on a per-function basis using the 
"amdgpu-post-ra-direction" function attribute.
This commit is contained in:
Harrison Hao 2025-08-01 16:07:09 +08:00 committed by GitHub
parent 76ce464073
commit f9b258c73a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 74 additions and 0 deletions

View File

@ -340,6 +340,43 @@ void GCNSubtarget::overrideSchedPolicy(MachineSchedPolicy &Policy,
Policy.ShouldTrackLaneMasks = true;
}
void GCNSubtarget::overridePostRASchedPolicy(MachineSchedPolicy &Policy,
const SchedRegion &Region) const {
const Function &F = Region.RegionBegin->getMF()->getFunction();
Attribute PostRADirectionAttr = F.getFnAttribute("amdgpu-post-ra-direction");
if (!PostRADirectionAttr.isValid())
return;
StringRef PostRADirectionStr = PostRADirectionAttr.getValueAsString();
if (PostRADirectionStr == "topdown") {
Policy.OnlyTopDown = true;
Policy.OnlyBottomUp = false;
} else if (PostRADirectionStr == "bottomup") {
Policy.OnlyTopDown = false;
Policy.OnlyBottomUp = true;
} else if (PostRADirectionStr == "bidirectional") {
Policy.OnlyTopDown = false;
Policy.OnlyBottomUp = false;
} else {
DiagnosticInfoOptimizationFailure Diag(
F, F.getSubprogram(), "invalid value for postRA direction attribute");
F.getContext().diagnose(Diag);
}
LLVM_DEBUG({
const char *DirStr = "default";
if (Policy.OnlyTopDown && !Policy.OnlyBottomUp)
DirStr = "topdown";
else if (!Policy.OnlyTopDown && Policy.OnlyBottomUp)
DirStr = "bottomup";
else if (!Policy.OnlyTopDown && !Policy.OnlyBottomUp)
DirStr = "bidirectional";
dbgs() << "Post-MI-sched direction (" << F.getName() << "): " << DirStr
<< '\n';
});
}
void GCNSubtarget::mirFileLoaded(MachineFunction &MF) const {
if (isWave32()) {
// Fix implicit $vcc operands after MIParser has verified that they match

View File

@ -1041,6 +1041,9 @@ public:
void overrideSchedPolicy(MachineSchedPolicy &Policy,
const SchedRegion &Region) const override;
void overridePostRASchedPolicy(MachineSchedPolicy &Policy,
const SchedRegion &Region) const override;
void mirFileLoaded(MachineFunction &MF) const override;
unsigned getMaxNumUserSGPRs() const {

View File

@ -0,0 +1,34 @@
; REQUIRES: asserts
; RUN: llc -mtriple=amdgcn-amd-amdhsa -mcpu=gfx1100 -debug-only=gcn-subtarget < %s 2>&1 | FileCheck %s
; RUN: llc -mtriple=amdgcn-amd-amdhsa -mcpu=gfx1100 < %s 2>&1 | FileCheck -check-prefixes=WARNING %s
; CHECK: Post-MI-sched direction (postra-sched-topdown): topdown
define float @postra-sched-topdown(float %input) nounwind #0 {
%x = fadd float %input, 1.000000e+00
ret float %x
}
; CHECK: Post-MI-sched direction (postra-sched-bottomup): bottomup
define float @postra-sched-bottomup(float %input) nounwind #1 {
%x = fsub float %input, 1.000000e+00
ret float %x
}
; CHECK: Post-MI-sched direction (postra-sched-bidirectional): bidirectional
define float @postra-sched-bidirectional(float %input) nounwind #2 {
%x = fadd float %input, 1.000000e+00
ret float %x
}
; CHECK: Post-MI-sched direction (postra-sched-warning): topdown
; WARNING: invalid value for postRA direction attribute
define float @postra-sched-warning(float %input) nounwind #3 {
%x = fsub float %input, 1.000000e+00
ret float %x
}
attributes #0 = {"amdgpu-post-ra-direction"="topdown"}
attributes #1 = {"amdgpu-post-ra-direction"="bottomup"}
attributes #2 = {"amdgpu-post-ra-direction"="bidirectional"}
attributes #3 = {"amdgpu-post-ra-direction"="warning"}