16 #ifndef LLVM_CODEGEN_TARGETREGISTERINFO_H 17 #define LLVM_CODEGEN_TARGETREGISTERINFO_H 39 class MachineFunction;
95 bool contains(
unsigned Reg1,
unsigned Reg2)
const {
117 return (SubClassMask[ID / 32] >> (ID % 32)) & 1;
172 return SuperClasses[0] !=
nullptr;
230 const char *
const *SubRegIndexNames;
243 const char *
const *SRINames,
271 return int(Reg) >= (1 << 30);
276 assert(isStackSlot(Reg) &&
"Not a stack slot");
277 return int(Reg - (1u << 30));
282 assert(FI >= 0 &&
"Cannot hold a negative frame index.");
283 return FI + (1u << 30);
289 assert(!isStackSlot(Reg) &&
"Not a register! Check isStackSlot() first.");
296 assert(!isStackSlot(Reg) &&
"Not a register! Check isStackSlot() first.");
303 assert(isVirtualRegister(Reg) &&
"Not a virtual register");
304 return Reg & ~(1u << 31);
310 return Index | (1u << 31);
315 return getRegClassInfo(RC).RegSize;
321 return getRegClassInfo(RC).SpillSize / 8;
327 return getRegClassInfo(RC).SpillAlignment / 8;
332 for (
auto I = legalclasstypes_begin(RC); *
I !=
MVT::Other; ++
I)
341 return getRegClassInfo(RC).VTList;
382 assert(SubIdx && SubIdx < getNumSubRegIndices() &&
383 "This is not a subregister index");
384 return SubRegIndexNames[SubIdx-1];
392 assert(SubIdx < getNumSubRegIndices() &&
"This is not a subregister index");
393 return SubRegIndexLaneMasks[SubIdx];
424 if (regA == regB)
return true;
425 if (isVirtualRegister(regA) || isVirtualRegister(regB))
432 if (*RUA == *RUB)
return true;
433 if (*RUA < *RUB) ++RUA;
442 if (*Units == RegUnit)
451 virtual unsigned lookThruCopyLike(
unsigned SrcReg,
495 bool regmaskSubsetEqual(
const uint32_t *mask0,
const uint32_t *mask1)
const;
516 unsigned PhysReg)
const {
562 unsigned SrcSubReg)
const;
578 assert(Idx == 0 &&
"Target has no sub-registers");
598 return composeSubRegIndicesImpl(a, b);
608 return composeSubRegIndexLaneMaskImpl(IdxA, Mask);
622 return reverseComposeSubRegIndexLaneMaskImpl(IdxA, LaneMask);
626 static void dumpReg(
unsigned Reg,
unsigned SubRegIndex = 0,
672 unsigned &PreA,
unsigned &PreB)
const;
679 return RCInfos[getNumRegClasses() * HwMode + RC.
getID()];
687 return make_range(regclass_begin(), regclass_end());
691 return (
unsigned)(regclass_end()-regclass_begin());
697 assert(i < getNumRegClasses() &&
"Register Class ID out of range");
698 return RegClassBegin[i];
761 unsigned PSetID)
const {
773 virtual unsigned getRegUnitWeight(
unsigned RegUnit)
const = 0;
776 virtual unsigned getNumRegPressureSets()
const = 0;
779 virtual const char *getRegPressureSetName(
unsigned Idx)
const = 0;
784 unsigned Idx)
const = 0;
788 virtual const int *getRegClassPressureSets(
793 virtual const int *getRegUnitPressureSets(
unsigned RegUnit)
const = 0;
809 virtual bool getRegAllocationHints(
unsigned VirtReg,
881 int &FrameIdx)
const {
917 unsigned BaseReg,
int FrameIdx,
945 unsigned Reg)
const {
957 int SPAdj,
unsigned FIOperandNum,
989 virtual unsigned getFrameRegister(
const MachineFunction &MF)
const = 0;
996 bool checkAllSuperRegsMarked(
const BitVector &RegisterSet,
1023 const unsigned RCMaskWords;
1025 const uint16_t *Idx;
1033 bool IncludeSelf =
false)
1034 : RCMaskWords((TRI->getNumRegClasses() + 31) / 32),
1053 assert(isValid() &&
"Cannot move iterator past end.");
1054 Mask += RCMaskWords;
1070 const unsigned NumRegClasses;
1086 void moveToNextID() {
1090 while (!CurrentChunk) {
1093 if (Base >= NumRegClasses) {
1097 CurrentChunk = *++
Mask;
1119 void moveNBits(
unsigned NumBits) {
1120 assert(NumBits < 32 &&
"Undefined behavior spotted!");
1122 CurrentChunk >>= NumBits;
1133 : NumRegClasses(TRI.getNumRegClasses()), Mask(Mask), CurrentChunk(*Mask) {
1146 assert(isValid() &&
"Cannot move iterator past end.");
1170 unsigned SubIdx = 0,
1194 #endif // LLVM_CODEGEN_TARGETREGISTERINFO_H
A common definition of LaneBitmask for use in TableGen and CodeGen.
virtual bool requiresRegisterScavenging(const MachineFunction &MF) const
Returns true if the target requires (and can make use of) the register scavenger. ...
bool contains(unsigned Reg) const
Return true if the specified register is included in this register class.
LaneBitmask reverseComposeSubRegIndexLaneMask(unsigned IdxA, LaneBitmask LaneMask) const
Transform a lanemask given for a virtual register to the corresponding lanemask before using subregis...
static unsigned virtReg2Index(unsigned Reg)
Convert a virtual register number to a 0-based index.
iterator begin() const
begin/end - Return all of the registers in this class.
This class represents lattice values for constants.
unsigned getNumRegs() const
Return the number of registers in this class.
const uint16_t * getSuperRegIndices() const
Returns a 0-terminated list of sub-register indices that project some super-register class into this ...
iterator begin() const
begin/end - Return all of the registers in this class.
static unsigned index2VirtReg(unsigned Index)
Convert a 0-based index to a virtual register number.
virtual bool hasReservedSpillSlot(const MachineFunction &MF, unsigned Reg, int &FrameIdx) const
Return true if target has reserved a spill slot in the stack frame of the given function for the spec...
ArrayRef< MCPhysReg > getRawAllocationOrder(const MachineFunction &MF) const
Returns the preferred order for allocating registers from this register class in MF.
unsigned getRegister(unsigned i) const
Return the specified register in the class.
This provides a very simple, boring adaptor for a begin and end iterator into a range type...
static bool isVirtualRegister(unsigned Reg)
Return true if the specified register number is in the virtual register namespace.
unsigned getCostPerUse(unsigned RegNo) const
Return the additional cost of using this register instead of other registers in its class...
virtual const uint32_t * getNoPreservedMask() const
Return a register mask that clobbers everything.
virtual bool reverseLocalAssignment() const
Allow the target to reverse allocation order of local live ranges.
unsigned const TargetRegisterInfo * TRI
ArrayRef< MCPhysReg >(* OrderFunc)(const MachineFunction &)
const uint32_t * SubClassMask
virtual unsigned composeSubRegIndicesImpl(unsigned, unsigned) const
Overridden by TableGen in targets that have sub-registers.
unsigned getSubReg() const
Returns the current sub-register index.
virtual unsigned getRegPressureLimit(const TargetRegisterClass *RC, MachineFunction &MF) const
Return the register pressure "high water mark" for the specific register class.
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 ...
const TargetRegisterClass * getRegClass(unsigned i) const
Returns the register class associated with the enumeration value.
unsigned getID() const
getID() - Return the register class ID number.
const char * getRegClassName(const TargetRegisterClass *Class) const
Returns the name of the register class.
static int stackSlot2Index(unsigned Reg)
Compute the frame index from a register value representing a stack slot.
virtual bool isFrameOffsetLegal(const MachineInstr *MI, unsigned BaseReg, int64_t Offset) const
Determine whether a given base register plus offset immediate is encodable to resolve a frame index...
unsigned getSpillAlignment(const TargetRegisterClass &RC) const
Return the minimum required alignment in bytes for a spill slot for a register of this class...
Each TargetRegisterClass has a per register weight, and weight limit which must be less than the limi...
const uint16_t * SuperRegIndices
vt_iterator legalclasstypes_end(const TargetRegisterClass &RC) const
bool contains(unsigned Reg) const
contains - Return true if the specified register is included in this register class.
ArrayRef< T > makeArrayRef(const T &OneElt)
Construct an ArrayRef from a single element.
Printable printReg(unsigned Reg, const TargetRegisterInfo *TRI=nullptr, unsigned SubIdx=0, const MachineRegisterInfo *MRI=nullptr)
Prints virtual and physical registers with or without a TRI instance.
virtual LaneBitmask composeSubRegIndexLaneMaskImpl(unsigned, LaneBitmask) const
Overridden by TableGen in targets that have sub-registers.
virtual bool requiresFrameIndexScavenging(const MachineFunction &MF) const
Returns true if the target requires post PEI scavenging of registers for materializing frame index co...
std::set< RegisterRef > RegisterSet
static StringRef getName(Value *V)
iterator_range< regclass_iterator > regclasses() const
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 *const * sc_iterator
unsigned getID() const
Return the register class ID number.
Printable printRegUnit(unsigned Unit, const TargetRegisterInfo *TRI)
Create Printable object to print register units on a raw_ostream.
unsigned getNumRegClasses() const
regclass_iterator regclass_begin() const
Register class iterators.
bool hasRegUnit(unsigned Reg, unsigned RegUnit) const
Returns true if Reg contains RegUnit.
void operator++()
Advance iterator to the next entry.
bool contains(unsigned Reg1, unsigned Reg2) const
Return true if both registers are in this class.
unsigned getRegister(unsigned i) const
getRegister - Return the specified register in the class.
const char * getSubRegIndexName(unsigned SubIdx) const
Return the human-readable symbolic target-specific name for the specified SubRegIndex.
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...
Printable printRegClassOrBank(unsigned Reg, const MachineRegisterInfo &RegInfo, const TargetRegisterInfo *TRI)
Create Printable object to print register classes or register banks on a raw_ostream.
LaneBitmask getLaneMask() const
Returns the combination of all lane masks of register in this class.
bool isTypeLegalForClass(const TargetRegisterClass &RC, MVT T) const
Return true if the given TargetRegisterClass has the ValueType T.
virtual const TargetRegisterClass * getCrossCopyRegClass(const TargetRegisterClass *RC) const
Returns a legal register class to copy a register in the specified class to or from.
MCRegisterClass - Base class of TargetRegisterClass.
virtual StringRef getRegAsmName(unsigned Reg) const
Return the assembly name for Reg.
unsigned getNumRegs() const
getNumRegs - Return the number of registers in this class.
uint16_t MCPhysReg
An unsigned integer type large enough to represent all physical registers, but not necessarily virtua...
MCRegisterInfo base class - We assume that the target defines a static array of MCRegisterDesc object...
This class encapuslates the logic to iterate over bitmask returned by the various RegClass related AP...
sc_iterator getSuperClasses() const
Returns a NULL-terminated list of super-classes.
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...
const uint8_t AllocationPriority
Classes with a higher priority value are assigned first by register allocators using a greedy heurist...
iterator_range< SmallVectorImpl< MCPhysReg >::const_iterator > getRegisters() const
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
unsigned const MachineRegisterInfo * MRI
std::size_t countTrailingZeros(T Val, ZeroBehavior ZB=ZB_Width)
Count number of 0's from the least significant bit to the most stopping at the first 1...
unsigned getMatchingSuperReg(unsigned 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...
bool hasSuperClassEq(const TargetRegisterClass *RC) const
Returns true if RC is a super-class of or equal to this class.
const sc_iterator SuperClasses
const TargetRegisterClass *const * regclass_iterator
const RegClassInfo & getRegClassInfo(const TargetRegisterClass &RC) const
MachineInstrBuilder & UseMI
regclass_iterator regclass_end() const
unsigned composeSubRegIndices(unsigned a, unsigned b) const
Return the subregister index you get from composing two subregister indices.
Printable printVRegOrUnit(unsigned VRegOrUnit, const TargetRegisterInfo *TRI)
Create Printable object to print virtual registers and physical registers on a raw_ostream.
int getCopyCost() const
getCopyCost - Return the cost of copying a value between two registers in this class.
bool hasSubClass(const TargetRegisterClass *RC) const
Return true if the specified TargetRegisterClass is a proper sub-class of this TargetRegisterClass.
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.
virtual unsigned getCSRFirstUseCost() const
Allow the target to override the cost of using a callee-saved register for the first time...
virtual bool isConstantPhysReg(unsigned PhysReg) const
Returns true if PhysReg is unallocatable and constant throughout the function.
Extra information, not in MCRegisterDesc, about registers.
virtual void updateRegAllocHint(unsigned Reg, unsigned NewReg, MachineFunction &MF) const
A callback to allow target a chance to update register allocation hints when a register is "changed" ...
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
bool hasSubClassEq(const TargetRegisterClass *RC) const
Returns true if RC is a sub-class of or equal to this class.
const bool HasDisjunctSubRegs
Whether the class supports two (or more) disjunct subregister indices.
static bool isStackSlot(unsigned Reg)
isStackSlot - Sometimes it is useful the be able to store a non-negative frame index in a variable th...
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
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.
virtual bool shouldCoalesce(MachineInstr *MI, const TargetRegisterClass *SrcRC, unsigned SubReg, const TargetRegisterClass *DstRC, unsigned DstSubReg, const TargetRegisterClass *NewRC, LiveIntervals &LIS) const
Subtarget Hooks.
const uint32_t * getMask() const
Returns the bit mask of register classes that getSubReg() projects into RC.
const char * getRegClassName(const MCRegisterClass *Class) const
bool regsOverlap(unsigned regA, unsigned regB) const
Returns true if the two registers are equal or alias each other.
MachineOperand class - Representation of each machine instruction operand.
int getCopyCost() const
Return the cost of copying a value between two registers in this class.
bool isInAllocatableClass(unsigned RegNo) const
Return true if the register is in the allocation of any register class.
LaneBitmask getSubRegIndexLaneMask(unsigned SubIdx) const
Return a bitmask representing the parts of a register that are covered by SubIdx. ...
LaneBitmask composeSubRegIndexLaneMask(unsigned IdxA, LaneBitmask Mask) const
Transforms a LaneMask computed for one subregister to the lanemask that would have been computed when...
A range adaptor for a pair of iterators.
const MCRegisterClass * MC
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...
bool isValid() const
isValid - returns true if this iterator is not yet at the end.
SuperRegClassIterator(const TargetRegisterClass *RC, const TargetRegisterInfo *TRI, bool IncludeSelf=false)
Create a SuperRegClassIterator that visits all the super-register classes of RC.
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...
const MCPhysReg * iterator
virtual bool requiresVirtualBaseRegisters(const MachineFunction &MF) const
Returns true if the target wants the LocalStackAllocation pass to be run and virtual base registers u...
const uint32_t * getSubClassMask() const
Returns a bit vector of subclasses, including this one.
MachineRegisterInfo - Keep track of information for virtual and physical registers, including vreg register classes, use/def chains for registers, etc.
unsigned operator()(unsigned Reg) const
virtual LaneBitmask reverseComposeSubRegIndexLaneMaskImpl(unsigned, LaneBitmask) const
Representation of each machine instruction.
static bool isPhysicalRegister(unsigned Reg)
Return true if the specified register number is in the physical register namespace.
virtual bool requiresFrameIndexReplacementScavenging(const MachineFunction &MF) const
Returns true if the target requires using the RegScavenger directly for frame elimination despite usi...
unsigned getMatchingSuperReg(unsigned 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(unsigned PhysReg, const MachineFunction &MF) const
Physical registers that may be modified within a function but are guaranteed to be restored before an...
const LaneBitmask LaneMask
const bool CoveredBySubRegs
Whether a combination of subregisters can cover every register in the class.
bool isAllocatable() const
Return true if this register class may be used to create virtual registers.
unsigned getID() const
Returns the current register class ID.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
std::underlying_type< E >::type Mask()
Get a bitmask with 1s in all places up to the high-order bit of E's largest value.
virtual const TargetRegisterClass * getConstrainedRegClassForOperand(const MachineOperand &MO, const MachineRegisterInfo &MRI) const
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...
const MCPhysReg * const_iterator
bool hasSuperClass(const TargetRegisterClass *RC) const
Return true if the specified TargetRegisterClass is a proper super-class of this TargetRegisterClass...
StringRef - Represent a constant reference to a string, i.e.
const TargetRegisterClass & getMinimalPhysRegClass(unsigned Reg, const TargetRegisterInfo &TRI) const
Get the MinimalPhysRegClass for Reg.
virtual bool trackLivenessAfterRegAlloc(const MachineFunction &MF) const
Returns true if the live-ins should be tracked after register allocation.
unsigned getRegSizeInBits(const TargetRegisterClass &RC) const
Return the size in bits of a register from class RC.
Simple wrapper around std::function<void(raw_ostream&)>.
void operator++()
Advance iterator to the next entry.
virtual bool isAsmClobberable(const MachineFunction &MF, unsigned PhysReg) const
Returns false if we can't guarantee that Physreg, specified as an IR asm clobber constraint, will be preserved across the statement.
virtual void materializeFrameBaseRegister(MachineBasicBlock *MBB, unsigned BaseReg, int FrameIdx, int64_t Offset) const
Insert defining instruction(s) for BaseReg to be a pointer to FrameIdx before insertion point I...
static unsigned index2StackSlot(int FI)
Convert a non-negative frame index to a stack slot register value.
LaneBitmask getCoveringLanes() const
The lane masks returned by getSubRegIndexLaneMask() above can only be used to determine if sub-regist...
virtual unsigned getRegPressureSetScore(const MachineFunction &MF, unsigned PSetID) const
Return a heuristic for the machine scheduler to compare the profitability of increasing one register ...
virtual bool saveScavengerRegister(MachineBasicBlock &MBB, MachineBasicBlock::iterator I, MachineBasicBlock::iterator &UseMI, const TargetRegisterClass *RC, unsigned Reg) const
Spill the register so it can be used by the register scavenger.
bool isAllocatable() const
isAllocatable - Return true if this register class may be used to create virtual registers.
bool isValid() const
Returns true if this iterator is still pointing at a valid entry.
bool isASubClass() const
Return true if this TargetRegisterClass is a subset class of at least one other TargetRegisterClass.
virtual const TargetRegisterClass * getPointerRegClass(const MachineFunction &MF, unsigned Kind=0) const
Returns a TargetRegisterClass used for pointer values.
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 void resolveFrameIndex(MachineInstr &MI, unsigned BaseReg, int64_t Offset) const
Resolve a frame index operand of an instruction to reference the indicated base register plus offset ...