29#include "llvm/Config/llvm-config.h"
42#define DEBUG_TYPE "target-reg-info"
48 cl::desc(
"A threshold of live range size which may cause "
49 "high compile time cost in global splitting."),
59 : InfoDesc(ID), SubRegIndexStrings(SubRegIndexStrings),
60 SubRegIndexNameOffsets(SubRegIndexNameOffsets),
61 SubRegIdxRanges(SubRegIdxRanges),
62 SubRegIndexLaneMasks(SubRegIndexLaneMasks), CoveringLanes(CoveringLanes),
63 RCInfos(RCInfos), RCVTLists(RCVTLists), HwMode(Mode) {}
72 if (
MI &&
TII->isTriviallyReMaterializable(*
MI) &&
88 for (
unsigned Reg : RegisterSet.set_bits()) {
92 if (!RegisterSet[SR] && !
is_contained(Exceptions, Reg)) {
94 <<
" of reserved register " <<
printReg(Reg,
this)
95 <<
" is not reserved.\n";
112 else if (Reg.isStack())
113 OS <<
"SS#" << Reg.stackSlotIndex();
114 else if (Reg.isVirtual()) {
119 OS <<
'%' << Reg.virtRegIndex();
122 OS <<
'$' <<
"physreg" << Reg.id();
131 OS <<
':' <<
TRI->getSubRegIndexName(SubIdx);
133 OS <<
":sub(" << SubIdx <<
')';
142 OS <<
"Unit~" <<
static_cast<unsigned>(Unit);
147 if (
static_cast<unsigned>(Unit) >=
TRI->getNumRegUnits()) {
148 OS <<
"BadUnit~" <<
static_cast<unsigned>(Unit);
155 OS <<
TRI->getName(*Roots);
156 for (++Roots; Roots.
isValid(); ++Roots)
157 OS <<
'~' <<
TRI->getName(*Roots);
176 if (RegInfo.getRegClassOrNull(Reg))
178 else if (RegInfo.getRegBankOrNull(Reg))
179 OS <<
StringRef(RegInfo.getRegBankOrNull(Reg)->getName()).
lower();
182 assert((RegInfo.def_empty(Reg) || RegInfo.getType(Reg).isValid()) &&
183 "Generic registers must have a valid type");
208 "Reg1/Reg2 must be a physical register");
213 if (RC.contains(Reg1, Reg2) && (!BestRC || BestRC->
hasSubClass(&RC)))
217 assert(BestRC &&
"Couldn't find the register class");
224 return ::getCommonMinimalPhysRegClass(
this, Reg1, Reg2);
248 if (
C.isAllocatable())
264 for (
unsigned I = 0,
E =
TRI->getNumRegClasses();
I <
E;
I += 32)
265 if (
unsigned Common = *
A++ & *
B++)
287 unsigned Idx)
const {
288 assert(
A &&
B &&
"Missing register class");
289 assert(Idx &&
"Bad sub-register index");
293 if (RCI.getSubReg() == Idx)
303 unsigned &PreA,
unsigned &PreB)
const {
304 assert(RCA && SubA && RCB && SubB &&
"Invalid arguments");
319 unsigned *BestPreA = &PreA;
320 unsigned *BestPreB = &PreB;
342 if (FinalA != FinalB)
351 *BestPreA = IA.getSubReg();
352 *BestPreB = IB.getSubReg();
369 if (DefRC == SrcRC && DefSubReg == SrcSubReg)
373 unsigned SrcIdx, DefIdx;
374 if (SrcSubReg && DefSubReg) {
405 const std::pair<unsigned, SmallVector<Register, 4>> *Hints_MRI =
413 bool Skip = (Hints_MRI->first != 0);
414 for (
auto Reg : Hints_MRI->second) {
427 if (!HintedRegs.
insert(Phys).second)
449 return AntiHintedRegUnits.
test(
static_cast<unsigned>(Unit));
459 if (AntiHintedRegUnits.
none())
462 assert(HintsAndCustomOrder.
size() == NumHints &&
463 "HintsAndCustomOrder should only contain the hints here.");
479 [[maybe_unused]]
auto *PartitionPoint = std::stable_partition(
480 CustomOrder.
begin(), CustomOrder.
end(),
481 [&](
MCPhysReg Reg) { return !isAntiHintedReg(Reg, AntiHintedRegUnits); });
484 size_t NonAntiHintedCount =
485 std::distance(CustomOrder.
begin(), PartitionPoint);
486 size_t AntiHintedCount = std::distance(PartitionPoint, CustomOrder.
end());
487 dbgs() <<
"Added " << NonAntiHintedCount
488 <<
" non-anti-hinted registers first\n"
489 <<
"Added " << AntiHintedCount
490 <<
" anti-hinted registers at the end\n";
498 const uint32_t *callerPreservedRegs =
500 if (callerPreservedRegs) {
502 return (callerPreservedRegs[PhysReg.
id() / 32] >> PhysReg.
id() % 32) & 1;
518 for (
unsigned I = 0;
I <
N; ++
I)
519 if ((mask0[
I] & mask1[
I]) != mask0[
I])
528 if (Reg.isPhysical()) {
533 assert(RC &&
"Unable to deduce the register class");
542 assert(RC &&
"Unable to deduce the register class");
550 unsigned BestIdx = 0;
551 unsigned BestCover = 0;
559 if (SubRegMask == LaneMask) {
565 if ((SubRegMask & ~LaneMask).any())
570 if (PopCount > BestCover) {
571 BestCover = PopCount;
585 while (LanesLeft.
any()) {
586 unsigned BestIdx = 0;
587 int BestCover = std::numeric_limits<int>::min();
588 for (
unsigned Idx : PossibleIndexes) {
591 if (SubRegMask == LanesLeft) {
599 if ((SubRegMask & ~LanesLeft).any())
603 const int Cover = (SubRegMask & LanesLeft).getNumLanes();
604 if (Cover > BestCover) {
623 unsigned SubB)
const {
624 if (RegA == RegB && SubA == SubB)
631 return (LA & LB).any();
644 "This is not a subregister index");
650 "This is not a subregister index");
659 if (!
MI || !
MI->isCopyLike())
664 CopySrcReg =
MI->getOperand(1).getReg();
666 assert(
MI->isSubregToReg() &&
"Bad opcode for lookThruCopyLike");
667 CopySrcReg =
MI->getOperand(1).getReg();
682 if (!
MI || !
MI->isCopyLike())
687 CopySrcReg =
MI->getOperand(1).getReg();
689 assert(
MI->isSubregToReg() &&
"Bad opcode for lookThruCopyLike");
690 CopySrcReg =
MI->getOperand(1).getReg();
704 assert(!
Offset.getScalable() &&
"Scalable offsets are not handled");
710 unsigned PrependFlags,
715 "Unsupported prepend flag");
718 OffsetExpr.
push_back(dwarf::DW_OP_deref);
721 OffsetExpr.
push_back(dwarf::DW_OP_deref);
727#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
This file defines the SmallSet class.
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 unsigned id() const
constexpr bool isPhysical() const
Return true if the specified register number is in the physical register namespace.
SmallSet - This maintains a set of unique values, optimizing for the case when the set is small (less...
std::pair< const_iterator, bool > insert(const T &V)
insert - Insert an element into the set if it isn't already there.
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 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 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 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...