[llvm] r284619 - [AMDGPU] Stop using MCRegisterClass::getSize()
Krzysztof Parzyszek via llvm-commits
llvm-commits at lists.llvm.org
Wed Oct 19 10:40:36 PDT 2016
Author: kparzysz
Date: Wed Oct 19 12:40:36 2016
New Revision: 284619
URL: http://llvm.org/viewvc/llvm-project?rev=284619&view=rev
Log:
[AMDGPU] Stop using MCRegisterClass::getSize()
Differential Review: https://reviews.llvm.org/D24675
Modified:
llvm/trunk/lib/Target/AMDGPU/InstPrinter/AMDGPUInstPrinter.cpp
llvm/trunk/lib/Target/AMDGPU/MCTargetDesc/SIMCCodeEmitter.cpp
llvm/trunk/lib/Target/AMDGPU/Utils/AMDGPUBaseInfo.cpp
llvm/trunk/lib/Target/AMDGPU/Utils/AMDGPUBaseInfo.h
Modified: llvm/trunk/lib/Target/AMDGPU/InstPrinter/AMDGPUInstPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/AMDGPU/InstPrinter/AMDGPUInstPrinter.cpp?rev=284619&r1=284618&r2=284619&view=diff
==============================================================================
--- llvm/trunk/lib/Target/AMDGPU/InstPrinter/AMDGPUInstPrinter.cpp (original)
+++ llvm/trunk/lib/Target/AMDGPU/InstPrinter/AMDGPUInstPrinter.cpp Wed Oct 19 12:40:36 2016
@@ -403,10 +403,10 @@ void AMDGPUInstPrinter::printOperand(con
const MCInstrDesc &Desc = MII.get(MI->getOpcode());
int RCID = Desc.OpInfo[OpNo].RegClass;
if (RCID != -1) {
- const MCRegisterClass &ImmRC = MRI.getRegClass(RCID);
- if (ImmRC.getSize() == 4)
+ unsigned RCBits = AMDGPU::getRegBitWidth(MRI.getRegClass(RCID));
+ if (RCBits == 32)
printImmediate32(Op.getImm(), O);
- else if (ImmRC.getSize() == 8)
+ else if (RCBits == 64)
printImmediate64(Op.getImm(), O);
else
llvm_unreachable("Invalid register class size");
@@ -424,11 +424,11 @@ void AMDGPUInstPrinter::printOperand(con
O << "0.0";
else {
const MCInstrDesc &Desc = MII.get(MI->getOpcode());
- const MCRegisterClass &ImmRC = MRI.getRegClass(Desc.OpInfo[OpNo].RegClass);
-
- if (ImmRC.getSize() == 4)
+ int RCID = Desc.OpInfo[OpNo].RegClass;
+ unsigned RCBits = AMDGPU::getRegBitWidth(MRI.getRegClass(RCID));
+ if (RCBits == 32)
printImmediate32(FloatToBits(Op.getFPImm()), O);
- else if (ImmRC.getSize() == 8)
+ else if (RCBits == 64)
printImmediate64(DoubleToBits(Op.getFPImm()), O);
else
llvm_unreachable("Invalid register class size");
Modified: llvm/trunk/lib/Target/AMDGPU/MCTargetDesc/SIMCCodeEmitter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/AMDGPU/MCTargetDesc/SIMCCodeEmitter.cpp?rev=284619&r1=284618&r2=284619&view=diff
==============================================================================
--- llvm/trunk/lib/Target/AMDGPU/MCTargetDesc/SIMCCodeEmitter.cpp (original)
+++ llvm/trunk/lib/Target/AMDGPU/MCTargetDesc/SIMCCodeEmitter.cpp Wed Oct 19 12:40:36 2016
@@ -214,7 +214,7 @@ void SIMCCodeEmitter::encodeInstruction(
// Is this operand a literal immediate?
const MCOperand &Op = MI.getOperand(i);
- if (getLitEncoding(Op, RC.getSize(), STI) != 255)
+ if (getLitEncoding(Op, AMDGPU::getRegBitWidth(RC) / 8, STI) != 255)
continue;
// Yes! Encode it
Modified: llvm/trunk/lib/Target/AMDGPU/Utils/AMDGPUBaseInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/AMDGPU/Utils/AMDGPUBaseInfo.cpp?rev=284619&r1=284618&r2=284619&view=diff
==============================================================================
--- llvm/trunk/lib/Target/AMDGPU/Utils/AMDGPUBaseInfo.cpp (original)
+++ llvm/trunk/lib/Target/AMDGPU/Utils/AMDGPUBaseInfo.cpp Wed Oct 19 12:40:36 2016
@@ -337,11 +337,42 @@ bool isSISrcInlinableOperand(const MCIns
OpType == AMDGPU::OPERAND_REG_INLINE_C_FP;
}
+// Avoid using MCRegisterClass::getSize, since that function will go away
+// (move from MC* level to Target* level). Return size in bits.
+unsigned getRegBitWidth(const MCRegisterClass &RC) {
+ switch (RC.getID()) {
+ case AMDGPU::SGPR_32RegClassID:
+ case AMDGPU::VGPR_32RegClassID:
+ case AMDGPU::VS_32RegClassID:
+ case AMDGPU::SReg_32RegClassID:
+ case AMDGPU::SReg_32_XM0RegClassID:
+ return 32;
+ case AMDGPU::SGPR_64RegClassID:
+ case AMDGPU::VS_64RegClassID:
+ case AMDGPU::SReg_64RegClassID:
+ case AMDGPU::VReg_64RegClassID:
+ return 64;
+ case AMDGPU::VReg_96RegClassID:
+ return 96;
+ case AMDGPU::SGPR_128RegClassID:
+ case AMDGPU::SReg_128RegClassID:
+ case AMDGPU::VReg_128RegClassID:
+ return 128;
+ case AMDGPU::SReg_256RegClassID:
+ case AMDGPU::VReg_256RegClassID:
+ return 256;
+ case AMDGPU::SReg_512RegClassID:
+ case AMDGPU::VReg_512RegClassID:
+ return 512;
+ default:
+ llvm_unreachable("Unexpected register class");
+ }
+}
+
unsigned getRegOperandSize(const MCRegisterInfo *MRI, const MCInstrDesc &Desc,
unsigned OpNo) {
- int RCID = Desc.OpInfo[OpNo].RegClass;
- const MCRegisterClass &RC = MRI->getRegClass(RCID);
- return RC.getSize();
+ unsigned RCID = Desc.OpInfo[OpNo].RegClass;
+ return getRegBitWidth(MRI->getRegClass(RCID)) / 8;
}
bool isInlinableLiteral64(int64_t Literal, bool IsVI) {
Modified: llvm/trunk/lib/Target/AMDGPU/Utils/AMDGPUBaseInfo.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/AMDGPU/Utils/AMDGPUBaseInfo.h?rev=284619&r1=284618&r2=284619&view=diff
==============================================================================
--- llvm/trunk/lib/Target/AMDGPU/Utils/AMDGPUBaseInfo.h (original)
+++ llvm/trunk/lib/Target/AMDGPU/Utils/AMDGPUBaseInfo.h Wed Oct 19 12:40:36 2016
@@ -24,6 +24,7 @@ class Function;
class GlobalValue;
class MCContext;
class MCInstrDesc;
+class MCRegisterClass;
class MCRegisterInfo;
class MCSection;
class MCSubtargetInfo;
@@ -152,6 +153,9 @@ bool isSISrcFPOperand(const MCInstrDesc
/// \brief Does this opearnd support only inlinable literals?
bool isSISrcInlinableOperand(const MCInstrDesc &Desc, unsigned OpNo);
+/// \brief Get the size in bits of a register from the register class \p RC.
+unsigned getRegBitWidth(const MCRegisterClass &RC);
+
/// \brief Get size of register operand
unsigned getRegOperandSize(const MCRegisterInfo *MRI, const MCInstrDesc &Desc,
unsigned OpNo);
More information about the llvm-commits
mailing list