LLVM 23.0.0git
MachineRegisterInfo.h
Go to the documentation of this file.
1//===- llvm/CodeGen/MachineRegisterInfo.h -----------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file defines the MachineRegisterInfo class.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef LLVM_CODEGEN_MACHINEREGISTERINFO_H
14#define LLVM_CODEGEN_MACHINEREGISTERINFO_H
15
16#include "llvm/ADT/ArrayRef.h"
17#include "llvm/ADT/BitVector.h"
18#include "llvm/ADT/IndexedMap.h"
22#include "llvm/ADT/StringSet.h"
32#include "llvm/MC/LaneBitmask.h"
34#include <cassert>
35#include <cstddef>
36#include <cstdint>
37#include <iterator>
38#include <memory>
39#include <utility>
40#include <vector>
41
42namespace llvm {
43
44class PSetIterator;
45
46/// Convenient type to represent either a register class or a register bank.
49
50/// MachineRegisterInfo - Keep track of information for virtual and physical
51/// registers, including vreg register classes, use/def chains for registers,
52/// etc.
54public:
56 virtual void anchor();
57
58 public:
59 virtual ~Delegate() = default;
60
63 Register SrcReg) {
65 }
66 };
67
68private:
70 SmallPtrSet<Delegate *, 1> TheDelegates;
71
72 /// True if subregister liveness is tracked.
73 const bool TracksSubRegLiveness;
74
75 /// VRegInfo - Information we keep for each virtual register.
76 ///
77 /// Each element in this list contains the register class of the vreg and the
78 /// start of the use/def list for the register.
82
83 /// Map for recovering vreg name from vreg number.
84 /// This map is used by the MIR Printer.
86
87 /// StringSet that is used to unique vreg names.
88 StringSet<> VRegNames;
89
90 /// The flag is true upon \p UpdatedCSRs initialization
91 /// and false otherwise.
92 bool IsUpdatedCSRsInitialized = false;
93
94 /// Contains the updated callee saved register list.
95 /// As opposed to the static list defined in register info,
96 /// all registers that were disabled are removed from the list.
98
99 /// RegAllocHints - This vector records register allocation hints for
100 /// virtual registers. For each virtual register, it keeps a pair of hint
101 /// type and hints vector making up the allocation hints. Only the first
102 /// hint may be target specific, and in that case this is reflected by the
103 /// first member of the pair being non-zero. If the hinted register is
104 /// virtual, it means the allocator should prefer the physical register
105 /// allocated to it if any.
108 RegAllocHints;
109
110 /// PhysRegUseDefLists - This is an array of the head of the use/def list for
111 /// physical registers.
112 std::unique_ptr<MachineOperand *[]> PhysRegUseDefLists;
113
114 /// getRegUseDefListHead - Return the head pointer for the register use/def
115 /// list for the specified virtual or physical register.
116 MachineOperand *&getRegUseDefListHead(Register RegNo) {
117 if (RegNo.isVirtual())
118 return VRegInfo[RegNo.id()].second;
119 return PhysRegUseDefLists[RegNo.id()];
120 }
121
122 MachineOperand *getRegUseDefListHead(Register RegNo) const {
123 if (RegNo.isVirtual())
124 return VRegInfo[RegNo.id()].second;
125 return PhysRegUseDefLists[RegNo.id()];
126 }
127
128 /// Get the next element in the use-def chain.
129 static MachineOperand *getNextOperandForReg(const MachineOperand *MO) {
130 assert(MO && MO->isReg() && "This is not a register operand!");
131 return MO->Contents.Reg.Next;
132 }
133
134 /// UsedPhysRegMask - Additional used physregs including aliases.
135 /// This bit vector represents all the registers clobbered by function calls.
136 BitVector UsedPhysRegMask;
137
138 /// ReservedRegs - This is a bit vector of reserved registers. The target
139 /// may change its mind about which registers should be reserved. This
140 /// vector is the frozen set of reserved registers when register allocation
141 /// started.
142 BitVector ReservedRegs;
143
144 using VRegToTypeMap = IndexedMap<LLT, VirtReg2IndexFunctor>;
145 /// Map generic virtual registers to their low-level type.
146 VRegToTypeMap VRegToType;
147
148 /// Keep track of the physical registers that are live in to the function.
149 /// Live in values are typically arguments in registers. LiveIn values are
150 /// allowed to have virtual registers associated with them, stored in the
151 /// second element.
152 std::vector<std::pair<MCRegister, Register>> LiveIns;
153
154public:
155 LLVM_ABI explicit MachineRegisterInfo(MachineFunction *MF);
158
160 return MF->getSubtarget().getRegisterInfo();
161 }
162
163 void resetDelegate(Delegate *delegate) {
164 // Ensure another delegate does not take over unless the current
165 // delegate first unattaches itself.
166 assert(TheDelegates.count(delegate) &&
167 "Only an existing delegate can perform reset!");
168 TheDelegates.erase(delegate);
169 }
170
171 void addDelegate(Delegate *delegate) {
172 assert(delegate && !TheDelegates.count(delegate) &&
173 "Attempted to add null delegate, or to change it without "
174 "first resetting it!");
175
176 TheDelegates.insert(delegate);
177 }
178
180 for (auto *TheDelegate : TheDelegates)
181 TheDelegate->MRI_NoteNewVirtualRegister(Reg);
182 }
183
185 for (auto *TheDelegate : TheDelegates)
186 TheDelegate->MRI_NoteCloneVirtualRegister(NewReg, SrcReg);
187 }
188
189 const MachineFunction &getMF() const { return *MF; }
190
191 //===--------------------------------------------------------------------===//
192 // Function State
193 //===--------------------------------------------------------------------===//
194
195 // isSSA - Returns true when the machine function is in SSA form. Early
196 // passes require the machine function to be in SSA form where every virtual
197 // register has a single defining instruction.
198 //
199 // The TwoAddressInstructionPass and PHIElimination passes take the machine
200 // function out of SSA form when they introduce multiple defs per virtual
201 // register.
202 bool isSSA() const { return MF->getProperties().hasIsSSA(); }
203
204 // leaveSSA - Indicates that the machine function is no longer in SSA form.
205 void leaveSSA() { MF->getProperties().resetIsSSA(); }
206
207 /// tracksLiveness - Returns true when tracking register liveness accurately.
208 /// (see MachineFUnctionProperties::Property description for details)
209 bool tracksLiveness() const {
210 return MF->getProperties().hasTracksLiveness();
211 }
212
213 /// invalidateLiveness - Indicates that register liveness is no longer being
214 /// tracked accurately.
215 ///
216 /// This should be called by late passes that invalidate the liveness
217 /// information.
218 void invalidateLiveness() { MF->getProperties().resetTracksLiveness(); }
219
220 /// Returns true if liveness for register class @p RC should be tracked at
221 /// the subregister level.
226 assert(VReg.isVirtual() && "Must pass a VReg");
227 const TargetRegisterClass *RC = getRegClassOrNull(VReg);
228 return LLVM_LIKELY(RC) ? shouldTrackSubRegLiveness(*RC) : false;
229 }
231 return TracksSubRegLiveness;
232 }
233
234 //===--------------------------------------------------------------------===//
235 // Register Info
236 //===--------------------------------------------------------------------===//
237
238 /// Returns true if the updated CSR list was initialized and false otherwise.
239 bool isUpdatedCSRsInitialized() const { return IsUpdatedCSRsInitialized; }
240
241 /// Disables the register from the list of CSRs.
242 /// I.e. the register will not appear as part of the CSR mask.
243 /// \see UpdatedCalleeSavedRegs.
245
246 /// Returns list of callee saved registers.
247 /// The function returns the updated CSR list (after taking into account
248 /// registers that are disabled from the CSR list).
250
251 /// Sets the updated Callee Saved Registers list.
252 /// Notice that it will override ant previously disabled/saved CSRs.
254
255 // Strictly for use by MachineInstr.cpp.
257
258 // Strictly for use by MachineInstr.cpp.
260
261 // Strictly for use by MachineInstr.cpp.
263 unsigned NumOps);
264
265 /// Verify the sanity of the use list for Reg.
267
268 /// Verify the use list of all registers.
269 LLVM_ABI void verifyUseLists() const;
270
271 /// reg_begin/reg_end - Provide iteration support to walk over all definitions
272 /// and uses of a register within the MachineFunction that corresponds to this
273 /// MachineRegisterInfo object.
274 template <bool Uses, bool Defs, bool SkipDebug, bool ByOperand, bool ByInstr>
276 template <bool Uses, bool Defs, bool SkipDebug, bool ByInstr>
278
279 // Make it a friend so it can access getNextOperandForReg().
280 template <bool, bool, bool, bool, bool> friend class defusechain_iterator;
281 template <bool, bool, bool, bool> friend class defusechain_instr_iterator;
282
283 /// reg_iterator/reg_begin/reg_end - Walk all defs and uses of the specified
284 /// register.
287 return reg_iterator(getRegUseDefListHead(RegNo));
288 }
289 static reg_iterator reg_end() { return reg_iterator(nullptr); }
290
294
295 /// reg_instr_iterator/reg_instr_begin/reg_instr_end - Walk all defs and uses
296 /// of the specified register, stepping by MachineInstr.
298 defusechain_instr_iterator<true, true, false, /*ByInstr=*/true>;
300 return reg_instr_iterator(getRegUseDefListHead(RegNo));
301 }
303 return reg_instr_iterator(nullptr);
304 }
305
310
311 /// reg_bundle_iterator/reg_bundle_begin/reg_bundle_end - Walk all defs and uses
312 /// of the specified register, stepping by bundle.
314 defusechain_instr_iterator<true, true, false, /*ByInstr=*/false>;
316 return reg_bundle_iterator(getRegUseDefListHead(RegNo));
317 }
319 return reg_bundle_iterator(nullptr);
320 }
321
325
326 /// reg_empty - Return true if there are no instructions using or defining the
327 /// specified register (it may be live-in).
328 bool reg_empty(Register RegNo) const { return reg_begin(RegNo) == reg_end(); }
329
330 /// reg_nodbg_iterator/reg_nodbg_begin/reg_nodbg_end - Walk all defs and uses
331 /// of the specified register, skipping those marked as Debug.
335 return reg_nodbg_iterator(getRegUseDefListHead(RegNo));
336 }
338 return reg_nodbg_iterator(nullptr);
339 }
340
345
346 /// reg_instr_nodbg_iterator/reg_instr_nodbg_begin/reg_instr_nodbg_end - Walk
347 /// all defs and uses of the specified register, stepping by MachineInstr,
348 /// skipping those marked as Debug.
350 defusechain_instr_iterator<true, true, true, /*ByInstr=*/true>;
352 return reg_instr_nodbg_iterator(getRegUseDefListHead(RegNo));
353 }
357
362
363 /// reg_bundle_nodbg_iterator/reg_bundle_nodbg_begin/reg_bundle_nodbg_end - Walk
364 /// all defs and uses of the specified register, stepping by bundle,
365 /// skipping those marked as Debug.
367 defusechain_instr_iterator<true, true, true, /*ByInstr=*/false>;
369 return reg_bundle_nodbg_iterator(getRegUseDefListHead(RegNo));
370 }
374
379
380 /// reg_nodbg_empty - Return true if the only instructions using or defining
381 /// Reg are Debug instructions.
382 bool reg_nodbg_empty(Register RegNo) const {
383 return reg_nodbg_begin(RegNo) == reg_nodbg_end();
384 }
385
386 /// def_iterator/def_begin/def_end - Walk all defs of the specified register.
389 return def_iterator(getRegUseDefListHead(RegNo));
390 }
391 static def_iterator def_end() { return def_iterator(nullptr); }
392
396
397 /// def_instr_iterator/def_instr_begin/def_instr_end - Walk all defs of the
398 /// specified register, stepping by MachineInst.
400 defusechain_instr_iterator<false, true, false, /*ByInstr=*/true>;
402 return def_instr_iterator(getRegUseDefListHead(RegNo));
403 }
405 return def_instr_iterator(nullptr);
406 }
407
412
413 /// def_bundle_iterator/def_bundle_begin/def_bundle_end - Walk all defs of the
414 /// specified register, stepping by bundle.
416 defusechain_instr_iterator<false, true, false, /*ByInstr=*/false>;
418 return def_bundle_iterator(getRegUseDefListHead(RegNo));
419 }
421 return def_bundle_iterator(nullptr);
422 }
423
427
428 /// def_empty - Return true if there are no instructions defining the
429 /// specified register (it may be live-in).
430 bool def_empty(Register RegNo) const { return def_begin(RegNo) == def_end(); }
431
433 return VReg2Name.inBounds(Reg) ? StringRef(VReg2Name[Reg]) : "";
434 }
435
437 assert((Name.empty() || !VRegNames.contains(Name)) &&
438 "Named VRegs Must be Unique.");
439 if (!Name.empty()) {
440 VRegNames.insert(Name);
441 VReg2Name.grow(Reg);
442 VReg2Name[Reg] = Name.str();
443 }
444 }
445
446 /// Return true if there is exactly one operand defining the specified
447 /// register.
448 bool hasOneDef(Register RegNo) const {
449 return hasSingleElement(def_operands(RegNo));
450 }
451
452 /// Returns the defining operand if there is exactly one operand defining the
453 /// specified register, otherwise nullptr.
456 if (DI == def_end()) // No defs.
457 return nullptr;
458
459 def_iterator OneDef = DI;
460 if (++DI == def_end())
461 return &*OneDef;
462 return nullptr; // Multiple defs.
463 }
464
465 /// use_iterator/use_begin/use_end - Walk all uses of the specified register.
468 return use_iterator(getRegUseDefListHead(RegNo));
469 }
470 static use_iterator use_end() { return use_iterator(nullptr); }
471
475
476 /// use_instr_iterator/use_instr_begin/use_instr_end - Walk all uses of the
477 /// specified register, stepping by MachineInstr.
479 defusechain_instr_iterator<true, false, false, /*ByInstr=*/true>;
481 return use_instr_iterator(getRegUseDefListHead(RegNo));
482 }
484 return use_instr_iterator(nullptr);
485 }
486
491
492 /// use_bundle_iterator/use_bundle_begin/use_bundle_end - Walk all uses of the
493 /// specified register, stepping by bundle.
495 defusechain_instr_iterator<true, false, false, /*ByInstr=*/false>;
497 return use_bundle_iterator(getRegUseDefListHead(RegNo));
498 }
500 return use_bundle_iterator(nullptr);
501 }
502
506
507 /// use_empty - Return true if there are no instructions using the specified
508 /// register.
509 bool use_empty(Register RegNo) const { return use_begin(RegNo) == use_end(); }
510
511 /// hasOneUse - Return true if there is exactly one instruction using the
512 /// specified register.
513 bool hasOneUse(Register RegNo) const {
514 MachineOperand *Head = getRegUseDefListHead(RegNo);
515 if (!Head)
516 return false;
517 // Prev links are circular, and defs always precede uses.
518 MachineOperand *Tail = Head->Contents.Reg.Prev;
519 if (!Tail->isUse())
520 return false;
521 if (Tail == Head)
522 return true;
523 return Tail->Contents.Reg.Prev->isDef();
524 }
525
526 /// use_nodbg_iterator/use_nodbg_begin/use_nodbg_end - Walk all uses of the
527 /// specified register, skipping those marked as Debug.
531 return use_nodbg_iterator(getRegUseDefListHead(RegNo));
532 }
534 return use_nodbg_iterator(nullptr);
535 }
536
541
542 /// use_instr_nodbg_iterator/use_instr_nodbg_begin/use_instr_nodbg_end - Walk
543 /// all uses of the specified register, stepping by MachineInstr, skipping
544 /// those marked as Debug.
546 defusechain_instr_iterator<true, false, true, /*ByInstr=*/true>;
548 return use_instr_nodbg_iterator(getRegUseDefListHead(RegNo));
549 }
553
558
559 /// use_bundle_nodbg_iterator/use_bundle_nodbg_begin/use_bundle_nodbg_end - Walk
560 /// all uses of the specified register, stepping by bundle, skipping
561 /// those marked as Debug.
563 defusechain_instr_iterator<true, false, true, /*ByInstr=*/false>;
565 return use_bundle_nodbg_iterator(getRegUseDefListHead(RegNo));
566 }
570
575
576 /// use_nodbg_empty - Return true if there are no non-Debug instructions
577 /// using the specified register.
578 bool use_nodbg_empty(Register RegNo) const {
579 return use_nodbg_begin(RegNo) == use_nodbg_end();
580 }
581
582 /// hasOneNonDBGUse - Return true if there is exactly one non-Debug
583 /// use of the specified register.
584 LLVM_ABI bool hasOneNonDBGUse(Register RegNo) const;
585
586 /// hasOneNonDBGUse - Return true if there is exactly one non-Debug
587 /// instruction using the specified register. Said instruction may have
588 /// multiple uses.
589 LLVM_ABI bool hasOneNonDBGUser(Register RegNo) const;
590
591 /// If the register has a single non-Debug use, returns it; otherwise returns
592 /// nullptr.
594
595 /// If the register has a single non-Debug instruction using the specified
596 /// register, returns it; otherwise returns nullptr.
598
599 /// hasAtMostUses - Return true if the given register has at most \p MaxUsers
600 /// non-debug user instructions.
601 LLVM_ABI bool hasAtMostUserInstrs(Register Reg, unsigned MaxUsers) const;
602
603 /// replaceRegWith - Replace all instances of FromReg with ToReg in the
604 /// machine function. This is like llvm-level X->replaceAllUsesWith(Y),
605 /// except that it also changes any definitions of the register as well.
606 ///
607 /// Note that it is usually necessary to first constrain ToReg's register
608 /// class and register bank to match the FromReg constraints using one of the
609 /// methods:
610 ///
611 /// constrainRegClass(ToReg, getRegClass(FromReg))
612 /// constrainRegAttrs(ToReg, FromReg)
613 /// RegisterBankInfo::constrainGenericRegister(ToReg,
614 /// *MRI.getRegClass(FromReg), MRI)
615 ///
616 /// These functions will return a falsy result if the virtual registers have
617 /// incompatible constraints.
618 ///
619 /// Note that if ToReg is a physical register the function will replace and
620 /// apply sub registers to ToReg in order to obtain a final/proper physical
621 /// register.
622 LLVM_ABI void replaceRegWith(Register FromReg, Register ToReg);
623
624 /// getVRegDef - Return the machine instr that defines the specified virtual
625 /// register or null if none is found. This assumes that the code is in SSA
626 /// form, so there should only be one definition.
628
629 /// getUniqueVRegDef - Return the unique machine instr that defines the
630 /// specified virtual register or null if none is found. If there are
631 /// multiple definitions or no definition, return null.
633
634 /// clearKillFlags - Iterate over all the uses of the given register and
635 /// clear the kill flag from the MachineOperand. This function is used by
636 /// optimization passes which extend register lifetimes and need only
637 /// preserve conservative kill flag information.
639
640 LLVM_ABI void dumpUses(Register RegNo) const;
641
642 /// Returns true if PhysReg is unallocatable and constant throughout the
643 /// function. Writing to a constant register has no effect.
644 LLVM_ABI bool isConstantPhysReg(MCRegister PhysReg) const;
645
646 /// Get an iterator over the pressure sets affected by the virtual register
647 /// or register unit.
649
650 //===--------------------------------------------------------------------===//
651 // Virtual Register Info
652 //===--------------------------------------------------------------------===//
653
654 /// Return the register class of the specified virtual register.
655 /// This shouldn't be used directly unless \p Reg has a register class.
656 /// \see getRegClassOrNull when this might happen.
658 assert(isa<const TargetRegisterClass *>(VRegInfo[Reg.id()].first) &&
659 "Register class not set, wrong accessor");
660 return cast<const TargetRegisterClass *>(VRegInfo[Reg.id()].first);
661 }
662
663 /// Return the register class of \p Reg, or null if Reg has not been assigned
664 /// a register class yet.
665 ///
666 /// \note A null register class can only happen when these two
667 /// conditions are met:
668 /// 1. Generic virtual registers are created.
669 /// 2. The machine function has not completely been through the
670 /// instruction selection process.
671 /// None of this condition is possible without GlobalISel for now.
672 /// In other words, if GlobalISel is not used or if the query happens after
673 /// the select pass, using getRegClass is safe.
675 const RegClassOrRegBank &Val = VRegInfo[Reg].first;
677 }
678
679 /// Return the register bank of \p Reg.
680 /// This shouldn't be used directly unless \p Reg has a register bank.
682 return cast<const RegisterBank *>(VRegInfo[Reg.id()].first);
683 }
684
685 /// Return the register bank of \p Reg, or null if Reg has not been assigned
686 /// a register bank or has been assigned a register class.
687 /// \note It is possible to get the register bank from the register class via
688 /// RegisterBankInfo::getRegBankFromRegClass.
690 const RegClassOrRegBank &Val = VRegInfo[Reg].first;
692 }
693
694 /// Return the register bank or register class of \p Reg.
695 /// \note Before the register bank gets assigned (i.e., before the
696 /// RegBankSelect pass) \p Reg may not have either.
698 return VRegInfo[Reg].first;
699 }
700
701 /// setRegClass - Set the register class of the specified virtual register.
703
704 /// Set the register bank to \p RegBank for \p Reg.
705 LLVM_ABI void setRegBank(Register Reg, const RegisterBank &RegBank);
706
708 const RegClassOrRegBank &RCOrRB){
709 VRegInfo[Reg].first = RCOrRB;
710 }
711
712 /// constrainRegClass - Constrain the register class of the specified virtual
713 /// register to be a common subclass of RC and the current register class,
714 /// but only if the new class has at least MinNumRegs registers. Return the
715 /// new register class, or NULL if no such class exists.
716 /// This should only be used when the constraint is known to be trivial, like
717 /// GR32 -> GR32_NOSP. Beware of increasing register pressure.
718 ///
719 /// \note Assumes that the register has a register class assigned.
720 /// Use RegisterBankInfo::constrainGenericRegister in GlobalISel's
721 /// InstructionSelect pass and constrainRegAttrs in every other pass,
722 /// including non-select passes of GlobalISel, instead.
725 unsigned MinNumRegs = 0);
726
727 /// Constrain the register class or the register bank of the virtual register
728 /// \p Reg (and low-level type) to be a common subclass or a common bank of
729 /// both registers provided respectively (and a common low-level type). Do
730 /// nothing if any of the attributes (classes, banks, or low-level types) of
731 /// the registers are deemed incompatible, or if the resulting register will
732 /// have a class smaller than before and of size less than \p MinNumRegs.
733 /// Return true if such register attributes exist, false otherwise.
734 ///
735 /// \note Use this method instead of constrainRegClass and
736 /// RegisterBankInfo::constrainGenericRegister everywhere but SelectionDAG
737 /// ISel / FastISel and GlobalISel's InstructionSelect pass respectively.
738 LLVM_ABI bool constrainRegAttrs(Register Reg, Register ConstrainingReg,
739 unsigned MinNumRegs = 0);
740
741 /// recomputeRegClass - Try to find a legal super-class of Reg's register
742 /// class that still satisfies the constraints from the instructions using
743 /// Reg. Returns true if Reg was upgraded.
744 ///
745 /// This method can be used after constraints have been removed from a
746 /// virtual register, for example after removing instructions or splitting
747 /// the live range.
749
750 /// createVirtualRegister - Create and return a new virtual register in the
751 /// function with the specified register class.
753 StringRef Name = "");
754
755 /// All attributes(register class or bank and low-level type) a virtual
756 /// register can have.
761
762 /// Returns register class or bank and low level type of \p Reg. Always safe
763 /// to use. Special values are returned when \p Reg does not have some of the
764 /// attributes.
768
769 /// Create and return a new virtual register in the function with the
770 /// specified register attributes(register class or bank and low level type).
771 LLVM_ABI Register createVirtualRegister(VRegAttrs RegAttr,
772 StringRef Name = "");
773
774 /// Create and return a new virtual register in the function with the same
775 /// attributes as the given register.
777
778 /// Get the low-level type of \p Reg or LLT{} if Reg is not a generic
779 /// (target independent) virtual register.
781 if (Reg.isVirtual() && VRegToType.inBounds(Reg))
782 return VRegToType[Reg];
783 return LLT{};
784 }
785
786 /// Set the low-level type of \p VReg to \p Ty.
787 LLVM_ABI void setType(Register VReg, LLT Ty);
788
789 /// Create and return a new generic virtual register with low-level
790 /// type \p Ty.
792
793 /// Remove all types associated to virtual registers (after instruction
794 /// selection and constraining of all generic virtual registers).
796
797 /// Creates a new virtual register that has no register class, register bank
798 /// or size assigned yet. This is only allowed to be used
799 /// temporarily while constructing machine instructions. Most operations are
800 /// undefined on an incomplete register until one of setRegClass(),
801 /// setRegBank() or setSize() has been called on it.
803
804 /// getNumVirtRegs - Return the number of virtual registers created.
805 unsigned getNumVirtRegs() const { return VRegInfo.size(); }
806
807 /// clearVirtRegs - Remove all virtual registers (after physreg assignment).
808 LLVM_ABI void clearVirtRegs();
809
810 /// setRegAllocationHint - Specify a register allocation hint for the
811 /// specified virtual register. This is typically used by target, and in case
812 /// of an earlier hint it will be overwritten.
813 void setRegAllocationHint(Register VReg, unsigned Type, Register PrefReg) {
814 assert(VReg.isVirtual());
815 RegAllocHints.grow(Register::index2VirtReg(getNumVirtRegs()));
816 auto &Hint = RegAllocHints[VReg];
817 Hint.first = Type;
818 Hint.second.clear();
819 Hint.second.push_back(PrefReg);
820 }
821
822 /// addRegAllocationHint - Add a register allocation hint to the hints
823 /// vector for VReg.
825 assert(VReg.isVirtual());
826 RegAllocHints.grow(Register::index2VirtReg(getNumVirtRegs()));
827 RegAllocHints[VReg].second.push_back(PrefReg);
828 }
829
830 /// Specify the preferred (target independent) register allocation hint for
831 /// the specified virtual register.
832 void setSimpleHint(Register VReg, Register PrefReg) {
833 setRegAllocationHint(VReg, /*Type=*/0, PrefReg);
834 }
835
837 assert (!RegAllocHints[VReg].first &&
838 "Expected to clear a non-target hint!");
839 if (RegAllocHints.inBounds(VReg))
840 RegAllocHints[VReg].second.clear();
841 }
842
843 /// getRegAllocationHint - Return the register allocation hint for the
844 /// specified virtual register. If there are many hints, this returns the
845 /// one with the greatest weight.
846 std::pair<unsigned, Register> getRegAllocationHint(Register VReg) const {
847 assert(VReg.isVirtual());
848 if (!RegAllocHints.inBounds(VReg))
849 return {0, Register()};
850 auto &Hint = RegAllocHints[VReg.id()];
851 Register BestHint = (Hint.second.size() ? Hint.second[0] : Register());
852 return {Hint.first, BestHint};
853 }
854
855 /// getSimpleHint - same as getRegAllocationHint except it will only return
856 /// a target independent hint.
858 assert(VReg.isVirtual());
859 std::pair<unsigned, Register> Hint = getRegAllocationHint(VReg);
860 return Hint.first ? Register() : Hint.second;
861 }
862
863 /// getRegAllocationHints - Return a reference to the vector of all
864 /// register allocation hints for VReg.
865 const std::pair<unsigned, SmallVector<Register, 4>> *
867 assert(VReg.isVirtual());
868 return RegAllocHints.inBounds(VReg) ? &RegAllocHints[VReg] : nullptr;
869 }
870
871 /// markUsesInDebugValueAsUndef - Mark every DBG_VALUE referencing the
872 /// specified register as undefined which causes the DBG_VALUE to be
873 /// deleted during LiveDebugVariables analysis.
875
876 /// updateDbgUsersToReg - Update a collection of debug instructions
877 /// to refer to the designated register.
880 // If this operand is a register, check whether it overlaps with OldReg.
881 // If it does, replace with NewReg.
882 auto UpdateOp = [this, &NewReg, &OldReg](MachineOperand &Op) {
883 if (Op.isReg() &&
884 getTargetRegisterInfo()->regsOverlap(Op.getReg(), OldReg))
885 Op.setReg(NewReg);
886 };
887
888 // Iterate through (possibly several) operands to DBG_VALUEs and update
889 // each. For DBG_PHIs, only one operand will be present.
890 for (MachineInstr *MI : Users) {
891 if (MI->isDebugValue()) {
892 for (auto &Op : MI->debug_operands())
893 UpdateOp(Op);
894 assert(MI->hasDebugOperandForReg(NewReg) &&
895 "Expected debug value to have some overlap with OldReg");
896 } else if (MI->isDebugPHI()) {
897 UpdateOp(MI->getOperand(0));
898 } else {
899 llvm_unreachable("Non-DBG_VALUE, Non-DBG_PHI debug instr updated");
900 }
901 }
902 }
903
904 /// Return true if the specified register is modified in this function.
905 /// This checks that no defining machine operands exist for the register or
906 /// any of its aliases. Definitions found on functions marked noreturn are
907 /// ignored, to consider them pass 'true' for optional parameter
908 /// SkipNoReturnDef. The register is also considered modified when it is set
909 /// in the UsedPhysRegMask.
911 bool SkipNoReturnDef = false) const;
912
913 /// Return true if the specified register is modified or read in this
914 /// function. This checks that no machine operands exist for the register or
915 /// any of its aliases. If SkipRegMaskTest is false, the register is
916 /// considered used when it is set in the UsedPhysRegMask.
917 LLVM_ABI bool isPhysRegUsed(MCRegister PhysReg,
918 bool SkipRegMaskTest = false) const;
919
920 /// addPhysRegsUsedFromRegMask - Mark any registers not in RegMask as used.
921 /// This corresponds to the bit mask attached to register mask operands.
923 UsedPhysRegMask.setBitsNotInMask(RegMask);
924 }
925
926 const BitVector &getUsedPhysRegsMask() const { return UsedPhysRegMask; }
927
928 //===--------------------------------------------------------------------===//
929 // Reserved Register Info
930 //===--------------------------------------------------------------------===//
931 //
932 // The set of reserved registers must be invariant during register
933 // allocation. For example, the target cannot suddenly decide it needs a
934 // frame pointer when the register allocator has already used the frame
935 // pointer register for something else.
936 //
937 // These methods can be used by target hooks like hasFP() to avoid changing
938 // the reserved register set during register allocation.
939
940 /// freezeReservedRegs - Called by the register allocator to freeze the set
941 /// of reserved registers before allocation begins.
943
944 /// reserveReg -- Mark a register as reserved so checks like isAllocatable
945 /// will not suggest using it. This should not be used during the middle
946 /// of a function walk, or when liveness info is available.
949 "Reserved registers haven't been frozen yet. ");
950 MCRegAliasIterator R(PhysReg, TRI, true);
951
952 for (; R.isValid(); ++R)
953 ReservedRegs.set((*R).id());
954 }
955
956 /// reservedRegsFrozen - Returns true after freezeReservedRegs() was called
957 /// to ensure the set of reserved registers stays constant.
958 bool reservedRegsFrozen() const {
959 return !ReservedRegs.empty();
960 }
961
962 /// canReserveReg - Returns true if PhysReg can be used as a reserved
963 /// register. Any register can be reserved before freezeReservedRegs() is
964 /// called.
965 bool canReserveReg(MCRegister PhysReg) const {
966 return !reservedRegsFrozen() || ReservedRegs.test(PhysReg.id());
967 }
968
969 /// getReservedRegs - Returns a reference to the frozen set of reserved
970 /// registers. This method should always be preferred to calling
971 /// TRI::getReservedRegs() when possible.
972 const BitVector &getReservedRegs() const {
974 "Reserved registers haven't been frozen yet. "
975 "Use TRI::getReservedRegs().");
976 return ReservedRegs;
977 }
978
979 /// isReserved - Returns true when PhysReg is a reserved register.
980 ///
981 /// Reserved registers may belong to an allocatable register class, but the
982 /// target has explicitly requested that they are not used.
983 bool isReserved(MCRegister PhysReg) const {
984 return getReservedRegs().test(PhysReg.id());
985 }
986
987 /// Returns true when the given register unit is considered reserved.
988 ///
989 /// Register units are considered reserved when for at least one of their
990 /// root registers, the root register and all super registers are reserved.
991 /// This currently iterates the register hierarchy and may be slower than
992 /// expected.
993 LLVM_ABI bool isReservedRegUnit(MCRegUnit Unit) const;
994
995 /// isAllocatable - Returns true when PhysReg belongs to an allocatable
996 /// register class and it hasn't been reserved.
997 ///
998 /// Allocatable registers may show up in the allocation order of some virtual
999 /// register, so a register allocator needs to track its liveness and
1000 /// availability.
1001 bool isAllocatable(MCRegister PhysReg) const {
1002 return getTargetRegisterInfo()->isInAllocatableClass(PhysReg) &&
1003 !isReserved(PhysReg);
1004 }
1005
1006 //===--------------------------------------------------------------------===//
1007 // LiveIn Management
1008 //===--------------------------------------------------------------------===//
1009
1010 /// addLiveIn - Add the specified register as a live-in. Note that it
1011 /// is an error to add the same register to the same set more than once.
1013 LiveIns.push_back(std::make_pair(Reg, vreg));
1014 }
1015
1016 // Iteration support for the live-ins set. It's kept in sorted order
1017 // by register number.
1019 std::vector<std::pair<MCRegister,Register>>::const_iterator;
1020 livein_iterator livein_begin() const { return LiveIns.begin(); }
1021 livein_iterator livein_end() const { return LiveIns.end(); }
1022 bool livein_empty() const { return LiveIns.empty(); }
1023
1025 return LiveIns;
1026 }
1027
1028 LLVM_ABI bool isLiveIn(Register Reg) const;
1029
1030 /// getLiveInPhysReg - If VReg is a live-in virtual register, return the
1031 /// corresponding live-in physical register.
1033
1034 /// getLiveInVirtReg - If PReg is a live-in physical register, return the
1035 /// corresponding live-in virtual register.
1037
1038 /// EmitLiveInCopies - Emit copies to initialize livein virtual registers
1039 /// into the given entry block.
1041 const TargetRegisterInfo &TRI,
1042 const TargetInstrInfo &TII);
1043
1044 /// Returns a mask covering all bits that can appear in lane masks of
1045 /// subregisters of the virtual register @p Reg.
1047
1048 /// defusechain_iterator - This class provides iterator support for machine
1049 /// operands in the function that use or define a specific register. If
1050 /// ReturnUses is true it returns uses of registers, if ReturnDefs is true it
1051 /// returns defs. If neither are true then you are silly and it always
1052 /// returns end(). If SkipDebug is true it skips uses marked Debug
1053 /// when incrementing.
1054 template <bool ReturnUses, bool ReturnDefs, bool SkipDebug, bool ByOperand,
1055 bool ByInstr>
1056 class defusechain_iterator {
1058 static_assert(!ByOperand || !ByInstr,
1059 "ByOperand and ByInstr are mutually exclusive");
1060
1061 public:
1062 using iterator_category = std::forward_iterator_tag;
1064 using difference_type = std::ptrdiff_t;
1067
1068 private:
1069 MachineOperand *Op = nullptr;
1070
1071 explicit defusechain_iterator(MachineOperand *op) : Op(op) {
1072 // If the first node isn't one we're interested in, advance to one that
1073 // we are interested in.
1074 if (op) {
1075 if ((!ReturnUses && op->isUse()) ||
1076 (!ReturnDefs && op->isDef()) ||
1077 (SkipDebug && op->isDebug()))
1078 advance();
1079 }
1080 }
1081
1082 void advance() {
1083 assert(Op && "Cannot increment end iterator!");
1084 Op = getNextOperandForReg(Op);
1085
1086 // All defs come before the uses, so stop def_iterator early.
1087 if (!ReturnUses) {
1088 if (Op) {
1089 if (Op->isUse())
1090 Op = nullptr;
1091 else
1092 assert(!Op->isDebug() && "Can't have debug defs");
1093 }
1094 } else {
1095 // If this is an operand we don't care about, skip it.
1096 while (Op && ((!ReturnDefs && Op->isDef()) ||
1097 (SkipDebug && Op->isDebug())))
1098 Op = getNextOperandForReg(Op);
1099 }
1100 }
1101
1102 public:
1104
1105 bool operator==(const defusechain_iterator &x) const {
1106 return Op == x.Op;
1107 }
1108 bool operator!=(const defusechain_iterator &x) const {
1109 return !operator==(x);
1110 }
1111
1112 // Iterator traversal: forward iteration only
1113 defusechain_iterator &operator++() { // Preincrement
1114 assert(Op && "Cannot increment end iterator!");
1115 if (ByOperand)
1116 advance();
1117 else if (ByInstr) {
1118 MachineInstr *P = Op->getParent();
1119 do {
1120 advance();
1121 } while (Op && Op->getParent() == P);
1122 } else {
1124 getBundleStart(Op->getParent()->getIterator());
1125 do {
1126 advance();
1127 } while (Op && getBundleStart(Op->getParent()->getIterator()) == P);
1128 }
1129
1130 return *this;
1131 }
1132 defusechain_iterator operator++(int) { // Postincrement
1133 defusechain_iterator tmp = *this; ++*this; return tmp;
1134 }
1135
1136 /// getOperandNo - Return the operand # of this MachineOperand in its
1137 /// MachineInstr.
1138 unsigned getOperandNo() const {
1139 assert(Op && "Cannot dereference end iterator!");
1140 return Op - &Op->getParent()->getOperand(0);
1141 }
1142
1143 // Retrieve a reference to the current operand.
1145 assert(Op && "Cannot dereference end iterator!");
1146 return *Op;
1147 }
1148
1150 assert(Op && "Cannot dereference end iterator!");
1151 return Op;
1152 }
1153 };
1154
1155 /// defusechain_iterator - This class provides iterator support for machine
1156 /// operands in the function that use or define a specific register. If
1157 /// ReturnUses is true it returns uses of registers, if ReturnDefs is true it
1158 /// returns defs. If neither are true then you are silly and it always
1159 /// returns end(). If SkipDebug is true it skips uses marked Debug
1160 /// when incrementing.
1161 template <bool ReturnUses, bool ReturnDefs, bool SkipDebug, bool ByInstr>
1162 class defusechain_instr_iterator {
1164
1165 public:
1166 using iterator_category = std::forward_iterator_tag;
1168 using difference_type = std::ptrdiff_t;
1171
1172 private:
1173 MachineOperand *Op = nullptr;
1174
1176 // If the first node isn't one we're interested in, advance to one that
1177 // we are interested in.
1178 if (op) {
1179 if ((!ReturnUses && op->isUse()) ||
1180 (!ReturnDefs && op->isDef()) ||
1181 (SkipDebug && op->isDebug()))
1182 advance();
1183 }
1184 }
1185
1186 void advance() {
1187 assert(Op && "Cannot increment end iterator!");
1188 Op = getNextOperandForReg(Op);
1189
1190 // All defs come before the uses, so stop def_iterator early.
1191 if (!ReturnUses) {
1192 if (Op) {
1193 if (Op->isUse())
1194 Op = nullptr;
1195 else
1196 assert(!Op->isDebug() && "Can't have debug defs");
1197 }
1198 } else {
1199 // If this is an operand we don't care about, skip it.
1200 while (Op && ((!ReturnDefs && Op->isDef()) ||
1201 (SkipDebug && Op->isDebug())))
1202 Op = getNextOperandForReg(Op);
1203 }
1204 }
1205
1206 public:
1208
1209 bool operator==(const defusechain_instr_iterator &x) const {
1210 return Op == x.Op;
1211 }
1212 bool operator!=(const defusechain_instr_iterator &x) const {
1213 return !operator==(x);
1214 }
1215
1216 // Iterator traversal: forward iteration only
1217 defusechain_instr_iterator &operator++() { // Preincrement
1218 assert(Op && "Cannot increment end iterator!");
1219 if (ByInstr) {
1220 MachineInstr *P = Op->getParent();
1221 do {
1222 advance();
1223 } while (Op && Op->getParent() == P);
1224 } else {
1226 getBundleStart(Op->getParent()->getIterator());
1227 do {
1228 advance();
1229 } while (Op && getBundleStart(Op->getParent()->getIterator()) == P);
1230 }
1231
1232 return *this;
1233 }
1234 defusechain_instr_iterator operator++(int) { // Postincrement
1235 defusechain_instr_iterator tmp = *this; ++*this; return tmp;
1236 }
1237
1238 // Retrieve a reference to the current operand.
1240 assert(Op && "Cannot dereference end iterator!");
1241 if (!ByInstr)
1242 return *getBundleStart(Op->getParent()->getIterator());
1243 return *Op->getParent();
1244 }
1245
1246 MachineInstr *operator->() const { return &operator*(); }
1247 };
1248};
1249
1250/// Iterate over the pressure sets affected by the given physical or virtual
1251/// register. If Reg is physical, it must be a register unit (from
1252/// MCRegUnitIterator).
1254 const int *PSet = nullptr;
1255 unsigned Weight = 0;
1256
1257public:
1258 PSetIterator() = default;
1259
1262 if (VRegOrUnit.isVirtualReg()) {
1263 const TargetRegisterClass *RC =
1264 MRI->getRegClass(VRegOrUnit.asVirtualReg());
1265 PSet = TRI->getRegClassPressureSets(RC);
1266 Weight = TRI->getRegClassWeight(RC).RegWeight;
1267 } else {
1268 PSet = TRI->getRegUnitPressureSets(VRegOrUnit.asMCRegUnit());
1269 Weight = TRI->getRegUnitWeight(VRegOrUnit.asMCRegUnit());
1270 }
1271 if (*PSet == -1)
1272 PSet = nullptr;
1273 }
1274
1275 bool isValid() const { return PSet; }
1276
1277 unsigned getWeight() const { return Weight; }
1278
1279 unsigned operator*() const { return *PSet; }
1280
1281 void operator++() {
1282 assert(isValid() && "Invalid PSetIterator.");
1283 ++PSet;
1284 if (*PSet == -1)
1285 PSet = nullptr;
1286 }
1287};
1288
1289inline PSetIterator
1291 return PSetIterator(VRegOrUnit, this);
1292}
1293
1294} // end namespace llvm
1295
1296#endif // LLVM_CODEGEN_MACHINEREGISTERINFO_H
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
This file implements the BitVector class.
#define LLVM_ABI
Definition Compiler.h:213
#define LLVM_LIKELY(EXPR)
Definition Compiler.h:335
#define op(i)
const HexagonInstrInfo * TII
IRTranslator LLVM IR MI
iv Induction Variable Users
Definition IVUsers.cpp:48
This file implements an indexed map.
const size_t AbstractManglingParser< Derived, Alloc >::NumOps
A common definition of LaneBitmask for use in TableGen and CodeGen.
Register Reg
Register const TargetRegisterInfo * TRI
Promote Memory to Register
Definition Mem2Reg.cpp:110
#define P(N)
This file defines the PointerUnion class, which is a discriminated union of pointer types.
This file defines the SmallPtrSet class.
This file defines the SmallVector class.
StringSet - A set-like wrapper for the StringMap.
Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:40
bool test(unsigned Idx) const
Returns true if bit Idx is set.
Definition BitVector.h:482
MCRegAliasIterator enumerates all registers aliasing Reg.
Wrapper class representing physical registers. Should be passed by value.
Definition MCRegister.h:41
constexpr unsigned id() const
Definition MCRegister.h:82
Instructions::iterator instr_iterator
Representation of each machine instruction.
MachineOperand class - Representation of each machine instruction operand.
virtual void MRI_NoteNewVirtualRegister(Register Reg)=0
virtual void MRI_NoteCloneVirtualRegister(Register NewReg, Register SrcReg)
defusechain_iterator - This class provides iterator support for machine operands in the function that...
bool operator==(const defusechain_instr_iterator &x) const
bool operator!=(const defusechain_instr_iterator &x) const
reg_begin/reg_end - Provide iteration support to walk over all definitions and uses of a register wit...
unsigned getOperandNo() const
getOperandNo - Return the operand # of this MachineOperand in its MachineInstr.
bool operator!=(const defusechain_iterator &x) const
bool operator==(const defusechain_iterator &x) const
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.
Register getSimpleHint(Register VReg) const
getSimpleHint - same as getRegAllocationHint except it will only return a target independent hint.
use_nodbg_iterator use_nodbg_begin(Register RegNo) const
reg_nodbg_iterator reg_nodbg_begin(Register RegNo) const
void insertVRegByName(StringRef Name, Register Reg)
iterator_range< reg_bundle_iterator > reg_bundles(Register Reg) const
defusechain_instr_iterator< true, false, true, true > use_instr_nodbg_iterator
use_instr_nodbg_iterator/use_instr_nodbg_begin/use_instr_nodbg_end - Walk all uses of the specified r...
LLVM_ABI void verifyUseLists() const
Verify the use list of all registers.
defusechain_instr_iterator< false, true, false, false > def_bundle_iterator
def_bundle_iterator/def_bundle_begin/def_bundle_end - Walk all defs of the specified register,...
VRegAttrs getVRegAttrs(Register Reg) const
Returns register class or bank and low level type of Reg.
static reg_iterator reg_end()
LLVM_ABI void markUsesInDebugValueAsUndef(Register Reg) const
markUsesInDebugValueAsUndef - Mark every DBG_VALUE referencing the specified register as undefined wh...
bool tracksLiveness() const
tracksLiveness - Returns true when tracking register liveness accurately.
defusechain_instr_iterator< true, false, false, true > use_instr_iterator
use_instr_iterator/use_instr_begin/use_instr_end - Walk all uses of the specified register,...
const BitVector & getUsedPhysRegsMask() const
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 ...
static reg_instr_nodbg_iterator reg_instr_nodbg_end()
reg_instr_iterator reg_instr_begin(Register RegNo) const
defusechain_instr_iterator< true, true, false, false > reg_bundle_iterator
reg_bundle_iterator/reg_bundle_begin/reg_bundle_end - Walk all defs and uses of the specified registe...
MachineRegisterInfo & operator=(const MachineRegisterInfo &)=delete
bool isUpdatedCSRsInitialized() const
Returns true if the updated CSR list was initialized and false otherwise.
LLVM_ABI void freezeReservedRegs()
freezeReservedRegs - Called by the register allocator to freeze the set of reserved registers before ...
defusechain_instr_iterator< true, false, true, false > use_bundle_nodbg_iterator
use_bundle_nodbg_iterator/use_bundle_nodbg_begin/use_bundle_nodbg_end - Walk all uses of the specifie...
const TargetRegisterClass * getRegClass(Register Reg) const
Return the register class of the specified virtual register.
static use_nodbg_iterator use_nodbg_end()
reg_bundle_nodbg_iterator reg_bundle_nodbg_begin(Register RegNo) const
defusechain_instr_iterator< true, true, true, false > reg_bundle_nodbg_iterator
reg_bundle_nodbg_iterator/reg_bundle_nodbg_begin/reg_bundle_nodbg_end - Walk all defs and uses of the...
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)
reg_iterator reg_begin(Register RegNo) const
defusechain_instr_iterator< true, true, true, true > reg_instr_nodbg_iterator
reg_instr_nodbg_iterator/reg_instr_nodbg_begin/reg_instr_nodbg_end - Walk all defs and uses of the sp...
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< def_instr_iterator > def_instructions(Register Reg) const
bool shouldTrackSubRegLiveness(Register VReg) const
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.
static reg_instr_iterator reg_instr_end()
use_instr_iterator use_instr_begin(Register RegNo) const
PSetIterator getPressureSets(VirtRegOrUnit VRegOrUnit) const
Get an iterator over the pressure sets affected by the virtual register or register unit.
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.
iterator_range< reg_bundle_nodbg_iterator > reg_nodbg_bundles(Register Reg) const
bool isReserved(MCRegister PhysReg) const
isReserved - Returns true when PhysReg is a reserved register.
const RegisterBank * getRegBank(Register Reg) const
Return the register bank of Reg.
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.
MachineOperand * getOneDef(Register Reg) const
Returns the defining operand if there is exactly one operand defining the specified register,...
def_iterator def_begin(Register RegNo) const
defusechain_iterator< true, false, false, true, false > use_iterator
use_iterator/use_begin/use_end - Walk all uses of the specified register.
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,...
static def_bundle_iterator def_bundle_end()
const BitVector & getReservedRegs() const
getReservedRegs - Returns a reference to the frozen set of reserved registers.
iterator_range< use_bundle_nodbg_iterator > use_nodbg_bundles(Register Reg) const
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 reservedRegsFrozen() const
reservedRegsFrozen - Returns true after freezeReservedRegs() was called to ensure the set of reserved...
bool def_empty(Register RegNo) const
def_empty - Return true if there are no instructions defining the specified register (it may be live-...
bool hasOneUse(Register RegNo) const
hasOneUse - Return true if there is exactly one instruction using the specified register.
void resetDelegate(Delegate *delegate)
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.
std::vector< std::pair< MCRegister, Register > >::const_iterator livein_iterator
static use_bundle_iterator use_bundle_end()
const RegisterBank * getRegBankOrNull(Register Reg) const
Return the register bank of Reg, or null if Reg has not been assigned a register bank or has been ass...
void invalidateLiveness()
invalidateLiveness - Indicates that register liveness is no longer being tracked accurately.
static reg_nodbg_iterator reg_nodbg_end()
use_instr_nodbg_iterator use_instr_nodbg_begin(Register RegNo) const
ArrayRef< std::pair< MCRegister, Register > > liveins() const
use_bundle_nodbg_iterator use_bundle_nodbg_begin(Register RegNo) 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.
static use_instr_iterator use_instr_end()
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 shouldTrackSubRegLiveness(const TargetRegisterClass &RC) const
Returns true if liveness for register class RC should be tracked at the subregister level.
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.
defusechain_iterator< true, false, true, true, false > use_nodbg_iterator
use_nodbg_iterator/use_nodbg_begin/use_nodbg_end - Walk all uses of the specified register,...
defusechain_iterator< false, true, false, true, false > def_iterator
def_iterator/def_begin/def_end - Walk all defs of the specified register.
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.
std::pair< unsigned, Register > getRegAllocationHint(Register VReg) const
getRegAllocationHint - Return the register allocation hint for the specified virtual register.
iterator_range< use_instr_nodbg_iterator > use_nodbg_instructions(Register Reg) const
iterator_range< def_iterator > def_operands(Register Reg) const
LLVM_ABI void setType(Register VReg, LLT Ty)
Set the low-level type of VReg to Ty.
void setRegAllocationHint(Register VReg, unsigned Type, Register PrefReg)
setRegAllocationHint - Specify a register allocation hint for the specified virtual register.
void addDelegate(Delegate *delegate)
const MachineFunction & getMF() const
bool hasOneDef(Register RegNo) const
Return true if there is exactly one operand defining the specified register.
static reg_bundle_nodbg_iterator reg_bundle_nodbg_end()
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.
bool canReserveReg(MCRegister PhysReg) const
canReserveReg - Returns true if PhysReg can be used as a reserved register.
LLVM_ABI bool isReservedRegUnit(MCRegUnit Unit) const
Returns true when the given register unit is considered reserved.
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...
const TargetRegisterClass * getRegClassOrNull(Register Reg) const
Return the register class of Reg, or null if Reg has not been assigned a register class yet.
void setSimpleHint(Register VReg, Register PrefReg)
Specify the preferred (target independent) register allocation hint for the specified virtual registe...
static def_iterator def_end()
LLVM_ABI void disableCalleeSavedRegister(MCRegister Reg)
Disables the register from the list of CSRs.
use_bundle_iterator use_bundle_begin(Register RegNo) const
livein_iterator livein_end() const
reg_bundle_iterator reg_bundle_begin(Register RegNo) const
iterator_range< reg_instr_iterator > reg_instructions(Register Reg) const
void noteNewVirtualRegister(Register Reg)
static use_bundle_nodbg_iterator use_bundle_nodbg_end()
const std::pair< unsigned, SmallVector< Register, 4 > > * getRegAllocationHints(Register VReg) const
getRegAllocationHints - Return a reference to the vector of all register allocation hints for VReg.
LLVM_ABI void setCalleeSavedRegs(ArrayRef< MCPhysReg > CSRs)
Sets the updated Callee Saved Registers list.
static reg_bundle_iterator reg_bundle_end()
iterator_range< use_instr_iterator > use_instructions(Register Reg) const
void reserveReg(MCRegister PhysReg, const TargetRegisterInfo *TRI)
reserveReg – Mark a register as reserved so checks like isAllocatable will not suggest using it.
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...
use_iterator use_begin(Register RegNo) const
void addRegAllocationHint(Register VReg, Register PrefReg)
addRegAllocationHint - Add a register allocation hint to the hints vector for VReg.
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...
void addPhysRegsUsedFromRegMask(const uint32_t *RegMask)
addPhysRegsUsedFromRegMask - Mark any registers not in RegMask as used.
MachineRegisterInfo(const MachineRegisterInfo &)=delete
defusechain_instr_iterator< true, false, false, false > use_bundle_iterator
use_bundle_iterator/use_bundle_begin/use_bundle_end - Walk all uses of the specified register,...
static use_iterator use_end()
void addLiveIn(MCRegister Reg, Register vreg=Register())
addLiveIn - Add the specified register as a live-in.
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...
iterator_range< def_bundle_iterator > def_bundles(Register Reg) const
defusechain_instr_iterator< true, true, false, true > reg_instr_iterator
reg_instr_iterator/reg_instr_begin/reg_instr_end - Walk all defs and uses of the specified register,...
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...
void clearSimpleHint(Register VReg)
defusechain_iterator< true, true, false, true, false > reg_iterator
reg_iterator/reg_begin/reg_end - Walk all defs and uses of the specified register.
void noteCloneVirtualRegister(Register NewReg, Register SrcReg)
iterator_range< use_iterator > use_operands(Register Reg) const
livein_iterator livein_begin() const
reg_instr_nodbg_iterator reg_instr_nodbg_begin(Register RegNo) const
unsigned getNumVirtRegs() const
getNumVirtRegs - Return the number of virtual registers created.
iterator_range< reg_instr_nodbg_iterator > reg_nodbg_instructions(Register Reg) const
LLVM_ABI void removeRegOperandFromUseList(MachineOperand *MO)
Remove MO from its use-def list.
bool use_empty(Register RegNo) const
use_empty - Return true if there are no instructions using the specified register.
bool reg_empty(Register RegNo) const
reg_empty - Return true if there are no instructions using or defining the specified register (it may...
StringRef getVRegName(Register Reg) const
iterator_range< use_bundle_iterator > use_bundles(Register Reg) const
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.
void updateDbgUsersToReg(MCRegister OldReg, MCRegister NewReg, ArrayRef< MachineInstr * > Users) const
updateDbgUsersToReg - Update a collection of debug instructions to refer to the designated register.
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...
def_bundle_iterator def_bundle_begin(Register RegNo) const
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.
defusechain_iterator< true, true, true, true, false > reg_nodbg_iterator
reg_nodbg_iterator/reg_nodbg_begin/reg_nodbg_end - Walk all defs and uses of the specified register,...
Iterate over the pressure sets affected by the given physical or virtual register.
unsigned operator*() const
unsigned getWeight() const
PSetIterator()=default
PSetIterator(VirtRegOrUnit VRegOrUnit, const MachineRegisterInfo *MRI)
A discriminated union of two or more pointer types, with the discriminator in the low bits of the poi...
This class implements the register bank concept.
Wrapper class representing virtual and physical registers.
Definition Register.h:20
static Register index2VirtReg(unsigned Index)
Convert a 0-based index to a virtual register number.
Definition Register.h:72
constexpr bool isVirtual() const
Return true if the specified register number is in the virtual register namespace.
Definition Register.h:79
constexpr unsigned id() const
Definition Register.h:100
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
StringSet - A wrapper for StringMap that provides set-like functionality.
Definition StringSet.h:25
TargetInstrInfo - Interface to description of machine instruction set.
const bool HasDisjunctSubRegs
Whether the class supports two (or more) disjunct subregister indices.
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
bool isInAllocatableClass(MCRegister RegNo) const
Return true if the register is in the allocation of any register class.
The instances of the Type class are immutable: once they are created, they are never changed.
Definition Type.h:46
Wrapper class representing a virtual register or register unit.
Definition Register.h:175
constexpr bool isVirtualReg() const
Definition Register.h:191
constexpr MCRegUnit asMCRegUnit() const
Definition Register.h:195
constexpr Register asVirtualReg() const
Definition Register.h:200
A range adaptor for a pair of iterators.
This provides a very simple, boring adaptor for a begin and end iterator into a range type.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
@ Tail
Attemps to make calls as fast as possible while guaranteeing that tail call optimization can always b...
Definition CallingConv.h:76
This is an optimization pass for GlobalISel generic memory operations.
MachineBasicBlock::instr_iterator getBundleStart(MachineBasicBlock::instr_iterator I)
Returns an iterator to the first instruction in the bundle containing I.
PointerUnion< const TargetRegisterClass *, const RegisterBank * > RegClassOrRegBank
Convenient type to represent either a register class or a register bank.
auto dyn_cast_if_present(const Y &Val)
dyn_cast_if_present<X> - Functionally identical to dyn_cast, except that a null (or none in the case ...
Definition Casting.h:732
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
bool hasSingleElement(ContainerTy &&C)
Returns true if the given container only contains a single element.
Definition STLExtras.h:299
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:547
uint16_t MCPhysReg
An unsigned integer type large enough to represent all physical registers, but not necessarily virtua...
Definition MCRegister.h:21
DWARFExpression::Operation Op
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:559
All attributes(register class or bank and low-level type) a virtual register can have.