LLVM 20.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.
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 Edit->anyRematerializable();
381}
382
383#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
385 if (RegAssign.empty()) {
386 dbgs() << " empty\n";
387 return;
388 }
389
390 for (RegAssignMap::const_iterator I = RegAssign.begin(); I.valid(); ++I)
391 dbgs() << " [" << I.start() << ';' << I.stop() << "):" << I.value();
392 dbgs() << '\n';
393}
394#endif
395
396/// Find a subrange corresponding to the exact lane mask @p LM in the live
397/// interval @p LI. The interval @p LI is assumed to contain such a subrange.
398/// This function is used to find corresponding subranges between the
399/// original interval and the new intervals.
400template <typename T> auto &getSubrangeImpl(LaneBitmask LM, T &LI) {
401 for (auto &S : LI.subranges())
402 if (S.LaneMask == LM)
403 return S;
404 llvm_unreachable("SubRange for this mask not found");
405}
406
408 LiveInterval &LI) {
409 return getSubrangeImpl(LM, LI);
410}
411
413 const LiveInterval &LI) {
414 return getSubrangeImpl(LM, LI);
415}
416
417/// Find a subrange corresponding to the lane mask @p LM, or a superset of it,
418/// in the live interval @p LI. The interval @p LI is assumed to contain such
419/// a subrange. This function is used to find corresponding subranges between
420/// the original interval and the new intervals.
422 const LiveInterval &LI) {
423 for (const LiveInterval::SubRange &S : LI.subranges())
424 if ((S.LaneMask & LM) == LM)
425 return S;
426 llvm_unreachable("SubRange for this mask not found");
427}
428
429void SplitEditor::addDeadDef(LiveInterval &LI, VNInfo *VNI, bool Original) {
430 if (!LI.hasSubRanges()) {
431 LI.createDeadDef(VNI);
432 return;
433 }
434
435 SlotIndex Def = VNI->def;
436 if (Original) {
437 // If we are transferring a def from the original interval, make sure
438 // to only update the subranges for which the original subranges had
439 // a def at this location.
440 for (LiveInterval::SubRange &S : LI.subranges()) {
441 auto &PS = getSubRangeForMask(S.LaneMask, Edit->getParent());
442 VNInfo *PV = PS.getVNInfoAt(Def);
443 if (PV != nullptr && PV->def == Def)
444 S.createDeadDef(Def, LIS.getVNInfoAllocator());
445 }
446 } else {
447 // This is a new def: either from rematerialization, or from an inserted
448 // copy. Since rematerialization can regenerate a definition of a sub-
449 // register, we need to check which subranges need to be updated.
451 assert(DefMI != nullptr);
452 LaneBitmask LM;
453 for (const MachineOperand &DefOp : DefMI->defs()) {
454 Register R = DefOp.getReg();
455 if (R != LI.reg())
456 continue;
457 if (unsigned SR = DefOp.getSubReg())
458 LM |= TRI.getSubRegIndexLaneMask(SR);
459 else {
460 LM = MRI.getMaxLaneMaskForVReg(R);
461 break;
462 }
463 }
464 for (LiveInterval::SubRange &S : LI.subranges())
465 if ((S.LaneMask & LM).any())
466 S.createDeadDef(Def, LIS.getVNInfoAllocator());
467 }
468}
469
470VNInfo *SplitEditor::defValue(unsigned RegIdx,
471 const VNInfo *ParentVNI,
473 bool Original) {
474 assert(ParentVNI && "Mapping NULL value");
475 assert(Idx.isValid() && "Invalid SlotIndex");
476 assert(Edit->getParent().getVNInfoAt(Idx) == ParentVNI && "Bad Parent VNI");
477 LiveInterval *LI = &LIS.getInterval(Edit->get(RegIdx));
478
479 // Create a new value.
480 VNInfo *VNI = LI->getNextValue(Idx, LIS.getVNInfoAllocator());
481
482 bool Force = LI->hasSubRanges();
483 ValueForcePair FP(Force ? nullptr : VNI, Force);
484 // Use insert for lookup, so we can add missing values with a second lookup.
485 std::pair<ValueMap::iterator, bool> InsP =
486 Values.insert(std::make_pair(std::make_pair(RegIdx, ParentVNI->id), FP));
487
488 // This was the first time (RegIdx, ParentVNI) was mapped, and it is not
489 // forced. Keep it as a simple def without any liveness.
490 if (!Force && InsP.second)
491 return VNI;
492
493 // If the previous value was a simple mapping, add liveness for it now.
494 if (VNInfo *OldVNI = InsP.first->second.getPointer()) {
495 addDeadDef(*LI, OldVNI, Original);
496
497 // No longer a simple mapping. Switch to a complex mapping. If the
498 // interval has subranges, make it a forced mapping.
499 InsP.first->second = ValueForcePair(nullptr, Force);
500 }
501
502 // This is a complex mapping, add liveness for VNI
503 addDeadDef(*LI, VNI, Original);
504 return VNI;
505}
506
507void SplitEditor::forceRecompute(unsigned RegIdx, const VNInfo &ParentVNI) {
508 ValueForcePair &VFP = Values[std::make_pair(RegIdx, ParentVNI.id)];
509 VNInfo *VNI = VFP.getPointer();
510
511 // ParentVNI was either unmapped or already complex mapped. Either way, just
512 // set the force bit.
513 if (!VNI) {
514 VFP.setInt(true);
515 return;
516 }
517
518 // This was previously a single mapping. Make sure the old def is represented
519 // by a trivial live range.
520 addDeadDef(LIS.getInterval(Edit->get(RegIdx)), VNI, false);
521
522 // Mark as complex mapped, forced.
523 VFP = ValueForcePair(nullptr, true);
524}
525
526SlotIndex SplitEditor::buildSingleSubRegCopy(
527 Register FromReg, Register ToReg, MachineBasicBlock &MBB,
528 MachineBasicBlock::iterator InsertBefore, unsigned SubIdx,
529 LiveInterval &DestLI, bool Late, SlotIndex Def, const MCInstrDesc &Desc) {
530 bool FirstCopy = !Def.isValid();
531 MachineInstr *CopyMI = BuildMI(MBB, InsertBefore, DebugLoc(), Desc)
532 .addReg(ToReg, RegState::Define | getUndefRegState(FirstCopy)
533 | getInternalReadRegState(!FirstCopy), SubIdx)
534 .addReg(FromReg, 0, SubIdx);
535
536 SlotIndexes &Indexes = *LIS.getSlotIndexes();
537 if (FirstCopy) {
538 Def = Indexes.insertMachineInstrInMaps(*CopyMI, Late).getRegSlot();
539 } else {
540 CopyMI->bundleWithPred();
541 }
542 return Def;
543}
544
545SlotIndex SplitEditor::buildCopy(Register FromReg, Register ToReg,
547 MachineBasicBlock::iterator InsertBefore, bool Late, unsigned RegIdx) {
548 const MCInstrDesc &Desc =
549 TII.get(TII.getLiveRangeSplitOpcode(FromReg, *MBB.getParent()));
550 SlotIndexes &Indexes = *LIS.getSlotIndexes();
551 if (LaneMask.all() || LaneMask == MRI.getMaxLaneMaskForVReg(FromReg)) {
552 // The full vreg is copied.
553 MachineInstr *CopyMI =
554 BuildMI(MBB, InsertBefore, DebugLoc(), Desc, ToReg).addReg(FromReg);
555 return Indexes.insertMachineInstrInMaps(*CopyMI, Late).getRegSlot();
556 }
557
558 // Only a subset of lanes needs to be copied. The following is a simple
559 // heuristic to construct a sequence of COPYs. We could add a target
560 // specific callback if this turns out to be suboptimal.
561 LiveInterval &DestLI = LIS.getInterval(Edit->get(RegIdx));
562
563 // First pass: Try to find a perfectly matching subregister index. If none
564 // exists find the one covering the most lanemask bits.
565 const TargetRegisterClass *RC = MRI.getRegClass(FromReg);
566 assert(RC == MRI.getRegClass(ToReg) && "Should have same reg class");
567
568 SmallVector<unsigned, 8> SubIndexes;
569
570 // Abort if we cannot possibly implement the COPY with the given indexes.
571 if (!TRI.getCoveringSubRegIndexes(MRI, RC, LaneMask, SubIndexes))
572 report_fatal_error("Impossible to implement partial COPY");
573
575 for (unsigned BestIdx : SubIndexes) {
576 Def = buildSingleSubRegCopy(FromReg, ToReg, MBB, InsertBefore, BestIdx,
577 DestLI, Late, Def, Desc);
578 }
579
580 BumpPtrAllocator &Allocator = LIS.getVNInfoAllocator();
581 DestLI.refineSubRanges(
582 Allocator, LaneMask,
583 [Def, &Allocator](LiveInterval::SubRange &SR) {
584 SR.createDeadDef(Def, Allocator);
585 },
586 Indexes, TRI);
587
588 return Def;
589}
590
591VNInfo *SplitEditor::defFromParent(unsigned RegIdx, const VNInfo *ParentVNI,
595 LiveInterval *LI = &LIS.getInterval(Edit->get(RegIdx));
596
597 // We may be trying to avoid interference that ends at a deleted instruction,
598 // so always begin RegIdx 0 early and all others late.
599 bool Late = RegIdx != 0;
600
601 // Attempt cheap-as-a-copy rematerialization.
602 Register Original = VRM.getOriginal(Edit->get(RegIdx));
603 LiveInterval &OrigLI = LIS.getInterval(Original);
604 VNInfo *OrigVNI = OrigLI.getVNInfoAt(UseIdx);
605
606 Register Reg = LI->reg();
607 bool DidRemat = false;
608 if (OrigVNI) {
609 LiveRangeEdit::Remat RM(ParentVNI);
610 RM.OrigMI = LIS.getInstructionFromIndex(OrigVNI->def);
611 if (Edit->canRematerializeAt(RM, OrigVNI, UseIdx, true)) {
612 Def = Edit->rematerializeAt(MBB, I, Reg, RM, TRI, Late);
613 ++NumRemats;
614 DidRemat = true;
615 }
616 }
617 if (!DidRemat) {
618 LaneBitmask LaneMask;
619 if (OrigLI.hasSubRanges()) {
620 LaneMask = LaneBitmask::getNone();
621 for (LiveInterval::SubRange &S : OrigLI.subranges()) {
622 if (S.liveAt(UseIdx))
623 LaneMask |= S.LaneMask;
624 }
625 } else {
626 LaneMask = LaneBitmask::getAll();
627 }
628
629 if (LaneMask.none()) {
630 const MCInstrDesc &Desc = TII.get(TargetOpcode::IMPLICIT_DEF);
631 MachineInstr *ImplicitDef = BuildMI(MBB, I, DebugLoc(), Desc, Reg);
632 SlotIndexes &Indexes = *LIS.getSlotIndexes();
633 Def = Indexes.insertMachineInstrInMaps(*ImplicitDef, Late).getRegSlot();
634 } else {
635 ++NumCopies;
636 Def = buildCopy(Edit->getReg(), Reg, LaneMask, MBB, I, Late, RegIdx);
637 }
638 }
639
640 // Define the value in Reg.
641 return defValue(RegIdx, ParentVNI, Def, false);
642}
643
644/// Create a new virtual register and live interval.
646 // Create the complement as index 0.
647 if (Edit->empty())
648 Edit->createEmptyInterval();
649
650 // Create the open interval.
651 OpenIdx = Edit->size();
652 Edit->createEmptyInterval();
653 return OpenIdx;
654}
655
657 assert(Idx != 0 && "Cannot select the complement interval");
658 assert(Idx < Edit->size() && "Can only select previously opened interval");
659 LLVM_DEBUG(dbgs() << " selectIntv " << OpenIdx << " -> " << Idx << '\n');
660 OpenIdx = Idx;
661}
662
664 assert(OpenIdx && "openIntv not called before enterIntvBefore");
665 LLVM_DEBUG(dbgs() << " enterIntvBefore " << Idx);
666 Idx = Idx.getBaseIndex();
667 VNInfo *ParentVNI = Edit->getParent().getVNInfoAt(Idx);
668 if (!ParentVNI) {
669 LLVM_DEBUG(dbgs() << ": not live\n");
670 return Idx;
671 }
672 LLVM_DEBUG(dbgs() << ": valno " << ParentVNI->id << '\n');
674 assert(MI && "enterIntvBefore called with invalid index");
675
676 VNInfo *VNI = defFromParent(OpenIdx, ParentVNI, Idx, *MI->getParent(), MI);
677 return VNI->def;
678}
679
681 assert(OpenIdx && "openIntv not called before enterIntvAfter");
682 LLVM_DEBUG(dbgs() << " enterIntvAfter " << Idx);
683 Idx = Idx.getBoundaryIndex();
684 VNInfo *ParentVNI = Edit->getParent().getVNInfoAt(Idx);
685 if (!ParentVNI) {
686 LLVM_DEBUG(dbgs() << ": not live\n");
687 return Idx;
688 }
689 LLVM_DEBUG(dbgs() << ": valno " << ParentVNI->id << '\n');
691 assert(MI && "enterIntvAfter called with invalid index");
692
693 VNInfo *VNI = defFromParent(OpenIdx, ParentVNI, Idx, *MI->getParent(),
694 std::next(MachineBasicBlock::iterator(MI)));
695 return VNI->def;
696}
697
699 assert(OpenIdx && "openIntv not called before enterIntvAtEnd");
701 SlotIndex Last = End.getPrevSlot();
702 LLVM_DEBUG(dbgs() << " enterIntvAtEnd " << printMBBReference(MBB) << ", "
703 << Last);
704 VNInfo *ParentVNI = Edit->getParent().getVNInfoAt(Last);
705 if (!ParentVNI) {
706 LLVM_DEBUG(dbgs() << ": not live\n");
707 return End;
708 }
710 if (LSP < Last) {
711 // It could be that the use after LSP is a def, and thus the ParentVNI
712 // just selected starts at that def. For this case to exist, the def
713 // must be part of a tied def/use pair (as otherwise we'd have split
714 // distinct live ranges into individual live intervals), and thus we
715 // can insert the def into the VNI of the use and the tied def/use
716 // pair can live in the resulting interval.
717 Last = LSP;
718 ParentVNI = Edit->getParent().getVNInfoAt(Last);
719 if (!ParentVNI) {
720 // undef use --> undef tied def
721 LLVM_DEBUG(dbgs() << ": tied use not live\n");
722 return End;
723 }
724 }
725
726 LLVM_DEBUG(dbgs() << ": valno " << ParentVNI->id);
727 VNInfo *VNI = defFromParent(OpenIdx, ParentVNI, Last, MBB,
729 RegAssign.insert(VNI->def, End, OpenIdx);
730 LLVM_DEBUG(dump());
731 return VNI->def;
732}
733
734/// useIntv - indicate that all instructions in MBB should use OpenLI.
737}
738
740 assert(OpenIdx && "openIntv not called before useIntv");
741 LLVM_DEBUG(dbgs() << " useIntv [" << Start << ';' << End << "):");
742 RegAssign.insert(Start, End, OpenIdx);
743 LLVM_DEBUG(dump());
744}
745
747 assert(OpenIdx && "openIntv not called before leaveIntvAfter");
748 LLVM_DEBUG(dbgs() << " leaveIntvAfter " << Idx);
749
750 // The interval must be live beyond the instruction at Idx.
751 SlotIndex Boundary = Idx.getBoundaryIndex();
752 VNInfo *ParentVNI = Edit->getParent().getVNInfoAt(Boundary);
753 if (!ParentVNI) {
754 LLVM_DEBUG(dbgs() << ": not live\n");
755 return Boundary.getNextSlot();
756 }
757 LLVM_DEBUG(dbgs() << ": valno " << ParentVNI->id << '\n');
758 MachineInstr *MI = LIS.getInstructionFromIndex(Boundary);
759 assert(MI && "No instruction at index");
760
761 // In spill mode, make live ranges as short as possible by inserting the copy
762 // before MI. This is only possible if that instruction doesn't redefine the
763 // value. The inserted COPY is not a kill, and we don't need to recompute
764 // the source live range. The spiller also won't try to hoist this copy.
765 if (SpillMode && !SlotIndex::isSameInstr(ParentVNI->def, Idx) &&
766 MI->readsVirtualRegister(Edit->getReg())) {
767 forceRecompute(0, *ParentVNI);
768 defFromParent(0, ParentVNI, Idx, *MI->getParent(), MI);
769 return Idx;
770 }
771
772 VNInfo *VNI = defFromParent(0, ParentVNI, Boundary, *MI->getParent(),
773 std::next(MachineBasicBlock::iterator(MI)));
774 return VNI->def;
775}
776
778 assert(OpenIdx && "openIntv not called before leaveIntvBefore");
779 LLVM_DEBUG(dbgs() << " leaveIntvBefore " << Idx);
780
781 // The interval must be live into the instruction at Idx.
782 Idx = Idx.getBaseIndex();
783 VNInfo *ParentVNI = Edit->getParent().getVNInfoAt(Idx);
784 if (!ParentVNI) {
785 LLVM_DEBUG(dbgs() << ": not live\n");
786 return Idx.getNextSlot();
787 }
788 LLVM_DEBUG(dbgs() << ": valno " << ParentVNI->id << '\n');
789
791 assert(MI && "No instruction at index");
792 VNInfo *VNI = defFromParent(0, ParentVNI, Idx, *MI->getParent(), MI);
793 return VNI->def;
794}
795
797 assert(OpenIdx && "openIntv not called before leaveIntvAtTop");
798 SlotIndex Start = LIS.getMBBStartIdx(&MBB);
799 LLVM_DEBUG(dbgs() << " leaveIntvAtTop " << printMBBReference(MBB) << ", "
800 << Start);
801
802 VNInfo *ParentVNI = Edit->getParent().getVNInfoAt(Start);
803 if (!ParentVNI) {
804 LLVM_DEBUG(dbgs() << ": not live\n");
805 return Start;
806 }
807
808 unsigned RegIdx = 0;
809 Register Reg = LIS.getInterval(Edit->get(RegIdx)).reg();
810 VNInfo *VNI = defFromParent(RegIdx, ParentVNI, Start, MBB,
812 RegAssign.insert(Start, VNI->def, OpenIdx);
813 LLVM_DEBUG(dump());
814 return VNI->def;
815}
816
817static bool hasTiedUseOf(MachineInstr &MI, unsigned Reg) {
818 return any_of(MI.defs(), [Reg](const MachineOperand &MO) {
819 return MO.isReg() && MO.isTied() && MO.getReg() == Reg;
820 });
821}
822
824 assert(OpenIdx && "openIntv not called before overlapIntv");
825 const VNInfo *ParentVNI = Edit->getParent().getVNInfoAt(Start);
826 assert(ParentVNI == Edit->getParent().getVNInfoBefore(End) &&
827 "Parent changes value in extended range");
828 assert(LIS.getMBBFromIndex(Start) == LIS.getMBBFromIndex(End) &&
829 "Range cannot span basic blocks");
830
831 // The complement interval will be extended as needed by LICalc.extend().
832 if (ParentVNI)
833 forceRecompute(0, *ParentVNI);
834
835 // If the last use is tied to a def, we can't mark it as live for the
836 // interval which includes only the use. That would cause the tied pair
837 // to end up in two different intervals.
838 if (auto *MI = LIS.getInstructionFromIndex(End))
839 if (hasTiedUseOf(*MI, Edit->getReg())) {
840 LLVM_DEBUG(dbgs() << "skip overlap due to tied def at end\n");
841 return;
842 }
843
844 LLVM_DEBUG(dbgs() << " overlapIntv [" << Start << ';' << End << "):");
845 RegAssign.insert(Start, End, OpenIdx);
846 LLVM_DEBUG(dump());
847}
848
849//===----------------------------------------------------------------------===//
850// Spill modes
851//===----------------------------------------------------------------------===//
852
853void SplitEditor::removeBackCopies(SmallVectorImpl<VNInfo*> &Copies) {
854 LiveInterval *LI = &LIS.getInterval(Edit->get(0));
855 LLVM_DEBUG(dbgs() << "Removing " << Copies.size() << " back-copies.\n");
857 AssignI.setMap(RegAssign);
858
859 for (const VNInfo *C : Copies) {
860 SlotIndex Def = C->def;
862 assert(MI && "No instruction for back-copy");
863
864 MachineBasicBlock *MBB = MI->getParent();
866 bool AtBegin;
867 do AtBegin = MBBI == MBB->begin();
868 while (!AtBegin && (--MBBI)->isDebugOrPseudoInstr());
869
870 LLVM_DEBUG(dbgs() << "Removing " << Def << '\t' << *MI);
871 LIS.removeVRegDefAt(*LI, Def);
873 MI->eraseFromParent();
874
875 // Adjust RegAssign if a register assignment is killed at Def. We want to
876 // avoid calculating the live range of the source register if possible.
877 AssignI.find(Def.getPrevSlot());
878 if (!AssignI.valid() || AssignI.start() >= Def)
879 continue;
880 // If MI doesn't kill the assigned register, just leave it.
881 if (AssignI.stop() != Def)
882 continue;
883 unsigned RegIdx = AssignI.value();
884 // We could hoist back-copy right after another back-copy. As a result
885 // MMBI points to copy instruction which is actually dead now.
886 // We cannot set its stop to MBBI which will be the same as start and
887 // interval does not support that.
888 SlotIndex Kill =
889 AtBegin ? SlotIndex() : LIS.getInstructionIndex(*MBBI).getRegSlot();
890 if (AtBegin || !MBBI->readsVirtualRegister(Edit->getReg()) ||
891 Kill <= AssignI.start()) {
892 LLVM_DEBUG(dbgs() << " cannot find simple kill of RegIdx " << RegIdx
893 << '\n');
894 forceRecompute(RegIdx, *Edit->getParent().getVNInfoAt(Def));
895 } else {
896 LLVM_DEBUG(dbgs() << " move kill to " << Kill << '\t' << *MBBI);
897 AssignI.setStop(Kill);
898 }
899 }
900}
901
903SplitEditor::findShallowDominator(MachineBasicBlock *MBB,
904 MachineBasicBlock *DefMBB) {
905 if (MBB == DefMBB)
906 return MBB;
907 assert(MDT.dominates(DefMBB, MBB) && "MBB must be dominated by the def.");
908
909 const MachineLoopInfo &Loops = SA.Loops;
910 const MachineLoop *DefLoop = Loops.getLoopFor(DefMBB);
911 MachineDomTreeNode *DefDomNode = MDT[DefMBB];
912
913 // Best candidate so far.
914 MachineBasicBlock *BestMBB = MBB;
915 unsigned BestDepth = std::numeric_limits<unsigned>::max();
916
917 while (true) {
918 const MachineLoop *Loop = Loops.getLoopFor(MBB);
919
920 // MBB isn't in a loop, it doesn't get any better. All dominators have a
921 // higher frequency by definition.
922 if (!Loop) {
923 LLVM_DEBUG(dbgs() << "Def in " << printMBBReference(*DefMBB)
924 << " dominates " << printMBBReference(*MBB)
925 << " at depth 0\n");
926 return MBB;
927 }
928
929 // We'll never be able to exit the DefLoop.
930 if (Loop == DefLoop) {
931 LLVM_DEBUG(dbgs() << "Def in " << printMBBReference(*DefMBB)
932 << " dominates " << printMBBReference(*MBB)
933 << " in the same loop\n");
934 return MBB;
935 }
936
937 // Least busy dominator seen so far.
938 unsigned Depth = Loop->getLoopDepth();
939 if (Depth < BestDepth) {
940 BestMBB = MBB;
941 BestDepth = Depth;
942 LLVM_DEBUG(dbgs() << "Def in " << printMBBReference(*DefMBB)
943 << " dominates " << printMBBReference(*MBB)
944 << " at depth " << Depth << '\n');
945 }
946
947 // Leave loop by going to the immediate dominator of the loop header.
948 // This is a bigger stride than simply walking up the dominator tree.
949 MachineDomTreeNode *IDom = MDT[Loop->getHeader()]->getIDom();
950
951 // Too far up the dominator tree?
952 if (!IDom || !MDT.dominates(DefDomNode, IDom))
953 return BestMBB;
954
955 MBB = IDom->getBlock();
956 }
957}
958
959void SplitEditor::computeRedundantBackCopies(
960 DenseSet<unsigned> &NotToHoistSet, SmallVectorImpl<VNInfo *> &BackCopies) {
961 LiveInterval *LI = &LIS.getInterval(Edit->get(0));
962 const LiveInterval *Parent = &Edit->getParent();
964 SmallPtrSet<VNInfo *, 8> DominatedVNIs;
965
966 // Aggregate VNIs having the same value as ParentVNI.
967 for (VNInfo *VNI : LI->valnos) {
968 if (VNI->isUnused())
969 continue;
970 VNInfo *ParentVNI = Edit->getParent().getVNInfoAt(VNI->def);
971 EqualVNs[ParentVNI->id].insert(VNI);
972 }
973
974 // For VNI aggregation of each ParentVNI, collect dominated, i.e.,
975 // redundant VNIs to BackCopies.
976 for (unsigned i = 0, e = Parent->getNumValNums(); i != e; ++i) {
977 const VNInfo *ParentVNI = Parent->getValNumInfo(i);
978 if (!NotToHoistSet.count(ParentVNI->id))
979 continue;
980 SmallPtrSetIterator<VNInfo *> It1 = EqualVNs[ParentVNI->id].begin();
982 for (; It1 != EqualVNs[ParentVNI->id].end(); ++It1) {
983 It2 = It1;
984 for (++It2; It2 != EqualVNs[ParentVNI->id].end(); ++It2) {
985 if (DominatedVNIs.count(*It1) || DominatedVNIs.count(*It2))
986 continue;
987
988 MachineBasicBlock *MBB1 = LIS.getMBBFromIndex((*It1)->def);
989 MachineBasicBlock *MBB2 = LIS.getMBBFromIndex((*It2)->def);
990 if (MBB1 == MBB2) {
991 DominatedVNIs.insert((*It1)->def < (*It2)->def ? (*It2) : (*It1));
992 } else if (MDT.dominates(MBB1, MBB2)) {
993 DominatedVNIs.insert(*It2);
994 } else if (MDT.dominates(MBB2, MBB1)) {
995 DominatedVNIs.insert(*It1);
996 }
997 }
998 }
999 if (!DominatedVNIs.empty()) {
1000 forceRecompute(0, *ParentVNI);
1001 append_range(BackCopies, DominatedVNIs);
1002 DominatedVNIs.clear();
1003 }
1004 }
1005}
1006
1007/// For SM_Size mode, find a common dominator for all the back-copies for
1008/// the same ParentVNI and hoist the backcopies to the dominator BB.
1009/// For SM_Speed mode, if the common dominator is hot and it is not beneficial
1010/// to do the hoisting, simply remove the dominated backcopies for the same
1011/// ParentVNI.
1012void SplitEditor::hoistCopies() {
1013 // Get the complement interval, always RegIdx 0.
1014 LiveInterval *LI = &LIS.getInterval(Edit->get(0));
1015 const LiveInterval *Parent = &Edit->getParent();
1016
1017 // Track the nearest common dominator for all back-copies for each ParentVNI,
1018 // indexed by ParentVNI->id.
1019 using DomPair = std::pair<MachineBasicBlock *, SlotIndex>;
1020 SmallVector<DomPair, 8> NearestDom(Parent->getNumValNums());
1021 // The total cost of all the back-copies for each ParentVNI.
1023 // The ParentVNI->id set for which hoisting back-copies are not beneficial
1024 // for Speed.
1025 DenseSet<unsigned> NotToHoistSet;
1026
1027 // Find the nearest common dominator for parent values with multiple
1028 // back-copies. If a single back-copy dominates, put it in DomPair.second.
1029 for (VNInfo *VNI : LI->valnos) {
1030 if (VNI->isUnused())
1031 continue;
1032 VNInfo *ParentVNI = Edit->getParent().getVNInfoAt(VNI->def);
1033 assert(ParentVNI && "Parent not live at complement def");
1034
1035 // Don't hoist remats. The complement is probably going to disappear
1036 // completely anyway.
1037 if (Edit->didRematerialize(ParentVNI))
1038 continue;
1039
1040 MachineBasicBlock *ValMBB = LIS.getMBBFromIndex(VNI->def);
1041
1042 DomPair &Dom = NearestDom[ParentVNI->id];
1043
1044 // Keep directly defined parent values. This is either a PHI or an
1045 // instruction in the complement range. All other copies of ParentVNI
1046 // should be eliminated.
1047 if (VNI->def == ParentVNI->def) {
1048 LLVM_DEBUG(dbgs() << "Direct complement def at " << VNI->def << '\n');
1049 Dom = DomPair(ValMBB, VNI->def);
1050 continue;
1051 }
1052 // Skip the singly mapped values. There is nothing to gain from hoisting a
1053 // single back-copy.
1054 if (Values.lookup(std::make_pair(0, ParentVNI->id)).getPointer()) {
1055 LLVM_DEBUG(dbgs() << "Single complement def at " << VNI->def << '\n');
1056 continue;
1057 }
1058
1059 if (!Dom.first) {
1060 // First time we see ParentVNI. VNI dominates itself.
1061 Dom = DomPair(ValMBB, VNI->def);
1062 } else if (Dom.first == ValMBB) {
1063 // Two defs in the same block. Pick the earlier def.
1064 if (!Dom.second.isValid() || VNI->def < Dom.second)
1065 Dom.second = VNI->def;
1066 } else {
1067 // Different basic blocks. Check if one dominates.
1069 MDT.findNearestCommonDominator(Dom.first, ValMBB);
1070 if (Near == ValMBB)
1071 // Def ValMBB dominates.
1072 Dom = DomPair(ValMBB, VNI->def);
1073 else if (Near != Dom.first)
1074 // None dominate. Hoist to common dominator, need new def.
1075 Dom = DomPair(Near, SlotIndex());
1076 Costs[ParentVNI->id] += MBFI.getBlockFreq(ValMBB);
1077 }
1078
1079 LLVM_DEBUG(dbgs() << "Multi-mapped complement " << VNI->id << '@'
1080 << VNI->def << " for parent " << ParentVNI->id << '@'
1081 << ParentVNI->def << " hoist to "
1082 << printMBBReference(*Dom.first) << ' ' << Dom.second
1083 << '\n');
1084 }
1085
1086 // Insert the hoisted copies.
1087 for (unsigned i = 0, e = Parent->getNumValNums(); i != e; ++i) {
1088 DomPair &Dom = NearestDom[i];
1089 if (!Dom.first || Dom.second.isValid())
1090 continue;
1091 // This value needs a hoisted copy inserted at the end of Dom.first.
1092 const VNInfo *ParentVNI = Parent->getValNumInfo(i);
1093 MachineBasicBlock *DefMBB = LIS.getMBBFromIndex(ParentVNI->def);
1094 // Get a less loopy dominator than Dom.first.
1095 Dom.first = findShallowDominator(Dom.first, DefMBB);
1096 if (SpillMode == SM_Speed &&
1097 MBFI.getBlockFreq(Dom.first) > Costs[ParentVNI->id]) {
1098 NotToHoistSet.insert(ParentVNI->id);
1099 continue;
1100 }
1101 SlotIndex LSP = SA.getLastSplitPoint(Dom.first);
1102 if (LSP <= ParentVNI->def) {
1103 NotToHoistSet.insert(ParentVNI->id);
1104 continue;
1105 }
1106 Dom.second = defFromParent(0, ParentVNI, LSP, *Dom.first,
1107 SA.getLastSplitPointIter(Dom.first))->def;
1108 }
1109
1110 // Remove redundant back-copies that are now known to be dominated by another
1111 // def with the same value.
1112 SmallVector<VNInfo*, 8> BackCopies;
1113 for (VNInfo *VNI : LI->valnos) {
1114 if (VNI->isUnused())
1115 continue;
1116 VNInfo *ParentVNI = Edit->getParent().getVNInfoAt(VNI->def);
1117 const DomPair &Dom = NearestDom[ParentVNI->id];
1118 if (!Dom.first || Dom.second == VNI->def ||
1119 NotToHoistSet.count(ParentVNI->id))
1120 continue;
1121 BackCopies.push_back(VNI);
1122 forceRecompute(0, *ParentVNI);
1123 }
1124
1125 // If it is not beneficial to hoist all the BackCopies, simply remove
1126 // redundant BackCopies in speed mode.
1127 if (SpillMode == SM_Speed && !NotToHoistSet.empty())
1128 computeRedundantBackCopies(NotToHoistSet, BackCopies);
1129
1130 removeBackCopies(BackCopies);
1131}
1132
1133/// transferValues - Transfer all possible values to the new live ranges.
1134/// Values that were rematerialized are left alone, they need LICalc.extend().
1135bool SplitEditor::transferValues() {
1136 bool Skipped = false;
1137 RegAssignMap::const_iterator AssignI = RegAssign.begin();
1138 for (const LiveRange::Segment &S : Edit->getParent()) {
1139 LLVM_DEBUG(dbgs() << " blit " << S << ':');
1140 VNInfo *ParentVNI = S.valno;
1141 // RegAssign has holes where RegIdx 0 should be used.
1142 SlotIndex Start = S.start;
1143 AssignI.advanceTo(Start);
1144 do {
1145 unsigned RegIdx;
1146 SlotIndex End = S.end;
1147 if (!AssignI.valid()) {
1148 RegIdx = 0;
1149 } else if (AssignI.start() <= Start) {
1150 RegIdx = AssignI.value();
1151 if (AssignI.stop() < End) {
1152 End = AssignI.stop();
1153 ++AssignI;
1154 }
1155 } else {
1156 RegIdx = 0;
1157 End = std::min(End, AssignI.start());
1158 }
1159
1160 // The interval [Start;End) is continuously mapped to RegIdx, ParentVNI.
1161 LLVM_DEBUG(dbgs() << " [" << Start << ';' << End << ")=" << RegIdx << '('
1162 << printReg(Edit->get(RegIdx)) << ')');
1163 LiveInterval &LI = LIS.getInterval(Edit->get(RegIdx));
1164
1165 // Check for a simply defined value that can be blitted directly.
1166 ValueForcePair VFP = Values.lookup(std::make_pair(RegIdx, ParentVNI->id));
1167 if (VNInfo *VNI = VFP.getPointer()) {
1168 LLVM_DEBUG(dbgs() << ':' << VNI->id);
1169 LI.addSegment(LiveInterval::Segment(Start, End, VNI));
1170 Start = End;
1171 continue;
1172 }
1173
1174 // Skip values with forced recomputation.
1175 if (VFP.getInt()) {
1176 LLVM_DEBUG(dbgs() << "(recalc)");
1177 Skipped = true;
1178 Start = End;
1179 continue;
1180 }
1181
1182 LiveIntervalCalc &LIC = getLICalc(RegIdx);
1183
1184 // This value has multiple defs in RegIdx, but it wasn't rematerialized,
1185 // so the live range is accurate. Add live-in blocks in [Start;End) to the
1186 // LiveInBlocks.
1188 SlotIndex BlockStart, BlockEnd;
1189 std::tie(BlockStart, BlockEnd) = LIS.getSlotIndexes()->getMBBRange(&*MBB);
1190
1191 // The first block may be live-in, or it may have its own def.
1192 if (Start != BlockStart) {
1193 VNInfo *VNI = LI.extendInBlock(BlockStart, std::min(BlockEnd, End));
1194 assert(VNI && "Missing def for complex mapped value");
1195 LLVM_DEBUG(dbgs() << ':' << VNI->id << "*" << printMBBReference(*MBB));
1196 // MBB has its own def. Is it also live-out?
1197 if (BlockEnd <= End)
1198 LIC.setLiveOutValue(&*MBB, VNI);
1199
1200 // Skip to the next block for live-in.
1201 ++MBB;
1202 BlockStart = BlockEnd;
1203 }
1204
1205 // Handle the live-in blocks covered by [Start;End).
1206 assert(Start <= BlockStart && "Expected live-in block");
1207 while (BlockStart < End) {
1208 LLVM_DEBUG(dbgs() << ">" << printMBBReference(*MBB));
1209 BlockEnd = LIS.getMBBEndIdx(&*MBB);
1210 if (BlockStart == ParentVNI->def) {
1211 // This block has the def of a parent PHI, so it isn't live-in.
1212 assert(ParentVNI->isPHIDef() && "Non-phi defined at block start?");
1213 VNInfo *VNI = LI.extendInBlock(BlockStart, std::min(BlockEnd, End));
1214 assert(VNI && "Missing def for complex mapped parent PHI");
1215 if (End >= BlockEnd)
1216 LIC.setLiveOutValue(&*MBB, VNI); // Live-out as well.
1217 } else {
1218 // This block needs a live-in value. The last block covered may not
1219 // be live-out.
1220 if (End < BlockEnd)
1221 LIC.addLiveInBlock(LI, MDT[&*MBB], End);
1222 else {
1223 // Live-through, and we don't know the value.
1224 LIC.addLiveInBlock(LI, MDT[&*MBB]);
1225 LIC.setLiveOutValue(&*MBB, nullptr);
1226 }
1227 }
1228 BlockStart = BlockEnd;
1229 ++MBB;
1230 }
1231 Start = End;
1232 } while (Start != S.end);
1233 LLVM_DEBUG(dbgs() << '\n');
1234 }
1235
1236 LICalc[0].calculateValues();
1237 if (SpillMode)
1238 LICalc[1].calculateValues();
1239
1240 return Skipped;
1241}
1242
1244 const LiveRange::Segment *Seg = LR.getSegmentContaining(Def);
1245 if (Seg == nullptr)
1246 return true;
1247 if (Seg->end != Def.getDeadSlot())
1248 return false;
1249 // This is a dead PHI. Remove it.
1250 LR.removeSegment(*Seg, true);
1251 return true;
1252}
1253
1254void SplitEditor::extendPHIRange(MachineBasicBlock &B, LiveIntervalCalc &LIC,
1255 LiveRange &LR, LaneBitmask LM,
1256 ArrayRef<SlotIndex> Undefs) {
1257 for (MachineBasicBlock *P : B.predecessors()) {
1258 SlotIndex End = LIS.getMBBEndIdx(P);
1259 SlotIndex LastUse = End.getPrevSlot();
1260 // The predecessor may not have a live-out value. That is OK, like an
1261 // undef PHI operand.
1262 const LiveInterval &PLI = Edit->getParent();
1263 // Need the cast because the inputs to ?: would otherwise be deemed
1264 // "incompatible": SubRange vs LiveInterval.
1265 const LiveRange &PSR = !LM.all() ? getSubRangeForMaskExact(LM, PLI)
1266 : static_cast<const LiveRange &>(PLI);
1267 if (PSR.liveAt(LastUse))
1268 LIC.extend(LR, End, /*PhysReg=*/0, Undefs);
1269 }
1270}
1271
1272void SplitEditor::extendPHIKillRanges() {
1273 // Extend live ranges to be live-out for successor PHI values.
1274
1275 // Visit each PHI def slot in the parent live interval. If the def is dead,
1276 // remove it. Otherwise, extend the live interval to reach the end indexes
1277 // of all predecessor blocks.
1278
1279 const LiveInterval &ParentLI = Edit->getParent();
1280 for (const VNInfo *V : ParentLI.valnos) {
1281 if (V->isUnused() || !V->isPHIDef())
1282 continue;
1283
1284 unsigned RegIdx = RegAssign.lookup(V->def);
1285 LiveInterval &LI = LIS.getInterval(Edit->get(RegIdx));
1286 LiveIntervalCalc &LIC = getLICalc(RegIdx);
1287 MachineBasicBlock &B = *LIS.getMBBFromIndex(V->def);
1288 if (!removeDeadSegment(V->def, LI))
1289 extendPHIRange(B, LIC, LI, LaneBitmask::getAll(), /*Undefs=*/{});
1290 }
1291
1293 LiveIntervalCalc SubLIC;
1294
1295 for (const LiveInterval::SubRange &PS : ParentLI.subranges()) {
1296 for (const VNInfo *V : PS.valnos) {
1297 if (V->isUnused() || !V->isPHIDef())
1298 continue;
1299 unsigned RegIdx = RegAssign.lookup(V->def);
1300 LiveInterval &LI = LIS.getInterval(Edit->get(RegIdx));
1301 LiveInterval::SubRange &S = getSubRangeForMaskExact(PS.LaneMask, LI);
1302 if (removeDeadSegment(V->def, S))
1303 continue;
1304
1305 MachineBasicBlock &B = *LIS.getMBBFromIndex(V->def);
1306 SubLIC.reset(&VRM.getMachineFunction(), LIS.getSlotIndexes(), &MDT,
1307 &LIS.getVNInfoAllocator());
1308 Undefs.clear();
1309 LI.computeSubRangeUndefs(Undefs, PS.LaneMask, MRI, *LIS.getSlotIndexes());
1310 extendPHIRange(B, SubLIC, S, PS.LaneMask, Undefs);
1311 }
1312 }
1313}
1314
1315/// rewriteAssigned - Rewrite all uses of Edit->getReg().
1316void SplitEditor::rewriteAssigned(bool ExtendRanges) {
1317 struct ExtPoint {
1318 ExtPoint(const MachineOperand &O, unsigned R, SlotIndex N)
1319 : MO(O), RegIdx(R), Next(N) {}
1320
1321 MachineOperand MO;
1322 unsigned RegIdx;
1323 SlotIndex Next;
1324 };
1325
1326 SmallVector<ExtPoint,4> ExtPoints;
1327
1328 for (MachineOperand &MO :
1329 llvm::make_early_inc_range(MRI.reg_operands(Edit->getReg()))) {
1330 MachineInstr *MI = MO.getParent();
1331 // LiveDebugVariables should have handled all DBG_VALUE instructions.
1332 if (MI->isDebugValue()) {
1333 LLVM_DEBUG(dbgs() << "Zapping " << *MI);
1334 MO.setReg(0);
1335 continue;
1336 }
1337
1338 // <undef> operands don't really read the register, so it doesn't matter
1339 // which register we choose. When the use operand is tied to a def, we must
1340 // use the same register as the def, so just do that always.
1342 if (MO.isDef() || MO.isUndef())
1343 Idx = Idx.getRegSlot(MO.isEarlyClobber());
1344
1345 // Rewrite to the mapped register at Idx.
1346 unsigned RegIdx = RegAssign.lookup(Idx);
1347 LiveInterval &LI = LIS.getInterval(Edit->get(RegIdx));
1348 MO.setReg(LI.reg());
1349 LLVM_DEBUG(dbgs() << " rewr " << printMBBReference(*MI->getParent())
1350 << '\t' << Idx << ':' << RegIdx << '\t' << *MI);
1351
1352 // Extend liveness to Idx if the instruction reads reg.
1353 if (!ExtendRanges || MO.isUndef())
1354 continue;
1355
1356 // Skip instructions that don't read Reg.
1357 if (MO.isDef()) {
1358 if (!MO.getSubReg() && !MO.isEarlyClobber())
1359 continue;
1360 // We may want to extend a live range for a partial redef, or for a use
1361 // tied to an early clobber.
1362 if (!Edit->getParent().liveAt(Idx.getPrevSlot()))
1363 continue;
1364 } else {
1365 assert(MO.isUse());
1366 bool IsEarlyClobber = false;
1367 if (MO.isTied()) {
1368 // We want to extend a live range into `e` slot rather than `r` slot if
1369 // tied-def is early clobber, because the `e` slot already contained
1370 // in the live range of early-clobber tied-def operand, give an example
1371 // here:
1372 // 0 %0 = ...
1373 // 16 early-clobber %0 = Op %0 (tied-def 0), ...
1374 // 32 ... = Op %0
1375 // Before extend:
1376 // %0 = [0r, 0d) [16e, 32d)
1377 // The point we want to extend is 0d to 16e not 16r in this case, but if
1378 // we use 16r here we will extend nothing because that already contained
1379 // in [16e, 32d).
1380 unsigned OpIdx = MO.getOperandNo();
1381 unsigned DefOpIdx = MI->findTiedOperandIdx(OpIdx);
1382 const MachineOperand &DefOp = MI->getOperand(DefOpIdx);
1383 IsEarlyClobber = DefOp.isEarlyClobber();
1384 }
1385
1386 Idx = Idx.getRegSlot(IsEarlyClobber);
1387 }
1388
1389 SlotIndex Next = Idx;
1390 if (LI.hasSubRanges()) {
1391 // We have to delay extending subranges until we have seen all operands
1392 // defining the register. This is because a <def,read-undef> operand
1393 // will create an "undef" point, and we cannot extend any subranges
1394 // until all of them have been accounted for.
1395 if (MO.isUse())
1396 ExtPoints.push_back(ExtPoint(MO, RegIdx, Next));
1397 } else {
1398 LiveIntervalCalc &LIC = getLICalc(RegIdx);
1399 LIC.extend(LI, Next, 0, ArrayRef<SlotIndex>());
1400 }
1401 }
1402
1403 for (ExtPoint &EP : ExtPoints) {
1404 LiveInterval &LI = LIS.getInterval(Edit->get(EP.RegIdx));
1405 assert(LI.hasSubRanges());
1406
1407 LiveIntervalCalc SubLIC;
1408 Register Reg = EP.MO.getReg(), Sub = EP.MO.getSubReg();
1409 LaneBitmask LM = Sub != 0 ? TRI.getSubRegIndexLaneMask(Sub)
1410 : MRI.getMaxLaneMaskForVReg(Reg);
1411 for (LiveInterval::SubRange &S : LI.subranges()) {
1412 if ((S.LaneMask & LM).none())
1413 continue;
1414 // The problem here can be that the new register may have been created
1415 // for a partially defined original register. For example:
1416 // %0:subreg_hireg<def,read-undef> = ...
1417 // ...
1418 // %1 = COPY %0
1419 if (S.empty())
1420 continue;
1421 SubLIC.reset(&VRM.getMachineFunction(), LIS.getSlotIndexes(), &MDT,
1422 &LIS.getVNInfoAllocator());
1424 LI.computeSubRangeUndefs(Undefs, S.LaneMask, MRI, *LIS.getSlotIndexes());
1425 SubLIC.extend(S, EP.Next, 0, Undefs);
1426 }
1427 }
1428
1429 for (Register R : *Edit) {
1430 LiveInterval &LI = LIS.getInterval(R);
1431 if (!LI.hasSubRanges())
1432 continue;
1433 LI.clear();
1436 }
1437}
1438
1439void SplitEditor::deleteRematVictims() {
1441 for (const Register &R : *Edit) {
1442 LiveInterval *LI = &LIS.getInterval(R);
1443 for (const LiveRange::Segment &S : LI->segments) {
1444 // Dead defs end at the dead slot.
1445 if (S.end != S.valno->def.getDeadSlot())
1446 continue;
1447 if (S.valno->isPHIDef())
1448 continue;
1450 assert(MI && "Missing instruction for dead def");
1451 MI->addRegisterDead(LI->reg(), &TRI);
1452
1453 if (!MI->allDefsAreDead())
1454 continue;
1455
1456 LLVM_DEBUG(dbgs() << "All defs dead: " << *MI);
1457 Dead.push_back(MI);
1458 }
1459 }
1460
1461 if (Dead.empty())
1462 return;
1463
1464 Edit->eliminateDeadDefs(Dead, {});
1465}
1466
1467void SplitEditor::forceRecomputeVNI(const VNInfo &ParentVNI) {
1468 // Fast-path for common case.
1469 if (!ParentVNI.isPHIDef()) {
1470 for (unsigned I = 0, E = Edit->size(); I != E; ++I)
1471 forceRecompute(I, ParentVNI);
1472 return;
1473 }
1474
1475 // Trace value through phis.
1476 SmallPtrSet<const VNInfo *, 8> Visited; ///< whether VNI was/is in worklist.
1478 Visited.insert(&ParentVNI);
1479 WorkList.push_back(&ParentVNI);
1480
1481 const LiveInterval &ParentLI = Edit->getParent();
1482 const SlotIndexes &Indexes = *LIS.getSlotIndexes();
1483 do {
1484 const VNInfo &VNI = *WorkList.back();
1485 WorkList.pop_back();
1486 for (unsigned I = 0, E = Edit->size(); I != E; ++I)
1487 forceRecompute(I, VNI);
1488 if (!VNI.isPHIDef())
1489 continue;
1490
1491 MachineBasicBlock &MBB = *Indexes.getMBBFromIndex(VNI.def);
1492 for (const MachineBasicBlock *Pred : MBB.predecessors()) {
1493 SlotIndex PredEnd = Indexes.getMBBEndIdx(Pred);
1494 VNInfo *PredVNI = ParentLI.getVNInfoBefore(PredEnd);
1495 assert(PredVNI && "Value available in PhiVNI predecessor");
1496 if (Visited.insert(PredVNI).second)
1497 WorkList.push_back(PredVNI);
1498 }
1499 } while(!WorkList.empty());
1500}
1501
1503 ++NumFinished;
1504
1505 // At this point, the live intervals in Edit contain VNInfos corresponding to
1506 // the inserted copies.
1507
1508 // Add the original defs from the parent interval.
1509 for (const VNInfo *ParentVNI : Edit->getParent().valnos) {
1510 if (ParentVNI->isUnused())
1511 continue;
1512 unsigned RegIdx = RegAssign.lookup(ParentVNI->def);
1513 defValue(RegIdx, ParentVNI, ParentVNI->def, true);
1514
1515 // Force rematted values to be recomputed everywhere.
1516 // The new live ranges may be truncated.
1517 if (Edit->didRematerialize(ParentVNI))
1518 forceRecomputeVNI(*ParentVNI);
1519 }
1520
1521 // Hoist back-copies to the complement interval when in spill mode.
1522 switch (SpillMode) {
1523 case SM_Partition:
1524 // Leave all back-copies as is.
1525 break;
1526 case SM_Size:
1527 case SM_Speed:
1528 // hoistCopies will behave differently between size and speed.
1529 hoistCopies();
1530 }
1531
1532 // Transfer the simply mapped values, check if any are skipped.
1533 bool Skipped = transferValues();
1534
1535 // Rewrite virtual registers, possibly extending ranges.
1536 rewriteAssigned(Skipped);
1537
1538 if (Skipped)
1539 extendPHIKillRanges();
1540 else
1541 ++NumSimple;
1542
1543 // Delete defs that were rematted everywhere.
1544 if (Skipped)
1545 deleteRematVictims();
1546
1547 // Get rid of unused values and set phi-kill flags.
1548 for (Register Reg : *Edit) {
1549 LiveInterval &LI = LIS.getInterval(Reg);
1551 LI.RenumberValues();
1552 }
1553
1554 // Provide a reverse mapping from original indices to Edit ranges.
1555 if (LRMap) {
1556 auto Seq = llvm::seq<unsigned>(0, Edit->size());
1557 LRMap->assign(Seq.begin(), Seq.end());
1558 }
1559
1560 // Now check if any registers were separated into multiple components.
1561 ConnectedVNInfoEqClasses ConEQ(LIS);
1562 for (unsigned i = 0, e = Edit->size(); i != e; ++i) {
1563 // Don't use iterators, they are invalidated by create() below.
1564 Register VReg = Edit->get(i);
1565 LiveInterval &LI = LIS.getInterval(VReg);
1567 LIS.splitSeparateComponents(LI, SplitLIs);
1568 Register Original = VRM.getOriginal(VReg);
1569 for (LiveInterval *SplitLI : SplitLIs)
1570 VRM.setIsSplitFromReg(SplitLI->reg(), Original);
1571
1572 // The new intervals all map back to i.
1573 if (LRMap)
1574 LRMap->resize(Edit->size(), i);
1575 }
1576
1577 // Calculate spill weight and allocation hints for new intervals.
1578 Edit->calculateRegClassAndHint(VRM.getMachineFunction(), VRAI);
1579
1580 assert(!LRMap || LRMap->size() == Edit->size());
1581}
1582
1583//===----------------------------------------------------------------------===//
1584// Single Block Splitting
1585//===----------------------------------------------------------------------===//
1586
1588 bool SingleInstrs) const {
1589 // Always split for multiple instructions.
1590 if (!BI.isOneInstr())
1591 return true;
1592 // Don't split for single instructions unless explicitly requested.
1593 if (!SingleInstrs)
1594 return false;
1595 // Splitting a live-through range always makes progress.
1596 if (BI.LiveIn && BI.LiveOut)
1597 return true;
1598 // No point in isolating a copy. It has no register class constraints.
1600 bool copyLike = TII.isCopyInstr(*MI) || MI->isSubregToReg();
1601 if (copyLike)
1602 return false;
1603 // Finally, don't isolate an end point that was created by earlier splits.
1604 return isOriginalEndpoint(BI.FirstInstr);
1605}
1606
1608 openIntv();
1609 SlotIndex LastSplitPoint = SA.getLastSplitPoint(BI.MBB);
1610 SlotIndex SegStart = enterIntvBefore(std::min(BI.FirstInstr,
1611 LastSplitPoint));
1612 if (!BI.LiveOut || BI.LastInstr < LastSplitPoint) {
1613 useIntv(SegStart, leaveIntvAfter(BI.LastInstr));
1614 } else {
1615 // The last use is after the last valid split point.
1616 SlotIndex SegStop = leaveIntvBefore(LastSplitPoint);
1617 useIntv(SegStart, SegStop);
1618 overlapIntv(SegStop, BI.LastInstr);
1619 }
1620}
1621
1622//===----------------------------------------------------------------------===//
1623// Global Live Range Splitting Support
1624//===----------------------------------------------------------------------===//
1625
1626// These methods support a method of global live range splitting that uses a
1627// global algorithm to decide intervals for CFG edges. They will insert split
1628// points and color intervals in basic blocks while avoiding interference.
1629//
1630// Note that splitSingleBlock is also useful for blocks where both CFG edges
1631// are on the stack.
1632
1634 unsigned IntvIn, SlotIndex LeaveBefore,
1635 unsigned IntvOut, SlotIndex EnterAfter){
1636 SlotIndex Start, Stop;
1637 std::tie(Start, Stop) = LIS.getSlotIndexes()->getMBBRange(MBBNum);
1638
1639 LLVM_DEBUG(dbgs() << "%bb." << MBBNum << " [" << Start << ';' << Stop
1640 << ") intf " << LeaveBefore << '-' << EnterAfter
1641 << ", live-through " << IntvIn << " -> " << IntvOut);
1642
1643 assert((IntvIn || IntvOut) && "Use splitSingleBlock for isolated blocks");
1644
1645 assert((!LeaveBefore || LeaveBefore < Stop) && "Interference after block");
1646 assert((!IntvIn || !LeaveBefore || LeaveBefore > Start) && "Impossible intf");
1647 assert((!EnterAfter || EnterAfter >= Start) && "Interference before block");
1648
1650
1651 if (!IntvOut) {
1652 LLVM_DEBUG(dbgs() << ", spill on entry.\n");
1653 //
1654 // <<<<<<<<< Possible LeaveBefore interference.
1655 // |-----------| Live through.
1656 // -____________ Spill on entry.
1657 //
1658 selectIntv(IntvIn);
1660 assert((!LeaveBefore || Idx <= LeaveBefore) && "Interference");
1661 (void)Idx;
1662 return;
1663 }
1664
1665 if (!IntvIn) {
1666 LLVM_DEBUG(dbgs() << ", reload on exit.\n");
1667 //
1668 // >>>>>>> Possible EnterAfter interference.
1669 // |-----------| Live through.
1670 // ___________-- Reload on exit.
1671 //
1672 selectIntv(IntvOut);
1674 assert((!EnterAfter || Idx >= EnterAfter) && "Interference");
1675 (void)Idx;
1676 return;
1677 }
1678
1679 if (IntvIn == IntvOut && !LeaveBefore && !EnterAfter) {
1680 LLVM_DEBUG(dbgs() << ", straight through.\n");
1681 //
1682 // |-----------| Live through.
1683 // ------------- Straight through, same intv, no interference.
1684 //
1685 selectIntv(IntvOut);
1686 useIntv(Start, Stop);
1687 return;
1688 }
1689
1690 // We cannot legally insert splits after LSP.
1691 SlotIndex LSP = SA.getLastSplitPoint(MBBNum);
1692 assert((!IntvOut || !EnterAfter || EnterAfter < LSP) && "Impossible intf");
1693
1694 if (IntvIn != IntvOut && (!LeaveBefore || !EnterAfter ||
1695 LeaveBefore.getBaseIndex() > EnterAfter.getBoundaryIndex())) {
1696 LLVM_DEBUG(dbgs() << ", switch avoiding interference.\n");
1697 //
1698 // >>>> <<<< Non-overlapping EnterAfter/LeaveBefore interference.
1699 // |-----------| Live through.
1700 // ------======= Switch intervals between interference.
1701 //
1702 selectIntv(IntvOut);
1703 SlotIndex Idx;
1704 if (LeaveBefore && LeaveBefore < LSP) {
1705 Idx = enterIntvBefore(LeaveBefore);
1706 useIntv(Idx, Stop);
1707 } else {
1709 }
1710 selectIntv(IntvIn);
1711 useIntv(Start, Idx);
1712 assert((!LeaveBefore || Idx <= LeaveBefore) && "Interference");
1713 assert((!EnterAfter || Idx >= EnterAfter) && "Interference");
1714 return;
1715 }
1716
1717 LLVM_DEBUG(dbgs() << ", create local intv for interference.\n");
1718 //
1719 // >>><><><><<<< Overlapping EnterAfter/LeaveBefore interference.
1720 // |-----------| Live through.
1721 // ==---------== Switch intervals before/after interference.
1722 //
1723 assert(LeaveBefore <= EnterAfter && "Missed case");
1724
1725 selectIntv(IntvOut);
1726 SlotIndex Idx = enterIntvAfter(EnterAfter);
1727 useIntv(Idx, Stop);
1728 assert((!EnterAfter || Idx >= EnterAfter) && "Interference");
1729
1730 selectIntv(IntvIn);
1731 Idx = leaveIntvBefore(LeaveBefore);
1732 useIntv(Start, Idx);
1733 assert((!LeaveBefore || Idx <= LeaveBefore) && "Interference");
1734}
1735
1737 unsigned IntvIn, SlotIndex LeaveBefore) {
1738 SlotIndex Start, Stop;
1739 std::tie(Start, Stop) = LIS.getSlotIndexes()->getMBBRange(BI.MBB);
1740
1741 LLVM_DEBUG(dbgs() << printMBBReference(*BI.MBB) << " [" << Start << ';'
1742 << Stop << "), uses " << BI.FirstInstr << '-'
1743 << BI.LastInstr << ", reg-in " << IntvIn
1744 << ", leave before " << LeaveBefore
1745 << (BI.LiveOut ? ", stack-out" : ", killed in block"));
1746
1747 assert(IntvIn && "Must have register in");
1748 assert(BI.LiveIn && "Must be live-in");
1749 assert((!LeaveBefore || LeaveBefore > Start) && "Bad interference");
1750
1751 if (!BI.LiveOut && (!LeaveBefore || LeaveBefore >= BI.LastInstr)) {
1752 LLVM_DEBUG(dbgs() << " before interference.\n");
1753 //
1754 // <<< Interference after kill.
1755 // |---o---x | Killed in block.
1756 // ========= Use IntvIn everywhere.
1757 //
1758 selectIntv(IntvIn);
1759 useIntv(Start, BI.LastInstr);
1760 return;
1761 }
1762
1763 SlotIndex LSP = SA.getLastSplitPoint(BI.MBB);
1764
1765 if (!LeaveBefore || LeaveBefore > BI.LastInstr.getBoundaryIndex()) {
1766 //
1767 // <<< Possible interference after last use.
1768 // |---o---o---| Live-out on stack.
1769 // =========____ Leave IntvIn after last use.
1770 //
1771 // < Interference after last use.
1772 // |---o---o--o| Live-out on stack, late last use.
1773 // ============ Copy to stack after LSP, overlap IntvIn.
1774 // \_____ Stack interval is live-out.
1775 //
1776 if (BI.LastInstr < LSP) {
1777 LLVM_DEBUG(dbgs() << ", spill after last use before interference.\n");
1778 selectIntv(IntvIn);
1780 useIntv(Start, Idx);
1781 assert((!LeaveBefore || Idx <= LeaveBefore) && "Interference");
1782 } else {
1783 LLVM_DEBUG(dbgs() << ", spill before last split point.\n");
1784 selectIntv(IntvIn);
1787 useIntv(Start, Idx);
1788 assert((!LeaveBefore || Idx <= LeaveBefore) && "Interference");
1789 }
1790 return;
1791 }
1792
1793 // The interference is overlapping somewhere we wanted to use IntvIn. That
1794 // means we need to create a local interval that can be allocated a
1795 // different register.
1796 unsigned LocalIntv = openIntv();
1797 (void)LocalIntv;
1798 LLVM_DEBUG(dbgs() << ", creating local interval " << LocalIntv << ".\n");
1799
1800 if (!BI.LiveOut || BI.LastInstr < LSP) {
1801 //
1802 // <<<<<<< Interference overlapping uses.
1803 // |---o---o---| Live-out on stack.
1804 // =====----____ Leave IntvIn before interference, then spill.
1805 //
1807 SlotIndex From = enterIntvBefore(LeaveBefore);
1808 useIntv(From, To);
1809 selectIntv(IntvIn);
1810 useIntv(Start, From);
1811 assert((!LeaveBefore || From <= LeaveBefore) && "Interference");
1812 return;
1813 }
1814
1815 // <<<<<<< Interference overlapping uses.
1816 // |---o---o--o| Live-out on stack, late last use.
1817 // =====------- Copy to stack before LSP, overlap LocalIntv.
1818 // \_____ Stack interval is live-out.
1819 //
1820 SlotIndex To = leaveIntvBefore(LSP);
1821 overlapIntv(To, BI.LastInstr);
1822 SlotIndex From = enterIntvBefore(std::min(To, LeaveBefore));
1823 useIntv(From, To);
1824 selectIntv(IntvIn);
1825 useIntv(Start, From);
1826 assert((!LeaveBefore || From <= LeaveBefore) && "Interference");
1827}
1828
1830 unsigned IntvOut, SlotIndex EnterAfter) {
1831 SlotIndex Start, Stop;
1832 std::tie(Start, Stop) = LIS.getSlotIndexes()->getMBBRange(BI.MBB);
1833
1834 LLVM_DEBUG(dbgs() << printMBBReference(*BI.MBB) << " [" << Start << ';'
1835 << Stop << "), uses " << BI.FirstInstr << '-'
1836 << BI.LastInstr << ", reg-out " << IntvOut
1837 << ", enter after " << EnterAfter
1838 << (BI.LiveIn ? ", stack-in" : ", defined in block"));
1839
1840 SlotIndex LSP = SA.getLastSplitPoint(BI.MBB);
1841
1842 assert(IntvOut && "Must have register out");
1843 assert(BI.LiveOut && "Must be live-out");
1844 assert((!EnterAfter || EnterAfter < LSP) && "Bad interference");
1845
1846 if (!BI.LiveIn && (!EnterAfter || EnterAfter <= BI.FirstInstr)) {
1847 LLVM_DEBUG(dbgs() << " after interference.\n");
1848 //
1849 // >>>> Interference before def.
1850 // | o---o---| Defined in block.
1851 // ========= Use IntvOut everywhere.
1852 //
1853 selectIntv(IntvOut);
1854 useIntv(BI.FirstInstr, Stop);
1855 return;
1856 }
1857
1858 if (!EnterAfter || EnterAfter < BI.FirstInstr.getBaseIndex()) {
1859 LLVM_DEBUG(dbgs() << ", reload after interference.\n");
1860 //
1861 // >>>> Interference before def.
1862 // |---o---o---| Live-through, stack-in.
1863 // ____========= Enter IntvOut before first use.
1864 //
1865 selectIntv(IntvOut);
1866 SlotIndex Idx = enterIntvBefore(std::min(LSP, BI.FirstInstr));
1867 useIntv(Idx, Stop);
1868 assert((!EnterAfter || Idx >= EnterAfter) && "Interference");
1869 return;
1870 }
1871
1872 // The interference is overlapping somewhere we wanted to use IntvOut. That
1873 // means we need to create a local interval that can be allocated a
1874 // different register.
1875 LLVM_DEBUG(dbgs() << ", interference overlaps uses.\n");
1876 //
1877 // >>>>>>> Interference overlapping uses.
1878 // |---o---o---| Live-through, stack-in.
1879 // ____---====== Create local interval for interference range.
1880 //
1881 selectIntv(IntvOut);
1882 SlotIndex Idx = enterIntvAfter(EnterAfter);
1883 useIntv(Idx, Stop);
1884 assert((!EnterAfter || Idx >= EnterAfter) && "Interference");
1885
1886 openIntv();
1887 SlotIndex From = enterIntvBefore(std::min(Idx, BI.FirstInstr));
1888 useIntv(From, Idx);
1889}
1890
1892 OS << "{" << printMBBReference(*MBB) << ", "
1893 << "uses " << FirstInstr << " to " << LastInstr << ", "
1894 << "1st def " << FirstDef << ", "
1895 << (LiveIn ? "live in" : "dead in") << ", "
1896 << (LiveOut ? "live out" : "dead out") << "}";
1897}
1898
1900 print(dbgs());
1901 dbgs() << "\n";
1902}
unsigned const MachineRegisterInfo * MRI
MachineInstrBuilder MachineInstrBuilder & DefMI
aarch64 promote const
MachineBasicBlock & MBB
MachineBasicBlock MachineBasicBlock::iterator MBBI
This file defines the BumpPtrAllocator interface.
BlockVerifier::State From
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:622
Returns the sub type a function will return at a given Idx Should correspond to the result type of an ExtractValue instruction executed with just that one unsigned Idx
#define LLVM_DEBUG(...)
Definition: Debug.h:106
bool End
Definition: ELF_riscv.cpp:480
const HexagonInstrInfo * TII
Hexagon Hardware Loops
IRTranslator LLVM IR MI
#define I(x, y, z)
Definition: MD5.cpp:58
unsigned const TargetRegisterInfo * TRI
#define P(N)
Basic Register Allocator
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
SI Lower i1 Copies
This file contains some templates that are useful if you are working with the STL at all.
raw_pwrite_stream & OS
LiveInterval::SubRange & getSubRangeForMaskExact(LaneBitmask LM, LiveInterval &LI)
Definition: SplitKit.cpp:407
static bool hasTiedUseOf(MachineInstr &MI, unsigned Reg)
Definition: SplitKit.cpp:817
static bool removeDeadSegment(SlotIndex Def, LiveRange &LR)
Definition: SplitKit.cpp:1243
auto & getSubrangeImpl(LaneBitmask LM, T &LI)
Find a subrange corresponding to the exact lane mask LM in the live interval LI.
Definition: SplitKit.cpp:400
const LiveInterval::SubRange & getSubRangeForMask(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:421
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:166
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: ArrayRef.h:41
void resize(unsigned N, bool t=false)
resize - Grow or shrink the bitvector.
Definition: BitVector.h:341
void clear()
clear - Removes all bits from the bitvector.
Definition: BitVector.h:335
BitVector & set()
Definition: BitVector.h:351
Allocate memory in an ever growing pool, as if by bump-pointer.
Definition: Allocator.h:66
ConnectedVNInfoEqClasses - Helper class that can divide VNInfos in a LiveInterval into equivalence cl...
A debug info location.
Definition: DebugLoc.h:33
ValueT lookup(const_arg_type_t< KeyT > Val) const
lookup - Return the entry for the specified key, or a default constructed value if no such entry exis...
Definition: DenseMap.h:194
std::pair< iterator, bool > insert(const std::pair< KeyT, ValueT > &KV)
Definition: DenseMap.h:211
Implements a dense probed hash-table based set.
Definition: DenseSet.h:278
Base class for the actual dominator tree node.
NodeT * getBlock() const
NodeT * findNearestCommonDominator(NodeT *A, NodeT *B) const
Find nearest common dominator basic block for basic block A and B.
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
const_iterator begin() const
Definition: IntervalMap.h:1146
void insert(KeyT a, KeyT b, ValT y)
insert - Add a mapping of [a;b] to y, coalesce with adjacent intervals.
Definition: IntervalMap.h:1129
ValT lookup(KeyT x, ValT NotFound=ValT()) const
lookup - Return the mapped value at x or NotFound.
Definition: IntervalMap.h:1119
bool empty() const
empty - Return true when no intervals are mapped.
Definition: IntervalMap.h:1101
void clear()
clear - Remove all entries.
Definition: IntervalMap.h:1330
A live range for subregisters.
Definition: LiveInterval.h:694
LiveInterval - This class represents the liveness of a register, or stack slot.
Definition: LiveInterval.h:687
void removeEmptySubRanges()
Removes all subranges without any segments (subranges without segments are not considered valid and s...
Register reg() const
Definition: LiveInterval.h:718
bool hasSubRanges() const
Returns true if subregister liveness information is available.
Definition: LiveInterval.h:810
iterator_range< subrange_iterator > subranges()
Definition: LiveInterval.h:782
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.
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 ...
SlotIndex getMBBStartIdx(const MachineBasicBlock *mbb) const
Return the first index in the given basic block.
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)
VNInfo::Allocator & getVNInfoAllocator()
SlotIndex getMBBEndIdx(const MachineBasicBlock *mbb) const
Return the last index in the given basic block.
LiveInterval & getInterval(Register Reg)
void removeVRegDefAt(LiveInterval &LI, SlotIndex Pos)
Remove value number and related live segments of LI and its subranges that start at position Pos.
void constructMainRangeFromSubranges(LiveInterval &LI)
For live interval LI with correct SubRanges construct matching information for the main live range.
void splitSeparateComponents(LiveInterval &LI, SmallVectorImpl< LiveInterval * > &SplitLIs)
Split separate components in LiveInterval LI into separate intervals.
MachineBasicBlock * getMBBFromIndex(SlotIndex index) const
bool isLiveInToMBB(const LiveRange &LR, const MachineBasicBlock *mbb) const
void addLiveInBlock(LiveRange &LR, MachineDomTreeNode *DomNode, SlotIndex Kill=SlotIndex())
addLiveInBlock - Add a block with an unknown live-in value.
void reset(const MachineFunction *mf, SlotIndexes *SI, MachineDominatorTree *MDT, VNInfo::Allocator *VNIA)
reset - Prepare caches for a new set of non-overlapping live ranges.
void extend(LiveRange &LR, SlotIndex Use, unsigned PhysReg, ArrayRef< SlotIndex > Undefs)
Extend the live range of LR to reach Use.
void calculateValues()
calculateValues - Calculate the value that will be live-in to each block added with addLiveInBlock.
void setLiveOutValue(MachineBasicBlock *MBB, VNInfo *VNI)
setLiveOutValue - Indicate that VNI is live out from MBB.
bool empty() const
unsigned size() const
Register get(unsigned idx) const
LiveInterval & createEmptyInterval()
create - Create a new register with the same class and original slot as parent.
const LiveInterval & getParent() const
Register getReg() const
SlotIndex rematerializeAt(MachineBasicBlock &MBB, MachineBasicBlock::iterator MI, Register DestReg, const Remat &RM, const TargetRegisterInfo &, bool Late=false, unsigned SubIdx=0, MachineInstr *ReplaceIndexMI=nullptr)
rematerializeAt - Rematerialize RM.ParentVNI into DestReg by inserting an instruction into MBB before...
bool canRematerializeAt(Remat &RM, VNInfo *OrigVNI, SlotIndex UseIdx, bool cheapAsAMove)
canRematerializeAt - Determine if ParentVNI can be rematerialized at UseIdx.
bool didRematerialize(const VNInfo *ParentVNI) const
didRematerialize - Return true if ParentVNI was rematerialized anywhere.
bool anyRematerializable()
anyRematerializable - Return true if any parent values may be rematerializable.
This class represents the liveness of a register, stack slot, etc.
Definition: LiveInterval.h:157
VNInfo * getValNumInfo(unsigned ValNo)
getValNumInfo - Returns pointer to the specified val#.
Definition: LiveInterval.h:317
iterator addSegment(Segment S)
Add the specified Segment to this range, merging segments as appropriate.
const Segment * getSegmentContaining(SlotIndex Idx) const
Return the segment that contains the specified index, or null if there is none.
Definition: LiveInterval.h:408
bool liveAt(SlotIndex index) const
Definition: LiveInterval.h:401
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,...
Definition: LiveInterval.h:271
bool empty() const
Definition: LiveInterval.h:382
void RenumberValues()
RenumberValues - Renumber all values in order of appearance and remove unused values.
iterator end()
Definition: LiveInterval.h:216
VNInfo * getVNInfoBefore(SlotIndex Idx) const
getVNInfoBefore - Return the VNInfo that is live up to but not necessarily including Idx,...
Definition: LiveInterval.h:429
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
Definition: LiveInterval.h:313
iterator begin()
Definition: LiveInterval.h:215
Segments segments
Definition: LiveInterval.h:203
VNInfoList valnos
Definition: LiveInterval.h:204
VNInfo * getNextValue(SlotIndex Def, VNInfo::Allocator &VNInfoAllocator)
getNextValue - Create a new value number and return it.
Definition: LiveInterval.h:331
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.
Definition: LiveInterval.h:421
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.
LoopT * getLoopFor(const BlockT *BB) const
Return the inner most loop that BB lives in.
Represents a single loop in the control flow graph.
Definition: LoopInfo.h:39
Describe properties that are true of each instruction in the target description file.
Definition: MCInstrDesc.h:198
const MCInstrDesc & get(unsigned Opcode) const
Return the machine instruction descriptor that corresponds to the specified instruction opcode.
Definition: MCInstrInfo.h:63
int getNumber() const
MachineBasicBlocks are uniquely numbered at the function level, unless they're not in a MachineFuncti...
iterator SkipPHIsLabelsAndDebug(iterator I, Register Reg=Register(), bool SkipPseudoOp=true)
Return the first instruction in MBB after I that is not a PHI, label or debug.
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< succ_iterator > successors()
iterator_range< pred_iterator > predecessors()
MachineBlockFrequencyInfo pass uses BlockFrequencyInfoImpl implementation to estimate machine basic b...
BlockFrequency getBlockFreq(const MachineBasicBlock *MBB) const
getblockFreq - Return block frequency.
DominatorTree Class - Concrete subclass of DominatorTreeBase that is used to compute a normal dominat...
bool dominates(const MachineInstr *A, const MachineInstr *B) const
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
MachineBasicBlock * getBlockNumbered(unsigned N) const
getBlockNumbered - MachineBasicBlocks are automatically numbered when they are inserted into the mach...
unsigned getNumBlockIDs() const
getNumBlockIDs - Return the number of MBB ID's allocated.
BasicBlockListType::const_iterator const_iterator
const MachineInstrBuilder & addReg(Register RegNo, unsigned flags=0, unsigned SubReg=0) const
Add a new virtual register operand.
Representation of each machine instruction.
Definition: MachineInstr.h:69
void bundleWithPred()
Bundle this instruction with its predecessor.
iterator_range< mop_iterator > defs()
Returns a range over all explicit operands that are register definitions.
Definition: MachineInstr.h:728
MachineOperand class - Representation of each machine instruction operand.
bool isEarlyClobber() const
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
Wrapper class representing virtual and physical registers.
Definition: Register.h:19
SlotIndex - An opaque wrapper around machine indexes.
Definition: SlotIndexes.h:65
static bool isSameInstr(SlotIndex A, SlotIndex B)
isSameInstr - Return true if A and B refer to the same instruction.
Definition: SlotIndexes.h:176
SlotIndex getDeadSlot() const
Returns the dead def kill slot for the current instruction.
Definition: SlotIndexes.h:242
static bool isEarlierInstr(SlotIndex A, SlotIndex B)
isEarlierInstr - Return true if A refers to an instruction earlier than B.
Definition: SlotIndexes.h:182
SlotIndex getBoundaryIndex() const
Returns the boundary index for associated with this index.
Definition: SlotIndexes.h:231
SlotIndex getBaseIndex() const
Returns the base index for associated with this index.
Definition: SlotIndexes.h:224
SlotIndex getNextSlot() const
Returns the next slot in the index list.
Definition: SlotIndexes.h:252
SlotIndex getRegSlot(bool EC=false) const
Returns the register use/def slot in the current instruction for a normal or early-clobber def.
Definition: SlotIndexes.h:237
SlotIndexes pass.
Definition: SlotIndexes.h:297
SlotIndex insertMachineInstrInMaps(MachineInstr &MI, bool Late=false)
Insert the given machine instruction into the mapping.
Definition: SlotIndexes.h:531
MachineBasicBlock * getMBBFromIndex(SlotIndex index) const
Returns the basic block which the given index falls in.
Definition: SlotIndexes.h:515
const std::pair< SlotIndex, SlotIndex > & getMBBRange(unsigned Num) const
Return the (start,end) range of the given basic block number.
Definition: SlotIndexes.h:449
SlotIndex getMBBEndIdx(unsigned Num) const
Returns the last index in the given basic block number.
Definition: SlotIndexes.h:470
size_type count(ConstPtrType Ptr) const
count - Return 1 if the specified pointer is in the set, 0 otherwise.
Definition: SmallPtrSet.h:452
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
Definition: SmallPtrSet.h:384
SmallPtrSetIterator - This implements a const_iterator for SmallPtrSet.
Definition: SmallPtrSet.h:312
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
Definition: SmallPtrSet.h:519
bool empty() const
Definition: SmallVector.h:81
size_t size() const
Definition: SmallVector.h:78
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition: SmallVector.h:573
void assign(size_type NumElts, ValueParamT Elt)
Definition: SmallVector.h:704
typename SuperClass::const_iterator const_iterator
Definition: SmallVector.h:578
void resize(size_type N)
Definition: SmallVector.h:638
void push_back(const T &Elt)
Definition: SmallVector.h:413
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1196
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
MachineBasicBlock::iterator getLastSplitPointIter(MachineBasicBlock *BB)
Definition: SplitKit.h:243
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
SlotIndex getLastSplitPoint(unsigned Num)
Definition: SplitKit.h:235
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...
Definition: SplitKit.cpp:1587
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:823
unsigned openIntv()
Create a new virtual register and live interval.
Definition: SplitKit.cpp:645
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'...
Definition: SplitKit.cpp:1829
SlotIndex enterIntvAfter(SlotIndex Idx)
enterIntvAfter - Enter the open interval after the instruction at Idx.
Definition: SplitKit.cpp:680
SlotIndex enterIntvBefore(SlotIndex Idx)
enterIntvBefore - Enter the open interval before the instruction at Idx.
Definition: SplitKit.cpp:663
void useIntv(const MachineBasicBlock &MBB)
useIntv - indicate that all instructions in MBB should use OpenLI.
Definition: SplitKit.cpp:735
SlotIndex leaveIntvAfter(SlotIndex Idx)
leaveIntvAfter - Leave the open interval after the instruction at Idx.
Definition: SplitKit.cpp:746
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:698
SlotIndex leaveIntvAtTop(MachineBasicBlock &MBB)
leaveIntvAtTop - Leave the interval at the top of MBB.
Definition: SplitKit.cpp:796
SlotIndex leaveIntvBefore(SlotIndex Idx)
leaveIntvBefore - Leave the open interval before the instruction at Idx.
Definition: SplitKit.cpp:777
void finish(SmallVectorImpl< unsigned > *LRMap=nullptr)
finish - after all the new live ranges have been created, compute the remaining live range,...
Definition: SplitKit.cpp:1502
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...
Definition: SplitKit.cpp:1736
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...
Definition: SplitKit.cpp:1633
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:656
void splitSingleBlock(const SplitAnalysis::BlockInfo &BI)
splitSingleBlock - Split CurLI into a separate live interval around the uses in a single block.
Definition: SplitKit.cpp:1607
void dump() const
dump - print the current interval mapping to dbgs().
Definition: SplitKit.cpp:384
virtual unsigned getLiveRangeSplitOpcode(Register Reg, const MachineFunction &MF) const
Allows targets to use appropriate copy instruction while spilitting live range of a register in regis...
std::optional< DestSourcePair > isCopyInstr(const MachineInstr &MI) const
If the specific machine instruction is a instruction that moves/copies value from one register to ano...
LaneBitmask getSubRegIndexLaneMask(unsigned SubIdx) const
Return a bitmask representing the parts of a register that are covered by SubIdx.
bool getCoveringSubRegIndexes(const MachineRegisterInfo &MRI, const TargetRegisterClass *RC, LaneBitmask LaneMask, SmallVectorImpl< unsigned > &Indexes) const
Try to find one or more subregister indexes to cover LaneMask.
VNInfo - Value Number Information.
Definition: LiveInterval.h:53
bool isUnused() const
Returns true if this value is unused.
Definition: LiveInterval.h:81
unsigned id
The ID number of this value.
Definition: LiveInterval.h:58
SlotIndex def
The index of the defining instruction.
Definition: LiveInterval.h:61
bool isPHIDef() const
Returns true if this value is defined by a PHI instruction (or was, PHI instructions may have been el...
Definition: LiveInterval.h:78
Calculate auxiliary information for a virtual register such as its spill weight and allocation hint.
void setIsSplitFromReg(Register virtReg, Register SReg)
records virtReg is a split live interval from SReg.
Definition: VirtRegMap.h:138
Register getOriginal(Register VirtReg) const
getOriginal - Return the original virtual register that VirtReg descends from through splitting.
Definition: VirtRegMap.h:154
MachineFunction & getMachineFunction() const
Definition: VirtRegMap.h:74
std::pair< iterator, bool > insert(const ValueT &V)
Definition: DenseSet.h:213
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:95
self_iterator getIterator()
Definition: ilist_node.h:132
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:52
#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
@ Dead
Unused definition.
@ Define
Register definition.
Reg
All possible values of the reg field in the ModR/M byte.
initializer< Ty > init(const Ty &Val)
Definition: CommandLine.h:443
NodeAddr< DefNode * > Def
Definition: RDFGraph.h:384
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
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:1697
MachineInstrBuilder BuildMI(MachineFunction &MF, const MIMetadata &MIMD, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
void append_range(Container &C, Range &&R)
Wrapper function to append range R to container C.
Definition: STLExtras.h:2115
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:657
auto unique(Range &&R, Predicate P)
Definition: STLExtras.h:2055
Printable print(const GCNRegPressure &RP, const GCNSubtarget *ST=nullptr)
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:1746
auto reverse(ContainerTy &&C)
Definition: STLExtras.h:420
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition: Debug.cpp:163
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:1753
void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
Definition: Error.cpp:167
unsigned getInternalReadRegState(bool B)
unsigned getUndefRegState(bool B)
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:1624
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.
Printable printMBBReference(const MachineBasicBlock &MBB)
Prints a machine basic block reference.
#define N
Description of the encoding of one expression Op.
static constexpr LaneBitmask getAll()
Definition: LaneBitmask.h:82
constexpr bool none() const
Definition: LaneBitmask.h:52
constexpr bool all() const
Definition: LaneBitmask.h:54
static constexpr LaneBitmask getNone()
Definition: LaneBitmask.h:81
Remat - Information needed to rematerialize at a specific location.
This represents a simple continuous liveness interval for a value.
Definition: LiveInterval.h:162
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
Definition: SplitKit.cpp:1891
SlotIndex LastInstr
Last instr accessing current reg.
Definition: SplitKit.h:124
SlotIndex FirstInstr
First instr accessing current reg.
Definition: SplitKit.h:123