LLVM 23.0.0git
SplitKit.cpp
Go to the documentation of this file.
1//===- SplitKit.cpp - Toolkit for splitting live ranges -------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file contains the SplitAnalysis class as well as mutator functions for
10// live range splitting.
11//
12//===----------------------------------------------------------------------===//
13
14#include "SplitKit.h"
15#include "llvm/ADT/STLExtras.h"
16#include "llvm/ADT/Statistic.h"
30#include "llvm/Config/llvm-config.h"
31#include "llvm/IR/DebugLoc.h"
34#include "llvm/Support/Debug.h"
37#include <algorithm>
38#include <cassert>
39#include <iterator>
40#include <limits>
41#include <tuple>
42
43using namespace llvm;
44
45#define DEBUG_TYPE "regalloc"
46
47static cl::opt<bool>
48 EnableLoopIVHeuristic("enable-split-loopiv-heuristic",
49 cl::desc("Enable loop iv regalloc heuristic"),
50 cl::init(true));
51
52STATISTIC(NumFinished, "Number of splits finished");
53STATISTIC(NumSimple, "Number of splits that were simple");
54STATISTIC(NumCopies, "Number of copies inserted for splitting");
55STATISTIC(NumRemats, "Number of rematerialized defs for splitting");
56
57//===----------------------------------------------------------------------===//
58// Last Insert Point Analysis
59//===----------------------------------------------------------------------===//
60
62 unsigned BBNum)
63 : LIS(lis), LastInsertPoint(BBNum) {}
64
66InsertPointAnalysis::computeLastInsertPoint(const LiveInterval &CurLI,
67 const MachineBasicBlock &MBB) {
68 unsigned Num = MBB.getNumber();
69 std::pair<SlotIndex, SlotIndex> &LIP = LastInsertPoint[Num];
70 SlotIndex MBBEnd = LIS.getMBBEndIdx(&MBB);
71
73 bool EHPadSuccessor = false;
74 for (const MachineBasicBlock *SMBB : MBB.successors()) {
75 if (SMBB->isEHPad()) {
76 ExceptionalSuccessors.push_back(SMBB);
77 EHPadSuccessor = true;
78 } else if (SMBB->isInlineAsmBrIndirectTarget())
79 ExceptionalSuccessors.push_back(SMBB);
80 }
81
82 // Compute insert points on the first call. The pair is independent of the
83 // current live interval.
84 if (!LIP.first.isValid()) {
86 if (FirstTerm == MBB.end())
87 LIP.first = MBBEnd;
88 else
89 LIP.first = LIS.getInstructionIndex(*FirstTerm);
90
91 // If there is a landing pad or inlineasm_br successor, also find the
92 // instruction. If there is no such instruction, we don't need to do
93 // anything special. We assume there cannot be multiple instructions that
94 // are Calls with EHPad successors or INLINEASM_BR in a block. Further, we
95 // assume that if there are any, they will be after any other call
96 // instructions in the block.
97 if (ExceptionalSuccessors.empty())
98 return LIP.first;
99 for (const MachineInstr &MI : llvm::reverse(MBB)) {
100 if ((EHPadSuccessor && MI.isCall()) ||
101 MI.getOpcode() == TargetOpcode::INLINEASM_BR) {
102 LIP.second = LIS.getInstructionIndex(MI);
103 break;
104 }
105 }
106 }
107
108 // If CurLI is live into a landing pad successor, move the last insert point
109 // back to the call that may throw.
110 if (!LIP.second)
111 return LIP.first;
112
113 if (none_of(ExceptionalSuccessors, [&](const MachineBasicBlock *EHPad) {
114 return LIS.isLiveInToMBB(CurLI, EHPad);
115 }))
116 return LIP.first;
117
118 // Find the value leaving MBB.
119 const VNInfo *VNI = CurLI.getVNInfoBefore(MBBEnd);
120 if (!VNI)
121 return LIP.first;
122
123 // The def of statepoint instruction is a gc relocation and it should be alive
124 // in landing pad. So we cannot split interval after statepoint instruction.
125 if (SlotIndex::isSameInstr(VNI->def, LIP.second))
126 if (auto *I = LIS.getInstructionFromIndex(LIP.second))
127 if (I->getOpcode() == TargetOpcode::STATEPOINT)
128 return LIP.second;
129
130 // If the value leaving MBB was defined after the call in MBB, it can't
131 // really be live-in to the landing pad. This can happen if the landing pad
132 // has a PHI, and this register is undef on the exceptional edge.
133 if (!SlotIndex::isEarlierInstr(VNI->def, LIP.second) && VNI->def < MBBEnd)
134 return LIP.first;
135
136 // Value is properly live-in to the landing pad.
137 // Only allow inserts before the call.
138 return LIP.second;
139}
140
144 SlotIndex LIP = getLastInsertPoint(CurLI, MBB);
145 if (LIP == LIS.getMBBEndIdx(&MBB))
146 return MBB.end();
147 return LIS.getInstructionFromIndex(LIP);
148}
149
150//===----------------------------------------------------------------------===//
151// Split Analysis
152//===----------------------------------------------------------------------===//
153
155 const MachineLoopInfo &mli)
156 : MF(vrm.getMachineFunction()), VRM(vrm), LIS(lis), Loops(mli),
157 TII(*MF.getSubtarget().getInstrInfo()), IPA(lis, MF.getNumBlockIDs()) {}
158
160 UseSlots.clear();
161 UseBlocks.clear();
162 ThroughBlocks.clear();
163 CurLI = nullptr;
164}
165
166/// analyzeUses - Count instructions, basic blocks, and loops using CurLI.
167void SplitAnalysis::analyzeUses() {
168 assert(UseSlots.empty() && "Call clear first");
169
170 // First get all the defs from the interval values. This provides the correct
171 // slots for early clobbers.
172 for (const VNInfo *VNI : CurLI->valnos)
173 if (!VNI->isPHIDef() && !VNI->isUnused())
174 UseSlots.push_back(VNI->def);
175
176 // Get use slots form the use-def chain.
177 const MachineRegisterInfo &MRI = MF.getRegInfo();
178 for (MachineOperand &MO : MRI.use_nodbg_operands(CurLI->reg()))
179 if (!MO.isUndef())
180 UseSlots.push_back(LIS.getInstructionIndex(*MO.getParent()).getRegSlot());
181
182 array_pod_sort(UseSlots.begin(), UseSlots.end());
183
184 // Remove duplicates, keeping the smaller slot for each instruction.
185 // That is what we want for early clobbers.
186 UseSlots.erase(llvm::unique(UseSlots, SlotIndex::isSameInstr),
187 UseSlots.end());
188
189 // Compute per-live block info.
190 calcLiveBlockInfo();
191
192 LLVM_DEBUG(dbgs() << "Analyze counted " << UseSlots.size() << " instrs in "
193 << UseBlocks.size() << " blocks, through "
194 << NumThroughBlocks << " blocks.\n");
195}
196
197/// calcLiveBlockInfo - Fill the LiveBlocks array with information about blocks
198/// where CurLI is live.
199void SplitAnalysis::calcLiveBlockInfo() {
200 ThroughBlocks.resize(MF.getNumBlockIDs());
201 NumThroughBlocks = NumGapBlocks = 0;
202 if (CurLI->empty())
203 return;
204
205 LiveInterval::const_iterator LVI = CurLI->begin();
206 LiveInterval::const_iterator LVE = CurLI->end();
207
209 UseI = UseSlots.begin();
210 UseE = UseSlots.end();
211
212 // Loop over basic blocks where CurLI is live.
214 LIS.getMBBFromIndex(LVI->start)->getIterator();
215 while (true) {
216 BlockInfo BI;
217 BI.MBB = &*MFI;
218 SlotIndex Start, Stop;
219 std::tie(Start, Stop) = LIS.getSlotIndexes()->getMBBRange(BI.MBB);
220
221 // If the block contains no uses, the range must be live through. At one
222 // point, RegisterCoalescer could create dangling ranges that ended
223 // mid-block.
224 if (UseI == UseE || *UseI >= Stop) {
225 ++NumThroughBlocks;
226 ThroughBlocks.set(BI.MBB->getNumber());
227 // The range shouldn't end mid-block if there are no uses. This shouldn't
228 // happen.
229 assert(LVI->end >= Stop && "range ends mid block with no uses");
230 } else {
231 // This block has uses. Find the first and last uses in the block.
232 BI.FirstInstr = *UseI;
233 assert(BI.FirstInstr >= Start);
234 do ++UseI;
235 while (UseI != UseE && *UseI < Stop);
236 BI.LastInstr = UseI[-1];
237 assert(BI.LastInstr < Stop);
238
239 // LVI is the first live segment overlapping MBB.
240 BI.LiveIn = LVI->start <= Start;
241
242 // When not live in, the first use should be a def.
243 if (!BI.LiveIn) {
244 assert(LVI->start == LVI->valno->def && "Dangling Segment start");
245 assert(LVI->start == BI.FirstInstr && "First instr should be a def");
246 BI.FirstDef = BI.FirstInstr;
247 }
248
249 // Look for gaps in the live range.
250 BI.LiveOut = true;
251 while (LVI->end < Stop) {
252 SlotIndex LastStop = LVI->end;
253 if (++LVI == LVE || LVI->start >= Stop) {
254 BI.LiveOut = false;
255 BI.LastInstr = LastStop;
256 break;
257 }
258
259 if (LastStop < LVI->start) {
260 // There is a gap in the live range. Create duplicate entries for the
261 // live-in snippet and the live-out snippet.
262 ++NumGapBlocks;
263
264 // Push the Live-in part.
265 BI.LiveOut = false;
266 UseBlocks.push_back(BI);
267 UseBlocks.back().LastInstr = LastStop;
268
269 // Set up BI for the live-out part.
270 BI.LiveIn = false;
271 BI.LiveOut = true;
272 BI.FirstInstr = BI.FirstDef = LVI->start;
273 }
274
275 // A Segment that starts in the middle of the block must be a def.
276 assert(LVI->start == LVI->valno->def && "Dangling Segment start");
277 if (!BI.FirstDef)
278 BI.FirstDef = LVI->start;
279 }
280
281 UseBlocks.push_back(BI);
282
283 // LVI is now at LVE or LVI->end >= Stop.
284 if (LVI == LVE)
285 break;
286 }
287
288 // Live segment ends exactly at Stop. Move to the next segment.
289 if (LVI->end == Stop && ++LVI == LVE)
290 break;
291
292 // Pick the next basic block.
293 if (LVI->start < Stop)
294 ++MFI;
295 else
296 MFI = LIS.getMBBFromIndex(LVI->start)->getIterator();
297 }
298
299 LooksLikeLoopIV = EnableLoopIVHeuristic && UseBlocks.size() == 2 &&
300 any_of(UseBlocks, [this](BlockInfo &BI) {
301 MachineLoop *L = Loops.getLoopFor(BI.MBB);
302 return BI.LiveIn && BI.LiveOut && BI.FirstDef && L &&
303 L->isLoopLatch(BI.MBB);
304 });
305
306 assert(getNumLiveBlocks() == countLiveBlocks(CurLI) && "Bad block count");
307}
308
310 if (cli->empty())
311 return 0;
312 LiveInterval *li = const_cast<LiveInterval*>(cli);
313 LiveInterval::iterator LVI = li->begin();
314 LiveInterval::iterator LVE = li->end();
315 unsigned Count = 0;
316
317 // Loop over basic blocks where li is live.
319 LIS.getMBBFromIndex(LVI->start)->getIterator();
320 SlotIndex Stop = LIS.getMBBEndIdx(&*MFI);
321 while (true) {
322 ++Count;
323 LVI = li->advanceTo(LVI, Stop);
324 if (LVI == LVE)
325 return Count;
326 do {
327 ++MFI;
328 Stop = LIS.getMBBEndIdx(&*MFI);
329 } while (Stop <= LVI->start);
330 }
331}
332
334 Register OrigReg = VRM.getOriginal(CurLI->reg());
335 const LiveInterval &Orig = LIS.getInterval(OrigReg);
336 assert(!Orig.empty() && "Splitting empty interval?");
338
339 // Range containing Idx should begin at Idx.
340 if (I != Orig.end() && I->start <= Idx)
341 return I->start == Idx;
342
343 // Range does not contain Idx, previous must end at Idx.
344 return I != Orig.begin() && (--I)->end == Idx;
345}
346
348 clear();
349 CurLI = li;
350 analyzeUses();
351}
352
353//===----------------------------------------------------------------------===//
354// Split Editor
355//===----------------------------------------------------------------------===//
356
357/// Create a new SplitEditor for editing the LiveInterval analyzed by SA.
361 : SA(SA), LIS(LIS), VRM(VRM), MRI(VRM.getMachineFunction().getRegInfo()),
362 MDT(MDT), TII(*VRM.getMachineFunction().getSubtarget().getInstrInfo()),
363 TRI(*VRM.getMachineFunction().getSubtarget().getRegisterInfo()),
364 MBFI(MBFI), VRAI(VRAI), RegAssign(Allocator) {}
365
367 Edit = &LRE;
368 SpillMode = SM;
369 OpenIdx = 0;
370 RegAssign.clear();
371 Values.clear();
372
373 // Reset the LiveIntervalCalc instances needed for this spill mode.
374 LICalc[0].reset(&VRM.getMachineFunction(), LIS.getSlotIndexes(), &MDT,
375 &LIS.getVNInfoAllocator());
376 if (SpillMode)
377 LICalc[1].reset(&VRM.getMachineFunction(), LIS.getSlotIndexes(), &MDT,
378 &LIS.getVNInfoAllocator());
379}
380
381#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
383 if (RegAssign.empty()) {
384 dbgs() << " empty\n";
385 return;
386 }
387
388 for (RegAssignMap::const_iterator I = RegAssign.begin(); I.valid(); ++I)
389 dbgs() << " [" << I.start() << ';' << I.stop() << "):" << I.value();
390 dbgs() << '\n';
391}
392#endif
393
394/// Find a subrange corresponding to the exact lane mask @p LM in the live
395/// interval @p LI. The interval @p LI is assumed to contain such a subrange.
396/// This function is used to find corresponding subranges between the
397/// original interval and the new intervals.
398template <typename T> auto &getSubrangeImpl(LaneBitmask LM, T &LI) {
399 for (auto &S : LI.subranges())
400 if (S.LaneMask == LM)
401 return S;
402 llvm_unreachable("SubRange for this mask not found");
403}
404
409
411 const LiveInterval &LI) {
412 return getSubrangeImpl(LM, LI);
413}
414
415/// Find a subrange corresponding to the lane mask @p LM, or a superset of it,
416/// in the live interval @p LI.
417/// \return nullptr is such subrange is not found.
419 const LiveInterval &LI) {
420 for (const LiveInterval::SubRange &S : LI.subranges())
421 if ((S.LaneMask & LM) == LM)
422 return &S;
423 return nullptr;
424}
425
427 const MachineRegisterInfo &MRI) {
428 if (!LI.hasSubRanges())
429 return MRI.getMaxLaneMaskForVReg(LI.reg());
430
431 LaneBitmask LaneMask;
432 for (const LiveInterval::SubRange &S : LI.subranges())
433 if (S.liveAt(Idx))
434 LaneMask |= S.LaneMask;
435 return LaneMask;
436}
437
438void SplitEditor::addDeadDef(LiveInterval &LI, VNInfo *VNI, bool Original) {
439 if (!LI.hasSubRanges()) {
440 LI.createDeadDef(VNI);
441 return;
442 }
443
444 SlotIndex Def = VNI->def;
445 if (Original) {
446 // If we are transferring a def from the original interval, make sure
447 // to only update the subranges for which the original subranges had
448 // a def at this location.
449 for (LiveInterval::SubRange &S : LI.subranges()) {
450 const LiveInterval::SubRange *PS =
451 findSubRangeForMask(S.LaneMask, Edit->getParent());
452 if (PS == nullptr)
453 continue;
454 VNInfo *PV = PS->getVNInfoAt(Def);
455 if (PV != nullptr && PV->def == Def)
456 S.createDeadDef(Def, LIS.getVNInfoAllocator());
457 }
458 } else {
459 // This is a new def: either from rematerialization, or from an inserted
460 // copy. Since rematerialization can regenerate a definition of a sub-
461 // register, we need to check which subranges need to be updated.
462 const MachineInstr *DefMI = LIS.getInstructionFromIndex(Def);
463 assert(DefMI != nullptr);
464 LaneBitmask LM;
465 for (const MachineOperand &DefOp : DefMI->defs()) {
466 Register R = DefOp.getReg();
467 if (R != LI.reg())
468 continue;
469 if (unsigned SR = DefOp.getSubReg())
470 LM |= TRI.getSubRegIndexLaneMask(SR);
471 else {
472 LM = MRI.getMaxLaneMaskForVReg(R);
473 break;
474 }
475 }
476 for (LiveInterval::SubRange &S : LI.subranges())
477 if ((S.LaneMask & LM).any())
478 S.createDeadDef(Def, LIS.getVNInfoAllocator());
479 }
480}
481
482VNInfo *SplitEditor::defValue(unsigned RegIdx,
483 const VNInfo *ParentVNI,
484 SlotIndex Idx,
485 bool Original) {
486 assert(ParentVNI && "Mapping NULL value");
487 assert(Idx.isValid() && "Invalid SlotIndex");
488 assert(Edit->getParent().getVNInfoAt(Idx) == ParentVNI && "Bad Parent VNI");
489 LiveInterval *LI = &LIS.getInterval(Edit->get(RegIdx));
490
491 // Create a new value.
492 VNInfo *VNI = LI->getNextValue(Idx, LIS.getVNInfoAllocator());
493
494 bool Force = LI->hasSubRanges();
495 ValueForcePair FP(Force ? nullptr : VNI, Force);
496 // Use insert for lookup, so we can add missing values with a second lookup.
497 std::pair<ValueMap::iterator, bool> InsP =
498 Values.insert(std::make_pair(std::make_pair(RegIdx, ParentVNI->id), FP));
499
500 // This was the first time (RegIdx, ParentVNI) was mapped, and it is not
501 // forced. Keep it as a simple def without any liveness.
502 if (!Force && InsP.second)
503 return VNI;
504
505 // If the previous value was a simple mapping, add liveness for it now.
506 if (VNInfo *OldVNI = InsP.first->second.getPointer()) {
507 addDeadDef(*LI, OldVNI, Original);
508
509 // No longer a simple mapping. Switch to a complex mapping. If the
510 // interval has subranges, make it a forced mapping.
511 InsP.first->second = ValueForcePair(nullptr, Force);
512 }
513
514 // This is a complex mapping, add liveness for VNI
515 addDeadDef(*LI, VNI, Original);
516 return VNI;
517}
518
519void SplitEditor::forceRecompute(unsigned RegIdx, const VNInfo &ParentVNI) {
520 ValueForcePair &VFP = Values[std::make_pair(RegIdx, ParentVNI.id)];
521 VNInfo *VNI = VFP.getPointer();
522
523 // ParentVNI was either unmapped or already complex mapped. Either way, just
524 // set the force bit.
525 if (!VNI) {
526 VFP.setInt(true);
527 return;
528 }
529
530 // This was previously a single mapping. Make sure the old def is represented
531 // by a trivial live range.
532 addDeadDef(LIS.getInterval(Edit->get(RegIdx)), VNI, false);
533
534 // Mark as complex mapped, forced.
535 VFP = ValueForcePair(nullptr, true);
536}
537
538SlotIndex SplitEditor::buildSingleSubRegCopy(
539 Register FromReg, Register ToReg, MachineBasicBlock &MBB,
540 MachineBasicBlock::iterator InsertBefore, unsigned SubIdx,
541 LiveInterval &DestLI, bool Late, SlotIndex Def, const MCInstrDesc &Desc) {
542 bool FirstCopy = !Def.isValid();
543 MachineInstr *CopyMI =
544 BuildMI(MBB, InsertBefore, DebugLoc(), Desc)
545 .addReg(ToReg,
547 getInternalReadRegState(!FirstCopy),
548 SubIdx)
549 .addReg(FromReg, {}, SubIdx);
550
552 SlotIndexes &Indexes = *LIS.getSlotIndexes();
553 if (FirstCopy) {
554 Def = Indexes.insertMachineInstrInMaps(*CopyMI, Late).getRegSlot();
555 } else {
556 CopyMI->bundleWithPred();
557 }
558 return Def;
559}
560
561SlotIndex SplitEditor::buildCopy(Register FromReg, Register ToReg,
563 MachineBasicBlock::iterator InsertBefore, bool Late, unsigned RegIdx) {
564 const MCInstrDesc &Desc =
565 TII.get(TII.getLiveRangeSplitOpcode(FromReg, *MBB.getParent()));
566 SlotIndexes &Indexes = *LIS.getSlotIndexes();
567 if (LaneMask.all() || LaneMask == MRI.getMaxLaneMaskForVReg(FromReg)) {
568 // The full vreg is copied.
569 MachineInstr *CopyMI =
570 BuildMI(MBB, InsertBefore, DebugLoc(), Desc, ToReg).addReg(FromReg);
572 return Indexes.insertMachineInstrInMaps(*CopyMI, Late).getRegSlot();
573 }
574
575 // Only a subset of lanes needs to be copied. The following is a simple
576 // heuristic to construct a sequence of COPYs. We could add a target
577 // specific callback if this turns out to be suboptimal.
578 LiveInterval &DestLI = LIS.getInterval(Edit->get(RegIdx));
579
580 // First pass: Try to find a perfectly matching subregister index. If none
581 // exists find the one covering the most lanemask bits.
582 const TargetRegisterClass *RC = MRI.getRegClass(FromReg);
583 assert(RC == MRI.getRegClass(ToReg) && "Should have same reg class");
584
585 SmallVector<unsigned, 8> SubIndexes;
586
587 // Abort if we cannot possibly implement the COPY with the given indexes.
588 if (!TRI.getCoveringSubRegIndexes(RC, LaneMask, SubIndexes))
589 report_fatal_error("Impossible to implement partial COPY");
590
591 SlotIndex Def;
592 for (unsigned BestIdx : SubIndexes) {
593 Def = buildSingleSubRegCopy(FromReg, ToReg, MBB, InsertBefore, BestIdx,
594 DestLI, Late, Def, Desc);
595 }
596
597 BumpPtrAllocator &Allocator = LIS.getVNInfoAllocator();
598 DestLI.refineSubRanges(
599 Allocator, LaneMask,
600 [Def, &Allocator](LiveInterval::SubRange &SR) {
601 SR.createDeadDef(Def, Allocator);
602 },
603 Indexes, TRI);
604
605 return Def;
606}
607
608bool SplitEditor::rematWillIncreaseRestriction(const MachineInstr *DefMI,
610 SlotIndex UseIdx) const {
611 const MachineInstr *UseMI = LIS.getInstructionFromIndex(UseIdx);
612 if (!UseMI)
613 return false;
614
615 // Currently code assumes rematerialization only happens for a def at 0.
616 const unsigned DefOperandIdx = 0;
617 // We want to compute the static register class constraint for the instruction
618 // def. If it is a smaller subclass than getLargestLegalSuperClass at the use
619 // site, then rematerializing it will increase the constraints.
620 const TargetRegisterClass *DefConstrainRC =
621 DefMI->getRegClassConstraint(DefOperandIdx, &TII, &TRI);
622 if (!DefConstrainRC)
623 return false;
624
625 const TargetRegisterClass *RC = MRI.getRegClass(Edit->getReg());
626
627 // We want to find the register class that can be inflated to after the split
628 // occurs in recomputeRegClass
629 const TargetRegisterClass *SuperRC =
630 TRI.getLargestLegalSuperClass(RC, *MBB.getParent());
631
632 Register DefReg = DefMI->getOperand(DefOperandIdx).getReg();
633 const TargetRegisterClass *UseConstrainRC =
634 UseMI->getRegClassConstraintEffectForVReg(DefReg, SuperRC, &TII, &TRI,
635 /*ExploreBundle=*/true);
636 return UseConstrainRC->hasSubClass(DefConstrainRC);
637}
638
639VNInfo *SplitEditor::defFromParent(unsigned RegIdx, const VNInfo *ParentVNI,
642 LiveInterval *LI = &LIS.getInterval(Edit->get(RegIdx));
643
644 // We may be trying to avoid interference that ends at a deleted instruction,
645 // so always begin RegIdx 0 early and all others late.
646 bool Late = RegIdx != 0;
647
648 // Attempt cheap-as-a-copy rematerialization.
649 Register Original = VRM.getOriginal(Edit->get(RegIdx));
650 LiveInterval &OrigLI = LIS.getInterval(Original);
651 VNInfo *OrigVNI = OrigLI.getVNInfoAt(UseIdx);
652
653 Register Reg = LI->reg();
654 LaneBitmask LaneMask = getLiveLaneMaskAt(Edit->getParent(), UseIdx, MRI);
655 if (OrigVNI && LaneMask.any()) {
656 LiveRangeEdit::Remat RM(ParentVNI);
657 RM.OrigMI = LIS.getInstructionFromIndex(OrigVNI->def);
658 if (RM.OrigMI && TII.isAsCheapAsAMove(*RM.OrigMI) &&
659 Edit->canRematerializeAt(RM, UseIdx)) {
660 if (!rematWillIncreaseRestriction(RM.OrigMI, MBB, UseIdx)) {
661 SlotIndex Def = Edit->rematerializeAt(MBB, I, Reg, RM, TRI, Late, 0,
662 nullptr, LaneMask);
663 ++NumRemats;
664 // Define the value in Reg.
665 return defValue(RegIdx, ParentVNI, Def, false);
666 }
668 dbgs() << "skipping rematerialize of " << printReg(Reg) << " at "
669 << UseIdx
670 << " since it will increase register class restrictions\n");
671 }
672 }
673
674 SlotIndex Def;
675 if (LaneMask.none()) {
676 const MCInstrDesc &Desc = TII.get(TargetOpcode::IMPLICIT_DEF);
677 MachineInstr *ImplicitDef = BuildMI(MBB, I, DebugLoc(), Desc, Reg);
678 SlotIndexes &Indexes = *LIS.getSlotIndexes();
679 Def = Indexes.insertMachineInstrInMaps(*ImplicitDef, Late).getRegSlot();
680 } else {
681 ++NumCopies;
682 Def = buildCopy(Edit->getReg(), Reg, LaneMask, MBB, I, Late, RegIdx);
683 }
684
685 // Define the value in Reg.
686 return defValue(RegIdx, ParentVNI, Def, false);
687}
688
689/// Create a new virtual register and live interval.
691 // Create the complement as index 0.
692 if (Edit->empty())
693 Edit->createEmptyInterval();
694
695 // Create the open interval.
696 OpenIdx = Edit->size();
697 Edit->createEmptyInterval();
698 return OpenIdx;
699}
700
701void SplitEditor::selectIntv(unsigned Idx) {
702 assert(Idx != 0 && "Cannot select the complement interval");
703 assert(Idx < Edit->size() && "Can only select previously opened interval");
704 LLVM_DEBUG(dbgs() << " selectIntv " << OpenIdx << " -> " << Idx << '\n');
705 OpenIdx = Idx;
706}
707
709 assert(OpenIdx && "openIntv not called before enterIntvBefore");
710 LLVM_DEBUG(dbgs() << " enterIntvBefore " << Idx);
711 Idx = Idx.getBaseIndex();
712 VNInfo *ParentVNI = Edit->getParent().getVNInfoAt(Idx);
713 if (!ParentVNI) {
714 LLVM_DEBUG(dbgs() << ": not live\n");
715 return Idx;
716 }
717 LLVM_DEBUG(dbgs() << ": valno " << ParentVNI->id << '\n');
718 MachineInstr *MI = LIS.getInstructionFromIndex(Idx);
719 assert(MI && "enterIntvBefore called with invalid index");
720
721 VNInfo *VNI = defFromParent(OpenIdx, ParentVNI, Idx, *MI->getParent(), MI);
722 return VNI->def;
723}
724
726 assert(OpenIdx && "openIntv not called before enterIntvAfter");
727 LLVM_DEBUG(dbgs() << " enterIntvAfter " << Idx);
728 Idx = Idx.getBoundaryIndex();
729 VNInfo *ParentVNI = Edit->getParent().getVNInfoAt(Idx);
730 if (!ParentVNI) {
731 LLVM_DEBUG(dbgs() << ": not live\n");
732 return Idx;
733 }
734 LLVM_DEBUG(dbgs() << ": valno " << ParentVNI->id << '\n');
735 MachineInstr *MI = LIS.getInstructionFromIndex(Idx);
736 assert(MI && "enterIntvAfter called with invalid index");
737
738 VNInfo *VNI = defFromParent(OpenIdx, ParentVNI, Idx, *MI->getParent(),
739 std::next(MachineBasicBlock::iterator(MI)));
740 return VNI->def;
741}
742
744 assert(OpenIdx && "openIntv not called before enterIntvAtEnd");
745 SlotIndex End = LIS.getMBBEndIdx(&MBB);
746 SlotIndex Last = End.getPrevSlot();
747 LLVM_DEBUG(dbgs() << " enterIntvAtEnd " << printMBBReference(MBB) << ", "
748 << Last);
749 VNInfo *ParentVNI = Edit->getParent().getVNInfoAt(Last);
750 if (!ParentVNI) {
751 LLVM_DEBUG(dbgs() << ": not live\n");
752 return End;
753 }
754 SlotIndex LSP = SA.getLastSplitPoint(&MBB);
755 if (LSP < Last) {
756 // It could be that the use after LSP is a def, and thus the ParentVNI
757 // just selected starts at that def. For this case to exist, the def
758 // must be part of a tied def/use pair (as otherwise we'd have split
759 // distinct live ranges into individual live intervals), and thus we
760 // can insert the def into the VNI of the use and the tied def/use
761 // pair can live in the resulting interval.
762 Last = LSP;
763 ParentVNI = Edit->getParent().getVNInfoAt(Last);
764 if (!ParentVNI) {
765 // undef use --> undef tied def
766 LLVM_DEBUG(dbgs() << ": tied use not live\n");
767 return End;
768 }
769 }
770
771 LLVM_DEBUG(dbgs() << ": valno " << ParentVNI->id);
772 VNInfo *VNI = defFromParent(OpenIdx, ParentVNI, Last, MBB,
773 SA.getLastSplitPointIter(&MBB));
774 RegAssign.insert(VNI->def, End, OpenIdx);
775 LLVM_DEBUG(dump());
776 return VNI->def;
777}
778
779/// useIntv - indicate that all instructions in MBB should use OpenLI.
781 useIntv(LIS.getMBBStartIdx(&MBB), LIS.getMBBEndIdx(&MBB));
782}
783
785 assert(OpenIdx && "openIntv not called before useIntv");
786 LLVM_DEBUG(dbgs() << " useIntv [" << Start << ';' << End << "):");
787 RegAssign.insert(Start, End, OpenIdx);
788 LLVM_DEBUG(dump());
789}
790
792 assert(OpenIdx && "openIntv not called before leaveIntvAfter");
793 LLVM_DEBUG(dbgs() << " leaveIntvAfter " << Idx);
794
795 // The interval must be live beyond the instruction at Idx.
796 SlotIndex Boundary = Idx.getBoundaryIndex();
797 VNInfo *ParentVNI = Edit->getParent().getVNInfoAt(Boundary);
798 if (!ParentVNI) {
799 LLVM_DEBUG(dbgs() << ": not live\n");
800 return Boundary.getNextSlot();
801 }
802 LLVM_DEBUG(dbgs() << ": valno " << ParentVNI->id << '\n');
803 MachineInstr *MI = LIS.getInstructionFromIndex(Boundary);
804 assert(MI && "No instruction at index");
805
806 // In spill mode, make live ranges as short as possible by inserting the copy
807 // before MI. This is only possible if that instruction doesn't redefine the
808 // value. The inserted COPY is not a kill, and we don't need to recompute
809 // the source live range. The spiller also won't try to hoist this copy.
810 if (SpillMode && !SlotIndex::isSameInstr(ParentVNI->def, Idx) &&
811 MI->readsVirtualRegister(Edit->getReg())) {
812 forceRecompute(0, *ParentVNI);
813 defFromParent(0, ParentVNI, Idx, *MI->getParent(), MI);
814 return Idx;
815 }
816
817 VNInfo *VNI = defFromParent(0, ParentVNI, Boundary, *MI->getParent(),
818 std::next(MachineBasicBlock::iterator(MI)));
819 return VNI->def;
820}
821
823 assert(OpenIdx && "openIntv not called before leaveIntvBefore");
824 LLVM_DEBUG(dbgs() << " leaveIntvBefore " << Idx);
825
826 // The interval must be live into the instruction at Idx.
827 Idx = Idx.getBaseIndex();
828 VNInfo *ParentVNI = Edit->getParent().getVNInfoAt(Idx);
829 if (!ParentVNI) {
830 LLVM_DEBUG(dbgs() << ": not live\n");
831 return Idx.getNextSlot();
832 }
833 LLVM_DEBUG(dbgs() << ": valno " << ParentVNI->id << '\n');
834
835 MachineInstr *MI = LIS.getInstructionFromIndex(Idx);
836 assert(MI && "No instruction at index");
837 VNInfo *VNI = defFromParent(0, ParentVNI, Idx, *MI->getParent(), MI);
838 return VNI->def;
839}
840
842 assert(OpenIdx && "openIntv not called before leaveIntvAtTop");
843 SlotIndex Start = LIS.getMBBStartIdx(&MBB);
844 LLVM_DEBUG(dbgs() << " leaveIntvAtTop " << printMBBReference(MBB) << ", "
845 << Start);
846
847 VNInfo *ParentVNI = Edit->getParent().getVNInfoAt(Start);
848 if (!ParentVNI) {
849 LLVM_DEBUG(dbgs() << ": not live\n");
850 return Start;
851 }
852
853 unsigned RegIdx = 0;
854 Register Reg = LIS.getInterval(Edit->get(RegIdx)).reg();
855 VNInfo *VNI = defFromParent(RegIdx, ParentVNI, Start, MBB,
856 MBB.SkipPHIsLabelsAndDebug(MBB.begin(), Reg));
857 RegAssign.insert(Start, VNI->def, OpenIdx);
858 LLVM_DEBUG(dump());
859 return VNI->def;
860}
861
863 return any_of(MI.defs(), [Reg](const MachineOperand &MO) {
864 return MO.isReg() && MO.isTied() && MO.getReg() == Reg;
865 });
866}
867
869 assert(OpenIdx && "openIntv not called before overlapIntv");
870 const VNInfo *ParentVNI = Edit->getParent().getVNInfoAt(Start);
871 assert(ParentVNI == Edit->getParent().getVNInfoBefore(End) &&
872 "Parent changes value in extended range");
873 assert(LIS.getMBBFromIndex(Start) == LIS.getMBBFromIndex(End) &&
874 "Range cannot span basic blocks");
875
876 // The complement interval will be extended as needed by LICalc.extend().
877 if (ParentVNI)
878 forceRecompute(0, *ParentVNI);
879
880 // If the last use is tied to a def, we can't mark it as live for the
881 // interval which includes only the use. That would cause the tied pair
882 // to end up in two different intervals.
883 if (auto *MI = LIS.getInstructionFromIndex(End))
884 if (hasTiedUseOf(*MI, Edit->getReg())) {
885 LLVM_DEBUG(dbgs() << "skip overlap due to tied def at end\n");
886 return;
887 }
888
889 LLVM_DEBUG(dbgs() << " overlapIntv [" << Start << ';' << End << "):");
890 RegAssign.insert(Start, End, OpenIdx);
891 LLVM_DEBUG(dump());
892}
893
894//===----------------------------------------------------------------------===//
895// Spill modes
896//===----------------------------------------------------------------------===//
897
898void SplitEditor::removeBackCopies(SmallVectorImpl<VNInfo*> &Copies) {
899 LiveInterval *LI = &LIS.getInterval(Edit->get(0));
900 LLVM_DEBUG(dbgs() << "Removing " << Copies.size() << " back-copies.\n");
902 AssignI.setMap(RegAssign);
903
904 for (const VNInfo *C : Copies) {
905 SlotIndex Def = C->def;
907 assert(MI && "No instruction for back-copy");
908
909 MachineBasicBlock *MBB = MI->getParent();
911 bool AtBegin;
912 do AtBegin = MBBI == MBB->begin();
913 while (!AtBegin && (--MBBI)->isDebugOrPseudoInstr());
914
915 LLVM_DEBUG(dbgs() << "Removing " << Def << '\t' << *MI);
916 LIS.removeVRegDefAt(*LI, Def);
918 MI->eraseFromParent();
919
920 // Adjust RegAssign if a register assignment is killed at Def. We want to
921 // avoid calculating the live range of the source register if possible.
922 AssignI.find(Def.getPrevSlot());
923 if (!AssignI.valid() || AssignI.start() >= Def)
924 continue;
925 // If MI doesn't kill the assigned register, just leave it.
926 if (AssignI.stop() != Def)
927 continue;
928 unsigned RegIdx = AssignI.value();
929 // We could hoist back-copy right after another back-copy. As a result
930 // MMBI points to copy instruction which is actually dead now.
931 // We cannot set its stop to MBBI which will be the same as start and
932 // interval does not support that.
934 AtBegin ? SlotIndex() : LIS.getInstructionIndex(*MBBI).getRegSlot();
935 if (AtBegin || !MBBI->readsVirtualRegister(Edit->getReg()) ||
936 Kill <= AssignI.start()) {
937 LLVM_DEBUG(dbgs() << " cannot find simple kill of RegIdx " << RegIdx
938 << '\n');
939 forceRecompute(RegIdx, *Edit->getParent().getVNInfoAt(Def));
940 } else {
941 LLVM_DEBUG(dbgs() << " move kill to " << Kill << '\t' << *MBBI);
942 AssignI.setStop(Kill);
943 }
944 }
945}
946
948SplitEditor::findShallowDominator(MachineBasicBlock *MBB,
949 MachineBasicBlock *DefMBB) {
950 if (MBB == DefMBB)
951 return MBB;
952 assert(MDT.dominates(DefMBB, MBB) && "MBB must be dominated by the def.");
953
954 const MachineLoopInfo &Loops = SA.Loops;
955 const MachineLoop *DefLoop = Loops.getLoopFor(DefMBB);
956 MachineDomTreeNode *DefDomNode = MDT[DefMBB];
957
958 // Best candidate so far.
959 MachineBasicBlock *BestMBB = MBB;
960 unsigned BestDepth = std::numeric_limits<unsigned>::max();
961
962 while (true) {
963 const MachineLoop *Loop = Loops.getLoopFor(MBB);
964
965 // MBB isn't in a loop, it doesn't get any better. All dominators have a
966 // higher frequency by definition.
967 if (!Loop) {
968 LLVM_DEBUG(dbgs() << "Def in " << printMBBReference(*DefMBB)
969 << " dominates " << printMBBReference(*MBB)
970 << " at depth 0\n");
971 return MBB;
972 }
973
974 // We'll never be able to exit the DefLoop.
975 if (Loop == DefLoop) {
976 LLVM_DEBUG(dbgs() << "Def in " << printMBBReference(*DefMBB)
977 << " dominates " << printMBBReference(*MBB)
978 << " in the same loop\n");
979 return MBB;
980 }
981
982 // Least busy dominator seen so far.
983 unsigned Depth = Loop->getLoopDepth();
984 if (Depth < BestDepth) {
985 BestMBB = MBB;
986 BestDepth = Depth;
987 LLVM_DEBUG(dbgs() << "Def in " << printMBBReference(*DefMBB)
988 << " dominates " << printMBBReference(*MBB)
989 << " at depth " << Depth << '\n');
990 }
991
992 // Leave loop by going to the immediate dominator of the loop header.
993 // This is a bigger stride than simply walking up the dominator tree.
994 MachineDomTreeNode *IDom = MDT[Loop->getHeader()]->getIDom();
995
996 // Too far up the dominator tree?
997 if (!IDom || !MDT.dominates(DefDomNode, IDom))
998 return BestMBB;
999
1000 MBB = IDom->getBlock();
1001 }
1002}
1003
1004void SplitEditor::computeRedundantBackCopies(
1005 DenseSet<unsigned> &NotToHoistSet, SmallVectorImpl<VNInfo *> &BackCopies) {
1006 LiveInterval *LI = &LIS.getInterval(Edit->get(0));
1007 const LiveInterval *Parent = &Edit->getParent();
1009 SmallPtrSet<VNInfo *, 8> DominatedVNIs;
1010
1011 // Aggregate VNIs having the same value as ParentVNI.
1012 for (VNInfo *VNI : LI->valnos) {
1013 if (VNI->isUnused())
1014 continue;
1015 VNInfo *ParentVNI = Edit->getParent().getVNInfoAt(VNI->def);
1016 EqualVNs[ParentVNI->id].insert(VNI);
1017 }
1018
1019 // For VNI aggregation of each ParentVNI, collect dominated, i.e.,
1020 // redundant VNIs to BackCopies.
1021 for (unsigned i = 0, e = Parent->getNumValNums(); i != e; ++i) {
1022 const VNInfo *ParentVNI = Parent->getValNumInfo(i);
1023 if (!NotToHoistSet.count(ParentVNI->id))
1024 continue;
1025 SmallPtrSetIterator<VNInfo *> It1 = EqualVNs[ParentVNI->id].begin();
1026 SmallPtrSetIterator<VNInfo *> It2 = It1;
1027 for (; It1 != EqualVNs[ParentVNI->id].end(); ++It1) {
1028 It2 = It1;
1029 for (++It2; It2 != EqualVNs[ParentVNI->id].end(); ++It2) {
1030 if (DominatedVNIs.count(*It1) || DominatedVNIs.count(*It2))
1031 continue;
1032
1033 MachineBasicBlock *MBB1 = LIS.getMBBFromIndex((*It1)->def);
1034 MachineBasicBlock *MBB2 = LIS.getMBBFromIndex((*It2)->def);
1035 if (MBB1 == MBB2) {
1036 DominatedVNIs.insert((*It1)->def < (*It2)->def ? (*It2) : (*It1));
1037 } else if (MDT.dominates(MBB1, MBB2)) {
1038 DominatedVNIs.insert(*It2);
1039 } else if (MDT.dominates(MBB2, MBB1)) {
1040 DominatedVNIs.insert(*It1);
1041 }
1042 }
1043 }
1044 if (!DominatedVNIs.empty()) {
1045 forceRecompute(0, *ParentVNI);
1046 append_range(BackCopies, DominatedVNIs);
1047 DominatedVNIs.clear();
1048 }
1049 }
1050}
1051
1052/// For SM_Size mode, find a common dominator for all the back-copies for
1053/// the same ParentVNI and hoist the backcopies to the dominator BB.
1054/// For SM_Speed mode, if the common dominator is hot and it is not beneficial
1055/// to do the hoisting, simply remove the dominated backcopies for the same
1056/// ParentVNI.
1057void SplitEditor::hoistCopies() {
1058 // Get the complement interval, always RegIdx 0.
1059 LiveInterval *LI = &LIS.getInterval(Edit->get(0));
1060 const LiveInterval *Parent = &Edit->getParent();
1061
1062 // Track the nearest common dominator for all back-copies for each ParentVNI,
1063 // indexed by ParentVNI->id.
1064 using DomPair = std::pair<MachineBasicBlock *, SlotIndex>;
1065 SmallVector<DomPair, 8> NearestDom(Parent->getNumValNums());
1066 // The total cost of all the back-copies for each ParentVNI.
1068 // The ParentVNI->id set for which hoisting back-copies are not beneficial
1069 // for Speed.
1070 DenseSet<unsigned> NotToHoistSet;
1071
1072 // Find the nearest common dominator for parent values with multiple
1073 // back-copies. If a single back-copy dominates, put it in DomPair.second.
1074 for (VNInfo *VNI : LI->valnos) {
1075 if (VNI->isUnused())
1076 continue;
1077 VNInfo *ParentVNI = Edit->getParent().getVNInfoAt(VNI->def);
1078 assert(ParentVNI && "Parent not live at complement def");
1079
1080 // Don't hoist remats. The complement is probably going to disappear
1081 // completely anyway.
1082 if (Edit->didRematerialize(ParentVNI))
1083 continue;
1084
1085 MachineBasicBlock *ValMBB = LIS.getMBBFromIndex(VNI->def);
1086
1087 DomPair &Dom = NearestDom[ParentVNI->id];
1088
1089 // Keep directly defined parent values. This is either a PHI or an
1090 // instruction in the complement range. All other copies of ParentVNI
1091 // should be eliminated.
1092 if (VNI->def == ParentVNI->def) {
1093 LLVM_DEBUG(dbgs() << "Direct complement def at " << VNI->def << '\n');
1094 Dom = DomPair(ValMBB, VNI->def);
1095 continue;
1096 }
1097 // Skip the singly mapped values. There is nothing to gain from hoisting a
1098 // single back-copy.
1099 if (Values.lookup(std::make_pair(0, ParentVNI->id)).getPointer()) {
1100 LLVM_DEBUG(dbgs() << "Single complement def at " << VNI->def << '\n');
1101 continue;
1102 }
1103
1104 if (!Dom.first) {
1105 // First time we see ParentVNI. VNI dominates itself.
1106 Dom = DomPair(ValMBB, VNI->def);
1107 } else if (Dom.first == ValMBB) {
1108 // Two defs in the same block. Pick the earlier def.
1109 if (!Dom.second.isValid() || VNI->def < Dom.second)
1110 Dom.second = VNI->def;
1111 } else {
1112 // Different basic blocks. Check if one dominates.
1113 MachineBasicBlock *Near =
1114 MDT.findNearestCommonDominator(Dom.first, ValMBB);
1115 if (Near == ValMBB)
1116 // Def ValMBB dominates.
1117 Dom = DomPair(ValMBB, VNI->def);
1118 else if (Near != Dom.first)
1119 // None dominate. Hoist to common dominator, need new def.
1120 Dom = DomPair(Near, SlotIndex());
1121 Costs[ParentVNI->id] += MBFI.getBlockFreq(ValMBB);
1122 }
1123
1124 LLVM_DEBUG(dbgs() << "Multi-mapped complement " << VNI->id << '@'
1125 << VNI->def << " for parent " << ParentVNI->id << '@'
1126 << ParentVNI->def << " hoist to "
1127 << printMBBReference(*Dom.first) << ' ' << Dom.second
1128 << '\n');
1129 }
1130
1131 // Insert the hoisted copies.
1132 for (unsigned i = 0, e = Parent->getNumValNums(); i != e; ++i) {
1133 DomPair &Dom = NearestDom[i];
1134 if (!Dom.first || Dom.second.isValid())
1135 continue;
1136 // This value needs a hoisted copy inserted at the end of Dom.first.
1137 const VNInfo *ParentVNI = Parent->getValNumInfo(i);
1138 MachineBasicBlock *DefMBB = LIS.getMBBFromIndex(ParentVNI->def);
1139 // Get a less loopy dominator than Dom.first.
1140 Dom.first = findShallowDominator(Dom.first, DefMBB);
1141 if (SpillMode == SM_Speed &&
1142 MBFI.getBlockFreq(Dom.first) > Costs[ParentVNI->id]) {
1143 NotToHoistSet.insert(ParentVNI->id);
1144 continue;
1145 }
1146 SlotIndex LSP = SA.getLastSplitPoint(Dom.first);
1147 if (LSP <= ParentVNI->def) {
1148 NotToHoistSet.insert(ParentVNI->id);
1149 continue;
1150 }
1151 Dom.second = defFromParent(0, ParentVNI, LSP, *Dom.first,
1152 SA.getLastSplitPointIter(Dom.first))->def;
1153 }
1154
1155 // Remove redundant back-copies that are now known to be dominated by another
1156 // def with the same value.
1157 SmallVector<VNInfo*, 8> BackCopies;
1158 for (VNInfo *VNI : LI->valnos) {
1159 if (VNI->isUnused())
1160 continue;
1161 VNInfo *ParentVNI = Edit->getParent().getVNInfoAt(VNI->def);
1162 const DomPair &Dom = NearestDom[ParentVNI->id];
1163 if (!Dom.first || Dom.second == VNI->def ||
1164 NotToHoistSet.count(ParentVNI->id))
1165 continue;
1166 BackCopies.push_back(VNI);
1167 forceRecompute(0, *ParentVNI);
1168 }
1169
1170 // If it is not beneficial to hoist all the BackCopies, simply remove
1171 // redundant BackCopies in speed mode.
1172 if (SpillMode == SM_Speed && !NotToHoistSet.empty())
1173 computeRedundantBackCopies(NotToHoistSet, BackCopies);
1174
1175 removeBackCopies(BackCopies);
1176}
1177
1178/// transferValues - Transfer all possible values to the new live ranges.
1179/// Values that were rematerialized are left alone, they need LICalc.extend().
1180bool SplitEditor::transferValues() {
1181 bool Skipped = false;
1182 RegAssignMap::const_iterator AssignI = RegAssign.begin();
1183 for (const LiveRange::Segment &S : Edit->getParent()) {
1184 LLVM_DEBUG(dbgs() << " blit " << S << ':');
1185 VNInfo *ParentVNI = S.valno;
1186 // RegAssign has holes where RegIdx 0 should be used.
1187 SlotIndex Start = S.start;
1188 AssignI.advanceTo(Start);
1189 do {
1190 unsigned RegIdx;
1191 SlotIndex End = S.end;
1192 if (!AssignI.valid()) {
1193 RegIdx = 0;
1194 } else if (AssignI.start() <= Start) {
1195 RegIdx = AssignI.value();
1196 if (AssignI.stop() < End) {
1197 End = AssignI.stop();
1198 ++AssignI;
1199 }
1200 } else {
1201 RegIdx = 0;
1202 End = std::min(End, AssignI.start());
1203 }
1204
1205 // The interval [Start;End) is continuously mapped to RegIdx, ParentVNI.
1206 LLVM_DEBUG(dbgs() << " [" << Start << ';' << End << ")=" << RegIdx << '('
1207 << printReg(Edit->get(RegIdx)) << ')');
1208 LiveInterval &LI = LIS.getInterval(Edit->get(RegIdx));
1209
1210 // Check for a simply defined value that can be blitted directly.
1211 ValueForcePair VFP = Values.lookup(std::make_pair(RegIdx, ParentVNI->id));
1212 if (VNInfo *VNI = VFP.getPointer()) {
1213 LLVM_DEBUG(dbgs() << ':' << VNI->id);
1214 LI.addSegment(LiveInterval::Segment(Start, End, VNI));
1215 Start = End;
1216 continue;
1217 }
1218
1219 // Skip values with forced recomputation.
1220 if (VFP.getInt()) {
1221 LLVM_DEBUG(dbgs() << "(recalc)");
1222 Skipped = true;
1223 Start = End;
1224 continue;
1225 }
1226
1227 LiveIntervalCalc &LIC = getLICalc(RegIdx);
1228
1229 // This value has multiple defs in RegIdx, but it wasn't rematerialized,
1230 // so the live range is accurate. Add live-in blocks in [Start;End) to the
1231 // LiveInBlocks.
1232 MachineFunction::iterator MBB = LIS.getMBBFromIndex(Start)->getIterator();
1233 SlotIndex BlockStart, BlockEnd;
1234 std::tie(BlockStart, BlockEnd) = LIS.getSlotIndexes()->getMBBRange(&*MBB);
1235
1236 // The first block may be live-in, or it may have its own def.
1237 if (Start != BlockStart) {
1238 VNInfo *VNI = LI.extendInBlock(BlockStart, std::min(BlockEnd, End));
1239 assert(VNI && "Missing def for complex mapped value");
1240 LLVM_DEBUG(dbgs() << ':' << VNI->id << "*" << printMBBReference(*MBB));
1241 // MBB has its own def. Is it also live-out?
1242 if (BlockEnd <= End)
1243 LIC.setLiveOutValue(&*MBB, VNI);
1244
1245 // Skip to the next block for live-in.
1246 ++MBB;
1247 BlockStart = BlockEnd;
1248 }
1249
1250 // Handle the live-in blocks covered by [Start;End).
1251 assert(Start <= BlockStart && "Expected live-in block");
1252 while (BlockStart < End) {
1253 LLVM_DEBUG(dbgs() << ">" << printMBBReference(*MBB));
1254 BlockEnd = LIS.getMBBEndIdx(&*MBB);
1255 if (BlockStart == ParentVNI->def) {
1256 // This block has the def of a parent PHI, so it isn't live-in.
1257 assert(ParentVNI->isPHIDef() && "Non-phi defined at block start?");
1258 VNInfo *VNI = LI.extendInBlock(BlockStart, std::min(BlockEnd, End));
1259 assert(VNI && "Missing def for complex mapped parent PHI");
1260 if (End >= BlockEnd)
1261 LIC.setLiveOutValue(&*MBB, VNI); // Live-out as well.
1262 } else {
1263 // This block needs a live-in value. The last block covered may not
1264 // be live-out.
1265 if (End < BlockEnd)
1266 LIC.addLiveInBlock(LI, MDT[&*MBB], End);
1267 else {
1268 // Live-through, and we don't know the value.
1269 LIC.addLiveInBlock(LI, MDT[&*MBB]);
1270 LIC.setLiveOutValue(&*MBB, nullptr);
1271 }
1272 }
1273 BlockStart = BlockEnd;
1274 ++MBB;
1275 }
1276 Start = End;
1277 } while (Start != S.end);
1278 LLVM_DEBUG(dbgs() << '\n');
1279 }
1280
1281 LICalc[0].calculateValues();
1282 if (SpillMode)
1283 LICalc[1].calculateValues();
1284
1285 return Skipped;
1286}
1287
1289 const LiveRange::Segment *Seg = LR.getSegmentContaining(Def);
1290 if (Seg == nullptr)
1291 return true;
1292 if (Seg->end != Def.getDeadSlot())
1293 return false;
1294 // This is a dead PHI. Remove it.
1295 LR.removeSegment(*Seg, true);
1296 return true;
1297}
1298
1299void SplitEditor::extendPHIRange(MachineBasicBlock &B, LiveIntervalCalc &LIC,
1300 LiveRange &LR, LaneBitmask LM,
1301 ArrayRef<SlotIndex> Undefs) {
1302 for (MachineBasicBlock *P : B.predecessors()) {
1303 SlotIndex End = LIS.getMBBEndIdx(P);
1304 SlotIndex LastUse = End.getPrevSlot();
1305 // The predecessor may not have a live-out value. That is OK, like an
1306 // undef PHI operand.
1307 const LiveInterval &PLI = Edit->getParent();
1308 // Need the cast because the inputs to ?: would otherwise be deemed
1309 // "incompatible": SubRange vs LiveInterval.
1310 const LiveRange &PSR = !LM.all() ? getSubRangeForMaskExact(LM, PLI)
1311 : static_cast<const LiveRange &>(PLI);
1312 if (PSR.liveAt(LastUse))
1313 LIC.extend(LR, End, /*PhysReg=*/0, Undefs);
1314 }
1315}
1316
1317void SplitEditor::extendPHIKillRanges() {
1318 // Extend live ranges to be live-out for successor PHI values.
1319
1320 // Visit each PHI def slot in the parent live interval. If the def is dead,
1321 // remove it. Otherwise, extend the live interval to reach the end indexes
1322 // of all predecessor blocks.
1323
1324 const LiveInterval &ParentLI = Edit->getParent();
1325 for (const VNInfo *V : ParentLI.valnos) {
1326 if (V->isUnused() || !V->isPHIDef())
1327 continue;
1328
1329 unsigned RegIdx = RegAssign.lookup(V->def);
1330 LiveInterval &LI = LIS.getInterval(Edit->get(RegIdx));
1331 LiveIntervalCalc &LIC = getLICalc(RegIdx);
1332 MachineBasicBlock &B = *LIS.getMBBFromIndex(V->def);
1333 if (!removeDeadSegment(V->def, LI))
1334 extendPHIRange(B, LIC, LI, LaneBitmask::getAll(), /*Undefs=*/{});
1335 }
1336
1338 LiveIntervalCalc SubLIC;
1339
1340 for (const LiveInterval::SubRange &PS : ParentLI.subranges()) {
1341 for (const VNInfo *V : PS.valnos) {
1342 if (V->isUnused() || !V->isPHIDef())
1343 continue;
1344 unsigned RegIdx = RegAssign.lookup(V->def);
1345 LiveInterval &LI = LIS.getInterval(Edit->get(RegIdx));
1346 LiveInterval::SubRange &S = getSubRangeForMaskExact(PS.LaneMask, LI);
1347 if (removeDeadSegment(V->def, S))
1348 continue;
1349
1350 MachineBasicBlock &B = *LIS.getMBBFromIndex(V->def);
1351 SubLIC.reset(&VRM.getMachineFunction(), LIS.getSlotIndexes(), &MDT,
1352 &LIS.getVNInfoAllocator());
1353 Undefs.clear();
1354 LI.computeSubRangeUndefs(Undefs, PS.LaneMask, MRI, *LIS.getSlotIndexes());
1355 extendPHIRange(B, SubLIC, S, PS.LaneMask, Undefs);
1356 }
1357 }
1358}
1359
1360/// rewriteAssigned - Rewrite all uses of Edit->getReg().
1361void SplitEditor::rewriteAssigned(bool ExtendRanges) {
1362 struct ExtPoint {
1363 ExtPoint(const MachineOperand &O, unsigned R, SlotIndex N)
1364 : MO(O), RegIdx(R), Next(N) {}
1365
1366 MachineOperand MO;
1367 unsigned RegIdx;
1368 SlotIndex Next;
1369 };
1370
1371 SmallVector<ExtPoint,4> ExtPoints;
1372
1373 for (MachineOperand &MO :
1374 llvm::make_early_inc_range(MRI.reg_operands(Edit->getReg()))) {
1375 MachineInstr *MI = MO.getParent();
1376 // LiveDebugVariables should have handled all DBG_VALUE instructions.
1377 if (MI->isDebugValue()) {
1378 LLVM_DEBUG(dbgs() << "Zapping " << *MI);
1379 MO.setReg(0);
1380 continue;
1381 }
1382
1383 // <undef> operands don't really read the register, so it doesn't matter
1384 // which register we choose. When the use operand is tied to a def, we must
1385 // use the same register as the def, so just do that always.
1386 SlotIndex Idx = LIS.getInstructionIndex(*MI);
1387 if (MO.isDef() || MO.isUndef())
1388 Idx = Idx.getRegSlot(MO.isEarlyClobber());
1389
1390 // Rewrite to the mapped register at Idx.
1391 unsigned RegIdx = RegAssign.lookup(Idx);
1392 LiveInterval &LI = LIS.getInterval(Edit->get(RegIdx));
1393 MO.setReg(LI.reg());
1394 LLVM_DEBUG(dbgs() << " rewr " << printMBBReference(*MI->getParent())
1395 << '\t' << Idx << ':' << RegIdx << '\t' << *MI);
1396
1397 // Extend liveness to Idx if the instruction reads reg.
1398 if (!ExtendRanges || MO.isUndef())
1399 continue;
1400
1401 // Skip instructions that don't read Reg.
1402 if (MO.isDef()) {
1403 if (!MO.getSubReg() && !MO.isEarlyClobber())
1404 continue;
1405 // We may want to extend a live range for a partial redef, or for a use
1406 // tied to an early clobber.
1407 if (!Edit->getParent().liveAt(Idx.getPrevSlot()))
1408 continue;
1409 } else {
1410 assert(MO.isUse());
1411 bool IsEarlyClobber = false;
1412 if (MO.isTied()) {
1413 // We want to extend a live range into `e` slot rather than `r` slot if
1414 // tied-def is early clobber, because the `e` slot already contained
1415 // in the live range of early-clobber tied-def operand, give an example
1416 // here:
1417 // 0 %0 = ...
1418 // 16 early-clobber %0 = Op %0 (tied-def 0), ...
1419 // 32 ... = Op %0
1420 // Before extend:
1421 // %0 = [0r, 0d) [16e, 32d)
1422 // The point we want to extend is 0d to 16e not 16r in this case, but if
1423 // we use 16r here we will extend nothing because that already contained
1424 // in [16e, 32d).
1425 unsigned OpIdx = MO.getOperandNo();
1426 unsigned DefOpIdx = MI->findTiedOperandIdx(OpIdx);
1427 const MachineOperand &DefOp = MI->getOperand(DefOpIdx);
1428 IsEarlyClobber = DefOp.isEarlyClobber();
1429 }
1430
1431 Idx = Idx.getRegSlot(IsEarlyClobber);
1432 }
1433
1434 SlotIndex Next = Idx;
1435 if (LI.hasSubRanges()) {
1436 // We have to delay extending subranges until we have seen all operands
1437 // defining the register. This is because a <def,read-undef> operand
1438 // will create an "undef" point, and we cannot extend any subranges
1439 // until all of them have been accounted for.
1440 if (MO.isUse())
1441 ExtPoints.push_back(ExtPoint(MO, RegIdx, Next));
1442 } else {
1443 LiveIntervalCalc &LIC = getLICalc(RegIdx);
1444 LIC.extend(LI, Next, 0, ArrayRef<SlotIndex>());
1445 }
1446 }
1447
1448 for (ExtPoint &EP : ExtPoints) {
1449 LiveInterval &LI = LIS.getInterval(Edit->get(EP.RegIdx));
1450 assert(LI.hasSubRanges());
1451
1452 LiveIntervalCalc SubLIC;
1453 Register Reg = EP.MO.getReg();
1454 unsigned Sub = EP.MO.getSubReg();
1455 LaneBitmask LM = Sub != 0 ? TRI.getSubRegIndexLaneMask(Sub)
1457 for (LiveInterval::SubRange &S : LI.subranges()) {
1458 if ((S.LaneMask & LM).none())
1459 continue;
1460 // The problem here can be that the new register may have been created
1461 // for a partially defined original register. For example:
1462 // %0:subreg_hireg<def,read-undef> = ...
1463 // ...
1464 // %1 = COPY %0
1465 if (S.empty())
1466 continue;
1467 SubLIC.reset(&VRM.getMachineFunction(), LIS.getSlotIndexes(), &MDT,
1468 &LIS.getVNInfoAllocator());
1470 LI.computeSubRangeUndefs(Undefs, S.LaneMask, MRI, *LIS.getSlotIndexes());
1471 SubLIC.extend(S, EP.Next, 0, Undefs);
1472 }
1473 }
1474
1475 for (Register R : *Edit) {
1476 LiveInterval &LI = LIS.getInterval(R);
1477 if (!LI.hasSubRanges())
1478 continue;
1479 LI.clear();
1481 LIS.constructMainRangeFromSubranges(LI);
1482 }
1483}
1484
1485void SplitEditor::deleteRematVictims() {
1486 SmallVector<MachineInstr*, 8> Dead;
1487 for (const Register &R : *Edit) {
1488 LiveInterval *LI = &LIS.getInterval(R);
1489 for (const LiveRange::Segment &S : LI->segments) {
1490 // Dead defs end at the dead slot.
1491 if (S.end != S.valno->def.getDeadSlot())
1492 continue;
1493 if (S.valno->isPHIDef())
1494 continue;
1495 MachineInstr *MI = LIS.getInstructionFromIndex(S.valno->def);
1496 assert(MI && "Missing instruction for dead def");
1497 MI->addRegisterDead(LI->reg(), &TRI);
1498
1499 if (!MI->allDefsAreDead())
1500 continue;
1501
1502 LLVM_DEBUG(dbgs() << "All defs dead: " << *MI);
1503 Dead.push_back(MI);
1504 }
1505 }
1506
1507 if (Dead.empty())
1508 return;
1509
1510 Edit->eliminateDeadDefs(Dead, {});
1511}
1512
1513void SplitEditor::forceRecomputeVNI(const VNInfo &ParentVNI) {
1514 // Fast-path for common case.
1515 if (!ParentVNI.isPHIDef()) {
1516 for (unsigned I = 0, E = Edit->size(); I != E; ++I)
1517 forceRecompute(I, ParentVNI);
1518 return;
1519 }
1520
1521 // Trace value through phis.
1522 ///< whether VNI was/is in worklist.
1523 SmallPtrSet<const VNInfo *, 8> Visited = {&ParentVNI};
1524 SmallVector<const VNInfo *, 4> WorkList = {&ParentVNI};
1525
1526 const LiveInterval &ParentLI = Edit->getParent();
1527 const SlotIndexes &Indexes = *LIS.getSlotIndexes();
1528 do {
1529 const VNInfo &VNI = *WorkList.pop_back_val();
1530 for (unsigned I = 0, E = Edit->size(); I != E; ++I)
1531 forceRecompute(I, VNI);
1532 if (!VNI.isPHIDef())
1533 continue;
1534
1535 MachineBasicBlock &MBB = *Indexes.getMBBFromIndex(VNI.def);
1536 for (const MachineBasicBlock *Pred : MBB.predecessors()) {
1537 SlotIndex PredEnd = Indexes.getMBBEndIdx(Pred);
1538 VNInfo *PredVNI = ParentLI.getVNInfoBefore(PredEnd);
1539 assert(PredVNI && "Value available in PhiVNI predecessor");
1540 if (Visited.insert(PredVNI).second)
1541 WorkList.push_back(PredVNI);
1542 }
1543 } while(!WorkList.empty());
1544}
1545
1547 ++NumFinished;
1548
1549 // At this point, the live intervals in Edit contain VNInfos corresponding to
1550 // the inserted copies.
1551
1552 // Add the original defs from the parent interval.
1553 for (const VNInfo *ParentVNI : Edit->getParent().valnos) {
1554 if (ParentVNI->isUnused())
1555 continue;
1556 unsigned RegIdx = RegAssign.lookup(ParentVNI->def);
1557 defValue(RegIdx, ParentVNI, ParentVNI->def, true);
1558
1559 // Force rematted values to be recomputed everywhere.
1560 // The new live ranges may be truncated.
1561 if (Edit->didRematerialize(ParentVNI))
1562 forceRecomputeVNI(*ParentVNI);
1563 }
1564
1565 // Hoist back-copies to the complement interval when in spill mode.
1566 switch (SpillMode) {
1567 case SM_Partition:
1568 // Leave all back-copies as is.
1569 break;
1570 case SM_Size:
1571 case SM_Speed:
1572 // hoistCopies will behave differently between size and speed.
1573 hoistCopies();
1574 }
1575
1576 // Transfer the simply mapped values, check if any are skipped.
1577 bool Skipped = transferValues();
1578
1579 // Rewrite virtual registers, possibly extending ranges.
1580 rewriteAssigned(Skipped);
1581
1582 if (Skipped)
1583 extendPHIKillRanges();
1584 else
1585 ++NumSimple;
1586
1587 // Delete defs that were rematted everywhere.
1588 if (Skipped)
1589 deleteRematVictims();
1590
1591 // Get rid of unused values and set phi-kill flags.
1592 for (Register Reg : *Edit) {
1593 LiveInterval &LI = LIS.getInterval(Reg);
1595 LI.RenumberValues();
1596 }
1597
1598 // Provide a reverse mapping from original indices to Edit ranges.
1599 if (LRMap) {
1600 auto Seq = llvm::seq<unsigned>(0, Edit->size());
1601 LRMap->assign(Seq.begin(), Seq.end());
1602 }
1603
1604 // Now check if any registers were separated into multiple components.
1605 ConnectedVNInfoEqClasses ConEQ(LIS);
1606 for (unsigned i = 0, e = Edit->size(); i != e; ++i) {
1607 // Don't use iterators, they are invalidated by create() below.
1608 Register VReg = Edit->get(i);
1609 LiveInterval &LI = LIS.getInterval(VReg);
1611 LIS.splitSeparateComponents(LI, SplitLIs);
1612 Register Original = VRM.getOriginal(VReg);
1613 for (LiveInterval *SplitLI : SplitLIs)
1614 VRM.setIsSplitFromReg(SplitLI->reg(), Original);
1615
1616 // The new intervals all map back to i.
1617 if (LRMap)
1618 LRMap->resize(Edit->size(), i);
1619 }
1620
1621 // Calculate spill weight and allocation hints for new intervals.
1622 Edit->calculateRegClassAndHint(VRM.getMachineFunction(), VRAI);
1623
1624 assert(!LRMap || LRMap->size() == Edit->size());
1625}
1626
1627//===----------------------------------------------------------------------===//
1628// Single Block Splitting
1629//===----------------------------------------------------------------------===//
1630
1632 bool SingleInstrs) const {
1633 // Always split for multiple instructions.
1634 if (!BI.isOneInstr())
1635 return true;
1636 // Don't split for single instructions unless explicitly requested.
1637 if (!SingleInstrs)
1638 return false;
1639 // Splitting a live-through range always makes progress.
1640 if (BI.LiveIn && BI.LiveOut)
1641 return true;
1642 // No point in isolating a copy. It has no register class constraints.
1643 MachineInstr *MI = LIS.getInstructionFromIndex(BI.FirstInstr);
1644 bool copyLike = TII.isCopyInstr(*MI) || MI->isSubregToReg();
1645 if (copyLike)
1646 return false;
1647 // Finally, don't isolate an end point that was created by earlier splits.
1648 return isOriginalEndpoint(BI.FirstInstr);
1649}
1650
1652 openIntv();
1653 SlotIndex LastSplitPoint = SA.getLastSplitPoint(BI.MBB);
1654 SlotIndex SegStart = enterIntvBefore(std::min(BI.FirstInstr,
1655 LastSplitPoint));
1656 if (!BI.LiveOut || BI.LastInstr < LastSplitPoint) {
1657 useIntv(SegStart, leaveIntvAfter(BI.LastInstr));
1658 } else {
1659 // The last use is after the last valid split point.
1660 SlotIndex SegStop = leaveIntvBefore(LastSplitPoint);
1661 useIntv(SegStart, SegStop);
1662 overlapIntv(SegStop, BI.LastInstr);
1663 }
1664}
1665
1666//===----------------------------------------------------------------------===//
1667// Global Live Range Splitting Support
1668//===----------------------------------------------------------------------===//
1669
1670// These methods support a method of global live range splitting that uses a
1671// global algorithm to decide intervals for CFG edges. They will insert split
1672// points and color intervals in basic blocks while avoiding interference.
1673//
1674// Note that splitSingleBlock is also useful for blocks where both CFG edges
1675// are on the stack.
1676
1678 unsigned IntvIn, SlotIndex LeaveBefore,
1679 unsigned IntvOut, SlotIndex EnterAfter){
1680 SlotIndex Start, Stop;
1681 std::tie(Start, Stop) = LIS.getSlotIndexes()->getMBBRange(MBBNum);
1682
1683 LLVM_DEBUG(dbgs() << "%bb." << MBBNum << " [" << Start << ';' << Stop
1684 << ") intf " << LeaveBefore << '-' << EnterAfter
1685 << ", live-through " << IntvIn << " -> " << IntvOut);
1686
1687 assert((IntvIn || IntvOut) && "Use splitSingleBlock for isolated blocks");
1688
1689 assert((!LeaveBefore || LeaveBefore < Stop) && "Interference after block");
1690 assert((!IntvIn || !LeaveBefore || LeaveBefore > Start) && "Impossible intf");
1691 assert((!EnterAfter || EnterAfter >= Start) && "Interference before block");
1692
1693 MachineBasicBlock *MBB = VRM.getMachineFunction().getBlockNumbered(MBBNum);
1694
1695 if (!IntvOut) {
1696 LLVM_DEBUG(dbgs() << ", spill on entry.\n");
1697 //
1698 // <<<<<<<<< Possible LeaveBefore interference.
1699 // |-----------| Live through.
1700 // -____________ Spill on entry.
1701 //
1702 selectIntv(IntvIn);
1704 assert((!LeaveBefore || Idx <= LeaveBefore) && "Interference");
1705 (void)Idx;
1706 return;
1707 }
1708
1709 if (!IntvIn) {
1710 LLVM_DEBUG(dbgs() << ", reload on exit.\n");
1711 //
1712 // >>>>>>> Possible EnterAfter interference.
1713 // |-----------| Live through.
1714 // ___________-- Reload on exit.
1715 //
1716 selectIntv(IntvOut);
1718 assert((!EnterAfter || Idx >= EnterAfter) && "Interference");
1719 (void)Idx;
1720 return;
1721 }
1722
1723 if (IntvIn == IntvOut && !LeaveBefore && !EnterAfter) {
1724 LLVM_DEBUG(dbgs() << ", straight through.\n");
1725 //
1726 // |-----------| Live through.
1727 // ------------- Straight through, same intv, no interference.
1728 //
1729 selectIntv(IntvOut);
1730 useIntv(Start, Stop);
1731 return;
1732 }
1733
1734 // We cannot legally insert splits after LSP.
1735 SlotIndex LSP = SA.getLastSplitPoint(MBBNum);
1736 assert((!IntvOut || !EnterAfter || EnterAfter < LSP) && "Impossible intf");
1737
1738 if (IntvIn != IntvOut && (!LeaveBefore || !EnterAfter ||
1739 LeaveBefore.getBaseIndex() > EnterAfter.getBoundaryIndex())) {
1740 LLVM_DEBUG(dbgs() << ", switch avoiding interference.\n");
1741 //
1742 // >>>> <<<< Non-overlapping EnterAfter/LeaveBefore interference.
1743 // |-----------| Live through.
1744 // ------======= Switch intervals between interference.
1745 //
1746 selectIntv(IntvOut);
1747 SlotIndex Idx;
1748 if (LeaveBefore && LeaveBefore < LSP) {
1749 Idx = enterIntvBefore(LeaveBefore);
1750 useIntv(Idx, Stop);
1751 } else {
1752 Idx = enterIntvAtEnd(*MBB);
1753 }
1754 selectIntv(IntvIn);
1755 useIntv(Start, Idx);
1756 assert((!LeaveBefore || Idx <= LeaveBefore) && "Interference");
1757 assert((!EnterAfter || Idx >= EnterAfter) && "Interference");
1758 return;
1759 }
1760
1761 LLVM_DEBUG(dbgs() << ", create local intv for interference.\n");
1762 //
1763 // >>><><><><<<< Overlapping EnterAfter/LeaveBefore interference.
1764 // |-----------| Live through.
1765 // ==---------== Switch intervals before/after interference.
1766 //
1767 assert(LeaveBefore <= EnterAfter && "Missed case");
1768
1769 selectIntv(IntvOut);
1770 SlotIndex Idx = enterIntvAfter(EnterAfter);
1771 useIntv(Idx, Stop);
1772 assert((!EnterAfter || Idx >= EnterAfter) && "Interference");
1773
1774 selectIntv(IntvIn);
1775 Idx = leaveIntvBefore(LeaveBefore);
1776 useIntv(Start, Idx);
1777 assert((!LeaveBefore || Idx <= LeaveBefore) && "Interference");
1778}
1779
1781 unsigned IntvIn, SlotIndex LeaveBefore) {
1782 SlotIndex Start, Stop;
1783 std::tie(Start, Stop) = LIS.getSlotIndexes()->getMBBRange(BI.MBB);
1784
1785 LLVM_DEBUG(dbgs() << printMBBReference(*BI.MBB) << " [" << Start << ';'
1786 << Stop << "), uses " << BI.FirstInstr << '-'
1787 << BI.LastInstr << ", reg-in " << IntvIn
1788 << ", leave before " << LeaveBefore
1789 << (BI.LiveOut ? ", stack-out" : ", killed in block"));
1790
1791 assert(IntvIn && "Must have register in");
1792 assert(BI.LiveIn && "Must be live-in");
1793 assert((!LeaveBefore || LeaveBefore > Start) && "Bad interference");
1794
1795 if (!BI.LiveOut && (!LeaveBefore || LeaveBefore >= BI.LastInstr)) {
1796 LLVM_DEBUG(dbgs() << " before interference.\n");
1797 //
1798 // <<< Interference after kill.
1799 // |---o---x | Killed in block.
1800 // ========= Use IntvIn everywhere.
1801 //
1802 selectIntv(IntvIn);
1803 useIntv(Start, BI.LastInstr);
1804 return;
1805 }
1806
1807 SlotIndex LSP = SA.getLastSplitPoint(BI.MBB);
1808
1809 if (!LeaveBefore || LeaveBefore > BI.LastInstr.getBoundaryIndex()) {
1810 //
1811 // <<< Possible interference after last use.
1812 // |---o---o---| Live-out on stack.
1813 // =========____ Leave IntvIn after last use.
1814 //
1815 // < Interference after last use.
1816 // |---o---o--o| Live-out on stack, late last use.
1817 // ============ Copy to stack after LSP, overlap IntvIn.
1818 // \_____ Stack interval is live-out.
1819 //
1820 if (BI.LastInstr < LSP) {
1821 LLVM_DEBUG(dbgs() << ", spill after last use before interference.\n");
1822 selectIntv(IntvIn);
1824 useIntv(Start, Idx);
1825 assert((!LeaveBefore || Idx <= LeaveBefore) && "Interference");
1826 } else {
1827 LLVM_DEBUG(dbgs() << ", spill before last split point.\n");
1828 selectIntv(IntvIn);
1829 SlotIndex Idx = leaveIntvBefore(LSP);
1830 overlapIntv(Idx, BI.LastInstr);
1831 useIntv(Start, Idx);
1832 assert((!LeaveBefore || Idx <= LeaveBefore) && "Interference");
1833 }
1834 return;
1835 }
1836
1837 // The interference is overlapping somewhere we wanted to use IntvIn. That
1838 // means we need to create a local interval that can be allocated a
1839 // different register.
1840 unsigned LocalIntv = openIntv();
1841 (void)LocalIntv;
1842 LLVM_DEBUG(dbgs() << ", creating local interval " << LocalIntv << ".\n");
1843
1844 if (!BI.LiveOut || BI.LastInstr < LSP) {
1845 //
1846 // <<<<<<< Interference overlapping uses.
1847 // |---o---o---| Live-out on stack.
1848 // =====----____ Leave IntvIn before interference, then spill.
1849 //
1851 SlotIndex From = enterIntvBefore(LeaveBefore);
1852 useIntv(From, To);
1853 selectIntv(IntvIn);
1854 useIntv(Start, From);
1855 assert((!LeaveBefore || From <= LeaveBefore) && "Interference");
1856 return;
1857 }
1858
1859 // <<<<<<< Interference overlapping uses.
1860 // |---o---o--o| Live-out on stack, late last use.
1861 // =====------- Copy to stack before LSP, overlap LocalIntv.
1862 // \_____ Stack interval is live-out.
1863 //
1864 SlotIndex To = leaveIntvBefore(LSP);
1865 overlapIntv(To, BI.LastInstr);
1866 SlotIndex From = enterIntvBefore(std::min(To, LeaveBefore));
1867 useIntv(From, To);
1868 selectIntv(IntvIn);
1869 useIntv(Start, From);
1870 assert((!LeaveBefore || From <= LeaveBefore) && "Interference");
1871}
1872
1874 unsigned IntvOut, SlotIndex EnterAfter) {
1875 SlotIndex Start, Stop;
1876 std::tie(Start, Stop) = LIS.getSlotIndexes()->getMBBRange(BI.MBB);
1877
1878 LLVM_DEBUG(dbgs() << printMBBReference(*BI.MBB) << " [" << Start << ';'
1879 << Stop << "), uses " << BI.FirstInstr << '-'
1880 << BI.LastInstr << ", reg-out " << IntvOut
1881 << ", enter after " << EnterAfter
1882 << (BI.LiveIn ? ", stack-in" : ", defined in block"));
1883
1884 SlotIndex LSP = SA.getLastSplitPoint(BI.MBB);
1885
1886 assert(IntvOut && "Must have register out");
1887 assert(BI.LiveOut && "Must be live-out");
1888 assert((!EnterAfter || EnterAfter < LSP) && "Bad interference");
1889
1890 if (!BI.LiveIn && (!EnterAfter || EnterAfter <= BI.FirstInstr)) {
1891 LLVM_DEBUG(dbgs() << " after interference.\n");
1892 //
1893 // >>>> Interference before def.
1894 // | o---o---| Defined in block.
1895 // ========= Use IntvOut everywhere.
1896 //
1897 selectIntv(IntvOut);
1898 useIntv(BI.FirstInstr, Stop);
1899 return;
1900 }
1901
1902 if (!EnterAfter || EnterAfter < BI.FirstInstr.getBaseIndex()) {
1903 LLVM_DEBUG(dbgs() << ", reload after interference.\n");
1904 //
1905 // >>>> Interference before def.
1906 // |---o---o---| Live-through, stack-in.
1907 // ____========= Enter IntvOut before first use.
1908 //
1909 selectIntv(IntvOut);
1910 SlotIndex Idx = enterIntvBefore(std::min(LSP, BI.FirstInstr));
1911 useIntv(Idx, Stop);
1912 assert((!EnterAfter || Idx >= EnterAfter) && "Interference");
1913 return;
1914 }
1915
1916 // The interference is overlapping somewhere we wanted to use IntvOut. That
1917 // means we need to create a local interval that can be allocated a
1918 // different register.
1919 LLVM_DEBUG(dbgs() << ", interference overlaps uses.\n");
1920 //
1921 // >>>>>>> Interference overlapping uses.
1922 // |---o---o---| Live-through, stack-in.
1923 // ____---====== Create local interval for interference range.
1924 //
1925 selectIntv(IntvOut);
1926 SlotIndex Idx = enterIntvAfter(EnterAfter);
1927 useIntv(Idx, Stop);
1928 assert((!EnterAfter || Idx >= EnterAfter) && "Interference");
1929
1930 openIntv();
1931 SlotIndex From = enterIntvBefore(std::min(Idx, BI.FirstInstr));
1932 useIntv(From, Idx);
1933}
1934
1936 OS << "{" << printMBBReference(*MBB) << ", "
1937 << "uses " << FirstInstr << " to " << LastInstr << ", "
1938 << "1st def " << FirstDef << ", "
1939 << (LiveIn ? "live in" : "dead in") << ", "
1940 << (LiveOut ? "live out" : "dead out") << "}";
1941}
1942
1944 print(dbgs());
1945 dbgs() << "\n";
1946}
MachineInstrBuilder & UseMI
MachineInstrBuilder MachineInstrBuilder & DefMI
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
aarch64 promote const
MachineBasicBlock & MBB
MachineBasicBlock MachineBasicBlock::iterator MBBI
This file defines the BumpPtrAllocator interface.
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds.
Definition Compiler.h:661
Hexagon Hardware Loops
IRTranslator LLVM IR MI
#define I(x, y, z)
Definition MD5.cpp:57
Register Reg
Register const TargetRegisterInfo * TRI
Promote Memory to Register
Definition Mem2Reg.cpp:110
#define T
static constexpr unsigned SM(unsigned Version)
#define P(N)
if(PassOpts->AAPipeline)
SI Lower i1 Copies
SI Optimize VGPR LiveRange
This file contains some templates that are useful if you are working with the STL at all.
LiveInterval::SubRange & getSubRangeForMaskExact(LaneBitmask LM, LiveInterval &LI)
Definition SplitKit.cpp:405
static bool removeDeadSegment(SlotIndex Def, LiveRange &LR)
LaneBitmask getLiveLaneMaskAt(const LiveInterval &LI, SlotIndex Idx, const MachineRegisterInfo &MRI)
Definition SplitKit.cpp:426
auto & getSubrangeImpl(LaneBitmask LM, T &LI)
Find a subrange corresponding to the exact lane mask LM in the live interval LI.
Definition SplitKit.cpp:398
static bool hasTiedUseOf(MachineInstr &MI, Register Reg)
Definition SplitKit.cpp:862
const LiveInterval::SubRange * findSubRangeForMask(LaneBitmask LM, const LiveInterval &LI)
Find a subrange corresponding to the lane mask LM, or a superset of it, in the live interval LI.
Definition SplitKit.cpp:418
static cl::opt< bool > EnableLoopIVHeuristic("enable-split-loopiv-heuristic", cl::desc("Enable loop iv regalloc heuristic"), cl::init(true))
This file defines the 'Statistic' class, which is designed to be an easy way to expose various metric...
#define STATISTIC(VARNAME, DESC)
Definition Statistic.h:171
#define LLVM_DEBUG(...)
Definition Debug.h:119
Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:40
void resize(unsigned N, bool t=false)
Grow or shrink the bitvector.
Definition BitVector.h:355
BitVector & set()
Set all bits in the bitvector.
Definition BitVector.h:366
ConnectedVNInfoEqClasses - Helper class that can divide VNInfos in a LiveInterval into equivalence cl...
Implements a dense probed hash-table based set.
Definition DenseSet.h:279
DomTreeNodeBase * getIDom() const
NodeT * getBlock() const
MachineBasicBlock::iterator getLastInsertPointIter(const LiveInterval &CurLI, MachineBasicBlock &MBB)
Returns the last insert point as an iterator for \pCurLI in \pMBB.
Definition SplitKit.cpp:142
SlotIndex getLastInsertPoint(const LiveInterval &CurLI, const MachineBasicBlock &MBB)
Return the base index of the last valid insert point for \pCurLI in \pMBB.
Definition SplitKit.h:67
InsertPointAnalysis(const LiveIntervals &lis, unsigned BBNum)
Definition SplitKit.cpp:61
A live range for subregisters.
LiveInterval - This class represents the liveness of a register, or stack slot.
LLVM_ABI void removeEmptySubRanges()
Removes all subranges without any segments (subranges without segments are not considered valid and s...
Register reg() const
bool hasSubRanges() const
Returns true if subregister liveness information is available.
iterator_range< subrange_iterator > subranges()
LLVM_ABI void refineSubRanges(BumpPtrAllocator &Allocator, LaneBitmask LaneMask, std::function< void(LiveInterval::SubRange &)> Apply, const SlotIndexes &Indexes, const TargetRegisterInfo &TRI, unsigned ComposeSubRegIdx=0)
Refines the subranges to support LaneMask.
LLVM_ABI void computeSubRangeUndefs(SmallVectorImpl< SlotIndex > &Undefs, LaneBitmask LaneMask, const MachineRegisterInfo &MRI, const SlotIndexes &Indexes) const
For a given lane mask LaneMask, compute indexes at which the lane is marked undefined by subregister ...
MachineInstr * getInstructionFromIndex(SlotIndex index) const
Returns the instruction associated with the given index.
SlotIndexes * getSlotIndexes() const
SlotIndex getInstructionIndex(const MachineInstr &Instr) const
Returns the base index of the given instruction.
void RemoveMachineInstrFromMaps(MachineInstr &MI)
SlotIndex getMBBEndIdx(const MachineBasicBlock *mbb) const
Return the last index in the given basic block.
LiveInterval & getInterval(Register Reg)
LLVM_ABI void removeVRegDefAt(LiveInterval &LI, SlotIndex Pos)
Remove value number and related live segments of LI and its subranges that start at position Pos.
MachineBasicBlock * getMBBFromIndex(SlotIndex index) const
void addLiveInBlock(LiveRange &LR, MachineDomTreeNode *DomNode, SlotIndex Kill=SlotIndex())
addLiveInBlock - Add a block with an unknown live-in value.
LLVM_ABI void reset(const MachineFunction *mf, SlotIndexes *SI, MachineDominatorTree *MDT, VNInfo::Allocator *VNIA)
reset - Prepare caches for a new set of non-overlapping live ranges.
LLVM_ABI void extend(LiveRange &LR, SlotIndex Use, Register PhysReg, ArrayRef< SlotIndex > Undefs)
Extend the live range of LR to reach Use.
void setLiveOutValue(MachineBasicBlock *MBB, VNInfo *VNI)
setLiveOutValue - Indicate that VNI is live out from MBB.
Register get(unsigned idx) const
Register getReg() const
This class represents the liveness of a register, stack slot, etc.
VNInfo * getValNumInfo(unsigned ValNo)
getValNumInfo - Returns pointer to the specified val#.
LLVM_ABI iterator addSegment(Segment S)
Add the specified Segment to this range, merging segments as appropriate.
Segments::iterator iterator
const Segment * getSegmentContaining(SlotIndex Idx) const
Return the segment that contains the specified index, or null if there is none.
Segments::const_iterator const_iterator
bool liveAt(SlotIndex index) const
LLVM_ABI VNInfo * createDeadDef(SlotIndex Def, VNInfo::Allocator &VNIAlloc)
createDeadDef - Make sure the range has a value defined at Def.
iterator advanceTo(iterator I, SlotIndex Pos)
advanceTo - Advance the specified iterator to point to the Segment containing the specified position,...
bool empty() const
LLVM_ABI void RenumberValues()
RenumberValues - Renumber all values in order of appearance and remove unused values.
VNInfo * getVNInfoBefore(SlotIndex Idx) const
getVNInfoBefore - Return the VNInfo that is live up to but not necessarily including Idx,...
LLVM_ABI std::pair< VNInfo *, bool > extendInBlock(ArrayRef< SlotIndex > Undefs, SlotIndex StartIdx, SlotIndex Kill)
Attempt to extend a value defined after StartIdx to include Use.
unsigned getNumValNums() const
iterator begin()
VNInfoList valnos
VNInfo * getNextValue(SlotIndex Def, VNInfo::Allocator &VNInfoAllocator)
getNextValue - Create a new value number and return it.
LLVM_ABI void removeSegment(SlotIndex Start, SlotIndex End, bool RemoveDeadValNo=false)
Remove the specified interval from this live range.
VNInfo * getVNInfoAt(SlotIndex Idx) const
getVNInfoAt - Return the VNInfo that is live at Idx, or NULL.
LLVM_ABI iterator find(SlotIndex Pos)
find - Return an iterator pointing to the first segment that ends after Pos, or end().
BlockT * getHeader() const
unsigned getLoopDepth() const
Return the nesting level of this loop.
Describe properties that are true of each instruction in the target description file.
MachineInstrBundleIterator< const MachineInstr > const_iterator
LLVM_ABI iterator getFirstTerminator()
Returns an iterator to the first terminator instruction of this basic block.
const MachineFunction * getParent() const
Return the MachineFunction containing this basic block.
iterator_range< pred_iterator > predecessors()
MachineInstrBundleIterator< MachineInstr > iterator
MachineBlockFrequencyInfo pass uses BlockFrequencyInfoImpl implementation to estimate machine basic b...
DominatorTree Class - Concrete subclass of DominatorTreeBase that is used to compute a normal dominat...
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
unsigned getNumBlockIDs() const
getNumBlockIDs - Return the number of MBB ID's allocated.
BasicBlockListType::iterator iterator
BasicBlockListType::const_iterator const_iterator
const MachineInstrBuilder & addReg(Register RegNo, RegState Flags={}, unsigned SubReg=0) const
Add a new virtual register operand.
Representation of each machine instruction.
mop_range defs()
Returns all explicit operands that are register definitions.
LLVM_ABI void bundleWithPred()
Bundle this instruction with its predecessor.
LLVM_ABI const TargetRegisterClass * getRegClassConstraintEffectForVReg(Register Reg, const TargetRegisterClass *CurRC, const TargetInstrInfo *TII, const TargetRegisterInfo *TRI, bool ExploreBundle=false) const
Applies the constraints (def/use) implied by this MI on Reg to the given CurRC.
void setFlag(MIFlag Flag)
Set a MI flag.
const MachineOperand & getOperand(unsigned i) const
LLVM_ABI const TargetRegisterClass * getRegClassConstraint(unsigned OpIdx, const TargetInstrInfo *TII, const TargetRegisterInfo *TRI) const
Compute the static register class constraint for operand OpIdx.
MachineOperand class - Representation of each machine instruction operand.
Register getReg() const
getReg - Returns the register number.
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
iterator_range< use_nodbg_iterator > use_nodbg_operands(Register Reg) const
LLVM_ABI LaneBitmask getMaxLaneMaskForVReg(Register Reg) const
Returns a mask covering all bits that can appear in lane masks of subregisters of the virtual registe...
Wrapper class representing virtual and physical registers.
Definition Register.h:20
SlotIndex - An opaque wrapper around machine indexes.
Definition SlotIndexes.h:66
static bool isSameInstr(SlotIndex A, SlotIndex B)
isSameInstr - Return true if A and B refer to the same instruction.
SlotIndex getDeadSlot() const
Returns the dead def kill slot for the current instruction.
static bool isEarlierInstr(SlotIndex A, SlotIndex B)
isEarlierInstr - Return true if A refers to an instruction earlier than B.
bool isValid() const
Returns true if this is a valid index.
SlotIndex getBoundaryIndex() const
Returns the boundary index for associated with this index.
SlotIndex getBaseIndex() const
Returns the base index for associated with this index.
SlotIndex getNextSlot() const
Returns the next slot in the index list.
SlotIndex getPrevSlot() const
Returns the previous slot in the index list.
SlotIndex getRegSlot(bool EC=false) const
Returns the register use/def slot in the current instruction for a normal or early-clobber def.
SlotIndex insertMachineInstrInMaps(MachineInstr &MI, bool Late=false)
Insert the given machine instruction into the mapping.
MachineBasicBlock * getMBBFromIndex(SlotIndex index) const
Returns the basic block which the given index falls in.
const std::pair< SlotIndex, SlotIndex > & getMBBRange(unsigned Num) const
Return the (start,end) range of the given basic block number.
SlotIndex getMBBEndIdx(unsigned Num) const
Returns the index past the last valid index in the given basic block.
size_type count(ConstPtrType Ptr) const
count - Return 1 if the specified pointer is in the set, 0 otherwise.
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
void assign(size_type NumElts, ValueParamT Elt)
typename SuperClass::const_iterator const_iterator
void resize(size_type N)
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
SplitAnalysis - Analyze a LiveInterval, looking for live range splitting opportunities.
Definition SplitKit.h:96
SplitAnalysis(const VirtRegMap &vrm, const LiveIntervals &lis, const MachineLoopInfo &mli)
Definition SplitKit.cpp:154
const MachineFunction & MF
Definition SplitKit.h:98
bool isOriginalEndpoint(SlotIndex Idx) const
isOriginalEndpoint - Return true if the original live range was killed or (re-)defined at Idx.
Definition SplitKit.cpp:333
unsigned countLiveBlocks(const LiveInterval *li) const
countLiveBlocks - Return the number of blocks where li is live.
Definition SplitKit.cpp:309
const LiveIntervals & LIS
Definition SplitKit.h:100
void analyze(const LiveInterval *li)
analyze - set CurLI to the specified interval, and analyze how it may be split.
Definition SplitKit.cpp:347
void clear()
clear - clear all data structures so SplitAnalysis is ready to analyze a new interval.
Definition SplitKit.cpp:159
const MachineLoopInfo & Loops
Definition SplitKit.h:101
const TargetInstrInfo & TII
Definition SplitKit.h:102
unsigned getNumLiveBlocks() const
getNumLiveBlocks - Return the number of blocks where CurLI is live.
Definition SplitKit.h:212
const VirtRegMap & VRM
Definition SplitKit.h:99
bool shouldSplitSingleBlock(const BlockInfo &BI, bool SingleInstrs) const
shouldSplitSingleBlock - Returns true if it would help to create a local live range for the instructi...
void overlapIntv(SlotIndex Start, SlotIndex End)
overlapIntv - Indicate that all instructions in range should use the open interval if End does not ha...
Definition SplitKit.cpp:868
unsigned openIntv()
Create a new virtual register and live interval.
Definition SplitKit.cpp:690
SplitEditor(SplitAnalysis &SA, LiveIntervals &LIS, VirtRegMap &VRM, MachineDominatorTree &MDT, MachineBlockFrequencyInfo &MBFI, VirtRegAuxInfo &VRAI)
Create a new SplitEditor for editing the LiveInterval analyzed by SA.
Definition SplitKit.cpp:358
void splitRegOutBlock(const SplitAnalysis::BlockInfo &BI, unsigned IntvOut, SlotIndex EnterAfter)
splitRegOutBlock - Split CurLI in the given block such that it enters the block on the stack (or isn'...
SlotIndex enterIntvAfter(SlotIndex Idx)
enterIntvAfter - Enter the open interval after the instruction at Idx.
Definition SplitKit.cpp:725
SlotIndex enterIntvBefore(SlotIndex Idx)
enterIntvBefore - Enter the open interval before the instruction at Idx.
Definition SplitKit.cpp:708
void useIntv(const MachineBasicBlock &MBB)
useIntv - indicate that all instructions in MBB should use OpenLI.
Definition SplitKit.cpp:780
SlotIndex leaveIntvAfter(SlotIndex Idx)
leaveIntvAfter - Leave the open interval after the instruction at Idx.
Definition SplitKit.cpp:791
void reset(LiveRangeEdit &, ComplementSpillMode=SM_Partition)
reset - Prepare for a new split.
Definition SplitKit.cpp:366
SlotIndex enterIntvAtEnd(MachineBasicBlock &MBB)
enterIntvAtEnd - Enter the open interval at the end of MBB.
Definition SplitKit.cpp:743
SlotIndex leaveIntvAtTop(MachineBasicBlock &MBB)
leaveIntvAtTop - Leave the interval at the top of MBB.
Definition SplitKit.cpp:841
SlotIndex leaveIntvBefore(SlotIndex Idx)
leaveIntvBefore - Leave the open interval before the instruction at Idx.
Definition SplitKit.cpp:822
void finish(SmallVectorImpl< unsigned > *LRMap=nullptr)
finish - after all the new live ranges have been created, compute the remaining live range,...
void splitRegInBlock(const SplitAnalysis::BlockInfo &BI, unsigned IntvIn, SlotIndex LeaveBefore)
splitRegInBlock - Split CurLI in the given block such that it enters the block in IntvIn and leaves i...
void splitLiveThroughBlock(unsigned MBBNum, unsigned IntvIn, SlotIndex LeaveBefore, unsigned IntvOut, SlotIndex EnterAfter)
splitLiveThroughBlock - Split CurLI in the given block such that it enters the block in IntvIn and le...
ComplementSpillMode
ComplementSpillMode - Select how the complement live range should be created.
Definition SplitKit.h:281
@ SM_Partition
SM_Partition(Default) - Try to create the complement interval so it doesn't overlap any other interva...
Definition SplitKit.h:286
@ SM_Speed
SM_Speed - Overlap intervals to minimize the expected execution frequency of the inserted copies.
Definition SplitKit.h:298
@ SM_Size
SM_Size - Overlap intervals to minimize the number of inserted COPY instructions.
Definition SplitKit.h:293
void selectIntv(unsigned Idx)
selectIntv - Select a previously opened interval index.
Definition SplitKit.cpp:701
void splitSingleBlock(const SplitAnalysis::BlockInfo &BI)
splitSingleBlock - Split CurLI into a separate live interval around the uses in a single block.
void dump() const
dump - print the current interval mapping to dbgs().
Definition SplitKit.cpp:382
bool hasSubClass(const TargetRegisterClass *RC) const
Return true if the specified TargetRegisterClass is a proper sub-class of this TargetRegisterClass.
VNInfo - Value Number Information.
bool isUnused() const
Returns true if this value is unused.
unsigned id
The ID number of this value.
SlotIndex def
The index of the defining instruction.
bool isPHIDef() const
Returns true if this value is defined by a PHI instruction (or was, PHI instructions may have been el...
Calculate auxiliary information for a virtual register such as its spill weight and allocation hint.
std::pair< iterator, bool > insert(const ValueT &V)
Definition DenseSet.h:202
size_type count(const_arg_type_t< ValueT > V) const
Return 1 if the specified key is in the set, 0 otherwise.
Definition DenseSet.h:180
self_iterator getIterator()
Definition ilist_node.h:123
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition raw_ostream.h:53
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
@ C
The default llvm calling convention, compatible with C.
Definition CallingConv.h:34
@ Skipped
Validation was skipped, as it was not needed.
initializer< Ty > init(const Ty &Val)
NodeAddr< DefNode * > Def
Definition RDFGraph.h:384
This is an optimization pass for GlobalISel generic memory operations.
Printable print(const GCNRegPressure &RP, const GCNSubtarget *ST=nullptr, unsigned DynamicVGPRBlockSize=0)
auto size(R &&Range, std::enable_if_t< std::is_base_of< std::random_access_iterator_tag, typename std::iterator_traits< decltype(Range.begin())>::iterator_category >::value, void > *=nullptr)
Get the size of a range.
Definition STLExtras.h:1668
MachineInstrBuilder BuildMI(MachineFunction &MF, const MIMetadata &MIMD, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
@ Dead
Unused definition.
@ Kill
The last use of a register.
@ Define
Register definition.
constexpr RegState getInternalReadRegState(bool B)
void append_range(Container &C, Range &&R)
Wrapper function to append range R to container C.
Definition STLExtras.h:2207
iterator_range< early_inc_iterator_impl< detail::IterOfRange< RangeT > > > make_early_inc_range(RangeT &&Range)
Make a range that does early increment to allow mutation of the underlying range without disrupting i...
Definition STLExtras.h:633
auto unique(Range &&R, Predicate P)
Definition STLExtras.h:2133
Op::Description Desc
bool any_of(R &&range, UnaryPredicate P)
Provide wrappers to std::any_of which take ranges instead of having to pass begin/end explicitly.
Definition STLExtras.h:1745
auto reverse(ContainerTy &&C)
Definition STLExtras.h:407
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition Debug.cpp:209
bool none_of(R &&Range, UnaryPredicate P)
Provide wrappers to std::none_of which take ranges instead of having to pass begin/end explicitly.
Definition STLExtras.h:1752
LLVM_ABI void report_fatal_error(Error Err, bool gen_crash_diag=true)
Definition Error.cpp:163
FunctionAddr VTableAddr Count
Definition InstrProf.h:139
class LLVM_GSL_OWNER SmallVector
Forward declaration of SmallVector so that calculateSmallVectorDefaultInlinedElements can reference s...
DomTreeNodeBase< MachineBasicBlock > MachineDomTreeNode
@ Sub
Subtraction of integers.
FunctionAddr VTableAddr Next
Definition InstrProf.h:141
auto seq(T Begin, T End)
Iterate over an integral type from Begin up to - but not including - End.
Definition Sequence.h:305
void array_pod_sort(IteratorTy Start, IteratorTy End)
array_pod_sort - This sorts an array with the specified start and end extent.
Definition STLExtras.h:1595
BumpPtrAllocatorImpl<> BumpPtrAllocator
The standard BumpPtrAllocator which just uses the default template parameters.
Definition Allocator.h:383
constexpr RegState getUndefRegState(bool B)
LLVM_ABI Printable printReg(Register Reg, const TargetRegisterInfo *TRI=nullptr, unsigned SubIdx=0, const MachineRegisterInfo *MRI=nullptr)
Prints virtual and physical registers with or without a TRI instance.
LLVM_ABI Printable printMBBReference(const MachineBasicBlock &MBB)
Prints a machine basic block reference.
#define N
static constexpr LaneBitmask getAll()
Definition LaneBitmask.h:82
constexpr bool none() const
Definition LaneBitmask.h:52
constexpr bool any() const
Definition LaneBitmask.h:53
constexpr bool all() const
Definition LaneBitmask.h:54
This represents a simple continuous liveness interval for a value.
Additional information about basic blocks where the current variable is live.
Definition SplitKit.h:121
SlotIndex FirstDef
First non-phi valno->def, or SlotIndex().
Definition SplitKit.h:125
bool LiveOut
Current reg is live out.
Definition SplitKit.h:127
bool LiveIn
Current reg is live in.
Definition SplitKit.h:126
bool isOneInstr() const
isOneInstr - Returns true when this BlockInfo describes a single instruction.
Definition SplitKit.h:131
MachineBasicBlock * MBB
Definition SplitKit.h:122
void print(raw_ostream &OS) const
SlotIndex LastInstr
Last instr accessing current reg.
Definition SplitKit.h:124
SlotIndex FirstInstr
First instr accessing current reg.
Definition SplitKit.h:123