xref: /freebsd/contrib/llvm-project/llvm/lib/Target/AMDGPU/DSDIRInstructions.td (revision 6580f5c38dd5b01aeeaed16b370f1a12423437f0)
1//===-- DSDIRInstructions.td - LDS/VDS Direct 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//===----------------------------------------------------------------------===//
10// LDSDIR/VDSDIR encoding (LDSDIR is gfx11, VDSDIR is gfx12+)
11//===----------------------------------------------------------------------===//
12
13class LDSDIRe<bits<2> op, bit is_direct> : Enc32 {
14  // encoding fields
15  bits<2> attrchan;
16  bits<6> attr;
17  bits<4> waitvdst;
18  bits<8> vdst;
19
20  // encoding
21  let Inst{31-24} = 0xce; // encoding
22  let Inst{23-22} = 0x0; // reserved
23  let Inst{21-20} = op;
24  let Inst{19-16} = waitvdst;
25  let Inst{15-10} = !if(is_direct, ?, attr);
26  let Inst{9-8} = !if(is_direct, ?, attrchan);
27  let Inst{7-0} = vdst;
28}
29
30class VDSDIRe<bits<2> op, bit is_direct> : Enc32 {
31  // encoding fields
32  bits<2> attrchan;
33  bits<6> attr;
34  bits<4> waitvdst;
35  bits<8> vdst;
36  bits<1> waitvsrc;
37
38  // encoding
39  let Inst{31-24} = 0xce; // encoding
40  let Inst{23} = waitvsrc;
41  let Inst{22} = 0x0; // reserved
42  let Inst{21-20} = op;
43  let Inst{19-16} = waitvdst;
44  let Inst{15-10} = !if(is_direct, ?, attr);
45  let Inst{9-8} = !if(is_direct, ?, attrchan);
46  let Inst{7-0} = vdst;
47}
48
49//===----------------------------------------------------------------------===//
50// LDSDIR/VDSDIR Classes
51//===----------------------------------------------------------------------===//
52
53class LDSDIR_getIns<bit direct> {
54  dag ret = !if(direct,
55    (ins wait_vdst:$waitvdst),
56    (ins InterpAttr:$attr, InterpAttrChan:$attrchan, wait_vdst:$waitvdst)
57  );
58}
59
60class VDSDIR_getIns<bit direct> {
61  dag ret = !if(direct,
62    (ins wait_va_vdst:$waitvdst, wait_va_vsrc:$waitvsrc),
63    (ins InterpAttr:$attr, InterpAttrChan:$attrchan, wait_va_vdst:$waitvdst,
64         wait_va_vsrc:$waitvsrc)
65  );
66}
67
68class DSDIR_Common<string opName, string asm = "", dag ins, bit direct> :
69  InstSI<(outs VGPR_32:$vdst), ins, asm> {
70  let LDSDIR = 1;
71  let EXP_CNT = 1;
72
73  let hasSideEffects = 0;
74  let mayLoad = 1;
75  let mayStore = 0;
76  let maybeAtomic = 0;
77
78  string Mnemonic = opName;
79  let UseNamedOperandTable = 1;
80
81  let Uses = [M0, EXEC];
82  let DisableWQM = 0;
83  let SchedRW = [WriteLDS];
84
85  bit is_direct;
86  let is_direct = direct;
87}
88
89class DSDIR_Pseudo<string opName, dag ins, bit direct> :
90  DSDIR_Common<opName, "", ins, direct>,
91  SIMCInstr<opName, SIEncodingFamily.NONE> {
92  let isPseudo = 1;
93  let isCodeGenOnly = 1;
94}
95
96class LDSDIR_getAsm<bit direct> {
97  string ret = !if(direct,
98    " $vdst$waitvdst",
99    " $vdst, $attr$attrchan$waitvdst"
100  );
101}
102
103class VDSDIR_getAsm<bit direct> {
104  string ret = !if(direct,
105    " $vdst$waitvdst$waitvsrc",
106    " $vdst, $attr$attrchan$waitvdst$waitvsrc"
107  );
108}
109
110class DSDIR_Real<DSDIR_Pseudo lds, dag ins, string asm, int subtarget> :
111  DSDIR_Common<lds.Mnemonic,
112               lds.Mnemonic # asm,
113               ins,
114               lds.is_direct>,
115  SIMCInstr <lds.Mnemonic, subtarget> {
116  let isPseudo = 0;
117  let isCodeGenOnly = 0;
118}
119
120//===----------------------------------------------------------------------===//
121// LDS/VDS Direct Instructions
122//===----------------------------------------------------------------------===//
123
124let SubtargetPredicate = isGFX11Only in {
125
126def LDS_DIRECT_LOAD : DSDIR_Pseudo<"lds_direct_load", LDSDIR_getIns<1>.ret, 1>;
127def LDS_PARAM_LOAD : DSDIR_Pseudo<"lds_param_load", LDSDIR_getIns<0>.ret, 0>;
128
129def : GCNPat <
130  (f32 (int_amdgcn_lds_direct_load M0)),
131  (LDS_DIRECT_LOAD 0)
132>;
133
134def : GCNPat <
135  (f32 (int_amdgcn_lds_param_load timm:$attrchan, timm:$attr, M0)),
136  (LDS_PARAM_LOAD timm:$attr, timm:$attrchan, 0)
137>;
138
139} // End SubtargetPredicate = isGFX11Only
140
141let SubtargetPredicate = isGFX12Plus in {
142
143def DS_DIRECT_LOAD : DSDIR_Pseudo<"ds_direct_load", VDSDIR_getIns<1>.ret, 1>;
144def DS_PARAM_LOAD : DSDIR_Pseudo<"ds_param_load", VDSDIR_getIns<0>.ret, 0>;
145
146def : GCNPat <
147  (f32 (int_amdgcn_lds_direct_load M0)),
148  (DS_DIRECT_LOAD 0, 1)
149>;
150
151def : GCNPat <
152  (f32 (int_amdgcn_lds_param_load timm:$attrchan, timm:$attr, M0)),
153  (DS_PARAM_LOAD timm:$attr, timm:$attrchan, 0, 1)
154>;
155
156} // End SubtargetPredicate = isGFX12Only
157
158//===----------------------------------------------------------------------===//
159// GFX11
160//===----------------------------------------------------------------------===//
161
162multiclass DSDIR_Real_gfx11<bits<2> op,
163                            DSDIR_Pseudo lds = !cast<DSDIR_Pseudo>(NAME)> {
164  def _gfx11 : DSDIR_Real<lds, lds.InOperandList,
165                          LDSDIR_getAsm<lds.is_direct>.ret,
166                          SIEncodingFamily.GFX11>,
167               LDSDIRe<op, lds.is_direct> {
168    let AssemblerPredicate = isGFX11Only;
169    let DecoderNamespace = "GFX11";
170  }
171}
172
173defm LDS_PARAM_LOAD : DSDIR_Real_gfx11<0x0>;
174defm LDS_DIRECT_LOAD : DSDIR_Real_gfx11<0x1>;
175
176//===----------------------------------------------------------------------===//
177// GFX12+
178//===----------------------------------------------------------------------===//
179
180multiclass DSDIR_Real_gfx12<bits<2> op,
181                            DSDIR_Pseudo lds = !cast<DSDIR_Pseudo>(NAME)> {
182  def _gfx12 : DSDIR_Real<lds, lds.InOperandList,
183                          VDSDIR_getAsm<lds.is_direct>.ret,
184                          SIEncodingFamily.GFX12>,
185               VDSDIRe<op, lds.is_direct> {
186    let AssemblerPredicate = isGFX12Plus;
187    let DecoderNamespace = "GFX12";
188  }
189}
190
191defm DS_PARAM_LOAD : DSDIR_Real_gfx12<0x0>;
192defm DS_DIRECT_LOAD : DSDIR_Real_gfx12<0x1>;
193