LLVM 24.0.0git
RegisterPressure.cpp
Go to the documentation of this file.
1//===- RegisterPressure.cpp - Dynamic Register Pressure -------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file implements the RegisterPressure class which can be used to track
10// MachineInstr level register pressure.
11//
12//===----------------------------------------------------------------------===//
13
15#include "llvm/ADT/ArrayRef.h"
16#include "llvm/ADT/STLExtras.h"
30#include "llvm/Config/llvm-config.h"
31#include "llvm/MC/LaneBitmask.h"
33#include "llvm/Support/Debug.h"
36#include <algorithm>
37#include <cassert>
38#include <cstdint>
39#include <cstdlib>
40#include <cstring>
41#include <iterator>
42#include <limits>
43#include <utility>
44#include <vector>
45
46using namespace llvm;
47
48/// Increase pressure for each pressure set provided by TargetRegisterInfo.
49static void increaseSetPressure(std::vector<unsigned> &CurrSetPressure,
51 VirtRegOrUnit VRegOrUnit, LaneBitmask PrevMask,
52 LaneBitmask NewMask) {
53 assert((PrevMask & ~NewMask).none() && "Must not remove bits");
54 if (PrevMask.any() || NewMask.none())
55 return;
56
57 PSetIterator PSetI = MRI.getPressureSets(VRegOrUnit);
58 unsigned Weight = PSetI.getWeight();
59 for (; PSetI.isValid(); ++PSetI)
60 CurrSetPressure[*PSetI] += Weight;
61}
62
63/// Decrease pressure for each pressure set provided by TargetRegisterInfo.
64static void decreaseSetPressure(std::vector<unsigned> &CurrSetPressure,
66 VirtRegOrUnit VRegOrUnit, LaneBitmask PrevMask,
67 LaneBitmask NewMask) {
68 assert((NewMask & ~PrevMask).none() && "Must not add bits");
69 if (NewMask.any() || PrevMask.none())
70 return;
71
72 PSetIterator PSetI = MRI.getPressureSets(VRegOrUnit);
73 unsigned Weight = PSetI.getWeight();
74 for (; PSetI.isValid(); ++PSetI) {
75 assert(CurrSetPressure[*PSetI] >= Weight && "register pressure underflow");
76 CurrSetPressure[*PSetI] -= Weight;
77 }
78}
79
80#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
83 const TargetRegisterInfo *TRI) {
84 for (unsigned i = 0, e = SetPressure.size(); i < e; ++i) {
85 if (SetPressure[i] != 0) {
86 dbgs() << TRI->getRegPressureSetName(i) << "=" << SetPressure[i] << ' ';
87 }
88 }
89 dbgs() << "\n";
90}
91
94 dbgs() << "Max Pressure: ";
96 dbgs() << "Live In: ";
97 for (const VRegMaskOrUnit &P : LiveInRegs) {
98 dbgs() << printVRegOrUnit(P.VRegOrUnit, TRI);
99 if (!P.LaneMask.all())
100 dbgs() << ':' << PrintLaneMask(P.LaneMask);
101 dbgs() << ' ';
102 }
103 dbgs() << '\n';
104 dbgs() << "Live Out: ";
105 for (const VRegMaskOrUnit &P : LiveOutRegs) {
106 dbgs() << printVRegOrUnit(P.VRegOrUnit, TRI);
107 if (!P.LaneMask.all())
108 dbgs() << ':' << PrintLaneMask(P.LaneMask);
109 dbgs() << ' ';
110 }
111 dbgs() << '\n';
112}
113
116 if (!isTopClosed() || !isBottomClosed()) {
117 dbgs() << "Curr Pressure: ";
118 dumpRegSetPressure(CurrSetPressure, TRI);
119 }
120 P.dump(TRI);
121}
122
125 const char *sep = "";
126 for (const PressureChange &Change : *this) {
127 if (!Change.isValid())
128 break;
129 dbgs() << sep << TRI.getRegPressureSetName(Change.getPSet())
130 << " " << Change.getUnitInc();
131 sep = " ";
132 }
133 dbgs() << '\n';
134}
135
138 dbgs() << "[" << getPSetOrMax() << ", " << getUnitInc() << "]\n";
139}
140
142 dbgs() << "[Excess=";
143 Excess.dump();
144 dbgs() << ", CriticalMax=";
145 CriticalMax.dump();
146 dbgs() << ", CurrentMax=";
147 CurrentMax.dump();
148 dbgs() << "]\n";
149}
150
151#endif
152
154 LaneBitmask PreviousMask,
155 LaneBitmask NewMask) {
156 if (PreviousMask.any() || NewMask.none())
157 return;
158
159 PSetIterator PSetI = MRI->getPressureSets(VRegOrUnit);
160 unsigned Weight = PSetI.getWeight();
161 for (; PSetI.isValid(); ++PSetI) {
162 CurrSetPressure[*PSetI] += Weight;
163 P.MaxSetPressure[*PSetI] =
164 std::max(P.MaxSetPressure[*PSetI], CurrSetPressure[*PSetI]);
165 }
166}
167
169 LaneBitmask PreviousMask,
170 LaneBitmask NewMask) {
171 decreaseSetPressure(CurrSetPressure, *MRI, VRegOrUnit, PreviousMask, NewMask);
172}
173
174/// Clear the result so it can be used for another round of pressure tracking.
177 MaxSetPressure.clear();
178 LiveInRegs.clear();
179 LiveOutRegs.clear();
180}
181
182/// Clear the result so it can be used for another round of pressure tracking.
189
190/// If the current top is not less than or equal to the next index, open it.
191/// We happen to need the SlotIndex for the next top for pressure update.
193 if (TopIdx <= NextTop)
194 return;
195 TopIdx = SlotIndex();
196 LiveInRegs.clear();
197}
198
199/// If the current top is the previous instruction (before receding), open it.
201 if (TopPos != PrevTop)
202 return;
204 LiveInRegs.clear();
205}
206
207/// If the current bottom is not greater than the previous index, open it.
209 if (BottomIdx > PrevBottom)
210 return;
212 LiveInRegs.clear();
213}
214
215/// If the current bottom is the previous instr (before advancing), open it.
217 if (BottomPos != PrevBottom)
218 return;
220 LiveInRegs.clear();
221}
222
224 const TargetRegisterInfo &TRI = *MRI.getTargetRegisterInfo();
225 unsigned NumRegUnits = TRI.getNumRegs();
226 unsigned NumVirtRegs = MRI.getNumVirtRegs();
227 Regs.setUniverse(NumRegUnits + NumVirtRegs);
228 this->NumRegUnits = NumRegUnits;
229}
230
232 Regs.clear();
233}
234
236 MBB = nullptr;
237 LIS = nullptr;
238
239 CurrSetPressure.clear();
240 LiveThruPressure.clear();
241 P.MaxSetPressure.clear();
242
243 if (RequireIntervals)
244 static_cast<IntervalPressure&>(P).reset();
245 else
246 static_cast<RegionPressure&>(P).reset();
247
248 LiveRegs.clear();
249 UntiedDefs.clear();
250}
251
252/// Setup the RegPressureTracker.
253///
254/// TODO: Add support for pressure without LiveIntervals.
256 const RegisterClassInfo *rci, LiveIntervals *lis,
257 const MachineBasicBlock *mbb,
259 bool TrackLaneMasks, bool TrackUntiedDefs) {
260 reset();
261
262 MF = mf;
263 TRI = MF->getSubtarget().getRegisterInfo();
264 RCI = rci;
265 MRI = &MF->getRegInfo();
266 MBB = mbb;
267 this->TrackUntiedDefs = TrackUntiedDefs;
268 this->TrackLaneMasks = TrackLaneMasks;
269
270 if (RequireIntervals) {
271 assert(lis && "IntervalPressure requires LiveIntervals");
272 LIS = lis;
273 }
274
275 CurrPos = pos;
276 CurrSetPressure.assign(TRI->getNumRegPressureSets(), 0);
277
278 P.MaxSetPressure = CurrSetPressure;
279
280 LiveRegs.init(*MRI);
281 if (TrackUntiedDefs)
282 UntiedDefs.setUniverse(MRI->getNumVirtRegs());
283}
284
285/// Does this pressure result have a valid top position and live ins.
287 if (RequireIntervals)
288 return static_cast<IntervalPressure&>(P).TopIdx.isValid();
289 return (static_cast<RegionPressure&>(P).TopPos ==
291}
292
293/// Does this pressure result have a valid bottom position and live outs.
295 if (RequireIntervals)
296 return static_cast<IntervalPressure&>(P).BottomIdx.isValid();
297 return (static_cast<RegionPressure&>(P).BottomPos ==
299}
300
303 skipDebugInstructionsForward(CurrPos, MBB->end());
304 if (IdxPos == MBB->end())
305 return LIS->getMBBEndIdx(MBB);
306 return LIS->getInstructionIndex(*IdxPos).getRegSlot();
307}
308
309/// Set the boundary for the top of the region and summarize live ins.
311 if (RequireIntervals)
312 static_cast<IntervalPressure&>(P).TopIdx = getCurrSlot();
313 else
314 static_cast<RegionPressure&>(P).TopPos = CurrPos;
315
316 assert(P.LiveInRegs.empty() && "inconsistent max pressure result");
317 P.LiveInRegs.reserve(LiveRegs.size());
318 LiveRegs.appendTo(P.LiveInRegs);
319}
320
321/// Set the boundary for the bottom of the region and summarize live outs.
323 if (RequireIntervals)
324 static_cast<IntervalPressure&>(P).BottomIdx = getCurrSlot();
325 else
326 static_cast<RegionPressure&>(P).BottomPos = CurrPos;
327
328 assert(P.LiveOutRegs.empty() && "inconsistent max pressure result");
329 P.LiveOutRegs.reserve(LiveRegs.size());
330 LiveRegs.appendTo(P.LiveOutRegs);
331}
332
333/// Finalize the region boundaries and record live ins and live outs.
335 if (!isTopClosed() && !isBottomClosed()) {
336 assert(LiveRegs.size() == 0 && "no region boundary");
337 return;
338 }
339 if (!isBottomClosed())
340 closeBottom();
341 else if (!isTopClosed())
342 closeTop();
343 // If both top and bottom are closed, do nothing.
344}
345
346/// The register tracker is unaware of global liveness so ignores normal
347/// live-thru ranges. However, two-address or coalesced chains can also lead
348/// to live ranges with no holes. Count these to inform heuristics that we
349/// can never drop below this pressure.
351 LiveThruPressure.assign(TRI->getNumRegPressureSets(), 0);
352 assert(isBottomClosed() && "need bottom-up tracking to initialize.");
353 for (const VRegMaskOrUnit &Pair : P.LiveOutRegs) {
354 VirtRegOrUnit VRegOrUnit = Pair.VRegOrUnit;
355 if (VRegOrUnit.isVirtualReg() &&
356 !RPTracker.hasUntiedDef(VRegOrUnit.asVirtualReg()))
357 increaseSetPressure(LiveThruPressure, *MRI, VRegOrUnit,
359 }
360}
361
363 VirtRegOrUnit VRegOrUnit) {
364 auto I = llvm::find_if(RegUnits, [VRegOrUnit](const VRegMaskOrUnit Other) {
365 return Other.VRegOrUnit == VRegOrUnit;
366 });
367 if (I == RegUnits.end())
368 return LaneBitmask::getNone();
369 return I->LaneMask;
370}
371
373 VRegMaskOrUnit Pair) {
374 VirtRegOrUnit VRegOrUnit = Pair.VRegOrUnit;
375 assert(Pair.LaneMask.any());
376 auto I = llvm::find_if(RegUnits, [VRegOrUnit](const VRegMaskOrUnit Other) {
377 return Other.VRegOrUnit == VRegOrUnit;
378 });
379 if (I == RegUnits.end()) {
380 RegUnits.push_back(Pair);
381 } else {
382 I->LaneMask |= Pair.LaneMask;
383 }
384}
385
387 VirtRegOrUnit VRegOrUnit) {
388 auto I = llvm::find_if(RegUnits, [VRegOrUnit](const VRegMaskOrUnit Other) {
389 return Other.VRegOrUnit == VRegOrUnit;
390 });
391 if (I == RegUnits.end()) {
392 RegUnits.emplace_back(VRegOrUnit, LaneBitmask::getNone());
393 } else {
394 I->LaneMask = LaneBitmask::getNone();
395 }
396}
397
399 VRegMaskOrUnit Pair) {
400 VirtRegOrUnit VRegOrUnit = Pair.VRegOrUnit;
401 assert(Pair.LaneMask.any());
402 auto I = llvm::find_if(RegUnits, [VRegOrUnit](const VRegMaskOrUnit Other) {
403 return Other.VRegOrUnit == VRegOrUnit;
404 });
405 if (I != RegUnits.end()) {
406 I->LaneMask &= ~Pair.LaneMask;
407 if (I->LaneMask.none())
408 RegUnits.erase(I);
409 }
410}
411
412static LaneBitmask
414 bool TrackLaneMasks, VirtRegOrUnit VRegOrUnit,
415 SlotIndex Pos, LaneBitmask SafeDefault,
416 bool (*Property)(const LiveRange &LR, SlotIndex Pos),
417 bool ComputePhysRegs = false) {
418 if (VRegOrUnit.isVirtualReg()) {
419 const LiveInterval &LI = LIS.getInterval(VRegOrUnit.asVirtualReg());
420 LaneBitmask Result;
421 if (TrackLaneMasks && LI.hasSubRanges()) {
422 for (const LiveInterval::SubRange &SR : LI.subranges()) {
423 if (Property(SR, Pos))
424 Result |= SR.LaneMask;
425 }
426 } else if (Property(LI, Pos)) {
427 Result = TrackLaneMasks
428 ? MRI.getMaxLaneMaskForVReg(VRegOrUnit.asVirtualReg())
430 }
431
432 return Result;
433 } else {
434 MCRegUnit Unit = VRegOrUnit.asMCRegUnit();
435 // We usually do not compute liveranges for physical registers on targets
436 // with many registers (GPUs), so the cached range may be absent. Callers
437 // that require an authoritative answer pass ComputePhysRegs to force the
438 // range to be computed on demand.
439 const LiveRange *LR =
440 ComputePhysRegs ? &LIS.getRegUnit(Unit) : LIS.getCachedRegUnit(Unit);
441 if (LR == nullptr)
442 return SafeDefault;
443 return Property(*LR, Pos) ? LaneBitmask::getAll() : LaneBitmask::getNone();
444 }
445}
446
449 bool TrackLaneMasks, VirtRegOrUnit VRegOrUnit,
450 SlotIndex Pos, bool ComputePhysRegs = false) {
452 LIS, MRI, TrackLaneMasks, VRegOrUnit, Pos, LaneBitmask::getAll(),
453 [](const LiveRange &LR, SlotIndex Pos) { return LR.liveAt(Pos); },
454 ComputePhysRegs);
455}
456
457namespace {
458
459/// Collect this instruction's unique uses and defs into SmallVectors for
460/// processing defs and uses in order.
461///
462/// FIXME: always ignore tied opers
463class RegisterOperandsCollector {
464 friend class llvm::RegisterOperands;
465
466 RegisterOperands &RegOpers;
467 const TargetRegisterInfo &TRI;
468 const MachineRegisterInfo &MRI;
469 bool IgnoreDead;
470
471 RegisterOperandsCollector(RegisterOperands &RegOpers,
472 const TargetRegisterInfo &TRI,
473 const MachineRegisterInfo &MRI, bool IgnoreDead)
474 : RegOpers(RegOpers), TRI(TRI), MRI(MRI), IgnoreDead(IgnoreDead) {}
475
476 void collectInstr(const MachineInstr &MI) const {
477 for (ConstMIBundleOperands OperI(MI); OperI.isValid(); ++OperI)
478 collectOperand(*OperI);
479
480 // Remove redundant physreg dead defs. A regunit unit is dead iff every def
481 // covering it is dead
482 for (const VRegMaskOrUnit &P : RegOpers.Defs)
483 removeRegLanes(RegOpers.DeadDefs, P);
484 }
485
486 void collectInstrLanes(const MachineInstr &MI) const {
487 for (ConstMIBundleOperands OperI(MI); OperI.isValid(); ++OperI)
488 collectOperandLanes(*OperI);
489
490 // Remove redundant physreg dead defs.
491 for (const VRegMaskOrUnit &P : RegOpers.Defs)
492 removeRegLanes(RegOpers.DeadDefs, P);
493 }
494
495 /// Push this operand's register onto the correct vectors.
496 void collectOperand(const MachineOperand &MO) const {
497 if (!MO.isReg() || !MO.getReg())
498 return;
499 Register Reg = MO.getReg();
500 if (MO.isUse()) {
501 if (!MO.isUndef() && !MO.isInternalRead())
502 pushReg(Reg, RegOpers.Uses);
503 } else {
504 assert(MO.isDef());
505 // Subregister definitions may imply a register read.
506 if (MO.readsReg())
507 pushReg(Reg, RegOpers.Uses);
508
509 if (MO.isDead()) {
510 if (!IgnoreDead)
511 pushReg(Reg, RegOpers.DeadDefs);
512 } else
513 pushReg(Reg, RegOpers.Defs);
514 }
515 }
516
517 void pushReg(Register Reg, SmallVectorImpl<VRegMaskOrUnit> &RegUnits) const {
518 if (Reg.isVirtual()) {
519 addRegLanes(RegUnits,
520 VRegMaskOrUnit(VirtRegOrUnit(Reg), LaneBitmask::getAll()));
521 } else if (MRI.isAllocatable(Reg)) {
522 for (MCRegUnit Unit : TRI.regunits(Reg.asMCReg()))
523 addRegLanes(RegUnits,
524 VRegMaskOrUnit(VirtRegOrUnit(Unit), LaneBitmask::getAll()));
525 }
526 }
527
528 void collectOperandLanes(const MachineOperand &MO) const {
529 if (!MO.isReg() || !MO.getReg())
530 return;
531 Register Reg = MO.getReg();
532 unsigned SubRegIdx = MO.getSubReg();
533 if (MO.isUse()) {
534 if (!MO.isUndef() && !MO.isInternalRead())
535 pushRegLanes(Reg, SubRegIdx, RegOpers.Uses);
536 } else {
537 assert(MO.isDef());
538 // Treat read-undef subreg defs as definitions of the whole register.
539 if (MO.isUndef())
540 SubRegIdx = 0;
541
542 if (MO.isDead()) {
543 if (!IgnoreDead)
544 pushRegLanes(Reg, SubRegIdx, RegOpers.DeadDefs);
545 } else
546 pushRegLanes(Reg, SubRegIdx, RegOpers.Defs);
547 }
548 }
549
550 void pushRegLanes(Register Reg, unsigned SubRegIdx,
551 SmallVectorImpl<VRegMaskOrUnit> &RegUnits) const {
552 if (Reg.isVirtual()) {
553 LaneBitmask LaneMask = SubRegIdx != 0
554 ? TRI.getSubRegIndexLaneMask(SubRegIdx)
556 addRegLanes(RegUnits, VRegMaskOrUnit(VirtRegOrUnit(Reg), LaneMask));
557 } else if (MRI.isAllocatable(Reg)) {
558 for (MCRegUnit Unit : TRI.regunits(Reg.asMCReg()))
559 addRegLanes(RegUnits,
560 VRegMaskOrUnit(VirtRegOrUnit(Unit), LaneBitmask::getAll()));
561 }
562 }
563};
564
565} // end anonymous namespace
566
568 const TargetRegisterInfo &TRI,
570 bool TrackLaneMasks, bool IgnoreDead) {
571 RegisterOperandsCollector Collector(*this, TRI, MRI, IgnoreDead);
572 if (TrackLaneMasks)
573 Collector.collectInstrLanes(MI);
574 else
575 Collector.collectInstr(MI);
576}
577
579 LiveIntervals &LIS,
580 const MachineRegisterInfo &MRI) {
581 SlotIndex DeadSlotIdx = LIS.getInstructionIndex(MI).getDeadSlot();
582 for (auto *I = Defs.begin(); I != Defs.end(); /*empty*/) {
583 // Force physreg unit ranges to be computed, we need to accurately know if a
584 // physreg is dead.
585 LaneBitmask LiveAfter =
586 getLiveLanesAt(LIS, MRI, /*TrackLaneMasks=*/false, I->VRegOrUnit,
587 DeadSlotIdx, /*ComputePhysRegs=*/true);
588 I = adjustDef(*I, LiveAfter);
589 }
590}
591
594 SlotIndex Pos) {
595 for (auto *I = Defs.begin(); I != Defs.end(); /*empty*/) {
596 LaneBitmask LiveAfter =
597 getLiveLanesAt(LIS, MRI, /*TrackLaneMasks=*/true, I->VRegOrUnit,
598 Pos.getDeadSlot(), /*ComputePhysRegs=*/true);
599 I = adjustDef(*I, LiveAfter);
600 }
601 adjustUses(LIS, MRI, Pos.getBaseIndex());
602}
603
606 MachineInstr &MI) {
608 for (auto *I = Defs.begin(); I != Defs.end(); /*empty*/) {
609 LaneBitmask LiveAfter =
610 getLiveLanesAt(LIS, MRI, /*TrackLaneMasks=*/true, I->VRegOrUnit,
611 Pos.getDeadSlot(), /*ComputePhysRegs=*/true);
612 // If the def is all that is live after the instruction, then in case
613 // of a subregister def we need a read-undef flag.
614 VirtRegOrUnit VRegOrUnit = I->VRegOrUnit;
615 if (VRegOrUnit.isVirtualReg() && (LiveAfter & ~I->LaneMask).none())
616 MI.setRegisterDefReadUndef(VRegOrUnit.asVirtualReg());
617 I = adjustDef(*I, LiveAfter);
618 }
619
620 adjustUses(LIS, MRI, Pos);
621
622 const TargetRegisterInfo *TRI = MRI.getTargetRegisterInfo();
623 for (const VRegMaskOrUnit &P : DeadDefs) {
624 VirtRegOrUnit VRegOrUnit = P.VRegOrUnit;
625 if (!VRegOrUnit.isVirtualReg())
626 continue;
627 Register VReg = VRegOrUnit.asVirtualReg();
628 LaneBitmask LiveAfter = getLiveLanesAt(LIS, MRI, /*TrackLaneMasks=*/true,
629 VRegOrUnit, Pos.getDeadSlot());
630 if (!LiveAfter.none())
631 continue;
632 // The register's read value doesn't matter if none of its lanes are live
633 // after the def.
634 MI.setRegisterDefReadUndef(VReg);
635
636 // The register's last definition should be marked dead.
637 const LiveInterval &LI = LIS.getInterval(VReg);
638 if (LI.segments.back().end == Pos.getDeadSlot())
639 MI.addRegisterDead(VReg, TRI, /*AddIfNotFound=*/false);
640 }
641}
642
644 const TargetRegisterInfo &TRI,
646 LiveIntervals &LIS,
647 bool TrackLaneMasks,
648 ArrayRef<Register> OnlyRegs) {
649 assert(!MI.isDebugInstr() && "No flags to restore on debug instructions");
650 // Clear potentially-stale read-undef flags. They are re-added below for the
651 // lanes that are still dead.
652 bool HasClearedDef = false;
653 for (MachineOperand &MO : MI.all_defs()) {
654 if (!OnlyRegs.empty() && (!MO.getReg().isVirtual() || MO.getSubReg() == 0 ||
655 !llvm::is_contained(OnlyRegs, MO.getReg())))
656 continue;
657 MO.setIsUndef(false);
658 HasClearedDef = true;
659 }
660 if (!HasClearedDef)
661 return;
662 RegisterOperands RegOpers;
663 RegOpers.collect(MI, TRI, MRI, TrackLaneMasks, /*IgnoreDead=*/false);
664 if (TrackLaneMasks) {
665 // Adjust liveness and add missing dead+read-undef flags.
666 RegOpers.adjustLaneLiveness(LIS, MRI, MI);
667 } else {
668 // Adjust for missing dead-def flags.
669 RegOpers.detectDeadDefs(MI, LIS, MRI);
670 }
671}
672
673VRegMaskOrUnit *RegisterOperands::adjustDef(VRegMaskOrUnit &Def,
674 LaneBitmask LiveAfterDef) {
675 LaneBitmask ActualDef = Def.LaneMask & LiveAfterDef;
676 if (ActualDef.none()) {
677 DeadDefs.push_back(Def);
678 return Defs.erase(&Def);
679 }
680
681 Def.LaneMask = ActualDef;
682 return &Def + 1;
683}
684
685void RegisterOperands::adjustUses(LiveIntervals &LIS,
687 SlotIndex Pos) {
688 for (auto &[VRegOrUnit, LaneMask] : Uses) {
689 LaneMask =
690 getLiveLanesAt(LIS, MRI, /*TrackLaneMasks=*/true, VRegOrUnit, Pos);
691 }
692}
693
694/// Initialize an array of N PressureDiffs.
695void PressureDiffs::init(unsigned N) {
696 Size = N;
697 if (N <= Max) {
698 memset(PDiffArray, 0, N * sizeof(PressureDiff));
699 return;
700 }
701 Max = Size;
702 free(PDiffArray);
703 PDiffArray = static_cast<PressureDiff*>(safe_calloc(N, sizeof(PressureDiff)));
704}
705
707 const RegisterOperands &RegOpers,
708 const MachineRegisterInfo &MRI) {
709 PressureDiff &PDiff = (*this)[Idx];
710 assert(!PDiff.begin()->isValid() && "stale PDiff");
711 for (const VRegMaskOrUnit &P : RegOpers.Defs)
712 PDiff.addPressureChange(P.VRegOrUnit, true, &MRI);
713
714 for (const VRegMaskOrUnit &P : RegOpers.Uses)
715 PDiff.addPressureChange(P.VRegOrUnit, false, &MRI);
716}
717
718/// Add a change in pressure to the pressure diff of a given instruction.
720 const MachineRegisterInfo *MRI) {
721 PSetIterator PSetI = MRI->getPressureSets(VRegOrUnit);
722 int Weight = IsDec ? -PSetI.getWeight() : PSetI.getWeight();
723 for (; PSetI.isValid(); ++PSetI) {
724 // Find an existing entry in the pressure diff for this PSet.
725 PressureDiff::iterator I = nonconst_begin(), E = nonconst_end();
726 for (; I != E && I->isValid(); ++I) {
727 if (I->getPSet() >= *PSetI)
728 break;
729 }
730 // If all pressure sets are more constrained, skip the remaining PSets.
731 if (I == E)
732 break;
733 // Insert this PressureChange.
734 if (!I->isValid() || I->getPSet() != *PSetI) {
735 PressureChange PTmp = PressureChange(*PSetI);
736 for (PressureDiff::iterator J = I; J != E && PTmp.isValid(); ++J)
737 std::swap(*J, PTmp);
738 }
739 // Update the units for this pressure set.
740 unsigned NewUnitInc = I->getUnitInc() + Weight;
741 if (NewUnitInc != 0) {
742 I->setUnitInc(NewUnitInc);
743 } else {
744 // Remove entry
745 PressureDiff::iterator J;
746 for (J = std::next(I); J != E && J->isValid(); ++J, ++I)
747 *I = *J;
748 *I = PressureChange();
749 }
750 }
751}
752
753/// Force liveness of registers.
755 for (const VRegMaskOrUnit &P : Regs) {
756 LaneBitmask PrevMask = LiveRegs.insert(P);
757 LaneBitmask NewMask = PrevMask | P.LaneMask;
758 increaseRegPressure(P.VRegOrUnit, PrevMask, NewMask);
759 }
760}
761
764 assert(Pair.LaneMask.any());
765
766 VirtRegOrUnit VRegOrUnit = Pair.VRegOrUnit;
767 auto I = find_if(LiveInOrOut, [VRegOrUnit](const VRegMaskOrUnit &Other) {
768 return Other.VRegOrUnit == VRegOrUnit;
769 });
770 LaneBitmask PrevMask;
771 LaneBitmask NewMask;
772 if (I == LiveInOrOut.end()) {
773 PrevMask = LaneBitmask::getNone();
774 NewMask = Pair.LaneMask;
775 LiveInOrOut.push_back(Pair);
776 } else {
777 PrevMask = I->LaneMask;
778 NewMask = PrevMask | Pair.LaneMask;
779 I->LaneMask = NewMask;
780 }
781 increaseSetPressure(P.MaxSetPressure, *MRI, VRegOrUnit, PrevMask, NewMask);
782}
783
787
791
793 for (const VRegMaskOrUnit &P : DeadDefs) {
794 LaneBitmask LiveMask = LiveRegs.contains(P.VRegOrUnit);
795 LaneBitmask BumpedMask = LiveMask | P.LaneMask;
796 increaseRegPressure(P.VRegOrUnit, LiveMask, BumpedMask);
797 }
798 for (const VRegMaskOrUnit &P : DeadDefs) {
799 LaneBitmask LiveMask = LiveRegs.contains(P.VRegOrUnit);
800 LaneBitmask BumpedMask = LiveMask | P.LaneMask;
801 decreaseRegPressure(P.VRegOrUnit, BumpedMask, LiveMask);
802 }
803}
804
805/// Recede across the previous instruction. If LiveUses is provided, record any
806/// RegUnits that are made live by the current instruction's uses. This includes
807/// registers that are both defined and used by the instruction. If a pressure
808/// difference pointer is provided record the changes is pressure caused by this
809/// instruction independent of liveness.
812 assert(!CurrPos->isDebugOrPseudoInstr());
813
814 // Boost pressure for all dead defs together.
815 bumpDeadDefs(RegOpers.DeadDefs);
816
817 // Kill liveness at live defs.
818 // TODO: consider earlyclobbers?
819 for (const VRegMaskOrUnit &Def : RegOpers.Defs) {
820 VirtRegOrUnit VRegOrUnit = Def.VRegOrUnit;
821
822 LaneBitmask LiveLanesAfterDef = LiveRegs.erase(Def);
823 LaneBitmask LiveLanesBeforeDef = LiveLanesAfterDef & ~Def.LaneMask;
824
825 // Conservatively treat defined lanes not known to be live as live out of
826 // the region. Account for them retroactively, increasing pressure only if
827 // the register was not already live.
828 LaneBitmask NewLiveOutLanes = Def.LaneMask & ~LiveLanesAfterDef;
829 if (NewLiveOutLanes.any()) {
830 discoverLiveOut(VRegMaskOrUnit(VRegOrUnit, NewLiveOutLanes));
831 increaseSetPressure(CurrSetPressure, *MRI, VRegOrUnit, LiveLanesAfterDef,
832 LiveLanesAfterDef | NewLiveOutLanes);
833 // Preserve existing live lanes for the decrease below.
834 LiveLanesAfterDef |= NewLiveOutLanes;
835 }
836
837 if (LiveLanesBeforeDef.none()) {
838 // Add a 0 entry to LiveUses as a marker that the complete vreg has become
839 // dead.
840 if (TrackLaneMasks && LiveUses != nullptr)
841 setRegZero(*LiveUses, VRegOrUnit);
842 }
843
844 decreaseRegPressure(VRegOrUnit, LiveLanesAfterDef, LiveLanesBeforeDef);
845 }
846
847 SlotIndex SlotIdx;
848 if (RequireIntervals)
849 SlotIdx = LIS->getInstructionIndex(*CurrPos).getRegSlot();
850
851 // Generate liveness for uses.
852 for (const VRegMaskOrUnit &Use : RegOpers.Uses) {
853 VirtRegOrUnit VRegOrUnit = Use.VRegOrUnit;
854 assert(Use.LaneMask.any());
855 LaneBitmask PreviousMask = LiveRegs.insert(Use);
856 LaneBitmask NewMask = PreviousMask | Use.LaneMask;
857 if (NewMask == PreviousMask)
858 continue;
859
860 // Did the register just become live?
861 if (PreviousMask.none()) {
862 if (LiveUses != nullptr) {
863 if (!TrackLaneMasks) {
864 addRegLanes(*LiveUses, VRegMaskOrUnit(VRegOrUnit, NewMask));
865 } else {
866 auto I = find_if(*LiveUses, [VRegOrUnit](const VRegMaskOrUnit Other) {
867 return Other.VRegOrUnit == VRegOrUnit;
868 });
869 bool IsRedef = I != LiveUses->end();
870 if (IsRedef) {
871 // ignore re-defs here...
872 assert(I->LaneMask.none());
873 removeRegLanes(*LiveUses, VRegMaskOrUnit(VRegOrUnit, NewMask));
874 } else {
875 addRegLanes(*LiveUses, VRegMaskOrUnit(VRegOrUnit, NewMask));
876 }
877 }
878 }
879
880 // Discover live outs if this may be the first occurance of this register.
881 if (RequireIntervals) {
882 LaneBitmask LiveOut = getLiveThroughAt(VRegOrUnit, SlotIdx);
883 if (LiveOut.any())
884 discoverLiveOut(VRegMaskOrUnit(VRegOrUnit, LiveOut));
885 }
886 }
887
888 increaseRegPressure(VRegOrUnit, PreviousMask, NewMask);
889 }
890 if (TrackUntiedDefs) {
891 for (const VRegMaskOrUnit &Def : RegOpers.Defs) {
892 VirtRegOrUnit VRegOrUnit = Def.VRegOrUnit;
893 if (VRegOrUnit.isVirtualReg() &&
894 (LiveRegs.contains(VRegOrUnit) & Def.LaneMask).none())
895 UntiedDefs.insert(VRegOrUnit.asVirtualReg());
896 }
897 }
898}
899
901 assert(CurrPos != MBB->begin());
902 if (!isBottomClosed())
903 closeBottom();
904
905 // Open the top of the region using block iterators.
906 if (!RequireIntervals && isTopClosed())
907 static_cast<RegionPressure&>(P).openTop(CurrPos);
908
909 // Find the previous instruction.
910 CurrPos = prev_nodbg(CurrPos, MBB->begin());
911
912 SlotIndex SlotIdx;
913 if (RequireIntervals && !CurrPos->isDebugOrPseudoInstr())
914 SlotIdx = LIS->getInstructionIndex(*CurrPos).getRegSlot();
915
916 // Open the top of the region using slot indexes.
917 if (RequireIntervals && isTopClosed())
918 static_cast<IntervalPressure&>(P).openTop(SlotIdx);
919}
920
923 if (CurrPos->isDebugOrPseudoInstr()) {
924 // It's possible to only have debug_value and pseudo probe instructions and
925 // hit the start of the block.
926 assert(CurrPos == MBB->begin());
927 return;
928 }
929
930 const MachineInstr &MI = *CurrPos;
931 RegisterOperands RegOpers;
932 RegOpers.collect(MI, *TRI, *MRI, TrackLaneMasks, /*IgnoreDead=*/false);
933 if (TrackLaneMasks) {
934 SlotIndex SlotIdx = LIS->getInstructionIndex(*CurrPos).getRegSlot();
935 RegOpers.adjustLaneLiveness(*LIS, *MRI, SlotIdx);
936 } else if (RequireIntervals) {
937 RegOpers.detectDeadDefs(MI, *LIS, *MRI);
938 }
939
940 recede(RegOpers, LiveUses);
941}
942
943/// Advance across the current instruction.
945 assert(!TrackUntiedDefs && "unsupported mode");
946 assert(CurrPos != MBB->end());
947 if (!isTopClosed())
948 closeTop();
949
950 SlotIndex SlotIdx;
951 if (RequireIntervals)
952 SlotIdx = getCurrSlot();
953
954 // Open the bottom of the region using slot indexes.
955 if (isBottomClosed()) {
956 if (RequireIntervals)
957 static_cast<IntervalPressure&>(P).openBottom(SlotIdx);
958 else
959 static_cast<RegionPressure&>(P).openBottom(CurrPos);
960 }
961
962 for (const VRegMaskOrUnit &Use : RegOpers.Uses) {
963 VirtRegOrUnit VRegOrUnit = Use.VRegOrUnit;
964 LaneBitmask LiveMask = LiveRegs.contains(VRegOrUnit);
965 LaneBitmask LiveIn = Use.LaneMask & ~LiveMask;
966 if (LiveIn.any()) {
967 discoverLiveIn(VRegMaskOrUnit(VRegOrUnit, LiveIn));
968 increaseRegPressure(VRegOrUnit, LiveMask, LiveMask | LiveIn);
969 LiveRegs.insert(VRegMaskOrUnit(VRegOrUnit, LiveIn));
970 }
971 // Kill liveness at last uses.
972 if (RequireIntervals) {
973 LaneBitmask LastUseMask = getLastUsedLanes(VRegOrUnit, SlotIdx);
974 if (LastUseMask.any()) {
975 LiveRegs.erase(VRegMaskOrUnit(VRegOrUnit, LastUseMask));
976 decreaseRegPressure(VRegOrUnit, LiveMask, LiveMask & ~LastUseMask);
977 }
978 }
979 }
980
981 // Generate liveness for defs.
982 for (const VRegMaskOrUnit &Def : RegOpers.Defs) {
983 LaneBitmask PreviousMask = LiveRegs.insert(Def);
984 LaneBitmask NewMask = PreviousMask | Def.LaneMask;
985 increaseRegPressure(Def.VRegOrUnit, PreviousMask, NewMask);
986 }
987
988 // Boost pressure for all dead defs together.
989 bumpDeadDefs(RegOpers.DeadDefs);
990
991 // Find the next instruction.
992 CurrPos = next_nodbg(CurrPos, MBB->end());
993}
994
996 const MachineInstr &MI = *CurrPos;
997 RegisterOperands RegOpers;
998 RegOpers.collect(MI, *TRI, *MRI, TrackLaneMasks, false);
999 if (TrackLaneMasks) {
1000 SlotIndex SlotIdx = getCurrSlot();
1001 RegOpers.adjustLaneLiveness(*LIS, *MRI, SlotIdx);
1002 }
1003 advance(RegOpers);
1004}
1005
1006/// Find the max change in excess pressure across all sets.
1008 ArrayRef<unsigned> NewPressureVec,
1009 RegPressureDelta &Delta,
1010 const RegisterClassInfo *RCI,
1011 ArrayRef<unsigned> LiveThruPressureVec) {
1012 Delta.Excess = PressureChange();
1013 for (unsigned i = 0, e = OldPressureVec.size(); i < e; ++i) {
1014 unsigned POld = OldPressureVec[i];
1015 unsigned PNew = NewPressureVec[i];
1016 int PDiff = (int)PNew - (int)POld;
1017 if (!PDiff) // No change in this set in the common case.
1018 continue;
1019 // Only consider change beyond the limit.
1020 unsigned Limit = RCI->getRegPressureSetLimit(i);
1021 if (!LiveThruPressureVec.empty())
1022 Limit += LiveThruPressureVec[i];
1023
1024 if (Limit > POld) {
1025 if (Limit > PNew)
1026 PDiff = 0; // Under the limit
1027 else
1028 PDiff = PNew - Limit; // Just exceeded limit.
1029 } else if (Limit > PNew)
1030 PDiff = Limit - POld; // Just obeyed limit.
1031
1032 if (PDiff) {
1033 Delta.Excess = PressureChange(i);
1034 Delta.Excess.setUnitInc(PDiff);
1035 break;
1036 }
1037 }
1038}
1039
1040/// Find the max change in max pressure that either surpasses a critical PSet
1041/// limit or exceeds the current MaxPressureLimit.
1042///
1043/// FIXME: comparing each element of the old and new MaxPressure vectors here is
1044/// silly. It's done now to demonstrate the concept but will go away with a
1045/// RegPressureTracker API change to work with pressure differences.
1046static void computeMaxPressureDelta(ArrayRef<unsigned> OldMaxPressureVec,
1047 ArrayRef<unsigned> NewMaxPressureVec,
1048 ArrayRef<PressureChange> CriticalPSets,
1049 ArrayRef<unsigned> MaxPressureLimit,
1050 RegPressureDelta &Delta) {
1051 Delta.CriticalMax = PressureChange();
1052 Delta.CurrentMax = PressureChange();
1053
1054 unsigned CritIdx = 0, CritEnd = CriticalPSets.size();
1055 for (unsigned i = 0, e = OldMaxPressureVec.size(); i < e; ++i) {
1056 unsigned POld = OldMaxPressureVec[i];
1057 unsigned PNew = NewMaxPressureVec[i];
1058 if (PNew == POld) // No change in this set in the common case.
1059 continue;
1060
1061 if (!Delta.CriticalMax.isValid()) {
1062 while (CritIdx != CritEnd && CriticalPSets[CritIdx].getPSet() < i)
1063 ++CritIdx;
1064
1065 if (CritIdx != CritEnd && CriticalPSets[CritIdx].getPSet() == i) {
1066 int PDiff = (int)PNew - CriticalPSets[CritIdx].getUnitInc();
1067 if (PDiff > 0) {
1068 Delta.CriticalMax = PressureChange(i);
1069 Delta.CriticalMax.setUnitInc(PDiff);
1070 }
1071 }
1072 }
1073 // Find the first increase above MaxPressureLimit.
1074 // (Ignores negative MDiff).
1075 if (!Delta.CurrentMax.isValid() && PNew > MaxPressureLimit[i]) {
1076 Delta.CurrentMax = PressureChange(i);
1077 Delta.CurrentMax.setUnitInc(PNew - POld);
1078 if (CritIdx == CritEnd || Delta.CriticalMax.isValid())
1079 break;
1080 }
1081 }
1082}
1083
1084/// Record the upward impact of a single instruction on current register
1085/// pressure. Unlike the advance/recede pressure tracking interface, this does
1086/// not discover live in/outs.
1087///
1088/// This is intended for speculative queries. It leaves pressure inconsistent
1089/// with the current position, so must be restored by the caller.
1091 assert(!MI->isDebugOrPseudoInstr() && "Expect a nondebug instruction.");
1092
1093 SlotIndex SlotIdx;
1094 if (RequireIntervals)
1095 SlotIdx = LIS->getInstructionIndex(*MI).getRegSlot();
1096
1097 // Account for register pressure similar to RegPressureTracker::recede().
1098 RegisterOperands RegOpers;
1099 RegOpers.collect(*MI, *TRI, *MRI, TrackLaneMasks, /*IgnoreDead=*/true);
1100 assert(RegOpers.DeadDefs.empty());
1101 if (TrackLaneMasks)
1102 RegOpers.adjustLaneLiveness(*LIS, *MRI, SlotIdx);
1103 else if (RequireIntervals)
1104 RegOpers.detectDeadDefs(*MI, *LIS, *MRI);
1105
1106 // Boost max pressure for all dead defs together.
1107 // Since CurrSetPressure and MaxSetPressure
1108 bumpDeadDefs(RegOpers.DeadDefs);
1109
1110 // Kill liveness at live defs.
1111 for (const VRegMaskOrUnit &P : RegOpers.Defs) {
1112 LaneBitmask LiveAfter = LiveRegs.contains(P.VRegOrUnit);
1113 LaneBitmask UseLanes = getRegLanes(RegOpers.Uses, P.VRegOrUnit);
1114 LaneBitmask DefLanes = P.LaneMask;
1115 LaneBitmask LiveBefore = (LiveAfter & ~DefLanes) | UseLanes;
1116
1117 // There may be parts of the register that were dead before the
1118 // instruction, but became live afterwards.
1119 decreaseRegPressure(P.VRegOrUnit, LiveAfter, LiveAfter & LiveBefore);
1120 }
1121 // Generate liveness for uses. Also handle any uses which overlap with defs.
1122 for (const VRegMaskOrUnit &P : RegOpers.Uses) {
1123 LaneBitmask LiveAfter = LiveRegs.contains(P.VRegOrUnit);
1124 LaneBitmask LiveBefore = LiveAfter | P.LaneMask;
1125 increaseRegPressure(P.VRegOrUnit, LiveAfter, LiveBefore);
1126 }
1127}
1128
1129/// Consider the pressure increase caused by traversing this instruction
1130/// bottom-up. Find the pressure set with the most change beyond its pressure
1131/// limit based on the tracker's current pressure, and return the change in
1132/// number of register units of that pressure set introduced by this
1133/// instruction.
1134///
1135/// This assumes that the current LiveOut set is sufficient.
1136///
1137/// This is expensive for an on-the-fly query because it calls
1138/// bumpUpwardPressure to recompute the pressure sets based on current
1139/// liveness. This mainly exists to verify correctness, e.g. with
1140/// -verify-misched. getUpwardPressureDelta is the fast version of this query
1141/// that uses the per-SUnit cache of the PressureDiff.
1144 RegPressureDelta &Delta,
1145 ArrayRef<PressureChange> CriticalPSets,
1146 ArrayRef<unsigned> MaxPressureLimit) {
1147 // Snapshot Pressure.
1148 // FIXME: The snapshot heap space should persist. But I'm planning to
1149 // summarize the pressure effect so we don't need to snapshot at all.
1150 std::vector<unsigned> SavedPressure = CurrSetPressure;
1151 std::vector<unsigned> SavedMaxPressure = P.MaxSetPressure;
1152
1154
1155 computeExcessPressureDelta(SavedPressure, CurrSetPressure, Delta, RCI,
1156 LiveThruPressure);
1157 computeMaxPressureDelta(SavedMaxPressure, P.MaxSetPressure, CriticalPSets,
1158 MaxPressureLimit, Delta);
1159 assert(Delta.CriticalMax.getUnitInc() >= 0 &&
1160 Delta.CurrentMax.getUnitInc() >= 0 && "cannot decrease max pressure");
1161
1162 // Restore the tracker's state.
1163 P.MaxSetPressure.swap(SavedMaxPressure);
1164 CurrSetPressure.swap(SavedPressure);
1165
1166#ifndef NDEBUG
1167 if (!PDiff)
1168 return;
1169
1170 // Check if the alternate algorithm yields the same result.
1171 RegPressureDelta Delta2;
1172 getUpwardPressureDelta(MI, *PDiff, Delta2, CriticalPSets, MaxPressureLimit);
1173 if (Delta != Delta2) {
1174 dbgs() << "PDiff: ";
1175 PDiff->dump(*TRI);
1176 dbgs() << "DELTA: " << *MI;
1177 if (Delta.Excess.isValid())
1178 dbgs() << "Excess1 " << TRI->getRegPressureSetName(Delta.Excess.getPSet())
1179 << " " << Delta.Excess.getUnitInc() << "\n";
1180 if (Delta.CriticalMax.isValid())
1181 dbgs() << "Critic1 " << TRI->getRegPressureSetName(Delta.CriticalMax.getPSet())
1182 << " " << Delta.CriticalMax.getUnitInc() << "\n";
1183 if (Delta.CurrentMax.isValid())
1184 dbgs() << "CurrMx1 " << TRI->getRegPressureSetName(Delta.CurrentMax.getPSet())
1185 << " " << Delta.CurrentMax.getUnitInc() << "\n";
1186 if (Delta2.Excess.isValid())
1187 dbgs() << "Excess2 " << TRI->getRegPressureSetName(Delta2.Excess.getPSet())
1188 << " " << Delta2.Excess.getUnitInc() << "\n";
1189 if (Delta2.CriticalMax.isValid())
1190 dbgs() << "Critic2 " << TRI->getRegPressureSetName(Delta2.CriticalMax.getPSet())
1191 << " " << Delta2.CriticalMax.getUnitInc() << "\n";
1192 if (Delta2.CurrentMax.isValid())
1193 dbgs() << "CurrMx2 " << TRI->getRegPressureSetName(Delta2.CurrentMax.getPSet())
1194 << " " << Delta2.CurrentMax.getUnitInc() << "\n";
1195 llvm_unreachable("RegP Delta Mismatch");
1196 }
1197#endif
1198}
1199
1200/// This is the fast version of querying register pressure that does not
1201/// directly depend on current liveness.
1202///
1203/// @param Delta captures information needed for heuristics.
1204///
1205/// @param CriticalPSets Are the pressure sets that are known to exceed some
1206/// limit within the region, not necessarily at the current position.
1207///
1208/// @param MaxPressureLimit Is the max pressure within the region, not
1209/// necessarily at the current position.
1211getUpwardPressureDelta(const MachineInstr *MI, /*const*/ PressureDiff &PDiff,
1212 RegPressureDelta &Delta,
1213 ArrayRef<PressureChange> CriticalPSets,
1214 ArrayRef<unsigned> MaxPressureLimit) const {
1215 unsigned CritIdx = 0, CritEnd = CriticalPSets.size();
1217 PDiffI = PDiff.begin(), PDiffE = PDiff.end();
1218 PDiffI != PDiffE && PDiffI->isValid(); ++PDiffI) {
1219
1220 unsigned PSetID = PDiffI->getPSet();
1221 unsigned Limit = RCI->getRegPressureSetLimit(PSetID);
1222 if (!LiveThruPressure.empty())
1223 Limit += LiveThruPressure[PSetID];
1224
1225 unsigned POld = CurrSetPressure[PSetID];
1226 unsigned MOld = P.MaxSetPressure[PSetID];
1227 unsigned MNew = MOld;
1228 // Ignore DeadDefs here because they aren't captured by PressureChange.
1229 unsigned PNew = POld + PDiffI->getUnitInc();
1230 assert((PDiffI->getUnitInc() >= 0) == (PNew >= POld)
1231 && "PSet overflow/underflow");
1232 if (PNew > MOld)
1233 MNew = PNew;
1234 // Check if current pressure has exceeded the limit.
1235 if (!Delta.Excess.isValid()) {
1236 unsigned ExcessInc = 0;
1237 if (PNew > Limit)
1238 ExcessInc = POld > Limit ? PNew - POld : PNew - Limit;
1239 else if (POld > Limit)
1240 ExcessInc = Limit - POld;
1241 if (ExcessInc) {
1242 Delta.Excess = PressureChange(PSetID);
1243 Delta.Excess.setUnitInc(ExcessInc);
1244 }
1245 }
1246 // Check if max pressure has exceeded a critical pressure set max.
1247 if (MNew == MOld)
1248 continue;
1249 if (!Delta.CriticalMax.isValid()) {
1250 while (CritIdx != CritEnd && CriticalPSets[CritIdx].getPSet() < PSetID)
1251 ++CritIdx;
1252
1253 if (CritIdx != CritEnd && CriticalPSets[CritIdx].getPSet() == PSetID) {
1254 int CritInc = (int)MNew - CriticalPSets[CritIdx].getUnitInc();
1255 if (CritInc > 0 && CritInc <= std::numeric_limits<int16_t>::max()) {
1256 Delta.CriticalMax = PressureChange(PSetID);
1257 Delta.CriticalMax.setUnitInc(CritInc);
1258 }
1259 }
1260 }
1261 // Check if max pressure has exceeded the current max.
1262 if (!Delta.CurrentMax.isValid() && MNew > MaxPressureLimit[PSetID]) {
1263 Delta.CurrentMax = PressureChange(PSetID);
1264 Delta.CurrentMax.setUnitInc(MNew - MOld);
1265 }
1266 }
1267}
1268
1269/// Helper to find a vreg use between two indices [PriorUseIdx, NextUseIdx).
1270/// The query starts with a lane bitmask which gets lanes/bits removed for every
1271/// use we find.
1273 LaneBitmask LastUseMask,
1274 SlotIndex PriorUseIdx, SlotIndex NextUseIdx,
1275 const MachineRegisterInfo &MRI,
1276 const LiveIntervals *LIS) {
1277 const TargetRegisterInfo &TRI = *MRI.getTargetRegisterInfo();
1278 // FIXME: The static_cast is a bug.
1279 Register Reg =
1280 VRegOrUnit.isVirtualReg()
1281 ? VRegOrUnit.asVirtualReg()
1282 : Register(static_cast<unsigned>(VRegOrUnit.asMCRegUnit()));
1283 for (const MachineOperand &MO : MRI.use_nodbg_operands(Reg)) {
1284 if (MO.isUndef())
1285 continue;
1286 const MachineInstr *MI = MO.getParent();
1287 SlotIndex InstSlot = LIS->getInstructionIndex(*MI).getRegSlot();
1288 if (InstSlot >= PriorUseIdx && InstSlot < NextUseIdx) {
1289 unsigned SubRegIdx = MO.getSubReg();
1290 LaneBitmask UseMask = TRI.getSubRegIndexLaneMask(SubRegIdx);
1291 LastUseMask &= ~UseMask;
1292 if (LastUseMask.none())
1293 return LaneBitmask::getNone();
1294 }
1295 }
1296 return LastUseMask;
1297}
1298
1300 SlotIndex Pos) const {
1301 assert(RequireIntervals);
1302 return getLanesWithProperty(
1303 *LIS, *MRI, TrackLaneMasks, VRegOrUnit, Pos, LaneBitmask::getAll(),
1304 [](const LiveRange &LR, SlotIndex Pos) { return LR.liveAt(Pos); });
1305}
1306
1308 SlotIndex Pos) const {
1309 assert(RequireIntervals);
1310 return getLanesWithProperty(
1311 *LIS, *MRI, TrackLaneMasks, VRegOrUnit, Pos.getBaseIndex(),
1312 LaneBitmask::getNone(), [](const LiveRange &LR, SlotIndex Pos) {
1313 const LiveRange::Segment *S = LR.getSegmentContaining(Pos);
1314 return S != nullptr && S->end == Pos.getRegSlot();
1315 });
1316}
1317
1319 SlotIndex Pos) const {
1320 assert(RequireIntervals);
1321 return getLanesWithProperty(
1322 *LIS, *MRI, TrackLaneMasks, VRegOrUnit, Pos, LaneBitmask::getNone(),
1323 [](const LiveRange &LR, SlotIndex Pos) {
1324 const LiveRange::Segment *S = LR.getSegmentContaining(Pos);
1325 return S != nullptr && S->start < Pos.getRegSlot(true) &&
1326 S->end != Pos.getDeadSlot();
1327 });
1328}
1329
1330/// Record the downward impact of a single instruction on current register
1331/// pressure. Unlike the advance/recede pressure tracking interface, this does
1332/// not discover live in/outs.
1333///
1334/// This is intended for speculative queries. It leaves pressure inconsistent
1335/// with the current position, so must be restored by the caller.
1337 assert(!MI->isDebugOrPseudoInstr() && "Expect a nondebug instruction.");
1338
1339 SlotIndex SlotIdx;
1340 if (RequireIntervals)
1341 SlotIdx = LIS->getInstructionIndex(*MI).getRegSlot();
1342
1343 // Account for register pressure similar to RegPressureTracker::advance().
1344 RegisterOperands RegOpers;
1345 RegOpers.collect(*MI, *TRI, *MRI, TrackLaneMasks, /*IgnoreDead=*/false);
1346 if (TrackLaneMasks)
1347 RegOpers.adjustLaneLiveness(*LIS, *MRI, SlotIdx);
1348
1349 if (RequireIntervals) {
1350 for (const VRegMaskOrUnit &Use : RegOpers.Uses) {
1351 VirtRegOrUnit VRegOrUnit = Use.VRegOrUnit;
1352 LaneBitmask LastUseMask = getLastUsedLanes(VRegOrUnit, SlotIdx);
1353 if (LastUseMask.none())
1354 continue;
1355 // The LastUseMask is queried from the liveness information of instruction
1356 // which may be further down the schedule. Some lanes may actually not be
1357 // last uses for the current position.
1358 // FIXME: allow the caller to pass in the list of vreg uses that remain
1359 // to be bottom-scheduled to avoid searching uses at each query.
1360 SlotIndex CurrIdx = getCurrSlot();
1361 LastUseMask =
1362 findUseBetween(VRegOrUnit, LastUseMask, CurrIdx, SlotIdx, *MRI, LIS);
1363 if (LastUseMask.none())
1364 continue;
1365
1366 LaneBitmask LiveMask = LiveRegs.contains(VRegOrUnit);
1367 LaneBitmask NewMask = LiveMask & ~LastUseMask;
1368 decreaseRegPressure(VRegOrUnit, LiveMask, NewMask);
1369 }
1370 }
1371
1372 // Generate liveness for defs.
1373 for (const VRegMaskOrUnit &Def : RegOpers.Defs) {
1374 LaneBitmask LiveMask = LiveRegs.contains(Def.VRegOrUnit);
1375 LaneBitmask NewMask = LiveMask | Def.LaneMask;
1376 increaseRegPressure(Def.VRegOrUnit, LiveMask, NewMask);
1377 }
1378
1379 // Boost pressure for all dead defs together.
1380 bumpDeadDefs(RegOpers.DeadDefs);
1381}
1382
1383/// Consider the pressure increase caused by traversing this instruction
1384/// top-down. Find the register class with the most change in its pressure limit
1385/// based on the tracker's current pressure, and return the number of excess
1386/// register units of that pressure set introduced by this instruction.
1387///
1388/// This assumes that the current LiveIn set is sufficient.
1389///
1390/// This is expensive for an on-the-fly query because it calls
1391/// bumpDownwardPressure to recompute the pressure sets based on current
1392/// liveness. We don't yet have a fast version of downward pressure tracking
1393/// analogous to getUpwardPressureDelta.
1396 ArrayRef<PressureChange> CriticalPSets,
1397 ArrayRef<unsigned> MaxPressureLimit) {
1398 // Snapshot Pressure.
1399 std::vector<unsigned> SavedPressure = CurrSetPressure;
1400 std::vector<unsigned> SavedMaxPressure = P.MaxSetPressure;
1401
1403
1404 computeExcessPressureDelta(SavedPressure, CurrSetPressure, Delta, RCI,
1405 LiveThruPressure);
1406 computeMaxPressureDelta(SavedMaxPressure, P.MaxSetPressure, CriticalPSets,
1407 MaxPressureLimit, Delta);
1408 assert(Delta.CriticalMax.getUnitInc() >= 0 &&
1409 Delta.CurrentMax.getUnitInc() >= 0 && "cannot decrease max pressure");
1410
1411 // Restore the tracker's state.
1412 P.MaxSetPressure.swap(SavedMaxPressure);
1413 CurrSetPressure.swap(SavedPressure);
1414}
1415
1416/// Get the pressure of each PSet after traversing this instruction bottom-up.
1419 std::vector<unsigned> &PressureResult,
1420 std::vector<unsigned> &MaxPressureResult) {
1421 // Snapshot pressure.
1422 PressureResult = CurrSetPressure;
1423 MaxPressureResult = P.MaxSetPressure;
1424
1426
1427 // Current pressure becomes the result. Restore current pressure.
1428 P.MaxSetPressure.swap(MaxPressureResult);
1429 CurrSetPressure.swap(PressureResult);
1430}
1431
1432/// Get the pressure of each PSet after traversing this instruction top-down.
1435 std::vector<unsigned> &PressureResult,
1436 std::vector<unsigned> &MaxPressureResult) {
1437 // Snapshot pressure.
1438 PressureResult = CurrSetPressure;
1439 MaxPressureResult = P.MaxSetPressure;
1440
1442
1443 // Current pressure becomes the result. Restore current pressure.
1444 P.MaxSetPressure.swap(MaxPressureResult);
1445 CurrSetPressure.swap(PressureResult);
1446}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds.
Definition Compiler.h:702
IRTranslator LLVM IR MI
A common definition of LaneBitmask for use in TableGen and CodeGen.
#define I(x, y, z)
Definition MD5.cpp:57
Register Reg
Register const TargetRegisterInfo * TRI
Promote Memory to Register
Definition Mem2Reg.cpp:110
#define P(N)
MachineRegisterInfo & MRI
Register Usage Information Collector
static void computeExcessPressureDelta(ArrayRef< unsigned > OldPressureVec, ArrayRef< unsigned > NewPressureVec, RegPressureDelta &Delta, const RegisterClassInfo *RCI, ArrayRef< unsigned > LiveThruPressureVec)
Find the max change in excess pressure across all sets.
static void increaseSetPressure(std::vector< unsigned > &CurrSetPressure, const MachineRegisterInfo &MRI, VirtRegOrUnit VRegOrUnit, LaneBitmask PrevMask, LaneBitmask NewMask)
Increase pressure for each pressure set provided by TargetRegisterInfo.
static LaneBitmask getRegLanes(ArrayRef< VRegMaskOrUnit > RegUnits, VirtRegOrUnit VRegOrUnit)
static void removeRegLanes(SmallVectorImpl< VRegMaskOrUnit > &RegUnits, VRegMaskOrUnit Pair)
static void computeMaxPressureDelta(ArrayRef< unsigned > OldMaxPressureVec, ArrayRef< unsigned > NewMaxPressureVec, ArrayRef< PressureChange > CriticalPSets, ArrayRef< unsigned > MaxPressureLimit, RegPressureDelta &Delta)
Find the max change in max pressure that either surpasses a critical PSet limit or exceeds the curren...
static LaneBitmask getLanesWithProperty(LiveIntervals &LIS, const MachineRegisterInfo &MRI, bool TrackLaneMasks, VirtRegOrUnit VRegOrUnit, SlotIndex Pos, LaneBitmask SafeDefault, bool(*Property)(const LiveRange &LR, SlotIndex Pos), bool ComputePhysRegs=false)
static void setRegZero(SmallVectorImpl< VRegMaskOrUnit > &RegUnits, VirtRegOrUnit VRegOrUnit)
static LaneBitmask findUseBetween(VirtRegOrUnit VRegOrUnit, LaneBitmask LastUseMask, SlotIndex PriorUseIdx, SlotIndex NextUseIdx, const MachineRegisterInfo &MRI, const LiveIntervals *LIS)
Helper to find a vreg use between two indices [PriorUseIdx, NextUseIdx).
static LaneBitmask getLiveLanesAt(LiveIntervals &LIS, const MachineRegisterInfo &MRI, bool TrackLaneMasks, VirtRegOrUnit VRegOrUnit, SlotIndex Pos, bool ComputePhysRegs=false)
static void addRegLanes(SmallVectorImpl< VRegMaskOrUnit > &RegUnits, VRegMaskOrUnit Pair)
static void decreaseSetPressure(std::vector< unsigned > &CurrSetPressure, const MachineRegisterInfo &MRI, VirtRegOrUnit VRegOrUnit, LaneBitmask PrevMask, LaneBitmask NewMask)
Decrease pressure for each pressure set provided by TargetRegisterInfo.
This file contains some templates that are useful if you are working with the STL at all.
This file defines the SmallVector class.
Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:40
iterator end() const
Definition ArrayRef.h:130
size_t size() const
Get the array size.
Definition ArrayRef.h:141
bool empty() const
Check if the array is empty.
Definition ArrayRef.h:136
A live range for subregisters.
LiveInterval - This class represents the liveness of a register, or stack slot.
bool hasSubRanges() const
Returns true if subregister liveness information is available.
iterator_range< subrange_iterator > subranges()
SlotIndex getInstructionIndex(const MachineInstr &Instr) const
Returns the base index of the given instruction.
LiveInterval & getInterval(Register Reg)
LiveRange & getRegUnit(MCRegUnit Unit)
Return the live range for register unit Unit.
LiveRange * getCachedRegUnit(MCRegUnit Unit)
Return the live range for register unit Unit if it has already been computed, or nullptr if it hasn't...
This class represents the liveness of a register, stack slot, etc.
const Segment * getSegmentContaining(SlotIndex Idx) const
Return the segment that contains the specified index, or null if there is none.
bool liveAt(SlotIndex index) const
LLVM_ABI void clear()
LLVM_ABI void init(const MachineRegisterInfo &MRI)
MachineInstrBundleIterator< const MachineInstr > const_iterator
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
Representation of each machine instruction.
MachineOperand class - Representation of each machine instruction operand.
unsigned getSubReg() const
bool readsReg() const
readsReg - Returns true if this operand reads the previous value of its register.
bool isReg() const
isReg - Tests if this is a MO_Register operand.
MachineInstr * getParent()
getParent - Return the instruction that this operand belongs to.
void setIsUndef(bool Val=true)
Register getReg() const
getReg - Returns the register number.
bool isInternalRead() const
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
bool isAllocatable(MCRegister PhysReg) const
isAllocatable - Returns true when PhysReg belongs to an allocatable register class and it hasn't been...
LLVM_ABI LaneBitmask getMaxLaneMaskForVReg(Register Reg) const
Returns a mask covering all bits that can appear in lane masks of subregisters of the virtual registe...
Iterate over the pressure sets affected by the given physical or virtual register.
unsigned getWeight() const
Capture a change in pressure for a single pressure set.
unsigned getPSetOrMax() const
LLVM_ABI void dump() const
unsigned getPSet() const
List of PressureChanges in order of increasing, unique PSetID.
const PressureChange * const_iterator
LLVM_ABI void dump(const TargetRegisterInfo &TRI) const
const_iterator end() const
LLVM_ABI void addPressureChange(VirtRegOrUnit VRegOrUnit, bool IsDec, const MachineRegisterInfo *MRI)
Add a change in pressure to the pressure diff of a given instruction.
const_iterator begin() const
LLVM_ABI void addInstruction(unsigned Idx, const RegisterOperands &RegOpers, const MachineRegisterInfo &MRI)
Record pressure difference induced by the given operand list to node with index Idx.
LLVM_ABI void init(unsigned N)
Initialize an array of N PressureDiffs.
LLVM_ABI void init(const MachineFunction *mf, const RegisterClassInfo *rci, LiveIntervals *lis, const MachineBasicBlock *mbb, MachineBasicBlock::const_iterator pos, bool TrackLaneMasks, bool TrackUntiedDefs)
Setup the RegPressureTracker.
LLVM_ABI void closeRegion()
Finalize the region boundaries and recored live ins and live outs.
LLVM_ABI void discoverLiveIn(VRegMaskOrUnit Pair)
Add Reg to the live in set and increase max pressure.
LLVM_ABI void closeBottom()
Set the boundary for the bottom of the region and summarize live outs.
LLVM_ABI void recede(SmallVectorImpl< VRegMaskOrUnit > *LiveUses=nullptr)
Recede across the previous instruction.
LLVM_ABI void bumpDownwardPressure(const MachineInstr *MI)
Record the downward impact of a single instruction on current register pressure.
LLVM_ABI void addLiveRegs(ArrayRef< VRegMaskOrUnit > Regs)
Force liveness of virtual registers or physical register units.
LLVM_ABI void recedeSkipDebugValues()
Recede until we find an instruction which is not a DebugValue.
LLVM_ABI void getMaxUpwardPressureDelta(const MachineInstr *MI, PressureDiff *PDiff, RegPressureDelta &Delta, ArrayRef< PressureChange > CriticalPSets, ArrayRef< unsigned > MaxPressureLimit)
Consider the pressure increase caused by traversing this instruction bottom-up.
LLVM_ABI void initLiveThru(const RegPressureTracker &RPTracker)
Initialize the LiveThru pressure set based on the untied defs found in RPTracker.
LLVM_ABI void bumpDeadDefs(ArrayRef< VRegMaskOrUnit > DeadDefs)
RegPressureTracker(IntervalPressure &rp)
LLVM_ABI void dump() const
LLVM_ABI void discoverLiveInOrOut(VRegMaskOrUnit Pair, SmallVectorImpl< VRegMaskOrUnit > &LiveInOrOut)
LLVM_ABI LaneBitmask getLiveThroughAt(VirtRegOrUnit VRegOrUnit, SlotIndex Pos) const
LLVM_ABI bool isBottomClosed() const
Does this pressure result have a valid bottom position and live outs.
LLVM_ABI LaneBitmask getLiveLanesAt(VirtRegOrUnit VRegOrUnit, SlotIndex Pos) const
bool hasUntiedDef(Register VirtReg) const
LLVM_ABI void closeTop()
Set the boundary for the top of the region and summarize live ins.
LLVM_ABI void getMaxDownwardPressureDelta(const MachineInstr *MI, RegPressureDelta &Delta, ArrayRef< PressureChange > CriticalPSets, ArrayRef< unsigned > MaxPressureLimit)
Consider the pressure increase caused by traversing this instruction top-down.
LLVM_ABI void advance()
Advance across the current instruction.
LLVM_ABI bool isTopClosed() const
Does this pressure result have a valid top position and live ins.
LLVM_ABI void bumpUpwardPressure(const MachineInstr *MI)
Record the upward impact of a single instruction on current register pressure.
LLVM_ABI LaneBitmask getLastUsedLanes(VirtRegOrUnit VRegOrUnit, SlotIndex Pos) const
LLVM_ABI void increaseRegPressure(VirtRegOrUnit VRegOrUnit, LaneBitmask PreviousMask, LaneBitmask NewMask)
LLVM_ABI void getDownwardPressure(const MachineInstr *MI, std::vector< unsigned > &PressureResult, std::vector< unsigned > &MaxPressureResult)
Get the pressure of each PSet after traversing this instruction top-down.
LLVM_ABI SlotIndex getCurrSlot() const
Get the SlotIndex for the first nondebug instruction including or after the current position.
LLVM_ABI void decreaseRegPressure(VirtRegOrUnit VRegOrUnit, LaneBitmask PreviousMask, LaneBitmask NewMask)
LLVM_ABI void getUpwardPressure(const MachineInstr *MI, std::vector< unsigned > &PressureResult, std::vector< unsigned > &MaxPressureResult)
Get the pressure of each PSet after traversing this instruction bottom-up.
LLVM_ABI void discoverLiveOut(VRegMaskOrUnit Pair)
Add Reg to the live out set and increase max pressure.
LLVM_ABI void getUpwardPressureDelta(const MachineInstr *MI, PressureDiff &PDiff, RegPressureDelta &Delta, ArrayRef< PressureChange > CriticalPSets, ArrayRef< unsigned > MaxPressureLimit) const
This is the fast version of querying register pressure that does not directly depend on current liven...
unsigned getRegPressureSetLimit(unsigned Idx) const
Get the register unit limit for the given pressure set index.
List of registers defined and used by a machine instruction.
LLVM_ABI void detectDeadDefs(const MachineInstr &MI, LiveIntervals &LIS, const MachineRegisterInfo &MRI)
Use liveness information to find dead defs at MI's dead slot not marked with a dead flag and move the...
SmallVector< VRegMaskOrUnit, 8 > Defs
List of virtual registers and register units defined by the instruction which are not dead.
LLVM_ABI void adjustLaneLiveness(LiveIntervals &LIS, const MachineRegisterInfo &MRI, SlotIndex Pos)
Use liveness information to find out which uses/defs are partially undefined/dead at Pos and adjust t...
LLVM_ABI void collect(const MachineInstr &MI, const TargetRegisterInfo &TRI, const MachineRegisterInfo &MRI, bool TrackLaneMasks, bool IgnoreDead)
Analyze the given instruction MI and fill in the Uses, Defs and DeadDefs list based on the MachineOpe...
SmallVector< VRegMaskOrUnit, 8 > DeadDefs
List of virtual registers and register units defined by the instruction but dead.
SmallVector< VRegMaskOrUnit, 8 > Uses
List of virtual registers and register units read by the instruction.
static LLVM_ABI void restoreLivenessFlags(MachineInstr &MI, const TargetRegisterInfo &TRI, const MachineRegisterInfo &MRI, LiveIntervals &LIS, bool TrackLaneMasks=true, ArrayRef< Register > OnlyRegs={})
Clear potentially-stale read-undef flags on the defs of MI, then recompute them from LIS.
Wrapper class representing virtual and physical registers.
Definition Register.h:20
MCRegister asMCReg() const
Utility to check-convert this value to a MCRegister.
Definition Register.h:107
constexpr bool isVirtual() const
Return true if the specified register number is in the virtual register namespace.
Definition Register.h:79
SlotIndex - An opaque wrapper around machine indexes.
Definition SlotIndexes.h:70
SlotIndex getDeadSlot() const
Returns the dead def kill slot for the current instruction.
SlotIndex getBaseIndex() const
Returns the base index for associated with this index.
SlotIndex getRegSlot(bool EC=false) const
Returns the register use/def slot in the current instruction for a normal or early-clobber def.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
reference emplace_back(ArgTypes &&... Args)
iterator erase(const_iterator CI)
void push_back(const T &Elt)
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
virtual const TargetRegisterInfo * getRegisterInfo() const =0
Return the target's register information.
A Use represents the edge between a Value definition and its users.
Definition Use.h:35
Wrapper class representing a virtual register or register unit.
Definition Register.h:175
constexpr bool isVirtualReg() const
Definition Register.h:191
constexpr MCRegUnit asMCRegUnit() const
Definition Register.h:195
constexpr Register asVirtualReg() const
Definition Register.h:200
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
This is an optimization pass for GlobalISel generic memory operations.
IterT next_nodbg(IterT It, IterT End, bool SkipPseudoOp=true)
Increment It, then continue incrementing it while it points to a debug instruction.
Printable PrintLaneMask(LaneBitmask LaneMask)
Create Printable object to print LaneBitmasks on a raw_ostream.
Definition LaneBitmask.h:92
LLVM_ATTRIBUTE_RETURNS_NONNULL void * safe_calloc(size_t Count, size_t Sz)
Definition MemAlloc.h:38
IterT skipDebugInstructionsForward(IterT It, IterT End, bool SkipPseudoOp=true)
Increment It until it points to a non-debug instruction or to End and return the resulting iterator.
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition Debug.cpp:209
@ Other
Any other memory.
Definition ModRef.h:68
auto find_if(R &&Range, UnaryPredicate P)
Provide wrappers to std::find_if which take ranges instead of having to pass begin/end explicitly.
Definition STLExtras.h:1788
bool is_contained(R &&Range, const E &Element)
Returns true if Element is found in Range.
Definition STLExtras.h:1963
LLVM_ABI void dumpRegSetPressure(ArrayRef< unsigned > SetPressure, const TargetRegisterInfo *TRI)
IterT prev_nodbg(IterT It, IterT Begin, bool SkipPseudoOp=true)
Decrement It, then continue decrementing it while it points to a debug instruction.
LLVM_ABI Printable printVRegOrUnit(VirtRegOrUnit VRegOrUnit, const TargetRegisterInfo *TRI)
Create Printable object to print virtual registers and physical registers on a raw_ostream.
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.
Definition BitVector.h:881
#define N
RegisterPressure computed within a region of instructions delimited by TopIdx and BottomIdx.
LLVM_ABI void reset()
Clear the result so it can be used for another round of pressure tracking.
LLVM_ABI void openBottom(SlotIndex PrevBottom)
If the current bottom is not greater than the previous index, open it.
SlotIndex TopIdx
Record the boundary of the region being tracked.
LLVM_ABI void openTop(SlotIndex NextTop)
If the current top is not less than or equal to the next index, open it.
static constexpr LaneBitmask getAll()
Definition LaneBitmask.h:82
constexpr bool none() const
Definition LaneBitmask.h:52
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.
Store the effects of a change in pressure on things that MI scheduler cares about.
LLVM_ABI void dump() const
RegisterPressure computed within a region of instructions delimited by TopPos and BottomPos.
MachineBasicBlock::const_iterator TopPos
Record the boundary of the region being tracked.
MachineBasicBlock::const_iterator BottomPos
LLVM_ABI void openTop(MachineBasicBlock::const_iterator PrevTop)
If the current top is the previous instruction (before receding), open it.
LLVM_ABI void reset()
Clear the result so it can be used for another round of pressure tracking.
LLVM_ABI void openBottom(MachineBasicBlock::const_iterator PrevBottom)
If the current bottom is the previous instr (before advancing), open it.
SmallVector< VRegMaskOrUnit, 8 > LiveOutRegs
SmallVector< VRegMaskOrUnit, 8 > LiveInRegs
List of live in virtual registers or physical register units.
LLVM_ABI void dump(const TargetRegisterInfo *TRI) const
std::vector< unsigned > MaxSetPressure
Map of max reg pressure indexed by pressure set ID, not class ID.