blob: 6216651e48a404e2513cb95adcc5ef2d874c4d82 [file] [log] [blame]
Scott Michel564427e2007-12-05 01:24:05 +00001//===- SPUOperands.td - Cell SPU Instruction Operands ------*- tablegen -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner4ee451d2007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Scott Michel564427e2007-12-05 01:24:05 +00007//
8//===----------------------------------------------------------------------===//
9// Cell SPU Instruction Operands:
10//===----------------------------------------------------------------------===//
11
Chris Lattner420c69d2010-03-15 05:53:47 +000012// TO_IMM32 - Convert an i8/i16 to i32.
13def TO_IMM32 : SDNodeXForm<imm, [{
14 return getI32Imm(N->getZExtValue());
15}]>;
16
17// TO_IMM16 - Convert an i8/i32 to i16.
18def TO_IMM16 : SDNodeXForm<imm, [{
19 return CurDAG->getTargetConstant(N->getZExtValue(), MVT::i16);
20}]>;
21
22
Scott Michel564427e2007-12-05 01:24:05 +000023def LO16 : SDNodeXForm<imm, [{
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +000024 unsigned val = N->getZExtValue();
Scott Michel564427e2007-12-05 01:24:05 +000025 // Transformation function: get the low 16 bits.
26 return getI32Imm(val & 0xffff);
27}]>;
28
29def LO16_vec : SDNodeXForm<scalar_to_vector, [{
Dan Gohman475871a2008-07-27 21:46:04 +000030 SDValue OpVal(0, 0);
Scott Michel564427e2007-12-05 01:24:05 +000031
32 // Transformation function: get the low 16 bit immediate from a build_vector
33 // node.
34 assert(N->getOpcode() == ISD::BUILD_VECTOR
35 && "LO16_vec got something other than a BUILD_VECTOR");
36
37 // Get first constant operand...
Gabor Greif93c53e52008-08-31 15:37:04 +000038 for (unsigned i = 0, e = N->getNumOperands();
39 OpVal.getNode() == 0 && i != e; ++i) {
Scott Michel564427e2007-12-05 01:24:05 +000040 if (N->getOperand(i).getOpcode() == ISD::UNDEF) continue;
Gabor Greifba36cb52008-08-28 21:40:38 +000041 if (OpVal.getNode() == 0)
Scott Michel564427e2007-12-05 01:24:05 +000042 OpVal = N->getOperand(i);
43 }
44
Gabor Greifba36cb52008-08-28 21:40:38 +000045 assert(OpVal.getNode() != 0 && "LO16_vec did not locate a <defined> node");
Dan Gohmand8ed2a72008-08-20 14:50:24 +000046 ConstantSDNode *CN = cast<ConstantSDNode>(OpVal);
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +000047 return getI32Imm((unsigned)CN->getZExtValue() & 0xffff);
Scott Michel564427e2007-12-05 01:24:05 +000048}]>;
49
50// Transform an immediate, returning the high 16 bits shifted down:
51def HI16 : SDNodeXForm<imm, [{
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +000052 return getI32Imm((unsigned)N->getZExtValue() >> 16);
Scott Michel564427e2007-12-05 01:24:05 +000053}]>;
54
55// Transformation function: shift the high 16 bit immediate from a build_vector
56// node into the low 16 bits, and return a 16-bit constant.
57def HI16_vec : SDNodeXForm<scalar_to_vector, [{
Dan Gohman475871a2008-07-27 21:46:04 +000058 SDValue OpVal(0, 0);
Scott Michel564427e2007-12-05 01:24:05 +000059
60 assert(N->getOpcode() == ISD::BUILD_VECTOR
61 && "HI16_vec got something other than a BUILD_VECTOR");
62
63 // Get first constant operand...
Gabor Greif93c53e52008-08-31 15:37:04 +000064 for (unsigned i = 0, e = N->getNumOperands();
65 OpVal.getNode() == 0 && i != e; ++i) {
Scott Michel564427e2007-12-05 01:24:05 +000066 if (N->getOperand(i).getOpcode() == ISD::UNDEF) continue;
Gabor Greifba36cb52008-08-28 21:40:38 +000067 if (OpVal.getNode() == 0)
Scott Michel564427e2007-12-05 01:24:05 +000068 OpVal = N->getOperand(i);
69 }
70
Gabor Greifba36cb52008-08-28 21:40:38 +000071 assert(OpVal.getNode() != 0 && "HI16_vec did not locate a <defined> node");
Dan Gohmand8ed2a72008-08-20 14:50:24 +000072 ConstantSDNode *CN = cast<ConstantSDNode>(OpVal);
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +000073 return getI32Imm((unsigned)CN->getZExtValue() >> 16);
Scott Michel564427e2007-12-05 01:24:05 +000074}]>;
75
76// simm7 predicate - True if the immediate fits in an 7-bit signed
77// field.
78def simm7: PatLeaf<(imm), [{
Dan Gohman7810bfe2008-09-26 21:54:37 +000079 int sextVal = int(N->getSExtValue());
Scott Michel564427e2007-12-05 01:24:05 +000080 return (sextVal >= -64 && sextVal <= 63);
81}]>;
82
83// uimm7 predicate - True if the immediate fits in an 7-bit unsigned
84// field.
85def uimm7: PatLeaf<(imm), [{
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +000086 return (N->getZExtValue() <= 0x7f);
Scott Michel564427e2007-12-05 01:24:05 +000087}]>;
88
89// immSExt8 predicate - True if the immediate fits in an 8-bit sign extended
90// field.
91def immSExt8 : PatLeaf<(imm), [{
Dan Gohman7810bfe2008-09-26 21:54:37 +000092 int Value = int(N->getSExtValue());
Scott Michel79698f62008-03-20 00:51:36 +000093 return (Value >= -(1 << 8) && Value <= (1 << 8) - 1);
Scott Michel564427e2007-12-05 01:24:05 +000094}]>;
95
96// immU8: immediate, unsigned 8-bit quantity
97def immU8 : PatLeaf<(imm), [{
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +000098 return (N->getZExtValue() <= 0xff);
Scott Michel564427e2007-12-05 01:24:05 +000099}]>;
100
101// i64ImmSExt10 predicate - True if the i64 immediate fits in a 10-bit sign
102// extended field. Used by RI10Form instructions like 'ldq'.
103def i64ImmSExt10 : PatLeaf<(imm), [{
104 return isI64IntS10Immediate(N);
105}]>;
106
107// i32ImmSExt10 predicate - True if the i32 immediate fits in a 10-bit sign
108// extended field. Used by RI10Form instructions like 'ldq'.
109def i32ImmSExt10 : PatLeaf<(imm), [{
110 return isI32IntS10Immediate(N);
111}]>;
112
Scott Michel504c3692007-12-17 22:32:34 +0000113// i32ImmUns10 predicate - True if the i32 immediate fits in a 10-bit unsigned
114// field. Used by RI10Form instructions like 'ldq'.
115def i32ImmUns10 : PatLeaf<(imm), [{
116 return isI32IntU10Immediate(N);
117}]>;
118
Scott Michelec2a08f2007-12-15 00:38:50 +0000119// i16ImmSExt10 predicate - True if the i16 immediate fits in a 10-bit sign
Scott Michel564427e2007-12-05 01:24:05 +0000120// extended field. Used by RI10Form instructions like 'ldq'.
121def i16ImmSExt10 : PatLeaf<(imm), [{
122 return isI16IntS10Immediate(N);
123}]>;
124
Scott Michel504c3692007-12-17 22:32:34 +0000125// i16ImmUns10 predicate - True if the i16 immediate fits into a 10-bit unsigned
Scott Michelec2a08f2007-12-15 00:38:50 +0000126// value. Used by RI10Form instructions.
Scott Michel504c3692007-12-17 22:32:34 +0000127def i16ImmUns10 : PatLeaf<(imm), [{
Scott Michelec2a08f2007-12-15 00:38:50 +0000128 return isI16IntU10Immediate(N);
129}]>;
130
Scott Michel564427e2007-12-05 01:24:05 +0000131def immSExt16 : PatLeaf<(imm), [{
132 // immSExt16 predicate - True if the immediate fits in a 16-bit sign extended
133 // field.
134 short Ignored;
135 return isIntS16Immediate(N, Ignored);
136}]>;
137
138def immZExt16 : PatLeaf<(imm), [{
139 // immZExt16 predicate - True if the immediate fits in a 16-bit zero extended
140 // field.
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000141 return (uint64_t)N->getZExtValue() == (unsigned short)N->getZExtValue();
Scott Michel564427e2007-12-05 01:24:05 +0000142}], LO16>;
143
144def immU16 : PatLeaf<(imm), [{
145 // immU16 predicate- True if the immediate fits into a 16-bit unsigned field.
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000146 return (uint64_t)N->getZExtValue() == (N->getZExtValue() & 0xffff);
Scott Michel564427e2007-12-05 01:24:05 +0000147}]>;
148
149def imm18 : PatLeaf<(imm), [{
150 // imm18 predicate: True if the immediate fits into an 18-bit unsigned field.
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000151 int Value = (int) N->getZExtValue();
Scott Michel564427e2007-12-05 01:24:05 +0000152 return ((Value & ((1 << 19) - 1)) == Value);
153}]>;
154
Scott Michel9de5d0d2008-01-11 02:53:15 +0000155def lo16 : PatLeaf<(imm), [{
Scott Michelad2715e2008-03-05 23:02:02 +0000156 // lo16 predicate - returns true if the immediate has all zeros in the
Scott Michel9de5d0d2008-01-11 02:53:15 +0000157 // low order bits and is a 32-bit constant:
Owen Anderson825b72b2009-08-11 20:47:22 +0000158 if (N->getValueType(0) == MVT::i32) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000159 uint32_t val = N->getZExtValue();
Scott Michel9de5d0d2008-01-11 02:53:15 +0000160 return ((val & 0x0000ffff) == val);
161 }
162
163 return false;
164}], LO16>;
165
Scott Michel564427e2007-12-05 01:24:05 +0000166def hi16 : PatLeaf<(imm), [{
167 // hi16 predicate - returns true if the immediate has all zeros in the
168 // low order bits and is a 32-bit constant:
Owen Anderson825b72b2009-08-11 20:47:22 +0000169 if (N->getValueType(0) == MVT::i32) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000170 uint32_t val = uint32_t(N->getZExtValue());
Scott Michel564427e2007-12-05 01:24:05 +0000171 return ((val & 0xffff0000) == val);
Owen Anderson825b72b2009-08-11 20:47:22 +0000172 } else if (N->getValueType(0) == MVT::i64) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000173 uint64_t val = N->getZExtValue();
Scott Michelad2715e2008-03-05 23:02:02 +0000174 return ((val & 0xffff0000ULL) == val);
Scott Michel564427e2007-12-05 01:24:05 +0000175 }
176
177 return false;
178}], HI16>;
179
Scott Michela59d4692008-02-23 18:41:37 +0000180def bitshift : PatLeaf<(imm), [{
181 // bitshift predicate - returns true if 0 < imm <= 7 for SHLQBII
182 // (shift left quadword by bits immediate)
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000183 int64_t Val = N->getZExtValue();
Scott Michela59d4692008-02-23 18:41:37 +0000184 return (Val > 0 && Val <= 7);
185}]>;
186
Scott Michel564427e2007-12-05 01:24:05 +0000187//===----------------------------------------------------------------------===//
188// Floating point operands:
189//===----------------------------------------------------------------------===//
190
191// Transform a float, returning the high 16 bits shifted down, as if
192// the float was really an unsigned integer:
193def HI16_f32 : SDNodeXForm<fpimm, [{
Chris Lattner10d724a2007-12-16 20:41:33 +0000194 float fval = N->getValueAPF().convertToFloat();
195 return getI32Imm(FloatToBits(fval) >> 16);
Scott Michel564427e2007-12-05 01:24:05 +0000196}]>;
197
198// Transformation function on floats: get the low 16 bits as if the float was
199// an unsigned integer.
200def LO16_f32 : SDNodeXForm<fpimm, [{
Chris Lattner10d724a2007-12-16 20:41:33 +0000201 float fval = N->getValueAPF().convertToFloat();
202 return getI32Imm(FloatToBits(fval) & 0xffff);
Scott Michel564427e2007-12-05 01:24:05 +0000203}]>;
204
205def FPimm_sext16 : SDNodeXForm<fpimm, [{
Chris Lattner10d724a2007-12-16 20:41:33 +0000206 float fval = N->getValueAPF().convertToFloat();
207 return getI32Imm((int) ((FloatToBits(fval) << 16) >> 16));
Scott Michel564427e2007-12-05 01:24:05 +0000208}]>;
209
210def FPimm_u18 : SDNodeXForm<fpimm, [{
Chris Lattner10d724a2007-12-16 20:41:33 +0000211 float fval = N->getValueAPF().convertToFloat();
212 return getI32Imm(FloatToBits(fval) & ((1 << 19) - 1));
Scott Michel564427e2007-12-05 01:24:05 +0000213}]>;
214
215def fpimmSExt16 : PatLeaf<(fpimm), [{
216 short Ignored;
217 return isFPS16Immediate(N, Ignored);
218}], FPimm_sext16>;
219
220// Does the SFP constant only have upp 16 bits set?
221def hi16_f32 : PatLeaf<(fpimm), [{
Owen Anderson825b72b2009-08-11 20:47:22 +0000222 if (N->getValueType(0) == MVT::f32) {
Chris Lattner10d724a2007-12-16 20:41:33 +0000223 uint32_t val = FloatToBits(N->getValueAPF().convertToFloat());
Scott Michel564427e2007-12-05 01:24:05 +0000224 return ((val & 0xffff0000) == val);
225 }
226
227 return false;
228}], HI16_f32>;
229
230// Does the SFP constant fit into 18 bits?
231def fpimm18 : PatLeaf<(fpimm), [{
Owen Anderson825b72b2009-08-11 20:47:22 +0000232 if (N->getValueType(0) == MVT::f32) {
Chris Lattner10d724a2007-12-16 20:41:33 +0000233 uint32_t Value = FloatToBits(N->getValueAPF().convertToFloat());
Scott Michel564427e2007-12-05 01:24:05 +0000234 return ((Value & ((1 << 19) - 1)) == Value);
235 }
236
237 return false;
238}], FPimm_u18>;
239
240//===----------------------------------------------------------------------===//
Scott Michelec2a08f2007-12-15 00:38:50 +0000241// 64-bit operands (TODO):
Scott Michel564427e2007-12-05 01:24:05 +0000242//===----------------------------------------------------------------------===//
243
244//===----------------------------------------------------------------------===//
245// build_vector operands:
246//===----------------------------------------------------------------------===//
247
248// v16i8SExt8Imm_xform function: convert build_vector to 8-bit sign extended
249// immediate constant load for v16i8 vectors. N.B.: The incoming constant has
250// to be a 16-bit quantity with the upper and lower bytes equal (e.g., 0x2a2a).
251def v16i8SExt8Imm_xform: SDNodeXForm<build_vector, [{
Owen Anderson825b72b2009-08-11 20:47:22 +0000252 return SPU::get_vec_i8imm(N, *CurDAG, MVT::i8);
Scott Michel564427e2007-12-05 01:24:05 +0000253}]>;
254
255// v16i8SExt8Imm: Predicate test for 8-bit sign extended immediate constant
256// load, works in conjunction with its transform function. N.B.: This relies the
257// incoming constant being a 16-bit quantity, where the upper and lower bytes
258// are EXACTLY the same (e.g., 0x2a2a)
259def v16i8SExt8Imm: PatLeaf<(build_vector), [{
Owen Anderson825b72b2009-08-11 20:47:22 +0000260 return SPU::get_vec_i8imm(N, *CurDAG, MVT::i8).getNode() != 0;
Scott Michel564427e2007-12-05 01:24:05 +0000261}], v16i8SExt8Imm_xform>;
262
263// v16i8U8Imm_xform function: convert build_vector to unsigned 8-bit
264// immediate constant load for v16i8 vectors. N.B.: The incoming constant has
265// to be a 16-bit quantity with the upper and lower bytes equal (e.g., 0x2a2a).
266def v16i8U8Imm_xform: SDNodeXForm<build_vector, [{
Owen Anderson825b72b2009-08-11 20:47:22 +0000267 return SPU::get_vec_i8imm(N, *CurDAG, MVT::i8);
Scott Michel564427e2007-12-05 01:24:05 +0000268}]>;
269
270// v16i8U8Imm: Predicate test for unsigned 8-bit immediate constant
271// load, works in conjunction with its transform function. N.B.: This relies the
272// incoming constant being a 16-bit quantity, where the upper and lower bytes
273// are EXACTLY the same (e.g., 0x2a2a)
274def v16i8U8Imm: PatLeaf<(build_vector), [{
Owen Anderson825b72b2009-08-11 20:47:22 +0000275 return SPU::get_vec_i8imm(N, *CurDAG, MVT::i8).getNode() != 0;
Scott Michel564427e2007-12-05 01:24:05 +0000276}], v16i8U8Imm_xform>;
277
278// v8i16SExt8Imm_xform function: convert build_vector to 8-bit sign extended
279// immediate constant load for v8i16 vectors.
280def v8i16SExt8Imm_xform: SDNodeXForm<build_vector, [{
Owen Anderson825b72b2009-08-11 20:47:22 +0000281 return SPU::get_vec_i8imm(N, *CurDAG, MVT::i16);
Scott Michel564427e2007-12-05 01:24:05 +0000282}]>;
283
284// v8i16SExt8Imm: Predicate test for 8-bit sign extended immediate constant
285// load, works in conjunction with its transform function.
286def v8i16SExt8Imm: PatLeaf<(build_vector), [{
Owen Anderson825b72b2009-08-11 20:47:22 +0000287 return SPU::get_vec_i8imm(N, *CurDAG, MVT::i16).getNode() != 0;
Scott Michel564427e2007-12-05 01:24:05 +0000288}], v8i16SExt8Imm_xform>;
289
290// v8i16SExt10Imm_xform function: convert build_vector to 16-bit sign extended
291// immediate constant load for v8i16 vectors.
292def v8i16SExt10Imm_xform: SDNodeXForm<build_vector, [{
Owen Anderson825b72b2009-08-11 20:47:22 +0000293 return SPU::get_vec_i10imm(N, *CurDAG, MVT::i16);
Scott Michel564427e2007-12-05 01:24:05 +0000294}]>;
295
296// v8i16SExt10Imm: Predicate test for 16-bit sign extended immediate constant
297// load, works in conjunction with its transform function.
298def v8i16SExt10Imm: PatLeaf<(build_vector), [{
Owen Anderson825b72b2009-08-11 20:47:22 +0000299 return SPU::get_vec_i10imm(N, *CurDAG, MVT::i16).getNode() != 0;
Scott Michel564427e2007-12-05 01:24:05 +0000300}], v8i16SExt10Imm_xform>;
301
Scott Michel504c3692007-12-17 22:32:34 +0000302// v8i16Uns10Imm_xform function: convert build_vector to 16-bit unsigned
303// immediate constant load for v8i16 vectors.
304def v8i16Uns10Imm_xform: SDNodeXForm<build_vector, [{
Owen Anderson825b72b2009-08-11 20:47:22 +0000305 return SPU::get_vec_i10imm(N, *CurDAG, MVT::i16);
Scott Michel504c3692007-12-17 22:32:34 +0000306}]>;
307
308// v8i16Uns10Imm: Predicate test for 16-bit unsigned immediate constant
309// load, works in conjunction with its transform function.
310def v8i16Uns10Imm: PatLeaf<(build_vector), [{
Owen Anderson825b72b2009-08-11 20:47:22 +0000311 return SPU::get_vec_i10imm(N, *CurDAG, MVT::i16).getNode() != 0;
Scott Michel504c3692007-12-17 22:32:34 +0000312}], v8i16Uns10Imm_xform>;
313
Scott Michel564427e2007-12-05 01:24:05 +0000314// v8i16SExt16Imm_xform function: convert build_vector to 16-bit sign extended
315// immediate constant load for v8i16 vectors.
Scott Michel504c3692007-12-17 22:32:34 +0000316def v8i16Uns16Imm_xform: SDNodeXForm<build_vector, [{
Owen Anderson825b72b2009-08-11 20:47:22 +0000317 return SPU::get_vec_i16imm(N, *CurDAG, MVT::i16);
Scott Michel564427e2007-12-05 01:24:05 +0000318}]>;
319
320// v8i16SExt16Imm: Predicate test for 16-bit sign extended immediate constant
321// load, works in conjunction with its transform function.
322def v8i16SExt16Imm: PatLeaf<(build_vector), [{
Owen Anderson825b72b2009-08-11 20:47:22 +0000323 return SPU::get_vec_i16imm(N, *CurDAG, MVT::i16).getNode() != 0;
Scott Michel504c3692007-12-17 22:32:34 +0000324}], v8i16Uns16Imm_xform>;
Scott Michel564427e2007-12-05 01:24:05 +0000325
326// v4i32SExt10Imm_xform function: convert build_vector to 10-bit sign extended
327// immediate constant load for v4i32 vectors.
328def v4i32SExt10Imm_xform: SDNodeXForm<build_vector, [{
Owen Anderson825b72b2009-08-11 20:47:22 +0000329 return SPU::get_vec_i10imm(N, *CurDAG, MVT::i32);
Scott Michel564427e2007-12-05 01:24:05 +0000330}]>;
331
332// v4i32SExt10Imm: Predicate test for 10-bit sign extended immediate constant
333// load, works in conjunction with its transform function.
334def v4i32SExt10Imm: PatLeaf<(build_vector), [{
Owen Anderson825b72b2009-08-11 20:47:22 +0000335 return SPU::get_vec_i10imm(N, *CurDAG, MVT::i32).getNode() != 0;
Scott Michel564427e2007-12-05 01:24:05 +0000336}], v4i32SExt10Imm_xform>;
337
Scott Michel504c3692007-12-17 22:32:34 +0000338// v4i32Uns10Imm_xform function: convert build_vector to 10-bit unsigned
339// immediate constant load for v4i32 vectors.
340def v4i32Uns10Imm_xform: SDNodeXForm<build_vector, [{
Owen Anderson825b72b2009-08-11 20:47:22 +0000341 return SPU::get_vec_i10imm(N, *CurDAG, MVT::i32);
Scott Michel504c3692007-12-17 22:32:34 +0000342}]>;
343
344// v4i32Uns10Imm: Predicate test for 10-bit unsigned immediate constant
345// load, works in conjunction with its transform function.
346def v4i32Uns10Imm: PatLeaf<(build_vector), [{
Owen Anderson825b72b2009-08-11 20:47:22 +0000347 return SPU::get_vec_i10imm(N, *CurDAG, MVT::i32).getNode() != 0;
Scott Michel504c3692007-12-17 22:32:34 +0000348}], v4i32Uns10Imm_xform>;
349
Scott Michel564427e2007-12-05 01:24:05 +0000350// v4i32SExt16Imm_xform function: convert build_vector to 16-bit sign extended
351// immediate constant load for v4i32 vectors.
352def v4i32SExt16Imm_xform: SDNodeXForm<build_vector, [{
Owen Anderson825b72b2009-08-11 20:47:22 +0000353 return SPU::get_vec_i16imm(N, *CurDAG, MVT::i32);
Scott Michel564427e2007-12-05 01:24:05 +0000354}]>;
355
356// v4i32SExt16Imm: Predicate test for 16-bit sign extended immediate constant
357// load, works in conjunction with its transform function.
358def v4i32SExt16Imm: PatLeaf<(build_vector), [{
Owen Anderson825b72b2009-08-11 20:47:22 +0000359 return SPU::get_vec_i16imm(N, *CurDAG, MVT::i32).getNode() != 0;
Scott Michel564427e2007-12-05 01:24:05 +0000360}], v4i32SExt16Imm_xform>;
361
362// v4i32Uns18Imm_xform function: convert build_vector to 18-bit unsigned
363// immediate constant load for v4i32 vectors.
364def v4i32Uns18Imm_xform: SDNodeXForm<build_vector, [{
Owen Anderson825b72b2009-08-11 20:47:22 +0000365 return SPU::get_vec_u18imm(N, *CurDAG, MVT::i32);
Scott Michel564427e2007-12-05 01:24:05 +0000366}]>;
367
368// v4i32Uns18Imm: Predicate test for 18-bit unsigned immediate constant load,
369// works in conjunction with its transform function.
370def v4i32Uns18Imm: PatLeaf<(build_vector), [{
Owen Anderson825b72b2009-08-11 20:47:22 +0000371 return SPU::get_vec_u18imm(N, *CurDAG, MVT::i32).getNode() != 0;
Scott Michel564427e2007-12-05 01:24:05 +0000372}], v4i32Uns18Imm_xform>;
373
374// ILHUvec_get_imm xform function: convert build_vector to ILHUvec imm constant
375// load.
376def ILHUvec_get_imm: SDNodeXForm<build_vector, [{
Owen Anderson825b72b2009-08-11 20:47:22 +0000377 return SPU::get_ILHUvec_imm(N, *CurDAG, MVT::i32);
Scott Michel564427e2007-12-05 01:24:05 +0000378}]>;
379
380/// immILHUvec: Predicate test for a ILHU constant vector.
381def immILHUvec: PatLeaf<(build_vector), [{
Owen Anderson825b72b2009-08-11 20:47:22 +0000382 return SPU::get_ILHUvec_imm(N, *CurDAG, MVT::i32).getNode() != 0;
Scott Michel564427e2007-12-05 01:24:05 +0000383}], ILHUvec_get_imm>;
384
385// Catch-all for any other i32 vector constants
386def v4i32_get_imm: SDNodeXForm<build_vector, [{
387 return SPU::get_v4i32_imm(N, *CurDAG);
388}]>;
389
390def v4i32Imm: PatLeaf<(build_vector), [{
Gabor Greifba36cb52008-08-28 21:40:38 +0000391 return SPU::get_v4i32_imm(N, *CurDAG).getNode() != 0;
Scott Michel564427e2007-12-05 01:24:05 +0000392}], v4i32_get_imm>;
393
394// v2i64SExt10Imm_xform function: convert build_vector to 10-bit sign extended
395// immediate constant load for v2i64 vectors.
396def v2i64SExt10Imm_xform: SDNodeXForm<build_vector, [{
Owen Anderson825b72b2009-08-11 20:47:22 +0000397 return SPU::get_vec_i10imm(N, *CurDAG, MVT::i64);
Scott Michel564427e2007-12-05 01:24:05 +0000398}]>;
399
400// v2i64SExt10Imm: Predicate test for 10-bit sign extended immediate constant
401// load, works in conjunction with its transform function.
402def v2i64SExt10Imm: PatLeaf<(build_vector), [{
Owen Anderson825b72b2009-08-11 20:47:22 +0000403 return SPU::get_vec_i10imm(N, *CurDAG, MVT::i64).getNode() != 0;
Scott Michel564427e2007-12-05 01:24:05 +0000404}], v2i64SExt10Imm_xform>;
405
406// v2i64SExt16Imm_xform function: convert build_vector to 16-bit sign extended
407// immediate constant load for v2i64 vectors.
408def v2i64SExt16Imm_xform: SDNodeXForm<build_vector, [{
Owen Anderson825b72b2009-08-11 20:47:22 +0000409 return SPU::get_vec_i16imm(N, *CurDAG, MVT::i64);
Scott Michel564427e2007-12-05 01:24:05 +0000410}]>;
411
412// v2i64SExt16Imm: Predicate test for 16-bit sign extended immediate constant
413// load, works in conjunction with its transform function.
414def v2i64SExt16Imm: PatLeaf<(build_vector), [{
Owen Anderson825b72b2009-08-11 20:47:22 +0000415 return SPU::get_vec_i16imm(N, *CurDAG, MVT::i64).getNode() != 0;
Scott Michel564427e2007-12-05 01:24:05 +0000416}], v2i64SExt16Imm_xform>;
417
418// v2i64Uns18Imm_xform function: convert build_vector to 18-bit unsigned
419// immediate constant load for v2i64 vectors.
420def v2i64Uns18Imm_xform: SDNodeXForm<build_vector, [{
Owen Anderson825b72b2009-08-11 20:47:22 +0000421 return SPU::get_vec_u18imm(N, *CurDAG, MVT::i64);
Scott Michel564427e2007-12-05 01:24:05 +0000422}]>;
423
424// v2i64Uns18Imm: Predicate test for 18-bit unsigned immediate constant load,
425// works in conjunction with its transform function.
426def v2i64Uns18Imm: PatLeaf<(build_vector), [{
Owen Anderson825b72b2009-08-11 20:47:22 +0000427 return SPU::get_vec_u18imm(N, *CurDAG, MVT::i64).getNode() != 0;
Scott Michel564427e2007-12-05 01:24:05 +0000428}], v2i64Uns18Imm_xform>;
429
430/// immILHUvec: Predicate test for a ILHU constant vector.
431def immILHUvec_i64: PatLeaf<(build_vector), [{
Owen Anderson825b72b2009-08-11 20:47:22 +0000432 return SPU::get_ILHUvec_imm(N, *CurDAG, MVT::i64).getNode() != 0;
Scott Michel564427e2007-12-05 01:24:05 +0000433}], ILHUvec_get_imm>;
434
435// Catch-all for any other i32 vector constants
436def v2i64_get_imm: SDNodeXForm<build_vector, [{
437 return SPU::get_v2i64_imm(N, *CurDAG);
438}]>;
439
440def v2i64Imm: PatLeaf<(build_vector), [{
Gabor Greifba36cb52008-08-28 21:40:38 +0000441 return SPU::get_v2i64_imm(N, *CurDAG).getNode() != 0;
Scott Michel564427e2007-12-05 01:24:05 +0000442}], v2i64_get_imm>;
443
444//===----------------------------------------------------------------------===//
445// Operand Definitions.
446
Scott Michel9de5d0d2008-01-11 02:53:15 +0000447def s7imm: Operand<i8> {
448 let PrintMethod = "printS7ImmOperand";
449}
450
451def s7imm_i8: Operand<i8> {
Scott Michel564427e2007-12-05 01:24:05 +0000452 let PrintMethod = "printS7ImmOperand";
453}
454
455def u7imm: Operand<i16> {
456 let PrintMethod = "printU7ImmOperand";
457}
458
Scott Michel504c3692007-12-17 22:32:34 +0000459def u7imm_i8: Operand<i8> {
460 let PrintMethod = "printU7ImmOperand";
461}
462
Scott Michel564427e2007-12-05 01:24:05 +0000463def u7imm_i32: Operand<i32> {
464 let PrintMethod = "printU7ImmOperand";
465}
466
467// Halfword, signed 10-bit constant
468def s10imm : Operand<i16> {
469 let PrintMethod = "printS10ImmOperand";
470}
471
Scott Michela59d4692008-02-23 18:41:37 +0000472def s10imm_i8: Operand<i8> {
473 let PrintMethod = "printS10ImmOperand";
474}
475
Scott Michel564427e2007-12-05 01:24:05 +0000476def s10imm_i32: Operand<i32> {
477 let PrintMethod = "printS10ImmOperand";
478}
479
480def s10imm_i64: Operand<i64> {
481 let PrintMethod = "printS10ImmOperand";
482}
483
484// Unsigned 10-bit integers:
485def u10imm: Operand<i16> {
486 let PrintMethod = "printU10ImmOperand";
487}
488
Scott Michel504c3692007-12-17 22:32:34 +0000489def u10imm_i8: Operand<i8> {
490 let PrintMethod = "printU10ImmOperand";
491}
492
Scott Michel564427e2007-12-05 01:24:05 +0000493def u10imm_i32: Operand<i32> {
494 let PrintMethod = "printU10ImmOperand";
495}
496
497def s16imm : Operand<i16> {
498 let PrintMethod = "printS16ImmOperand";
499}
500
Scott Michel504c3692007-12-17 22:32:34 +0000501def s16imm_i8: Operand<i8> {
502 let PrintMethod = "printS16ImmOperand";
503}
504
Scott Michel564427e2007-12-05 01:24:05 +0000505def s16imm_i32: Operand<i32> {
506 let PrintMethod = "printS16ImmOperand";
507}
508
509def s16imm_i64: Operand<i64> {
510 let PrintMethod = "printS16ImmOperand";
511}
512
513def s16imm_f32: Operand<f32> {
514 let PrintMethod = "printS16ImmOperand";
515}
516
517def s16imm_f64: Operand<f64> {
518 let PrintMethod = "printS16ImmOperand";
519}
520
Scott Michelad2715e2008-03-05 23:02:02 +0000521def u16imm_i64 : Operand<i64> {
522 let PrintMethod = "printU16ImmOperand";
523}
524
Scott Michel203b2d62008-04-30 00:30:08 +0000525def u16imm_i32 : Operand<i32> {
526 let PrintMethod = "printU16ImmOperand";
527}
528
529def u16imm : Operand<i16> {
Scott Michel564427e2007-12-05 01:24:05 +0000530 let PrintMethod = "printU16ImmOperand";
531}
532
533def f16imm : Operand<f32> {
534 let PrintMethod = "printU16ImmOperand";
535}
536
537def s18imm : Operand<i32> {
538 let PrintMethod = "printS18ImmOperand";
539}
540
541def u18imm : Operand<i32> {
542 let PrintMethod = "printU18ImmOperand";
543}
544
545def u18imm_i64 : Operand<i64> {
546 let PrintMethod = "printU18ImmOperand";
547}
548
549def f18imm : Operand<f32> {
550 let PrintMethod = "printU18ImmOperand";
551}
552
553def f18imm_f64 : Operand<f64> {
554 let PrintMethod = "printU18ImmOperand";
555}
556
557// Negated 7-bit halfword rotate immediate operands
558def rothNeg7imm : Operand<i32> {
559 let PrintMethod = "printROTHNeg7Imm";
560}
561
562def rothNeg7imm_i16 : Operand<i16> {
563 let PrintMethod = "printROTHNeg7Imm";
564}
565
566// Negated 7-bit word rotate immediate operands
567def rotNeg7imm : Operand<i32> {
568 let PrintMethod = "printROTNeg7Imm";
569}
570
571def rotNeg7imm_i16 : Operand<i16> {
572 let PrintMethod = "printROTNeg7Imm";
573}
574
Scott Michel8bf61e82008-06-02 22:18:03 +0000575def rotNeg7imm_i8 : Operand<i8> {
576 let PrintMethod = "printROTNeg7Imm";
577}
578
Scott Michel564427e2007-12-05 01:24:05 +0000579def target : Operand<OtherVT> {
580 let PrintMethod = "printBranchOperand";
581}
582
583// Absolute address call target
584def calltarget : Operand<iPTR> {
585 let PrintMethod = "printCallOperand";
586 let MIOperandInfo = (ops u18imm:$calldest);
587}
588
Scott Michelaedc6372008-12-10 00:15:19 +0000589// PC relative call target
Scott Michel564427e2007-12-05 01:24:05 +0000590def relcalltarget : Operand<iPTR> {
591 let PrintMethod = "printPCRelativeOperand";
592 let MIOperandInfo = (ops s16imm:$calldest);
593}
594
595// Branch targets:
596def brtarget : Operand<OtherVT> {
597 let PrintMethod = "printPCRelativeOperand";
598}
599
Scott Michelaedc6372008-12-10 00:15:19 +0000600// Hint for branch target
601def hbrtarget : Operand<OtherVT> {
602 let PrintMethod = "printHBROperand";
603}
604
Scott Michel564427e2007-12-05 01:24:05 +0000605// Indirect call target
606def indcalltarget : Operand<iPTR> {
607 let PrintMethod = "printCallOperand";
608 let MIOperandInfo = (ops ptr_rc:$calldest);
609}
610
611def symbolHi: Operand<i32> {
612 let PrintMethod = "printSymbolHi";
613}
614
615def symbolLo: Operand<i32> {
616 let PrintMethod = "printSymbolLo";
617}
618
619def symbolLSA: Operand<i32> {
620 let PrintMethod = "printSymbolLSA";
621}
622
Scott Michelf0569be2008-12-27 04:51:36 +0000623// Shuffle address memory operaand [s7imm(reg) d-format]
624def shufaddr : Operand<iPTR> {
625 let PrintMethod = "printShufAddr";
Scott Michel564427e2007-12-05 01:24:05 +0000626 let MIOperandInfo = (ops s7imm:$imm, ptr_rc:$reg);
627}
628
629// memory s10imm(reg) operand
Scott Michelf0569be2008-12-27 04:51:36 +0000630def dformaddr : Operand<iPTR> {
631 let PrintMethod = "printDFormAddr";
Scott Michel564427e2007-12-05 01:24:05 +0000632 let MIOperandInfo = (ops s10imm:$imm, ptr_rc:$reg);
633}
634
635// 256K local store address
636// N.B.: The tblgen code generator expects to have two operands, an offset
637// and a pointer. Of these, only the immediate is actually used.
638def addr256k : Operand<iPTR> {
639 let PrintMethod = "printAddr256K";
640 let MIOperandInfo = (ops s16imm:$imm, ptr_rc:$reg);
641}
642
643// memory s18imm(reg) operand
644def memri18 : Operand<iPTR> {
645 let PrintMethod = "printMemRegImmS18";
646 let MIOperandInfo = (ops s18imm:$imm, ptr_rc:$reg);
647}
648
649// memory register + register operand
650def memrr : Operand<iPTR> {
651 let PrintMethod = "printMemRegReg";
652 let MIOperandInfo = (ops ptr_rc:$reg_a, ptr_rc:$reg_b);
653}
654
655// Define SPU-specific addressing modes: These come in three basic
656// flavors:
657//
658// D-form : [r+I10] (10-bit signed offset + reg)
659// X-form : [r+r] (reg+reg)
660// A-form : abs (256K LSA offset)
661// D-form(2): [r+I7] (7-bit signed offset + reg)
662
663def dform_addr : ComplexPattern<iPTR, 2, "SelectDFormAddr", [], []>;
664def xform_addr : ComplexPattern<iPTR, 2, "SelectXFormAddr", [], []>;
665def aform_addr : ComplexPattern<iPTR, 2, "SelectAFormAddr", [], []>;
666def dform2_addr : ComplexPattern<iPTR, 2, "SelectDForm2Addr", [], []>;