blob: 5778a8c2b23f8c3f07fa59e9dbbf0bc2138ba755 [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
Tom Stellard0351ea22013-09-28 02:50:50 +000046def COND_OEQ : PatLeaf <
47 (cond),
48 [{return N->get() == ISD::SETOEQ || N->get() == ISD::SETEQ;}]
49>;
50
Tom Stellard75aadc22012-12-11 21:25:42 +000051def COND_NE : PatLeaf <
52 (cond),
53 [{switch(N->get()){{default: return false;
54 case ISD::SETONE: case ISD::SETUNE:
55 case ISD::SETNE: return true;}}}]
56>;
Tom Stellard0351ea22013-09-28 02:50:50 +000057
58def COND_UNE : PatLeaf <
59 (cond),
60 [{return N->get() == ISD::SETUNE || N->get() == ISD::SETNE;}]
61>;
62
Tom Stellard75aadc22012-12-11 21:25:42 +000063def COND_GT : PatLeaf <
64 (cond),
65 [{switch(N->get()){{default: return false;
66 case ISD::SETOGT: case ISD::SETUGT:
67 case ISD::SETGT: return true;}}}]
68>;
69
Tom Stellard0351ea22013-09-28 02:50:50 +000070def COND_OGT : PatLeaf <
71 (cond),
72 [{return N->get() == ISD::SETOGT || N->get() == ISD::SETGT;}]
73>;
74
Tom Stellard75aadc22012-12-11 21:25:42 +000075def COND_GE : PatLeaf <
76 (cond),
77 [{switch(N->get()){{default: return false;
78 case ISD::SETOGE: case ISD::SETUGE:
79 case ISD::SETGE: return true;}}}]
80>;
81
Tom Stellard0351ea22013-09-28 02:50:50 +000082def COND_OGE : PatLeaf <
83 (cond),
84 [{return N->get() == ISD::SETOGE || N->get() == ISD::SETGE;}]
85>;
86
Tom Stellard75aadc22012-12-11 21:25:42 +000087def COND_LT : PatLeaf <
88 (cond),
89 [{switch(N->get()){{default: return false;
90 case ISD::SETOLT: case ISD::SETULT:
91 case ISD::SETLT: return true;}}}]
92>;
93
94def COND_LE : PatLeaf <
95 (cond),
96 [{switch(N->get()){{default: return false;
97 case ISD::SETOLE: case ISD::SETULE:
98 case ISD::SETLE: return true;}}}]
99>;
100
Christian Konigb19849a2013-02-21 15:17:04 +0000101def COND_NULL : PatLeaf <
102 (cond),
103 [{return false;}]
104>;
105
Tom Stellard75aadc22012-12-11 21:25:42 +0000106//===----------------------------------------------------------------------===//
107// Load/Store Pattern Fragments
108//===----------------------------------------------------------------------===//
109
Tom Stellard31209cc2013-07-15 19:00:09 +0000110def az_extload : PatFrag<(ops node:$ptr), (unindexedload node:$ptr), [{
111 LoadSDNode *L = cast<LoadSDNode>(N);
112 return L->getExtensionType() == ISD::ZEXTLOAD ||
113 L->getExtensionType() == ISD::EXTLOAD;
114}]>;
115
Tom Stellard33dd04b2013-07-23 01:47:52 +0000116def az_extloadi8 : PatFrag<(ops node:$ptr), (az_extload node:$ptr), [{
117 return cast<LoadSDNode>(N)->getMemoryVT() == MVT::i8;
118}]>;
119
Tom Stellardc6f4a292013-08-26 15:05:59 +0000120def az_extloadi8_global : PatFrag<(ops node:$ptr), (az_extloadi8 node:$ptr), [{
121 return isGlobalLoad(dyn_cast<LoadSDNode>(N));
122}]>;
123
Tom Stellard9f950332013-07-23 01:48:35 +0000124def sextloadi8_global : PatFrag<(ops node:$ptr), (sextloadi8 node:$ptr), [{
Tom Stellard75aadc22012-12-11 21:25:42 +0000125 return isGlobalLoad(dyn_cast<LoadSDNode>(N));
126}]>;
127
Tom Stellard33dd04b2013-07-23 01:47:52 +0000128def az_extloadi8_constant : PatFrag<(ops node:$ptr), (az_extloadi8 node:$ptr), [{
Tom Stellard9f950332013-07-23 01:48:35 +0000129 return isConstantLoad(dyn_cast<LoadSDNode>(N), -1);
130}]>;
131
132def sextloadi8_constant : PatFrag<(ops node:$ptr), (sextloadi8 node:$ptr), [{
133 return isConstantLoad(dyn_cast<LoadSDNode>(N), -1);
134}]>;
135
Tom Stellardc6f4a292013-08-26 15:05:59 +0000136def az_extloadi8_local : PatFrag<(ops node:$ptr), (az_extloadi8 node:$ptr), [{
137 return isLocalLoad(dyn_cast<LoadSDNode>(N));
138}]>;
139
140def sextloadi8_local : PatFrag<(ops node:$ptr), (sextloadi8 node:$ptr), [{
141 return isLocalLoad(dyn_cast<LoadSDNode>(N));
Tom Stellard33dd04b2013-07-23 01:47:52 +0000142}]>;
143
144def az_extloadi16 : PatFrag<(ops node:$ptr), (az_extload node:$ptr), [{
145 return cast<LoadSDNode>(N)->getMemoryVT() == MVT::i16;
146}]>;
147
148def az_extloadi16_global : PatFrag<(ops node:$ptr), (az_extloadi16 node:$ptr), [{
149 return isGlobalLoad(dyn_cast<LoadSDNode>(N));
150}]>;
151
Tom Stellard9f950332013-07-23 01:48:35 +0000152def sextloadi16_global : PatFrag<(ops node:$ptr), (sextloadi16 node:$ptr), [{
Tom Stellard07a10a32013-06-03 17:39:43 +0000153 return isGlobalLoad(dyn_cast<LoadSDNode>(N));
154}]>;
155
Tom Stellard9f950332013-07-23 01:48:35 +0000156def az_extloadi16_constant : PatFrag<(ops node:$ptr), (az_extloadi16 node:$ptr), [{
157 return isConstantLoad(dyn_cast<LoadSDNode>(N), -1);
158}]>;
159
160def sextloadi16_constant : PatFrag<(ops node:$ptr), (sextloadi16 node:$ptr), [{
161 return isConstantLoad(dyn_cast<LoadSDNode>(N), -1);
162}]>;
163
Tom Stellardc6f4a292013-08-26 15:05:59 +0000164def az_extloadi16_local : PatFrag<(ops node:$ptr), (az_extloadi16 node:$ptr), [{
165 return isLocalLoad(dyn_cast<LoadSDNode>(N));
166}]>;
167
168def sextloadi16_local : PatFrag<(ops node:$ptr), (sextloadi16 node:$ptr), [{
169 return isLocalLoad(dyn_cast<LoadSDNode>(N));
170}]>;
171
Tom Stellard31209cc2013-07-15 19:00:09 +0000172def az_extloadi32 : PatFrag<(ops node:$ptr), (az_extload node:$ptr), [{
173 return cast<LoadSDNode>(N)->getMemoryVT() == MVT::i32;
174}]>;
175
176def az_extloadi32_global : PatFrag<(ops node:$ptr),
177 (az_extloadi32 node:$ptr), [{
178 return isGlobalLoad(dyn_cast<LoadSDNode>(N));
179}]>;
180
181def az_extloadi32_constant : PatFrag<(ops node:$ptr),
182 (az_extloadi32 node:$ptr), [{
183 return isConstantLoad(dyn_cast<LoadSDNode>(N), -1);
184}]>;
185
Tom Stellardd3ee8c12013-08-16 01:12:06 +0000186def truncstorei8_global : PatFrag<(ops node:$val, node:$ptr),
187 (truncstorei8 node:$val, node:$ptr), [{
188 return isGlobalStore(dyn_cast<StoreSDNode>(N));
189}]>;
190
191def truncstorei16_global : PatFrag<(ops node:$val, node:$ptr),
192 (truncstorei16 node:$val, node:$ptr), [{
193 return isGlobalStore(dyn_cast<StoreSDNode>(N));
194}]>;
195
Tom Stellardc026e8b2013-06-28 15:47:08 +0000196def local_store : PatFrag<(ops node:$val, node:$ptr),
197 (store node:$val, node:$ptr), [{
Tom Stellardf3d166a2013-08-26 15:05:49 +0000198 return isLocalStore(dyn_cast<StoreSDNode>(N));
199}]>;
200
201def truncstorei8_local : PatFrag<(ops node:$val, node:$ptr),
202 (truncstorei8 node:$val, node:$ptr), [{
203 return isLocalStore(dyn_cast<StoreSDNode>(N));
204}]>;
205
206def truncstorei16_local : PatFrag<(ops node:$val, node:$ptr),
207 (truncstorei16 node:$val, node:$ptr), [{
208 return isLocalStore(dyn_cast<StoreSDNode>(N));
209}]>;
210
211def local_load : PatFrag<(ops node:$ptr), (load node:$ptr), [{
212 return isLocalLoad(dyn_cast<LoadSDNode>(N));
Tom Stellardc026e8b2013-06-28 15:47:08 +0000213}]>;
214
Tom Stellard13c68ef2013-09-05 18:38:09 +0000215def atomic_load_add_local : PatFrag<(ops node:$ptr, node:$value),
216 (atomic_load_add node:$ptr, node:$value), [{
217 return dyn_cast<MemSDNode>(N)->getAddressSpace() == AMDGPUAS::LOCAL_ADDRESS;
218}]>;
219
Aaron Watry372cecf2013-09-06 20:17:42 +0000220def atomic_load_sub_local : PatFrag<(ops node:$ptr, node:$value),
221 (atomic_load_sub node:$ptr, node:$value), [{
222 return dyn_cast<MemSDNode>(N)->getAddressSpace() == AMDGPUAS::LOCAL_ADDRESS;
223}]>;
224
Tom Stellardd3ee8c12013-08-16 01:12:06 +0000225def mskor_global : PatFrag<(ops node:$val, node:$ptr),
226 (AMDGPUstore_mskor node:$val, node:$ptr), [{
227 return dyn_cast<MemSDNode>(N)->getAddressSpace() == AMDGPUAS::GLOBAL_ADDRESS;
228}]>;
229
Tom Stellard75aadc22012-12-11 21:25:42 +0000230class Constants {
231int TWO_PI = 0x40c90fdb;
232int PI = 0x40490fdb;
233int TWO_PI_INV = 0x3e22f983;
Michel Danzer8caa9042013-04-10 17:17:56 +0000234int FP_UINT_MAX_PLUS_1 = 0x4f800000; // 1 << 32 in floating point encoding
Tom Stellard75aadc22012-12-11 21:25:42 +0000235}
236def CONST : Constants;
237
238def FP_ZERO : PatLeaf <
239 (fpimm),
240 [{return N->getValueAPF().isZero();}]
241>;
242
243def FP_ONE : PatLeaf <
244 (fpimm),
245 [{return N->isExactlyValue(1.0);}]
246>;
247
Tom Stellard41fc7852013-07-23 01:48:42 +0000248def U24 : ComplexPattern<i32, 1, "SelectU24", [], []>;
249def I24 : ComplexPattern<i32, 1, "SelectI24", [], []>;
250
Tom Stellardf3b2a1e2013-02-06 17:32:29 +0000251let isCodeGenOnly = 1, isPseudo = 1 in {
252
253let usesCustomInserter = 1 in {
Tom Stellard75aadc22012-12-11 21:25:42 +0000254
255class CLAMP <RegisterClass rc> : AMDGPUShaderInst <
256 (outs rc:$dst),
257 (ins rc:$src0),
258 "CLAMP $dst, $src0",
Tom Stellard40b7f1f2013-05-02 15:30:12 +0000259 [(set f32:$dst, (int_AMDIL_clamp f32:$src0, (f32 FP_ZERO), (f32 FP_ONE)))]
Tom Stellard75aadc22012-12-11 21:25:42 +0000260>;
261
262class FABS <RegisterClass rc> : AMDGPUShaderInst <
263 (outs rc:$dst),
264 (ins rc:$src0),
265 "FABS $dst, $src0",
Tom Stellard40b7f1f2013-05-02 15:30:12 +0000266 [(set f32:$dst, (fabs f32:$src0))]
Tom Stellard75aadc22012-12-11 21:25:42 +0000267>;
268
269class FNEG <RegisterClass rc> : AMDGPUShaderInst <
270 (outs rc:$dst),
271 (ins rc:$src0),
272 "FNEG $dst, $src0",
Tom Stellard40b7f1f2013-05-02 15:30:12 +0000273 [(set f32:$dst, (fneg f32:$src0))]
Tom Stellard75aadc22012-12-11 21:25:42 +0000274>;
275
Tom Stellardf3b2a1e2013-02-06 17:32:29 +0000276} // usesCustomInserter = 1
277
278multiclass RegisterLoadStore <RegisterClass dstClass, Operand addrClass,
279 ComplexPattern addrPat> {
280 def RegisterLoad : AMDGPUShaderInst <
281 (outs dstClass:$dst),
282 (ins addrClass:$addr, i32imm:$chan),
283 "RegisterLoad $dst, $addr",
Tom Stellard40b7f1f2013-05-02 15:30:12 +0000284 [(set i32:$dst, (AMDGPUregister_load addrPat:$addr, (i32 timm:$chan)))]
Tom Stellardf3b2a1e2013-02-06 17:32:29 +0000285 > {
286 let isRegisterLoad = 1;
287 }
288
289 def RegisterStore : AMDGPUShaderInst <
290 (outs),
291 (ins dstClass:$val, addrClass:$addr, i32imm:$chan),
292 "RegisterStore $val, $addr",
Tom Stellard40b7f1f2013-05-02 15:30:12 +0000293 [(AMDGPUregister_store i32:$val, addrPat:$addr, (i32 timm:$chan))]
Tom Stellardf3b2a1e2013-02-06 17:32:29 +0000294 > {
295 let isRegisterStore = 1;
296 }
297}
298
299} // End isCodeGenOnly = 1, isPseudo = 1
Tom Stellard75aadc22012-12-11 21:25:42 +0000300
301/* Generic helper patterns for intrinsics */
302/* -------------------------------------- */
303
Tom Stellard40b7f1f2013-05-02 15:30:12 +0000304class POW_Common <AMDGPUInst log_ieee, AMDGPUInst exp_ieee, AMDGPUInst mul>
305 : Pat <
306 (fpow f32:$src0, f32:$src1),
307 (exp_ieee (mul f32:$src1, (log_ieee f32:$src0)))
Tom Stellard75aadc22012-12-11 21:25:42 +0000308>;
309
310/* Other helper patterns */
311/* --------------------- */
312
313/* Extract element pattern */
Tom Stellard40b7f1f2013-05-02 15:30:12 +0000314class Extract_Element <ValueType sub_type, ValueType vec_type, int sub_idx,
315 SubRegIndex sub_reg>
316 : Pat<
317 (sub_type (vector_extract vec_type:$src, sub_idx)),
318 (EXTRACT_SUBREG $src, sub_reg)
Tom Stellard75aadc22012-12-11 21:25:42 +0000319>;
320
321/* Insert element pattern */
322class Insert_Element <ValueType elem_type, ValueType vec_type,
Tom Stellard40b7f1f2013-05-02 15:30:12 +0000323 int sub_idx, SubRegIndex sub_reg>
324 : Pat <
325 (vector_insert vec_type:$vec, elem_type:$elem, sub_idx),
326 (INSERT_SUBREG $vec, $elem, sub_reg)
Tom Stellard75aadc22012-12-11 21:25:42 +0000327>;
328
Tom Stellard40b7f1f2013-05-02 15:30:12 +0000329class Vector4_Build <ValueType vecType, ValueType elemType> : Pat <
330 (vecType (build_vector elemType:$x, elemType:$y, elemType:$z, elemType:$w)),
Tom Stellard75aadc22012-12-11 21:25:42 +0000331 (INSERT_SUBREG (INSERT_SUBREG (INSERT_SUBREG (INSERT_SUBREG
Tom Stellard40b7f1f2013-05-02 15:30:12 +0000332 (vecType (IMPLICIT_DEF)), $x, sub0), $y, sub1), $z, sub2), $w, sub3)
Tom Stellard75aadc22012-12-11 21:25:42 +0000333>;
334
Tom Stellard40b7f1f2013-05-02 15:30:12 +0000335// XXX: Convert to new syntax and use COPY_TO_REG, once the DFAPacketizer
336// can handle COPY instructions.
Tom Stellard75aadc22012-12-11 21:25:42 +0000337// bitconvert pattern
338class BitConvert <ValueType dt, ValueType st, RegisterClass rc> : Pat <
339 (dt (bitconvert (st rc:$src0))),
340 (dt rc:$src0)
341>;
342
Tom Stellard40b7f1f2013-05-02 15:30:12 +0000343// XXX: Convert to new syntax and use COPY_TO_REG, once the DFAPacketizer
344// can handle COPY instructions.
Tom Stellard75aadc22012-12-11 21:25:42 +0000345class DwordAddrPat<ValueType vt, RegisterClass rc> : Pat <
346 (vt (AMDGPUdwordaddr (vt rc:$addr))),
347 (vt rc:$addr)
348>;
349
Tom Stellard9d10c4c2013-04-19 02:11:06 +0000350// BFI_INT patterns
351
352multiclass BFIPatterns <Instruction BFI_INT> {
353
354 // Definition from ISA doc:
355 // (y & x) | (z & ~x)
356 def : Pat <
357 (or (and i32:$y, i32:$x), (and i32:$z, (not i32:$x))),
358 (BFI_INT $x, $y, $z)
359 >;
360
361 // SHA-256 Ch function
362 // z ^ (x & (y ^ z))
363 def : Pat <
364 (xor i32:$z, (and i32:$x, (xor i32:$y, i32:$z))),
365 (BFI_INT $x, $y, $z)
366 >;
367
368}
369
Tom Stellardeac65dd2013-05-03 17:21:20 +0000370// SHA-256 Ma patterns
371
372// ((x & z) | (y & (x | z))) -> BFI_INT (XOR x, y), z, y
373class SHA256MaPattern <Instruction BFI_INT, Instruction XOR> : Pat <
374 (or (and i32:$x, i32:$z), (and i32:$y, (or i32:$x, i32:$z))),
375 (BFI_INT (XOR i32:$x, i32:$y), i32:$z, i32:$y)
376>;
377
Tom Stellard2b971eb2013-05-10 02:09:45 +0000378// Bitfield extract patterns
379
380def legalshift32 : ImmLeaf <i32, [{return Imm >=0 && Imm < 32;}]>;
381def bfemask : PatLeaf <(imm), [{return isMask_32(N->getZExtValue());}],
382 SDNodeXForm<imm, [{ return CurDAG->getTargetConstant(CountTrailingOnes_32(N->getZExtValue()), MVT::i32);}]>>;
383
384class BFEPattern <Instruction BFE> : Pat <
385 (and (srl i32:$x, legalshift32:$y), bfemask:$z),
386 (BFE $x, $y, $z)
387>;
388
Tom Stellard5643c4a2013-05-20 15:02:19 +0000389// rotr pattern
390class ROTRPattern <Instruction BIT_ALIGN> : Pat <
391 (rotr i32:$src0, i32:$src1),
392 (BIT_ALIGN $src0, $src0, $src1)
393>;
394
Tom Stellard41fc7852013-07-23 01:48:42 +0000395// 24-bit arithmetic patterns
396def umul24 : PatFrag <(ops node:$x, node:$y), (mul node:$x, node:$y)>;
397
398/*
399class UMUL24Pattern <Instruction UMUL24> : Pat <
400 (mul U24:$x, U24:$y),
401 (UMUL24 $x, $y)
402>;
403*/
404
Tom Stellard75aadc22012-12-11 21:25:42 +0000405include "R600Instructions.td"
406
407include "SIInstrInfo.td"
408