Skip to content

Commit 6ddb767

Browse files
committed
Remove the -color-ss-with-regs option.
It was off by default. The new register allocators don't have the problems that made it necessary to reallocate registers during stack slot coloring. llvm-svn: 144481
1 parent 5343da6 commit 6ddb767

File tree

2 files changed

+2
-361
lines changed

2 files changed

+2
-361
lines changed

llvm/lib/CodeGen/StackSlotColoring.cpp

Lines changed: 2 additions & 306 deletions
Original file line numberDiff line numberDiff line change
@@ -40,18 +40,9 @@ DisableSharing("no-stack-slot-sharing",
4040
cl::init(false), cl::Hidden,
4141
cl::desc("Suppress slot sharing during stack coloring"));
4242

43-
static cl::opt<bool>
44-
ColorWithRegsOpt("color-ss-with-regs",
45-
cl::init(false), cl::Hidden,
46-
cl::desc("Color stack slots with free registers"));
47-
48-
4943
static cl::opt<int> DCELimit("ssc-dce-limit", cl::init(-1), cl::Hidden);
5044

5145
STATISTIC(NumEliminated, "Number of stack slots eliminated due to coloring");
52-
STATISTIC(NumRegRepl, "Number of stack slot refs replaced with reg refs");
53-
STATISTIC(NumLoadElim, "Number of loads eliminated");
54-
STATISTIC(NumStoreElim, "Number of stores eliminated");
5546
STATISTIC(NumDead, "Number of trivially dead stack accesses eliminated");
5647

5748
namespace {
@@ -127,22 +118,8 @@ namespace {
127118
bool OverlapWithAssignments(LiveInterval *li, int Color) const;
128119
int ColorSlot(LiveInterval *li);
129120
bool ColorSlots(MachineFunction &MF);
130-
bool ColorSlotsWithFreeRegs(SmallVector<int, 16> &SlotMapping,
131-
SmallVector<SmallVector<int, 4>, 16> &RevMap,
132-
BitVector &SlotIsReg);
133121
void RewriteInstruction(MachineInstr *MI, int OldFI, int NewFI,
134122
MachineFunction &MF);
135-
bool PropagateBackward(MachineBasicBlock::iterator MII,
136-
MachineBasicBlock *MBB,
137-
unsigned OldReg, unsigned NewReg);
138-
bool PropagateForward(MachineBasicBlock::iterator MII,
139-
MachineBasicBlock *MBB,
140-
unsigned OldReg, unsigned NewReg);
141-
void UnfoldAndRewriteInstruction(MachineInstr *MI, int OldFI,
142-
unsigned Reg, const TargetRegisterClass *RC,
143-
SmallSet<unsigned, 4> &Defs,
144-
MachineFunction &MF);
145-
bool AllMemRefsCanBeUnfolded(int SS);
146123
bool RemoveDeadStores(MachineBasicBlock* MBB);
147124
};
148125
} // end anonymous namespace
@@ -248,79 +225,6 @@ StackSlotColoring::OverlapWithAssignments(LiveInterval *li, int Color) const {
248225
return false;
249226
}
250227

