LLVM 22.0.0git
MachineRegisterInfo.cpp
Go to the documentation of this file.
1//===- lib/Codegen/MachineRegisterInfo.cpp --------------------------------===//
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// Implementation of the MachineRegisterInfo class.
10//
11//===----------------------------------------------------------------------===//
12
23#include "llvm/Config/llvm-config.h"
24#include "llvm/IR/Attributes.h"
25#include "llvm/IR/DebugLoc.h"
26#include "llvm/IR/Function.h"
33#include <cassert>
34
35using namespace llvm;
36
37static cl::opt<bool> EnableSubRegLiveness("enable-subreg-liveness", cl::Hidden,
38 cl::init(true), cl::desc("Enable subregister liveness tracking."));
39
40// Pin the vtable to this file.
41void MachineRegisterInfo::Delegate::anchor() {}
42
44 : MF(MF),
45 TracksSubRegLiveness(EnableSubRegLiveness.getNumOccurrences()
47 : MF->getSubtarget().enableSubRegLiveness()) {
48 unsigned NumRegs = getTargetRegisterInfo()->getNumRegs();
49 VRegInfo.reserve(256);
50 UsedPhysRegMask.resize(NumRegs);
51 PhysRegUseDefLists.reset(new MachineOperand*[NumRegs]());
52 TheDelegates.clear();
53}
54
55/// setRegClass - Set the register class of the specified virtual register.
56///
57void
59 assert(RC && RC->isAllocatable() && "Invalid RC for virtual register");
60 VRegInfo[Reg].first = RC;
61}
62
64 const RegisterBank &RegBank) {
65 VRegInfo[Reg].first = &RegBank;
66}
67
68static const TargetRegisterClass *
70 const TargetRegisterClass *OldRC,
71 const TargetRegisterClass *RC, unsigned MinNumRegs) {
72 if (OldRC == RC)
73 return RC;
74 const TargetRegisterClass *NewRC =
75 MRI.getTargetRegisterInfo()->getCommonSubClass(OldRC, RC);
76 if (!NewRC || NewRC == OldRC)
77 return NewRC;
78 if (NewRC->getNumRegs() < MinNumRegs)
79 return nullptr;
80 MRI.setRegClass(Reg, NewRC);
81 return NewRC;
82}
83
85 Register Reg, const TargetRegisterClass *RC, unsigned MinNumRegs) {
86 return ::constrainRegClass(*this, Reg, getRegClass(Reg), RC, MinNumRegs);
87}
88
89bool
91 Register ConstrainingReg,
92 unsigned MinNumRegs) {
93 const LLT RegTy = getType(Reg);
94 const LLT ConstrainingRegTy = getType(ConstrainingReg);
95 if (RegTy.isValid() && ConstrainingRegTy.isValid() &&
96 RegTy != ConstrainingRegTy)
97 return false;
98 const auto &ConstrainingRegCB = getRegClassOrRegBank(ConstrainingReg);
99 if (!ConstrainingRegCB.isNull()) {
100 const auto &RegCB = getRegClassOrRegBank(Reg);
101 if (RegCB.isNull())
102 setRegClassOrRegBank(Reg, ConstrainingRegCB);
103 else if (isa<const TargetRegisterClass *>(RegCB) !=
104 isa<const TargetRegisterClass *>(ConstrainingRegCB))
105 return false;
106 else if (isa<const TargetRegisterClass *>(RegCB)) {
108 *this, Reg, cast<const TargetRegisterClass *>(RegCB),
109 cast<const TargetRegisterClass *>(ConstrainingRegCB), MinNumRegs))
110 return false;
111 } else if (RegCB != ConstrainingRegCB)
112 return false;
113 }
114 if (ConstrainingRegTy.isValid())
115 setType(Reg, ConstrainingRegTy);
116 return true;
117}
118
119bool
121 const TargetInstrInfo *TII = MF->getSubtarget().getInstrInfo();
122 const TargetRegisterClass *OldRC = getRegClass(Reg);
124 const TargetRegisterClass *NewRC = TRI->getLargestLegalSuperClass(OldRC, *MF);
125
126 // Stop early if there is no room to grow.
127 if (NewRC == OldRC)
128 return false;
129
130 // Accumulate constraints from all uses.
131 for (MachineOperand &MO : reg_nodbg_operands(Reg)) {
132 // Apply the effect of the given operand to NewRC.
133 MachineInstr *MI = MO.getParent();
134 unsigned OpNo = &MO - &MI->getOperand(0);
135 NewRC = MI->getRegClassConstraintEffect(OpNo, NewRC, TII, TRI);
136 if (!NewRC || NewRC == OldRC)
137 return false;
138 }
139 setRegClass(Reg, NewRC);
140 return true;
141}
142
145 VRegInfo.grow(Reg);
146 insertVRegByName(Name, Reg);
147 return Reg;
148}
149
150/// createVirtualRegister - Create and return a new virtual register in the
151/// function with the specified register class.
152///
155 StringRef Name) {
156 assert(RegClass && "Cannot create register without RegClass!");
157 assert(RegClass->isAllocatable() &&
158 "Virtual register RegClass must be allocatable.");
159
160 // New virtual register number.
162 VRegInfo[Reg].first = RegClass;
164 return Reg;
165}
166
168 StringRef Name) {
170 VRegInfo[Reg].first = RegAttr.RCOrRB;
171 setType(Reg, RegAttr.Ty);
173 return Reg;
174}
175
177 StringRef Name) {
179 VRegInfo[Reg].first = VRegInfo[VReg].first;
180 setType(Reg, getType(VReg));
181 noteCloneVirtualRegister(Reg, VReg);
182 return Reg;
183}
184
186 VRegToType.grow(VReg);
187 VRegToType[VReg] = Ty;
188}
189
192 // New virtual register number.
194 // FIXME: Should we use a dummy register class?
195 VRegInfo[Reg].first = static_cast<RegisterBank *>(nullptr);
196 setType(Reg, Ty);
198 return Reg;
199}
200
201void MachineRegisterInfo::clearVirtRegTypes() { VRegToType.clear(); }
202
203/// clearVirtRegs - Remove all virtual registers (after physreg assignment).
205#ifndef NDEBUG
206 for (unsigned i = 0, e = getNumVirtRegs(); i != e; ++i) {
208 if (!VRegInfo[Reg].second)
209 continue;
210 verifyUseList(Reg);
211 errs() << "Remaining virtual register "
212 << printReg(Reg, getTargetRegisterInfo()) << "...\n";
213 for (MachineInstr &MI : reg_instructions(Reg))
214 errs() << "...in instruction: " << MI << "\n";
215 std::abort();
216 }
217#endif
218 VRegInfo.clear();
219 for (auto &I : LiveIns)
220 I.second = 0;
221}
222
224#ifndef NDEBUG
225 bool Valid = true;
226 for (MachineOperand &M : reg_operands(Reg)) {
227 MachineOperand *MO = &M;
228 MachineInstr *MI = MO->getParent();
229 if (!MI) {
231 << " use list MachineOperand " << MO
232 << " has no parent instruction.\n";
233 Valid = false;
234 continue;
235 }
236 MachineOperand *MO0 = &MI->getOperand(0);
237 unsigned NumOps = MI->getNumOperands();
238 if (!(MO >= MO0 && MO < MO0+NumOps)) {
240 << " use list MachineOperand " << MO
241 << " doesn't belong to parent MI: " << *MI;
242 Valid = false;
243 }
244 if (!MO->isReg()) {
246 << " MachineOperand " << MO << ": " << *MO
247 << " is not a register\n";
248 Valid = false;
249 }
250 if (MO->getReg() != Reg) {
252 << " use-list MachineOperand " << MO << ": "
253 << *MO << " is the wrong register\n";
254 Valid = false;
255 }
256 }
257 assert(Valid && "Invalid use list");
258#endif
259}
260
262#ifndef NDEBUG
263 for (unsigned i = 0, e = getNumVirtRegs(); i != e; ++i)
265 for (unsigned i = 1, e = getTargetRegisterInfo()->getNumRegs(); i != e; ++i)
266 verifyUseList(i);
267#endif
268}
269
270/// Add MO to the linked list of operands for its register.
272 assert(!MO->isOnRegUseList() && "Already on list");
273 MachineOperand *&HeadRef = getRegUseDefListHead(MO->getReg());
274 MachineOperand *const Head = HeadRef;
275
276 // Head points to the first list element.
277 // Next is NULL on the last list element.
278 // Prev pointers are circular, so Head->Prev == Last.
279
280 // Head is NULL for an empty list.
281 if (!Head) {
282 MO->Contents.Reg.Prev = MO;
283 MO->Contents.Reg.Next = nullptr;
284 HeadRef = MO;
285 return;
286 }
287 assert(MO->getReg() == Head->getReg() && "Different regs on the same list!");
288
289 // Insert MO between Last and Head in the circular Prev chain.
290 MachineOperand *Last = Head->Contents.Reg.Prev;
291 assert(Last && "Inconsistent use list");
292 assert(MO->getReg() == Last->getReg() && "Different regs on the same list!");
293 Head->Contents.Reg.Prev = MO;
294 MO->Contents.Reg.Prev = Last;
295
296 // Def operands always precede uses. This allows def_iterator to stop early.
297 // Insert def operands at the front, and use operands at the back.
298 if (MO->isDef()) {
299 // Insert def at the front.
300 MO->Contents.Reg.Next = Head;
301 HeadRef = MO;
302 } else {
303 // Insert use at the end.
304 MO->Contents.Reg.Next = nullptr;
305 Last->Contents.Reg.Next = MO;
306 }
307}
308
309/// Remove MO from its use-def list.
311 assert(MO->isOnRegUseList() && "Operand not on use list");
312 MachineOperand *&HeadRef = getRegUseDefListHead(MO->getReg());
313 MachineOperand *const Head = HeadRef;
314 assert(Head && "List already empty");
315
316 // Unlink this from the doubly linked list of operands.
317 MachineOperand *Next = MO->Contents.Reg.Next;
318 MachineOperand *Prev = MO->Contents.Reg.Prev;
319
320 // Prev links are circular, next link is NULL instead of looping back to Head.
321 if (MO == Head)
322 HeadRef = Next;
323 else
324 Prev->Contents.Reg.Next = Next;
325
326 (Next ? Next : Head)->Contents.Reg.Prev = Prev;
327
328 MO->Contents.Reg.Prev = nullptr;
329 MO->Contents.Reg.Next = nullptr;
330}
331
332/// Move NumOps operands from Src to Dst, updating use-def lists as needed.
333///
334/// The Dst range is assumed to be uninitialized memory. (Or it may contain
335/// operands that won't be destroyed, which is OK because the MO destructor is
336/// trivial anyway).
337///
338/// The Src and Dst ranges may overlap.
340 MachineOperand *Src,
341 unsigned NumOps) {
342 assert(Src != Dst && NumOps && "Noop moveOperands");
343
344 // Copy backwards if Dst is within the Src range.
345 int Stride = 1;
346 if (Dst >= Src && Dst < Src + NumOps) {
347 Stride = -1;
348 Dst += NumOps - 1;
349 Src += NumOps - 1;
350 }
351
352 // Copy one operand at a time.
353 do {
354 new (Dst) MachineOperand(*Src);
355
356 // Dst takes Src's place in the use-def chain.
357 if (Src->isReg()) {
358 MachineOperand *&Head = getRegUseDefListHead(Src->getReg());
359 MachineOperand *Prev = Src->Contents.Reg.Prev;
360 MachineOperand *Next = Src->Contents.Reg.Next;
361 assert(Head && "List empty, but operand is chained");
362 assert(Prev && "Operand was not on use-def list");
363
364 // Prev links are circular, next link is NULL instead of looping back to
365 // Head.
366 if (Src == Head)
367 Head = Dst;
368 else
369 Prev->Contents.Reg.Next = Dst;
370
371 // Update Prev pointer. This also works when Src was pointing to itself
372 // in a 1-element list. In that case Head == Dst.
373 (Next ? Next : Head)->Contents.Reg.Prev = Dst;
374 }
375
376 Dst += Stride;
377 Src += Stride;
378 } while (--NumOps);
379}
380
381/// replaceRegWith - Replace all instances of FromReg with ToReg in the
382/// machine function. This is like llvm-level X->replaceAllUsesWith(Y),
383/// except that it also changes any definitions of the register as well.
384/// If ToReg is a physical register we apply the sub register to obtain the
385/// final/proper physical register.
387 assert(FromReg != ToReg && "Cannot replace a reg with itself");
388
390
391 // TODO: This could be more efficient by bulk changing the operands.
393 if (ToReg.isPhysical()) {
394 O.substPhysReg(ToReg, *TRI);
395 } else {
396 O.setReg(ToReg);
397 }
398 }
399}
400
401/// getVRegDef - Return the machine instr that defines the specified virtual
402/// register or null if none is found. This assumes that the code is in SSA
403/// form, so there should only be one definition.
405 // Since we are in SSA form, we can use the first definition.
407 if (I == def_instr_end())
408 return nullptr;
409 assert(std::next(I) == def_instr_end() &&
410 "getVRegDef assumes at most one definition");
411 return &*I;
412}
413
414/// getUniqueVRegDef - Return the unique machine instr that defines the
415/// specified virtual register or null if none is found. If there are
416/// multiple definitions or no definition, return null.
418 if (def_empty(Reg)) return nullptr;
420 if (std::next(I) != def_instr_end())
421 return nullptr;
422 return &*I;
423}
424
428
432
434 auto RegNoDbgUses = use_nodbg_operands(RegNo);
435 return hasSingleElement(RegNoDbgUses) ? &*RegNoDbgUses.begin() : nullptr;
436}
437
439 auto RegNoDbgUsers = use_nodbg_instructions(RegNo);
440 return hasSingleElement(RegNoDbgUsers) ? &*RegNoDbgUsers.begin() : nullptr;
441}
442
444 unsigned MaxUsers) const {
446 MaxUsers);
447}
448
449/// clearKillFlags - Iterate over all the uses of the given register and
450/// clear the kill flag from the MachineOperand. This function is used by
451/// optimization passes which extend register lifetimes and need only
452/// preserve conservative kill flag information.
454 for (MachineOperand &MO : use_operands(Reg))
455 MO.setIsKill(false);
456}
457
459 for (const std::pair<MCRegister, Register> &LI : liveins())
460 if ((Register)LI.first == Reg || LI.second == Reg)
461 return true;
462 return false;
463}
464
465/// getLiveInPhysReg - If VReg is a live-in virtual register, return the
466/// corresponding live-in physical register.
468 for (const std::pair<MCRegister, Register> &LI : liveins())
469 if (LI.second == VReg)
470 return LI.first;
471 return MCRegister();
472}
473
474/// getLiveInVirtReg - If PReg is a live-in physical register, return the
475/// corresponding live-in physical register.
477 for (const std::pair<MCRegister, Register> &LI : liveins())
478 if (LI.first == PReg)
479 return LI.second;
480 return Register();
481}
482
483/// EmitLiveInCopies - Emit copies to initialize livein virtual registers
484/// into the given entry block.
485void
487 const TargetRegisterInfo &TRI,
488 const TargetInstrInfo &TII) {
489 // Emit the copies into the top of the block.
490 for (unsigned i = 0, e = LiveIns.size(); i != e; ++i)
491 if (LiveIns[i].second) {
492 if (use_nodbg_empty(LiveIns[i].second)) {
493 // The livein has no non-dbg uses. Drop it.
494 //
495 // It would be preferable to have isel avoid creating live-in
496 // records for unused arguments in the first place, but it's
497 // complicated by the debug info code for arguments.
498 LiveIns.erase(LiveIns.begin() + i);
499 --i; --e;
500 } else {
501 // Emit a copy.
502 BuildMI(*EntryMBB, EntryMBB->begin(), DebugLoc(),
503 TII.get(TargetOpcode::COPY), LiveIns[i].second)
504 .addReg(LiveIns[i].first);
505
506 // Add the register to the entry block live-in set.
507 EntryMBB->addLiveIn(LiveIns[i].first);
508 }
509 } else {
510 // Add the register to the entry block live-in set.
511 EntryMBB->addLiveIn(LiveIns[i].first);
512 }
513}
514
516 // Lane masks are only defined for vregs.
517 assert(Reg.isVirtual());
518 const TargetRegisterClass &TRC = *getRegClass(Reg);
519 return TRC.getLaneMask();
520}
521
522#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
524 for (MachineInstr &I : use_instructions(Reg))
525 I.dump();
526}
527#endif
528
530 ReservedRegs = getTargetRegisterInfo()->getReservedRegs(*MF);
531 assert(ReservedRegs.size() == getTargetRegisterInfo()->getNumRegs() &&
532 "Invalid ReservedRegs vector from target");
533}
534
536 assert(PhysReg.isPhysical());
537
539 if (TRI->isConstantPhysReg(PhysReg))
540 return true;
541
542 // Check if any overlapping register is modified, or allocatable so it may be
543 // used later.
544 for (MCRegAliasIterator AI(PhysReg, TRI, true);
545 AI.isValid(); ++AI)
546 if (!def_empty(*AI) || isAllocatable(*AI))
547 return false;
548 return true;
549}
550
551/// markUsesInDebugValueAsUndef - Mark every DBG_VALUE referencing the
552/// specified register as undefined which causes the DBG_VALUE to be
553/// deleted during LiveDebugVariables analysis.
555 // Mark any DBG_VALUE* that uses Reg as undef (but don't delete it.)
556 // We use make_early_inc_range because setReg invalidates the iterator.
558 if (UseMI.isDebugValue() && UseMI.hasDebugOperandForReg(Reg))
559 UseMI.setDebugValueUndef();
560 }
561}
562
564 for (const MachineOperand &MO : MI.operands()) {
565 if (!MO.isGlobal())
566 continue;
567 const Function *Func = dyn_cast<Function>(MO.getGlobal());
568 if (Func != nullptr)
569 return Func;
570 }
571 return nullptr;
572}
573
574static bool isNoReturnDef(const MachineOperand &MO) {
575 // Anything which is not a noreturn function is a real def.
576 const MachineInstr &MI = *MO.getParent();
577 if (!MI.isCall())
578 return false;
579 const MachineBasicBlock &MBB = *MI.getParent();
580 if (!MBB.succ_empty())
581 return false;
582 const MachineFunction &MF = *MBB.getParent();
583 // We need to keep correct unwind information even if the function will
584 // not return, since the runtime may need it.
585 if (MF.getFunction().hasFnAttribute(Attribute::UWTable))
586 return false;
587 const Function *Called = getCalledFunction(MI);
588 return !(Called == nullptr || !Called->hasFnAttribute(Attribute::NoReturn) ||
589 !Called->hasFnAttribute(Attribute::NoUnwind));
590}
591
593 bool SkipNoReturnDef) const {
594 if (UsedPhysRegMask.test(PhysReg.id()))
595 return true;
597 for (MCRegAliasIterator AI(PhysReg, TRI, true); AI.isValid(); ++AI) {
598 for (const MachineOperand &MO : make_range(def_begin(*AI), def_end())) {
599 if (!SkipNoReturnDef && isNoReturnDef(MO))
600 continue;
601 return true;
602 }
603 }
604 return false;
605}
606
608 bool SkipRegMaskTest) const {
609 if (!SkipRegMaskTest && UsedPhysRegMask.test(PhysReg.id()))
610 return true;
612 for (MCRegAliasIterator AliasReg(PhysReg, TRI, true); AliasReg.isValid();
613 ++AliasReg) {
614 if (!reg_nodbg_empty(*AliasReg))
615 return true;
616 }
617 return false;
618}
619
621
623 assert(Reg && (Reg < TRI->getNumRegs()) &&
624 "Trying to disable an invalid register");
625
626 if (!IsUpdatedCSRsInitialized) {
627 const MCPhysReg *CSR = TRI->getCalleeSavedRegs(MF);
628 for (const MCPhysReg *I = CSR; *I; ++I)
629 UpdatedCSRs.push_back(*I);
630
631 // Zero value represents the end of the register list
632 // (no more registers should be pushed).
633 UpdatedCSRs.push_back(0);
634
635 IsUpdatedCSRsInitialized = true;
636 }
637
638 // Remove the register (and its aliases from the list).
639 for (MCRegAliasIterator AI(Reg, TRI, true); AI.isValid(); ++AI)
640 llvm::erase(UpdatedCSRs, *AI);
641}
642
644 if (IsUpdatedCSRsInitialized)
645 return UpdatedCSRs.data();
646
648
649 for (unsigned I = 0; Regs[I]; ++I)
650 if (MF->getSubtarget().isRegisterReservedByUser(Regs[I]))
651 MF->getRegInfo().disableCalleeSavedRegister(Regs[I]);
652
653 return Regs;
654}
655
657 if (IsUpdatedCSRsInitialized)
658 UpdatedCSRs.clear();
659
660 append_range(UpdatedCSRs, CSRs);
661
662 // Zero value represents the end of the register list
663 // (no more registers should be pushed).
664 UpdatedCSRs.push_back(0);
665 IsUpdatedCSRsInitialized = true;
666}
667
668bool MachineRegisterInfo::isReservedRegUnit(unsigned Unit) const {
670 for (MCRegUnitRootIterator Root(Unit, TRI); Root.isValid(); ++Root) {
671 if (all_of(TRI->superregs_inclusive(*Root),
672 [&](MCPhysReg Super) { return isReserved(Super); }))
673 return true;
674 }
675 return false;
676}
unsigned const MachineRegisterInfo * MRI
MachineInstrBuilder & UseMI
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
MachineBasicBlock & MBB
This file contains the simple types necessary to represent the attributes associated with functions a...
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds.
Definition Compiler.h:638
const HexagonInstrInfo * TII
IRTranslator LLVM IR MI
const size_t AbstractManglingParser< Derived, Alloc >::NumOps
#define I(x, y, z)
Definition MD5.cpp:58
static cl::opt< bool > EnableSubRegLiveness("enable-subreg-liveness", cl::Hidden, cl::init(true), cl::desc("Enable subregister liveness tracking."))
static bool isNoReturnDef(const MachineOperand &MO)
static const TargetRegisterClass * constrainRegClass(MachineRegisterInfo &MRI, Register Reg, const TargetRegisterClass *OldRC, const TargetRegisterClass *RC, unsigned MinNumRegs)
Register Reg
Register const TargetRegisterInfo * TRI
Promote Memory to Register
Definition Mem2Reg.cpp:110
static const Function * getCalledFunction(const Value *V)
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:41
A debug info location.
Definition DebugLoc.h:124
bool hasFnAttribute(Attribute::AttrKind Kind) const
Return true if the function has the attribute.
Definition Function.cpp:727
constexpr bool isValid() const
MCRegAliasIterator enumerates all registers aliasing Reg.
MCRegUnitRootIterator enumerates the root registers of a register unit.
bool isValid() const
Check if the iterator is at the end of the list.
unsigned getNumRegs() const
Return the number of registers this target has (useful for sizing arrays holding per register informa...
Wrapper class representing physical registers. Should be passed by value.
Definition MCRegister.h:33
constexpr bool isPhysical() const
Return true if the specified register number is in the physical register namespace.
Definition MCRegister.h:64
constexpr unsigned id() const
Definition MCRegister.h:74
void addLiveIn(MCRegister PhysReg, LaneBitmask LaneMask=LaneBitmask::getAll())
Adds the specified register as a live in.
Function & getFunction()
Return the LLVM function that this machine code represents.
const MachineInstrBuilder & addReg(Register RegNo, unsigned flags=0, unsigned SubReg=0) const
Add a new virtual register operand.
Representation of each machine instruction.
MachineOperand class - Representation of each machine instruction operand.
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.
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
LLVM_ABI void verifyUseList(Register Reg) const
Verify the sanity of the use list for Reg.
LLVM_ABI bool hasOneNonDBGUse(Register RegNo) const
hasOneNonDBGUse - Return true if there is exactly one non-Debug use of the specified register.
void insertVRegByName(StringRef Name, Register Reg)
LLVM_ABI void verifyUseLists() const
Verify the use list of all registers.
LLVM_ABI void markUsesInDebugValueAsUndef(Register Reg) const
markUsesInDebugValueAsUndef - Mark every DBG_VALUE referencing the specified register as undefined wh...
iterator_range< reg_iterator > reg_operands(Register Reg) const
LLVM_ABI bool recomputeRegClass(Register Reg)
recomputeRegClass - Try to find a legal super-class of Reg's register class that still satisfies the ...
LLVM_ABI void freezeReservedRegs()
freezeReservedRegs - Called by the register allocator to freeze the set of reserved registers before ...
const TargetRegisterClass * getRegClass(Register Reg) const
Return the register class of the specified virtual register.
LLVM_ABI void clearKillFlags(Register Reg) const
clearKillFlags - Iterate over all the uses of the given register and clear the kill flag from the Mac...
LLVM_ABI MachineRegisterInfo(MachineFunction *MF)
LLVM_ABI MachineInstr * getVRegDef(Register Reg) const
getVRegDef - Return the machine instr that defines the specified virtual register or null if none is ...
iterator_range< use_nodbg_iterator > use_nodbg_operands(Register Reg) const
LLVM_ABI void EmitLiveInCopies(MachineBasicBlock *EntryMBB, const TargetRegisterInfo &TRI, const TargetInstrInfo &TII)
EmitLiveInCopies - Emit copies to initialize livein virtual registers into the given entry block.
bool use_nodbg_empty(Register RegNo) const
use_nodbg_empty - Return true if there are no non-Debug instructions using the specified register.
const RegClassOrRegBank & getRegClassOrRegBank(Register Reg) const
Return the register bank or register class of Reg.
LLVM_ABI MachineOperand * getOneNonDBGUse(Register RegNo) const
If the register has a single non-Debug use, returns it; otherwise returns nullptr.
static def_instr_iterator def_instr_end()
LLVM_ABI void dumpUses(Register RegNo) const
LLVM_ABI void moveOperands(MachineOperand *Dst, MachineOperand *Src, unsigned NumOps)
Move NumOps operands from Src to Dst, updating use-def lists as needed.
def_iterator def_begin(Register RegNo) const
defusechain_instr_iterator< false, true, false, true > def_instr_iterator
def_instr_iterator/def_instr_begin/def_instr_end - Walk all defs of the specified register,...
void setRegClassOrRegBank(Register Reg, const RegClassOrRegBank &RCOrRB)
LLVM_ABI Register createVirtualRegister(const TargetRegisterClass *RegClass, StringRef Name="")
createVirtualRegister - Create and return a new virtual register in the function with the specified r...
def_instr_iterator def_instr_begin(Register RegNo) const
LLT getType(Register Reg) const
Get the low-level type of Reg or LLT{} if Reg is not a generic (target independent) virtual register.
bool def_empty(Register RegNo) const
def_empty - Return true if there are no instructions defining the specified register (it may be live-...
LLVM_ABI bool isLiveIn(Register Reg) const
bool reg_nodbg_empty(Register RegNo) const
reg_nodbg_empty - Return true if the only instructions using or defining Reg are Debug instructions.
use_instr_nodbg_iterator use_instr_nodbg_begin(Register RegNo) const
ArrayRef< std::pair< MCRegister, Register > > liveins() const
LLVM_ABI bool hasAtMostUserInstrs(Register Reg, unsigned MaxUsers) const
hasAtMostUses - Return true if the given register has at most MaxUsers non-debug user instructions.
LLVM_ABI bool hasOneNonDBGUser(Register RegNo) const
hasOneNonDBGUse - Return true if there is exactly one non-Debug instruction using the specified regis...
LLVM_ABI void clearVirtRegs()
clearVirtRegs - Remove all virtual registers (after physreg assignment).
LLVM_ABI Register createIncompleteVirtualRegister(StringRef Name="")
Creates a new virtual register that has no register class, register bank or size assigned yet.
bool isAllocatable(MCRegister PhysReg) const
isAllocatable - Returns true when PhysReg belongs to an allocatable register class and it hasn't been...
LLVM_ABI void setRegBank(Register Reg, const RegisterBank &RegBank)
Set the register bank to RegBank for Reg.
LLVM_ABI MCRegister getLiveInPhysReg(Register VReg) const
getLiveInPhysReg - If VReg is a live-in virtual register, return the corresponding live-in physical r...
LLVM_ABI const MCPhysReg * getCalleeSavedRegs() const
Returns list of callee saved registers.
iterator_range< use_instr_nodbg_iterator > use_nodbg_instructions(Register Reg) const
LLVM_ABI void setType(Register VReg, LLT Ty)
Set the low-level type of VReg to Ty.
LLVM_ABI void setRegClass(Register Reg, const TargetRegisterClass *RC)
setRegClass - Set the register class of the specified virtual register.
LLVM_ABI Register createGenericVirtualRegister(LLT Ty, StringRef Name="")
Create and return a new generic virtual register with low-level type Ty.
LLVM_ABI void clearVirtRegTypes()
Remove all types associated to virtual registers (after instruction selection and constraining of all...
LLVM_ABI Register getLiveInVirtReg(MCRegister PReg) const
getLiveInVirtReg - If PReg is a live-in physical register, return the corresponding live-in virtual r...
static def_iterator def_end()
LLVM_ABI void disableCalleeSavedRegister(MCRegister Reg)
Disables the register from the list of CSRs.
iterator_range< reg_instr_iterator > reg_instructions(Register Reg) const
void noteNewVirtualRegister(Register Reg)
LLVM_ABI void setCalleeSavedRegs(ArrayRef< MCPhysReg > CSRs)
Sets the updated Callee Saved Registers list.
iterator_range< use_instr_iterator > use_instructions(Register Reg) const
const TargetRegisterInfo * getTargetRegisterInfo() const
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...
LLVM_ABI 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
LLVM_ABI Register cloneVirtualRegister(Register VReg, StringRef Name="")
Create and return a new virtual register in the function with the same attributes as the given regist...
LLVM_ABI bool constrainRegAttrs(Register Reg, Register ConstrainingReg, unsigned MinNumRegs=0)
Constrain the register class or the register bank of the virtual register Reg (and low-level type) to...
LLVM_ABI const TargetRegisterClass * constrainRegClass(Register Reg, const TargetRegisterClass *RC, unsigned MinNumRegs=0)
constrainRegClass - Constrain the register class of the specified virtual register to be a common sub...
LLVM_ABI bool isReservedRegUnit(unsigned Unit) const
Returns true when the given register unit is considered reserved.
void noteCloneVirtualRegister(Register NewReg, Register SrcReg)
iterator_range< use_iterator > use_operands(Register Reg) const
unsigned getNumVirtRegs() const
getNumVirtRegs - Return the number of virtual registers created.
LLVM_ABI void removeRegOperandFromUseList(MachineOperand *MO)
Remove MO from its use-def list.
LLVM_ABI void replaceRegWith(Register FromReg, Register ToReg)
replaceRegWith - Replace all instances of FromReg with ToReg in the machine function.
LLVM_ABI bool isPhysRegModified(MCRegister PhysReg, bool SkipNoReturnDef=false) const
Return true if the specified register is modified in this function.
LLVM_ABI void addRegOperandToUseList(MachineOperand *MO)
Add MO to the linked list of operands for its register.
LLVM_ABI MachineInstr * getOneNonDBGUser(Register RegNo) const
If the register has a single non-Debug instruction using the specified register, returns it; otherwis...
LLVM_ABI MachineInstr * getUniqueVRegDef(Register Reg) const
getUniqueVRegDef - Return the unique machine instr that defines the specified virtual register or nul...
static use_instr_nodbg_iterator use_instr_nodbg_end()
LLVM_ABI bool isPhysRegUsed(MCRegister PhysReg, bool SkipRegMaskTest=false) const
Return true if the specified register is modified or read in this function.
This class implements the register bank concept.
Wrapper class representing virtual and physical registers.
Definition Register.h:19
static Register index2VirtReg(unsigned Index)
Convert a 0-based index to a virtual register number.
Definition Register.h:67
constexpr bool isPhysical() const
Return true if the specified register number is in the physical register namespace.
Definition Register.h:78
StringRef - Represent a constant reference to a string, i.e.
Definition StringRef.h:55
TargetInstrInfo - Interface to description of machine instruction set.
unsigned getNumRegs() const
Return the number of registers in this class.
bool isAllocatable() const
Return true if this register class may be used to create virtual registers.
LaneBitmask getLaneMask() const
Returns the combination of all lane masks of register in this class.
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
virtual BitVector getReservedRegs(const MachineFunction &MF) const =0
Returns a bitset indexed by physical register number indicating if a register is a special register t...
virtual const MCPhysReg * getCalleeSavedRegs(const MachineFunction *MF) const =0
Return a null-terminated list of all of the callee-saved registers on this target.
This provides a very simple, boring adaptor for a begin and end iterator into a range type.
initializer< Ty > init(const Ty &Val)
This is an optimization pass for GlobalISel generic memory operations.
bool all_of(R &&range, UnaryPredicate P)
Provide wrappers to std::all_of which take ranges instead of having to pass begin/end explicitly.
Definition STLExtras.h:1705
MachineInstrBuilder BuildMI(MachineFunction &MF, const MIMetadata &MIMD, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:644
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
void append_range(Container &C, Range &&R)
Wrapper function to append range R to container C.
Definition STLExtras.h:2116
bool hasNItemsOrLess(IterTy &&Begin, IterTy &&End, unsigned N, Pred &&ShouldBeCounted=[](const decltype(*std::declval< IterTy >()) &) { return true;})
Returns true if the sequence [Begin, End) has N or less items.
Definition STLExtras.h:2557
iterator_range< early_inc_iterator_impl< detail::IterOfRange< RangeT > > > make_early_inc_range(RangeT &&Range)
Make a range that does early increment to allow mutation of the underlying range without disrupting i...
Definition STLExtras.h:634
void erase(Container &C, ValueType V)
Wrapper function to remove a value from a container:
Definition STLExtras.h:2108
bool hasSingleElement(ContainerTy &&C)
Returns true if the given container only contains a single element.
Definition STLExtras.h:302
bool isa(const From &Val)
isa<X> - Return true if the parameter to the template is an instance of one of the template type argu...
Definition Casting.h:548
LLVM_ABI raw_fd_ostream & errs()
This returns a reference to a raw_ostream for standard error.
uint16_t MCPhysReg
An unsigned integer type large enough to represent all physical registers, but not necessarily virtua...
Definition MCRegister.h:21
FunctionAddr VTableAddr Next
Definition InstrProf.h:141
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:560
LLVM_ABI Printable printReg(Register Reg, const TargetRegisterInfo *TRI=nullptr, unsigned SubIdx=0, const MachineRegisterInfo *MRI=nullptr)
Prints virtual and physical registers with or without a TRI instance.
All attributes(register class or bank and low-level type) a virtual register can have.