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

Harrison Hao via llvm-commits llvm-commits at lists.llvm.org
Sun Jul 13 06:59:10 PDT 2025


================
@@ -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
+      reportFatalUsageError(
+          Twine("invalid value for 'misched-postra-direction' attribute: ") +
+          PostRADirectionStr);
----------------
harrisonGPU wrote:

Thanks Matt. I've already added a `DiagnosticInfoOptimizationFailure` to emit a warning. I also thought about how to add a lit test for this patch, so I added a dbgs() print for the PostRA direction and checked it using FileCheck. What do you think?

https://github.com/llvm/llvm-project/pull/147708


More information about the llvm-commits mailing list