//===-- MIMGInstructions.td - MIMG Instruction Definitions ----------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // MIMG-specific encoding families to distinguish between semantically // equivalent machine instructions with different encoding. // // - MIMGEncGfx6: encoding introduced with gfx6 (obsoleted for atomics in gfx8) // - MIMGEncGfx8: encoding introduced with gfx8 for atomics // - MIMGEncGfx10Default: gfx default (non-NSA) encoding // - MIMGEncGfx10NSA: gfx10 NSA encoding class MIMGEncoding; def MIMGEncGfx6 : MIMGEncoding; def MIMGEncGfx8 : MIMGEncoding; def MIMGEncGfx10Default : MIMGEncoding; def MIMGEncGfx10NSA : MIMGEncoding; def MIMGEncoding : GenericEnum { let FilterClass = "MIMGEncoding"; } // Represent an ISA-level opcode, independent of the encoding and the // vdata/vaddr size. class MIMGBaseOpcode : PredicateControl { MIMGBaseOpcode BaseOpcode = !cast(NAME); bit Store = 0; bit Atomic = 0; bit AtomicX2 = 0; // (f)cmpswap bit Sampler = 0; bit Gather4 = 0; bits<8> NumExtraArgs = 0; bit Gradients = 0; bit G16 = 0; bit Coordinates = 1; bit LodOrClampOrMip = 0; bit HasD16 = 0; } def MIMGBaseOpcode : GenericEnum { let FilterClass = "MIMGBaseOpcode"; } def MIMGBaseOpcodesTable : GenericTable { let FilterClass = "MIMGBaseOpcode"; let CppTypeName = "MIMGBaseOpcodeInfo"; let Fields = ["BaseOpcode", "Store", "Atomic", "AtomicX2", "Sampler", "Gather4", "NumExtraArgs", "Gradients", "G16", "Coordinates", "LodOrClampOrMip", "HasD16"]; GenericEnum TypeOf_BaseOpcode = MIMGBaseOpcode; let PrimaryKey = ["BaseOpcode"]; let PrimaryKeyName = "getMIMGBaseOpcodeInfo"; } def MIMGDim : GenericEnum { let FilterClass = "AMDGPUDimProps"; } def MIMGDimInfoTable : GenericTable { let FilterClass = "AMDGPUDimProps"; let CppTypeName = "MIMGDimInfo"; let Fields = ["Dim", "NumCoords", "NumGradients", "DA", "Encoding", "AsmSuffix"]; GenericEnum TypeOf_Dim = MIMGDim; let PrimaryKey = ["Dim"]; let PrimaryKeyName = "getMIMGDimInfo"; } def getMIMGDimInfoByEncoding : SearchIndex { let Table = MIMGDimInfoTable; let Key = ["Encoding"]; } def getMIMGDimInfoByAsmSuffix : SearchIndex { let Table = MIMGDimInfoTable; let Key = ["AsmSuffix"]; } class mimg si_gfx10, bits<8> vi = si_gfx10> { field bits<8> SI_GFX10 = si_gfx10; field bits<8> VI = vi; } class MIMGLZMapping { MIMGBaseOpcode L = l; MIMGBaseOpcode LZ = lz; } def MIMGLZMappingTable : GenericTable { let FilterClass = "MIMGLZMapping"; let CppTypeName = "MIMGLZMappingInfo"; let Fields = ["L", "LZ"]; GenericEnum TypeOf_L = MIMGBaseOpcode; GenericEnum TypeOf_LZ = MIMGBaseOpcode; let PrimaryKey = ["L"]; let PrimaryKeyName = "getMIMGLZMappingInfo"; } class MIMGMIPMapping { MIMGBaseOpcode MIP = mip; MIMGBaseOpcode NONMIP = nonmip; } def MIMGMIPMappingTable : GenericTable { let FilterClass = "MIMGMIPMapping"; let CppTypeName = "MIMGMIPMappingInfo"; let Fields = ["MIP", "NONMIP"]; GenericEnum TypeOf_MIP = MIMGBaseOpcode; GenericEnum TypeOf_NONMIP = MIMGBaseOpcode; let PrimaryKey = ["MIP"]; let PrimaryKeyName = "getMIMGMIPMappingInfo"; } class MIMGG16Mapping { MIMGBaseOpcode G = g; MIMGBaseOpcode G16 = g16; } def MIMGG16MappingTable : GenericTable { let FilterClass = "MIMGG16Mapping"; let CppTypeName = "MIMGG16MappingInfo"; let Fields = ["G", "G16"]; GenericEnum TypeOf_G = MIMGBaseOpcode; GenericEnum TypeOf_G16 = MIMGBaseOpcode; let PrimaryKey = ["G"]; let PrimaryKeyName = "getMIMGG16MappingInfo"; } class MIMG_Base : InstSI { let VM_CNT = 1; let EXP_CNT = 1; let MIMG = 1; let Uses = [EXEC]; let mayLoad = 1; let mayStore = 0; let SchedRW = [WriteVMEM]; let UseNamedOperandTable = 1; let hasSideEffects = 0; // XXX ???? let DecoderNamespace = dns; let isAsmParserOnly = !if(!eq(dns,""), 1, 0); } class MIMG : MIMG_Base { let hasPostISelHook = 1; let AsmMatchConverter = "cvtMIMG"; Instruction Opcode = !cast(NAME); MIMGBaseOpcode BaseOpcode; MIMGEncoding MIMGEncoding; bits<8> VDataDwords; bits<8> VAddrDwords; } def MIMGInfoTable : GenericTable { let FilterClass = "MIMG"; let CppTypeName = "MIMGInfo"; let Fields = ["Opcode", "BaseOpcode", "MIMGEncoding", "VDataDwords", "VAddrDwords"]; GenericEnum TypeOf_BaseOpcode = MIMGBaseOpcode; GenericEnum TypeOf_MIMGEncoding = MIMGEncoding; let PrimaryKey = ["BaseOpcode", "MIMGEncoding", "VDataDwords", "VAddrDwords"]; let PrimaryKeyName = "getMIMGOpcodeHelper"; } def getMIMGInfo : SearchIndex { let Table = MIMGInfoTable; let Key = ["Opcode"]; } // This is a separate class so that TableGen memoizes the computations. class MIMGNSAHelper { list AddrAsmNames = !foldl([], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11], lhs, i, !if(!lt(i, num_addrs), !listconcat(lhs, ["vaddr"#!size(lhs)]), lhs)); dag AddrIns = !dag(ins, !foreach(arg, AddrAsmNames, VGPR_32), AddrAsmNames); string AddrAsm = "[" # !foldl("$" # !head(AddrAsmNames), !tail(AddrAsmNames), lhs, rhs, lhs # ", $" # rhs) # "]"; int NSA = !if(!le(num_addrs, 1), ?, !if(!le(num_addrs, 5), 1, !if(!le(num_addrs, 9), 2, !if(!le(num_addrs, 13), 3, ?)))); } // Base class of all pre-gfx10 MIMG instructions. class MIMG_gfx6789 op, dag outs, string dns = ""> : MIMG, MIMGe_gfx6789 { let SubtargetPredicate = isGFX6GFX7GFX8GFX9; let AssemblerPredicate = isGFX6GFX7GFX8GFX9; let MIMGEncoding = MIMGEncGfx6; let d16 = !if(BaseOpcode.HasD16, ?, 0); } // Base class of all non-NSA gfx10 MIMG instructions. class MIMG_gfx10 : MIMG, MIMGe_gfx10 { let SubtargetPredicate = isGFX10Plus; let AssemblerPredicate = isGFX10Plus; let MIMGEncoding = MIMGEncGfx10Default; let d16 = !if(BaseOpcode.HasD16, ?, 0); let nsa = 0; } // Base class for all NSA MIMG instructions. Note that 1-dword addresses always // use non-NSA variants. class MIMG_nsa_gfx10 : MIMG, MIMGe_gfx10 { let SubtargetPredicate = isGFX10Plus; let AssemblerPredicate = isGFX10Plus; let MIMGEncoding = MIMGEncGfx10NSA; MIMGNSAHelper nsah = MIMGNSAHelper; dag AddrIns = nsah.AddrIns; string AddrAsm = nsah.AddrAsm; let d16 = !if(BaseOpcode.HasD16, ?, 0); let nsa = nsah.NSA; } class MIMG_NoSampler_Helper op, string asm, RegisterClass dst_rc, RegisterClass addr_rc, string dns=""> : MIMG_gfx6789 { let InOperandList = !con((ins addr_rc:$vaddr, SReg_256:$srsrc, DMask:$dmask, UNorm:$unorm, GLC:$glc, SLC:$slc, R128A16:$r128, TFE:$tfe, LWE:$lwe, DA:$da), !if(BaseOpcode.HasD16, (ins D16:$d16), (ins))); let AsmString = asm#" $vdata, $vaddr, $srsrc$dmask$unorm$glc$slc$r128$tfe$lwe$da" #!if(BaseOpcode.HasD16, "$d16", ""); } class MIMG_NoSampler_gfx10 : MIMG_gfx10 { let InOperandList = !con((ins AddrRC:$vaddr0, SReg_256:$srsrc, DMask:$dmask, Dim:$dim, UNorm:$unorm, DLC:$dlc, GLC:$glc, SLC:$slc, R128A16:$r128, GFX10A16:$a16, TFE:$tfe, LWE:$lwe), !if(BaseOpcode.HasD16, (ins D16:$d16), (ins))); let AsmString = opcode#" $vdata, $vaddr0, $srsrc$dmask$dim$unorm$dlc$glc$slc$r128$a16$tfe$lwe" #!if(BaseOpcode.HasD16, "$d16", ""); } class MIMG_NoSampler_nsa_gfx10 : MIMG_nsa_gfx10 { let InOperandList = !con(AddrIns, (ins SReg_256:$srsrc, DMask:$dmask, Dim:$dim, UNorm:$unorm, DLC:$dlc, GLC:$glc, SLC:$slc, R128A16:$r128, GFX10A16:$a16, TFE:$tfe, LWE:$lwe), !if(BaseOpcode.HasD16, (ins D16:$d16), (ins))); let AsmString = opcode#" $vdata, "#AddrAsm#", $srsrc$dmask$dim$unorm$dlc$glc$slc$r128$a16$tfe$lwe" #!if(BaseOpcode.HasD16, "$d16", ""); } multiclass MIMG_NoSampler_Src_Helper op, string asm, RegisterClass dst_rc, bit enableDisasm> { let ssamp = 0 in { let VAddrDwords = 1 in { def _V1 : MIMG_NoSampler_Helper ; def _V1_gfx10 : MIMG_NoSampler_gfx10; } let VAddrDwords = 2 in { def _V2 : MIMG_NoSampler_Helper ; def _V2_gfx10 : MIMG_NoSampler_gfx10; def _V2_nsa_gfx10 : MIMG_NoSampler_nsa_gfx10; } let VAddrDwords = 3 in { def _V3 : MIMG_NoSampler_Helper ; def _V3_gfx10 : MIMG_NoSampler_gfx10; def _V3_nsa_gfx10 : MIMG_NoSampler_nsa_gfx10; } let VAddrDwords = 4 in { def _V4 : MIMG_NoSampler_Helper ; def _V4_gfx10 : MIMG_NoSampler_gfx10; def _V4_nsa_gfx10 : MIMG_NoSampler_nsa_gfx10; } } } multiclass MIMG_NoSampler op, string asm, bit has_d16, bit mip = 0, bit isResInfo = 0> { def "" : MIMGBaseOpcode { let Coordinates = !if(isResInfo, 0, 1); let LodOrClampOrMip = mip; let HasD16 = has_d16; } let BaseOpcode = !cast(NAME), mayLoad = !if(isResInfo, 0, 1) in { let VDataDwords = 1 in defm _V1 : MIMG_NoSampler_Src_Helper ; let VDataDwords = 2 in defm _V2 : MIMG_NoSampler_Src_Helper ; let VDataDwords = 3 in defm _V3 : MIMG_NoSampler_Src_Helper ; let VDataDwords = 4 in defm _V4 : MIMG_NoSampler_Src_Helper ; let VDataDwords = 5 in defm _V5 : MIMG_NoSampler_Src_Helper ; } } class MIMG_Store_Helper op, string asm, RegisterClass data_rc, RegisterClass addr_rc, string dns = ""> : MIMG_gfx6789 { let InOperandList = !con((ins data_rc:$vdata, addr_rc:$vaddr, SReg_256:$srsrc, DMask:$dmask, UNorm:$unorm, GLC:$glc, SLC:$slc, R128A16:$r128, TFE:$tfe, LWE:$lwe, DA:$da), !if(BaseOpcode.HasD16, (ins D16:$d16), (ins))); let AsmString = asm#" $vdata, $vaddr, $srsrc$dmask$unorm$glc$slc$r128$tfe$lwe$da" #!if(BaseOpcode.HasD16, "$d16", ""); } class MIMG_Store_gfx10 : MIMG_gfx10 { let InOperandList = !con((ins DataRC:$vdata, AddrRC:$vaddr0, SReg_256:$srsrc, DMask:$dmask, Dim:$dim, UNorm:$unorm, DLC:$dlc, GLC:$glc, SLC:$slc, R128A16:$r128, GFX10A16:$a16, TFE:$tfe, LWE:$lwe), !if(BaseOpcode.HasD16, (ins D16:$d16), (ins))); let AsmString = opcode#" $vdata, $vaddr0, $srsrc$dmask$dim$unorm$dlc$glc$slc$r128$a16$tfe$lwe" #!if(BaseOpcode.HasD16, "$d16", ""); } class MIMG_Store_nsa_gfx10 : MIMG_nsa_gfx10 { let InOperandList = !con((ins DataRC:$vdata), AddrIns, (ins SReg_256:$srsrc, DMask:$dmask, Dim:$dim, UNorm:$unorm, DLC:$dlc, GLC:$glc, SLC:$slc, R128A16:$r128, GFX10A16:$a16, TFE:$tfe, LWE:$lwe), !if(BaseOpcode.HasD16, (ins D16:$d16), (ins))); let AsmString = opcode#" $vdata, "#AddrAsm#", $srsrc$dmask$dim$unorm$dlc$glc$slc$r128$a16$tfe$lwe" #!if(BaseOpcode.HasD16, "$d16", ""); } multiclass MIMG_Store_Addr_Helper { let mayLoad = 0, mayStore = 1, hasSideEffects = 0, hasPostISelHook = 0, DisableWQM = 1, ssamp = 0 in { let VAddrDwords = 1 in { def _V1 : MIMG_Store_Helper ; def _V1_gfx10 : MIMG_Store_gfx10 ; } let VAddrDwords = 2 in { def _V2 : MIMG_Store_Helper ; def _V2_gfx10 : MIMG_Store_gfx10 ; def _V2_nsa_gfx10 : MIMG_Store_nsa_gfx10 ; } let VAddrDwords = 3 in { def _V3 : MIMG_Store_Helper ; def _V3_gfx10 : MIMG_Store_gfx10 ; def _V3_nsa_gfx10 : MIMG_Store_nsa_gfx10 ; } let VAddrDwords = 4 in { def _V4 : MIMG_Store_Helper ; def _V4_gfx10 : MIMG_Store_gfx10 ; def _V4_nsa_gfx10 : MIMG_Store_nsa_gfx10 ; } } } multiclass MIMG_Store op, string asm, bit has_d16, bit mip = 0> { def "" : MIMGBaseOpcode { let Store = 1; let LodOrClampOrMip = mip; let HasD16 = has_d16; } let BaseOpcode = !cast(NAME) in { let VDataDwords = 1 in defm _V1 : MIMG_Store_Addr_Helper ; let VDataDwords = 2 in defm _V2 : MIMG_Store_Addr_Helper ; let VDataDwords = 3 in defm _V3 : MIMG_Store_Addr_Helper ; let VDataDwords = 4 in defm _V4 : MIMG_Store_Addr_Helper ; } } class MIMG_Atomic_gfx6789_base op, string asm, RegisterClass data_rc, RegisterClass addr_rc, string dns=""> : MIMG_gfx6789 { let Constraints = "$vdst = $vdata"; let AsmMatchConverter = "cvtMIMGAtomic"; let InOperandList = (ins data_rc:$vdata, addr_rc:$vaddr, SReg_256:$srsrc, DMask:$dmask, UNorm:$unorm, GLC:$glc, SLC:$slc, R128A16:$r128, TFE:$tfe, LWE:$lwe, DA:$da); let AsmString = asm#" $vdst, $vaddr, $srsrc$dmask$unorm$glc$slc$r128$tfe$lwe$da"; } class MIMG_Atomic_si : MIMG_Atomic_gfx6789_base { let AssemblerPredicate = isGFX6GFX7; } class MIMG_Atomic_vi : MIMG_Atomic_gfx6789_base { let AssemblerPredicate = isGFX8GFX9; let MIMGEncoding = MIMGEncGfx8; } class MIMG_Atomic_gfx10 : MIMG_gfx10(op.SI_GFX10), (outs DataRC:$vdst), !if(enableDisasm, "AMDGPU", "")> { let Constraints = "$vdst = $vdata"; let AsmMatchConverter = "cvtMIMGAtomic"; let InOperandList = (ins DataRC:$vdata, AddrRC:$vaddr0, SReg_256:$srsrc, DMask:$dmask, Dim:$dim, UNorm:$unorm, DLC:$dlc, GLC:$glc, SLC:$slc, R128A16:$r128, GFX10A16:$a16, TFE:$tfe, LWE:$lwe); let AsmString = opcode#" $vdst, $vaddr0, $srsrc$dmask$dim$unorm$dlc$glc$slc$r128$a16$tfe$lwe"; } class MIMG_Atomic_nsa_gfx10 : MIMG_nsa_gfx10(op.SI_GFX10), (outs DataRC:$vdst), num_addrs, !if(enableDisasm, "AMDGPU", "")> { let Constraints = "$vdst = $vdata"; let AsmMatchConverter = "cvtMIMGAtomic"; let InOperandList = !con((ins DataRC:$vdata), AddrIns, (ins SReg_256:$srsrc, DMask:$dmask, Dim:$dim, UNorm:$unorm, DLC:$dlc, GLC:$glc, SLC:$slc, R128A16:$r128, GFX10A16:$a16, TFE:$tfe, LWE:$lwe)); let AsmString = opcode#" $vdata, "#AddrAsm#", $srsrc$dmask$dim$unorm$dlc$glc$slc$r128$a16$tfe$lwe"; } multiclass MIMG_Atomic_Addr_Helper_m { let hasSideEffects = 1, // FIXME: remove this mayLoad = 1, mayStore = 1, hasPostISelHook = 0, DisableWQM = 1, ssamp = 0 in { let VAddrDwords = 1 in { def _V1_si : MIMG_Atomic_si ; def _V1_vi : MIMG_Atomic_vi ; def _V1_gfx10 : MIMG_Atomic_gfx10 ; } let VAddrDwords = 2 in { def _V2_si : MIMG_Atomic_si ; def _V2_vi : MIMG_Atomic_vi ; def _V2_gfx10 : MIMG_Atomic_gfx10 ; def _V2_nsa_gfx10 : MIMG_Atomic_nsa_gfx10 ; } let VAddrDwords = 3 in { def _V3_si : MIMG_Atomic_si ; def _V3_vi : MIMG_Atomic_vi ; def _V3_gfx10 : MIMG_Atomic_gfx10 ; def _V3_nsa_gfx10 : MIMG_Atomic_nsa_gfx10 ; } let VAddrDwords = 4 in { def _V4_si : MIMG_Atomic_si ; def _V4_vi : MIMG_Atomic_vi ; def _V4_gfx10 : MIMG_Atomic_gfx10 ; def _V4_nsa_gfx10 : MIMG_Atomic_nsa_gfx10 ; } } } multiclass MIMG_Atomic { // 64-bit atomics def "" : MIMGBaseOpcode { let Atomic = 1; let AtomicX2 = isCmpSwap; } let BaseOpcode = !cast(NAME) in { // _V* variants have different dst size, but the size is encoded implicitly, // using dmask and tfe. Only 32-bit variant is registered with disassembler. // Other variants are reconstructed by disassembler using dmask and tfe. let VDataDwords = !if(isCmpSwap, 2, 1) in defm _V1 : MIMG_Atomic_Addr_Helper_m ; let VDataDwords = !if(isCmpSwap, 4, 2) in defm _V2 : MIMG_Atomic_Addr_Helper_m ; } } class MIMG_Sampler_Helper op, string asm, RegisterClass dst_rc, RegisterClass src_rc, string dns=""> : MIMG_gfx6789 { let InOperandList = !con((ins src_rc:$vaddr, SReg_256:$srsrc, SReg_128:$ssamp, DMask:$dmask, UNorm:$unorm, GLC:$glc, SLC:$slc, R128A16:$r128, TFE:$tfe, LWE:$lwe, DA:$da), !if(BaseOpcode.HasD16, (ins D16:$d16), (ins))); let AsmString = asm#" $vdata, $vaddr, $srsrc, $ssamp$dmask$unorm$glc$slc$r128$tfe$lwe$da" #!if(BaseOpcode.HasD16, "$d16", ""); } class MIMG_Sampler_gfx10 : MIMG_gfx10 { let InOperandList = !con((ins AddrRC:$vaddr0, SReg_256:$srsrc, SReg_128:$ssamp, DMask:$dmask, Dim:$dim, UNorm:$unorm, DLC:$dlc, GLC:$glc, SLC:$slc, R128A16:$r128, GFX10A16:$a16, TFE:$tfe, LWE:$lwe), !if(BaseOpcode.HasD16, (ins D16:$d16), (ins))); let AsmString = opcode#" $vdata, $vaddr0, $srsrc, $ssamp$dmask$dim$unorm" #"$dlc$glc$slc$r128$a16$tfe$lwe" #!if(BaseOpcode.HasD16, "$d16", ""); } class MIMG_Sampler_nsa_gfx10 : MIMG_nsa_gfx10 { let InOperandList = !con(AddrIns, (ins SReg_256:$srsrc, SReg_128:$ssamp, DMask:$dmask, Dim:$dim, UNorm:$unorm, DLC:$dlc, GLC:$glc, SLC:$slc, R128A16:$r128, GFX10A16:$a16, TFE:$tfe, LWE:$lwe), !if(BaseOpcode.HasD16, (ins D16:$d16), (ins))); let AsmString = opcode#" $vdata, "#AddrAsm#", $srsrc, $ssamp$dmask$dim$unorm" #"$dlc$glc$slc$r128$a16$tfe$lwe" #!if(BaseOpcode.HasD16, "$d16", ""); } class MIMGAddrSize { int NumWords = dw; RegisterClass RegClass = !if(!le(NumWords, 0), ?, !if(!eq(NumWords, 1), VGPR_32, !if(!eq(NumWords, 2), VReg_64, !if(!eq(NumWords, 3), VReg_96, !if(!eq(NumWords, 4), VReg_128, !if(!le(NumWords, 8), VReg_256, !if(!le(NumWords, 16), VReg_512, ?))))))); // Whether the instruction variant with this vaddr size should be enabled for // the auto-generated disassembler. bit Disassemble = enable_disasm; } // Return whether x is in lst. class isIntInList lst> { bit ret = !foldl(0, lst, lhs, y, !or(lhs, !eq(x, y))); } // Return whether a value inside the range [min, max] (endpoints inclusive) // is in the given list. class isRangeInList lst> { bit ret = !foldl(0, lst, lhs, y, !or(lhs, !and(!le(min, y), !le(y, max)))); } class MIMGAddrSizes_tmp lst, int min> { list List = lst; int Min = min; } class MIMG_Sampler_AddrSizes { // List of all possible numbers of address words, taking all combinations of // A16 and image dimension into account (note: no MSAA, since this is for // sample/gather ops). list AllNumAddrWords = !foreach(dw, !if(sample.Gradients, !if(!eq(sample.LodOrClamp, ""), [2, 3, 4, 5, 6, 7, 9], [2, 3, 4, 5, 7, 8, 10]), !if(!eq(sample.LodOrClamp, ""), [1, 2, 3], [1, 2, 3, 4])), !add(dw, !size(sample.ExtraAddrArgs))); // Generate machine instructions based on possible register classes for the // required numbers of address words. The disassembler defaults to the // smallest register class. list MachineInstrs = !foldl(MIMGAddrSizes_tmp<[], 0>, [1, 2, 3, 4, 8, 16], lhs, dw, !if(isRangeInList.ret, MIMGAddrSizes_tmp< !listconcat(lhs.List, [MIMGAddrSize]), !if(!eq(dw, 3), 3, !add(dw, 1))>, // we still need _V4 for codegen w/ 3 dwords lhs)).List; // For NSA, generate machine instructions for all possible numbers of words // except 1 (which is already covered by the non-NSA case). // The disassembler defaults to the largest number of arguments among the // variants with the same number of NSA words, and custom code then derives // the exact variant based on the sample variant and the image dimension. list NSAInstrs = !foldl([], [[12, 11, 10], [9, 8, 7, 6], [5, 4, 3, 2]], prev, nsa_group, !listconcat(prev, !foldl([], nsa_group, lhs, dw, !if(isIntInList.ret, !listconcat(lhs, [MIMGAddrSize]), lhs)))); } multiclass MIMG_Sampler_Src_Helper op, string asm, AMDGPUSampleVariant sample, RegisterClass dst_rc, bit enableDisasm = 0> { foreach addr = MIMG_Sampler_AddrSizes.MachineInstrs in { let VAddrDwords = addr.NumWords in { def _V # addr.NumWords : MIMG_Sampler_Helper ; def _V # addr.NumWords # _gfx10 : MIMG_Sampler_gfx10 ; } } foreach addr = MIMG_Sampler_AddrSizes.NSAInstrs in { let VAddrDwords = addr.NumWords in { def _V # addr.NumWords # _nsa_gfx10 : MIMG_Sampler_nsa_gfx10; } } } class MIMG_Sampler_BaseOpcode : MIMGBaseOpcode { let Sampler = 1; let NumExtraArgs = !size(sample.ExtraAddrArgs); let Gradients = sample.Gradients; let LodOrClampOrMip = !ne(sample.LodOrClamp, ""); } multiclass MIMG_Sampler op, AMDGPUSampleVariant sample, bit wqm = 0, bit isG16 = 0, bit isGetLod = 0, string asm = "image_sample"#sample.LowerCaseMod#!if(isG16, "_g16", "")> { def "" : MIMG_Sampler_BaseOpcode { let HasD16 = !if(isGetLod, 0, 1); let G16 = isG16; } let BaseOpcode = !cast(NAME), WQM = wqm, mayLoad = !if(isGetLod, 0, 1) in { let VDataDwords = 1 in defm _V1 : MIMG_Sampler_Src_Helper; let VDataDwords = 2 in defm _V2 : MIMG_Sampler_Src_Helper; let VDataDwords = 3 in defm _V3 : MIMG_Sampler_Src_Helper; let VDataDwords = 4 in defm _V4 : MIMG_Sampler_Src_Helper; let VDataDwords = 5 in defm _V5 : MIMG_Sampler_Src_Helper; } } multiclass MIMG_Sampler_WQM op, AMDGPUSampleVariant sample> : MIMG_Sampler; multiclass MIMG_Gather op, AMDGPUSampleVariant sample, bit wqm = 0, string asm = "image_gather4"#sample.LowerCaseMod> { def "" : MIMG_Sampler_BaseOpcode { let HasD16 = 1; let Gather4 = 1; } let BaseOpcode = !cast(NAME), WQM = wqm, Gather4 = 1, hasPostISelHook = 0 in { let VDataDwords = 2 in defm _V2 : MIMG_Sampler_Src_Helper; /* for packed D16 only */ let VDataDwords = 4 in defm _V4 : MIMG_Sampler_Src_Helper; let VDataDwords = 5 in defm _V5 : MIMG_Sampler_Src_Helper; } } multiclass MIMG_Gather_WQM op, AMDGPUSampleVariant sample> : MIMG_Gather; //===----------------------------------------------------------------------===// // MIMG Instructions //===----------------------------------------------------------------------===// defm IMAGE_LOAD : MIMG_NoSampler <0x00000000, "image_load", 1>; defm IMAGE_LOAD_MIP : MIMG_NoSampler <0x00000001, "image_load_mip", 1, 1>; defm IMAGE_LOAD_PCK : MIMG_NoSampler <0x00000002, "image_load_pck", 0>; defm IMAGE_LOAD_PCK_SGN : MIMG_NoSampler <0x00000003, "image_load_pck_sgn", 0>; defm IMAGE_LOAD_MIP_PCK : MIMG_NoSampler <0x00000004, "image_load_mip_pck", 0, 1>; defm IMAGE_LOAD_MIP_PCK_SGN : MIMG_NoSampler <0x00000005, "image_load_mip_pck_sgn", 0, 1>; defm IMAGE_STORE : MIMG_Store <0x00000008, "image_store", 1>; defm IMAGE_STORE_MIP : MIMG_Store <0x00000009, "image_store_mip", 1, 1>; defm IMAGE_STORE_PCK : MIMG_Store <0x0000000a, "image_store_pck", 0>; defm IMAGE_STORE_MIP_PCK : MIMG_Store <0x0000000b, "image_store_mip_pck", 0, 1>; defm IMAGE_GET_RESINFO : MIMG_NoSampler <0x0000000e, "image_get_resinfo", 0, 1, 1>; defm IMAGE_ATOMIC_SWAP : MIMG_Atomic , "image_atomic_swap">; defm IMAGE_ATOMIC_CMPSWAP : MIMG_Atomic , "image_atomic_cmpswap", 1>; defm IMAGE_ATOMIC_ADD : MIMG_Atomic , "image_atomic_add">; defm IMAGE_ATOMIC_SUB : MIMG_Atomic , "image_atomic_sub">; //def IMAGE_ATOMIC_RSUB : MIMG_NoPattern_ <"image_atomic_rsub", 0x00000013>; -- not on VI defm IMAGE_ATOMIC_SMIN : MIMG_Atomic , "image_atomic_smin">; defm IMAGE_ATOMIC_UMIN : MIMG_Atomic , "image_atomic_umin">; defm IMAGE_ATOMIC_SMAX : MIMG_Atomic , "image_atomic_smax">; defm IMAGE_ATOMIC_UMAX : MIMG_Atomic , "image_atomic_umax">; defm IMAGE_ATOMIC_AND : MIMG_Atomic , "image_atomic_and">; defm IMAGE_ATOMIC_OR : MIMG_Atomic , "image_atomic_or">; defm IMAGE_ATOMIC_XOR : MIMG_Atomic , "image_atomic_xor">; defm IMAGE_ATOMIC_INC : MIMG_Atomic , "image_atomic_inc">; defm IMAGE_ATOMIC_DEC : MIMG_Atomic , "image_atomic_dec">; //let FPAtomic = 1 in { //def IMAGE_ATOMIC_FCMPSWAP : MIMG_NoPattern_ <"image_atomic_fcmpswap", 0x0000001d, 1>; -- not on VI //def IMAGE_ATOMIC_FMIN : MIMG_NoPattern_ <"image_atomic_fmin", 0x0000001e>; -- not on VI //def IMAGE_ATOMIC_FMAX : MIMG_NoPattern_ <"image_atomic_fmax", 0x0000001f>; -- not on VI //} // End let FPAtomic = 1 defm IMAGE_SAMPLE : MIMG_Sampler_WQM <0x00000020, AMDGPUSample>; defm IMAGE_SAMPLE_CL : MIMG_Sampler_WQM <0x00000021, AMDGPUSample_cl>; defm IMAGE_SAMPLE_D : MIMG_Sampler <0x00000022, AMDGPUSample_d>; defm IMAGE_SAMPLE_D_CL : MIMG_Sampler <0x00000023, AMDGPUSample_d_cl>; defm IMAGE_SAMPLE_D_G16 : MIMG_Sampler <0x000000a2, AMDGPUSample_d, 0, 1>; defm IMAGE_SAMPLE_D_CL_G16 : MIMG_Sampler <0x000000a3, AMDGPUSample_d_cl, 0, 1>; defm IMAGE_SAMPLE_L : MIMG_Sampler <0x00000024, AMDGPUSample_l>; defm IMAGE_SAMPLE_B : MIMG_Sampler_WQM <0x00000025, AMDGPUSample_b>; defm IMAGE_SAMPLE_B_CL : MIMG_Sampler_WQM <0x00000026, AMDGPUSample_b_cl>; defm IMAGE_SAMPLE_LZ : MIMG_Sampler <0x00000027, AMDGPUSample_lz>; defm IMAGE_SAMPLE_C : MIMG_Sampler_WQM <0x00000028, AMDGPUSample_c>; defm IMAGE_SAMPLE_C_CL : MIMG_Sampler_WQM <0x00000029, AMDGPUSample_c_cl>; defm IMAGE_SAMPLE_C_D : MIMG_Sampler <0x0000002a, AMDGPUSample_c_d>; defm IMAGE_SAMPLE_C_D_CL : MIMG_Sampler <0x0000002b, AMDGPUSample_c_d_cl>; defm IMAGE_SAMPLE_C_D_G16 : MIMG_Sampler <0x000000aa, AMDGPUSample_c_d, 0, 1>; defm IMAGE_SAMPLE_C_D_CL_G16 : MIMG_Sampler <0x000000ab, AMDGPUSample_c_d_cl, 0, 1>; defm IMAGE_SAMPLE_C_L : MIMG_Sampler <0x0000002c, AMDGPUSample_c_l>; defm IMAGE_SAMPLE_C_B : MIMG_Sampler_WQM <0x0000002d, AMDGPUSample_c_b>; defm IMAGE_SAMPLE_C_B_CL : MIMG_Sampler_WQM <0x0000002e, AMDGPUSample_c_b_cl>; defm IMAGE_SAMPLE_C_LZ : MIMG_Sampler <0x0000002f, AMDGPUSample_c_lz>; defm IMAGE_SAMPLE_O : MIMG_Sampler_WQM <0x00000030, AMDGPUSample_o>; defm IMAGE_SAMPLE_CL_O : MIMG_Sampler_WQM <0x00000031, AMDGPUSample_cl_o>; defm IMAGE_SAMPLE_D_O : MIMG_Sampler <0x00000032, AMDGPUSample_d_o>; defm IMAGE_SAMPLE_D_CL_O : MIMG_Sampler <0x00000033, AMDGPUSample_d_cl_o>; defm IMAGE_SAMPLE_D_O_G16 : MIMG_Sampler <0x000000b2, AMDGPUSample_d_o, 0, 1>; defm IMAGE_SAMPLE_D_CL_O_G16 : MIMG_Sampler <0x000000b3, AMDGPUSample_d_cl_o, 0, 1>; defm IMAGE_SAMPLE_L_O : MIMG_Sampler <0x00000034, AMDGPUSample_l_o>; defm IMAGE_SAMPLE_B_O : MIMG_Sampler_WQM <0x00000035, AMDGPUSample_b_o>; defm IMAGE_SAMPLE_B_CL_O : MIMG_Sampler_WQM <0x00000036, AMDGPUSample_b_cl_o>; defm IMAGE_SAMPLE_LZ_O : MIMG_Sampler <0x00000037, AMDGPUSample_lz_o>; defm IMAGE_SAMPLE_C_O : MIMG_Sampler_WQM <0x00000038, AMDGPUSample_c_o>; defm IMAGE_SAMPLE_C_CL_O : MIMG_Sampler_WQM <0x00000039, AMDGPUSample_c_cl_o>; defm IMAGE_SAMPLE_C_D_O : MIMG_Sampler <0x0000003a, AMDGPUSample_c_d_o>; defm IMAGE_SAMPLE_C_D_CL_O : MIMG_Sampler <0x0000003b, AMDGPUSample_c_d_cl_o>; defm IMAGE_SAMPLE_C_D_O_G16 : MIMG_Sampler <0x000000ba, AMDGPUSample_c_d_o, 0, 1>; defm IMAGE_SAMPLE_C_D_CL_O_G16 : MIMG_Sampler <0x000000bb, AMDGPUSample_c_d_cl_o, 0, 1>; defm IMAGE_SAMPLE_C_L_O : MIMG_Sampler <0x0000003c, AMDGPUSample_c_l_o>; defm IMAGE_SAMPLE_C_B_CL_O : MIMG_Sampler_WQM <0x0000003e, AMDGPUSample_c_b_cl_o>; defm IMAGE_SAMPLE_C_B_O : MIMG_Sampler_WQM <0x0000003d, AMDGPUSample_c_b_o>; defm IMAGE_SAMPLE_C_LZ_O : MIMG_Sampler <0x0000003f, AMDGPUSample_c_lz_o>; defm IMAGE_GATHER4 : MIMG_Gather_WQM <0x00000040, AMDGPUSample>; defm IMAGE_GATHER4_CL : MIMG_Gather_WQM <0x00000041, AMDGPUSample_cl>; defm IMAGE_GATHER4_L : MIMG_Gather <0x00000044, AMDGPUSample_l>; defm IMAGE_GATHER4_B : MIMG_Gather_WQM <0x00000045, AMDGPUSample_b>; defm IMAGE_GATHER4_B_CL : MIMG_Gather_WQM <0x00000046, AMDGPUSample_b_cl>; defm IMAGE_GATHER4_LZ : MIMG_Gather <0x00000047, AMDGPUSample_lz>; defm IMAGE_GATHER4_C : MIMG_Gather_WQM <0x00000048, AMDGPUSample_c>; defm IMAGE_GATHER4_C_CL : MIMG_Gather_WQM <0x00000049, AMDGPUSample_c_cl>; defm IMAGE_GATHER4_C_L : MIMG_Gather <0x0000004c, AMDGPUSample_c_l>; defm IMAGE_GATHER4_C_B : MIMG_Gather_WQM <0x0000004d, AMDGPUSample_c_b>; defm IMAGE_GATHER4_C_B_CL : MIMG_Gather_WQM <0x0000004e, AMDGPUSample_c_b_cl>; defm IMAGE_GATHER4_C_LZ : MIMG_Gather <0x0000004f, AMDGPUSample_c_lz>; defm IMAGE_GATHER4_O : MIMG_Gather_WQM <0x00000050, AMDGPUSample_o>; defm IMAGE_GATHER4_CL_O : MIMG_Gather_WQM <0x00000051, AMDGPUSample_cl_o>; defm IMAGE_GATHER4_L_O : MIMG_Gather <0x00000054, AMDGPUSample_l_o>; defm IMAGE_GATHER4_B_O : MIMG_Gather_WQM <0x00000055, AMDGPUSample_b_o>; defm IMAGE_GATHER4_B_CL_O : MIMG_Gather <0x00000056, AMDGPUSample_b_cl_o>; defm IMAGE_GATHER4_LZ_O : MIMG_Gather <0x00000057, AMDGPUSample_lz_o>; defm IMAGE_GATHER4_C_O : MIMG_Gather_WQM <0x00000058, AMDGPUSample_c_o>; defm IMAGE_GATHER4_C_CL_O : MIMG_Gather_WQM <0x00000059, AMDGPUSample_c_cl_o>; defm IMAGE_GATHER4_C_L_O : MIMG_Gather <0x0000005c, AMDGPUSample_c_l_o>; defm IMAGE_GATHER4_C_B_O : MIMG_Gather_WQM <0x0000005d, AMDGPUSample_c_b_o>; defm IMAGE_GATHER4_C_B_CL_O : MIMG_Gather_WQM <0x0000005e, AMDGPUSample_c_b_cl_o>; defm IMAGE_GATHER4_C_LZ_O : MIMG_Gather <0x0000005f, AMDGPUSample_c_lz_o>; defm IMAGE_GET_LOD : MIMG_Sampler <0x00000060, AMDGPUSample, 1, 0, 1, "image_get_lod">; defm IMAGE_SAMPLE_CD : MIMG_Sampler <0x00000068, AMDGPUSample_cd>; defm IMAGE_SAMPLE_CD_CL : MIMG_Sampler <0x00000069, AMDGPUSample_cd_cl>; defm IMAGE_SAMPLE_C_CD : MIMG_Sampler <0x0000006a, AMDGPUSample_c_cd>; defm IMAGE_SAMPLE_C_CD_CL : MIMG_Sampler <0x0000006b, AMDGPUSample_c_cd_cl>; defm IMAGE_SAMPLE_CD_O : MIMG_Sampler <0x0000006c, AMDGPUSample_cd_o>; defm IMAGE_SAMPLE_CD_CL_O : MIMG_Sampler <0x0000006d, AMDGPUSample_cd_cl_o>; defm IMAGE_SAMPLE_C_CD_O : MIMG_Sampler <0x0000006e, AMDGPUSample_c_cd_o>; defm IMAGE_SAMPLE_C_CD_CL_O : MIMG_Sampler <0x0000006f, AMDGPUSample_c_cd_cl_o>; defm IMAGE_SAMPLE_CD_G16 : MIMG_Sampler <0x000000e8, AMDGPUSample_cd, 0, 1>; defm IMAGE_SAMPLE_CD_CL_G16 : MIMG_Sampler <0x000000e9, AMDGPUSample_cd_cl, 0, 1>; defm IMAGE_SAMPLE_C_CD_G16 : MIMG_Sampler <0x000000ea, AMDGPUSample_c_cd, 0, 1>; defm IMAGE_SAMPLE_C_CD_CL_G16 : MIMG_Sampler <0x000000eb, AMDGPUSample_c_cd_cl, 0, 1>; defm IMAGE_SAMPLE_CD_O_G16 : MIMG_Sampler <0x000000ec, AMDGPUSample_cd_o, 0, 1>; defm IMAGE_SAMPLE_CD_CL_O_G16 : MIMG_Sampler <0x000000ed, AMDGPUSample_cd_cl_o, 0, 1>; defm IMAGE_SAMPLE_C_CD_O_G16 : MIMG_Sampler <0x000000ee, AMDGPUSample_c_cd_o, 0, 1>; defm IMAGE_SAMPLE_C_CD_CL_O_G16 : MIMG_Sampler <0x000000ef, AMDGPUSample_c_cd_cl_o, 0, 1>; //def IMAGE_RSRC256 : MIMG_NoPattern_RSRC256 <"image_rsrc256", 0x0000007e>; //def IMAGE_SAMPLER : MIMG_NoPattern_ <"image_sampler", 0x0000007f>; let SubtargetPredicate = HasGFX10_BEncoding in defm IMAGE_MSAA_LOAD : MIMG_NoSampler <0x00000080, "image_msaa_load", 1>; /********** ========================================= **********/ /********** Table of dimension-aware image intrinsics **********/ /********** ========================================= **********/ class ImageDimIntrinsicInfo { Intrinsic Intr = I; MIMGBaseOpcode BaseOpcode = !cast(!strconcat("IMAGE_", I.P.OpMod)); AMDGPUDimProps Dim = I.P.Dim; } def ImageDimIntrinsicTable : GenericTable { let FilterClass = "ImageDimIntrinsicInfo"; let Fields = ["Intr", "BaseOpcode", "Dim"]; GenericEnum TypeOf_BaseOpcode = MIMGBaseOpcode; GenericEnum TypeOf_Dim = MIMGDim; let PrimaryKey = ["Intr"]; let PrimaryKeyName = "getImageDimIntrinsicInfo"; let PrimaryKeyEarlyOut = 1; } def getImageDimInstrinsicByBaseOpcode : SearchIndex { let Table = ImageDimIntrinsicTable; let Key = ["BaseOpcode", "Dim"]; } foreach intr = !listconcat(AMDGPUImageDimIntrinsics, AMDGPUImageDimAtomicIntrinsics) in { def : ImageDimIntrinsicInfo; } // L to LZ Optimization Mapping def : MIMGLZMapping; def : MIMGLZMapping; def : MIMGLZMapping; def : MIMGLZMapping; def : MIMGLZMapping; def : MIMGLZMapping; def : MIMGLZMapping; def : MIMGLZMapping; // MIP to NONMIP Optimization Mapping def : MIMGMIPMapping; def : MIMGMIPMapping; // G to G16 Optimization Mapping def : MIMGG16Mapping; def : MIMGG16Mapping; def : MIMGG16Mapping; def : MIMGG16Mapping; def : MIMGG16Mapping; def : MIMGG16Mapping; def : MIMGG16Mapping; def : MIMGG16Mapping; def : MIMGG16Mapping; def : MIMGG16Mapping; def : MIMGG16Mapping; def : MIMGG16Mapping; def : MIMGG16Mapping; def : MIMGG16Mapping; def : MIMGG16Mapping; def : MIMGG16Mapping;