Skip to content

Commit

Permalink
[AMDGPU] Make getInstSizeInBytes more generic
Browse files Browse the repository at this point in the history
NFC. This check mainly handles size affecting literals. Make it check all
explicit operands instead of a few by name. Also make the isLiteral
check handle the KIMM operands, see https://reviews.llvm.org/D111067

Change-Id: I1a362d55b2a10f5c74d445272e8b7829a8b77597

Reviewed By: arsenm

Differential Revision: https://reviews.llvm.org/D113318

Change-Id: Ie6c688f30a71e0335d1c6dd1ff65019bd7ce684e
  • Loading branch information
Sisyph committed Nov 8, 2021
1 parent ce4fa93 commit 79f52af
Showing 1 changed file with 14 additions and 23 deletions.
37 changes: 14 additions & 23 deletions llvm/lib/Target/AMDGPU/SIInstrInfo.cpp
Expand Up @@ -3471,6 +3471,9 @@ bool SIInstrInfo::isInlineConstant(const MachineOperand &MO,
uint32_t Trunc = static_cast<uint32_t>(Imm);
return AMDGPU::isInlinableLiteralV216(Trunc, ST.hasInv2PiInlineImm());
}
case AMDGPU::OPERAND_KIMM32:
case AMDGPU::OPERAND_KIMM16:
return false;
default:
llvm_unreachable("invalid bitwidth");
}
Expand Down Expand Up @@ -7307,31 +7310,19 @@ unsigned SIInstrInfo::getInstSizeInBytes(const MachineInstr &MI) const {
return Size;
}

// 4-byte instructions may have a 32-bit literal encoded after them. Check
// operands that coud ever be literals.
// Instructions may have a 32-bit literal encoded after them. Check
// operands that could ever be literals.
if (isVALU(MI) || isSALU(MI)) {
int Src0Idx = AMDGPU::getNamedOperandIdx(Opc, AMDGPU::OpName::src0);
if (Src0Idx == -1)
return DescSize; // No operands.

if (isLiteralConstantLike(MI.getOperand(Src0Idx), Desc.OpInfo[Src0Idx]))
return isVOP3(MI) ? 12 : (DescSize + 4);

int Src1Idx = AMDGPU::getNamedOperandIdx(Opc, AMDGPU::OpName::src1);
if (Src1Idx == -1)
return DescSize;

if (isLiteralConstantLike(MI.getOperand(Src1Idx), Desc.OpInfo[Src1Idx]))
return isVOP3(MI) ? 12 : (DescSize + 4);

int Src2Idx = AMDGPU::getNamedOperandIdx(Opc, AMDGPU::OpName::src2);
if (Src2Idx == -1)
if (isDPP(MI))
return DescSize;

if (isLiteralConstantLike(MI.getOperand(Src2Idx), Desc.OpInfo[Src2Idx]))
return isVOP3(MI) ? 12 : (DescSize + 4);

return DescSize;
bool HasLiteral = false;
for (int I = 0, E = MI.getNumExplicitOperands(); I != E; ++I) {
if (isLiteralConstant(MI, I)) {
HasLiteral = true;
break;
}
}
return HasLiteral ? DescSize + 4 : DescSize;
}

// Check whether we have extra NSA words.
Expand Down

0 comments on commit 79f52af

Please sign in to comment.