blob: 3f43d697fcb6b76b2be41904edbb881bfa863369 [file] [log] [blame]
Rafael Espindola6ee1e082012-11-21 16:56:33 +00001//===- HexagonOperands.td - Hexagon immediate processing -*- tablegen -*-===//
Tony Linthicumb4b54152011-12-12 21:14:40 +00002//
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
Jyotsna Verma81081b12012-11-21 19:53:42 +000010// Immediate operands.
11
12let 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 s4Imm : Operand<i32>;
31 def s4_0Imm : Operand<i32>;
32 def s4_1Imm : Operand<i32>;
33 def s4_2Imm : Operand<i32>;
34 def s4_3Imm : Operand<i32>;
35 def u64Imm : Operand<i64>;
36 def u32Imm : Operand<i32>;
37 def u26_6Imm : Operand<i32>;
38 def u16Imm : Operand<i32>;
39 def u16_0Imm : Operand<i32>;
40 def u16_1Imm : Operand<i32>;
41 def u16_2Imm : Operand<i32>;
42 def u11_3Imm : Operand<i32>;
43 def u10Imm : Operand<i32>;
44 def u9Imm : Operand<i32>;
45 def u8Imm : Operand<i32>;
46 def u7Imm : Operand<i32>;
47 def u6Imm : Operand<i32>;
48 def u6_0Imm : Operand<i32>;
49 def u6_1Imm : Operand<i32>;
50 def u6_2Imm : Operand<i32>;
51 def u6_3Imm : Operand<i32>;
52 def u5Imm : Operand<i32>;
53 def u4Imm : Operand<i32>;
54 def u3Imm : Operand<i32>;
55 def u2Imm : Operand<i32>;
56 def u1Imm : Operand<i32>;
57 def n8Imm : Operand<i32>;
58 def m6Imm : Operand<i32>;
Tony Linthicumb4b54152011-12-12 21:14:40 +000059}
60
Jyotsna Verma81081b12012-11-21 19:53:42 +000061let PrintMethod = "printNOneImmOperand" in
62def nOneImm : Operand<i32>;
Sirish Pandeab7955b2012-02-15 18:52:27 +000063
Tony Linthicumb4b54152011-12-12 21:14:40 +000064//
65// Immediate predicates
66//
67def s32ImmPred : PatLeaf<(i32 imm), [{
Jyotsna Verma5c1f3d12012-11-26 21:56:51 +000068 // s32ImmPred predicate - True if the immediate fits in a 32-bit sign extended
Tony Linthicumb4b54152011-12-12 21:14:40 +000069 // field.
70 int64_t v = (int64_t)N->getSExtValue();
71 return isInt<32>(v);
72}]>;
73
74def s32_24ImmPred : PatLeaf<(i32 imm), [{
75 // s32_24ImmPred predicate - True if the immediate fits in a 32-bit sign
76 // extended field that is a multiple of 0x1000000.
77 int64_t v = (int64_t)N->getSExtValue();
78 return isShiftedInt<32,24>(v);
79}]>;
80
81def s32_16s8ImmPred : PatLeaf<(i32 imm), [{
82 // s32_16s8ImmPred predicate - True if the immediate fits in a 32-bit sign
83 // extended field that is a multiple of 0x10000.
84 int64_t v = (int64_t)N->getSExtValue();
85 return isShiftedInt<24,16>(v);
86}]>;
87
Jyotsna Vermab546d5a2012-11-21 20:05:09 +000088def s26_6ImmPred : PatLeaf<(i32 imm), [{
Jyotsna Verma5c1f3d12012-11-26 21:56:51 +000089 // s26_6ImmPred predicate - True if the immediate fits in a 32-bit
90 // sign extended field.
Jyotsna Vermab546d5a2012-11-21 20:05:09 +000091 int64_t v = (int64_t)N->getSExtValue();
92 return isShiftedInt<26,6>(v);
93}]>;
94
95
Tony Linthicumb4b54152011-12-12 21:14:40 +000096def s16ImmPred : PatLeaf<(i32 imm), [{
Jyotsna Verma5c1f3d12012-11-26 21:56:51 +000097 // s16ImmPred predicate - True if the immediate fits in a 16-bit sign extended
Tony Linthicumb4b54152011-12-12 21:14:40 +000098 // field.
99 int64_t v = (int64_t)N->getSExtValue();
100 return isInt<16>(v);
101}]>;
102
103
104def s13ImmPred : PatLeaf<(i32 imm), [{
Jyotsna Verma5c1f3d12012-11-26 21:56:51 +0000105 // s13ImmPred predicate - True if the immediate fits in a 13-bit sign extended
Tony Linthicumb4b54152011-12-12 21:14:40 +0000106 // field.
107 int64_t v = (int64_t)N->getSExtValue();
108 return isInt<13>(v);
109}]>;
110
111
112def s12ImmPred : PatLeaf<(i32 imm), [{
Jyotsna Verma5c1f3d12012-11-26 21:56:51 +0000113 // s12ImmPred predicate - True if the immediate fits in a 12-bit
114 // sign extended field.
Tony Linthicumb4b54152011-12-12 21:14:40 +0000115 int64_t v = (int64_t)N->getSExtValue();
116 return isInt<12>(v);
117}]>;
118
119def s11_0ImmPred : PatLeaf<(i32 imm), [{
Jyotsna Verma5c1f3d12012-11-26 21:56:51 +0000120 // s11_0ImmPred predicate - True if the immediate fits in a 11-bit
121 // sign extended field.
Tony Linthicumb4b54152011-12-12 21:14:40 +0000122 int64_t v = (int64_t)N->getSExtValue();
123 return isInt<11>(v);
124}]>;
125
126
127def s11_1ImmPred : PatLeaf<(i32 imm), [{
Jyotsna Verma5c1f3d12012-11-26 21:56:51 +0000128 // s11_1ImmPred predicate - True if the immediate fits in a 12-bit
129 // sign extended field and is a multiple of 2.
Tony Linthicumb4b54152011-12-12 21:14:40 +0000130 int64_t v = (int64_t)N->getSExtValue();
131 return isShiftedInt<11,1>(v);
132}]>;
133
134
135def s11_2ImmPred : PatLeaf<(i32 imm), [{
Jyotsna Verma5c1f3d12012-11-26 21:56:51 +0000136 // s11_2ImmPred predicate - True if the immediate fits in a 13-bit
137 // sign extended field and is a multiple of 4.
Tony Linthicumb4b54152011-12-12 21:14:40 +0000138 int64_t v = (int64_t)N->getSExtValue();
139 return isShiftedInt<11,2>(v);
140}]>;
141
142
143def s11_3ImmPred : PatLeaf<(i32 imm), [{
Jyotsna Verma5c1f3d12012-11-26 21:56:51 +0000144 // s11_3ImmPred predicate - True if the immediate fits in a 14-bit
145 // sign extended field and is a multiple of 8.
Tony Linthicumb4b54152011-12-12 21:14:40 +0000146 int64_t v = (int64_t)N->getSExtValue();
147 return isShiftedInt<11,3>(v);
148}]>;
149
150
151def s10ImmPred : PatLeaf<(i32 imm), [{
152 // s10ImmPred predicate - True if the immediate fits in a 10-bit sign extended
153 // field.
154 int64_t v = (int64_t)N->getSExtValue();
155 return isInt<10>(v);
156}]>;
157
158
159def s9ImmPred : PatLeaf<(i32 imm), [{
160 // s9ImmPred predicate - True if the immediate fits in a 9-bit sign extended
161 // field.
162 int64_t v = (int64_t)N->getSExtValue();
163 return isInt<9>(v);
164}]>;
165
Jyotsna Vermab546d5a2012-11-21 20:05:09 +0000166def m9ImmPred : PatLeaf<(i32 imm), [{
167 // m9ImmPred predicate - True if the immediate fits in a 9-bit magnitude
168 // field. The range of m9 is -255 to 255.
169 int64_t v = (int64_t)N->getSExtValue();
170 return isInt<9>(v) && (v != -256);
171}]>;
Tony Linthicumb4b54152011-12-12 21:14:40 +0000172
173def s8ImmPred : PatLeaf<(i32 imm), [{
174 // s8ImmPred predicate - True if the immediate fits in a 8-bit sign extended
175 // field.
176 int64_t v = (int64_t)N->getSExtValue();
177 return isInt<8>(v);
178}]>;
179
180
181def s8Imm64Pred : PatLeaf<(i64 imm), [{
182 // s8ImmPred predicate - True if the immediate fits in a 8-bit sign extended
183 // field.
184 int64_t v = (int64_t)N->getSExtValue();
185 return isInt<8>(v);
186}]>;
187
188
189def s6ImmPred : PatLeaf<(i32 imm), [{
190 // s6ImmPred predicate - True if the immediate fits in a 6-bit sign extended
191 // field.
192 int64_t v = (int64_t)N->getSExtValue();
193 return isInt<6>(v);
194}]>;
195
196
197def s4_0ImmPred : PatLeaf<(i32 imm), [{
198 // s4_0ImmPred predicate - True if the immediate fits in a 4-bit sign extended
199 // field.
200 int64_t v = (int64_t)N->getSExtValue();
201 return isInt<4>(v);
202}]>;
203
204
205def s4_1ImmPred : PatLeaf<(i32 imm), [{
206 // s4_1ImmPred predicate - True if the immediate fits in a 4-bit sign extended
207 // field of 2.
208 int64_t v = (int64_t)N->getSExtValue();
209 return isShiftedInt<4,1>(v);
210}]>;
211
212
213def s4_2ImmPred : PatLeaf<(i32 imm), [{
214 // s4_2ImmPred predicate - True if the immediate fits in a 4-bit sign extended
215 // field that is a multiple of 4.
216 int64_t v = (int64_t)N->getSExtValue();
217 return isShiftedInt<4,2>(v);
218}]>;
219
220
221def s4_3ImmPred : PatLeaf<(i32 imm), [{
222 // s4_3ImmPred predicate - True if the immediate fits in a 4-bit sign extended
223 // field that is a multiple of 8.
224 int64_t v = (int64_t)N->getSExtValue();
225 return isShiftedInt<4,3>(v);
226}]>;
227
228
229def u64ImmPred : PatLeaf<(i64 imm), [{
Benjamin Kramerd9b0b022012-06-02 10:20:22 +0000230 // Adding "N ||" to suppress gcc unused warning.
Tony Linthicumb4b54152011-12-12 21:14:40 +0000231 return (N || true);
232}]>;
233
234def u32ImmPred : PatLeaf<(i32 imm), [{
Jyotsna Verma5c1f3d12012-11-26 21:56:51 +0000235 // u32ImmPred predicate - True if the immediate fits in a 32-bit field.
Tony Linthicumb4b54152011-12-12 21:14:40 +0000236 int64_t v = (int64_t)N->getSExtValue();
237 return isUInt<32>(v);
238}]>;
239
Jyotsna Vermab546d5a2012-11-21 20:05:09 +0000240def u26_6ImmPred : PatLeaf<(i32 imm), [{
Jyotsna Verma5c1f3d12012-11-26 21:56:51 +0000241 // u26_6ImmPred - True if the immediate fits in a 32-bit field and
242 // is a multiple of 64.
Jyotsna Vermab546d5a2012-11-21 20:05:09 +0000243 int64_t v = (int64_t)N->getSExtValue();
244 return isShiftedUInt<26,6>(v);
245}]>;
246
Tony Linthicumb4b54152011-12-12 21:14:40 +0000247def u16ImmPred : PatLeaf<(i32 imm), [{
248 // u16ImmPred predicate - True if the immediate fits in a 16-bit unsigned
249 // field.
250 int64_t v = (int64_t)N->getSExtValue();
251 return isUInt<16>(v);
252}]>;
253
254def u16_s8ImmPred : PatLeaf<(i32 imm), [{
255 // u16_s8ImmPred predicate - True if the immediate fits in a 16-bit sign
256 // extended s8 field.
257 int64_t v = (int64_t)N->getSExtValue();
258 return isShiftedUInt<16,8>(v);
259}]>;
260
261def u9ImmPred : PatLeaf<(i32 imm), [{
262 // u9ImmPred predicate - True if the immediate fits in a 9-bit unsigned
263 // field.
264 int64_t v = (int64_t)N->getSExtValue();
265 return isUInt<9>(v);
266}]>;
267
268
269def u8ImmPred : PatLeaf<(i32 imm), [{
270 // u8ImmPred predicate - True if the immediate fits in a 8-bit unsigned
271 // field.
272 int64_t v = (int64_t)N->getSExtValue();
273 return isUInt<8>(v);
274}]>;
275
Jyotsna Vermab546d5a2012-11-21 20:05:09 +0000276def u7StrictPosImmPred : ImmLeaf<i32, [{
277 // u7StrictPosImmPred predicate - True if the immediate fits in an 7-bit
278 // unsigned field and is strictly greater than 0.
279 return isUInt<7>(Imm) && Imm > 0;
280}]>;
281
Tony Linthicumb4b54152011-12-12 21:14:40 +0000282def u7ImmPred : PatLeaf<(i32 imm), [{
Jyotsna Verma5c1f3d12012-11-26 21:56:51 +0000283 // u7ImmPred predicate - True if the immediate fits in a 7-bit unsigned
Tony Linthicumb4b54152011-12-12 21:14:40 +0000284 // field.
285 int64_t v = (int64_t)N->getSExtValue();
286 return isUInt<7>(v);
287}]>;
288
289
290def u6ImmPred : PatLeaf<(i32 imm), [{
291 // u6ImmPred predicate - True if the immediate fits in a 6-bit unsigned
292 // field.
293 int64_t v = (int64_t)N->getSExtValue();
294 return isUInt<6>(v);
295}]>;
296
297def u6_0ImmPred : PatLeaf<(i32 imm), [{
298 // u6_0ImmPred predicate - True if the immediate fits in a 6-bit unsigned
299 // field. Same as u6ImmPred.
300 int64_t v = (int64_t)N->getSExtValue();
301 return isUInt<6>(v);
302}]>;
303
304def u6_1ImmPred : PatLeaf<(i32 imm), [{
Jyotsna Verma5c1f3d12012-11-26 21:56:51 +0000305 // u6_1ImmPred predicate - True if the immediate fits in a 7-bit unsigned
Tony Linthicumb4b54152011-12-12 21:14:40 +0000306 // field that is 1 bit alinged - multiple of 2.
307 int64_t v = (int64_t)N->getSExtValue();
308 return isShiftedUInt<6,1>(v);
309}]>;
310
311def u6_2ImmPred : PatLeaf<(i32 imm), [{
Jyotsna Verma5c1f3d12012-11-26 21:56:51 +0000312 // u6_2ImmPred predicate - True if the immediate fits in a 8-bit unsigned
Tony Linthicumb4b54152011-12-12 21:14:40 +0000313 // field that is 2 bits alinged - multiple of 4.
314 int64_t v = (int64_t)N->getSExtValue();
315 return isShiftedUInt<6,2>(v);
316}]>;
317
318def u6_3ImmPred : PatLeaf<(i32 imm), [{
Jyotsna Verma5c1f3d12012-11-26 21:56:51 +0000319 // u6_3ImmPred predicate - True if the immediate fits in a 9-bit unsigned
Tony Linthicumb4b54152011-12-12 21:14:40 +0000320 // field that is 3 bits alinged - multiple of 8.
321 int64_t v = (int64_t)N->getSExtValue();
322 return isShiftedUInt<6,3>(v);
323}]>;
324
325def u5ImmPred : PatLeaf<(i32 imm), [{
326 // u5ImmPred predicate - True if the immediate fits in a 5-bit unsigned
327 // field.
328 int64_t v = (int64_t)N->getSExtValue();
329 return isUInt<5>(v);
330}]>;
331
332
333def u3ImmPred : PatLeaf<(i32 imm), [{
334 // u3ImmPred predicate - True if the immediate fits in a 3-bit unsigned
335 // field.
336 int64_t v = (int64_t)N->getSExtValue();
337 return isUInt<3>(v);
338}]>;
339
340
341def u2ImmPred : PatLeaf<(i32 imm), [{
342 // u2ImmPred predicate - True if the immediate fits in a 2-bit unsigned
343 // field.
344 int64_t v = (int64_t)N->getSExtValue();
345 return isUInt<2>(v);
346}]>;
347
348
349def u1ImmPred : PatLeaf<(i1 imm), [{
350 // u1ImmPred predicate - True if the immediate fits in a 1-bit unsigned
351 // field.
352 int64_t v = (int64_t)N->getSExtValue();
353 return isUInt<1>(v);
354}]>;
355
Jyotsna Vermab546d5a2012-11-21 20:05:09 +0000356def m5BImmPred : PatLeaf<(i32 imm), [{
357 // m5BImmPred predicate - True if the (char) number is in range -1 .. -31
358 // and will fit in a 5 bit field when made positive, for use in memops.
359 // this is specific to the zero extending of a negative by CombineInstr
360 int8_t v = (int8_t)N->getSExtValue();
361 return (-31 <= v && v <= -1);
362}]>;
363
364def m5HImmPred : PatLeaf<(i32 imm), [{
365 // m5HImmPred predicate - True if the (short) number is in range -1 .. -31
366 // and will fit in a 5 bit field when made positive, for use in memops.
367 // this is specific to the zero extending of a negative by CombineInstr
368 int16_t v = (int16_t)N->getSExtValue();
369 return (-31 <= v && v <= -1);
370}]>;
371
372def m5ImmPred : PatLeaf<(i32 imm), [{
373 // m5ImmPred predicate - True if the number is in range -1 .. -31
374 // and will fit in a 5 bit field when made positive, for use in memops.
Tony Linthicumb4b54152011-12-12 21:14:40 +0000375 int64_t v = (int64_t)N->getSExtValue();
Jyotsna Vermab546d5a2012-11-21 20:05:09 +0000376 return (-31 <= v && v <= -1);
Tony Linthicumb4b54152011-12-12 21:14:40 +0000377}]>;
378
379//InN means negative integers in [-(2^N - 1), 0]
380def n8ImmPred : PatLeaf<(i32 imm), [{
Evandro Menezese5041e62012-04-12 17:55:53 +0000381 // n8ImmPred predicate - True if the immediate fits in a 8-bit signed
Tony Linthicumb4b54152011-12-12 21:14:40 +0000382 // field.
383 int64_t v = (int64_t)N->getSExtValue();
384 return (-255 <= v && v <= 0);
385}]>;
Sirish Pandeab7955b2012-02-15 18:52:27 +0000386
387def nOneImmPred : PatLeaf<(i32 imm), [{
388 // nOneImmPred predicate - True if the immediate is -1.
389 int64_t v = (int64_t)N->getSExtValue();
390 return (-1 == v);
391}]>;
392
Jyotsna Vermab546d5a2012-11-21 20:05:09 +0000393def Set5ImmPred : PatLeaf<(i32 imm), [{
394 // Set5ImmPred predicate - True if the number is in the series of values.
395 // [ 2^0, 2^1, ... 2^31 ]
396 // For use in setbit immediate.
397 uint32_t v = (int32_t)N->getSExtValue();
398 // Constrain to 32 bits, and then check for single bit.
399 return ImmIsSingleBit(v);
400}]>;
401
402def Clr5ImmPred : PatLeaf<(i32 imm), [{
403 // Clr5ImmPred predicate - True if the number is in the series of
404 // bit negated values.
405 // [ 2^0, 2^1, ... 2^31 ]
406 // For use in clrbit immediate.
407 // Note: we are bit NOTing the value.
408 uint32_t v = ~ (int32_t)N->getSExtValue();
409 // Constrain to 32 bits, and then check for single bit.
410 return ImmIsSingleBit(v);
411}]>;
412
413def SetClr5ImmPred : PatLeaf<(i32 imm), [{
Jyotsna Verma5c1f3d12012-11-26 21:56:51 +0000414 // SetClr5ImmPred predicate - True if the immediate is in range 0..31.
Jyotsna Vermab546d5a2012-11-21 20:05:09 +0000415 int32_t v = (int32_t)N->getSExtValue();
416 return (v >= 0 && v <= 31);
417}]>;
418
419def Set4ImmPred : PatLeaf<(i32 imm), [{
420 // Set4ImmPred predicate - True if the number is in the series of values:
421 // [ 2^0, 2^1, ... 2^15 ].
422 // For use in setbit immediate.
423 uint16_t v = (int16_t)N->getSExtValue();
424 // Constrain to 16 bits, and then check for single bit.
425 return ImmIsSingleBit(v);
426}]>;
427
428def Clr4ImmPred : PatLeaf<(i32 imm), [{
429 // Clr4ImmPred predicate - True if the number is in the series of
430 // bit negated values:
431 // [ 2^0, 2^1, ... 2^15 ].
432 // For use in setbit and clrbit immediate.
433 uint16_t v = ~ (int16_t)N->getSExtValue();
434 // Constrain to 16 bits, and then check for single bit.
435 return ImmIsSingleBit(v);
436}]>;
437
438def SetClr4ImmPred : PatLeaf<(i32 imm), [{
Jyotsna Verma5c1f3d12012-11-26 21:56:51 +0000439 // SetClr4ImmPred predicate - True if the immediate is in the range 0..15.
Jyotsna Vermab546d5a2012-11-21 20:05:09 +0000440 int16_t v = (int16_t)N->getSExtValue();
441 return (v >= 0 && v <= 15);
442}]>;
443
444def Set3ImmPred : PatLeaf<(i32 imm), [{
Jyotsna Verma5c1f3d12012-11-26 21:56:51 +0000445 // Set3ImmPred predicate - True if the number is in the series of values:
Jyotsna Vermab546d5a2012-11-21 20:05:09 +0000446 // [ 2^0, 2^1, ... 2^7 ].
447 // For use in setbit immediate.
448 uint8_t v = (int8_t)N->getSExtValue();
449 // Constrain to 8 bits, and then check for single bit.
450 return ImmIsSingleBit(v);
451}]>;
452
453def Clr3ImmPred : PatLeaf<(i32 imm), [{
Jyotsna Verma5c1f3d12012-11-26 21:56:51 +0000454 // Clr3ImmPred predicate - True if the number is in the series of
Jyotsna Vermab546d5a2012-11-21 20:05:09 +0000455 // bit negated values:
456 // [ 2^0, 2^1, ... 2^7 ].
457 // For use in setbit and clrbit immediate.
458 uint8_t v = ~ (int8_t)N->getSExtValue();
459 // Constrain to 8 bits, and then check for single bit.
460 return ImmIsSingleBit(v);
461}]>;
462
463def SetClr3ImmPred : PatLeaf<(i32 imm), [{
Jyotsna Verma5c1f3d12012-11-26 21:56:51 +0000464 // SetClr3ImmPred predicate - True if the immediate is in the range 0..7.
Jyotsna Vermab546d5a2012-11-21 20:05:09 +0000465 int8_t v = (int8_t)N->getSExtValue();
466 return (v >= 0 && v <= 7);
467}]>;