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