blob: e30abc08bdb17f0957f4d05d65d9b2446c0d8a0f [file] [log] [blame]
Tom Stellard75aadc22012-12-11 21:25:42 +00001//===-- AMDGPUInstructions.td - Common instruction defs ---*- tablegen -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file contains instruction defs that are common to all hw codegen
11// targets.
12//
13//===----------------------------------------------------------------------===//
14
15class AMDGPUInst <dag outs, dag ins, string asm, list<dag> pattern> : Instruction {
Tom Stellardf3b2a1e2013-02-06 17:32:29 +000016 field bit isRegisterLoad = 0;
17 field bit isRegisterStore = 0;
Tom Stellard75aadc22012-12-11 21:25:42 +000018
19 let Namespace = "AMDGPU";
20 let OutOperandList = outs;
21 let InOperandList = ins;
22 let AsmString = asm;
23 let Pattern = pattern;
24 let Itinerary = NullALU;
Tom Stellardf3b2a1e2013-02-06 17:32:29 +000025
26 let TSFlags{63} = isRegisterLoad;
27 let TSFlags{62} = isRegisterStore;
Tom Stellard75aadc22012-12-11 21:25:42 +000028}
29
30class AMDGPUShaderInst <dag outs, dag ins, string asm, list<dag> pattern>
31 : AMDGPUInst<outs, ins, asm, pattern> {
32
33 field bits<32> Inst = 0xffffffff;
34
35}
36
37def InstFlag : OperandWithDefaultOps <i32, (ops (i32 0))>;
38
39def COND_EQ : PatLeaf <
40 (cond),
41 [{switch(N->get()){{default: return false;
42 case ISD::SETOEQ: case ISD::SETUEQ:
43 case ISD::SETEQ: return true;}}}]
44>;
45
46def COND_NE : PatLeaf <
47 (cond),
48 [{switch(N->get()){{default: return false;
49 case ISD::SETONE: case ISD::SETUNE:
50 case ISD::SETNE: return true;}}}]
51>;
52def COND_GT : PatLeaf <
53 (cond),
54 [{switch(N->get()){{default: return false;
55 case ISD::SETOGT: case ISD::SETUGT:
56 case ISD::SETGT: return true;}}}]
57>;
58
59def COND_GE : PatLeaf <
60 (cond),
61 [{switch(N->get()){{default: return false;
62 case ISD::SETOGE: case ISD::SETUGE:
63 case ISD::SETGE: return true;}}}]
64>;
65
66def COND_LT : PatLeaf <
67 (cond),
68 [{switch(N->get()){{default: return false;
69 case ISD::SETOLT: case ISD::SETULT:
70 case ISD::SETLT: return true;}}}]
71>;
72
73def COND_LE : PatLeaf <
74 (cond),
75 [{switch(N->get()){{default: return false;
76 case ISD::SETOLE: case ISD::SETULE:
77 case ISD::SETLE: return true;}}}]
78>;
79
Christian Konigb19849a2013-02-21 15:17:04 +000080def COND_NULL : PatLeaf <
81 (cond),
82 [{return false;}]
83>;
84
Tom Stellard75aadc22012-12-11 21:25:42 +000085//===----------------------------------------------------------------------===//
86// Load/Store Pattern Fragments
87//===----------------------------------------------------------------------===//
88
Tom Stellard31209cc2013-07-15 19:00:09 +000089def az_extload : PatFrag<(ops node:$ptr), (unindexedload node:$ptr), [{
90 LoadSDNode *L = cast<LoadSDNode>(N);
91 return L->getExtensionType() == ISD::ZEXTLOAD ||
92 L->getExtensionType() == ISD::EXTLOAD;
93}]>;
94
Tom Stellard33dd04b2013-07-23 01:47:52 +000095def az_extloadi8 : PatFrag<(ops node:$ptr), (az_extload node:$ptr), [{
96 return cast<LoadSDNode>(N)->getMemoryVT() == MVT::i8;
97}]>;
98
Tom Stellardc6f4a292013-08-26 15:05:59 +000099def az_extloadi8_global : PatFrag<(ops node:$ptr), (az_extloadi8 node:$ptr), [{
100 return isGlobalLoad(dyn_cast<LoadSDNode>(N));
101}]>;
102
Tom Stellard9f950332013-07-23 01:48:35 +0000103def sextloadi8_global : PatFrag<(ops node:$ptr), (sextloadi8 node:$ptr), [{
Tom Stellard75aadc22012-12-11 21:25:42 +0000104 return isGlobalLoad(dyn_cast<LoadSDNode>(N));
105}]>;
106
Tom Stellard33dd04b2013-07-23 01:47:52 +0000107def az_extloadi8_constant : PatFrag<(ops node:$ptr), (az_extloadi8 node:$ptr), [{
Tom Stellard9f950332013-07-23 01:48:35 +0000108 return isConstantLoad(dyn_cast<LoadSDNode>(N), -1);
109}]>;
110
111def sextloadi8_constant : PatFrag<(ops node:$ptr), (sextloadi8 node:$ptr), [{
112 return isConstantLoad(dyn_cast<LoadSDNode>(N), -1);
113}]>;
114
Tom Stellardc6f4a292013-08-26 15:05:59 +0000115def az_extloadi8_local : PatFrag<(ops node:$ptr), (az_extloadi8 node:$ptr), [{
116 return isLocalLoad(dyn_cast<LoadSDNode>(N));
117}]>;
118
119def sextloadi8_local : PatFrag<(ops node:$ptr), (sextloadi8 node:$ptr), [{
120 return isLocalLoad(dyn_cast<LoadSDNode>(N));
Tom Stellard33dd04b2013-07-23 01:47:52 +0000121}]>;
122
123def az_extloadi16 : PatFrag<(ops node:$ptr), (az_extload node:$ptr), [{
124 return cast<LoadSDNode>(N)->getMemoryVT() == MVT::i16;
125}]>;
126
127def az_extloadi16_global : PatFrag<(ops node:$ptr), (az_extloadi16 node:$ptr), [{
128 return isGlobalLoad(dyn_cast<LoadSDNode>(N));
129}]>;
130
Tom Stellard9f950332013-07-23 01:48:35 +0000131def sextloadi16_global : PatFrag<(ops node:$ptr), (sextloadi16 node:$ptr), [{
Tom Stellard07a10a32013-06-03 17:39:43 +0000132 return isGlobalLoad(dyn_cast<LoadSDNode>(N));
133}]>;
134
Tom Stellard9f950332013-07-23 01:48:35 +0000135def az_extloadi16_constant : PatFrag<(ops node:$ptr), (az_extloadi16 node:$ptr), [{
136 return isConstantLoad(dyn_cast<LoadSDNode>(N), -1);
137}]>;
138
139def sextloadi16_constant : PatFrag<(ops node:$ptr), (sextloadi16 node:$ptr), [{
140 return isConstantLoad(dyn_cast<LoadSDNode>(N), -1);
141}]>;
142
Tom Stellardc6f4a292013-08-26 15:05:59 +0000143def az_extloadi16_local : PatFrag<(ops node:$ptr), (az_extloadi16 node:$ptr), [{
144 return isLocalLoad(dyn_cast<LoadSDNode>(N));
145}]>;
146
147def sextloadi16_local : PatFrag<(ops node:$ptr), (sextloadi16 node:$ptr), [{
148 return isLocalLoad(dyn_cast<LoadSDNode>(N));
149}]>;
150
Tom Stellard31209cc2013-07-15 19:00:09 +0000151def az_extloadi32 : PatFrag<(ops node:$ptr), (az_extload node:$ptr), [{
152 return cast<LoadSDNode>(N)->getMemoryVT() == MVT::i32;
153}]>;
154
155def az_extloadi32_global : PatFrag<(ops node:$ptr),
156 (az_extloadi32 node:$ptr), [{
157 return isGlobalLoad(dyn_cast<LoadSDNode>(N));
158}]>;
159
160def az_extloadi32_constant : PatFrag<(ops node:$ptr),
161 (az_extloadi32 node:$ptr), [{
162 return isConstantLoad(dyn_cast<LoadSDNode>(N), -1);
163}]>;
164
Tom Stellardd3ee8c12013-08-16 01:12:06 +0000165def truncstorei8_global : PatFrag<(ops node:$val, node:$ptr),
166 (truncstorei8 node:$val, node:$ptr), [{
167 return isGlobalStore(dyn_cast<StoreSDNode>(N));
168}]>;
169
170def truncstorei16_global : PatFrag<(ops node:$val, node:$ptr),
171 (truncstorei16 node:$val, node:$ptr), [{
172 return isGlobalStore(dyn_cast<StoreSDNode>(N));
173}]>;
174
Tom Stellardc026e8b2013-06-28 15:47:08 +0000175def local_store : PatFrag<(ops node:$val, node:$ptr),
176 (store node:$val, node:$ptr), [{
Tom Stellardf3d166a2013-08-26 15:05:49 +0000177 return isLocalStore(dyn_cast<StoreSDNode>(N));
178}]>;
179
180def truncstorei8_local : PatFrag<(ops node:$val, node:$ptr),
181 (truncstorei8 node:$val, node:$ptr), [{
182 return isLocalStore(dyn_cast<StoreSDNode>(N));
183}]>;
184
185def truncstorei16_local : PatFrag<(ops node:$val, node:$ptr),
186 (truncstorei16 node:$val, node:$ptr), [{
187 return isLocalStore(dyn_cast<StoreSDNode>(N));
188}]>;
189
190def local_load : PatFrag<(ops node:$ptr), (load node:$ptr), [{
191 return isLocalLoad(dyn_cast<LoadSDNode>(N));
Tom Stellardc026e8b2013-06-28 15:47:08 +0000192}]>;
193
Tom Stellard13c68ef2013-09-05 18:38:09 +0000194def atomic_load_add_local : PatFrag<(ops node:$ptr, node:$value),
195 (atomic_load_add node:$ptr, node:$value), [{
196 return dyn_cast<MemSDNode>(N)->getAddressSpace() == AMDGPUAS::LOCAL_ADDRESS;
197}]>;
198
Aaron Watry372cecf2013-09-06 20:17:42 +0000199def atomic_load_sub_local : PatFrag<(ops node:$ptr, node:$value),
200 (atomic_load_sub node:$ptr, node:$value), [{
201 return dyn_cast<MemSDNode>(N)->getAddressSpace() == AMDGPUAS::LOCAL_ADDRESS;
202}]>;
203
Tom Stellardd3ee8c12013-08-16 01:12:06 +0000204def mskor_global : PatFrag<(ops node:$val, node:$ptr),
205 (AMDGPUstore_mskor node:$val, node:$ptr), [{
206 return dyn_cast<MemSDNode>(N)->getAddressSpace() == AMDGPUAS::GLOBAL_ADDRESS;
207}]>;
208
Tom Stellard75aadc22012-12-11 21:25:42 +0000209class Constants {
210int TWO_PI = 0x40c90fdb;
211int PI = 0x40490fdb;
212int TWO_PI_INV = 0x3e22f983;
Michel Danzer8caa9042013-04-10 17:17:56 +0000213int FP_UINT_MAX_PLUS_1 = 0x4f800000; // 1 << 32 in floating point encoding
Tom Stellard75aadc22012-12-11 21:25:42 +0000214}
215def CONST : Constants;
216
217def FP_ZERO : PatLeaf <
218 (fpimm),
219 [{return N->getValueAPF().isZero();}]
220>;
221
222def FP_ONE : PatLeaf <
223 (fpimm),
224 [{return N->isExactlyValue(1.0);}]
225>;
226
Tom Stellard41fc7852013-07-23 01:48:42 +0000227def U24 : ComplexPattern<i32, 1, "SelectU24", [], []>;
228def I24 : ComplexPattern<i32, 1, "SelectI24", [], []>;
229
Tom Stellardf3b2a1e2013-02-06 17:32:29 +0000230let isCodeGenOnly = 1, isPseudo = 1 in {
231
232let usesCustomInserter = 1 in {
Tom Stellard75aadc22012-12-11 21:25:42 +0000233
234class CLAMP <RegisterClass rc> : AMDGPUShaderInst <
235 (outs rc:$dst),
236 (ins rc:$src0),
237 "CLAMP $dst, $src0",
Tom Stellard40b7f1f2013-05-02 15:30:12 +0000238 [(set f32:$dst, (int_AMDIL_clamp f32:$src0, (f32 FP_ZERO), (f32 FP_ONE)))]
Tom Stellard75aadc22012-12-11 21:25:42 +0000239>;
240
241class FABS <RegisterClass rc> : AMDGPUShaderInst <
242 (outs rc:$dst),
243 (ins rc:$src0),
244 "FABS $dst, $src0",
Tom Stellard40b7f1f2013-05-02 15:30:12 +0000245 [(set f32:$dst, (fabs f32:$src0))]
Tom Stellard75aadc22012-12-11 21:25:42 +0000246>;
247
248class FNEG <RegisterClass rc> : AMDGPUShaderInst <
249 (outs rc:$dst),
250 (ins rc:$src0),
251 "FNEG $dst, $src0",
Tom Stellard40b7f1f2013-05-02 15:30:12 +0000252 [(set f32:$dst, (fneg f32:$src0))]
Tom Stellard75aadc22012-12-11 21:25:42 +0000253>;
254
Tom Stellardf3b2a1e2013-02-06 17:32:29 +0000255} // usesCustomInserter = 1
256
257multiclass RegisterLoadStore <RegisterClass dstClass, Operand addrClass,
258 ComplexPattern addrPat> {
259 def RegisterLoad : AMDGPUShaderInst <
260 (outs dstClass:$dst),
261 (ins addrClass:$addr, i32imm:$chan),
262 "RegisterLoad $dst, $addr",
Tom Stellard40b7f1f2013-05-02 15:30:12 +0000263 [(set i32:$dst, (AMDGPUregister_load addrPat:$addr, (i32 timm:$chan)))]
Tom Stellardf3b2a1e2013-02-06 17:32:29 +0000264 > {
265 let isRegisterLoad = 1;
266 }
267
268 def RegisterStore : AMDGPUShaderInst <
269 (outs),
270 (ins dstClass:$val, addrClass:$addr, i32imm:$chan),
271 "RegisterStore $val, $addr",
Tom Stellard40b7f1f2013-05-02 15:30:12 +0000272 [(AMDGPUregister_store i32:$val, addrPat:$addr, (i32 timm:$chan))]
Tom Stellardf3b2a1e2013-02-06 17:32:29 +0000273 > {
274 let isRegisterStore = 1;
275 }
276}
277
278} // End isCodeGenOnly = 1, isPseudo = 1
Tom Stellard75aadc22012-12-11 21:25:42 +0000279
280/* Generic helper patterns for intrinsics */
281/* -------------------------------------- */
282
Tom Stellard40b7f1f2013-05-02 15:30:12 +0000283class POW_Common <AMDGPUInst log_ieee, AMDGPUInst exp_ieee, AMDGPUInst mul>
284 : Pat <
285 (fpow f32:$src0, f32:$src1),
286 (exp_ieee (mul f32:$src1, (log_ieee f32:$src0)))
Tom Stellard75aadc22012-12-11 21:25:42 +0000287>;
288
289/* Other helper patterns */
290/* --------------------- */
291
292/* Extract element pattern */
Tom Stellard40b7f1f2013-05-02 15:30:12 +0000293class Extract_Element <ValueType sub_type, ValueType vec_type, int sub_idx,
294 SubRegIndex sub_reg>
295 : Pat<
296 (sub_type (vector_extract vec_type:$src, sub_idx)),
297 (EXTRACT_SUBREG $src, sub_reg)
Tom Stellard75aadc22012-12-11 21:25:42 +0000298>;
299
300/* Insert element pattern */
301class Insert_Element <ValueType elem_type, ValueType vec_type,
Tom Stellard40b7f1f2013-05-02 15:30:12 +0000302 int sub_idx, SubRegIndex sub_reg>
303 : Pat <
304 (vector_insert vec_type:$vec, elem_type:$elem, sub_idx),
305 (INSERT_SUBREG $vec, $elem, sub_reg)
Tom Stellard75aadc22012-12-11 21:25:42 +0000306>;
307
Tom Stellard40b7f1f2013-05-02 15:30:12 +0000308class Vector4_Build <ValueType vecType, ValueType elemType> : Pat <
309 (vecType (build_vector elemType:$x, elemType:$y, elemType:$z, elemType:$w)),
Tom Stellard75aadc22012-12-11 21:25:42 +0000310 (INSERT_SUBREG (INSERT_SUBREG (INSERT_SUBREG (INSERT_SUBREG
Tom Stellard40b7f1f2013-05-02 15:30:12 +0000311 (vecType (IMPLICIT_DEF)), $x, sub0), $y, sub1), $z, sub2), $w, sub3)
Tom Stellard75aadc22012-12-11 21:25:42 +0000312>;
313
Tom Stellard40b7f1f2013-05-02 15:30:12 +0000314// XXX: Convert to new syntax and use COPY_TO_REG, once the DFAPacketizer
315// can handle COPY instructions.
Tom Stellard75aadc22012-12-11 21:25:42 +0000316// bitconvert pattern
317class BitConvert <ValueType dt, ValueType st, RegisterClass rc> : Pat <
318 (dt (bitconvert (st rc:$src0))),
319 (dt rc:$src0)
320>;
321
Tom Stellard40b7f1f2013-05-02 15:30:12 +0000322// XXX: Convert to new syntax and use COPY_TO_REG, once the DFAPacketizer
323// can handle COPY instructions.
Tom Stellard75aadc22012-12-11 21:25:42 +0000324class DwordAddrPat<ValueType vt, RegisterClass rc> : Pat <
325 (vt (AMDGPUdwordaddr (vt rc:$addr))),
326 (vt rc:$addr)
327>;
328
Tom Stellard9d10c4c2013-04-19 02:11:06 +0000329// BFI_INT patterns
330
331multiclass BFIPatterns <Instruction BFI_INT> {
332
333 // Definition from ISA doc:
334 // (y & x) | (z & ~x)
335 def : Pat <
336 (or (and i32:$y, i32:$x), (and i32:$z, (not i32:$x))),
337 (BFI_INT $x, $y, $z)
338 >;
339
340 // SHA-256 Ch function
341 // z ^ (x & (y ^ z))
342 def : Pat <
343 (xor i32:$z, (and i32:$x, (xor i32:$y, i32:$z))),
344 (BFI_INT $x, $y, $z)
345 >;
346
347}
348
Tom Stellardeac65dd2013-05-03 17:21:20 +0000349// SHA-256 Ma patterns
350
351// ((x & z) | (y & (x | z))) -> BFI_INT (XOR x, y), z, y
352class SHA256MaPattern <Instruction BFI_INT, Instruction XOR> : Pat <
353 (or (and i32:$x, i32:$z), (and i32:$y, (or i32:$x, i32:$z))),
354 (BFI_INT (XOR i32:$x, i32:$y), i32:$z, i32:$y)
355>;
356
Tom Stellard2b971eb2013-05-10 02:09:45 +0000357// Bitfield extract patterns
358
359def legalshift32 : ImmLeaf <i32, [{return Imm >=0 && Imm < 32;}]>;
360def bfemask : PatLeaf <(imm), [{return isMask_32(N->getZExtValue());}],
361 SDNodeXForm<imm, [{ return CurDAG->getTargetConstant(CountTrailingOnes_32(N->getZExtValue()), MVT::i32);}]>>;
362
363class BFEPattern <Instruction BFE> : Pat <
364 (and (srl i32:$x, legalshift32:$y), bfemask:$z),
365 (BFE $x, $y, $z)
366>;
367
Tom Stellard5643c4a2013-05-20 15:02:19 +0000368// rotr pattern
369class ROTRPattern <Instruction BIT_ALIGN> : Pat <
370 (rotr i32:$src0, i32:$src1),
371 (BIT_ALIGN $src0, $src0, $src1)
372>;
373
Tom Stellard41fc7852013-07-23 01:48:42 +0000374// 24-bit arithmetic patterns
375def umul24 : PatFrag <(ops node:$x, node:$y), (mul node:$x, node:$y)>;
376
377/*
378class UMUL24Pattern <Instruction UMUL24> : Pat <
379 (mul U24:$x, U24:$y),
380 (UMUL24 $x, $y)
381>;
382*/
383
Tom Stellard75aadc22012-12-11 21:25:42 +0000384include "R600Instructions.td"
385
386include "SIInstrInfo.td"
387