[llvm] [AMDGPU] Support function attribute to override postRA scheduling direction (PR #147708)
Harrison Hao via llvm-commits
llvm-commits at lists.llvm.org
Tue Jul 15 05:01:09 PDT 2025
https://github.com/harrisonGPU updated https://github.com/llvm/llvm-project/pull/147708
>From 953ea0ed57689273896025a5813a82744ec8e121 Mon Sep 17 00:00:00 2001
From: Harrison Hao <tsworld1314 at gmail.com>
Date: Wed, 9 Jul 2025 17:46:23 +0800
Subject: [PATCH 1/5] [AMDGPU] Support function attribute to override postRA
scheduling direction
---
llvm/include/llvm/CodeGen/MachineScheduler.h | 1 +
llvm/lib/CodeGen/MachineScheduler.cpp | 2 +-
llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp | 17 +++++++++++++++++
3 files changed, 19 insertions(+), 1 deletion(-)
diff --git a/llvm/include/llvm/CodeGen/MachineScheduler.h b/llvm/include/llvm/CodeGen/MachineScheduler.h
index e7a7091acee64..1635eae758590 100644
--- a/llvm/include/llvm/CodeGen/MachineScheduler.h
+++ b/llvm/include/llvm/CodeGen/MachineScheduler.h
@@ -116,6 +116,7 @@ enum Direction {
} // namespace MISched
LLVM_ABI extern cl::opt<MISched::Direction> PreRADirection;
+LLVM_ABI extern cl::opt<MISched::Direction> PostRADirection;
LLVM_ABI extern cl::opt<bool> VerifyScheduling;
#ifndef NDEBUG
extern cl::opt<bool> ViewMISchedDAGs;
diff --git a/llvm/lib/CodeGen/MachineScheduler.cpp b/llvm/lib/CodeGen/MachineScheduler.cpp
index 76cba2949af60..72e1fce07f33e 100644
--- a/llvm/lib/CodeGen/MachineScheduler.cpp
+++ b/llvm/lib/CodeGen/MachineScheduler.cpp
@@ -190,7 +190,7 @@ cl::opt<MISched::Direction> PreRADirection(
clEnumValN(MISched::Bidirectional, "bidirectional",
"Force bidirectional pre reg-alloc list scheduling")));
-static cl::opt<MISched::Direction> PostRADirection(
+cl::opt<MISched::Direction> PostRADirection(
"misched-postra-direction", cl::Hidden,
cl::desc("Post reg-alloc list scheduling direction"),
cl::init(MISched::Unspecified),
diff --git a/llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp b/llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp
index f4dc4a483181c..33c70c87ab415 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp
+++ b/llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp
@@ -1145,6 +1145,23 @@ GCNTargetMachine::createMachineScheduler(MachineSchedContext *C) const {
ScheduleDAGInstrs *
GCNTargetMachine::createPostMachineScheduler(MachineSchedContext *C) const {
+ Attribute PostRADirectionAttr =
+ C->MF->getFunction().getFnAttribute("misched-postra-direction");
+
+ if (PostRADirectionAttr.isValid()) {
+ StringRef PostRADirectionStr = PostRADirectionAttr.getValueAsString();
+ if (PostRADirectionStr == "topdown")
+ PostRADirection = MISched::TopDown;
+ else if (PostRADirectionStr == "bottomup")
+ PostRADirection = MISched::BottomUp;
+ else if (PostRADirectionStr == "bidirectional")
+ PostRADirection = MISched::Bidirectional;
+ else
+ report_fatal_error(
+ Twine("invalid value for 'misched-postra-direction' attribute: ") +
+ PostRADirectionStr);
+ }
+
ScheduleDAGMI *DAG =
new GCNPostScheduleDAGMILive(C, std::make_unique<PostGenericScheduler>(C),
/*RemoveKillFlags=*/true);
>From 7b38963f1a5c44e638d6796c36197c579512ee87 Mon Sep 17 00:00:00 2001
From: Harrison Hao <tsworld1314 at gmail.com>
Date: Sun, 13 Jul 2025 20:54:37 +0800
Subject: [PATCH 2/5] [AMDGPU] Add a new attr and lit test.
---
llvm/lib/CodeGen/MachineScheduler.cpp | 19 ++++++++++
.../lib/Target/AMDGPU/AMDGPUTargetMachine.cpp | 19 +++++++---
.../CodeGen/AMDGPU/postra-sched-attribute.ll | 38 +++++++++++++++++++
3 files changed, 71 insertions(+), 5 deletions(-)
create mode 100644 llvm/test/CodeGen/AMDGPU/postra-sched-attribute.ll
diff --git a/llvm/lib/CodeGen/MachineScheduler.cpp b/llvm/lib/CodeGen/MachineScheduler.cpp
index 72e1fce07f33e..f1d5b90ed0fb2 100644
--- a/llvm/lib/CodeGen/MachineScheduler.cpp
+++ b/llvm/lib/CodeGen/MachineScheduler.cpp
@@ -4352,6 +4352,25 @@ void PostGenericScheduler::initPolicy(MachineBasicBlock::iterator Begin,
RegionPolicy.OnlyTopDown = false;
}
+ LLVM_DEBUG({
+ const char *DirStr = "default";
+ switch (PostRADirection) {
+ case MISched::TopDown:
+ DirStr = "topdown";
+ break;
+ case MISched::BottomUp:
+ DirStr = "bottomup";
+ break;
+ case MISched::Bidirectional:
+ DirStr = "bidirectional";
+ break;
+ default:;
+ }
+
+ dbgs() << "Post-MI-sched direction (" << MF.getName() << "): " << DirStr
+ << '\n';
+ });
+
BotIdx = NumRegionInstrs - 1;
this->NumRegionInstrs = NumRegionInstrs;
}
diff --git a/llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp b/llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp
index 33c70c87ab415..893a5558731e1 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp
+++ b/llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp
@@ -457,6 +457,11 @@ static cl::opt<std::string>
cl::desc("Select custom AMDGPU scheduling strategy."),
cl::Hidden, cl::init(""));
+static cl::opt<std::string>
+ AMDGPUPostRADirection("amdgpu-post-ra-direction",
+ cl::desc("Select custom AMDGPU postRA direction."),
+ cl::Hidden, cl::init(""));
+
static cl::opt<bool> EnableRewritePartialRegUses(
"amdgpu-enable-rewrite-partial-reg-uses",
cl::desc("Enable rewrite partial reg uses pass"), cl::init(true),
@@ -1146,7 +1151,7 @@ GCNTargetMachine::createMachineScheduler(MachineSchedContext *C) const {
ScheduleDAGInstrs *
GCNTargetMachine::createPostMachineScheduler(MachineSchedContext *C) const {
Attribute PostRADirectionAttr =
- C->MF->getFunction().getFnAttribute("misched-postra-direction");
+ C->MF->getFunction().getFnAttribute("amdgpu-post-ra-direction");
if (PostRADirectionAttr.isValid()) {
StringRef PostRADirectionStr = PostRADirectionAttr.getValueAsString();
@@ -1156,10 +1161,14 @@ GCNTargetMachine::createPostMachineScheduler(MachineSchedContext *C) const {
PostRADirection = MISched::BottomUp;
else if (PostRADirectionStr == "bidirectional")
PostRADirection = MISched::Bidirectional;
- else
- report_fatal_error(
- Twine("invalid value for 'misched-postra-direction' attribute: ") +
- PostRADirectionStr);
+ else {
+ PostRADirection = MISched::Unspecified;
+ DiagnosticInfoOptimizationFailure Diag(
+ C->MF->getFunction(), C->MF->getFunction().getSubprogram(),
+ Twine("invalid value for postRa direction attribute: '") +
+ PostRADirectionStr);
+ C->MF->getFunction().getContext().diagnose(Diag);
+ }
}
ScheduleDAGMI *DAG =
diff --git a/llvm/test/CodeGen/AMDGPU/postra-sched-attribute.ll b/llvm/test/CodeGen/AMDGPU/postra-sched-attribute.ll
new file mode 100644
index 0000000000000..7d9422d81c129
--- /dev/null
+++ b/llvm/test/CodeGen/AMDGPU/postra-sched-attribute.ll
@@ -0,0 +1,38 @@
+; REQUIRES: asserts
+
+; RUN: llc -mtriple=amdgcn-amd-amdhsa -mcpu=gfx1100 -debug-only=machine-scheduler < %s 2>&1 | FileCheck %s
+; RUN: llc -mtriple=amdgcn-amd-amdhsa -mcpu=gfx1100 < %s 2>&1 | FileCheck -check-prefixes=WARNING %s
+
+; CHECK-LABEL: {{^}}postra-sched-topdown:
+; 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-LABEL: {{^}}postra-sched-bottomup:
+; 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-LABEL: {{^}}postra-sched-bidirectional:
+; 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-LABEL: {{^}}postra-sched-warning:
+; CHECK: Post-MI-sched direction (postra-sched-warning): default
+; 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 = { alwaysinline nounwind memory(readwrite) "amdgpu-post-ra-direction"="topdown"}
+attributes #1 = { alwaysinline nounwind memory(readwrite) "amdgpu-post-ra-direction"="bottomup"}
+attributes #2 = { alwaysinline nounwind memory(readwrite) "amdgpu-post-ra-direction"="bidirectional"}
+attributes #3 = { alwaysinline nounwind memory(readwrite) "amdgpu-post-ra-direction"="warning"}
>From 35fe8fd3c3de2e5dec10f00f7d98f25748e49318 Mon Sep 17 00:00:00 2001
From: Harrison Hao <tsworld1314 at gmail.com>
Date: Mon, 14 Jul 2025 09:51:36 +0800
Subject: [PATCH 3/5] [AMDGPU] Remove other att.
---
llvm/test/CodeGen/AMDGPU/postra-sched-attribute.ll | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/llvm/test/CodeGen/AMDGPU/postra-sched-attribute.ll b/llvm/test/CodeGen/AMDGPU/postra-sched-attribute.ll
index 7d9422d81c129..c6f63f3b4a1b3 100644
--- a/llvm/test/CodeGen/AMDGPU/postra-sched-attribute.ll
+++ b/llvm/test/CodeGen/AMDGPU/postra-sched-attribute.ll
@@ -32,7 +32,7 @@ define float @postra-sched-warning(float %input) nounwind #3 {
ret float %x
}
-attributes #0 = { alwaysinline nounwind memory(readwrite) "amdgpu-post-ra-direction"="topdown"}
-attributes #1 = { alwaysinline nounwind memory(readwrite) "amdgpu-post-ra-direction"="bottomup"}
-attributes #2 = { alwaysinline nounwind memory(readwrite) "amdgpu-post-ra-direction"="bidirectional"}
-attributes #3 = { alwaysinline nounwind memory(readwrite) "amdgpu-post-ra-direction"="warning"}
+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"}
>From 566c678eca8f735e143551fe94d7bd8336342875 Mon Sep 17 00:00:00 2001
From: Harrison Hao <tsworld1314 at gmail.com>
Date: Tue, 15 Jul 2025 13:48:18 +0800
Subject: [PATCH 4/5] [AMDGPU]
---
.../lib/Target/AMDGPU/AMDGPUTargetMachine.cpp | 38 ++++++++++---------
1 file changed, 20 insertions(+), 18 deletions(-)
diff --git a/llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp b/llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp
index 893a5558731e1..2b0c668d0c732 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp
+++ b/llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp
@@ -1150,24 +1150,26 @@ GCNTargetMachine::createMachineScheduler(MachineSchedContext *C) const {
ScheduleDAGInstrs *
GCNTargetMachine::createPostMachineScheduler(MachineSchedContext *C) const {
- Attribute PostRADirectionAttr =
- C->MF->getFunction().getFnAttribute("amdgpu-post-ra-direction");
-
- if (PostRADirectionAttr.isValid()) {
- StringRef PostRADirectionStr = PostRADirectionAttr.getValueAsString();
- if (PostRADirectionStr == "topdown")
- PostRADirection = MISched::TopDown;
- else if (PostRADirectionStr == "bottomup")
- PostRADirection = MISched::BottomUp;
- else if (PostRADirectionStr == "bidirectional")
- PostRADirection = MISched::Bidirectional;
- else {
- PostRADirection = MISched::Unspecified;
- DiagnosticInfoOptimizationFailure Diag(
- C->MF->getFunction(), C->MF->getFunction().getSubprogram(),
- Twine("invalid value for postRa direction attribute: '") +
- PostRADirectionStr);
- C->MF->getFunction().getContext().diagnose(Diag);
+ if (PostRADirection.getNumOccurrences() == 0) {
+ Attribute PostRADirectionAttr =
+ C->MF->getFunction().getFnAttribute("amdgpu-post-ra-direction");
+
+ if (PostRADirectionAttr.isValid()) {
+ StringRef PostRADirectionStr = PostRADirectionAttr.getValueAsString();
+ if (PostRADirectionStr == "topdown")
+ PostRADirection = MISched::TopDown;
+ else if (PostRADirectionStr == "bottomup")
+ PostRADirection = MISched::BottomUp;
+ else if (PostRADirectionStr == "bidirectional")
+ PostRADirection = MISched::Bidirectional;
+ else {
+ PostRADirection = MISched::Unspecified;
+ DiagnosticInfoOptimizationFailure Diag(
+ C->MF->getFunction(), C->MF->getFunction().getSubprogram(),
+ Twine("invalid value for postRa direction attribute: '") +
+ PostRADirectionStr);
+ C->MF->getFunction().getContext().diagnose(Diag);
+ }
}
}
>From db514b44710ef78b390b6c51c755f234d3cf66ae Mon Sep 17 00:00:00 2001
From: Harrison Hao <tsworld1314 at gmail.com>
Date: Tue, 15 Jul 2025 20:00:37 +0800
Subject: [PATCH 5/5] [AMDGPU] Add post-RA scheduling direction control via
target features
---
llvm/include/llvm/CodeGen/MachineScheduler.h | 1 -
llvm/lib/CodeGen/MachineScheduler.cpp | 21 +---------
llvm/lib/Target/AMDGPU/AMDGPUFeatures.td | 21 ++++++++++
llvm/lib/Target/AMDGPU/AMDGPUSubtarget.h | 6 +++
.../lib/Target/AMDGPU/AMDGPUTargetMachine.cpp | 28 --------------
llvm/lib/Target/AMDGPU/GCNSubtarget.cpp | 34 +++++++++++++++++
llvm/lib/Target/AMDGPU/GCNSubtarget.h | 3 ++
.../CodeGen/AMDGPU/postra-sched-attribute.ll | 38 -------------------
.../AMDGPU/postra-sched-target-features.ll | 25 ++++++++++++
9 files changed, 90 insertions(+), 87 deletions(-)
delete mode 100644 llvm/test/CodeGen/AMDGPU/postra-sched-attribute.ll
create mode 100644 llvm/test/CodeGen/AMDGPU/postra-sched-target-features.ll
diff --git a/llvm/include/llvm/CodeGen/MachineScheduler.h b/llvm/include/llvm/CodeGen/MachineScheduler.h
index 1635eae758590..e7a7091acee64 100644
--- a/llvm/include/llvm/CodeGen/MachineScheduler.h
+++ b/llvm/include/llvm/CodeGen/MachineScheduler.h
@@ -116,7 +116,6 @@ enum Direction {
} // namespace MISched
LLVM_ABI extern cl::opt<MISched::Direction> PreRADirection;
-LLVM_ABI extern cl::opt<MISched::Direction> PostRADirection;
LLVM_ABI extern cl::opt<bool> VerifyScheduling;
#ifndef NDEBUG
extern cl::opt<bool> ViewMISchedDAGs;
diff --git a/llvm/lib/CodeGen/MachineScheduler.cpp b/llvm/lib/CodeGen/MachineScheduler.cpp
index f1d5b90ed0fb2..76cba2949af60 100644
--- a/llvm/lib/CodeGen/MachineScheduler.cpp
+++ b/llvm/lib/CodeGen/MachineScheduler.cpp
@@ -190,7 +190,7 @@ cl::opt<MISched::Direction> PreRADirection(
clEnumValN(MISched::Bidirectional, "bidirectional",
"Force bidirectional pre reg-alloc list scheduling")));
-cl::opt<MISched::Direction> PostRADirection(
+static cl::opt<MISched::Direction> PostRADirection(
"misched-postra-direction", cl::Hidden,
cl::desc("Post reg-alloc list scheduling direction"),
cl::init(MISched::Unspecified),
@@ -4352,25 +4352,6 @@ void PostGenericScheduler::initPolicy(MachineBasicBlock::iterator Begin,
RegionPolicy.OnlyTopDown = false;
}
- LLVM_DEBUG({
- const char *DirStr = "default";
- switch (PostRADirection) {
- case MISched::TopDown:
- DirStr = "topdown";
- break;
- case MISched::BottomUp:
- DirStr = "bottomup";
- break;
- case MISched::Bidirectional:
- DirStr = "bidirectional";
- break;
- default:;
- }
-
- dbgs() << "Post-MI-sched direction (" << MF.getName() << "): " << DirStr
- << '\n';
- });
-
BotIdx = NumRegionInstrs - 1;
this->NumRegionInstrs = NumRegionInstrs;
}
diff --git a/llvm/lib/Target/AMDGPU/AMDGPUFeatures.td b/llvm/lib/Target/AMDGPU/AMDGPUFeatures.td
index 74d1faeb6f545..870144f43b993 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPUFeatures.td
+++ b/llvm/lib/Target/AMDGPU/AMDGPUFeatures.td
@@ -6,6 +6,10 @@
//
//===----------------------------------------------------------------------===//
+defvar TopDown = [{ MISched::TopDown }];
+defvar BottomUp = [{ MISched::BottomUp }];
+defvar Bidirectional = [{ MISched::Bidirectional }];
+
def FeatureFP64 : SubtargetFeature<"fp64",
"FP64",
"true",
@@ -54,3 +58,20 @@ def FeaturePromoteAlloca : SubtargetFeature <"promote-alloca",
"Enable promote alloca pass"
>;
+def FeaturePostRATopDown : SubtargetFeature <"postra-top-down",
+ "PostRASchedDirection",
+ TopDown,
+ "Force Post-RA scheduler to run top-down"
+>;
+
+def FeaturePostRABottomUp : SubtargetFeature <"postra-bottom-up",
+ "PostRASchedDirection",
+ BottomUp,
+ "Force Post-RA scheduler to run bottom-up"
+>;
+
+def FeaturePostRABidirectional : SubtargetFeature <"postra-bidirectional",
+ "PostRASchedDirection",
+ Bidirectional,
+ "Force Post-RA scheduler to run bidirectionally"
+>;
diff --git a/llvm/lib/Target/AMDGPU/AMDGPUSubtarget.h b/llvm/lib/Target/AMDGPU/AMDGPUSubtarget.h
index 1e44be8e47201..3b1b154abdeb9 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPUSubtarget.h
+++ b/llvm/lib/Target/AMDGPU/AMDGPUSubtarget.h
@@ -15,6 +15,7 @@
#define LLVM_LIB_TARGET_AMDGPU_AMDGPUSUBTARGET_H
#include "llvm/ADT/SmallVector.h"
+#include "llvm/CodeGen/MachineScheduler.h"
#include "llvm/IR/CallingConv.h"
#include "llvm/Support/Alignment.h"
#include "llvm/TargetParser/Triple.h"
@@ -79,6 +80,7 @@ class AMDGPUSubtarget {
unsigned LocalMemorySize = 0;
unsigned AddressableLocalMemorySize = 0;
char WavefrontSizeLog2 = 0;
+ MISched::Direction PostRASchedDirection = MISched::TopDown;
public:
AMDGPUSubtarget(Triple TT);
@@ -379,6 +381,10 @@ class AMDGPUSubtarget {
AMDGPUDwarfFlavour getAMDGPUDwarfFlavour() const;
virtual ~AMDGPUSubtarget() = default;
+
+ MISched::Direction getPostRASchedDirection() const {
+ return PostRASchedDirection;
+ }
};
} // end namespace llvm
diff --git a/llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp b/llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp
index 2b0c668d0c732..f4dc4a483181c 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp
+++ b/llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp
@@ -457,11 +457,6 @@ static cl::opt<std::string>
cl::desc("Select custom AMDGPU scheduling strategy."),
cl::Hidden, cl::init(""));
-static cl::opt<std::string>
- AMDGPUPostRADirection("amdgpu-post-ra-direction",
- cl::desc("Select custom AMDGPU postRA direction."),
- cl::Hidden, cl::init(""));
-
static cl::opt<bool> EnableRewritePartialRegUses(
"amdgpu-enable-rewrite-partial-reg-uses",
cl::desc("Enable rewrite partial reg uses pass"), cl::init(true),
@@ -1150,29 +1145,6 @@ GCNTargetMachine::createMachineScheduler(MachineSchedContext *C) const {
ScheduleDAGInstrs *
GCNTargetMachine::createPostMachineScheduler(MachineSchedContext *C) const {
- if (PostRADirection.getNumOccurrences() == 0) {
- Attribute PostRADirectionAttr =
- C->MF->getFunction().getFnAttribute("amdgpu-post-ra-direction");
-
- if (PostRADirectionAttr.isValid()) {
- StringRef PostRADirectionStr = PostRADirectionAttr.getValueAsString();
- if (PostRADirectionStr == "topdown")
- PostRADirection = MISched::TopDown;
- else if (PostRADirectionStr == "bottomup")
- PostRADirection = MISched::BottomUp;
- else if (PostRADirectionStr == "bidirectional")
- PostRADirection = MISched::Bidirectional;
- else {
- PostRADirection = MISched::Unspecified;
- DiagnosticInfoOptimizationFailure Diag(
- C->MF->getFunction(), C->MF->getFunction().getSubprogram(),
- Twine("invalid value for postRa direction attribute: '") +
- PostRADirectionStr);
- C->MF->getFunction().getContext().diagnose(Diag);
- }
- }
- }
-
ScheduleDAGMI *DAG =
new GCNPostScheduleDAGMILive(C, std::make_unique<PostGenericScheduler>(C),
/*RemoveKillFlags=*/true);
diff --git a/llvm/lib/Target/AMDGPU/GCNSubtarget.cpp b/llvm/lib/Target/AMDGPU/GCNSubtarget.cpp
index 7b8f0f44cbe2c..73abf2fe68cdd 100644
--- a/llvm/lib/Target/AMDGPU/GCNSubtarget.cpp
+++ b/llvm/lib/Target/AMDGPU/GCNSubtarget.cpp
@@ -340,6 +340,40 @@ void GCNSubtarget::overrideSchedPolicy(MachineSchedPolicy &Policy,
Policy.ShouldTrackLaneMasks = true;
}
+void GCNSubtarget::overridePostRASchedPolicy(MachineSchedPolicy &Policy,
+ unsigned NumRegionInstrs) const {
+ switch (getPostRASchedDirection()) {
+ case MISched::TopDown:
+ Policy.OnlyTopDown = true;
+ Policy.OnlyBottomUp = false;
+ break;
+ case MISched::BottomUp:
+ Policy.OnlyTopDown = false;
+ Policy.OnlyBottomUp = true;
+ break;
+ case MISched::Bidirectional:
+ default:
+ Policy.OnlyTopDown = false;
+ Policy.OnlyBottomUp = false;
+ break;
+ }
+
+ LLVM_DEBUG({
+ const char *DirStr = "topdown";
+ switch (getPostRASchedDirection()) {
+ case MISched::BottomUp:
+ DirStr = "bottomup";
+ break;
+ case MISched::Bidirectional:
+ DirStr = "bidirectional";
+ break;
+ default:
+ break;
+ }
+ dbgs() << "Post-MI-sched direction: " << DirStr << '\n';
+ });
+}
+
void GCNSubtarget::mirFileLoaded(MachineFunction &MF) const {
if (isWave32()) {
// Fix implicit $vcc operands after MIParser has verified that they match
diff --git a/llvm/lib/Target/AMDGPU/GCNSubtarget.h b/llvm/lib/Target/AMDGPU/GCNSubtarget.h
index 0ad4778875cd3..a5fedfc8cb20c 100644
--- a/llvm/lib/Target/AMDGPU/GCNSubtarget.h
+++ b/llvm/lib/Target/AMDGPU/GCNSubtarget.h
@@ -1022,6 +1022,9 @@ class GCNSubtarget final : public AMDGPUGenSubtargetInfo,
void overrideSchedPolicy(MachineSchedPolicy &Policy,
unsigned NumRegionInstrs) const override;
+ void overridePostRASchedPolicy(MachineSchedPolicy &Policy,
+ unsigned NumRegionInstrs) const override;
+
void mirFileLoaded(MachineFunction &MF) const override;
unsigned getMaxNumUserSGPRs() const {
diff --git a/llvm/test/CodeGen/AMDGPU/postra-sched-attribute.ll b/llvm/test/CodeGen/AMDGPU/postra-sched-attribute.ll
deleted file mode 100644
index c6f63f3b4a1b3..0000000000000
--- a/llvm/test/CodeGen/AMDGPU/postra-sched-attribute.ll
+++ /dev/null
@@ -1,38 +0,0 @@
-; REQUIRES: asserts
-
-; RUN: llc -mtriple=amdgcn-amd-amdhsa -mcpu=gfx1100 -debug-only=machine-scheduler < %s 2>&1 | FileCheck %s
-; RUN: llc -mtriple=amdgcn-amd-amdhsa -mcpu=gfx1100 < %s 2>&1 | FileCheck -check-prefixes=WARNING %s
-
-; CHECK-LABEL: {{^}}postra-sched-topdown:
-; 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-LABEL: {{^}}postra-sched-bottomup:
-; 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-LABEL: {{^}}postra-sched-bidirectional:
-; 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-LABEL: {{^}}postra-sched-warning:
-; CHECK: Post-MI-sched direction (postra-sched-warning): default
-; 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"}
diff --git a/llvm/test/CodeGen/AMDGPU/postra-sched-target-features.ll b/llvm/test/CodeGen/AMDGPU/postra-sched-target-features.ll
new file mode 100644
index 0000000000000..339fbe4159db4
--- /dev/null
+++ b/llvm/test/CodeGen/AMDGPU/postra-sched-target-features.ll
@@ -0,0 +1,25 @@
+; REQUIRES: asserts
+
+; RUN: llc -mtriple=amdgcn-amd-amdhsa -mcpu=gfx1100 -debug-only=gcn-subtarget < %s 2>&1 | FileCheck %s
+
+; CHECK: Post-MI-sched direction: 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: 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: bidirectional
+define float @postra-sched-bidirectional(float %input) nounwind #2 {
+ %x = fadd float %input, 1.000000e+00
+ ret float %x
+}
+
+attributes #0 = { "target-features"="+postra-top-down" }
+attributes #1 = { "target-features"="+postra-bottom-up" }
+attributes #2 = { "target-features"="+postra-bidirectional" }
More information about the llvm-commits
mailing list