blob: 3227f944e8b7ad468ffef2e9a9933b546dca1847 [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 Stellard9f950332013-07-23 01:48:35 +000099def sextloadi8_global : PatFrag<(ops node:$ptr), (sextloadi8 node:$ptr), [{
Tom Stellard75aadc22012-12-11 21:25:42 +0000100 return isGlobalLoad(dyn_cast<LoadSDNode>(N));
101}]>;
102
Tom Stellard33dd04b2013-07-23 01:47:52 +0000103def az_extloadi8_constant : PatFrag<(ops node:$ptr), (az_extloadi8 node:$ptr), [{
Tom Stellard9f950332013-07-23 01:48:35 +0000104 return isConstantLoad(dyn_cast<LoadSDNode>(N), -1);
105}]>;
106
107def sextloadi8_constant : PatFrag<(ops node:$ptr), (sextloadi8 node:$ptr), [{
108 return isConstantLoad(dyn_cast<LoadSDNode>(N), -1);
109}]>;
110
111def az_extloadi8_global : PatFrag<(ops node:$ptr), (az_extloadi8 node:$ptr), [{
Tom Stellard33dd04b2013-07-23 01:47:52 +0000112 return isGlobalLoad(dyn_cast<LoadSDNode>(N));
113}]>;
114
115def az_extloadi16 : PatFrag<(ops node:$ptr), (az_extload node:$ptr), [{
116 return cast<LoadSDNode>(N)->getMemoryVT() == MVT::i16;
117}]>;
118
119def az_extloadi16_global : PatFrag<(ops node:$ptr), (az_extloadi16 node:$ptr), [{
120 return isGlobalLoad(dyn_cast<LoadSDNode>(N));
121}]>;
122
Tom Stellard9f950332013-07-23 01:48:35 +0000123def sextloadi16_global : PatFrag<(ops node:$ptr), (sextloadi16 node:$ptr), [{
Tom Stellard07a10a32013-06-03 17:39:43 +0000124 return isGlobalLoad(dyn_cast<LoadSDNode>(N));
125}]>;
126
Tom Stellard9f950332013-07-23 01:48:35 +0000127def az_extloadi16_constant : PatFrag<(ops node:$ptr), (az_extloadi16 node:$ptr), [{
128 return isConstantLoad(dyn_cast<LoadSDNode>(N), -1);
129}]>;
130
131def sextloadi16_constant : PatFrag<(ops node:$ptr), (sextloadi16 node:$ptr), [{
132 return isConstantLoad(dyn_cast<LoadSDNode>(N), -1);
133}]>;
134
Tom Stellard31209cc2013-07-15 19:00:09 +0000135def az_extloadi32 : PatFrag<(ops node:$ptr), (az_extload node:$ptr), [{
136 return cast<LoadSDNode>(N)->getMemoryVT() == MVT::i32;
137}]>;
138
139def az_extloadi32_global : PatFrag<(ops node:$ptr),
140 (az_extloadi32 node:$ptr), [{
141 return isGlobalLoad(dyn_cast<LoadSDNode>(N));
142}]>;
143
144def az_extloadi32_constant : PatFrag<(ops node:$ptr),
145 (az_extloadi32 node:$ptr), [{
146 return isConstantLoad(dyn_cast<LoadSDNode>(N), -1);
147}]>;
148
Tom Stellardd3ee8c12013-08-16 01:12:06 +0000149def truncstorei8_global : PatFrag<(ops node:$val, node:$ptr),
150 (truncstorei8 node:$val, node:$ptr), [{
151 return isGlobalStore(dyn_cast<StoreSDNode>(N));
152}]>;
153
154def truncstorei16_global : PatFrag<(ops node:$val, node:$ptr),
155 (truncstorei16 node:$val, node:$ptr), [{
156 return isGlobalStore(dyn_cast<StoreSDNode>(N));
157}]>;
158
Tom Stellardc026e8b2013-06-28 15:47:08 +0000159def local_store : PatFrag<(ops node:$val, node:$ptr),
160 (store node:$val, node:$ptr), [{
Tom Stellardf3d166a2013-08-26 15:05:49 +0000161 return isLocalStore(dyn_cast<StoreSDNode>(N));
162}]>;
163
164def truncstorei8_local : PatFrag<(ops node:$val, node:$ptr),
165 (truncstorei8 node:$val, node:$ptr), [{
166 return isLocalStore(dyn_cast<StoreSDNode>(N));
167}]>;
168
169def truncstorei16_local : PatFrag<(ops node:$val, node:$ptr),
170 (truncstorei16 node:$val, node:$ptr), [{
171 return isLocalStore(dyn_cast<StoreSDNode>(N));
172}]>;
173
174def local_load : PatFrag<(ops node:$ptr), (load node:$ptr), [{
175 return isLocalLoad(dyn_cast<LoadSDNode>(N));
Tom Stellardc026e8b2013-06-28 15:47:08 +0000176}]>;
177
Tom Stellardd3ee8c12013-08-16 01:12:06 +0000178def mskor_global : PatFrag<(ops node:$val, node:$ptr),
179 (AMDGPUstore_mskor node:$val, node:$ptr), [{
180 return dyn_cast<MemSDNode>(N)->getAddressSpace() == AMDGPUAS::GLOBAL_ADDRESS;
181}]>;
182
Tom Stellard75aadc22012-12-11 21:25:42 +0000183class Constants {
184int TWO_PI = 0x40c90fdb;
185int PI = 0x40490fdb;
186int TWO_PI_INV = 0x3e22f983;
Michel Danzer8caa9042013-04-10 17:17:56 +0000187int FP_UINT_MAX_PLUS_1 = 0x4f800000; // 1 << 32 in floating point encoding
Tom Stellard75aadc22012-12-11 21:25:42 +0000188}
189def CONST : Constants;
190
191def FP_ZERO : PatLeaf <
192 (fpimm),
193 [{return N->getValueAPF().isZero();}]
194>;
195
196def FP_ONE : PatLeaf <
197 (fpimm),
198 [{return N->isExactlyValue(1.0);}]
199>;
200
Tom Stellard41fc7852013-07-23 01:48:42 +0000201def U24 : ComplexPattern<i32, 1, "SelectU24", [], []>;
202def I24 : ComplexPattern<i32, 1, "SelectI24", [], []>;
203
Tom Stellardf3b2a1e2013-02-06 17:32:29 +0000204let isCodeGenOnly = 1, isPseudo = 1 in {
205
206let usesCustomInserter = 1 in {
Tom Stellard75aadc22012-12-11 21:25:42 +0000207
208class CLAMP <RegisterClass rc> : AMDGPUShaderInst <
209 (outs rc:$dst),
210 (ins rc:$src0),
211 "CLAMP $dst, $src0",
Tom Stellard40b7f1f2013-05-02 15:30:12 +0000212 [(set f32:$dst, (int_AMDIL_clamp f32:$src0, (f32 FP_ZERO), (f32 FP_ONE)))]
Tom Stellard75aadc22012-12-11 21:25:42 +0000213>;
214
215class FABS <RegisterClass rc> : AMDGPUShaderInst <
216 (outs rc:$dst),
217 (ins rc:$src0),
218 "FABS $dst, $src0",
Tom Stellard40b7f1f2013-05-02 15:30:12 +0000219 [(set f32:$dst, (fabs f32:$src0))]
Tom Stellard75aadc22012-12-11 21:25:42 +0000220>;
221
222class FNEG <RegisterClass rc> : AMDGPUShaderInst <
223 (outs rc:$dst),
224 (ins rc:$src0),
225 "FNEG $dst, $src0",
Tom Stellard40b7f1f2013-05-02 15:30:12 +0000226 [(set f32:$dst, (fneg f32:$src0))]
Tom Stellard75aadc22012-12-11 21:25:42 +0000227>;
228
Tom Stellardf3b2a1e2013-02-06 17:32:29 +0000229} // usesCustomInserter = 1
230
231multiclass RegisterLoadStore <RegisterClass dstClass, Operand addrClass,
232 ComplexPattern addrPat> {
233 def RegisterLoad : AMDGPUShaderInst <
234 (outs dstClass:$dst),
235 (ins addrClass:$addr, i32imm:$chan),
236 "RegisterLoad $dst, $addr",
Tom Stellard40b7f1f2013-05-02 15:30:12 +0000237 [(set i32:$dst, (AMDGPUregister_load addrPat:$addr, (i32 timm:$chan)))]
Tom Stellardf3b2a1e2013-02-06 17:32:29 +0000238 > {
239 let isRegisterLoad = 1;
240 }
241
242 def RegisterStore : AMDGPUShaderInst <
243 (outs),
244 (ins dstClass:$val, addrClass:$addr, i32imm:$chan),
245 "RegisterStore $val, $addr",
Tom Stellard40b7f1f2013-05-02 15:30:12 +0000246 [(AMDGPUregister_store i32:$val, addrPat:$addr, (i32 timm:$chan))]
Tom Stellardf3b2a1e2013-02-06 17:32:29 +0000247 > {
248 let isRegisterStore = 1;
249 }
250}
251
252} // End isCodeGenOnly = 1, isPseudo = 1
Tom Stellard75aadc22012-12-11 21:25:42 +0000253
254/* Generic helper patterns for intrinsics */
255/* -------------------------------------- */
256
Tom Stellard40b7f1f2013-05-02 15:30:12 +0000257class POW_Common <AMDGPUInst log_ieee, AMDGPUInst exp_ieee, AMDGPUInst mul>
258 : Pat <
259 (fpow f32:$src0, f32:$src1),
260 (exp_ieee (mul f32:$src1, (log_ieee f32:$src0)))
Tom Stellard75aadc22012-12-11 21:25:42 +0000261>;
262
263/* Other helper patterns */
264/* --------------------- */
265
266/* Extract element pattern */
Tom Stellard40b7f1f2013-05-02 15:30:12 +0000267class Extract_Element <ValueType sub_type, ValueType vec_type, int sub_idx,
268 SubRegIndex sub_reg>
269 : Pat<
270 (sub_type (vector_extract vec_type:$src, sub_idx)),
271 (EXTRACT_SUBREG $src, sub_reg)
Tom Stellard75aadc22012-12-11 21:25:42 +0000272>;
273
274/* Insert element pattern */
275class Insert_Element <ValueType elem_type, ValueType vec_type,
Tom Stellard40b7f1f2013-05-02 15:30:12 +0000276 int sub_idx, SubRegIndex sub_reg>
277 : Pat <
278 (vector_insert vec_type:$vec, elem_type:$elem, sub_idx),
279 (INSERT_SUBREG $vec, $elem, sub_reg)
Tom Stellard75aadc22012-12-11 21:25:42 +0000280>;
281
Tom Stellard40b7f1f2013-05-02 15:30:12 +0000282class Vector4_Build <ValueType vecType, ValueType elemType> : Pat <
283 (vecType (build_vector elemType:$x, elemType:$y, elemType:$z, elemType:$w)),
Tom Stellard75aadc22012-12-11 21:25:42 +0000284 (INSERT_SUBREG (INSERT_SUBREG (INSERT_SUBREG (INSERT_SUBREG
Tom Stellard40b7f1f2013-05-02 15:30:12 +0000285 (vecType (IMPLICIT_DEF)), $x, sub0), $y, sub1), $z, sub2), $w, sub3)
Tom Stellard75aadc22012-12-11 21:25:42 +0000286>;
287
Tom Stellard40b7f1f2013-05-02 15:30:12 +0000288// XXX: Convert to new syntax and use COPY_TO_REG, once the DFAPacketizer
289// can handle COPY instructions.
Tom Stellard75aadc22012-12-11 21:25:42 +0000290// bitconvert pattern
291class BitConvert <ValueType dt, ValueType st, RegisterClass rc> : Pat <
292 (dt (bitconvert (st rc:$src0))),
293 (dt rc:$src0)
294>;
295
Tom Stellard40b7f1f2013-05-02 15:30:12 +0000296// XXX: Convert to new syntax and use COPY_TO_REG, once the DFAPacketizer
297// can handle COPY instructions.
Tom Stellard75aadc22012-12-11 21:25:42 +0000298class DwordAddrPat<ValueType vt, RegisterClass rc> : Pat <
299 (vt (AMDGPUdwordaddr (vt rc:$addr))),
300 (vt rc:$addr)
301>;
302
Tom Stellard9d10c4c2013-04-19 02:11:06 +0000303// BFI_INT patterns
304
305multiclass BFIPatterns <Instruction BFI_INT> {
306
307 // Definition from ISA doc:
308 // (y & x) | (z & ~x)
309 def : Pat <
310 (or (and i32:$y, i32:$x), (and i32:$z, (not i32:$x))),
311 (BFI_INT $x, $y, $z)
312 >;
313
314 // SHA-256 Ch function
315 // z ^ (x & (y ^ z))
316 def : Pat <
317 (xor i32:$z, (and i32:$x, (xor i32:$y, i32:$z))),
318 (BFI_INT $x, $y, $z)
319 >;
320
321}
322
Tom Stellardeac65dd2013-05-03 17:21:20 +0000323// SHA-256 Ma patterns
324
325// ((x & z) | (y & (x | z))) -> BFI_INT (XOR x, y), z, y
326class SHA256MaPattern <Instruction BFI_INT, Instruction XOR> : Pat <
327 (or (and i32:$x, i32:$z), (and i32:$y, (or i32:$x, i32:$z))),
328 (BFI_INT (XOR i32:$x, i32:$y), i32:$z, i32:$y)
329>;
330
Tom Stellard2b971eb2013-05-10 02:09:45 +0000331// Bitfield extract patterns
332
333def legalshift32 : ImmLeaf <i32, [{return Imm >=0 && Imm < 32;}]>;
334def bfemask : PatLeaf <(imm), [{return isMask_32(N->getZExtValue());}],
335 SDNodeXForm<imm, [{ return CurDAG->getTargetConstant(CountTrailingOnes_32(N->getZExtValue()), MVT::i32);}]>>;
336
337class BFEPattern <Instruction BFE> : Pat <
338 (and (srl i32:$x, legalshift32:$y), bfemask:$z),
339 (BFE $x, $y, $z)
340>;
341
Tom Stellard5643c4a2013-05-20 15:02:19 +0000342// rotr pattern
343class ROTRPattern <Instruction BIT_ALIGN> : Pat <
344 (rotr i32:$src0, i32:$src1),
345 (BIT_ALIGN $src0, $src0, $src1)
346>;
347
Tom Stellard41fc7852013-07-23 01:48:42 +0000348// 24-bit arithmetic patterns
349def umul24 : PatFrag <(ops node:$x, node:$y), (mul node:$x, node:$y)>;
350
351/*
352class UMUL24Pattern <Instruction UMUL24> : Pat <
353 (mul U24:$x, U24:$y),
354 (UMUL24 $x, $y)
355>;
356*/
357
Tom Stellard75aadc22012-12-11 21:25:42 +0000358include "R600Instructions.td"
359
360include "SIInstrInfo.td"
361