LLVM 23.0.0git
TargetRegisterInfo.h
Go to the documentation of this file.
1//==- CodeGen/TargetRegisterInfo.h - Target Register Information -*- 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 describes an abstract interface used to get information about a
10// target machines register file. This information is used for a variety of
11// purposed, especially register allocation.
12//
13//===----------------------------------------------------------------------===//
14
15#ifndef LLVM_CODEGEN_TARGETREGISTERINFO_H
16#define LLVM_CODEGEN_TARGETREGISTERINFO_H
17
18#include "llvm/ADT/ArrayRef.h"
20#include "llvm/ADT/StringRef.h"
25#include "llvm/IR/CallingConv.h"
26#include "llvm/MC/LaneBitmask.h"
32#include <cassert>
33#include <cstdint>
34
35namespace llvm {
36
37class BitVector;
38class DIExpression;
39class LiveRegMatrix;
40class MachineFunction;
41class MachineInstr;
42class RegScavenger;
43class VirtRegMap;
44class LiveIntervals;
45class LiveInterval;
47public:
48 using iterator = const MCPhysReg *;
49 using const_iterator = const MCPhysReg *;
50
51 // Instance variables filled by tablegen, do not use!
56 /// Classes with a higher priority value are assigned first by register
57 /// allocators using a greedy heuristic. The value is in the range [0,31].
59
60 // Change allocation priority heuristic used by greedy.
61 const bool GlobalPriority;
62
63 /// Configurable target specific flags.
66 /// Whether the class supports two (or more) disjunct subregister indices.
68 /// Whether a combination of subregisters can cover every register in the
69 /// class. See also the CoveredBySubRegs description in Target.td.
70 const bool CoveredBySubRegs;
71 const unsigned *SuperClasses;
73 ArrayRef<MCPhysReg> (*OrderFunc)(const MachineFunction &, bool Rev);
74
75 /// Return the register class ID number.
76 unsigned getID() const { return MC->getID(); }
77
78 /// begin/end - Return all of the registers in this class.
79 ///
80 iterator begin() const { return MC->begin(); }
81 iterator end() const { return MC->end(); }
82
83 /// Return the number of registers in this class.
84 unsigned getNumRegs() const { return MC->getNumRegs(); }
85
87 return ArrayRef(begin(), getNumRegs());
88 }
89
90 /// Return the specified register in the class.
91 MCRegister getRegister(unsigned i) const {
92 return MC->getRegister(i);
93 }
94
95 /// Return true if the specified register is included in this register class.
96 /// This does not include virtual registers.
97 bool contains(Register Reg) const {
98 /// FIXME: Historically this function has returned false when given vregs
99 /// but it should probably only receive physical registers
100 if (!Reg.isPhysical())
101 return false;
102 return MC->contains(Reg.asMCReg());
103 }
104
105 /// Return true if both registers are in this class.
106 bool contains(Register Reg1, Register Reg2) const {
107 /// FIXME: Historically this function has returned false when given a vregs
108 /// but it should probably only receive physical registers
109 if (!Reg1.isPhysical() || !Reg2.isPhysical())
110 return false;
111 return MC->contains(Reg1.asMCReg(), Reg2.asMCReg());
112 }
113
114 /// Return the cost of copying a value between two registers in this class. If
115 /// this is the maximum value, the register may be impossible to copy.
116 uint8_t getCopyCost() const { return MC->getCopyCost(); }
117
118 /// \return true if register class is very expensive to copy e.g. status flag
119 /// register classes.
121 return MC->getCopyCost() == std::numeric_limits<uint8_t>::max();
122 }
123
124 /// Return true if this register class may be used to create virtual
125 /// registers.
126 bool isAllocatable() const { return MC->isAllocatable(); }
127
128 /// Return true if this register class has a defined BaseClassOrder.
129 bool isBaseClass() const { return MC->isBaseClass(); }
130
131 /// Return true if the specified TargetRegisterClass
132 /// is a proper sub-class of this TargetRegisterClass.
133 bool hasSubClass(const TargetRegisterClass *RC) const {
134 return RC != this && hasSubClassEq(RC);
135 }
136
137 /// Returns true if RC is a sub-class of or equal to this class.
138 bool hasSubClassEq(const TargetRegisterClass *RC) const {
139 unsigned ID = RC->getID();
140 return (SubClassMask[ID / 32] >> (ID % 32)) & 1;
141 }
142
143 /// Return true if the specified TargetRegisterClass is a
144 /// proper super-class of this TargetRegisterClass.
145 bool hasSuperClass(const TargetRegisterClass *RC) const {
146 return RC->hasSubClass(this);
147 }
148
149 /// Returns true if RC is a super-class of or equal to this class.
150 bool hasSuperClassEq(const TargetRegisterClass *RC) const {
151 return RC->hasSubClassEq(this);
152 }
153
154 /// Returns a bit vector of subclasses, including this one.
155 /// The vector is indexed by class IDs.
156 ///
157 /// To use it, consider the returned array as a chunk of memory that
158 /// contains an array of bits of size NumRegClasses. Each 32-bit chunk
159 /// contains a bitset of the ID of the subclasses in big-endian style.
160
161 /// I.e., the representation of the memory from left to right at the
162 /// bit level looks like:
163 /// [31 30 ... 1 0] [ 63 62 ... 33 32] ...
164 /// [ XXX NumRegClasses NumRegClasses - 1 ... ]
165 /// Where the number represents the class ID and XXX bits that
166 /// should be ignored.
167 ///
168 /// See the implementation of hasSubClassEq for an example of how it
169 /// can be used.
170 const uint32_t *getSubClassMask() const {
171 return SubClassMask;
172 }
173
174 /// Returns a 0-terminated list of sub-register indices that project some
175 /// super-register class into this register class. The list has an entry for
176 /// each Idx such that:
177 ///
178 /// There exists SuperRC where:
179 /// For all Reg in SuperRC:
180 /// this->contains(Reg:Idx)
182 return SuperRegIndices;
183 }
184
185 /// Returns a list of super-classes. The
186 /// classes are ordered by ID which is also a topological ordering from large
187 /// to small classes. The list does NOT include the current class.
191
192 /// Return true if this TargetRegisterClass is a subset
193 /// class of at least one other TargetRegisterClass.
194 bool isASubClass() const { return SuperClasses != nullptr; }
195
196 /// Returns the preferred order for allocating registers from this register
197 /// class in MF. The raw order comes directly from the .td file and may
198 /// include reserved registers that are not allocatable.
199 /// Register allocators should also make sure to allocate
200 /// callee-saved registers only after all the volatiles are used. The
201 /// RegisterClassInfo class provides filtered allocation orders with
202 /// callee-saved registers moved to the end.
203 ///
204 /// The MachineFunction argument can be used to tune the allocatable
205 /// registers based on the characteristics of the function, subtarget, or
206 /// other criteria.
207 ///
208 /// By default, this method returns all registers in the class.
210 bool Rev = false) const {
211 return OrderFunc ? OrderFunc(MF, Rev) : getRegisters();
212 }
213
214 /// Returns the combination of all lane masks of register in this class.
215 /// The lane masks of the registers are the combination of all lane masks
216 /// of their subregisters. Returns 1 if there are no subregisters.
218 return LaneMask;
219 }
220};
221
222/// Extra information, not in MCRegisterDesc, about registers.
223/// These are used by codegen, not by MC.
225 const uint8_t *CostPerUse; // Extra cost of instructions using register.
226 unsigned NumCosts; // Number of cost values associated with each register.
227 const bool
228 *InAllocatableClass; // Register belongs to an allocatable regclass.
229};
230
231/// Each TargetRegisterClass has a per register weight, and weight
232/// limit which must be less than the limits of its pressure sets.
234 unsigned RegWeight;
235 unsigned WeightLimit;
236};
237
238/// TargetRegisterInfo base class - We assume that the target defines a static
239/// array of TargetRegisterDesc objects that represent all of the machine
240/// registers that the target has. As such, we simply have to track a pointer
241/// to this array so that we can turn register number into a register
242/// descriptor.
243///
245public:
246 using regclass_iterator = const TargetRegisterClass * const *;
250 unsigned VTListOffset;
251 };
252
253 /// SubRegCoveredBits - Emitted by tablegen: bit range covered by a subreg
254 /// index, -1 in any being invalid.
259
260private:
261 const TargetRegisterInfoDesc *InfoDesc; // Extra desc array for codegen
262 const char *SubRegIndexStrings; // Names of subreg indexes.
263 ArrayRef<uint32_t> SubRegIndexNameOffsets;
264 const SubRegCoveredBits *SubRegIdxRanges; // Pointer to the subreg covered
265 // bit ranges array.
266
267 // Pointer to array of lane masks, one per sub-reg index.
268 const LaneBitmask *SubRegIndexLaneMasks;
269
270 regclass_iterator RegClassBegin, RegClassEnd; // List of regclasses
271 LaneBitmask CoveringLanes;
272 const RegClassInfo *const RCInfos;
273 const MVT::SimpleValueType *const RCVTLists;
274 unsigned HwMode;
275
276protected:
279 const char *SubRegIndexStrings,
280 ArrayRef<uint32_t> SubRegIndexNameOffsets,
281 const SubRegCoveredBits *SubRegIdxRanges,
282 const LaneBitmask *SubRegIndexLaneMasks,
283 LaneBitmask CoveringLanes,
284 const RegClassInfo *const RCInfos,
285 const MVT::SimpleValueType *const RCVTLists,
286 unsigned Mode = 0);
287
288public:
290
291 /// Return the number of registers for the function. (may overestimate)
292 virtual unsigned getNumSupportedRegs(const MachineFunction &) const {
293 return getNumRegs();
294 }
295
296 // Register numbers can represent physical registers, virtual registers, and
297 // sometimes stack slots. The unsigned values are divided into these ranges:
298 //
299 // 0 Not a register, can be used as a sentinel.
300 // [1;2^30) Physical registers assigned by TableGen.
301 // [2^30;2^31) Stack slots. (Rarely used.)
302 // [2^31;2^32) Virtual registers assigned by MachineRegisterInfo.
303 //
304 // Further sentinels can be allocated from the small negative integers.
305 // DenseMapInfo<unsigned> uses -1u and -2u.
306
307 /// Return the size in bits of a register from class RC.
311
312 /// Return the size in bytes of the stack slot allocated to hold a spilled
313 /// copy of a register from class RC.
314 unsigned getSpillSize(const TargetRegisterClass &RC) const {
315 return getRegClassInfo(RC).SpillSize / 8;
316 }
317
318 /// Return the minimum required alignment in bytes for a spill slot for
319 /// a register of this class.
321 return Align(getRegClassInfo(RC).SpillAlignment / 8);
322 }
323
324 /// Return the stack ID for spill slots holding a spilled copy of a register
325 /// from this class.
327 return static_cast<TargetStackID::Value>(RC.SpillStackID);
328 }
329
330 /// Return true if the given TargetRegisterClass has the ValueType T.
332 for (auto I = legalclasstypes_begin(RC); *I != MVT::Other; ++I)
333 if (MVT(*I) == T)
334 return true;
335 return false;
336 }
337
338 /// Return true if the given TargetRegisterClass is compatible with LLT T.
340 for (auto I = legalclasstypes_begin(RC); *I != MVT::Other; ++I) {
341 MVT VT(*I);
342 if (VT == MVT::Untyped)
343 return true;
344
345 if (LLT(VT) == T)
346 return true;
347 }
348 return false;
349 }
350
351 /// Loop over all of the value types that can be represented by values
352 /// in the given register class.
354 return &RCVTLists[getRegClassInfo(RC).VTListOffset];
355 }
356
359 while (*I != MVT::Other)
360 ++I;
361 return I;
362 }
363
364 /// Returns the Register Class of a physical register, picking the smallest
365 /// register subclass that contains this physreg.
366 virtual const TargetRegisterClass *
368
369 /// Returns the common Register Class of two physical registers, picking the
370 /// smallest register subclass that contains these two physregs.
371 const TargetRegisterClass *
373
374 /// Return the maximal subclass of the given register class that is
375 /// allocatable or NULL.
376 const TargetRegisterClass *
378
379 /// Returns a bitset indexed by register number indicating if a register is
380 /// allocatable or not. If a register class is specified, returns the subset
381 /// for the class.
383 const TargetRegisterClass *RC = nullptr) const;
384
385 /// Get a list of cost values for all registers that correspond to the index
386 /// returned by RegisterCostTableIndex.
388 unsigned Idx = getRegisterCostTableIndex(MF);
389 unsigned NumRegs = getNumRegs();
390 assert(Idx < InfoDesc->NumCosts && "CostPerUse index out of bounds");
391
392 return ArrayRef(&InfoDesc->CostPerUse[Idx * NumRegs], NumRegs);
393 }
394
395 /// Return true if the register is in the allocation of any register class.
397 return InfoDesc->InAllocatableClass[RegNo];
398 }
399
400 /// Return the human-readable symbolic target-specific name for the specified
401 /// SubRegIndex.
402 const char *getSubRegIndexName(unsigned SubIdx) const {
403 assert(SubIdx && SubIdx < getNumSubRegIndices() &&
404 "This is not a subregister index");
405 return SubRegIndexStrings + SubRegIndexNameOffsets[SubIdx - 1];
406 }
407
408 /// Get the size of the bit range covered by a sub-register index.
409 /// If the index isn't continuous, return the sum of the sizes of its parts.
410 /// If the index is used to access subregisters of different sizes, return -1.
411 unsigned getSubRegIdxSize(unsigned Idx) const;
412
413 /// Get the offset of the bit range covered by a sub-register index.
414 /// If an Offset doesn't make sense (the index isn't continuous, or is used to
415 /// access sub-registers at different offsets), return -1.
416 unsigned getSubRegIdxOffset(unsigned Idx) const;
417
418 /// Return a bitmask representing the parts of a register that are covered by
419 /// SubIdx \see LaneBitmask.
420 ///
421 /// SubIdx == 0 is allowed, it has the lane mask ~0u.
422 LaneBitmask getSubRegIndexLaneMask(unsigned SubIdx) const {
423 assert(SubIdx < getNumSubRegIndices() && "This is not a subregister index");
424 return SubRegIndexLaneMasks[SubIdx];
425 }
426
427 /// Try to find one or more subregister indexes to cover \p LaneMask.
428 ///
429 /// If this is possible, returns true and appends the best matching set of
430 /// indexes to \p Indexes. If this is not possible, returns false.
431 bool getCoveringSubRegIndexes(const TargetRegisterClass *RC,
432 LaneBitmask LaneMask,
433 SmallVectorImpl<unsigned> &Indexes) const;
434
435 /// The lane masks returned by getSubRegIndexLaneMask() above can only be
436 /// used to determine if sub-registers overlap - they can't be used to
437 /// determine if a set of sub-registers completely cover another
438 /// sub-register.
439 ///
440 /// The X86 general purpose registers have two lanes corresponding to the
441 /// sub_8bit and sub_8bit_hi sub-registers. Both sub_32bit and sub_16bit have
442 /// lane masks '3', but the sub_16bit sub-register doesn't fully cover the
443 /// sub_32bit sub-register.
444 ///
445 /// On the other hand, the ARM NEON lanes fully cover their registers: The
446 /// dsub_0 sub-register is completely covered by the ssub_0 and ssub_1 lanes.
447 /// This is related to the CoveredBySubRegs property on register definitions.
448 ///
449 /// This function returns a bit mask of lanes that completely cover their
450 /// sub-registers. More precisely, given:
451 ///
452 /// Covering = getCoveringLanes();
453 /// MaskA = getSubRegIndexLaneMask(SubA);
454 /// MaskB = getSubRegIndexLaneMask(SubB);
455 ///
456 /// If (MaskA & ~(MaskB & Covering)) == 0, then SubA is completely covered by
457 /// SubB.
458 LaneBitmask getCoveringLanes() const { return CoveringLanes; }
459
460 /// Returns true if the two registers are equal or alias each other.
461 /// The registers may be virtual registers.
462 bool regsOverlap(Register RegA, Register RegB) const {
463 if (RegA == RegB)
464 return true;
465 if (RegA.isPhysical() && RegB.isPhysical())
466 return MCRegisterInfo::regsOverlap(RegA.asMCReg(), RegB.asMCReg());
467 return false;
468 }
469
470 /// Returns true if the two subregisters are equal or overlap.
471 /// The registers may be virtual registers.
472 bool checkSubRegInterference(Register RegA, unsigned SubA, Register RegB,
473 unsigned SubB) const;
474
475 /// Returns true if Reg contains RegUnit.
476 bool hasRegUnit(MCRegister Reg, MCRegUnit RegUnit) const {
477 return llvm::is_contained(regunits(Reg), RegUnit);
478 }
479
480 /// Returns the original SrcReg unless it is the target of a copy-like
481 /// operation, in which case we chain backwards through all such operations
482 /// to the ultimate source register. If a physical register is encountered,
483 /// we stop the search.
484 virtual Register lookThruCopyLike(Register SrcReg,
485 const MachineRegisterInfo *MRI) const;
486
487 /// Find the original SrcReg unless it is the target of a copy-like operation,
488 /// in which case we chain backwards through all such operations to the
489 /// ultimate source register. If a physical register is encountered, we stop
490 /// the search.
491 /// Return the original SrcReg if all the definitions in the chain only have
492 /// one user and not a physical register.
493 virtual Register
494 lookThruSingleUseCopyChain(Register SrcReg,
495 const MachineRegisterInfo *MRI) const;
496
497 /// Return a null-terminated list of all of the callee-saved registers on
498 /// this target. The register should be in the order of desired callee-save
499 /// stack frame offset. The first register is closest to the incoming stack
500 /// pointer if stack grows down, and vice versa.
501 /// Notice: This function does not take into account disabled CSRs.
502 /// In most cases you will want to use instead the function
503 /// getCalleeSavedRegs that is implemented in MachineRegisterInfo.
504 virtual const MCPhysReg*
506
507 /// Return a null-terminated list of all of the callee-saved registers on
508 /// this target when IPRA is on. The list should include any non-allocatable
509 /// registers that the backend uses and assumes will be saved by all calling
510 /// conventions. This is typically the ISA-standard frame pointer, but could
511 /// include the thread pointer, TOC pointer, or base pointer for different
512 /// targets.
513 virtual const MCPhysReg *getIPRACSRegs(const MachineFunction *MF) const {
514 return nullptr;
515 }
516
517 /// Return a mask of call-preserved registers for the given calling convention
518 /// on the current function. The mask should include all call-preserved
519 /// aliases. This is used by the register allocator to determine which
520 /// registers can be live across a call.
521 ///
522 /// The mask is an array containing (TRI::getNumRegs()+31)/32 entries.
523 /// A set bit indicates that all bits of the corresponding register are
524 /// preserved across the function call. The bit mask is expected to be
525 /// sub-register complete, i.e. if A is preserved, so are all its
526 /// sub-registers.
527 ///
528 /// Bits are numbered from the LSB, so the bit for physical register Reg can
529 /// be found as (Mask[Reg / 32] >> Reg % 32) & 1.
530 ///
531 /// A NULL pointer means that no register mask will be used, and call
532 /// instructions should use implicit-def operands to indicate call clobbered
533 /// registers.
534 ///
536 CallingConv::ID) const {
537 // The default mask clobbers everything. All targets should override.
538 return nullptr;
539 }
540
541 /// Return a register mask for the registers preserved by the unwinder,
542 /// or nullptr if no custom mask is needed.
543 virtual const uint32_t *
545 return nullptr;
546 }
547
548 /// Return a register mask that clobbers everything.
549 virtual const uint32_t *getNoPreservedMask() const {
550 llvm_unreachable("target does not provide no preserved mask");
551 }
552
553 /// Return a list of all of the registers which are clobbered "inside" a call
554 /// to the given function. For example, these might be needed for PLT
555 /// sequences of long-branch veneers.
556 virtual ArrayRef<MCPhysReg>
558 return {};
559 }
560
561 /// Return true if all bits that are set in mask \p mask0 are also set in
562 /// \p mask1.
563 bool regmaskSubsetEqual(const uint32_t *mask0, const uint32_t *mask1) const;
564
565 /// Return all the call-preserved register masks defined for this target.
568
569 /// Returns a bitset indexed by physical register number indicating if a
570 /// register is a special register that has particular uses and should be
571 /// considered unavailable at all times, e.g. stack pointer, return address.
572 /// A reserved register:
573 /// - is not allocatable
574 /// - is considered always live
575 /// - is ignored by liveness tracking
576 /// It is often necessary to reserve the super registers of a reserved
577 /// register as well, to avoid them getting allocated indirectly. You may use
578 /// markSuperRegs() and checkAllSuperRegsMarked() in this case.
579 virtual BitVector getReservedRegs(const MachineFunction &MF) const = 0;
580
581 /// Returns either a string explaining why the given register is reserved for
582 /// this function, or an empty optional if no explanation has been written.
583 /// The absence of an explanation does not mean that the register is not
584 /// reserved (meaning, you should check that PhysReg is in fact reserved
585 /// before calling this).
586 virtual std::optional<std::string>
588 return {};
589 }
590
591 /// Returns false if we can't guarantee that Physreg, specified as an IR asm
592 /// clobber constraint, will be preserved across the statement.
593 virtual bool isAsmClobberable(const MachineFunction &MF,
594 MCRegister PhysReg) const {
595 return true;
596 }
597
598 /// Returns true if PhysReg cannot be written to in inline asm statements.
600 MCRegister PhysReg) const {
601 return false;
602 }
603
604 /// Returns true if PhysReg is unallocatable and constant throughout the
605 /// function. Used by MachineRegisterInfo::isConstantPhysReg().
606 virtual bool isConstantPhysReg(MCRegister PhysReg) const { return false; }
607
608 /// Returns true if the register class is considered divergent.
609 virtual bool isDivergentRegClass(const TargetRegisterClass *RC) const {
610 return false;
611 }
612
613 /// Returns true if the register is considered uniform.
614 virtual bool isUniformReg(const MachineRegisterInfo &MRI,
615 const RegisterBankInfo &RBI, Register Reg) const {
616 return false;
617 }
618
619 /// Returns true if MachineLoopInfo should analyze the given physreg
620 /// for loop invariance.
622 return false;
623 }
624
625 /// Physical registers that may be modified within a function but are
626 /// guaranteed to be restored before any uses. This is useful for targets that
627 /// have call sequences where a GOT register may be updated by the caller
628 /// prior to a call and is guaranteed to be restored (also by the caller)
629 /// after the call.
631 const MachineFunction &MF) const {
632 return false;
633 }
634
635 /// This is a wrapper around getCallPreservedMask().
636 /// Return true if the register is preserved after the call.
637 virtual bool isCalleeSavedPhysReg(MCRegister PhysReg,
638 const MachineFunction &MF) const;
639
640 /// Returns true if PhysReg can be used as an argument to a function.
641 virtual bool isArgumentRegister(const MachineFunction &MF,
642 MCRegister PhysReg) const {
643 return false;
644 }
645
646 /// Returns true if PhysReg is a fixed register.
647 virtual bool isFixedRegister(const MachineFunction &MF,
648 MCRegister PhysReg) const {
649 return false;
650 }
651
652 /// Returns true if PhysReg is a general purpose register.
654 MCRegister PhysReg) const {
655 return false;
656 }
657
658 /// Returns true if RC is a class/subclass of general purpose register.
659 virtual bool
661 return false;
662 }
663
664 /// Prior to adding the live-out mask to a stackmap or patchpoint
665 /// instruction, provide the target the opportunity to adjust it (mainly to
666 /// remove pseudo-registers that should be ignored).
667 virtual void adjustStackMapLiveOutMask(uint32_t *Mask) const {}
668
669 /// Return a super-register of register \p Reg such that its sub-register of
670 /// index \p SubIdx is \p Reg.
672 const TargetRegisterClass *RC) const {
673 return MCRegisterInfo::getMatchingSuperReg(Reg, SubIdx, RC->MC);
674 }
675
676 /// Return a subclass of the register class \p A so that each register in it
677 /// has a sub-register of sub-register index \p Idx which is in the register
678 /// class \p B.
679 ///
680 /// TableGen will synthesize missing A sub-classes.
681 virtual const TargetRegisterClass *
682 getMatchingSuperRegClass(const TargetRegisterClass *A,
683 const TargetRegisterClass *B, unsigned Idx) const;
684
685 /// Find a common register class that can accomodate both the source and
686 /// destination operands of a copy-like instruction:
687 ///
688 /// DefRC:DefSubReg = COPY SrcRC:SrcSubReg
689 ///
690 /// This is a generalized form of getMatchingSuperRegClass,
691 /// getCommonSuperRegClass, and getCommonSubClass which handles 0, 1, or 2
692 /// subregister indexes. Those utilities should be preferred if the number of
693 /// non-0 subregister indexes is known.
694 const TargetRegisterClass *
695 findCommonRegClass(const TargetRegisterClass *DefRC, unsigned DefSubReg,
696 const TargetRegisterClass *SrcRC,
697 unsigned SrcSubReg) const;
698
699 // For a copy-like instruction that defines a register of class DefRC with
700 // subreg index DefSubReg, reading from another source with class SrcRC and
701 // subregister SrcSubReg return true if this is a preferable copy
702 // instruction or an earlier use should be used.
703 virtual bool shouldRewriteCopySrc(const TargetRegisterClass *DefRC,
704 unsigned DefSubReg,
705 const TargetRegisterClass *SrcRC,
706 unsigned SrcSubReg) const {
707 // If this source does not incur a cross register bank copy, use it.
708 return findCommonRegClass(DefRC, DefSubReg, SrcRC, SrcSubReg) != nullptr;
709 }
710
711 /// Returns the largest legal sub-class of \p RC that supports the
712 /// sub-register index \p Idx.
713 /// If no such sub-class exists, return NULL.
714 /// If all registers in RC already have an Idx sub-register, return RC.
715 ///
716 /// TableGen generates a version of this function that is good enough in most
717 /// cases. Targets can override if they have constraints that TableGen
718 /// doesn't understand. For example, the x86 sub_8bit sub-register index is
719 /// supported by the full GR32 register class in 64-bit mode, but only by the
720 /// GR32_ABCD regiister class in 32-bit mode.
721 ///
722 /// TableGen will synthesize missing RC sub-classes.
723 virtual const TargetRegisterClass *
724 getSubClassWithSubReg(const TargetRegisterClass *RC, unsigned Idx) const {
725 assert(Idx == 0 && "Target has no sub-registers");
726 return RC;
727 }
728
729 /// Returns the register class of all sub-registers of \p SuperRC obtained by
730 /// applying the sub-register index \p SubRegIdx.
731 ///
732 /// TableGen *may not* synthesize the missing sub-register classes, so this
733 /// function may return null even if SubRegIdx can be applied to all registers
734 /// in SuperRC, i.e., even if
735 /// isSubRegValidForRegClass(SuperRC, SubRegIdx) is true.
736 virtual const TargetRegisterClass *
738 unsigned SubRegIdx) const {
739 return nullptr;
740 }
741
742 /// Returns true if sub-register \p Idx can be used with register class \p RC.
743 /// Idx is valid if the largest subclass of RC that supports sub-register
744 /// index Idx is same as RC. That is, every physical register in RC supports
745 /// sub-register index Idx.
747 unsigned Idx) const {
748 return getSubClassWithSubReg(RC, Idx) == RC;
749 }
750
751 /// Return the subregister index you get from composing
752 /// two subregister indices.
753 ///
754 /// The special null sub-register index composes as the identity.
755 ///
756 /// If R:a:b is the same register as R:c, then composeSubRegIndices(a, b)
757 /// returns c. Note that composeSubRegIndices does not tell you about illegal
758 /// compositions. If R does not have a subreg a, or R:a does not have a subreg
759 /// b, composeSubRegIndices doesn't tell you.
760 ///
761 /// The ARM register Q0 has two D subregs dsub_0:D0 and dsub_1:D1. It also has
762 /// ssub_0:S0 - ssub_3:S3 subregs.
763 /// If you compose subreg indices dsub_1, ssub_0 you get ssub_2.
764 unsigned composeSubRegIndices(unsigned a, unsigned b) const {
765 if (!a) return b;
766 if (!b) return a;
767 return composeSubRegIndicesImpl(a, b);
768 }
769
770 /// Return a subregister index that will compose to give you the subregister
771 /// index.
772 ///
773 /// Finds a subregister index x such that composeSubRegIndices(a, x) ==
774 /// b. Note that this relationship does not hold if
775 /// reverseComposeSubRegIndices returns the null subregister.
776 ///
777 /// The special null sub-register index composes as the identity.
778 unsigned reverseComposeSubRegIndices(unsigned a, unsigned b) const {
779 if (!a)
780 return b;
781 if (!b)
782 return a;
784 }
785
786 /// Transforms a LaneMask computed for one subregister to the lanemask that
787 /// would have been computed when composing the subsubregisters with IdxA
788 /// first. @sa composeSubRegIndices()
790 LaneBitmask Mask) const {
791 if (!IdxA)
792 return Mask;
793 return composeSubRegIndexLaneMaskImpl(IdxA, Mask);
794 }
795
796 /// Transform a lanemask given for a virtual register to the corresponding
797 /// lanemask before using subregister with index \p IdxA.
798 /// This is the reverse of composeSubRegIndexLaneMask(), assuming Mask is a
799 /// valie lane mask (no invalid bits set) the following holds:
800 /// X0 = composeSubRegIndexLaneMask(Idx, Mask)
801 /// X1 = reverseComposeSubRegIndexLaneMask(Idx, X0)
802 /// => X1 == Mask
804 LaneBitmask LaneMask) const {
805 if (!IdxA)
806 return LaneMask;
807 return reverseComposeSubRegIndexLaneMaskImpl(IdxA, LaneMask);
808 }
809
810 /// Debugging helper: dump register in human readable form to dbgs() stream.
811 static void dumpReg(Register Reg, unsigned SubRegIndex = 0,
812 const TargetRegisterInfo *TRI = nullptr);
813
814 /// Return target defined base register class for a physical register.
815 /// This is the register class with the lowest BaseClassOrder containing the
816 /// register.
817 /// Will be nullptr if the register is not in any base register class.
819 return nullptr;
820 }
821
822protected:
823 /// Overridden by TableGen in targets that have sub-registers.
824 virtual unsigned composeSubRegIndicesImpl(unsigned, unsigned) const {
825 llvm_unreachable("Target has no sub-registers");
826 }
827
828 /// Overridden by TableGen in targets that have sub-registers.
829 virtual unsigned reverseComposeSubRegIndicesImpl(unsigned, unsigned) const {
830 llvm_unreachable("Target has no sub-registers");
831 }
832
833 /// Overridden by TableGen in targets that have sub-registers.
834 virtual LaneBitmask
836 llvm_unreachable("Target has no sub-registers");
837 }
838
840 LaneBitmask) const {
841 llvm_unreachable("Target has no sub-registers");
842 }
843
844 /// Return the register cost table index. This implementation is sufficient
845 /// for most architectures and can be overriden by targets in case there are
846 /// multiple cost values associated with each register.
847 virtual unsigned getRegisterCostTableIndex(const MachineFunction &MF) const {
848 return 0;
849 }
850
851public:
852 /// Find a common super-register class if it exists.
853 ///
854 /// Find a register class, SuperRC and two sub-register indices, PreA and
855 /// PreB, such that:
856 ///
857 /// 1. PreA + SubA == PreB + SubB (using composeSubRegIndices()), and
858 ///
859 /// 2. For all Reg in SuperRC: Reg:PreA in RCA and Reg:PreB in RCB, and
860 ///
861 /// 3. SuperRC->getSize() >= max(RCA->getSize(), RCB->getSize()).
862 ///
863 /// SuperRC will be chosen such that no super-class of SuperRC satisfies the
864 /// requirements, and there is no register class with a smaller spill size
865 /// that satisfies the requirements.
866 ///
867 /// SubA and SubB must not be 0. Use getMatchingSuperRegClass() instead.
868 ///
869 /// Either of the PreA and PreB sub-register indices may be returned as 0. In
870 /// that case, the returned register class will be a sub-class of the
871 /// corresponding argument register class.
872 ///
873 /// The function returns NULL if no register class can be found.
875 getCommonSuperRegClass(const TargetRegisterClass *RCA, unsigned SubA,
876 const TargetRegisterClass *RCB, unsigned SubB,
877 unsigned &PreA, unsigned &PreB) const;
878
879 //===--------------------------------------------------------------------===//
880 // Register Class Information
881 //
882protected:
884 return RCInfos[getNumRegClasses() * HwMode + RC.getID()];
885 }
886
887public:
888 /// Register class iterators
889 regclass_iterator regclass_begin() const { return RegClassBegin; }
890 regclass_iterator regclass_end() const { return RegClassEnd; }
894
895 unsigned getNumRegClasses() const {
896 return (unsigned)(regclass_end()-regclass_begin());
897 }
898
899 /// Returns the register class associated with the enumeration value.
900 /// See class MCOperandInfo.
901 const TargetRegisterClass *getRegClass(unsigned i) const {
902 assert(i < getNumRegClasses() && "Register Class ID out of range");
903 return RegClassBegin[i];
904 }
905
906 /// Returns the name of the register class.
907 const char *getRegClassName(const TargetRegisterClass *Class) const {
908 return MCRegisterInfo::getRegClassName(Class->MC);
909 }
910
911 /// Find the largest common subclass of A and B.
912 /// Return NULL if there is no common subclass.
913 const TargetRegisterClass *
914 getCommonSubClass(const TargetRegisterClass *A,
915 const TargetRegisterClass *B) const;
916
917 /// Returns a TargetRegisterClass used for pointer values.
918 /// If a target supports multiple different pointer register classes,
919 /// kind specifies which one is indicated.
920 virtual const TargetRegisterClass *
921 getPointerRegClass(unsigned Kind = 0) const {
922 llvm_unreachable("Target didn't implement getPointerRegClass!");
923 }
924
925 /// Returns a legal register class to copy a register in the specified class
926 /// to or from. If it is possible to copy the register directly without using
927 /// a cross register class copy, return the specified RC. Returns NULL if it
928 /// is not possible to copy between two registers of the specified class.
929 virtual const TargetRegisterClass *
931 return RC;
932 }
933
934 /// Returns the largest super class of RC that is legal to use in the current
935 /// sub-target and has the same spill size.
936 /// The returned register class can be used to create virtual registers which
937 /// means that all its registers can be copied and spilled.
938 virtual const TargetRegisterClass *
940 const MachineFunction &) const {
941 /// The default implementation is very conservative and doesn't allow the
942 /// register allocator to inflate register classes.
943 return RC;
944 }
945
946 /// Return the register pressure "high water mark" for the specific register
947 /// class. The scheduler is in high register pressure mode (for the specific
948 /// register class) if it goes over the limit.
949 ///
950 /// Note: this is the old register pressure model that relies on a manually
951 /// specified representative register class per value type.
952 virtual unsigned getRegPressureLimit(const TargetRegisterClass *RC,
953 MachineFunction &MF) const {
954 return 0;
955 }
956
957 /// Return a heuristic for the machine scheduler to compare the profitability
958 /// of increasing one register pressure set versus another. The scheduler
959 /// will prefer increasing the register pressure of the set which returns
960 /// the largest value for this function.
961 virtual unsigned getRegPressureSetScore(const MachineFunction &MF,
962 unsigned PSetID) const {
963 return PSetID;
964 }
965
966 /// Get the weight in units of pressure for this register class.
968 const TargetRegisterClass *RC) const = 0;
969
970 /// Returns size in bits of a phys/virtual/generic register.
972
973 /// Get the weight in units of pressure for this register unit.
974 virtual unsigned getRegUnitWeight(MCRegUnit RegUnit) const = 0;
975
976 /// Get the number of dimensions of register pressure.
977 virtual unsigned getNumRegPressureSets() const = 0;
978
979 /// Get the name of this register unit pressure set.
980 virtual const char *getRegPressureSetName(unsigned Idx) const = 0;
981
982 /// Get the register unit pressure limit for this dimension.
983 /// This limit must be adjusted dynamically for reserved registers.
984 virtual unsigned getRegPressureSetLimit(const MachineFunction &MF,
985 unsigned Idx) const = 0;
986
987 /// Get the dimensions of register pressure impacted by this register class.
988 /// Returns a -1 terminated array of pressure set IDs.
989 virtual const int *getRegClassPressureSets(
990 const TargetRegisterClass *RC) const = 0;
991
992 /// Get the dimensions of register pressure impacted by this register unit.
993 /// Returns a -1 terminated array of pressure set IDs.
994 virtual const int *getRegUnitPressureSets(MCRegUnit RegUnit) const = 0;
995
996 /// Get the scale factor of spill weight for this register class.
997 virtual float getSpillWeightScaleFactor(const TargetRegisterClass *RC) const;
998
999 /// Get a list of 'hint' registers that the register allocator should try
1000 /// first when allocating a physical register for the virtual register
1001 /// VirtReg. These registers are effectively moved to the front of the
1002 /// allocation order. If true is returned, regalloc will try to only use
1003 /// hints to the greatest extent possible even if it means spilling.
1004 ///
1005 /// The Order argument is the allocation order for VirtReg's register class
1006 /// as returned from RegisterClassInfo::getOrder(). The hint registers must
1007 /// come from Order, and they must not be reserved.
1008 ///
1009 /// The default implementation of this function will only add target
1010 /// independent register allocation hints. Targets that override this
1011 /// function should typically call this default implementation as well and
1012 /// expect to see generic copy hints added.
1013 virtual bool
1016 const MachineFunction &MF,
1017 const VirtRegMap *VRM = nullptr,
1018 const LiveRegMatrix *Matrix = nullptr) const;
1019
1020 /// A callback to allow target a chance to update register allocation hints
1021 /// when a register is "changed" (e.g. coalesced) to another register.
1022 /// e.g. On ARM, some virtual registers should target register pairs,
1023 /// if one of pair is coalesced to another register, the allocation hint of
1024 /// the other half of the pair should be changed to point to the new register.
1026 MachineFunction &MF) const {
1027 // Do nothing.
1028 }
1029
1030 /// Allow the target to reverse allocation order of local live ranges. This
1031 /// will generally allocate shorter local live ranges first. For targets with
1032 /// many registers, this could reduce regalloc compile time by a large
1033 /// factor. It is disabled by default for three reasons:
1034 /// (1) Top-down allocation is simpler and easier to debug for targets that
1035 /// don't benefit from reversing the order.
1036 /// (2) Bottom-up allocation could result in poor evicition decisions on some
1037 /// targets affecting the performance of compiled code.
1038 /// (3) Bottom-up allocation is no longer guaranteed to optimally color.
1039 virtual bool reverseLocalAssignment() const { return false; }
1040
1041 /// Allow the target to override the cost of using a callee-saved register for
1042 /// the first time. Default value of 0 means we will use a callee-saved
1043 /// register if it is available.
1044 virtual unsigned getCSRFirstUseCost() const { return 0; }
1045 /// FIXME: We should deprecate this usage.
1046 virtual unsigned getCSRCost() const { return 0; }
1047
1048 /// Returns true if the target requires (and can make use of) the register
1049 /// scavenger.
1050 virtual bool requiresRegisterScavenging(const MachineFunction &MF) const {
1051 return false;
1052 }
1053
1054 /// Returns true if the target wants to use frame pointer based accesses to
1055 /// spill to the scavenger emergency spill slot.
1056 virtual bool useFPForScavengingIndex(const MachineFunction &MF) const {
1057 return true;
1058 }
1059
1060 /// Returns true if the target requires post PEI scavenging of registers for
1061 /// materializing frame index constants.
1062 virtual bool requiresFrameIndexScavenging(const MachineFunction &MF) const {
1063 return false;
1064 }
1065
1066 /// Returns true if the target requires using the RegScavenger directly for
1067 /// frame elimination despite using requiresFrameIndexScavenging.
1069 const MachineFunction &MF) const {
1070 return false;
1071 }
1072
1073 /// Returns true if the target wants the LocalStackAllocation pass to be run
1074 /// and virtual base registers used for more efficient stack access.
1075 virtual bool requiresVirtualBaseRegisters(const MachineFunction &MF) const {
1076 return false;
1077 }
1078
1079 /// Return true if target has reserved a spill slot in the stack frame of
1080 /// the given function for the specified register. e.g. On x86, if the frame
1081 /// register is required, the first fixed stack object is reserved as its
1082 /// spill slot. This tells PEI not to create a new stack frame
1083 /// object for the given register. It should be called only after
1084 /// determineCalleeSaves().
1086 int &FrameIdx) const {
1087 return false;
1088 }
1089
1090 /// Returns true if the live-ins should be tracked after register allocation.
1091 virtual bool trackLivenessAfterRegAlloc(const MachineFunction &MF) const {
1092 return true;
1093 }
1094
1095 /// True if the stack can be realigned for the target.
1096 virtual bool canRealignStack(const MachineFunction &MF) const;
1097
1098 /// True if storage within the function requires the stack pointer to be
1099 /// aligned more than the normal calling convention calls for.
1100 virtual bool shouldRealignStack(const MachineFunction &MF) const;
1101
1102 /// True if stack realignment is required and still possible.
1103 bool hasStackRealignment(const MachineFunction &MF) const {
1104 return shouldRealignStack(MF) && canRealignStack(MF);
1105 }
1106
1107 /// Get the offset from the referenced frame index in the instruction,
1108 /// if there is one.
1110 int Idx) const {
1111 return 0;
1112 }
1113
1114 /// Returns true if the instruction's frame index reference would be better
1115 /// served by a base register other than FP or SP.
1116 /// Used by LocalStackFrameAllocation to determine which frame index
1117 /// references it should create new base registers for.
1118 virtual bool needsFrameBaseReg(MachineInstr *MI, int64_t Offset) const {
1119 return false;
1120 }
1121
1122 /// Insert defining instruction(s) for a pointer to FrameIdx before
1123 /// insertion point I. Return materialized frame pointer.
1125 int FrameIdx,
1126 int64_t Offset) const {
1127 llvm_unreachable("materializeFrameBaseRegister does not exist on this "
1128 "target");
1129 }
1130
1131 /// Resolve a frame index operand of an instruction
1132 /// to reference the indicated base register plus offset instead.
1134 int64_t Offset) const {
1135 llvm_unreachable("resolveFrameIndex does not exist on this target");
1136 }
1137
1138 /// Determine whether a given base register plus offset immediate is
1139 /// encodable to resolve a frame index.
1140 virtual bool isFrameOffsetLegal(const MachineInstr *MI, Register BaseReg,
1141 int64_t Offset) const {
1142 llvm_unreachable("isFrameOffsetLegal does not exist on this target");
1143 }
1144
1145 /// Gets the DWARF expression opcodes for \p Offset.
1146 virtual void getOffsetOpcodes(const StackOffset &Offset,
1148
1149 /// Prepends a DWARF expression for \p Offset to DIExpression \p Expr.
1150 DIExpression *
1151 prependOffsetExpression(const DIExpression *Expr, unsigned PrependFlags,
1152 const StackOffset &Offset) const;
1153
1154 virtual int64_t getDwarfRegNumForVirtReg(Register RegNum, bool isEH) const {
1155 llvm_unreachable("getDwarfRegNumForVirtReg does not exist on this target");
1156 }
1157
1158 /// Spill the register so it can be used by the register scavenger.
1159 /// Return true if the register was spilled, false otherwise.
1160 /// If this function does not spill the register, the scavenger
1161 /// will instead spill it to the emergency spill slot.
1165 const TargetRegisterClass *RC,
1166 Register Reg) const {
1167 return false;
1168 }
1169
1170 /// Process frame indices in reverse block order. This changes the behavior of
1171 /// the RegScavenger passed to eliminateFrameIndex. If this is true targets
1172 /// should scavengeRegisterBackwards in eliminateFrameIndex. New targets
1173 /// should prefer reverse scavenging behavior.
1174 /// TODO: Remove this when all targets return true.
1175 virtual bool eliminateFrameIndicesBackwards() const { return true; }
1176
1177 /// This method must be overriden to eliminate abstract frame indices from
1178 /// instructions which may use them. The instruction referenced by the
1179 /// iterator contains an MO_FrameIndex operand which must be eliminated by
1180 /// this method. This method may modify or replace the specified instruction,
1181 /// as long as it keeps the iterator pointing at the finished product.
1182 /// SPAdj is the SP adjustment due to call frame setup instruction.
1183 /// FIOperandNum is the FI operand number.
1184 /// Returns true if the current instruction was removed and the iterator
1185 /// is not longer valid
1187 int SPAdj, unsigned FIOperandNum,
1188 RegScavenger *RS = nullptr) const = 0;
1189
1190 /// Return the assembly name for \p Reg.
1192 // FIXME: We are assuming that the assembly name is equal to the TableGen
1193 // name converted to lower case
1194 //
1195 // The TableGen name is the name of the definition for this register in the
1196 // target's tablegen files. For example, the TableGen name of
1197 // def EAX : Register <...>; is "EAX"
1198 return StringRef(getName(Reg));
1199 }
1200
1201 //===--------------------------------------------------------------------===//
1202 /// Subtarget Hooks
1203
1204 /// SrcRC and DstRC will be morphed into NewRC if this returns true.
1206 const TargetRegisterClass *SrcRC,
1207 unsigned SubReg,
1208 const TargetRegisterClass *DstRC,
1209 unsigned DstSubReg,
1210 const TargetRegisterClass *NewRC,
1211 LiveIntervals &LIS) const
1212 { return true; }
1213
1214 /// Region split has a high compile time cost especially for large live range.
1215 /// This method is used to decide whether or not \p VirtReg should
1216 /// go through this expensive splitting heuristic.
1217 virtual bool shouldRegionSplitForVirtReg(const MachineFunction &MF,
1218 const LiveInterval &VirtReg) const;
1219
1220 /// Last chance recoloring has a high compile time cost especially for
1221 /// targets with a lot of registers.
1222 /// This method is used to decide whether or not \p VirtReg should
1223 /// go through this expensive heuristic.
1224 /// When this target hook is hit, by returning false, there is a high
1225 /// chance that the register allocation will fail altogether (usually with
1226 /// "ran out of registers").
1227 /// That said, this error usually points to another problem in the
1228 /// optimization pipeline.
1229 virtual bool
1231 const LiveInterval &VirtReg) const {
1232 return true;
1233 }
1234
1235 /// When prioritizing live ranges in register allocation, if this hook returns
1236 /// true then the AllocationPriority of the register class will be treated as
1237 /// more important than whether the range is local to a basic block or global.
1238 virtual bool
1240 return false;
1241 }
1242
1243 //===--------------------------------------------------------------------===//
1244 /// Debug information queries.
1245
1246 /// getFrameRegister - This method should return the register used as a base
1247 /// for values allocated in the current stack frame.
1248 virtual Register getFrameRegister(const MachineFunction &MF) const = 0;
1249
1250 /// Mark a register and all its aliases as reserved in the given set.
1251 void markSuperRegs(BitVector &RegisterSet, MCRegister Reg) const;
1252
1253 /// Returns true if for every register in the set all super registers are part
1254 /// of the set as well.
1255 bool checkAllSuperRegsMarked(const BitVector &RegisterSet,
1256 ArrayRef<MCPhysReg> Exceptions = ArrayRef<MCPhysReg>()) const;
1257
1258 virtual const TargetRegisterClass *
1260 const MachineRegisterInfo &MRI) const {
1261 return nullptr;
1262 }
1263
1264 /// Some targets have non-allocatable registers that aren't technically part
1265 /// of the explicit callee saved register list, but should be handled as such
1266 /// in certain cases.
1268 return false;
1269 }
1270
1271 /// Some targets delay assigning the frame until late and use a placeholder
1272 /// to represent it earlier. This method can be used to identify the frame
1273 /// register placeholder.
1274 virtual bool isVirtualFrameRegister(MCRegister Reg) const { return false; }
1275
1276 virtual std::optional<uint8_t> getVRegFlagValue(StringRef Name) const {
1277 return {};
1278 }
1279
1282 return {};
1283 }
1284
1285 // Whether this register should be ignored when generating CodeView debug
1286 // info, because it's a known there is no mapping available.
1287 virtual bool isIgnoredCVReg(MCRegister LLVMReg) const { return false; }
1288};
1289
1290//===----------------------------------------------------------------------===//
1291// SuperRegClassIterator
1292//===----------------------------------------------------------------------===//
1293//
1294// Iterate over the possible super-registers for a given register class. The
1295// iterator will visit a list of pairs (Idx, Mask) corresponding to the
1296// possible classes of super-registers.
1297//
1298// Each bit mask will have at least one set bit, and each set bit in Mask
1299// corresponds to a SuperRC such that:
1300//
1301// For all Reg in SuperRC: Reg:Idx is in RC.
1302//
1303// The iterator can include (O, RC->getSubClassMask()) as the first entry which
1304// also satisfies the above requirement, assuming Reg:0 == Reg.
1305//
1307 const unsigned RCMaskWords;
1308 unsigned SubReg = 0;
1309 const uint16_t *Idx;
1310 const uint32_t *Mask;
1311
1312public:
1313 /// Create a SuperRegClassIterator that visits all the super-register classes
1314 /// of RC. When IncludeSelf is set, also include the (0, sub-classes) entry.
1316 const TargetRegisterInfo *TRI,
1317 bool IncludeSelf = false)
1318 : RCMaskWords((TRI->getNumRegClasses() + 31) / 32),
1319 Idx(RC->getSuperRegIndices()), Mask(RC->getSubClassMask()) {
1320 if (!IncludeSelf)
1321 ++*this;
1322 }
1323
1324 /// Returns true if this iterator is still pointing at a valid entry.
1325 bool isValid() const { return Idx; }
1326
1327 /// Returns the current sub-register index.
1328 unsigned getSubReg() const { return SubReg; }
1329
1330 /// Returns the bit mask of register classes that getSubReg() projects into
1331 /// RC.
1332 /// See TargetRegisterClass::getSubClassMask() for how to use it.
1333 const uint32_t *getMask() const { return Mask; }
1334
1335 /// Advance iterator to the next entry.
1336 void operator++() {
1337 assert(isValid() && "Cannot move iterator past end.");
1338 Mask += RCMaskWords;
1339 SubReg = *Idx++;
1340 if (!SubReg)
1341 Idx = nullptr;
1342 }
1343};
1344
1345//===----------------------------------------------------------------------===//
1346// BitMaskClassIterator
1347//===----------------------------------------------------------------------===//
1348/// This class encapuslates the logic to iterate over bitmask returned by
1349/// the various RegClass related APIs.
1350/// E.g., this class can be used to iterate over the subclasses provided by
1351/// TargetRegisterClass::getSubClassMask or SuperRegClassIterator::getMask.
1353 /// Total number of register classes.
1354 const unsigned NumRegClasses;
1355 /// Base index of CurrentChunk.
1356 /// In other words, the number of bit we read to get at the
1357 /// beginning of that chunck.
1358 unsigned Base = 0;
1359 /// Adjust base index of CurrentChunk.
1360 /// Base index + how many bit we read within CurrentChunk.
1361 unsigned Idx = 0;
1362 /// Current register class ID.
1363 unsigned ID = 0;
1364 /// Mask we are iterating over.
1365 const uint32_t *Mask;
1366 /// Current chunk of the Mask we are traversing.
1367 uint32_t CurrentChunk;
1368
1369 /// Move ID to the next set bit.
1370 void moveToNextID() {
1371 // If the current chunk of memory is empty, move to the next one,
1372 // while making sure we do not go pass the number of register
1373 // classes.
1374 while (!CurrentChunk) {
1375 // Move to the next chunk.
1376 Base += 32;
1377 if (Base >= NumRegClasses) {
1378 ID = NumRegClasses;
1379 return;
1380 }
1381 CurrentChunk = *++Mask;
1382 Idx = Base;
1383 }
1384 // Otherwise look for the first bit set from the right
1385 // (representation of the class ID is big endian).
1386 // See getSubClassMask for more details on the representation.
1387 unsigned Offset = llvm::countr_zero(CurrentChunk);
1388 // Add the Offset to the adjusted base number of this chunk: Idx.
1389 // This is the ID of the register class.
1390 ID = Idx + Offset;
1391
1392 // Consume the zeros, if any, and the bit we just read
1393 // so that we are at the right spot for the next call.
1394 // Do not do Offset + 1 because Offset may be 31 and 32
1395 // will be UB for the shift, though in that case we could
1396 // have make the chunk being equal to 0, but that would
1397 // have introduced a if statement.
1398 moveNBits(Offset);
1399 moveNBits(1);
1400 }
1401
1402 /// Move \p NumBits Bits forward in CurrentChunk.
1403 void moveNBits(unsigned NumBits) {
1404 assert(NumBits < 32 && "Undefined behavior spotted!");
1405 // Consume the bit we read for the next call.
1406 CurrentChunk >>= NumBits;
1407 // Adjust the base for the chunk.
1408 Idx += NumBits;
1409 }
1410
1411public:
1412 /// Create a BitMaskClassIterator that visits all the register classes
1413 /// represented by \p Mask.
1414 ///
1415 /// \pre \p Mask != nullptr
1417 : NumRegClasses(TRI.getNumRegClasses()), Mask(Mask), CurrentChunk(*Mask) {
1418 // Move to the first ID.
1419 moveToNextID();
1420 }
1421
1422 /// Returns true if this iterator is still pointing at a valid entry.
1423 bool isValid() const { return getID() != NumRegClasses; }
1424
1425 /// Returns the current register class ID.
1426 unsigned getID() const { return ID; }
1427
1428 /// Advance iterator to the next entry.
1429 void operator++() {
1430 assert(isValid() && "Cannot move iterator past end.");
1431 moveToNextID();
1432 }
1433};
1434
1435// This is useful when building IndexedMaps keyed on virtual registers
1438 unsigned operator()(Register Reg) const { return Reg.virtRegIndex(); }
1439};
1440
1441/// Prints virtual and physical registers with or without a TRI instance.
1442///
1443/// The format is:
1444/// %noreg - NoRegister
1445/// %5 - a virtual register.
1446/// %5:sub_8bit - a virtual register with sub-register index (with TRI).
1447/// %eax - a physical register
1448/// %physreg17 - a physical register when no TRI instance given.
1449///
1450/// Usage: OS << printReg(Reg, TRI, SubRegIdx) << '\n';
1451LLVM_ABI Printable printReg(Register Reg,
1452 const TargetRegisterInfo *TRI = nullptr,
1453 unsigned SubIdx = 0,
1454 const MachineRegisterInfo *MRI = nullptr);
1455
1456/// Create Printable object to print register units on a \ref raw_ostream.
1457///
1458/// Register units are named after their root registers:
1459///
1460/// al - Single root.
1461/// fp0~st7 - Dual roots.
1462///
1463/// Usage: OS << printRegUnit(Unit, TRI) << '\n';
1464LLVM_ABI Printable printRegUnit(MCRegUnit Unit, const TargetRegisterInfo *TRI);
1465
1466/// Create Printable object to print virtual registers and physical
1467/// registers on a \ref raw_ostream.
1468LLVM_ABI Printable printVRegOrUnit(VirtRegOrUnit VRegOrUnit,
1469 const TargetRegisterInfo *TRI);
1470
1471/// Create Printable object to print register classes or register banks
1472/// on a \ref raw_ostream.
1474 const MachineRegisterInfo &RegInfo,
1475 const TargetRegisterInfo *TRI);
1476
1477} // end namespace llvm
1478
1479#endif // LLVM_CODEGEN_TARGETREGISTERINFO_H
MachineInstrBuilder & UseMI
unsigned RegSize
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
MachineBasicBlock & MBB
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
#define LLVM_ABI
Definition Compiler.h:213
IRTranslator LLVM IR MI
const AbstractManglingParser< Derived, Alloc >::OperatorInfo AbstractManglingParser< Derived, Alloc >::Ops[]
A common definition of LaneBitmask for use in TableGen and CodeGen.
Live Register Matrix
#define I(x, y, z)
Definition MD5.cpp:57
Register Reg
Register const TargetRegisterInfo * TRI
Promote Memory to Register
Definition Mem2Reg.cpp:110
#define T
static StringRef getName(Value *V)
static cl::opt< RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode > Mode("regalloc-enable-advisor", cl::Hidden, cl::init(RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode::Default), cl::desc("Enable regalloc advisor mode"), cl::values(clEnumValN(RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode::Default, "default", "Default"), clEnumValN(RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode::Release, "release", "precompiled"), clEnumValN(RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode::Development, "development", "for training")))
This file defines the SmallVector class.
static const TargetRegisterClass * getCommonMinimalPhysRegClass(const TargetRegisterInfo *TRI, MCRegister Reg1, MCRegister Reg2)
Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:40
void operator++()
Advance iterator to the next entry.
unsigned getID() const
Returns the current register class ID.
BitMaskClassIterator(const uint32_t *Mask, const TargetRegisterInfo &TRI)
Create a BitMaskClassIterator that visits all the register classes represented by Mask.
bool isValid() const
Returns true if this iterator is still pointing at a valid entry.
DWARF expression.
LiveInterval - This class represents the liveness of a register, or stack slot.
MCRegisterClass - Base class of TargetRegisterClass.
MCRegisterInfo base class - We assume that the target defines a static array of MCRegisterDesc object...
unsigned getNumSubRegIndices() const
Return the number of sub-register indices understood by the target.
bool regsOverlap(MCRegister RegA, MCRegister RegB) const
Returns true if the two registers are equal or alias each other.
MCRegister getMatchingSuperReg(MCRegister Reg, unsigned SubIdx, const MCRegisterClass *RC) const
Return a super-register of the specified register Reg so its sub-register of index SubIdx is Reg.
iota_range< MCRegUnit > regunits() const
Returns an iterator range over all regunits.
const char * getRegClassName(const MCRegisterClass *Class) const
unsigned getNumRegs() const
Return the number of registers this target has (useful for sizing arrays holding per register informa...
Wrapper class representing physical registers. Should be passed by value.
Definition MCRegister.h:41
Machine Value Type.
MachineInstrBundleIterator< MachineInstr > iterator
Representation of each machine instruction.
MachineOperand class - Representation of each machine instruction operand.
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
Holds all the information related to register banks.
Wrapper class representing virtual and physical registers.
Definition Register.h:20
MCRegister asMCReg() const
Utility to check-convert this value to a MCRegister.
Definition Register.h:107
constexpr bool isPhysical() const
Return true if the specified register number is in the physical register namespace.
Definition Register.h:83
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
StackOffset holds a fixed and a scalable offset in bytes.
Definition TypeSize.h:30
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
void operator++()
Advance iterator to the next entry.
unsigned getSubReg() const
Returns the current sub-register index.
const uint32_t * getMask() const
Returns the bit mask of register classes that getSubReg() projects into RC.
SuperRegClassIterator(const TargetRegisterClass *RC, const TargetRegisterInfo *TRI, bool IncludeSelf=false)
Create a SuperRegClassIterator that visits all the super-register classes of RC.
bool isValid() const
Returns true if this iterator is still pointing at a valid entry.
unsigned getNumRegs() const
Return the number of registers in this class.
const uint8_t TSFlags
Configurable target specific flags.
ArrayRef< MCPhysReg > getRegisters() const
bool isBaseClass() const
Return true if this register class has a defined BaseClassOrder.
const uint16_t * getSuperRegIndices() const
Returns a 0-terminated list of sub-register indices that project some super-register class into this ...
unsigned getID() const
Return the register class ID number.
ArrayRef< MCPhysReg > getRawAllocationOrder(const MachineFunction &MF, bool Rev=false) const
Returns the preferred order for allocating registers from this register class in MF.
const bool HasDisjunctSubRegs
Whether the class supports two (or more) disjunct subregister indices.
bool contains(Register Reg) const
Return true if the specified register is included in this register class.
bool isAllocatable() const
Return true if this register class may be used to create virtual registers.
ArrayRef< MCPhysReg >(* OrderFunc)(const MachineFunction &, bool Rev)
uint8_t getCopyCost() const
Return the cost of copying a value between two registers in this class.
bool hasSubClassEq(const TargetRegisterClass *RC) const
Returns true if RC is a sub-class of or equal to this class.
bool hasSubClass(const TargetRegisterClass *RC) const
Return true if the specified TargetRegisterClass is a proper sub-class of this TargetRegisterClass.
ArrayRef< unsigned > superclasses() const
Returns a list of super-classes.
const MCRegisterClass * MC
const MCPhysReg * const_iterator
bool hasSuperClassEq(const TargetRegisterClass *RC) const
Returns true if RC is a super-class of or equal to this class.
const bool CoveredBySubRegs
Whether a combination of subregisters can cover every register in the class.
LaneBitmask getLaneMask() const
Returns the combination of all lane masks of register in this class.
bool hasSuperClass(const TargetRegisterClass *RC) const
Return true if the specified TargetRegisterClass is a proper super-class of this TargetRegisterClass.
bool contains(Register Reg1, Register Reg2) const
Return true if both registers are in this class.
bool isASubClass() const
Return true if this TargetRegisterClass is a subset class of at least one other TargetRegisterClass.
const uint32_t * getSubClassMask() const
Returns a bit vector of subclasses, including this one.
const uint8_t AllocationPriority
Classes with a higher priority value are assigned first by register allocators using a greedy heurist...
MCRegister getRegister(unsigned i) const
Return the specified register in the class.
iterator begin() const
begin/end - Return all of the registers in this class.
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
virtual bool isConstantPhysReg(MCRegister PhysReg) const
Returns true if PhysReg is unallocatable and constant throughout the function.
virtual SmallVector< StringLiteral > getVRegFlagsOfReg(Register Reg, const MachineFunction &MF) const
const TargetRegisterClass *const * regclass_iterator
virtual bool isFrameOffsetLegal(const MachineInstr *MI, Register BaseReg, int64_t Offset) const
Determine whether a given base register plus offset immediate is encodable to resolve a frame index.
vt_iterator legalclasstypes_end(const TargetRegisterClass &RC) const
bool isTypeLegalForClass(const TargetRegisterClass &RC, LLT T) const
Return true if the given TargetRegisterClass is compatible with LLT T.
bool hasRegUnit(MCRegister Reg, MCRegUnit RegUnit) const
Returns true if Reg contains RegUnit.
virtual unsigned getNumRegPressureSets() const =0
Get the number of dimensions of register pressure.
~TargetRegisterInfo() override
unsigned reverseComposeSubRegIndices(unsigned a, unsigned b) const
Return a subregister index that will compose to give you the subregister index.
iterator_range< regclass_iterator > regclasses() const
virtual const int * getRegUnitPressureSets(MCRegUnit RegUnit) const =0
Get the dimensions of register pressure impacted by this register unit.
virtual const TargetRegisterClass * getPhysRegBaseClass(MCRegister Reg) const
Return target defined base register class for a physical register.
virtual bool canRealignStack(const MachineFunction &MF) const
True if the stack can be realigned for the target.
virtual bool isAsmClobberable(const MachineFunction &MF, MCRegister PhysReg) const
Returns false if we can't guarantee that Physreg, specified as an IR asm clobber constraint,...
virtual const TargetRegisterClass * getSubClassWithSubReg(const TargetRegisterClass *RC, unsigned Idx) const
Returns the largest legal sub-class of RC that supports the sub-register index Idx.
const TargetRegisterClass * getRegClass(unsigned i) const
Returns the register class associated with the enumeration value.
virtual bool useFPForScavengingIndex(const MachineFunction &MF) const
Returns true if the target wants to use frame pointer based accesses to spill to the scavenger emerge...
virtual const TargetRegisterClass * getCrossCopyRegClass(const TargetRegisterClass *RC) const
Returns a legal register class to copy a register in the specified class to or from.
virtual bool isVirtualFrameRegister(MCRegister Reg) const
Some targets delay assigning the frame until late and use a placeholder to represent it earlier.
virtual bool shouldUseLastChanceRecoloringForVirtReg(const MachineFunction &MF, const LiveInterval &VirtReg) const
Last chance recoloring has a high compile time cost especially for targets with a lot of registers.
virtual bool eliminateFrameIndicesBackwards() const
Process frame indices in reverse block order.
unsigned composeSubRegIndices(unsigned a, unsigned b) const
Return the subregister index you get from composing two subregister indices.
virtual LaneBitmask composeSubRegIndexLaneMaskImpl(unsigned, LaneBitmask) const
Overridden by TableGen in targets that have sub-registers.
virtual bool isIgnoredCVReg(MCRegister LLVMReg) const
virtual bool isGeneralPurposeRegisterClass(const TargetRegisterClass *RC) const
Returns true if RC is a class/subclass of general purpose register.
virtual unsigned getCSRFirstUseCost() const
Allow the target to override the cost of using a callee-saved register for the first time.
void markSuperRegs(BitVector &RegisterSet, MCRegister Reg) const
Mark a register and all its aliases as reserved in the given set.
TargetRegisterInfo(const TargetRegisterInfoDesc *ID, ArrayRef< const TargetRegisterClass * > RegisterClasses, const char *SubRegIndexStrings, ArrayRef< uint32_t > SubRegIndexNameOffsets, const SubRegCoveredBits *SubRegIdxRanges, const LaneBitmask *SubRegIndexLaneMasks, LaneBitmask CoveringLanes, const RegClassInfo *const RCInfos, const MVT::SimpleValueType *const RCVTLists, unsigned Mode=0)
virtual const MCPhysReg * getIPRACSRegs(const MachineFunction *MF) const
Return a null-terminated list of all of the callee-saved registers on this target when IPRA is on.
virtual const uint32_t * getCustomEHPadPreservedMask(const MachineFunction &MF) const
Return a register mask for the registers preserved by the unwinder, or nullptr if no custom mask is n...
virtual float getSpillWeightScaleFactor(const TargetRegisterClass *RC) const
Get the scale factor of spill weight for this register class.
const MVT::SimpleValueType * vt_iterator
virtual bool isUniformReg(const MachineRegisterInfo &MRI, const RegisterBankInfo &RBI, Register Reg) const
Returns true if the register is considered uniform.
TypeSize getRegSizeInBits(const TargetRegisterClass &RC) const
Return the size in bits of a register from class RC.
virtual std::optional< std::string > explainReservedReg(const MachineFunction &MF, MCRegister PhysReg) const
Returns either a string explaining why the given register is reserved for this function,...
virtual bool requiresFrameIndexScavenging(const MachineFunction &MF) const
Returns true if the target requires post PEI scavenging of registers for materializing frame index co...
const char * getSubRegIndexName(unsigned SubIdx) const
Return the human-readable symbolic target-specific name for the specified SubRegIndex.
virtual const uint32_t * getCallPreservedMask(const MachineFunction &MF, CallingConv::ID) const
Return a mask of call-preserved registers for the given calling convention on the current function.
virtual const char * getRegPressureSetName(unsigned Idx) const =0
Get the name of this register unit pressure set.
virtual LaneBitmask reverseComposeSubRegIndexLaneMaskImpl(unsigned, LaneBitmask) const
LaneBitmask getCoveringLanes() const
The lane masks returned by getSubRegIndexLaneMask() above can only be used to determine if sub-regist...
virtual int64_t getFrameIndexInstrOffset(const MachineInstr *MI, int Idx) const
Get the offset from the referenced frame index in the instruction, if there is one.
ArrayRef< uint8_t > getRegisterCosts(const MachineFunction &MF) const
Get a list of cost values for all registers that correspond to the index returned by RegisterCostTabl...
virtual bool isGeneralPurposeRegister(const MachineFunction &MF, MCRegister PhysReg) const
Returns true if PhysReg is a general purpose register.
virtual ArrayRef< const uint32_t * > getRegMasks() const =0
Return all the call-preserved register masks defined for this target.
LaneBitmask reverseComposeSubRegIndexLaneMask(unsigned IdxA, LaneBitmask LaneMask) const
Transform a lanemask given for a virtual register to the corresponding lanemask before using subregis...
regclass_iterator regclass_begin() const
Register class iterators.
virtual unsigned getRegPressureSetScore(const MachineFunction &MF, unsigned PSetID) const
Return a heuristic for the machine scheduler to compare the profitability of increasing one register ...
unsigned getNumRegClasses() const
virtual const int * getRegClassPressureSets(const TargetRegisterClass *RC) const =0
Get the dimensions of register pressure impacted by this register class.
virtual const RegClassWeight & getRegClassWeight(const TargetRegisterClass *RC) const =0
Get the weight in units of pressure for this register class.
virtual ArrayRef< MCPhysReg > getIntraCallClobberedRegs(const MachineFunction *MF) const
Return a list of all of the registers which are clobbered "inside" a call to the given function.
virtual bool reverseLocalAssignment() const
Allow the target to reverse allocation order of local live ranges.
virtual bool isNonallocatableRegisterCalleeSave(MCRegister Reg) const
Some targets have non-allocatable registers that aren't technically part of the explicit callee saved...
vt_iterator legalclasstypes_begin(const TargetRegisterClass &RC) const
Loop over all of the value types that can be represented by values in the given register class.
virtual unsigned getRegPressureLimit(const TargetRegisterClass *RC, MachineFunction &MF) const
Return the register pressure "high water mark" for the specific register class.
LaneBitmask getSubRegIndexLaneMask(unsigned SubIdx) const
Return a bitmask representing the parts of a register that are covered by SubIdx.
virtual const TargetRegisterClass * getMinimalPhysRegClass(MCRegister Reg) const =0
Returns the Register Class of a physical register, picking the smallest register subclass that contai...
bool checkAllSuperRegsMarked(const BitVector &RegisterSet, ArrayRef< MCPhysReg > Exceptions=ArrayRef< MCPhysReg >()) const
Returns true if for every register in the set all super registers are part of the set as well.
virtual int64_t getDwarfRegNumForVirtReg(Register RegNum, bool isEH) const
virtual const TargetRegisterClass * getLargestLegalSuperClass(const TargetRegisterClass *RC, const MachineFunction &) const
Returns the largest super class of RC that is legal to use in the current sub-target and has the same...
virtual BitVector getReservedRegs(const MachineFunction &MF) const =0
Returns a bitset indexed by physical register number indicating if a register is a special register t...
const RegClassInfo & getRegClassInfo(const TargetRegisterClass &RC) const
virtual const uint32_t * getNoPreservedMask() const
Return a register mask that clobbers everything.
virtual bool trackLivenessAfterRegAlloc(const MachineFunction &MF) const
Returns true if the live-ins should be tracked after register allocation.
virtual bool isArgumentRegister(const MachineFunction &MF, MCRegister PhysReg) const
Returns true if PhysReg can be used as an argument to a function.
Align getSpillAlign(const TargetRegisterClass &RC) const
Return the minimum required alignment in bytes for a spill slot for a register of this class.
virtual std::optional< uint8_t > getVRegFlagValue(StringRef Name) const
virtual const TargetRegisterClass * getSubRegisterClass(const TargetRegisterClass *SuperRC, unsigned SubRegIdx) const
Returns the register class of all sub-registers of SuperRC obtained by applying the sub-register inde...
virtual unsigned getRegPressureSetLimit(const MachineFunction &MF, unsigned Idx) const =0
Get the register unit pressure limit for this dimension.
virtual bool requiresFrameIndexReplacementScavenging(const MachineFunction &MF) const
Returns true if the target requires using the RegScavenger directly for frame elimination despite usi...
virtual bool eliminateFrameIndex(MachineBasicBlock::iterator MI, int SPAdj, unsigned FIOperandNum, RegScavenger *RS=nullptr) const =0
This method must be overriden to eliminate abstract frame indices from instructions which may use the...
virtual unsigned getRegUnitWeight(MCRegUnit RegUnit) const =0
Get the weight in units of pressure for this register unit.
virtual bool requiresRegisterScavenging(const MachineFunction &MF) const
Returns true if the target requires (and can make use of) the register scavenger.
const TargetRegisterClass * getAllocatableClass(const TargetRegisterClass *RC) const
Return the maximal subclass of the given register class that is allocatable or NULL.
regclass_iterator regclass_end() const
LaneBitmask composeSubRegIndexLaneMask(unsigned IdxA, LaneBitmask Mask) const
Transforms a LaneMask computed for one subregister to the lanemask that would have been computed when...
bool hasStackRealignment(const MachineFunction &MF) const
True if stack realignment is required and still possible.
virtual bool shouldAnalyzePhysregInMachineLoopInfo(MCRegister R) const
Returns true if MachineLoopInfo should analyze the given physreg for loop invariance.
virtual bool saveScavengerRegister(MachineBasicBlock &MBB, MachineBasicBlock::iterator I, MachineBasicBlock::iterator &UseMI, const TargetRegisterClass *RC, Register Reg) const
Spill the register so it can be used by the register scavenger.
virtual bool shouldRewriteCopySrc(const TargetRegisterClass *DefRC, unsigned DefSubReg, const TargetRegisterClass *SrcRC, unsigned SrcSubReg) const
MCRegister getMatchingSuperReg(MCRegister Reg, unsigned SubIdx, const TargetRegisterClass *RC) const
Return a super-register of register Reg such that its sub-register of index SubIdx is Reg.
virtual bool isCallerPreservedPhysReg(MCRegister PhysReg, const MachineFunction &MF) const
Physical registers that may be modified within a function but are guaranteed to be restored before an...
virtual bool hasReservedSpillSlot(const MachineFunction &MF, Register Reg, int &FrameIdx) const
Return true if target has reserved a spill slot in the stack frame of the given function for the spec...
virtual void resolveFrameIndex(MachineInstr &MI, Register BaseReg, int64_t Offset) const
Resolve a frame index operand of an instruction to reference the indicated base register plus offset ...
virtual bool isDivergentRegClass(const TargetRegisterClass *RC) const
Returns true if the register class is considered divergent.
virtual Register materializeFrameBaseRegister(MachineBasicBlock *MBB, int FrameIdx, int64_t Offset) const
Insert defining instruction(s) for a pointer to FrameIdx before insertion point I.
bool regsOverlap(Register RegA, Register RegB) const
Returns true if the two registers are equal or alias each other.
virtual bool shouldRealignStack(const MachineFunction &MF) const
True if storage within the function requires the stack pointer to be aligned more than the normal cal...
virtual unsigned getNumSupportedRegs(const MachineFunction &) const
Return the number of registers for the function. (may overestimate)
TargetStackID::Value getSpillStackID(const TargetRegisterClass &RC) const
Return the stack ID for spill slots holding a spilled copy of a register from this class.
virtual unsigned getCSRCost() const
FIXME: We should deprecate this usage.
virtual ArrayRef< const char * > getRegMaskNames() const =0
virtual bool isFixedRegister(const MachineFunction &MF, MCRegister PhysReg) const
Returns true if PhysReg is a fixed register.
const TargetRegisterClass * findCommonRegClass(const TargetRegisterClass *DefRC, unsigned DefSubReg, const TargetRegisterClass *SrcRC, unsigned SrcSubReg) const
Find a common register class that can accomodate both the source and destination operands of a copy-l...
virtual const TargetRegisterClass * getConstrainedRegClassForOperand(const MachineOperand &MO, const MachineRegisterInfo &MRI) const
unsigned getSpillSize(const TargetRegisterClass &RC) const
Return the size in bytes of the stack slot allocated to hold a spilled copy of a register from class ...
virtual StringRef getRegAsmName(MCRegister Reg) const
Return the assembly name for Reg.
virtual const MCPhysReg * getCalleeSavedRegs(const MachineFunction *MF) const =0
Return a null-terminated list of all of the callee-saved registers on this target.
bool isTypeLegalForClass(const TargetRegisterClass &RC, MVT T) const
Return true if the given TargetRegisterClass has the ValueType T.
virtual unsigned getRegisterCostTableIndex(const MachineFunction &MF) const
Return the register cost table index.
virtual bool needsFrameBaseReg(MachineInstr *MI, int64_t Offset) const
Returns true if the instruction's frame index reference would be better served by a base register oth...
virtual unsigned composeSubRegIndicesImpl(unsigned, unsigned) const
Overridden by TableGen in targets that have sub-registers.
virtual const TargetRegisterClass * getPointerRegClass(unsigned Kind=0) const
Returns a TargetRegisterClass used for pointer values.
virtual unsigned reverseComposeSubRegIndicesImpl(unsigned, unsigned) const
Overridden by TableGen in targets that have sub-registers.
virtual void adjustStackMapLiveOutMask(uint32_t *Mask) const
Prior to adding the live-out mask to a stackmap or patchpoint instruction, provide the target the opp...
bool isSubRegValidForRegClass(const TargetRegisterClass *RC, unsigned Idx) const
Returns true if sub-register Idx can be used with register class RC.
virtual bool isInlineAsmReadOnlyReg(const MachineFunction &MF, MCRegister PhysReg) const
Returns true if PhysReg cannot be written to in inline asm statements.
virtual bool shouldCoalesce(MachineInstr *MI, const TargetRegisterClass *SrcRC, unsigned SubReg, const TargetRegisterClass *DstRC, unsigned DstSubReg, const TargetRegisterClass *NewRC, LiveIntervals &LIS) const
Subtarget Hooks.
virtual Register getFrameRegister(const MachineFunction &MF) const =0
Debug information queries.
const char * getRegClassName(const TargetRegisterClass *Class) const
Returns the name of the register class.
virtual bool regClassPriorityTrumpsGlobalness(const MachineFunction &MF) const
When prioritizing live ranges in register allocation, if this hook returns true then the AllocationPr...
bool isInAllocatableClass(MCRegister RegNo) const
Return true if the register is in the allocation of any register class.
BitVector getAllocatableSet(const MachineFunction &MF, const TargetRegisterClass *RC=nullptr) const
Returns a bitset indexed by register number indicating if a register is allocatable or not.
virtual void updateRegAllocHint(Register Reg, Register NewReg, MachineFunction &MF) const
A callback to allow target a chance to update register allocation hints when a register is "changed" ...
virtual bool getRegAllocationHints(Register VirtReg, ArrayRef< MCPhysReg > Order, SmallVectorImpl< MCPhysReg > &Hints, const MachineFunction &MF, const VirtRegMap *VRM=nullptr, const LiveRegMatrix *Matrix=nullptr) const
Get a list of 'hint' registers that the register allocator should try first when allocating a physica...
virtual bool requiresVirtualBaseRegisters(const MachineFunction &MF) const
Returns true if the target wants the LocalStackAllocation pass to be run and virtual base registers u...
static constexpr TypeSize getFixed(ScalarTy ExactSize)
Definition TypeSize.h:343
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.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
Definition CallingConv.h:24
This is an optimization pass for GlobalISel generic memory operations.
@ Offset
Definition DWP.cpp:558
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
LLVM_ABI Printable printRegUnit(MCRegUnit Unit, const TargetRegisterInfo *TRI)
Create Printable object to print register units on a raw_ostream.
int countr_zero(T Val)
Count number of 0's from the least significant bit to the most stopping at the first 1.
Definition bit.h:204
LLVM_ABI Printable printRegClassOrBank(Register Reg, const MachineRegisterInfo &RegInfo, const TargetRegisterInfo *TRI)
Create Printable object to print register classes or register banks on a raw_ostream.
uint16_t MCPhysReg
An unsigned integer type large enough to represent all physical registers, but not necessarily virtua...
Definition MCRegister.h:21
ArrayRef(const T &OneElt) -> ArrayRef< T >
bool is_contained(R &&Range, const E &Element)
Returns true if Element is found in Range.
Definition STLExtras.h:1946
LLVM_ABI Printable printReg(Register Reg, const TargetRegisterInfo *TRI=nullptr, unsigned SubIdx=0, const MachineRegisterInfo *MRI=nullptr)
Prints virtual and physical registers with or without a TRI instance.
LLVM_ABI Printable printVRegOrUnit(VirtRegOrUnit VRegOrUnit, const TargetRegisterInfo *TRI)
Create Printable object to print virtual registers and physical registers on a raw_ostream.
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition Alignment.h:39
Each TargetRegisterClass has a per register weight, and weight limit which must be less than the limi...
Extra information, not in MCRegisterDesc, about registers.
SubRegCoveredBits - Emitted by tablegen: bit range covered by a subreg index, -1 in any being invalid...
unsigned operator()(Register Reg) const