Skip to content

Commit bc497d7

Browse files
committed
Added configuration flag for StackSlotColoring & refactored comments.
1 parent 74381cb commit bc497d7

File tree

4 files changed

+22
-19
lines changed

4 files changed

+22
-19
lines changed

llvm/include/llvm/CodeGen/Passes.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,8 @@ namespace llvm {
371371

372372
/// StackSlotColoring - This pass performs stack slot coloring.
373373
extern char &StackSlotColoringID;
374+
FunctionPass *
375+
createStackSlotColoring(bool preserveRegAllocNeededAnalysis = false);
374376

375377
/// This pass lays out funclets contiguously.
376378
extern char &FuncletLayoutID;

llvm/lib/CodeGen/StackSlotColoring.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,9 @@ namespace {
6767
const MachineBlockFrequencyInfo *MBFI = nullptr;
6868
SlotIndexes *Indexes = nullptr;
6969

70+
// - preserves Analysis passes in case RA may be called afterwards.
71+
bool preserveRegAllocNeededAnalysis = false;
72+
7073
// SSIntervals - Spill slot intervals.
7174
std::vector<LiveInterval*> SSIntervals;
7275

@@ -142,7 +145,9 @@ namespace {
142145
public:
143146
static char ID; // Pass identification
144147

145-
StackSlotColoring() : MachineFunctionPass(ID) {
148+
StackSlotColoring(bool preserveRegAllocNeededAnalysis_ = false)
149+
: MachineFunctionPass(ID),
150+
preserveRegAllocNeededAnalysis(preserveRegAllocNeededAnalysis_) {
146151
initializeStackSlotColoringPass(*PassRegistry::getPassRegistry());
147152
}
148153

@@ -563,3 +568,8 @@ bool StackSlotColoring::runOnMachineFunction(MachineFunction &MF) {
563568

564569
return Changed;
565570
}
571+
572+
FunctionPass *
573+
llvm::createStackSlotColoring(bool preserveRegAllocNeededAnalysis) {
574+
return new StackSlotColoring(preserveRegAllocNeededAnalysis);
575+
}

llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1421,8 +1421,11 @@ bool GCNPassConfig::addRegAssignAndRewriteOptimized() {
14211421
// since FastRegAlloc does the replacements itself.
14221422
addPass(createVirtRegRewriter(false));
14231423

1424-
// Optimizes SGPR spills into VGPR lanes for non-interferring spill-ranges.
1425-
addPass(&StackSlotColoringID);
1424+
// As by this point SGPR's RA is done introducing SGPR spills to stack frame
1425+
// through SGPRAllocPass. So, invoking StackSlotColoring here, may allow these
1426+
// SGPR spills to re-use stack slots, before these spills is further lowered
1427+
// down via SILowerSGPRSpills(i.e. equivalent of PEI for SGPRs).
1428+
addPass(createStackSlotColoring(/*preserveRegAllocNeededAnalysis*/ true));
14261429

14271430
// Equivalent of PEI for SGPRs.
14281431
addPass(&SILowerSGPRSpillsID);

llvm/lib/Target/AMDGPU/SILowerSGPRSpills.cpp

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,7 @@ class SILowerSGPRSpills : public MachineFunctionPass {
5252
void calculateSaveRestoreBlocks(MachineFunction &MF);
5353
bool spillCalleeSavedRegs(MachineFunction &MF,
5454
SmallVectorImpl<int> &CalleeSavedFIs);
55-
void extendWWMVirtRegLiveness(MachineFunction &MF, SlotIndexes *Indexes,
56-
LiveIntervals *LIS);
55+
void extendWWMVirtRegLiveness(MachineFunction &MF, LiveIntervals *LIS);
5756

5857
bool runOnMachineFunction(MachineFunction &MF) override;
5958

@@ -261,7 +260,6 @@ bool SILowerSGPRSpills::spillCalleeSavedRegs(
261260
}
262261

263262
void SILowerSGPRSpills::extendWWMVirtRegLiveness(MachineFunction &MF,
264-
SlotIndexes *Indexes,
265263
LiveIntervals *LIS) {
266264
// TODO: This is a workaround to avoid the unmodelled liveness computed with
267265
// whole-wave virtual registers when allocated together with the regular VGPR
@@ -280,7 +278,6 @@ void SILowerSGPRSpills::extendWWMVirtRegLiveness(MachineFunction &MF,
280278
for (auto Reg : MFI->getSGPRSpillVGPRs()) {
281279
for (MachineBasicBlock *SaveBlock : SaveBlocks) {
282280
MachineBasicBlock::iterator InsertBefore = SaveBlock->begin();
283-
MachineInstrSpan MIS(InsertBefore, SaveBlock);
284281

285282
DebugLoc DL = SaveBlock->findDebugLoc(InsertBefore);
286283
auto MIB = BuildMI(*SaveBlock, InsertBefore, DL,
@@ -289,13 +286,8 @@ void SILowerSGPRSpills::extendWWMVirtRegLiveness(MachineFunction &MF,
289286
// Set SGPR_SPILL asm printer flag
290287
MIB->setAsmPrinterFlag(AMDGPU::SGPR_SPILL);
291288

292-
if (LIS) {
289+
if (LIS)
293290
LIS->InsertMachineInstrInMaps(*MIB);
294-
} else if (Indexes) {
295-
assert(std::distance(MIS.begin(), InsertBefore) == 1);
296-
MachineInstr &Inst = *std::prev(InsertBefore);
297-
Indexes->insertMachineInstrInMaps(Inst);
298-
}
299291
}
300292
}
301293

@@ -310,12 +302,8 @@ void SILowerSGPRSpills::extendWWMVirtRegLiveness(MachineFunction &MF,
310302
TII->get(TargetOpcode::KILL));
311303
MIB.addReg(Reg);
312304

313-
if (LIS) {
305+
if (LIS)
314306
LIS->InsertMachineInstrInMaps(*MIB);
315-
} else if (Indexes) {
316-
MachineInstr &Inst = *std::prev(InsertBefore);
317-
Indexes->insertMachineInstrInMaps(Inst);
318-
}
319307
}
320308
}
321309
}
@@ -406,7 +394,7 @@ bool SILowerSGPRSpills::runOnMachineFunction(MachineFunction &MF) {
406394
}
407395

408396
if (SpilledToVirtVGPRLanes) {
409-
extendWWMVirtRegLiveness(MF, Indexes, LIS);
397+
extendWWMVirtRegLiveness(MF, LIS);
410398
if (LIS) {
411399
// Compute the LiveInterval for the newly created virtual registers.
412400
for (auto Reg : FuncInfo->getSGPRSpillVGPRs())

0 commit comments

Comments
 (0)