diff --git a/llvm/lib/Target/AMDGPU/SIFoldOperands.cpp b/llvm/lib/Target/AMDGPU/SIFoldOperands.cpp --- a/llvm/lib/Target/AMDGPU/SIFoldOperands.cpp +++ b/llvm/lib/Target/AMDGPU/SIFoldOperands.cpp @@ -908,11 +908,10 @@ TRI->getRegClass(FoldDesc.operands()[0].RegClass); // Split 64-bit constants into 32-bits for folding. - if (UseOp.getSubReg() && AMDGPU::getRegBitWidth(FoldRC->getID()) == 64) { + if (UseOp.getSubReg() && AMDGPU::getRegBitWidth(*FoldRC) == 64) { Register UseReg = UseOp.getReg(); const TargetRegisterClass *UseRC = MRI->getRegClass(UseReg); - - if (AMDGPU::getRegBitWidth(UseRC->getID()) != 64) + if (AMDGPU::getRegBitWidth(*UseRC) != 64) return; APInt Imm(64, OpToFold.getImm()); diff --git a/llvm/lib/Target/AMDGPU/SIInstrInfo.cpp b/llvm/lib/Target/AMDGPU/SIInstrInfo.cpp --- a/llvm/lib/Target/AMDGPU/SIInstrInfo.cpp +++ b/llvm/lib/Target/AMDGPU/SIInstrInfo.cpp @@ -2882,7 +2882,7 @@ if (MRI.getRegClass(FalseReg) != RC) return false; - int NumInsts = AMDGPU::getRegBitWidth(RC->getID()) / 32; + int NumInsts = AMDGPU::getRegBitWidth(*RC) / 32; CondCycles = TrueCycles = FalseCycles = NumInsts; // ??? // Limit to equal cost for branch vs. N v_cndmask_b32s. @@ -2897,7 +2897,7 @@ if (MRI.getRegClass(FalseReg) != RC) return false; - int NumInsts = AMDGPU::getRegBitWidth(RC->getID()) / 32; + int NumInsts = AMDGPU::getRegBitWidth(*RC) / 32; // Multiples of 8 can do s_cselect_b64 if (NumInsts % 2 == 0) diff --git a/llvm/lib/Target/AMDGPU/SIRegisterInfo.cpp b/llvm/lib/Target/AMDGPU/SIRegisterInfo.cpp --- a/llvm/lib/Target/AMDGPU/SIRegisterInfo.cpp +++ b/llvm/lib/Target/AMDGPU/SIRegisterInfo.cpp @@ -1310,7 +1310,7 @@ const TargetRegisterClass *RC = getRegClassForReg(MF->getRegInfo(), ValueReg); // On gfx90a+ AGPR is a regular VGPR acceptable for loads and stores. const bool IsAGPR = !ST.hasGFX90AInsts() && isAGPRClass(RC); - const unsigned RegWidth = AMDGPU::getRegBitWidth(RC->getID()) / 8; + const unsigned RegWidth = AMDGPU::getRegBitWidth(*RC) / 8; // Always use 4 byte operations for AGPRs because we need to scavenge // a temporary VGPR. @@ -2904,7 +2904,7 @@ ArrayRef SIRegisterInfo::getRegSplitParts(const TargetRegisterClass *RC, unsigned EltSize) const { - const unsigned RegBitWidth = AMDGPU::getRegBitWidth(*RC->MC); + const unsigned RegBitWidth = AMDGPU::getRegBitWidth(*RC); assert(RegBitWidth >= 32 && RegBitWidth <= 1024); const unsigned RegDWORDs = RegBitWidth / 32; @@ -3209,4 +3209,4 @@ break; } return 0; -} \ No newline at end of file +} diff --git a/llvm/lib/Target/AMDGPU/Utils/AMDGPUBaseInfo.h b/llvm/lib/Target/AMDGPU/Utils/AMDGPUBaseInfo.h --- a/llvm/lib/Target/AMDGPU/Utils/AMDGPUBaseInfo.h +++ b/llvm/lib/Target/AMDGPU/Utils/AMDGPUBaseInfo.h @@ -31,6 +31,7 @@ class MCRegisterInfo; class MCSubtargetInfo; class StringRef; +class TargetRegisterClass; class Triple; class raw_ostream; @@ -1178,6 +1179,9 @@ /// Get the size in bits of a register from the register class \p RC. unsigned getRegBitWidth(const MCRegisterClass &RC); +/// Get the size in bits of a register from the register class \p RC. +unsigned getRegBitWidth(const TargetRegisterClass &RC); + /// Get size of register operand unsigned getRegOperandSize(const MCRegisterInfo *MRI, const MCInstrDesc &Desc, unsigned OpNo); diff --git a/llvm/lib/Target/AMDGPU/Utils/AMDGPUBaseInfo.cpp b/llvm/lib/Target/AMDGPU/Utils/AMDGPUBaseInfo.cpp --- a/llvm/lib/Target/AMDGPU/Utils/AMDGPUBaseInfo.cpp +++ b/llvm/lib/Target/AMDGPU/Utils/AMDGPUBaseInfo.cpp @@ -12,6 +12,7 @@ #include "AMDKernelCodeT.h" #include "MCTargetDesc/AMDGPUMCTargetDesc.h" #include "llvm/BinaryFormat/ELF.h" +#include "llvm/CodeGen/TargetRegisterInfo.h" #include "llvm/IR/Attributes.h" #include "llvm/IR/Constants.h" #include "llvm/IR/Function.h" @@ -2367,11 +2368,15 @@ return getRegBitWidth(RC.getID()); } +unsigned getRegBitWidth(const TargetRegisterClass &RC) { + return getRegBitWidth(RC.getID()); +} + unsigned getRegOperandSize(const MCRegisterInfo *MRI, const MCInstrDesc &Desc, unsigned OpNo) { assert(OpNo < Desc.NumOperands); unsigned RCID = Desc.operands()[OpNo].RegClass; - return getRegBitWidth(MRI->getRegClass(RCID)) / 8; + return getRegBitWidth(RCID) / 8; } bool isInlinableLiteral64(int64_t Literal, bool HasInv2Pi) {