Skip to content

Commit f9b258c

Browse files
authored
[AMDGPU] Support function attribute to override postRA scheduling direction (llvm#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.
1 parent 76ce464 commit f9b258c

File tree

3 files changed

+74
-0
lines changed

3 files changed

+74
-0
lines changed

llvm/lib/Target/AMDGPU/GCNSubtarget.cpp

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,43 @@ void GCNSubtarget::overrideSchedPolicy(MachineSchedPolicy &Policy,
340340
Policy.ShouldTrackLaneMasks = true;
341341
}
342342

343+
void GCNSubtarget::overridePostRASchedPolicy(MachineSchedPolicy &Policy,
344+
const SchedRegion &Region) const {
345+
const Function &F = Region.RegionBegin->getMF()->getFunction();
346+
Attribute PostRADirectionAttr = F.getFnAttribute("amdgpu-post-ra-direction");
347+
if (!PostRADirectionAttr.isValid())
348+
return;
349+
350+
StringRef PostRADirectionStr = PostRADirectionAttr.getValueAsString();
351+
if (PostRADirectionStr == "topdown") {
352+
Policy.OnlyTopDown = true;
353+
Policy.OnlyBottomUp = false;
354+
} else if (PostRADirectionStr == "bottomup") {
355+
Policy.OnlyTopDown = false;
356+
Policy.OnlyBottomUp = true;
357+
} else if (PostRADirectionStr == "bidirectional") {
358+
Policy.OnlyTopDown = false;
359+
Policy.OnlyBottomUp = false;
360+
} else {
361+
DiagnosticInfoOptimizationFailure Diag(
362+
F, F.getSubprogram(), "invalid value for postRA direction attribute");
363+
F.getContext().diagnose(Diag);
364+
}
365+
366+
LLVM_DEBUG({
367+
const char *DirStr = "default";
368+
if (Policy.OnlyTopDown && !Policy.OnlyBottomUp)
369+
DirStr = "topdown";
370+
else if (!Policy.OnlyTopDown && Policy.OnlyBottomUp)
371+
DirStr = "bottomup";
372+
else if (!Policy.OnlyTopDown && !Policy.OnlyBottomUp)
373+
DirStr = "bidirectional";
374+
375+
dbgs() << "Post-MI-sched direction (" << F.getName() << "): " << DirStr
376+
<< '\n';
377+
});
378+
}
379+
343380
void GCNSubtarget::mirFileLoaded(MachineFunction &MF) const {
344381
if (isWave32()) {
345382
// Fix implicit $vcc operands after MIParser has verified that they match

llvm/lib/Target/AMDGPU/GCNSubtarget.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1041,6 +1041,9 @@ class GCNSubtarget final : public AMDGPUGenSubtargetInfo,
10411041
void overrideSchedPolicy(MachineSchedPolicy &Policy,
10421042
const SchedRegion &Region) const override;
10431043

1044+
void overridePostRASchedPolicy(MachineSchedPolicy &Policy,
1045+
const SchedRegion &Region) const override;
1046+
10441047
void mirFileLoaded(MachineFunction &MF) const override;
10451048

10461049
unsigned getMaxNumUserSGPRs() const {
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
; REQUIRES: asserts
2+
3+
; RUN: llc -mtriple=amdgcn-amd-amdhsa -mcpu=gfx1100 -debug-only=gcn-subtarget < %s 2>&1 | FileCheck %s
4+
; RUN: llc -mtriple=amdgcn-amd-amdhsa -mcpu=gfx1100 < %s 2>&1 | FileCheck -check-prefixes=WARNING %s
5+
6+
; CHECK: Post-MI-sched direction (postra-sched-topdown): topdown
7+
define float @postra-sched-topdown(float %input) nounwind #0 {
8+
%x = fadd float %input, 1.000000e+00
9+
ret float %x
10+
}
11+
12+
; CHECK: Post-MI-sched direction (postra-sched-bottomup): bottomup
13+
define float @postra-sched-bottomup(float %input) nounwind #1 {
14+
%x = fsub float %input, 1.000000e+00
15+
ret float %x
16+
}
17+
18+
; CHECK: Post-MI-sched direction (postra-sched-bidirectional): bidirectional
19+
define float @postra-sched-bidirectional(float %input) nounwind #2 {
20+
%x = fadd float %input, 1.000000e+00
21+
ret float %x
22+
}
23+
24+
; CHECK: Post-MI-sched direction (postra-sched-warning): topdown
25+
; WARNING: invalid value for postRA direction attribute
26+
define float @postra-sched-warning(float %input) nounwind #3 {
27+
%x = fsub float %input, 1.000000e+00
28+
ret float %x
29+
}
30+
31+
attributes #0 = {"amdgpu-post-ra-direction"="topdown"}
32+
attributes #1 = {"amdgpu-post-ra-direction"="bottomup"}
33+
attributes #2 = {"amdgpu-post-ra-direction"="bidirectional"}
34+
attributes #3 = {"amdgpu-post-ra-direction"="warning"}

0 commit comments

Comments
 (0)