@@ -513,8 +513,7 @@ void AMDGPUDisassembler::decodeImmOperands(MCInst &MI,
513513 }
514514
515515 if (Imm == AMDGPU::EncValues::LITERAL_CONST) {
516- Op = decodeLiteralConstant (
517- Desc, OpDesc, OpDesc.OperandType == AMDGPU::OPERAND_REG_IMM_FP64);
516+ Op = decodeLiteralConstant (Desc, OpDesc);
518517 continue ;
519518 }
520519
@@ -1545,21 +1544,21 @@ AMDGPUDisassembler::decodeMandatoryLiteralConstant(unsigned Val) const {
15451544MCOperand
15461545AMDGPUDisassembler::decodeMandatoryLiteral64Constant (uint64_t Val) const {
15471546 if (HasLiteral) {
1548- if (Literal64 != Val)
1547+ if (Literal != Val)
15491548 return errOperand (Val, " More than one unique literal is illegal" );
15501549 }
15511550 HasLiteral = true ;
1552- Literal = Literal64 = Val;
1551+ Literal = Val;
15531552
1554- bool UseLit64 = Hi_32 (Literal64 ) == 0 ;
1553+ bool UseLit64 = Hi_32 (Literal ) == 0 ;
15551554 return UseLit64 ? MCOperand::createExpr (AMDGPUMCExpr::createLit (
1556- LitModifier::Lit64, Literal64 , getContext ()))
1557- : MCOperand::createImm (Literal64 );
1555+ LitModifier::Lit64, Literal , getContext ()))
1556+ : MCOperand::createImm (Literal );
15581557}
15591558
1560- MCOperand AMDGPUDisassembler::decodeLiteralConstant ( const MCInstrDesc &Desc,
1561- const MCOperandInfo &OpDesc ,
1562- bool ExtendFP64 ) const {
1559+ MCOperand
1560+ AMDGPUDisassembler::decodeLiteralConstant ( const MCInstrDesc &Desc ,
1561+ const MCOperandInfo &OpDesc ) const {
15631562 // For now all literal constants are supposed to be unsigned integer
15641563 // ToDo: deal with signed/unsigned 64-bit integer constants
15651564 // ToDo: deal with float/double constants
@@ -1569,35 +1568,79 @@ MCOperand AMDGPUDisassembler::decodeLiteralConstant(const MCInstrDesc &Desc,
15691568 Twine (Bytes.size ()));
15701569 }
15711570 HasLiteral = true ;
1572- Literal = Literal64 = eatBytes<uint32_t >(Bytes);
1573- if (ExtendFP64)
1574- Literal64 <<= 32 ;
1571+ Literal = eatBytes<uint32_t >(Bytes);
15751572 }
15761573
1577- int64_t Val = ExtendFP64 ? Literal64 : Literal;
1574+ // For disassembling always assume all inline constants are available.
1575+ bool HasInv2Pi = true ;
15781576
1579- bool CanUse64BitLiterals =
1580- STI.hasFeature (AMDGPU::Feature64BitLiterals) &&
1581- !(Desc.TSFlags & (SIInstrFlags::VOP3 | SIInstrFlags::VOP3P));
1582-
1583- bool UseLit64 = false ;
1584- if (CanUse64BitLiterals) {
1585- if (OpDesc.OperandType == AMDGPU::OPERAND_REG_IMM_INT64 ||
1586- OpDesc.OperandType == AMDGPU::OPERAND_REG_INLINE_C_INT64)
1587- UseLit64 = false ;
1588- else if (OpDesc.OperandType == AMDGPU::OPERAND_REG_IMM_FP64 ||
1589- OpDesc.OperandType == AMDGPU::OPERAND_REG_INLINE_C_FP64 ||
1590- OpDesc.OperandType == AMDGPU::OPERAND_REG_INLINE_AC_FP64)
1591- UseLit64 = Hi_32 (Literal64) == 0 ;
1577+ // Invalid instruction codes may contain literals for inline-only
1578+ // operands, so we support them here as well.
1579+ int64_t Val = Literal;
1580+ bool UseLit = false ;
1581+ switch (OpDesc.OperandType ) {
1582+ default :
1583+ llvm_unreachable (" Unexpected operand type!" );
1584+ case AMDGPU::OPERAND_REG_IMM_BF16:
1585+ case AMDGPU::OPERAND_REG_INLINE_C_BF16:
1586+ case AMDGPU::OPERAND_REG_INLINE_C_V2BF16:
1587+ UseLit = AMDGPU::isInlinableLiteralBF16 (Val, HasInv2Pi);
1588+ break ;
1589+ case AMDGPU::OPERAND_REG_IMM_V2BF16:
1590+ UseLit = AMDGPU::isInlinableLiteralV2BF16 (Val);
1591+ break ;
1592+ case AMDGPU::OPERAND_REG_IMM_FP16:
1593+ case AMDGPU::OPERAND_REG_INLINE_C_FP16:
1594+ case AMDGPU::OPERAND_REG_INLINE_C_V2FP16:
1595+ UseLit = AMDGPU::isInlinableLiteralFP16 (Val, HasInv2Pi);
1596+ break ;
1597+ case AMDGPU::OPERAND_REG_IMM_V2FP16:
1598+ UseLit = AMDGPU::isInlinableLiteralV2F16 (Val);
1599+ break ;
1600+ case AMDGPU::OPERAND_REG_IMM_NOINLINE_V2FP16:
1601+ break ;
1602+ case AMDGPU::OPERAND_REG_IMM_INT16:
1603+ case AMDGPU::OPERAND_REG_INLINE_C_INT16:
1604+ case AMDGPU::OPERAND_REG_INLINE_C_V2INT16:
1605+ UseLit = AMDGPU::isInlinableLiteralI16 (Val, HasInv2Pi);
1606+ break ;
1607+ case AMDGPU::OPERAND_REG_IMM_V2INT16:
1608+ UseLit = AMDGPU::isInlinableLiteralV2I16 (Val);
1609+ break ;
1610+ case AMDGPU::OPERAND_REG_IMM_FP32:
1611+ case AMDGPU::OPERAND_REG_INLINE_C_FP32:
1612+ case AMDGPU::OPERAND_REG_INLINE_AC_FP32:
1613+ case AMDGPU::OPERAND_REG_IMM_INT32:
1614+ case AMDGPU::OPERAND_REG_INLINE_C_INT32:
1615+ case AMDGPU::OPERAND_REG_INLINE_AC_INT32:
1616+ case AMDGPU::OPERAND_REG_IMM_V2FP32:
1617+ case AMDGPU::OPERAND_REG_IMM_V2INT32:
1618+ case AMDGPU::OPERAND_KIMM32:
1619+ UseLit = AMDGPU::isInlinableLiteral32 (Val, HasInv2Pi);
1620+ break ;
1621+ case AMDGPU::OPERAND_REG_IMM_FP64:
1622+ case AMDGPU::OPERAND_REG_INLINE_C_FP64:
1623+ case AMDGPU::OPERAND_REG_INLINE_AC_FP64:
1624+ Val <<= 32 ;
1625+ break ;
1626+ case AMDGPU::OPERAND_REG_IMM_INT64:
1627+ case AMDGPU::OPERAND_REG_INLINE_C_INT64:
1628+ UseLit = AMDGPU::isInlinableLiteral64 (Val, HasInv2Pi);
1629+ break ;
1630+ case MCOI::OPERAND_REGISTER:
1631+ // TODO: Disassembling V_DUAL_FMAMK_F32_X_FMAMK_F32_gfx11 hits
1632+ // decoding a literal in a position of a register operand. Give
1633+ // it special handling in the caller, decodeImmOperands(), instead
1634+ // of quietly allowing it here.
1635+ break ;
15921636 }
15931637
1594- return UseLit64 ? MCOperand::createExpr (AMDGPUMCExpr::createLit (
1595- LitModifier::Lit64 , Val, getContext ()))
1596- : MCOperand::createImm (Val);
1638+ return UseLit ? MCOperand::createExpr (AMDGPUMCExpr::createLit (
1639+ LitModifier::Lit , Val, getContext ()))
1640+ : MCOperand::createImm (Val);
15971641}
15981642
1599- MCOperand
1600- AMDGPUDisassembler::decodeLiteral64Constant (const MCInst &Inst) const {
1643+ MCOperand AMDGPUDisassembler::decodeLiteral64Constant () const {
16011644 assert (STI.hasFeature (AMDGPU::Feature64BitLiterals));
16021645
16031646 if (!HasLiteral) {
@@ -1606,25 +1649,13 @@ AMDGPUDisassembler::decodeLiteral64Constant(const MCInst &Inst) const {
16061649 Twine (Bytes.size ()));
16071650 }
16081651 HasLiteral = true ;
1609- Literal64 = eatBytes<uint64_t >(Bytes);
1610- }
1611-
1612- bool UseLit64 = false ;
1613- const MCInstrDesc &Desc = MCII->get (Inst.getOpcode ());
1614- const MCOperandInfo &OpDesc = Desc.operands ()[Inst.getNumOperands ()];
1615- if (OpDesc.OperandType == AMDGPU::OPERAND_REG_IMM_INT64 ||
1616- OpDesc.OperandType == AMDGPU::OPERAND_REG_INLINE_C_INT64) {
1617- UseLit64 = false ;
1618- } else {
1619- assert (OpDesc.OperandType == AMDGPU::OPERAND_REG_IMM_FP64 ||
1620- OpDesc.OperandType == AMDGPU::OPERAND_REG_INLINE_C_FP64 ||
1621- OpDesc.OperandType == AMDGPU::OPERAND_REG_INLINE_AC_FP64);
1622- UseLit64 = Hi_32 (Literal64) == 0 ;
1652+ Literal = eatBytes<uint64_t >(Bytes);
16231653 }
16241654
1655+ bool UseLit64 = Hi_32 (Literal) == 0 ;
16251656 return UseLit64 ? MCOperand::createExpr (AMDGPUMCExpr::createLit (
1626- LitModifier::Lit64, Literal64 , getContext ()))
1627- : MCOperand::createImm (Literal64 );
1657+ LitModifier::Lit64, Literal , getContext ()))
1658+ : MCOperand::createImm (Literal );
16281659}
16291660
16301661MCOperand AMDGPUDisassembler::decodeIntImmed (unsigned Imm) {
@@ -1913,7 +1944,7 @@ MCOperand AMDGPUDisassembler::decodeNonVGPRSrcOp(const MCInst &Inst,
19131944 return MCOperand::createImm (Val);
19141945
19151946 if (Val == LITERAL64_CONST && STI.hasFeature (AMDGPU::Feature64BitLiterals)) {
1916- return decodeLiteral64Constant (Inst );
1947+ return decodeLiteral64Constant ();
19171948 }
19181949
19191950 switch (Width) {
0 commit comments