28#include "llvm/Config/llvm-config.h"
41#define DEBUG_TYPE "target-reg-info"
47 cl::desc(
"A threshold of live range size which may cause "
48 "high compile time cost in global splitting."),
58 : InfoDesc(ID), SubRegIndexStrings(SubRegIndexStrings),
59 SubRegIndexNameOffsets(SubRegIndexNameOffsets),
60 SubRegIdxRanges(SubRegIdxRanges),
61 SubRegIndexLaneMasks(SubRegIndexLaneMasks), CoveringLanes(CoveringLanes),
62 RCInfos(RCInfos), RCVTLists(RCVTLists), HwMode(Mode) {}
71 if (
MI &&
TII->isTriviallyReMaterializable(*
MI) &&
87 for (
unsigned Reg : RegisterSet.set_bits()) {
91 if (!RegisterSet[SR] && !
is_contained(Exceptions, Reg)) {
93 <<
" of reserved register " <<
printReg(Reg,
this)
94 <<
" is not reserved.\n";
111 else if (Reg.isStack())
112 OS <<
"SS#" << Reg.stackSlotIndex();
113 else if (Reg.isVirtual()) {
118 OS <<
'%' << Reg.virtRegIndex();
121 OS <<
'$' <<
"physreg" << Reg.id();
130 OS <<
':' <<
TRI->getSubRegIndexName(SubIdx);
132 OS <<
":sub(" << SubIdx <<
')';
141 OS <<
"Unit~" <<
static_cast<unsigned>(Unit);
146 if (
static_cast<unsigned>(Unit) >=
TRI->getNumRegUnits()) {
147 OS <<
"BadUnit~" <<
static_cast<unsigned>(Unit);
154 OS <<
TRI->getName(*Roots);
155 for (++Roots; Roots.
isValid(); ++Roots)
156 OS <<
'~' <<
TRI->getName(*Roots);
175 if (RegInfo.getRegClassOrNull(Reg))
177 else if (RegInfo.getRegBankOrNull(Reg))
178 OS <<
StringRef(RegInfo.getRegBankOrNull(Reg)->getName()).
lower();
181 assert((RegInfo.def_empty(Reg) || RegInfo.getType(Reg).isValid()) &&
182 "Generic registers must have a valid type");
207 "Reg1/Reg2 must be a physical register");
212 if (RC.contains(Reg1, Reg2) && (!BestRC || BestRC->
hasSubClass(&RC)))
216 assert(BestRC &&
"Couldn't find the register class");
223 return ::getCommonMinimalPhysRegClass(
this, Reg1, Reg2);
247 if (
C.isAllocatable())
263 for (
unsigned I = 0,
E =
TRI->getNumRegClasses();
I <
E;
I += 32)
264 if (
unsigned Common = *
A++ & *
B++)
286 unsigned Idx)
const {
287 assert(
A &&
B &&
"Missing register class");
288 assert(Idx &&
"Bad sub-register index");
292 if (RCI.getSubReg() == Idx)
302 unsigned &PreA,
unsigned &PreB)
const {
303 assert(RCA && SubA && RCB && SubB &&
"Invalid arguments");
318 unsigned *BestPreA = &PreA;
319 unsigned *BestPreB = &PreB;
341 if (FinalA != FinalB)
350 *BestPreA = IA.getSubReg();
351 *BestPreB = IB.getSubReg();
368 if (DefRC == SrcRC && DefSubReg == SrcSubReg)
372 unsigned SrcIdx, DefIdx;
373 if (SrcSubReg && DefSubReg) {
404 const std::pair<unsigned, SmallVector<Register, 4>> *Hints_MRI =
411 bool Skip = (Hints_MRI->first != 0);
412 for (
auto Reg : Hints_MRI->second) {
443 return AntiHintedRegUnits.
test(
static_cast<unsigned>(Unit));
453 if (AntiHintedRegUnits.
none())
456 assert(HintsAndCustomOrder.
size() == NumHints &&
457 "HintsAndCustomOrder should only contain the hints here.");
473 [[maybe_unused]]
auto *PartitionPoint = std::stable_partition(
474 CustomOrder.
begin(), CustomOrder.
end(),
475 [&](
MCPhysReg Reg) { return !isAntiHintedReg(Reg, AntiHintedRegUnits); });
478 size_t NonAntiHintedCount =
479 std::distance(CustomOrder.
begin(), PartitionPoint);
480 size_t AntiHintedCount = std::distance(PartitionPoint, CustomOrder.
end());
481 dbgs() <<
"Added " << NonAntiHintedCount
482 <<
" non-anti-hinted registers first\n"
483 <<
"Added " << AntiHintedCount
484 <<
" anti-hinted registers at the end\n";
492 const uint32_t *callerPreservedRegs =
494 if (callerPreservedRegs) {
496 return (callerPreservedRegs[PhysReg.
id() / 32] >> PhysReg.
id() % 32) & 1;
512 for (
unsigned I = 0;
I <
N; ++
I)
513 if ((mask0[
I] & mask1[
I]) != mask0[
I])
522 if (Reg.isPhysical()) {
527 assert(RC &&
"Unable to deduce the register class");
536 assert(RC &&
"Unable to deduce the register class");
544 unsigned BestIdx = 0;
545 unsigned BestCover = 0;
553 if (SubRegMask == LaneMask) {
559 if ((SubRegMask & ~LaneMask).any())
564 if (PopCount > BestCover) {
565 BestCover = PopCount;
579 while (LanesLeft.
any()) {
580 unsigned BestIdx = 0;
581 int BestCover = std::numeric_limits<int>::min();
582 for (
unsigned Idx : PossibleIndexes) {
585 if (SubRegMask == LanesLeft) {
593 if ((SubRegMask & ~LanesLeft).any())
597 const int Cover = (SubRegMask & LanesLeft).getNumLanes();
598 if (Cover > BestCover) {
617 unsigned SubB)
const {
618 if (RegA == RegB && SubA == SubB)
625 return (LA & LB).any();
638 "This is not a subregister index");
644 "This is not a subregister index");
653 if (!
MI || !
MI->isCopyLike())
658 CopySrcReg =
MI->getOperand(1).getReg();
660 assert(
MI->isSubregToReg() &&
"Bad opcode for lookThruCopyLike");
661 CopySrcReg =
MI->getOperand(1).getReg();
676 if (!
MI || !
MI->isCopyLike())
681 CopySrcReg =
MI->getOperand(1).getReg();
683 assert(
MI->isSubregToReg() &&
"Bad opcode for lookThruCopyLike");
684 CopySrcReg =
MI->getOperand(1).getReg();
698 assert(!
Offset.getScalable() &&
"Scalable offsets are not handled");
704 unsigned PrependFlags,
709 "Unsupported prepend flag");
712 OffsetExpr.
push_back(dwarf::DW_OP_deref);
715 OffsetExpr.
push_back(dwarf::DW_OP_deref);
721#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
This file contains the simple types necessary to represent the attributes associated with functions a...
This file implements the BitVector class.
static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds.
This file contains constants used for implementing Dwarf debug support.
const HexagonInstrInfo * TII
const AbstractManglingParser< Derived, Alloc >::OperatorInfo AbstractManglingParser< Derived, Alloc >::Ops[]
Register const TargetRegisterInfo * TRI
Promote Memory to Register
static void getAllocatableSetForRC(const MachineFunction &MF, const TargetRegisterClass *RC, BitVector &R)
getAllocatableSetForRC - Toggle the bits that represent allocatable registers for the specific regist...
static const TargetRegisterClass * firstCommonClass(const uint32_t *A, const uint32_t *B, const TargetRegisterInfo *TRI)
static cl::opt< unsigned > HugeSizeForSplit("huge-size-for-split", cl::Hidden, cl::desc("A threshold of live range size which may cause " "high compile time cost in global splitting."), cl::init(5000))
static const TargetRegisterClass * getCommonMinimalPhysRegClass(const TargetRegisterInfo *TRI, MCRegister Reg1, MCRegister Reg2)
Represent a constant reference to an array (0 or more elements consecutively in memory),...
This class encapuslates the logic to iterate over bitmask returned by the various RegClass related AP...
bool isValid() const
Returns true if this iterator is still pointing at a valid entry.
bool test(unsigned Idx) const
Returns true if bit Idx is set.
BitVector & reset()
Reset all bits in the bitvector.
BitVector & set()
Set all bits in the bitvector.
bool none() const
Returns true if none of the bits are set.
static LLVM_ABI void appendOffset(SmallVectorImpl< uint64_t > &Ops, int64_t Offset)
Append Ops with operations to apply the Offset.
static LLVM_ABI DIExpression * prependOpcodes(const DIExpression *Expr, SmallVectorImpl< uint64_t > &Ops, bool StackValue=false, bool EntryValue=false)
Prepend DIExpr with the given opcodes and optionally turn it into a stack value.
CallingConv::ID getCallingConv() const
getCallingConv()/setCallingConv(CC) - These method get and set the calling convention of this functio...
constexpr TypeSize getSizeInBits() const
Returns the total size of the type. Must only be called on sized types.
LiveInterval - This class represents the liveness of a register, or stack slot.
MCRegUnitRootIterator enumerates the root registers of a register unit.
bool isValid() const
Check if the iterator is at the end of the list.
const uint32_t * getSubClassMask() const
Returns a bit vector of subclasses, including this one.
bool isAllocatable() const
isAllocatable - Return true if this register class may be used to create virtual registers.
bool hasSubClass(const MCRegisterClass *RC) const
Return true if the specified TargetRegisterClass is a proper sub-class of this TargetRegisterClass.
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.
iterator_range< regclass_iterator > regclasses() const
iota_range< MCRegUnit > regunits() const
Returns an iterator range over all regunits.
iterator_range< MCSuperRegIterator > superregs(MCRegister Reg) const
Return an iterator range over all super-registers of Reg, excluding Reg.
iterator_range< MCSuperRegIterator > superregs_inclusive(MCRegister Reg) const
Return an iterator range over all super-registers of Reg, including Reg.
MCRegister getSubReg(MCRegister Reg, unsigned Idx) const
Returns the physical register number of sub-register "Index" for physical register RegNo.
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.
constexpr bool isValid() const
constexpr bool isPhysical() const
Return true if the specified register number is in the physical register namespace.
constexpr unsigned id() const
bool shouldRealignStack() const
Return true if stack realignment is forced by function attributes or if the stack alignment.
bool isStackRealignable() const
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
MachineFrameInfo & getFrameInfo()
getFrameInfo - Return the frame info object for the current function.
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
Function & getFunction()
Return the LLVM function that this machine code represents.
Representation of each machine instruction.
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
LLVM_ABI bool hasOneNonDBGUse(Register RegNo) const
hasOneNonDBGUse - Return true if there is exactly one non-Debug use of the specified register.
const TargetRegisterClass * getRegClass(Register Reg) const
Return the register class of the specified virtual register.
LLVM_ABI LLVM_READONLY MachineInstr * getVRegDef(Register Reg) const
getVRegDef - Return the machine instr that defines the specified virtual register or null if none is ...
bool isReserved(MCRegister PhysReg) const
isReserved - Returns true when PhysReg is a reserved register.
const BitVector & getReservedRegs() const
getReservedRegs - Returns a reference to the frozen set of reserved registers.
LLT getType(Register Reg) const
Get the low-level type of Reg or LLT{} if Reg is not a generic (target independent) virtual register.
const std::pair< unsigned, SmallVector< Register, 4 > > * getRegAllocationHints(Register VReg) const
getRegAllocationHints - Return a reference to the vector of all register allocation hints for VReg.
StringRef getVRegName(Register Reg) const
LLVM_ABI LLVM_READONLY MachineInstr * getUniqueVRegDef(Register Reg) const
getUniqueVRegDef - Return the unique machine instr that defines the specified virtual register or nul...
Represent a mutable reference to an array (0 or more elements consecutively in memory),...
Simple wrapper around std::function<void(raw_ostream&)>.
Wrapper class representing virtual and physical registers.
MCRegister asMCReg() const
Utility to check-convert this value to a MCRegister.
unsigned virtRegIndex() const
Convert a virtual register number to a 0-based index.
constexpr bool isVirtual() const
Return true if the specified register number is in the virtual register namespace.
constexpr bool isPhysical() const
Return true if the specified register number is in the physical register namespace.
bool insert(const value_type &X)
Insert a new element into the SetVector.
A SetVector that performs no allocations if smaller than a certain size.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
void append(ItTy in_start, ItTy in_end)
Add the specified range to the end of the SmallVector.
void push_back(const T &Elt)
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.
Represent a constant reference to a string, i.e.
LLVM_ABI std::string lower() const
bool isValid() const
Returns true if this iterator is still pointing at a valid entry.
TargetInstrInfo - Interface to description of machine instruction set.
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
~TargetRegisterInfo() override
virtual bool shouldRegionSplitForVirtReg(const MachineFunction &MF, const LiveInterval &VirtReg) const
Region split has a high compile time cost especially for large live range.
virtual bool canRealignStack(const MachineFunction &MF) const
True if the stack can be realigned for the target.
bool getCoveringSubRegIndexes(const TargetRegisterClass *RC, LaneBitmask LaneMask, SmallVectorImpl< unsigned > &Indexes) const
Try to find one or more subregister indexes to cover LaneMask.
const TargetRegisterClass * getRegClass(unsigned i) const
Returns the register class associated with the enumeration value.
unsigned composeSubRegIndices(unsigned a, unsigned b) const
Return the subregister index you get from composing two subregister indices.
bool checkSubRegInterference(Register RegA, unsigned SubA, Register RegB, unsigned SubB) const
Returns true if the two subregisters are equal or overlap.
const TargetRegisterClass * getCommonSubClass(const TargetRegisterClass *A, const TargetRegisterClass *B) const
Find the largest common subclass of A and B.
void markSuperRegs(BitVector &RegisterSet, MCRegister Reg) const
Mark a register and all its aliases as reserved in the given set.
virtual float getSpillWeightScaleFactor(const TargetRegisterClass *RC) const
Get the scale factor of spill weight for this register class.
bool isAntiHintedReg(MCPhysReg Reg, const BitVector &AntiHintedRegUnits) const
Return true if Reg overlaps one of the anti-hinted register units.
bool regmaskSubsetEqual(const uint32_t *mask0, const uint32_t *mask1) const
Return true if all bits that are set in mask mask0 are also set in mask1.
TypeSize getRegSizeInBits(const TargetRegisterClass &RC) const
Return the size in bits of a register from class RC.
virtual 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 Register lookThruSingleUseCopyChain(Register SrcReg, const MachineRegisterInfo *MRI) const
Find the original SrcReg unless it is the target of a copy-like operation, in which case we chain bac...
virtual void filterAndSortForAntiHintedRegs(Register VirtReg, MutableArrayRef< MCPhysReg > CustomOrder, const BitVector &AntiHintedRegUnits, const MachineFunction &MF, const LiveRegMatrix *Matrix=nullptr, const RegisterClassInfo *RegClassInfo=nullptr) const
Custom reordering of the allocation order.
LaneBitmask getSubRegIndexLaneMask(unsigned SubIdx) const
Return a bitmask representing the parts of a register that are covered by SubIdx.
virtual const TargetRegisterClass * getMinimalPhysRegClass(MCRegister Reg) const =0
Returns the Register Class of a physical register, picking the smallest register subclass that contai...
bool checkAllSuperRegsMarked(const BitVector &RegisterSet, ArrayRef< MCPhysReg > Exceptions=ArrayRef< MCPhysReg >()) const
Returns true if for every register in the set all super registers are part of the set as well.
const TargetRegisterClass * getAllocatableClass(const TargetRegisterClass *RC) const
Return the maximal subclass of the given register class that is allocatable or NULL.
virtual Register lookThruCopyLike(Register SrcReg, const MachineRegisterInfo *MRI) const
Returns the original SrcReg unless it is the target of a copy-like operation, in which case we chain ...
void applyRegAllocationAntiHints(Register VirtReg, ArrayRef< MCPhysReg > Order, SmallVectorImpl< MCPhysReg > &HintsAndCustomOrder, unsigned NumHints, const BitVector &AntiHintedRegUnits, const MachineFunction &MF, const LiveRegMatrix *Matrix=nullptr, const RegisterClassInfo *RegClassInfo=nullptr) const
Apply anti-hints to the allocation order.
const TargetRegisterClass * getCommonSuperRegClass(const TargetRegisterClass *RCA, unsigned SubA, const TargetRegisterClass *RCB, unsigned SubB, unsigned &PreA, unsigned &PreB) const
Find a common super-register class if it exists.
unsigned getSubRegIdxSize(unsigned Idx) const
Get the size of the bit range covered by a sub-register index.
static void dumpReg(Register Reg, unsigned SubRegIndex=0, const TargetRegisterInfo *TRI=nullptr)
Debugging helper: dump register in human readable form to dbgs() stream.
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...
DIExpression * prependOffsetExpression(const DIExpression *Expr, unsigned PrependFlags, const StackOffset &Offset) const
Prepends a DWARF expression for Offset to DIExpression Expr.
const TargetRegisterClass * findCommonRegClass(const TargetRegisterClass *DefRC, unsigned DefSubReg, const TargetRegisterClass *SrcRC, unsigned SrcSubReg) const
Find a common register class that can accomodate both the source and destination operands of a copy-l...
virtual bool getRegAllocationHints(Register VirtReg, ArrayRef< MCPhysReg > Order, SmallSetVector< MCPhysReg, 16 > &Hints, const MachineFunction &MF, const VirtRegMap *VRM=nullptr, const LiveRegMatrix *Matrix=nullptr) const
Get a list of 'hint' registers that the register allocator should try first when allocating a physica...
virtual bool isCalleeSavedPhysReg(MCRegister PhysReg, const MachineFunction &MF) const
This is a wrapper around getCallPreservedMask().
TargetRegisterInfo(const TargetRegisterInfoDesc *ID, const char *SubRegIndexStrings, ArrayRef< uint32_t > SubRegIndexNameOffsets, const SubRegCoveredBits *SubRegIdxRanges, const LaneBitmask *SubRegIndexLaneMasks, LaneBitmask CoveringLanes, const RegClassInfo *const RCInfos, const MVT::SimpleValueType *const RCVTLists, unsigned Mode=0)
unsigned getSubRegIdxOffset(unsigned Idx) const
Get the offset of the bit range covered by a sub-register index.
const TargetRegisterClass * getCommonMinimalPhysRegClass(MCRegister Reg1, MCRegister Reg2) const
Returns the common Register Class of two physical registers, picking the smallest register subclass t...
bool isSubRegValidForRegClass(const TargetRegisterClass *RC, unsigned Idx) const
Returns true if sub-register Idx can be used with register class RC.
virtual const TargetRegisterClass * getMatchingSuperRegClass(const TargetRegisterClass *A, const TargetRegisterClass *B, unsigned Idx) const
Return a subclass of the register class A so that each register in it has a sub-register of sub-regis...
virtual void getOffsetOpcodes(const StackOffset &Offset, SmallVectorImpl< uint64_t > &Ops) const
Gets the DWARF expression opcodes for Offset.
BitVector getAllocatableSet(const MachineFunction &MF, const TargetRegisterClass *RC=nullptr) const
Returns a bitset indexed by register number indicating if a register is allocatable or not.
virtual const TargetInstrInfo * getInstrInfo() const
virtual const TargetRegisterInfo * getRegisterInfo() const =0
Return the target's register information.
MCRegister getPhys(Register virtReg) const
returns the physical register mapped to the specified virtual register
Wrapper class representing a virtual register or register unit.
constexpr bool isVirtualReg() const
constexpr MCRegUnit asMCRegUnit() const
constexpr Register asVirtualReg() const
This class implements an extremely fast bulk output stream that can only output to a stream.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
initializer< Ty > init(const Ty &Val)
This is an optimization pass for GlobalISel generic memory operations.
LLVM_ABI void printLowerCase(StringRef String, raw_ostream &Out)
printLowerCase - Print each character as lowercase if it is uppercase.
LLVM_ABI Printable printRegUnit(MCRegUnit Unit, const TargetRegisterInfo *TRI)
Create Printable object to print register units on a raw_ostream.
int countr_zero(T Val)
Count number of 0's from the least significant bit to the most stopping at the first 1.
bool any_of(R &&range, UnaryPredicate P)
Provide wrappers to std::any_of which take ranges instead of having to pass begin/end explicitly.
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
LLVM_ABI Printable printRegClassOrBank(Register Reg, const MachineRegisterInfo &RegInfo, const TargetRegisterInfo *TRI)
Create Printable object to print register classes or register banks on a raw_ostream.
uint16_t MCPhysReg
An unsigned integer type large enough to represent all physical registers, but not necessarily virtua...
bool is_contained(R &&Range, const E &Element)
Returns true if Element is found in Range.
LLVM_ABI Printable printReg(Register Reg, const TargetRegisterInfo *TRI=nullptr, unsigned SubIdx=0, const MachineRegisterInfo *MRI=nullptr)
Prints virtual and physical registers with or without a TRI instance.
LLVM_ABI Printable printVRegOrUnit(VirtRegOrUnit VRegOrUnit, const TargetRegisterInfo *TRI)
Create Printable object to print virtual registers and physical registers on a raw_ostream.
MCRegisterClass TargetRegisterClass
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.
constexpr bool any() const
unsigned getNumLanes() const
Extra information, not in MCRegisterDesc, about registers.
SubRegCoveredBits - Emitted by tablegen: bit range covered by a subreg index, -1 in any being invalid...