Index: lib/Target/AMDGPU/AMDGPUAsmPrinter.cpp =================================================================== --- lib/Target/AMDGPU/AMDGPUAsmPrinter.cpp +++ lib/Target/AMDGPU/AMDGPUAsmPrinter.cpp @@ -29,6 +29,7 @@ #include "SIDefines.h" #include "SIMachineFunctionInfo.h" #include "SIRegisterInfo.h" +#include "SIInstrInfo.h" #include "llvm/CodeGen/MachineFrameInfo.h" #include "llvm/MC/MCContext.h" #include "llvm/MC/MCSectionELF.h" @@ -309,6 +310,8 @@ bool FlatUsed = false; const SIRegisterInfo *RI = static_cast(STM.getRegisterInfo()); + const SIInstrInfo *TII = + static_cast(STM.getInstrInfo()); for (const MachineBasicBlock &MBB : MF) { for (const MachineInstr &MI : MBB) { @@ -318,8 +321,8 @@ if (MI.isDebugValue()) continue; - // FIXME: This is reporting 0 for many instructions. - CodeSize += MI.getDesc().Size; + if (isVerbose()) + CodeSize += TII->getInstSizeInBytes(MI); unsigned numOperands = MI.getNumOperands(); for (unsigned op_idx = 0; op_idx < numOperands; op_idx++) { Index: lib/Target/AMDGPU/CIInstructions.td =================================================================== --- lib/Target/AMDGPU/CIInstructions.td +++ lib/Target/AMDGPU/CIInstructions.td @@ -293,7 +293,7 @@ >; class FlatStoreAtomicPat : Pat < - // atomic store follows aotmic binop convenction so the address comes first + // atomic store follows atomic binop convenction so the address comes first. (node i64:$addr, vt:$data), (inst $addr, $data, 1, 0, 0) >; Index: lib/Target/AMDGPU/MCTargetDesc/SIMCCodeEmitter.cpp =================================================================== --- lib/Target/AMDGPU/MCTargetDesc/SIMCCodeEmitter.cpp +++ lib/Target/AMDGPU/MCTargetDesc/SIMCCodeEmitter.cpp @@ -186,6 +186,11 @@ const MCInstrDesc &Desc = MCII.get(MI.getOpcode()); unsigned bytes = Desc.getSize(); + // Instructions sizes that can't just be determined by the opcode have a base + // size of 4, and then the following 4 byte literal. + if (bytes == 0) + bytes = 4; + for (unsigned i = 0; i < bytes; i++) { OS.write((uint8_t) ((Encoding >> (8 * i)) & 0xff)); } @@ -266,7 +271,7 @@ const MCRegisterClass &RC = MRI.getRegClass(RCID); uint32_t Enc = getLitEncoding(MO, RC.getSize()); - if (Enc != ~0U && (Enc != 255 || Desc.getSize() == 4)) + if (Enc != ~0U && (Enc != 255 || Desc.getSize() != 8)) return Enc; } else if (MO.isImm()) Index: lib/Target/AMDGPU/SIInstrFormats.td =================================================================== --- lib/Target/AMDGPU/SIInstrFormats.td +++ lib/Target/AMDGPU/SIInstrFormats.td @@ -86,16 +86,19 @@ field bits<1> DisableDecoder = 0; let isAsmParserOnly = !if(!eq(DisableDecoder{0}, {0}), 0, 1); + + // Similar to Size field. Get encoding size for the format ignoring + // 32-bit literals that could really make the full instruction + // encoding be 8 bytes. + int BaseSize = 4; } class Enc32 { field bits<32> Inst; - int Size = 4; } class Enc64 { field bits<64> Inst; - int Size = 8; } class VOPDstOperand : RegisterOperand ; @@ -124,14 +127,12 @@ VOPAnyCommon { let VOP1 = 1; - let Size = 4; } class VOP2Common pattern> : VOPAnyCommon { let VOP2 = 1; - let Size = 4; } class VOP3Common pattern, bit HasMods = 0, bit VOP3Only = 0> : @@ -153,7 +154,8 @@ let isCodeGenOnly = 0; - int Size = 8; + let Size = 8; + let BaseSize = 8; // Because SGPRs may be allowed if there are multiple operands, we // need a post-isel hook to insert copies in order to avoid @@ -325,6 +327,7 @@ let hasSideEffects = 0; let SALU = 1; let SOPP = 1; + let Size = 4; let UseNamedOperandTable = 1; } @@ -336,6 +339,7 @@ let LGKM_CNT = 1; let SMRD = 1; + let mayStore = 0; let mayLoad = 1; let hasSideEffects = 0; @@ -647,6 +651,7 @@ let mayLoad = 1; let mayStore = 0; let hasSideEffects = 0; + let Size = 4; } } // End Uses = [EXEC] @@ -660,6 +665,8 @@ let LGKM_CNT = 1; let DS = 1; + let Size = 8; + let BaseSize = 8; let UseNamedOperandTable = 1; let Uses = [M0, EXEC]; @@ -678,6 +685,8 @@ let VM_CNT = 1; let EXP_CNT = 1; let MUBUF = 1; + let Size = 8; + let BaseSize = 8; let Uses = [EXEC]; let hasSideEffects = 0; @@ -692,6 +701,8 @@ let VM_CNT = 1; let EXP_CNT = 1; let MTBUF = 1; + let Size = 8; + let BaseSize = 8; let Uses = [EXEC]; let hasSideEffects = 0; @@ -707,6 +718,8 @@ // and are not considered done until both have been decremented. let VM_CNT = 1; let LGKM_CNT = 1; + let Size = 8; + let BaseSize = 8; let Uses = [EXEC, FLAT_SCR]; // M0 @@ -721,6 +734,8 @@ let VM_CNT = 1; let EXP_CNT = 1; let MIMG = 1; + let Size = 8; + let BaseSize = 8; let Uses = [EXEC]; let UseNamedOperandTable = 1; Index: lib/Target/AMDGPU/SIInstrInfo.td =================================================================== --- lib/Target/AMDGPU/SIInstrInfo.td +++ lib/Target/AMDGPU/SIInstrInfo.td @@ -644,6 +644,7 @@ [] > { let EXP_CNT = 1; + let Size = 8; let Uses = [EXEC]; let SchedRW = [WriteExport]; } @@ -764,7 +765,6 @@ SIMCInstr { let isPseudo = 1; let isCodeGenOnly = 1; - let Size = 4; // Pseudo instructions have no encodings, but adding this field here allows // us to do: @@ -926,6 +926,7 @@ let DecoderNamespace = "SICI"; let DisableDecoder = DisableSIDecoder; let isCodeGenOnly = 0; + let Size = 8; } def _vi : SOPK , @@ -935,6 +936,7 @@ let DecoderNamespace = "VI"; let DisableDecoder = DisableVIDecoder; let isCodeGenOnly = 0; + let Size = 8; } } //===----------------------------------------------------------------------===// @@ -956,6 +958,7 @@ let AssemblerPredicates = [isSICI]; let DecoderNamespace = "SICI"; let DisableDecoder = DisableSIDecoder; + let Size = 4; } class SMRD_SOFF_Real_si op, string opName, dag outs, dag ins, @@ -966,6 +969,7 @@ let AssemblerPredicates = [isSICI]; let DecoderNamespace = "SICI"; let DisableDecoder = DisableSIDecoder; + let Size = 4; } @@ -977,6 +981,7 @@ let AssemblerPredicates = [isVI]; let DecoderNamespace = "VI"; let DisableDecoder = DisableVIDecoder; + let Size = 8; } class SMRD_SOFF_Real_vi op, string opName, dag outs, dag ins, @@ -987,6 +992,7 @@ let AssemblerPredicates = [isVI]; let DecoderNamespace = "VI"; let DisableDecoder = DisableVIDecoder; + let Size = 8; } @@ -1076,6 +1082,7 @@ opName#" $sdst, $sbase, $offset", []>, SMRD_IMMe_ci { let AssemblerPredicates = [isCIOnly]; let DecoderNamespace = "CI"; + let Size = 8; } defm _SGPR : SMRD_SOFF_m < @@ -2198,6 +2205,7 @@ let AssemblerPredicates = [isSICI]; let DecoderNamespace = "SICI"; let DisableDecoder = DisableSIDecoder; + let Size = 8; } def _vi : VOP2Common