[SystemZ] Add LOC and LOCG
[oota-llvm.git] / lib / Target / SystemZ / SystemZOperands.td
1 //===-- SystemZOperands.td - SystemZ instruction operands ----*- tblgen-*--===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 //===----------------------------------------------------------------------===//
11 // Class definitions
12 //===----------------------------------------------------------------------===//
13
14 class ImmediateAsmOperand<string name>
15   : AsmOperandClass {
16   let Name = name;
17   let RenderMethod = "addImmOperands";
18 }
19
20 // Constructs both a DAG pattern and instruction operand for an immediate
21 // of type VT.  PRED returns true if a node is acceptable and XFORM returns
22 // the operand value associated with the node.  ASMOP is the name of the
23 // associated asm operand, and also forms the basis of the asm print method.
24 class Immediate<ValueType vt, code pred, SDNodeXForm xform, string asmop>
25   : PatLeaf<(vt imm), pred, xform>, Operand<vt> {
26   let PrintMethod = "print"##asmop##"Operand";
27   let DecoderMethod = "decode"##asmop##"Operand";
28   let ParserMatchClass = !cast<AsmOperandClass>(asmop);
29 }
30
31 // Constructs an asm operand for a PC-relative address.  SIZE says how
32 // many bits there are.
33 class PCRelAsmOperand<string size> : ImmediateAsmOperand<"PCRel"##size> {
34   let PredicateMethod = "isImm";
35   let ParserMethod = "parsePCRel"##size;
36 }
37
38 // Constructs an operand for a PC-relative address with address type VT.
39 // ASMOP is the associated asm operand.
40 class PCRelOperand<ValueType vt, AsmOperandClass asmop> : Operand<vt> {
41   let PrintMethod = "printPCRelOperand";
42   let ParserMatchClass = asmop;
43 }
44
45 // Constructs both a DAG pattern and instruction operand for a PC-relative
46 // address with address size VT.  SELF is the name of the operand and
47 // ASMOP is the associated asm operand.
48 class PCRelAddress<ValueType vt, string self, AsmOperandClass asmop>
49   : ComplexPattern<vt, 1, "selectPCRelAddress", [z_pcrel_wrapper]>,
50     PCRelOperand<vt, asmop> {
51   let MIOperandInfo = (ops !cast<Operand>(self));
52 }
53
54 // Constructs an AsmOperandClass for addressing mode FORMAT, treating the
55 // registers as having BITSIZE bits and displacements as having DISPSIZE bits.
56 // LENGTH is "LenN" for addresses with an N-bit length field, otherwise it
57 // is "".
58 class AddressAsmOperand<string format, string bitsize, string dispsize,
59                         string length = "">
60   : AsmOperandClass {
61   let Name = format##bitsize##"Disp"##dispsize##length;
62   let ParserMethod = "parse"##format##bitsize;
63   let RenderMethod = "add"##format##"Operands";
64 }
65
66 // Constructs both a DAG pattern and instruction operand for an addressing mode.
67 // FORMAT, BITSIZE, DISPSIZE and LENGTH are the parameters to an associated
68 // AddressAsmOperand.  OPERANDS is a list of NUMOPS individual operands
69 // (base register, displacement, etc.).  SELTYPE is the type of the memory
70 // operand for selection purposes; sometimes we want different selection
71 // choices for the same underlying addressing mode.  SUFFIX is similarly
72 // a suffix appended to the displacement for selection purposes;
73 // e.g. we want to reject small 20-bit displacements if a 12-bit form
74 // also exists, but we want to accept them otherwise.
75 class AddressingMode<string seltype, string bitsize, string dispsize,
76                      string suffix, string length, int numops, string format,
77                      dag operands>
78   : ComplexPattern<!cast<ValueType>("i"##bitsize), numops,
79                    "select"##seltype##dispsize##suffix##length,
80                    [add, sub, or, frameindex, z_adjdynalloc]>,
81     Operand<!cast<ValueType>("i"##bitsize)> {
82   let PrintMethod = "print"##format##"Operand";
83   let EncoderMethod = "get"##format##dispsize##length##"Encoding";
84   let DecoderMethod =
85     "decode"##format##bitsize##"Disp"##dispsize##length##"Operand";
86   let MIOperandInfo = operands;
87   let ParserMatchClass =
88     !cast<AddressAsmOperand>(format##bitsize##"Disp"##dispsize##length);
89 }
90
91 // An addressing mode with a base and displacement but no index.
92 class BDMode<string type, string bitsize, string dispsize, string suffix>
93   : AddressingMode<type, bitsize, dispsize, suffix, "", 2, "BDAddr",
94                    (ops !cast<RegisterOperand>("ADDR"##bitsize),
95                         !cast<Immediate>("disp"##dispsize##"imm"##bitsize))>;
96
97 // An addressing mode with a base, displacement and index.
98 class BDXMode<string type, string bitsize, string dispsize, string suffix>
99   : AddressingMode<type, bitsize, dispsize, suffix, "", 3, "BDXAddr",
100                    (ops !cast<RegisterOperand>("ADDR"##bitsize),
101                         !cast<Immediate>("disp"##dispsize##"imm"##bitsize),
102                         !cast<RegisterOperand>("ADDR"##bitsize))>;
103
104 // A BDMode paired with an immediate length operand of LENSIZE bits.
105 class BDLMode<string type, string bitsize, string dispsize, string suffix,
106               string lensize>
107   : AddressingMode<type, bitsize, dispsize, suffix, "Len"##lensize, 3,
108                    "BDLAddr",
109                    (ops !cast<RegisterOperand>("ADDR"##bitsize),
110                         !cast<Immediate>("disp"##dispsize##"imm"##bitsize),
111                         !cast<Immediate>("imm"##bitsize))>;
112
113 //===----------------------------------------------------------------------===//
114 // Manipulating CC masks
115 //===----------------------------------------------------------------------===//
116
117 def INVCC : SDNodeXForm<imm, [{
118   unsigned Value = N->getZExtValue() ^ SystemZ::CCMASK_ANY;
119   return CurDAG->getTargetConstant(Value, MVT::i8);
120 }]>;
121
122 //===----------------------------------------------------------------------===//
123 // Extracting immediate operands from nodes
124 // These all create MVT::i64 nodes to ensure the value is not sign-extended
125 // when converted from an SDNode to a MachineOperand later on.
126 //===----------------------------------------------------------------------===//
127
128 // Bits 0-15 (counting from the lsb).
129 def LL16 : SDNodeXForm<imm, [{
130   uint64_t Value = N->getZExtValue() & 0x000000000000FFFFULL;
131   return CurDAG->getTargetConstant(Value, MVT::i64);
132 }]>;
133
134 // Bits 16-31 (counting from the lsb).
135 def LH16 : SDNodeXForm<imm, [{
136   uint64_t Value = (N->getZExtValue() & 0x00000000FFFF0000ULL) >> 16;
137   return CurDAG->getTargetConstant(Value, MVT::i64);
138 }]>;
139
140 // Bits 32-47 (counting from the lsb).
141 def HL16 : SDNodeXForm<imm, [{
142   uint64_t Value = (N->getZExtValue() & 0x0000FFFF00000000ULL) >> 32;
143   return CurDAG->getTargetConstant(Value, MVT::i64);
144 }]>;
145
146 // Bits 48-63 (counting from the lsb).
147 def HH16 : SDNodeXForm<imm, [{
148   uint64_t Value = (N->getZExtValue() & 0xFFFF000000000000ULL) >> 48;
149   return CurDAG->getTargetConstant(Value, MVT::i64);
150 }]>;
151
152 // Low 32 bits.
153 def LF32 : SDNodeXForm<imm, [{
154   uint64_t Value = N->getZExtValue() & 0x00000000FFFFFFFFULL;
155   return CurDAG->getTargetConstant(Value, MVT::i64);
156 }]>;
157
158 // High 32 bits.
159 def HF32 : SDNodeXForm<imm, [{
160   uint64_t Value = N->getZExtValue() >> 32;
161   return CurDAG->getTargetConstant(Value, MVT::i64);
162 }]>;
163
164 // Truncate an immediate to a 8-bit signed quantity.
165 def SIMM8 : SDNodeXForm<imm, [{
166   return CurDAG->getTargetConstant(int8_t(N->getZExtValue()), MVT::i64);
167 }]>;
168
169 // Truncate an immediate to a 8-bit unsigned quantity.
170 def UIMM8 : SDNodeXForm<imm, [{
171   return CurDAG->getTargetConstant(uint8_t(N->getZExtValue()), MVT::i64);
172 }]>;
173
174 // Truncate an immediate to a 16-bit signed quantity.
175 def SIMM16 : SDNodeXForm<imm, [{
176   return CurDAG->getTargetConstant(int16_t(N->getZExtValue()), MVT::i64);
177 }]>;
178
179 // Truncate an immediate to a 16-bit unsigned quantity.
180 def UIMM16 : SDNodeXForm<imm, [{
181   return CurDAG->getTargetConstant(uint16_t(N->getZExtValue()), MVT::i64);
182 }]>;
183
184 // Truncate an immediate to a 32-bit signed quantity.
185 def SIMM32 : SDNodeXForm<imm, [{
186   return CurDAG->getTargetConstant(int32_t(N->getZExtValue()), MVT::i64);
187 }]>;
188
189 // Truncate an immediate to a 32-bit unsigned quantity.
190 def UIMM32 : SDNodeXForm<imm, [{
191   return CurDAG->getTargetConstant(uint32_t(N->getZExtValue()), MVT::i64);
192 }]>;
193
194 // Negate and then truncate an immediate to a 32-bit unsigned quantity.
195 def NEGIMM32 : SDNodeXForm<imm, [{
196   return CurDAG->getTargetConstant(uint32_t(-N->getZExtValue()), MVT::i64);
197 }]>;
198
199 //===----------------------------------------------------------------------===//
200 // Immediate asm operands.
201 //===----------------------------------------------------------------------===//
202
203 def U4Imm  : ImmediateAsmOperand<"U4Imm">;
204 def U6Imm  : ImmediateAsmOperand<"U6Imm">;
205 def S8Imm  : ImmediateAsmOperand<"S8Imm">;
206 def U8Imm  : ImmediateAsmOperand<"U8Imm">;
207 def S16Imm : ImmediateAsmOperand<"S16Imm">;
208 def U16Imm : ImmediateAsmOperand<"U16Imm">;
209 def S32Imm : ImmediateAsmOperand<"S32Imm">;
210 def U32Imm : ImmediateAsmOperand<"U32Imm">;
211
212 //===----------------------------------------------------------------------===//
213 // 8-bit immediates
214 //===----------------------------------------------------------------------===//
215
216 def uimm8zx4 : Immediate<i8, [{
217   return isUInt<4>(N->getZExtValue());
218 }], NOOP_SDNodeXForm, "U4Imm">;
219
220 def uimm8zx6 : Immediate<i8, [{
221   return isUInt<6>(N->getZExtValue());
222 }], NOOP_SDNodeXForm, "U6Imm">;
223
224 def simm8    : Immediate<i8, [{}], SIMM8, "S8Imm">;
225 def uimm8    : Immediate<i8, [{}], UIMM8, "U8Imm">;
226
227 //===----------------------------------------------------------------------===//
228 // i32 immediates
229 //===----------------------------------------------------------------------===//
230
231 // Immediates for 8-bit lengths.
232 def imm32len8 : Immediate<i32, [{
233   return isUInt<8>(N->getZExtValue() - 1);
234 }], NOOP_SDNodeXForm, "U32Imm">;
235
236 // Immediates for the lower and upper 16 bits of an i32, with the other
237 // bits of the i32 being zero.
238 def imm32ll16 : Immediate<i32, [{
239   return SystemZ::isImmLL(N->getZExtValue());
240 }], LL16, "U16Imm">;
241
242 def imm32lh16 : Immediate<i32, [{
243   return SystemZ::isImmLH(N->getZExtValue());
244 }], LH16, "U16Imm">;
245
246 // Immediates for the lower and upper 16 bits of an i32, with the other
247 // bits of the i32 being one.
248 def imm32ll16c : Immediate<i32, [{
249   return SystemZ::isImmLL(uint32_t(~N->getZExtValue()));
250 }], LL16, "U16Imm">;
251
252 def imm32lh16c : Immediate<i32, [{
253   return SystemZ::isImmLH(uint32_t(~N->getZExtValue()));
254 }], LH16, "U16Imm">;
255
256 // Short immediates
257 def imm32sx8 : Immediate<i32, [{
258   return isInt<8>(N->getSExtValue());
259 }], SIMM8, "S8Imm">;
260
261 def imm32zx8 : Immediate<i32, [{
262   return isUInt<8>(N->getZExtValue());
263 }], UIMM8, "U8Imm">;
264
265 def imm32zx8trunc : Immediate<i32, [{}], UIMM8, "U8Imm">;
266
267 def imm32sx16 : Immediate<i32, [{
268   return isInt<16>(N->getSExtValue());
269 }], SIMM16, "S16Imm">;
270
271 def imm32zx16 : Immediate<i32, [{
272   return isUInt<16>(N->getZExtValue());
273 }], UIMM16, "U16Imm">;
274
275 def imm32sx16trunc : Immediate<i32, [{}], SIMM16, "S16Imm">;
276
277 // Full 32-bit immediates.  we need both signed and unsigned versions
278 // because the assembler is picky.  E.g. AFI requires signed operands
279 // while NILF requires unsigned ones.
280 def simm32 : Immediate<i32, [{}], SIMM32, "S32Imm">;
281 def uimm32 : Immediate<i32, [{}], UIMM32, "U32Imm">;
282
283 def imm32 : ImmLeaf<i32, [{}]>;
284
285 //===----------------------------------------------------------------------===//
286 // 64-bit immediates
287 //===----------------------------------------------------------------------===//
288
289 // Immediates for 16-bit chunks of an i64, with the other bits of the
290 // i32 being zero.
291 def imm64ll16 : Immediate<i64, [{
292   return SystemZ::isImmLL(N->getZExtValue());
293 }], LL16, "U16Imm">;
294
295 def imm64lh16 : Immediate<i64, [{
296   return SystemZ::isImmLH(N->getZExtValue());
297 }], LH16, "U16Imm">;
298
299 def imm64hl16 : Immediate<i64, [{
300   return SystemZ::isImmHL(N->getZExtValue());
301 }], HL16, "U16Imm">;
302
303 def imm64hh16 : Immediate<i64, [{
304   return SystemZ::isImmHH(N->getZExtValue());
305 }], HH16, "U16Imm">;
306
307 // Immediates for 16-bit chunks of an i64, with the other bits of the
308 // i32 being one.
309 def imm64ll16c : Immediate<i64, [{
310   return SystemZ::isImmLL(uint64_t(~N->getZExtValue()));
311 }], LL16, "U16Imm">;
312
313 def imm64lh16c : Immediate<i64, [{
314   return SystemZ::isImmLH(uint64_t(~N->getZExtValue()));
315 }], LH16, "U16Imm">;
316
317 def imm64hl16c : Immediate<i64, [{
318   return SystemZ::isImmHL(uint64_t(~N->getZExtValue()));
319 }], HL16, "U16Imm">;
320
321 def imm64hh16c : Immediate<i64, [{
322   return SystemZ::isImmHH(uint64_t(~N->getZExtValue()));
323 }], HH16, "U16Imm">;
324
325 // Immediates for the lower and upper 32 bits of an i64, with the other
326 // bits of the i32 being zero.
327 def imm64lf32 : Immediate<i64, [{
328   return SystemZ::isImmLF(N->getZExtValue());
329 }], LF32, "U32Imm">;
330
331 def imm64hf32 : Immediate<i64, [{
332   return SystemZ::isImmHF(N->getZExtValue());
333 }], HF32, "U32Imm">;
334
335 // Immediates for the lower and upper 32 bits of an i64, with the other
336 // bits of the i32 being one.
337 def imm64lf32c : Immediate<i64, [{
338   return SystemZ::isImmLF(uint64_t(~N->getZExtValue()));
339 }], LF32, "U32Imm">;
340
341 def imm64hf32c : Immediate<i64, [{
342   return SystemZ::isImmHF(uint64_t(~N->getZExtValue()));
343 }], HF32, "U32Imm">;
344
345 // Short immediates.
346 def imm64sx8 : Immediate<i64, [{
347   return isInt<8>(N->getSExtValue());
348 }], SIMM8, "S8Imm">;
349
350 def imm64sx16 : Immediate<i64, [{
351   return isInt<16>(N->getSExtValue());
352 }], SIMM16, "S16Imm">;
353
354 def imm64zx16 : Immediate<i64, [{
355   return isUInt<16>(N->getZExtValue());
356 }], UIMM16, "U16Imm">;
357
358 def imm64sx32 : Immediate<i64, [{
359   return isInt<32>(N->getSExtValue());
360 }], SIMM32, "S32Imm">;
361
362 def imm64zx32 : Immediate<i64, [{
363   return isUInt<32>(N->getZExtValue());
364 }], UIMM32, "U32Imm">;
365
366 def imm64zx32n : Immediate<i64, [{
367   return isUInt<32>(-N->getSExtValue());
368 }], NEGIMM32, "U32Imm">;
369
370 def imm64 : ImmLeaf<i64, [{}]>;
371
372 //===----------------------------------------------------------------------===//
373 // Floating-point immediates
374 //===----------------------------------------------------------------------===//
375
376 // Floating-point zero.
377 def fpimm0 : PatLeaf<(fpimm), [{ return N->isExactlyValue(+0.0); }]>;
378
379 // Floating point negative zero.
380 def fpimmneg0 : PatLeaf<(fpimm), [{ return N->isExactlyValue(-0.0); }]>;
381
382 //===----------------------------------------------------------------------===//
383 // Symbolic address operands
384 //===----------------------------------------------------------------------===//
385
386 // PC-relative asm operands.
387 def PCRel16 : PCRelAsmOperand<"16">;
388 def PCRel32 : PCRelAsmOperand<"32">;
389
390 // PC-relative offsets of a basic block.  The offset is sign-extended
391 // and multiplied by 2.
392 def brtarget16 : PCRelOperand<OtherVT, PCRel16> {
393   let EncoderMethod = "getPC16DBLEncoding";
394   let DecoderMethod = "decodePC16DBLOperand";
395 }
396 def brtarget32 : PCRelOperand<OtherVT, PCRel32> {
397   let EncoderMethod = "getPC32DBLEncoding";
398   let DecoderMethod = "decodePC32DBLOperand";
399 }
400
401 // A PC-relative offset of a global value.  The offset is sign-extended
402 // and multiplied by 2.
403 def pcrel32 : PCRelAddress<i64, "pcrel32", PCRel32> {
404   let EncoderMethod = "getPC32DBLEncoding";
405   let DecoderMethod = "decodePC32DBLOperand";
406 }
407
408 // A PC-relative offset of a global value when the value is used as a
409 // call target.  The offset is sign-extended and multiplied by 2.
410 def pcrel16call : PCRelAddress<i64, "pcrel16call", PCRel16> {
411   let PrintMethod = "printCallOperand";
412   let EncoderMethod = "getPLT16DBLEncoding";
413   let DecoderMethod = "decodePC16DBLOperand";
414 }
415 def pcrel32call : PCRelAddress<i64, "pcrel32call", PCRel32> {
416   let PrintMethod = "printCallOperand";
417   let EncoderMethod = "getPLT32DBLEncoding";
418   let DecoderMethod = "decodePC32DBLOperand";
419 }
420
421 //===----------------------------------------------------------------------===//
422 // Addressing modes
423 //===----------------------------------------------------------------------===//
424
425 // 12-bit displacement operands.
426 def disp12imm32 : Operand<i32>;
427 def disp12imm64 : Operand<i64>;
428
429 // 20-bit displacement operands.
430 def disp20imm32 : Operand<i32>;
431 def disp20imm64 : Operand<i64>;
432
433 def BDAddr32Disp12      : AddressAsmOperand<"BDAddr",   "32", "12">;
434 def BDAddr32Disp20      : AddressAsmOperand<"BDAddr",   "32", "20">;
435 def BDAddr64Disp12      : AddressAsmOperand<"BDAddr",   "64", "12">;
436 def BDAddr64Disp20      : AddressAsmOperand<"BDAddr",   "64", "20">;
437 def BDXAddr64Disp12     : AddressAsmOperand<"BDXAddr",  "64", "12">;
438 def BDXAddr64Disp20     : AddressAsmOperand<"BDXAddr",  "64", "20">;
439 def BDLAddr64Disp12Len8 : AddressAsmOperand<"BDLAddr",  "64", "12", "Len8">;
440
441 // DAG patterns and operands for addressing modes.  Each mode has
442 // the form <type><range><group>[<len>] where:
443 //
444 // <type> is one of:
445 //   shift    : base + displacement (32-bit)
446 //   bdaddr   : base + displacement
447 //   bdxaddr  : base + displacement + index
448 //   laaddr   : like bdxaddr, but used for Load Address operations
449 //   dynalloc : base + displacement + index + ADJDYNALLOC
450 //   bdladdr  : base + displacement with a length field
451 //
452 // <range> is one of:
453 //   12       : the displacement is an unsigned 12-bit value
454 //   20       : the displacement is a signed 20-bit value
455 //
456 // <group> is one of:
457 //   pair     : used when there is an equivalent instruction with the opposite
458 //              range value (12 or 20)
459 //   only     : used when there is no equivalent instruction with the opposite
460 //              range value
461 //
462 // <len> is one of:
463 //
464 //   <empty>  : there is no length field
465 //   len8     : the length field is 8 bits, with a range of [1, 0x100].
466 def shift12only       : BDMode <"BDAddr",   "32", "12", "Only">;
467 def shift20only       : BDMode <"BDAddr",   "32", "20", "Only">;
468 def bdaddr12only      : BDMode <"BDAddr",   "64", "12", "Only">;
469 def bdaddr12pair      : BDMode <"BDAddr",   "64", "12", "Pair">;
470 def bdaddr20only      : BDMode <"BDAddr",   "64", "20", "Only">;
471 def bdaddr20pair      : BDMode <"BDAddr",   "64", "20", "Pair">;
472 def bdxaddr12only     : BDXMode<"BDXAddr",  "64", "12", "Only">;
473 def bdxaddr12pair     : BDXMode<"BDXAddr",  "64", "12", "Pair">;
474 def bdxaddr20only     : BDXMode<"BDXAddr",  "64", "20", "Only">;
475 def bdxaddr20only128  : BDXMode<"BDXAddr",  "64", "20", "Only128">;
476 def bdxaddr20pair     : BDXMode<"BDXAddr",  "64", "20", "Pair">;
477 def dynalloc12only    : BDXMode<"DynAlloc", "64", "12", "Only">;
478 def laaddr12pair      : BDXMode<"LAAddr",   "64", "12", "Pair">;
479 def laaddr20pair      : BDXMode<"LAAddr",   "64", "20", "Pair">;
480 def bdladdr12onlylen8 : BDLMode<"BDLAddr",  "64", "12", "Only", "8">;
481
482 //===----------------------------------------------------------------------===//
483 // Miscellaneous
484 //===----------------------------------------------------------------------===//
485
486 // Access registers.  At present we just use them for accessing the thread
487 // pointer, so we don't expose them as register to LLVM.
488 def AccessReg : AsmOperandClass {
489   let Name = "AccessReg";
490   let ParserMethod = "parseAccessReg";
491 }
492 def access_reg : Immediate<i8, [{ return N->getZExtValue() < 16; }],
493                            NOOP_SDNodeXForm, "AccessReg"> {
494   let ParserMatchClass = AccessReg;
495 }
496
497 // A 4-bit condition-code mask.
498 def cond4 : PatLeaf<(i8 imm), [{ return (N->getZExtValue() < 16); }]>,
499             Operand<i8> {
500   let PrintMethod = "printCond4Operand";
501 }