Skip to content

Commit

Permalink
Move value type list from TargetRegisterClass to TargetRegisterInfo
Browse files Browse the repository at this point in the history
Differential Revision: https://reviews.llvm.org/D31937

llvm-svn: 301231
  • Loading branch information
Krzysztof Parzyszek committed Apr 24, 2017
1 parent 0774ea2 commit c019706
Show file tree
Hide file tree
Showing 16 changed files with 77 additions and 68 deletions.
3 changes: 2 additions & 1 deletion llvm/include/llvm/Target/TargetLowering.h
Expand Up @@ -2274,7 +2274,8 @@ class TargetLoweringBase {

/// Return true if the value types that can be represented by the specified
/// register class are all legal.
bool isLegalRC(const TargetRegisterClass *RC) const;
bool isLegalRC(const TargetRegisterInfo &TRI,
const TargetRegisterClass &RC) const;

/// Replace/modify any TargetFrameIndex operands with a targte-dependent
/// sequence of memory operands that is recognized by PrologEpilogInserter.
Expand Down
45 changes: 23 additions & 22 deletions llvm/include/llvm/Target/TargetRegisterInfo.h
Expand Up @@ -40,13 +40,12 @@ class TargetRegisterClass {
public:
typedef const MCPhysReg* iterator;
typedef const MCPhysReg* const_iterator;
typedef const MVT::SimpleValueType* vt_iterator;
typedef const TargetRegisterClass* const * sc_iterator;

// Instance variables filled by tablegen, do not use!
const MCRegisterClass *MC;
const uint16_t SpillSize, SpillAlignment;
const vt_iterator VTs;
const MVT::SimpleValueType *VTs;
const uint32_t *SubClassMask;
const uint16_t *SuperRegIndices;
const LaneBitmask LaneMask;
Expand Down Expand Up @@ -102,26 +101,6 @@ class TargetRegisterClass {
/// registers.
bool isAllocatable() const { return MC->isAllocatable(); }

/// Return true if this TargetRegisterClass has the ValueType vt.
bool hasType(MVT vt) const {
for(int i = 0; VTs[i] != MVT::Other; ++i)
if (MVT(VTs[i]) == vt)
return true;
return false;
}

/// vt_begin / vt_end - Loop over all of the value types that can be
/// represented by values in this register class.
vt_iterator vt_begin() const {
return VTs;
}

vt_iterator vt_end() const {
vt_iterator I = VTs;
while (*I != MVT::Other) ++I;
return I;
}

/// Return true if the specified TargetRegisterClass
/// is a proper sub-class of this TargetRegisterClass.
bool hasSubClass(const TargetRegisterClass *RC) const {
Expand Down Expand Up @@ -239,6 +218,7 @@ struct RegClassWeight {
class TargetRegisterInfo : public MCRegisterInfo {
public:
typedef const TargetRegisterClass * const * regclass_iterator;
typedef const MVT::SimpleValueType* vt_iterator;
private:
const TargetRegisterInfoDesc *InfoDesc; // Extra desc array for codegen
const char *const *SubRegIndexNames; // Names of subreg indexes.
Expand Down Expand Up @@ -337,6 +317,27 @@ class TargetRegisterInfo : public MCRegisterInfo {
return RC.SpillAlignment;
}

/// Return true if the given TargetRegisterClass has the ValueType T.
bool hasType(const TargetRegisterClass &RC, MVT T) const {
for (int i = 0; RC.VTs[i] != MVT::Other; ++i)
if (MVT(RC.VTs[i]) == T)
return true;
return false;
}

/// Loop over all of the value types that can be represented by values
// in the given register class.
vt_iterator valuetypes_begin(const TargetRegisterClass &RC) const {
return RC.VTs;
}

vt_iterator valuetypes_end(const TargetRegisterClass &RC) const {
vt_iterator I = RC.VTs;
while (*I != MVT::Other)
++I;
return I;
}

/// Returns the Register Class of a physical register of the given type,
/// picking the most sub register class of the right type that contains this
/// physreg.
Expand Down
3 changes: 2 additions & 1 deletion llvm/lib/CodeGen/SelectionDAG/InstrEmitter.cpp
Expand Up @@ -161,7 +161,8 @@ EmitCopyFromReg(SDNode *Node, unsigned ResNo, bool IsClone, bool IsCloned,
if (VRBase) {
DstRC = MRI->getRegClass(VRBase);
} else if (UseRC) {
assert(UseRC->hasType(VT) && "Incompatible phys register def and uses!");
assert(TRI->hasType(*UseRC, VT) &&
"Incompatible phys register def and uses!");
DstRC = UseRC;
} else {
DstRC = TLI->getRegClassFor(VT);
Expand Down
14 changes: 7 additions & 7 deletions llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
Expand Up @@ -6653,12 +6653,12 @@ static void GetRegistersForValue(SelectionDAG &DAG, const TargetLowering &TLI,

MachineFunction &MF = DAG.getMachineFunction();
SmallVector<unsigned, 4> Regs;
const TargetRegisterInfo &TRI = *MF.getSubtarget().getRegisterInfo();

// If this is a constraint for a single physreg, or a constraint for a
// register class, find it.
std::pair<unsigned, const TargetRegisterClass *> PhysReg =
TLI.getRegForInlineAsmConstraint(MF.getSubtarget().getRegisterInfo(),
OpInfo.ConstraintCode,
TLI.getRegForInlineAsmConstraint(&TRI, OpInfo.ConstraintCode,
OpInfo.ConstraintVT);

unsigned NumRegs = 1;
Expand All @@ -6667,11 +6667,11 @@ static void GetRegistersForValue(SelectionDAG &DAG, const TargetLowering &TLI,
// cast of the input value. More generally, handle any case where the input
// value disagrees with the register class we plan to stick this in.
if (OpInfo.Type == InlineAsm::isInput &&
PhysReg.second && !PhysReg.second->hasType(OpInfo.ConstraintVT)) {
PhysReg.second && !TRI.hasType(*PhysReg.second, OpInfo.ConstraintVT)) {
// Try to convert to the first EVT that the reg class contains. If the
// types are identical size, use a bitcast to convert (e.g. two differing
// vector types).
MVT RegVT = *PhysReg.second->vt_begin();
MVT RegVT = *TRI.valuetypes_begin(*PhysReg.second);
if (RegVT.getSizeInBits() == OpInfo.CallOperand.getValueSizeInBits()) {
OpInfo.CallOperand = DAG.getNode(ISD::BITCAST, DL,
RegVT, OpInfo.CallOperand);
Expand Down Expand Up @@ -6699,12 +6699,12 @@ static void GetRegistersForValue(SelectionDAG &DAG, const TargetLowering &TLI,
if (unsigned AssignedReg = PhysReg.first) {
const TargetRegisterClass *RC = PhysReg.second;
if (OpInfo.ConstraintVT == MVT::Other)
ValueVT = *RC->vt_begin();
ValueVT = *TRI.valuetypes_begin(*RC);

// Get the actual register value type. This is important, because the user
// may have asked for (e.g.) the AX register in i32 type. We need to
// remember that AX is actually i16 to get the right extension.
RegVT = *RC->vt_begin();
RegVT = *TRI.valuetypes_begin(*RC);

// This is a explicit reference to a physical register.
Regs.push_back(AssignedReg);
Expand All @@ -6730,7 +6730,7 @@ static void GetRegistersForValue(SelectionDAG &DAG, const TargetLowering &TLI,
// Otherwise, if this was a reference to an LLVM register class, create vregs
// for this reference.
if (const TargetRegisterClass *RC = PhysReg.second) {
RegVT = *RC->vt_begin();
RegVT = *TRI.valuetypes_begin(*RC);
if (OpInfo.ConstraintVT == MVT::Other)
ValueVT = RegVT;

Expand Down
6 changes: 3 additions & 3 deletions llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp
Expand Up @@ -2541,7 +2541,7 @@ TargetLowering::getRegForInlineAsmConstraint(const TargetRegisterInfo *RI,
for (const TargetRegisterClass *RC : RI->regclasses()) {
// If none of the value types for this register class are valid, we
// can't use it. For example, 64-bit reg classes on 32-bit targets.
if (!isLegalRC(RC))
if (!isLegalRC(*RI, *RC))
continue;

for (TargetRegisterClass::iterator I = RC->begin(), E = RC->end();
Expand All @@ -2553,9 +2553,9 @@ TargetLowering::getRegForInlineAsmConstraint(const TargetRegisterInfo *RI,
// If this register class has the requested value type, return it,
// otherwise keep searching and return the first class found
// if no other is found which explicitly has the requested type.
if (RC->hasType(VT))
if (RI->hasType(*RC, VT))
return S;
else if (!R.second)
if (!R.second)
R = S;
}
}
Expand Down
9 changes: 4 additions & 5 deletions llvm/lib/CodeGen/TargetLoweringBase.cpp
Expand Up @@ -1184,12 +1184,11 @@ static unsigned getVectorTypeBreakdownMVT(MVT VT, MVT &IntermediateVT,

/// isLegalRC - Return true if the value types that can be represented by the
/// specified register class are all legal.
bool TargetLoweringBase::isLegalRC(const TargetRegisterClass *RC) const {
for (TargetRegisterClass::vt_iterator I = RC->vt_begin(), E = RC->vt_end();
I != E; ++I) {
bool TargetLoweringBase::isLegalRC(const TargetRegisterInfo &TRI,
const TargetRegisterClass &RC) const {
for (auto I = TRI.valuetypes_begin(RC); *I != MVT::Other; ++I)
if (isTypeLegal(*I))
return true;
}
return false;
}

Expand Down Expand Up @@ -1301,7 +1300,7 @@ TargetLoweringBase::findRepresentativeClass(const TargetRegisterInfo *TRI,
// We want the largest possible spill size.
if (TRI->getSpillSize(*SuperRC) <= TRI->getSpillSize(*BestRC))
continue;
if (!isLegalRC(SuperRC))
if (!isLegalRC(*TRI, *SuperRC))
continue;
BestRC = SuperRC;
}
Expand Down
4 changes: 2 additions & 2 deletions llvm/lib/CodeGen/TargetRegisterInfo.cpp
Expand Up @@ -156,7 +156,7 @@ TargetRegisterInfo::getMinimalPhysRegClass(unsigned reg, MVT VT) const {
// this physreg.
const TargetRegisterClass* BestRC = nullptr;
for (const TargetRegisterClass* RC : regclasses()) {
if ((VT == MVT::Other || RC->hasType(VT)) && RC->contains(reg) &&
if ((VT == MVT::Other || hasType(*RC, VT)) && RC->contains(reg) &&
(!BestRC || BestRC->hasSubClass(RC)))
BestRC = RC;
}
Expand Down Expand Up @@ -207,7 +207,7 @@ const TargetRegisterClass *firstCommonClass(const uint32_t *A,
if (unsigned Common = *A++ & *B++) {
const TargetRegisterClass *RC =
TRI->getRegClass(I + countTrailingZeros(Common));
if (SVT == MVT::SimpleValueType::Any || RC->hasType(VT))
if (SVT == MVT::SimpleValueType::Any || TRI->hasType(*RC, VT))
return RC;
}
return nullptr;
Expand Down
8 changes: 4 additions & 4 deletions llvm/lib/Target/AVR/AVRInstrInfo.cpp
Expand Up @@ -142,9 +142,9 @@ void AVRInstrInfo::storeRegToStackSlot(MachineBasicBlock &MBB,
MFI.getObjectAlignment(FrameIndex));

unsigned Opcode = 0;
if (RC->hasType(MVT::i8)) {
if (TRI->hasType(*RC, MVT::i8)) {
Opcode = AVR::STDPtrQRr;
} else if (RC->hasType(MVT::i16)) {
} else if (TRI->hasType(*RC, MVT::i16)) {
Opcode = AVR::STDWPtrQRr;
} else {
llvm_unreachable("Cannot store this register into a stack slot!");
Expand Down Expand Up @@ -176,9 +176,9 @@ void AVRInstrInfo::loadRegFromStackSlot(MachineBasicBlock &MBB,
MFI.getObjectAlignment(FrameIndex));

unsigned Opcode = 0;
if (RC->hasType(MVT::i8)) {
if (TRI->hasType(*RC, MVT::i8)) {
Opcode = AVR::LDDRdPtrQ;
} else if (RC->hasType(MVT::i16)) {
} else if (TRI->hasType(*RC, MVT::i16)) {
// Opcode = AVR::LDDWRdPtrQ;
//:FIXME: remove this once PR13375 gets fixed
Opcode = AVR::LDDWRdYQ;
Expand Down
5 changes: 3 additions & 2 deletions llvm/lib/Target/AVR/AVRRegisterInfo.cpp
Expand Up @@ -78,11 +78,12 @@ BitVector AVRRegisterInfo::getReservedRegs(const MachineFunction &MF) const {
const TargetRegisterClass *
AVRRegisterInfo::getLargestLegalSuperClass(const TargetRegisterClass *RC,
const MachineFunction &MF) const {
if (RC->hasType(MVT::i16)) {
const TargetRegisterInfo *TRI = MF.getSubtarget().getRegisterInfo();
if (TRI->hasType(*RC, MVT::i16)) {
return &AVR::DREGSRegClass;
}

if (RC->hasType(MVT::i8)) {
if (TRI->hasType(*RC, MVT::i8)) {
return &AVR::GPR8RegClass;
}

Expand Down
5 changes: 3 additions & 2 deletions llvm/lib/Target/Mips/MipsOptimizePICCall.cpp
Expand Up @@ -116,9 +116,10 @@ static MachineOperand *getCallTargetRegOpnd(MachineInstr &MI) {

/// Return type of register Reg.
static MVT::SimpleValueType getRegTy(unsigned Reg, MachineFunction &MF) {
const TargetRegisterInfo &TRI = *MF.getSubtarget().getRegisterInfo();
const TargetRegisterClass *RC = MF.getRegInfo().getRegClass(Reg);
assert(RC->vt_end() - RC->vt_begin() == 1);
return *RC->vt_begin();
assert(TRI.valuetypes_end(*RC) - TRI.valuetypes_begin(*RC) == 1);
return *TRI.valuetypes_begin(*RC);
}

/// Do the following transformation:
Expand Down
16 changes: 8 additions & 8 deletions llvm/lib/Target/Mips/MipsSEInstrInfo.cpp
Expand Up @@ -207,13 +207,13 @@ storeRegToStack(MachineBasicBlock &MBB, MachineBasicBlock::iterator I,
Opc = Mips::SDC1;
else if (Mips::FGR64RegClass.hasSubClassEq(RC))
Opc = Mips::SDC164;
else if (RC->hasType(MVT::v16i8))
else if (TRI->hasType(*RC, MVT::v16i8))
Opc = Mips::ST_B;
else if (RC->hasType(MVT::v8i16) || RC->hasType(MVT::v8f16))
else if (TRI->hasType(*RC, MVT::v8i16) || TRI->hasType(*RC, MVT::v8f16))
Opc = Mips::ST_H;
else if (RC->hasType(MVT::v4i32) || RC->hasType(MVT::v4f32))
else if (TRI->hasType(*RC, MVT::v4i32) || TRI->hasType(*RC, MVT::v4f32))
Opc = Mips::ST_W;
else if (RC->hasType(MVT::v2i64) || RC->hasType(MVT::v2f64))
else if (TRI->hasType(*RC, MVT::v2i64) || TRI->hasType(*RC, MVT::v2f64))
Opc = Mips::ST_D;
else if (Mips::LO32RegClass.hasSubClassEq(RC))
Opc = Mips::SW;
Expand Down Expand Up @@ -280,13 +280,13 @@ loadRegFromStack(MachineBasicBlock &MBB, MachineBasicBlock::iterator I,
Opc = Mips::LDC1;
else if (Mips::FGR64RegClass.hasSubClassEq(RC))
Opc = Mips::LDC164;
else if (RC->hasType(MVT::v16i8))
else if (TRI->hasType(*RC, MVT::v16i8))
Opc = Mips::LD_B;
else if (RC->hasType(MVT::v8i16) || RC->hasType(MVT::v8f16))
else if (TRI->hasType(*RC, MVT::v8i16) || TRI->hasType(*RC, MVT::v8f16))
Opc = Mips::LD_H;
else if (RC->hasType(MVT::v4i32) || RC->hasType(MVT::v4f32))
else if (TRI->hasType(*RC, MVT::v4i32) || TRI->hasType(*RC, MVT::v4f32))
Opc = Mips::LD_W;
else if (RC->hasType(MVT::v2i64) || RC->hasType(MVT::v2f64))
else if (TRI->hasType(*RC, MVT::v2i64) || TRI->hasType(*RC, MVT::v2f64))
Opc = Mips::LD_D;
else if (Mips::HI32RegClass.hasSubClassEq(RC))
Opc = Mips::LW;
Expand Down
4 changes: 2 additions & 2 deletions llvm/lib/Target/PowerPC/PPCISelLowering.cpp
Expand Up @@ -9057,6 +9057,7 @@ PPCTargetLowering::emitEHSjLjSetJmp(MachineInstr &MI,
MachineBasicBlock *MBB) const {
DebugLoc DL = MI.getDebugLoc();
const TargetInstrInfo *TII = Subtarget.getInstrInfo();
const PPCRegisterInfo *TRI = Subtarget.getRegisterInfo();

MachineFunction *MF = MBB->getParent();
MachineRegisterInfo &MRI = MF->getRegInfo();
Expand All @@ -9070,7 +9071,7 @@ PPCTargetLowering::emitEHSjLjSetJmp(MachineInstr &MI,

unsigned DstReg = MI.getOperand(0).getReg();
const TargetRegisterClass *RC = MRI.getRegClass(DstReg);
assert(RC->hasType(MVT::i32) && "Invalid destination!");
assert(TRI->hasType(*RC, MVT::i32) && "Invalid destination!");
unsigned mainDstReg = MRI.createVirtualRegister(RC);
unsigned restoreDstReg = MRI.createVirtualRegister(RC);

Expand Down Expand Up @@ -9153,7 +9154,6 @@ PPCTargetLowering::emitEHSjLjSetJmp(MachineInstr &MI,

// Setup
MIB = BuildMI(*thisMBB, MI, DL, TII->get(PPC::BCLalways)).addMBB(mainMBB);
const PPCRegisterInfo *TRI = Subtarget.getRegisterInfo();
MIB.addRegMask(TRI->getNoPreservedMask());

BuildMI(*thisMBB, MI, DL, TII->get(PPC::LI), restoreDstReg).addImm(1);
Expand Down
4 changes: 3 additions & 1 deletion llvm/lib/Target/Sparc/SparcISelLowering.cpp
Expand Up @@ -3234,6 +3234,7 @@ SparcTargetLowering::emitEHSjLjSetJmp(MachineInstr &MI,
MachineBasicBlock *MBB) const {
DebugLoc DL = MI.getDebugLoc();
const TargetInstrInfo *TII = Subtarget->getInstrInfo();
const TargetRegisterInfo *TRI = Subtarget->getRegisterInfo();

MachineFunction *MF = MBB->getParent();
MachineRegisterInfo &MRI = MF->getRegInfo();
Expand All @@ -3245,7 +3246,8 @@ SparcTargetLowering::emitEHSjLjSetJmp(MachineInstr &MI,

unsigned DstReg = MI.getOperand(0).getReg();
const TargetRegisterClass *RC = MRI.getRegClass(DstReg);
assert(RC->hasType(MVT::i32) && "Invalid destination!");
assert(TRI->hasType(*RC, MVT::i32) && "Invalid destination!");
(void)TRI;
unsigned mainDstReg = MRI.createVirtualRegister(RC);
unsigned restoreDstReg = MRI.createVirtualRegister(RC);

Expand Down
3 changes: 2 additions & 1 deletion llvm/lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp
Expand Up @@ -45,10 +45,11 @@ using namespace llvm;
//===----------------------------------------------------------------------===//

MVT WebAssemblyAsmPrinter::getRegType(unsigned RegNo) const {
const TargetRegisterInfo *TRI = Subtarget->getRegisterInfo();
const TargetRegisterClass *TRC = MRI->getRegClass(RegNo);
for (MVT T : {MVT::i32, MVT::i64, MVT::f32, MVT::f64, MVT::v16i8, MVT::v8i16,
MVT::v4i32, MVT::v4f32})
if (TRC->hasType(T))
if (TRI->hasType(*TRC, T))
return T;
DEBUG(errs() << "Unknown type for register number: " << RegNo);
llvm_unreachable("Unknown register type");
Expand Down

0 comments on commit c019706

Please sign in to comment.