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