R600: Remove unnecessary build_vector pattern.
[oota-llvm.git] / lib / Target / R600 / AMDGPUInstructions.td
1 //===-- 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
15 class AMDGPUInst <dag outs, dag ins, string asm, list<dag> pattern> : Instruction {
16   field bit isRegisterLoad = 0;
17   field bit isRegisterStore = 0;
18
19   let Namespace = "AMDGPU";
20   let OutOperandList = outs;
21   let InOperandList = ins;
22   let AsmString = asm;
23   let Pattern = pattern;
24   let Itinerary = NullALU;
25
26   let TSFlags{63} = isRegisterLoad;
27   let TSFlags{62} = isRegisterStore;
28 }
29
30 class 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
37 def InstFlag : OperandWithDefaultOps <i32, (ops (i32 0))>;
38 def ADDRIndirect : ComplexPattern<iPTR, 2, "SelectADDRIndirect", [], []>;
39
40 //===----------------------------------------------------------------------===//
41 // PatLeafs for floating-point comparisons
42 //===----------------------------------------------------------------------===//
43
44 def COND_OEQ : PatLeaf <
45   (cond),
46   [{return N->get() == ISD::SETOEQ || N->get() == ISD::SETEQ;}]
47 >;
48
49 def COND_OGT : PatLeaf <
50   (cond),
51   [{return N->get() == ISD::SETOGT || N->get() == ISD::SETGT;}]
52 >;
53
54 def COND_OGE : PatLeaf <
55   (cond),
56   [{return N->get() == ISD::SETOGE || N->get() == ISD::SETGE;}]
57 >;
58
59 def COND_OLT : PatLeaf <
60   (cond),
61   [{return N->get() == ISD::SETOLT || N->get() == ISD::SETLT;}]
62 >;
63
64 def COND_OLE : PatLeaf <
65   (cond),
66   [{return N->get() == ISD::SETOLE || N->get() == ISD::SETLE;}]
67 >;
68
69 def COND_UNE : PatLeaf <
70   (cond),
71   [{return N->get() == ISD::SETUNE || N->get() == ISD::SETNE;}]
72 >;
73
74 def COND_O : PatLeaf <(cond), [{return N->get() == ISD::SETO;}]>;
75 def COND_UO : PatLeaf <(cond), [{return N->get() == ISD::SETUO;}]>;
76
77 //===----------------------------------------------------------------------===//
78 // PatLeafs for unsigned comparisons
79 //===----------------------------------------------------------------------===//
80
81 def COND_UGT : PatLeaf <(cond), [{return N->get() == ISD::SETUGT;}]>;
82 def COND_UGE : PatLeaf <(cond), [{return N->get() == ISD::SETUGE;}]>;
83 def COND_ULT : PatLeaf <(cond), [{return N->get() == ISD::SETULT;}]>;
84 def COND_ULE : PatLeaf <(cond), [{return N->get() == ISD::SETULE;}]>;
85
86 //===----------------------------------------------------------------------===//
87 // PatLeafs for signed comparisons
88 //===----------------------------------------------------------------------===//
89
90 def COND_SGT : PatLeaf <(cond), [{return N->get() == ISD::SETGT;}]>;
91 def COND_SGE : PatLeaf <(cond), [{return N->get() == ISD::SETGE;}]>;
92 def COND_SLT : PatLeaf <(cond), [{return N->get() == ISD::SETLT;}]>;
93 def COND_SLE : PatLeaf <(cond), [{return N->get() == ISD::SETLE;}]>;
94
95 //===----------------------------------------------------------------------===//
96 // PatLeafs for integer equality
97 //===----------------------------------------------------------------------===//
98
99 def COND_EQ : PatLeaf <
100   (cond),
101   [{return N->get() == ISD::SETEQ || N->get() == ISD::SETUEQ;}]
102 >;
103
104 def COND_NE : PatLeaf <
105   (cond),
106   [{return N->get() == ISD::SETNE || N->get() == ISD::SETUNE;}]
107 >;
108
109 def COND_NULL : PatLeaf <
110   (cond),
111   [{return false;}]
112 >;
113
114 //===----------------------------------------------------------------------===//
115 // Load/Store Pattern Fragments
116 //===----------------------------------------------------------------------===//
117
118 def az_extload : PatFrag<(ops node:$ptr), (unindexedload node:$ptr), [{
119   LoadSDNode *L = cast<LoadSDNode>(N);
120   return L->getExtensionType() == ISD::ZEXTLOAD ||
121          L->getExtensionType() == ISD::EXTLOAD;
122 }]>;
123
124 def az_extloadi8 : PatFrag<(ops node:$ptr), (az_extload node:$ptr), [{
125   return cast<LoadSDNode>(N)->getMemoryVT() == MVT::i8;
126 }]>;
127
128 def az_extloadi8_global : PatFrag<(ops node:$ptr), (az_extloadi8 node:$ptr), [{
129     return isGlobalLoad(dyn_cast<LoadSDNode>(N));
130 }]>;
131
132 def sextloadi8_global : PatFrag<(ops node:$ptr), (sextloadi8 node:$ptr), [{
133     return isGlobalLoad(dyn_cast<LoadSDNode>(N));
134 }]>;
135
136 def az_extloadi8_constant : PatFrag<(ops node:$ptr), (az_extloadi8 node:$ptr), [{
137     return isConstantLoad(dyn_cast<LoadSDNode>(N), -1);
138 }]>;
139
140 def sextloadi8_constant : PatFrag<(ops node:$ptr), (sextloadi8 node:$ptr), [{
141     return isConstantLoad(dyn_cast<LoadSDNode>(N), -1);
142 }]>;
143
144 def az_extloadi8_local : PatFrag<(ops node:$ptr), (az_extloadi8 node:$ptr), [{
145     return isLocalLoad(dyn_cast<LoadSDNode>(N));
146 }]>;
147
148 def sextloadi8_local : PatFrag<(ops node:$ptr), (sextloadi8 node:$ptr), [{
149     return isLocalLoad(dyn_cast<LoadSDNode>(N));
150 }]>;
151
152 def az_extloadi16 : PatFrag<(ops node:$ptr), (az_extload node:$ptr), [{
153   return cast<LoadSDNode>(N)->getMemoryVT() == MVT::i16;
154 }]>;
155
156 def az_extloadi16_global : PatFrag<(ops node:$ptr), (az_extloadi16 node:$ptr), [{
157     return isGlobalLoad(dyn_cast<LoadSDNode>(N));
158 }]>;
159
160 def sextloadi16_global : PatFrag<(ops node:$ptr), (sextloadi16 node:$ptr), [{
161     return isGlobalLoad(dyn_cast<LoadSDNode>(N));
162 }]>;
163
164 def az_extloadi16_constant : PatFrag<(ops node:$ptr), (az_extloadi16 node:$ptr), [{
165     return isConstantLoad(dyn_cast<LoadSDNode>(N), -1);
166 }]>;
167
168 def sextloadi16_constant : PatFrag<(ops node:$ptr), (sextloadi16 node:$ptr), [{
169     return isConstantLoad(dyn_cast<LoadSDNode>(N), -1);
170 }]>;
171
172 def az_extloadi16_local : PatFrag<(ops node:$ptr), (az_extloadi16 node:$ptr), [{
173     return isLocalLoad(dyn_cast<LoadSDNode>(N));
174 }]>;
175
176 def sextloadi16_local : PatFrag<(ops node:$ptr), (sextloadi16 node:$ptr), [{
177     return isLocalLoad(dyn_cast<LoadSDNode>(N));
178 }]>;
179
180 def az_extloadi32 : PatFrag<(ops node:$ptr), (az_extload node:$ptr), [{
181   return cast<LoadSDNode>(N)->getMemoryVT() == MVT::i32;
182 }]>;
183
184 def az_extloadi32_global : PatFrag<(ops node:$ptr),
185                                    (az_extloadi32 node:$ptr), [{
186   return isGlobalLoad(dyn_cast<LoadSDNode>(N));
187 }]>;
188
189 def az_extloadi32_constant : PatFrag<(ops node:$ptr),
190                                      (az_extloadi32 node:$ptr), [{
191   return isConstantLoad(dyn_cast<LoadSDNode>(N), -1);
192 }]>;
193
194 def truncstorei8_global : PatFrag<(ops node:$val, node:$ptr),
195                                   (truncstorei8 node:$val, node:$ptr), [{
196   return isGlobalStore(dyn_cast<StoreSDNode>(N));
197 }]>;
198
199 def truncstorei16_global : PatFrag<(ops node:$val, node:$ptr),
200                                   (truncstorei16 node:$val, node:$ptr), [{
201   return isGlobalStore(dyn_cast<StoreSDNode>(N));
202 }]>;
203
204 def local_store : PatFrag<(ops node:$val, node:$ptr),
205                              (store node:$val, node:$ptr), [{
206   return isLocalStore(dyn_cast<StoreSDNode>(N));
207 }]>;
208
209 def truncstorei8_local : PatFrag<(ops node:$val, node:$ptr),
210                                   (truncstorei8 node:$val, node:$ptr), [{
211   return isLocalStore(dyn_cast<StoreSDNode>(N));
212 }]>;
213
214 def truncstorei16_local : PatFrag<(ops node:$val, node:$ptr),
215                                   (truncstorei16 node:$val, node:$ptr), [{
216   return isLocalStore(dyn_cast<StoreSDNode>(N));
217 }]>;
218
219 def local_load : PatFrag<(ops node:$ptr), (load node:$ptr), [{
220     return isLocalLoad(dyn_cast<LoadSDNode>(N));
221 }]>;
222
223 def atomic_load_add_local : PatFrag<(ops node:$ptr, node:$value),
224                                     (atomic_load_add node:$ptr, node:$value), [{
225   return dyn_cast<MemSDNode>(N)->getAddressSpace() == AMDGPUAS::LOCAL_ADDRESS;
226 }]>;
227
228 def atomic_load_sub_local : PatFrag<(ops node:$ptr, node:$value),
229                                     (atomic_load_sub node:$ptr, node:$value), [{
230   return dyn_cast<MemSDNode>(N)->getAddressSpace() == AMDGPUAS::LOCAL_ADDRESS;
231 }]>;
232
233 def mskor_global : PatFrag<(ops node:$val, node:$ptr),
234                             (AMDGPUstore_mskor node:$val, node:$ptr), [{
235   return dyn_cast<MemSDNode>(N)->getAddressSpace() == AMDGPUAS::GLOBAL_ADDRESS;
236 }]>;
237
238 class Constants {
239 int TWO_PI = 0x40c90fdb;
240 int PI = 0x40490fdb;
241 int TWO_PI_INV = 0x3e22f983;
242 int FP_UINT_MAX_PLUS_1 = 0x4f800000;    // 1 << 32 in floating point encoding
243 }
244 def CONST : Constants;
245
246 def FP_ZERO : PatLeaf <
247   (fpimm),
248   [{return N->getValueAPF().isZero();}]
249 >;
250
251 def FP_ONE : PatLeaf <
252   (fpimm),
253   [{return N->isExactlyValue(1.0);}]
254 >;
255
256 def U24 : ComplexPattern<i32, 1, "SelectU24", [], []>;
257 def I24 : ComplexPattern<i32, 1, "SelectI24", [], []>;
258
259 let isCodeGenOnly = 1, isPseudo = 1 in {
260
261 let usesCustomInserter = 1  in {
262
263 class CLAMP <RegisterClass rc> : AMDGPUShaderInst <
264   (outs rc:$dst),
265   (ins rc:$src0),
266   "CLAMP $dst, $src0",
267   [(set f32:$dst, (int_AMDIL_clamp f32:$src0, (f32 FP_ZERO), (f32 FP_ONE)))]
268 >;
269
270 class FABS <RegisterClass rc> : AMDGPUShaderInst <
271   (outs rc:$dst),
272   (ins rc:$src0),
273   "FABS $dst, $src0",
274   [(set f32:$dst, (fabs f32:$src0))]
275 >;
276
277 class FNEG <RegisterClass rc> : AMDGPUShaderInst <
278   (outs rc:$dst),
279   (ins rc:$src0),
280   "FNEG $dst, $src0",
281   [(set f32:$dst, (fneg f32:$src0))]
282 >;
283
284 } // usesCustomInserter = 1
285
286 multiclass RegisterLoadStore <RegisterClass dstClass, Operand addrClass,
287                     ComplexPattern addrPat> {
288 let UseNamedOperandTable = 1 in {
289
290   def RegisterLoad : AMDGPUShaderInst <
291     (outs dstClass:$dst),
292     (ins addrClass:$addr, i32imm:$chan),
293     "RegisterLoad $dst, $addr",
294     [(set i32:$dst, (AMDGPUregister_load addrPat:$addr, (i32 timm:$chan)))]
295   > {
296     let isRegisterLoad = 1;
297   }
298
299   def RegisterStore : AMDGPUShaderInst <
300     (outs),
301     (ins dstClass:$val, addrClass:$addr, i32imm:$chan),
302     "RegisterStore $val, $addr",
303     [(AMDGPUregister_store i32:$val, addrPat:$addr, (i32 timm:$chan))]
304   > {
305     let isRegisterStore = 1;
306   }
307 }
308 }
309
310 } // End isCodeGenOnly = 1, isPseudo = 1
311
312 /* Generic helper patterns for intrinsics */
313 /* -------------------------------------- */
314
315 class POW_Common <AMDGPUInst log_ieee, AMDGPUInst exp_ieee, AMDGPUInst mul>
316   : Pat <
317   (fpow f32:$src0, f32:$src1),
318   (exp_ieee (mul f32:$src1, (log_ieee f32:$src0)))
319 >;
320
321 /* Other helper patterns */
322 /* --------------------- */
323
324 /* Extract element pattern */
325 class Extract_Element <ValueType sub_type, ValueType vec_type, int sub_idx,
326                        SubRegIndex sub_reg>
327   : Pat<
328   (sub_type (vector_extract vec_type:$src, sub_idx)),
329   (EXTRACT_SUBREG $src, sub_reg)
330 >;
331
332 /* Insert element pattern */
333 class Insert_Element <ValueType elem_type, ValueType vec_type,
334                       int sub_idx, SubRegIndex sub_reg>
335   : Pat <
336   (vector_insert vec_type:$vec, elem_type:$elem, sub_idx),
337   (INSERT_SUBREG $vec, $elem, sub_reg)
338 >;
339
340 // XXX: Convert to new syntax and use COPY_TO_REG, once the DFAPacketizer
341 // can handle COPY instructions.
342 // bitconvert pattern
343 class BitConvert <ValueType dt, ValueType st, RegisterClass rc> : Pat <
344   (dt (bitconvert (st rc:$src0))),
345   (dt rc:$src0)
346 >;
347
348 // XXX: Convert to new syntax and use COPY_TO_REG, once the DFAPacketizer
349 // can handle COPY instructions.
350 class DwordAddrPat<ValueType vt, RegisterClass rc> : Pat <
351   (vt (AMDGPUdwordaddr (vt rc:$addr))),
352   (vt rc:$addr)
353 >;
354
355 // BFI_INT patterns
356
357 multiclass BFIPatterns <Instruction BFI_INT> {
358
359   // Definition from ISA doc:
360   // (y & x) | (z & ~x)
361   def : Pat <
362     (or (and i32:$y, i32:$x), (and i32:$z, (not i32:$x))),
363     (BFI_INT $x, $y, $z)
364   >;
365
366   // SHA-256 Ch function
367   // z ^ (x & (y ^ z))
368   def : Pat <
369     (xor i32:$z, (and i32:$x, (xor i32:$y, i32:$z))),
370     (BFI_INT $x, $y, $z)
371   >;
372
373 }
374
375 // SHA-256 Ma patterns
376
377 // ((x & z) | (y & (x | z))) -> BFI_INT (XOR x, y), z, y
378 class SHA256MaPattern <Instruction BFI_INT, Instruction XOR> : Pat <
379   (or (and i32:$x, i32:$z), (and i32:$y, (or i32:$x, i32:$z))),
380   (BFI_INT (XOR i32:$x, i32:$y), i32:$z, i32:$y)
381 >;
382
383 // Bitfield extract patterns
384
385 /*
386
387 XXX: The BFE pattern is not working correctly because the XForm is not being
388 applied.
389
390 def legalshift32 : ImmLeaf <i32, [{return Imm >=0 && Imm < 32;}]>;
391 def bfemask : PatLeaf <(imm), [{return isMask_32(N->getZExtValue());}],
392                             SDNodeXForm<imm, [{ return CurDAG->getTargetConstant(CountTrailingOnes_32(N->getZExtValue()), MVT::i32);}]>>;
393
394 class BFEPattern <Instruction BFE> : Pat <
395   (and (srl i32:$x, legalshift32:$y), bfemask:$z),
396   (BFE $x, $y, $z)
397 >;
398
399 */
400
401 // rotr pattern
402 class ROTRPattern <Instruction BIT_ALIGN> : Pat <
403   (rotr i32:$src0, i32:$src1),
404   (BIT_ALIGN $src0, $src0, $src1)
405 >;
406
407 // 24-bit arithmetic patterns
408 def umul24 : PatFrag <(ops node:$x, node:$y), (mul node:$x, node:$y)>;
409
410 /*
411 class UMUL24Pattern <Instruction UMUL24> : Pat <
412   (mul U24:$x, U24:$y),
413   (UMUL24 $x, $y)
414 >;
415 */
416
417 include "R600Instructions.td"
418
419 include "SIInstrInfo.td"
420