[Hexagon] Adding functionality for duplexing. Duplexing is a way to compress commonl...
[oota-llvm.git] / lib / Target / Hexagon / HexagonOperands.td
1 //===- HexagonOperands.td - Hexagon immediate processing -*- tablegen -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illnois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 // Immediate operands.
11
12 let PrintMethod = "printImmOperand" in {
13   // f32Ext type is used to identify constant extended floating point immediates.
14   def f32Ext : Operand<f32>;
15   def s32Imm : Operand<i32>;
16   def s26_6Imm : Operand<i32>;
17   def s16Imm : Operand<i32>;
18   def s12Imm : Operand<i32>;
19   def s11Imm : Operand<i32>;
20   def s11_0Imm : Operand<i32>;
21   def s11_1Imm : Operand<i32>;
22   def s11_2Imm : Operand<i32>;
23   def s11_3Imm : Operand<i32>;
24   def s10Imm : Operand<i32>;
25   def s9Imm : Operand<i32>;
26   def m9Imm : Operand<i32>;
27   def s8Imm : Operand<i32>;
28   def s8Imm64 : Operand<i64>;
29   def s6Imm : Operand<i32>;
30   def s6_3Imm : Operand<i32>;
31   def s4Imm : Operand<i32>;
32   def s4_0Imm : Operand<i32>;
33   def s4_1Imm : Operand<i32>;
34   def s4_2Imm : Operand<i32>;
35   def s4_3Imm : Operand<i32>;
36   def u64Imm : Operand<i64>;
37   def u32Imm : Operand<i32>;
38   def u26_6Imm : Operand<i32>;
39   def u16Imm : Operand<i32>;
40   def u16_0Imm : Operand<i32>;
41   def u16_1Imm : Operand<i32>;
42   def u16_2Imm : Operand<i32>;
43   def u16_3Imm : Operand<i32>;
44   def u11_3Imm : Operand<i32>;
45   def u10Imm : Operand<i32>;
46   def u9Imm : Operand<i32>;
47   def u8Imm : Operand<i32>;
48   def u7Imm : Operand<i32>;
49   def u6Imm : Operand<i32>;
50   def u6_0Imm : Operand<i32>;
51   def u6_1Imm : Operand<i32>;
52   def u6_2Imm : Operand<i32>;
53   def u6_3Imm : Operand<i32>;
54   def u5Imm : Operand<i32>;
55   def u5_2Imm : Operand<i32>;
56   def u5_3Imm : Operand<i32>;
57   def u4Imm : Operand<i32>;
58   def u4_0Imm : Operand<i32>;
59   def u4_2Imm : Operand<i32>;
60   def u3Imm : Operand<i32>;
61   def u3_0Imm : Operand<i32>;
62   def u3_1Imm : Operand<i32>;
63   def u2Imm : Operand<i32>;
64   def u1Imm : Operand<i32>;
65   def n8Imm : Operand<i32>;
66   def m6Imm : Operand<i32>;
67 }
68
69 let PrintMethod = "printNOneImmOperand" in
70 def nOneImm : Operand<i32>;
71
72 //
73 // Immediate predicates
74 //
75 def s32ImmPred  : PatLeaf<(i32 imm), [{
76   int64_t v = (int64_t)N->getSExtValue();
77   return isInt<32>(v);
78 }]>;
79
80 def s32_0ImmPred  : PatLeaf<(i32 imm), [{
81   int64_t v = (int64_t)N->getSExtValue();
82   return isInt<32>(v);
83 }]>;
84
85 def s31_1ImmPred  : PatLeaf<(i32 imm), [{
86   int64_t v = (int64_t)N->getSExtValue();
87   return isShiftedInt<31,1>(v);
88 }]>;
89
90 def s30_2ImmPred  : PatLeaf<(i32 imm), [{
91   int64_t v = (int64_t)N->getSExtValue();
92   return isShiftedInt<31,1>(v);
93 }]>;
94
95 def s29_3ImmPred  : PatLeaf<(i32 imm), [{
96   int64_t v = (int64_t)N->getSExtValue();
97   return isShiftedInt<31,1>(v);
98 }]>;
99
100 def s22_10ImmPred  : PatLeaf<(i32 imm), [{
101   int64_t v = (int64_t)N->getSExtValue();
102   return isShiftedInt<22,10>(v);
103 }]>;
104
105 def s8_24ImmPred  : PatLeaf<(i32 imm), [{
106   int64_t v = (int64_t)N->getSExtValue();
107   return isShiftedInt<8,24>(v);
108 }]>;
109
110 def s16_16ImmPred  : PatLeaf<(i32 imm), [{
111   int64_t v = (int64_t)N->getSExtValue();
112   return isShiftedInt<16,16>(v);
113 }]>;
114
115 def s26_6ImmPred  : PatLeaf<(i32 imm), [{
116   int64_t v = (int64_t)N->getSExtValue();
117   return isShiftedInt<26,6>(v);
118 }]>;
119
120 def s16ImmPred  : PatLeaf<(i32 imm), [{
121   int64_t v = (int64_t)N->getSExtValue();
122   return isInt<16>(v);
123 }]>;
124
125 def s13ImmPred  : PatLeaf<(i32 imm), [{
126   int64_t v = (int64_t)N->getSExtValue();
127   return isInt<13>(v);
128 }]>;
129
130 def s12ImmPred  : PatLeaf<(i32 imm), [{
131   int64_t v = (int64_t)N->getSExtValue();
132   return isInt<12>(v);
133 }]>;
134
135 def s11_0ImmPred  : PatLeaf<(i32 imm), [{
136   int64_t v = (int64_t)N->getSExtValue();
137   return isInt<11>(v);
138 }]>;
139
140 def s11_1ImmPred  : PatLeaf<(i32 imm), [{
141   int64_t v = (int64_t)N->getSExtValue();
142   return isShiftedInt<11,1>(v);
143 }]>;
144
145 def s11_2ImmPred  : PatLeaf<(i32 imm), [{
146   int64_t v = (int64_t)N->getSExtValue();
147   return isShiftedInt<11,2>(v);
148 }]>;
149
150 def s11_3ImmPred  : PatLeaf<(i32 imm), [{
151   int64_t v = (int64_t)N->getSExtValue();
152   return isShiftedInt<11,3>(v);
153 }]>;
154
155 def s10ImmPred  : PatLeaf<(i32 imm), [{
156   int64_t v = (int64_t)N->getSExtValue();
157   return isInt<10>(v);
158 }]>;
159
160 def s9ImmPred  : PatLeaf<(i32 imm), [{
161   int64_t v = (int64_t)N->getSExtValue();
162   return isInt<9>(v);
163 }]>;
164
165 def m9ImmPred  : PatLeaf<(i32 imm), [{
166   int64_t v = (int64_t)N->getSExtValue();
167   return isInt<9>(v) && (v != -256);
168 }]>;
169
170 def s8ImmPred  : PatLeaf<(i32 imm), [{
171   int64_t v = (int64_t)N->getSExtValue();
172   return isInt<8>(v);
173 }]>;
174
175 def s8Imm64Pred  : PatLeaf<(i64 imm), [{
176   int64_t v = (int64_t)N->getSExtValue();
177   return isInt<8>(v);
178 }]>;
179
180 def s6ImmPred  : PatLeaf<(i32 imm), [{
181   int64_t v = (int64_t)N->getSExtValue();
182   return isInt<6>(v);
183 }]>;
184
185 def s4_0ImmPred  : PatLeaf<(i32 imm), [{
186   int64_t v = (int64_t)N->getSExtValue();
187   return isInt<4>(v);
188 }]>;
189
190 def s4_1ImmPred  : PatLeaf<(i32 imm), [{
191   int64_t v = (int64_t)N->getSExtValue();
192   return isShiftedInt<4,1>(v);
193 }]>;
194
195 def s4_2ImmPred  : PatLeaf<(i32 imm), [{
196   int64_t v = (int64_t)N->getSExtValue();
197   return isShiftedInt<4,2>(v);
198 }]>;
199
200 def s4_3ImmPred  : PatLeaf<(i32 imm), [{
201   int64_t v = (int64_t)N->getSExtValue();
202   return isShiftedInt<4,3>(v);
203 }]>;
204
205
206 def u64ImmPred  : PatLeaf<(i64 imm), [{
207   // Adding "N ||" to suppress gcc unused warning.
208   return (N || true);
209 }]>;
210
211 def u32ImmPred  : PatLeaf<(i32 imm), [{
212   int64_t v = (int64_t)N->getSExtValue();
213   return isUInt<32>(v);
214 }]>;
215
216 def u32_0ImmPred  : PatLeaf<(i32 imm), [{
217   int64_t v = (int64_t)N->getSExtValue();
218   return isUInt<32>(v);
219 }]>;
220
221 def u31_1ImmPred  : PatLeaf<(i32 imm), [{
222   int64_t v = (int64_t)N->getSExtValue();
223   return isShiftedUInt<31,1>(v);
224 }]>;
225
226 def u30_2ImmPred  : PatLeaf<(i32 imm), [{
227   int64_t v = (int64_t)N->getSExtValue();
228   return isShiftedUInt<30,2>(v);
229 }]>;
230
231 def u29_3ImmPred  : PatLeaf<(i32 imm), [{
232   int64_t v = (int64_t)N->getSExtValue();
233   return isShiftedUInt<29,3>(v);
234 }]>;
235
236 def u26_6ImmPred  : PatLeaf<(i32 imm), [{
237   int64_t v = (int64_t)N->getSExtValue();
238   return isShiftedUInt<26,6>(v);
239 }]>;
240
241 def u16ImmPred  : PatLeaf<(i32 imm), [{
242   int64_t v = (int64_t)N->getSExtValue();
243   return isUInt<16>(v);
244 }]>;
245
246 def u16_s8ImmPred  : PatLeaf<(i32 imm), [{
247   int64_t v = (int64_t)N->getSExtValue();
248   return isShiftedUInt<16,8>(v);
249 }]>;
250
251 def u16_0ImmPred  : PatLeaf<(i32 imm), [{
252   int64_t v = (int64_t)N->getSExtValue();
253   return isUInt<16>(v);
254 }]>;
255
256 def u11_3ImmPred : PatLeaf<(i32 imm), [{
257   int64_t v = (int64_t)N->getSExtValue();
258   return isShiftedUInt<11,3>(v);
259 }]>;
260
261 def u9ImmPred  : PatLeaf<(i32 imm), [{
262   int64_t v = (int64_t)N->getSExtValue();
263   return isUInt<9>(v);
264 }]>;
265
266 def u8ImmPred  : PatLeaf<(i32 imm), [{
267   int64_t v = (int64_t)N->getSExtValue();
268   return isUInt<8>(v);
269 }]>;
270
271 def u7StrictPosImmPred : ImmLeaf<i32, [{
272   // u7StrictPosImmPred predicate - True if the immediate fits in an 7-bit
273   // unsigned field and is strictly greater than 0.
274   return isUInt<7>(Imm) && Imm > 0;
275 }]>;
276
277 def u7ImmPred  : PatLeaf<(i32 imm), [{
278   int64_t v = (int64_t)N->getSExtValue();
279   return isUInt<7>(v);
280 }]>;
281
282 def u6ImmPred  : PatLeaf<(i32 imm), [{
283   int64_t v = (int64_t)N->getSExtValue();
284   return isUInt<6>(v);
285 }]>;
286
287 def u6_0ImmPred  : PatLeaf<(i32 imm), [{
288   int64_t v = (int64_t)N->getSExtValue();
289   return isUInt<6>(v);
290 }]>;
291
292 def u6_1ImmPred  : PatLeaf<(i32 imm), [{
293   int64_t v = (int64_t)N->getSExtValue();
294   return isShiftedUInt<6,1>(v);
295 }]>;
296
297 def u6_2ImmPred  : PatLeaf<(i32 imm), [{
298   int64_t v = (int64_t)N->getSExtValue();
299   return isShiftedUInt<6,2>(v);
300 }]>;
301
302 def u6_3ImmPred  : PatLeaf<(i32 imm), [{
303   int64_t v = (int64_t)N->getSExtValue();
304   return isShiftedUInt<6,3>(v);
305 }]>;
306
307 def u5ImmPred  : PatLeaf<(i32 imm), [{
308   int64_t v = (int64_t)N->getSExtValue();
309   return isUInt<5>(v);
310 }]>;
311
312 def u4ImmPred  : PatLeaf<(i32 imm), [{
313   int64_t v = (int64_t)N->getSExtValue();
314   return isUInt<4>(v);
315 }]>;
316
317 def u3ImmPred  : PatLeaf<(i32 imm), [{
318   int64_t v = (int64_t)N->getSExtValue();
319   return isUInt<3>(v);
320 }]>;
321
322 def u2ImmPred  : PatLeaf<(i32 imm), [{
323   int64_t v = (int64_t)N->getSExtValue();
324   return isUInt<2>(v);
325 }]>;
326
327 def u1ImmPred  : PatLeaf<(i1 imm), [{
328   int64_t v = (int64_t)N->getSExtValue();
329   return isUInt<1>(v);
330 }]>;
331
332 def m5BImmPred  : PatLeaf<(i32 imm), [{
333   // m5BImmPred predicate - True if the (char) number is in range -1 .. -31
334   // and will fit in a 5 bit field when made positive, for use in memops.
335   // this is specific to the zero extending of a negative by CombineInstr
336   int8_t v = (int8_t)N->getSExtValue();
337   return (-31 <= v && v <= -1);
338 }]>;
339
340 def m5HImmPred  : PatLeaf<(i32 imm), [{
341   // m5HImmPred predicate - True if the (short) number is in range -1 .. -31
342   // and will fit in a 5 bit field when made positive, for use in memops.
343   // this is specific to the zero extending of a negative by CombineInstr
344   int16_t v = (int16_t)N->getSExtValue();
345   return (-31 <= v && v <= -1);
346 }]>;
347
348 def m5ImmPred  : PatLeaf<(i32 imm), [{
349   // m5ImmPred predicate - True if the number is in range -1 .. -31
350   // and will fit in a 5 bit field when made positive, for use in memops.
351   int64_t v = (int64_t)N->getSExtValue();
352   return (-31 <= v && v <= -1);
353 }]>;
354
355 //InN means negative integers in [-(2^N - 1), 0]
356 def n8ImmPred  : PatLeaf<(i32 imm), [{
357   // n8ImmPred predicate - True if the immediate fits in a 8-bit signed
358   // field.
359   int64_t v = (int64_t)N->getSExtValue();
360   return (-255 <= v && v <= 0);
361 }]>;
362
363 def nOneImmPred  : PatLeaf<(i32 imm), [{
364   // nOneImmPred predicate - True if the immediate is -1.
365   int64_t v = (int64_t)N->getSExtValue();
366   return (-1 == v);
367 }]>;
368
369 def Set5ImmPred : PatLeaf<(i32 imm), [{
370   // Set5ImmPred predicate - True if the number is in the series of values.
371   // [ 2^0, 2^1, ... 2^31 ]
372   // For use in setbit immediate.
373   uint32_t v = (int32_t)N->getSExtValue();
374   // Constrain to 32 bits, and then check for single bit.
375   return ImmIsSingleBit(v);
376 }]>;
377
378 def Clr5ImmPred : PatLeaf<(i32 imm), [{
379   // Clr5ImmPred predicate - True if the number is in the series of
380   // bit negated values.
381   // [ 2^0, 2^1, ... 2^31 ]
382   // For use in clrbit immediate.
383   // Note: we are bit NOTing the value.
384   uint32_t v = ~ (int32_t)N->getSExtValue();
385   // Constrain to 32 bits, and then check for single bit.
386   return ImmIsSingleBit(v);
387 }]>;
388
389 def SetClr5ImmPred : PatLeaf<(i32 imm), [{
390   // SetClr5ImmPred predicate - True if the immediate is in range 0..31.
391   int32_t v = (int32_t)N->getSExtValue();
392   return (v >= 0 && v <= 31);
393 }]>;
394
395 def Set4ImmPred : PatLeaf<(i32 imm), [{
396   // Set4ImmPred predicate - True if the number is in the series of values:
397   // [ 2^0, 2^1, ... 2^15 ].
398   // For use in setbit immediate.
399   uint16_t v = (int16_t)N->getSExtValue();
400   // Constrain to 16 bits, and then check for single bit.
401   return ImmIsSingleBit(v);
402 }]>;
403
404 def Clr4ImmPred : PatLeaf<(i32 imm), [{
405   // Clr4ImmPred predicate - True if the number is in the series of
406   // bit negated values:
407   // [ 2^0, 2^1, ... 2^15 ].
408   // For use in setbit and clrbit immediate.
409   uint16_t v = ~ (int16_t)N->getSExtValue();
410   // Constrain to 16 bits, and then check for single bit.
411   return ImmIsSingleBit(v);
412 }]>;
413
414 def SetClr4ImmPred : PatLeaf<(i32 imm), [{
415   // SetClr4ImmPred predicate - True if the immediate is in the range 0..15.
416   int16_t v = (int16_t)N->getSExtValue();
417   return (v >= 0 && v <= 15);
418 }]>;
419
420 def Set3ImmPred : PatLeaf<(i32 imm), [{
421   // Set3ImmPred predicate - True if the number is in the series of values:
422   // [ 2^0, 2^1, ... 2^7 ].
423   // For use in setbit immediate.
424   uint8_t v = (int8_t)N->getSExtValue();
425   // Constrain to 8 bits, and then check for single bit.
426   return ImmIsSingleBit(v);
427 }]>;
428
429 def Clr3ImmPred : PatLeaf<(i32 imm), [{
430   // Clr3ImmPred predicate - True if the number is in the series of
431   // bit negated values:
432   // [ 2^0, 2^1, ... 2^7 ].
433   // For use in setbit and clrbit immediate.
434   uint8_t v = ~ (int8_t)N->getSExtValue();
435   // Constrain to 8 bits, and then check for single bit.
436   return ImmIsSingleBit(v);
437 }]>;
438
439 def SetClr3ImmPred : PatLeaf<(i32 imm), [{
440   // SetClr3ImmPred predicate - True if the immediate is in the range  0..7.
441   int8_t v = (int8_t)N->getSExtValue();
442   return (v >= 0 && v <= 7);
443 }]>;
444
445
446 // Extendable immediate operands.
447
448 let PrintMethod = "printExtOperand" in {
449   def s16Ext : Operand<i32>;
450   def s12Ext : Operand<i32>;
451   def s10Ext : Operand<i32>;
452   def s9Ext : Operand<i32>;
453   def s8Ext : Operand<i32>;
454   def s7Ext : Operand<i32>;
455   def s6Ext : Operand<i32>;
456   def s11_0Ext : Operand<i32>;
457   def s11_1Ext : Operand<i32>;
458   def s11_2Ext : Operand<i32>;
459   def s11_3Ext : Operand<i32>;
460   def u6Ext : Operand<i32>;
461   def u7Ext : Operand<i32>;
462   def u8Ext : Operand<i32>;
463   def u9Ext : Operand<i32>;
464   def u10Ext : Operand<i32>;
465   def u6_0Ext : Operand<i32>;
466   def u6_1Ext : Operand<i32>;
467   def u6_2Ext : Operand<i32>;
468   def u6_3Ext : Operand<i32>;
469 }
470
471
472 // This complex pattern exists only to create a machine instruction operand
473 // of type "frame index". There doesn't seem to be a way to do that directly
474 // in the patterns.
475 def AddrFI : ComplexPattern<i32, 1, "SelectAddrFI", [frameindex], []>;
476
477 // These complex patterns are not strictly necessary, since global address
478 // folding will happen during DAG combining. For distinguishing between GA
479 // and GP, pat frags with HexagonCONST32 and HexagonCONST32_GP can be used.
480 def AddrGA : ComplexPattern<i32, 1, "SelectAddrGA", [], []>;
481 def AddrGP : ComplexPattern<i32, 1, "SelectAddrGP", [], []>;
482
483 // Address operands.
484
485 let PrintMethod = "printGlobalOperand" in {
486   def globaladdress : Operand<i32>;
487   def globaladdressExt : Operand<i32>;
488 }
489
490 let PrintMethod = "printJumpTable" in
491 def jumptablebase : Operand<i32>;
492
493 def brtarget : Operand<OtherVT>;
494 def brtargetExt : Operand<OtherVT> {
495   let PrintMethod = "printExtBrtarget";
496 }
497 def calltarget : Operand<i32>;
498
499 def bblabel : Operand<i32>;
500 def bbl   : SDNode<"ISD::BasicBlock", SDTPtrLeaf   , [], "BasicBlockSDNode">;
501
502 def symbolHi32 : Operand<i32> {
503   let PrintMethod = "printSymbolHi";
504 }
505 def symbolLo32 : Operand<i32> {
506   let PrintMethod = "printSymbolLo";
507 }
508
509 // Return true if for a 32 to 64-bit sign-extended load.
510 def is_sext_i32 : PatLeaf<(i64 DoubleRegs:$src1), [{
511   LoadSDNode *LD = dyn_cast<LoadSDNode>(N);
512   if (!LD)
513     return false;
514   return LD->getExtensionType() == ISD::SEXTLOAD &&
515          LD->getMemoryVT().getScalarType() == MVT::i32;
516 }]>;