1 //===-- StackSlotColoring.cpp - Stack slot coloring pass. -----------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file implements the stack slot coloring pass.
12 //===----------------------------------------------------------------------===//
14 #define DEBUG_TYPE "stackcoloring"
15 #include "VirtRegMap.h"
16 #include "llvm/CodeGen/Passes.h"
17 #include "llvm/CodeGen/LiveIntervalAnalysis.h"
18 #include "llvm/CodeGen/LiveStackAnalysis.h"
19 #include "llvm/CodeGen/MachineFrameInfo.h"
20 #include "llvm/CodeGen/MachineLoopInfo.h"
21 #include "llvm/CodeGen/MachineRegisterInfo.h"
22 #include "llvm/CodeGen/PseudoSourceValue.h"
23 #include "llvm/Support/CommandLine.h"
24 #include "llvm/Support/Compiler.h"
25 #include "llvm/Support/Debug.h"
26 #include "llvm/Target/TargetInstrInfo.h"
27 #include "llvm/Target/TargetMachine.h"
28 #include "llvm/ADT/BitVector.h"
29 #include "llvm/ADT/SmallVector.h"
30 #include "llvm/ADT/Statistic.h"
35 DisableSharing("no-stack-slot-sharing",
36 cl::init(false), cl::Hidden
,
37 cl::desc("Suppress slot sharing during stack coloring"));
40 ColorWithRegsOpt("color-ss-with-regs",
41 cl::init(false), cl::Hidden
,
42 cl::desc("Color stack slots with free registers"));
45 static cl::opt
<int> DCELimit("ssc-dce-limit", cl::init(-1), cl::Hidden
);
47 STATISTIC(NumEliminated
, "Number of stack slots eliminated due to coloring");
48 STATISTIC(NumRegRepl
, "Number of stack slot refs replaced with reg refs");
49 STATISTIC(NumLoadElim
, "Number of loads eliminated");
50 STATISTIC(NumStoreElim
, "Number of stores eliminated");
51 STATISTIC(NumDead
, "Number of trivially dead stack accesses eliminated");
54 class VISIBILITY_HIDDEN StackSlotColoring
: public MachineFunctionPass
{
58 MachineFrameInfo
*MFI
;
59 MachineRegisterInfo
*MRI
;
60 const TargetInstrInfo
*TII
;
61 const TargetRegisterInfo
*TRI
;
62 const MachineLoopInfo
*loopInfo
;
64 // SSIntervals - Spill slot intervals.
65 std::vector
<LiveInterval
*> SSIntervals
;
67 // SSRefs - Keep a list of frame index references for each spill slot.
68 SmallVector
<SmallVector
<MachineInstr
*, 8>, 16> SSRefs
;
70 // OrigAlignments - Alignments of stack objects before coloring.
71 SmallVector
<unsigned, 16> OrigAlignments
;
73 // OrigSizes - Sizess of stack objects before coloring.
74 SmallVector
<unsigned, 16> OrigSizes
;
76 // AllColors - If index is set, it's a spill slot, i.e. color.
77 // FIXME: This assumes PEI locate spill slot with smaller indices
78 // closest to stack pointer / frame pointer. Therefore, smaller
79 // index == better color.
82 // NextColor - Next "color" that's not yet used.
85 // UsedColors - "Colors" that have been assigned.
88 // Assignments - Color to intervals mapping.
89 SmallVector
<SmallVector
<LiveInterval
*,4>, 16> Assignments
;
92 static char ID
; // Pass identification
94 MachineFunctionPass(&ID
), ColorWithRegs(false), NextColor(-1) {}
95 StackSlotColoring(bool RegColor
) :
96 MachineFunctionPass(&ID
), ColorWithRegs(RegColor
), NextColor(-1) {}
98 virtual void getAnalysisUsage(AnalysisUsage
&AU
) const {
99 AU
.addRequired
<LiveStacks
>();
100 AU
.addRequired
<VirtRegMap
>();
101 AU
.addPreserved
<VirtRegMap
>();
102 AU
.addRequired
<MachineLoopInfo
>();
103 AU
.addPreserved
<MachineLoopInfo
>();
104 AU
.addPreservedID(MachineDominatorsID
);
105 MachineFunctionPass::getAnalysisUsage(AU
);
108 virtual bool runOnMachineFunction(MachineFunction
&MF
);
109 virtual const char* getPassName() const {
110 return "Stack Slot Coloring";
114 void InitializeSlots();
115 void ScanForSpillSlotRefs(MachineFunction
&MF
);
116 bool OverlapWithAssignments(LiveInterval
*li
, int Color
) const;
117 int ColorSlot(LiveInterval
*li
);
118 bool ColorSlots(MachineFunction
&MF
);
119 bool ColorSlotsWithFreeRegs(SmallVector
<int, 16> &SlotMapping
,
120 SmallVector
<SmallVector
<int, 4>, 16> &RevMap
,
121 BitVector
&SlotIsReg
);
122 void RewriteInstruction(MachineInstr
*MI
, int OldFI
, int NewFI
,
123 MachineFunction
&MF
);
124 bool PropagateBackward(MachineBasicBlock::iterator MII
,
125 MachineBasicBlock
*MBB
,
126 unsigned OldReg
, unsigned NewReg
);
127 bool PropagateForward(MachineBasicBlock::iterator MII
,
128 MachineBasicBlock
*MBB
,
129 unsigned OldReg
, unsigned NewReg
);
130 void UnfoldAndRewriteInstruction(MachineInstr
*MI
, int OldFI
,
131 unsigned Reg
, const TargetRegisterClass
*RC
,
132 MachineFunction
&MF
);
133 bool AllMemRefsCanBeUnfolded(int SS
);
134 bool RemoveDeadStores(MachineBasicBlock
* MBB
);
136 } // end anonymous namespace
138 char StackSlotColoring::ID
= 0;
140 static RegisterPass
<StackSlotColoring
>
141 X("stack-slot-coloring", "Stack Slot Coloring");
143 FunctionPass
*llvm::createStackSlotColoringPass(bool RegColor
) {
144 return new StackSlotColoring(RegColor
);
148 // IntervalSorter - Comparison predicate that sort live intervals by
150 struct IntervalSorter
{
151 bool operator()(LiveInterval
* LHS
, LiveInterval
* RHS
) const {
152 return LHS
->weight
> RHS
->weight
;
157 /// ScanForSpillSlotRefs - Scan all the machine instructions for spill slot
158 /// references and update spill slot weights.
159 void StackSlotColoring::ScanForSpillSlotRefs(MachineFunction
&MF
) {
160 SSRefs
.resize(MFI
->getObjectIndexEnd());
162 // FIXME: Need the equivalent of MachineRegisterInfo for frameindex operands.
163 for (MachineFunction::iterator MBBI
= MF
.begin(), E
= MF
.end();
165 MachineBasicBlock
*MBB
= &*MBBI
;
166 unsigned loopDepth
= loopInfo
->getLoopDepth(MBB
);
167 for (MachineBasicBlock::iterator MII
= MBB
->begin(), EE
= MBB
->end();
169 MachineInstr
*MI
= &*MII
;
170 for (unsigned i
= 0, e
= MI
->getNumOperands(); i
!= e
; ++i
) {
171 MachineOperand
&MO
= MI
->getOperand(i
);
174 int FI
= MO
.getIndex();
177 if (!LS
->hasInterval(FI
))
179 LiveInterval
&li
= LS
->getInterval(FI
);
180 li
.weight
+= LiveIntervals::getSpillWeight(false, true, loopDepth
);
181 SSRefs
[FI
].push_back(MI
);
187 /// InitializeSlots - Process all spill stack slot liveintervals and add them
188 /// to a sorted (by weight) list.
189 void StackSlotColoring::InitializeSlots() {
190 int LastFI
= MFI
->getObjectIndexEnd();
191 OrigAlignments
.resize(LastFI
);
192 OrigSizes
.resize(LastFI
);
193 AllColors
.resize(LastFI
);
194 UsedColors
.resize(LastFI
);
195 Assignments
.resize(LastFI
);
197 // Gather all spill slots into a list.
198 DOUT
<< "Spill slot intervals:\n";
199 for (LiveStacks::iterator i
= LS
->begin(), e
= LS
->end(); i
!= e
; ++i
) {
200 LiveInterval
&li
= i
->second
;
202 int FI
= li
.getStackSlotIndex();
203 if (MFI
->isDeadObjectIndex(FI
))
205 SSIntervals
.push_back(&li
);
206 OrigAlignments
[FI
] = MFI
->getObjectAlignment(FI
);
207 OrigSizes
[FI
] = MFI
->getObjectSize(FI
);
212 // Sort them by weight.
213 std::stable_sort(SSIntervals
.begin(), SSIntervals
.end(), IntervalSorter());
215 // Get first "color".
216 NextColor
= AllColors
.find_first();
219 /// OverlapWithAssignments - Return true if LiveInterval overlaps with any
220 /// LiveIntervals that have already been assigned to the specified color.
222 StackSlotColoring::OverlapWithAssignments(LiveInterval
*li
, int Color
) const {
223 const SmallVector
<LiveInterval
*,4> &OtherLIs
= Assignments
[Color
];
224 for (unsigned i
= 0, e
= OtherLIs
.size(); i
!= e
; ++i
) {
225 LiveInterval
*OtherLI
= OtherLIs
[i
];
226 if (OtherLI
->overlaps(*li
))
232 /// ColorSlotsWithFreeRegs - If there are any free registers available, try
233 /// replacing spill slots references with registers instead.
235 StackSlotColoring::ColorSlotsWithFreeRegs(SmallVector
<int, 16> &SlotMapping
,
236 SmallVector
<SmallVector
<int, 4>, 16> &RevMap
,
237 BitVector
&SlotIsReg
) {
238 if (!(ColorWithRegs
|| ColorWithRegsOpt
) || !VRM
->HasUnusedRegisters())
241 bool Changed
= false;
242 DOUT
<< "Assigning unused registers to spill slots:\n";
243 for (unsigned i
= 0, e
= SSIntervals
.size(); i
!= e
; ++i
) {
244 LiveInterval
*li
= SSIntervals
[i
];
245 int SS
= li
->getStackSlotIndex();
246 if (!UsedColors
[SS
] || li
->weight
< 20)
247 // If the weight is < 20, i.e. two references in a loop with depth 1,
248 // don't bother with it.
251 // These slots allow to share the same registers.
252 bool AllColored
= true;
253 SmallVector
<unsigned, 4> ColoredRegs
;
254 for (unsigned j
= 0, ee
= RevMap
[SS
].size(); j
!= ee
; ++j
) {
255 int RSS
= RevMap
[SS
][j
];
256 const TargetRegisterClass
*RC
= LS
->getIntervalRegClass(RSS
);
257 // If it's not colored to another stack slot, try coloring it
258 // to a "free" register.
263 unsigned Reg
= VRM
->getFirstUnusedRegister(RC
);
268 if (!AllMemRefsCanBeUnfolded(RSS
)) {
272 DOUT
<< "Assigning fi#" << RSS
<< " to " << TRI
->getName(Reg
) << '\n';
273 ColoredRegs
.push_back(Reg
);
274 SlotMapping
[RSS
] = Reg
;
280 // Register and its sub-registers are no longer free.
281 while (!ColoredRegs
.empty()) {
282 unsigned Reg
= ColoredRegs
.back();
283 ColoredRegs
.pop_back();
284 VRM
->setRegisterUsed(Reg
);
285 // If reg is a callee-saved register, it will have to be spilled in
287 MRI
->setPhysRegUsed(Reg
);
288 for (const unsigned *AS
= TRI
->getAliasSet(Reg
); *AS
; ++AS
) {
289 VRM
->setRegisterUsed(*AS
);
290 MRI
->setPhysRegUsed(*AS
);
293 // This spill slot is dead after the rewrites
295 MFI
->RemoveStackObject(SS
);
304 /// ColorSlot - Assign a "color" (stack slot) to the specified stack slot.
306 int StackSlotColoring::ColorSlot(LiveInterval
*li
) {
309 if (!DisableSharing
) {
310 // Check if it's possible to reuse any of the used colors.
311 Color
= UsedColors
.find_first();
312 while (Color
!= -1) {
313 if (!OverlapWithAssignments(li
, Color
)) {
318 Color
= UsedColors
.find_next(Color
);
322 // Assign it to the first available color (assumed to be the best) if it's
323 // not possible to share a used color with other objects.
325 assert(NextColor
!= -1 && "No more spill slots?");
327 UsedColors
.set(Color
);
328 NextColor
= AllColors
.find_next(NextColor
);
331 // Record the assignment.
332 Assignments
[Color
].push_back(li
);
333 int FI
= li
->getStackSlotIndex();
334 DOUT
<< "Assigning fi#" << FI
<< " to fi#" << Color
<< "\n";
336 // Change size and alignment of the allocated slot. If there are multiple
337 // objects sharing the same slot, then make sure the size and alignment
338 // are large enough for all.
339 unsigned Align
= OrigAlignments
[FI
];
340 if (!Share
|| Align
> MFI
->getObjectAlignment(Color
))
341 MFI
->setObjectAlignment(Color
, Align
);
342 int64_t Size
= OrigSizes
[FI
];
343 if (!Share
|| Size
> MFI
->getObjectSize(Color
))
344 MFI
->setObjectSize(Color
, Size
);
348 /// Colorslots - Color all spill stack slots and rewrite all frameindex machine
349 /// operands in the function.
350 bool StackSlotColoring::ColorSlots(MachineFunction
&MF
) {
351 unsigned NumObjs
= MFI
->getObjectIndexEnd();
352 SmallVector
<int, 16> SlotMapping(NumObjs
, -1);
353 SmallVector
<float, 16> SlotWeights(NumObjs
, 0.0);
354 SmallVector
<SmallVector
<int, 4>, 16> RevMap(NumObjs
);
355 BitVector
SlotIsReg(NumObjs
);
356 BitVector
UsedColors(NumObjs
);
358 DOUT
<< "Color spill slot intervals:\n";
359 bool Changed
= false;
360 for (unsigned i
= 0, e
= SSIntervals
.size(); i
!= e
; ++i
) {
361 LiveInterval
*li
= SSIntervals
[i
];
362 int SS
= li
->getStackSlotIndex();
363 int NewSS
= ColorSlot(li
);
364 assert(NewSS
>= 0 && "Stack coloring failed?");
365 SlotMapping
[SS
] = NewSS
;
366 RevMap
[NewSS
].push_back(SS
);
367 SlotWeights
[NewSS
] += li
->weight
;
368 UsedColors
.set(NewSS
);
369 Changed
|= (SS
!= NewSS
);
372 DOUT
<< "\nSpill slots after coloring:\n";
373 for (unsigned i
= 0, e
= SSIntervals
.size(); i
!= e
; ++i
) {
374 LiveInterval
*li
= SSIntervals
[i
];
375 int SS
= li
->getStackSlotIndex();
376 li
->weight
= SlotWeights
[SS
];
378 // Sort them by new weight.
379 std::stable_sort(SSIntervals
.begin(), SSIntervals
.end(), IntervalSorter());
382 for (unsigned i
= 0, e
= SSIntervals
.size(); i
!= e
; ++i
)
383 DEBUG(SSIntervals
[i
]->dump());
387 // Can we "color" a stack slot with a unused register?
388 Changed
|= ColorSlotsWithFreeRegs(SlotMapping
, RevMap
, SlotIsReg
);
393 // Rewrite all MO_FrameIndex operands.
394 for (unsigned SS
= 0, SE
= SSRefs
.size(); SS
!= SE
; ++SS
) {
395 bool isReg
= SlotIsReg
[SS
];
396 int NewFI
= SlotMapping
[SS
];
397 if (NewFI
== -1 || (NewFI
== (int)SS
&& !isReg
))
400 SmallVector
<MachineInstr
*, 8> &RefMIs
= SSRefs
[SS
];
401 for (unsigned i
= 0, e
= RefMIs
.size(); i
!= e
; ++i
)
403 RewriteInstruction(RefMIs
[i
], SS
, NewFI
, MF
);
405 // Rewrite to use a register instead.
406 const TargetRegisterClass
*RC
= LS
->getIntervalRegClass(SS
);
407 UnfoldAndRewriteInstruction(RefMIs
[i
], SS
, NewFI
, RC
, MF
);
411 // Delete unused stack slots.
412 while (NextColor
!= -1) {
413 DOUT
<< "Removing unused stack object fi#" << NextColor
<< "\n";
414 MFI
->RemoveStackObject(NextColor
);
415 NextColor
= AllColors
.find_next(NextColor
);
421 /// AllMemRefsCanBeUnfolded - Return true if all references of the specified
422 /// spill slot index can be unfolded.
423 bool StackSlotColoring::AllMemRefsCanBeUnfolded(int SS
) {
424 SmallVector
<MachineInstr
*, 8> &RefMIs
= SSRefs
[SS
];
425 for (unsigned i
= 0, e
= RefMIs
.size(); i
!= e
; ++i
) {
426 MachineInstr
*MI
= RefMIs
[i
];
427 if (TII
->isLoadFromStackSlot(MI
, SS
) ||
428 TII
->isStoreToStackSlot(MI
, SS
))
429 // Restore and spill will become copies.
431 if (!TII
->getOpcodeAfterMemoryUnfold(MI
->getOpcode(), false, false))
433 for (unsigned j
= 0, ee
= MI
->getNumOperands(); j
!= ee
; ++j
) {
434 MachineOperand
&MO
= MI
->getOperand(j
);
435 if (MO
.isFI() && MO
.getIndex() != SS
)
436 // If it uses another frameindex, we can, currently* unfold it.
443 /// RewriteInstruction - Rewrite specified instruction by replacing references
444 /// to old frame index with new one.
445 void StackSlotColoring::RewriteInstruction(MachineInstr
*MI
, int OldFI
,
446 int NewFI
, MachineFunction
&MF
) {
447 for (unsigned i
= 0, ee
= MI
->getNumOperands(); i
!= ee
; ++i
) {
448 MachineOperand
&MO
= MI
->getOperand(i
);
451 int FI
= MO
.getIndex();
457 // Update the MachineMemOperand for the new memory location.
458 // FIXME: We need a better method of managing these too.
459 SmallVector
<MachineMemOperand
, 2> MMOs(MI
->memoperands_begin(),
460 MI
->memoperands_end());
461 MI
->clearMemOperands(MF
);
462 const Value
*OldSV
= PseudoSourceValue::getFixedStack(OldFI
);
463 for (unsigned i
= 0, ee
= MMOs
.size(); i
!= ee
; ++i
) {
464 if (MMOs
[i
].getValue() != OldSV
)
465 MI
->addMemOperand(MF
, MMOs
[i
]);
467 MachineMemOperand
MMO(PseudoSourceValue::getFixedStack(NewFI
),
468 MMOs
[i
].getFlags(), MMOs
[i
].getOffset(),
469 MMOs
[i
].getSize(), MMOs
[i
].getAlignment());
470 MI
->addMemOperand(MF
, MMO
);
475 /// PropagateBackward - Traverse backward and look for the definition of
476 /// OldReg. If it can successfully update all of the references with NewReg,
477 /// do so and return true.
478 bool StackSlotColoring::PropagateBackward(MachineBasicBlock::iterator MII
,
479 MachineBasicBlock
*MBB
,
480 unsigned OldReg
, unsigned NewReg
) {
481 if (MII
== MBB
->begin())
484 SmallVector
<MachineOperand
*, 4> Refs
;
485 while (--MII
!= MBB
->begin()) {
486 bool FoundDef
= false; // Not counting 2address def.
487 bool FoundUse
= false;
488 bool FoundKill
= false;
489 const TargetInstrDesc
&TID
= MII
->getDesc();
490 for (unsigned i
= 0, e
= MII
->getNumOperands(); i
!= e
; ++i
) {
491 MachineOperand
&MO
= MII
->getOperand(i
);
494 unsigned Reg
= MO
.getReg();
498 const TargetRegisterClass
*RC
= getInstrOperandRegClass(TRI
, TID
, i
);
499 if (RC
&& !RC
->contains(NewReg
))
509 if (!MII
->isRegTiedToUseOperand(i
))
512 } else if (TRI
->regsOverlap(Reg
, NewReg
)) {
514 } else if (TRI
->regsOverlap(Reg
, OldReg
)) {
515 if (!MO
.isUse() || !MO
.isKill())
520 for (unsigned i
= 0, e
= Refs
.size(); i
!= e
; ++i
)
521 Refs
[i
]->setReg(NewReg
);
528 /// PropagateForward - Traverse forward and look for the kill of OldReg. If
529 /// it can successfully update all of the uses with NewReg, do so and
531 bool StackSlotColoring::PropagateForward(MachineBasicBlock::iterator MII
,
532 MachineBasicBlock
*MBB
,
533 unsigned OldReg
, unsigned NewReg
) {
534 if (MII
== MBB
->end())
537 SmallVector
<MachineOperand
*, 4> Uses
;
538 while (++MII
!= MBB
->end()) {
539 bool FoundUse
= false;
540 bool FoundKill
= false;
541 const TargetInstrDesc
&TID
= MII
->getDesc();
542 for (unsigned i
= 0, e
= MII
->getNumOperands(); i
!= e
; ++i
) {
543 MachineOperand
&MO
= MII
->getOperand(i
);
546 unsigned Reg
= MO
.getReg();
553 const TargetRegisterClass
*RC
= getInstrOperandRegClass(TRI
, TID
, i
);
554 if (RC
&& !RC
->contains(NewReg
))
560 } else if (TRI
->regsOverlap(Reg
, NewReg
) ||
561 TRI
->regsOverlap(Reg
, OldReg
))
565 for (unsigned i
= 0, e
= Uses
.size(); i
!= e
; ++i
)
566 Uses
[i
]->setReg(NewReg
);
573 /// UnfoldAndRewriteInstruction - Rewrite specified instruction by unfolding
574 /// folded memory references and replacing those references with register
575 /// references instead.
576 void StackSlotColoring::UnfoldAndRewriteInstruction(MachineInstr
*MI
, int OldFI
,
578 const TargetRegisterClass
*RC
,
579 MachineFunction
&MF
) {
580 MachineBasicBlock
*MBB
= MI
->getParent();
581 if (unsigned DstReg
= TII
->isLoadFromStackSlot(MI
, OldFI
)) {
582 if (PropagateForward(MI
, MBB
, DstReg
, Reg
)) {
583 DOUT
<< "Eliminated load: ";
587 TII
->copyRegToReg(*MBB
, MI
, DstReg
, Reg
, RC
, RC
);
590 } else if (unsigned SrcReg
= TII
->isStoreToStackSlot(MI
, OldFI
)) {
591 if (MI
->killsRegister(SrcReg
) && PropagateBackward(MI
, MBB
, SrcReg
, Reg
)) {
592 DOUT
<< "Eliminated store: ";
596 TII
->copyRegToReg(*MBB
, MI
, Reg
, SrcReg
, RC
, RC
);
600 SmallVector
<MachineInstr
*, 4> NewMIs
;
601 bool Success
= TII
->unfoldMemoryOperand(MF
, MI
, Reg
, false, false, NewMIs
);
602 assert(Success
&& "Failed to unfold!");
603 MBB
->insert(MI
, NewMIs
[0]);
609 /// RemoveDeadStores - Scan through a basic block and look for loads followed
610 /// by stores. If they're both using the same stack slot, then the store is
611 /// definitely dead. This could obviously be much more aggressive (consider
612 /// pairs with instructions between them), but such extensions might have a
613 /// considerable compile time impact.
614 bool StackSlotColoring::RemoveDeadStores(MachineBasicBlock
* MBB
) {
615 // FIXME: This could be much more aggressive, but we need to investigate
616 // the compile time impact of doing so.
617 bool changed
= false;
619 SmallVector
<MachineInstr
*, 4> toErase
;
621 for (MachineBasicBlock::iterator I
= MBB
->begin(), E
= MBB
->end();
623 if (DCELimit
!= -1 && (int)NumDead
>= DCELimit
)
626 MachineBasicBlock::iterator NextMI
= next(I
);
627 if (NextMI
== MBB
->end()) continue;
629 int FirstSS
, SecondSS
;
630 unsigned LoadReg
= 0;
631 unsigned StoreReg
= 0;
632 if (!(LoadReg
= TII
->isLoadFromStackSlot(I
, FirstSS
))) continue;
633 if (!(StoreReg
= TII
->isStoreToStackSlot(NextMI
, SecondSS
))) continue;
634 if (FirstSS
!= SecondSS
|| LoadReg
!= StoreReg
|| FirstSS
== -1) continue;
639 if (NextMI
->findRegisterUseOperandIdx(LoadReg
, true, 0) != -1) {
641 toErase
.push_back(I
);
644 toErase
.push_back(NextMI
);
648 for (SmallVector
<MachineInstr
*, 4>::iterator I
= toErase
.begin(),
649 E
= toErase
.end(); I
!= E
; ++I
)
650 (*I
)->eraseFromParent();
656 bool StackSlotColoring::runOnMachineFunction(MachineFunction
&MF
) {
657 DOUT
<< "********** Stack Slot Coloring **********\n";
659 MFI
= MF
.getFrameInfo();
660 MRI
= &MF
.getRegInfo();
661 TII
= MF
.getTarget().getInstrInfo();
662 TRI
= MF
.getTarget().getRegisterInfo();
663 LS
= &getAnalysis
<LiveStacks
>();
664 VRM
= &getAnalysis
<VirtRegMap
>();
665 loopInfo
= &getAnalysis
<MachineLoopInfo
>();
667 bool Changed
= false;
669 unsigned NumSlots
= LS
->getNumIntervals();
671 if (NumSlots
== 0 || !VRM
->HasUnusedRegisters())
676 // Gather spill slot references
677 ScanForSpillSlotRefs(MF
);
679 Changed
= ColorSlots(MF
);
683 for (unsigned i
= 0, e
= SSRefs
.size(); i
!= e
; ++i
)
686 OrigAlignments
.clear();
690 for (unsigned i
= 0, e
= Assignments
.size(); i
!= e
; ++i
)
691 Assignments
[i
].clear();
695 for (MachineFunction::iterator I
= MF
.begin(), E
= MF
.end(); I
!= E
; ++I
)
696 Changed
|= RemoveDeadStores(I
);