LLVM 17.0.0git
LiveRangeEdit.cpp
Go to the documentation of this file.
1//===-- LiveRangeEdit.cpp - Basic tools for editing a register live range -===//
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// The LiveRangeEdit class represents changes done to a virtual register when it
10// is spilled or split.
11//===----------------------------------------------------------------------===//
12
14#include "llvm/ADT/Statistic.h"
20#include "llvm/Support/Debug.h"
22
23using namespace llvm;
24
25#define DEBUG_TYPE "regalloc"
26
27STATISTIC(NumDCEDeleted, "Number of instructions deleted by DCE");
28STATISTIC(NumDCEFoldedLoads, "Number of single use loads folded after DCE");
29STATISTIC(NumFracRanges, "Number of live ranges fractured by DCE");
30STATISTIC(NumReMaterialization, "Number of instructions rematerialized");
31
32void LiveRangeEdit::Delegate::anchor() { }
33
34LiveInterval &LiveRangeEdit::createEmptyIntervalFrom(Register OldReg,
35 bool createSubRanges) {
36 Register VReg = MRI.cloneVirtualRegister(OldReg);
37 if (VRM)
38 VRM->setIsSplitFromReg(VReg, VRM->getOriginal(OldReg));
39
40 LiveInterval &LI = LIS.createEmptyInterval(VReg);
41 if (Parent && !Parent->isSpillable())
43 if (createSubRanges) {
44 // Create empty subranges if the OldReg's interval has them. Do not create
45 // the main range here---it will be constructed later after the subranges
46 // have been finalized.
47 LiveInterval &OldLI = LIS.getInterval(OldReg);
49 for (LiveInterval::SubRange &S : OldLI.subranges())
50 LI.createSubRange(Alloc, S.LaneMask);
51 }
52 return LI;
53}
54
56 Register VReg = MRI.cloneVirtualRegister(OldReg);
57 if (VRM) {
58 VRM->setIsSplitFromReg(VReg, VRM->getOriginal(OldReg));
59 }
60 // FIXME: Getting the interval here actually computes it.
61 // In theory, this may not be what we want, but in practice
62 // the createEmptyIntervalFrom API is used when this is not
63 // the case. Generally speaking we just want to annotate the
64 // LiveInterval when it gets created but we cannot do that at
65 // the moment.
66 if (Parent && !Parent->isSpillable())
67 LIS.getInterval(VReg).markNotSpillable();
68 return VReg;
69}
70
72 const MachineInstr *DefMI) {
73 assert(DefMI && "Missing instruction");
74 ScannedRemattable = true;
76 return false;
77 Remattable.insert(VNI);
78 return true;
79}
80
81void LiveRangeEdit::scanRemattable() {
82 for (VNInfo *VNI : getParent().valnos) {
83 if (VNI->isUnused())
84 continue;
85 Register Original = VRM->getOriginal(getReg());
86 LiveInterval &OrigLI = LIS.getInterval(Original);
87 VNInfo *OrigVNI = OrigLI.getVNInfoAt(VNI->def);
88 if (!OrigVNI)
89 continue;
91 if (!DefMI)
92 continue;
94 }
95 ScannedRemattable = true;
96}
97
99 if (!ScannedRemattable)
100 scanRemattable();
101 return !Remattable.empty();
102}
103
104/// allUsesAvailableAt - Return true if all registers used by OrigMI at
105/// OrigIdx are also available with the same value at UseIdx.
107 SlotIndex OrigIdx,
108 SlotIndex UseIdx) const {
109 OrigIdx = OrigIdx.getRegSlot(true);
110 UseIdx = std::max(UseIdx, UseIdx.getRegSlot(true));
111 for (const MachineOperand &MO : OrigMI->operands()) {
112 if (!MO.isReg() || !MO.getReg() || !MO.readsReg())
113 continue;
114
115 // We can't remat physreg uses, unless it is a constant or target wants
116 // to ignore this use.
117 if (MO.getReg().isPhysical()) {
118 if (MRI.isConstantPhysReg(MO.getReg()) || TII.isIgnorableUse(MO))
119 continue;
120 return false;
121 }
122
123 LiveInterval &li = LIS.getInterval(MO.getReg());
124 const VNInfo *OVNI = li.getVNInfoAt(OrigIdx);
125 if (!OVNI)
126 continue;
127
128 // Don't allow rematerialization immediately after the original def.
129 // It would be incorrect if OrigMI redefines the register.
130 // See PR14098.
131 if (SlotIndex::isSameInstr(OrigIdx, UseIdx))
132 return false;
133
134 if (OVNI != li.getVNInfoAt(UseIdx))
135 return false;
136
137 // Check that subrange is live at UseIdx.
138 if (li.hasSubRanges()) {
140 unsigned SubReg = MO.getSubReg();
141 LaneBitmask LM = SubReg ? TRI->getSubRegIndexLaneMask(SubReg)
142 : MRI.getMaxLaneMaskForVReg(MO.getReg());
143 for (LiveInterval::SubRange &SR : li.subranges()) {
144 if ((SR.LaneMask & LM).none())
145 continue;
146 if (!SR.liveAt(UseIdx))
147 return false;
148 // Early exit if all used lanes are checked. No need to continue.
149 LM &= ~SR.LaneMask;
150 if (LM.none())
151 break;
152 }
153 }
154 }
155 return true;
156}
157
159 SlotIndex UseIdx, bool cheapAsAMove) {
160 assert(ScannedRemattable && "Call anyRematerializable first");
161
162 // Use scanRemattable info.
163 if (!Remattable.count(OrigVNI))
164 return false;
165
166 // No defining instruction provided.
167 SlotIndex DefIdx;
168 assert(RM.OrigMI && "No defining instruction for remattable value");
169 DefIdx = LIS.getInstructionIndex(*RM.OrigMI);
170
171 // If only cheap remats were requested, bail out early.
172 if (cheapAsAMove && !TII.isAsCheapAsAMove(*RM.OrigMI))
173 return false;
174
175 // Verify that all used registers are available with the same values.
176 if (!allUsesAvailableAt(RM.OrigMI, DefIdx, UseIdx))
177 return false;
178
179 return true;
180}
181
184 Register DestReg, const Remat &RM,
185 const TargetRegisterInfo &tri,
186 bool Late, unsigned SubIdx,
187 MachineInstr *ReplaceIndexMI) {
188 assert(RM.OrigMI && "Invalid remat");
189 TII.reMaterialize(MBB, MI, DestReg, SubIdx, *RM.OrigMI, tri);
190 // DestReg of the cloned instruction cannot be Dead. Set isDead of DestReg
191 // to false anyway in case the isDead flag of RM.OrigMI's dest register
192 // is true.
193 (*--MI).getOperand(0).setIsDead(false);
194 Rematted.insert(RM.ParentVNI);
195 ++NumReMaterialization;
196
197 if (ReplaceIndexMI)
198 return LIS.ReplaceMachineInstrInMaps(*ReplaceIndexMI, *MI).getRegSlot();
200}
201
203 if (TheDelegate && TheDelegate->LRE_CanEraseVirtReg(Reg))
204 LIS.removeInterval(Reg);
205}
206
207bool LiveRangeEdit::foldAsLoad(LiveInterval *LI,
209 MachineInstr *DefMI = nullptr, *UseMI = nullptr;
210
211 // Check that there is a single def and a single use.
212 for (MachineOperand &MO : MRI.reg_nodbg_operands(LI->reg())) {
213 MachineInstr *MI = MO.getParent();
214 if (MO.isDef()) {
215 if (DefMI && DefMI != MI)
216 return false;
217 if (!MI->canFoldAsLoad())
218 return false;
219 DefMI = MI;
220 } else if (!MO.isUndef()) {
221 if (UseMI && UseMI != MI)
222 return false;
223 // FIXME: Targets don't know how to fold subreg uses.
224 if (MO.getSubReg())
225 return false;
226 UseMI = MI;
227 }
228 }
229 if (!DefMI || !UseMI)
230 return false;
231
232 // Since we're moving the DefMI load, make sure we're not extending any live
233 // ranges.
236 return false;
237
238 // We also need to make sure it is safe to move the load.
239 // Assume there are stores between DefMI and UseMI.
240 bool SawStore = true;
241 if (!DefMI->isSafeToMove(nullptr, SawStore))
242 return false;
243
244 LLVM_DEBUG(dbgs() << "Try to fold single def: " << *DefMI
245 << " into single use: " << *UseMI);
246
248 if (UseMI->readsWritesVirtualRegister(LI->reg(), &Ops).second)
249 return false;
250
251 MachineInstr *FoldMI = TII.foldMemoryOperand(*UseMI, Ops, *DefMI, &LIS);
252 if (!FoldMI)
253 return false;
254 LLVM_DEBUG(dbgs() << " folded: " << *FoldMI);
255 LIS.ReplaceMachineInstrInMaps(*UseMI, *FoldMI);
256 // Update the call site info.
258 UseMI->getMF()->moveCallSiteInfo(UseMI, FoldMI);
260 DefMI->addRegisterDead(LI->reg(), nullptr);
261 Dead.push_back(DefMI);
262 ++NumDCEFoldedLoads;
263 return true;
264}
265
266bool LiveRangeEdit::useIsKill(const LiveInterval &LI,
267 const MachineOperand &MO) const {
268 const MachineInstr &MI = *MO.getParent();
270 if (LI.Query(Idx).isKill())
271 return true;
273 unsigned SubReg = MO.getSubReg();
274 LaneBitmask LaneMask = TRI.getSubRegIndexLaneMask(SubReg);
275 for (const LiveInterval::SubRange &S : LI.subranges()) {
276 if ((S.LaneMask & LaneMask).any() && S.Query(Idx).isKill())
277 return true;
278 }
279 return false;
280}
281
282/// Find all live intervals that need to shrink, then remove the instruction.
283void LiveRangeEdit::eliminateDeadDef(MachineInstr *MI, ToShrinkSet &ToShrink) {
284 assert(MI->allDefsAreDead() && "Def isn't really dead");
286
287 // Never delete a bundled instruction.
288 if (MI->isBundled()) {
289 return;
290 }
291 // Never delete inline asm.
292 if (MI->isInlineAsm()) {
293 LLVM_DEBUG(dbgs() << "Won't delete: " << Idx << '\t' << *MI);
294 return;
295 }
296
297 // Use the same criteria as DeadMachineInstructionElim.
298 bool SawStore = false;
299 if (!MI->isSafeToMove(nullptr, SawStore)) {
300 LLVM_DEBUG(dbgs() << "Can't delete: " << Idx << '\t' << *MI);
301 return;
302 }
303
304 LLVM_DEBUG(dbgs() << "Deleting dead def " << Idx << '\t' << *MI);
305
306 // Collect virtual registers to be erased after MI is gone.
307 SmallVector<Register, 8> RegsToErase;
308 bool ReadsPhysRegs = false;
309 bool isOrigDef = false;
310 Register Dest;
311 unsigned DestSubReg;
312 // Only optimize rematerialize case when the instruction has one def, since
313 // otherwise we could leave some dead defs in the code. This case is
314 // extremely rare.
315 if (VRM && MI->getOperand(0).isReg() && MI->getOperand(0).isDef() &&
316 MI->getDesc().getNumDefs() == 1) {
317 Dest = MI->getOperand(0).getReg();
318 DestSubReg = MI->getOperand(0).getSubReg();
319 Register Original = VRM->getOriginal(Dest);
320 LiveInterval &OrigLI = LIS.getInterval(Original);
321 VNInfo *OrigVNI = OrigLI.getVNInfoAt(Idx);
322 // The original live-range may have been shrunk to
323 // an empty live-range. It happens when it is dead, but
324 // we still keep it around to be able to rematerialize
325 // other values that depend on it.
326 if (OrigVNI)
327 isOrigDef = SlotIndex::isSameInstr(OrigVNI->def, Idx);
328 }
329
330 bool HasLiveVRegUses = false;
331
332 // Check for live intervals that may shrink
333 for (const MachineOperand &MO : MI->operands()) {
334 if (!MO.isReg())
335 continue;
336 Register Reg = MO.getReg();
337 if (!Reg.isVirtual()) {
338 // Check if MI reads any unreserved physregs.
339 if (Reg && MO.readsReg() && !MRI.isReserved(Reg))
340 ReadsPhysRegs = true;
341 else if (MO.isDef())
342 LIS.removePhysRegDefAt(Reg.asMCReg(), Idx);
343 continue;
344 }
345 LiveInterval &LI = LIS.getInterval(Reg);
346
347 // Shrink read registers, unless it is likely to be expensive and
348 // unlikely to change anything. We typically don't want to shrink the
349 // PIC base register that has lots of uses everywhere.
350 // Always shrink COPY uses that probably come from live range splitting.
351 if ((MI->readsVirtualRegister(Reg) && (MI->isCopy() || MO.isDef())) ||
352 (MO.readsReg() && (MRI.hasOneNonDBGUse(Reg) || useIsKill(LI, MO))))
353 ToShrink.insert(&LI);
354 else if (MO.readsReg())
355 HasLiveVRegUses = true;
356
357 // Remove defined value.
358 if (MO.isDef()) {
359 if (TheDelegate && LI.getVNInfoAt(Idx) != nullptr)
360 TheDelegate->LRE_WillShrinkVirtReg(LI.reg());
361 LIS.removeVRegDefAt(LI, Idx);
362 if (LI.empty())
363 RegsToErase.push_back(Reg);
364 }
365 }
366
367 // Currently, we don't support DCE of physreg live ranges. If MI reads
368 // any unreserved physregs, don't erase the instruction, but turn it into
369 // a KILL instead. This way, the physreg live ranges don't end up
370 // dangling.
371 // FIXME: It would be better to have something like shrinkToUses() for
372 // physregs. That could potentially enable more DCE and it would free up
373 // the physreg. It would not happen often, though.
374 if (ReadsPhysRegs) {
375 MI->setDesc(TII.get(TargetOpcode::KILL));
376 // Remove all operands that aren't physregs.
377 for (unsigned i = MI->getNumOperands(); i; --i) {
378 const MachineOperand &MO = MI->getOperand(i-1);
379 if (MO.isReg() && MO.getReg().isPhysical())
380 continue;
381 MI->removeOperand(i-1);
382 }
383 LLVM_DEBUG(dbgs() << "Converted physregs to:\t" << *MI);
384 } else {
385 // If the dest of MI is an original reg and MI is reMaterializable,
386 // don't delete the inst. Replace the dest with a new reg, and keep
387 // the inst for remat of other siblings. The inst is saved in
388 // LiveRangeEdit::DeadRemats and will be deleted after all the
389 // allocations of the func are done.
390 // However, immediately delete instructions which have unshrunk virtual
391 // register uses. That may provoke RA to split an interval at the KILL
392 // and later result in an invalid live segment end.
393 if (isOrigDef && DeadRemats && !HasLiveVRegUses &&
395 LiveInterval &NewLI = createEmptyIntervalFrom(Dest, false);
397 VNInfo *VNI = NewLI.getNextValue(Idx, Alloc);
398 NewLI.addSegment(LiveInterval::Segment(Idx, Idx.getDeadSlot(), VNI));
399
400 if (DestSubReg) {
402 auto *SR = NewLI.createSubRange(
403 Alloc, TRI->getSubRegIndexLaneMask(DestSubReg));
404 SR->addSegment(LiveInterval::Segment(Idx, Idx.getDeadSlot(),
405 SR->getNextValue(Idx, Alloc)));
406 }
407
408 pop_back();
409 DeadRemats->insert(MI);
411 MI->substituteRegister(Dest, NewLI.reg(), 0, TRI);
412 MI->getOperand(0).setIsDead(true);
413 } else {
414 if (TheDelegate)
415 TheDelegate->LRE_WillEraseInstruction(MI);
417 MI->eraseFromParent();
418 ++NumDCEDeleted;
419 }
420 }
421
422 // Erase any virtregs that are now empty and unused. There may be <undef>
423 // uses around. Keep the empty live range in that case.
424 for (unsigned i = 0, e = RegsToErase.size(); i != e; ++i) {
425 Register Reg = RegsToErase[i];
426 if (LIS.hasInterval(Reg) && MRI.reg_nodbg_empty(Reg)) {
427 ToShrink.remove(&LIS.getInterval(Reg));
428 eraseVirtReg(Reg);
429 }
430 }
431}
432
434 ArrayRef<Register> RegsBeingSpilled) {
435 ToShrinkSet ToShrink;
436
437 for (;;) {
438 // Erase all dead defs.
439 while (!Dead.empty())
440 eliminateDeadDef(Dead.pop_back_val(), ToShrink);
441
442 if (ToShrink.empty())
443 break;
444
445 // Shrink just one live interval. Then delete new dead defs.
446 LiveInterval *LI = ToShrink.pop_back_val();
447 if (foldAsLoad(LI, Dead))
448 continue;
449 Register VReg = LI->reg();
450 if (TheDelegate)
451 TheDelegate->LRE_WillShrinkVirtReg(VReg);
452 if (!LIS.shrinkToUses(LI, &Dead))
453 continue;
454
455 // Don't create new intervals for a register being spilled.
456 // The new intervals would have to be spilled anyway so its not worth it.
457 // Also they currently aren't spilled so creating them and not spilling
458 // them results in incorrect code.
459 if (llvm::is_contained(RegsBeingSpilled, VReg))
460 continue;
461
462 // LI may have been separated, create new intervals.
463 LI->RenumberValues();
465 LIS.splitSeparateComponents(*LI, SplitLIs);
466 if (!SplitLIs.empty())
467 ++NumFracRanges;
468
469 Register Original = VRM ? VRM->getOriginal(VReg) : Register();
470 for (const LiveInterval *SplitLI : SplitLIs) {
471 // If LI is an original interval that hasn't been split yet, make the new
472 // intervals their own originals instead of referring to LI. The original
473 // interval must contain all the split products, and LI doesn't.
474 if (Original != VReg && Original != 0)
475 VRM->setIsSplitFromReg(SplitLI->reg(), Original);
476 if (TheDelegate)
477 TheDelegate->LRE_DidCloneVirtReg(SplitLI->reg(), VReg);
478 }
479 }
480}
481
482// Keep track of new virtual registers created via
483// MachineRegisterInfo::createVirtualRegister.
484void
485LiveRangeEdit::MRI_NoteNewVirtualRegister(Register VReg) {
486 if (VRM)
487 VRM->grow();
488
489 NewRegs.push_back(VReg);
490}
491
493 VirtRegAuxInfo &VRAI) {
494 for (unsigned I = 0, Size = size(); I < Size; ++I) {
495 LiveInterval &LI = LIS.getInterval(get(I));
496 if (MRI.recomputeRegClass(LI.reg()))
497 LLVM_DEBUG({
498 const TargetRegisterInfo *TRI = MF.getSubtarget().getRegisterInfo();
499 dbgs() << "Inflated " << printReg(LI.reg()) << " to "
500 << TRI->getRegClassName(MRI.getRegClass(LI.reg())) << '\n';
501 });
503 }
504}
unsigned SubReg
MachineInstrBuilder & UseMI
MachineInstrBuilder MachineInstrBuilder & DefMI
MachineBasicBlock & MBB
Returns the sub type a function will return at a given Idx Should correspond to the result type of an ExtractValue instruction executed with just that one unsigned Idx
#define LLVM_DEBUG(X)
Definition: Debug.h:101
uint64_t Size
IRTranslator LLVM IR MI
#define I(x, y, z)
Definition: MD5.cpp:58
unsigned const TargetRegisterInfo * TRI
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This file defines the 'Statistic' class, which is designed to be an easy way to expose various metric...
#define STATISTIC(VARNAME, DESC)
Definition: Statistic.h:167
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: ArrayRef.h:41
Allocate memory in an ever growing pool, as if by bump-pointer.
Definition: Allocator.h:66
A live range for subregisters.
Definition: LiveInterval.h:693
LiveInterval - This class represents the liveness of a register, or stack slot.
Definition: LiveInterval.h:686
void markNotSpillable()
markNotSpillable - Mark interval as not spillable
Definition: LiveInterval.h:822
Register reg() const
Definition: LiveInterval.h:717
bool isSpillable() const
isSpillable - Can this interval be spilled?
Definition: LiveInterval.h:819
bool hasSubRanges() const
Returns true if subregister liveness information is available.
Definition: LiveInterval.h:803
iterator_range< subrange_iterator > subranges()
Definition: LiveInterval.h:775
SubRange * createSubRange(BumpPtrAllocator &Allocator, LaneBitmask LaneMask)
Creates a new empty subregister live range.
Definition: LiveInterval.h:785
bool hasInterval(Register Reg) const
MachineInstr * getInstructionFromIndex(SlotIndex index) const
Returns the instruction associated with the given index.
SlotIndexes * getSlotIndexes() const
SlotIndex getInstructionIndex(const MachineInstr &Instr) const
Returns the base index of the given instruction.
void RemoveMachineInstrFromMaps(MachineInstr &MI)
VNInfo::Allocator & getVNInfoAllocator()
LiveInterval & getInterval(Register Reg)
void removeInterval(Register Reg)
Interval removal.
void removeVRegDefAt(LiveInterval &LI, SlotIndex Pos)
Remove value number and related live segments of LI and its subranges that start at position Pos.
bool shrinkToUses(LiveInterval *li, SmallVectorImpl< MachineInstr * > *dead=nullptr)
After removing some uses of a register, shrink its live range to just the remaining uses.
LiveInterval & createEmptyInterval(Register Reg)
Interval creation.
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.
SlotIndex ReplaceMachineInstrInMaps(MachineInstr &MI, MachineInstr &NewMI)
bool isKill() const
Return true if the live-in value is killed by this instruction.
Definition: LiveInterval.h:112
virtual bool LRE_CanEraseVirtReg(Register)
Called when a virtual register is no longer used.
Definition: LiveRangeEdit.h:56
virtual void LRE_WillEraseInstruction(MachineInstr *MI)
Called immediately before erasing a dead machine instruction.
Definition: LiveRangeEdit.h:52
virtual void LRE_WillShrinkVirtReg(Register)
Called before shrinking the live range of a virtual register.
Definition: LiveRangeEdit.h:59
virtual void LRE_DidCloneVirtReg(Register New, Register Old)
Called after cloning a virtual register.
Definition: LiveRangeEdit.h:63
void eraseVirtReg(Register Reg)
eraseVirtReg - Notify the delegate that Reg is no longer in use, and try to erase it from LIS.
unsigned size() const
Register get(unsigned idx) const
void eliminateDeadDefs(SmallVectorImpl< MachineInstr * > &Dead, ArrayRef< Register > RegsBeingSpilled=std::nullopt)
eliminateDeadDefs - Try to delete machine instructions that are now dead (allDefsAreDead returns true...
Register createFrom(Register OldReg)
createFrom - Create a new virtual register based on OldReg.
void calculateRegClassAndHint(MachineFunction &, VirtRegAuxInfo &)
calculateRegClassAndHint - Recompute register class and hint for each new register.
const LiveInterval & getParent() const
Register getReg() const
SlotIndex rematerializeAt(MachineBasicBlock &MBB, MachineBasicBlock::iterator MI, Register DestReg, const Remat &RM, const TargetRegisterInfo &, bool Late=false, unsigned SubIdx=0, MachineInstr *ReplaceIndexMI=nullptr)
rematerializeAt - Rematerialize RM.ParentVNI into DestReg by inserting an instruction into MBB before...
bool allUsesAvailableAt(const MachineInstr *OrigMI, SlotIndex OrigIdx, SlotIndex UseIdx) const
allUsesAvailableAt - Return true if all registers used by OrigMI at OrigIdx are also available with t...
void pop_back()
pop_back - It allows LiveRangeEdit users to drop new registers.
bool checkRematerializable(VNInfo *VNI, const MachineInstr *DefMI)
checkRematerializable - Manually add VNI to the list of rematerializable values if DefMI may be remat...
bool canRematerializeAt(Remat &RM, VNInfo *OrigVNI, SlotIndex UseIdx, bool cheapAsAMove)
canRematerializeAt - Determine if ParentVNI can be rematerialized at UseIdx.
bool anyRematerializable()
anyRematerializable - Return true if any parent values may be rematerializable.
iterator addSegment(Segment S)
Add the specified Segment to this range, merging segments as appropriate.
bool empty() const
Definition: LiveInterval.h:382
void RenumberValues()
RenumberValues - Renumber all values in order of appearance and remove unused values.
LiveQueryResult Query(SlotIndex Idx) const
Query Liveness at Idx.
Definition: LiveInterval.h:541
VNInfo * getNextValue(SlotIndex def, VNInfo::Allocator &VNInfoAllocator)
getNextValue - Create a new value number and return it.
Definition: LiveInterval.h:331
VNInfo * getVNInfoAt(SlotIndex Idx) const
getVNInfoAt - Return the VNInfo that is live at Idx, or NULL.
Definition: LiveInterval.h:421
const MCInstrDesc & get(unsigned Opcode) const
Return the machine instruction descriptor that corresponds to the specified instruction opcode.
Definition: MCInstrInfo.h:63
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
void moveCallSiteInfo(const MachineInstr *Old, const MachineInstr *New)
Move the call site info from Old to \New call site info.
Representation of each machine instruction.
Definition: MachineInstr.h:68
bool isSafeToMove(AAResults *AA, bool &SawStore) const
Return true if it is safe to move this instruction.
std::pair< bool, bool > readsWritesVirtualRegister(Register Reg, SmallVectorImpl< unsigned > *Ops=nullptr) const
Return a pair of bools (reads, writes) indicating if this instruction reads or writes Reg.
bool shouldUpdateCallSiteInfo() const
Return true if copying, moving, or erasing this instruction requires updating Call Site Info (see cop...
iterator_range< mop_iterator > operands()
Definition: MachineInstr.h:641
const MachineFunction * getMF() const
Return the function that contains the basic block that this instruction belongs to.
void eraseFromParent()
Unlink 'this' from the containing basic block and delete it.
bool addRegisterDead(Register Reg, const TargetRegisterInfo *RegInfo, bool AddIfNotFound=false)
We have determined MI defined a register without a use.
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.
Register getReg() const
getReg - Returns the register number.
bool hasOneNonDBGUse(Register RegNo) const
hasOneNonDBGUse - Return true if there is exactly one non-Debug use of the specified register.
bool recomputeRegClass(Register Reg)
recomputeRegClass - Try to find a legal super-class of Reg's register class that still satisfies the ...
const TargetRegisterClass * getRegClass(Register Reg) const
Return the register class of the specified virtual register.
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.
const TargetRegisterInfo * getTargetRegisterInfo() 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 isConstantPhysReg(MCRegister PhysReg) const
Returns true if PhysReg is unallocatable and constant throughout the function.
iterator_range< reg_nodbg_iterator > reg_nodbg_operands(Register Reg) const
Register cloneVirtualRegister(Register VReg, StringRef Name="")
Create and return a new virtual register in the function with the same attributes as the given regist...
Wrapper class representing virtual and physical registers.
Definition: Register.h:19
bool isPhysical() const
Return true if the specified register number is in the physical register namespace.
Definition: Register.h:97
A vector that has set insertion semantics.
Definition: SetVector.h:40
bool empty() const
Determine if the SetVector is empty or not.
Definition: SetVector.h:72
SlotIndex - An opaque wrapper around machine indexes.
Definition: SlotIndexes.h:82
static bool isSameInstr(SlotIndex A, SlotIndex B)
isSameInstr - Return true if A and B refer to the same instruction.
Definition: SlotIndexes.h:198
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:259
SlotIndex insertMachineInstrInMaps(MachineInstr &MI, bool Late=false)
Insert the given machine instruction into the mapping.
Definition: SlotIndexes.h:540
bool empty() const
Definition: SmallVector.h:94
size_t size() const
Definition: SmallVector.h:91
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition: SmallVector.h:577
void push_back(const T &Elt)
Definition: SmallVector.h:416
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1200
bool isTriviallyReMaterializable(const MachineInstr &MI) const
Return true if the instruction is trivially rematerializable, meaning it has no side effects and requ...
virtual bool isIgnorableUse(const MachineOperand &MO) const
Given MO is a PhysReg use return if it can be ignored for the purpose of instruction rematerializatio...
MachineInstr * foldMemoryOperand(MachineInstr &MI, ArrayRef< unsigned > Ops, int FI, LiveIntervals *LIS=nullptr, VirtRegMap *VRM=nullptr) const
Attempt to fold a load or store of the specified stack slot into the specified machine instruction fo...
virtual bool isAsCheapAsAMove(const MachineInstr &MI) const
Return true if the instruction is as cheap as a move instruction.
virtual void reMaterialize(MachineBasicBlock &MBB, MachineBasicBlock::iterator MI, Register DestReg, unsigned SubIdx, const MachineInstr &Orig, const TargetRegisterInfo &TRI) const
Re-issue the specified 'original' instruction at the specific location targeting a new destination re...
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
VNInfo - Value Number Information.
Definition: LiveInterval.h:53
SlotIndex def
The index of the defining instruction.
Definition: LiveInterval.h:61
Calculate auxiliary information for a virtual register such as its spill weight and allocation hint.
void calculateSpillWeightAndHint(LiveInterval &LI)
(re)compute li's spill weight and allocation hint.
void setIsSplitFromReg(Register virtReg, Register SReg)
records virtReg is a split live interval from SReg.
Definition: VirtRegMap.h:153
Register getOriginal(Register VirtReg) const
getOriginal - Return the original virtual register that VirtReg descends from through splitting.
Definition: VirtRegMap.h:169
@ Dead
Unused definition.
Reg
All possible values of the reg field in the ModR/M byte.
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition: Debug.cpp:163
bool is_contained(R &&Range, const E &Element)
Returns true if Element is found in Range.
Definition: STLExtras.h:1939
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.
constexpr bool none() const
Definition: LaneBitmask.h:52
Remat - Information needed to rematerialize at a specific location.
This represents a simple continuous liveness interval for a value.
Definition: LiveInterval.h:162