LLVM 24.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"
20#include "llvm/ADT/STLExtras.h"
23#include "llvm/ADT/StringSet.h"
33#include "llvm/MC/LaneBitmask.h"
35#include <cassert>
36#include <cstddef>
37#include <cstdint>
38#include <iterator>
39#include <memory>
40#include <utility>
41#include <vector>
42
43namespace llvm {
44
45class PSetIterator;
46class VirtRegMap;
47
48/// Convenient type to represent either a register class or a register bank.
51
52/// MachineRegisterInfo - Keep track of information for virtual and physical
53/// registers, including vreg register classes, use/def chains for registers,
54/// etc.
56public:
58 virtual void anchor();
59
60 public:
61 virtual ~Delegate() = default;
62
65 Register SrcReg) {
67 }
68 };
69
70 // VirtRegMap state parsed from MIR and waiting to be consumed by
71 // VirtRegMap::init().
74 Register SplitFrom; // NoReg if absent.
75 MCRegister AssignedPhys; // NoReg if absent.
76 };
77
78private:
80 SmallPtrSet<Delegate *, 1> TheDelegates;
81
82 /// True if subregister liveness is tracked.
83 const bool TracksSubRegLiveness;
84
85 /// VRegInfo - Information we keep for each virtual register.
86 ///
87 /// Each element in this list contains the register class of the vreg and the
88 /// start of the use/def list for the register.
91 VRegInfo;
92
93 /// Map for recovering vreg name from vreg number.
94 /// This map is used by the MIR Printer.
96
97 /// StringSet that is used to unique vreg names.
98 StringSet<> VRegNames;
99
100 /// The flag is true upon \p UpdatedCSRs initialization
101 /// and false otherwise.
102 bool IsUpdatedCSRsInitialized = false;
103
104 /// Contains the updated callee saved register list.
105 /// As opposed to the static list defined in register info,
106 /// all registers that were disabled are removed from the list.
107 SmallVector<MCPhysReg, 16> UpdatedCSRs;
108
109 /// RegAllocHints - This vector records register allocation hints for
110 /// virtual registers. For each virtual register, it keeps a pair of hint
111 /// type and hints vector making up the allocation hints. Only the first
112 /// hint may be target specific, and in that case this is reflected by the
113 /// first member of the pair being non-zero. If the hinted register is
114 /// virtual, it means the allocator should prefer the physical register
115 /// allocated to it if any.
118 RegAllocHints;
119
120 /// Hold the register properties that are used to populate the VirtRegMap
121 /// pass when deserializing from .mir files.
122 SmallVector<PendingVirtRegMapEntry, 0> PendingVirtRegMapEntries;
123
124 /// AntiHintRegs - This vector records register anti-hints for
125 /// virtual registers. For each virtual register, it keeps a vector of virtual
126 /// registers that should NOT be allocated to the same or overlapping physical
127 /// registers.
129
130 /// PhysRegUseDefLists - This is an array of the head of the use/def list for
131 /// physical registers.
132 std::unique_ptr<MachineOperand *[]> PhysRegUseDefLists;
133
134 /// getRegUseDefListHead - Return the head pointer for the register use/def
135 /// list for the specified virtual or physical register.
136 MachineOperand *&getRegUseDefListHead(Register RegNo) {
137 if (RegNo.isVirtual())
138 return VRegInfo[RegNo.id()].second;
139 return PhysRegUseDefLists[RegNo.id()];
140 }
141
142 MachineOperand *getRegUseDefListHead(Register RegNo) const {
143 if (RegNo.isVirtual())
144 return VRegInfo[RegNo.id()].second;
145 return PhysRegUseDefLists[RegNo.id()];
146 }
147
148 /// Get the next element in the use-def chain.
149 static MachineOperand *getNextOperandForReg(const MachineOperand *MO) {
150 assert(MO && MO->isReg() && "This is not a register operand!");
151 return MO->Contents.Reg.Next;
152 }
153
154 /// UsedPhysRegMask - Additional used physregs including aliases.
155 /// This bit vector represents all the registers clobbered by function calls.
156 BitVector UsedPhysRegMask;
157
158 /// ReservedRegs - This is a bit vector of reserved registers. The target
159 /// may change its mind about which registers should be reserved. This
160 /// vector is the frozen set of reserved registers when register allocation
161 /// started.
162 BitVector ReservedRegs;
163
164 using VRegToTypeMap = IndexedMap<LLT, VirtReg2IndexFunctor>;
165 /// Map generic virtual registers to their low-level type.
166 VRegToTypeMap VRegToType;
167
168 /// Keep track of the physical registers that are live in to the function.
169 /// Live in values are typically arguments in registers. LiveIn values are
170 /// allowed to have virtual registers associated with them, stored in the
171 /// second element.
172 std::vector<std::pair<MCRegister, Register>> LiveIns;
173
174public:
178
180 return MF->getSubtarget().getRegisterInfo();
181 }
182
183 void resetDelegate(Delegate *delegate) {
184 // Ensure another delegate does not take over unless the current
185 // delegate first unattaches itself.
186 assert(TheDelegates.count(delegate) &&
187 "Only an existing delegate can perform reset!");
188 TheDelegates.erase(delegate);
189 }
190
191 void addDelegate(Delegate *delegate) {
192 assert(delegate && !TheDelegates.count(delegate) &&
193 "Attempted to add null delegate, or to change it without "
194 "first resetting it!");
195
196 TheDelegates.insert(delegate);
197 }
198
200 for (auto *TheDelegate : TheDelegates)
201 TheDelegate->MRI_NoteNewVirtualRegister(Reg);
202 }
203
205 for (auto *TheDelegate : TheDelegates)
206 TheDelegate->MRI_NoteCloneVirtualRegister(NewReg, SrcReg);
207 }
208
209 const MachineFunction &getMF() const { return *MF; }
210
211 //===--------------------------------------------------------------------===//
212 // Function State
213 //===--------------------------------------------------------------------===//
214
215 // isSSA - Returns true when the machine function is in SSA form. Early
216 // passes require the machine function to be in SSA form where every virtual
217 // register has a single defining instruction.
218 //
219 // The TwoAddressInstructionPass and PHIElimination passes take the machine
220 // function out of SSA form when they introduce multiple defs per virtual
221 // register.
222 bool isSSA() const { return MF->getProperties().hasIsSSA(); }
223
224 // leaveSSA - Indicates that the machine function is no longer in SSA form.
225 void leaveSSA() { MF->getProperties().resetIsSSA(); }
226
227 /// tracksLiveness - Returns true when tracking register liveness accurately.
228 /// (see MachineFUnctionProperties::Property description for details)
229 bool tracksLiveness() const {
230 return MF->getProperties().hasTracksLiveness();
231 }
232
233 /// invalidateLiveness - Indicates that register liveness is no longer being
234 /// tracked accurately.
235 ///
236 /// This should be called by late passes that invalidate the liveness
237 /// information.
238 void invalidateLiveness() { MF->getProperties().resetTracksLiveness(); }
239
240 /// Returns true if liveness for register class @p RC should be tracked at
241 /// the subregister level.
246 assert(VReg.isVirtual() && "Must pass a VReg");
247 const TargetRegisterClass *RC = getRegClassOrNull(VReg);
248 return LLVM_LIKELY(RC) ? shouldTrackSubRegLiveness(*RC) : false;
249 }
251 return TracksSubRegLiveness;
252 }
253
254 //===--------------------------------------------------------------------===//
255 // Register Info
256 //===--------------------------------------------------------------------===//
257
258 /// Returns true if the updated CSR list was initialized and false otherwise.
259 bool isUpdatedCSRsInitialized() const { return IsUpdatedCSRsInitialized; }
260
261 /// Disables the register from the list of CSRs.
262 /// I.e. the register will not appear as part of the CSR mask.
263 /// \see UpdatedCalleeSavedRegs.
265
266 /// Returns list of callee saved registers.
267 /// The function returns the updated CSR list (after taking into account
268 /// registers that are disabled from the CSR list).
270
271 /// Sets the updated Callee Saved Registers list.
272 /// Notice that it will override ant previously disabled/saved CSRs.
274
275 // Strictly for use by MachineInstr.cpp.
277
278 // Strictly for use by MachineInstr.cpp.
280
281 // Strictly for use by MachineInstr.cpp.
283 unsigned NumOps);
284
285 /// Verify the sanity of the use list for Reg.
287
288 /// Verify the use list of all registers.
289 LLVM_ABI void verifyUseLists() const;
290
291 /// reg_begin/reg_end - Provide iteration support to walk over all definitions
292 /// and uses of a register within the MachineFunction that corresponds to this
293 /// MachineRegisterInfo object.
294 template <bool Uses, bool Defs, bool SkipDebug, bool ByOperand, bool ByInstr>
296 template <bool Uses, bool Defs, bool SkipDebug, bool ByInstr>
298
299 // Make it a friend so it can access getNextOperandForReg().
300 template <bool, bool, bool, bool, bool> friend class defusechain_iterator;
301 template <bool, bool, bool, bool> friend class defusechain_instr_iterator;
302
303 /// reg_iterator/reg_begin/reg_end - Walk all defs and uses of the specified
304 /// register.
307 return reg_iterator(getRegUseDefListHead(RegNo));
308 }
309 static reg_iterator reg_end() { return reg_iterator(nullptr); }
310
314
315 /// reg_instr_iterator/reg_instr_begin/reg_instr_end - Walk all defs and uses
316 /// of the specified register, stepping by MachineInstr.
318 defusechain_instr_iterator<true, true, false, /*ByInstr=*/true>;
320 return reg_instr_iterator(getRegUseDefListHead(RegNo));
321 }
323 return reg_instr_iterator(nullptr);
324 }
325
330
331 /// reg_bundle_iterator/reg_bundle_begin/reg_bundle_end - Walk all defs and uses
332 /// of the specified register, stepping by bundle.
334 defusechain_instr_iterator<true, true, false, /*ByInstr=*/false>;
336 return reg_bundle_iterator(getRegUseDefListHead(RegNo));
337 }
339 return reg_bundle_iterator(nullptr);
340 }
341
345
346 /// reg_empty - Return true if there are no instructions using or defining the
347 /// specified register (it may be live-in).
348 bool reg_empty(Register RegNo) const { return reg_begin(RegNo) == reg_end(); }
349
350 /// reg_nodbg_iterator/reg_nodbg_begin/reg_nodbg_end - Walk all defs and uses
351 /// of the specified register, skipping those marked as Debug.
355 return reg_nodbg_iterator(getRegUseDefListHead(RegNo));
356 }
358 return reg_nodbg_iterator(nullptr);
359 }
360
365
366 /// reg_instr_nodbg_iterator/reg_instr_nodbg_begin/reg_instr_nodbg_end - Walk
367 /// all defs and uses of the specified register, stepping by MachineInstr,
368 /// skipping those marked as Debug.
370 defusechain_instr_iterator<true, true, true, /*ByInstr=*/true>;
372 return reg_instr_nodbg_iterator(getRegUseDefListHead(RegNo));
373 }
377
382
383 /// reg_bundle_nodbg_iterator/reg_bundle_nodbg_begin/reg_bundle_nodbg_end - Walk
384 /// all defs and uses of the specified register, stepping by bundle,
385 /// skipping those marked as Debug.
387 defusechain_instr_iterator<true, true, true, /*ByInstr=*/false>;
389 return reg_bundle_nodbg_iterator(getRegUseDefListHead(RegNo));
390 }
394
399
400 /// reg_nodbg_empty - Return true if the only instructions using or defining
401 /// Reg are Debug instructions.
402 bool reg_nodbg_empty(Register RegNo) const {
403 return reg_nodbg_begin(RegNo) == reg_nodbg_end();
404 }
405
406 /// def_iterator/def_begin/def_end - Walk all defs of the specified register.
409 return def_iterator(getRegUseDefListHead(RegNo));
410 }
411 static def_iterator def_end() { return def_iterator(nullptr); }
412
416
417 /// def_instr_iterator/def_instr_begin/def_instr_end - Walk all defs of the
418 /// specified register, stepping by MachineInst.
420 defusechain_instr_iterator<false, true, false, /*ByInstr=*/true>;
422 return def_instr_iterator(getRegUseDefListHead(RegNo));
423 }
425 return def_instr_iterator(nullptr);
426 }
427
432
433 /// def_bundle_iterator/def_bundle_begin/def_bundle_end - Walk all defs of the
434 /// specified register, stepping by bundle.
436 defusechain_instr_iterator<false, true, false, /*ByInstr=*/false>;
438 return def_bundle_iterator(getRegUseDefListHead(RegNo));
439 }
441 return def_bundle_iterator(nullptr);
442 }
443
447
448 /// def_empty - Return true if there are no instructions defining the
449 /// specified register (it may be live-in).
450 bool def_empty(Register RegNo) const { return def_begin(RegNo) == def_end(); }
451
453 return VReg2Name.inBounds(Reg) ? StringRef(VReg2Name[Reg]) : "";
454 }
455
457 assert((Name.empty() || !VRegNames.contains(Name)) &&
458 "Named VRegs Must be Unique.");
459 if (!Name.empty()) {
460 VRegNames.insert(Name);
461 VReg2Name.grow(Reg);
462 VReg2Name[Reg] = Name.str();
463 }
464 }
465
466 /// Return true if there is exactly one operand defining the specified
467 /// register.
468 bool hasOneDef(Register RegNo) const {
469 return hasSingleElement(def_operands(RegNo));
470 }
471
472 /// Returns the defining operand if there is exactly one operand defining the
473 /// specified register, otherwise nullptr.
476 if (DI == def_end()) // No defs.
477 return nullptr;
478
479 def_iterator OneDef = DI;
480 if (++DI == def_end())
481 return &*OneDef;
482 return nullptr; // Multiple defs.
483 }
484
485 /// use_iterator/use_begin/use_end - Walk all uses of the specified register.
488 return use_iterator(getRegUseDefListHead(RegNo));
489 }
490 static use_iterator use_end() { return use_iterator(nullptr); }
491
495
496 /// use_instr_iterator/use_instr_begin/use_instr_end - Walk all uses of the
497 /// specified register, stepping by MachineInstr.
499 defusechain_instr_iterator<true, false, false, /*ByInstr=*/true>;
501 return use_instr_iterator(getRegUseDefListHead(RegNo));
502 }
504 return use_instr_iterator(nullptr);
505 }
506
511
512 /// use_bundle_iterator/use_bundle_begin/use_bundle_end - Walk all uses of the
513 /// specified register, stepping by bundle.
515 defusechain_instr_iterator<true, false, false, /*ByInstr=*/false>;
517 return use_bundle_iterator(getRegUseDefListHead(RegNo));
518 }
520 return use_bundle_iterator(nullptr);
521 }
522
526
527 /// use_empty - Return true if there are no instructions using the specified
528 /// register.
529 bool use_empty(Register RegNo) const { return use_begin(RegNo) == use_end(); }
530
531 /// hasOneUse - Return true if there is exactly one instruction using the
532 /// specified register.
533 bool hasOneUse(Register RegNo) const {
534 MachineOperand *Head = getRegUseDefListHead(RegNo);
535 if (!Head)
536 return false;
537 // Prev links are circular, and defs always precede uses.
538 MachineOperand *Tail = Head->Contents.Reg.Prev;
539 if (!Tail->isUse())
540 return false;
541 if (Tail == Head)
542 return true;
543 return Tail->Contents.Reg.Prev->isDef();
544 }
545
546 /// use_nodbg_iterator/use_nodbg_begin/use_nodbg_end - Walk all uses of the
547 /// specified register, skipping those marked as Debug.
551 return use_nodbg_iterator(getRegUseDefListHead(RegNo));
552 }
554 return use_nodbg_iterator(nullptr);
555 }
556
561
562 /// use_instr_nodbg_iterator/use_instr_nodbg_begin/use_instr_nodbg_end - Walk
563 /// all uses of the specified register, stepping by MachineInstr, skipping
564 /// those marked as Debug.
566 defusechain_instr_iterator<true, false, true, /*ByInstr=*/true>;
568 return use_instr_nodbg_iterator(getRegUseDefListHead(RegNo));
569 }
573
578
579 /// use_bundle_nodbg_iterator/use_bundle_nodbg_begin/use_bundle_nodbg_end - Walk
580 /// all uses of the specified register, stepping by bundle, skipping
581 /// those marked as Debug.
583 defusechain_instr_iterator<true, false, true, /*ByInstr=*/false>;
585 return use_bundle_nodbg_iterator(getRegUseDefListHead(RegNo));
586 }
590
595
596 /// use_nodbg_empty - Return true if there are no non-Debug instructions
597 /// using the specified register.
598 bool use_nodbg_empty(Register RegNo) const {
599 return use_nodbg_begin(RegNo) == use_nodbg_end();
600 }
601
602 /// hasOneNonDBGUse - Return true if there is exactly one non-Debug
603 /// use of the specified register.
604 LLVM_ABI bool hasOneNonDBGUse(Register RegNo) const;
605
606 /// hasOneNonDBGUse - Return true if there is exactly one non-Debug
607 /// instruction using the specified register. Said instruction may have
608 /// multiple uses.
609 LLVM_ABI bool hasOneNonDBGUser(Register RegNo) const;
610
611 /// If the register has a single non-Debug use, returns it; otherwise returns
612 /// nullptr.
614
615 /// If the register has a single non-Debug instruction using the specified
616 /// register, returns it; otherwise returns nullptr.
618
619 /// hasAtMostUses - Return true if the given register has at most \p MaxUsers
620 /// non-debug user instructions.
621 LLVM_ABI bool hasAtMostUserInstrs(Register Reg, unsigned MaxUsers) const;
622
623 /// replaceRegWith - Replace all instances of FromReg with ToReg in the
624 /// machine function. This is like llvm-level X->replaceAllUsesWith(Y),
625 /// except that it also changes any definitions of the register as well.
626 ///
627 /// Note that it is usually necessary to first constrain ToReg's register
628 /// class and register bank to match the FromReg constraints using one of the
629 /// methods:
630 ///
631 /// constrainRegClass(ToReg, getRegClass(FromReg))
632 /// constrainRegAttrs(ToReg, FromReg)
633 /// RegisterBankInfo::constrainGenericRegister(ToReg,
634 /// *MRI.getRegClass(FromReg), MRI)
635 ///
636 /// These functions will return a falsy result if the virtual registers have
637 /// incompatible constraints.
638 ///
639 /// Note that if ToReg is a physical register the function will replace and
640 /// apply sub registers to ToReg in order to obtain a final/proper physical
641 /// register.
642 LLVM_ABI void replaceRegWith(Register FromReg, Register ToReg);
643
644 /// getVRegDef - Return the machine instr that defines the specified virtual
645 /// register or null if none is found. This assumes that the code is in SSA
646 /// form, so there should only be one definition.
648
649 /// getUniqueVRegDef - Return the unique machine instr that defines the
650 /// specified virtual register or null if none is found. If there are
651 /// multiple definitions or no definition, return null.
653
654 /// Return the machine basic block in which the specified virtual register is
655 /// defined, or null if it has no definition. This assumes SSA form.
658 return DefMI ? DefMI->getParent() : nullptr;
659 }
660
661 /// clearKillFlags - Iterate over all the uses of the given register and
662 /// clear the kill flag from the MachineOperand. This function is used by
663 /// optimization passes which extend register lifetimes and need only
664 /// preserve conservative kill flag information.
666
667 LLVM_ABI void dumpUses(Register RegNo) const;
668
669 /// Returns true if PhysReg is unallocatable and constant throughout the
670 /// function. Writing to a constant register has no effect.
671 LLVM_ABI bool isConstantPhysReg(MCRegister PhysReg) const;
672
673 /// Get an iterator over the pressure sets affected by the virtual register
674 /// or register unit.
676
677 //===--------------------------------------------------------------------===//
678 // Virtual Register Info
679 //===--------------------------------------------------------------------===//
680
681 /// Return the register class of the specified virtual register.
682 /// This shouldn't be used directly unless \p Reg has a register class.
683 /// \see getRegClassOrNull when this might happen.
685 assert(isa<const TargetRegisterClass *>(VRegInfo[Reg.id()].first) &&
686 "Register class not set, wrong accessor");
687 return cast<const TargetRegisterClass *>(VRegInfo[Reg.id()].first);
688 }
689
690 /// Return the register class of \p Reg, or null if Reg has not been assigned
691 /// a register class yet.
692 ///
693 /// \note A null register class can only happen when these two
694 /// conditions are met:
695 /// 1. Generic virtual registers are created.
696 /// 2. The machine function has not completely been through the
697 /// instruction selection process.
698 /// None of this condition is possible without GlobalISel for now.
699 /// In other words, if GlobalISel is not used or if the query happens after
700 /// the select pass, using getRegClass is safe.
702 const RegClassOrRegBank &Val = VRegInfo[Reg].first;
704 }
705
706 /// Return the register bank of \p Reg.
707 /// This shouldn't be used directly unless \p Reg has a register bank.
709 return cast<const RegisterBank *>(VRegInfo[Reg.id()].first);
710 }
711
712 /// Return the register bank of \p Reg, or null if Reg has not been assigned
713 /// a register bank or has been assigned a register class.
714 /// \note It is possible to get the register bank from the register class via
715 /// RegisterBankInfo::getRegBankFromRegClass.
717 const RegClassOrRegBank &Val = VRegInfo[Reg].first;
719 }
720
721 /// Return the register bank or register class of \p Reg.
722 /// \note Before the register bank gets assigned (i.e., before the
723 /// RegBankSelect pass) \p Reg may not have either.
725 return VRegInfo[Reg].first;
726 }
727
728 /// setRegClass - Set the register class of the specified virtual register.
730
731 /// Set the register bank to \p RegBank for \p Reg.
732 LLVM_ABI void setRegBank(Register Reg, const RegisterBank &RegBank);
733
735 const RegClassOrRegBank &RCOrRB){
736 VRegInfo[Reg].first = RCOrRB;
737 }
738
739 /// constrainRegClass - Constrain the register class of the specified virtual
740 /// register to be a common subclass of RC and the current register class,
741 /// but only if the new class has at least MinNumRegs registers. Return the
742 /// new register class, or NULL if no such class exists.
743 /// This should only be used when the constraint is known to be trivial, like
744 /// GR32 -> GR32_NOSP. Beware of increasing register pressure.
745 ///
746 /// \note Assumes that the register has a register class assigned.
747 /// Use RegisterBankInfo::constrainGenericRegister in GlobalISel's
748 /// InstructionSelect pass and constrainRegAttrs in every other pass,
749 /// including non-select passes of GlobalISel, instead.
752 unsigned MinNumRegs = 0);
753
754 /// Constrain the register class or the register bank of the virtual register
755 /// \p Reg (and low-level type) to be a common subclass or a common bank of
756 /// both registers provided respectively (and a common low-level type). Do
757 /// nothing if any of the attributes (classes, banks, or low-level types) of
758 /// the registers are deemed incompatible, or if the resulting register will
759 /// have a class smaller than before and of size less than \p MinNumRegs.
760 /// Return true if such register attributes exist, false otherwise.
761 ///
762 /// \note Use this method instead of constrainRegClass and
763 /// RegisterBankInfo::constrainGenericRegister everywhere but SelectionDAG
764 /// ISel / FastISel and GlobalISel's InstructionSelect pass respectively.
765 LLVM_ABI bool constrainRegAttrs(Register Reg, Register ConstrainingReg,
766 unsigned MinNumRegs = 0);
767
768 /// recomputeRegClass - Try to find a legal super-class of Reg's register
769 /// class that still satisfies the constraints from the instructions using
770 /// Reg. Returns true if Reg was upgraded.
771 ///
772 /// This method can be used after constraints have been removed from a
773 /// virtual register, for example after removing instructions or splitting
774 /// the live range.
776
777 /// createVirtualRegister - Create and return a new virtual register in the
778 /// function with the specified register class.
780 StringRef Name = "");
781
782 /// All attributes(register class or bank and low-level type) a virtual
783 /// register can have.
788
789 /// Returns register class or bank and low level type of \p Reg. Always safe
790 /// to use. Special values are returned when \p Reg does not have some of the
791 /// attributes.
795
796 /// Create and return a new virtual register in the function with the
797 /// specified register attributes(register class or bank and low level type).
798 LLVM_ABI Register createVirtualRegister(VRegAttrs RegAttr,
799 StringRef Name = "");
800
801 /// Create and return a new virtual register in the function with the same
802 /// attributes as the given register.
804
805 /// Get the low-level type of \p Reg or LLT{} if Reg is not a generic
806 /// (target independent) virtual register.
808 if (Reg.isVirtual() && VRegToType.inBounds(Reg))
809 return VRegToType[Reg];
810 return LLT{};
811 }
812
813 /// Set the low-level type of \p VReg to \p Ty.
814 LLVM_ABI void setType(Register VReg, LLT Ty);
815
816 /// Create and return a new generic virtual register with low-level
817 /// type \p Ty.
819
820 /// Remove all types associated to virtual registers (after instruction
821 /// selection and constraining of all generic virtual registers).
823
824 /// Creates a new virtual register that has no register class, register bank
825 /// or size assigned yet. This is only allowed to be used
826 /// temporarily while constructing machine instructions. Most operations are
827 /// undefined on an incomplete register until one of setRegClass(),
828 /// setRegBank() or setSize() has been called on it.
830
831 /// getNumVirtRegs - Return the number of virtual registers created.
832 unsigned getNumVirtRegs() const { return VRegInfo.size(); }
833
834 /// Reserve space for at least \p NumVirtRegs virtual registers.
835 void reserveVirtRegs(unsigned NumVirtRegs) {
836 VRegInfo.reserve(NumVirtRegs);
837 VRegToType.reserve(NumVirtRegs);
838 }
839
840 /// clearVirtRegs - Remove all virtual registers (after physreg assignment).
841 LLVM_ABI void clearVirtRegs();
842
844 assert(Entry.VReg.isVirtual());
845 assert(!Entry.SplitFrom.isValid() || Entry.SplitFrom.isVirtual());
846 assert(!Entry.AssignedPhys.isValid() || Entry.AssignedPhys.isPhysical());
847 PendingVirtRegMapEntries.push_back(Entry);
848 }
849
851 return PendingVirtRegMapEntries;
852 }
853
854 void clearPendingVirtRegMapEntries() { PendingVirtRegMapEntries.clear(); }
855
857 assert(getNumVirtRegs() == Other.getNumVirtRegs() &&
858 "expected MachineFunction clone to preserve virtual registers");
859 PendingVirtRegMapEntries = Other.PendingVirtRegMapEntries;
860 }
861
862 /// setRegAllocationHint - Specify a register allocation hint for the
863 /// specified virtual register. This is typically used by target, and in case
864 /// of an earlier hint it will be overwritten.
865 void setRegAllocationHint(Register VReg, unsigned Type, Register PrefReg) {
866 assert(VReg.isVirtual());
867 RegAllocHints.grow(Register::index2VirtReg(getNumVirtRegs()));
868 auto &Hint = RegAllocHints[VReg];
869 Hint.first = Type;
870 Hint.second.clear();
871 Hint.second.push_back(PrefReg);
872 }
873
874 /// addRegAllocationHint - Add a register allocation hint to the hints
875 /// vector for VReg.
877 assert(VReg.isVirtual());
878 RegAllocHints.grow(Register::index2VirtReg(getNumVirtRegs()));
879 RegAllocHints[VReg].second.push_back(PrefReg);
880 }
881
882 /// Specify the preferred (target independent) register allocation hint for
883 /// the specified virtual register.
884 void setSimpleHint(Register VReg, Register PrefReg) {
885 setRegAllocationHint(VReg, /*Type=*/0, PrefReg);
886 }
887
889 assert (!RegAllocHints[VReg].first &&
890 "Expected to clear a non-target hint!");
891 if (RegAllocHints.inBounds(VReg))
892 RegAllocHints[VReg].second.clear();
893 }
894
895 /// getRegAllocationHint - Return the register allocation hint for the
896 /// specified virtual register. If there are many hints, this returns the
897 /// one with the greatest weight.
898 std::pair<unsigned, Register> getRegAllocationHint(Register VReg) const {
899 assert(VReg.isVirtual());
900 if (!RegAllocHints.inBounds(VReg))
901 return {0, Register()};
902 auto &Hint = RegAllocHints[VReg.id()];
903 Register BestHint = (Hint.second.size() ? Hint.second[0] : Register());
904 return {Hint.first, BestHint};
905 }
906
907 /// getSimpleHint - same as getRegAllocationHint except it will only return
908 /// a target independent hint.
910 assert(VReg.isVirtual());
911 std::pair<unsigned, Register> Hint = getRegAllocationHint(VReg);
912 return Hint.first ? Register() : Hint.second;
913 }
914
915 /// getRegAllocationHints - Return a reference to the vector of all
916 /// register allocation hints for VReg.
917 const std::pair<unsigned, SmallVector<Register, 4>> *
919 assert(VReg.isVirtual());
920 return RegAllocHints.inBounds(VReg) ? &RegAllocHints[VReg] : nullptr;
921 }
922
923 /// Add a register allocation anti-hint for the specified virtual register.
924 /// This tells the allocator to avoid allocating VReg to the same physical
925 /// register as AntiHintVReg (or overlapping ones).
926 void addRegAllocationAntiHint(Register VReg, Register AntiHintVReg) {
927 assert(VReg.isVirtual() && AntiHintVReg.isVirtual() &&
928 "Anti-hints and anti-hint targets are only for virtual registers");
929 AntiHintRegs.grow(VReg);
930 SmallVector<Register, 4> &AntiHints = AntiHintRegs[VReg];
931 // Avoid duplicates.
932 if (!is_contained(AntiHints, AntiHintVReg))
933 AntiHints.push_back(AntiHintVReg);
934 }
935
936 /// Add multiple anti-hints at once.
938 ArrayRef<Register> AntiHintVRegs) {
939 for (Register AntiHint : AntiHintVRegs)
940 addRegAllocationAntiHint(VReg, AntiHint);
941 }
942
943 /// Clear all anti-hints for a register.
945 assert(VReg.isVirtual() && "Anti-hints are only for virtual registers");
946 if (AntiHintRegs.inBounds(VReg))
947 AntiHintRegs[VReg].clear();
948 }
949
950 /// Return the vector of anti-hints for VReg.
952 assert(VReg.isVirtual() && "Anti-hints are only for virtual registers");
953 if (!AntiHintRegs.inBounds(VReg))
954 return ArrayRef<Register>();
955 return AntiHintRegs[VReg];
956 }
957
958 /// Check if VReg has AntiHintVReg as an anti-hint.
959 bool hasRegAllocationAntiHint(Register VReg, Register AntiHintVReg) const {
960 assert(VReg.isVirtual() && AntiHintVReg.isVirtual() &&
961 "Anti-hints and anti-hint targets are only for virtual registers");
962 if (!AntiHintRegs.inBounds(VReg))
963 return false;
964 const SmallVector<Register, 4> &AntiHints = AntiHintRegs[VReg];
965 return is_contained(AntiHints, AntiHintVReg);
966 }
967
968 /// markUsesInDebugValueAsUndef - Mark every DBG_VALUE referencing the
969 /// specified register as undefined which causes the DBG_VALUE to be
970 /// deleted during LiveDebugVariables analysis.
972
973 /// updateDbgUsersToReg - Update a collection of debug instructions
974 /// to refer to the designated register.
977
978 /// Return true if the specified register is modified in this function.
979 /// This checks that no defining machine operands exist for the register or
980 /// any of its aliases. Definitions found on functions marked noreturn are
981 /// ignored, to consider them pass 'true' for optional parameter
982 /// SkipNoReturnDef. The register is also considered modified when it is set
983 /// in the UsedPhysRegMask.
985 bool SkipNoReturnDef = false) const;
986
987 /// Return true if the specified register is modified or read in this
988 /// function. This checks that no machine operands exist for the register or
989 /// any of its aliases. If SkipRegMaskTest is false, the register is
990 /// considered used when it is set in the UsedPhysRegMask.
991 LLVM_ABI bool isPhysRegUsed(MCRegister PhysReg,
992 bool SkipRegMaskTest = false) const;
993
994 /// addPhysRegsUsedFromRegMask - Mark any registers not in RegMask as used.
995 /// This corresponds to the bit mask attached to register mask operands.
997 UsedPhysRegMask.setBitsNotInMask(RegMask);
998 }
999
1000 const BitVector &getUsedPhysRegsMask() const { return UsedPhysRegMask; }
1001
1002 //===--------------------------------------------------------------------===//
1003 // Reserved Register Info
1004 //===--------------------------------------------------------------------===//
1005 //
1006 // The set of reserved registers must be invariant during register
1007 // allocation. For example, the target cannot suddenly decide it needs a
1008 // frame pointer when the register allocator has already used the frame
1009 // pointer register for something else.
1010 //
1011 // These methods can be used by target hooks like hasFP() to avoid changing
1012 // the reserved register set during register allocation.
1013
1014 /// freezeReservedRegs - Called by the register allocator to freeze the set
1015 /// of reserved registers before allocation begins.
1017
1018 /// reserveReg -- Mark a register as reserved so checks like isAllocatable
1019 /// will not suggest using it. This should not be used during the middle
1020 /// of a function walk, or when liveness info is available.
1023 "Reserved registers haven't been frozen yet. ");
1024 MCRegAliasIterator R(PhysReg, TRI, true);
1025
1026 for (; R.isValid(); ++R)
1027 ReservedRegs.set((*R).id());
1028 }
1029
1030 /// reservedRegsFrozen - Returns true after freezeReservedRegs() was called
1031 /// to ensure the set of reserved registers stays constant.
1032 bool reservedRegsFrozen() const {
1033 return !ReservedRegs.empty();
1034 }
1035
1036 /// canReserveReg - Returns true if PhysReg can be used as a reserved
1037 /// register. Any register can be reserved before freezeReservedRegs() is
1038 /// called.
1039 bool canReserveReg(MCRegister PhysReg) const {
1040 return !reservedRegsFrozen() || ReservedRegs.test(PhysReg.id());
1041 }
1042
1043 /// getReservedRegs - Returns a reference to the frozen set of reserved
1044 /// registers. This method should always be preferred to calling
1045 /// TRI::getReservedRegs() when possible.
1048 "Reserved registers haven't been frozen yet. "
1049 "Use TRI::getReservedRegs().");
1050 return ReservedRegs;
1051 }
1052
1053 /// isReserved - Returns true when PhysReg is a reserved register.
1054 ///
1055 /// Reserved registers may belong to an allocatable register class, but the
1056 /// target has explicitly requested that they are not used.
1057 bool isReserved(MCRegister PhysReg) const {
1058 return getReservedRegs().test(PhysReg.id());
1059 }
1060
1061 /// Returns true when the given register unit is considered reserved.
1062 ///
1063 /// Register units are considered reserved when for at least one of their
1064 /// root registers, the root register and all super registers are reserved.
1065 /// This currently iterates the register hierarchy and may be slower than
1066 /// expected.
1067 LLVM_ABI bool isReservedRegUnit(MCRegUnit Unit) const;
1068
1069 /// isAllocatable - Returns true when PhysReg belongs to an allocatable
1070 /// register class and it hasn't been reserved.
1071 ///
1072 /// Allocatable registers may show up in the allocation order of some virtual
1073 /// register, so a register allocator needs to track its liveness and
1074 /// availability.
1075 bool isAllocatable(MCRegister PhysReg) const {
1076 return getTargetRegisterInfo()->isInAllocatableClass(PhysReg) &&
1077 !isReserved(PhysReg);
1078 }
1079
1080 //===--------------------------------------------------------------------===//
1081 // LiveIn Management
1082 //===--------------------------------------------------------------------===//
1083
1084 /// addLiveIn - Add the specified register as a live-in. Note that it
1085 /// is an error to add the same register to the same set more than once.
1087 LiveIns.push_back(std::make_pair(Reg, vreg));
1088 }
1089
1090 // Iteration support for the live-ins set. It's kept in sorted order
1091 // by register number.
1093 std::vector<std::pair<MCRegister,Register>>::const_iterator;
1094 livein_iterator livein_begin() const { return LiveIns.begin(); }
1095 livein_iterator livein_end() const { return LiveIns.end(); }
1096 bool livein_empty() const { return LiveIns.empty(); }
1097
1099 return LiveIns;
1100 }
1101
1102 LLVM_ABI bool isLiveIn(Register Reg) const;
1103
1104 /// getLiveInPhysReg - If VReg is a live-in virtual register, return the
1105 /// corresponding live-in physical register.
1107
1108 /// getLiveInVirtReg - If PReg is a live-in physical register, return the
1109 /// corresponding live-in virtual register.
1111
1112 /// EmitLiveInCopies - Emit copies to initialize livein virtual registers
1113 /// into the given entry block.
1115 const TargetRegisterInfo &TRI,
1116 const TargetInstrInfo &TII);
1117
1118 /// Returns a mask covering all bits that can appear in lane masks of
1119 /// subregisters of the virtual register @p Reg.
1121
1122 /// defusechain_iterator - This class provides iterator support for machine
1123 /// operands in the function that use or define a specific register. If
1124 /// ReturnUses is true it returns uses of registers, if ReturnDefs is true it
1125 /// returns defs. If neither are true then you are silly and it always
1126 /// returns end(). If SkipDebug is true it skips uses marked Debug
1127 /// when incrementing.
1128 template <bool ReturnUses, bool ReturnDefs, bool SkipDebug, bool ByOperand,
1129 bool ByInstr>
1130 class defusechain_iterator {
1132 static_assert(!ByOperand || !ByInstr,
1133 "ByOperand and ByInstr are mutually exclusive");
1134
1135 public:
1136 using iterator_category = std::forward_iterator_tag;
1138 using difference_type = std::ptrdiff_t;
1141
1142 private:
1143 MachineOperand *Op = nullptr;
1144
1145 explicit defusechain_iterator(MachineOperand *op) : Op(op) {
1146 // If the first node isn't one we're interested in, advance to one that
1147 // we are interested in.
1148 if (op) {
1149 if ((!ReturnUses && op->isUse()) ||
1150 (!ReturnDefs && op->isDef()) ||
1151 (SkipDebug && op->isDebug()))
1152 advance();
1153 }
1154 }
1155
1156 void advance() {
1157 assert(Op && "Cannot increment end iterator!");
1158 Op = getNextOperandForReg(Op);
1159
1160 // All defs come before the uses, so stop def_iterator early.
1161 if (!ReturnUses) {
1162 if (Op) {
1163 if (Op->isUse())
1164 Op = nullptr;
1165 else
1166 assert(!Op->isDebug() && "Can't have debug defs");
1167 }
1168 } else {
1169 // If this is an operand we don't care about, skip it.
1170 while (Op && ((!ReturnDefs && Op->isDef()) ||
1171 (SkipDebug && Op->isDebug())))
1172 Op = getNextOperandForReg(Op);
1173 }
1174 }
1175
1176 public:
1178
1179 bool operator==(const defusechain_iterator &x) const {
1180 return Op == x.Op;
1181 }
1182 bool operator!=(const defusechain_iterator &x) const {
1183 return !operator==(x);
1184 }
1185
1186 // Iterator traversal: forward iteration only
1187 defusechain_iterator &operator++() { // Preincrement
1188 assert(Op && "Cannot increment end iterator!");
1189 if (ByOperand)
1190 advance();
1191 else if (ByInstr) {
1192 MachineInstr *P = Op->getParent();
1193 do {
1194 advance();
1195 } while (Op && Op->getParent() == P);
1196 } else {
1198 getBundleStart(Op->getParent()->getIterator());
1199 do {
1200 advance();
1201 } while (Op && getBundleStart(Op->getParent()->getIterator()) == P);
1202 }
1203
1204 return *this;
1205 }
1206 defusechain_iterator operator++(int) { // Postincrement
1207 defusechain_iterator tmp = *this; ++*this; return tmp;
1208 }
1209
1210 /// getOperandNo - Return the operand # of this MachineOperand in its
1211 /// MachineInstr.
1212 unsigned getOperandNo() const {
1213 assert(Op && "Cannot dereference end iterator!");
1214 return Op - &Op->getParent()->getOperand(0);
1215 }
1216
1217 // Retrieve a reference to the current operand.
1219 assert(Op && "Cannot dereference end iterator!");
1220 return *Op;
1221 }
1222
1224 assert(Op && "Cannot dereference end iterator!");
1225 return Op;
1226 }
1227 };
1228
1229 /// defusechain_iterator - This class provides iterator support for machine
1230 /// operands in the function that use or define a specific register. If
1231 /// ReturnUses is true it returns uses of registers, if ReturnDefs is true it
1232 /// returns defs. If neither are true then you are silly and it always
1233 /// returns end(). If SkipDebug is true it skips uses marked Debug
1234 /// when incrementing.
1235 template <bool ReturnUses, bool ReturnDefs, bool SkipDebug, bool ByInstr>
1236 class defusechain_instr_iterator {
1238
1239 public:
1240 using iterator_category = std::forward_iterator_tag;
1242 using difference_type = std::ptrdiff_t;
1245
1246 private:
1247 MachineOperand *Op = nullptr;
1248
1250 // If the first node isn't one we're interested in, advance to one that
1251 // we are interested in.
1252 if (op) {
1253 if ((!ReturnUses && op->isUse()) ||
1254 (!ReturnDefs && op->isDef()) ||
1255 (SkipDebug && op->isDebug()))
1256 advance();
1257 }
1258 }
1259
1260 void advance() {
1261 assert(Op && "Cannot increment end iterator!");
1262 Op = getNextOperandForReg(Op);
1263
1264 // All defs come before the uses, so stop def_iterator early.
1265 if (!ReturnUses) {
1266 if (Op) {
1267 if (Op->isUse())
1268 Op = nullptr;
1269 else
1270 assert(!Op->isDebug() && "Can't have debug defs");
1271 }
1272 } else {
1273 // If this is an operand we don't care about, skip it.
1274 while (Op && ((!ReturnDefs && Op->isDef()) ||
1275 (SkipDebug && Op->isDebug())))
1276 Op = getNextOperandForReg(Op);
1277 }
1278 }
1279
1280 public:
1282
1283 bool operator==(const defusechain_instr_iterator &x) const {
1284 return Op == x.Op;
1285 }
1286 bool operator!=(const defusechain_instr_iterator &x) const {
1287 return !operator==(x);
1288 }
1289
1290 // Iterator traversal: forward iteration only
1291 defusechain_instr_iterator &operator++() { // Preincrement
1292 assert(Op && "Cannot increment end iterator!");
1293 if (ByInstr) {
1294 MachineInstr *P = Op->getParent();
1295 do {
1296 advance();
1297 } while (Op && Op->getParent() == P);
1298 } else {
1300 getBundleStart(Op->getParent()->getIterator());
1301 do {
1302 advance();
1303 } while (Op && getBundleStart(Op->getParent()->getIterator()) == P);
1304 }
1305
1306 return *this;
1307 }
1308 defusechain_instr_iterator operator++(int) { // Postincrement
1309 defusechain_instr_iterator tmp = *this; ++*this; return tmp;
1310 }
1311
1312 // Retrieve a reference to the current operand.
1314 assert(Op && "Cannot dereference end iterator!");
1315 if (!ByInstr)
1316 return *getBundleStart(Op->getParent()->getIterator());
1317 return *Op->getParent();
1318 }
1319
1320 MachineInstr *operator->() const { return &operator*(); }
1321 };
1322};
1323
1324/// Iterate over the pressure sets affected by the given physical or virtual
1325/// register. If Reg is physical, it must be a register unit (from
1326/// MCRegUnitIterator).
1328 const int *PSet = nullptr;
1329 unsigned Weight = 0;
1330
1331public:
1332 PSetIterator() = default;
1333
1336 if (VRegOrUnit.isVirtualReg()) {
1337 const TargetRegisterClass *RC =
1338 MRI->getRegClass(VRegOrUnit.asVirtualReg());
1339 PSet = TRI->getRegClassPressureSets(RC);
1340 Weight = TRI->getRegClassWeight(RC).RegWeight;
1341 } else {
1342 PSet = TRI->getRegUnitPressureSets(VRegOrUnit.asMCRegUnit());
1343 Weight = TRI->getRegUnitWeight(VRegOrUnit.asMCRegUnit());
1344 }
1345 if (*PSet == -1)
1346 PSet = nullptr;
1347 }
1348
1349 bool isValid() const { return PSet; }
1350
1351 unsigned getWeight() const { return Weight; }
1352
1353 unsigned operator*() const { return *PSet; }
1354
1355 void operator++() {
1356 assert(isValid() && "Invalid PSetIterator.");
1357 ++PSet;
1358 if (*PSet == -1)
1359 PSet = nullptr;
1360 }
1361};
1362
1363inline PSetIterator
1365 return PSetIterator(VRegOrUnit, this);
1366}
1367
1368} // end namespace llvm
1369
1370#endif // LLVM_CODEGEN_MACHINEREGISTERINFO_H
MachineInstrBuilder MachineInstrBuilder & DefMI
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
This file implements the BitVector class.
#define LLVM_ABI
Definition Compiler.h:215
#define LLVM_READONLY
Definition Compiler.h:330
#define LLVM_LIKELY(EXPR)
Definition Compiler.h:343
#define op(i)
const HexagonInstrInfo * TII
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 contains some templates that are useful if you are working with the STL at all.
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.
const bool HasDisjunctSubRegs
Whether the class supports two (or more) disjunct subregister indices.
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...
void addRegAllocationAntiHints(Register VReg, ArrayRef< Register > AntiHintVRegs)
Add multiple anti-hints at once.
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 LLVM_READONLY 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,...
MachineBasicBlock * getDefBlock(Register Reg) const
Return the machine basic block in which the specified virtual register is defined,...
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
void reserveVirtRegs(unsigned NumVirtRegs)
Reserve space for at least NumVirtRegs virtual registers.
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
bool hasRegAllocationAntiHint(Register VReg, Register AntiHintVReg) const
Check if VReg has AntiHintVReg as an anti-hint.
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.
ArrayRef< Register > getRegAllocationAntiHints(Register VReg) const
Return the vector of anti-hints for VReg.
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,...
void addPendingVirtRegMapEntry(PendingVirtRegMapEntry Entry)
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...
void addRegAllocationAntiHint(Register VReg, Register AntiHintVReg)
Add a register allocation anti-hint for the specified virtual register.
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.
ArrayRef< PendingVirtRegMapEntry > getPendingVirtRegMapEntries() const
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...
LLVM_ABI void updateDbgUsersToReg(MCRegister OldReg, MCRegister NewReg, ArrayRef< MachineInstr * > Users) const
updateDbgUsersToReg - Update a collection of debug instructions to refer to the designated register.
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.
void copyPendingVirtRegMapEntriesFrom(const MachineRegisterInfo &Other)
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,...
void clearRegAllocationAntiHints(Register VReg)
Clear all anti-hints for a 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.
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 LLVM_READONLY 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.
void push_back(const T &Elt)
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.
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.
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:300
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
@ Other
Any other memory.
Definition ModRef.h:68
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
ArrayRef(const T &OneElt) -> ArrayRef< T >
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:559
bool is_contained(R &&Range, const E &Element)
Returns true if Element is found in Range.
Definition STLExtras.h:1963
MCRegisterClass TargetRegisterClass
Definition FastISel.h:58
All attributes(register class or bank and low-level type) a virtual register can have.