Skip to content
Merged
37 changes: 37 additions & 0 deletions llvm/lib/Target/AMDGPU/GCNSubtarget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions llvm/lib/Target/AMDGPU/GCNSubtarget.h
Original file line number Diff line number Diff line change
Expand Up @@ -1041,6 +1041,9 @@ class GCNSubtarget final : public AMDGPUGenSubtargetInfo,
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 {
Expand Down
34 changes: 34 additions & 0 deletions llvm/test/CodeGen/AMDGPU/postra-sched-attribute.ll
Original file line number Diff line number Diff line change
@@ -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"}