@@ -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+
31193168ArrayRef<std::pair<int , const char *>>
31203169SIInstrInfo::getSerializableTargetIndices () const {
31213170 static const std::pair<int , const char *> TargetIndices[] = {
0 commit comments