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