1 //===-- AMDGPUInstructions.td - Common instruction defs ---*- 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 instruction defs that are common to all hw codegen
13 //===----------------------------------------------------------------------===//
15 class AMDGPUInst <dag outs, dag ins, string asm, list<dag> pattern> : Instruction {
16 field bit isRegisterLoad = 0;
17 field bit isRegisterStore = 0;
19 let Namespace = "AMDGPU";
20 let OutOperandList = outs;
21 let InOperandList = ins;
23 let Pattern = pattern;
24 let Itinerary = NullALU;
26 let TSFlags{63} = isRegisterLoad;
27 let TSFlags{62} = isRegisterStore;
30 class AMDGPUShaderInst <dag outs, dag ins, string asm, list<dag> pattern>
31 : AMDGPUInst<outs, ins, asm, pattern> {
33 field bits<32> Inst = 0xffffffff;
37 def InstFlag : OperandWithDefaultOps <i32, (ops (i32 0))>;
39 def COND_EQ : PatLeaf <
41 [{switch(N->get()){{default: return false;
42 case ISD::SETOEQ: case ISD::SETUEQ:
43 case ISD::SETEQ: return true;}}}]
46 def COND_NE : PatLeaf <
48 [{switch(N->get()){{default: return false;
49 case ISD::SETONE: case ISD::SETUNE:
50 case ISD::SETNE: return true;}}}]
52 def COND_GT : PatLeaf <
54 [{switch(N->get()){{default: return false;
55 case ISD::SETOGT: case ISD::SETUGT:
56 case ISD::SETGT: return true;}}}]
59 def COND_GE : PatLeaf <
61 [{switch(N->get()){{default: return false;
62 case ISD::SETOGE: case ISD::SETUGE:
63 case ISD::SETGE: return true;}}}]
66 def COND_LT : PatLeaf <
68 [{switch(N->get()){{default: return false;
69 case ISD::SETOLT: case ISD::SETULT:
70 case ISD::SETLT: return true;}}}]
73 def COND_LE : PatLeaf <
75 [{switch(N->get()){{default: return false;
76 case ISD::SETOLE: case ISD::SETULE:
77 case ISD::SETLE: return true;}}}]
80 def COND_NULL : PatLeaf <
85 //===----------------------------------------------------------------------===//
86 // Load/Store Pattern Fragments
87 //===----------------------------------------------------------------------===//
89 def zextloadi8_global : PatFrag<(ops node:$ptr), (zextloadi8 node:$ptr), [{
90 return isGlobalLoad(dyn_cast<LoadSDNode>(N));
93 def zextloadi8_constant : PatFrag<(ops node:$ptr), (zextloadi8 node:$ptr), [{
94 return isGlobalLoad(dyn_cast<LoadSDNode>(N));
98 int TWO_PI = 0x40c90fdb;
100 int TWO_PI_INV = 0x3e22f983;
101 int FP_UINT_MAX_PLUS_1 = 0x4f800000; // 1 << 32 in floating point encoding
103 def CONST : Constants;
105 def FP_ZERO : PatLeaf <
107 [{return N->getValueAPF().isZero();}]
110 def FP_ONE : PatLeaf <
112 [{return N->isExactlyValue(1.0);}]
115 let isCodeGenOnly = 1, isPseudo = 1 in {
117 let usesCustomInserter = 1 in {
119 class CLAMP <RegisterClass rc> : AMDGPUShaderInst <
123 [(set f32:$dst, (int_AMDIL_clamp f32:$src0, (f32 FP_ZERO), (f32 FP_ONE)))]
126 class FABS <RegisterClass rc> : AMDGPUShaderInst <
130 [(set f32:$dst, (fabs f32:$src0))]
133 class FNEG <RegisterClass rc> : AMDGPUShaderInst <
137 [(set f32:$dst, (fneg f32:$src0))]
140 } // usesCustomInserter = 1
142 multiclass RegisterLoadStore <RegisterClass dstClass, Operand addrClass,
143 ComplexPattern addrPat> {
144 def RegisterLoad : AMDGPUShaderInst <
145 (outs dstClass:$dst),
146 (ins addrClass:$addr, i32imm:$chan),
147 "RegisterLoad $dst, $addr",
148 [(set i32:$dst, (AMDGPUregister_load addrPat:$addr, (i32 timm:$chan)))]
150 let isRegisterLoad = 1;
153 def RegisterStore : AMDGPUShaderInst <
155 (ins dstClass:$val, addrClass:$addr, i32imm:$chan),
156 "RegisterStore $val, $addr",
157 [(AMDGPUregister_store i32:$val, addrPat:$addr, (i32 timm:$chan))]
159 let isRegisterStore = 1;
163 } // End isCodeGenOnly = 1, isPseudo = 1
165 /* Generic helper patterns for intrinsics */
166 /* -------------------------------------- */
168 class POW_Common <AMDGPUInst log_ieee, AMDGPUInst exp_ieee, AMDGPUInst mul>
170 (fpow f32:$src0, f32:$src1),
171 (exp_ieee (mul f32:$src1, (log_ieee f32:$src0)))
174 /* Other helper patterns */
175 /* --------------------- */
177 /* Extract element pattern */
178 class Extract_Element <ValueType sub_type, ValueType vec_type, int sub_idx,
181 (sub_type (vector_extract vec_type:$src, sub_idx)),
182 (EXTRACT_SUBREG $src, sub_reg)
185 /* Insert element pattern */
186 class Insert_Element <ValueType elem_type, ValueType vec_type,
187 int sub_idx, SubRegIndex sub_reg>
189 (vector_insert vec_type:$vec, elem_type:$elem, sub_idx),
190 (INSERT_SUBREG $vec, $elem, sub_reg)
193 // Vector Build pattern
194 class Vector1_Build <ValueType vecType, ValueType elemType,
195 RegisterClass rc> : Pat <
196 (vecType (build_vector elemType:$src)),
197 (vecType (COPY_TO_REGCLASS $src, rc))
200 class Vector2_Build <ValueType vecType, ValueType elemType> : Pat <
201 (vecType (build_vector elemType:$sub0, elemType:$sub1)),
202 (INSERT_SUBREG (INSERT_SUBREG
203 (vecType (IMPLICIT_DEF)), $sub0, sub0), $sub1, sub1)
206 class Vector4_Build <ValueType vecType, ValueType elemType> : Pat <
207 (vecType (build_vector elemType:$x, elemType:$y, elemType:$z, elemType:$w)),
208 (INSERT_SUBREG (INSERT_SUBREG (INSERT_SUBREG (INSERT_SUBREG
209 (vecType (IMPLICIT_DEF)), $x, sub0), $y, sub1), $z, sub2), $w, sub3)
212 class Vector8_Build <ValueType vecType, ValueType elemType> : Pat <
213 (vecType (build_vector elemType:$sub0, elemType:$sub1,
214 elemType:$sub2, elemType:$sub3,
215 elemType:$sub4, elemType:$sub5,
216 elemType:$sub6, elemType:$sub7)),
217 (INSERT_SUBREG (INSERT_SUBREG (INSERT_SUBREG (INSERT_SUBREG
218 (INSERT_SUBREG (INSERT_SUBREG (INSERT_SUBREG (INSERT_SUBREG
219 (vecType (IMPLICIT_DEF)), $sub0, sub0), $sub1, sub1),
220 $sub2, sub2), $sub3, sub3),
221 $sub4, sub4), $sub5, sub5),
222 $sub6, sub6), $sub7, sub7)
225 class Vector16_Build <ValueType vecType, ValueType elemType> : Pat <
226 (vecType (build_vector elemType:$sub0, elemType:$sub1,
227 elemType:$sub2, elemType:$sub3,
228 elemType:$sub4, elemType:$sub5,
229 elemType:$sub6, elemType:$sub7,
230 elemType:$sub8, elemType:$sub9,
231 elemType:$sub10, elemType:$sub11,
232 elemType:$sub12, elemType:$sub13,
233 elemType:$sub14, elemType:$sub15)),
234 (INSERT_SUBREG (INSERT_SUBREG (INSERT_SUBREG (INSERT_SUBREG
235 (INSERT_SUBREG (INSERT_SUBREG (INSERT_SUBREG (INSERT_SUBREG
236 (INSERT_SUBREG (INSERT_SUBREG (INSERT_SUBREG (INSERT_SUBREG
237 (INSERT_SUBREG (INSERT_SUBREG (INSERT_SUBREG (INSERT_SUBREG
238 (vecType (IMPLICIT_DEF)), $sub0, sub0), $sub1, sub1),
239 $sub2, sub2), $sub3, sub3),
240 $sub4, sub4), $sub5, sub5),
241 $sub6, sub6), $sub7, sub7),
242 $sub8, sub8), $sub9, sub9),
243 $sub10, sub10), $sub11, sub11),
244 $sub12, sub12), $sub13, sub13),
245 $sub14, sub14), $sub15, sub15)
248 // XXX: Convert to new syntax and use COPY_TO_REG, once the DFAPacketizer
249 // can handle COPY instructions.
250 // bitconvert pattern
251 class BitConvert <ValueType dt, ValueType st, RegisterClass rc> : Pat <
252 (dt (bitconvert (st rc:$src0))),
256 // XXX: Convert to new syntax and use COPY_TO_REG, once the DFAPacketizer
257 // can handle COPY instructions.
258 class DwordAddrPat<ValueType vt, RegisterClass rc> : Pat <
259 (vt (AMDGPUdwordaddr (vt rc:$addr))),
265 multiclass BFIPatterns <Instruction BFI_INT> {
267 // Definition from ISA doc:
268 // (y & x) | (z & ~x)
270 (or (and i32:$y, i32:$x), (and i32:$z, (not i32:$x))),
274 // SHA-256 Ch function
277 (xor i32:$z, (and i32:$x, (xor i32:$y, i32:$z))),
283 // SHA-256 Ma patterns
285 // ((x & z) | (y & (x | z))) -> BFI_INT (XOR x, y), z, y
286 class SHA256MaPattern <Instruction BFI_INT, Instruction XOR> : Pat <
287 (or (and i32:$x, i32:$z), (and i32:$y, (or i32:$x, i32:$z))),
288 (BFI_INT (XOR i32:$x, i32:$y), i32:$z, i32:$y)
291 // Bitfield extract patterns
293 def legalshift32 : ImmLeaf <i32, [{return Imm >=0 && Imm < 32;}]>;
294 def bfemask : PatLeaf <(imm), [{return isMask_32(N->getZExtValue());}],
295 SDNodeXForm<imm, [{ return CurDAG->getTargetConstant(CountTrailingOnes_32(N->getZExtValue()), MVT::i32);}]>>;
297 class BFEPattern <Instruction BFE> : Pat <
298 (and (srl i32:$x, legalshift32:$y), bfemask:$z),
303 class ROTRPattern <Instruction BIT_ALIGN> : Pat <
304 (rotr i32:$src0, i32:$src1),
305 (BIT_ALIGN $src0, $src0, $src1)
308 include "R600Instructions.td"
310 include "SIInstrInfo.td"