1 //===-- AMDGPUInstrInfo.td - AMDGPU DAG nodes --------------*- tablegen -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file contains DAG node defintions for the AMDGPU target.
12 //===----------------------------------------------------------------------===//
14 //===----------------------------------------------------------------------===//
15 // AMDGPU DAG Profiles
16 //===----------------------------------------------------------------------===//
18 def AMDGPUDTIntTernaryOp : SDTypeProfile<1, 3, [
19 SDTCisSameAs<0, 1>, SDTCisSameAs<0, 2>, SDTCisInt<0>, SDTCisInt<3>
22 def AMDGPUTrigPreOp : SDTypeProfile<1, 2,
23 [SDTCisSameAs<0, 1>, SDTCisFP<0>, SDTCisInt<2>]
26 def AMDGPULdExpOp : SDTypeProfile<1, 2,
27 [SDTCisSameAs<0, 1>, SDTCisFP<0>, SDTCisInt<2>]
30 def AMDGPUFPClassOp : SDTypeProfile<1, 2,
31 [SDTCisInt<0>, SDTCisFP<1>, SDTCisInt<2>]
34 def AMDGPUFPPackOp : SDTypeProfile<1, 2,
35 [SDTCisFP<1>, SDTCisSameAs<1, 2>]
38 def AMDGPUIntPackOp : SDTypeProfile<1, 2,
39 [SDTCisInt<1>, SDTCisSameAs<1, 2>]
42 def AMDGPUDivScaleOp : SDTypeProfile<2, 3,
43 [SDTCisFP<0>, SDTCisInt<1>, SDTCisSameAs<0, 2>, SDTCisSameAs<0, 3>, SDTCisSameAs<0, 4>]
46 // float, float, float, vcc
47 def AMDGPUFmasOp : SDTypeProfile<1, 4,
48 [SDTCisFP<0>, SDTCisSameAs<0, 1>, SDTCisSameAs<0, 2>, SDTCisSameAs<0, 3>, SDTCisInt<4>]
51 def AMDGPUKillSDT : SDTypeProfile<0, 1, [SDTCisInt<0>]>;
53 def AMDGPUIfOp : SDTypeProfile<1, 2,
54 [SDTCisVT<0, i64>, SDTCisVT<1, i1>, SDTCisVT<2, OtherVT>]
57 def AMDGPUElseOp : SDTypeProfile<1, 2,
58 [SDTCisVT<0, i64>, SDTCisVT<1, i64>, SDTCisVT<2, OtherVT>]
61 def AMDGPULoopOp : SDTypeProfile<0, 2,
62 [SDTCisVT<0, i64>, SDTCisVT<1, OtherVT>]
65 def AMDGPUIfBreakOp : SDTypeProfile<1, 2,
66 [SDTCisVT<0, i64>, SDTCisVT<1, i1>, SDTCisVT<2, i64>]
69 def AMDGPUAddeSubeOp : SDTypeProfile<2, 3,
70 [SDTCisSameAs<0, 2>, SDTCisSameAs<0, 3>, SDTCisVT<0, i32>, SDTCisVT<1, i1>, SDTCisVT<4, i1>]
73 def SDT_AMDGPUTCRET : SDTypeProfile<0, 2, [SDTCisPtrTy<0>]>;
75 //===----------------------------------------------------------------------===//
79 def AMDGPUif : SDNode<"AMDGPUISD::IF", AMDGPUIfOp, [SDNPHasChain]>;
80 def AMDGPUelse : SDNode<"AMDGPUISD::ELSE", AMDGPUElseOp, [SDNPHasChain]>;
81 def AMDGPUloop : SDNode<"AMDGPUISD::LOOP", AMDGPULoopOp, [SDNPHasChain]>;
83 def callseq_start : SDNode<"ISD::CALLSEQ_START",
84 SDCallSeqStart<[ SDTCisVT<0, i32>, SDTCisVT<1, i32> ]>,
85 [SDNPHasChain, SDNPOutGlue]
88 def callseq_end : SDNode<"ISD::CALLSEQ_END",
89 SDCallSeqEnd<[ SDTCisVT<0, i32>, SDTCisVT<1, i32> ]>,
90 [SDNPHasChain, SDNPOptInGlue, SDNPOutGlue]
93 def AMDGPUcall : SDNode<"AMDGPUISD::CALL",
94 SDTypeProfile<0, -1, [SDTCisPtrTy<0>]>,
95 [SDNPHasChain, SDNPOptInGlue, SDNPOutGlue,
99 def AMDGPUtc_return: SDNode<"AMDGPUISD::TC_RETURN", SDT_AMDGPUTCRET,
100 [SDNPHasChain, SDNPOptInGlue, SDNPVariadic]
103 def AMDGPUtrap : SDNode<"AMDGPUISD::TRAP",
104 SDTypeProfile<0, -1, [SDTCisVT<0, i16>]>,
105 [SDNPHasChain, SDNPVariadic, SDNPSideEffect, SDNPInGlue]
108 def AMDGPUconstdata_ptr : SDNode<
109 "AMDGPUISD::CONST_DATA_PTR", SDTypeProfile <1, 1, [SDTCisVT<0, iPTR>,
113 // This argument to this node is a dword address.
114 def AMDGPUdwordaddr : SDNode<"AMDGPUISD::DWORDADDR", SDTIntUnaryOp>;
116 // Force dependencies for vector trunc stores
117 def R600dummy_chain : SDNode<"AMDGPUISD::DUMMY_CHAIN", SDTNone, [SDNPHasChain]>;
119 def AMDGPUcos : SDNode<"AMDGPUISD::COS_HW", SDTFPUnaryOp>;
120 def AMDGPUsin : SDNode<"AMDGPUISD::SIN_HW", SDTFPUnaryOp>;
122 // out = a - floor(a)
123 def AMDGPUfract : SDNode<"AMDGPUISD::FRACT", SDTFPUnaryOp>;
126 def AMDGPUrcp : SDNode<"AMDGPUISD::RCP", SDTFPUnaryOp>;
128 // out = 1.0 / sqrt(a)
129 def AMDGPUrsq : SDNode<"AMDGPUISD::RSQ", SDTFPUnaryOp>;
131 // out = 1.0 / sqrt(a)
132 def AMDGPUrcp_legacy : SDNode<"AMDGPUISD::RCP_LEGACY", SDTFPUnaryOp>;
133 def AMDGPUrsq_legacy : SDNode<"AMDGPUISD::RSQ_LEGACY", SDTFPUnaryOp>;
135 def AMDGPUrcp_iflag : SDNode<"AMDGPUISD::RCP_IFLAG", SDTFPUnaryOp>;
137 // out = 1.0 / sqrt(a) result clamped to +/- max_float.
138 def AMDGPUrsq_clamp : SDNode<"AMDGPUISD::RSQ_CLAMP", SDTFPUnaryOp>;
140 def AMDGPUldexp : SDNode<"AMDGPUISD::LDEXP", AMDGPULdExpOp>;
142 def AMDGPUpkrtz_f16_f32 : SDNode<"AMDGPUISD::CVT_PKRTZ_F16_F32", AMDGPUFPPackOp>;
143 def AMDGPUpknorm_i16_f32 : SDNode<"AMDGPUISD::CVT_PKNORM_I16_F32", AMDGPUFPPackOp>;
144 def AMDGPUpknorm_u16_f32 : SDNode<"AMDGPUISD::CVT_PKNORM_U16_F32", AMDGPUFPPackOp>;
145 def AMDGPUpk_i16_i32 : SDNode<"AMDGPUISD::CVT_PK_I16_I32", AMDGPUIntPackOp>;
146 def AMDGPUpk_u16_u32 : SDNode<"AMDGPUISD::CVT_PK_U16_U32", AMDGPUIntPackOp>;
147 def AMDGPUfp_to_f16 : SDNode<"AMDGPUISD::FP_TO_FP16" , SDTFPToIntOp>;
148 def AMDGPUfp16_zext : SDNode<"AMDGPUISD::FP16_ZEXT" , SDTFPToIntOp>;
151 def AMDGPUfp_class : SDNode<"AMDGPUISD::FP_CLASS", AMDGPUFPClassOp>;
153 // out = max(a, b) a and b are floats, where a nan comparison fails.
154 // This is not commutative because this gives the second operand:
155 // x < nan ? x : nan -> nan
156 // nan < x ? nan : x -> x
157 def AMDGPUfmax_legacy : SDNode<"AMDGPUISD::FMAX_LEGACY", SDTFPBinOp,
161 def AMDGPUfmul_legacy : SDNode<"AMDGPUISD::FMUL_LEGACY", SDTFPBinOp,
162 [SDNPCommutative, SDNPAssociative]
165 // out = min(a, b) a and b are floats, where a nan comparison fails.
166 def AMDGPUfmin_legacy : SDNode<"AMDGPUISD::FMIN_LEGACY", SDTFPBinOp,
170 // FIXME: TableGen doesn't like commutative instructions with more
172 // out = max(a, b, c) a, b and c are floats
173 def AMDGPUfmax3 : SDNode<"AMDGPUISD::FMAX3", SDTFPTernaryOp,
174 [/*SDNPCommutative, SDNPAssociative*/]
177 // out = max(a, b, c) a, b, and c are signed ints
178 def AMDGPUsmax3 : SDNode<"AMDGPUISD::SMAX3", AMDGPUDTIntTernaryOp,
179 [/*SDNPCommutative, SDNPAssociative*/]
182 // out = max(a, b, c) a, b and c are unsigned ints
183 def AMDGPUumax3 : SDNode<"AMDGPUISD::UMAX3", AMDGPUDTIntTernaryOp,
184 [/*SDNPCommutative, SDNPAssociative*/]
187 // out = min(a, b, c) a, b and c are floats
188 def AMDGPUfmin3 : SDNode<"AMDGPUISD::FMIN3", SDTFPTernaryOp,
189 [/*SDNPCommutative, SDNPAssociative*/]
192 // out = min(a, b, c) a, b and c are signed ints
193 def AMDGPUsmin3 : SDNode<"AMDGPUISD::SMIN3", AMDGPUDTIntTernaryOp,
194 [/*SDNPCommutative, SDNPAssociative*/]
197 // out = min(a, b) a and b are unsigned ints
198 def AMDGPUumin3 : SDNode<"AMDGPUISD::UMIN3", AMDGPUDTIntTernaryOp,
199 [/*SDNPCommutative, SDNPAssociative*/]
202 // out = (src0 + src1 > 0xFFFFFFFF) ? 1 : 0
203 def AMDGPUcarry : SDNode<"AMDGPUISD::CARRY", SDTIntBinOp, []>;
205 // out = (src1 > src0) ? 1 : 0
206 def AMDGPUborrow : SDNode<"AMDGPUISD::BORROW", SDTIntBinOp, []>;
208 // TODO: remove AMDGPUadde/AMDGPUsube when ADDCARRY/SUBCARRY get their own
209 // nodes in TargetSelectionDAG.td.
210 def AMDGPUadde : SDNode<"ISD::ADDCARRY", AMDGPUAddeSubeOp, []>;
212 def AMDGPUsube : SDNode<"ISD::SUBCARRY", AMDGPUAddeSubeOp, []>;
214 def AMDGPUSetCCOp : SDTypeProfile<1, 3, [ // setcc
215 SDTCisVT<0, i64>, SDTCisSameAs<1, 2>, SDTCisVT<3, OtherVT>
218 def AMDGPUsetcc : SDNode<"AMDGPUISD::SETCC", AMDGPUSetCCOp>;
220 def AMDGPUSetRegOp : SDTypeProfile<0, 2, [
221 SDTCisInt<0>, SDTCisInt<1>
224 def AMDGPUsetreg : SDNode<"AMDGPUISD::SETREG", AMDGPUSetRegOp, [
225 SDNPHasChain, SDNPSideEffect, SDNPOptInGlue, SDNPOutGlue]>;
227 def AMDGPUfma : SDNode<"AMDGPUISD::FMA_W_CHAIN", SDTFPTernaryOp, [
228 SDNPHasChain, SDNPOptInGlue, SDNPOutGlue]>;
230 def AMDGPUmul : SDNode<"AMDGPUISD::FMUL_W_CHAIN", SDTFPBinOp, [
231 SDNPHasChain, SDNPOptInGlue, SDNPOutGlue]>;
233 def AMDGPUcvt_f32_ubyte0 : SDNode<"AMDGPUISD::CVT_F32_UBYTE0",
235 def AMDGPUcvt_f32_ubyte1 : SDNode<"AMDGPUISD::CVT_F32_UBYTE1",
237 def AMDGPUcvt_f32_ubyte2 : SDNode<"AMDGPUISD::CVT_F32_UBYTE2",
239 def AMDGPUcvt_f32_ubyte3 : SDNode<"AMDGPUISD::CVT_F32_UBYTE3",
243 // urecip - This operation is a helper for integer division, it returns the
244 // result of 1 / a as a fractional unsigned integer.
245 // out = (2^32 / a) + e
246 // e is rounding error
247 def AMDGPUurecip : SDNode<"AMDGPUISD::URECIP", SDTIntUnaryOp>;
249 // Special case divide preop and flags.
250 def AMDGPUdiv_scale : SDNode<"AMDGPUISD::DIV_SCALE", AMDGPUDivScaleOp>;
252 // Special case divide FMA with scale and flags (src0 = Quotient,
253 // src1 = Denominator, src2 = Numerator).
254 def AMDGPUdiv_fmas : SDNode<"AMDGPUISD::DIV_FMAS", AMDGPUFmasOp>;
256 // Single or double precision division fixup.
257 // Special case divide fixup and flags(src0 = Quotient, src1 =
258 // Denominator, src2 = Numerator).
259 def AMDGPUdiv_fixup : SDNode<"AMDGPUISD::DIV_FIXUP", SDTFPTernaryOp>;
261 def AMDGPUfmad_ftz : SDNode<"AMDGPUISD::FMAD_FTZ", SDTFPTernaryOp>;
263 // Look Up 2.0 / pi src0 with segment select src1[4:0]
264 def AMDGPUtrig_preop : SDNode<"AMDGPUISD::TRIG_PREOP", AMDGPUTrigPreOp>;
266 def AMDGPUregister_load : SDNode<"AMDGPUISD::REGISTER_LOAD",
267 SDTypeProfile<1, 2, [SDTCisPtrTy<1>, SDTCisInt<2>]>,
268 [SDNPHasChain, SDNPMayLoad]>;
270 def AMDGPUregister_store : SDNode<"AMDGPUISD::REGISTER_STORE",
271 SDTypeProfile<0, 3, [SDTCisPtrTy<1>, SDTCisInt<2>]>,
272 [SDNPHasChain, SDNPMayStore]>;
274 // MSKOR instructions are atomic memory instructions used mainly for storing
275 // 8-bit and 16-bit values. The definition is:
277 // MSKOR(dst, mask, src) MEM[dst] = ((MEM[dst] & ~mask) | src)
279 // src0: vec4(src, 0, 0, mask)
280 // src1: dst - rat offset (aka pointer) in dwords
281 def AMDGPUstore_mskor : SDNode<"AMDGPUISD::STORE_MSKOR",
282 SDTypeProfile<0, 2, []>,
283 [SDNPHasChain, SDNPMayStore, SDNPMemOperand]>;
285 def AMDGPUatomic_cmp_swap : SDNode<"AMDGPUISD::ATOMIC_CMP_SWAP",
286 SDTypeProfile<1, 2, [SDTCisPtrTy<1>, SDTCisVec<2>]>,
287 [SDNPHasChain, SDNPMayStore, SDNPMayLoad,
290 def AMDGPUround : SDNode<"ISD::FROUND",
291 SDTypeProfile<1, 1, [SDTCisFP<0>, SDTCisSameAs<0,1>]>>;
293 def AMDGPUbfe_u32 : SDNode<"AMDGPUISD::BFE_U32", AMDGPUDTIntTernaryOp>;
294 def AMDGPUbfe_i32 : SDNode<"AMDGPUISD::BFE_I32", AMDGPUDTIntTernaryOp>;
295 def AMDGPUbfi : SDNode<"AMDGPUISD::BFI", AMDGPUDTIntTernaryOp>;
296 def AMDGPUbfm : SDNode<"AMDGPUISD::BFM", SDTIntBinOp>;
298 def AMDGPUffbh_u32 : SDNode<"AMDGPUISD::FFBH_U32", SDTIntUnaryOp>;
299 def AMDGPUffbh_i32 : SDNode<"AMDGPUISD::FFBH_I32", SDTIntUnaryOp>;
301 def AMDGPUffbl_b32 : SDNode<"AMDGPUISD::FFBL_B32", SDTIntUnaryOp>;
303 // Signed and unsigned 24-bit multiply. The highest 8-bits are ignore
304 // when performing the mulitply. The result is a 32-bit value.
305 def AMDGPUmul_u24 : SDNode<"AMDGPUISD::MUL_U24", SDTIntBinOp,
306 [SDNPCommutative, SDNPAssociative]
308 def AMDGPUmul_i24 : SDNode<"AMDGPUISD::MUL_I24", SDTIntBinOp,
309 [SDNPCommutative, SDNPAssociative]
312 def AMDGPUmulhi_u24 : SDNode<"AMDGPUISD::MULHI_U24", SDTIntBinOp,
313 [SDNPCommutative, SDNPAssociative]
315 def AMDGPUmulhi_i24 : SDNode<"AMDGPUISD::MULHI_I24", SDTIntBinOp,
316 [SDNPCommutative, SDNPAssociative]
319 def AMDGPUmad_u24 : SDNode<"AMDGPUISD::MAD_U24", AMDGPUDTIntTernaryOp,
322 def AMDGPUmad_i24 : SDNode<"AMDGPUISD::MAD_I24", AMDGPUDTIntTernaryOp,
326 def AMDGPUsmed3 : SDNode<"AMDGPUISD::SMED3", AMDGPUDTIntTernaryOp,
330 def AMDGPUumed3 : SDNode<"AMDGPUISD::UMED3", AMDGPUDTIntTernaryOp,
334 def AMDGPUfmed3 : SDNode<"AMDGPUISD::FMED3", SDTFPTernaryOp, []>;
336 def AMDGPUfdot2 : SDNode<"AMDGPUISD::FDOT2",
337 SDTypeProfile<1, 4, [SDTCisSameAs<0, 3>, SDTCisSameAs<1, 2>,
338 SDTCisFP<0>, SDTCisVec<1>,
342 def AMDGPUperm : SDNode<"AMDGPUISD::PERM", AMDGPUDTIntTernaryOp, []>;
344 def AMDGPUinit_exec : SDNode<"AMDGPUISD::INIT_EXEC",
345 SDTypeProfile<0, 1, [SDTCisInt<0>]>,
346 [SDNPHasChain, SDNPInGlue]>;
348 def AMDGPUinit_exec_from_input : SDNode<"AMDGPUISD::INIT_EXEC_FROM_INPUT",
350 [SDTCisInt<0>, SDTCisInt<1>]>,
351 [SDNPHasChain, SDNPInGlue]>;
353 def AMDGPUsendmsg : SDNode<"AMDGPUISD::SENDMSG",
354 SDTypeProfile<0, 1, [SDTCisInt<0>]>,
355 [SDNPHasChain, SDNPInGlue]>;
357 def AMDGPUsendmsghalt : SDNode<"AMDGPUISD::SENDMSGHALT",
358 SDTypeProfile<0, 1, [SDTCisInt<0>]>,
359 [SDNPHasChain, SDNPInGlue]>;
361 def AMDGPUinterp_mov : SDNode<"AMDGPUISD::INTERP_MOV",
362 SDTypeProfile<1, 3, [SDTCisFP<0>]>,
365 def AMDGPUinterp_p1 : SDNode<"AMDGPUISD::INTERP_P1",
366 SDTypeProfile<1, 3, [SDTCisFP<0>]>,
367 [SDNPInGlue, SDNPOutGlue]>;
369 def AMDGPUinterp_p2 : SDNode<"AMDGPUISD::INTERP_P2",
370 SDTypeProfile<1, 4, [SDTCisFP<0>]>,
374 def AMDGPUkill : SDNode<"AMDGPUISD::KILL", AMDGPUKillSDT,
375 [SDNPHasChain, SDNPSideEffect]>;
378 def AMDGPUExportOp : SDTypeProfile<0, 8, [
379 SDTCisInt<0>, // i8 tgt
380 SDTCisInt<1>, // i8 en
382 SDTCisSameAs<3, 2>, // f32 src1
383 SDTCisSameAs<4, 2>, // f32 src2
384 SDTCisSameAs<5, 2>, // f32 src3
385 SDTCisInt<6>, // i1 compr
387 SDTCisInt<1> // i1 vm
391 def AMDGPUexport: SDNode<"AMDGPUISD::EXPORT", AMDGPUExportOp,
392 [SDNPHasChain, SDNPMayStore]>;
394 def AMDGPUexport_done: SDNode<"AMDGPUISD::EXPORT_DONE", AMDGPUExportOp,
395 [SDNPHasChain, SDNPMayLoad, SDNPMayStore]>;
398 def R600ExportOp : SDTypeProfile<0, 7, [SDTCisFP<0>, SDTCisInt<1>]>;
400 def R600_EXPORT: SDNode<"AMDGPUISD::R600_EXPORT", R600ExportOp,
401 [SDNPHasChain, SDNPSideEffect]>;
403 //===----------------------------------------------------------------------===//
404 // Flow Control Profile Types
405 //===----------------------------------------------------------------------===//
406 // Branch instruction where second and third are basic blocks
407 def SDTIL_BRCond : SDTypeProfile<0, 2, [
411 //===----------------------------------------------------------------------===//
412 // Flow Control DAG Nodes
413 //===----------------------------------------------------------------------===//
414 def IL_brcond : SDNode<"AMDGPUISD::BRANCH_COND", SDTIL_BRCond, [SDNPHasChain]>;
416 //===----------------------------------------------------------------------===//
417 // Call/Return DAG Nodes
418 //===----------------------------------------------------------------------===//
419 def AMDGPUendpgm : SDNode<"AMDGPUISD::ENDPGM", SDTNone,
420 [SDNPHasChain, SDNPOptInGlue]>;
422 def AMDGPUreturn_to_epilog : SDNode<"AMDGPUISD::RETURN_TO_EPILOG", SDTNone,
423 [SDNPHasChain, SDNPOptInGlue, SDNPVariadic]>;
425 def AMDGPUret_flag : SDNode<"AMDGPUISD::RET_FLAG", SDTypeProfile<0, 1, [SDTCisPtrTy<0>]>,
426 [SDNPHasChain, SDNPOptInGlue, SDNPVariadic]