[llvm] [AMDGPU] Add scheduling stage to rewrite MFMA from VGPR to AGPR (PR #170335)
Matt Arsenault via llvm-commits
llvm-commits at lists.llvm.org
Sun Dec 7 13:33:46 PST 2025
================
@@ -1216,6 +1223,107 @@ bool GCNSchedStage::initGCNSchedStage() {
return true;
}
+void RewriteScheduleStage::findReachingDefs(
+ MachineOperand &UseMO, LiveIntervals *LIS,
+ SmallVectorImpl<SlotIndex> &DefIdxs) {
+ assert(UseMO.isReg());
+ MachineInstr *UseMI = UseMO.getParent();
+ LiveInterval &UseLI = LIS->getInterval(UseMO.getReg());
+ VNInfo *VNI = UseLI.getVNInfoAt(LIS->getInstructionIndex(*UseMI));
+
+ // If the def is not a PHI, then it must be the only reaching def.
+ if (!VNI->isPHIDef()) {
+ DefIdxs.push_back(VNI->def);
+ return;
+ }
+
+ SmallPtrSet<MachineBasicBlock *, 8> Visited;
+ SmallVector<MachineBasicBlock *, 8> Worklist;
+
+ Visited.insert(UseMI->getParent());
+
+ // Mark the predecessor blocks for traversal
+ for (auto *PredMBB : UseMI->getParent()->predecessors()) {
+ Worklist.push_back(PredMBB);
+ Visited.insert(PredMBB);
+ }
+
+ while (!Worklist.empty()) {
+ MachineBasicBlock *CurrMBB = Worklist.pop_back_val();
+
+ SlotIndex CurrMBBEnd = LIS->getMBBEndIdx(CurrMBB);
+ VNInfo *VNI = UseLI.getVNInfoAt(CurrMBBEnd.getPrevSlot());
+
+ MachineBasicBlock *DefMBB = LIS->getMBBFromIndex(VNI->def);
+
+ // If there is a def in this block, then add it to the list. This is the
+ // reaching def of this path.
+ if (!VNI->isPHIDef()) {
+ DefIdxs.push_back(VNI->def);
+ continue;
+ }
+
+ for (auto *PredMBB : DefMBB->predecessors()) {
+ if (Visited.insert(PredMBB).second)
+ Worklist.push_back(PredMBB);
+ }
+ }
+}
+
+void RewriteScheduleStage::findReachingUses(
+ MachineInstr *DefMI, LiveIntervals *LIS,
+ SmallVectorImpl<MachineOperand *> &ReachingUses) {
+ SlotIndex DefIdx = LIS->getInstructionIndex(*DefMI);
+ for (auto &UseMO :
----------------
arsenm wrote:
```suggestion
for (MachineOperand &UseMO :
```
https://github.com/llvm/llvm-project/pull/170335
More information about the llvm-commits
mailing list