LLVM 22.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 return hasSingleElement(use_operands(RegNo));
515 }
516
517 /// use_nodbg_iterator/use_nodbg_begin/use_nodbg_end - Walk all uses of the
518 /// specified register, skipping those marked as Debug.
522 return use_nodbg_iterator(getRegUseDefListHead(RegNo));
523 }
525 return use_nodbg_iterator(nullptr);
526 }
527
532
533 /// use_instr_nodbg_iterator/use_instr_nodbg_begin/use_instr_nodbg_end - Walk
534 /// all uses of the specified register, stepping by MachineInstr, skipping
535 /// those marked as Debug.
537 defusechain_instr_iterator<true, false, true, /*ByInstr=*/true>;
539 return use_instr_nodbg_iterator(getRegUseDefListHead(RegNo));
540 }
544
549
550 /// use_bundle_nodbg_iterator/use_bundle_nodbg_begin/use_bundle_nodbg_end - Walk
551 /// all uses of the specified register, stepping by bundle, skipping
552 /// those marked as Debug.
554 defusechain_instr_iterator<true, false, true, /*ByInstr=*/false>;
556 return use_bundle_nodbg_iterator(getRegUseDefListHead(RegNo));
557 }
561
566
567 /// use_nodbg_empty - Return true if there are no non-Debug instructions
568 /// using the specified register.
569 bool use_nodbg_empty(Register RegNo) const {
570 return use_nodbg_begin(RegNo) == use_nodbg_end();
571 }
572
573 /// hasOneNonDBGUse - Return true if there is exactly one non-Debug
574 /// use of the specified register.
575 LLVM_ABI bool hasOneNonDBGUse(Register RegNo) const;
576
577 /// hasOneNonDBGUse - Return true if there is exactly one non-Debug
578 /// instruction using the specified register. Said instruction may have
579 /// multiple uses.
580 LLVM_ABI bool hasOneNonDBGUser(Register RegNo) const;
581
582 /// If the register has a single non-Debug use, returns it; otherwise returns
583 /// nullptr.
585
586 /// If the register has a single non-Debug instruction using the specified
587 /// register, returns it; otherwise returns nullptr.
589
590 /// hasAtMostUses - Return true if the given register has at most \p MaxUsers
591 /// non-debug user instructions.
592 LLVM_ABI bool hasAtMostUserInstrs(Register Reg, unsigned MaxUsers) const;
593
594 /// replaceRegWith - Replace all instances of FromReg with ToReg in the
595 /// machine function. This is like llvm-level X->replaceAllUsesWith(Y),
596 /// except that it also changes any definitions of the register as well.
597 ///
598 /// Note that it is usually necessary to first constrain ToReg's register
599 /// class and register bank to match the FromReg constraints using one of the
600 /// methods:
601 ///
602 /// constrainRegClass(ToReg, getRegClass(FromReg))
603 /// constrainRegAttrs(ToReg, FromReg)
604 /// RegisterBankInfo::constrainGenericRegister(ToReg,
605 /// *MRI.getRegClass(FromReg), MRI)
606 ///
607 /// These functions will return a falsy result if the virtual registers have
608 /// incompatible constraints.
609 ///
610 /// Note that if ToReg is a physical register the function will replace and
611 /// apply sub registers to ToReg in order to obtain a final/proper physical
612 /// register.
613 LLVM_ABI void replaceRegWith(Register FromReg, Register ToReg);
614
615 /// getVRegDef - Return the machine instr that defines the specified virtual
616 /// register or null if none is found. This assumes that the code is in SSA
617 /// form, so there should only be one definition.
619
620 /// getUniqueVRegDef - Return the unique machine instr that defines the
621 /// specified virtual register or null if none is found. If there are
622 /// multiple definitions or no definition, return null.
624
625 /// clearKillFlags - Iterate over all the uses of the given register and
626 /// clear the kill flag from the MachineOperand. This function is used by
627 /// optimization passes which extend register lifetimes and need only
628 /// preserve conservative kill flag information.
630
631 LLVM_ABI void dumpUses(Register RegNo) const;
632
633 /// Returns true if PhysReg is unallocatable and constant throughout the
634 /// function. Writing to a constant register has no effect.
635 LLVM_ABI bool isConstantPhysReg(MCRegister PhysReg) const;
636
637 /// Get an iterator over the pressure sets affected by the virtual register
638 /// or register unit.
640
641 //===--------------------------------------------------------------------===//
642 // Virtual Register Info
643 //===--------------------------------------------------------------------===//
644
645 /// Return the register class of the specified virtual register.
646 /// This shouldn't be used directly unless \p Reg has a register class.
647 /// \see getRegClassOrNull when this might happen.
649 assert(isa<const TargetRegisterClass *>(VRegInfo[Reg.id()].first) &&
650 "Register class not set, wrong accessor");
651 return cast<const TargetRegisterClass *>(VRegInfo[Reg.id()].first);
652 }
653
654 /// Return the register class of \p Reg, or null if Reg has not been assigned
655 /// a register class yet.
656 ///
657 /// \note A null register class can only happen when these two
658 /// conditions are met:
659 /// 1. Generic virtual registers are created.
660 /// 2. The machine function has not completely been through the
661 /// instruction selection process.
662 /// None of this condition is possible without GlobalISel for now.
663 /// In other words, if GlobalISel is not used or if the query happens after
664 /// the select pass, using getRegClass is safe.
666 const RegClassOrRegBank &Val = VRegInfo[Reg].first;
668 }
669
670 /// Return the register bank of \p Reg.
671 /// This shouldn't be used directly unless \p Reg has a register bank.
673 return cast<const RegisterBank *>(VRegInfo[Reg.id()].first);
674 }
675
676 /// Return the register bank of \p Reg, or null if Reg has not been assigned
677 /// a register bank or has been assigned a register class.
678 /// \note It is possible to get the register bank from the register class via
679 /// RegisterBankInfo::getRegBankFromRegClass.
681 const RegClassOrRegBank &Val = VRegInfo[Reg].first;
683 }
684
685 /// Return the register bank or register class of \p Reg.
686 /// \note Before the register bank gets assigned (i.e., before the
687 /// RegBankSelect pass) \p Reg may not have either.
689 return VRegInfo[Reg].first;
690 }
691
692 /// setRegClass - Set the register class of the specified virtual register.
694
695 /// Set the register bank to \p RegBank for \p Reg.
696 LLVM_ABI void setRegBank(Register Reg, const RegisterBank &RegBank);
697
699 const RegClassOrRegBank &RCOrRB){
700 VRegInfo[Reg].first = RCOrRB;
701 }
702
703 /// constrainRegClass - Constrain the register class of the specified virtual
704 /// register to be a common subclass of RC and the current register class,
705 /// but only if the new class has at least MinNumRegs registers. Return the
706 /// new register class, or NULL if no such class exists.
707 /// This should only be used when the constraint is known to be trivial, like
708 /// GR32 -> GR32_NOSP. Beware of increasing register pressure.
709 ///
710 /// \note Assumes that the register has a register class assigned.
711 /// Use RegisterBankInfo::constrainGenericRegister in GlobalISel's
712 /// InstructionSelect pass and constrainRegAttrs in every other pass,
713 /// including non-select passes of GlobalISel, instead.
716 unsigned MinNumRegs = 0);
717
718 /// Constrain the register class or the register bank of the virtual register
719 /// \p Reg (and low-level type) to be a common subclass or a common bank of
720 /// both registers provided respectively (and a common low-level type). Do
721 /// nothing if any of the attributes (classes, banks, or low-level types) of
722 /// the registers are deemed incompatible, or if the resulting register will
723 /// have a class smaller than before and of size less than \p MinNumRegs.
724 /// Return true if such register attributes exist, false otherwise.
725 ///
726 /// \note Use this method instead of constrainRegClass and
727 /// RegisterBankInfo::constrainGenericRegister everywhere but SelectionDAG
728 /// ISel / FastISel and GlobalISel's InstructionSelect pass respectively.
729 LLVM_ABI bool constrainRegAttrs(Register Reg, Register ConstrainingReg,
730 unsigned MinNumRegs = 0);
731
732 /// recomputeRegClass - Try to find a legal super-class of Reg's register
733 /// class that still satisfies the constraints from the instructions using
734 /// Reg. Returns true if Reg was upgraded.
735 ///
736 /// This method can be used after constraints have been removed from a
737 /// virtual register, for example after removing instructions or splitting
738 /// the live range.
740
741 /// createVirtualRegister - Create and return a new virtual register in the
742 /// function with the specified register class.
744 StringRef Name = "");
745
746 /// All attributes(register class or bank and low-level type) a virtual
747 /// register can have.
752
753 /// Returns register class or bank and low level type of \p Reg. Always safe
754 /// to use. Special values are returned when \p Reg does not have some of the
755 /// attributes.
759
760 /// Create and return a new virtual register in the function with the
761 /// specified register attributes(register class or bank and low level type).
762 LLVM_ABI Register createVirtualRegister(VRegAttrs RegAttr,
763 StringRef Name = "");
764
765 /// Create and return a new virtual register in the function with the same
766 /// attributes as the given register.
768
769 /// Get the low-level type of \p Reg or LLT{} if Reg is not a generic
770 /// (target independent) virtual register.
772 if (Reg.isVirtual() && VRegToType.inBounds(Reg))
773 return VRegToType[Reg];
774 return LLT{};
775 }
776
777 /// Set the low-level type of \p VReg to \p Ty.
778 LLVM_ABI void setType(Register VReg, LLT Ty);
779
780 /// Create and return a new generic virtual register with low-level
781 /// type \p Ty.
783
784 /// Remove all types associated to virtual registers (after instruction
785 /// selection and constraining of all generic virtual registers).
787
788 /// Creates a new virtual register that has no register class, register bank
789 /// or size assigned yet. This is only allowed to be used
790 /// temporarily while constructing machine instructions. Most operations are
791 /// undefined on an incomplete register until one of setRegClass(),
792 /// setRegBank() or setSize() has been called on it.
794
795 /// getNumVirtRegs - Return the number of virtual registers created.
796 unsigned getNumVirtRegs() const { return VRegInfo.size(); }
797
798 /// clearVirtRegs - Remove all virtual registers (after physreg assignment).
799 LLVM_ABI void clearVirtRegs();
800
801 /// setRegAllocationHint - Specify a register allocation hint for the
802 /// specified virtual register. This is typically used by target, and in case
803 /// of an earlier hint it will be overwritten.
804 void setRegAllocationHint(Register VReg, unsigned Type, Register PrefReg) {
805 assert(VReg.isVirtual());
806 RegAllocHints.grow(Register::index2VirtReg(getNumVirtRegs()));
807 auto &Hint = RegAllocHints[VReg];
808 Hint.first = Type;
809 Hint.second.clear();
810 Hint.second.push_back(PrefReg);
811 }
812
813 /// addRegAllocationHint - Add a register allocation hint to the hints
814 /// vector for VReg.
816 assert(VReg.isVirtual());
817 RegAllocHints.grow(Register::index2VirtReg(getNumVirtRegs()));
818 RegAllocHints[VReg].second.push_back(PrefReg);
819 }
820
821 /// Specify the preferred (target independent) register allocation hint for
822 /// the specified virtual register.
823 void setSimpleHint(Register VReg, Register PrefReg) {
824 setRegAllocationHint(VReg, /*Type=*/0, PrefReg);
825 }
826
828 assert (!RegAllocHints[VReg].first &&
829 "Expected to clear a non-target hint!");
830 if (RegAllocHints.inBounds(VReg))
831 RegAllocHints[VReg].second.clear();
832 }
833
834 /// getRegAllocationHint - Return the register allocation hint for the
835 /// specified virtual register. If there are many hints, this returns the
836 /// one with the greatest weight.
837 std::pair<unsigned, Register> getRegAllocationHint(Register VReg) const {
838 assert(VReg.isVirtual());
839 if (!RegAllocHints.inBounds(VReg))
840 return {0, Register()};
841 auto &Hint = RegAllocHints[VReg.id()];
842 Register BestHint = (Hint.second.size() ? Hint.second[0] : Register());
843 return {Hint.first, BestHint};
844 }
845
846 /// getSimpleHint - same as getRegAllocationHint except it will only return
847 /// a target independent hint.
849 assert(VReg.isVirtual());
850 std::pair<unsigned, Register> Hint = getRegAllocationHint(VReg);
851 return Hint.first ? Register() : Hint.second;
852 }
853
854 /// getRegAllocationHints - Return a reference to the vector of all
855 /// register allocation hints for VReg.
856 const std::pair<unsigned, SmallVector<Register, 4>> *
858 assert(VReg.isVirtual());
859 return RegAllocHints.inBounds(VReg) ? &RegAllocHints[VReg] : nullptr;
860 }
861
862 /// markUsesInDebugValueAsUndef - Mark every DBG_VALUE referencing the
863 /// specified register as undefined which causes the DBG_VALUE to be
864 /// deleted during LiveDebugVariables analysis.
866
867 /// updateDbgUsersToReg - Update a collection of debug instructions
868 /// to refer to the designated register.
871 // If this operand is a register, check whether it overlaps with OldReg.
872 // If it does, replace with NewReg.
873 auto UpdateOp = [this, &NewReg, &OldReg](MachineOperand &Op) {
874 if (Op.isReg() &&
875 getTargetRegisterInfo()->regsOverlap(Op.getReg(), OldReg))
876 Op.setReg(NewReg);
877 };
878
879 // Iterate through (possibly several) operands to DBG_VALUEs and update
880 // each. For DBG_PHIs, only one operand will be present.
881 for (MachineInstr *MI : Users) {
882 if (MI->isDebugValue()) {
883 for (auto &Op : MI->debug_operands())
884 UpdateOp(Op);
885 assert(MI->hasDebugOperandForReg(NewReg) &&
886 "Expected debug value to have some overlap with OldReg");
887 } else if (MI->isDebugPHI()) {
888 UpdateOp(MI->getOperand(0));
889 } else {
890 llvm_unreachable("Non-DBG_VALUE, Non-DBG_PHI debug instr updated");
891 }
892 }
893 }
894
895 /// Return true if the specified register is modified in this function.
896 /// This checks that no defining machine operands exist for the register or
897 /// any of its aliases. Definitions found on functions marked noreturn are
898 /// ignored, to consider them pass 'true' for optional parameter
899 /// SkipNoReturnDef. The register is also considered modified when it is set
900 /// in the UsedPhysRegMask.
902 bool SkipNoReturnDef = false) const;
903
904 /// Return true if the specified register is modified or read in this
905 /// function. This checks that no machine operands exist for the register or
906 /// any of its aliases. If SkipRegMaskTest is false, the register is
907 /// considered used when it is set in the UsedPhysRegMask.
908 LLVM_ABI bool isPhysRegUsed(MCRegister PhysReg,
909 bool SkipRegMaskTest = false) const;
910
911 /// addPhysRegsUsedFromRegMask - Mark any registers not in RegMask as used.
912 /// This corresponds to the bit mask attached to register mask operands.
914 UsedPhysRegMask.setBitsNotInMask(RegMask);
915 }
916
917 const BitVector &getUsedPhysRegsMask() const { return UsedPhysRegMask; }
918
919 //===--------------------------------------------------------------------===//
920 // Reserved Register Info
921 //===--------------------------------------------------------------------===//
922 //
923 // The set of reserved registers must be invariant during register
924 // allocation. For example, the target cannot suddenly decide it needs a
925 // frame pointer when the register allocator has already used the frame
926 // pointer register for something else.
927 //
928 // These methods can be used by target hooks like hasFP() to avoid changing
929 // the reserved register set during register allocation.
930
931 /// freezeReservedRegs - Called by the register allocator to freeze the set
932 /// of reserved registers before allocation begins.
934
935 /// reserveReg -- Mark a register as reserved so checks like isAllocatable
936 /// will not suggest using it. This should not be used during the middle
937 /// of a function walk, or when liveness info is available.
940 "Reserved registers haven't been frozen yet. ");
941 MCRegAliasIterator R(PhysReg, TRI, true);
942
943 for (; R.isValid(); ++R)
944 ReservedRegs.set((*R).id());
945 }
946
947 /// reservedRegsFrozen - Returns true after freezeReservedRegs() was called
948 /// to ensure the set of reserved registers stays constant.
949 bool reservedRegsFrozen() const {
950 return !ReservedRegs.empty();
951 }
952
953 /// canReserveReg - Returns true if PhysReg can be used as a reserved
954 /// register. Any register can be reserved before freezeReservedRegs() is
955 /// called.
956 bool canReserveReg(MCRegister PhysReg) const {
957 return !reservedRegsFrozen() || ReservedRegs.test(PhysReg.id());
958 }
959
960 /// getReservedRegs - Returns a reference to the frozen set of reserved
961 /// registers. This method should always be preferred to calling
962 /// TRI::getReservedRegs() when possible.
963 const BitVector &getReservedRegs() const {
965 "Reserved registers haven't been frozen yet. "
966 "Use TRI::getReservedRegs().");
967 return ReservedRegs;
968 }
969
970 /// isReserved - Returns true when PhysReg is a reserved register.
971 ///
972 /// Reserved registers may belong to an allocatable register class, but the
973 /// target has explicitly requested that they are not used.
974 bool isReserved(MCRegister PhysReg) const {
975 return getReservedRegs().test(PhysReg.id());
976 }
977
978 /// Returns true when the given register unit is considered reserved.
979 ///
980 /// Register units are considered reserved when for at least one of their
981 /// root registers, the root register and all super registers are reserved.
982 /// This currently iterates the register hierarchy and may be slower than
983 /// expected.
984 LLVM_ABI bool isReservedRegUnit(MCRegUnit Unit) const;
985
986 /// isAllocatable - Returns true when PhysReg belongs to an allocatable
987 /// register class and it hasn't been reserved.
988 ///
989 /// Allocatable registers may show up in the allocation order of some virtual
990 /// register, so a register allocator needs to track its liveness and
991 /// availability.
992 bool isAllocatable(MCRegister PhysReg) const {
993 return getTargetRegisterInfo()->isInAllocatableClass(PhysReg) &&
994 !isReserved(PhysReg);
995 }
996
997 //===--------------------------------------------------------------------===//
998 // LiveIn Management
999 //===--------------------------------------------------------------------===//
1000
1001 /// addLiveIn - Add the specified register as a live-in. Note that it
1002 /// is an error to add the same register to the same set more than once.
1004 LiveIns.push_back(std::make_pair(Reg, vreg));
1005 }
1006
1007 // Iteration support for the live-ins set. It's kept in sorted order
1008 // by register number.
1010 std::vector<std::pair<MCRegister,Register>>::const_iterator;
1011 livein_iterator livein_begin() const { return LiveIns.begin(); }
1012 livein_iterator livein_end() const { return LiveIns.end(); }
1013 bool livein_empty() const { return LiveIns.empty(); }
1014
1016 return LiveIns;
1017 }
1018
1019 LLVM_ABI bool isLiveIn(Register Reg) const;
1020
1021 /// getLiveInPhysReg - If VReg is a live-in virtual register, return the
1022 /// corresponding live-in physical register.
1024
1025 /// getLiveInVirtReg - If PReg is a live-in physical register, return the
1026 /// corresponding live-in virtual register.
1028
1029 /// EmitLiveInCopies - Emit copies to initialize livein virtual registers
1030 /// into the given entry block.
1032 const TargetRegisterInfo &TRI,
1033 const TargetInstrInfo &TII);
1034
1035 /// Returns a mask covering all bits that can appear in lane masks of
1036 /// subregisters of the virtual register @p Reg.
1038
1039 /// defusechain_iterator - This class provides iterator support for machine
1040 /// operands in the function that use or define a specific register. If
1041 /// ReturnUses is true it returns uses of registers, if ReturnDefs is true it
1042 /// returns defs. If neither are true then you are silly and it always
1043 /// returns end(). If SkipDebug is true it skips uses marked Debug
1044 /// when incrementing.
1045 template <bool ReturnUses, bool ReturnDefs, bool SkipDebug, bool ByOperand,
1046 bool ByInstr>
1047 class defusechain_iterator {
1049 static_assert(!ByOperand || !ByInstr,
1050 "ByOperand and ByInstr are mutually exclusive");
1051
1052 public:
1053 using iterator_category = std::forward_iterator_tag;
1055 using difference_type = std::ptrdiff_t;
1058
1059 private:
1060 MachineOperand *Op = nullptr;
1061
1062 explicit defusechain_iterator(MachineOperand *op) : Op(op) {
1063 // If the first node isn't one we're interested in, advance to one that
1064 // we are interested in.
1065 if (op) {
1066 if ((!ReturnUses && op->isUse()) ||
1067 (!ReturnDefs && op->isDef()) ||
1068 (SkipDebug && op->isDebug()))
1069 advance();
1070 }
1071 }
1072
1073 void advance() {
1074 assert(Op && "Cannot increment end iterator!");
1075 Op = getNextOperandForReg(Op);
1076
1077 // All defs come before the uses, so stop def_iterator early.
1078 if (!ReturnUses) {
1079 if (Op) {
1080 if (Op->isUse())
1081 Op = nullptr;
1082 else
1083 assert(!Op->isDebug() && "Can't have debug defs");
1084 }
1085 } else {
1086 // If this is an operand we don't care about, skip it.
1087 while (Op && ((!ReturnDefs && Op->isDef()) ||
1088 (SkipDebug && Op->isDebug())))
1089 Op = getNextOperandForReg(Op);
1090 }
1091 }
1092
1093 public:
1095
1096 bool operator==(const defusechain_iterator &x) const {
1097 return Op == x.Op;
1098 }
1099 bool operator!=(const defusechain_iterator &x) const {
1100 return !operator==(x);
1101 }
1102
1103 // Iterator traversal: forward iteration only
1104 defusechain_iterator &operator++() { // Preincrement
1105 assert(Op && "Cannot increment end iterator!");
1106 if (ByOperand)
1107 advance();
1108 else if (ByInstr) {
1109 MachineInstr *P = Op->getParent();
1110 do {
1111 advance();
1112 } while (Op && Op->getParent() == P);
1113 } else {
1115 getBundleStart(Op->getParent()->getIterator());
1116 do {
1117 advance();
1118 } while (Op && getBundleStart(Op->getParent()->getIterator()) == P);
1119 }
1120
1121 return *this;
1122 }
1123 defusechain_iterator operator++(int) { // Postincrement
1124 defusechain_iterator tmp = *this; ++*this; return tmp;
1125 }
1126
1127 /// getOperandNo - Return the operand # of this MachineOperand in its
1128 /// MachineInstr.
1129 unsigned getOperandNo() const {
1130 assert(Op && "Cannot dereference end iterator!");
1131 return Op - &Op->getParent()->getOperand(0);
1132 }
1133
1134 // Retrieve a reference to the current operand.
1136 assert(Op && "Cannot dereference end iterator!");
1137 return *Op;
1138 }
1139
1141 assert(Op && "Cannot dereference end iterator!");
1142 return Op;
1143 }
1144 };
1145
1146 /// defusechain_iterator - This class provides iterator support for machine
1147 /// operands in the function that use or define a specific register. If
1148 /// ReturnUses is true it returns uses of registers, if ReturnDefs is true it
1149 /// returns defs. If neither are true then you are silly and it always
1150 /// returns end(). If SkipDebug is true it skips uses marked Debug
1151 /// when incrementing.
1152 template <bool ReturnUses, bool ReturnDefs, bool SkipDebug, bool ByInstr>
1153 class defusechain_instr_iterator {
1155
1156 public:
1157 using iterator_category = std::forward_iterator_tag;
1159 using difference_type = std::ptrdiff_t;
1162
1163 private:
1164 MachineOperand *Op = nullptr;
1165
1167 // If the first node isn't one we're interested in, advance to one that
1168 // we are interested in.
1169 if (op) {
1170 if ((!ReturnUses && op->isUse()) ||
1171 (!ReturnDefs && op->isDef()) ||
1172 (SkipDebug && op->isDebug()))
1173 advance();
1174 }
1175 }
1176
1177 void advance() {
1178 assert(Op && "Cannot increment end iterator!");
1179 Op = getNextOperandForReg(Op);
1180
1181 // All defs come before the uses, so stop def_iterator early.
1182 if (!ReturnUses) {
1183 if (Op) {
1184 if (Op->isUse())
1185 Op = nullptr;
1186 else
1187 assert(!Op->isDebug() && "Can't have debug defs");
1188 }
1189 } else {
1190 // If this is an operand we don't care about, skip it.
1191 while (Op && ((!ReturnDefs && Op->isDef()) ||
1192 (SkipDebug && Op->isDebug())))
1193 Op = getNextOperandForReg(Op);
1194 }
1195 }
1196
1197 public:
1199
1200 bool operator==(const defusechain_instr_iterator &x) const {
1201 return Op == x.Op;
1202 }
1203 bool operator!=(const defusechain_instr_iterator &x) const {
1204 return !operator==(x);
1205 }
1206
1207 // Iterator traversal: forward iteration only
1208 defusechain_instr_iterator &operator++() { // Preincrement
1209 assert(Op && "Cannot increment end iterator!");
1210 if (ByInstr) {
1211 MachineInstr *P = Op->getParent();
1212 do {
1213 advance();
1214 } while (Op && Op->getParent() == P);
1215 } else {
1217 getBundleStart(Op->getParent()->getIterator());
1218 do {
1219 advance();
1220 } while (Op && getBundleStart(Op->getParent()->getIterator()) == P);
1221 }
1222
1223 return *this;
1224 }
1225 defusechain_instr_iterator operator++(int) { // Postincrement
1226 defusechain_instr_iterator tmp = *this; ++*this; return tmp;
1227 }
1228
1229 // Retrieve a reference to the current operand.
1231 assert(Op && "Cannot dereference end iterator!");
1232 if (!ByInstr)
1233 return *getBundleStart(Op->getParent()->getIterator());
1234 return *Op->getParent();
1235 }
1236
1237 MachineInstr *operator->() const { return &operator*(); }
1238 };
1239};
1240
1241/// Iterate over the pressure sets affected by the given physical or virtual
1242/// register. If Reg is physical, it must be a register unit (from
1243/// MCRegUnitIterator).
1245 const int *PSet = nullptr;
1246 unsigned Weight = 0;
1247
1248public:
1249 PSetIterator() = default;
1250
1252 const TargetRegisterInfo *TRI = MRI->getTargetRegisterInfo();
1253 if (VRegOrUnit.isVirtualReg()) {
1254 const TargetRegisterClass *RC =
1255 MRI->getRegClass(VRegOrUnit.asVirtualReg());
1256 PSet = TRI->getRegClassPressureSets(RC);
1257 Weight = TRI->getRegClassWeight(RC).RegWeight;
1258 } else {
1259 PSet = TRI->getRegUnitPressureSets(VRegOrUnit.asMCRegUnit());
1260 Weight = TRI->getRegUnitWeight(VRegOrUnit.asMCRegUnit());
1261 }
1262 if (*PSet == -1)
1263 PSet = nullptr;
1264 }
1265
1266 bool isValid() const { return PSet; }
1267
1268 unsigned getWeight() const { return Weight; }
1269
1270 unsigned operator*() const { return *PSet; }
1271
1272 void operator++() {
1273 assert(isValid() && "Invalid PSetIterator.");
1274 ++PSet;
1275 if (*PSet == -1)
1276 PSet = nullptr;
1277 }
1278};
1279
1280inline PSetIterator
1282 return PSetIterator(VRegOrUnit, this);
1283}
1284
1285} // end namespace llvm
1286
1287#endif // LLVM_CODEGEN_MACHINEREGISTERINFO_H
unsigned const MachineRegisterInfo * MRI
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.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:40
bool test(unsigned Idx) const
Definition BitVector.h:480
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 bit of the poin...
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.
StringRef - Represent a constant reference to a string, i.e.
Definition StringRef.h:55
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:45
Wrapper class representing a virtual register or register unit.
Definition Register.h:181
constexpr bool isVirtualReg() const
Definition Register.h:197
constexpr MCRegUnit asMCRegUnit() const
Definition Register.h:201
constexpr Register asVirtualReg() const
Definition Register.h:206
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.
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
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.