LLVM  9.0.0svn
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/DenseMap.h"
19 #include "llvm/ADT/IndexedMap.h"
20 #include "llvm/ADT/PointerUnion.h"
21 #include "llvm/ADT/SmallVector.h"
22 #include "llvm/ADT/StringSet.h"
32 #include "llvm/MC/LaneBitmask.h"
33 #include <cassert>
34 #include <cstddef>
35 #include <cstdint>
36 #include <iterator>
37 #include <memory>
38 #include <utility>
39 #include <vector>
40 
41 namespace llvm {
42 
43 class PSetIterator;
44 
45 /// Convenient type to represent either a register class or a register bank.
46 using RegClassOrRegBank =
48 
49 /// MachineRegisterInfo - Keep track of information for virtual and physical
50 /// registers, including vreg register classes, use/def chains for registers,
51 /// etc.
53 public:
54  class Delegate {
55  virtual void anchor();
56 
57  public:
58  virtual ~Delegate() = default;
59 
60  virtual void MRI_NoteNewVirtualRegister(unsigned Reg) = 0;
61  };
62 
63 private:
64  MachineFunction *MF;
65  Delegate *TheDelegate = nullptr;
66 
67  /// True if subregister liveness is tracked.
68  const bool TracksSubRegLiveness;
69 
70  /// VRegInfo - Information we keep for each virtual register.
71  ///
72  /// Each element in this list contains the register class of the vreg and the
73  /// start of the use/def list for the register.
76  VRegInfo;
77 
78  /// Map for recovering vreg name from vreg number.
79  /// This map is used by the MIR Printer.
81 
82  /// StringSet that is used to unique vreg names.
83  StringSet<> VRegNames;
84 
85  /// The flag is true upon \p UpdatedCSRs initialization
86  /// and false otherwise.
87  bool IsUpdatedCSRsInitialized;
88 
89  /// Contains the updated callee saved register list.
90  /// As opposed to the static list defined in register info,
91  /// all registers that were disabled are removed from the list.
92  SmallVector<MCPhysReg, 16> UpdatedCSRs;
93 
94  /// RegAllocHints - This vector records register allocation hints for
95  /// virtual registers. For each virtual register, it keeps a pair of hint
96  /// type and hints vector making up the allocation hints. Only the first
97  /// hint may be target specific, and in that case this is reflected by the
98  /// first member of the pair being non-zero. If the hinted register is
99  /// virtual, it means the allocator should prefer the physical register
100  /// allocated to it if any.
102  VirtReg2IndexFunctor> RegAllocHints;
103 
104  /// PhysRegUseDefLists - This is an array of the head of the use/def list for
105  /// physical registers.
106  std::unique_ptr<MachineOperand *[]> PhysRegUseDefLists;
107 
108  /// getRegUseDefListHead - Return the head pointer for the register use/def
109  /// list for the specified virtual or physical register.
110  MachineOperand *&getRegUseDefListHead(unsigned RegNo) {
112  return VRegInfo[RegNo].second;
113  return PhysRegUseDefLists[RegNo];
114  }
115 
116  MachineOperand *getRegUseDefListHead(unsigned RegNo) const {
118  return VRegInfo[RegNo].second;
119  return PhysRegUseDefLists[RegNo];
120  }
121 
122  /// Get the next element in the use-def chain.
123  static MachineOperand *getNextOperandForReg(const MachineOperand *MO) {
124  assert(MO && MO->isReg() && "This is not a register operand!");
125  return MO->Contents.Reg.Next;
126  }
127 
128  /// UsedPhysRegMask - Additional used physregs including aliases.
129  /// This bit vector represents all the registers clobbered by function calls.
130  BitVector UsedPhysRegMask;
131 
132  /// ReservedRegs - This is a bit vector of reserved registers. The target
133  /// may change its mind about which registers should be reserved. This
134  /// vector is the frozen set of reserved registers when register allocation
135  /// started.
136  BitVector ReservedRegs;
137 
139  /// Map generic virtual registers to their low-level type.
140  VRegToTypeMap VRegToType;
141 
142  /// Keep track of the physical registers that are live in to the function.
143  /// Live in values are typically arguments in registers. LiveIn values are
144  /// allowed to have virtual registers associated with them, stored in the
145  /// second element.
146  std::vector<std::pair<unsigned, unsigned>> LiveIns;
147 
148 public:
149  explicit MachineRegisterInfo(MachineFunction *MF);
150  MachineRegisterInfo(const MachineRegisterInfo &) = delete;
152 
154  return MF->getSubtarget().getRegisterInfo();
155  }
156 
157  void resetDelegate(Delegate *delegate) {
158  // Ensure another delegate does not take over unless the current
159  // delegate first unattaches itself. If we ever need to multicast
160  // notifications, we will need to change to using a list.
161  assert(TheDelegate == delegate &&
162  "Only the current delegate can perform reset!");
163  TheDelegate = nullptr;
164  }
165 
166  void setDelegate(Delegate *delegate) {
167  assert(delegate && !TheDelegate &&
168  "Attempted to set delegate to null, or to change it without "
169  "first resetting it!");
170 
171  TheDelegate = delegate;
172  }
173 
174  //===--------------------------------------------------------------------===//
175  // Function State
176  //===--------------------------------------------------------------------===//
177 
178  // isSSA - Returns true when the machine function is in SSA form. Early
179  // passes require the machine function to be in SSA form where every virtual
180  // register has a single defining instruction.
181  //
182  // The TwoAddressInstructionPass and PHIElimination passes take the machine
183  // function out of SSA form when they introduce multiple defs per virtual
184  // register.
185  bool isSSA() const {
186  return MF->getProperties().hasProperty(
188  }
189 
190  // leaveSSA - Indicates that the machine function is no longer in SSA form.
191  void leaveSSA() {
193  }
194 
195  /// tracksLiveness - Returns true when tracking register liveness accurately.
196  /// (see MachineFUnctionProperties::Property description for details)
197  bool tracksLiveness() const {
198  return MF->getProperties().hasProperty(
200  }
201 
202  /// invalidateLiveness - Indicates that register liveness is no longer being
203  /// tracked accurately.
204  ///
205  /// This should be called by late passes that invalidate the liveness
206  /// information.
208  MF->getProperties().reset(
210  }
211 
212  /// Returns true if liveness for register class @p RC should be tracked at
213  /// the subregister level.
216  }
217  bool shouldTrackSubRegLiveness(unsigned VReg) const {
218  assert(TargetRegisterInfo::isVirtualRegister(VReg) && "Must pass a VReg");
219  return shouldTrackSubRegLiveness(*getRegClass(VReg));
220  }
221  bool subRegLivenessEnabled() const {
222  return TracksSubRegLiveness;
223  }
224 
225  //===--------------------------------------------------------------------===//
226  // Register Info
227  //===--------------------------------------------------------------------===//
228 
229  /// Returns true if the updated CSR list was initialized and false otherwise.
230  bool isUpdatedCSRsInitialized() const { return IsUpdatedCSRsInitialized; }
231 
232  /// Disables the register from the list of CSRs.
233  /// I.e. the register will not appear as part of the CSR mask.
234  /// \see UpdatedCalleeSavedRegs.
235  void disableCalleeSavedRegister(unsigned Reg);
236 
237  /// Returns list of callee saved registers.
238  /// The function returns the updated CSR list (after taking into account
239  /// registers that are disabled from the CSR list).
240  const MCPhysReg *getCalleeSavedRegs() const;
241 
242  /// Sets the updated Callee Saved Registers list.
243  /// Notice that it will override ant previously disabled/saved CSRs.
245 
246  // Strictly for use by MachineInstr.cpp.
248 
249  // Strictly for use by MachineInstr.cpp.
251 
252  // Strictly for use by MachineInstr.cpp.
253  void moveOperands(MachineOperand *Dst, MachineOperand *Src, unsigned NumOps);
254 
255  /// Verify the sanity of the use list for Reg.
256  void verifyUseList(unsigned Reg) const;
257 
258  /// Verify the use list of all registers.
259  void verifyUseLists() const;
260 
261  /// reg_begin/reg_end - Provide iteration support to walk over all definitions
262  /// and uses of a register within the MachineFunction that corresponds to this
263  /// MachineRegisterInfo object.
264  template<bool Uses, bool Defs, bool SkipDebug,
265  bool ByOperand, bool ByInstr, bool ByBundle>
267  template<bool Uses, bool Defs, bool SkipDebug,
268  bool ByOperand, bool ByInstr, bool ByBundle>
270 
271  // Make it a friend so it can access getNextOperandForReg().
272  template<bool, bool, bool, bool, bool, bool>
273  friend class defusechain_iterator;
274  template<bool, bool, bool, bool, bool, bool>
276 
277  /// reg_iterator/reg_begin/reg_end - Walk all defs and uses of the specified
278  /// register.
279  using reg_iterator =
281  reg_iterator reg_begin(unsigned RegNo) const {
282  return reg_iterator(getRegUseDefListHead(RegNo));
283  }
284  static reg_iterator reg_end() { return reg_iterator(nullptr); }
285 
286  inline iterator_range<reg_iterator> reg_operands(unsigned Reg) const {
287  return make_range(reg_begin(Reg), reg_end());
288  }
289 
290  /// reg_instr_iterator/reg_instr_begin/reg_instr_end - Walk all defs and uses
291  /// of the specified register, stepping by MachineInstr.
292  using reg_instr_iterator =
294  reg_instr_iterator reg_instr_begin(unsigned RegNo) const {
295  return reg_instr_iterator(getRegUseDefListHead(RegNo));
296  }
298  return reg_instr_iterator(nullptr);
299  }
300 
302  reg_instructions(unsigned Reg) const {
303  return make_range(reg_instr_begin(Reg), reg_instr_end());
304  }
305 
306  /// reg_bundle_iterator/reg_bundle_begin/reg_bundle_end - Walk all defs and uses
307  /// of the specified register, stepping by bundle.
308  using reg_bundle_iterator =
310  reg_bundle_iterator reg_bundle_begin(unsigned RegNo) const {
311  return reg_bundle_iterator(getRegUseDefListHead(RegNo));
312  }
314  return reg_bundle_iterator(nullptr);
315  }
316 
319  }
320 
321  /// reg_empty - Return true if there are no instructions using or defining the
322  /// specified register (it may be live-in).
323  bool reg_empty(unsigned RegNo) const { return reg_begin(RegNo) == reg_end(); }
324 
325  /// reg_nodbg_iterator/reg_nodbg_begin/reg_nodbg_end - Walk all defs and uses
326  /// of the specified register, skipping those marked as Debug.
327  using reg_nodbg_iterator =
329  reg_nodbg_iterator reg_nodbg_begin(unsigned RegNo) const {
330  return reg_nodbg_iterator(getRegUseDefListHead(RegNo));
331  }
333  return reg_nodbg_iterator(nullptr);
334  }
335 
337  reg_nodbg_operands(unsigned Reg) const {
338  return make_range(reg_nodbg_begin(Reg), reg_nodbg_end());
339  }
340 
341  /// reg_instr_nodbg_iterator/reg_instr_nodbg_begin/reg_instr_nodbg_end - Walk
342  /// all defs and uses of the specified register, stepping by MachineInstr,
343  /// skipping those marked as Debug.
347  return reg_instr_nodbg_iterator(getRegUseDefListHead(RegNo));
348  }
350  return reg_instr_nodbg_iterator(nullptr);
351  }
352 
354  reg_nodbg_instructions(unsigned Reg) const {
356  }
357 
358  /// reg_bundle_nodbg_iterator/reg_bundle_nodbg_begin/reg_bundle_nodbg_end - Walk
359  /// all defs and uses of the specified register, stepping by bundle,
360  /// skipping those marked as Debug.
364  return reg_bundle_nodbg_iterator(getRegUseDefListHead(RegNo));
365  }
367  return reg_bundle_nodbg_iterator(nullptr);
368  }
369 
371  reg_nodbg_bundles(unsigned Reg) const {
373  }
374 
375  /// reg_nodbg_empty - Return true if the only instructions using or defining
376  /// Reg are Debug instructions.
377  bool reg_nodbg_empty(unsigned RegNo) const {
378  return reg_nodbg_begin(RegNo) == reg_nodbg_end();
379  }
380 
381  /// def_iterator/def_begin/def_end - Walk all defs of the specified register.
382  using def_iterator =
384  def_iterator def_begin(unsigned RegNo) const {
385  return def_iterator(getRegUseDefListHead(RegNo));
386  }
387  static def_iterator def_end() { return def_iterator(nullptr); }
388 
389  inline iterator_range<def_iterator> def_operands(unsigned Reg) const {
390  return make_range(def_begin(Reg), def_end());
391  }
392 
393  /// def_instr_iterator/def_instr_begin/def_instr_end - Walk all defs of the
394  /// specified register, stepping by MachineInst.
395  using def_instr_iterator =
397  def_instr_iterator def_instr_begin(unsigned RegNo) const {
398  return def_instr_iterator(getRegUseDefListHead(RegNo));
399  }
401  return def_instr_iterator(nullptr);
402  }
403 
405  def_instructions(unsigned Reg) const {
406  return make_range(def_instr_begin(Reg), def_instr_end());
407  }
408 
409  /// def_bundle_iterator/def_bundle_begin/def_bundle_end - Walk all defs of the
410  /// specified register, stepping by bundle.
411  using def_bundle_iterator =
413  def_bundle_iterator def_bundle_begin(unsigned RegNo) const {
414  return def_bundle_iterator(getRegUseDefListHead(RegNo));
415  }
417  return def_bundle_iterator(nullptr);
418  }
419 
422  }
423 
424  /// def_empty - Return true if there are no instructions defining the
425  /// specified register (it may be live-in).
426  bool def_empty(unsigned RegNo) const { return def_begin(RegNo) == def_end(); }
427 
428  StringRef getVRegName(unsigned Reg) const {
429  return VReg2Name.inBounds(Reg) ? StringRef(VReg2Name[Reg]) : "";
430  }
431 
432  void insertVRegByName(StringRef Name, unsigned Reg) {
433  assert((Name.empty() || VRegNames.find(Name) == VRegNames.end()) &&
434  "Named VRegs Must be Unique.");
435  if (!Name.empty()) {
436  VRegNames.insert(Name);
437  VReg2Name.grow(Reg);
438  VReg2Name[Reg] = Name.str();
439  }
440  }
441 
442  /// Return true if there is exactly one operand defining the specified
443  /// register.
444  bool hasOneDef(unsigned RegNo) const {
445  def_iterator DI = def_begin(RegNo);
446  if (DI == def_end())
447  return false;
448  return ++DI == def_end();
449  }
450 
451  /// use_iterator/use_begin/use_end - Walk all uses of the specified register.
452  using use_iterator =
454  use_iterator use_begin(unsigned RegNo) const {
455  return use_iterator(getRegUseDefListHead(RegNo));
456  }
457  static use_iterator use_end() { return use_iterator(nullptr); }
458 
459  inline iterator_range<use_iterator> use_operands(unsigned Reg) const {
460  return make_range(use_begin(Reg), use_end());
461  }
462 
463  /// use_instr_iterator/use_instr_begin/use_instr_end - Walk all uses of the
464  /// specified register, stepping by MachineInstr.
465  using use_instr_iterator =
467  use_instr_iterator use_instr_begin(unsigned RegNo) const {
468  return use_instr_iterator(getRegUseDefListHead(RegNo));
469  }
471  return use_instr_iterator(nullptr);
472  }
473 
475  use_instructions(unsigned Reg) const {
476  return make_range(use_instr_begin(Reg), use_instr_end());
477  }
478 
479  /// use_bundle_iterator/use_bundle_begin/use_bundle_end - Walk all uses of the
480  /// specified register, stepping by bundle.
481  using use_bundle_iterator =
483  use_bundle_iterator use_bundle_begin(unsigned RegNo) const {
484  return use_bundle_iterator(getRegUseDefListHead(RegNo));
485  }
487  return use_bundle_iterator(nullptr);
488  }
489 
492  }
493 
494  /// use_empty - Return true if there are no instructions using the specified
495  /// register.
496  bool use_empty(unsigned RegNo) const { return use_begin(RegNo) == use_end(); }
497 
498  /// hasOneUse - Return true if there is exactly one instruction using the
499  /// specified register.
500  bool hasOneUse(unsigned RegNo) const {
501  use_iterator UI = use_begin(RegNo);
502  if (UI == use_end())
503  return false;
504  return ++UI == use_end();
505  }
506 
507  /// use_nodbg_iterator/use_nodbg_begin/use_nodbg_end - Walk all uses of the
508  /// specified register, skipping those marked as Debug.
509  using use_nodbg_iterator =
511  use_nodbg_iterator use_nodbg_begin(unsigned RegNo) const {
512  return use_nodbg_iterator(getRegUseDefListHead(RegNo));
513  }
515  return use_nodbg_iterator(nullptr);
516  }
517 
519  use_nodbg_operands(unsigned Reg) const {
520  return make_range(use_nodbg_begin(Reg), use_nodbg_end());
521  }
522 
523  /// use_instr_nodbg_iterator/use_instr_nodbg_begin/use_instr_nodbg_end - Walk
524  /// all uses of the specified register, stepping by MachineInstr, skipping
525  /// those marked as Debug.
529  return use_instr_nodbg_iterator(getRegUseDefListHead(RegNo));
530  }
532  return use_instr_nodbg_iterator(nullptr);
533  }
534 
536  use_nodbg_instructions(unsigned Reg) const {
538  }
539 
540  /// use_bundle_nodbg_iterator/use_bundle_nodbg_begin/use_bundle_nodbg_end - Walk
541  /// all uses of the specified register, stepping by bundle, skipping
542  /// those marked as Debug.
546  return use_bundle_nodbg_iterator(getRegUseDefListHead(RegNo));
547  }
549  return use_bundle_nodbg_iterator(nullptr);
550  }
551 
553  use_nodbg_bundles(unsigned Reg) const {
555  }
556 
557  /// use_nodbg_empty - Return true if there are no non-Debug instructions
558  /// using the specified register.
559  bool use_nodbg_empty(unsigned RegNo) const {
560  return use_nodbg_begin(RegNo) == use_nodbg_end();
561  }
562 
563  /// hasOneNonDBGUse - Return true if there is exactly one non-Debug
564  /// instruction using the specified register.
565  bool hasOneNonDBGUse(unsigned RegNo) const;
566 
567  /// replaceRegWith - Replace all instances of FromReg with ToReg in the
568  /// machine function. This is like llvm-level X->replaceAllUsesWith(Y),
569  /// except that it also changes any definitions of the register as well.
570  ///
571  /// Note that it is usually necessary to first constrain ToReg's register
572  /// class and register bank to match the FromReg constraints using one of the
573  /// methods:
574  ///
575  /// constrainRegClass(ToReg, getRegClass(FromReg))
576  /// constrainRegAttrs(ToReg, FromReg)
577  /// RegisterBankInfo::constrainGenericRegister(ToReg,
578  /// *MRI.getRegClass(FromReg), MRI)
579  ///
580  /// These functions will return a falsy result if the virtual registers have
581  /// incompatible constraints.
582  ///
583  /// Note that if ToReg is a physical register the function will replace and
584  /// apply sub registers to ToReg in order to obtain a final/proper physical
585  /// register.
586  void replaceRegWith(unsigned FromReg, unsigned ToReg);
587 
588  /// getVRegDef - Return the machine instr that defines the specified virtual
589  /// register or null if none is found. This assumes that the code is in SSA
590  /// form, so there should only be one definition.
591  MachineInstr *getVRegDef(unsigned Reg) const;
592 
593  /// getUniqueVRegDef - Return the unique machine instr that defines the
594  /// specified virtual register or null if none is found. If there are
595  /// multiple definitions or no definition, return null.
596  MachineInstr *getUniqueVRegDef(unsigned Reg) const;
597 
598  /// clearKillFlags - Iterate over all the uses of the given register and
599  /// clear the kill flag from the MachineOperand. This function is used by
600  /// optimization passes which extend register lifetimes and need only
601  /// preserve conservative kill flag information.
602  void clearKillFlags(unsigned Reg) const;
603 
604  void dumpUses(unsigned RegNo) const;
605 
606  /// Returns true if PhysReg is unallocatable and constant throughout the
607  /// function. Writing to a constant register has no effect.
608  bool isConstantPhysReg(unsigned PhysReg) const;
609 
610  /// Returns true if either isConstantPhysReg or TRI->isCallerPreservedPhysReg
611  /// returns true. This is a utility member function.
612  bool isCallerPreservedOrConstPhysReg(unsigned PhysReg) const;
613 
614  /// Get an iterator over the pressure sets affected by the given physical or
615  /// virtual register. If RegUnit is physical, it must be a register unit (from
616  /// MCRegUnitIterator).
617  PSetIterator getPressureSets(unsigned RegUnit) const;
618 
619  //===--------------------------------------------------------------------===//
620  // Virtual Register Info
621  //===--------------------------------------------------------------------===//
622 
623  /// Return the register class of the specified virtual register.
624  /// This shouldn't be used directly unless \p Reg has a register class.
625  /// \see getRegClassOrNull when this might happen.
626  const TargetRegisterClass *getRegClass(unsigned Reg) const {
627  assert(VRegInfo[Reg].first.is<const TargetRegisterClass *>() &&
628  "Register class not set, wrong accessor");
629  return VRegInfo[Reg].first.get<const TargetRegisterClass *>();
630  }
631 
632  /// Return the register class of \p Reg, or null if Reg has not been assigned
633  /// a register class yet.
634  ///
635  /// \note A null register class can only happen when these two
636  /// conditions are met:
637  /// 1. Generic virtual registers are created.
638  /// 2. The machine function has not completely been through the
639  /// instruction selection process.
640  /// None of this condition is possible without GlobalISel for now.
641  /// In other words, if GlobalISel is not used or if the query happens after
642  /// the select pass, using getRegClass is safe.
643  const TargetRegisterClass *getRegClassOrNull(unsigned Reg) const {
644  const RegClassOrRegBank &Val = VRegInfo[Reg].first;
645  return Val.dyn_cast<const TargetRegisterClass *>();
646  }
647 
648  /// Return the register bank of \p Reg, or null if Reg has not been assigned
649  /// a register bank or has been assigned a register class.
650  /// \note It is possible to get the register bank from the register class via
651  /// RegisterBankInfo::getRegBankFromRegClass.
652  const RegisterBank *getRegBankOrNull(unsigned Reg) const {
653  const RegClassOrRegBank &Val = VRegInfo[Reg].first;
654  return Val.dyn_cast<const RegisterBank *>();
655  }
656 
657  /// Return the register bank or register class of \p Reg.
658  /// \note Before the register bank gets assigned (i.e., before the
659  /// RegBankSelect pass) \p Reg may not have either.
660  const RegClassOrRegBank &getRegClassOrRegBank(unsigned Reg) const {
661  return VRegInfo[Reg].first;
662  }
663 
664  /// setRegClass - Set the register class of the specified virtual register.
665  void setRegClass(unsigned Reg, const TargetRegisterClass *RC);
666 
667  /// Set the register bank to \p RegBank for \p Reg.
668  void setRegBank(unsigned Reg, const RegisterBank &RegBank);
669 
670  void setRegClassOrRegBank(unsigned Reg,
671  const RegClassOrRegBank &RCOrRB){
672  VRegInfo[Reg].first = RCOrRB;
673  }
674 
675  /// constrainRegClass - Constrain the register class of the specified virtual
676  /// register to be a common subclass of RC and the current register class,
677  /// but only if the new class has at least MinNumRegs registers. Return the
678  /// new register class, or NULL if no such class exists.
679  /// This should only be used when the constraint is known to be trivial, like
680  /// GR32 -> GR32_NOSP. Beware of increasing register pressure.
681  ///
682  /// \note Assumes that the register has a register class assigned.
683  /// Use RegisterBankInfo::constrainGenericRegister in GlobalISel's
684  /// InstructionSelect pass and constrainRegAttrs in every other pass,
685  /// including non-select passes of GlobalISel, instead.
686  const TargetRegisterClass *constrainRegClass(unsigned Reg,
687  const TargetRegisterClass *RC,
688  unsigned MinNumRegs = 0);
689 
690  /// Constrain the register class or the register bank of the virtual register
691  /// \p Reg (and low-level type) to be a common subclass or a common bank of
692  /// both registers provided respectively (and a common low-level type). Do
693  /// nothing if any of the attributes (classes, banks, or low-level types) of
694  /// the registers are deemed incompatible, or if the resulting register will
695  /// have a class smaller than before and of size less than \p MinNumRegs.
696  /// Return true if such register attributes exist, false otherwise.
697  ///
698  /// \note Use this method instead of constrainRegClass and
699  /// RegisterBankInfo::constrainGenericRegister everywhere but SelectionDAG
700  /// ISel / FastISel and GlobalISel's InstructionSelect pass respectively.
701  bool constrainRegAttrs(unsigned Reg, unsigned ConstrainingReg,
702  unsigned MinNumRegs = 0);
703 
704  /// recomputeRegClass - Try to find a legal super-class of Reg's register
705  /// class that still satisfies the constraints from the instructions using
706  /// Reg. Returns true if Reg was upgraded.
707  ///
708  /// This method can be used after constraints have been removed from a
709  /// virtual register, for example after removing instructions or splitting
710  /// the live range.
711  bool recomputeRegClass(unsigned Reg);
712 
713  /// createVirtualRegister - Create and return a new virtual register in the
714  /// function with the specified register class.
715  unsigned createVirtualRegister(const TargetRegisterClass *RegClass,
716  StringRef Name = "");
717 
718  /// Create and return a new virtual register in the function with the same
719  /// attributes as the given register.
720  unsigned cloneVirtualRegister(unsigned VReg, StringRef Name = "");
721 
722  /// Get the low-level type of \p Reg or LLT{} if Reg is not a generic
723  /// (target independent) virtual register.
724  LLT getType(unsigned Reg) const {
725  if (TargetRegisterInfo::isVirtualRegister(Reg) && VRegToType.inBounds(Reg))
726  return VRegToType[Reg];
727  return LLT{};
728  }
729 
730  /// Set the low-level type of \p VReg to \p Ty.
731  void setType(unsigned VReg, LLT Ty);
732 
733  /// Create and return a new generic virtual register with low-level
734  /// type \p Ty.
735  unsigned createGenericVirtualRegister(LLT Ty, StringRef Name = "");
736 
737  /// Remove all types associated to virtual registers (after instruction
738  /// selection and constraining of all generic virtual registers).
739  void clearVirtRegTypes();
740 
741  /// Creates a new virtual register that has no register class, register bank
742  /// or size assigned yet. This is only allowed to be used
743  /// temporarily while constructing machine instructions. Most operations are
744  /// undefined on an incomplete register until one of setRegClass(),
745  /// setRegBank() or setSize() has been called on it.
747 
748  /// getNumVirtRegs - Return the number of virtual registers created.
749  unsigned getNumVirtRegs() const { return VRegInfo.size(); }
750 
751  /// clearVirtRegs - Remove all virtual registers (after physreg assignment).
752  void clearVirtRegs();
753 
754  /// setRegAllocationHint - Specify a register allocation hint for the
755  /// specified virtual register. This is typically used by target, and in case
756  /// of an earlier hint it will be overwritten.
757  void setRegAllocationHint(unsigned VReg, unsigned Type, unsigned PrefReg) {
759  RegAllocHints[VReg].first = Type;
760  RegAllocHints[VReg].second.clear();
761  RegAllocHints[VReg].second.push_back(PrefReg);
762  }
763 
764  /// addRegAllocationHint - Add a register allocation hint to the hints
765  /// vector for VReg.
766  void addRegAllocationHint(unsigned VReg, unsigned PrefReg) {
768  RegAllocHints[VReg].second.push_back(PrefReg);
769  }
770 
771  /// Specify the preferred (target independent) register allocation hint for
772  /// the specified virtual register.
773  void setSimpleHint(unsigned VReg, unsigned PrefReg) {
774  setRegAllocationHint(VReg, /*Type=*/0, PrefReg);
775  }
776 
777  void clearSimpleHint(unsigned VReg) {
778  assert (RegAllocHints[VReg].first == 0 &&
779  "Expected to clear a non-target hint!");
780  RegAllocHints[VReg].second.clear();
781  }
782 
783  /// getRegAllocationHint - Return the register allocation hint for the
784  /// specified virtual register. If there are many hints, this returns the
785  /// one with the greatest weight.
786  std::pair<unsigned, unsigned>
787  getRegAllocationHint(unsigned VReg) const {
789  unsigned BestHint = (RegAllocHints[VReg].second.size() ?
790  RegAllocHints[VReg].second[0] : 0);
791  return std::pair<unsigned, unsigned>(RegAllocHints[VReg].first, BestHint);
792  }
793 
794  /// getSimpleHint - same as getRegAllocationHint except it will only return
795  /// a target independent hint.
796  unsigned getSimpleHint(unsigned VReg) const {
798  std::pair<unsigned, unsigned> Hint = getRegAllocationHint(VReg);
799  return Hint.first ? 0 : Hint.second;
800  }
801 
802  /// getRegAllocationHints - Return a reference to the vector of all
803  /// register allocation hints for VReg.
804  const std::pair<unsigned, SmallVector<unsigned, 4>>
805  &getRegAllocationHints(unsigned VReg) const {
807  return RegAllocHints[VReg];
808  }
809 
810  /// markUsesInDebugValueAsUndef - Mark every DBG_VALUE referencing the
811  /// specified register as undefined which causes the DBG_VALUE to be
812  /// deleted during LiveDebugVariables analysis.
813  void markUsesInDebugValueAsUndef(unsigned Reg) const;
814 
815  /// Return true if the specified register is modified in this function.
816  /// This checks that no defining machine operands exist for the register or
817  /// any of its aliases. Definitions found on functions marked noreturn are
818  /// ignored, to consider them pass 'true' for optional parameter
819  /// SkipNoReturnDef. The register is also considered modified when it is set
820  /// in the UsedPhysRegMask.
821  bool isPhysRegModified(unsigned PhysReg, bool SkipNoReturnDef = false) const;
822 
823  /// Return true if the specified register is modified or read in this
824  /// function. This checks that no machine operands exist for the register or
825  /// any of its aliases. The register is also considered used when it is set
826  /// in the UsedPhysRegMask.
827  bool isPhysRegUsed(unsigned PhysReg) const;
828 
829  /// addPhysRegsUsedFromRegMask - Mark any registers not in RegMask as used.
830  /// This corresponds to the bit mask attached to register mask operands.
831  void addPhysRegsUsedFromRegMask(const uint32_t *RegMask) {
832  UsedPhysRegMask.setBitsNotInMask(RegMask);
833  }
834 
835  const BitVector &getUsedPhysRegsMask() const { return UsedPhysRegMask; }
836 
837  //===--------------------------------------------------------------------===//
838  // Reserved Register Info
839  //===--------------------------------------------------------------------===//
840  //
841  // The set of reserved registers must be invariant during register
842  // allocation. For example, the target cannot suddenly decide it needs a
843  // frame pointer when the register allocator has already used the frame
844  // pointer register for something else.
845  //
846  // These methods can be used by target hooks like hasFP() to avoid changing
847  // the reserved register set during register allocation.
848 
849  /// freezeReservedRegs - Called by the register allocator to freeze the set
850  /// of reserved registers before allocation begins.
851  void freezeReservedRegs(const MachineFunction&);
852 
853  /// reservedRegsFrozen - Returns true after freezeReservedRegs() was called
854  /// to ensure the set of reserved registers stays constant.
855  bool reservedRegsFrozen() const {
856  return !ReservedRegs.empty();
857  }
858 
859  /// canReserveReg - Returns true if PhysReg can be used as a reserved
860  /// register. Any register can be reserved before freezeReservedRegs() is
861  /// called.
862  bool canReserveReg(unsigned PhysReg) const {
863  return !reservedRegsFrozen() || ReservedRegs.test(PhysReg);
864  }
865 
866  /// getReservedRegs - Returns a reference to the frozen set of reserved
867  /// registers. This method should always be preferred to calling
868  /// TRI::getReservedRegs() when possible.
869  const BitVector &getReservedRegs() const {
871  "Reserved registers haven't been frozen yet. "
872  "Use TRI::getReservedRegs().");
873  return ReservedRegs;
874  }
875 
876  /// isReserved - Returns true when PhysReg is a reserved register.
877  ///
878  /// Reserved registers may belong to an allocatable register class, but the
879  /// target has explicitly requested that they are not used.
880  bool isReserved(unsigned PhysReg) const {
881  return getReservedRegs().test(PhysReg);
882  }
883 
884  /// Returns true when the given register unit is considered reserved.
885  ///
886  /// Register units are considered reserved when for at least one of their
887  /// root registers, the root register and all super registers are reserved.
888  /// This currently iterates the register hierarchy and may be slower than
889  /// expected.
890  bool isReservedRegUnit(unsigned Unit) const;
891 
892  /// isAllocatable - Returns true when PhysReg belongs to an allocatable
893  /// register class and it hasn't been reserved.
894  ///
895  /// Allocatable registers may show up in the allocation order of some virtual
896  /// register, so a register allocator needs to track its liveness and
897  /// availability.
898  bool isAllocatable(unsigned PhysReg) const {
899  return getTargetRegisterInfo()->isInAllocatableClass(PhysReg) &&
900  !isReserved(PhysReg);
901  }
902 
903  //===--------------------------------------------------------------------===//
904  // LiveIn Management
905  //===--------------------------------------------------------------------===//
906 
907  /// addLiveIn - Add the specified register as a live-in. Note that it
908  /// is an error to add the same register to the same set more than once.
909  void addLiveIn(unsigned Reg, unsigned vreg = 0) {
910  LiveIns.push_back(std::make_pair(Reg, vreg));
911  }
912 
913  // Iteration support for the live-ins set. It's kept in sorted order
914  // by register number.
915  using livein_iterator =
916  std::vector<std::pair<unsigned,unsigned>>::const_iterator;
917  livein_iterator livein_begin() const { return LiveIns.begin(); }
918  livein_iterator livein_end() const { return LiveIns.end(); }
919  bool livein_empty() const { return LiveIns.empty(); }
920 
922  return LiveIns;
923  }
924 
925  bool isLiveIn(unsigned Reg) const;
926 
927  /// getLiveInPhysReg - If VReg is a live-in virtual register, return the
928  /// corresponding live-in physical register.
929  unsigned getLiveInPhysReg(unsigned VReg) const;
930 
931  /// getLiveInVirtReg - If PReg is a live-in physical register, return the
932  /// corresponding live-in physical register.
933  unsigned getLiveInVirtReg(unsigned PReg) const;
934 
935  /// EmitLiveInCopies - Emit copies to initialize livein virtual registers
936  /// into the given entry block.
937  void EmitLiveInCopies(MachineBasicBlock *EntryMBB,
938  const TargetRegisterInfo &TRI,
939  const TargetInstrInfo &TII);
940 
941  /// Returns a mask covering all bits that can appear in lane masks of
942  /// subregisters of the virtual register @p Reg.
943  LaneBitmask getMaxLaneMaskForVReg(unsigned Reg) const;
944 
945  /// defusechain_iterator - This class provides iterator support for machine
946  /// operands in the function that use or define a specific register. If
947  /// ReturnUses is true it returns uses of registers, if ReturnDefs is true it
948  /// returns defs. If neither are true then you are silly and it always
949  /// returns end(). If SkipDebug is true it skips uses marked Debug
950  /// when incrementing.
951  template<bool ReturnUses, bool ReturnDefs, bool SkipDebug,
952  bool ByOperand, bool ByInstr, bool ByBundle>
954  : public std::iterator<std::forward_iterator_tag, MachineInstr, ptrdiff_t> {
955  friend class MachineRegisterInfo;
956 
957  MachineOperand *Op = nullptr;
958 
959  explicit defusechain_iterator(MachineOperand *op) : Op(op) {
960  // If the first node isn't one we're interested in, advance to one that
961  // we are interested in.
962  if (op) {
963  if ((!ReturnUses && op->isUse()) ||
964  (!ReturnDefs && op->isDef()) ||
965  (SkipDebug && op->isDebug()))
966  advance();
967  }
968  }
969 
970  void advance() {
971  assert(Op && "Cannot increment end iterator!");
972  Op = getNextOperandForReg(Op);
973 
974  // All defs come before the uses, so stop def_iterator early.
975  if (!ReturnUses) {
976  if (Op) {
977  if (Op->isUse())
978  Op = nullptr;
979  else
980  assert(!Op->isDebug() && "Can't have debug defs");
981  }
982  } else {
983  // If this is an operand we don't care about, skip it.
984  while (Op && ((!ReturnDefs && Op->isDef()) ||
985  (SkipDebug && Op->isDebug())))
986  Op = getNextOperandForReg(Op);
987  }
988  }
989 
990  public:
991  using reference = std::iterator<std::forward_iterator_tag,
993  using pointer = std::iterator<std::forward_iterator_tag,
995 
996  defusechain_iterator() = default;
997 
998  bool operator==(const defusechain_iterator &x) const {
999  return Op == x.Op;
1000  }
1001  bool operator!=(const defusechain_iterator &x) const {
1002  return !operator==(x);
1003  }
1004 
1005  /// atEnd - return true if this iterator is equal to reg_end() on the value.
1006  bool atEnd() const { return Op == nullptr; }
1007 
1008  // Iterator traversal: forward iteration only
1009  defusechain_iterator &operator++() { // Preincrement
1010  assert(Op && "Cannot increment end iterator!");
1011  if (ByOperand)
1012  advance();
1013  else if (ByInstr) {
1014  MachineInstr *P = Op->getParent();
1015  do {
1016  advance();
1017  } while (Op && Op->getParent() == P);
1018  } else if (ByBundle) {
1021  do {
1022  advance();
1023  } while (Op && getBundleStart(Op->getParent()->getIterator()) == P);
1024  }
1025 
1026  return *this;
1027  }
1028  defusechain_iterator operator++(int) { // Postincrement
1029  defusechain_iterator tmp = *this; ++*this; return tmp;
1030  }
1031 
1032  /// getOperandNo - Return the operand # of this MachineOperand in its
1033  /// MachineInstr.
1034  unsigned getOperandNo() const {
1035  assert(Op && "Cannot dereference end iterator!");
1036  return Op - &Op->getParent()->getOperand(0);
1037  }
1038 
1039  // Retrieve a reference to the current operand.
1041  assert(Op && "Cannot dereference end iterator!");
1042  return *Op;
1043  }
1044 
1046  assert(Op && "Cannot dereference end iterator!");
1047  return Op;
1048  }
1049  };
1050 
1051  /// defusechain_iterator - This class provides iterator support for machine
1052  /// operands in the function that use or define a specific register. If
1053  /// ReturnUses is true it returns uses of registers, if ReturnDefs is true it
1054  /// returns defs. If neither are true then you are silly and it always
1055  /// returns end(). If SkipDebug is true it skips uses marked Debug
1056  /// when incrementing.
1057  template<bool ReturnUses, bool ReturnDefs, bool SkipDebug,
1058  bool ByOperand, bool ByInstr, bool ByBundle>
1060  : public std::iterator<std::forward_iterator_tag, MachineInstr, ptrdiff_t> {
1061  friend class MachineRegisterInfo;
1062 
1063  MachineOperand *Op = nullptr;
1064 
1065  explicit defusechain_instr_iterator(MachineOperand *op) : Op(op) {
1066  // If the first node isn't one we're interested in, advance to one that
1067  // we are interested in.
1068  if (op) {
1069  if ((!ReturnUses && op->isUse()) ||
1070  (!ReturnDefs && op->isDef()) ||
1071  (SkipDebug && op->isDebug()))
1072  advance();
1073  }
1074  }
1075 
1076  void advance() {
1077  assert(Op && "Cannot increment end iterator!");
1078  Op = getNextOperandForReg(Op);
1079 
1080  // All defs come before the uses, so stop def_iterator early.
1081  if (!ReturnUses) {
1082  if (Op) {
1083  if (Op->isUse())
1084  Op = nullptr;
1085  else
1086  assert(!Op->isDebug() && "Can't have debug defs");
1087  }
1088  } else {
1089  // If this is an operand we don't care about, skip it.
1090  while (Op && ((!ReturnDefs && Op->isDef()) ||
1091  (SkipDebug && Op->isDebug())))
1092  Op = getNextOperandForReg(Op);
1093  }
1094  }
1095 
1096  public:
1097  using reference = std::iterator<std::forward_iterator_tag,
1099  using pointer = std::iterator<std::forward_iterator_tag,
1101 
1102  defusechain_instr_iterator() = default;
1103 
1105  return Op == x.Op;
1106  }
1108  return !operator==(x);
1109  }
1110 
1111  /// atEnd - return true if this iterator is equal to reg_end() on the value.
1112  bool atEnd() const { return Op == nullptr; }
1113 
1114  // Iterator traversal: forward iteration only
1116  assert(Op && "Cannot increment end iterator!");
1117  if (ByOperand)
1118  advance();
1119  else if (ByInstr) {
1120  MachineInstr *P = Op->getParent();
1121  do {
1122  advance();
1123  } while (Op && Op->getParent() == P);
1124  } else if (ByBundle) {
1127  do {
1128  advance();
1129  } while (Op && getBundleStart(Op->getParent()->getIterator()) == P);
1130  }
1131 
1132  return *this;
1133  }
1134  defusechain_instr_iterator operator++(int) { // Postincrement
1135  defusechain_instr_iterator tmp = *this; ++*this; return tmp;
1136  }
1137 
1138  // Retrieve a reference to the current operand.
1140  assert(Op && "Cannot dereference end iterator!");
1141  if (ByBundle)
1142  return *getBundleStart(Op->getParent()->getIterator());
1143  return *Op->getParent();
1144  }
1145 
1146  MachineInstr *operator->() const { return &operator*(); }
1147  };
1148 };
1149 
1150 /// Iterate over the pressure sets affected by the given physical or virtual
1151 /// register. If Reg is physical, it must be a register unit (from
1152 /// MCRegUnitIterator).
1154  const int *PSet = nullptr;
1155  unsigned Weight = 0;
1156 
1157 public:
1158  PSetIterator() = default;
1159 
1160  PSetIterator(unsigned RegUnit, const MachineRegisterInfo *MRI) {
1161  const TargetRegisterInfo *TRI = MRI->getTargetRegisterInfo();
1163  const TargetRegisterClass *RC = MRI->getRegClass(RegUnit);
1164  PSet = TRI->getRegClassPressureSets(RC);
1165  Weight = TRI->getRegClassWeight(RC).RegWeight;
1166  }
1167  else {
1168  PSet = TRI->getRegUnitPressureSets(RegUnit);
1169  Weight = TRI->getRegUnitWeight(RegUnit);
1170  }
1171  if (*PSet == -1)
1172  PSet = nullptr;
1173  }
1174 
1175  bool isValid() const { return PSet; }
1176 
1177  unsigned getWeight() const { return Weight; }
1178 
1179  unsigned operator*() const { return *PSet; }
1180 
1181  void operator++() {
1182  assert(isValid() && "Invalid PSetIterator.");
1183  ++PSet;
1184  if (*PSet == -1)
1185  PSet = nullptr;
1186  }
1187 };
1188 
1190 getPressureSets(unsigned RegUnit) const {
1191  return PSetIterator(RegUnit, this);
1192 }
1193 
1194 } // end namespace llvm
1195 
1196 #endif // LLVM_CODEGEN_MACHINEREGISTERINFO_H
bool operator!=(const defusechain_iterator &x) const
bool reg_nodbg_empty(unsigned RegNo) const
reg_nodbg_empty - Return true if the only instructions using or defining Reg are Debug instructions...
defusechain_instr_iterator< true, false, false, false, true, false > use_instr_iterator
use_instr_iterator/use_instr_begin/use_instr_end - Walk all uses of the specified register...
defusechain_instr_iterator< true, true, false, false, true, false > reg_instr_iterator
reg_instr_iterator/reg_instr_begin/reg_instr_end - Walk all defs and uses of the specified register...
iterator_range< reg_instr_nodbg_iterator > reg_nodbg_instructions(unsigned Reg) const
Type
MessagePack types as defined in the standard, with the exception of Integer being divided into a sign...
Definition: MsgPackReader.h:48
A common definition of LaneBitmask for use in TableGen and CodeGen.
void EmitLiveInCopies(MachineBasicBlock *EntryMBB, const TargetRegisterInfo &TRI, const TargetInstrInfo &TII)
EmitLiveInCopies - Emit copies to initialize livein virtual registers into the given entry block...
defusechain_iterator< false, true, false, true, false, false > def_iterator
def_iterator/def_begin/def_end - Walk all defs of the specified register.
MachineInstr * getParent()
getParent - Return the instruction that this operand belongs to.
iterator_range< def_bundle_iterator > def_bundles(unsigned Reg) const
use_bundle_iterator use_bundle_begin(unsigned RegNo) const
bool use_nodbg_empty(unsigned RegNo) const
use_nodbg_empty - Return true if there are no non-Debug instructions using the specified register...
LLVM_NODISCARD std::string str() const
str - Get the contents as an std::string.
Definition: StringRef.h:218
const TargetRegisterClass * getRegClass(unsigned Reg) const
Return the register class of the specified virtual register.
livein_iterator livein_begin() const
StorageT::size_type size() const
Definition: IndexedMap.h:77
void removeRegOperandFromUseList(MachineOperand *MO)
Remove MO from its use-def list.
bool isAllocatable(unsigned PhysReg) const
isAllocatable - Returns true when PhysReg belongs to an allocatable register class and it hasn&#39;t been...
void clearVirtRegTypes()
Remove all types associated to virtual registers (after instruction selection and constraining of all...
LaneBitmask getMaxLaneMaskForVReg(unsigned Reg) const
Returns a mask covering all bits that can appear in lane masks of subregisters of the virtual registe...
This class represents lattice values for constants.
Definition: AllocatorList.h:23
MachineFunctionProperties & reset(Property P)
bool empty() const
empty - Tests whether there are no bits in this bitvector.
Definition: BitVector.h:166
PointerUnion< const TargetRegisterClass *, const RegisterBank * > RegClassOrRegBank
Convenient type to represent either a register class or a register bank.
amdgpu Simplify well known AMD library false FunctionCallee Value const Twine & Name
virtual const TargetRegisterInfo * getRegisterInfo() const
getRegisterInfo - If register information is available, return it.
void addLiveIn(unsigned Reg, unsigned vreg=0)
addLiveIn - Add the specified register as a live-in.
const MachineFunctionProperties & getProperties() const
Get the function properties.
bool isPhysRegModified(unsigned PhysReg, bool SkipNoReturnDef=false) const
Return true if the specified register is modified in this function.
This provides a very simple, boring adaptor for a begin and end iterator into a range type...
iterator_range< use_nodbg_iterator > use_nodbg_operands(unsigned Reg) const
iterator_range< use_bundle_iterator > use_bundles(unsigned Reg) const
static bool isVirtualRegister(unsigned Reg)
Return true if the specified register number is in the virtual register namespace.
iterator_range< reg_nodbg_iterator > reg_nodbg_operands(unsigned Reg) const
unsigned Reg
bool test(unsigned Idx) const
Definition: BitVector.h:501
iterator_range< reg_iterator > reg_operands(unsigned Reg) const
iterator find(StringRef Key)
Definition: StringMap.h:332
bool constrainRegAttrs(unsigned Reg, unsigned ConstrainingReg, unsigned MinNumRegs=0)
Constrain the register class or the register bank of the virtual register Reg (and low-level type) to...
void setBitsNotInMask(const uint32_t *Mask, unsigned MaskWords=~0u)
setBitsNotInMask - Add a bit to this vector for every &#39;0&#39; bit in Mask.
Definition: BitVector.h:787
LLT getType(unsigned Reg) const
Get the low-level type of Reg or LLT{} if Reg is not a generic (target independent) virtual register...
virtual const int * getRegClassPressureSets(const TargetRegisterClass *RC) const =0
Get the dimensions of register pressure impacted by this register class.
unsigned const TargetRegisterInfo * TRI
bool hasOneDef(unsigned RegNo) const
Return true if there is exactly one operand defining the specified register.
reg_nodbg_iterator reg_nodbg_begin(unsigned RegNo) const
defusechain_instr_iterator< false, true, false, false, false, true > def_bundle_iterator
def_bundle_iterator/def_bundle_begin/def_bundle_end - Walk all defs of the specified register...
void setRegBank(unsigned Reg, const RegisterBank &RegBank)
Set the register bank to RegBank for Reg.
bool reservedRegsFrozen() const
reservedRegsFrozen - Returns true after freezeReservedRegs() was called to ensure the set of reserved...
#define op(i)
use_nodbg_iterator use_nodbg_begin(unsigned RegNo) const
void verifyUseLists() const
Verify the use list of all registers.
static use_nodbg_iterator use_nodbg_end()
defusechain_instr_iterator< true, false, true, false, false, true > use_bundle_nodbg_iterator
use_bundle_nodbg_iterator/use_bundle_nodbg_begin/use_bundle_nodbg_end - Walk all uses of the specifie...
void clearVirtRegs()
clearVirtRegs - Remove all virtual registers (after physreg assignment).
bool operator==(const defusechain_iterator &x) const
virtual unsigned getRegUnitWeight(unsigned RegUnit) const =0
Get the weight in units of pressure for this register unit.
std::iterator< std::forward_iterator_tag, MachineInstr, ptrdiff_t >::reference reference
T dyn_cast() const
Returns the current pointer if it is of the specified pointer type, otherwises returns null...
Definition: PointerUnion.h:212
static use_iterator use_end()
iterator_range< reg_bundle_nodbg_iterator > reg_nodbg_bundles(unsigned Reg) const
reg_instr_nodbg_iterator reg_instr_nodbg_begin(unsigned RegNo) const
const HexagonInstrInfo * TII
defusechain_instr_iterator< true, true, true, false, true, false > reg_instr_nodbg_iterator
reg_instr_nodbg_iterator/reg_instr_nodbg_begin/reg_instr_nodbg_end - Walk all defs and uses of the sp...
void freezeReservedRegs(const MachineFunction &)
freezeReservedRegs - Called by the register allocator to freeze the set of reserved registers before ...
defusechain_instr_iterator< true, true, false, false, false, true > reg_bundle_iterator
reg_bundle_iterator/reg_bundle_begin/reg_bundle_end - Walk all defs and uses of the specified registe...
def_iterator def_begin(unsigned RegNo) const
LLVM_NODISCARD bool empty() const
empty - Check if the string is empty.
Definition: StringRef.h:126
defusechain_iterator< true, true, true, true, false, false > reg_nodbg_iterator
reg_nodbg_iterator/reg_nodbg_begin/reg_nodbg_end - Walk all defs and uses of the specified register...
APInt operator*(APInt a, uint64_t RHS)
Definition: APInt.h:2090
unsigned getLiveInPhysReg(unsigned VReg) const
getLiveInPhysReg - If VReg is a live-in virtual register, return the corresponding live-in physical r...
static reg_instr_iterator reg_instr_end()
MachineInstr * getVRegDef(unsigned Reg) const
getVRegDef - Return the machine instr that defines the specified virtual register or null if none is ...
defusechain_iterator - This class provides iterator support for machine operands in the function that...
void insertVRegByName(StringRef Name, unsigned Reg)
MachineBasicBlock::instr_iterator getBundleStart(MachineBasicBlock::instr_iterator I)
Returns an iterator to the first instruction in the bundle containing I.
defusechain_iterator< true, false, true, true, false, false > use_nodbg_iterator
use_nodbg_iterator/use_nodbg_begin/use_nodbg_end - Walk all uses of the specified register...
void clearKillFlags(unsigned Reg) const
clearKillFlags - Iterate over all the uses of the given register and clear the kill flag from the Mac...
const RegClassOrRegBank & getRegClassOrRegBank(unsigned Reg) const
Return the register bank or register class of Reg.
use_bundle_nodbg_iterator use_bundle_nodbg_begin(unsigned RegNo) const
iterator_range< def_iterator > def_operands(unsigned Reg) const
livein_iterator livein_end() const
static def_instr_iterator def_instr_end()
PSetIterator(unsigned RegUnit, const MachineRegisterInfo *MRI)
bool canReserveReg(unsigned PhysReg) const
canReserveReg - Returns true if PhysReg can be used as a reserved register.
defusechain_instr_iterator< false, true, false, false, true, false > def_instr_iterator
def_instr_iterator/def_instr_begin/def_instr_end - Walk all defs of the specified register...
std::iterator< std::forward_iterator_tag, MachineInstr, ptrdiff_t >::pointer pointer
void disableCalleeSavedRegister(unsigned Reg)
Disables the register from the list of CSRs.
bool inBounds(IndexT n) const
Definition: IndexedMap.h:73
const TargetRegisterClass * constrainRegClass(unsigned Reg, const TargetRegisterClass *RC, unsigned MinNumRegs=0)
constrainRegClass - Constrain the register class of the specified virtual register to be a common sub...
uint16_t MCPhysReg
An unsigned integer type large enough to represent all physical registers, but not necessarily virtua...
TargetInstrInfo - Interface to description of machine instruction set.
#define P(N)
reg_bundle_iterator reg_bundle_begin(unsigned RegNo) const
const TargetRegisterInfo * getTargetRegisterInfo() const
unsigned const MachineRegisterInfo * MRI
bool isCallerPreservedOrConstPhysReg(unsigned PhysReg) const
Returns true if either isConstantPhysReg or TRI->isCallerPreservedPhysReg returns true...
The instances of the Type class are immutable: once they are created, they are never changed...
Definition: Type.h:45
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
void setType(unsigned VReg, LLT Ty)
Set the low-level type of VReg to Ty.
use_instr_iterator use_instr_begin(unsigned RegNo) const
defusechain_iterator< true, false, false, true, false, false > use_iterator
use_iterator/use_begin/use_end - Walk all uses of the specified register.
bool def_empty(unsigned RegNo) const
def_empty - Return true if there are no instructions defining the specified register (it may be live-...
bool atEnd() const
atEnd - return true if this iterator is equal to reg_end() on the value.
const RegisterBank * getRegBankOrNull(unsigned Reg) const
Return the register bank of Reg, or null if Reg has not been assigned a register bank or has been ass...
self_iterator getIterator()
Definition: ilist_node.h:81
void setCalleeSavedRegs(ArrayRef< MCPhysReg > CSRs)
Sets the updated Callee Saved Registers list.
unsigned getNumVirtRegs() const
getNumVirtRegs - Return the number of virtual registers created.
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
std::iterator< std::forward_iterator_tag, MachineInstr, ptrdiff_t >::reference reference
std::pair< typename base::iterator, bool > insert(StringRef Key)
Definition: StringSet.h:38
bool isConstantPhysReg(unsigned PhysReg) const
Returns true if PhysReg is unallocatable and constant throughout the function.
unsigned first
const bool HasDisjunctSubRegs
Whether the class supports two (or more) disjunct subregister indices.
unsigned createGenericVirtualRegister(LLT Ty, StringRef Name="")
Create and return a new generic virtual register with low-level type Ty.
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
static use_bundle_nodbg_iterator use_bundle_nodbg_end()
struct llvm::MachineOperand::@169::@171 Reg
unsigned createIncompleteVirtualRegister(StringRef Name="")
Creates a new virtual register that has no register class, register bank or size assigned yet...
defusechain_iterator< true, true, false, true, false, false > reg_iterator
reg_iterator/reg_begin/reg_end - Walk all defs and uses of the specified register.
iterator_range< use_iterator > use_operands(unsigned Reg) const
MachineOperand class - Representation of each machine instruction operand.
virtual const RegClassWeight & getRegClassWeight(const TargetRegisterClass *RC) const =0
Get the weight in units of pressure for this register class.
void setRegAllocationHint(unsigned VReg, unsigned Type, unsigned PrefReg)
setRegAllocationHint - Specify a register allocation hint for the specified virtual register...
bool isInAllocatableClass(unsigned RegNo) const
Return true if the register is in the allocation of any register class.
bool atEnd() const
atEnd - return true if this iterator is equal to reg_end() on the value.
static reg_bundle_iterator reg_bundle_end()
bool isReservedRegUnit(unsigned Unit) const
Returns true when the given register unit is considered reserved.
reg_iterator reg_begin(unsigned RegNo) const
void clearSimpleHint(unsigned VReg)
void invalidateLiveness()
invalidateLiveness - Indicates that register liveness is no longer being tracked accurately.
This class implements the register bank concept.
Definition: RegisterBank.h:28
const BitVector & getUsedPhysRegsMask() const
bool recomputeRegClass(unsigned Reg)
recomputeRegClass - Try to find a legal super-class of Reg&#39;s register class that still satisfies the ...
void resetDelegate(Delegate *delegate)
MachineInstr * getUniqueVRegDef(unsigned Reg) const
getUniqueVRegDef - Return the unique machine instr that defines the specified virtual register or nul...
static reg_bundle_nodbg_iterator reg_bundle_nodbg_end()
bool isPhysRegUsed(unsigned PhysReg) const
Return true if the specified register is modified or read in this function.
A range adaptor for a pair of iterators.
iterator_range< reg_bundle_iterator > reg_bundles(unsigned Reg) const
ArrayRef< std::pair< unsigned, unsigned > > liveins() const
unsigned cloneVirtualRegister(unsigned VReg, StringRef Name="")
Create and return a new virtual register in the function with the same attributes as the given regist...
iterator_range< use_bundle_nodbg_iterator > use_nodbg_bundles(unsigned Reg) const
void verifyUseList(unsigned Reg) const
Verify the sanity of the use list for Reg.
bool use_empty(unsigned RegNo) const
use_empty - Return true if there are no instructions using the specified register.
void dumpUses(unsigned RegNo) const
def_instr_iterator def_instr_begin(unsigned RegNo) const
defusechain_instr_iterator< true, true, true, false, false, true > reg_bundle_nodbg_iterator
reg_bundle_nodbg_iterator/reg_bundle_nodbg_begin/reg_bundle_nodbg_end - Walk all defs and uses of the...
void replaceRegWith(unsigned FromReg, unsigned ToReg)
replaceRegWith - Replace all instances of FromReg with ToReg in the machine function.
const BitVector & getReservedRegs() const
getReservedRegs - Returns a reference to the frozen set of reserved registers.
bool operator!=(const defusechain_instr_iterator &x) const
MachineRegisterInfo - Keep track of information for virtual and physical registers, including vreg register classes, use/def chains for registers, etc.
bool isLiveIn(unsigned Reg) const
Representation of each machine instruction.
Definition: MachineInstr.h:63
std::vector< std::pair< unsigned, unsigned > >::const_iterator livein_iterator
unsigned getOperandNo() const
getOperandNo - Return the operand # of this MachineOperand in its MachineInstr.
static reg_instr_nodbg_iterator reg_instr_nodbg_end()
static use_bundle_iterator use_bundle_end()
std::pair< unsigned, unsigned > getRegAllocationHint(unsigned VReg) const
getRegAllocationHint - Return the register allocation hint for the specified virtual register...
bool isUpdatedCSRsInitialized() const
Returns true if the updated CSR list was initialized and false otherwise.
bool hasOneUse(unsigned RegNo) const
hasOneUse - Return true if there is exactly one instruction using the specified register.
use_iterator use_begin(unsigned RegNo) const
Iterate over the pressure sets affected by the given physical or virtual register.
unsigned operator*() const
PSetIterator getPressureSets(unsigned RegUnit) const
Get an iterator over the pressure sets affected by the given physical or virtual register.
bool shouldTrackSubRegLiveness(unsigned VReg) const
virtual const int * getRegUnitPressureSets(unsigned RegUnit) const =0
Get the dimensions of register pressure impacted by this register unit.
void addPhysRegsUsedFromRegMask(const uint32_t *RegMask)
addPhysRegsUsedFromRegMask - Mark any registers not in RegMask as used.
defusechain_instr_iterator< true, false, true, false, true, false > use_instr_nodbg_iterator
use_instr_nodbg_iterator/use_instr_nodbg_begin/use_instr_nodbg_end - Walk all uses of the specified r...
bool tracksLiveness() const
tracksLiveness - Returns true when tracking register liveness accurately.
void markUsesInDebugValueAsUndef(unsigned Reg) const
markUsesInDebugValueAsUndef - Mark every DBG_VALUE referencing the specified register as undefined wh...
bool hasOneNonDBGUse(unsigned RegNo) const
hasOneNonDBGUse - Return true if there is exactly one non-Debug instruction using the specified regis...
void setSimpleHint(unsigned VReg, unsigned PrefReg)
Specify the preferred (target independent) register allocation hint for the specified virtual registe...
bool shouldTrackSubRegLiveness(const TargetRegisterClass &RC) const
Returns true if liveness for register class RC should be tracked at the subregister level...
bool isReg() const
isReg - Tests if this is a MO_Register operand.
Instructions::iterator instr_iterator
static reg_nodbg_iterator reg_nodbg_end()
iterator_range< reg_instr_iterator > reg_instructions(unsigned Reg) const
iterator_range< use_instr_iterator > use_instructions(unsigned Reg) const
void grow(IndexT n)
Definition: IndexedMap.h:67
static use_instr_nodbg_iterator use_instr_nodbg_end()
const TargetRegisterClass * getRegClassOrNull(unsigned Reg) const
Return the register class of Reg, or null if Reg has not been assigned a register class yet...
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
bool hasProperty(Property P) const
static def_iterator def_end()
void addRegAllocationHint(unsigned VReg, unsigned PrefReg)
addRegAllocationHint - Add a register allocation hint to the hints vector for VReg.
use_instr_nodbg_iterator use_instr_nodbg_begin(unsigned RegNo) const
bool operator==(const defusechain_instr_iterator &x) const
MachineRegisterInfo(MachineFunction *MF)
reg_bundle_nodbg_iterator reg_bundle_nodbg_begin(unsigned RegNo) const
const std::pair< unsigned, SmallVector< unsigned, 4 > > & getRegAllocationHints(unsigned VReg) const
getRegAllocationHints - Return a reference to the vector of all register allocation hints for VReg...
void moveOperands(MachineOperand *Dst, MachineOperand *Src, unsigned NumOps)
Move NumOps operands from Src to Dst, updating use-def lists as needed.
static use_instr_iterator use_instr_end()
iterator_range< def_instr_iterator > def_instructions(unsigned Reg) const
const MCPhysReg * getCalleeSavedRegs() const
Returns list of callee saved registers.
bool reg_empty(unsigned RegNo) const
reg_empty - Return true if there are no instructions using or defining the specified register (it may...
def_bundle_iterator def_bundle_begin(unsigned RegNo) const
StringSet - A wrapper for StringMap that provides set-like functionality.
Definition: StringSet.h:27
void setRegClass(unsigned Reg, const TargetRegisterClass *RC)
setRegClass - Set the register class of the specified virtual register.
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:48
void setDelegate(Delegate *delegate)
virtual void MRI_NoteNewVirtualRegister(unsigned Reg)=0
bool operator==(uint64_t V1, const APInt &V2)
Definition: APInt.h:1966
unsigned getWeight() const
defusechain_instr_iterator< true, false, false, false, false, true > use_bundle_iterator
use_bundle_iterator/use_bundle_begin/use_bundle_end - Walk all uses of the specified register...
unsigned getSimpleHint(unsigned VReg) const
getSimpleHint - same as getRegAllocationHint except it will only return a target independent hint...
void setRegClassOrRegBank(unsigned Reg, const RegClassOrRegBank &RCOrRB)
static reg_iterator reg_end()
unsigned getLiveInVirtReg(unsigned PReg) const
getLiveInVirtReg - If PReg is a live-in physical register, return the corresponding live-in physical ...
const MachineOperand & getOperand(unsigned i) const
Definition: MachineInstr.h:415
iterator_range< use_instr_nodbg_iterator > use_nodbg_instructions(unsigned Reg) const
reg_begin/reg_end - Provide iteration support to walk over all definitions and uses of a register wit...
MachineRegisterInfo & operator=(const MachineRegisterInfo &)=delete
reg_instr_iterator reg_instr_begin(unsigned RegNo) const
static def_bundle_iterator def_bundle_end()
StringRef getVRegName(unsigned Reg) const
unsigned createVirtualRegister(const TargetRegisterClass *RegClass, StringRef Name="")
createVirtualRegister - Create and return a new virtual register in the function with the specified r...
std::iterator< std::forward_iterator_tag, MachineInstr, ptrdiff_t >::pointer pointer
bool isReserved(unsigned PhysReg) const
isReserved - Returns true when PhysReg is a reserved register.
A discriminated union of two or more pointer types, with the discriminator in the low bit of the poin...
Definition: PointerUnion.h:163
void addRegOperandToUseList(MachineOperand *MO)
Add MO to the linked list of operands for its register.