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