Skip to content

Commit 9507d53

Browse files
jrbyrnesTony Linthicum
authored andcommitted
[AMDGPU] Add scheduling stage to rewrite MFMA from VGPR to AGPR
Change-Id: I47b2a4274a35f3cf0a6d064674d1d29526e4dfd2
1 parent 2d4d7e3 commit 9507d53

File tree

6 files changed

+6866
-5
lines changed

6 files changed

+6866
-5
lines changed

llvm/include/llvm/CodeGen/MachineInstrBuilder.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -464,6 +464,21 @@ inline MachineInstrBuilder BuildMI(MachineBasicBlock &BB,
464464
return MachineInstrBuilder(MF, MI).copyMIMetadata(MIMD);
465465
}
466466

467+
/// This version of the builder inserts the newly-built instruction after the
468+
/// given position in the given MachineBasicBlock, and does NOT take a
469+
/// destination register.
470+
inline MachineInstrBuilder BuildMIAfter(MachineBasicBlock &BB,
471+
MachineBasicBlock::iterator I,
472+
const MIMetadata &MIMD,
473+
const MCInstrDesc &MCID) {
474+
MachineFunction &MF = *BB.getParent();
475+
MachineInstr *MI = MF.CreateMachineInstr(MCID, MIMD.getDL());
476+
BB.insertAfter(I, MI);
477+
return MachineInstrBuilder(MF, MI)
478+
.setPCSections(MIMD.getPCSections())
479+
.setMMRAMetadata(MIMD.getMMRAMetadata());
480+
}
481+
467482
inline MachineInstrBuilder BuildMI(MachineBasicBlock &BB,
468483
MachineBasicBlock::instr_iterator I,
469484
const MIMetadata &MIMD,

llvm/lib/Target/AMDGPU/GCNRegPressure.h

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,36 @@ struct GCNRegPressure {
102102
DynamicVGPRBlockSize));
103103
}
104104

105+
unsigned getVGPRSpills(const GCNSubtarget &ST, MachineFunction &MF) {
106+
if (!ST.hasGFX90AInsts())
107+
return 0;
108+
109+
auto MaxVectorRegs = ST.getMaxNumVectorRegs(MF.getFunction());
110+
unsigned ArchVGPRThreshold = MaxVectorRegs.first;
111+
unsigned AGPRThreshold = MaxVectorRegs.second;
112+
113+
unsigned ArchPressure = getArchVGPRNum();
114+
unsigned AGPRPressure = getAGPRNum();
115+
116+
unsigned ArchSpill = ArchPressure > ArchVGPRThreshold
117+
? (ArchPressure - ArchVGPRThreshold)
118+
: 0;
119+
unsigned AGPRSpill =
120+
AGPRPressure > AGPRThreshold ? (AGPRPressure - AGPRThreshold) : 0;
121+
122+
unsigned UnifiedSpill = 0;
123+
124+
if (ST.hasGFX90AInsts()) {
125+
unsigned CombinedThreshold = ST.getMaxNumVGPRs(MF);
126+
unsigned UnifiedPressure = getVGPRNum(true);
127+
UnifiedSpill = UnifiedPressure > CombinedThreshold
128+
? (UnifiedPressure - CombinedThreshold)
129+
: 0;
130+
}
131+
132+
return std::max(UnifiedSpill, (ArchSpill + AGPRSpill));
133+
}
134+
105135
void inc(unsigned Reg,
106136
LaneBitmask PrevMask,
107137
LaneBitmask NewMask,

0 commit comments

Comments
 (0)