-
Notifications
You must be signed in to change notification settings - Fork 14.4k
[AMDGPU] Support function attribute to override postRA scheduling direction #147708
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
@llvm/pr-subscribers-backend-amdgpu Author: Harrison Hao (harrisonGPU) ChangesFull diff: https://github.com/llvm/llvm-project/pull/147708.diff 3 Files Affected:
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 c3536113e9bef..4c46e703b4604 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp
+++ b/llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp
@@ -1144,6 +1144,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);
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing tests and I thought there already was an attribute for this
I wonder what the reason of having a function attribute for this |
We use function attributes here because in graphics shader compiler, performance tuning often needs to be done per shader stage—not across the whole pipeline. |
No, we don’t have this attribute. I’ve run into this issue, the existing option is a static one, so it applies to the entire pipeline, not to individual shader stages. Also, I’m not sure how to write a proper lit test for this , what exactly should the test check? |
Allow postRA scheduling direction to be set via
misched-postra-direction
function attribute, supporting
topdown
,bottomup
, andbidirectional
.