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