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 if (Reg.isPhysical())
87 return nullptr;
88 return ::constrainRegClass(*this, Reg, getRegClass(Reg), RC, MinNumRegs);
89}
90
91bool
93 Register ConstrainingReg,
94 unsigned MinNumRegs) {
95 const LLT RegTy = getType(Reg);
96 const LLT ConstrainingRegTy = getType(ConstrainingReg);
97 if (RegTy.isValid() && ConstrainingRegTy.isValid() &&
98 RegTy != ConstrainingRegTy)
99 return false;
100 const auto &ConstrainingRegCB = getRegClassOrRegBank(ConstrainingReg);
101 if (!ConstrainingRegCB.isNull()) {
102 const auto &RegCB = getRegClassOrRegBank(Reg);
103 if (RegCB.isNull())
104 setRegClassOrRegBank(Reg, ConstrainingRegCB);
105 else if (isa<const TargetRegisterClass *>(RegCB) !=
106 isa<const TargetRegisterClass *>(ConstrainingRegCB))
107 return false;
108 else if (isa<const TargetRegisterClass *>(RegCB)) {
110 *this, Reg, cast<const TargetRegisterClass *>(RegCB),
111 cast<const TargetRegisterClass *>(ConstrainingRegCB), MinNumRegs))
112 return false;
113 } else if (RegCB != ConstrainingRegCB)
114 return false;
115 }
116 if (ConstrainingRegTy.isValid())
117 setType(Reg, ConstrainingRegTy);
118 return true;
119}
120
121bool
123 const TargetInstrInfo *TII = MF->getSubtarget().getInstrInfo();
124 const TargetRegisterClass *OldRC = getRegClass(Reg);
126 const TargetRegisterClass *NewRC = TRI->getLargestLegalSuperClass(OldRC, *MF);
127
128 // Stop early if there is no room to grow.
129 if (NewRC == OldRC)
130 return false;
131
132 // Accumulate constraints from all uses.
133 for (MachineOperand &MO : reg_nodbg_operands(Reg)) {
134 // Apply the effect of the given operand to NewRC.
135 MachineInstr *MI = MO.getParent();
136 unsigned OpNo = &MO - &MI->getOperand(0);
137 NewRC = MI->getRegClassConstraintEffect(OpNo, NewRC, TII, TRI);
138 if (!NewRC || NewRC == OldRC)
139 return false;
140 }
141 setRegClass(Reg, NewRC);
142 return true;
143}
144
147 VRegInfo.grow(Reg);
148 insertVRegByName(Name, Reg);
149 return Reg;
150}
151
152/// createVirtualRegister - Create and return a new virtual register in the
153/// function with the specified register class.
154///
157 StringRef Name) {
158 assert(RegClass && "Cannot create register without RegClass!");
159 assert(RegClass->isAllocatable() &&
160 "Virtual register RegClass must be allocatable.");
161
162 // New virtual register number.
164 VRegInfo[Reg].first = RegClass;
166 return Reg;
167}
168
170 StringRef Name) {
172 VRegInfo[Reg].first = RegAttr.RCOrRB;
173 setType(Reg, RegAttr.Ty);
175 return Reg;
176}
177
179 StringRef Name) {
181 VRegInfo[Reg].first = VRegInfo[VReg].first;
182 setType(Reg, getType(VReg));
183 noteCloneVirtualRegister(Reg, VReg);
184 return Reg;
185}
186
188 VRegToType.grow(VReg);
189 VRegToType[VReg] = Ty;
190}
191
194 // New virtual register number.
196 // FIXME: Should we use a dummy register class?
197 VRegInfo[Reg].first = static_cast<RegisterBank *>(nullptr);
198 setType(Reg, Ty);
200 return Reg;
201}
202
203void MachineRegisterInfo::clearVirtRegTypes() { VRegToType.clear(); }
204
205/// clearVirtRegs - Remove all virtual registers (after physreg assignment).
207#ifndef NDEBUG
208 for (unsigned i = 0, e = getNumVirtRegs(); i != e; ++i) {
210 if (!VRegInfo[Reg].second)
211 continue;
212 verifyUseList(Reg);
213 errs() << "Remaining virtual register "
214 << printReg(Reg, getTargetRegisterInfo()) << "...\n";
215 for (MachineInstr &MI : reg_instructions(Reg))
216 errs() << "...in instruction: " << MI << "\n";
217 std::abort();
218 }
219#endif
220 VRegInfo.clear();
221 for (auto &I : LiveIns)
222 I.second = 0;
223}
224
226#ifndef NDEBUG
227 bool Valid = true;
228 for (MachineOperand &M : reg_operands(Reg)) {
229 MachineOperand *MO = &M;
230 MachineInstr *MI = MO->getParent();
231 if (!MI) {
233 << " use list MachineOperand " << MO
234 << " has no parent instruction.\n";
235 Valid = false;
236 continue;
237 }
238 MachineOperand *MO0 = &MI->getOperand(0);
239 unsigned NumOps = MI->getNumOperands();
240 if (!(MO >= MO0 && MO < MO0+NumOps)) {
242 << " use list MachineOperand " << MO
243 << " doesn't belong to parent MI: " << *MI;
244 Valid = false;
245 }
246 if (!MO->isReg()) {
248 << " MachineOperand " << MO << ": " << *MO
249 << " is not a register\n";
250 Valid = false;
251 }
252 if (MO->getReg() != Reg) {
254 << " use-list MachineOperand " << MO << ": "
255 << *MO << " is the wrong register\n";
256 Valid = false;
257 }
258 }
259 assert(Valid && "Invalid use list");
260#endif
261}
262
264#ifndef NDEBUG
265 for (unsigned i = 0, e = getNumVirtRegs(); i != e; ++i)
267 for (unsigned i = 1, e = getTargetRegisterInfo()->getNumRegs(); i != e; ++i)
268 verifyUseList(i);
269#endif
270}
271
272/// Add MO to the linked list of operands for its register.
274 assert(!MO->isOnRegUseList() && "Already on list");
275 MachineOperand *&HeadRef = getRegUseDefListHead(MO->getReg());
276 MachineOperand *const Head = HeadRef;
277
278 // Head points to the first list element.
279 // Next is NULL on the last list element.
280 // Prev pointers are circular, so Head->Prev == Last.
281
282 // Head is NULL for an empty list.
283 if (!Head) {
284 MO->Contents.Reg.Prev = MO;
285 MO->Contents.Reg.Next = nullptr;
286 HeadRef = MO;
287 return;
288 }
289 assert(MO->getReg() == Head->getReg() && "Different regs on the same list!");
290
291 // Insert MO between Last and Head in the circular Prev chain.
292 MachineOperand *Last = Head->Contents.Reg.Prev;
293 assert(Last && "Inconsistent use list");
294 assert(MO->getReg() == Last->getReg() && "Different regs on the same list!");
295 Head->Contents.Reg.Prev = MO;
296 MO->Contents.Reg.Prev = Last;
297
298 // Def operands always precede uses. This allows def_iterator to stop early.
299 // Insert def operands at the front, and use operands at the back.
300 if (MO->isDef()) {
301 // Insert def at the front.
302 MO->Contents.Reg.Next = Head;
303 HeadRef = MO;
304 } else {
305 // Insert use at the end.
306 MO->Contents.Reg.Next = nullptr;
307 Last->Contents.Reg.Next = MO;
308 }
309}
310
311/// Remove MO from its use-def list.
313 assert(MO->isOnRegUseList() && "Operand not on use list");
314 MachineOperand *&HeadRef = getRegUseDefListHead(MO->getReg());
315 MachineOperand *const Head = HeadRef;
316 assert(Head && "List already empty");
317
318 // Unlink this from the doubly linked list of operands.
319 MachineOperand *Next = MO->Contents.Reg.Next;
320 MachineOperand *Prev = MO->Contents.Reg.Prev;
321
322 // Prev links are circular, next link is NULL instead of looping back to Head.
323 if (MO == Head)
324 HeadRef = Next;
325 else
326 Prev->Contents.Reg.Next = Next;
327
328 (Next ? Next : Head)->Contents.Reg.Prev = Prev;
329
330 MO->Contents.Reg.Prev = nullptr;
331 MO->Contents.Reg.Next = nullptr;
332}
333
334/// Move NumOps operands from Src to Dst, updating use-def lists as needed.
335///
336/// The Dst range is assumed to be uninitialized memory. (Or it may contain
337/// operands that won't be destroyed, which is OK because the MO destructor is
338/// trivial anyway).
339///
340/// The Src and Dst ranges may overlap.
342 MachineOperand *Src,
343 unsigned NumOps) {
344 assert(Src != Dst && NumOps && "Noop moveOperands");
345
346 // Copy backwards if Dst is within the Src range.
347 int Stride = 1;
348 if (Dst >= Src && Dst < Src + NumOps) {
349 Stride = -1;
350 Dst += NumOps - 1;
351 Src += NumOps - 1;
352 }
353
354 // Copy one operand at a time.
355 do {
356 new (Dst) MachineOperand(*Src);
357
358 // Dst takes Src's place in the use-def chain.
359 if (Src->isReg()) {
360 MachineOperand *&Head = getRegUseDefListHead(Src->getReg());
361 MachineOperand *Prev = Src->Contents.Reg.Prev;
362 MachineOperand *Next = Src->Contents.Reg.Next;
363 assert(Head && "List empty, but operand is chained");
364 assert(Prev && "Operand was not on use-def list");
365
366 // Prev links are circular, next link is NULL instead of looping back to
367 // Head.
368 if (Src == Head)
369 Head = Dst;
370 else
371 Prev->Contents.Reg.Next = Dst;
372
373 // Update Prev pointer. This also works when Src was pointing to itself
374 // in a 1-element list. In that case Head == Dst.
375 (Next ? Next : Head)->Contents.Reg.Prev = Dst;
376 }
377
378 Dst += Stride;
379 Src += Stride;
380 } while (--NumOps);
381}
382
383/// replaceRegWith - Replace all instances of FromReg with ToReg in the
384/// machine function. This is like llvm-level X->replaceAllUsesWith(Y),
385/// except that it also changes any definitions of the register as well.
386/// If ToReg is a physical register we apply the sub register to obtain the
387/// final/proper physical register.
389 assert(FromReg != ToReg && "Cannot replace a reg with itself");
390
392
393 // TODO: This could be more efficient by bulk changing the operands.
395 if (ToReg.isPhysical()) {
396 O.substPhysReg(ToReg, *TRI);
397 } else {
398 O.setReg(ToReg);
399 }
400 }
401}
402
403/// getVRegDef - Return the machine instr that defines the specified virtual
404/// register or null if none is found. This assumes that the code is in SSA
405/// form, so there should only be one definition.
407 // Since we are in SSA form, we can use the first definition.
409 if (I == def_instr_end())
410 return nullptr;
411 assert(std::next(I) == def_instr_end() &&
412 "getVRegDef assumes at most one definition");
413 return &*I;
414}
415
416/// getUniqueVRegDef - Return the unique machine instr that defines the
417/// specified virtual register or null if none is found. If there are
418/// multiple definitions or no definition, return null.
420 if (def_empty(Reg)) return nullptr;
422 if (std::next(I) != def_instr_end())
423 return nullptr;
424 return &*I;
425}
426
430
434
436 auto RegNoDbgUses = use_nodbg_operands(RegNo);
437 return hasSingleElement(RegNoDbgUses) ? &*RegNoDbgUses.begin() : nullptr;
438}
439
441 auto RegNoDbgUsers = use_nodbg_instructions(RegNo);
442 return hasSingleElement(RegNoDbgUsers) ? &*RegNoDbgUsers.begin() : nullptr;
443}
444
446 unsigned MaxUsers) const {
448 MaxUsers);
449}
450
451/// clearKillFlags - Iterate over all the uses of the given register and
452/// clear the kill flag from the MachineOperand. This function is used by
453/// optimization passes which extend register lifetimes and need only
454/// preserve conservative kill flag information.
456 for (MachineOperand &MO : use_operands(Reg))
457 MO.setIsKill(false);
458}
459
461 for (const std::pair<MCRegister, Register> &LI : liveins())
462 if ((Register)LI.first == Reg || LI.second == Reg)
463 return true;
464 return false;
465}
466
467/// getLiveInPhysReg - If VReg is a live-in virtual register, return the
468/// corresponding live-in physical register.
470 for (const std::pair<MCRegister, Register> &LI : liveins())
471 if (LI.second == VReg)
472 return LI.first;
473 return MCRegister();
474}
475
476/// getLiveInVirtReg - If PReg is a live-in physical register, return the
477/// corresponding live-in physical register.
479 for (const std::pair<MCRegister, Register> &LI : liveins())
480 if (LI.first == PReg)
481 return LI.second;
482 return Register();
483}
484
485/// EmitLiveInCopies - Emit copies to initialize livein virtual registers
486/// into the given entry block.
487void
489 const TargetRegisterInfo &TRI,
490 const TargetInstrInfo &TII) {
491 // Emit the copies into the top of the block.
492 for (unsigned i = 0, e = LiveIns.size(); i != e; ++i)
493 if (LiveIns[i].second) {
494 if (use_nodbg_empty(LiveIns[i].second)) {
495 // The livein has no non-dbg uses. Drop it.
496 //
497 // It would be preferable to have isel avoid creating live-in
498 // records for unused arguments in the first place, but it's
499 // complicated by the debug info code for arguments.
500 LiveIns.erase(LiveIns.begin() + i);
501 --i; --e;
502 } else {
503 // Emit a copy.
504 BuildMI(*EntryMBB, EntryMBB->begin(), DebugLoc(),
505 TII.get(TargetOpcode::COPY), LiveIns[i].second)
506 .addReg(LiveIns[i].first);
507
508 // Add the register to the entry block live-in set.
509 EntryMBB->addLiveIn(LiveIns[i].first);
510 }
511 } else {
512 // Add the register to the entry block live-in set.
513 EntryMBB->addLiveIn(LiveIns[i].first);
514 }
515}
516
518 // Lane masks are only defined for vregs.
519 assert(Reg.isVirtual());
520 const TargetRegisterClass &TRC = *getRegClass(Reg);
521 return TRC.getLaneMask();
522}
523
524#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
526 for (MachineInstr &I : use_instructions(Reg))
527 I.dump();
528}
529#endif
530
532 ReservedRegs = getTargetRegisterInfo()->getReservedRegs(*MF);
533 assert(ReservedRegs.size() == getTargetRegisterInfo()->getNumRegs() &&
534 "Invalid ReservedRegs vector from target");
535}
536
538 assert(PhysReg.isPhysical());
539
541 if (TRI->isConstantPhysReg(PhysReg))
542 return true;
543
544 // Check if any overlapping register is modified, or allocatable so it may be
545 // used later.
546 for (MCRegAliasIterator AI(PhysReg, TRI, true);
547 AI.isValid(); ++AI)
548 if (!def_empty(*AI) || isAllocatable(*AI))
549 return false;
550 return true;
551}
552
553/// markUsesInDebugValueAsUndef - Mark every DBG_VALUE referencing the
554/// specified register as undefined which causes the DBG_VALUE to be
555/// deleted during LiveDebugVariables analysis.
557 // Mark any DBG_VALUE* that uses Reg as undef (but don't delete it.)
558 // We use make_early_inc_range because setReg invalidates the iterator.
560 if (UseMI.isDebugValue() && UseMI.hasDebugOperandForReg(Reg))
561 UseMI.setDebugValueUndef();
562 }
563}
564
566 for (const MachineOperand &MO : MI.operands()) {
567 if (!MO.isGlobal())
568 continue;
569 const Function *Func = dyn_cast<Function>(MO.getGlobal());
570 if (Func != nullptr)
571 return Func;
572 }
573 return nullptr;
574}
575
576static bool isNoReturnDef(const MachineOperand &MO) {
577 // Anything which is not a noreturn function is a real def.
578 const MachineInstr &MI = *MO.getParent();
579 if (!MI.isCall())
580 return false;
581 const MachineBasicBlock &MBB = *MI.getParent();
582 if (!MBB.succ_empty())
583 return false;
584 const MachineFunction &MF = *MBB.getParent();
585 // We need to keep correct unwind information even if the function will
586 // not return, since the runtime may need it.
587 if (MF.getFunction().hasFnAttribute(Attribute::UWTable))
588 return false;
589 const Function *Called = getCalledFunction(MI);
590 return !(Called == nullptr || !Called->hasFnAttribute(Attribute::NoReturn) ||
591 !Called->hasFnAttribute(Attribute::NoUnwind));
592}
593
595 bool SkipNoReturnDef) const {
596 if (UsedPhysRegMask.test(PhysReg.id()))
597 return true;
599 for (MCRegAliasIterator AI(PhysReg, TRI, true); AI.isValid(); ++AI) {
600 for (const MachineOperand &MO : make_range(def_begin(*AI), def_end())) {
601 if (!SkipNoReturnDef && isNoReturnDef(MO))
602 continue;
603 return true;
604 }
605 }
606 return false;
607}
608
610 bool SkipRegMaskTest) const {
611 if (!SkipRegMaskTest && UsedPhysRegMask.test(PhysReg.id()))
612 return true;
614 for (MCRegAliasIterator AliasReg(PhysReg, TRI, true); AliasReg.isValid();
615 ++AliasReg) {
616 if (!reg_nodbg_empty(*AliasReg))
617 return true;
618 }
619 return false;
620}
621
623
625 assert(Reg && (Reg < TRI->getNumRegs()) &&
626 "Trying to disable an invalid register");
627
628 if (!IsUpdatedCSRsInitialized) {
629 const MCPhysReg *CSR = TRI->getCalleeSavedRegs(MF);
630 for (const MCPhysReg *I = CSR; *I; ++I)
631 UpdatedCSRs.push_back(*I);
632
633 // Zero value represents the end of the register list
634 // (no more registers should be pushed).
635 UpdatedCSRs.push_back(0);
636
637 IsUpdatedCSRsInitialized = true;
638 }
639
640 // Remove the register (and its aliases from the list).
641 for (MCRegAliasIterator AI(Reg, TRI, true); AI.isValid(); ++AI)
642 llvm::erase(UpdatedCSRs, *AI);
643}
644
646 if (IsUpdatedCSRsInitialized)
647 return UpdatedCSRs.data();
648
650
651 for (unsigned I = 0; Regs[I]; ++I)
652 if (MF->getSubtarget().isRegisterReservedByUser(Regs[I]))
653 MF->getRegInfo().disableCalleeSavedRegister(Regs[I]);
654
655 return Regs;
656}
657
659 if (IsUpdatedCSRsInitialized)
660 UpdatedCSRs.clear();
661
662 append_range(UpdatedCSRs, CSRs);
663
664 // Zero value represents the end of the register list
665 // (no more registers should be pushed).
666 UpdatedCSRs.push_back(0);
667 IsUpdatedCSRsInitialized = true;
668}
669
670bool MachineRegisterInfo::isReservedRegUnit(unsigned Unit) const {
672 for (MCRegUnitRootIterator Root(Unit, TRI); Root.isValid(); ++Root) {
673 if (all_of(TRI->superregs_inclusive(*Root),
674 [&](MCPhysReg Super) { return isReserved(Super); }))
675 return true;
676 }
677 return false;
678}
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:1707
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:649
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:2118
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:2559
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:626
void erase(Container &C, ValueType V)
Wrapper function to remove a value from a container:
Definition STLExtras.h:2110
bool hasSingleElement(ContainerTy &&C)
Returns true if the given container only contains a single element.
Definition STLExtras.h:294
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:565
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.