llvm.org GIT mirror llvm / 47dbf6c
Change the Spiller interface to take a LiveRangeEdit reference. This makes it possible to register delegates and get callbacks when the spiller edits live ranges. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@127389 91177308-0d34-0410-b5e6-96231b3b80d8 Jakob Stoklund Olesen 9 years ago
7 changed file(s) with 34 addition(s) and 50 deletion(s). Raw diff Collapse all Expand all
2323 #include "llvm/CodeGen/MachineRegisterInfo.h"
2424 #include "llvm/Target/TargetMachine.h"
2525 #include "llvm/Target/TargetInstrInfo.h"
26 #include "llvm/Support/CommandLine.h"
2726 #include "llvm/Support/Debug.h"
2827 #include "llvm/Support/raw_ostream.h"
2928
3029 using namespace llvm;
31
32 static cl::opt
33 VerifySpills("verify-spills", cl::desc("Verify after each spill/split"));
3430
3531 namespace {
3632 class InlineSpiller : public Spiller {
7268 tri_(*mf.getTarget().getRegisterInfo()),
7369 reserved_(tri_.getReservedRegs(mf_)) {}
7470
75 void spill(LiveInterval *li,
76 SmallVectorImpl &newIntervals,
77 const SmallVectorImpl *spillIs);
78
7971 void spill(LiveRangeEdit &);
8072
8173 private:
9587 Spiller *createInlineSpiller(MachineFunctionPass &pass,
9688 MachineFunction &mf,
9789 VirtRegMap &vrm) {
98 if (VerifySpills)
99 mf.verify(&pass, "When creating inline spiller");
10090 return new InlineSpiller(pass, mf, vrm);
10191 }
10292 }
329319 NewLI.addRange(LiveRange(Idx, StoreIdx, StoreVNI));
330320 }
331321
332 void InlineSpiller::spill(LiveInterval *li,
333 SmallVectorImpl &newIntervals,
334 const SmallVectorImpl *spillIs) {
335 LiveRangeEdit edit(*li, newIntervals, 0, spillIs);
336 spill(edit);
337 if (VerifySpills)
338 mf_.verify(&pass_, "After inline spill");
339 }
340
341322 void InlineSpiller::spill(LiveRangeEdit &edit) {
342323 edit_ = &edit;
343324 assert(!TargetRegisterInfo::isStackSlot(edit.getReg())
7575 /// rematerializing values because they are about to be removed.
7676 LiveRangeEdit(LiveInterval &parent,
7777 SmallVectorImpl &newRegs,
78 Delegate *delegate,
78 Delegate *delegate = 0,
7979 const SmallVectorImpl *uselessRegs = 0)
8080 : parent_(parent), newRegs_(newRegs),
8181 delegate_(delegate),
9393 unsigned size() const { return newRegs_.size()-firstNew_; }
9494 bool empty() const { return size() == 0; }
9595 LiveInterval *get(unsigned idx) const { return newRegs_[idx+firstNew_]; }
96
97 /// FIXME: Temporary accessors until we can get rid of
98 /// LiveIntervals::AddIntervalsForSpills
99 SmallVectorImpl *getNewVRegs() { return &newRegs_; }
100 const SmallVectorImpl *getUselessVRegs() {
101 return uselessRegs_;
102 }
96103
97104 /// create - Create a new register with the same class and stack slot as
98105 /// parent.
1313
1414 #define DEBUG_TYPE "regalloc"
1515 #include "LiveIntervalUnion.h"
16 #include "LiveRangeEdit.h"
1617 #include "RegAllocBase.h"
1718 #include "RenderMachineFunction.h"
1819 #include "Spiller.h"
343344 unassign(SpilledVReg, PhysReg);
344345
345346 // Spill the extracted interval.
346 spiller().spill(&SpilledVReg, SplitVRegs, &PendingSpills);
347 LiveRangeEdit LRE(SpilledVReg, SplitVRegs, 0, &PendingSpills);
348 spiller().spill(LRE);
347349 }
348350 // After extracting segments, the query's results are invalid. But keep the
349351 // contents valid until we're done accessing pendingSpills.
468470 }
469471 // No other spill candidates were found, so spill the current VirtReg.
470472 DEBUG(dbgs() << "spilling: " << VirtReg << '\n');
471 spiller().spill(&VirtReg, SplitVRegs, 0);
473 LiveRangeEdit LRE(VirtReg, SplitVRegs);
474 spiller().spill(LRE);
472475
473476 // The live virtual register requesting allocation was spilled, so tell
474477 // the caller not to allocate anything during this round.
12521252
12531253 // Finally spill VirtReg itself.
12541254 NamedRegionTimer T("Spiller", TimerGroupName, TimePassesIsEnabled);
1255 spiller().spill(&VirtReg, NewVRegs, 0);
1255 LiveRangeEdit LRE(VirtReg, NewVRegs, this);
1256 spiller().spill(LRE);
12561257
12571258 // The live virtual register requesting allocation was spilled, so tell
12581259 // the caller not to allocate anything during this round.
1212
1313 #define DEBUG_TYPE "regalloc"
1414 #include "LiveDebugVariables.h"
15 #include "LiveRangeEdit.h"
1516 #include "VirtRegMap.h"
1617 #include "VirtRegRewriter.h"
1718 #include "Spiller.h"
12291230 if (cur->weight != HUGE_VALF && cur->weight <= minWeight) {
12301231 DEBUG(dbgs() << "\t\t\tspilling(c): " << *cur << '\n');
12311232 SmallVector added;
1232 spiller_->spill(cur, added, 0);
1233 LiveRangeEdit LRE(*cur, added);
1234 spiller_->spill(LRE);
12331235
12341236 std::sort(added.begin(), added.end(), LISorter());
12351237 if (added.empty())
13051307 DEBUG(dbgs() << "\t\t\tspilling(a): " << *sli << '\n');
13061308 if (sli->beginIndex() < earliestStart)
13071309 earliestStart = sli->beginIndex();
1308 spiller_->spill(sli, added, &spillIs);
1310 LiveRangeEdit LRE(*sli, added, 0, &spillIs);
1311 spiller_->spill(LRE);
13091312 spilled.insert(sli->reg);
13101313 }
13111314
1010
1111 #include "Spiller.h"
1212 #include "VirtRegMap.h"
13 #include "LiveRangeEdit.h"
1314 #include "llvm/CodeGen/LiveIntervalAnalysis.h"
1415 #include "llvm/CodeGen/LiveStackAnalysis.h"
1516 #include "llvm/CodeGen/MachineFrameInfo.h"
179180 VirtRegMap &vrm)
180181 : SpillerBase(pass, mf, vrm) {}
181182
182 void spill(LiveInterval *li,
183 SmallVectorImpl &newIntervals,
184 const SmallVectorImpl*) {
183 void spill(LiveRangeEdit &LRE) {
185184 // Ignore spillIs - we don't use it.
186 trivialSpillEverywhere(li, newIntervals);
185 trivialSpillEverywhere(&LRE.getParent(), *LRE.getNewVRegs());
187186 }
188187 };
189188
209208 vrm(&vrm) {}
210209
211210 /// Falls back on LiveIntervals::addIntervalsForSpills.
212 void spill(LiveInterval *li,
213 SmallVectorImpl &newIntervals,
214 const SmallVectorImpl *spillIs) {
211 void spill(LiveRangeEdit &LRE) {
215212 std::vector added =
216 lis->addIntervalsForSpills(*li, spillIs, loopInfo, *vrm);
217 newIntervals.insert(newIntervals.end(), added.begin(), added.end());
213 lis->addIntervalsForSpills(LRE.getParent(), LRE.getUselessVRegs(),
214 loopInfo, *vrm);
215 LRE.getNewVRegs()->insert(LRE.getNewVRegs()->end(),
216 added.begin(), added.end());
218217
219218 // Update LiveStacks.
220 int SS = vrm->getStackSlot(li->reg);
219 int SS = vrm->getStackSlot(LRE.getReg());
221220 if (SS == VirtRegMap::NO_STACK_SLOT)
222221 return;
223 const TargetRegisterClass *RC = mf->getRegInfo().getRegClass(li->reg);
222 const TargetRegisterClass *RC = mf->getRegInfo().getRegClass(LRE.getReg());
224223 LiveInterval &SI = lss->getOrCreateInterval(SS, RC);
225224 if (!SI.hasAtLeastOneValue())
226225 SI.getNextValue(SlotIndex(), 0, lss->getVNInfoAllocator());
227 SI.MergeRangesInAsValue(*li, SI.getValNumInfo(0));
226 SI.MergeRangesInAsValue(LRE.getParent(), SI.getValNumInfo(0));
228227 }
229228 };
230229
1111
1212 namespace llvm {
1313
14 class LiveInterval;
14 class LiveRangeEdit;
1515 class MachineFunction;
1616 class MachineFunctionPass;
17 class SlotIndex;
18 template class SmallVectorImpl;
1917 class VirtRegMap;
2018
2119 /// Spiller interface.
2624 public:
2725 virtual ~Spiller() = 0;
2826
29 /// spill - Spill the given live interval. The method used will depend on
30 /// the Spiller implementation selected.
31 ///
32 /// @param li The live interval to be spilled.
33 /// @param spillIs A list of intervals that are about to be spilled,
34 /// and so cannot be used for remat etc.
35 /// @param newIntervals The newly created intervals will be appended here.
36 virtual void spill(LiveInterval *li,
37 SmallVectorImpl &newIntervals,
38 const SmallVectorImpl *spillIs) = 0;
27 /// spill - Spill the LRE.getParent() live interval.
28 virtual void spill(LiveRangeEdit &LRE) = 0;
3929
4030 };
4131