LLVM 22.0.0git
LiveIntervals.cpp
Go to the documentation of this file.
1//===- LiveIntervals.cpp - Live Interval Analysis -------------------------===//
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/// \file This file implements the LiveInterval analysis pass which is used
10/// by the Linear Scan Register allocator. This pass linearizes the
11/// basic blocks of the function in DFS order and computes live intervals for
12/// each virtual and physical register.
13//
14//===----------------------------------------------------------------------===//
15
17#include "llvm/ADT/ArrayRef.h"
34#include "llvm/CodeGen/Passes.h"
40#include "llvm/Config/llvm-config.h"
42#include "llvm/IR/Statepoint.h"
43#include "llvm/MC/LaneBitmask.h"
45#include "llvm/Pass.h"
48#include "llvm/Support/Debug.h"
51#include <algorithm>
52#include <cassert>
53#include <cstdint>
54#include <iterator>
55#include <tuple>
56#include <utility>
57
58using namespace llvm;
59
60#define DEBUG_TYPE "regalloc"
61
62AnalysisKey LiveIntervalsAnalysis::Key;
63
70
74 OS << "Live intervals for machine function: " << MF.getName() << ":\n";
77}
78
82 "Live Interval Analysis", false, false)
86 "Live Interval Analysis", false, true)
87
89 LIS.Indexes = &getAnalysis<SlotIndexesWrapperPass>().getSI();
90 LIS.DomTree = &getAnalysis<MachineDominatorTreeWrapperPass>().getDomTree();
91 LIS.analyze(MF);
93 return false;
94}
95
96#ifndef NDEBUG
98 "precompute-phys-liveness", cl::Hidden,
99 cl::desc("Eagerly compute live intervals for all physreg units."));
100#else
101static bool EnablePrecomputePhysRegs = false;
102#endif // NDEBUG
103
105 "use-segment-set-for-physregs", cl::Hidden, cl::init(true),
106 cl::desc(
107 "Use segment set for the computation of the live ranges of physregs."));
108
119
123
125
127 MachineFunction &MF, const PreservedAnalyses &PA,
128 MachineFunctionAnalysisManager::Invalidator &Inv) {
129 auto PAC = PA.getChecker<LiveIntervalsAnalysis>();
130
131 if (!PAC.preserved() && !PAC.preservedSet<AllAnalysesOn<MachineFunction>>())
132 return true;
133
134 // LiveIntervals holds pointers to these results, so check for their
135 // invalidation.
136 return Inv.invalidate<SlotIndexesAnalysis>(MF, PA) ||
137 Inv.invalidate<MachineDominatorTreeAnalysis>(MF, PA);
138}
139
140void LiveIntervals::clear() {
141 // Free the live intervals themselves.
142 for (unsigned i = 0, e = VirtRegIntervals.size(); i != e; ++i)
143 delete VirtRegIntervals[Register::index2VirtReg(i)];
144 VirtRegIntervals.clear();
145 RegMaskSlots.clear();
146 RegMaskBits.clear();
147 RegMaskBlocks.clear();
148
149 for (LiveRange *LR : RegUnitRanges)
150 delete LR;
151 RegUnitRanges.clear();
152
153 // Release VNInfo memory regions, VNInfo objects don't need to be dtor'd.
154 VNInfoAllocator.Reset();
155}
156
157void LiveIntervals::analyze(MachineFunction &fn) {
158 MF = &fn;
159 MRI = &MF->getRegInfo();
161 TII = MF->getSubtarget().getInstrInfo();
162
163 if (!LICalc)
164 LICalc = std::make_unique<LiveIntervalCalc>();
165
166 // Allocate space for all virtual registers.
167 VirtRegIntervals.resize(MRI->getNumVirtRegs());
168
169 computeVirtRegs();
170 computeRegMasks();
171 computeLiveInRegUnits();
172
174 // For stress testing, precompute live ranges of all physical register
175 // units, including reserved registers.
176 for (unsigned i = 0, e = TRI->getNumRegUnits(); i != e; ++i)
177 getRegUnit(i);
178 }
179}
180
182 OS << "********** INTERVALS **********\n";
183
184 // Dump the regunits.
185 for (unsigned Unit = 0, UnitE = RegUnitRanges.size(); Unit != UnitE; ++Unit)
186 if (LiveRange *LR = RegUnitRanges[Unit])
187 OS << printRegUnit(Unit, TRI) << ' ' << *LR << '\n';
188
189 // Dump the virtregs.
190 for (unsigned i = 0, e = MRI->getNumVirtRegs(); i != e; ++i) {
192 if (hasInterval(Reg))
193 OS << getInterval(Reg) << '\n';
194 }
195
196 OS << "RegMasks:";
197 for (SlotIndex Idx : RegMaskSlots)
198 OS << ' ' << Idx;
199 OS << '\n';
200
201 printInstrs(OS);
202}
203
204void LiveIntervals::printInstrs(raw_ostream &OS) const {
205 OS << "********** MACHINEINSTRS **********\n";
206 MF->print(OS, Indexes);
207}
208
209#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
210LLVM_DUMP_METHOD void LiveIntervals::dumpInstrs() const {
211 printInstrs(dbgs());
212}
213#endif
214
215#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
217#endif
218
219LiveInterval *LiveIntervals::createInterval(Register reg) {
220 float Weight = reg.isPhysical() ? huge_valf : 0.0F;
221 return new LiveInterval(reg, Weight);
222}
223
224/// Compute the live interval of a virtual register, based on defs and uses.
225bool LiveIntervals::computeVirtRegInterval(LiveInterval &LI) {
226 assert(LICalc && "LICalc not initialized.");
227 assert(LI.empty() && "Should only compute empty intervals.");
228 LICalc->reset(MF, getSlotIndexes(), DomTree, &getVNInfoAllocator());
229 LICalc->calculate(LI, MRI->shouldTrackSubRegLiveness(LI.reg()));
230 return computeDeadValues(LI, nullptr);
231}
232
233void LiveIntervals::computeVirtRegs() {
234 for (unsigned i = 0, e = MRI->getNumVirtRegs(); i != e; ++i) {
236 if (MRI->reg_nodbg_empty(Reg))
237 continue;
238 LiveInterval &LI = createEmptyInterval(Reg);
239 bool NeedSplit = computeVirtRegInterval(LI);
240 if (NeedSplit) {
242 splitSeparateComponents(LI, SplitLIs);
243 }
244 }
245}
246
247void LiveIntervals::computeRegMasks() {
248 RegMaskBlocks.resize(MF->getNumBlockIDs());
249
250 // Find all instructions with regmask operands.
251 for (const MachineBasicBlock &MBB : *MF) {
252 std::pair<unsigned, unsigned> &RMB = RegMaskBlocks[MBB.getNumber()];
253 RMB.first = RegMaskSlots.size();
254
255 // Some block starts, such as EH funclets, create masks.
256 if (const uint32_t *Mask = MBB.getBeginClobberMask(TRI)) {
257 RegMaskSlots.push_back(Indexes->getMBBStartIdx(&MBB));
258 RegMaskBits.push_back(Mask);
259 }
260
261 // Unwinders may clobber additional registers.
262 // FIXME: This functionality can possibly be merged into
263 // MachineBasicBlock::getBeginClobberMask().
264 if (MBB.isEHPad())
265 if (auto *Mask = TRI->getCustomEHPadPreservedMask(*MBB.getParent())) {
266 RegMaskSlots.push_back(Indexes->getMBBStartIdx(&MBB));
267 RegMaskBits.push_back(Mask);
268 }
269
270 for (const MachineInstr &MI : MBB) {
271 for (const MachineOperand &MO : MI.operands()) {
272 if (!MO.isRegMask())
273 continue;
274 RegMaskSlots.push_back(Indexes->getInstructionIndex(MI).getRegSlot());
275 RegMaskBits.push_back(MO.getRegMask());
276 }
277 }
278
279 // Some block ends, such as funclet returns, create masks. Put the mask on
280 // the last instruction of the block, because MBB slot index intervals are
281 // half-open.
282 if (const uint32_t *Mask = MBB.getEndClobberMask(TRI)) {
283 assert(!MBB.empty() && "empty return block?");
284 RegMaskSlots.push_back(
285 Indexes->getInstructionIndex(MBB.back()).getRegSlot());
286 RegMaskBits.push_back(Mask);
287 }
288
289 // Compute the number of register mask instructions in this block.
290 RMB.second = RegMaskSlots.size() - RMB.first;
291 }
292}
293
294//===----------------------------------------------------------------------===//
295// Register Unit Liveness
296//===----------------------------------------------------------------------===//
297//
298// Fixed interference typically comes from ABI boundaries: Function arguments
299// and return values are passed in fixed registers, and so are exception
300// pointers entering landing pads. Certain instructions require values to be
301// present in specific registers. That is also represented through fixed
302// interference.
303//
304
305/// Compute the live range of a register unit, based on the uses and defs of
306/// aliasing registers. The range should be empty, or contain only dead
307/// phi-defs from ABI blocks.
308void LiveIntervals::computeRegUnitRange(LiveRange &LR, unsigned Unit) {
309 assert(LICalc && "LICalc not initialized.");
310 LICalc->reset(MF, getSlotIndexes(), DomTree, &getVNInfoAllocator());
311
312 // The physregs aliasing Unit are the roots and their super-registers.
313 // Create all values as dead defs before extending to uses. Note that roots
314 // may share super-registers. That's OK because createDeadDefs() is
315 // idempotent. It is very rare for a register unit to have multiple roots, so
316 // uniquing super-registers is probably not worthwhile.
317 bool IsReserved = false;
318 for (MCRegUnitRootIterator Root(Unit, TRI); Root.isValid(); ++Root) {
319 bool IsRootReserved = true;
320 for (MCPhysReg Reg : TRI->superregs_inclusive(*Root)) {
321 if (!MRI->reg_empty(Reg))
322 LICalc->createDeadDefs(LR, Reg);
323 // A register unit is considered reserved if all its roots and all their
324 // super registers are reserved.
325 if (!MRI->isReserved(Reg))
326 IsRootReserved = false;
327 }
328 IsReserved |= IsRootReserved;
329 }
330 assert(IsReserved == MRI->isReservedRegUnit(Unit) &&
331 "reserved computation mismatch");
332
333 // Now extend LR to reach all uses.
334 // Ignore uses of reserved registers. We only track defs of those.
335 if (!IsReserved) {
336 for (MCRegUnitRootIterator Root(Unit, TRI); Root.isValid(); ++Root) {
337 for (MCPhysReg Reg : TRI->superregs_inclusive(*Root)) {
338 if (!MRI->reg_empty(Reg))
339 LICalc->extendToUses(LR, Reg);
340 }
341 }
342 }
343
344 // Flush the segment set to the segment vector.
346 LR.flushSegmentSet();
347}
348
349/// Precompute the live ranges of any register units that are live-in to an ABI
350/// block somewhere. Register values can appear without a corresponding def when
351/// entering the entry block or a landing pad.
352void LiveIntervals::computeLiveInRegUnits() {
353 RegUnitRanges.resize(TRI->getNumRegUnits());
354 LLVM_DEBUG(dbgs() << "Computing live-in reg-units in ABI blocks.\n");
355
356 // Keep track of the live range sets allocated.
357 SmallVector<unsigned, 8> NewRanges;
358
359 // Check all basic blocks for live-ins.
360 for (const MachineBasicBlock &MBB : *MF) {
361 // We only care about ABI blocks: Entry + landing pads.
362 if ((&MBB != &MF->front() && !MBB.isEHPad()) || MBB.livein_empty())
363 continue;
364
365 // Create phi-defs at Begin for all live-in registers.
366 SlotIndex Begin = Indexes->getMBBStartIdx(&MBB);
367 LLVM_DEBUG(dbgs() << Begin << "\t" << printMBBReference(MBB));
368 for (const auto &LI : MBB.liveins()) {
369 for (MCRegUnit Unit : TRI->regunits(LI.PhysReg)) {
370 LiveRange *LR = RegUnitRanges[Unit];
371 if (!LR) {
372 // Use segment set to speed-up initial computation of the live range.
373 LR = RegUnitRanges[Unit] = new LiveRange(UseSegmentSetForPhysRegs);
374 NewRanges.push_back(Unit);
375 }
376 VNInfo *VNI = LR->createDeadDef(Begin, getVNInfoAllocator());
377 (void)VNI;
378 LLVM_DEBUG(dbgs() << ' ' << printRegUnit(Unit, TRI) << '#' << VNI->id);
379 }
380 }
381 LLVM_DEBUG(dbgs() << '\n');
382 }
383 LLVM_DEBUG(dbgs() << "Created " << NewRanges.size() << " new intervals.\n");
384
385 // Compute the 'normal' part of the ranges.
386 for (unsigned Unit : NewRanges)
387 computeRegUnitRange(*RegUnitRanges[Unit], Unit);
388}
389
392 for (VNInfo *VNI : VNIs) {
393 if (VNI->isUnused())
394 continue;
395 SlotIndex Def = VNI->def;
396 LR.addSegment(LiveRange::Segment(Def, Def.getDeadSlot(), VNI));
397 }
398}
399
400void LiveIntervals::extendSegmentsToUses(LiveRange &Segments,
401 ShrinkToUsesWorkList &WorkList,
402 Register Reg, LaneBitmask LaneMask) {
403 // Keep track of the PHIs that are in use.
404 SmallPtrSet<VNInfo*, 8> UsedPHIs;
405 // Blocks that have already been added to WorkList as live-out.
406 SmallPtrSet<const MachineBasicBlock*, 16> LiveOut;
407
408 auto getSubRange = [](const LiveInterval &I, LaneBitmask M)
409 -> const LiveRange& {
410 if (M.none())
411 return I;
412 for (const LiveInterval::SubRange &SR : I.subranges()) {
413 if ((SR.LaneMask & M).any()) {
414 assert(SR.LaneMask == M && "Expecting lane masks to match exactly");
415 return SR;
416 }
417 }
418 llvm_unreachable("Subrange for mask not found");
419 };
420
421 const LiveInterval &LI = getInterval(Reg);
422 const LiveRange &OldRange = getSubRange(LI, LaneMask);
423
424 // Extend intervals to reach all uses in WorkList.
425 while (!WorkList.empty()) {
426 SlotIndex Idx = WorkList.back().first;
427 VNInfo *VNI = WorkList.back().second;
428 WorkList.pop_back();
429 const MachineBasicBlock *MBB = Indexes->getMBBFromIndex(Idx.getPrevSlot());
430 SlotIndex BlockStart = Indexes->getMBBStartIdx(MBB);
431
432 // Extend the live range for VNI to be live at Idx.
433 if (VNInfo *ExtVNI = Segments.extendInBlock(BlockStart, Idx)) {
434 assert(ExtVNI == VNI && "Unexpected existing value number");
435 (void)ExtVNI;
436 // Is this a PHIDef we haven't seen before?
437 if (!VNI->isPHIDef() || VNI->def != BlockStart ||
438 !UsedPHIs.insert(VNI).second)
439 continue;
440 // The PHI is live, make sure the predecessors are live-out.
441 for (const MachineBasicBlock *Pred : MBB->predecessors()) {
442 if (!LiveOut.insert(Pred).second)
443 continue;
444 SlotIndex Stop = Indexes->getMBBEndIdx(Pred);
445 // A predecessor is not required to have a live-out value for a PHI.
446 if (VNInfo *PVNI = OldRange.getVNInfoBefore(Stop))
447 WorkList.push_back(std::make_pair(Stop, PVNI));
448 }
449 continue;
450 }
451
452 // VNI is live-in to MBB.
453 LLVM_DEBUG(dbgs() << " live-in at " << BlockStart << '\n');
454 Segments.addSegment(LiveRange::Segment(BlockStart, Idx, VNI));
455
456 // Make sure VNI is live-out from the predecessors.
457 for (const MachineBasicBlock *Pred : MBB->predecessors()) {
458 if (!LiveOut.insert(Pred).second)
459 continue;
460 SlotIndex Stop = Indexes->getMBBEndIdx(Pred);
461 if (VNInfo *OldVNI = OldRange.getVNInfoBefore(Stop)) {
462 assert(OldVNI == VNI && "Wrong value out of predecessor");
463 (void)OldVNI;
464 WorkList.push_back(std::make_pair(Stop, VNI));
465 } else {
466#ifndef NDEBUG
467 // There was no old VNI. Verify that Stop is jointly dominated
468 // by <undef>s for this live range.
469 assert(LaneMask.any() &&
470 "Missing value out of predecessor for main range");
472 LI.computeSubRangeUndefs(Undefs, LaneMask, *MRI, *Indexes);
473 assert(LiveRangeCalc::isJointlyDominated(Pred, Undefs, *Indexes) &&
474 "Missing value out of predecessor for subrange");
475#endif
476 }
477 }
478 }
479}
480
483 LLVM_DEBUG(dbgs() << "Shrink: " << *li << '\n');
484 assert(li->reg().isVirtual() && "Can only shrink virtual registers");
485
486 // Shrink subregister live ranges.
487 bool NeedsCleanup = false;
488 for (LiveInterval::SubRange &S : li->subranges()) {
489 shrinkToUses(S, li->reg());
490 if (S.empty())
491 NeedsCleanup = true;
492 }
493 if (NeedsCleanup)
495
496 // Find all the values used, including PHI kills.
497 ShrinkToUsesWorkList WorkList;
498
499 // Visit all instructions reading li->reg().
500 Register Reg = li->reg();
501 for (MachineInstr &UseMI : MRI->reg_instructions(Reg)) {
502 if (UseMI.isDebugInstr() || !UseMI.readsVirtualRegister(Reg))
503 continue;
505 LiveQueryResult LRQ = li->Query(Idx);
506 VNInfo *VNI = LRQ.valueIn();
507 if (!VNI) {
508 // This shouldn't happen: readsVirtualRegister returns true, but there is
509 // no live value. It is likely caused by a target getting <undef> flags
510 // wrong.
512 dbgs() << Idx << '\t' << UseMI
513 << "Warning: Instr claims to read non-existent value in "
514 << *li << '\n');
515 continue;
516 }
517 // Special case: An early-clobber tied operand reads and writes the
518 // register one slot early.
519 if (VNInfo *DefVNI = LRQ.valueDefined())
520 Idx = DefVNI->def;
521
522 WorkList.push_back(std::make_pair(Idx, VNI));
523 }
524
525 // Create new live ranges with only minimal live segments per def.
526 LiveRange NewLR;
527 createSegmentsForValues(NewLR, li->vnis());
528 extendSegmentsToUses(NewLR, WorkList, Reg, LaneBitmask::getNone());
529
530 // Move the trimmed segments back.
531 li->segments.swap(NewLR.segments);
532
533 // Handle dead values.
534 bool CanSeparate = computeDeadValues(*li, dead);
535 LLVM_DEBUG(dbgs() << "Shrunk: " << *li << '\n');
536 return CanSeparate;
537}
538
539bool LiveIntervals::computeDeadValues(LiveInterval &LI,
541 bool MayHaveSplitComponents = false;
542
543 for (VNInfo *VNI : LI.valnos) {
544 if (VNI->isUnused())
545 continue;
546 SlotIndex Def = VNI->def;
548 assert(I != LI.end() && "Missing segment for VNI");
549
550 // Is the register live before? Otherwise we may have to add a read-undef
551 // flag for subregister defs.
552 Register VReg = LI.reg();
553 if (MRI->shouldTrackSubRegLiveness(VReg)) {
554 if ((I == LI.begin() || std::prev(I)->end < Def) && !VNI->isPHIDef()) {
556 MI->setRegisterDefReadUndef(VReg);
557 }
558 }
559
560 if (I->end != Def.getDeadSlot())
561 continue;
562 if (VNI->isPHIDef()) {
563 // This is a dead PHI. Remove it.
564 VNI->markUnused();
565 LI.removeSegment(I);
566 LLVM_DEBUG(dbgs() << "Dead PHI at " << Def << " may separate interval\n");
567 } else {
568 // This is a dead def. Make sure the instruction knows.
569 MachineInstr *MI = getInstructionFromIndex(Def);
570 assert(MI && "No instruction defining live value");
571 MI->addRegisterDead(LI.reg(), TRI);
572
573 if (dead && MI->allDefsAreDead()) {
574 LLVM_DEBUG(dbgs() << "All defs dead: " << Def << '\t' << *MI);
575 dead->push_back(MI);
576 }
577 }
578 MayHaveSplitComponents = true;
579 }
580 return MayHaveSplitComponents;
581}
582
584 LLVM_DEBUG(dbgs() << "Shrink: " << SR << '\n');
585 assert(Reg.isVirtual() && "Can only shrink virtual registers");
586 // Find all the values used, including PHI kills.
587 ShrinkToUsesWorkList WorkList;
588
589 // Visit all instructions reading Reg.
590 SlotIndex LastIdx;
591 for (MachineOperand &MO : MRI->use_nodbg_operands(Reg)) {
592 // Skip "undef" uses.
593 if (!MO.readsReg())
594 continue;
595 // Maybe the operand is for a subregister we don't care about.
596 unsigned SubReg = MO.getSubReg();
597 if (SubReg != 0) {
598 LaneBitmask LaneMask = TRI->getSubRegIndexLaneMask(SubReg);
599 if ((LaneMask & SR.LaneMask).none())
600 continue;
601 }
602 // We only need to visit each instruction once.
603 MachineInstr *UseMI = MO.getParent();
605 if (Idx == LastIdx)
606 continue;
607 LastIdx = Idx;
608
609 LiveQueryResult LRQ = SR.Query(Idx);
610 VNInfo *VNI = LRQ.valueIn();
611 // For Subranges it is possible that only undef values are left in that
612 // part of the subregister, so there is no real liverange at the use
613 if (!VNI)
614 continue;
615
616 // Special case: An early-clobber tied operand reads and writes the
617 // register one slot early.
618 if (VNInfo *DefVNI = LRQ.valueDefined())
619 Idx = DefVNI->def;
620
621 WorkList.push_back(std::make_pair(Idx, VNI));
622 }
623
624 // Create a new live ranges with only minimal live segments per def.
625 LiveRange NewLR;
626 createSegmentsForValues(NewLR, SR.vnis());
627 extendSegmentsToUses(NewLR, WorkList, Reg, SR.LaneMask);
628
629 // Move the trimmed ranges back.
630 SR.segments.swap(NewLR.segments);
631
632 // Remove dead PHI value numbers
633 for (VNInfo *VNI : SR.valnos) {
634 if (VNI->isUnused())
635 continue;
636 const LiveRange::Segment *Segment = SR.getSegmentContaining(VNI->def);
637 assert(Segment != nullptr && "Missing segment for VNI");
638 if (Segment->end != VNI->def.getDeadSlot())
639 continue;
640 if (VNI->isPHIDef()) {
641 // This is a dead PHI. Remove it.
642 LLVM_DEBUG(dbgs() << "Dead PHI at " << VNI->def
643 << " may separate interval\n");
644 VNI->markUnused();
645 SR.removeSegment(*Segment);
646 }
647 }
648
649 LLVM_DEBUG(dbgs() << "Shrunk: " << SR << '\n');
650}
651
653 ArrayRef<SlotIndex> Indices,
654 ArrayRef<SlotIndex> Undefs) {
655 assert(LICalc && "LICalc not initialized.");
656 LICalc->reset(MF, getSlotIndexes(), DomTree, &getVNInfoAllocator());
657 for (SlotIndex Idx : Indices)
658 LICalc->extend(LR, Idx, /*PhysReg=*/0, Undefs);
659}
660
662 SmallVectorImpl<SlotIndex> *EndPoints) {
663 LiveQueryResult LRQ = LR.Query(Kill);
664 // LR may have liveness reachable from early clobber slot, which may be
665 // only live-in instead of live-out of the instruction.
666 // For example, LR =[1r, 3r), Kill = 3e, we have to prune [3e, 3r) of LR.
667 VNInfo *VNI = LRQ.valueOutOrDead() ? LRQ.valueOutOrDead() : LRQ.valueIn();
668 if (!VNI)
669 return;
670
671 MachineBasicBlock *KillMBB = Indexes->getMBBFromIndex(Kill);
672 SlotIndex MBBEnd = Indexes->getMBBEndIdx(KillMBB);
673
674 // If VNI isn't live out from KillMBB, the value is trivially pruned.
675 if (LRQ.endPoint() < MBBEnd) {
676 LR.removeSegment(Kill, LRQ.endPoint());
677 if (EndPoints) EndPoints->push_back(LRQ.endPoint());
678 return;
679 }
680
681 // VNI is live out of KillMBB.
682 LR.removeSegment(Kill, MBBEnd);
683 if (EndPoints) EndPoints->push_back(MBBEnd);
684
685 // Find all blocks that are reachable from KillMBB without leaving VNI's live
686 // range. It is possible that KillMBB itself is reachable, so start a DFS
687 // from each successor.
689 VisitedTy Visited;
690 for (MachineBasicBlock *Succ : KillMBB->successors()) {
692 I = df_ext_begin(Succ, Visited), E = df_ext_end(Succ, Visited);
693 I != E;) {
695
696 // Check if VNI is live in to MBB.
697 SlotIndex MBBStart, MBBEnd;
698 std::tie(MBBStart, MBBEnd) = Indexes->getMBBRange(MBB);
699 LiveQueryResult LRQ = LR.Query(MBBStart);
700 if (LRQ.valueIn() != VNI) {
701 // This block isn't part of the VNI segment. Prune the search.
702 I.skipChildren();
703 continue;
704 }
705
706 // Prune the search if VNI is killed in MBB.
707 if (LRQ.endPoint() < MBBEnd) {
708 LR.removeSegment(MBBStart, LRQ.endPoint());
709 if (EndPoints) EndPoints->push_back(LRQ.endPoint());
710 I.skipChildren();
711 continue;
712 }
713
714 // VNI is live through MBB.
715 LR.removeSegment(MBBStart, MBBEnd);
716 if (EndPoints) EndPoints->push_back(MBBEnd);
717 ++I;
718 }
719 }
720}
721
722//===----------------------------------------------------------------------===//
723// Register allocator hooks.
724//
725
727 // Keep track of regunit ranges.
729
730 for (unsigned i = 0, e = MRI->getNumVirtRegs(); i != e; ++i) {
732 if (MRI->reg_nodbg_empty(Reg))
733 continue;
734 const LiveInterval &LI = getInterval(Reg);
735 if (LI.empty())
736 continue;
737
738 // Target may have not allocated this yet.
739 Register PhysReg = VRM->getPhys(Reg);
740 if (!PhysReg)
741 continue;
742
743 // Find the regunit intervals for the assigned register. They may overlap
744 // the virtual register live range, cancelling any kills.
745 RU.clear();
746 LaneBitmask ArtificialLanes;
747 for (MCRegUnitMaskIterator UI(PhysReg, TRI); UI.isValid(); ++UI) {
748 auto [Unit, Bitmask] = *UI;
749 // Record lane mask for all artificial RegUnits for this physreg.
750 if (TRI->isArtificialRegUnit(Unit))
751 ArtificialLanes |= Bitmask;
752 const LiveRange &RURange = getRegUnit(Unit);
753 if (RURange.empty())
754 continue;
755 RU.push_back(std::make_pair(&RURange, RURange.find(LI.begin()->end)));
756 }
757 // Every instruction that kills Reg corresponds to a segment range end
758 // point.
759 for (LiveInterval::const_iterator RI = LI.begin(), RE = LI.end(); RI != RE;
760 ++RI) {
761 // A block index indicates an MBB edge.
762 if (RI->end.isBlock())
763 continue;
765 if (!MI)
766 continue;
767
768 // Check if any of the regunits are live beyond the end of RI. That could
769 // happen when a physreg is defined as a copy of a virtreg:
770 //
771 // %eax = COPY %5
772 // FOO %5 <--- MI, cancel kill because %eax is live.
773 // BAR killed %eax
774 //
775 // There should be no kill flag on FOO when %5 is rewritten as %eax.
776 for (auto &RUP : RU) {
777 const LiveRange &RURange = *RUP.first;
778 LiveRange::const_iterator &I = RUP.second;
779 if (I == RURange.end())
780 continue;
781 I = RURange.advanceTo(I, RI->end);
782 if (I == RURange.end() || I->start >= RI->end)
783 continue;
784 // I is overlapping RI.
785 goto CancelKill;
786 }
787
788 if (MRI->subRegLivenessEnabled()) {
789 // When reading a partial undefined value we must not add a kill flag.
790 // The regalloc might have used the undef lane for something else.
791 // Example:
792 // %1 = ... ; R32: %1
793 // %2:high16 = ... ; R64: %2
794 // = read killed %2 ; R64: %2
795 // = read %1 ; R32: %1
796 // The <kill> flag is correct for %2, but the register allocator may
797 // assign R0L to %1, and R0 to %2 because the low 32bits of R0
798 // are actually never written by %2. After assignment the <kill>
799 // flag at the read instruction is invalid.
800 LaneBitmask DefinedLanesMask;
801 if (LI.hasSubRanges()) {
802 // Compute a mask of lanes that are defined.
803 // Artificial regunits are not independently allocatable so the
804 // register allocator cannot have used them to represent any other
805 // values. That's why we mark them as 'defined' here, as this
806 // otherwise prevents kill flags from being added.
807 DefinedLanesMask = ArtificialLanes;
808 for (const LiveInterval::SubRange &SR : LI.subranges())
809 for (const LiveRange::Segment &Segment : SR.segments) {
810 if (Segment.start >= RI->end)
811 break;
812 if (Segment.end == RI->end) {
813 DefinedLanesMask |= SR.LaneMask;
814 break;
815 }
816 }
817 } else
818 DefinedLanesMask = LaneBitmask::getAll();
819
820 bool IsFullWrite = false;
821 for (const MachineOperand &MO : MI->operands()) {
822 if (!MO.isReg() || MO.getReg() != Reg)
823 continue;
824 if (MO.isUse()) {
825 // Reading any undefined lanes?
826 unsigned SubReg = MO.getSubReg();
827 LaneBitmask UseMask = SubReg ? TRI->getSubRegIndexLaneMask(SubReg)
828 : MRI->getMaxLaneMaskForVReg(Reg);
829 if ((UseMask & ~DefinedLanesMask).any())
830 goto CancelKill;
831 } else if (MO.getSubReg() == 0) {
832 // Writing to the full register?
833 assert(MO.isDef());
834 IsFullWrite = true;
835 }
836 }
837
838 // If an instruction writes to a subregister, a new segment starts in
839 // the LiveInterval. But as this is only overriding part of the register
840 // adding kill-flags is not correct here after registers have been
841 // assigned.
842 if (!IsFullWrite) {
843 // Next segment has to be adjacent in the subregister write case.
844 LiveRange::const_iterator N = std::next(RI);
845 if (N != LI.end() && N->start == RI->end)
846 goto CancelKill;
847 }
848 }
849
850 MI->addRegisterKilled(Reg, nullptr);
851 continue;
852CancelKill:
853 MI->clearRegisterKills(Reg, nullptr);
854 }
855 }
856}
857
860 assert(!LI.empty() && "LiveInterval is empty.");
861
862 // A local live range must be fully contained inside the block, meaning it is
863 // defined and killed at instructions, not at block boundaries. It is not
864 // live in or out of any block.
865 //
866 // It is technically possible to have a PHI-defined live range identical to a
867 // single block, but we are going to return false in that case.
868
869 SlotIndex Start = LI.beginIndex();
870 if (Start.isBlock())
871 return nullptr;
872
873 SlotIndex Stop = LI.endIndex();
874 if (Stop.isBlock())
875 return nullptr;
876
877 // getMBBFromIndex doesn't need to search the MBB table when both indexes
878 // belong to proper instructions.
879 MachineBasicBlock *MBB1 = Indexes->getMBBFromIndex(Start);
880 MachineBasicBlock *MBB2 = Indexes->getMBBFromIndex(Stop);
881 return MBB1 == MBB2 ? MBB1 : nullptr;
882}
883
884bool
885LiveIntervals::hasPHIKill(const LiveInterval &LI, const VNInfo *VNI) const {
886 for (const VNInfo *PHI : LI.valnos) {
887 if (PHI->isUnused() || !PHI->isPHIDef())
888 continue;
889 const MachineBasicBlock *PHIMBB = getMBBFromIndex(PHI->def);
890 // Conservatively return true instead of scanning huge predecessor lists.
891 if (PHIMBB->pred_size() > 100)
892 return true;
893 for (const MachineBasicBlock *Pred : PHIMBB->predecessors())
894 if (VNI == LI.getVNInfoBefore(Indexes->getMBBEndIdx(Pred)))
895 return true;
896 }
897 return false;
898}
899
900float LiveIntervals::getSpillWeight(bool isDef, bool isUse,
901 const MachineBlockFrequencyInfo *MBFI,
902 const MachineInstr &MI,
903 ProfileSummaryInfo *PSI) {
904 return getSpillWeight(isDef, isUse, MBFI, MI.getParent(), PSI);
905}
906
907float LiveIntervals::getSpillWeight(bool isDef, bool isUse,
908 const MachineBlockFrequencyInfo *MBFI,
909 const MachineBasicBlock *MBB,
910 ProfileSummaryInfo *PSI) {
911 float Weight = isDef + isUse;
912 const auto *MF = MBB->getParent();
913 // When optimizing for size we only consider the codesize impact of spilling
914 // the register, not the runtime impact.
915 if (PSI && llvm::shouldOptimizeForSize(MF, PSI, MBFI))
916 return Weight;
917 return Weight * MBFI->getBlockFreqRelativeToEntryBlock(MBB);
918}
919
923 VNInfo *VN = Interval.getNextValue(
924 SlotIndex(getInstructionIndex(startInst).getRegSlot()),
926 LiveRange::Segment S(SlotIndex(getInstructionIndex(startInst).getRegSlot()),
927 getMBBEndIdx(startInst.getParent()), VN);
928 Interval.addSegment(S);
929
930 return S;
931}
932
933//===----------------------------------------------------------------------===//
934// Register mask functions
935//===----------------------------------------------------------------------===//
936/// Check whether use of reg in MI is live-through. Live-through means that
937/// the value is alive on exit from Machine instruction. The example of such
938/// use is a deopt value in statepoint instruction.
940 if (MI->getOpcode() != TargetOpcode::STATEPOINT)
941 return false;
944 return false;
945 for (unsigned Idx = SO.getNumDeoptArgsIdx(), E = SO.getNumGCPtrIdx(); Idx < E;
946 ++Idx) {
947 const MachineOperand &MO = MI->getOperand(Idx);
948 if (MO.isReg() && MO.getReg() == Reg)
949 return true;
950 }
951 return false;
952}
953
955 BitVector &UsableRegs) {
956 if (LI.empty())
957 return false;
958 LiveInterval::const_iterator LiveI = LI.begin(), LiveE = LI.end();
959
960 // Use a smaller arrays for local live ranges.
964 Slots = getRegMaskSlotsInBlock(MBB->getNumber());
965 Bits = getRegMaskBitsInBlock(MBB->getNumber());
966 } else {
967 Slots = getRegMaskSlots();
968 Bits = getRegMaskBits();
969 }
970
971 // We are going to enumerate all the register mask slots contained in LI.
972 // Start with a binary search of RegMaskSlots to find a starting point.
973 ArrayRef<SlotIndex>::iterator SlotI = llvm::lower_bound(Slots, LiveI->start);
974 ArrayRef<SlotIndex>::iterator SlotE = Slots.end();
975
976 // No slots in range, LI begins after the last call.
977 if (SlotI == SlotE)
978 return false;
979
980 bool Found = false;
981 // Utility to union regmasks.
982 auto unionBitMask = [&](unsigned Idx) {
983 if (!Found) {
984 // This is the first overlap. Initialize UsableRegs to all ones.
985 UsableRegs.clear();
986 UsableRegs.resize(TRI->getNumRegs(), true);
987 Found = true;
988 }
989 // Remove usable registers clobbered by this mask.
990 UsableRegs.clearBitsNotInMask(Bits[Idx]);
991 };
992 while (true) {
993 assert(*SlotI >= LiveI->start);
994 // Loop over all slots overlapping this segment.
995 while (*SlotI < LiveI->end) {
996 // *SlotI overlaps LI. Collect mask bits.
997 unionBitMask(SlotI - Slots.begin());
998 if (++SlotI == SlotE)
999 return Found;
1000 }
1001 // If segment ends with live-through use we need to collect its regmask.
1002 if (*SlotI == LiveI->end)
1004 if (hasLiveThroughUse(MI, LI.reg()))
1005 unionBitMask(SlotI++ - Slots.begin());
1006 // *SlotI is beyond the current LI segment.
1007 // Special advance implementation to not miss next LiveI->end.
1008 if (++LiveI == LiveE || SlotI == SlotE || *SlotI > LI.endIndex())
1009 return Found;
1010 while (LiveI->end < *SlotI)
1011 ++LiveI;
1012 // Advance SlotI until it overlaps.
1013 while (*SlotI < LiveI->start)
1014 if (++SlotI == SlotE)
1015 return Found;
1016 }
1017}
1018
1019//===----------------------------------------------------------------------===//
1020// IntervalUpdate class.
1021//===----------------------------------------------------------------------===//
1022
1023/// Toolkit used by handleMove to trim or extend live intervals.
1025private:
1026 LiveIntervals& LIS;
1027 const MachineRegisterInfo& MRI;
1028 const TargetRegisterInfo& TRI;
1029 SlotIndex OldIdx;
1030 SlotIndex NewIdx;
1032 bool UpdateFlags;
1033
1034public:
1035 HMEditor(LiveIntervals& LIS, const MachineRegisterInfo& MRI,
1036 const TargetRegisterInfo& TRI,
1037 SlotIndex OldIdx, SlotIndex NewIdx, bool UpdateFlags)
1038 : LIS(LIS), MRI(MRI), TRI(TRI), OldIdx(OldIdx), NewIdx(NewIdx),
1039 UpdateFlags(UpdateFlags) {}
1040
1041 // FIXME: UpdateFlags is a workaround that creates live intervals for all
1042 // physregs, even those that aren't needed for regalloc, in order to update
1043 // kill flags. This is wasteful. Eventually, LiveVariables will strip all kill
1044 // flags, and postRA passes will use a live register utility instead.
1045 LiveRange *getRegUnitLI(unsigned Unit) {
1046 if (UpdateFlags && !MRI.isReservedRegUnit(Unit))
1047 return &LIS.getRegUnit(Unit);
1048 return LIS.getCachedRegUnit(Unit);
1049 }
1050
1051 /// Update all live ranges touched by MI, assuming a move from OldIdx to
1052 /// NewIdx.
1054 LLVM_DEBUG(dbgs() << "handleMove " << OldIdx << " -> " << NewIdx << ": "
1055 << *MI);
1056 bool hasRegMask = false;
1057 for (MachineOperand &MO : MI->operands()) {
1058 if (MO.isRegMask())
1059 hasRegMask = true;
1060 if (!MO.isReg())
1061 continue;
1062 if (MO.isUse()) {
1063 if (!MO.readsReg())
1064 continue;
1065 // Aggressively clear all kill flags.
1066 // They are reinserted by VirtRegRewriter.
1067 MO.setIsKill(false);
1068 }
1069
1070 Register Reg = MO.getReg();
1071 if (!Reg)
1072 continue;
1073 if (Reg.isVirtual()) {
1074 LiveInterval &LI = LIS.getInterval(Reg);
1075 if (LI.hasSubRanges()) {
1076 unsigned SubReg = MO.getSubReg();
1077 LaneBitmask LaneMask = SubReg ? TRI.getSubRegIndexLaneMask(SubReg)
1078 : MRI.getMaxLaneMaskForVReg(Reg);
1079 for (LiveInterval::SubRange &S : LI.subranges()) {
1080 if ((S.LaneMask & LaneMask).none())
1081 continue;
1082 updateRange(S, VirtRegOrUnit(Reg), S.LaneMask);
1083 }
1084 }
1085 updateRange(LI, VirtRegOrUnit(Reg), LaneBitmask::getNone());
1086 // If main range has a hole and we are moving a subrange use across
1087 // the hole updateRange() cannot properly handle it since it only
1088 // gets the LiveRange and not the whole LiveInterval. As a result
1089 // we may end up with a main range not covering all subranges.
1090 // This is extremely rare case, so let's check and reconstruct the
1091 // main range.
1092 if (LI.hasSubRanges()) {
1093 unsigned SubReg = MO.getSubReg();
1094 LaneBitmask LaneMask = SubReg ? TRI.getSubRegIndexLaneMask(SubReg)
1095 : MRI.getMaxLaneMaskForVReg(Reg);
1096 for (LiveInterval::SubRange &S : LI.subranges()) {
1097 if ((S.LaneMask & LaneMask).none() || LI.covers(S))
1098 continue;
1099 LI.clear();
1100 LIS.constructMainRangeFromSubranges(LI);
1101 break;
1102 }
1103 }
1104
1105 continue;
1106 }
1107
1108 // For physregs, only update the regunits that actually have a
1109 // precomputed live range.
1110 for (MCRegUnit Unit : TRI.regunits(Reg.asMCReg()))
1111 if (LiveRange *LR = getRegUnitLI(Unit))
1112 updateRange(*LR, VirtRegOrUnit(Unit), LaneBitmask::getNone());
1113 }
1114 if (hasRegMask)
1115 updateRegMaskSlots();
1116 }
1117
1118private:
1119 /// Update a single live range, assuming an instruction has been moved from
1120 /// OldIdx to NewIdx.
1121 void updateRange(LiveRange &LR, VirtRegOrUnit VRegOrUnit,
1122 LaneBitmask LaneMask) {
1123 if (!Updated.insert(&LR).second)
1124 return;
1125 LLVM_DEBUG({
1126 dbgs() << " ";
1127 if (VRegOrUnit.isVirtualReg()) {
1128 dbgs() << printReg(VRegOrUnit.asVirtualReg());
1129 if (LaneMask.any())
1130 dbgs() << " L" << PrintLaneMask(LaneMask);
1131 } else {
1132 dbgs() << printRegUnit(VRegOrUnit.asMCRegUnit(), &TRI);
1133 }
1134 dbgs() << ":\t" << LR << '\n';
1135 });
1136 if (SlotIndex::isEarlierInstr(OldIdx, NewIdx))
1137 handleMoveDown(LR);
1138 else
1139 handleMoveUp(LR, VRegOrUnit, LaneMask);
1140 LLVM_DEBUG(dbgs() << " -->\t" << LR << '\n');
1141 assert(LR.verify());
1142 }
1143
1144 /// Update LR to reflect an instruction has been moved downwards from OldIdx
1145 /// to NewIdx (OldIdx < NewIdx).
1146 void handleMoveDown(LiveRange &LR) {
1147 LiveRange::iterator E = LR.end();
1148 // Segment going into OldIdx.
1149 LiveRange::iterator OldIdxIn = LR.find(OldIdx.getBaseIndex());
1150
1151 // No value live before or after OldIdx? Nothing to do.
1152 if (OldIdxIn == E || SlotIndex::isEarlierInstr(OldIdx, OldIdxIn->start))
1153 return;
1154
1155 LiveRange::iterator OldIdxOut;
1156 // Do we have a value live-in to OldIdx?
1157 if (SlotIndex::isEarlierInstr(OldIdxIn->start, OldIdx)) {
1158 // If the live-in value already extends to NewIdx, there is nothing to do.
1159 if (SlotIndex::isEarlierEqualInstr(NewIdx, OldIdxIn->end))
1160 return;
1161 // Aggressively remove all kill flags from the old kill point.
1162 // Kill flags shouldn't be used while live intervals exist, they will be
1163 // reinserted by VirtRegRewriter.
1164 if (MachineInstr *KillMI = LIS.getInstructionFromIndex(OldIdxIn->end))
1165 for (MachineOperand &MOP : mi_bundle_ops(*KillMI))
1166 if (MOP.isReg() && MOP.isUse())
1167 MOP.setIsKill(false);
1168
1169 // Is there a def before NewIdx which is not OldIdx?
1170 LiveRange::iterator Next = std::next(OldIdxIn);
1171 if (Next != E && !SlotIndex::isSameInstr(OldIdx, Next->start) &&
1172 SlotIndex::isEarlierInstr(Next->start, NewIdx)) {
1173 // If we are here then OldIdx was just a use but not a def. We only have
1174 // to ensure liveness extends to NewIdx.
1175 LiveRange::iterator NewIdxIn =
1176 LR.advanceTo(Next, NewIdx.getBaseIndex());
1177 // Extend the segment before NewIdx if necessary.
1178 if (NewIdxIn == E ||
1179 !SlotIndex::isEarlierInstr(NewIdxIn->start, NewIdx)) {
1180 LiveRange::iterator Prev = std::prev(NewIdxIn);
1181 Prev->end = NewIdx.getRegSlot();
1182 }
1183 // Extend OldIdxIn.
1184 OldIdxIn->end = Next->start;
1185 return;
1186 }
1187
1188 // Adjust OldIdxIn->end to reach NewIdx. This may temporarily make LR
1189 // invalid by overlapping ranges.
1190 bool isKill = SlotIndex::isSameInstr(OldIdx, OldIdxIn->end);
1191 OldIdxIn->end = NewIdx.getRegSlot(OldIdxIn->end.isEarlyClobber());
1192 // If this was not a kill, then there was no def and we're done.
1193 if (!isKill)
1194 return;
1195
1196 // Did we have a Def at OldIdx?
1197 OldIdxOut = Next;
1198 if (OldIdxOut == E || !SlotIndex::isSameInstr(OldIdx, OldIdxOut->start))
1199 return;
1200 } else {
1201 OldIdxOut = OldIdxIn;
1202 }
1203
1204 // If we are here then there is a Definition at OldIdx. OldIdxOut points
1205 // to the segment starting there.
1206 assert(OldIdxOut != E && SlotIndex::isSameInstr(OldIdx, OldIdxOut->start) &&
1207 "No def?");
1208 VNInfo *OldIdxVNI = OldIdxOut->valno;
1209 assert(OldIdxVNI->def == OldIdxOut->start && "Inconsistent def");
1210
1211 // If the defined value extends beyond NewIdx, just move the beginning
1212 // of the segment to NewIdx.
1213 SlotIndex NewIdxDef = NewIdx.getRegSlot(OldIdxOut->start.isEarlyClobber());
1214 if (SlotIndex::isEarlierInstr(NewIdxDef, OldIdxOut->end)) {
1215 OldIdxVNI->def = NewIdxDef;
1216 OldIdxOut->start = OldIdxVNI->def;
1217 return;
1218 }
1219
1220 // If we are here then we have a Definition at OldIdx which ends before
1221 // NewIdx.
1222
1223 // Is there an existing Def at NewIdx?
1224 LiveRange::iterator AfterNewIdx
1225 = LR.advanceTo(OldIdxOut, NewIdx.getRegSlot());
1226 bool OldIdxDefIsDead = OldIdxOut->end.isDead();
1227 if (!OldIdxDefIsDead &&
1228 SlotIndex::isEarlierInstr(OldIdxOut->end, NewIdxDef)) {
1229 // OldIdx is not a dead def, and NewIdxDef is inside a new interval.
1230 VNInfo *DefVNI;
1231 if (OldIdxOut != LR.begin() &&
1232 !SlotIndex::isEarlierInstr(std::prev(OldIdxOut)->end,
1233 OldIdxOut->start)) {
1234 // There is no gap between OldIdxOut and its predecessor anymore,
1235 // merge them.
1236 LiveRange::iterator IPrev = std::prev(OldIdxOut);
1237 DefVNI = OldIdxVNI;
1238 IPrev->end = OldIdxOut->end;
1239 } else {
1240 // The value is live in to OldIdx
1241 LiveRange::iterator INext = std::next(OldIdxOut);
1242 assert(INext != E && "Must have following segment");
1243 // We merge OldIdxOut and its successor. As we're dealing with subreg
1244 // reordering, there is always a successor to OldIdxOut in the same BB
1245 // We don't need INext->valno anymore and will reuse for the new segment
1246 // we create later.
1247 DefVNI = OldIdxVNI;
1248 INext->start = OldIdxOut->end;
1249 INext->valno->def = INext->start;
1250 }
1251 // If NewIdx is behind the last segment, extend that and append a new one.
1252 if (AfterNewIdx == E) {
1253 // OldIdxOut is undef at this point, Slide (OldIdxOut;AfterNewIdx] up
1254 // one position.
1255 // |- ?/OldIdxOut -| |- X0 -| ... |- Xn -| end
1256 // => |- X0/OldIdxOut -| ... |- Xn -| |- undef/NewS -| end
1257 std::copy(std::next(OldIdxOut), E, OldIdxOut);
1258 // The last segment is undefined now, reuse it for a dead def.
1259 LiveRange::iterator NewSegment = std::prev(E);
1260 *NewSegment = LiveRange::Segment(NewIdxDef, NewIdxDef.getDeadSlot(),
1261 DefVNI);
1262 DefVNI->def = NewIdxDef;
1263
1264 LiveRange::iterator Prev = std::prev(NewSegment);
1265 Prev->end = NewIdxDef;
1266 } else {
1267 // OldIdxOut is undef at this point, Slide (OldIdxOut;AfterNewIdx] up
1268 // one position.
1269 // |- ?/OldIdxOut -| |- X0 -| ... |- Xn/AfterNewIdx -| |- Next -|
1270 // => |- X0/OldIdxOut -| ... |- Xn -| |- Xn/AfterNewIdx -| |- Next -|
1271 std::copy(std::next(OldIdxOut), std::next(AfterNewIdx), OldIdxOut);
1272 LiveRange::iterator Prev = std::prev(AfterNewIdx);
1273 // We have two cases:
1274 if (SlotIndex::isEarlierInstr(Prev->start, NewIdxDef)) {
1275 // Case 1: NewIdx is inside a liverange. Split this liverange at
1276 // NewIdxDef into the segment "Prev" followed by "NewSegment".
1277 LiveRange::iterator NewSegment = AfterNewIdx;
1278 *NewSegment = LiveRange::Segment(NewIdxDef, Prev->end, Prev->valno);
1279 Prev->valno->def = NewIdxDef;
1280
1281 *Prev = LiveRange::Segment(Prev->start, NewIdxDef, DefVNI);
1282 DefVNI->def = Prev->start;
1283 } else {
1284 // Case 2: NewIdx is in a lifetime hole. Keep AfterNewIdx as is and
1285 // turn Prev into a segment from NewIdx to AfterNewIdx->start.
1286 *Prev = LiveRange::Segment(NewIdxDef, AfterNewIdx->start, DefVNI);
1287 DefVNI->def = NewIdxDef;
1288 assert(DefVNI != AfterNewIdx->valno);
1289 }
1290 }
1291 return;
1292 }
1293
1294 if (AfterNewIdx != E &&
1295 SlotIndex::isSameInstr(AfterNewIdx->start, NewIdxDef)) {
1296 // There is an existing def at NewIdx. The def at OldIdx is coalesced into
1297 // that value.
1298 assert(AfterNewIdx->valno != OldIdxVNI && "Multiple defs of value?");
1299 LR.removeValNo(OldIdxVNI);
1300 } else {
1301 // There was no existing def at NewIdx. We need to create a dead def
1302 // at NewIdx. Shift segments over the old OldIdxOut segment, this frees
1303 // a new segment at the place where we want to construct the dead def.
1304 // |- OldIdxOut -| |- X0 -| ... |- Xn -| |- AfterNewIdx -|
1305 // => |- X0/OldIdxOut -| ... |- Xn -| |- undef/NewS. -| |- AfterNewIdx -|
1306 assert(AfterNewIdx != OldIdxOut && "Inconsistent iterators");
1307 std::copy(std::next(OldIdxOut), AfterNewIdx, OldIdxOut);
1308 // We can reuse OldIdxVNI now.
1309 LiveRange::iterator NewSegment = std::prev(AfterNewIdx);
1310 VNInfo *NewSegmentVNI = OldIdxVNI;
1311 NewSegmentVNI->def = NewIdxDef;
1312 *NewSegment = LiveRange::Segment(NewIdxDef, NewIdxDef.getDeadSlot(),
1313 NewSegmentVNI);
1314 }
1315 }
1316
1317 /// Update LR to reflect an instruction has been moved upwards from OldIdx
1318 /// to NewIdx (NewIdx < OldIdx).
1319 void handleMoveUp(LiveRange &LR, VirtRegOrUnit VRegOrUnit,
1320 LaneBitmask LaneMask) {
1321 LiveRange::iterator E = LR.end();
1322 // Segment going into OldIdx.
1323 LiveRange::iterator OldIdxIn = LR.find(OldIdx.getBaseIndex());
1324
1325 // No value live before or after OldIdx? Nothing to do.
1326 if (OldIdxIn == E || SlotIndex::isEarlierInstr(OldIdx, OldIdxIn->start))
1327 return;
1328
1329 LiveRange::iterator OldIdxOut;
1330 // Do we have a value live-in to OldIdx?
1331 if (SlotIndex::isEarlierInstr(OldIdxIn->start, OldIdx)) {
1332 // If the live-in value isn't killed here, then we have no Def at
1333 // OldIdx, moreover the value must be live at NewIdx so there is nothing
1334 // to do.
1335 bool isKill = SlotIndex::isSameInstr(OldIdx, OldIdxIn->end);
1336 if (!isKill)
1337 return;
1338
1339 // At this point we have to move OldIdxIn->end back to the nearest
1340 // previous use or (dead-)def but no further than NewIdx.
1341 SlotIndex DefBeforeOldIdx
1342 = std::max(OldIdxIn->start.getDeadSlot(),
1343 NewIdx.getRegSlot(OldIdxIn->end.isEarlyClobber()));
1344 OldIdxIn->end = findLastUseBefore(DefBeforeOldIdx, VRegOrUnit, LaneMask);
1345
1346 // Did we have a Def at OldIdx? If not we are done now.
1347 OldIdxOut = std::next(OldIdxIn);
1348 if (OldIdxOut == E || !SlotIndex::isSameInstr(OldIdx, OldIdxOut->start))
1349 return;
1350 } else {
1351 OldIdxOut = OldIdxIn;
1352 OldIdxIn = OldIdxOut != LR.begin() ? std::prev(OldIdxOut) : E;
1353 }
1354
1355 // If we are here then there is a Definition at OldIdx. OldIdxOut points
1356 // to the segment starting there.
1357 assert(OldIdxOut != E && SlotIndex::isSameInstr(OldIdx, OldIdxOut->start) &&
1358 "No def?");
1359 VNInfo *OldIdxVNI = OldIdxOut->valno;
1360 assert(OldIdxVNI->def == OldIdxOut->start && "Inconsistent def");
1361 bool OldIdxDefIsDead = OldIdxOut->end.isDead();
1362
1363 // Is there an existing def at NewIdx?
1364 SlotIndex NewIdxDef = NewIdx.getRegSlot(OldIdxOut->start.isEarlyClobber());
1365 LiveRange::iterator NewIdxOut = LR.find(NewIdx.getRegSlot());
1366 if (SlotIndex::isSameInstr(NewIdxOut->start, NewIdx)) {
1367 assert(NewIdxOut->valno != OldIdxVNI &&
1368 "Same value defined more than once?");
1369 // If OldIdx was a dead def remove it.
1370 if (!OldIdxDefIsDead) {
1371 // Remove segment starting at NewIdx and move begin of OldIdxOut to
1372 // NewIdx so it can take its place.
1373 OldIdxVNI->def = NewIdxDef;
1374 OldIdxOut->start = NewIdxDef;
1375 LR.removeValNo(NewIdxOut->valno);
1376 } else {
1377 // Simply remove the dead def at OldIdx.
1378 LR.removeValNo(OldIdxVNI);
1379 }
1380 } else {
1381 // Previously nothing was live after NewIdx, so all we have to do now is
1382 // move the begin of OldIdxOut to NewIdx.
1383 if (!OldIdxDefIsDead) {
1384 // Do we have any intermediate Defs between OldIdx and NewIdx?
1385 if (OldIdxIn != E &&
1386 SlotIndex::isEarlierInstr(NewIdxDef, OldIdxIn->start)) {
1387 // OldIdx is not a dead def and NewIdx is before predecessor start.
1388 LiveRange::iterator NewIdxIn = NewIdxOut;
1389 assert(NewIdxIn == LR.find(NewIdx.getBaseIndex()));
1390 const SlotIndex SplitPos = NewIdxDef;
1391 OldIdxVNI = OldIdxIn->valno;
1392
1393 SlotIndex NewDefEndPoint = std::next(NewIdxIn)->end;
1394 LiveRange::iterator Prev = std::prev(OldIdxIn);
1395 if (OldIdxIn != LR.begin() &&
1396 SlotIndex::isEarlierInstr(NewIdx, Prev->end)) {
1397 // If the segment before OldIdx read a value defined earlier than
1398 // NewIdx, the moved instruction also reads and forwards that
1399 // value. Extend the lifetime of the new def point.
1400
1401 // Extend to where the previous range started, unless there is
1402 // another redef first.
1403 NewDefEndPoint = std::min(OldIdxIn->start,
1404 std::next(NewIdxOut)->start);
1405 }
1406
1407 // Merge the OldIdxIn and OldIdxOut segments into OldIdxOut.
1408 OldIdxOut->valno->def = OldIdxIn->start;
1409 *OldIdxOut = LiveRange::Segment(OldIdxIn->start, OldIdxOut->end,
1410 OldIdxOut->valno);
1411 // OldIdxIn and OldIdxVNI are now undef and can be overridden.
1412 // We Slide [NewIdxIn, OldIdxIn) down one position.
1413 // |- X0/NewIdxIn -| ... |- Xn-1 -||- Xn/OldIdxIn -||- OldIdxOut -|
1414 // => |- undef/NexIdxIn -| |- X0 -| ... |- Xn-1 -| |- Xn/OldIdxOut -|
1415 std::copy_backward(NewIdxIn, OldIdxIn, OldIdxOut);
1416 // NewIdxIn is now considered undef so we can reuse it for the moved
1417 // value.
1418 LiveRange::iterator NewSegment = NewIdxIn;
1419 LiveRange::iterator Next = std::next(NewSegment);
1420 if (SlotIndex::isEarlierInstr(Next->start, NewIdx)) {
1421 // There is no gap between NewSegment and its predecessor.
1422 *NewSegment = LiveRange::Segment(Next->start, SplitPos,
1423 Next->valno);
1424
1425 *Next = LiveRange::Segment(SplitPos, NewDefEndPoint, OldIdxVNI);
1426 Next->valno->def = SplitPos;
1427 } else {
1428 // There is a gap between NewSegment and its predecessor
1429 // Value becomes live in.
1430 *NewSegment = LiveRange::Segment(SplitPos, Next->start, OldIdxVNI);
1431 NewSegment->valno->def = SplitPos;
1432 }
1433 } else {
1434 // Leave the end point of a live def.
1435 OldIdxOut->start = NewIdxDef;
1436 OldIdxVNI->def = NewIdxDef;
1437 if (OldIdxIn != E && SlotIndex::isEarlierInstr(NewIdx, OldIdxIn->end))
1438 OldIdxIn->end = NewIdxDef;
1439 }
1440 } else if (OldIdxIn != E
1441 && SlotIndex::isEarlierInstr(NewIdxOut->start, NewIdx)
1442 && SlotIndex::isEarlierInstr(NewIdx, NewIdxOut->end)) {
1443 // OldIdxVNI is a dead def that has been moved into the middle of
1444 // another value in LR. That can happen when LR is a whole register,
1445 // but the dead def is a write to a subreg that is dead at NewIdx.
1446 // The dead def may have been moved across other values
1447 // in LR, so move OldIdxOut up to NewIdxOut. Slide [NewIdxOut;OldIdxOut)
1448 // down one position.
1449 // |- X0/NewIdxOut -| ... |- Xn-1 -| |- Xn/OldIdxOut -| |- next - |
1450 // => |- X0/NewIdxOut -| |- X0 -| ... |- Xn-1 -| |- next -|
1451 std::copy_backward(NewIdxOut, OldIdxOut, std::next(OldIdxOut));
1452 // Modify the segment at NewIdxOut and the following segment to meet at
1453 // the point of the dead def, with the following segment getting
1454 // OldIdxVNI as its value number.
1455 *NewIdxOut = LiveRange::Segment(
1456 NewIdxOut->start, NewIdxDef.getRegSlot(), NewIdxOut->valno);
1457 *(NewIdxOut + 1) = LiveRange::Segment(
1458 NewIdxDef.getRegSlot(), (NewIdxOut + 1)->end, OldIdxVNI);
1459 OldIdxVNI->def = NewIdxDef;
1460 // Modify subsequent segments to be defined by the moved def OldIdxVNI.
1461 for (auto *Idx = NewIdxOut + 2; Idx <= OldIdxOut; ++Idx)
1462 Idx->valno = OldIdxVNI;
1463 // Aggressively remove all dead flags from the former dead definition.
1464 // Kill/dead flags shouldn't be used while live intervals exist; they
1465 // will be reinserted by VirtRegRewriter.
1466 if (MachineInstr *KillMI = LIS.getInstructionFromIndex(NewIdx))
1467 for (MIBundleOperands MO(*KillMI); MO.isValid(); ++MO)
1468 if (MO->isReg() && !MO->isUse())
1469 MO->setIsDead(false);
1470 } else {
1471 // OldIdxVNI is a dead def. It may have been moved across other values
1472 // in LR, so move OldIdxOut up to NewIdxOut. Slide [NewIdxOut;OldIdxOut)
1473 // down one position.
1474 // |- X0/NewIdxOut -| ... |- Xn-1 -| |- Xn/OldIdxOut -| |- next - |
1475 // => |- undef/NewIdxOut -| |- X0 -| ... |- Xn-1 -| |- next -|
1476 std::copy_backward(NewIdxOut, OldIdxOut, std::next(OldIdxOut));
1477 // OldIdxVNI can be reused now to build a new dead def segment.
1478 LiveRange::iterator NewSegment = NewIdxOut;
1479 VNInfo *NewSegmentVNI = OldIdxVNI;
1480 *NewSegment = LiveRange::Segment(NewIdxDef, NewIdxDef.getDeadSlot(),
1481 NewSegmentVNI);
1482 NewSegmentVNI->def = NewIdxDef;
1483 }
1484 }
1485 }
1486
1487 void updateRegMaskSlots() {
1489 llvm::lower_bound(LIS.RegMaskSlots, OldIdx);
1490 assert(RI != LIS.RegMaskSlots.end() && *RI == OldIdx.getRegSlot() &&
1491 "No RegMask at OldIdx.");
1492 *RI = NewIdx.getRegSlot();
1493 assert((RI == LIS.RegMaskSlots.begin() ||
1494 SlotIndex::isEarlierInstr(*std::prev(RI), *RI)) &&
1495 "Cannot move regmask instruction above another call");
1496 assert((std::next(RI) == LIS.RegMaskSlots.end() ||
1497 SlotIndex::isEarlierInstr(*RI, *std::next(RI))) &&
1498 "Cannot move regmask instruction below another call");
1499 }
1500
1501 // Return the last use of reg between NewIdx and OldIdx.
1502 SlotIndex findLastUseBefore(SlotIndex Before, VirtRegOrUnit VRegOrUnit,
1503 LaneBitmask LaneMask) {
1504 if (VRegOrUnit.isVirtualReg()) {
1505 SlotIndex LastUse = Before;
1506 for (MachineOperand &MO :
1507 MRI.use_nodbg_operands(VRegOrUnit.asVirtualReg())) {
1508 if (MO.isUndef())
1509 continue;
1510 unsigned SubReg = MO.getSubReg();
1511 if (SubReg != 0 && LaneMask.any()
1512 && (TRI.getSubRegIndexLaneMask(SubReg) & LaneMask).none())
1513 continue;
1514
1515 const MachineInstr &MI = *MO.getParent();
1516 SlotIndex InstSlot = LIS.getSlotIndexes()->getInstructionIndex(MI);
1517 if (InstSlot > LastUse && InstSlot < OldIdx)
1518 LastUse = InstSlot.getRegSlot();
1519 }
1520 return LastUse;
1521 }
1522
1523 // This is a regunit interval, so scanning the use list could be very
1524 // expensive. Scan upwards from OldIdx instead.
1525 assert(Before < OldIdx && "Expected upwards move");
1526 SlotIndexes *Indexes = LIS.getSlotIndexes();
1527 MachineBasicBlock *MBB = Indexes->getMBBFromIndex(Before);
1528
1529 // OldIdx may not correspond to an instruction any longer, so set MII to
1530 // point to the next instruction after OldIdx, or MBB->end().
1532 if (MachineInstr *MI = Indexes->getInstructionFromIndex(
1533 Indexes->getNextNonNullIndex(OldIdx)))
1534 if (MI->getParent() == MBB)
1535 MII = MI;
1536
1538 while (MII != Begin) {
1539 if ((--MII)->isDebugOrPseudoInstr())
1540 continue;
1541 SlotIndex Idx = Indexes->getInstructionIndex(*MII);
1542
1543 // Stop searching when Before is reached.
1544 if (!SlotIndex::isEarlierInstr(Before, Idx))
1545 return Before;
1546
1547 // Check if MII uses Reg.
1548 for (MIBundleOperands MO(*MII); MO.isValid(); ++MO)
1549 if (MO->isReg() && !MO->isUndef() && MO->getReg().isPhysical() &&
1550 TRI.hasRegUnit(MO->getReg(), VRegOrUnit.asMCRegUnit()))
1551 return Idx.getRegSlot();
1552 }
1553 // Didn't reach Before. It must be the first instruction in the block.
1554 return Before;
1555 }
1556};
1557
1559 // It is fine to move a bundle as a whole, but not an individual instruction
1560 // inside it.
1561 assert((!MI.isBundled() || MI.getOpcode() == TargetOpcode::BUNDLE) &&
1562 "Cannot move instruction in bundle");
1563 SlotIndex OldIndex = Indexes->getInstructionIndex(MI);
1564 Indexes->removeMachineInstrFromMaps(MI);
1565 SlotIndex NewIndex = Indexes->insertMachineInstrInMaps(MI);
1566 assert(getMBBStartIdx(MI.getParent()) <= OldIndex &&
1567 OldIndex < getMBBEndIdx(MI.getParent()) &&
1568 "Cannot handle moves across basic block boundaries.");
1569
1570 HMEditor HME(*this, *MRI, *TRI, OldIndex, NewIndex, UpdateFlags);
1571 HME.updateAllRanges(&MI);
1572}
1573
1575 bool UpdateFlags) {
1576 assert((BundleStart.getOpcode() == TargetOpcode::BUNDLE) &&
1577 "Bundle start is not a bundle");
1579 const SlotIndex NewIndex = Indexes->insertMachineInstrInMaps(BundleStart);
1580 auto BundleEnd = getBundleEnd(BundleStart.getIterator());
1581
1582 auto I = BundleStart.getIterator();
1583 I++;
1584 while (I != BundleEnd) {
1585 if (!Indexes->hasIndex(*I))
1586 continue;
1587 SlotIndex OldIndex = Indexes->getInstructionIndex(*I, true);
1588 ToProcess.push_back(OldIndex);
1589 Indexes->removeMachineInstrFromMaps(*I, true);
1590 I++;
1591 }
1592 for (SlotIndex OldIndex : ToProcess) {
1593 HMEditor HME(*this, *MRI, *TRI, OldIndex, NewIndex, UpdateFlags);
1594 HME.updateAllRanges(&BundleStart);
1595 }
1596
1597 // Fix up dead defs
1598 const SlotIndex Index = getInstructionIndex(BundleStart);
1599 for (MachineOperand &MO : BundleStart.operands()) {
1600 if (!MO.isReg())
1601 continue;
1602 Register Reg = MO.getReg();
1603 if (Reg.isVirtual() && hasInterval(Reg) && !MO.isUndef()) {
1604 LiveInterval &LI = getInterval(Reg);
1605 LiveQueryResult LRQ = LI.Query(Index);
1606 if (LRQ.isDeadDef())
1607 MO.setIsDead();
1608 }
1609 }
1610}
1611
1612void LiveIntervals::repairOldRegInRange(const MachineBasicBlock::iterator Begin,
1614 const SlotIndex EndIdx, LiveRange &LR,
1615 const Register Reg,
1616 LaneBitmask LaneMask) {
1617 LiveInterval::iterator LII = LR.find(EndIdx);
1618 SlotIndex lastUseIdx;
1619 if (LII != LR.end() && LII->start < EndIdx) {
1620 lastUseIdx = LII->end;
1621 } else if (LII == LR.begin()) {
1622 // We may not have a liverange at all if this is a subregister untouched
1623 // between \p Begin and \p End.
1624 } else {
1625 --LII;
1626 }
1627
1628 for (MachineBasicBlock::iterator I = End; I != Begin;) {
1629 --I;
1630 MachineInstr &MI = *I;
1631 if (MI.isDebugOrPseudoInstr())
1632 continue;
1633
1634 SlotIndex instrIdx = getInstructionIndex(MI);
1635 bool isStartValid = getInstructionFromIndex(LII->start);
1636 bool isEndValid = getInstructionFromIndex(LII->end);
1637
1638 // FIXME: This doesn't currently handle early-clobber or multiple removed
1639 // defs inside of the region to repair.
1640 for (const MachineOperand &MO : MI.operands()) {
1641 if (!MO.isReg() || MO.getReg() != Reg)
1642 continue;
1643
1644 unsigned SubReg = MO.getSubReg();
1645 LaneBitmask Mask = TRI->getSubRegIndexLaneMask(SubReg);
1646 if ((Mask & LaneMask).none())
1647 continue;
1648
1649 if (MO.isDef()) {
1650 if (!isStartValid) {
1651 if (LII->end.isDead()) {
1652 LII = LR.removeSegment(LII, true);
1653 if (LII != LR.begin())
1654 --LII;
1655 } else {
1656 LII->start = instrIdx.getRegSlot();
1657 LII->valno->def = instrIdx.getRegSlot();
1658 if (MO.getSubReg() && !MO.isUndef())
1659 lastUseIdx = instrIdx.getRegSlot();
1660 else
1661 lastUseIdx = SlotIndex();
1662 continue;
1663 }
1664 }
1665
1666 if (!lastUseIdx.isValid()) {
1667 VNInfo *VNI = LR.getNextValue(instrIdx.getRegSlot(), VNInfoAllocator);
1668 LiveRange::Segment S(instrIdx.getRegSlot(),
1669 instrIdx.getDeadSlot(), VNI);
1670 LII = LR.addSegment(S);
1671 } else if (LII->start != instrIdx.getRegSlot()) {
1672 VNInfo *VNI = LR.getNextValue(instrIdx.getRegSlot(), VNInfoAllocator);
1673 LiveRange::Segment S(instrIdx.getRegSlot(), lastUseIdx, VNI);
1674 LII = LR.addSegment(S);
1675 }
1676
1677 if (MO.getSubReg() && !MO.isUndef())
1678 lastUseIdx = instrIdx.getRegSlot();
1679 else
1680 lastUseIdx = SlotIndex();
1681 } else if (MO.isUse()) {
1682 // FIXME: This should probably be handled outside of this branch,
1683 // either as part of the def case (for defs inside of the region) or
1684 // after the loop over the region.
1685 if (!isEndValid && !LII->end.isBlock())
1686 LII->end = instrIdx.getRegSlot();
1687 if (!lastUseIdx.isValid())
1688 lastUseIdx = instrIdx.getRegSlot();
1689 }
1690 }
1691 }
1692
1693 bool isStartValid = getInstructionFromIndex(LII->start);
1694 if (!isStartValid && LII->end.isDead())
1695 LR.removeSegment(*LII, true);
1696}
1697
1698void
1702 ArrayRef<Register> OrigRegs) {
1703 // Find anchor points, which are at the beginning/end of blocks or at
1704 // instructions that already have indexes.
1705 while (Begin != MBB->begin() && !Indexes->hasIndex(*std::prev(Begin)))
1706 --Begin;
1707 while (End != MBB->end() && !Indexes->hasIndex(*End))
1708 ++End;
1709
1710 SlotIndex EndIdx;
1711 if (End == MBB->end())
1712 EndIdx = getMBBEndIdx(MBB).getPrevSlot();
1713 else
1714 EndIdx = getInstructionIndex(*End);
1715
1716 Indexes->repairIndexesInRange(MBB, Begin, End);
1717
1718 // Make sure a live interval exists for all register operands in the range.
1719 SmallVector<Register> RegsToRepair(OrigRegs);
1720 for (MachineBasicBlock::iterator I = End; I != Begin;) {
1721 --I;
1722 MachineInstr &MI = *I;
1723 if (MI.isDebugOrPseudoInstr())
1724 continue;
1725 for (const MachineOperand &MO : MI.operands()) {
1726 if (MO.isReg() && MO.getReg().isVirtual()) {
1727 Register Reg = MO.getReg();
1728 if (MO.getSubReg() && hasInterval(Reg) &&
1729 MRI->shouldTrackSubRegLiveness(Reg)) {
1730 LiveInterval &LI = getInterval(Reg);
1731 if (!LI.hasSubRanges()) {
1732 // If the new instructions refer to subregs but the old instructions
1733 // did not, throw away any old live interval so it will be
1734 // recomputed with subranges.
1735 removeInterval(Reg);
1736 } else if (MO.isDef()) {
1737 // Similarly if a subreg def has no precise subrange match then
1738 // assume we need to recompute all subranges.
1739 unsigned SubReg = MO.getSubReg();
1740 LaneBitmask Mask = TRI->getSubRegIndexLaneMask(SubReg);
1741 if (llvm::none_of(LI.subranges(),
1742 [Mask](LiveInterval::SubRange &SR) {
1743 return SR.LaneMask == Mask;
1744 })) {
1745 removeInterval(Reg);
1746 }
1747 }
1748 }
1749 if (!hasInterval(Reg)) {
1751 // Don't bother to repair a freshly calculated live interval.
1752 llvm::erase(RegsToRepair, Reg);
1753 }
1754 }
1755 }
1756 }
1757
1758 for (Register Reg : RegsToRepair) {
1759 if (!Reg.isVirtual())
1760 continue;
1761
1762 LiveInterval &LI = getInterval(Reg);
1763 // FIXME: Should we support undefs that gain defs?
1764 if (!LI.hasAtLeastOneValue())
1765 continue;
1766
1767 for (LiveInterval::SubRange &S : LI.subranges())
1768 repairOldRegInRange(Begin, End, EndIdx, S, Reg, S.LaneMask);
1770
1771 repairOldRegInRange(Begin, End, EndIdx, LI, Reg);
1772 }
1773}
1774
1776 for (MCRegUnit Unit : TRI->regunits(Reg)) {
1777 if (LiveRange *LR = getCachedRegUnit(Unit))
1778 if (VNInfo *VNI = LR->getVNInfoAt(Pos))
1779 LR->removeValNo(VNI);
1780 }
1781}
1782
1784 // LI may not have the main range computed yet, but its subranges may
1785 // be present.
1786 VNInfo *VNI = LI.getVNInfoAt(Pos);
1787 if (VNI != nullptr) {
1788 assert(VNI->def.getBaseIndex() == Pos.getBaseIndex());
1789 LI.removeValNo(VNI);
1790 }
1791
1792 // Also remove the value defined in subranges.
1793 for (LiveInterval::SubRange &S : LI.subranges()) {
1794 if (VNInfo *SVNI = S.getVNInfoAt(Pos))
1795 if (SVNI->def.getBaseIndex() == Pos.getBaseIndex())
1796 S.removeValNo(SVNI);
1797 }
1799}
1800
1803 ConnectedVNInfoEqClasses ConEQ(*this);
1804 unsigned NumComp = ConEQ.Classify(LI);
1805 if (NumComp <= 1)
1806 return;
1807 LLVM_DEBUG(dbgs() << " Split " << NumComp << " components: " << LI << '\n');
1808 Register Reg = LI.reg();
1809 for (unsigned I = 1; I < NumComp; ++I) {
1810 Register NewVReg = MRI->cloneVirtualRegister(Reg);
1811 LiveInterval &NewLI = createEmptyInterval(NewVReg);
1812 SplitLIs.push_back(&NewLI);
1813 }
1814 ConEQ.Distribute(LI, SplitLIs.data(), *MRI);
1815}
1816
1818 assert(LICalc && "LICalc not initialized.");
1819 LICalc->reset(MF, getSlotIndexes(), DomTree, &getVNInfoAllocator());
1820 LICalc->constructMainRangeFromSubranges(LI);
1821}
unsigned SubReg
unsigned const MachineRegisterInfo * MRI
MachineInstrBuilder & UseMI
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
Rewrite undef for PHI
MachineBasicBlock & MBB
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds.
Definition Compiler.h:638
This file builds on the ADT/GraphTraits.h file to build generic depth first graph iterator.
const HexagonInstrInfo * TII
IRTranslator LLVM IR MI
A common definition of LaneBitmask for use in TableGen and CodeGen.
static cl::opt< bool > EnablePrecomputePhysRegs("precompute-phys-liveness", cl::Hidden, cl::desc("Eagerly compute live intervals for all physreg units."))
static bool hasLiveThroughUse(const MachineInstr *MI, Register Reg)
Check whether use of reg in MI is live-through.
static void createSegmentsForValues(LiveRange &LR, iterator_range< LiveInterval::vni_iterator > VNIs)
#define I(x, y, z)
Definition MD5.cpp:58
Register Reg
Register const TargetRegisterInfo * TRI
std::pair< uint64_t, uint64_t > Interval
Promote Memory to Register
Definition Mem2Reg.cpp:110
#define INITIALIZE_PASS_DEPENDENCY(depName)
Definition PassSupport.h:42
#define INITIALIZE_PASS_END(passName, arg, name, cfg, analysis)
Definition PassSupport.h:44
#define INITIALIZE_PASS_BEGIN(passName, arg, name, cfg, analysis)
Definition PassSupport.h:39
SI Optimize VGPR LiveRange
This file defines the SmallPtrSet class.
This file defines the SmallVector class.
#define LLVM_DEBUG(...)
Definition Debug.h:114
Toolkit used by handleMove to trim or extend live intervals.
HMEditor(LiveIntervals &LIS, const MachineRegisterInfo &MRI, const TargetRegisterInfo &TRI, SlotIndex OldIdx, SlotIndex NewIdx, bool UpdateFlags)
void updateAllRanges(MachineInstr *MI)
Update all live ranges touched by MI, assuming a move from OldIdx to NewIdx.
LiveRange * getRegUnitLI(unsigned Unit)
This templated class represents "all analyses that operate over <aparticular IR unit>" (e....
Definition Analysis.h:50
PassT::Result & getResult(IRUnitT &IR, ExtraArgTs... ExtraArgs)
Get the result of an analysis pass for a given IR unit.
Represent the analysis usage information of a pass.
LLVM_ABI AnalysisUsage & addRequiredTransitiveID(char &ID)
Definition Pass.cpp:294
AnalysisUsage & addPreservedID(const void *ID)
AnalysisUsage & addPreserved()
Add the specified Pass class to the set of analyses preserved by this pass.
LLVM_ABI void setPreservesCFG()
This function should be called by the pass, iff they do not:
Definition Pass.cpp:270
AnalysisUsage & addRequiredTransitive()
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:41
iterator end() const
Definition ArrayRef.h:136
const_pointer iterator
Definition ArrayRef.h:48
iterator begin() const
Definition ArrayRef.h:135
void resize(unsigned N, bool t=false)
resize - Grow or shrink the bitvector.
Definition BitVector.h:360
void clear()
clear - Removes all bits from the bitvector.
Definition BitVector.h:354
void clearBitsNotInMask(const uint32_t *Mask, unsigned MaskWords=~0u)
clearBitsNotInMask - Clear a bit in this vector for every '0' bit in Mask.
Definition BitVector.h:741
void Reset()
Deallocate all but the current slab and reset the current pointer to the beginning of it,...
Definition Allocator.h:124
ConnectedVNInfoEqClasses - Helper class that can divide VNInfos in a LiveInterval into equivalence cl...
LLVM_ABI void Distribute(LiveInterval &LI, LiveInterval *LIV[], MachineRegisterInfo &MRI)
Distribute values in LI into a separate LiveIntervals for each connected component.
LLVM_ABI unsigned Classify(const LiveRange &LR)
Classify the values in LR into connected components.
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 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 ...
LLVM_ABI Result run(MachineFunction &MF, MachineFunctionAnalysisManager &MFAM)
LLVM_ABI PreservedAnalyses run(MachineFunction &MF, MachineFunctionAnalysisManager &MFAM)
bool runOnMachineFunction(MachineFunction &) override
Pass entry point; Calculates LiveIntervals.
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - This function should be overriden by passes that need analysis information to do t...
LLVM_ABI void repairIntervalsInRange(MachineBasicBlock *MBB, MachineBasicBlock::iterator Begin, MachineBasicBlock::iterator End, ArrayRef< Register > OrigRegs)
Update live intervals for instructions in a range of iterators.
bool hasInterval(Register Reg) const
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.
LLVM_ABI bool hasPHIKill(const LiveInterval &LI, const VNInfo *VNI) const
Returns true if VNI is killed by any PHI-def values in LI.
LLVM_ABI bool checkRegMaskInterference(const LiveInterval &LI, BitVector &UsableRegs)
Test if LI is live across any register mask instructions, and compute a bit mask of physical register...
LLVM_ABI void handleMove(MachineInstr &MI, bool UpdateFlags=false)
Call this method to notify LiveIntervals that instruction MI has been moved within a basic block.
SlotIndexes * getSlotIndexes() const
ArrayRef< const uint32_t * > getRegMaskBits() const
Returns an array of register mask pointers corresponding to getRegMaskSlots().
LiveInterval & getOrCreateEmptyInterval(Register Reg)
Return an existing interval for Reg.
LLVM_ABI void addKillFlags(const VirtRegMap *)
Add kill flags to any instruction that kills a virtual register.
SlotIndex getInstructionIndex(const MachineInstr &Instr) const
Returns the base index of the given instruction.
LLVM_ABI bool invalidate(MachineFunction &MF, const PreservedAnalyses &PA, MachineFunctionAnalysisManager::Invalidator &Inv)
VNInfo::Allocator & getVNInfoAllocator()
ArrayRef< const uint32_t * > getRegMaskBitsInBlock(unsigned MBBNum) const
Returns an array of mask pointers corresponding to getRegMaskSlotsInBlock(MBBNum).
SlotIndex getMBBEndIdx(const MachineBasicBlock *mbb) const
Return the last index in the given basic block.
static LLVM_ABI float getSpillWeight(bool isDef, bool isUse, const MachineBlockFrequencyInfo *MBFI, const MachineInstr &MI, ProfileSummaryInfo *PSI=nullptr)
Calculate the spill weight to assign to a single instruction.
ArrayRef< SlotIndex > getRegMaskSlots() const
Returns a sorted array of slot indices of all instructions with register mask operands.
LiveRange & getRegUnit(unsigned Unit)
Return the live range for register unit Unit.
ArrayRef< SlotIndex > getRegMaskSlotsInBlock(unsigned MBBNum) const
Returns a sorted array of slot indices of all instructions with register mask operands in the basic b...
LiveRange * getCachedRegUnit(unsigned Unit)
Return the live range for register unit Unit if it has already been computed, or nullptr if it hasn't...
LiveInterval & getInterval(Register Reg)
friend class LiveIntervalsAnalysis
LLVM_ABI void pruneValue(LiveRange &LR, SlotIndex Kill, SmallVectorImpl< SlotIndex > *EndPoints)
If LR has a live value at Kill, prune its live range by removing any liveness reachable from Kill.
void removeInterval(Register Reg)
Interval removal.
LLVM_ABI void handleMoveIntoNewBundle(MachineInstr &BundleStart, bool UpdateFlags=false)
Update intervals of operands of all instructions in the newly created bundle specified by BundleStart...
LLVM_ABI MachineBasicBlock * intervalIsInOneMBB(const LiveInterval &LI) const
If LI is confined to a single basic block, return a pointer to that block.
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.
LLVM_ABI LiveInterval::Segment addSegmentToEndOfBlock(Register Reg, MachineInstr &startInst)
Given a register and an instruction, adds a live segment from that instruction to the end of its MBB.
LLVM_ABI bool shrinkToUses(LiveInterval *li, SmallVectorImpl< MachineInstr * > *dead=nullptr)
After removing some uses of a register, shrink its live range to just the remaining uses.
LLVM_ABI void constructMainRangeFromSubranges(LiveInterval &LI)
For live interval LI with correct SubRanges construct matching information for the main live range.
LiveInterval & createEmptyInterval(Register Reg)
Interval creation.
LLVM_ABI void extendToIndices(LiveRange &LR, ArrayRef< SlotIndex > Indices, ArrayRef< SlotIndex > Undefs)
Extend the live range LR to reach all points in Indices.
LLVM_ABI void dump() const
LLVM_ABI void print(raw_ostream &O) const
Implement the dump method.
LLVM_ABI void removePhysRegDefAt(MCRegister Reg, SlotIndex Pos)
Remove value numbers and related live segments starting at position Pos that are part of any liverang...
LLVM_ABI void splitSeparateComponents(LiveInterval &LI, SmallVectorImpl< LiveInterval * > &SplitLIs)
Split separate components in LiveInterval LI into separate intervals.
MachineBasicBlock * getMBBFromIndex(SlotIndex index) const
LiveInterval & createAndComputeVirtRegInterval(Register Reg)
Result of a LiveRange query.
VNInfo * valueOutOrDead() const
Returns the value alive at the end of the instruction, if any.
bool isDeadDef() const
Return true if this instruction has a dead def.
VNInfo * valueIn() const
Return the value that is live-in to the instruction.
VNInfo * valueDefined() const
Return the value defined by this instruction, if any.
SlotIndex endPoint() const
Return the end point of the last live range segment to interact with the instruction,...
static LLVM_ABI bool isJointlyDominated(const MachineBasicBlock *MBB, ArrayRef< SlotIndex > Defs, const SlotIndexes &Indexes)
A diagnostic function to check if the end of the block MBB is jointly dominated by the blocks corresp...
This class represents the liveness of a register, stack slot, etc.
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.
iterator_range< vni_iterator > vnis()
Segments::const_iterator const_iterator
LLVM_ABI VNInfo * createDeadDef(SlotIndex Def, VNInfo::Allocator &VNIAlloc)
createDeadDef - Make sure the range has a value defined at Def.
LLVM_ABI bool covers(const LiveRange &Other) const
Returns true if all segments of the Other live range are completely covered by this live range.
iterator advanceTo(iterator I, SlotIndex Pos)
advanceTo - Advance the specified iterator to point to the Segment containing the specified position,...
LLVM_ABI void removeValNo(VNInfo *ValNo)
removeValNo - Remove all the segments defined by the specified value#.
bool empty() const
LiveQueryResult Query(SlotIndex Idx) const
Query Liveness at Idx.
VNInfo * getVNInfoBefore(SlotIndex Idx) const
getVNInfoBefore - Return the VNInfo that is live up to but not necessarily including Idx,...
bool verify() const
Walk the range and assert if any invariants fail to hold.
iterator begin()
SlotIndex beginIndex() const
beginIndex - Return the lowest numbered slot covered.
VNInfoList valnos
SlotIndex endIndex() const
endNumber - return the maximum point of the range of the whole, exclusive.
bool hasAtLeastOneValue() const
VNInfo * getNextValue(SlotIndex Def, VNInfo::Allocator &VNInfoAllocator)
getNextValue - Create a new value number and return it.
iterator FindSegmentContaining(SlotIndex Idx)
Return an iterator to the segment that contains the specified index, or end() if there is none.
LLVM_ABI void removeSegment(SlotIndex Start, SlotIndex End, bool RemoveDeadValNo=false)
Remove the specified interval from this live range.
LLVM_ABI void flushSegmentSet()
Flush segment set into the regular segment vector.
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().
MCRegUnitMaskIterator enumerates a list of register units and their associated lane masks for Reg.
bool isValid() const
Returns true if this iterator is not yet at the end.
Wrapper class representing physical registers. Should be passed by value.
Definition MCRegister.h:33
bool isEHPad() const
Returns true if the block is a landing pad.
iterator_range< livein_iterator > liveins() const
int getNumber() const
MachineBasicBlocks are uniquely numbered at the function level, unless they're not in a MachineFuncti...
LLVM_ABI const uint32_t * getBeginClobberMask(const TargetRegisterInfo *TRI) const
Get the clobber mask for the start 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()
MachineInstrBundleIterator< MachineInstr > iterator
LLVM_ABI const uint32_t * getEndClobberMask(const TargetRegisterInfo *TRI) const
Get the clobber mask for the end of the basic block.
MachineBlockFrequencyInfo pass uses BlockFrequencyInfoImpl implementation to estimate machine basic b...
double getBlockFreqRelativeToEntryBlock(const MachineBasicBlock *MBB) const
Compute the frequency of the block, relative to the entry block.
Analysis pass which computes a MachineDominatorTree.
Analysis pass which computes a MachineDominatorTree.
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
StringRef getName() const
getName - Return the name of the corresponding LLVM function.
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
void print(raw_ostream &OS, const SlotIndexes *=nullptr) const
print - Print out the MachineFunction in a format suitable for debugging to the specified stream.
Representation of each machine instruction.
unsigned getOpcode() const
Returns the opcode of this MachineInstr.
const MachineBasicBlock * getParent() const
mop_range operands()
MachineOperand class - Representation of each machine instruction operand.
bool isReg() const
isReg - Tests if this is a MO_Register operand.
Register getReg() const
getReg - Returns the register number.
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
static LLVM_ABI PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
AnalysisType & getAnalysis() const
getAnalysis<AnalysisType>() - This function is used by subclasses to get to the analysis information ...
A set of analyses that are preserved following a run of a transformation pass.
Definition Analysis.h:112
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
Definition Analysis.h:118
PreservedAnalysisChecker getChecker() const
Build a checker for this PreservedAnalyses and the specified analysis type.
Definition Analysis.h:275
Analysis providing profile information.
Wrapper class representing virtual and physical registers.
Definition Register.h:19
static Register index2VirtReg(unsigned Index)
Convert a 0-based index to a virtual register number.
Definition Register.h:67
constexpr bool isVirtual() const
Return true if the specified register number is in the virtual register namespace.
Definition Register.h:74
constexpr bool isPhysical() const
Return true if the specified register number is in the physical register namespace.
Definition Register.h:78
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.
bool isBlock() const
isBlock - Returns true if this is a block boundary slot.
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.
static bool isEarlierEqualInstr(SlotIndex A, SlotIndex B)
Return true if A refers to the same instruction as B or an earlier one.
SlotIndex getBaseIndex() const
Returns the base index for associated with this index.
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.
MachineBasicBlock * getMBBFromIndex(SlotIndex index) const
Returns the basic block which the given index falls in.
SlotIndex getNextNonNullIndex(SlotIndex Index)
Returns the next non-null index, if one exists.
SlotIndex getInstructionIndex(const MachineInstr &MI, bool IgnoreBundle=false) const
Returns the base index for the given instruction.
MachineInstr * getInstructionFromIndex(SlotIndex index) const
Returns the instruction for the given index, or null if the given index has no instruction associated...
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
void swap(SmallVectorImpl &RHS)
typename SuperClass::iterator iterator
void push_back(const T &Elt)
pointer data()
Return a pointer to the vector's buffer, even if empty().
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
MI-level Statepoint operands.
Definition StackMaps.h:159
unsigned getNumDeoptArgsIdx() const
Get index of Number Deopt Arguments operand.
Definition StackMaps.h:200
uint64_t getFlags() const
Return the statepoint flags.
Definition StackMaps.h:223
LLVM_ABI unsigned getNumGCPtrIdx()
Get index of number of GC pointers.
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
virtual const TargetInstrInfo * getInstrInfo() const
virtual const TargetRegisterInfo * getRegisterInfo() const =0
Return the target's register information.
VNInfo - Value Number Information.
void markUnused()
Mark this value as unused.
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...
MCRegister getPhys(Register virtReg) const
returns the physical register mapped to the specified virtual register
Definition VirtRegMap.h:91
Wrapper class representing a virtual register or register unit.
Definition Register.h:176
constexpr bool isVirtualReg() const
Definition Register.h:187
constexpr MCRegUnit asMCRegUnit() const
Definition Register.h:191
constexpr Register asVirtualReg() const
Definition Register.h:196
self_iterator getIterator()
Definition ilist_node.h:123
A range adaptor for a pair of iterators.
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition raw_ostream.h:53
This provides a very simple, boring adaptor for a begin and end iterator into a range type.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
constexpr std::underlying_type_t< E > Mask()
Get a bitmask with 1s in all places up to the high-order bit of E's largest value.
initializer< Ty > init(const Ty &Val)
NodeAddr< DefNode * > Def
Definition RDFGraph.h:384
This is an optimization pass for GlobalISel generic memory operations.
void dump(const SparseBitVector< ElementSize > &LHS, raw_ostream &out)
Printable print(const GCNRegPressure &RP, const GCNSubtarget *ST=nullptr, unsigned DynamicVGPRBlockSize=0)
LLVM_ABI cl::opt< bool > UseSegmentSetForPhysRegs
LLVM_ABI char & MachineDominatorsID
MachineDominators - This pass is a machine dominators analysis pass.
LLVM_ABI Printable printRegUnit(unsigned Unit, const TargetRegisterInfo *TRI)
Create Printable object to print register units on a raw_ostream.
LLVM_ABI bool shouldOptimizeForSize(const MachineFunction *MF, ProfileSummaryInfo *PSI, const MachineBlockFrequencyInfo *BFI, PGSOQueryType QueryType=PGSOQueryType::Other)
Returns true if machine function MF is suggested to be size-optimized based on the profile.
LLVM_ABI void initializeLiveIntervalsWrapperPassPass(PassRegistry &)
Printable PrintLaneMask(LaneBitmask LaneMask)
Create Printable object to print LaneBitmasks on a raw_ostream.
Definition LaneBitmask.h:92
AnalysisManager< MachineFunction > MachineFunctionAnalysisManager
void erase(Container &C, ValueType V)
Wrapper function to remove a value from a container:
Definition STLExtras.h:2128
LLVM_ABI char & MachineLoopInfoID
MachineLoopInfo - This pass is a loop analysis pass.
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition Debug.cpp:207
df_ext_iterator< T, SetTy > df_ext_begin(const T &G, SetTy &S)
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:1739
MachineBasicBlock::instr_iterator getBundleEnd(MachineBasicBlock::instr_iterator I)
Returns an iterator pointing beyond the bundle containing I.
unsigned MCRegUnit
Register units are used to compute register aliasing.
Definition MCRegister.h:30
class LLVM_GSL_OWNER SmallVector
Forward declaration of SmallVector so that calculateSmallVectorDefaultInlinedElements can reference s...
LLVM_ABI const float huge_valf
Use this rather than HUGE_VALF; the latter causes warnings on MSVC.
auto lower_bound(R &&Range, T &&Value)
Provide wrappers to std::lower_bound which take ranges instead of having to pass begin/end explicitly...
Definition STLExtras.h:1994
uint16_t MCPhysReg
An unsigned integer type large enough to represent all physical registers, but not necessarily virtua...
Definition MCRegister.h:21
FunctionAddr VTableAddr Next
Definition InstrProf.h:141
@ DeoptLiveIn
Mark the deopt arguments associated with the statepoint as only being "live-in".
Definition Statepoint.h:49
iterator_range< MIBundleOperands > mi_bundle_ops(MachineInstr &MI)
df_ext_iterator< T, SetTy > df_ext_end(const T &G, SetTy &S)
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 char & LiveIntervalsID
LiveIntervals - This analysis keeps track of the live ranges of virtual and physical registers.
LLVM_ABI Printable printMBBReference(const MachineBasicBlock &MBB)
Prints a machine basic block reference.
#define N
A special type used by analysis passes to provide an address that identifies that particular analysis...
Definition Analysis.h:29
static constexpr LaneBitmask getAll()
Definition LaneBitmask.h:82
constexpr bool any() const
Definition LaneBitmask.h:53
static constexpr LaneBitmask getNone()
Definition LaneBitmask.h:81
This represents a simple continuous liveness interval for a value.