Skip to content

Commit 02458c2

Browse files
committed
AMDGPU: Add function for getting instruction size
llvm-svn: 271936
1 parent 3b2e2a5 commit 02458c2

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed

llvm/lib/Target/AMDGPU/SIInstrInfo.cpp

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3116,6 +3116,55 @@ bool SIInstrInfo::isHighLatencyInstruction(const MachineInstr *MI) const {
31163116
return isMUBUF(Opc) || isMTBUF(Opc) || isMIMG(Opc);
31173117
}
31183118

3119+
unsigned SIInstrInfo::getInstSizeInBytes(const MachineInstr &MI) const {
3120+
unsigned Opc = MI.getOpcode();
3121+
const MCInstrDesc &Desc = getMCOpcodeFromPseudo(Opc);
3122+
unsigned DescSize = Desc.getSize();
3123+
3124+
// If we have a definitive size, we can use it. Otherwise we need to inspect
3125+
// the operands to know the size.
3126+
if (DescSize == 8 || DescSize == 4)
3127+
return DescSize;
3128+
3129+
assert(DescSize == 0);
3130+
3131+
// 4-byte instructions may have a 32-bit literal encoded after them. Check
3132+
// operands that coud ever be literals.
3133+
if (isVALU(MI) || isSALU(MI)) {
3134+
int Src0Idx = AMDGPU::getNamedOperandIdx(Opc, AMDGPU::OpName::src0);
3135+
if (Src0Idx == -1)
3136+
return 4; // No operands.
3137+
3138+
if (isLiteralConstant(MI.getOperand(Src0Idx), getOpSize(MI, Src0Idx)))
3139+
return 8;
3140+
3141+
int Src1Idx = AMDGPU::getNamedOperandIdx(Opc, AMDGPU::OpName::src1);
3142+
if (Src1Idx == -1)
3143+
return 4;
3144+
3145+
if (isLiteralConstant(MI.getOperand(Src1Idx), getOpSize(MI, Src1Idx)))
3146+
return 8;
3147+
3148+
return 4;
3149+
}
3150+
3151+
switch (Opc) {
3152+
case TargetOpcode::IMPLICIT_DEF:
3153+
case TargetOpcode::KILL:
3154+
case TargetOpcode::DBG_VALUE:
3155+
case TargetOpcode::BUNDLE:
3156+
case TargetOpcode::EH_LABEL:
3157+
return 0;
3158+
case TargetOpcode::INLINEASM: {
3159+
const MachineFunction *MF = MI.getParent()->getParent();
3160+
const char *AsmStr = MI.getOperand(0).getSymbolName();
3161+
return getInlineAsmLength(AsmStr, *MF->getTarget().getMCAsmInfo());
3162+
}
3163+
default:
3164+
llvm_unreachable("unable to find instruction size");
3165+
}
3166+
}
3167+
31193168
ArrayRef<std::pair<int, const char *>>
31203169
SIInstrInfo::getSerializableTargetIndices() const {
31213170
static const std::pair<int, const char *> TargetIndices[] = {

llvm/lib/Target/AMDGPU/SIInstrInfo.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -512,6 +512,8 @@ class SIInstrInfo final : public AMDGPUInstrInfo {
512512
return get(pseudoToMCOpcode(Opcode));
513513
}
514514

515+
unsigned getInstSizeInBytes(const MachineInstr &MI) const;
516+
515517
ArrayRef<std::pair<int, const char *>>
516518
getSerializableTargetIndices() const override;
517519

0 commit comments

Comments
 (0)