28#include "llvm/Config/llvm-config.h"
43#define DEBUG_TYPE "target-reg-info"
49 cl::desc(
"A threshold of live range size which may cause "
50 "high compile time cost in global splitting."),
55 const char *
const *SRINames,
60 : InfoDesc(
ID), SubRegIndexNames(SRINames),
61 SubRegIndexLaneMasks(SRILaneMasks),
62 RegClassBegin(RCB), RegClassEnd(RCE),
63 CoveringLanes(SRICoveringLanes),
64 RCInfos(RCIs), HwMode(Mode) {
74 if (
MI &&
TII->isTriviallyReMaterializable(*
MI) &&
90 for (
unsigned Reg : RegisterSet.set_bits()) {
94 if (!RegisterSet[*SR] && !
is_contained(Exceptions, Reg)) {
95 dbgs() <<
"Error: Super register " <<
printReg(*SR,
this)
96 <<
" of reserved register " <<
printReg(Reg,
this)
97 <<
" is not reserved.\n";
118 else if (Reg.isVirtual()) {
119 StringRef Name = MRI ? MRI->getVRegName(Reg) :
"";
123 OS <<
'%' << Register::virtReg2Index(Reg);
126 OS <<
'$' <<
"physreg" << Reg;
127 else if (Reg < TRI->getNumRegs()) {
129 printLowerCase(
TRI->getName(Reg),
OS);
135 OS <<
':' <<
TRI->getSubRegIndexName(SubIdx);
137 OS <<
":sub(" << SubIdx <<
')';
146 OS <<
"Unit~" << Unit;
151 if (Unit >=
TRI->getNumRegUnits()) {
152 OS <<
"BadUnit~" << Unit;
158 assert(Roots.isValid() &&
"Unit has no roots.");
159 OS <<
TRI->getName(*Roots);
160 for (++Roots; Roots.isValid(); ++Roots)
161 OS <<
'~' <<
TRI->getName(*Roots);
184 assert((RegInfo.def_empty(Reg) || RegInfo.getType(Reg).isValid()) &&
185 "Generic registers must have a valid type");
214 "reg must be a physical register");
221 RC->contains(reg) && (!BestRC || BestRC->
hasSubClass(RC)))
225 assert(BestRC &&
"Couldn't find the register class");
232 "reg must be a physical register");
266 if (
C->isAllocatable())
282 for (
unsigned I = 0,
E =
TRI->getNumRegClasses();
I <
E;
I += 32)
283 if (
unsigned Common = *
A++ & *
B++)
305 unsigned Idx)
const {
306 assert(
A &&
B &&
"Missing register class");
311 if (RCI.getSubReg() ==
Idx)
321 unsigned &PreA,
unsigned &PreB)
const {
322 assert(RCA && SubA && RCB && SubB &&
"Invalid arguments");
337 unsigned *BestPreA = &PreA;
338 unsigned *BestPreB = &PreB;
360 if (FinalA != FinalB)
369 *BestPreA = IA.getSubReg();
370 *BestPreB = IB.getSubReg();
386 unsigned SrcSubReg) {
392 unsigned SrcIdx, DefIdx;
393 if (SrcSubReg && DefSubReg) {
394 return TRI.getCommonSuperRegClass(SrcRC, SrcSubReg, DefRC, DefSubReg,
395 SrcIdx, DefIdx) !=
nullptr;
407 return TRI.getMatchingSuperRegClass(SrcRC, DefRC, SrcSubReg) !=
nullptr;
410 return TRI.getCommonSubClass(DefRC, SrcRC) !=
nullptr;
416 unsigned SrcSubReg)
const {
427 const std::pair<Register, SmallVector<Register, 4>> &Hints_MRI =
428 MRI.getRegAllocationHints(VirtReg);
432 bool Skip = (Hints_MRI.first != 0);
433 for (
auto Reg : Hints_MRI.second) {
446 if (!HintedRegs.
insert(Phys).second)
451 if (
MRI.isReserved(Phys))
469 const uint32_t *callerPreservedRegs =
471 if (callerPreservedRegs) {
473 "Expected physical register");
474 return (callerPreservedRegs[PhysReg / 32] >> PhysReg % 32) & 1;
487 return F.hasFnAttribute(
"stackrealign") ||
489 F.hasFnAttribute(Attribute::StackAlignment);
495 for (
unsigned I = 0;
I <
N; ++
I)
496 if ((mask0[
I] & mask1[
I]) != mask0[
I])
505 if (Reg.isPhysical()) {
511 LLT Ty =
MRI.getType(Reg);
518 RC =
MRI.getRegClass(Reg);
520 assert(RC &&
"Unable to deduce the register class");
528 unsigned BestIdx = 0;
529 unsigned BestCover = 0;
537 if (SubRegMask == LaneMask) {
543 if ((SubRegMask & ~LaneMask).any())
548 if (PopCount > BestCover) {
549 BestCover = PopCount;
562 LaneBitmask LanesLeft = LaneMask & ~getSubRegIndexLaneMask(BestIdx);
563 while (LanesLeft.
any()) {
564 unsigned BestIdx = 0;
565 int BestCover = std::numeric_limits<int>::min();
566 for (
unsigned Idx : PossibleIndexes) {
569 if (SubRegMask == LanesLeft) {
577 if ((SubRegMask & ~LanesLeft).any())
581 const int Cover = (SubRegMask & LanesLeft).getNumLanes();
582 if (Cover > BestCover) {
593 LanesLeft &= ~getSubRegIndexLaneMask(BestIdx);
604 if (!
MI->isCopyLike())
609 CopySrcReg =
MI->getOperand(1).getReg();
611 assert(
MI->isSubregToReg() &&
"Bad opcode for lookThruCopyLike");
612 CopySrcReg =
MI->getOperand(2).getReg();
627 if (!
MI->isCopyLike())
628 return MRI->hasOneNonDBGUse(SrcReg) ? SrcReg :
Register();
632 CopySrcReg =
MI->getOperand(1).getReg();
634 assert(
MI->isSubregToReg() &&
"Bad opcode for lookThruCopyLike");
635 CopySrcReg =
MI->getOperand(2).getReg();
640 if (!CopySrcReg.
isVirtual() || !
MRI->hasOneNonDBGUse(CopySrcReg))
649 assert(!
Offset.getScalable() &&
"Scalable offsets are not handled");
655 unsigned PrependFlags,
660 "Unsupported prepend flag");
663 OffsetExpr.
push_back(dwarf::DW_OP_deref);
666 OffsetExpr.
push_back(dwarf::DW_OP_deref);
672#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
unsigned const MachineRegisterInfo * MRI
This file contains the simple types necessary to represent the attributes associated with functions a...
This file implements the BitVector class.
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds.
Returns the sub type a function will return at a given Idx Should correspond to the result type of an ExtractValue instruction executed with just that one unsigned Idx
This file contains constants used for implementing Dwarf debug support.
const HexagonInstrInfo * TII
unsigned const TargetRegisterInfo * TRI
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
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 bool shareSameRegisterFile(const TargetRegisterInfo &TRI, const TargetRegisterClass *DefRC, unsigned DefSubReg, const TargetRegisterClass *SrcRC, unsigned SrcSubReg)
Check if the registers defined by the pair (RegisterClass, SubReg) share the same register file.
ArrayRef - 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.
static void appendOffset(SmallVectorImpl< uint64_t > &Ops, int64_t Offset)
Append Ops with operations to apply the Offset.
static 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...
bool hasFnAttribute(Attribute::AttrKind Kind) const
Return true if the function has the attribute.
constexpr bool isValid() const
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
isValid - returns true if this iterator is not yet at the end.
unsigned getNumSubRegIndices() const
Return the number of sub-register indices understood by the target.
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.
MCSuperRegIterator enumerates all super-registers of Reg.
The MachineFrameInfo class represents an abstract stack frame until prolog/epilog code is inserted.
Align getMaxAlign() const
Return the alignment in bytes that this function must be aligned to, which is greater than the defaul...
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,...
const TargetRegisterClass * getRegClass(Register Reg) const
Return the register class of the specified virtual register.
const RegisterBank * getRegBankOrNull(Register Reg) const
Return the register bank of Reg, or null if Reg has not been assigned a register bank or has been ass...
const TargetRegisterClass * getRegClassOrNull(Register Reg) const
Return the register class of Reg, or null if Reg has not been assigned a register class yet.
Simple wrapper around std::function<void(raw_ostream&)>.
const char * getName() const
Get a user friendly name of this register bank.
Wrapper class representing virtual and physical registers.
bool isPhysical() const
Return true if the specified register number is in the physical register namespace.
static bool isStackSlot(unsigned Reg)
isStackSlot - Sometimes it is useful the be able to store a non-negative frame index in a variable th...
static int stackSlot2Index(Register Reg)
Compute the frame index from a register value representing a stack slot.
static unsigned virtReg2Index(Register Reg)
Convert a virtual register number to a 0-based index.
static bool isVirtualRegister(unsigned Reg)
Return true if the specified register number is in the virtual register namespace.
bool isVirtual() const
Return true if the specified register number is in the virtual register namespace.
static bool isPhysicalRegister(unsigned Reg)
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 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.
StringRef - Represent a constant reference to a string, i.e.
std::string lower() const
bool isValid() const
Returns true if this iterator is still pointing at a valid entry.
Information about stack frame layout on the target.
Align getStackAlign() const
getStackAlignment - This method returns the number of bytes to which the stack pointer must be aligne...
TargetInstrInfo - Interface to description of machine instruction set.
bool isAllocatable() const
Return true if this register class may be used to create virtual registers.
bool hasSubClass(const TargetRegisterClass *RC) const
Return true if the specified TargetRegisterClass is a proper sub-class of this TargetRegisterClass.
const uint32_t * getSubClassMask() const
Returns a bit vector of subclasses, including this one.
ArrayRef< MCPhysReg > getRawAllocationOrder(const MachineFunction &MF) const
Returns the preferred order for allocating registers from this register class in MF.
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
const TargetRegisterClass *const * regclass_iterator
const TargetRegisterClass * getMinimalPhysRegClass(MCRegister Reg, MVT VT=MVT::Other) const
Returns the Register Class of a physical register of the given type, picking the most sub register cl...
iterator_range< regclass_iterator > regclasses() const
virtual bool shouldRegionSplitForVirtReg(const MachineFunction &MF, const LiveInterval &VirtReg) const
Region split has a high compile time cost especially for large live range.
virtual bool canRealignStack(const MachineFunction &MF) const
True if the stack can be realigned for the target.
unsigned getRegSizeInBits(const TargetRegisterClass &RC) const
Return the size in bits of a register from class RC.
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.
unsigned composeSubRegIndices(unsigned a, unsigned b) const
Return the subregister index you get from composing two subregister indices.
const TargetRegisterClass * getCommonSubClass(const TargetRegisterClass *A, const TargetRegisterClass *B) const
Find the largest common subclass of A and B.
const TargetRegisterClass * getMinimalPhysRegClassLLT(MCRegister Reg, LLT Ty=LLT()) const
Returns the Register Class of a physical register of the given type, picking the most sub register cl...
void markSuperRegs(BitVector &RegisterSet, MCRegister Reg) const
Mark a register and all its aliases as reserved in the given set.
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.
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 ~TargetRegisterInfo()
virtual bool shouldRewriteCopySrc(const TargetRegisterClass *DefRC, unsigned DefSubReg, const TargetRegisterClass *SrcRC, unsigned SrcSubReg) const
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.
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 ...
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.
static void dumpReg(Register Reg, unsigned SubRegIndex=0, const TargetRegisterInfo *TRI=nullptr)
Debugging helper: dump register in human readable form to dbgs() stream.
TargetRegisterInfo(const TargetRegisterInfoDesc *ID, regclass_iterator RCB, regclass_iterator RCE, const char *const *SRINames, const LaneBitmask *SRILaneMasks, LaneBitmask CoveringLanes, const RegClassInfo *const RCIs, unsigned Mode=0)
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.
virtual bool isCalleeSavedPhysReg(MCRegister PhysReg, const MachineFunction &MF) const
This is a wrapper around getCallPreservedMask().
bool isTypeLegalForClass(const TargetRegisterClass &RC, MVT T) const
Return true if the given TargetRegisterClass has the ValueType T.
bool getCoveringSubRegIndexes(const MachineRegisterInfo &MRI, const TargetRegisterClass *RC, LaneBitmask LaneMask, SmallVectorImpl< unsigned > &Indexes) const
Try to find one or more subregister indexes to cover LaneMask.
virtual const TargetRegisterClass * getMatchingSuperRegClass(const TargetRegisterClass *A, const TargetRegisterClass *B, unsigned Idx) const
Return a subclass of the specified register class A so that each register in it has a sub-register of...
virtual void getOffsetOpcodes(const StackOffset &Offset, SmallVectorImpl< uint64_t > &Ops) const
Gets the DWARF expression opcodes for Offset.
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 TargetFrameLowering * getFrameLowering() const
virtual const TargetInstrInfo * getInstrInfo() const
MCRegister getPhys(Register virtReg) const
returns the physical register mapped to the specified virtual register
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.
@ C
The default llvm calling convention, compatible with C.
initializer< Ty > init(const Ty &Val)
This is an optimization pass for GlobalISel generic memory operations.
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.
Printable printVRegOrUnit(unsigned VRegOrUnit, const TargetRegisterInfo *TRI)
Create Printable object to print virtual registers and physical registers on a raw_ostream.
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Printable printRegClassOrBank(Register Reg, const MachineRegisterInfo &RegInfo, const TargetRegisterInfo *TRI)
Create Printable object to print register classes or register banks on a raw_ostream.
bool is_contained(R &&Range, const E &Element)
Returns true if Element is found in Range.
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.
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.