xref: /freebsd/contrib/llvm-project/llvm/lib/Target/AMDGPU/EXPInstructions.td (revision 0fca6ea1d4eea4c934cfff25ac9ee8ad6fe95583)
1e8d8bef9SDimitry Andric//===-- EXPInstructions.td - Export Instruction Definitions ---------------===//
2e8d8bef9SDimitry Andric//
3e8d8bef9SDimitry Andric// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4e8d8bef9SDimitry Andric// See https://llvm.org/LICENSE.txt for license information.
5e8d8bef9SDimitry Andric// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6e8d8bef9SDimitry Andric//
7e8d8bef9SDimitry Andric//===----------------------------------------------------------------------===//
8e8d8bef9SDimitry Andric
9e8d8bef9SDimitry Andric//===----------------------------------------------------------------------===//
10e8d8bef9SDimitry Andric// EXP classes
11e8d8bef9SDimitry Andric//===----------------------------------------------------------------------===//
12e8d8bef9SDimitry Andric
13*0fca6ea1SDimitry Andricclass EXPCommon<bit _row, bit _done, string asm = ""> : InstSI<
14e8d8bef9SDimitry Andric  (outs),
15e8d8bef9SDimitry Andric  (ins exp_tgt:$tgt,
16e8d8bef9SDimitry Andric       ExpSrc0:$src0, ExpSrc1:$src1, ExpSrc2:$src2, ExpSrc3:$src3,
17e8d8bef9SDimitry Andric       exp_vm:$vm, exp_compr:$compr, i32imm:$en),
18e8d8bef9SDimitry Andric  asm> {
19e8d8bef9SDimitry Andric  let EXP = 1;
20e8d8bef9SDimitry Andric  let EXP_CNT = 1;
21*0fca6ea1SDimitry Andric  let mayLoad = _done;
22e8d8bef9SDimitry Andric  let mayStore = 1;
231db9f3b2SDimitry Andric  let maybeAtomic = 0;
24e8d8bef9SDimitry Andric  let UseNamedOperandTable = 1;
25*0fca6ea1SDimitry Andric  let Uses = !if(_row, [EXEC, M0], [EXEC]);
26e8d8bef9SDimitry Andric  let SchedRW = [WriteExport];
27e8d8bef9SDimitry Andric  let DisableWQM = 1;
28*0fca6ea1SDimitry Andric
29*0fca6ea1SDimitry Andric  bit row = _row;
30*0fca6ea1SDimitry Andric  bit done = _done;
31e8d8bef9SDimitry Andric}
32e8d8bef9SDimitry Andric
3381ad6265SDimitry Andricclass EXP_Pseudo<bit row, bit done>
3481ad6265SDimitry Andric  : EXPCommon<row, done>, SIMCInstr<NAME, SIEncodingFamily.NONE> {
35e8d8bef9SDimitry Andric  let isPseudo = 1;
36e8d8bef9SDimitry Andric  let isCodeGenOnly = 1;
37e8d8bef9SDimitry Andric}
38e8d8bef9SDimitry Andric
3981ad6265SDimitry Andric// Real instruction with optional asm operands "compr" and "vm".
40*0fca6ea1SDimitry Andricclass EXP_Real_ComprVM<EXP_Pseudo ps, int subtarget>
41*0fca6ea1SDimitry Andric  : EXPCommon<0, ps.done, "exp$tgt $src0, $src1, $src2, $src3"
42*0fca6ea1SDimitry Andric                       #!if(ps.done, " done", "")#"$compr$vm">,
43*0fca6ea1SDimitry Andric    SIMCInstr<ps.PseudoInstr, subtarget> {
4481ad6265SDimitry Andric  let AsmMatchConverter = "cvtExp";
4581ad6265SDimitry Andric}
4681ad6265SDimitry Andric
4781ad6265SDimitry Andric// Real instruction with optional asm operand "row_en".
48*0fca6ea1SDimitry Andricclass EXP_Real_Row<EXP_Pseudo ps, int subtarget, string name = "exp">
49*0fca6ea1SDimitry Andric  : EXPCommon<ps.row, ps.done, name#"$tgt $src0, $src1, $src2, $src3"
50*0fca6ea1SDimitry Andric                         #!if(ps.done, " done", "")#!if(ps.row, " row_en", "")>,
51*0fca6ea1SDimitry Andric    SIMCInstr<ps.PseudoInstr, subtarget> {
52e8d8bef9SDimitry Andric  let AsmMatchConverter = "cvtExp";
53e8d8bef9SDimitry Andric}
54e8d8bef9SDimitry Andric
55e8d8bef9SDimitry Andric//===----------------------------------------------------------------------===//
56e8d8bef9SDimitry Andric// EXP Instructions
57e8d8bef9SDimitry Andric//===----------------------------------------------------------------------===//
58e8d8bef9SDimitry Andric
5981ad6265SDimitry Andric// DONE variants have mayLoad = 1.
6081ad6265SDimitry Andric// ROW variants have an implicit use of M0.
61*0fca6ea1SDimitry Andriclet SubtargetPredicate = HasExportInsts in {
6281ad6265SDimitry Andricdef EXP          : EXP_Pseudo<0, 0>;
6381ad6265SDimitry Andricdef EXP_DONE     : EXP_Pseudo<0, 1>;
6481ad6265SDimitry Andricdef EXP_ROW      : EXP_Pseudo<1, 0>;
6581ad6265SDimitry Andricdef EXP_ROW_DONE : EXP_Pseudo<1, 1>;
66*0fca6ea1SDimitry Andric} // let SubtargetPredicate = HasExportInsts
67e8d8bef9SDimitry Andric
68e8d8bef9SDimitry Andric//===----------------------------------------------------------------------===//
69*0fca6ea1SDimitry Andric// SI, VI, GFX10.
70e8d8bef9SDimitry Andric//===----------------------------------------------------------------------===//
71e8d8bef9SDimitry Andric
72*0fca6ea1SDimitry Andricmulticlass EXP_Real_si {
73*0fca6ea1SDimitry Andric  defvar ps = !cast<EXP_Pseudo>(NAME);
74*0fca6ea1SDimitry Andric  def _si : EXP_Real_ComprVM<ps, SIEncodingFamily.SI>, EXPe_ComprVM {
75e8d8bef9SDimitry Andric    let AssemblerPredicate = isGFX6GFX7;
76e8d8bef9SDimitry Andric    let DecoderNamespace = "GFX6GFX7";
77*0fca6ea1SDimitry Andric    let done = ps.done;
78*0fca6ea1SDimitry Andric  }
79e8d8bef9SDimitry Andric}
80e8d8bef9SDimitry Andric
81*0fca6ea1SDimitry Andricmulticlass EXP_Real_vi {
82*0fca6ea1SDimitry Andric  defvar ps = !cast<EXP_Pseudo>(NAME);
83*0fca6ea1SDimitry Andric  def _vi : EXP_Real_ComprVM<ps, SIEncodingFamily.VI>, EXPe_vi {
84e8d8bef9SDimitry Andric    let AssemblerPredicate = isGFX8GFX9;
8581ad6265SDimitry Andric    let SubtargetPredicate = isNotGFX90APlus;
86e8d8bef9SDimitry Andric    let DecoderNamespace = "GFX8";
87*0fca6ea1SDimitry Andric    let done = ps.done;
88*0fca6ea1SDimitry Andric  }
89e8d8bef9SDimitry Andric}
90e8d8bef9SDimitry Andric
91*0fca6ea1SDimitry Andricmulticlass EXP_Real_gfx10 {
92*0fca6ea1SDimitry Andric  defvar ps = !cast<EXP_Pseudo>(NAME);
93*0fca6ea1SDimitry Andric  def _gfx10 : EXP_Real_ComprVM<ps, SIEncodingFamily.GFX10>, EXPe_ComprVM {
9481ad6265SDimitry Andric    let AssemblerPredicate = isGFX10Only;
95e8d8bef9SDimitry Andric    let DecoderNamespace = "GFX10";
96*0fca6ea1SDimitry Andric    let done = ps.done;
97*0fca6ea1SDimitry Andric  }
98e8d8bef9SDimitry Andric}
99e8d8bef9SDimitry Andric
100*0fca6ea1SDimitry Andricdefm EXP      : EXP_Real_si, EXP_Real_vi, EXP_Real_gfx10;
101*0fca6ea1SDimitry Andricdefm EXP_DONE : EXP_Real_si, EXP_Real_vi, EXP_Real_gfx10;
102e8d8bef9SDimitry Andric
103e8d8bef9SDimitry Andric//===----------------------------------------------------------------------===//
104*0fca6ea1SDimitry Andric// GFX11, GFX12.
10581ad6265SDimitry Andric//===----------------------------------------------------------------------===//
10681ad6265SDimitry Andric
107*0fca6ea1SDimitry Andricmulticlass EXP_Real_gfx11 {
108*0fca6ea1SDimitry Andric  defvar ps = !cast<EXP_Pseudo>(NAME);
109*0fca6ea1SDimitry Andric  def _gfx11 : EXP_Real_Row<ps, SIEncodingFamily.GFX11>, EXPe_Row {
1105f757f3fSDimitry Andric    let AssemblerPredicate = isGFX11Only;
11181ad6265SDimitry Andric    let DecoderNamespace = "GFX11";
112*0fca6ea1SDimitry Andric    let row = ps.row;
113*0fca6ea1SDimitry Andric    let done = ps.done;
114*0fca6ea1SDimitry Andric  }
11581ad6265SDimitry Andric}
11681ad6265SDimitry Andric
117*0fca6ea1SDimitry Andricmulticlass VEXPORT_Real_gfx12 {
118*0fca6ea1SDimitry Andric  defvar ps = !cast<EXP_Pseudo>(NAME);
119*0fca6ea1SDimitry Andric  def _gfx12 : EXP_Real_Row<ps, SIEncodingFamily.GFX12, "export">,
120*0fca6ea1SDimitry Andric    EXPe_Row {
121*0fca6ea1SDimitry Andric    let AssemblerPredicate = isGFX12Only;
1225f757f3fSDimitry Andric    let DecoderNamespace = "GFX12";
123*0fca6ea1SDimitry Andric    let row = ps.row;
124*0fca6ea1SDimitry Andric    let done = ps.done;
125*0fca6ea1SDimitry Andric  }
126*0fca6ea1SDimitry Andric  def : AMDGPUMnemonicAlias<"exp", "export"> {
127*0fca6ea1SDimitry Andric    let AssemblerPredicate = isGFX12Plus;
128*0fca6ea1SDimitry Andric  }
1295f757f3fSDimitry Andric}
1305f757f3fSDimitry Andric
131*0fca6ea1SDimitry Andricdefm EXP          : EXP_Real_gfx11, VEXPORT_Real_gfx12;
132*0fca6ea1SDimitry Andricdefm EXP_DONE     : EXP_Real_gfx11, VEXPORT_Real_gfx12;
133*0fca6ea1SDimitry Andricdefm EXP_ROW      : EXP_Real_gfx11, VEXPORT_Real_gfx12;
134*0fca6ea1SDimitry Andricdefm EXP_ROW_DONE : EXP_Real_gfx11, VEXPORT_Real_gfx12;
1355f757f3fSDimitry Andric
1365f757f3fSDimitry Andric//===----------------------------------------------------------------------===//
137e8d8bef9SDimitry Andric// EXP Patterns
138e8d8bef9SDimitry Andric//===----------------------------------------------------------------------===//
139e8d8bef9SDimitry Andric
140e8d8bef9SDimitry Andricclass ExpPattern<ValueType vt, Instruction Inst, int done_val> : GCNPat<
141e8d8bef9SDimitry Andric  (int_amdgcn_exp timm:$tgt, timm:$en,
142e8d8bef9SDimitry Andric                  (vt ExpSrc0:$src0), (vt ExpSrc1:$src1),
143e8d8bef9SDimitry Andric                  (vt ExpSrc2:$src2), (vt ExpSrc3:$src3),
144e8d8bef9SDimitry Andric                  done_val, timm:$vm),
145e8d8bef9SDimitry Andric  (Inst timm:$tgt, ExpSrc0:$src0, ExpSrc1:$src1,
146e8d8bef9SDimitry Andric        ExpSrc2:$src2, ExpSrc3:$src3, timm:$vm, 0, timm:$en)
147e8d8bef9SDimitry Andric>;
148e8d8bef9SDimitry Andric
14981ad6265SDimitry Andricclass ExpRowPattern<ValueType vt, Instruction Inst, int done_val> : GCNPat<
15081ad6265SDimitry Andric  (int_amdgcn_exp_row timm:$tgt, timm:$en,
15181ad6265SDimitry Andric                      (vt ExpSrc0:$src0), (vt ExpSrc1:$src1),
15281ad6265SDimitry Andric                      (vt ExpSrc2:$src2), (vt ExpSrc3:$src3),
15381ad6265SDimitry Andric                      done_val, M0),
15481ad6265SDimitry Andric  (Inst timm:$tgt, ExpSrc0:$src0, ExpSrc1:$src1,
15581ad6265SDimitry Andric        ExpSrc2:$src2, ExpSrc3:$src3, 0, 0, timm:$en)
15681ad6265SDimitry Andric>;
15781ad6265SDimitry Andric
158e8d8bef9SDimitry Andricclass ExpComprPattern<ValueType vt, Instruction Inst, int done_val> : GCNPat<
159e8d8bef9SDimitry Andric  (int_amdgcn_exp_compr timm:$tgt, timm:$en,
160e8d8bef9SDimitry Andric                        (vt ExpSrc0:$src0), (vt ExpSrc1:$src1),
161e8d8bef9SDimitry Andric                        done_val, timm:$vm),
162e8d8bef9SDimitry Andric  (Inst timm:$tgt, ExpSrc0:$src0, ExpSrc1:$src1,
163e8d8bef9SDimitry Andric        (IMPLICIT_DEF), (IMPLICIT_DEF), timm:$vm, 1, timm:$en)
164e8d8bef9SDimitry Andric>;
165e8d8bef9SDimitry Andric
166e8d8bef9SDimitry Andric// FIXME: The generated DAG matcher seems to have strange behavior
167e8d8bef9SDimitry Andric// with a 1-bit literal to match, so use a -1 for checking a true
168e8d8bef9SDimitry Andric// 1-bit value.
169e8d8bef9SDimitry Andricdef : ExpPattern<i32, EXP, 0>;
170e8d8bef9SDimitry Andricdef : ExpPattern<i32, EXP_DONE, -1>;
171e8d8bef9SDimitry Andricdef : ExpPattern<f32, EXP, 0>;
172e8d8bef9SDimitry Andricdef : ExpPattern<f32, EXP_DONE, -1>;
173e8d8bef9SDimitry Andric
17481ad6265SDimitry Andricdef : ExpRowPattern<i32, EXP_ROW, 0>;
17581ad6265SDimitry Andricdef : ExpRowPattern<i32, EXP_ROW_DONE, -1>;
17681ad6265SDimitry Andricdef : ExpRowPattern<f32, EXP_ROW, 0>;
17781ad6265SDimitry Andricdef : ExpRowPattern<f32, EXP_ROW_DONE, -1>;
17881ad6265SDimitry Andric
179e8d8bef9SDimitry Andricdef : ExpComprPattern<v2i16, EXP, 0>;
180e8d8bef9SDimitry Andricdef : ExpComprPattern<v2i16, EXP_DONE, -1>;
181e8d8bef9SDimitry Andricdef : ExpComprPattern<v2f16, EXP, 0>;
182e8d8bef9SDimitry Andricdef : ExpComprPattern<v2f16, EXP_DONE, -1>;
183