1//===-- MIMGInstructions.td - MIMG Instruction Definitions ----------------===// 2// 3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4// See https://llvm.org/LICENSE.txt for license information. 5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6// 7//===----------------------------------------------------------------------===// 8 9// MIMG-specific encoding families to distinguish between semantically 10// equivalent machine instructions with different encoding. 11// 12// - MIMGEncGfx6: encoding introduced with gfx6 (obsoleted for atomics in gfx8) 13// - MIMGEncGfx8: encoding introduced with gfx8 for atomics 14// - MIMGEncGfx90a: encoding for gfx90a for atomics 15// - MIMGEncGfx10Default: gfx10 default (non-NSA) encoding 16// - MIMGEncGfx10NSA: gfx10 NSA encoding 17// - MIMGEncGfx11Default: gfx11 default (non-NSA) encoding 18// - MIMGEncGfx11NSA: gfx11 partial NSA encoding 19// - MIMGEncGfx12: gfx12 encoding (partial NSA) 20class MIMGEncoding; 21 22def MIMGEncGfx6 : MIMGEncoding; 23def MIMGEncGfx8 : MIMGEncoding; 24def MIMGEncGfx90a : MIMGEncoding; 25def MIMGEncGfx10Default : MIMGEncoding; 26def MIMGEncGfx10NSA : MIMGEncoding; 27def MIMGEncGfx11Default : MIMGEncoding; 28def MIMGEncGfx11NSA : MIMGEncoding; 29def MIMGEncGfx12 : MIMGEncoding; 30 31def MIMGEncoding : GenericEnum { 32 let FilterClass = "MIMGEncoding"; 33} 34 35// Represent an ISA-level opcode, independent of the encoding and the 36// vdata/vaddr size. 37class MIMGBaseOpcode : PredicateControl { 38 MIMGBaseOpcode BaseOpcode = !cast<MIMGBaseOpcode>(NAME); 39 bit Store = 0; 40 bit Atomic = 0; 41 bit AtomicX2 = 0; // (f)cmpswap 42 bit Sampler = 0; 43 bit Gather4 = 0; 44 bits<8> NumExtraArgs = 0; 45 bit Gradients = 0; 46 bit G16 = 0; 47 bit Coordinates = 1; 48 bit LodOrClampOrMip = 0; 49 bit HasD16 = 0; 50 bit IsAtomicRet = 0; 51 bit MSAA = 0; 52 bit BVH = 0; 53 bit A16 = 0; 54 bit NoReturn = 0; 55 bit PointSampleAccel = 0; // Opcode eligible for gfx11.5 point sample acceleration 56} 57 58def MIMGBaseOpcode : GenericEnum { 59 let FilterClass = "MIMGBaseOpcode"; 60} 61 62def MIMGBaseOpcodesTable : GenericTable { 63 let FilterClass = "MIMGBaseOpcode"; 64 let CppTypeName = "MIMGBaseOpcodeInfo"; 65 let Fields = ["BaseOpcode", "Store", "Atomic", "AtomicX2", "Sampler", 66 "Gather4", "NumExtraArgs", "Gradients", "G16", "Coordinates", 67 "LodOrClampOrMip", "HasD16", "MSAA", "BVH", "A16", "NoReturn", 68 "PointSampleAccel"]; 69 string TypeOf_BaseOpcode = "MIMGBaseOpcode"; 70 71 let PrimaryKey = ["BaseOpcode"]; 72 let PrimaryKeyName = "getMIMGBaseOpcodeInfo"; 73} 74 75def MIMGDim : GenericEnum { 76 let FilterClass = "AMDGPUDimProps"; 77} 78 79def MIMGDimInfoTable : GenericTable { 80 let FilterClass = "AMDGPUDimProps"; 81 let CppTypeName = "MIMGDimInfo"; 82 let Fields = ["Dim", "NumCoords", "NumGradients", "MSAA", "DA", "Encoding", "AsmSuffix"]; 83 string TypeOf_Dim = "MIMGDim"; 84 85 let PrimaryKey = ["Dim"]; 86 let PrimaryKeyName = "getMIMGDimInfo"; 87} 88 89def getMIMGDimInfoByEncoding : SearchIndex { 90 let Table = MIMGDimInfoTable; 91 let Key = ["Encoding"]; 92} 93 94def getMIMGDimInfoByAsmSuffix : SearchIndex { 95 let Table = MIMGDimInfoTable; 96 let Key = ["AsmSuffix"]; 97} 98 99def MIMG { 100 int NOP = -1; 101} 102 103class mimgopc <int gfx12, int gfx11, int gfx10m, int vi = gfx10m, int si = gfx10m> { 104 field bits<8> GFX12 = gfx12; 105 field bits<8> GFX11 = gfx11; 106 field bits<8> GFX10M = gfx10m; // GFX10minus for all but atomics 107 field bits<8> VI = vi; // VI is only used for atomic/sampler/gather instructions 108 field bits<8> SI = si; // SI is only used for atomic instructions 109 bit HAS_GFX12 = !ne(gfx12, MIMG.NOP); 110 bit HAS_GFX11 = !ne(gfx11, MIMG.NOP); 111 bit HAS_GFX10M = !ne(gfx10m, MIMG.NOP); 112 bit HAS_VI = !ne(vi, MIMG.NOP); 113 bit HAS_SI = !ne(si, MIMG.NOP); 114} 115 116class MIMGLZMapping<MIMGBaseOpcode l, MIMGBaseOpcode lz> { 117 MIMGBaseOpcode L = l; 118 MIMGBaseOpcode LZ = lz; 119} 120 121def MIMGLZMappingTable : GenericTable { 122 let FilterClass = "MIMGLZMapping"; 123 let CppTypeName = "MIMGLZMappingInfo"; 124 let Fields = ["L", "LZ"]; 125 string TypeOf_L = "MIMGBaseOpcode"; 126 string TypeOf_LZ = "MIMGBaseOpcode"; 127 128 let PrimaryKey = ["L"]; 129 let PrimaryKeyName = "getMIMGLZMappingInfo"; 130} 131 132class MIMGMIPMapping<MIMGBaseOpcode mip, MIMGBaseOpcode nonmip> { 133 MIMGBaseOpcode MIP = mip; 134 MIMGBaseOpcode NONMIP = nonmip; 135} 136 137def MIMGMIPMappingTable : GenericTable { 138 let FilterClass = "MIMGMIPMapping"; 139 let CppTypeName = "MIMGMIPMappingInfo"; 140 let Fields = ["MIP", "NONMIP"]; 141 string TypeOf_MIP = "MIMGBaseOpcode"; 142 string TypeOf_NONMIP = "MIMGBaseOpcode"; 143 144 let PrimaryKey = ["MIP"]; 145 let PrimaryKeyName = "getMIMGMIPMappingInfo"; 146} 147 148class MIMGBiasMapping<MIMGBaseOpcode bias, MIMGBaseOpcode nobias> { 149 MIMGBaseOpcode Bias = bias; 150 MIMGBaseOpcode NoBias = nobias; 151} 152 153def MIMGBiasMappingTable : GenericTable { 154 let FilterClass = "MIMGBiasMapping"; 155 let CppTypeName = "MIMGBiasMappingInfo"; 156 let Fields = ["Bias", "NoBias"]; 157 string TypeOf_Bias = "MIMGBaseOpcode"; 158 string TypeOf_NoBias = "MIMGBaseOpcode"; 159 160 let PrimaryKey = ["Bias"]; 161 let PrimaryKeyName = "getMIMGBiasMappingInfo"; 162} 163 164class MIMGOffsetMapping<MIMGBaseOpcode offset, MIMGBaseOpcode nooffset> { 165 MIMGBaseOpcode Offset = offset; 166 MIMGBaseOpcode NoOffset = nooffset; 167} 168 169def MIMGOffsetMappingTable : GenericTable { 170 let FilterClass = "MIMGOffsetMapping"; 171 let CppTypeName = "MIMGOffsetMappingInfo"; 172 let Fields = ["Offset", "NoOffset"]; 173 string TypeOf_Offset = "MIMGBaseOpcode"; 174 string TypeOf_NoOffset = "MIMGBaseOpcode"; 175 176 let PrimaryKey = ["Offset"]; 177 let PrimaryKeyName = "getMIMGOffsetMappingInfo"; 178} 179 180class MIMGG16Mapping<MIMGBaseOpcode g, MIMGBaseOpcode g16> { 181 MIMGBaseOpcode G = g; 182 MIMGBaseOpcode G16 = g16; 183} 184 185def MIMGG16MappingTable : GenericTable { 186 let FilterClass = "MIMGG16Mapping"; 187 let CppTypeName = "MIMGG16MappingInfo"; 188 let Fields = ["G", "G16"]; 189 string TypeOf_G = "MIMGBaseOpcode"; 190 string TypeOf_G16 = "MIMGBaseOpcode"; 191 192 let PrimaryKey = ["G"]; 193 let PrimaryKeyName = "getMIMGG16MappingInfo"; 194} 195 196class MIMG_Base <dag outs, string dns = ""> 197 : InstSI <outs, (ins), "", []> { 198 199 let VM_CNT = 1; 200 let EXP_CNT = 1; 201 let MIMG = 1; 202 let Uses = [EXEC]; 203 let mayLoad = 1; 204 let mayStore = 0; 205 let SchedRW = [WriteVMEM]; 206 let UseNamedOperandTable = 1; 207 let hasSideEffects = 0; // XXX ???? 208 209 let DecoderNamespace = dns; 210 let isAsmParserOnly = !eq(dns, ""); 211} 212 213class MIMG <dag outs, string dns = ""> 214 : MIMG_Base <outs, dns> { 215 216 let hasPostISelHook = 1; 217 let usesCustomInserter = 1; 218 219 Instruction Opcode = !cast<Instruction>(NAME); 220 MIMGBaseOpcode BaseOpcode; 221 MIMGEncoding MIMGEncoding; 222 bits<8> VDataDwords; 223 bits<8> VAddrDwords; 224 225 // If NSA is used this counts number of operands VAddrDwords is split into. 226 bits<8> VAddrOperands; 227} 228 229class VIMAGE <dag outs, string dns = ""> : MIMG<outs, dns> { 230 let MIMG = 0; 231 let VIMAGE = 1; 232} 233 234class VSAMPLE <dag outs, string dns = ""> : MIMG<outs, dns> { 235 let MIMG = 0; 236 let VSAMPLE = 1; 237} 238 239def MIMGInfoTable : GenericTable { 240 let FilterClass = "MIMG"; 241 let CppTypeName = "MIMGInfo"; 242 let Fields = ["Opcode", "BaseOpcode", "MIMGEncoding", "VDataDwords", 243 "VAddrDwords", "VAddrOperands"]; 244 string TypeOf_BaseOpcode = "MIMGBaseOpcode"; 245 string TypeOf_MIMGEncoding = "MIMGEncoding"; 246 247 let PrimaryKey = ["BaseOpcode", "MIMGEncoding", "VDataDwords", "VAddrDwords"]; 248 let PrimaryKeyName = "getMIMGOpcodeHelper"; 249} 250 251def getMIMGInfo : SearchIndex { 252 let Table = MIMGInfoTable; 253 let Key = ["Opcode"]; 254} 255 256class NSAHelper { 257 dag AddrIns; 258 string AddrAsm; 259 int NSA; 260} 261 262class MIMGNSAHelper<int num_addrs, 263 list<RegisterClass> addr_types=!listsplat(VGPR_32, num_addrs)> 264 : NSAHelper<> { 265 list<string> AddrAsmNames = !foreach(i, !range(num_addrs), "vaddr" # i); 266 let AddrIns = !dag(ins, addr_types, AddrAsmNames); 267 let AddrAsm = "[$" # !interleave(AddrAsmNames, ", $") # "]"; 268 269 let NSA = !if(!le(num_addrs, 1), ?, 270 !if(!le(num_addrs, 5), 1, 271 !if(!le(num_addrs, 9), 2, 272 !if(!le(num_addrs, 13), 3, ?)))); 273} 274 275class PartialNSAHelper<int num_addrs, int max_addr, RegisterClass LastAddrRC> 276 : NSAHelper<> { 277 278 list<RegisterClass> addr_types = 279 !if(!ge(num_addrs, max_addr), 280 !listconcat(!listsplat(VGPR_32, !sub(max_addr, 1)), [LastAddrRC]), 281 !listsplat(VGPR_32, num_addrs)); 282 283 int VAddrCount = !if(!gt(num_addrs, max_addr), max_addr, num_addrs); 284 list<string> AddrAsmNames = !foreach(i, !range(VAddrCount), "vaddr" # i); 285 286 let AddrIns = !dag(ins, addr_types, AddrAsmNames); 287 let AddrAsm = "[$" # !interleave(AddrAsmNames, ", $") # "]"; 288 let NSA = 1; 289} 290 291// Base class of all pre-gfx10 MIMG instructions. 292class MIMG_gfx6789<bits<8> op, dag outs, string dns = ""> 293 : MIMG<outs, dns>, MIMGe_gfx6789<op> { 294 let SubtargetPredicate = isGFX6GFX7GFX8GFX9NotGFX90A; 295 let AssemblerPredicate = isGFX6GFX7GFX8GFX9NotGFX90A; 296 297 let MIMGEncoding = MIMGEncGfx6; 298 let VAddrOperands = 1; 299 300 let d16 = !if(BaseOpcode.HasD16, ?, 0); 301} 302 303class MIMG_gfx90a<bits<8> op, dag outs, string dns = ""> 304 : MIMG<outs, dns>, MIMGe_gfx90a<op> { 305 let SubtargetPredicate = isGFX90APlus; 306 let AssemblerPredicate = isGFX90APlus; 307 308 let MIMGEncoding = MIMGEncGfx90a; 309 let VAddrOperands = 1; 310 311 let d16 = !if(BaseOpcode.HasD16, ?, 0); 312} 313 314// Base class of all non-NSA gfx10 MIMG instructions. 315class MIMG_gfx10<int op, dag outs, string dns = ""> 316 : MIMG<outs, dns>, MIMGe_gfx10<op> { 317 let SubtargetPredicate = isGFX10Only; 318 let AssemblerPredicate = isGFX10Only; 319 320 let MIMGEncoding = MIMGEncGfx10Default; 321 let VAddrOperands = 1; 322 323 let d16 = !if(BaseOpcode.HasD16, ?, 0); 324 let nsa = 0; 325} 326 327// Base class for all NSA MIMG instructions. 328// Note that 1-dword addresses always use non-NSA variants. 329class MIMG_nsa_gfx10<int op, dag outs, int num_addrs, string dns=""> 330 : MIMG<outs, dns>, MIMGe_gfx10<op> { 331 let SubtargetPredicate = isGFX10Only; 332 let AssemblerPredicate = isGFX10Only; 333 334 let MIMGEncoding = MIMGEncGfx10NSA; 335 let VAddrOperands = num_addrs; 336 337 MIMGNSAHelper nsah = MIMGNSAHelper<num_addrs>; 338 dag AddrIns = nsah.AddrIns; 339 string AddrAsm = nsah.AddrAsm; 340 341 let d16 = !if(BaseOpcode.HasD16, ?, 0); 342 let nsa = nsah.NSA; 343} 344 345// Base class of all non-NSA gfx11 MIMG instructions. 346class MIMG_gfx11<int op, dag outs, string dns = ""> 347 : MIMG<outs, dns>, MIMGe_gfx11<op> { 348 let SubtargetPredicate = isGFX11Only; 349 let AssemblerPredicate = isGFX11Only; 350 351 let MIMGEncoding = MIMGEncGfx11Default; 352 let VAddrOperands = 1; 353 354 let d16 = !if(BaseOpcode.HasD16, ?, 0); 355 let nsa = 0; 356} 357 358// Base class for all NSA MIMG instructions. 359// Note that 1-dword addresses always use non-NSA variants. 360class MIMG_nsa_gfx11<int op, dag outs, int num_addrs, string dns="", 361 list<RegisterClass> addr_types=[], 362 RegisterClass LastAddrRC = VGPR_32> 363 : MIMG<outs, dns>, MIMGe_gfx11<op> { 364 let SubtargetPredicate = isGFX11Only; 365 let AssemblerPredicate = isGFX11Only; 366 367 let MIMGEncoding = MIMGEncGfx11NSA; 368 let VAddrOperands = num_addrs; 369 370 NSAHelper nsah = !if(!empty(addr_types), 371 PartialNSAHelper<num_addrs, 5, LastAddrRC>, 372 MIMGNSAHelper<num_addrs, addr_types>); 373 dag AddrIns = nsah.AddrIns; 374 string AddrAsm = nsah.AddrAsm; 375 376 let d16 = !if(BaseOpcode.HasD16, ?, 0); 377 let nsa = nsah.NSA; 378} 379 380class VIMAGE_gfx12<int op, dag outs, int num_addrs, string dns="", 381 list<RegisterClass> addr_types=[]> 382 : VIMAGE<outs, dns>, VIMAGEe<op> { 383 let SubtargetPredicate = isGFX12Plus; 384 let AssemblerPredicate = isGFX12Plus; 385 386 let MIMGEncoding = MIMGEncGfx12; 387 let VAddrOperands = num_addrs; 388 389 MIMGNSAHelper nsah = !if(!empty(addr_types), 390 MIMGNSAHelper<num_addrs>, 391 MIMGNSAHelper<num_addrs, addr_types>); 392 dag AddrIns = nsah.AddrIns; 393 string AddrAsm = !if(!eq(num_addrs, 1), "$vaddr0", nsah.AddrAsm); 394 395 let d16 = !if(BaseOpcode.HasD16, ?, 0); 396 let vaddr1 = !if(!lt(num_addrs, 2), 0, ?); 397 let vaddr2 = !if(!lt(num_addrs, 3), 0, ?); 398 let vaddr3 = !if(!lt(num_addrs, 4), 0, ?); 399 let vaddr4 = !if(!lt(num_addrs, 5), 0, ?); 400} 401 402class VSAMPLE_gfx12<int op, dag outs, int num_addrs, string dns="", 403 RegisterClass Addr3RC> 404 : VSAMPLE<outs, dns>, VSAMPLEe<op> { 405 let SubtargetPredicate = isGFX12Plus; 406 let AssemblerPredicate = isGFX12Plus; 407 408 let MIMGEncoding = MIMGEncGfx12; 409 let VAddrOperands = num_addrs; 410 411 PartialNSAHelper nsah = PartialNSAHelper<num_addrs, 4, Addr3RC>; 412 413 dag AddrIns = nsah.AddrIns; 414 string AddrAsm = !if(!eq(num_addrs, 1), "$vaddr0", nsah.AddrAsm); 415 416 let d16 = !if(BaseOpcode.HasD16, ?, 0); 417 let vaddr1 = !if(!lt(num_addrs, 2), 0, ?); 418 let vaddr2 = !if(!lt(num_addrs, 3), 0, ?); 419 let vaddr3 = !if(!lt(num_addrs, 4), 0, ?); 420} 421 422class MIMG_NoSampler_Helper <mimgopc op, string asm, 423 RegisterClass dst_rc, 424 RegisterClass addr_rc, 425 string dns=""> 426 : MIMG_gfx6789 <op.GFX10M, (outs dst_rc:$vdata), dns> { 427 let InOperandList = !con((ins addr_rc:$vaddr, SReg_256_XNULL:$srsrc, 428 DMask:$dmask, UNorm:$unorm, CPol:$cpol, 429 R128A16:$r128, TFE:$tfe, LWE:$lwe, DA:$da), 430 !if(BaseOpcode.HasD16, (ins D16:$d16), (ins))); 431 let AsmString = asm#" $vdata, $vaddr, $srsrc$dmask$unorm$cpol$r128$tfe$lwe$da" 432 #!if(BaseOpcode.HasD16, "$d16", ""); 433} 434 435class MIMG_NoSampler_Helper_gfx90a <mimgopc op, string asm, 436 RegisterClass dst_rc, 437 RegisterClass addr_rc, 438 string dns=""> 439 : MIMG_gfx90a <op.GFX10M, (outs getLdStRegisterOperand<dst_rc>.ret:$vdata), dns> { 440 let InOperandList = !con((ins addr_rc:$vaddr, SReg_256_XNULL:$srsrc, 441 DMask:$dmask, UNorm:$unorm, CPol:$cpol, 442 R128A16:$r128, LWE:$lwe, DA:$da), 443 !if(BaseOpcode.HasD16, (ins D16:$d16), (ins))); 444 let AsmString = asm#" $vdata, $vaddr, $srsrc$dmask$unorm$cpol$r128$lwe$da" 445 #!if(BaseOpcode.HasD16, "$d16", ""); 446} 447 448class MIMG_NoSampler_gfx10<mimgopc op, string opcode, 449 RegisterClass DataRC, RegisterClass AddrRC, 450 string dns=""> 451 : MIMG_gfx10<op.GFX10M, (outs DataRC:$vdata), dns> { 452 let InOperandList = !con((ins AddrRC:$vaddr0, SReg_256_XNULL:$srsrc, DMask:$dmask, 453 Dim:$dim, UNorm:$unorm, CPol:$cpol, 454 R128A16:$r128, A16:$a16, TFE:$tfe, LWE:$lwe), 455 !if(BaseOpcode.HasD16, (ins D16:$d16), (ins))); 456 let AsmString = opcode#" $vdata, $vaddr0, $srsrc$dmask$dim$unorm$cpol$r128$a16$tfe$lwe" 457 #!if(BaseOpcode.HasD16, "$d16", ""); 458} 459 460class MIMG_NoSampler_nsa_gfx10<mimgopc op, string opcode, 461 RegisterClass DataRC, int num_addrs, 462 string dns=""> 463 : MIMG_nsa_gfx10<op.GFX10M, (outs DataRC:$vdata), num_addrs, dns> { 464 let InOperandList = !con(AddrIns, 465 (ins SReg_256_XNULL:$srsrc, DMask:$dmask, 466 Dim:$dim, UNorm:$unorm, CPol:$cpol, 467 R128A16:$r128, A16:$a16, TFE:$tfe, LWE:$lwe), 468 !if(BaseOpcode.HasD16, (ins D16:$d16), (ins))); 469 let AsmString = opcode#" $vdata, "#AddrAsm#", $srsrc$dmask$dim$unorm$cpol$r128$a16$tfe$lwe" 470 #!if(BaseOpcode.HasD16, "$d16", ""); 471} 472 473class MIMG_NoSampler_gfx11<mimgopc op, string opcode, 474 RegisterClass DataRC, RegisterClass AddrRC, 475 string dns=""> 476 : MIMG_gfx11<op.GFX11, (outs DataRC:$vdata), dns> { 477 let InOperandList = !con((ins AddrRC:$vaddr0, SReg_256_XNULL:$srsrc, DMask:$dmask, 478 Dim:$dim, UNorm:$unorm, CPol:$cpol, 479 R128A16:$r128, A16:$a16, TFE:$tfe, LWE:$lwe), 480 !if(BaseOpcode.HasD16, (ins D16:$d16), (ins))); 481 let AsmString = opcode#" $vdata, $vaddr0, $srsrc$dmask$dim$unorm$cpol$r128$a16$tfe$lwe" 482 #!if(BaseOpcode.HasD16, "$d16", ""); 483} 484 485class MIMG_NoSampler_nsa_gfx11<mimgopc op, string opcode, 486 RegisterClass DataRC, int num_addrs, 487 string dns=""> 488 : MIMG_nsa_gfx11<op.GFX11, (outs DataRC:$vdata), num_addrs, dns> { 489 let InOperandList = !con(AddrIns, 490 (ins SReg_256_XNULL:$srsrc, DMask:$dmask, 491 Dim:$dim, UNorm:$unorm, CPol:$cpol, 492 R128A16:$r128, A16:$a16, TFE:$tfe, LWE:$lwe), 493 !if(BaseOpcode.HasD16, (ins D16:$d16), (ins))); 494 let AsmString = opcode#" $vdata, "#AddrAsm#", $srsrc$dmask$dim$unorm$cpol$r128$a16$tfe$lwe" 495 #!if(BaseOpcode.HasD16, "$d16", ""); 496} 497 498class VIMAGE_NoSampler_gfx12<mimgopc op, string opcode, 499 RegisterClass DataRC, int num_addrs, 500 string dns=""> 501 : VIMAGE_gfx12<op.GFX12, (outs DataRC:$vdata), num_addrs, dns> { 502 let InOperandList = !con(AddrIns, 503 (ins SReg_256_XNULL:$rsrc, DMask:$dmask, Dim:$dim, 504 CPol:$cpol, R128A16:$r128, A16:$a16, TFE:$tfe), 505 !if(BaseOpcode.HasD16, (ins D16:$d16), (ins))); 506 let AsmString = opcode#" $vdata, "#AddrAsm#", $rsrc$dmask$dim$cpol$r128$a16$tfe" 507 #!if(BaseOpcode.HasD16, "$d16", ""); 508} 509 510class VSAMPLE_Sampler_gfx12<mimgopc op, string opcode, RegisterClass DataRC, 511 int num_addrs, RegisterClass Addr3RC = VGPR_32, 512 string dns=""> 513 : VSAMPLE_gfx12<op.GFX12, (outs DataRC:$vdata), num_addrs, dns, Addr3RC> { 514 let InOperandList = !con(AddrIns, 515 (ins SReg_256_XNULL:$rsrc), 516 !if(BaseOpcode.Sampler, (ins SReg_128_XNULL:$samp), (ins)), 517 (ins DMask:$dmask, Dim:$dim, UNorm:$unorm, 518 CPol:$cpol, R128A16:$r128, A16:$a16, TFE:$tfe, 519 LWE:$lwe), 520 !if(BaseOpcode.HasD16, (ins D16:$d16), (ins))); 521 let AsmString = opcode#" $vdata, "#AddrAsm#", $rsrc" 522 #!if(BaseOpcode.Sampler, ", $samp", "") 523 #"$dmask$dim$unorm$cpol$r128$a16$tfe$lwe" 524 #!if(BaseOpcode.HasD16, "$d16", ""); 525} 526 527class VSAMPLE_Sampler_nortn_gfx12<mimgopc op, string opcode, 528 int num_addrs, RegisterClass Addr3RC = VGPR_32, 529 string dns=""> 530 : VSAMPLE_gfx12<op.GFX12, (outs), num_addrs, dns, Addr3RC> { 531 let InOperandList = !con(AddrIns, 532 (ins SReg_256_XNULL:$rsrc), 533 !if(BaseOpcode.Sampler, (ins SReg_128_XNULL:$samp), (ins)), 534 (ins DMask:$dmask, Dim:$dim, UNorm:$unorm, 535 CPol:$cpol, R128A16:$r128, A16:$a16, TFE:$tfe, 536 LWE:$lwe), 537 !if(BaseOpcode.HasD16, (ins D16:$d16), (ins))); 538 let AsmString = opcode#" off, "#AddrAsm#", $rsrc" 539 #!if(BaseOpcode.Sampler, ", $samp", "") 540 #"$dmask$dim$unorm$cpol$r128$a16$tfe$lwe" 541 #!if(BaseOpcode.HasD16, "$d16", ""); 542 // Force vdata to VGPR0 as no result will be returned. 543 let vdata = 0; 544} 545 546multiclass MIMG_NoSampler_Src_Helper <mimgopc op, string asm, 547 RegisterClass dst_rc, bit enableDisasm, 548 bit ExtendedImageInst = 1, 549 bit isVSample = 0> { 550 let VAddrDwords = 1 in { 551 let ssamp = 0 in { 552 if op.HAS_GFX10M then { 553 def _V1 : MIMG_NoSampler_Helper <op, asm, dst_rc, VGPR_32, 554 !if(enableDisasm, "GFX8", "")>; 555 if !not(ExtendedImageInst) then 556 def _V1_gfx90a : MIMG_NoSampler_Helper_gfx90a <op, asm, dst_rc, VGPR_32, 557 !if(enableDisasm, "GFX90A", "")>; 558 def _V1_gfx10 : MIMG_NoSampler_gfx10<op, asm, dst_rc, VGPR_32, 559 !if(enableDisasm, "GFX10", "")>; 560 } 561 if op.HAS_GFX11 then { 562 def _V1_gfx11 : MIMG_NoSampler_gfx11<op, asm, dst_rc, VGPR_32, 563 !if(enableDisasm, "GFX11", "")>; 564 } 565 } 566 if op.HAS_GFX12 then { 567 if isVSample then { 568 let samp = 0 in 569 def _V1_gfx12 : VSAMPLE_Sampler_gfx12<op, asm, dst_rc, 1>; 570 } 571 else { 572 def _V1_gfx12 : VIMAGE_NoSampler_gfx12<op, asm, dst_rc, 1>; 573 } 574 } 575 } 576 let VAddrDwords = 2 in { 577 let ssamp = 0 in { 578 if op.HAS_GFX10M then { 579 def _V2 : MIMG_NoSampler_Helper <op, asm, dst_rc, VReg_64>; 580 if !not(ExtendedImageInst) then 581 def _V2_gfx90a : MIMG_NoSampler_Helper_gfx90a <op, asm, dst_rc, VReg_64>; 582 def _V2_gfx10 : MIMG_NoSampler_gfx10<op, asm, dst_rc, VReg_64>; 583 def _V2_nsa_gfx10 : MIMG_NoSampler_nsa_gfx10<op, asm, dst_rc, 2>; 584 } 585 if op.HAS_GFX11 then { 586 def _V2_gfx11 : MIMG_NoSampler_gfx11<op, asm, dst_rc, VReg_64>; 587 def _V2_nsa_gfx11 : MIMG_NoSampler_nsa_gfx11<op, asm, dst_rc, 2>; 588 } 589 } 590 if op.HAS_GFX12 then { 591 if isVSample then { 592 let samp = 0 in 593 def _V2_gfx12 : VSAMPLE_Sampler_gfx12<op, asm, dst_rc, 2>; 594 } 595 else { 596 def _V2_gfx12 : VIMAGE_NoSampler_gfx12<op, asm, dst_rc, 2>; 597 } 598 } 599 } 600 let VAddrDwords = 3 in { 601 let ssamp = 0 in { 602 if op.HAS_GFX10M then { 603 def _V3 : MIMG_NoSampler_Helper <op, asm, dst_rc, VReg_96>; 604 if !not(ExtendedImageInst) then 605 def _V3_gfx90a : MIMG_NoSampler_Helper_gfx90a <op, asm, dst_rc, VReg_96>; 606 def _V3_gfx10 : MIMG_NoSampler_gfx10<op, asm, dst_rc, VReg_96>; 607 def _V3_nsa_gfx10 : MIMG_NoSampler_nsa_gfx10<op, asm, dst_rc, 3>; 608 } 609 if op.HAS_GFX11 then { 610 def _V3_gfx11 : MIMG_NoSampler_gfx11<op, asm, dst_rc, VReg_96>; 611 def _V3_nsa_gfx11 : MIMG_NoSampler_nsa_gfx11<op, asm, dst_rc, 3>; 612 } 613 } 614 if op.HAS_GFX12 then { 615 if isVSample then { 616 let samp = 0 in 617 def _V3_gfx12 : VSAMPLE_Sampler_gfx12<op, asm, dst_rc, 3>; 618 } 619 else { 620 def _V3_gfx12 : VIMAGE_NoSampler_gfx12<op, asm, dst_rc, 3>; 621 } 622 } 623 } 624 let VAddrDwords = 4 in { 625 let ssamp = 0 in { 626 if op.HAS_GFX10M then { 627 def _V4 : MIMG_NoSampler_Helper <op, asm, dst_rc, VReg_128>; 628 if !not(ExtendedImageInst) then 629 def _V4_gfx90a : MIMG_NoSampler_Helper_gfx90a <op, asm, dst_rc, VReg_128>; 630 def _V4_gfx10 : MIMG_NoSampler_gfx10<op, asm, dst_rc, VReg_128>; 631 def _V4_nsa_gfx10 : MIMG_NoSampler_nsa_gfx10<op, asm, dst_rc, 4, 632 !if(enableDisasm, "GFX10", "")>; 633 } 634 if op.HAS_GFX11 then { 635 def _V4_gfx11 : MIMG_NoSampler_gfx11<op, asm, dst_rc, VReg_128>; 636 def _V4_nsa_gfx11 : MIMG_NoSampler_nsa_gfx11<op, asm, dst_rc, 4, 637 !if(enableDisasm, "GFX11", "")>; 638 } 639 } 640 if op.HAS_GFX12 then { 641 if isVSample then { 642 let samp = 0 in 643 def _V4_gfx12 : VSAMPLE_Sampler_gfx12<op, asm, dst_rc, 4, VGPR_32, 644 !if(enableDisasm, "GFX12", "")>; 645 } 646 else { 647 def _V4_gfx12 : VIMAGE_NoSampler_gfx12<op, asm, dst_rc, 4, 648 !if(enableDisasm, "GFX12", "")>; 649 } 650 } 651 } 652} 653 654multiclass MIMG_NoSampler <mimgopc op, string asm, bit has_d16, bit mip = 0, 655 bit isResInfo = 0, 656 bit msaa = 0> { 657 def "" : MIMGBaseOpcode { 658 let Coordinates = !not(isResInfo); 659 let LodOrClampOrMip = mip; 660 let HasD16 = has_d16; 661 let MSAA = msaa; 662 } 663 664 let BaseOpcode = !cast<MIMGBaseOpcode>(NAME), 665 mayLoad = !not(isResInfo) in { 666 let VDataDwords = 1 in 667 defm _V1 : MIMG_NoSampler_Src_Helper <op, asm, VGPR_32, 1, msaa>; 668 let VDataDwords = 2 in 669 defm _V2 : MIMG_NoSampler_Src_Helper <op, asm, VReg_64, 0, msaa>; 670 let VDataDwords = 3 in 671 defm _V3 : MIMG_NoSampler_Src_Helper <op, asm, VReg_96, 0, msaa>; 672 let VDataDwords = 4 in 673 defm _V4 : MIMG_NoSampler_Src_Helper <op, asm, VReg_128, 0, msaa>; 674 let VDataDwords = 5 in 675 defm _V5 : MIMG_NoSampler_Src_Helper <op, asm, VReg_160, 0, msaa>; 676 } 677} 678 679class MIMG_Store_Helper <mimgopc op, string asm, 680 RegisterClass data_rc, 681 RegisterClass addr_rc, 682 string dns = ""> 683 : MIMG_gfx6789<op.GFX10M, (outs), dns> { 684 let InOperandList = !con((ins data_rc:$vdata, addr_rc:$vaddr, SReg_256_XNULL:$srsrc, 685 DMask:$dmask, UNorm:$unorm, CPol:$cpol, 686 R128A16:$r128, TFE:$tfe, LWE:$lwe, DA:$da), 687 !if(BaseOpcode.HasD16, (ins D16:$d16), (ins))); 688 let AsmString = asm#" $vdata, $vaddr, $srsrc$dmask$unorm$cpol$r128$tfe$lwe$da" 689 #!if(BaseOpcode.HasD16, "$d16", ""); 690} 691 692class MIMG_Store_Helper_gfx90a <mimgopc op, string asm, 693 RegisterClass data_rc, 694 RegisterClass addr_rc, 695 string dns = ""> 696 : MIMG_gfx90a<op.GFX10M, (outs), dns> { 697 let InOperandList = !con((ins getLdStRegisterOperand<data_rc>.ret:$vdata, 698 addr_rc:$vaddr, SReg_256_XNULL:$srsrc, 699 DMask:$dmask, UNorm:$unorm, CPol:$cpol, 700 R128A16:$r128, LWE:$lwe, DA:$da), 701 !if(BaseOpcode.HasD16, (ins D16:$d16), (ins))); 702 let AsmString = asm#" $vdata, $vaddr, $srsrc$dmask$unorm$cpol$r128$lwe$da" 703 #!if(BaseOpcode.HasD16, "$d16", ""); 704} 705 706class MIMG_Store_gfx10<mimgopc op, string opcode, 707 RegisterClass DataRC, RegisterClass AddrRC, 708 string dns=""> 709 : MIMG_gfx10<op.GFX10M, (outs), dns> { 710 let InOperandList = !con((ins DataRC:$vdata, AddrRC:$vaddr0, SReg_256_XNULL:$srsrc, 711 DMask:$dmask, Dim:$dim, UNorm:$unorm, CPol:$cpol, 712 R128A16:$r128, A16:$a16, TFE:$tfe, LWE:$lwe), 713 !if(BaseOpcode.HasD16, (ins D16:$d16), (ins))); 714 let AsmString = opcode#" $vdata, $vaddr0, $srsrc$dmask$dim$unorm$cpol$r128$a16$tfe$lwe" 715 #!if(BaseOpcode.HasD16, "$d16", ""); 716} 717 718class MIMG_Store_nsa_gfx10<mimgopc op, string opcode, 719 RegisterClass DataRC, int num_addrs, 720 string dns=""> 721 : MIMG_nsa_gfx10<op.GFX10M, (outs), num_addrs, dns> { 722 let InOperandList = !con((ins DataRC:$vdata), 723 AddrIns, 724 (ins SReg_256_XNULL:$srsrc, DMask:$dmask, 725 Dim:$dim, UNorm:$unorm, CPol:$cpol, 726 R128A16:$r128, A16:$a16, TFE:$tfe, LWE:$lwe), 727 !if(BaseOpcode.HasD16, (ins D16:$d16), (ins))); 728 let AsmString = opcode#" $vdata, "#AddrAsm#", $srsrc$dmask$dim$unorm$cpol$r128$a16$tfe$lwe" 729 #!if(BaseOpcode.HasD16, "$d16", ""); 730} 731 732class MIMG_Store_gfx11<mimgopc op, string opcode, 733 RegisterClass DataRC, RegisterClass AddrRC, 734 string dns=""> 735 : MIMG_gfx11<op.GFX11, (outs), dns> { 736 let InOperandList = !con((ins DataRC:$vdata, AddrRC:$vaddr0, SReg_256_XNULL:$srsrc, 737 DMask:$dmask, Dim:$dim, UNorm:$unorm, CPol:$cpol, 738 R128A16:$r128, A16:$a16, TFE:$tfe, LWE:$lwe), 739 !if(BaseOpcode.HasD16, (ins D16:$d16), (ins))); 740 let AsmString = opcode#" $vdata, $vaddr0, $srsrc$dmask$dim$unorm$cpol$r128$a16$tfe$lwe" 741 #!if(BaseOpcode.HasD16, "$d16", ""); 742} 743 744class MIMG_Store_nsa_gfx11<mimgopc op, string opcode, 745 RegisterClass DataRC, int num_addrs, 746 string dns=""> 747 : MIMG_nsa_gfx11<op.GFX11, (outs), num_addrs, dns> { 748 let InOperandList = !con((ins DataRC:$vdata), 749 AddrIns, 750 (ins SReg_256_XNULL:$srsrc, DMask:$dmask, 751 Dim:$dim, UNorm:$unorm, CPol:$cpol, 752 R128A16:$r128, A16:$a16, TFE:$tfe, LWE:$lwe), 753 !if(BaseOpcode.HasD16, (ins D16:$d16), (ins))); 754 let AsmString = opcode#" $vdata, "#AddrAsm#", $srsrc$dmask$dim$unorm$cpol$r128$a16$tfe$lwe" 755 #!if(BaseOpcode.HasD16, "$d16", ""); 756} 757 758class VIMAGE_Store_gfx12<mimgopc op, string opcode, 759 RegisterClass DataRC, int num_addrs, 760 string dns=""> 761 : VIMAGE_gfx12<op.GFX12, (outs), num_addrs, dns> { 762 let InOperandList = !con((ins DataRC:$vdata), 763 AddrIns, 764 (ins SReg_256_XNULL:$rsrc, DMask:$dmask, Dim:$dim, 765 CPol:$cpol, R128A16:$r128, A16:$a16, TFE:$tfe), 766 !if(BaseOpcode.HasD16, (ins D16:$d16), (ins))); 767 let AsmString = opcode#" $vdata, "#AddrAsm#", $rsrc$dmask$dim$cpol$r128$a16$tfe" 768 #!if(BaseOpcode.HasD16, "$d16", ""); 769} 770 771multiclass MIMG_Store_Addr_Helper <mimgopc op, string asm, 772 RegisterClass data_rc, 773 bit enableDisasm> { 774 let mayLoad = 0, mayStore = 1, hasSideEffects = 0, hasPostISelHook = 0, 775 DisableWQM = 1 in { 776 let VAddrDwords = 1 in { 777 let ssamp = 0 in { 778 if op.HAS_GFX10M then { 779 def _V1 : MIMG_Store_Helper <op, asm, data_rc, VGPR_32, 780 !if(enableDisasm, "GFX8", "")>; 781 let hasPostISelHook = 1 in 782 def _V1_gfx90a : MIMG_Store_Helper_gfx90a <op, asm, data_rc, VGPR_32, 783 !if(enableDisasm, "GFX90A", "")>; 784 def _V1_gfx10 : MIMG_Store_gfx10 <op, asm, data_rc, VGPR_32, 785 !if(enableDisasm, "GFX10", "")>; 786 } 787 if op.HAS_GFX11 then { 788 def _V1_gfx11 : MIMG_Store_gfx11 <op, asm, data_rc, VGPR_32, 789 !if(enableDisasm, "GFX11", "")>; 790 } 791 } 792 if op.HAS_GFX12 then { 793 def _V1_gfx12 : VIMAGE_Store_gfx12 <op, asm, data_rc, 1>; 794 } 795 } 796 let VAddrDwords = 2 in { 797 let ssamp = 0 in { 798 if op.HAS_GFX10M then { 799 def _V2 : MIMG_Store_Helper <op, asm, data_rc, VReg_64>; 800 def _V2_gfx90a : MIMG_Store_Helper_gfx90a <op, asm, data_rc, VReg_64>; 801 def _V2_gfx10 : MIMG_Store_gfx10 <op, asm, data_rc, VReg_64>; 802 def _V2_nsa_gfx10 : MIMG_Store_nsa_gfx10 <op, asm, data_rc, 2>; 803 } 804 if op.HAS_GFX11 then { 805 def _V2_gfx11 : MIMG_Store_gfx11 <op, asm, data_rc, VReg_64>; 806 def _V2_nsa_gfx11 : MIMG_Store_nsa_gfx11 <op, asm, data_rc, 2>; 807 } 808 } 809 if op.HAS_GFX12 then { 810 def _V2_gfx12 : VIMAGE_Store_gfx12 <op, asm, data_rc, 2>; 811 } 812 } 813 let VAddrDwords = 3 in { 814 let ssamp = 0 in { 815 if op.HAS_GFX10M then { 816 def _V3 : MIMG_Store_Helper <op, asm, data_rc, VReg_96>; 817 def _V3_gfx90a : MIMG_Store_Helper_gfx90a <op, asm, data_rc, VReg_96>; 818 def _V3_gfx10 : MIMG_Store_gfx10 <op, asm, data_rc, VReg_96>; 819 def _V3_nsa_gfx10 : MIMG_Store_nsa_gfx10 <op, asm, data_rc, 3>; 820 } 821 if op.HAS_GFX11 then { 822 def _V3_gfx11 : MIMG_Store_gfx11 <op, asm, data_rc, VReg_96>; 823 def _V3_nsa_gfx11 : MIMG_Store_nsa_gfx11 <op, asm, data_rc, 3>; 824 } 825 } 826 if op.HAS_GFX12 then { 827 def _V3_gfx12 : VIMAGE_Store_gfx12 <op, asm, data_rc, 3>; 828 } 829 } 830 let VAddrDwords = 4 in { 831 let ssamp = 0 in { 832 if op.HAS_GFX10M then { 833 def _V4 : MIMG_Store_Helper <op, asm, data_rc, VReg_128>; 834 def _V4_gfx90a : MIMG_Store_Helper_gfx90a <op, asm, data_rc, VReg_128>; 835 def _V4_gfx10 : MIMG_Store_gfx10 <op, asm, data_rc, VReg_128>; 836 def _V4_nsa_gfx10 : MIMG_Store_nsa_gfx10 <op, asm, data_rc, 4, 837 !if(enableDisasm, "GFX10", "")>; 838 } 839 if op.HAS_GFX11 then { 840 def _V4_gfx11 : MIMG_Store_gfx11 <op, asm, data_rc, VReg_128>; 841 def _V4_nsa_gfx11 : MIMG_Store_nsa_gfx11 <op, asm, data_rc, 4, 842 !if(enableDisasm, "GFX11", "")>; 843 } 844 } 845 if op.HAS_GFX12 then { 846 def _V4_gfx12 : VIMAGE_Store_gfx12 <op, asm, data_rc, 4, 847 !if(enableDisasm, "GFX12", "")>; 848 } 849 } 850 } 851} 852 853multiclass MIMG_Store <mimgopc op, string asm, bit has_d16, bit mip = 0> { 854 def "" : MIMGBaseOpcode { 855 let Store = 1; 856 let LodOrClampOrMip = mip; 857 let HasD16 = has_d16; 858 let NoReturn = 1; 859 } 860 861 let BaseOpcode = !cast<MIMGBaseOpcode>(NAME) in { 862 let VDataDwords = 1 in 863 defm _V1 : MIMG_Store_Addr_Helper <op, asm, VGPR_32, 1>; 864 let VDataDwords = 2 in 865 defm _V2 : MIMG_Store_Addr_Helper <op, asm, VReg_64, 0>; 866 let VDataDwords = 3 in 867 defm _V3 : MIMG_Store_Addr_Helper <op, asm, VReg_96, 0>; 868 let VDataDwords = 4 in 869 defm _V4 : MIMG_Store_Addr_Helper <op, asm, VReg_128, 0>; 870 let VDataDwords = 5 in 871 defm _V5 : MIMG_Store_Addr_Helper <op, asm, VReg_160, 0>; 872 } 873} 874 875class MIMG_Atomic_gfx6789_base <bits<8> op, string asm, RegisterClass data_rc, 876 RegisterClass addr_rc, string dns=""> 877 : MIMG_gfx6789 <op, (outs data_rc:$vdst), dns> { 878 let Constraints = "$vdst = $vdata"; 879 880 let InOperandList = (ins data_rc:$vdata, addr_rc:$vaddr, SReg_256_XNULL:$srsrc, 881 DMask:$dmask, UNorm:$unorm, CPol:$cpol, 882 R128A16:$r128, TFE:$tfe, LWE:$lwe, DA:$da); 883 let AsmString = asm#" $vdst, $vaddr, $srsrc$dmask$unorm$cpol$r128$tfe$lwe$da"; 884} 885 886class MIMG_Atomic_gfx90a_base <bits<8> op, string asm, RegisterClass data_rc, 887 RegisterClass addr_rc, string dns=""> 888 : MIMG_gfx90a <op, (outs getLdStRegisterOperand<data_rc>.ret:$vdst), dns> { 889 let Constraints = "$vdst = $vdata"; 890 891 let InOperandList = (ins getLdStRegisterOperand<data_rc>.ret:$vdata, 892 addr_rc:$vaddr, SReg_256_XNULL:$srsrc, 893 DMask:$dmask, UNorm:$unorm, CPol:$cpol, 894 R128A16:$r128, LWE:$lwe, DA:$da); 895 let AsmString = asm#" $vdst, $vaddr, $srsrc$dmask$unorm$cpol$r128$lwe$da"; 896} 897 898class MIMG_Atomic_si<mimgopc op, string asm, RegisterClass data_rc, 899 RegisterClass addr_rc, bit enableDasm = 0> 900 : MIMG_Atomic_gfx6789_base<op.SI, asm, data_rc, addr_rc, 901 !if(enableDasm, "GFX6GFX7", "")> { 902 let AssemblerPredicate = isGFX6GFX7; 903} 904 905class MIMG_Atomic_vi<mimgopc op, string asm, RegisterClass data_rc, 906 RegisterClass addr_rc, bit enableDasm = 0> 907 : MIMG_Atomic_gfx6789_base<op.VI, asm, data_rc, addr_rc, !if(enableDasm, "GFX8", "")> { 908 let AssemblerPredicate = isGFX8GFX9NotGFX90A; 909 let MIMGEncoding = MIMGEncGfx8; 910} 911 912class MIMG_Atomic_gfx90a<mimgopc op, string asm, RegisterClass data_rc, 913 RegisterClass addr_rc, bit enableDasm = 0> 914 : MIMG_Atomic_gfx90a_base<op.VI, asm, data_rc, addr_rc, !if(enableDasm, "GFX90A", "")> { 915 let AssemblerPredicate = isGFX90APlus; 916 let MIMGEncoding = MIMGEncGfx90a; 917} 918 919class MIMG_Atomic_gfx10<mimgopc op, string opcode, 920 RegisterClass DataRC, RegisterClass AddrRC, 921 bit enableDisasm = 0> 922 : MIMG_gfx10<op.GFX10M, (outs DataRC:$vdst), 923 !if(enableDisasm, "GFX10", "")> { 924 let Constraints = "$vdst = $vdata"; 925 926 let InOperandList = (ins DataRC:$vdata, AddrRC:$vaddr0, SReg_256_XNULL:$srsrc, 927 DMask:$dmask, Dim:$dim, UNorm:$unorm, CPol:$cpol, 928 R128A16:$r128, A16:$a16, TFE:$tfe, LWE:$lwe); 929 let AsmString = opcode#" $vdst, $vaddr0, $srsrc$dmask$dim$unorm$cpol$r128$a16$tfe$lwe"; 930} 931 932class MIMG_Atomic_nsa_gfx10<mimgopc op, string opcode, 933 RegisterClass DataRC, int num_addrs, 934 bit enableDisasm = 0> 935 : MIMG_nsa_gfx10<op.GFX10M, (outs DataRC:$vdst), num_addrs, 936 !if(enableDisasm, "GFX10", "")> { 937 let Constraints = "$vdst = $vdata"; 938 939 let InOperandList = !con((ins DataRC:$vdata), 940 AddrIns, 941 (ins SReg_256_XNULL:$srsrc, DMask:$dmask, 942 Dim:$dim, UNorm:$unorm, CPol:$cpol, 943 R128A16:$r128, A16:$a16, TFE:$tfe, LWE:$lwe)); 944 let AsmString = opcode#" $vdata, "#AddrAsm#", $srsrc$dmask$dim$unorm$cpol$r128$a16$tfe$lwe"; 945} 946 947class MIMG_Atomic_gfx11<mimgopc op, string opcode, 948 RegisterClass DataRC, RegisterClass AddrRC, 949 bit enableDisasm = 0> 950 : MIMG_gfx11<op.GFX11, (outs DataRC:$vdst), 951 !if(enableDisasm, "GFX11", "")> { 952 let Constraints = "$vdst = $vdata"; 953 954 let InOperandList = (ins DataRC:$vdata, AddrRC:$vaddr0, SReg_256_XNULL:$srsrc, 955 DMask:$dmask, Dim:$dim, UNorm:$unorm, CPol:$cpol, 956 R128A16:$r128, A16:$a16, TFE:$tfe, LWE:$lwe); 957 let AsmString = opcode#" $vdst, $vaddr0, $srsrc$dmask$dim$unorm$cpol$r128$a16$tfe$lwe"; 958} 959 960class MIMG_Atomic_nsa_gfx11<mimgopc op, string opcode, 961 RegisterClass DataRC, int num_addrs, 962 bit enableDisasm = 0> 963 : MIMG_nsa_gfx11<op.GFX11, (outs DataRC:$vdst), num_addrs, 964 !if(enableDisasm, "GFX11", "")> { 965 let Constraints = "$vdst = $vdata"; 966 967 let InOperandList = !con((ins DataRC:$vdata), 968 AddrIns, 969 (ins SReg_256_XNULL:$srsrc, DMask:$dmask, 970 Dim:$dim, UNorm:$unorm, CPol:$cpol, 971 R128A16:$r128, A16:$a16, TFE:$tfe, LWE:$lwe)); 972 let AsmString = opcode#" $vdata, "#AddrAsm#", $srsrc$dmask$dim$unorm$cpol$r128$a16$tfe$lwe"; 973} 974 975class VIMAGE_Atomic_gfx12<mimgopc op, string opcode, RegisterClass DataRC, 976 int num_addrs, string renamed, bit enableDisasm = 0> 977 : VIMAGE_gfx12<op.GFX12, (outs DataRC:$vdst), num_addrs, 978 !if(enableDisasm, "GFX12", "")> { 979 let Constraints = "$vdst = $vdata"; 980 981 let InOperandList = !con((ins DataRC:$vdata), 982 AddrIns, 983 (ins SReg_256_XNULL:$rsrc, DMask:$dmask, Dim:$dim, 984 CPol:$cpol, R128A16:$r128, A16:$a16, TFE:$tfe)); 985 let AsmString = !if(!empty(renamed), opcode, renamed)#" $vdata, "#AddrAsm# 986 ", $rsrc$dmask$dim$cpol$r128$a16$tfe"; 987} 988 989multiclass MIMG_Atomic_Addr_Helper_m <mimgopc op, string asm, 990 RegisterClass data_rc, 991 bit enableDasm = 0, 992 bit isFP = 0, 993 string renamed = ""> { 994 let hasSideEffects = 1, // FIXME: remove this 995 mayLoad = 1, mayStore = 1, hasPostISelHook = 0, DisableWQM = 1, 996 FPAtomic = isFP in { 997 let VAddrDwords = 1 in { 998 let ssamp = 0 in { 999 if op.HAS_SI then { 1000 def _V1_si : MIMG_Atomic_si <op, asm, data_rc, VGPR_32, enableDasm>; 1001 } 1002 if op.HAS_VI then { 1003 def _V1_vi : MIMG_Atomic_vi <op, asm, data_rc, VGPR_32, enableDasm>; 1004 let hasPostISelHook = 1 in 1005 def _V1_gfx90a : MIMG_Atomic_gfx90a <op, asm, data_rc, VGPR_32, enableDasm>; 1006 } 1007 if op.HAS_GFX10M then { 1008 def _V1_gfx10 : MIMG_Atomic_gfx10 <op, asm, data_rc, VGPR_32, enableDasm>; 1009 } 1010 if op.HAS_GFX11 then { 1011 def _V1_gfx11 : MIMG_Atomic_gfx11 <op, asm, data_rc, VGPR_32, enableDasm>; 1012 } 1013 } 1014 if op.HAS_GFX12 then { 1015 def _V1_gfx12 : VIMAGE_Atomic_gfx12 <op, asm, data_rc, 1, renamed>; 1016 } 1017 } 1018 let VAddrDwords = 2 in { 1019 let ssamp = 0 in { 1020 if op.HAS_SI then { 1021 def _V2_si : MIMG_Atomic_si <op, asm, data_rc, VReg_64, 0>; 1022 } 1023 if op.HAS_VI then { 1024 def _V2_vi : MIMG_Atomic_vi <op, asm, data_rc, VReg_64, 0>; 1025 def _V2_gfx90a : MIMG_Atomic_gfx90a <op, asm, data_rc, VReg_64, 0>; 1026 } 1027 if op.HAS_GFX10M then { 1028 def _V2_gfx10 : MIMG_Atomic_gfx10 <op, asm, data_rc, VReg_64, 0>; 1029 def _V2_nsa_gfx10 : MIMG_Atomic_nsa_gfx10 <op, asm, data_rc, 2, 0>; 1030 } 1031 if op.HAS_GFX11 then { 1032 def _V2_gfx11 : MIMG_Atomic_gfx11 <op, asm, data_rc, VReg_64, 0>; 1033 def _V2_nsa_gfx11 : MIMG_Atomic_nsa_gfx11 <op, asm, data_rc, 2, 0>; 1034 } 1035 } 1036 if op.HAS_GFX12 then { 1037 def _V2_gfx12 : VIMAGE_Atomic_gfx12 <op, asm, data_rc, 2, renamed>; 1038 } 1039 } 1040 let VAddrDwords = 3 in { 1041 let ssamp = 0 in { 1042 if op.HAS_SI then { 1043 def _V3_si : MIMG_Atomic_si <op, asm, data_rc, VReg_96, 0>; 1044 } 1045 if op.HAS_VI then { 1046 def _V3_vi : MIMG_Atomic_vi <op, asm, data_rc, VReg_96, 0>; 1047 def _V3_gfx90a : MIMG_Atomic_gfx90a <op, asm, data_rc, VReg_96, 0>; 1048 } 1049 if op.HAS_GFX10M then { 1050 def _V3_gfx10 : MIMG_Atomic_gfx10 <op, asm, data_rc, VReg_96, 0>; 1051 def _V3_nsa_gfx10 : MIMG_Atomic_nsa_gfx10 <op, asm, data_rc, 3, 0>; 1052 } 1053 if op.HAS_GFX11 then { 1054 def _V3_gfx11 : MIMG_Atomic_gfx11 <op, asm, data_rc, VReg_96, 0>; 1055 def _V3_nsa_gfx11 : MIMG_Atomic_nsa_gfx11 <op, asm, data_rc, 3, 0>; 1056 } 1057 } 1058 if op.HAS_GFX12 then { 1059 def _V3_gfx12 : VIMAGE_Atomic_gfx12 <op, asm, data_rc, 3, renamed>; 1060 } 1061 } 1062 let VAddrDwords = 4 in { 1063 let ssamp = 0 in { 1064 if op.HAS_SI then { 1065 def _V4_si : MIMG_Atomic_si <op, asm, data_rc, VReg_128, 0>; 1066 } 1067 if op.HAS_VI then { 1068 def _V4_vi : MIMG_Atomic_vi <op, asm, data_rc, VReg_128, 0>; 1069 def _V4_gfx90a : MIMG_Atomic_gfx90a <op, asm, data_rc, VReg_128, 0>; 1070 } 1071 if op.HAS_GFX10M then { 1072 def _V4_gfx10 : MIMG_Atomic_gfx10 <op, asm, data_rc, VReg_128, 0>; 1073 def _V4_nsa_gfx10 : MIMG_Atomic_nsa_gfx10 <op, asm, data_rc, 4, enableDasm>; 1074 } 1075 if op.HAS_GFX11 then { 1076 def _V4_gfx11 : MIMG_Atomic_gfx11 <op, asm, data_rc, VReg_128, 0>; 1077 def _V4_nsa_gfx11 : MIMG_Atomic_nsa_gfx11 <op, asm, data_rc, 4, enableDasm>; 1078 } 1079 } 1080 if op.HAS_GFX12 then { 1081 def _V4_gfx12 : VIMAGE_Atomic_gfx12 <op, asm, data_rc, 4, renamed, enableDasm>; 1082 } 1083 } 1084 } 1085 if !and(op.HAS_GFX12, !not(!empty(renamed))) then 1086 def : AMDGPUMnemonicAlias<asm, renamed> { 1087 let AssemblerPredicate = isGFX12Plus; 1088 bit IsAtomicRet; // Unused 1089 MIMGBaseOpcode BaseOpcode; // Unused 1090 int VDataDwords; // Unused 1091 } 1092} 1093 1094multiclass MIMG_Atomic <mimgopc op, string asm, bit isCmpSwap = 0, bit isFP = 0, 1095 string renamed = ""> { // 64-bit atomics 1096 let IsAtomicRet = 1 in { 1097 def "" : MIMGBaseOpcode { 1098 let Atomic = 1; 1099 let AtomicX2 = isCmpSwap; 1100 } 1101 1102 let BaseOpcode = !cast<MIMGBaseOpcode>(NAME) in { 1103 // _V* variants have different dst size, but the size is encoded implicitly, 1104 // using dmask and tfe. Only 32-bit variant is registered with disassembler. 1105 // Other variants are reconstructed by disassembler using dmask and tfe. 1106 if !not(isCmpSwap) then { 1107 let VDataDwords = 1 in 1108 defm _V1 : MIMG_Atomic_Addr_Helper_m <op, asm, VGPR_32, 1, isFP, renamed>; 1109 } 1110 1111 let VDataDwords = 2 in 1112 defm _V2 : MIMG_Atomic_Addr_Helper_m <op, asm, VReg_64, isCmpSwap, isFP, renamed>; 1113 let VDataDwords = 3 in 1114 defm _V3 : MIMG_Atomic_Addr_Helper_m <op, asm, VReg_96, 0, isFP, renamed>; 1115 1116 if isCmpSwap then { 1117 let VDataDwords = 4 in 1118 defm _V4 : MIMG_Atomic_Addr_Helper_m <op, asm, VReg_128, 0, isFP, renamed>; 1119 let VDataDwords = 5 in 1120 defm _V5 : MIMG_Atomic_Addr_Helper_m <op, asm, VReg_160, 0, isFP, renamed>; 1121 } 1122 } 1123 } // End IsAtomicRet = 1 1124} 1125 1126multiclass MIMG_Atomic_Renamed <mimgopc op, string asm, string renamed, 1127 bit isCmpSwap = 0, bit isFP = 0> 1128 : MIMG_Atomic <op, asm, isCmpSwap, isFP, renamed>; 1129 1130class MIMG_Sampler_Helper <mimgopc op, string asm, RegisterClass dst_rc, 1131 RegisterClass src_rc, string dns=""> 1132 : MIMG_gfx6789 <op.VI, (outs dst_rc:$vdata), dns> { 1133 let InOperandList = !con((ins src_rc:$vaddr, SReg_256_XNULL:$srsrc, SReg_128_XNULL:$ssamp, 1134 DMask:$dmask, UNorm:$unorm, CPol:$cpol, 1135 R128A16:$r128, TFE:$tfe, LWE:$lwe, DA:$da), 1136 !if(BaseOpcode.HasD16, (ins D16:$d16), (ins))); 1137 let AsmString = asm#" $vdata, $vaddr, $srsrc, $ssamp$dmask$unorm$cpol$r128$tfe$lwe$da" 1138 #!if(BaseOpcode.HasD16, "$d16", ""); 1139} 1140 1141class MIMG_Sampler_gfx90a<mimgopc op, string asm, RegisterClass dst_rc, 1142 RegisterClass src_rc, string dns=""> 1143 : MIMG_gfx90a<op.GFX10M, (outs getLdStRegisterOperand<dst_rc>.ret:$vdata), dns> { 1144 let InOperandList = !con((ins src_rc:$vaddr, SReg_256_XNULL:$srsrc, SReg_128_XNULL:$ssamp, 1145 DMask:$dmask, UNorm:$unorm, CPol:$cpol, 1146 R128A16:$r128, LWE:$lwe, DA:$da), 1147 !if(BaseOpcode.HasD16, (ins D16:$d16), (ins))); 1148 let AsmString = asm#" $vdata, $vaddr, $srsrc, $ssamp$dmask$unorm$cpol$r128$lwe$da" 1149 #!if(BaseOpcode.HasD16, "$d16", ""); 1150} 1151 1152class MIMG_Sampler_OpList_gfx10p<dag OpPrefix, bit HasD16> { 1153 dag ret = !con(OpPrefix, 1154 (ins SReg_256_XNULL:$srsrc, SReg_128_XNULL:$ssamp, 1155 DMask:$dmask, Dim:$dim, UNorm:$unorm, CPol:$cpol, 1156 R128A16:$r128, A16:$a16, TFE:$tfe, LWE:$lwe), 1157 !if(HasD16, (ins D16:$d16), (ins))); 1158} 1159 1160class MIMG_Sampler_Asm_gfx10p<string opcode, string AsmPrefix, bit HasD16> { 1161 string ret = opcode#" "#AsmPrefix#", $srsrc, $ssamp$dmask$dim$unorm" 1162 #"$cpol$r128$a16$tfe$lwe" 1163 #!if(HasD16, "$d16", ""); 1164} 1165 1166class MIMG_Sampler_gfx10<mimgopc op, string opcode, 1167 RegisterClass DataRC, RegisterClass AddrRC, 1168 string dns=""> 1169 : MIMG_gfx10<op.GFX10M, (outs DataRC:$vdata), dns> { 1170 let InOperandList = MIMG_Sampler_OpList_gfx10p<(ins AddrRC:$vaddr0), BaseOpcode.HasD16>.ret; 1171 let AsmString = MIMG_Sampler_Asm_gfx10p<opcode, "$vdata, $vaddr0", BaseOpcode.HasD16>.ret; 1172} 1173 1174class MIMG_Sampler_nsa_gfx10<mimgopc op, string opcode, 1175 RegisterClass DataRC, int num_addrs, 1176 string dns=""> 1177 : MIMG_nsa_gfx10<op.GFX10M, (outs DataRC:$vdata), num_addrs, dns> { 1178 let InOperandList = MIMG_Sampler_OpList_gfx10p<AddrIns, BaseOpcode.HasD16>.ret; 1179 let AsmString = MIMG_Sampler_Asm_gfx10p<opcode, " $vdata, "#AddrAsm, BaseOpcode.HasD16>.ret; 1180} 1181 1182class MIMG_Sampler_nortn_gfx10<mimgopc op, string opcode, 1183 RegisterClass AddrRC, 1184 string dns=""> 1185 : MIMG_gfx10<op.GFX10M, (outs), dns> { 1186 let InOperandList = MIMG_Sampler_OpList_gfx10p<(ins AddrRC:$vaddr0), BaseOpcode.HasD16>.ret; 1187 let AsmString = MIMG_Sampler_Asm_gfx10p<opcode, "off, $vaddr0", BaseOpcode.HasD16>.ret; 1188 // Force vdata to VGPR0 as no result will be returned. 1189 let vdata = 0; 1190} 1191 1192class MIMG_Sampler_nortn_nsa_gfx10<mimgopc op, string opcode, 1193 int num_addrs, 1194 string dns=""> 1195 : MIMG_nsa_gfx10<op.GFX10M, (outs), num_addrs, dns> { 1196 let InOperandList = MIMG_Sampler_OpList_gfx10p<AddrIns, BaseOpcode.HasD16>.ret; 1197 let AsmString = MIMG_Sampler_Asm_gfx10p<opcode, " off, "#AddrAsm, BaseOpcode.HasD16>.ret; 1198 // Force vdata to VGPR0 as no result will be returned. 1199 let vdata = 0; 1200} 1201 1202class MIMG_Sampler_gfx11<mimgopc op, string opcode, 1203 RegisterClass DataRC, RegisterClass AddrRC, 1204 string dns=""> 1205 : MIMG_gfx11<op.GFX11, (outs DataRC:$vdata), dns> { 1206 let InOperandList = MIMG_Sampler_OpList_gfx10p<(ins AddrRC:$vaddr0), BaseOpcode.HasD16>.ret; 1207 let AsmString = MIMG_Sampler_Asm_gfx10p<opcode, "$vdata, $vaddr0", BaseOpcode.HasD16>.ret; 1208} 1209 1210class MIMG_Sampler_nsa_gfx11<mimgopc op, string opcode, 1211 RegisterClass DataRC, int num_addrs, 1212 RegisterClass LastVAddrSize, string dns=""> 1213 : MIMG_nsa_gfx11<op.GFX11, (outs DataRC:$vdata), num_addrs, dns, [], 1214 LastVAddrSize> { 1215 let InOperandList = MIMG_Sampler_OpList_gfx10p<AddrIns, BaseOpcode.HasD16>.ret; 1216 let AsmString = MIMG_Sampler_Asm_gfx10p<opcode, " $vdata, "#AddrAsm, BaseOpcode.HasD16>.ret; 1217} 1218 1219class MIMG_Sampler_nortn_gfx11<mimgopc op, string opcode, 1220 RegisterClass AddrRC, 1221 string dns=""> 1222 : MIMG_gfx11<op.GFX11, (outs), dns> { 1223 let InOperandList = MIMG_Sampler_OpList_gfx10p<(ins AddrRC:$vaddr0), BaseOpcode.HasD16>.ret; 1224 let AsmString = MIMG_Sampler_Asm_gfx10p<opcode, "off, $vaddr0", BaseOpcode.HasD16>.ret; 1225 let vdata = 0; 1226} 1227 1228class MIMG_Sampler_nortn_nsa_gfx11<mimgopc op, string opcode, 1229 int num_addrs, 1230 RegisterClass LastVAddrSize, string dns=""> 1231 : MIMG_nsa_gfx11<op.GFX11, (outs), num_addrs, dns, [], LastVAddrSize> { 1232 let InOperandList = MIMG_Sampler_OpList_gfx10p<AddrIns, BaseOpcode.HasD16>.ret; 1233 let AsmString = MIMG_Sampler_Asm_gfx10p<opcode, "off, "#AddrAsm, BaseOpcode.HasD16>.ret; 1234 let vdata = 0; 1235} 1236 1237class MIMGAddrSize<int dw, bit enable_disasm, int AddrDW = dw> { 1238 int NumWords = dw; 1239 1240 RegisterClass RegClass = !if(!le(AddrDW, 0), ?, 1241 !if(!eq(AddrDW, 1), VGPR_32, 1242 !if(!eq(AddrDW, 2), VReg_64, 1243 !if(!eq(AddrDW, 3), VReg_96, 1244 !if(!eq(AddrDW, 4), VReg_128, 1245 !if(!eq(AddrDW, 5), VReg_160, 1246 !if(!eq(AddrDW, 6), VReg_192, 1247 !if(!eq(AddrDW, 7), VReg_224, 1248 !if(!eq(AddrDW, 8), VReg_256, 1249 !if(!eq(AddrDW, 9), VReg_288, 1250 !if(!eq(AddrDW, 10), VReg_320, 1251 !if(!eq(AddrDW, 11), VReg_352, 1252 !if(!eq(AddrDW, 12), VReg_384, 1253 !if(!le(AddrDW, 16), VReg_512, ?)))))))))))))); 1254 1255 // Whether the instruction variant with this vaddr size should be enabled for 1256 // the auto-generated disassembler. 1257 bit Disassemble = enable_disasm; 1258} 1259 1260// Returns the MIMGAddrSize with the size of last VAddr for partial NSA 1261class LastVAddrSize <int dw, int max_idx, bit enable_disasm> 1262 : MIMGAddrSize<dw, enable_disasm, 1263 !if(!gt(dw, max_idx), !sub(dw, max_idx), 0)>; 1264 1265// Return whether x is in lst. 1266class isIntInList<int x, list<int> lst> { 1267 bit ret = !foldl(0, lst, lhs, y, !or(lhs, !eq(x, y))); 1268} 1269 1270// Return whether a value inside the range [min, max] (endpoints inclusive) 1271// is in the given list. 1272class isRangeInList<int min, int max, list<int> lst> { 1273 bit ret = !foldl(0, lst, lhs, y, !or(lhs, !and(!le(min, y), !le(y, max)))); 1274} 1275 1276class MIMGAddrSizes_dw_range<list<int> range> { 1277 int Min = !head(range); 1278 int Max = !if(!empty(!tail(range)), Min, !head(!tail(range))); 1279} 1280 1281class MIMG_Sampler_AddrSizes<AMDGPUSampleVariant sample, bit isG16, 1282 int nsa_max_addr = 5, bit includeNSA1 = 0> { 1283 // List of all possible numbers of address words, taking all combinations of 1284 // A16 and image dimension into account (note: no MSAA, since this is for 1285 // sample/gather ops). 1286 list<int> AllNumAddrWords = 1287 !foreach(dw, !if(sample.Gradients, 1288 !if(isG16, 1289 !if(!eq(sample.LodOrClamp, ""), 1290 [2, 3, 4, 5, 6, 7], 1291 [2, 3, 4, 5, 6, 7, 8]), 1292 !if(!eq(sample.LodOrClamp, ""), 1293 [2, 3, 4, 5, 6, 7, 8, 9], 1294 [2, 3, 4, 5, 6, 7, 8, 9, 10])), 1295 !if(!eq(sample.LodOrClamp, ""), 1296 [1, 2, 3], 1297 [1, 2, 3, 4])), 1298 !add(dw, !size(sample.ExtraAddrArgs))); 1299 1300 // Generate machine instructions based on possible register classes for the 1301 // required numbers of address words. The disassembler defaults to the 1302 // smallest register class. 1303 list<MIMGAddrSize> MachineInstrs = 1304 !foldl([]<MIMGAddrSize>, 1305 !foreach(range, 1306 // V4 is generated for V3 and V4 1307 // V8 is generated for V5 through V8 1308 // V16 is generated for V13 through V16 1309 [[1],[2],[3],[3,4],[5],[6],[7],[5,8],[9],[10],[11],[12],[13,16]], 1310 MIMGAddrSizes_dw_range<range>), 1311 lhs, dw, 1312 !if(isRangeInList<dw.Min, dw.Max, AllNumAddrWords>.ret, 1313 !listconcat(lhs, [MIMGAddrSize<dw.Max, !empty(lhs)>]), 1314 lhs)); 1315 1316 // For NSA, generate machine instructions for all possible numbers of words 1317 // except 1 (which is already covered by the non-NSA case). 1318 // The disassembler defaults to the largest number of arguments among the 1319 // variants with the same number of NSA words, and custom code then derives 1320 // the exact variant based on the sample variant and the image dimension. 1321 list<MIMGAddrSize> NSAInstrs = 1322 !foldl([]<MIMGAddrSize>, [[12, 11, 10], [9, 8, 7, 6], [5, 4, 3, 2]], prev, nsa_group, 1323 !listconcat(prev, 1324 !foldl([]<MIMGAddrSize>, nsa_group, lhs, dw, 1325 !if(isIntInList<dw, AllNumAddrWords>.ret, 1326 !listconcat(lhs, [MIMGAddrSize<dw, !empty(lhs)>]), 1327 lhs)))); 1328 1329 // In NSA format if there is a requirement for more VGPRs than the format 1330 // supports, then the rest are sequential after the last one. Generate 1331 // machine instructions for all possible number of words. The disassembler 1332 // defaults to the largest number of arguments but no larger than max nsa 1333 // size. List is generated with the register class needed for last vaddr since 1334 // it is the only one that could have a register other than VGPR32. 1335 int EnableDisasmNum = !foldl(!head(AllNumAddrWords), !tail(AllNumAddrWords), 1336 acc, var, !if(!le(var, nsa_max_addr), var, acc)); 1337 list<int> PossibleVariants = 1338 !listconcat([12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2], !if(includeNSA1, [1], [])); 1339 list<LastVAddrSize> PartialNSAInstrs = 1340 !foldl([]<LastVAddrSize>, PossibleVariants, lhs, dw, 1341 !if(isIntInList<dw, AllNumAddrWords>.ret, 1342 !listconcat(lhs, [LastVAddrSize<dw, !sub(nsa_max_addr, 1), 1343 !eq(dw, EnableDisasmNum)>]), 1344 lhs)); 1345} 1346 1347multiclass MIMG_Sampler_Src_Helper <mimgopc op, string asm, 1348 AMDGPUSampleVariant sample, RegisterClass dst_rc, 1349 bit enableDisasm = 0, 1350 bit ExtendedImageInst = 1, bit isG16 = 0> { 1351 foreach addr = MIMG_Sampler_AddrSizes<sample, isG16>.MachineInstrs in { 1352 let VAddrDwords = addr.NumWords in { 1353 if op.HAS_GFX10M then { 1354 def _V # addr.NumWords 1355 : MIMG_Sampler_Helper <op, asm, dst_rc, addr.RegClass, 1356 !if(!and(enableDisasm, addr.Disassemble), "GFX8", "")>; 1357 if !not(ExtendedImageInst) then 1358 def _V # addr.NumWords # _gfx90a 1359 : MIMG_Sampler_gfx90a <op, asm, dst_rc, addr.RegClass, 1360 !if(!and(enableDisasm, addr.Disassemble), "GFX90A", "")>; 1361 def _V # addr.NumWords # _gfx10 1362 : MIMG_Sampler_gfx10 <op, asm, dst_rc, addr.RegClass, 1363 !if(!and(enableDisasm, addr.Disassemble), "GFX10", "")>; 1364 } 1365 if op.HAS_GFX11 then { 1366 def _V # addr.NumWords # _gfx11 1367 : MIMG_Sampler_gfx11 <op, asm, dst_rc, addr.RegClass, 1368 !if(!and(enableDisasm, addr.Disassemble), "GFX11", "")>; 1369 } 1370 } 1371 } 1372 1373 foreach addr = MIMG_Sampler_AddrSizes<sample, isG16>.NSAInstrs in { 1374 let VAddrDwords = addr.NumWords in { 1375 if op.HAS_GFX10M then { 1376 def _V # addr.NumWords # _nsa_gfx10 1377 : MIMG_Sampler_nsa_gfx10<op, asm, dst_rc, addr.NumWords, 1378 !if(!and(enableDisasm, addr.Disassemble), "GFX10", "")>; 1379 } 1380 } 1381 } 1382 1383 foreach addr = MIMG_Sampler_AddrSizes<sample, isG16, 5/*MaxNSASize*/>.PartialNSAInstrs in { 1384 let VAddrDwords = addr.NumWords in { 1385 if op.HAS_GFX11 then { 1386 def _V # addr.NumWords # _nsa_gfx11 1387 : MIMG_Sampler_nsa_gfx11<op, asm, dst_rc, addr.NumWords, addr.RegClass, 1388 !if(!and(enableDisasm, addr.Disassemble), "GFX11", "")>; 1389 } 1390 } 1391 } 1392 1393 foreach addr = MIMG_Sampler_AddrSizes<sample, isG16, 4/*MaxNSASize*/, 1>.PartialNSAInstrs in { 1394 let VAddrDwords = addr.NumWords in { 1395 if op.HAS_GFX12 then { 1396 def _V # addr.NumWords # _gfx12 1397 : VSAMPLE_Sampler_gfx12<op, asm, dst_rc, addr.NumWords, addr.RegClass, 1398 !if(!and(enableDisasm, addr.Disassemble), "GFX12", "")>; 1399 } 1400 } 1401 } 1402} 1403 1404class MIMG_Sampler_BaseOpcode<AMDGPUSampleVariant sample> 1405 : MIMGBaseOpcode { 1406 let Sampler = 1; 1407 let NumExtraArgs = !size(sample.ExtraAddrArgs); 1408 let Gradients = sample.Gradients; 1409 let LodOrClampOrMip = !ne(sample.LodOrClamp, ""); 1410} 1411 1412multiclass MIMG_Sampler_NoReturn <mimgopc op, AMDGPUSampleVariant sample, bit wqm = 0, bit isG16, string asm> { 1413 def "" : MIMG_Sampler_BaseOpcode<sample> { 1414 let HasD16 = 1; 1415 let G16 = isG16; 1416 let NoReturn = 1; 1417 } 1418 1419 let BaseOpcode = !cast<MIMGBaseOpcode>(NAME), WQM = wqm, 1420 mayLoad = 1, mayStore = 1, VDataDwords = 0 in { 1421 foreach addr = MIMG_Sampler_AddrSizes<sample, isG16>.MachineInstrs in { 1422 let VAddrDwords = addr.NumWords in { 1423 if op.HAS_GFX10M then { 1424 def _V # addr.NumWords # _gfx10 1425 : MIMG_Sampler_nortn_gfx10 <op, asm, addr.RegClass>; 1426 } 1427 if op.HAS_GFX11 then { 1428 def _V # addr.NumWords # _gfx11 1429 : MIMG_Sampler_nortn_gfx11 <op, asm, addr.RegClass>; 1430 } 1431 } 1432 } 1433 1434 foreach addr = MIMG_Sampler_AddrSizes<sample, isG16>.NSAInstrs in { 1435 let VAddrDwords = addr.NumWords in { 1436 if op.HAS_GFX10M then { 1437 def _V # addr.NumWords # _nsa_gfx10 1438 : MIMG_Sampler_nortn_nsa_gfx10<op, asm, addr.NumWords>; 1439 } 1440 } 1441 } 1442 1443 foreach addr = MIMG_Sampler_AddrSizes<sample, isG16, 5/*MaxNSASize*/>.PartialNSAInstrs in { 1444 let VAddrDwords = addr.NumWords in { 1445 if op.HAS_GFX11 then { 1446 def _V # addr.NumWords # _nsa_gfx11 1447 : MIMG_Sampler_nortn_nsa_gfx11<op, asm, addr.NumWords, addr.RegClass>; 1448 } 1449 } 1450 } 1451 1452 foreach addr = MIMG_Sampler_AddrSizes<sample, isG16, 4/*MaxNSASize*/, 1>.PartialNSAInstrs in { 1453 let VAddrDwords = addr.NumWords in { 1454 if op.HAS_GFX12 then { 1455 def _V # addr.NumWords # _gfx12 1456 : VSAMPLE_Sampler_nortn_gfx12<op, asm, addr.NumWords, addr.RegClass>; 1457 } 1458 } 1459 } 1460 } 1461} 1462 1463multiclass MIMG_Sampler <mimgopc op, AMDGPUSampleVariant sample, bit isPointSampleAccel = 0, 1464 bit wqm = 0, bit isG16 = 0, bit isGetLod = 0, 1465 string asm = "image_sample"#sample.LowerCaseMod#!if(isG16, "_g16", ""), 1466 bit ExtendedImageInst = !ne(sample.LowerCaseMod, "")> { 1467 def "" : MIMG_Sampler_BaseOpcode<sample> { 1468 let HasD16 = !not(isGetLod); 1469 let G16 = isG16; 1470 let PointSampleAccel = isPointSampleAccel; 1471 } 1472 1473 let BaseOpcode = !cast<MIMGBaseOpcode>(NAME), WQM = wqm, 1474 mayLoad = !not(isGetLod) in { 1475 let VDataDwords = 1 in 1476 defm _V1 : MIMG_Sampler_Src_Helper<op, asm, sample, VGPR_32, 1, ExtendedImageInst, isG16>; 1477 let VDataDwords = 2 in 1478 defm _V2 : MIMG_Sampler_Src_Helper<op, asm, sample, VReg_64, 0, ExtendedImageInst, isG16>; 1479 let VDataDwords = 3 in 1480 defm _V3 : MIMG_Sampler_Src_Helper<op, asm, sample, VReg_96, 0, ExtendedImageInst, isG16>; 1481 let VDataDwords = 4 in 1482 defm _V4 : MIMG_Sampler_Src_Helper<op, asm, sample, VReg_128, 0, ExtendedImageInst, isG16>; 1483 let VDataDwords = 5 in 1484 defm _V5 : MIMG_Sampler_Src_Helper<op, asm, sample, VReg_160, 0, ExtendedImageInst, isG16>; 1485 } 1486 1487 if !not(isGetLod) then 1488 defm "_nortn" : MIMG_Sampler_NoReturn <op, sample, wqm, isG16, asm>; 1489} 1490 1491multiclass MIMG_Sampler_WQM <mimgopc op, AMDGPUSampleVariant sample, bit isPointSampleAccel = 0> 1492 : MIMG_Sampler<op, sample, isPointSampleAccel, 1>; 1493 1494multiclass MIMG_Gather <mimgopc op, AMDGPUSampleVariant sample, bit wqm = 0, 1495 string asm = "image_gather4"#sample.LowerCaseMod> { 1496 def "" : MIMG_Sampler_BaseOpcode<sample> { 1497 let HasD16 = 1; 1498 let Gather4 = 1; 1499 } 1500 1501 let BaseOpcode = !cast<MIMGBaseOpcode>(NAME), WQM = wqm, 1502 Gather4 = 1 in { 1503 let VDataDwords = 2 in 1504 defm _V2 : MIMG_Sampler_Src_Helper<op, asm, sample, VReg_64, /*enableDisasm*/ true>; /* for packed D16 only */ 1505 let VDataDwords = 4 in 1506 defm _V4 : MIMG_Sampler_Src_Helper<op, asm, sample, VReg_128>; 1507 let VDataDwords = 5 in 1508 defm _V5 : MIMG_Sampler_Src_Helper<op, asm, sample, VReg_160>; 1509 } 1510} 1511 1512multiclass MIMG_Gather_WQM <mimgopc op, AMDGPUSampleVariant sample> 1513 : MIMG_Gather<op, sample, 1>; 1514 1515class MIMG_IntersectRay_Helper<bit Is64, bit IsA16, bit isDual, bit isBVH8> { 1516 int num_addrs = !if(isBVH8, 11, !if(Is64, !if(IsA16, 9, 12), !if(IsA16, 8, 11))); 1517 RegisterClass RegClass = MIMGAddrSize<num_addrs, 0>.RegClass; 1518 int VAddrDwords = !srl(RegClass.Size, 5); 1519 1520 int GFX11PlusNSAAddrs = !if(IsA16, 4, 5); 1521 RegisterClass node_ptr_type = !if(Is64, VReg_64, VGPR_32); 1522 list<RegisterClass> GFX11PlusAddrTypes = 1523 !cond(isBVH8 : [node_ptr_type, VReg_64, VReg_96, VReg_96, VGPR_32], 1524 isDual : [node_ptr_type, VReg_64, VReg_96, VReg_96, VReg_64], 1525 IsA16 : [node_ptr_type, VGPR_32, VReg_96, VReg_96], 1526 true : [node_ptr_type, VGPR_32, VReg_96, VReg_96, VReg_96]); 1527} 1528 1529class MIMG_IntersectRay_gfx10<mimgopc op, string opcode, RegisterClass AddrRC> 1530 : MIMG_gfx10<op.GFX10M, (outs VReg_128:$vdata), "GFX10"> { 1531 let InOperandList = (ins AddrRC:$vaddr0, SReg_128_XNULL:$srsrc, A16:$a16); 1532 let AsmString = opcode#" $vdata, $vaddr0, $srsrc$a16"; 1533 1534 let nsa = 0; 1535} 1536 1537class MIMG_IntersectRay_nsa_gfx10<mimgopc op, string opcode, int num_addrs> 1538 : MIMG_nsa_gfx10<op.GFX10M, (outs VReg_128:$vdata), num_addrs, "GFX10"> { 1539 let InOperandList = !con(nsah.AddrIns, (ins SReg_128_XNULL:$srsrc, A16:$a16)); 1540 let AsmString = opcode#" $vdata, "#nsah.AddrAsm#", $srsrc$a16"; 1541} 1542 1543class MIMG_IntersectRay_gfx11<mimgopc op, string opcode, RegisterClass AddrRC> 1544 : MIMG_gfx11<op.GFX11, (outs VReg_128:$vdata), "GFX11"> { 1545 let InOperandList = (ins AddrRC:$vaddr0, SReg_128_XNULL:$srsrc, A16:$a16); 1546 let AsmString = opcode#" $vdata, $vaddr0, $srsrc$a16"; 1547 1548 let nsa = 0; 1549} 1550 1551class MIMG_IntersectRay_nsa_gfx11<mimgopc op, string opcode, int num_addrs, 1552 list<RegisterClass> addr_types> 1553 : MIMG_nsa_gfx11<op.GFX11, (outs VReg_128:$vdata), num_addrs, "GFX11", 1554 addr_types> { 1555 let InOperandList = !con(nsah.AddrIns, (ins SReg_128_XNULL:$srsrc, A16:$a16)); 1556 let AsmString = opcode#" $vdata, "#nsah.AddrAsm#", $srsrc$a16"; 1557} 1558 1559class VIMAGE_IntersectRay_gfx12<mimgopc op, string opcode, int num_addrs, 1560 bit isDual, bit isBVH8, 1561 list<RegisterClass> addr_types> 1562 : VIMAGE_gfx12<op.GFX12, !if(!or(isDual, isBVH8), 1563 (outs VReg_320:$vdata, VReg_96:$ray_origin_out, 1564 VReg_96:$ray_dir_out), 1565 (outs VReg_128:$vdata)), 1566 num_addrs, "GFX12", addr_types> { 1567 let Constraints = !if(!or(isDual, isBVH8), 1568 "$ray_origin_out = $vaddr2, $ray_dir_out = $vaddr3", ""); 1569 let InOperandList = !con(nsah.AddrIns, (ins SReg_128_XNULL:$rsrc), 1570 !if(!or(isDual, isBVH8), (ins), (ins A16:$a16))); 1571 let AsmString = opcode#" $vdata, "#nsah.AddrAsm#", $rsrc"# 1572 !if(!or(isDual, isBVH8), "", "$a16"); 1573 let SchedRW = !if(!or(isDual, isBVH8), 1574 [WriteVMEM, WriteVMEM, WriteVMEM], [WriteVMEM]); 1575} 1576 1577multiclass MIMG_IntersectRay<mimgopc op, string opcode, bit Is64, bit IsA16, 1578 bit isDual, bit isBVH8 = 0> { 1579 defvar info = MIMG_IntersectRay_Helper<Is64, IsA16, isDual, isBVH8>; 1580 def "" : MIMGBaseOpcode { 1581 let BVH = 1; 1582 let A16 = IsA16; 1583 } 1584 let dmask = 0xf, 1585 d16 = 0, 1586 cpol = 0, 1587 tfe = 0, 1588 r128 = 1, 1589 dim = {0, 0, 0}, 1590 a16 = IsA16, 1591 d16 = 0, 1592 BaseOpcode = !cast<MIMGBaseOpcode>(NAME), 1593 VDataDwords = 4 in { 1594 let unorm = 1, 1595 lwe = 0, 1596 ssamp = 0 in { 1597 if op.HAS_GFX10M then 1598 def _sa_gfx10 : MIMG_IntersectRay_gfx10<op, opcode, info.RegClass> { 1599 let VAddrDwords = info.VAddrDwords; 1600 } 1601 if op.HAS_GFX11 then 1602 def _sa_gfx11 : MIMG_IntersectRay_gfx11<op, opcode, info.RegClass> { 1603 let VAddrDwords = info.VAddrDwords; 1604 } 1605 if op.HAS_GFX10M then 1606 def _nsa_gfx10 : MIMG_IntersectRay_nsa_gfx10<op, opcode, info.num_addrs> { 1607 let VAddrDwords = info.num_addrs; 1608 } 1609 if op.HAS_GFX11 then 1610 def _nsa_gfx11 : MIMG_IntersectRay_nsa_gfx11<op, opcode, 1611 info.GFX11PlusNSAAddrs, 1612 info.GFX11PlusAddrTypes> { 1613 let VAddrDwords = info.num_addrs; 1614 } 1615 } 1616 def _gfx12 : VIMAGE_IntersectRay_gfx12<op, opcode, info.GFX11PlusNSAAddrs, 1617 isDual, isBVH8, 1618 info.GFX11PlusAddrTypes> { 1619 let VDataDwords = !if(!or(isDual, isBVH8), 10, 4); 1620 let VAddrDwords = info.num_addrs; 1621 } 1622 } 1623} 1624 1625multiclass MIMG_MSAA_Load <mimgopc op, string asm> { 1626 def "" : MIMGBaseOpcode { 1627 let HasD16 = 1; 1628 let Gather4 = 1; /* for appropriate dmask handling */ 1629 let MSAA = 1; 1630 } 1631 1632 let BaseOpcode = !cast<MIMGBaseOpcode>(NAME), 1633 Gather4 = 1, hasPostISelHook = 0, mayLoad = 1 in { 1634 let VDataDwords = 2 in 1635 defm _V2 : MIMG_NoSampler_Src_Helper<op, asm, VReg_64, 0, 0, 1>; /* packed D16 */ 1636 let VDataDwords = 3 in 1637 defm _V3 : MIMG_NoSampler_Src_Helper<op, asm, VReg_96, 0, 0, 1>; /* packed D16 + tfe */ 1638 let VDataDwords = 4 in 1639 defm _V4 : MIMG_NoSampler_Src_Helper<op, asm, VReg_128, 1, 0, 1>; 1640 let VDataDwords = 5 in 1641 defm _V5 : MIMG_NoSampler_Src_Helper<op, asm, VReg_160, 0, 0, 1>; 1642 } 1643} 1644 1645//===----------------------------------------------------------------------===// 1646// MIMG Instructions 1647//===----------------------------------------------------------------------===// 1648let OtherPredicates = [HasImageInsts] in { 1649 1650defm IMAGE_LOAD : MIMG_NoSampler <mimgopc<0x00, 0x00, 0x00>, "image_load", 1>; 1651defm IMAGE_LOAD_MIP : MIMG_NoSampler <mimgopc<0x01, 0x01, 0x01>, "image_load_mip", 1, 1>; 1652defm IMAGE_LOAD_PCK : MIMG_NoSampler <mimgopc<0x02, 0x02, 0x02>, "image_load_pck", 0>; 1653defm IMAGE_LOAD_PCK_SGN : MIMG_NoSampler <mimgopc<0x03, 0x03, 0x03>, "image_load_pck_sgn", 0>; 1654defm IMAGE_LOAD_MIP_PCK : MIMG_NoSampler <mimgopc<0x04, 0x04, 0x04>, "image_load_mip_pck", 0, 1>; 1655defm IMAGE_LOAD_MIP_PCK_SGN : MIMG_NoSampler <mimgopc<0x05, 0x05, 0x05>, "image_load_mip_pck_sgn", 0, 1>; 1656defm IMAGE_STORE : MIMG_Store <mimgopc<0x06, 0x06, 0x08>, "image_store", 1>; 1657defm IMAGE_STORE_MIP : MIMG_Store <mimgopc<0x07, 0x07, 0x09>, "image_store_mip", 1, 1>; 1658defm IMAGE_STORE_PCK : MIMG_Store <mimgopc<0x08, 0x08, 0x0a>, "image_store_pck", 0>; 1659defm IMAGE_STORE_MIP_PCK : MIMG_Store <mimgopc<0x09, 0x09, 0x0b>, "image_store_mip_pck", 0, 1>; 1660 1661defm IMAGE_GET_RESINFO : MIMG_NoSampler <mimgopc<0x17, 0x17, 0x0e, 0x0e, 0x0e>, "image_get_resinfo", 0, 1, 1>; 1662 1663defm IMAGE_ATOMIC_SWAP : MIMG_Atomic <mimgopc<0x0a, 0x0a, 0x0f, 0x10, 0x0f>, "image_atomic_swap">; 1664defm IMAGE_ATOMIC_CMPSWAP : MIMG_Atomic <mimgopc<0x0b, 0x0b, 0x10, 0x11, 0x10>, "image_atomic_cmpswap", 1>; 1665defm IMAGE_ATOMIC_ADD : MIMG_Atomic_Renamed <mimgopc<0x0c, 0x0c, 0x11, 0x12, 0x11>, "image_atomic_add", "image_atomic_add_uint">; 1666defm IMAGE_ATOMIC_SUB : MIMG_Atomic_Renamed <mimgopc<0x0d, 0x0d, 0x12, 0x13, 0x12>, "image_atomic_sub", "image_atomic_sub_uint">; 1667defm IMAGE_ATOMIC_RSUB : MIMG_Atomic <mimgopc<MIMG.NOP, MIMG.NOP, MIMG.NOP, MIMG.NOP, 0x13>, "image_atomic_rsub">; 1668defm IMAGE_ATOMIC_SMIN : MIMG_Atomic_Renamed <mimgopc<0x0e, 0x0e, 0x14>, "image_atomic_smin", "image_atomic_min_int">; 1669defm IMAGE_ATOMIC_UMIN : MIMG_Atomic_Renamed <mimgopc<0x0f, 0x0f, 0x15>, "image_atomic_umin", "image_atomic_min_uint">; 1670defm IMAGE_ATOMIC_SMAX : MIMG_Atomic_Renamed <mimgopc<0x10, 0x10, 0x16>, "image_atomic_smax", "image_atomic_max_int">; 1671defm IMAGE_ATOMIC_UMAX : MIMG_Atomic_Renamed <mimgopc<0x11, 0x11, 0x17>, "image_atomic_umax", "image_atomic_max_uint">; 1672defm IMAGE_ATOMIC_AND : MIMG_Atomic <mimgopc<0x12, 0x12, 0x18>, "image_atomic_and">; 1673defm IMAGE_ATOMIC_OR : MIMG_Atomic <mimgopc<0x13, 0x13, 0x19>, "image_atomic_or">; 1674defm IMAGE_ATOMIC_XOR : MIMG_Atomic <mimgopc<0x14, 0x14, 0x1a>, "image_atomic_xor">; 1675defm IMAGE_ATOMIC_INC : MIMG_Atomic_Renamed <mimgopc<0x15, 0x15, 0x1b>, "image_atomic_inc", "image_atomic_inc_uint">; 1676defm IMAGE_ATOMIC_DEC : MIMG_Atomic_Renamed <mimgopc<0x16, 0x16, 0x1c>, "image_atomic_dec", "image_atomic_dec_uint">; 1677defm IMAGE_ATOMIC_FCMPSWAP : MIMG_Atomic <mimgopc<MIMG.NOP, MIMG.NOP, 0x1d, MIMG.NOP>, "image_atomic_fcmpswap", 1, 1>; 1678defm IMAGE_ATOMIC_FMIN : MIMG_Atomic <mimgopc<MIMG.NOP, MIMG.NOP, 0x1e, MIMG.NOP>, "image_atomic_fmin", 0, 1>; 1679defm IMAGE_ATOMIC_FMAX : MIMG_Atomic <mimgopc<MIMG.NOP, MIMG.NOP, 0x1f, MIMG.NOP>, "image_atomic_fmax", 0, 1>; 1680defm IMAGE_ATOMIC_PK_ADD_F16 : MIMG_Atomic <mimgopc<0x86, MIMG.NOP, MIMG.NOP, MIMG.NOP, MIMG.NOP>, "image_atomic_pk_add_f16", 0, 1>; 1681defm IMAGE_ATOMIC_PK_ADD_BF16 : MIMG_Atomic <mimgopc<0x87, MIMG.NOP, MIMG.NOP, MIMG.NOP, MIMG.NOP>, "image_atomic_pk_add_bf16", 0, 1>; 1682defm IMAGE_ATOMIC_ADD_FLT : MIMG_Atomic <mimgopc<0x83, MIMG.NOP, MIMG.NOP, MIMG.NOP>, "image_atomic_add_flt", 0, 1>; 1683defm IMAGE_ATOMIC_MIN_FLT : MIMG_Atomic <mimgopc<0x84, MIMG.NOP, MIMG.NOP, MIMG.NOP>, "image_atomic_min_num_flt", 0, 1, "image_atomic_min_flt">; 1684defm IMAGE_ATOMIC_MAX_FLT : MIMG_Atomic <mimgopc<0x85, MIMG.NOP, MIMG.NOP, MIMG.NOP>, "image_atomic_max_num_flt", 0, 1, "image_atomic_max_flt">; 1685let AssemblerPredicate = isGFX12Plus in { 1686 def : AMDGPUMnemonicAlias<"image_atomic_fmin", "image_atomic_min_flt">; 1687 def : AMDGPUMnemonicAlias<"image_atomic_fmax", "image_atomic_max_flt">; 1688} 1689 1690defm IMAGE_SAMPLE : MIMG_Sampler_WQM <mimgopc<0x1b, 0x1b, 0x20>, AMDGPUSample, 1>; 1691let OtherPredicates = [HasImageInsts, HasExtendedImageInsts] in { 1692defm IMAGE_SAMPLE_CL : MIMG_Sampler_WQM <mimgopc<0x40, 0x40, 0x21>, AMDGPUSample_cl>; 1693defm IMAGE_SAMPLE_D : MIMG_Sampler <mimgopc<0x1c, 0x1c, 0x22>, AMDGPUSample_d>; 1694defm IMAGE_SAMPLE_D_CL : MIMG_Sampler <mimgopc<0x41, 0x41, 0x23>, AMDGPUSample_d_cl>; 1695defm IMAGE_SAMPLE_L : MIMG_Sampler <mimgopc<0x1d, 0x1d, 0x24>, AMDGPUSample_l, 1>; 1696defm IMAGE_SAMPLE_B : MIMG_Sampler_WQM <mimgopc<0x1e, 0x1e, 0x25>, AMDGPUSample_b>; 1697defm IMAGE_SAMPLE_B_CL : MIMG_Sampler_WQM <mimgopc<0x42, 0x42, 0x26>, AMDGPUSample_b_cl>; 1698defm IMAGE_SAMPLE_LZ : MIMG_Sampler <mimgopc<0x1f, 0x1f, 0x27>, AMDGPUSample_lz, 1>; 1699defm IMAGE_SAMPLE_C : MIMG_Sampler_WQM <mimgopc<0x20, 0x20, 0x28>, AMDGPUSample_c>; 1700defm IMAGE_SAMPLE_C_CL : MIMG_Sampler_WQM <mimgopc<0x43, 0x43, 0x29>, AMDGPUSample_c_cl>; 1701defm IMAGE_SAMPLE_C_D : MIMG_Sampler <mimgopc<0x21, 0x21, 0x2a>, AMDGPUSample_c_d>; 1702defm IMAGE_SAMPLE_C_D_CL : MIMG_Sampler <mimgopc<0x44, 0x44, 0x2b>, AMDGPUSample_c_d_cl>; 1703defm IMAGE_SAMPLE_C_L : MIMG_Sampler <mimgopc<0x22, 0x22, 0x2c>, AMDGPUSample_c_l>; 1704defm IMAGE_SAMPLE_C_B : MIMG_Sampler_WQM <mimgopc<0x23, 0x23, 0x2d>, AMDGPUSample_c_b>; 1705defm IMAGE_SAMPLE_C_B_CL : MIMG_Sampler_WQM <mimgopc<0x45, 0x45, 0x2e>, AMDGPUSample_c_b_cl>; 1706defm IMAGE_SAMPLE_C_LZ : MIMG_Sampler <mimgopc<0x24, 0x24, 0x2f>, AMDGPUSample_c_lz>; 1707defm IMAGE_SAMPLE_O : MIMG_Sampler_WQM <mimgopc<0x25, 0x25, 0x30>, AMDGPUSample_o>; 1708defm IMAGE_SAMPLE_CL_O : MIMG_Sampler_WQM <mimgopc<0x46, 0x46, 0x31>, AMDGPUSample_cl_o>; 1709defm IMAGE_SAMPLE_D_O : MIMG_Sampler <mimgopc<0x26, 0x26, 0x32>, AMDGPUSample_d_o>; 1710defm IMAGE_SAMPLE_D_CL_O : MIMG_Sampler <mimgopc<0x47, 0x47, 0x33>, AMDGPUSample_d_cl_o>; 1711defm IMAGE_SAMPLE_L_O : MIMG_Sampler <mimgopc<0x27, 0x27, 0x34>, AMDGPUSample_l_o>; 1712defm IMAGE_SAMPLE_B_O : MIMG_Sampler_WQM <mimgopc<0x28, 0x28, 0x35>, AMDGPUSample_b_o>; 1713defm IMAGE_SAMPLE_B_CL_O : MIMG_Sampler_WQM <mimgopc<0x48, 0x48, 0x36>, AMDGPUSample_b_cl_o>; 1714defm IMAGE_SAMPLE_LZ_O : MIMG_Sampler <mimgopc<0x29, 0x29, 0x37>, AMDGPUSample_lz_o>; 1715defm IMAGE_SAMPLE_C_O : MIMG_Sampler_WQM <mimgopc<0x2a, 0x2a, 0x38>, AMDGPUSample_c_o>; 1716defm IMAGE_SAMPLE_C_CL_O : MIMG_Sampler_WQM <mimgopc<0x49, 0x49, 0x39>, AMDGPUSample_c_cl_o>; 1717defm IMAGE_SAMPLE_C_D_O : MIMG_Sampler <mimgopc<0x2b, 0x2b, 0x3a>, AMDGPUSample_c_d_o>; 1718defm IMAGE_SAMPLE_C_D_CL_O : MIMG_Sampler <mimgopc<0x4a, 0x4a, 0x3b>, AMDGPUSample_c_d_cl_o>; 1719defm IMAGE_SAMPLE_C_L_O : MIMG_Sampler <mimgopc<0x2c, 0x2c, 0x3c>, AMDGPUSample_c_l_o>; 1720defm IMAGE_SAMPLE_C_B_CL_O : MIMG_Sampler_WQM <mimgopc<0x4b, 0x4b, 0x3e>, AMDGPUSample_c_b_cl_o>; 1721defm IMAGE_SAMPLE_C_B_O : MIMG_Sampler_WQM <mimgopc<0x2d, 0x2d, 0x3d>, AMDGPUSample_c_b_o>; 1722defm IMAGE_SAMPLE_C_LZ_O : MIMG_Sampler <mimgopc<0x2e, 0x2e, 0x3f>, AMDGPUSample_c_lz_o>; 1723defm IMAGE_GATHER4 : MIMG_Gather_WQM <mimgopc<0x2f, 0x2f, 0x40>, AMDGPUSample>; 1724defm IMAGE_GATHER4_CL : MIMG_Gather_WQM <mimgopc<0x60, 0x60, 0x41>, AMDGPUSample_cl>; 1725defm IMAGE_GATHER4_L : MIMG_Gather <mimgopc<0x30, 0x30, 0x44>, AMDGPUSample_l>; 1726defm IMAGE_GATHER4_B : MIMG_Gather_WQM <mimgopc<0x31, 0x31, 0x45>, AMDGPUSample_b>; 1727defm IMAGE_GATHER4_B_CL : MIMG_Gather_WQM <mimgopc<0x61, 0x61, 0x46>, AMDGPUSample_b_cl>; 1728defm IMAGE_GATHER4_LZ : MIMG_Gather <mimgopc<0x32, 0x32, 0x47>, AMDGPUSample_lz>; 1729defm IMAGE_GATHER4_C : MIMG_Gather_WQM <mimgopc<0x33, 0x33, 0x48>, AMDGPUSample_c>; 1730defm IMAGE_GATHER4_C_CL : MIMG_Gather_WQM <mimgopc<0x62, 0x62, 0x49>, AMDGPUSample_c_cl>; 1731defm IMAGE_GATHER4_C_L : MIMG_Gather <mimgopc<0x63, 0x63, 0x4c>, AMDGPUSample_c_l>; 1732defm IMAGE_GATHER4_C_B : MIMG_Gather_WQM <mimgopc<0x64, 0x64, 0x4d>, AMDGPUSample_c_b>; 1733defm IMAGE_GATHER4_C_B_CL : MIMG_Gather_WQM <mimgopc<0x65, 0x65, 0x4e>, AMDGPUSample_c_b_cl>; 1734defm IMAGE_GATHER4_C_LZ : MIMG_Gather <mimgopc<0x34, 0x34, 0x4f>, AMDGPUSample_c_lz>; 1735defm IMAGE_GATHER4_O : MIMG_Gather_WQM <mimgopc<0x35, 0x35, 0x50>, AMDGPUSample_o>; 1736defm IMAGE_GATHER4_CL_O : MIMG_Gather_WQM <mimgopc<MIMG.NOP, MIMG.NOP, 0x51>, AMDGPUSample_cl_o>; 1737defm IMAGE_GATHER4_L_O : MIMG_Gather <mimgopc<MIMG.NOP, MIMG.NOP, 0x54>, AMDGPUSample_l_o>; 1738defm IMAGE_GATHER4_B_O : MIMG_Gather_WQM <mimgopc<MIMG.NOP, MIMG.NOP, 0x55>, AMDGPUSample_b_o>; 1739defm IMAGE_GATHER4_B_CL_O : MIMG_Gather <mimgopc<MIMG.NOP, MIMG.NOP, 0x56>, AMDGPUSample_b_cl_o>; 1740defm IMAGE_GATHER4_LZ_O : MIMG_Gather <mimgopc<0x36, 0x36, 0x57>, AMDGPUSample_lz_o>; 1741defm IMAGE_GATHER4_C_O : MIMG_Gather_WQM <mimgopc<MIMG.NOP, MIMG.NOP, 0x58>, AMDGPUSample_c_o>; 1742defm IMAGE_GATHER4_C_CL_O : MIMG_Gather_WQM <mimgopc<MIMG.NOP, MIMG.NOP, 0x59>, AMDGPUSample_c_cl_o>; 1743defm IMAGE_GATHER4_C_L_O : MIMG_Gather <mimgopc<MIMG.NOP, MIMG.NOP, 0x5c>, AMDGPUSample_c_l_o>; 1744defm IMAGE_GATHER4_C_B_O : MIMG_Gather_WQM <mimgopc<MIMG.NOP, MIMG.NOP, 0x5d>, AMDGPUSample_c_b_o>; 1745defm IMAGE_GATHER4_C_B_CL_O : MIMG_Gather_WQM <mimgopc<MIMG.NOP, MIMG.NOP, 0x5e>, AMDGPUSample_c_b_cl_o>; 1746defm IMAGE_GATHER4_C_LZ_O : MIMG_Gather <mimgopc<0x37, 0x37, 0x5f>, AMDGPUSample_c_lz_o>; 1747 1748let OtherPredicates = [HasImageInsts, HasExtendedImageInsts, isGFX9Plus] in 1749defm IMAGE_GATHER4H : MIMG_Gather <mimgopc<0x90, 0x90, 0x61, 0x42>, AMDGPUSample, 1, "image_gather4h">; 1750 1751defm IMAGE_GET_LOD : MIMG_Sampler <mimgopc<0x38, 0x38, 0x60>, AMDGPUSample, 0, 1, 0, 1, "image_get_lod">; 1752 1753defm IMAGE_SAMPLE_CD : MIMG_Sampler <mimgopc<MIMG.NOP, MIMG.NOP, 0x68>, AMDGPUSample_cd>; 1754defm IMAGE_SAMPLE_CD_CL : MIMG_Sampler <mimgopc<MIMG.NOP, MIMG.NOP, 0x69>, AMDGPUSample_cd_cl>; 1755defm IMAGE_SAMPLE_C_CD : MIMG_Sampler <mimgopc<MIMG.NOP, MIMG.NOP, 0x6a>, AMDGPUSample_c_cd>; 1756defm IMAGE_SAMPLE_C_CD_CL : MIMG_Sampler <mimgopc<MIMG.NOP, MIMG.NOP, 0x6b>, AMDGPUSample_c_cd_cl>; 1757defm IMAGE_SAMPLE_CD_O : MIMG_Sampler <mimgopc<MIMG.NOP, MIMG.NOP, 0x6c>, AMDGPUSample_cd_o>; 1758defm IMAGE_SAMPLE_CD_CL_O : MIMG_Sampler <mimgopc<MIMG.NOP, MIMG.NOP, 0x6d>, AMDGPUSample_cd_cl_o>; 1759defm IMAGE_SAMPLE_C_CD_O : MIMG_Sampler <mimgopc<MIMG.NOP, MIMG.NOP, 0x6e>, AMDGPUSample_c_cd_o>; 1760defm IMAGE_SAMPLE_C_CD_CL_O : MIMG_Sampler <mimgopc<MIMG.NOP, MIMG.NOP, 0x6f>, AMDGPUSample_c_cd_cl_o>; 1761} // End OtherPredicates = [HasImageInsts, HasExtendedImageInsts] 1762 1763let OtherPredicates = [HasImageInsts, HasExtendedImageInsts, HasG16] in { 1764defm IMAGE_SAMPLE_D_G16 : MIMG_Sampler <mimgopc<0x39, 0x39, 0xa2>, AMDGPUSample_d, 0, 0, 1>; 1765defm IMAGE_SAMPLE_D_CL_G16 : MIMG_Sampler <mimgopc<0x5f, 0x5f, 0xa3>, AMDGPUSample_d_cl, 0, 0, 1>; 1766defm IMAGE_SAMPLE_C_D_G16 : MIMG_Sampler <mimgopc<0x3a, 0x3a, 0xaa>, AMDGPUSample_c_d, 0, 0, 1>; 1767defm IMAGE_SAMPLE_C_D_CL_G16 : MIMG_Sampler <mimgopc<0x54, 0x54, 0xab>, AMDGPUSample_c_d_cl, 0, 0, 1>; 1768defm IMAGE_SAMPLE_D_O_G16 : MIMG_Sampler <mimgopc<0x3b, 0x3b, 0xb2>, AMDGPUSample_d_o, 0, 0, 1>; 1769defm IMAGE_SAMPLE_D_CL_O_G16 : MIMG_Sampler <mimgopc<0x55, 0x55, 0xb3>, AMDGPUSample_d_cl_o, 0, 0, 1>; 1770defm IMAGE_SAMPLE_C_D_O_G16 : MIMG_Sampler <mimgopc<0x3c, 0x3c, 0xba>, AMDGPUSample_c_d_o, 0, 0, 1>; 1771defm IMAGE_SAMPLE_C_D_CL_O_G16 : MIMG_Sampler <mimgopc<0x56, 0x56, 0xbb>, AMDGPUSample_c_d_cl_o, 0, 0, 1>; 1772defm IMAGE_SAMPLE_CD_G16 : MIMG_Sampler <mimgopc<MIMG.NOP, MIMG.NOP, 0xe8>, AMDGPUSample_cd, 0, 0, 1>; 1773defm IMAGE_SAMPLE_CD_CL_G16 : MIMG_Sampler <mimgopc<MIMG.NOP, MIMG.NOP, 0xe9>, AMDGPUSample_cd_cl, 0, 0, 1>; 1774defm IMAGE_SAMPLE_C_CD_G16 : MIMG_Sampler <mimgopc<MIMG.NOP, MIMG.NOP, 0xea>, AMDGPUSample_c_cd, 0, 0, 1>; 1775defm IMAGE_SAMPLE_C_CD_CL_G16 : MIMG_Sampler <mimgopc<MIMG.NOP, MIMG.NOP, 0xeb>, AMDGPUSample_c_cd_cl, 0, 0, 1>; 1776defm IMAGE_SAMPLE_CD_O_G16 : MIMG_Sampler <mimgopc<MIMG.NOP, MIMG.NOP, 0xec>, AMDGPUSample_cd_o, 0, 0, 1>; 1777defm IMAGE_SAMPLE_CD_CL_O_G16 : MIMG_Sampler <mimgopc<MIMG.NOP, MIMG.NOP, 0xed>, AMDGPUSample_cd_cl_o, 0, 0, 1>; 1778defm IMAGE_SAMPLE_C_CD_O_G16 : MIMG_Sampler <mimgopc<MIMG.NOP, MIMG.NOP, 0xee>, AMDGPUSample_c_cd_o, 0, 0, 1>; 1779defm IMAGE_SAMPLE_C_CD_CL_O_G16 : MIMG_Sampler <mimgopc<MIMG.NOP, MIMG.NOP, 0xef>, AMDGPUSample_c_cd_cl_o, 0, 0, 1>; 1780} // End OtherPredicates = [HasImageInsts, HasExtendedImageInsts, HasG16] 1781 1782//def IMAGE_RSRC256 : MIMG_NoPattern_RSRC256 <"image_rsrc256", mimgopc<0x7e>>; 1783//def IMAGE_SAMPLER : MIMG_NoPattern_ <"image_sampler", mimgopc<0x7f>>; 1784 1785let OtherPredicates = [HasImageInsts, HasGFX10_AEncoding, isGFX10Only] in 1786defm IMAGE_MSAA_LOAD_X : MIMG_NoSampler <mimgopc<MIMG.NOP, MIMG.NOP, 0x80>, "image_msaa_load", 1, 0, 0, 1>; 1787 1788let OtherPredicates = [HasImageInsts, HasGFX10_AEncoding] in { 1789defm IMAGE_MSAA_LOAD : MIMG_MSAA_Load <mimgopc<0x18, 0x18, MIMG.NOP>, "image_msaa_load">; 1790 1791defm IMAGE_BVH_INTERSECT_RAY : MIMG_IntersectRay<mimgopc<0x19, 0x19, 0xe6>, "image_bvh_intersect_ray", 0, 0, 0>; 1792defm IMAGE_BVH_INTERSECT_RAY_a16 : MIMG_IntersectRay<mimgopc<0x19, 0x19, 0xe6>, "image_bvh_intersect_ray", 0, 1, 0>; 1793defm IMAGE_BVH64_INTERSECT_RAY : MIMG_IntersectRay<mimgopc<0x1a, 0x1a, 0xe7>, "image_bvh64_intersect_ray", 1, 0, 0>; 1794defm IMAGE_BVH64_INTERSECT_RAY_a16 : MIMG_IntersectRay<mimgopc<0x1a, 0x1a, 0xe7>, "image_bvh64_intersect_ray", 1, 1, 0>; 1795} // End OtherPredicates = [HasImageInsts, HasGFX10_AEncoding] 1796 1797defm IMAGE_BVH_DUAL_INTERSECT_RAY : MIMG_IntersectRay<mimgopc<0x80, MIMG.NOP, MIMG.NOP>, "image_bvh_dual_intersect_ray", 1, 0, 1>; 1798defm IMAGE_BVH8_INTERSECT_RAY : MIMG_IntersectRay<mimgopc<0x81, MIMG.NOP, MIMG.NOP>, "image_bvh8_intersect_ray", 1, 0, 0, 1>; 1799 1800let SubtargetPredicate = isGFX12Plus in { 1801 def : AMDGPUMnemonicAlias<"bvh_intersect_ray", "image_bvh_intersect_ray">; 1802 def : AMDGPUMnemonicAlias<"bvh64_intersect_ray", "image_bvh64_intersect_ray">; 1803 def : AMDGPUMnemonicAlias<"bvh_dual_intersect_ray", "image_bvh_dual_intersect_ray">; 1804 def : AMDGPUMnemonicAlias<"bvh8_intersect_ray", "image_bvh8_intersect_ray">; 1805} 1806 1807} // End let OtherPredicates = [HasImageInsts] 1808 1809/********** ========================================= **********/ 1810/********** Table of dimension-aware image intrinsics **********/ 1811/********** ========================================= **********/ 1812 1813class ImageDimIntrinsicInfo<AMDGPUImageDimIntrinsic I> { 1814 Intrinsic Intr = I; 1815 MIMGBaseOpcode BaseOpcode = !cast<MIMGBaseOpcode>(!strconcat("IMAGE_", I.P.OpMod)); 1816 AMDGPUDimProps Dim = I.P.Dim; 1817 AMDGPUImageDimIntrinsicEval DimEval = AMDGPUImageDimIntrinsicEval<I.P>; 1818 1819 bits<8> NumOffsetArgs = DimEval.NumOffsetArgs; 1820 bits<8> NumBiasArgs = DimEval.NumBiasArgs; 1821 bits<8> NumZCompareArgs = DimEval.NumZCompareArgs; 1822 bits<8> NumGradients = DimEval.NumGradientArgs; 1823 bits<8> NumDmask = DimEval.NumDmaskArgs; 1824 bits<8> NumData = DimEval.NumDataArgs; 1825 bits<8> NumVAddrs = DimEval.NumVAddrArgs; 1826 bits<8> NumArgs = !add(DimEval.CachePolicyArgIndex, 1); 1827 1828 bits<8> DMaskIndex = DimEval.DmaskArgIndex; 1829 bits<8> VAddrStart = DimEval.VAddrArgIndex; 1830 bits<8> OffsetIndex = DimEval.OffsetArgIndex; 1831 bits<8> BiasIndex = DimEval.BiasArgIndex; 1832 bits<8> ZCompareIndex = DimEval.ZCompareArgIndex; 1833 bits<8> GradientStart = DimEval.GradientArgIndex; 1834 bits<8> CoordStart = DimEval.CoordArgIndex; 1835 bits<8> LodIndex = DimEval.LodArgIndex; 1836 bits<8> MipIndex = DimEval.MipArgIndex; 1837 bits<8> VAddrEnd = !add(DimEval.VAddrArgIndex, DimEval.NumVAddrArgs); 1838 bits<8> RsrcIndex = DimEval.RsrcArgIndex; 1839 bits<8> SampIndex = DimEval.SampArgIndex; 1840 bits<8> UnormIndex = DimEval.UnormArgIndex; 1841 bits<8> TexFailCtrlIndex = DimEval.TexFailCtrlArgIndex; 1842 bits<8> CachePolicyIndex = DimEval.CachePolicyArgIndex; 1843 1844 bits<8> BiasTyArg = !add(I.P.NumRetAndDataAnyTypes, 1845 !if(!eq(NumOffsetArgs, 0), 0, I.P.ExtraAddrArgs[0].Type.isAny)); 1846 bits<8> GradientTyArg = !add(I.P.NumRetAndDataAnyTypes, 1847 !foldl(0, I.P.ExtraAddrArgs, cnt, arg, !add(cnt, arg.Type.isAny))); 1848 bits<8> CoordTyArg = !add(GradientTyArg, !if(I.P.Gradients, 1, 0)); 1849} 1850 1851def ImageDimIntrinsicTable : GenericTable { 1852 let FilterClass = "ImageDimIntrinsicInfo"; 1853 let Fields = ["Intr", "BaseOpcode", "Dim", "NumOffsetArgs", "NumBiasArgs", "NumZCompareArgs", "NumGradients", "NumDmask", "NumData", "NumVAddrs", "NumArgs", 1854 "DMaskIndex", "VAddrStart", "OffsetIndex", "BiasIndex", "ZCompareIndex", "GradientStart", "CoordStart", "LodIndex", "MipIndex", "VAddrEnd", 1855 "RsrcIndex", "SampIndex", "UnormIndex", "TexFailCtrlIndex", "CachePolicyIndex", 1856 "BiasTyArg", "GradientTyArg", "CoordTyArg"]; 1857 string TypeOf_BaseOpcode = "MIMGBaseOpcode"; 1858 string TypeOf_Dim = "MIMGDim"; 1859 1860 let PrimaryKey = ["Intr"]; 1861 let PrimaryKeyName = "getImageDimIntrinsicInfo"; 1862 let PrimaryKeyEarlyOut = 1; 1863} 1864 1865def getImageDimIntrinsicByBaseOpcode : SearchIndex { 1866 let Table = ImageDimIntrinsicTable; 1867 let Key = ["BaseOpcode", "Dim"]; 1868} 1869 1870foreach intr = !listconcat(AMDGPUImageDimIntrinsics, 1871 AMDGPUImageDimAtomicIntrinsics) in { 1872 def : ImageDimIntrinsicInfo<intr>; 1873} 1874 1875// L to LZ Optimization Mapping 1876def : MIMGLZMapping<IMAGE_SAMPLE_L, IMAGE_SAMPLE_LZ>; 1877def : MIMGLZMapping<IMAGE_SAMPLE_C_L, IMAGE_SAMPLE_C_LZ>; 1878def : MIMGLZMapping<IMAGE_SAMPLE_L_O, IMAGE_SAMPLE_LZ_O>; 1879def : MIMGLZMapping<IMAGE_SAMPLE_C_L_O, IMAGE_SAMPLE_C_LZ_O>; 1880def : MIMGLZMapping<IMAGE_GATHER4_L, IMAGE_GATHER4_LZ>; 1881def : MIMGLZMapping<IMAGE_GATHER4_C_L, IMAGE_GATHER4_C_LZ>; 1882def : MIMGLZMapping<IMAGE_GATHER4_L_O, IMAGE_GATHER4_LZ_O>; 1883def : MIMGLZMapping<IMAGE_GATHER4_C_L_O, IMAGE_GATHER4_C_LZ_O>; 1884def : MIMGLZMapping<IMAGE_SAMPLE_L_nortn, IMAGE_SAMPLE_LZ_nortn>; 1885def : MIMGLZMapping<IMAGE_SAMPLE_C_L_nortn, IMAGE_SAMPLE_C_LZ_nortn>; 1886def : MIMGLZMapping<IMAGE_SAMPLE_L_O_nortn, IMAGE_SAMPLE_LZ_O_nortn>; 1887def : MIMGLZMapping<IMAGE_SAMPLE_C_L_O_nortn, IMAGE_SAMPLE_C_LZ_O_nortn>; 1888 1889// MIP to NONMIP Optimization Mapping 1890def : MIMGMIPMapping<IMAGE_LOAD_MIP, IMAGE_LOAD>; 1891def : MIMGMIPMapping<IMAGE_STORE_MIP, IMAGE_STORE>; 1892 1893// Bias to NoBias Optimization Mapping 1894def : MIMGBiasMapping<IMAGE_SAMPLE_B, IMAGE_SAMPLE>; 1895def : MIMGBiasMapping<IMAGE_SAMPLE_B_CL, IMAGE_SAMPLE_CL>; 1896def : MIMGBiasMapping<IMAGE_SAMPLE_C_B, IMAGE_SAMPLE_C>; 1897def : MIMGBiasMapping<IMAGE_SAMPLE_C_B_CL, IMAGE_SAMPLE_C_CL>; 1898def : MIMGBiasMapping<IMAGE_SAMPLE_B_O, IMAGE_SAMPLE_O>; 1899def : MIMGBiasMapping<IMAGE_SAMPLE_B_CL_O, IMAGE_SAMPLE_CL_O>; 1900def : MIMGBiasMapping<IMAGE_SAMPLE_C_B_O, IMAGE_SAMPLE_C_O>; 1901def : MIMGBiasMapping<IMAGE_SAMPLE_C_B_CL_O, IMAGE_SAMPLE_C_CL_O>; 1902def : MIMGBiasMapping<IMAGE_GATHER4_B, IMAGE_GATHER4>; 1903def : MIMGBiasMapping<IMAGE_GATHER4_B_CL, IMAGE_GATHER4_CL>; 1904def : MIMGBiasMapping<IMAGE_GATHER4_C_B, IMAGE_GATHER4_C>; 1905def : MIMGBiasMapping<IMAGE_GATHER4_C_B_CL, IMAGE_GATHER4_C_CL>; 1906def : MIMGBiasMapping<IMAGE_GATHER4_B_O, IMAGE_GATHER4_O>; 1907def : MIMGBiasMapping<IMAGE_GATHER4_B_CL_O, IMAGE_GATHER4_CL_O>; 1908def : MIMGBiasMapping<IMAGE_GATHER4_C_B_O, IMAGE_GATHER4_C_O>; 1909def : MIMGBiasMapping<IMAGE_GATHER4_C_B_CL_O, IMAGE_GATHER4_C_CL_O>; 1910def : MIMGBiasMapping<IMAGE_SAMPLE_B_nortn, IMAGE_SAMPLE_nortn>; 1911def : MIMGBiasMapping<IMAGE_SAMPLE_B_CL_nortn, IMAGE_SAMPLE_CL_nortn>; 1912def : MIMGBiasMapping<IMAGE_SAMPLE_C_B_nortn, IMAGE_SAMPLE_C_nortn>; 1913def : MIMGBiasMapping<IMAGE_SAMPLE_C_B_CL_nortn, IMAGE_SAMPLE_C_CL_nortn>; 1914def : MIMGBiasMapping<IMAGE_SAMPLE_B_O_nortn, IMAGE_SAMPLE_O_nortn>; 1915def : MIMGBiasMapping<IMAGE_SAMPLE_B_CL_O_nortn, IMAGE_SAMPLE_CL_O_nortn>; 1916def : MIMGBiasMapping<IMAGE_SAMPLE_C_B_O_nortn, IMAGE_SAMPLE_C_O_nortn>; 1917def : MIMGBiasMapping<IMAGE_SAMPLE_C_B_CL_O_nortn, IMAGE_SAMPLE_C_CL_O_nortn>; 1918 1919// Offset to NoOffset Optimization Mapping 1920def : MIMGOffsetMapping<IMAGE_SAMPLE_O, IMAGE_SAMPLE>; 1921def : MIMGOffsetMapping<IMAGE_SAMPLE_CL_O, IMAGE_SAMPLE_CL>; 1922def : MIMGOffsetMapping<IMAGE_SAMPLE_D_O, IMAGE_SAMPLE_D>; 1923def : MIMGOffsetMapping<IMAGE_SAMPLE_D_CL_O, IMAGE_SAMPLE_D_CL>; 1924def : MIMGOffsetMapping<IMAGE_SAMPLE_D_O_G16, IMAGE_SAMPLE_D_G16>; 1925def : MIMGOffsetMapping<IMAGE_SAMPLE_D_CL_O_G16, IMAGE_SAMPLE_D_CL_G16>; 1926def : MIMGOffsetMapping<IMAGE_SAMPLE_L_O, IMAGE_SAMPLE_L>; 1927def : MIMGOffsetMapping<IMAGE_SAMPLE_B_O, IMAGE_SAMPLE_B>; 1928def : MIMGOffsetMapping<IMAGE_SAMPLE_B_CL_O, IMAGE_SAMPLE_B_CL>; 1929def : MIMGOffsetMapping<IMAGE_SAMPLE_LZ_O, IMAGE_SAMPLE_LZ>; 1930def : MIMGOffsetMapping<IMAGE_SAMPLE_C_O, IMAGE_SAMPLE_C>; 1931def : MIMGOffsetMapping<IMAGE_SAMPLE_C_CL_O, IMAGE_SAMPLE_C_CL>; 1932def : MIMGOffsetMapping<IMAGE_SAMPLE_C_D_O, IMAGE_SAMPLE_C_D>; 1933def : MIMGOffsetMapping<IMAGE_SAMPLE_C_D_CL_O, IMAGE_SAMPLE_C_D_CL>; 1934def : MIMGOffsetMapping<IMAGE_SAMPLE_C_D_O_G16, IMAGE_SAMPLE_C_D_G16>; 1935def : MIMGOffsetMapping<IMAGE_SAMPLE_C_D_CL_O_G16, IMAGE_SAMPLE_C_D_CL_G16>; 1936def : MIMGOffsetMapping<IMAGE_SAMPLE_C_L_O, IMAGE_SAMPLE_C_L>; 1937def : MIMGOffsetMapping<IMAGE_SAMPLE_C_B_CL_O, IMAGE_SAMPLE_C_B_CL>; 1938def : MIMGOffsetMapping<IMAGE_SAMPLE_C_B_O, IMAGE_SAMPLE_C_B>; 1939def : MIMGOffsetMapping<IMAGE_SAMPLE_C_LZ_O, IMAGE_SAMPLE_C_LZ>; 1940def : MIMGOffsetMapping<IMAGE_GATHER4_O, IMAGE_GATHER4>; 1941def : MIMGOffsetMapping<IMAGE_GATHER4_CL_O, IMAGE_GATHER4_CL>; 1942def : MIMGOffsetMapping<IMAGE_GATHER4_L_O, IMAGE_GATHER4_L>; 1943def : MIMGOffsetMapping<IMAGE_GATHER4_B_O, IMAGE_GATHER4_B>; 1944def : MIMGOffsetMapping<IMAGE_GATHER4_B_CL_O, IMAGE_GATHER4_B_CL>; 1945def : MIMGOffsetMapping<IMAGE_GATHER4_LZ_O, IMAGE_GATHER4_LZ>; 1946def : MIMGOffsetMapping<IMAGE_GATHER4_C_O, IMAGE_GATHER4_C>; 1947def : MIMGOffsetMapping<IMAGE_GATHER4_C_CL_O, IMAGE_GATHER4_C_CL>; 1948def : MIMGOffsetMapping<IMAGE_GATHER4_C_L_O, IMAGE_GATHER4_C_L>; 1949def : MIMGOffsetMapping<IMAGE_GATHER4_C_B_O, IMAGE_GATHER4_C_B>; 1950def : MIMGOffsetMapping<IMAGE_GATHER4_C_B_CL_O, IMAGE_GATHER4_C_B_CL>; 1951def : MIMGOffsetMapping<IMAGE_GATHER4_C_LZ_O, IMAGE_GATHER4_C_LZ>; 1952def : MIMGOffsetMapping<IMAGE_SAMPLE_CD_O, IMAGE_SAMPLE_CD>; 1953def : MIMGOffsetMapping<IMAGE_SAMPLE_CD_CL_O, IMAGE_SAMPLE_CD_CL>; 1954def : MIMGOffsetMapping<IMAGE_SAMPLE_C_CD_O, IMAGE_SAMPLE_C_CD>; 1955def : MIMGOffsetMapping<IMAGE_SAMPLE_C_CD_CL_O, IMAGE_SAMPLE_C_CD_CL>; 1956def : MIMGOffsetMapping<IMAGE_SAMPLE_CD_O_G16, IMAGE_SAMPLE_CD_G16>; 1957def : MIMGOffsetMapping<IMAGE_SAMPLE_CD_CL_O_G16, IMAGE_SAMPLE_CD_CL_G16>; 1958def : MIMGOffsetMapping<IMAGE_SAMPLE_C_CD_O_G16, IMAGE_SAMPLE_C_CD_G16>; 1959def : MIMGOffsetMapping<IMAGE_SAMPLE_C_CD_CL_O_G16, IMAGE_SAMPLE_C_CD_CL_G16>; 1960def : MIMGOffsetMapping<IMAGE_SAMPLE_O_nortn, IMAGE_SAMPLE_nortn>; 1961def : MIMGOffsetMapping<IMAGE_SAMPLE_CL_O_nortn, IMAGE_SAMPLE_CL_nortn>; 1962def : MIMGOffsetMapping<IMAGE_SAMPLE_D_O_nortn, IMAGE_SAMPLE_D_nortn>; 1963def : MIMGOffsetMapping<IMAGE_SAMPLE_D_CL_O_nortn, IMAGE_SAMPLE_D_CL_nortn>; 1964def : MIMGOffsetMapping<IMAGE_SAMPLE_D_O_G16_nortn, IMAGE_SAMPLE_D_G16_nortn>; 1965def : MIMGOffsetMapping<IMAGE_SAMPLE_D_CL_O_G16_nortn, IMAGE_SAMPLE_D_CL_G16_nortn>; 1966def : MIMGOffsetMapping<IMAGE_SAMPLE_L_O_nortn, IMAGE_SAMPLE_L_nortn>; 1967def : MIMGOffsetMapping<IMAGE_SAMPLE_B_O_nortn, IMAGE_SAMPLE_B_nortn>; 1968def : MIMGOffsetMapping<IMAGE_SAMPLE_B_CL_O_nortn, IMAGE_SAMPLE_B_CL_nortn>; 1969def : MIMGOffsetMapping<IMAGE_SAMPLE_LZ_O_nortn, IMAGE_SAMPLE_LZ_nortn>; 1970def : MIMGOffsetMapping<IMAGE_SAMPLE_C_O_nortn, IMAGE_SAMPLE_C_nortn>; 1971def : MIMGOffsetMapping<IMAGE_SAMPLE_C_CL_O_nortn, IMAGE_SAMPLE_C_CL_nortn>; 1972def : MIMGOffsetMapping<IMAGE_SAMPLE_C_D_O_nortn, IMAGE_SAMPLE_C_D_nortn>; 1973def : MIMGOffsetMapping<IMAGE_SAMPLE_C_D_CL_O_nortn, IMAGE_SAMPLE_C_D_CL_nortn>; 1974def : MIMGOffsetMapping<IMAGE_SAMPLE_C_D_O_G16_nortn, IMAGE_SAMPLE_C_D_G16_nortn>; 1975def : MIMGOffsetMapping<IMAGE_SAMPLE_C_D_CL_O_G16_nortn, IMAGE_SAMPLE_C_D_CL_G16_nortn>; 1976def : MIMGOffsetMapping<IMAGE_SAMPLE_C_L_O_nortn, IMAGE_SAMPLE_C_L_nortn>; 1977def : MIMGOffsetMapping<IMAGE_SAMPLE_C_B_CL_O_nortn, IMAGE_SAMPLE_C_B_CL_nortn>; 1978def : MIMGOffsetMapping<IMAGE_SAMPLE_C_B_O_nortn, IMAGE_SAMPLE_C_B_nortn>; 1979def : MIMGOffsetMapping<IMAGE_SAMPLE_C_LZ_O_nortn, IMAGE_SAMPLE_C_LZ_nortn>; 1980def : MIMGOffsetMapping<IMAGE_SAMPLE_CD_O_nortn, IMAGE_SAMPLE_CD>; 1981def : MIMGOffsetMapping<IMAGE_SAMPLE_CD_CL_O_nortn, IMAGE_SAMPLE_CD_CL_nortn>; 1982def : MIMGOffsetMapping<IMAGE_SAMPLE_C_CD_O_nortn, IMAGE_SAMPLE_C_CD_nortn>; 1983def : MIMGOffsetMapping<IMAGE_SAMPLE_C_CD_CL_O_nortn, IMAGE_SAMPLE_C_CD_CL_nortn>; 1984def : MIMGOffsetMapping<IMAGE_SAMPLE_CD_O_G16_nortn, IMAGE_SAMPLE_CD_G16_nortn>; 1985def : MIMGOffsetMapping<IMAGE_SAMPLE_CD_CL_O_G16_nortn, IMAGE_SAMPLE_CD_CL_G16_nortn>; 1986def : MIMGOffsetMapping<IMAGE_SAMPLE_C_CD_O_G16_nortn, IMAGE_SAMPLE_C_CD_G16_nortn>; 1987def : MIMGOffsetMapping<IMAGE_SAMPLE_C_CD_CL_O_G16_nortn, IMAGE_SAMPLE_C_CD_CL_G16_nortn>; 1988 1989// G to G16 Optimization Mapping 1990def : MIMGG16Mapping<IMAGE_SAMPLE_D, IMAGE_SAMPLE_D_G16>; 1991def : MIMGG16Mapping<IMAGE_SAMPLE_D_CL, IMAGE_SAMPLE_D_CL_G16>; 1992def : MIMGG16Mapping<IMAGE_SAMPLE_C_D, IMAGE_SAMPLE_C_D_G16>; 1993def : MIMGG16Mapping<IMAGE_SAMPLE_C_D_CL, IMAGE_SAMPLE_C_D_CL_G16>; 1994def : MIMGG16Mapping<IMAGE_SAMPLE_D_O, IMAGE_SAMPLE_D_O_G16>; 1995def : MIMGG16Mapping<IMAGE_SAMPLE_D_CL_O, IMAGE_SAMPLE_D_CL_O_G16>; 1996def : MIMGG16Mapping<IMAGE_SAMPLE_C_D_O, IMAGE_SAMPLE_C_D_O_G16>; 1997def : MIMGG16Mapping<IMAGE_SAMPLE_C_D_CL_O, IMAGE_SAMPLE_C_D_CL_O_G16>; 1998def : MIMGG16Mapping<IMAGE_SAMPLE_CD, IMAGE_SAMPLE_CD_G16>; 1999def : MIMGG16Mapping<IMAGE_SAMPLE_CD_CL, IMAGE_SAMPLE_CD_CL_G16>; 2000def : MIMGG16Mapping<IMAGE_SAMPLE_C_CD, IMAGE_SAMPLE_C_CD_G16>; 2001def : MIMGG16Mapping<IMAGE_SAMPLE_C_CD_CL, IMAGE_SAMPLE_C_CD_CL_G16>; 2002def : MIMGG16Mapping<IMAGE_SAMPLE_CD_O, IMAGE_SAMPLE_CD_O_G16>; 2003def : MIMGG16Mapping<IMAGE_SAMPLE_CD_CL_O, IMAGE_SAMPLE_CD_CL_O_G16>; 2004def : MIMGG16Mapping<IMAGE_SAMPLE_C_CD_O, IMAGE_SAMPLE_C_CD_O_G16>; 2005def : MIMGG16Mapping<IMAGE_SAMPLE_C_CD_CL_O, IMAGE_SAMPLE_C_CD_CL_O_G16>; 2006def : MIMGG16Mapping<IMAGE_SAMPLE_D_nortn, IMAGE_SAMPLE_D_G16_nortn>; 2007def : MIMGG16Mapping<IMAGE_SAMPLE_D_CL_nortn, IMAGE_SAMPLE_D_CL_G16_nortn>; 2008def : MIMGG16Mapping<IMAGE_SAMPLE_C_D_nortn, IMAGE_SAMPLE_C_D_G16_nortn>; 2009def : MIMGG16Mapping<IMAGE_SAMPLE_C_D_CL_nortn, IMAGE_SAMPLE_C_D_CL_G16_nortn>; 2010def : MIMGG16Mapping<IMAGE_SAMPLE_D_O_nortn, IMAGE_SAMPLE_D_O_G16_nortn>; 2011def : MIMGG16Mapping<IMAGE_SAMPLE_D_CL_O_nortn, IMAGE_SAMPLE_D_CL_O_G16_nortn>; 2012def : MIMGG16Mapping<IMAGE_SAMPLE_C_D_O_nortn, IMAGE_SAMPLE_C_D_O_G16_nortn>; 2013def : MIMGG16Mapping<IMAGE_SAMPLE_C_D_CL_O_nortn, IMAGE_SAMPLE_C_D_CL_O_G16_nortn>; 2014def : MIMGG16Mapping<IMAGE_SAMPLE_CD_nortn, IMAGE_SAMPLE_CD_G16_nortn>; 2015def : MIMGG16Mapping<IMAGE_SAMPLE_CD_CL_nortn, IMAGE_SAMPLE_CD_CL_G16_nortn>; 2016def : MIMGG16Mapping<IMAGE_SAMPLE_C_CD_nortn, IMAGE_SAMPLE_C_CD_G16_nortn>; 2017def : MIMGG16Mapping<IMAGE_SAMPLE_C_CD_CL_nortn, IMAGE_SAMPLE_C_CD_CL_G16_nortn>; 2018def : MIMGG16Mapping<IMAGE_SAMPLE_CD_O_nortn, IMAGE_SAMPLE_CD_O_G16_nortn>; 2019def : MIMGG16Mapping<IMAGE_SAMPLE_CD_CL_O_nortn, IMAGE_SAMPLE_CD_CL_O_G16_nortn>; 2020def : MIMGG16Mapping<IMAGE_SAMPLE_C_CD_O_nortn, IMAGE_SAMPLE_C_CD_O_G16_nortn>; 2021def : MIMGG16Mapping<IMAGE_SAMPLE_C_CD_CL_O_nortn, IMAGE_SAMPLE_C_CD_CL_O_G16_nortn>; 2022 2023//===----------------------------------------------------------------------===// 2024// VIMAGE Tensor Instructions 2025//===----------------------------------------------------------------------===// 2026 2027class VIMAGE_TENSOR_Pseudo<string opName, bit _UpTo2D = 0> : 2028 InstSI<(outs ), (ins ), "", []>, 2029 SIMCInstr<opName#!if(_UpTo2D, "_D2", ""), SIEncodingFamily.NONE> { 2030 2031 let isPseudo = 1; 2032 let isCodeGenOnly = 1; 2033 string Mnemonic = opName; 2034 2035 let VALU = 1; 2036 let maybeAtomic = 0; 2037 let TENSOR_CNT = 1; 2038 let mayLoad = 1; 2039 let mayStore = 1; 2040 let Uses = [EXEC, TENSORcnt]; 2041 let Defs = [TENSORcnt]; 2042 let SchedRW = [WriteVMEM, WriteLDS]; 2043 let UseNamedOperandTable = 1; 2044 let hasSideEffects = 0; 2045 2046 bit UpTo2D = _UpTo2D; 2047 let InOperandList = !if(UpTo2D, (ins SReg_128:$vaddr0, SReg_256:$vaddr1, R128A16:$r128, CPol:$cpol), 2048 (ins SReg_128:$vaddr0, SReg_256:$vaddr1, SReg_128:$vaddr2, 2049 SReg_128:$vaddr3, R128A16:$r128, CPol:$cpol)); 2050 string AsmOperands = " $vaddr0, $vaddr1"#!if(UpTo2D, "", ", $vaddr2, $vaddr3")#"$r128$cpol"; 2051} 2052 2053let SubtargetPredicate = isGFX1250Plus in { 2054def TENSOR_LOAD_TO_LDS : VIMAGE_TENSOR_Pseudo<"tensor_load_to_lds">; 2055def TENSOR_STORE_FROM_LDS : VIMAGE_TENSOR_Pseudo<"tensor_store_from_lds">; 2056def TENSOR_LOAD_TO_LDS_D2 : VIMAGE_TENSOR_Pseudo<"tensor_load_to_lds", 1>; 2057def TENSOR_STORE_FROM_LDS_D2 : VIMAGE_TENSOR_Pseudo<"tensor_store_from_lds", 1>; 2058} // End SubtargetPredicate = isGFX1250Plus. 2059 2060class TensorPat <VIMAGE_TENSOR_Pseudo inst, SDPatternOperator node> : GCNPat < 2061 (node v4i32:$vaddr0, v8i32:$vaddr1, v4i32:$vaddr2, v4i32:$vaddr3, (i32 timm:$cpol)), 2062 (inst $vaddr0, $vaddr1, $vaddr2, $vaddr3, 0, $cpol) 2063>; 2064 2065class TensorD2Pat <VIMAGE_TENSOR_Pseudo inst, SDPatternOperator node> : GCNPat < 2066 (node v4i32:$vaddr0, v8i32:$vaddr1, (i32 timm:$cpol)), 2067 (inst $vaddr0, $vaddr1, 0, $cpol) 2068>; 2069 2070let SubtargetPredicate = isGFX1250Plus in { 2071def : TensorPat <TENSOR_LOAD_TO_LDS, int_amdgcn_tensor_load_to_lds>; 2072def : TensorPat <TENSOR_STORE_FROM_LDS, int_amdgcn_tensor_store_from_lds>; 2073def : TensorD2Pat <TENSOR_LOAD_TO_LDS_D2, int_amdgcn_tensor_load_to_lds_d2>; 2074def : TensorD2Pat <TENSOR_STORE_FROM_LDS_D2, int_amdgcn_tensor_store_from_lds_d2>; 2075} 2076 2077class VIMAGE_TENSOR_Real <bits<8> op, VIMAGE_TENSOR_Pseudo ps, string opName = ps.Mnemonic> : 2078 InstSI <ps.OutOperandList, ps.InOperandList, opName # ps.AsmOperands, []>, 2079 VIMAGEe<op> { 2080 2081 // copy relevant pseudo op flags 2082 let SubtargetPredicate = ps.SubtargetPredicate; 2083 let TSFlags = ps.TSFlags; 2084 let mayLoad = ps.mayLoad; 2085 let mayStore = ps.mayStore; 2086 let UseNamedOperandTable = ps.UseNamedOperandTable; 2087 let SchedRW = ps.SchedRW; 2088 2089 // D# group 2 and 3 set to NULL for 2D or less. 2090 let vaddr2 = !if(ps.UpTo2D, !cast<int>(SGPR_NULL_gfx11plus.HWEncoding), ?); 2091 let vaddr3 = !if(ps.UpTo2D, !cast<int>(SGPR_NULL_gfx11plus.HWEncoding), ?); 2092 2093 // set to 0 based on SPG. 2094 let vaddr4 = 0; 2095 let rsrc = 0; 2096 let vdata = 0; 2097 let d16 = 0; 2098 let a16 = 0; 2099 let tfe = 0; 2100 let dmask = 1; // sp3 2101 let dim = 1; // sp3 2102} 2103 2104multiclass VIMAGE_TENSOR_Real_gfx1250<bits<8> op> { 2105 let AssemblerPredicate = isGFX1250Plus, DecoderNamespace = "GFX1250" in { 2106 foreach DSuffix = ["_D2", ""] in { 2107 defvar ps = !cast<VIMAGE_TENSOR_Pseudo>(NAME # DSuffix); 2108 def DSuffix # _gfx1250 : VIMAGE_TENSOR_Real<op, ps, ps.Mnemonic>, 2109 SIMCInstr<ps.PseudoInstr, SIEncodingFamily.GFX1250>; 2110 } 2111 } 2112} 2113 2114defm TENSOR_LOAD_TO_LDS : VIMAGE_TENSOR_Real_gfx1250<0xc4>; 2115defm TENSOR_STORE_FROM_LDS : VIMAGE_TENSOR_Real_gfx1250<0xc5>; 2116