Skip to content

[AMDGPU][Scheduler] Make finalizeGCNRegion an overridable hook (NFC)#177199

Merged
lucas-rami merged 1 commit intomainfrom
users/lucas-rami/rematerialization-reapply/1
Jan 30, 2026
Merged

[AMDGPU][Scheduler] Make finalizeGCNRegion an overridable hook (NFC)#177199
lucas-rami merged 1 commit intomainfrom
users/lucas-rami/rematerialization-reapply/1

Conversation

@lucas-rami
Copy link
Contributor

@lucas-rami lucas-rami commented Jan 21, 2026

This allows individual stages to make decisions after re-scheduling
individual regions.
@llvmbot
Copy link
Member

llvmbot commented Jan 21, 2026

@llvm/pr-subscribers-backend-amdgpu

Author: Lucas Ramirez (lucas-rami)

Changes

This allows individual stages to make decisions after re-scheduling individual regions.


Full diff: https://github.com/llvm/llvm-project/pull/177199.diff

2 Files Affected:

  • (modified) llvm/lib/Target/AMDGPU/GCNSchedStrategy.cpp (+2-4)
  • (modified) llvm/lib/Target/AMDGPU/GCNSchedStrategy.h (+3-3)
diff --git a/llvm/lib/Target/AMDGPU/GCNSchedStrategy.cpp b/llvm/lib/Target/AMDGPU/GCNSchedStrategy.cpp
index cabf759762a72..876adddcfbbaa 100644
--- a/llvm/lib/Target/AMDGPU/GCNSchedStrategy.cpp
+++ b/llvm/lib/Target/AMDGPU/GCNSchedStrategy.cpp
@@ -145,7 +145,6 @@ void GCNSchedStrategy::initialize(ScheduleDAGMI *DAG) {
   VGPRCriticalLimit -= std::min(VGPRLimitBias + ErrorMargin, VGPRCriticalLimit);
   SGPRExcessLimit -= std::min(SGPRLimitBias + ErrorMargin, SGPRExcessLimit);
   VGPRExcessLimit -= std::min(VGPRLimitBias + ErrorMargin, VGPRExcessLimit);
-
   LLVM_DEBUG(dbgs() << "VGPRCriticalLimit = " << VGPRCriticalLimit
                     << ", VGPRExcessLimit = " << VGPRExcessLimit
                     << ", SGPRCriticalLimit = " << SGPRCriticalLimit
@@ -1163,6 +1162,8 @@ void GCNScheduleDAGMILive::runSchedStages() {
 
       ScheduleDAGMILive::schedule();
       Stage->finalizeGCNRegion();
+      Stage->advanceRegion();
+      exitRegion();
     }
 
     Stage->finalizeGCNSchedStage();
@@ -1473,9 +1474,6 @@ void GCNSchedStage::finalizeGCNRegion() {
   if (DAG.RegionsWithIGLPInstrs[RegionIdx] &&
       StageID != GCNSchedStageID::UnclusteredHighRPReschedule)
     SavedMutations.swap(DAG.Mutations);
-
-  DAG.exitRegion();
-  advanceRegion();
 }
 
 void GCNSchedStage::checkScheduling() {
diff --git a/llvm/lib/Target/AMDGPU/GCNSchedStrategy.h b/llvm/lib/Target/AMDGPU/GCNSchedStrategy.h
index 95a931b9beb2a..6563c8d050ff9 100644
--- a/llvm/lib/Target/AMDGPU/GCNSchedStrategy.h
+++ b/llvm/lib/Target/AMDGPU/GCNSchedStrategy.h
@@ -367,12 +367,12 @@ class GCNSchedStage {
   // be skipped.
   virtual bool initGCNRegion();
 
+  // Finalize state after scheduling a region.
+  virtual void finalizeGCNRegion();
+
   // Track whether a new region is also a new MBB.
   void setupNewBlock();
 
-  // Finalize state after scheudling a region.
-  void finalizeGCNRegion();
-
   // Check result of scheduling.
   void checkScheduling();
 

@arsenm
Copy link
Contributor

arsenm commented Jan 21, 2026

Isn't the point of finalize that it's done? Why would a stage need to do something else after it's done?

@lucas-rami
Copy link
Contributor Author

lucas-rami commented Jan 21, 2026

"Finalize" may not be a super clear name indeed; even in the current implementation this is where re-scheduling is reverted if it turns out to be worse than before (stages can customize what "worse" means with the shouldRevertScheduling hook) so stages already have some power to control what happens after a region is re-scheduled. finalizeGCNSchedStage is another stage hook that is invoked after all regions have been re-scheduled.

Having the ability to do something after each region is re-scheduled will allow a future change to early exit and skip further re-schedulings if it deems them to be useless.

@lucas-rami lucas-rami merged commit 8029699 into main Jan 30, 2026
13 checks passed
@lucas-rami lucas-rami deleted the users/lucas-rami/rematerialization-reapply/1 branch January 30, 2026 16:35
sshrestha-aa pushed a commit to sshrestha-aa/llvm-project that referenced this pull request Feb 4, 2026
llvm#177199)

This allows individual stages to make decisions after re-scheduling
individual regions.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants