xref: /freebsd/contrib/llvm-project/llvm/lib/Target/AMDGPU/DSDIRInstructions.td (revision dab59af3bcc7cb7ba01569d3044894b3e860ad56)
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 WaitVDST:$waitvdst),
56    (ins InterpAttr:$attr, InterpAttrChan:$attrchan, WaitVDST:$waitvdst)
57  );
58}
59
60class VDSDIR_getIns<bit direct> {
61  dag ret = !if(direct,
62    (ins WaitVAVDst:$waitvdst, WaitVMVSrc:$waitvsrc),
63    (ins InterpAttr:$attr, InterpAttrChan:$attrchan, WaitVAVDst:$waitvdst,
64         WaitVMVSrc:$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.PseudoInstr, subtarget> {
116  let isPseudo = 0;
117  let isCodeGenOnly = 0;
118
119  // copy SubtargetPredicate from pseudo.
120  let SubtargetPredicate = lds.SubtargetPredicate;
121}
122
123//===----------------------------------------------------------------------===//
124// LDS/VDS Direct Instructions
125//===----------------------------------------------------------------------===//
126
127let SubtargetPredicate = isGFX11Only in {
128
129def LDS_DIRECT_LOAD : DSDIR_Pseudo<"lds_direct_load", LDSDIR_getIns<1>.ret, 1>;
130def LDS_PARAM_LOAD : DSDIR_Pseudo<"lds_param_load", LDSDIR_getIns<0>.ret, 0>;
131
132def : GCNPat <
133  (f32 (int_amdgcn_lds_direct_load M0)),
134  (LDS_DIRECT_LOAD 0)
135>;
136
137def : GCNPat <
138  (f32 (int_amdgcn_lds_param_load timm:$attrchan, timm:$attr, M0)),
139  (LDS_PARAM_LOAD timm:$attr, timm:$attrchan, 0)
140>;
141
142} // End SubtargetPredicate = isGFX11Only
143
144let SubtargetPredicate = isGFX12Plus in {
145
146def DS_DIRECT_LOAD : DSDIR_Pseudo<"ds_direct_load", VDSDIR_getIns<1>.ret, 1>;
147def DS_PARAM_LOAD : DSDIR_Pseudo<"ds_param_load", VDSDIR_getIns<0>.ret, 0>;
148
149def : GCNPat <
150  (f32 (int_amdgcn_lds_direct_load M0)),
151  (DS_DIRECT_LOAD 0, 1)
152>;
153
154def : GCNPat <
155  (f32 (int_amdgcn_lds_param_load timm:$attrchan, timm:$attr, M0)),
156  (DS_PARAM_LOAD timm:$attr, timm:$attrchan, 0, 1)
157>;
158
159} // End SubtargetPredicate = isGFX12Only
160
161//===----------------------------------------------------------------------===//
162// GFX11
163//===----------------------------------------------------------------------===//
164
165multiclass DSDIR_Real_gfx11<bits<2> op> {
166  defvar lds = !cast<DSDIR_Pseudo>(NAME);
167  def _gfx11 : DSDIR_Real<lds, lds.InOperandList,
168                          LDSDIR_getAsm<lds.is_direct>.ret,
169                          SIEncodingFamily.GFX11>,
170               LDSDIRe<op, lds.is_direct> {
171    let AssemblerPredicate = isGFX11Only;
172    let DecoderNamespace = "GFX11";
173  }
174}
175
176defm LDS_PARAM_LOAD : DSDIR_Real_gfx11<0x0>;
177defm LDS_DIRECT_LOAD : DSDIR_Real_gfx11<0x1>;
178
179//===----------------------------------------------------------------------===//
180// GFX12+
181//===----------------------------------------------------------------------===//
182
183multiclass DSDIR_Real_gfx12<bits<2> op> {
184  defvar lds = !cast<DSDIR_Pseudo>(NAME);
185  def _gfx12 : DSDIR_Real<lds, lds.InOperandList,
186                          VDSDIR_getAsm<lds.is_direct>.ret,
187                          SIEncodingFamily.GFX12>,
188               VDSDIRe<op, lds.is_direct> {
189    let AssemblerPredicate = isGFX12Plus;
190    let DecoderNamespace = "GFX12";
191  }
192}
193
194defm DS_PARAM_LOAD : DSDIR_Real_gfx12<0x0>;
195defm DS_DIRECT_LOAD : DSDIR_Real_gfx12<0x1>;
196