32 #define DEBUG_TYPE "registerbankinfo"
37 "Number of partial mappings dynamically created");
39 "Number of partial mappings dynamically accessed");
41 "Number of value mappings dynamically created");
43 "Number of value mappings dynamically accessed");
45 "Number of operands mappings dynamically created");
47 "Number of operands mappings dynamically accessed");
49 "Number of instruction mappings dynamically created");
51 "Number of instruction mappings dynamically accessed");
61 : RegBanks(RegBanks), NumRegBanks(NumRegBanks) {
64 assert(RegBanks[Idx] !=
nullptr &&
"Invalid RegisterBank");
65 assert(RegBanks[Idx]->
isValid() &&
"RegisterBank should be valid");
75 "ID does not match the index in the array");
76 DEBUG(
dbgs() <<
"Verify " << RegBank <<
'\n');
89 assert(Reg &&
"NoRegister does not have a register bank");
111 "The mapping of the register bank does not make sense");
125 if (RB && !RB->
covers(RC))
141 MI.
getOpcode() == TargetOpcode::REG_SEQUENCE;
152 unsigned NumOperandsForMapping = IsCopyLike ? 1 : MI.
getNumOperands();
163 bool CompleteMapping =
true;
166 for (
unsigned OpIdx = 0, EndIdx = MI.
getNumOperands(); OpIdx != EndIdx;
183 const RegisterBank *CurRegBank = IsCopyLike ? AltRegBank :
nullptr;
190 CompleteMapping =
false;
201 OperandsMapping[0] = ValMapping;
202 CompleteMapping =
true;
205 OperandsMapping[OpIdx] = ValMapping;
208 if (IsCopyLike && !CompleteMapping)
212 assert(CompleteMapping &&
"Setting an uncomplete mapping");
216 NumOperandsForMapping);
235 ++NumPartialMappingsAccessed;
242 ++NumPartialMappingsCreated;
245 PartMapping = llvm::make_unique<PartialMapping>(StartIdx, Length, RegBank);
257 unsigned NumBreakDowns) {
261 for (
unsigned Idx = 0; Idx != NumBreakDowns; ++Idx)
268 unsigned NumBreakDowns)
const {
269 ++NumValueMappingsAccessed;
276 ++NumValueMappingsCreated;
279 ValMapping = llvm::make_unique<ValueMapping>(BreakDown, NumBreakDowns);
283 template <
typename Iterator>
287 ++NumOperandsMappingsAccessed;
296 ++NumOperandsMappingsCreated;
303 Res = llvm::make_unique<ValueMapping[]>(std::distance(Begin, End));
305 for (Iterator It = Begin; It !=
End; ++It, ++Idx) {
321 std::initializer_list<const RegisterBankInfo::ValueMapping *> OpdsMapping)
329 unsigned NumOperands) {
330 return hash_combine(ID, Cost, OperandsMapping, NumOperands);
334 RegisterBankInfo::getInstructionMappingImpl(
335 bool IsInvalid,
unsigned ID,
unsigned Cost,
337 unsigned NumOperands)
const {
339 OperandsMapping ==
nullptr && NumOperands == 0) ||
341 "Mismatch argument for invalid input");
342 ++NumInstructionMappingsAccessed;
350 ++NumInstructionMappingsCreated;
354 InstrMapping = llvm::make_unique<InstructionMapping>();
356 InstrMapping = llvm::make_unique<InstructionMapping>(
357 ID, Cost, OperandsMapping, NumOperands);
358 return *InstrMapping;
370 RegisterBankInfo::getInstrPossibleMappings(
const MachineInstr &
MI)
const {
380 assert(Mapping->verify(MI) &&
"Mapping is invalid");
382 return PossibleMappings;
394 DEBUG(
dbgs() <<
"Applying default-like mapping\n");
395 for (
unsigned OpIdx = 0,
397 OpIdx != EndIdx; ++OpIdx) {
401 DEBUG(
dbgs() <<
" is not a register, nothing to be done\n");
405 DEBUG(
dbgs() <<
" is %%noreg, nothing to be done\n");
413 "This mapping is too complex for this function");
416 if (NewRegs.begin() == NewRegs.end()) {
417 DEBUG(
dbgs() <<
" has not been repaired, nothing to be done\n");
420 unsigned OrigReg = MO.
getReg();
421 unsigned NewReg = *NewRegs.begin();
430 if (OrigTy != NewTy) {
432 "Types with difference size cannot be handled by the default "
434 DEBUG(
dbgs() <<
"\nChange type of new opd from " << NewTy <<
" to "
461 assert(RC &&
"Unable to deduce the register class");
468 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
476 assert(RegBank &&
"Register bank not set");
477 assert(Length &&
"Empty mapping");
478 assert((StartIdx <= getHighBitIdx()) &&
"Overflow, switch to APInt?");
480 assert(RegBank->
getSize() >= Length &&
"Register bank too small for Mask");
485 OS <<
"[" << StartIdx <<
", " << getHighBitIdx() <<
"], RegBank = ";
493 assert(NumBreakDowns &&
"Value mapped nowhere?!");
494 unsigned OrigValueBitWidth = 0;
498 assert(PartMap.
verify() &&
"Partial mapping is invalid");
504 assert(OrigValueBitWidth >= MeaningfulBitWidth &&
505 "Meaningful bits not covered by the mapping");
506 APInt ValueMask(OrigValueBitWidth, 0);
513 ValueMask ^= PartMapMask;
514 assert((ValueMask & PartMapMask) == PartMapMask &&
515 "Some partial mappings overlap");
521 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
529 OS <<
"#BreakDown: " << NumBreakDowns <<
" ";
534 OS <<
'[' << PartMap <<
']';
545 "NumOperands must match, see constructor");
547 "MI must be connected to a MachineFunction");
551 for (
unsigned Idx = 0; Idx < NumOperands; ++Idx) {
555 "We should not care about non-reg mapping");
558 unsigned Reg = MO.
getReg();
562 "We must have a mapping for reg operands");
568 Reg, MF.getRegInfo(), *MF.getSubtarget().getRegisterInfo())) &&
569 "Value mapping is invalid");
574 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
582 OS <<
"ID: " <<
getID() <<
" Cost: " << getCost() <<
" Mapping: ";
584 for (
unsigned OpIdx = 0; OpIdx != NumOperands; ++OpIdx) {
585 const ValueMapping &ValMapping = getOperandMapping(OpIdx);
588 OS <<
"{ Idx: " << OpIdx <<
" Map: " << ValMapping <<
'}';
592 const int RegisterBankInfo::OperandsMapper::DontKnowIdx = -1;
597 : MRI(MRI), MI(MI), InstrMapping(InstrMapping) {
599 OpToNewVRegIdx.
resize(NumOpds, OperandsMapper::DontKnowIdx);
600 assert(InstrMapping.
verify(MI) &&
"Invalid mapping for MI");
604 RegisterBankInfo::OperandsMapper::getVRegsMem(
unsigned OpIdx) {
606 unsigned NumPartialVal =
608 int StartIdx = OpToNewVRegIdx[OpIdx];
610 if (StartIdx == OperandsMapper::DontKnowIdx) {
614 StartIdx = NewVRegs.size();
615 OpToNewVRegIdx[OpIdx] = StartIdx;
616 for (
unsigned i = 0; i < NumPartialVal; ++i)
617 NewVRegs.push_back(0);
620 getNewVRegsEnd(StartIdx, NumPartialVal);
626 RegisterBankInfo::OperandsMapper::getNewVRegsEnd(
unsigned StartIdx,
627 unsigned NumVal)
const {
628 return const_cast<OperandsMapper *
>(
this)->getNewVRegsEnd(StartIdx, NumVal);
631 RegisterBankInfo::OperandsMapper::getNewVRegsEnd(
unsigned StartIdx,
633 assert((NewVRegs.size() == StartIdx + NumVal ||
634 NewVRegs.size() > StartIdx + NumVal) &&
635 "NewVRegs too small to contain all the partial mapping");
636 return NewVRegs.size() <= StartIdx + NumVal ? NewVRegs.end()
637 : &NewVRegs[StartIdx + NumVal];
646 for (
unsigned &NewVReg : NewVRegsForOpIdx) {
647 assert(PartMap != ValMapping.
end() &&
"Out-of-bound access");
648 assert(NewVReg == 0 &&
"Register has already been created");
661 unsigned PartialMapIdx,
666 "Out-of-bound access for partial mapping");
668 (void)getVRegsMem(OpIdx);
669 assert(NewVRegs[OpToNewVRegIdx[OpIdx] + PartialMapIdx] == 0 &&
670 "This value is already set");
671 NewVRegs[OpToNewVRegIdx[OpIdx] + PartialMapIdx] = NewVReg;
676 bool ForDebug)
const {
679 int StartIdx = OpToNewVRegIdx[OpIdx];
681 if (StartIdx == OperandsMapper::DontKnowIdx)
682 return make_range(NewVRegs.end(), NewVRegs.end());
684 unsigned PartMapSize =
687 getNewVRegsEnd(StartIdx, PartMapSize);
691 for (
unsigned VReg : Res)
692 assert((VReg || ForDebug) &&
"Some registers are uninitialized");
697 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
705 bool ForDebug)
const {
708 OS <<
"Mapping for " << getMI() <<
"\nwith " <<
getInstrMapping() <<
'\n';
710 OS <<
"Populated indices (CellNumber, IndexInNewVRegs): ";
712 for (
unsigned Idx = 0; Idx != NumOpds; ++Idx) {
713 if (OpToNewVRegIdx[Idx] != DontKnowIdx) {
716 OS <<
'(' << Idx <<
", " << OpToNewVRegIdx[Idx] <<
')';
724 OS <<
"Operand Mapping: ";
728 getMI().getParent() && getMI().getParent()->getParent()
729 ? getMI().getParent()->getParent()->getSubtarget().getRegisterInfo()
732 for (
unsigned Idx = 0; Idx != NumOpds; ++Idx) {
733 if (OpToNewVRegIdx[Idx] == DontKnowIdx)
738 OS <<
'(' <<
PrintReg(getMI().getOperand(Idx).
getReg(), TRI) <<
", [";
739 bool IsFirstNewVReg =
true;
740 for (
unsigned VReg : getVRegs(Idx)) {
743 IsFirstNewVReg =
false;
unsigned NumRegBanks
Total number of register banks.
void dump() const
Print this on dbgs() stream.
static const unsigned InvalidMappingID
Identifier used when the related instruction mapping instance is generated by the default constructor...
RegisterBank ** RegBanks
Hold the set of supported register banks.
void push_back(const T &Elt)
const MachineFunction * getParent() const
Return the MachineFunction containing this basic block.
const InstructionMapping & getInvalidInstructionMapping() const
Method to get a uniquely generated invalid InstructionMapping.
Helper class that represents how the value of an instruction may be mapped and what is the related co...
const InstructionMapping & getInstructionMapping(unsigned ID, unsigned Cost, const ValueMapping *OperandsMapping, unsigned NumOperands) const
Method to get a uniquely generated InstructionMapping.
GCNRegPressure max(const GCNRegPressure &P1, const GCNRegPressure &P2)
virtual const RegisterBank & getRegBankFromRegClass(const TargetRegisterClass &RC) const
Get a register bank that covers RC.
LLT getType(unsigned VReg) const
Get the low-level type of VReg or LLT{} if VReg is not a generic (target independent) virtual registe...
STATISTIC(NumFunctions,"Total number of functions")
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds...
unsigned getHighBitIdx() const
#define LLVM_LIKELY(EXPR)
DenseMap< unsigned, std::unique_ptr< const PartialMapping > > MapOfPartialMappings
Keep dynamically allocated PartialMapping in a separate map.
Helper class that represents how the value of an instruction may be mapped and what is the related co...
unsigned getRegSizeInBits(const TargetRegisterClass &RC) const
Return the size in bits of a register from class RC.
This provides a very simple, boring adaptor for a begin and end iterator into a range type...
T dyn_cast() const
Returns the current pointer if it is of the specified pointer type, otherwises returns null...
const ValueMapping & getValueMapping(unsigned StartIdx, unsigned Length, const RegisterBank &RegBank) const
The most common ValueMapping consists of a single PartialMapping.
iterator_range< SmallVectorImpl< unsigned >::const_iterator > getVRegs(unsigned OpIdx, bool ForDebug=false) const
Get all the virtual registers required to map the OpIdx-th operand of the instruction.
Helper class used to get/create the virtual registers that will be used to replace the MachineOperand...
void setRegBank(unsigned Reg, const RegisterBank &RegBank)
Set the register bank to RegBank for Reg.
unsigned createGenericVirtualRegister(LLT Ty)
Create and return a new generic virtual register with low-level type Ty.
static hash_code hashValueMapping(const RegisterBankInfo::PartialMapping *BreakDown, unsigned NumBreakDowns)
bool verify(const TargetRegisterInfo &TRI) const
Check if this register bank is valid.
virtual const InstructionMapping & getInstrMapping(const MachineInstr &MI) const
Get the mapping of the different operands of MI on the register bank.
void print(raw_ostream &OS, bool ForDebug=false) const
Print this operands mapper on OS stream.
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
const HexagonInstrInfo * TII
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
bool isReg() const
isReg - Tests if this is a MO_Register operand.
const TargetRegisterClass * getRegClass(unsigned Reg) const
Return the register class of the specified virtual register.
Reg
All possible values of the reg field in the ModR/M byte.
unsigned StartIdx
Number of bits at which this partial mapping starts in the original value.
const RegisterBank * getRegBankFromConstraints(const MachineInstr &MI, unsigned OpIdx, const TargetInstrInfo &TII, const TargetRegisterInfo &TRI) const
Get the register bank for the OpIdx-th operand of MI form the encoding constraints, if any.
unsigned getNumOperands() const
Access to explicit operands of the instruction.
bool verify(unsigned MeaningfulBitWidth) const
Verify that this mapping makes sense for a value of MeaningfulBitWidth.
virtual InstructionMappings getInstrAlternativeMappings(const MachineInstr &MI) const
Get the alternative mappings for MI.
bool verify() const
Check that the Mask is compatible with the RegBank.
static int getID(struct InternalInstruction *insn, const void *miiArg)
hash_code hash_value(const APFloat &Arg)
See friend declarations above.
static LLT scalar(unsigned SizeInBits)
Get a low-level scalar or aggregate "bag of bits".
Printable PrintReg(unsigned Reg, const TargetRegisterInfo *TRI=nullptr, unsigned SubRegIdx=0)
Prints virtual and physical registers with or without a TRI instance.
const TargetRegisterClass * constrainRegClass(unsigned Reg, const TargetRegisterClass *RC, unsigned MinNumRegs=0)
constrainRegClass - Constrain the register class of the specified virtual register to be a common sub...
const ValueMapping * getOperandsMapping(Iterator Begin, Iterator End) const
Get the uniquely generated array of ValueMapping for the elements of between Begin and End...
const RegisterBank * RegBank
Register bank where the partial value lives.
unsigned getOpcode() const
Returns the opcode of this MachineInstr.
const MachineBasicBlock * getParent() const
TargetInstrInfo - Interface to description of machine instruction set.
void setVRegs(unsigned OpIdx, unsigned PartialMapIdx, unsigned NewVReg)
Set the virtual register of the PartialMapIdx-th partial mapping of the OpIdx-th operand to NewVReg...
* if(!EatIfPresent(lltok::kw_thread_local)) return false
ParseOptionalThreadLocal := /*empty.
unsigned const MachineRegisterInfo * MRI
static unsigned getSizeInBits(unsigned Reg, const MachineRegisterInfo &MRI, const TargetRegisterInfo &TRI)
Get the size in bits of Reg.
LLVM_ATTRIBUTE_ALWAYS_INLINE iterator begin()
const MachineOperand & getOperand(unsigned i) const
const InstructionMapping & getInstrMapping() const
The final mapping of the instruction.
unsigned getID() const
Get the identifier of this register bank.
Helper struct that represents how a value is partially mapped into a register.
unsigned Length
Length of this mapping in bits.
void setType(unsigned VReg, LLT Ty)
Set the low-level type of VReg to Ty.
static bool isCopyLike(const MachineInstr &MI)
Check whether or not MI should be treated like a copy for the mappings.
static const unsigned End
static const unsigned DefaultMappingID
Identifier used when the related instruction mapping instance is generated by target independent code...
MachineInstr & getMI() const
const PartialMapping * begin() const
Iterators through the PartialMappings.
void dump() const
Print this partial mapping on dbgs() stream.
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
Helper class used to get/create the virtual registers that will be used to replace the MachineOperand...
OperandsMapper(MachineInstr &MI, const InstructionMapping &InstrMapping, MachineRegisterInfo &MRI)
Create an OperandsMapper that will hold the information to apply InstrMapping to MI.
static hash_code hashPartialMapping(unsigned StartIdx, unsigned Length, const RegisterBank *RegBank)
Hashing function for PartialMapping.
MachineRegisterInfo & getMRI() const
The MachineRegisterInfo we used to realize the mapping.
RegisterBank & getRegBank(unsigned ID)
Get the register bank identified by ID.
MachineOperand class - Representation of each machine instruction operand.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
static void applyDefaultMapping(const OperandsMapper &OpdMapper)
Helper method to apply something that is like the default mapping.
This class implements the register bank concept.
Helper struct that represents how a value is mapped through different register banks.
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
A range adaptor for a pair of iterators.
void dump() const
Print this operands mapper on dbgs() stream.
Class for arbitrary precision integers.
const TargetRegisterClass * getRegClassConstraint(unsigned OpIdx, const TargetInstrInfo *TII, const TargetRegisterInfo *TRI) const
Compute the static register class constraint for operand OpIdx.
hash_code hash_combine(const Ts &...args)
Combine values into a single hash_code.
static unsigned getReg(const void *D, unsigned RC, unsigned RegNo)
void print(raw_ostream &OS) const
Print this on OS;.
const TargetRegisterClass * getMinimalPhysRegClass(unsigned Reg, MVT VT=MVT::Other) const
Returns the Register Class of a physical register of the given type, picking the most sub register cl...
bool isValid() const
Check whether this object is valid.
static hash_code hashInstructionMapping(unsigned ID, unsigned Cost, const RegisterBankInfo::ValueMapping *OperandsMapping, unsigned NumOperands)
hash_code hash_combine_range(InputIteratorT first, InputIteratorT last)
Compute a hash_code for a sequence of values.
An opaque object representing a hash code.
void createVRegs(unsigned OpIdx)
Create as many new virtual registers as needed for the mapping of the OpIdx-th operand.
static APInt getBitsSet(unsigned numBits, unsigned loBit, unsigned hiBit)
Get a value with a block of bits set.
llvm_unreachable("Unknown RegBank!")
MachineRegisterInfo - Keep track of information for virtual and physical registers, including vreg register classes, use/def chains for registers, etc.
TargetSubtargetInfo - Generic base class for all target subtargets.
bool isAllOnesValue() const
Determine if all bits are set.
Representation of each machine instruction.
static bool isPhysicalRegister(unsigned Reg)
Return true if the specified register number is in the physical register namespace.
LLVM_ATTRIBUTE_ALWAYS_INLINE iterator end()
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
void print(raw_ostream &OS) const
Print this on OS;.
const RegClassOrRegBank & getRegClassOrRegBank(unsigned Reg) const
Return the register bank or register class of Reg.
DenseMap< unsigned, std::unique_ptr< ValueMapping[]> > MapOfOperandsMappings
Keep dynamically allocated array of ValueMapping in a separate map.
void setReg(unsigned Reg)
Change the register this operand corresponds to.
unsigned getNumRegBanks() const
Get the total number of register banks.
static const TargetRegisterClass * constrainGenericRegister(unsigned Reg, const TargetRegisterClass &RC, MachineRegisterInfo &MRI)
Constrain the (possibly generic) virtual register Reg to RC.
unsigned getNumOperands() const
Get the number of operands.
unsigned getSize() const
Get the maximal size in bits that fits in this register bank.
unsigned getID() const
Get the ID.
INITIALIZE_PASS(HexagonGenMux,"hexagon-gen-mux","Hexagon generate mux instructions", false, false) void HexagonGenMux I isValid()
bool covers(const TargetRegisterClass &RC) const
Check whether this register bank covers RC.
unsigned getReg() const
getReg - Returns the register number.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
const InstructionMapping & getInstrMappingImpl(const MachineInstr &MI) const
Try to get the mapping of MI.
void dump() const
Print this on dbgs() stream.
unsigned NumBreakDowns
Number of partial mapping to break down this value.
virtual const TargetInstrInfo * getInstrInfo() const
bool verify(const MachineInstr &MI) const
Verifiy that this mapping makes sense for MI.
const PartialMapping & getPartialMapping(unsigned StartIdx, unsigned Length, const RegisterBank &RegBank) const
Get the uniquely generated PartialMapping for the given arguments.
This class implements an extremely fast bulk output stream that can only output to a stream...
DenseMap< unsigned, std::unique_ptr< const InstructionMapping > > MapOfInstructionMappings
Keep dynamically allocated InstructionMapping in a separate map.
std::string Hash(const Unit &U)
const PartialMapping * end() const
virtual const TargetRegisterInfo * getRegisterInfo() const
getRegisterInfo - If register information is available, return it.
void setRegClass(unsigned Reg, const TargetRegisterClass *RC)
setRegClass - Set the register class of the specified virtual register.
unsigned getSizeInBits() const
Returns the total size of the type. Must only be called on sized types.
RegisterBankInfo()
This constructor is meaningless.
DenseMap< unsigned, std::unique_ptr< const ValueMapping > > MapOfValueMappings
Keep dynamically allocated ValueMapping in a separate map.
SmallVector< const InstructionMapping *, 4 > InstructionMappings
Convenient type to represent the alternatives for mapping an instruction.
void print(raw_ostream &OS) const
Print this partial mapping on OS;.
A discriminated union of two pointer types, with the discriminator in the low bit of the pointer...