1249259Sdim//===- HexagonOperands.td - Hexagon immediate processing -*- tablegen -*-===//
2249259Sdim//
3249259Sdim//                     The LLVM Compiler Infrastructure
4249259Sdim//
5249259Sdim// This file is distributed under the University of Illnois Open Source
6249259Sdim// License. See LICENSE.TXT for details.
7249259Sdim//
8249259Sdim//===----------------------------------------------------------------------===//
9249259Sdim
10249259Sdim// Immediate operands.
11249259Sdim
12249259Sdimlet PrintMethod = "printImmOperand" in {
13249259Sdim  // f32Ext type is used to identify constant extended floating point immediates.
14249259Sdim  def f32Ext : Operand<f32>;
15249259Sdim  def s32Imm : Operand<i32>;
16249259Sdim  def s26_6Imm : Operand<i32>;
17249259Sdim  def s16Imm : Operand<i32>;
18249259Sdim  def s12Imm : Operand<i32>;
19249259Sdim  def s11Imm : Operand<i32>;
20249259Sdim  def s11_0Imm : Operand<i32>;
21249259Sdim  def s11_1Imm : Operand<i32>;
22249259Sdim  def s11_2Imm : Operand<i32>;
23249259Sdim  def s11_3Imm : Operand<i32>;
24249259Sdim  def s10Imm : Operand<i32>;
25249259Sdim  def s9Imm : Operand<i32>;
26249259Sdim  def m9Imm : Operand<i32>;
27249259Sdim  def s8Imm : Operand<i32>;
28249259Sdim  def s8Imm64 : Operand<i64>;
29249259Sdim  def s6Imm : Operand<i32>;
30249259Sdim  def s4Imm : Operand<i32>;
31249259Sdim  def s4_0Imm : Operand<i32>;
32249259Sdim  def s4_1Imm : Operand<i32>;
33249259Sdim  def s4_2Imm : Operand<i32>;
34249259Sdim  def s4_3Imm : Operand<i32>;
35249259Sdim  def u64Imm : Operand<i64>;
36249259Sdim  def u32Imm : Operand<i32>;
37249259Sdim  def u26_6Imm : Operand<i32>;
38249259Sdim  def u16Imm : Operand<i32>;
39249259Sdim  def u16_0Imm : Operand<i32>;
40249259Sdim  def u16_1Imm : Operand<i32>;
41249259Sdim  def u16_2Imm : Operand<i32>;
42249259Sdim  def u11_3Imm : Operand<i32>;
43249259Sdim  def u10Imm : Operand<i32>;
44249259Sdim  def u9Imm : Operand<i32>;
45249259Sdim  def u8Imm : Operand<i32>;
46249259Sdim  def u7Imm : Operand<i32>;
47249259Sdim  def u6Imm : Operand<i32>;
48249259Sdim  def u6_0Imm : Operand<i32>;
49249259Sdim  def u6_1Imm : Operand<i32>;
50249259Sdim  def u6_2Imm : Operand<i32>;
51249259Sdim  def u6_3Imm : Operand<i32>;
52249259Sdim  def u5Imm : Operand<i32>;
53249259Sdim  def u4Imm : Operand<i32>;
54249259Sdim  def u3Imm : Operand<i32>;
55249259Sdim  def u2Imm : Operand<i32>;
56249259Sdim  def u1Imm : Operand<i32>;
57249259Sdim  def n8Imm : Operand<i32>;
58249259Sdim  def m6Imm : Operand<i32>;
59249259Sdim}
60249259Sdim
61249259Sdimlet PrintMethod = "printNOneImmOperand" in
62249259Sdimdef nOneImm : Operand<i32>;
63249259Sdim
64249259Sdim//
65249259Sdim// Immediate predicates
66249259Sdim//
67249259Sdimdef s32ImmPred  : PatLeaf<(i32 imm), [{
68249259Sdim  // s32ImmPred predicate - True if the immediate fits in a 32-bit sign extended
69249259Sdim  // field.
70249259Sdim  int64_t v = (int64_t)N->getSExtValue();
71249259Sdim  return isInt<32>(v);
72249259Sdim}]>;
73249259Sdim
74249259Sdimdef s32_24ImmPred  : PatLeaf<(i32 imm), [{
75249259Sdim  // s32_24ImmPred predicate - True if the immediate fits in a 32-bit sign
76249259Sdim  // extended field that is a multiple of 0x1000000.
77249259Sdim  int64_t v = (int64_t)N->getSExtValue();
78249259Sdim  return isShiftedInt<32,24>(v);
79249259Sdim}]>;
80249259Sdim
81249259Sdimdef s32_16s8ImmPred  : PatLeaf<(i32 imm), [{
82249259Sdim  // s32_16s8ImmPred predicate - True if the immediate fits in a 32-bit sign
83249259Sdim  // extended field that is a multiple of 0x10000.
84249259Sdim  int64_t v = (int64_t)N->getSExtValue();
85249259Sdim  return isShiftedInt<24,16>(v);
86249259Sdim}]>;
87249259Sdim
88249259Sdimdef s26_6ImmPred  : PatLeaf<(i32 imm), [{
89249259Sdim  // s26_6ImmPred predicate - True if the immediate fits in a 32-bit
90249259Sdim  // sign extended field.
91249259Sdim  int64_t v = (int64_t)N->getSExtValue();
92249259Sdim  return isShiftedInt<26,6>(v);
93249259Sdim}]>;
94249259Sdim
95249259Sdim
96249259Sdimdef s16ImmPred  : PatLeaf<(i32 imm), [{
97249259Sdim  // s16ImmPred predicate - True if the immediate fits in a 16-bit sign extended
98249259Sdim  // field.
99249259Sdim  int64_t v = (int64_t)N->getSExtValue();
100249259Sdim  return isInt<16>(v);
101249259Sdim}]>;
102249259Sdim
103249259Sdim
104249259Sdimdef s13ImmPred  : PatLeaf<(i32 imm), [{
105249259Sdim  // s13ImmPred predicate - True if the immediate fits in a 13-bit sign extended
106249259Sdim  // field.
107249259Sdim  int64_t v = (int64_t)N->getSExtValue();
108249259Sdim  return isInt<13>(v);
109249259Sdim}]>;
110249259Sdim
111249259Sdim
112249259Sdimdef s12ImmPred  : PatLeaf<(i32 imm), [{
113249259Sdim  // s12ImmPred predicate - True if the immediate fits in a 12-bit
114249259Sdim  // sign extended field.
115249259Sdim  int64_t v = (int64_t)N->getSExtValue();
116249259Sdim  return isInt<12>(v);
117249259Sdim}]>;
118249259Sdim
119249259Sdimdef s11_0ImmPred  : PatLeaf<(i32 imm), [{
120249259Sdim  // s11_0ImmPred predicate - True if the immediate fits in a 11-bit
121249259Sdim  // sign extended field.
122249259Sdim  int64_t v = (int64_t)N->getSExtValue();
123249259Sdim  return isInt<11>(v);
124249259Sdim}]>;
125249259Sdim
126249259Sdim
127249259Sdimdef s11_1ImmPred  : PatLeaf<(i32 imm), [{
128249259Sdim  // s11_1ImmPred predicate - True if the immediate fits in a 12-bit
129249259Sdim  // sign extended field and is a multiple of 2.
130249259Sdim  int64_t v = (int64_t)N->getSExtValue();
131249259Sdim  return isShiftedInt<11,1>(v);
132249259Sdim}]>;
133249259Sdim
134249259Sdim
135249259Sdimdef s11_2ImmPred  : PatLeaf<(i32 imm), [{
136249259Sdim  // s11_2ImmPred predicate - True if the immediate fits in a 13-bit
137249259Sdim  // sign extended field and is a multiple of 4.
138249259Sdim  int64_t v = (int64_t)N->getSExtValue();
139249259Sdim  return isShiftedInt<11,2>(v);
140249259Sdim}]>;
141249259Sdim
142249259Sdim
143249259Sdimdef s11_3ImmPred  : PatLeaf<(i32 imm), [{
144249259Sdim  // s11_3ImmPred predicate - True if the immediate fits in a 14-bit
145249259Sdim  // sign extended field and is a multiple of 8.
146249259Sdim  int64_t v = (int64_t)N->getSExtValue();
147249259Sdim  return isShiftedInt<11,3>(v);
148249259Sdim}]>;
149249259Sdim
150249259Sdim
151249259Sdimdef s10ImmPred  : PatLeaf<(i32 imm), [{
152249259Sdim  // s10ImmPred predicate - True if the immediate fits in a 10-bit sign extended
153249259Sdim  // field.
154249259Sdim  int64_t v = (int64_t)N->getSExtValue();
155249259Sdim  return isInt<10>(v);
156249259Sdim}]>;
157249259Sdim
158249259Sdim
159249259Sdimdef s9ImmPred  : PatLeaf<(i32 imm), [{
160249259Sdim  // s9ImmPred predicate - True if the immediate fits in a 9-bit sign extended
161249259Sdim  // field.
162249259Sdim  int64_t v = (int64_t)N->getSExtValue();
163249259Sdim  return isInt<9>(v);
164249259Sdim}]>;
165249259Sdim
166249259Sdimdef m9ImmPred  : PatLeaf<(i32 imm), [{
167249259Sdim  // m9ImmPred predicate - True if the immediate fits in a 9-bit magnitude
168249259Sdim  // field. The range of m9 is -255 to 255.
169249259Sdim  int64_t v = (int64_t)N->getSExtValue();
170249259Sdim  return isInt<9>(v) && (v != -256);
171249259Sdim}]>;
172249259Sdim
173249259Sdimdef s8ImmPred  : PatLeaf<(i32 imm), [{
174249259Sdim  // s8ImmPred predicate - True if the immediate fits in a 8-bit sign extended
175249259Sdim  // field.
176249259Sdim  int64_t v = (int64_t)N->getSExtValue();
177249259Sdim  return isInt<8>(v);
178249259Sdim}]>;
179249259Sdim
180249259Sdim
181249259Sdimdef s8Imm64Pred  : PatLeaf<(i64 imm), [{
182249259Sdim  // s8ImmPred predicate - True if the immediate fits in a 8-bit sign extended
183249259Sdim  // field.
184249259Sdim  int64_t v = (int64_t)N->getSExtValue();
185249259Sdim  return isInt<8>(v);
186249259Sdim}]>;
187249259Sdim
188249259Sdim
189249259Sdimdef s6ImmPred  : PatLeaf<(i32 imm), [{
190249259Sdim  // s6ImmPred predicate - True if the immediate fits in a 6-bit sign extended
191249259Sdim  // field.
192249259Sdim  int64_t v = (int64_t)N->getSExtValue();
193249259Sdim  return isInt<6>(v);
194249259Sdim}]>;
195249259Sdim
196249259Sdim
197249259Sdimdef s4_0ImmPred  : PatLeaf<(i32 imm), [{
198249259Sdim  // s4_0ImmPred predicate - True if the immediate fits in a 4-bit sign extended
199249259Sdim  // field.
200249259Sdim  int64_t v = (int64_t)N->getSExtValue();
201249259Sdim  return isInt<4>(v);
202249259Sdim}]>;
203249259Sdim
204249259Sdim
205249259Sdimdef s4_1ImmPred  : PatLeaf<(i32 imm), [{
206249259Sdim  // s4_1ImmPred predicate - True if the immediate fits in a 4-bit sign extended
207249259Sdim  // field of 2.
208249259Sdim  int64_t v = (int64_t)N->getSExtValue();
209249259Sdim  return isShiftedInt<4,1>(v);
210249259Sdim}]>;
211249259Sdim
212249259Sdim
213249259Sdimdef s4_2ImmPred  : PatLeaf<(i32 imm), [{
214249259Sdim  // s4_2ImmPred predicate - True if the immediate fits in a 4-bit sign extended
215249259Sdim  // field that is a multiple of 4.
216249259Sdim  int64_t v = (int64_t)N->getSExtValue();
217249259Sdim  return isShiftedInt<4,2>(v);
218249259Sdim}]>;
219249259Sdim
220249259Sdim
221249259Sdimdef s4_3ImmPred  : PatLeaf<(i32 imm), [{
222249259Sdim  // s4_3ImmPred predicate - True if the immediate fits in a 4-bit sign extended
223249259Sdim  // field that is a multiple of 8.
224249259Sdim  int64_t v = (int64_t)N->getSExtValue();
225249259Sdim  return isShiftedInt<4,3>(v);
226249259Sdim}]>;
227249259Sdim
228249259Sdim
229249259Sdimdef u64ImmPred  : PatLeaf<(i64 imm), [{
230249259Sdim  // Adding "N ||" to suppress gcc unused warning.
231249259Sdim  return (N || true);
232249259Sdim}]>;
233249259Sdim
234249259Sdimdef u32ImmPred  : PatLeaf<(i32 imm), [{
235249259Sdim  // u32ImmPred predicate - True if the immediate fits in a 32-bit field.
236249259Sdim  int64_t v = (int64_t)N->getSExtValue();
237249259Sdim  return isUInt<32>(v);
238249259Sdim}]>;
239249259Sdim
240249259Sdimdef u26_6ImmPred  : PatLeaf<(i32 imm), [{
241249259Sdim  // u26_6ImmPred - True if the immediate fits in a 32-bit field and
242249259Sdim  // is a multiple of 64.
243249259Sdim  int64_t v = (int64_t)N->getSExtValue();
244249259Sdim  return isShiftedUInt<26,6>(v);
245249259Sdim}]>;
246249259Sdim
247249259Sdimdef u16ImmPred  : PatLeaf<(i32 imm), [{
248249259Sdim  // u16ImmPred predicate - True if the immediate fits in a 16-bit unsigned
249249259Sdim  // field.
250249259Sdim  int64_t v = (int64_t)N->getSExtValue();
251249259Sdim  return isUInt<16>(v);
252249259Sdim}]>;
253249259Sdim
254249259Sdimdef u16_s8ImmPred  : PatLeaf<(i32 imm), [{
255249259Sdim  // u16_s8ImmPred predicate - True if the immediate fits in a 16-bit sign
256249259Sdim  // extended s8 field.
257249259Sdim  int64_t v = (int64_t)N->getSExtValue();
258249259Sdim  return isShiftedUInt<16,8>(v);
259249259Sdim}]>;
260249259Sdim
261249259Sdimdef u9ImmPred  : PatLeaf<(i32 imm), [{
262249259Sdim  // u9ImmPred predicate - True if the immediate fits in a 9-bit unsigned
263249259Sdim  // field.
264249259Sdim  int64_t v = (int64_t)N->getSExtValue();
265249259Sdim  return isUInt<9>(v);
266249259Sdim}]>;
267249259Sdim
268249259Sdim
269249259Sdimdef u8ImmPred  : PatLeaf<(i32 imm), [{
270249259Sdim  // u8ImmPred predicate - True if the immediate fits in a 8-bit unsigned
271249259Sdim  // field.
272249259Sdim  int64_t v = (int64_t)N->getSExtValue();
273249259Sdim  return isUInt<8>(v);
274249259Sdim}]>;
275249259Sdim
276249259Sdimdef u7StrictPosImmPred : ImmLeaf<i32, [{
277249259Sdim  // u7StrictPosImmPred predicate - True if the immediate fits in an 7-bit
278249259Sdim  // unsigned field and is strictly greater than 0.
279249259Sdim  return isUInt<7>(Imm) && Imm > 0;
280249259Sdim}]>;
281249259Sdim
282249259Sdimdef u7ImmPred  : PatLeaf<(i32 imm), [{
283249259Sdim  // u7ImmPred predicate - True if the immediate fits in a 7-bit unsigned
284249259Sdim  // field.
285249259Sdim  int64_t v = (int64_t)N->getSExtValue();
286249259Sdim  return isUInt<7>(v);
287249259Sdim}]>;
288249259Sdim
289249259Sdim
290249259Sdimdef u6ImmPred  : PatLeaf<(i32 imm), [{
291249259Sdim  // u6ImmPred predicate - True if the immediate fits in a 6-bit unsigned
292249259Sdim  // field.
293249259Sdim  int64_t v = (int64_t)N->getSExtValue();
294249259Sdim  return isUInt<6>(v);
295249259Sdim}]>;
296249259Sdim
297249259Sdimdef u6_0ImmPred  : PatLeaf<(i32 imm), [{
298249259Sdim  // u6_0ImmPred predicate - True if the immediate fits in a 6-bit unsigned
299249259Sdim  // field. Same as u6ImmPred.
300249259Sdim  int64_t v = (int64_t)N->getSExtValue();
301249259Sdim  return isUInt<6>(v);
302249259Sdim}]>;
303249259Sdim
304249259Sdimdef u6_1ImmPred  : PatLeaf<(i32 imm), [{
305249259Sdim  // u6_1ImmPred predicate - True if the immediate fits in a 7-bit unsigned
306249259Sdim  // field that is 1 bit alinged - multiple of 2.
307249259Sdim  int64_t v = (int64_t)N->getSExtValue();
308249259Sdim  return isShiftedUInt<6,1>(v);
309249259Sdim}]>;
310249259Sdim
311249259Sdimdef u6_2ImmPred  : PatLeaf<(i32 imm), [{
312249259Sdim  // u6_2ImmPred predicate - True if the immediate fits in a 8-bit unsigned
313249259Sdim  // field that is 2 bits alinged - multiple of 4.
314249259Sdim  int64_t v = (int64_t)N->getSExtValue();
315249259Sdim  return isShiftedUInt<6,2>(v);
316249259Sdim}]>;
317249259Sdim
318249259Sdimdef u6_3ImmPred  : PatLeaf<(i32 imm), [{
319249259Sdim  // u6_3ImmPred predicate - True if the immediate fits in a 9-bit unsigned
320249259Sdim  // field that is 3 bits alinged - multiple of 8.
321249259Sdim  int64_t v = (int64_t)N->getSExtValue();
322249259Sdim  return isShiftedUInt<6,3>(v);
323249259Sdim}]>;
324249259Sdim
325249259Sdimdef u5ImmPred  : PatLeaf<(i32 imm), [{
326249259Sdim  // u5ImmPred predicate - True if the immediate fits in a 5-bit unsigned
327249259Sdim  // field.
328249259Sdim  int64_t v = (int64_t)N->getSExtValue();
329249259Sdim  return isUInt<5>(v);
330249259Sdim}]>;
331249259Sdim
332249259Sdim
333249259Sdimdef u3ImmPred  : PatLeaf<(i32 imm), [{
334249259Sdim  // u3ImmPred predicate - True if the immediate fits in a 3-bit unsigned
335249259Sdim  // field.
336249259Sdim  int64_t v = (int64_t)N->getSExtValue();
337249259Sdim  return isUInt<3>(v);
338249259Sdim}]>;
339249259Sdim
340249259Sdim
341249259Sdimdef u2ImmPred  : PatLeaf<(i32 imm), [{
342249259Sdim  // u2ImmPred predicate - True if the immediate fits in a 2-bit unsigned
343249259Sdim  // field.
344249259Sdim  int64_t v = (int64_t)N->getSExtValue();
345249259Sdim  return isUInt<2>(v);
346249259Sdim}]>;
347249259Sdim
348249259Sdim
349249259Sdimdef u1ImmPred  : PatLeaf<(i1 imm), [{
350249259Sdim  // u1ImmPred predicate - True if the immediate fits in a 1-bit unsigned
351249259Sdim  // field.
352249259Sdim  int64_t v = (int64_t)N->getSExtValue();
353249259Sdim  return isUInt<1>(v);
354249259Sdim}]>;
355249259Sdim
356249259Sdimdef m5BImmPred  : PatLeaf<(i32 imm), [{
357249259Sdim  // m5BImmPred predicate - True if the (char) number is in range -1 .. -31
358249259Sdim  // and will fit in a 5 bit field when made positive, for use in memops.
359249259Sdim  // this is specific to the zero extending of a negative by CombineInstr
360249259Sdim  int8_t v = (int8_t)N->getSExtValue();
361249259Sdim  return (-31 <= v && v <= -1);
362249259Sdim}]>;
363249259Sdim
364249259Sdimdef m5HImmPred  : PatLeaf<(i32 imm), [{
365249259Sdim  // m5HImmPred predicate - True if the (short) number is in range -1 .. -31
366249259Sdim  // and will fit in a 5 bit field when made positive, for use in memops.
367249259Sdim  // this is specific to the zero extending of a negative by CombineInstr
368249259Sdim  int16_t v = (int16_t)N->getSExtValue();
369249259Sdim  return (-31 <= v && v <= -1);
370249259Sdim}]>;
371249259Sdim
372249259Sdimdef m5ImmPred  : PatLeaf<(i32 imm), [{
373249259Sdim  // m5ImmPred predicate - True if the number is in range -1 .. -31
374249259Sdim  // and will fit in a 5 bit field when made positive, for use in memops.
375249259Sdim  int64_t v = (int64_t)N->getSExtValue();
376249259Sdim  return (-31 <= v && v <= -1);
377249259Sdim}]>;
378249259Sdim
379249259Sdim//InN means negative integers in [-(2^N - 1), 0]
380249259Sdimdef n8ImmPred  : PatLeaf<(i32 imm), [{
381249259Sdim  // n8ImmPred predicate - True if the immediate fits in a 8-bit signed
382249259Sdim  // field.
383249259Sdim  int64_t v = (int64_t)N->getSExtValue();
384249259Sdim  return (-255 <= v && v <= 0);
385249259Sdim}]>;
386249259Sdim
387249259Sdimdef nOneImmPred  : PatLeaf<(i32 imm), [{
388249259Sdim  // nOneImmPred predicate - True if the immediate is -1.
389249259Sdim  int64_t v = (int64_t)N->getSExtValue();
390249259Sdim  return (-1 == v);
391249259Sdim}]>;
392249259Sdim
393249259Sdimdef Set5ImmPred : PatLeaf<(i32 imm), [{
394249259Sdim  // Set5ImmPred predicate - True if the number is in the series of values.
395249259Sdim  // [ 2^0, 2^1, ... 2^31 ]
396249259Sdim  // For use in setbit immediate.
397249259Sdim  uint32_t v = (int32_t)N->getSExtValue();
398249259Sdim  // Constrain to 32 bits, and then check for single bit.
399249259Sdim  return ImmIsSingleBit(v);
400249259Sdim}]>;
401249259Sdim
402249259Sdimdef Clr5ImmPred : PatLeaf<(i32 imm), [{
403249259Sdim  // Clr5ImmPred predicate - True if the number is in the series of
404249259Sdim  // bit negated values.
405249259Sdim  // [ 2^0, 2^1, ... 2^31 ]
406249259Sdim  // For use in clrbit immediate.
407249259Sdim  // Note: we are bit NOTing the value.
408249259Sdim  uint32_t v = ~ (int32_t)N->getSExtValue();
409249259Sdim  // Constrain to 32 bits, and then check for single bit.
410249259Sdim  return ImmIsSingleBit(v);
411249259Sdim}]>;
412249259Sdim
413249259Sdimdef SetClr5ImmPred : PatLeaf<(i32 imm), [{
414249259Sdim  // SetClr5ImmPred predicate - True if the immediate is in range 0..31.
415249259Sdim  int32_t v = (int32_t)N->getSExtValue();
416249259Sdim  return (v >= 0 && v <= 31);
417249259Sdim}]>;
418249259Sdim
419249259Sdimdef Set4ImmPred : PatLeaf<(i32 imm), [{
420249259Sdim  // Set4ImmPred predicate - True if the number is in the series of values:
421249259Sdim  // [ 2^0, 2^1, ... 2^15 ].
422249259Sdim  // For use in setbit immediate.
423249259Sdim  uint16_t v = (int16_t)N->getSExtValue();
424249259Sdim  // Constrain to 16 bits, and then check for single bit.
425249259Sdim  return ImmIsSingleBit(v);
426249259Sdim}]>;
427249259Sdim
428249259Sdimdef Clr4ImmPred : PatLeaf<(i32 imm), [{
429249259Sdim  // Clr4ImmPred predicate - True if the number is in the series of
430249259Sdim  // bit negated values:
431249259Sdim  // [ 2^0, 2^1, ... 2^15 ].
432249259Sdim  // For use in setbit and clrbit immediate.
433249259Sdim  uint16_t v = ~ (int16_t)N->getSExtValue();
434249259Sdim  // Constrain to 16 bits, and then check for single bit.
435249259Sdim  return ImmIsSingleBit(v);
436249259Sdim}]>;
437249259Sdim
438249259Sdimdef SetClr4ImmPred : PatLeaf<(i32 imm), [{
439249259Sdim  // SetClr4ImmPred predicate - True if the immediate is in the range 0..15.
440249259Sdim  int16_t v = (int16_t)N->getSExtValue();
441249259Sdim  return (v >= 0 && v <= 15);
442249259Sdim}]>;
443249259Sdim
444249259Sdimdef Set3ImmPred : PatLeaf<(i32 imm), [{
445249259Sdim  // Set3ImmPred predicate - True if the number is in the series of values:
446249259Sdim  // [ 2^0, 2^1, ... 2^7 ].
447249259Sdim  // For use in setbit immediate.
448249259Sdim  uint8_t v = (int8_t)N->getSExtValue();
449249259Sdim  // Constrain to 8 bits, and then check for single bit.
450249259Sdim  return ImmIsSingleBit(v);
451249259Sdim}]>;
452249259Sdim
453249259Sdimdef Clr3ImmPred : PatLeaf<(i32 imm), [{
454249259Sdim  // Clr3ImmPred predicate - True if the number is in the series of
455249259Sdim  // bit negated values:
456249259Sdim  // [ 2^0, 2^1, ... 2^7 ].
457249259Sdim  // For use in setbit and clrbit immediate.
458249259Sdim  uint8_t v = ~ (int8_t)N->getSExtValue();
459249259Sdim  // Constrain to 8 bits, and then check for single bit.
460249259Sdim  return ImmIsSingleBit(v);
461249259Sdim}]>;
462249259Sdim
463249259Sdimdef SetClr3ImmPred : PatLeaf<(i32 imm), [{
464249259Sdim  // SetClr3ImmPred predicate - True if the immediate is in the range  0..7.
465249259Sdim  int8_t v = (int8_t)N->getSExtValue();
466249259Sdim  return (v >= 0 && v <= 7);
467249259Sdim}]>;
468249259Sdim
469249259Sdim
470249259Sdim// Extendable immediate operands.
471249259Sdim
472249259Sdimlet PrintMethod = "printExtOperand" in {
473249259Sdim  def s16Ext : Operand<i32>;
474249259Sdim  def s12Ext : Operand<i32>;
475249259Sdim  def s10Ext : Operand<i32>;
476249259Sdim  def s9Ext : Operand<i32>;
477249259Sdim  def s8Ext : Operand<i32>;
478249259Sdim  def s6Ext : Operand<i32>;
479249259Sdim  def s11_0Ext : Operand<i32>;
480249259Sdim  def s11_1Ext : Operand<i32>;
481249259Sdim  def s11_2Ext : Operand<i32>;
482249259Sdim  def s11_3Ext : Operand<i32>;
483249259Sdim  def u6Ext : Operand<i32>;
484249259Sdim  def u7Ext : Operand<i32>;
485249259Sdim  def u8Ext : Operand<i32>;
486249259Sdim  def u9Ext : Operand<i32>;
487249259Sdim  def u10Ext : Operand<i32>;
488249259Sdim  def u6_0Ext : Operand<i32>;
489249259Sdim  def u6_1Ext : Operand<i32>;
490249259Sdim  def u6_2Ext : Operand<i32>;
491249259Sdim  def u6_3Ext : Operand<i32>;
492249259Sdim}
493249259Sdim
494249259Sdimlet PrintMethod = "printImmOperand" in
495249259Sdimdef u0AlwaysExt : Operand<i32>;
496249259Sdim
497249259Sdim// Predicates for constant extendable operands
498249259Sdimdef s16ExtPred  : PatLeaf<(i32 imm), [{
499249259Sdim  int64_t v = (int64_t)N->getSExtValue();
500249259Sdim  if (!Subtarget.hasV4TOps())
501249259Sdim    // Return true if the immediate can fit in a 16-bit sign extended field.
502249259Sdim    return isInt<16>(v);
503249259Sdim  else {
504249259Sdim    if (isInt<16>(v))
505249259Sdim      return true;
506249259Sdim
507249259Sdim    // Return true if extending this immediate is profitable and the value
508249259Sdim    // can fit in a 32-bit signed field.
509249259Sdim    return isConstExtProfitable(Node) && isInt<32>(v);
510249259Sdim  }
511249259Sdim}]>;
512249259Sdim
513249259Sdimdef s10ExtPred  : PatLeaf<(i32 imm), [{
514249259Sdim  int64_t v = (int64_t)N->getSExtValue();
515249259Sdim  if (!Subtarget.hasV4TOps())
516249259Sdim    // Return true if the immediate can fit in a 10-bit sign extended field.
517249259Sdim    return isInt<10>(v);
518249259Sdim  else {
519249259Sdim    if (isInt<10>(v))
520249259Sdim      return true;
521249259Sdim
522249259Sdim    // Return true if extending this immediate is profitable and the value
523249259Sdim    // can fit in a 32-bit signed field.
524249259Sdim    return isConstExtProfitable(Node) && isInt<32>(v);
525249259Sdim  }
526249259Sdim}]>;
527249259Sdim
528249259Sdimdef s9ExtPred  : PatLeaf<(i32 imm), [{
529249259Sdim  int64_t v = (int64_t)N->getSExtValue();
530249259Sdim  if (!Subtarget.hasV4TOps())
531249259Sdim    // Return true if the immediate can fit in a 9-bit sign extended field.
532249259Sdim    return isInt<9>(v);
533249259Sdim  else {
534249259Sdim    if (isInt<9>(v))
535249259Sdim      return true;
536249259Sdim
537249259Sdim    // Return true if extending this immediate is profitable and the value
538249259Sdim    // can fit in a 32-bit unsigned field.
539249259Sdim    return isConstExtProfitable(Node) && isInt<32>(v);
540249259Sdim  }
541249259Sdim}]>;
542249259Sdim
543249259Sdimdef s8ExtPred  : PatLeaf<(i32 imm), [{
544249259Sdim  int64_t v = (int64_t)N->getSExtValue();
545249259Sdim  if (!Subtarget.hasV4TOps())
546249259Sdim    // Return true if the immediate can fit in a 8-bit sign extended field.
547249259Sdim    return isInt<8>(v);
548249259Sdim  else {
549249259Sdim    if (isInt<8>(v))
550249259Sdim      return true;
551249259Sdim
552249259Sdim    // Return true if extending this immediate is profitable and the value
553249259Sdim    // can fit in a 32-bit signed field.
554249259Sdim    return isConstExtProfitable(Node) && isInt<32>(v);
555249259Sdim  }
556249259Sdim}]>;
557249259Sdim
558249259Sdimdef s8_16ExtPred  : PatLeaf<(i32 imm), [{
559249259Sdim  int64_t v = (int64_t)N->getSExtValue();
560249259Sdim  if (!Subtarget.hasV4TOps())
561249259Sdim    // Return true if the immediate fits in a 8-bit sign extended field.
562249259Sdim    return isInt<8>(v);
563249259Sdim  else {
564249259Sdim    if (isInt<8>(v))
565249259Sdim      return true;
566249259Sdim
567249259Sdim    // Return true if extending this immediate is profitable and the value
568249259Sdim    // can't fit in a 16-bit signed field. This is required to avoid
569249259Sdim    // unnecessary constant extenders.
570249259Sdim    return isConstExtProfitable(Node) && !isInt<16>(v);
571249259Sdim  }
572249259Sdim}]>;
573249259Sdim
574249259Sdimdef s6ExtPred  : PatLeaf<(i32 imm), [{
575249259Sdim  int64_t v = (int64_t)N->getSExtValue();
576249259Sdim  if (!Subtarget.hasV4TOps())
577249259Sdim    // Return true if the immediate can fit in a 6-bit sign extended field.
578249259Sdim    return isInt<6>(v);
579249259Sdim  else {
580249259Sdim    if (isInt<6>(v))
581249259Sdim      return true;
582249259Sdim
583249259Sdim    // Return true if extending this immediate is profitable and the value
584249259Sdim    // can fit in a 32-bit unsigned field.
585249259Sdim    return isConstExtProfitable(Node) && isInt<32>(v);
586249259Sdim  }
587249259Sdim}]>;
588249259Sdim
589249259Sdimdef s6_16ExtPred  : PatLeaf<(i32 imm), [{
590249259Sdim  int64_t v = (int64_t)N->getSExtValue();
591249259Sdim  if (!Subtarget.hasV4TOps())
592249259Sdim    // Return true if the immediate fits in a 6-bit sign extended field.
593249259Sdim    return isInt<6>(v);
594249259Sdim  else {
595249259Sdim    if (isInt<6>(v))
596249259Sdim      return true;
597249259Sdim
598249259Sdim    // Return true if extending this immediate is profitable and the value
599249259Sdim    // can't fit in a 16-bit signed field. This is required to avoid
600249259Sdim    // unnecessary constant extenders.
601249259Sdim    return isConstExtProfitable(Node) && !isInt<16>(v);
602249259Sdim  }
603249259Sdim}]>;
604249259Sdim
605249259Sdimdef s6_10ExtPred  : PatLeaf<(i32 imm), [{
606249259Sdim  int64_t v = (int64_t)N->getSExtValue();
607249259Sdim  if (!Subtarget.hasV4TOps())
608249259Sdim    // Return true if the immediate can fit in a 6-bit sign extended field.
609249259Sdim    return isInt<6>(v);
610249259Sdim  else {
611249259Sdim    if (isInt<6>(v))
612249259Sdim      return true;
613249259Sdim
614249259Sdim    // Return true if extending this immediate is profitable and the value
615249259Sdim    // can't fit in a 10-bit signed field. This is required to avoid
616249259Sdim    // unnecessary constant extenders.
617249259Sdim    return isConstExtProfitable(Node) && !isInt<10>(v);
618249259Sdim  }
619249259Sdim}]>;
620249259Sdim
621249259Sdimdef s11_0ExtPred  : PatLeaf<(i32 imm), [{
622249259Sdim  int64_t v = (int64_t)N->getSExtValue();
623249259Sdim  if (!Subtarget.hasV4TOps())
624249259Sdim    // Return true if the immediate can fit in a 11-bit sign extended field.
625249259Sdim    return isShiftedInt<11,0>(v);
626249259Sdim  else {
627249259Sdim    if (isInt<11>(v))
628249259Sdim      return true;
629249259Sdim
630249259Sdim    // Return true if extending this immediate is profitable and the value
631249259Sdim    // can fit in a 32-bit signed field.
632249259Sdim    return isConstExtProfitable(Node) && isInt<32>(v);
633249259Sdim  }
634249259Sdim}]>;
635249259Sdim
636249259Sdimdef s11_1ExtPred  : PatLeaf<(i32 imm), [{
637249259Sdim  int64_t v = (int64_t)N->getSExtValue();
638249259Sdim  if (!Subtarget.hasV4TOps())
639249259Sdim    // Return true if the immediate can fit in a 12-bit sign extended field and
640249259Sdim    // is 2 byte aligned.
641249259Sdim    return isShiftedInt<11,1>(v);
642249259Sdim  else {
643249259Sdim    if (isInt<12>(v))
644249259Sdim      return isShiftedInt<11,1>(v);
645249259Sdim
646249259Sdim    // Return true if extending this immediate is profitable and the low 1 bit
647249259Sdim    // is zero (2-byte aligned).
648249259Sdim    return isConstExtProfitable(Node) && isInt<32>(v) && ((v % 2) == 0);
649249259Sdim  }
650249259Sdim}]>;
651249259Sdim
652249259Sdimdef s11_2ExtPred  : PatLeaf<(i32 imm), [{
653249259Sdim  int64_t v = (int64_t)N->getSExtValue();
654249259Sdim  if (!Subtarget.hasV4TOps())
655249259Sdim    // Return true if the immediate can fit in a 13-bit sign extended field and
656249259Sdim    // is 4-byte aligned.
657249259Sdim    return isShiftedInt<11,2>(v);
658249259Sdim  else {
659249259Sdim    if (isInt<13>(v))
660249259Sdim      return isShiftedInt<11,2>(v);
661249259Sdim
662249259Sdim    // Return true if extending this immediate is profitable and the low 2-bits
663249259Sdim    // are zero (4-byte aligned).
664249259Sdim    return isConstExtProfitable(Node)  && isInt<32>(v) && ((v % 4) == 0);
665249259Sdim  }
666249259Sdim}]>;
667249259Sdim
668249259Sdimdef s11_3ExtPred  : PatLeaf<(i32 imm), [{
669249259Sdim  int64_t v = (int64_t)N->getSExtValue();
670249259Sdim  if (!Subtarget.hasV4TOps())
671249259Sdim    // Return true if the immediate can fit in a 14-bit sign extended field and
672249259Sdim    // is 8-byte aligned.
673249259Sdim    return isShiftedInt<11,3>(v);
674249259Sdim  else {
675249259Sdim    if (isInt<14>(v))
676249259Sdim     return isShiftedInt<11,3>(v);
677249259Sdim
678249259Sdim    // Return true if extending this immediate is profitable and the low 3-bits
679249259Sdim    // are zero (8-byte aligned).
680249259Sdim    return isConstExtProfitable(Node)  && isInt<32>(v) && ((v % 8) == 0);
681249259Sdim  }
682249259Sdim}]>;
683249259Sdim
684249259Sdimdef u0AlwaysExtPred : PatLeaf<(i32 imm), [{
685249259Sdim  // Predicate for an unsigned 32-bit value that always needs to be extended.
686249259Sdim  if (Subtarget.hasV4TOps()) {
687249259Sdim    if (isConstExtProfitable(Node)) {
688249259Sdim      int64_t v = (int64_t)N->getSExtValue();
689249259Sdim      return isUInt<32>(v);
690249259Sdim    }
691249259Sdim  }
692249259Sdim  return false;
693249259Sdim}]>;
694249259Sdim
695249259Sdimdef u6ExtPred  : PatLeaf<(i32 imm), [{
696249259Sdim  int64_t v = (int64_t)N->getSExtValue();
697249259Sdim  if (!Subtarget.hasV4TOps())
698249259Sdim    // Return true if the immediate can fit in a 6-bit unsigned field.
699249259Sdim    return isUInt<6>(v);
700249259Sdim  else {
701249259Sdim    if (isUInt<6>(v))
702249259Sdim      return true;
703249259Sdim
704249259Sdim    // Return true if extending this immediate is profitable and the value
705249259Sdim    // can fit in a 32-bit unsigned field.
706249259Sdim    return isConstExtProfitable(Node) && isUInt<32>(v);
707249259Sdim  }
708249259Sdim}]>;
709249259Sdim
710249259Sdimdef u7ExtPred  : PatLeaf<(i32 imm), [{
711249259Sdim  int64_t v = (int64_t)N->getSExtValue();
712249259Sdim  if (!Subtarget.hasV4TOps())
713249259Sdim    // Return true if the immediate can fit in a 7-bit unsigned field.
714249259Sdim    return isUInt<7>(v);
715249259Sdim  else {
716249259Sdim    if (isUInt<7>(v))
717249259Sdim      return true;
718249259Sdim
719249259Sdim    // Return true if extending this immediate is profitable and the value
720249259Sdim    // can fit in a 32-bit unsigned field.
721249259Sdim    return isConstExtProfitable(Node) && isUInt<32>(v);
722249259Sdim  }
723249259Sdim}]>;
724249259Sdim
725249259Sdimdef u8ExtPred  : PatLeaf<(i32 imm), [{
726249259Sdim  int64_t v = (int64_t)N->getSExtValue();
727249259Sdim  if (!Subtarget.hasV4TOps())
728249259Sdim    // Return true if the immediate can fit in a 8-bit unsigned field.
729249259Sdim    return isUInt<8>(v);
730249259Sdim  else {
731249259Sdim    if (isUInt<8>(v))
732249259Sdim      return true;
733249259Sdim
734249259Sdim    // Return true if extending this immediate is profitable and the value
735249259Sdim    // can fit in a 32-bit unsigned field.
736249259Sdim    return isConstExtProfitable(Node) && isUInt<32>(v);
737249259Sdim  }
738249259Sdim}]>;
739249259Sdim
740249259Sdimdef u9ExtPred  : PatLeaf<(i32 imm), [{
741249259Sdim  int64_t v = (int64_t)N->getSExtValue();
742249259Sdim  if (!Subtarget.hasV4TOps())
743249259Sdim    // Return true if the immediate can fit in a 9-bit unsigned field.
744249259Sdim    return isUInt<9>(v);
745249259Sdim  else {
746249259Sdim    if (isUInt<9>(v))
747249259Sdim      return true;
748249259Sdim
749249259Sdim    // Return true if extending this immediate is profitable and the value
750249259Sdim    // can fit in a 32-bit unsigned field.
751249259Sdim    return isConstExtProfitable(Node) && isUInt<32>(v);
752249259Sdim  }
753249259Sdim}]>;
754249259Sdim
755249259Sdimdef u6_1ExtPred  : PatLeaf<(i32 imm), [{
756249259Sdim  int64_t v = (int64_t)N->getSExtValue();
757249259Sdim  if (!Subtarget.hasV4TOps())
758249259Sdim    // Return true if the immediate can fit in a 7-bit unsigned field and
759249259Sdim    // is 2-byte aligned.
760249259Sdim    return isShiftedUInt<6,1>(v);
761249259Sdim  else {
762249259Sdim    if (isUInt<7>(v))
763249259Sdim      return isShiftedUInt<6,1>(v);
764249259Sdim
765249259Sdim    // Return true if extending this immediate is profitable and the value
766249259Sdim    // can fit in a 32-bit unsigned field.
767249259Sdim    return isConstExtProfitable(Node) && isUInt<32>(v) && ((v % 2) == 0);
768249259Sdim  }
769249259Sdim}]>;
770249259Sdim
771249259Sdimdef u6_2ExtPred  : PatLeaf<(i32 imm), [{
772249259Sdim  int64_t v = (int64_t)N->getSExtValue();
773249259Sdim  if (!Subtarget.hasV4TOps())
774249259Sdim    // Return true if the immediate can fit in a 8-bit unsigned field and
775249259Sdim    // is 4-byte aligned.
776249259Sdim    return isShiftedUInt<6,2>(v);
777249259Sdim  else {
778249259Sdim    if (isUInt<8>(v))
779249259Sdim      return isShiftedUInt<6,2>(v);
780249259Sdim
781249259Sdim    // Return true if extending this immediate is profitable and the value
782249259Sdim    // can fit in a 32-bit unsigned field.
783249259Sdim    return isConstExtProfitable(Node) && isUInt<32>(v) && ((v % 4) == 0);
784249259Sdim  }
785249259Sdim}]>;
786249259Sdim
787249259Sdimdef u6_3ExtPred  : PatLeaf<(i32 imm), [{
788249259Sdim  int64_t v = (int64_t)N->getSExtValue();
789249259Sdim  if (!Subtarget.hasV4TOps())
790249259Sdim    // Return true if the immediate can fit in a 9-bit unsigned field and
791249259Sdim    // is 8-byte aligned.
792249259Sdim    return isShiftedUInt<6,3>(v);
793249259Sdim  else {
794249259Sdim    if (isUInt<9>(v))
795249259Sdim      return isShiftedUInt<6,3>(v);
796249259Sdim
797249259Sdim    // Return true if extending this immediate is profitable and the value
798249259Sdim    // can fit in a 32-bit unsigned field.
799249259Sdim    return isConstExtProfitable(Node) && isUInt<32>(v) && ((v % 8) == 0);
800249259Sdim  }
801249259Sdim}]>;
802249259Sdim
803249259Sdim// Addressing modes.
804249259Sdim
805249259Sdimdef ADDRrr : ComplexPattern<i32, 2, "SelectADDRrr", [], []>;
806249259Sdimdef ADDRri : ComplexPattern<i32, 2, "SelectADDRri", [frameindex], []>;
807249259Sdimdef ADDRriS11_0 : ComplexPattern<i32, 2, "SelectADDRriS11_0", [frameindex], []>;
808249259Sdimdef ADDRriS11_1 : ComplexPattern<i32, 2, "SelectADDRriS11_1", [frameindex], []>;
809249259Sdimdef ADDRriS11_2 : ComplexPattern<i32, 2, "SelectADDRriS11_2", [frameindex], []>;
810249259Sdimdef ADDRriS11_3 : ComplexPattern<i32, 2, "SelectADDRriS11_3", [frameindex], []>;
811249259Sdimdef ADDRriU6_0 : ComplexPattern<i32, 2, "SelectADDRriU6_0", [frameindex], []>;
812249259Sdimdef ADDRriU6_1 : ComplexPattern<i32, 2, "SelectADDRriU6_1", [frameindex], []>;
813249259Sdimdef ADDRriU6_2 : ComplexPattern<i32, 2, "SelectADDRriU6_2", [frameindex], []>;
814249259Sdim
815249259Sdim// Address operands.
816249259Sdim
817249259Sdimdef MEMrr : Operand<i32> {
818249259Sdim  let PrintMethod = "printMEMrrOperand";
819249259Sdim  let MIOperandInfo = (ops IntRegs, IntRegs);
820249259Sdim}
821249259Sdim
822249259Sdimdef MEMri : Operand<i32> {
823249259Sdim  let PrintMethod = "printMEMriOperand";
824249259Sdim  let MIOperandInfo = (ops IntRegs, IntRegs);
825249259Sdim}
826249259Sdim
827249259Sdimdef MEMri_s11_2 : Operand<i32>,
828249259Sdim  ComplexPattern<i32, 2, "SelectMEMriS11_2", []> {
829249259Sdim  let PrintMethod = "printMEMriOperand";
830249259Sdim  let MIOperandInfo = (ops IntRegs, s11Imm);
831249259Sdim}
832249259Sdim
833249259Sdimdef FrameIndex : Operand<i32> {
834249259Sdim  let PrintMethod = "printFrameIndexOperand";
835249259Sdim  let MIOperandInfo = (ops IntRegs, s11Imm);
836249259Sdim}
837249259Sdim
838249259Sdimlet PrintMethod = "printGlobalOperand" in {
839249259Sdim  def globaladdress : Operand<i32>;
840249259Sdim  def globaladdressExt : Operand<i32>;
841249259Sdim}
842249259Sdim
843249259Sdimlet PrintMethod = "printJumpTable" in
844249259Sdimdef jumptablebase : Operand<i32>;
845249259Sdim
846249259Sdimdef brtarget : Operand<OtherVT>;
847249259Sdimdef brtargetExt : Operand<OtherVT>;
848249259Sdimdef calltarget : Operand<i32>;
849249259Sdim
850249259Sdimdef bblabel : Operand<i32>;
851249259Sdimdef bbl   : SDNode<"ISD::BasicBlock", SDTPtrLeaf   , [], "BasicBlockSDNode">;
852249259Sdim
853249259Sdimdef symbolHi32 : Operand<i32> {
854249259Sdim  let PrintMethod = "printSymbolHi";
855249259Sdim}
856249259Sdimdef symbolLo32 : Operand<i32> {
857249259Sdim  let PrintMethod = "printSymbolLo";
858249259Sdim}
859