251-
/// ColorSlotsWithFreeRegs - If there are any free registers available, try
252-
/// replacing spill slots references with registers instead.
253-
bool
254-
StackSlotColoring::ColorSlotsWithFreeRegs(SmallVector<int, 16> &SlotMapping,
255-
SmallVector<SmallVector<int, 4>, 16> &RevMap,
256-
BitVector &SlotIsReg) {
257-
if (!(ColorWithRegs || ColorWithRegsOpt) || !VRM->HasUnusedRegisters())
258-
return false;
259-
260-
bool Changed = false;
261-
DEBUG(dbgs() << "Assigning unused registers to spill slots:\n");
262-
for (unsigned i = 0, e = SSIntervals.size(); i != e; ++i) {
263-
LiveInterval *li = SSIntervals[i];
264-
int SS = TargetRegisterInfo::stackSlot2Index(li->reg);
265-
if (!UsedColors[SS] || li->weight < 20)
266-
// If the weight is < 20, i.e. two references in a loop with depth 1,
267-
// don't bother with it.
268-
continue;
269-
270-
// These slots allow to share the same registers.
271-
bool AllColored = true;
272-
SmallVector<unsigned, 4> ColoredRegs;
273-
for (unsigned j = 0, ee = RevMap[SS].size(); j != ee; ++j) {
274-
int RSS = RevMap[SS][j];
275-
const TargetRegisterClass *RC = LS->getIntervalRegClass(RSS);
276-
// If it's not colored to another stack slot, try coloring it
277-
// to a "free" register.
278-
if (!RC) {
279-
AllColored = false;
280-
continue;
281-
}
282-
unsigned Reg = VRM->getFirstUnusedRegister(RC);
283-
if (!Reg) {
284-
AllColored = false;
285-
continue;
286-
}
287-
if (!AllMemRefsCanBeUnfolded(RSS)) {
288-
AllColored = false;
289-
continue;
290-
} else {
291-
DEBUG(dbgs() << "Assigning fi#" << RSS << " to "
292-
<< TRI->getName(Reg) << '\n');
293-
ColoredRegs.push_back(Reg);
294-
SlotMapping[RSS] = Reg;
295-
SlotIsReg.set(RSS);
296-
Changed = true;
297-
}
298-
}
299-
300-
// Register and its sub-registers are no longer free.
301-
while (!ColoredRegs.empty()) {
302-
unsigned Reg = ColoredRegs.back();
303-
ColoredRegs.pop_back();
304-
VRM->setRegisterUsed(Reg);
305-
// If reg is a callee-saved register, it will have to be spilled in
306-
// the prologue.
307-
MRI->setPhysRegUsed(Reg);
308-
for (const unsigned *AS = TRI->getAliasSet(Reg); *AS; ++AS) {
309-
VRM->setRegisterUsed(*AS);
310-
MRI->setPhysRegUsed(*AS);
311-
}
312-
}
313-
// This spill slot is dead after the rewrites
314-
if (AllColored) {
315-
MFI->RemoveStackObject(SS);
316-
++NumEliminated;
317-
}
318-
}
319-
DEBUG(dbgs() << '\n');
320-
321-
return Changed;
322-
}
323-
324228
/// ColorSlot - Assign a "color" (stack slot) to the specified stack slot.
325229
///
326230
int StackSlotColoring::ColorSlot(LiveInterval *li) {
@@ -372,7 +276,6 @@ bool StackSlotColoring::ColorSlots(MachineFunction &MF) {
372276
SmallVector<int, 16> SlotMapping(NumObjs, -1);
373277
SmallVector<float, 16> SlotWeights(NumObjs, 0.0);
374278
SmallVector<SmallVector<int, 4>, 16> RevMap(NumObjs);
375-
BitVector SlotIsReg(NumObjs);
376279
BitVector UsedColors(NumObjs);
377280

378281
DEBUG(dbgs() << "Color spill slot intervals:\n");
@@ -404,31 +307,19 @@ bool StackSlotColoring::ColorSlots(MachineFunction &MF) {
404307
DEBUG(dbgs() << '\n');
405308
#endif
406309

407-
// Can we "color" a stack slot with a unused register?
408-
Changed |= ColorSlotsWithFreeRegs(SlotMapping, RevMap, SlotIsReg);
409-
410310
if (!Changed)
411311
return false;
412312

413313
// Rewrite all MO_FrameIndex operands.
414314
SmallVector<SmallSet<unsigned, 4>, 4> NewDefs(MF.getNumBlockIDs());
415315
for (unsigned SS = 0, SE = SSRefs.size(); SS != SE; ++SS) {
416-
bool isReg = SlotIsReg[SS];
417316
int NewFI = SlotMapping[SS];
418-
if (NewFI == -1 || (NewFI == (int)SS && !isReg))
317+
if (NewFI == -1 || (NewFI == (int)SS))
419318
continue;
420319

421-
const TargetRegisterClass *RC = LS->getIntervalRegClass(SS);
422320
SmallVector<MachineInstr*, 8> &RefMIs = SSRefs[SS];
423321
for (unsigned i = 0, e = RefMIs.size(); i != e; ++i)
424-
if (!isReg)
425-
RewriteInstruction(RefMIs[i], SS, NewFI, MF);
426-
else {
427-
// Rewrite to use a register instead.
428-
unsigned MBBId = RefMIs[i]->getParent()->getNumber();
429-
SmallSet<unsigned, 4> &Defs = NewDefs[MBBId];
430-
UnfoldAndRewriteInstruction(RefMIs[i], SS, NewFI, RC, Defs, MF);
431-
}
322+
RewriteInstruction(RefMIs[i], SS, NewFI, MF);
432323
}
433324

434325
// Delete unused stack slots.
@@ -441,28 +332,6 @@ bool StackSlotColoring::ColorSlots(MachineFunction &MF) {
441332
return true;
442333
}
443334

444-
/// AllMemRefsCanBeUnfolded - Return true if all references of the specified
445-
/// spill slot index can be unfolded.
446-
bool StackSlotColoring::AllMemRefsCanBeUnfolded(int SS) {
447-
SmallVector<MachineInstr*, 8> &RefMIs = SSRefs[SS];
448-
for (unsigned i = 0, e = RefMIs.size(); i != e; ++i) {
449-
MachineInstr *MI = RefMIs[i];
450-
if (TII->isLoadFromStackSlot(MI, SS) ||
451-
TII->isStoreToStackSlot(MI, SS))
452-
// Restore and spill will become copies.
453-
return true;
454-
if (!TII->getOpcodeAfterMemoryUnfold(MI->getOpcode(), false, false))
455-
return false;
456-
for (unsigned j = 0, ee = MI->getNumOperands(); j != ee; ++j) {
457-
MachineOperand &MO = MI->getOperand(j);
458-
if (MO.isFI() && MO.getIndex() != SS)
459-
// If it uses another frameindex, we can, currently* unfold it.
460-
return false;
461-
}
462-
}
463-
return true;
464-
}
465-
466335
/// RewriteInstruction - Rewrite specified instruction by replacing references
467336
/// to old frame index with new one.
468337
void StackSlotColoring::RewriteInstruction(MachineInstr *MI, int OldFI,
@@ -489,179 +358,6 @@ void StackSlotColoring::RewriteInstruction(MachineInstr *MI, int OldFI,
489358
(*I)->setValue(NewSV);
490359
}
491360

492-
/// PropagateBackward - Traverse backward and look for the definition of
493-
/// OldReg. If it can successfully update all of the references with NewReg,
494-
/// do so and return true.
495-
bool StackSlotColoring::PropagateBackward(MachineBasicBlock::iterator MII,
496-
MachineBasicBlock *MBB,
497-
unsigned OldReg, unsigned NewReg) {
498-
if (MII == MBB->begin())
499-
return false;
500-
501-
SmallVector<MachineOperand*, 4> Uses;
502-
SmallVector<MachineOperand*, 4> Refs;
503-
while (--MII != MBB->begin()) {
504-
bool FoundDef = false; // Not counting 2address def.
505-
506-
Uses.clear();
507-
const MCInstrDesc &MCID = MII->getDesc();
508-
for (unsigned i = 0, e = MII->getNumOperands(); i != e; ++i) {
509-
MachineOperand &MO = MII->getOperand(i);
510-
if (!MO.isReg())
511-
continue;
512-
unsigned Reg = MO.getReg();
513-
if (Reg == 0)
514-
continue;
515-
if (Reg == OldReg) {
516-
if (MO.isImplicit())
517-
return false;
518-
519-
// Abort the use is actually a sub-register def. We don't have enough
520-
// information to figure out if it is really legal.
521-
if (MO.getSubReg() || MII->isSubregToReg())
522-
return false;
523-
524-
const TargetRegisterClass *RC = TII->getRegClass(MCID, i, TRI);
525-
if (RC && !RC->contains(NewReg))
526-
return false;
527-
528-
if (MO.isUse()) {
529-
Uses.push_back(&MO);
530-
} else {
531-
Refs.push_back(&MO);
532-
if (!MII->isRegTiedToUseOperand(i))
533-
FoundDef = true;
534-
}
535-
} else if (TRI->regsOverlap(Reg, NewReg)) {
536-
return false;
537-
} else if (TRI->regsOverlap(Reg, OldReg)) {
538-
if (!MO.isUse() || !MO.isKill())
539-
return false;
540-
}
541-
}
542-
543-
if (FoundDef) {
544-
// Found non-two-address def. Stop here.
545-
for (unsigned i = 0, e = Refs.size(); i != e; ++i)
546-
Refs[i]->setReg(NewReg);
547-
return true;
548-
}
549-
550-
// Two-address uses must be updated as well.
551-
for (unsigned i = 0, e = Uses.size(); i != e; ++i)
552-
Refs.push_back(Uses[i]);
553-
}
554-
return false;
555-
}
556-
557-
/// PropagateForward - Traverse forward and look for the kill of OldReg. If
558-
/// it can successfully update all of the uses with NewReg, do so and
559-
/// return true.
560-
bool StackSlotColoring::PropagateForward(MachineBasicBlock::iterator MII,
561-
MachineBasicBlock *MBB,
562-
unsigned OldReg, unsigned NewReg) {
563-
if (MII == MBB->end())
564-
return false;
565-
566-
SmallVector<MachineOperand*, 4> Uses;
567-
while (++MII != MBB->end()) {
568-
bool FoundKill = false;
569-
const MCInstrDesc &MCID = MII->getDesc();
570-
for (unsigned i = 0, e = MII->getNumOperands(); i != e; ++i) {
571-
MachineOperand &MO = MII->getOperand(i);
572-
if (!MO.isReg())
573-
continue;
574-
unsigned Reg = MO.getReg();
575-
if (Reg == 0)
576-
continue;
577-
if (Reg == OldReg) {
578-
if (MO.isDef() || MO.isImplicit())
579-
return false;
580-
581-
// Abort the use is actually a sub-register use. We don't have enough
582-
// information to figure out if it is really legal.
583-
if (MO.getSubReg())
584-
return false;
585-
586-
const TargetRegisterClass *RC = TII->getRegClass(MCID, i, TRI);
587-
if (RC && !RC->contains(NewReg))
588-
return false;
589-
if (MO.isKill())
590-
FoundKill = true;
591-
592-
Uses.push_back(&MO);
593-
} else if (TRI->regsOverlap(Reg, NewReg) ||
594-
TRI->regsOverlap(Reg, OldReg))
595-
return false;
596-
}
597-
if (FoundKill) {
598-
for (unsigned i = 0, e = Uses.size(); i != e; ++i)
599-
Uses[i]->setReg(NewReg);
600-
return true;
601-
}
602-
}
603-
return false;
604-
}
605-
606-
/// UnfoldAndRewriteInstruction - Rewrite specified instruction by unfolding
607-
/// folded memory references and replacing those references with register
608-
/// references instead.
609-
void
610-
StackSlotColoring::UnfoldAndRewriteInstruction(MachineInstr *MI, int OldFI,
611-
unsigned Reg,
612-
const TargetRegisterClass *RC,
613-
SmallSet<unsigned, 4> &Defs,
614-
MachineFunction &MF) {
615-
MachineBasicBlock *MBB = MI->getParent();
616-
if (unsigned DstReg = TII->isLoadFromStackSlot(MI, OldFI)) {
617-
if (PropagateForward(MI, MBB, DstReg, Reg)) {
618-
DEBUG(dbgs() << "Eliminated load: ");
619-
DEBUG(MI->dump());
620-
++NumLoadElim;
621-
} else {
622-
BuildMI(*MBB, MI, MI->getDebugLoc(), TII->get(TargetOpcode::COPY),
623-
DstReg).addReg(Reg);
624-
++NumRegRepl;
625-
}
626-
627-
if (!Defs.count(Reg)) {
628-
// If this is the first use of Reg in this MBB and it wasn't previously
629-
// defined in MBB, add it to livein.
630-
MBB->addLiveIn(Reg);
631-
Defs.insert(Reg);
632-
}
633-
} else if (unsigned SrcReg = TII->isStoreToStackSlot(MI, OldFI)) {
634-
if (MI->killsRegister(SrcReg) && PropagateBackward(MI, MBB, SrcReg, Reg)) {
635-
DEBUG(dbgs() << "Eliminated store: ");
636-
DEBUG(MI->dump());
637-
++NumStoreElim;
638-
} else {
639-
BuildMI(*MBB, MI, MI->getDebugLoc(), TII->get(TargetOpcode::COPY), Reg)
640-
.addReg(SrcReg);
641-
++NumRegRepl;
642-
}
643-
644-
// Remember reg has been defined in MBB.
645-
Defs.insert(Reg);
646-
} else {
647-
SmallVector<MachineInstr*, 4> NewMIs;
648-
bool Success = TII->unfoldMemoryOperand(MF, MI, Reg, false, false, NewMIs);
649-
(void)Success; // Silence compiler warning.
650-
assert(Success && "Failed to unfold!");
651-
MachineInstr *NewMI = NewMIs[0];
652-
MBB->insert(MI, NewMI);
653-
++NumRegRepl;
654-
655-
if (NewMI->readsRegister(Reg)) {
656-
if (!Defs.count(Reg))
657-
// If this is the first use of Reg in this MBB and it wasn't previously
658-
// defined in MBB, add it to livein.
659-
MBB->addLiveIn(Reg);
660-
Defs.insert(Reg);
661-
}
662-
}
663-
MBB->erase(MI);
664-
}
665361

666362
/// RemoveDeadStores - Scan through a basic block and look for loads followed
667363
/// by stores. If they're both using the same stack slot, then the store is

0 commit comments

Comments
 (0)