[llvm] [AMDGPU] Add function attribute amdgpu-use-amdgpu-trackers (PR #223071)

Dhruva Chakrabarti via llvm-commits llvm-commits at lists.llvm.org
Fri Sep 11 21:23:47 PDT 2026


https://github.com/dhruvachak updated https://github.com/llvm/llvm-project/pull/223071

>From d905d399385c80aba20e5ee7fb90bccbff946ad2 Mon Sep 17 00:00:00 2001
From: Dhruva Chakrabarti <Dhruva.Chakrabarti at amd.com>
Date: Fri, 11 Sep 2026 16:19:04 -0500
Subject: [PATCH 1/2] [AMDGPU] Add function attribute
 amdgpu-use-amdgpu-trackers

---
 llvm/lib/Target/AMDGPU/GCNSchedStrategy.cpp   | 17 ++++++-
 .../schedule-amdgpu-trackers-attribute.ll     | 45 +++++++++++++++++++
 2 files changed, 60 insertions(+), 2 deletions(-)
 create mode 100644 llvm/test/CodeGen/AMDGPU/schedule-amdgpu-trackers-attribute.ll

diff --git a/llvm/lib/Target/AMDGPU/GCNSchedStrategy.cpp b/llvm/lib/Target/AMDGPU/GCNSchedStrategy.cpp
index aa85be758559a..fb28a6ece89ed 100644
--- a/llvm/lib/Target/AMDGPU/GCNSchedStrategy.cpp
+++ b/llvm/lib/Target/AMDGPU/GCNSchedStrategy.cpp
@@ -75,7 +75,10 @@ static cl::opt<bool>
 
 static cl::opt<bool> GCNTrackers(
     "amdgpu-use-amdgpu-trackers", cl::Hidden,
-    cl::desc("Use the AMDGPU specific RPTrackers during scheduling"),
+    cl::desc("Use the AMDGPU specific RPTrackers during scheduling. Can be "
+             "set per-function by the \"amdgpu-use-amdgpu-trackers\" "
+             "function attribute, unless this flag is explicitly passed on "
+             "the command line, in which case this flag takes precedence."),
     cl::init(false));
 
 static cl::opt<unsigned> PendingQueueLimit(
@@ -135,8 +138,18 @@ const unsigned ScheduleMetrics::ScaleFactor = 100;
 GCNSchedStrategy::GCNSchedStrategy(const MachineSchedContext *C)
     : GenericScheduler(C), TargetOccupancy(0), MF(nullptr),
       DownwardTracker(*C->LIS), UpwardTracker(*C->LIS), HasHighPressure(false) {
-  if (GCNTrackers.getNumOccurrences() > 0)
+  if (GCNTrackers.getNumOccurrences() > 0) {
+    // An explicit command-line flag always wins, regardless of any
+    // per-function attribute (see the "amdgpu-use-amdgpu-trackers"
+    // function attribute below).
     GCNTrackersOverride = GCNTrackers;
+  } else if (C->MF->getFunction()
+                 .getFnAttribute("amdgpu-use-amdgpu-trackers")
+                 .getValueAsBool()) {
+    // Let individual functions opt in to the AMDGPU RP trackers without
+    // having to flip the flag for the whole module.
+    GCNTrackersOverride = true;
+  }
 }
 
 void GCNSchedStrategy::initialize(ScheduleDAGMI *DAG) {
diff --git a/llvm/test/CodeGen/AMDGPU/schedule-amdgpu-trackers-attribute.ll b/llvm/test/CodeGen/AMDGPU/schedule-amdgpu-trackers-attribute.ll
new file mode 100644
index 0000000000000..38d1f0a9d10f1
--- /dev/null
+++ b/llvm/test/CodeGen/AMDGPU/schedule-amdgpu-trackers-attribute.ll
@@ -0,0 +1,45 @@
+; RUN: llc -mtriple=amdgpu6.00 -verify-misched < %s | FileCheck --check-prefixes=NOFLAG %s
+; RUN: llc -mtriple=amdgpu6.00 -amdgpu-use-amdgpu-trackers=1 -verify-misched < %s | FileCheck --check-prefixes=TRACKERSON %s
+; RUN: llc -mtriple=amdgpu6.00 -amdgpu-use-amdgpu-trackers=0 -verify-misched < %s | FileCheck --check-prefixes=TRACKERSOFF %s
+
+; The "amdgpu-use-amdgpu-trackers" function attribute lets a single kernel opt
+; in to the AMDGPU specific RP trackers without flipping the
+; -amdgpu-use-amdgpu-trackers flag (and therefore the scheduling behavior of
+; every other function) for the whole module. An explicit
+; -amdgpu-use-amdgpu-trackers=0/1 on the command line still takes precedence
+; over the attribute, for every function in the module.
+
+; This kernel does not have the attribute, so it only gets the AMDGPU RP
+; tracker behavior when the flag is explicitly passed on the command line.
+; CHECK-LABEL: {{^}}no_attribute:
+; NOFLAG:      NumVgprs: 20
+; NOFLAG:      Occupancy: 7
+; TRACKERSON:  NumVgprs: 20
+; TRACKERSON:  Occupancy: 10
+; TRACKERSOFF: NumVgprs: 20
+; TRACKERSOFF: Occupancy: 7
+define amdgpu_kernel void @no_attribute(ptr addrspace(1) %out, ptr addrspace(4) %in) {
+  %load = load <64 x i16>, ptr addrspace(4) %in
+  %ext = zext <64 x i16> %load to <64 x i32>
+  store <64 x i32> %ext, ptr addrspace(1) %out
+  ret void
+}
+
+; This kernel has the attribute set to true, so it behaves as though
+; -amdgpu-use-amdgpu-trackers=1 were passed even when no flag is given, but an
+; explicit command-line flag (in either direction) still wins.
+; CHECK-LABEL: {{^}}attribute_enables_trackers:
+; NOFLAG:      NumVgprs: 20
+; NOFLAG:      Occupancy: 10
+; TRACKERSON:  NumVgprs: 20
+; TRACKERSON:  Occupancy: 10
+; TRACKERSOFF: NumVgprs: 20
+; TRACKERSOFF: Occupancy: 7
+define amdgpu_kernel void @attribute_enables_trackers(ptr addrspace(1) %out, ptr addrspace(4) %in) #0 {
+  %load = load <64 x i16>, ptr addrspace(4) %in
+  %ext = zext <64 x i16> %load to <64 x i32>
+  store <64 x i32> %ext, ptr addrspace(1) %out
+  ret void
+}
+
+attributes #0 = { "amdgpu-use-amdgpu-trackers"="true" }

>From e8dcd1866669395a7831fdcc82b8bb33e7940a1e Mon Sep 17 00:00:00 2001
From: Dhruva Chakrabarti <Dhruva.Chakrabarti at amd.com>
Date: Fri, 11 Sep 2026 23:21:31 -0500
Subject: [PATCH 2/2] Added clarifying comment.

---
 llvm/lib/Target/AMDGPU/GCNSchedStrategy.cpp | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/llvm/lib/Target/AMDGPU/GCNSchedStrategy.cpp b/llvm/lib/Target/AMDGPU/GCNSchedStrategy.cpp
index fb28a6ece89ed..fdd752559cdb0 100644
--- a/llvm/lib/Target/AMDGPU/GCNSchedStrategy.cpp
+++ b/llvm/lib/Target/AMDGPU/GCNSchedStrategy.cpp
@@ -147,7 +147,10 @@ GCNSchedStrategy::GCNSchedStrategy(const MachineSchedContext *C)
                  .getFnAttribute("amdgpu-use-amdgpu-trackers")
                  .getValueAsBool()) {
     // Let individual functions opt in to the AMDGPU RP trackers without
-    // having to flip the flag for the whole module.
+    // having to flip the flag for the whole module. This attribute is set
+    // per-function and is not propagated across calls. If a function calls
+    // another function that was not inlined into it, the callee will only use
+    // the AMDGPU trackers if the attribute is also set on the callee itself.
     GCNTrackersOverride = true;
   }
 }



More information about the llvm-commits mailing list