blob: 0abc3f7517e03d6c0ec969b2462676bf625574b6 [file] [log] [blame]
Ulrich Weigand5f613df2013-05-06 16:15:19 +00001//===-- 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
14class 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.
24class 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 ParserMatchClass = !cast<AsmOperandClass>(asmop);
28}
29
30// Constructs both a DAG pattern and instruction operand for a PC-relative
31// address with address size VT. SELF is the name of the operand.
32class PCRelAddress<ValueType vt, string self>
33 : ComplexPattern<vt, 1, "selectPCRelAddress", [z_pcrel_wrapper]>,
34 Operand<vt> {
35 let MIOperandInfo = (ops !cast<Operand>(self));
36}
37
38// Constructs an AsmOperandClass for addressing mode FORMAT, treating the
39// registers as having BITSIZE bits and displacements as having DISPSIZE bits.
40class AddressAsmOperand<string format, string bitsize, string dispsize>
41 : AsmOperandClass {
42 let Name = format##bitsize##"Disp"##dispsize;
43 let ParserMethod = "parse"##format##bitsize;
44 let RenderMethod = "add"##format##"Operands";
45}
46
47// Constructs both a DAG pattern and instruction operand for an addressing mode.
48// The mode is selected by custom code in selectTYPE...SUFFIX(). The address
49// registers have BITSIZE bits and displacements have DISPSIZE bits. NUMOPS is
50// the number of operands that make up an address and OPERANDS lists the types
51// of those operands using (ops ...). FORMAT is the type of addressing mode,
52// which needs to match the names used in AddressAsmOperand.
53class AddressingMode<string type, string bitsize, string dispsize,
54 string suffix, int numops, string format, dag operands>
55 : ComplexPattern<!cast<ValueType>("i"##bitsize), numops,
56 "select"##type##dispsize##suffix,
57 [add, sub, or, frameindex, z_adjdynalloc]>,
58 Operand<!cast<ValueType>("i"##bitsize)> {
59 let PrintMethod = "print"##format##"Operand";
60 let MIOperandInfo = operands;
61 let ParserMatchClass =
62 !cast<AddressAsmOperand>(format##bitsize##"Disp"##dispsize);
63}
64
65// An addressing mode with a base and displacement but no index.
66class BDMode<string type, string bitsize, string dispsize, string suffix>
67 : AddressingMode<type, bitsize, dispsize, suffix, 2, "BDAddr",
68 (ops !cast<RegisterOperand>("ADDR"##bitsize),
69 !cast<Immediate>("disp"##dispsize##"imm"##bitsize))>;
70
71// An addressing mode with a base, displacement and index.
72class BDXMode<string type, string bitsize, string dispsize, string suffix>
73 : AddressingMode<type, bitsize, dispsize, suffix, 3, "BDXAddr",
74 (ops !cast<RegisterOperand>("ADDR"##bitsize),
75 !cast<Immediate>("disp"##dispsize##"imm"##bitsize),
76 !cast<RegisterOperand>("ADDR"##bitsize))>;
77
78//===----------------------------------------------------------------------===//
79// Extracting immediate operands from nodes
80// These all create MVT::i64 nodes to ensure the value is not sign-extended
81// when converted from an SDNode to a MachineOperand later on.
82//===----------------------------------------------------------------------===//
83
84// Bits 0-15 (counting from the lsb).
85def LL16 : SDNodeXForm<imm, [{
86 uint64_t Value = N->getZExtValue() & 0x000000000000FFFFULL;
87 return CurDAG->getTargetConstant(Value, MVT::i64);
88}]>;
89
90// Bits 16-31 (counting from the lsb).
91def LH16 : SDNodeXForm<imm, [{
92 uint64_t Value = (N->getZExtValue() & 0x00000000FFFF0000ULL) >> 16;
93 return CurDAG->getTargetConstant(Value, MVT::i64);
94}]>;
95
96// Bits 32-47 (counting from the lsb).
97def HL16 : SDNodeXForm<imm, [{
98 uint64_t Value = (N->getZExtValue() & 0x0000FFFF00000000ULL) >> 32;
99 return CurDAG->getTargetConstant(Value, MVT::i64);
100}]>;
101
102// Bits 48-63 (counting from the lsb).
103def HH16 : SDNodeXForm<imm, [{
104 uint64_t Value = (N->getZExtValue() & 0xFFFF000000000000ULL) >> 48;
105 return CurDAG->getTargetConstant(Value, MVT::i64);
106}]>;
107
108// Low 32 bits.
109def LF32 : SDNodeXForm<imm, [{
110 uint64_t Value = N->getZExtValue() & 0x00000000FFFFFFFFULL;
111 return CurDAG->getTargetConstant(Value, MVT::i64);
112}]>;
113
114// High 32 bits.
115def HF32 : SDNodeXForm<imm, [{
116 uint64_t Value = N->getZExtValue() >> 32;
117 return CurDAG->getTargetConstant(Value, MVT::i64);
118}]>;
119
120// Truncate an immediate to a 8-bit signed quantity.
121def SIMM8 : SDNodeXForm<imm, [{
122 return CurDAG->getTargetConstant(int8_t(N->getZExtValue()), MVT::i64);
123}]>;
124
125// Truncate an immediate to a 8-bit unsigned quantity.
126def UIMM8 : SDNodeXForm<imm, [{
127 return CurDAG->getTargetConstant(uint8_t(N->getZExtValue()), MVT::i64);
128}]>;
129
130// Truncate an immediate to a 16-bit signed quantity.
131def SIMM16 : SDNodeXForm<imm, [{
132 return CurDAG->getTargetConstant(int16_t(N->getZExtValue()), MVT::i64);
133}]>;
134
135// Truncate an immediate to a 16-bit unsigned quantity.
136def UIMM16 : SDNodeXForm<imm, [{
137 return CurDAG->getTargetConstant(uint16_t(N->getZExtValue()), MVT::i64);
138}]>;
139
140// Truncate an immediate to a 32-bit signed quantity.
141def SIMM32 : SDNodeXForm<imm, [{
142 return CurDAG->getTargetConstant(int32_t(N->getZExtValue()), MVT::i64);
143}]>;
144
145// Truncate an immediate to a 32-bit unsigned quantity.
146def UIMM32 : SDNodeXForm<imm, [{
147 return CurDAG->getTargetConstant(uint32_t(N->getZExtValue()), MVT::i64);
148}]>;
149
150// Negate and then truncate an immediate to a 32-bit unsigned quantity.
151def NEGIMM32 : SDNodeXForm<imm, [{
152 return CurDAG->getTargetConstant(uint32_t(-N->getZExtValue()), MVT::i64);
153}]>;
154
155//===----------------------------------------------------------------------===//
156// Immediate asm operands.
157//===----------------------------------------------------------------------===//
158
159def U4Imm : ImmediateAsmOperand<"U4Imm">;
160def U6Imm : ImmediateAsmOperand<"U6Imm">;
161def S8Imm : ImmediateAsmOperand<"S8Imm">;
162def U8Imm : ImmediateAsmOperand<"U8Imm">;
163def S16Imm : ImmediateAsmOperand<"S16Imm">;
164def U16Imm : ImmediateAsmOperand<"U16Imm">;
165def S32Imm : ImmediateAsmOperand<"S32Imm">;
166def U32Imm : ImmediateAsmOperand<"U32Imm">;
167
168//===----------------------------------------------------------------------===//
169// 8-bit immediates
170//===----------------------------------------------------------------------===//
171
172def uimm8zx4 : Immediate<i8, [{
173 return isUInt<4>(N->getZExtValue());
174}], NOOP_SDNodeXForm, "U4Imm">;
175
176def uimm8zx6 : Immediate<i8, [{
177 return isUInt<6>(N->getZExtValue());
178}], NOOP_SDNodeXForm, "U6Imm">;
179
180def simm8 : Immediate<i8, [{}], SIMM8, "S8Imm">;
181def uimm8 : Immediate<i8, [{}], UIMM8, "U8Imm">;
182
183//===----------------------------------------------------------------------===//
184// i32 immediates
185//===----------------------------------------------------------------------===//
186
187// Immediates for the lower and upper 16 bits of an i32, with the other
188// bits of the i32 being zero.
189def imm32ll16 : Immediate<i32, [{
190 return SystemZ::isImmLL(N->getZExtValue());
191}], LL16, "U16Imm">;
192
193def imm32lh16 : Immediate<i32, [{
194 return SystemZ::isImmLH(N->getZExtValue());
195}], LH16, "U16Imm">;
196
197// Immediates for the lower and upper 16 bits of an i32, with the other
198// bits of the i32 being one.
199def imm32ll16c : Immediate<i32, [{
200 return SystemZ::isImmLL(uint32_t(~N->getZExtValue()));
201}], LL16, "U16Imm">;
202
203def imm32lh16c : Immediate<i32, [{
204 return SystemZ::isImmLH(uint32_t(~N->getZExtValue()));
205}], LH16, "U16Imm">;
206
207// Short immediates
208def imm32sx8 : Immediate<i32, [{
209 return isInt<8>(N->getSExtValue());
210}], SIMM8, "S8Imm">;
211
212def imm32zx8 : Immediate<i32, [{
213 return isUInt<8>(N->getZExtValue());
214}], UIMM8, "U8Imm">;
215
216def imm32zx8trunc : Immediate<i32, [{}], UIMM8, "U8Imm">;
217
218def imm32sx16 : Immediate<i32, [{
219 return isInt<16>(N->getSExtValue());
220}], SIMM16, "S16Imm">;
221
222def imm32zx16 : Immediate<i32, [{
223 return isUInt<16>(N->getZExtValue());
224}], UIMM16, "U16Imm">;
225
226def imm32sx16trunc : Immediate<i32, [{}], SIMM16, "S16Imm">;
227
228// Full 32-bit immediates. we need both signed and unsigned versions
229// because the assembler is picky. E.g. AFI requires signed operands
230// while NILF requires unsigned ones.
231def simm32 : Immediate<i32, [{}], SIMM32, "S32Imm">;
232def uimm32 : Immediate<i32, [{}], UIMM32, "U32Imm">;
233
234def imm32 : ImmLeaf<i32, [{}]>;
235
236//===----------------------------------------------------------------------===//
237// 64-bit immediates
238//===----------------------------------------------------------------------===//
239
240// Immediates for 16-bit chunks of an i64, with the other bits of the
241// i32 being zero.
242def imm64ll16 : Immediate<i64, [{
243 return SystemZ::isImmLL(N->getZExtValue());
244}], LL16, "U16Imm">;
245
246def imm64lh16 : Immediate<i64, [{
247 return SystemZ::isImmLH(N->getZExtValue());
248}], LH16, "U16Imm">;
249
250def imm64hl16 : Immediate<i64, [{
251 return SystemZ::isImmHL(N->getZExtValue());
252}], HL16, "U16Imm">;
253
254def imm64hh16 : Immediate<i64, [{
255 return SystemZ::isImmHH(N->getZExtValue());
256}], HH16, "U16Imm">;
257
258// Immediates for 16-bit chunks of an i64, with the other bits of the
259// i32 being one.
260def imm64ll16c : Immediate<i64, [{
261 return SystemZ::isImmLL(uint64_t(~N->getZExtValue()));
262}], LL16, "U16Imm">;
263
264def imm64lh16c : Immediate<i64, [{
265 return SystemZ::isImmLH(uint64_t(~N->getZExtValue()));
266}], LH16, "U16Imm">;
267
268def imm64hl16c : Immediate<i64, [{
269 return SystemZ::isImmHL(uint64_t(~N->getZExtValue()));
270}], HL16, "U16Imm">;
271
272def imm64hh16c : Immediate<i64, [{
273 return SystemZ::isImmHH(uint64_t(~N->getZExtValue()));
274}], HH16, "U16Imm">;
275
276// Immediates for the lower and upper 32 bits of an i64, with the other
277// bits of the i32 being zero.
278def imm64lf32 : Immediate<i64, [{
279 return SystemZ::isImmLF(N->getZExtValue());
280}], LF32, "U32Imm">;
281
282def imm64hf32 : Immediate<i64, [{
283 return SystemZ::isImmHF(N->getZExtValue());
284}], HF32, "U32Imm">;
285
286// Immediates for the lower and upper 32 bits of an i64, with the other
287// bits of the i32 being one.
288def imm64lf32c : Immediate<i64, [{
289 return SystemZ::isImmLF(uint64_t(~N->getZExtValue()));
290}], LF32, "U32Imm">;
291
292def imm64hf32c : Immediate<i64, [{
293 return SystemZ::isImmHF(uint64_t(~N->getZExtValue()));
294}], HF32, "U32Imm">;
295
296// Short immediates.
297def imm64sx8 : Immediate<i64, [{
298 return isInt<8>(N->getSExtValue());
299}], SIMM8, "S8Imm">;
300
301def imm64sx16 : Immediate<i64, [{
302 return isInt<16>(N->getSExtValue());
303}], SIMM16, "S16Imm">;
304
305def imm64zx16 : Immediate<i64, [{
306 return isUInt<16>(N->getZExtValue());
307}], UIMM16, "U16Imm">;
308
309def imm64sx32 : Immediate<i64, [{
310 return isInt<32>(N->getSExtValue());
311}], SIMM32, "S32Imm">;
312
313def imm64zx32 : Immediate<i64, [{
314 return isUInt<32>(N->getZExtValue());
315}], UIMM32, "U32Imm">;
316
317def imm64zx32n : Immediate<i64, [{
318 return isUInt<32>(-N->getSExtValue());
319}], NEGIMM32, "U32Imm">;
320
321def imm64 : ImmLeaf<i64, [{}]>;
322
323//===----------------------------------------------------------------------===//
324// Floating-point immediates
325//===----------------------------------------------------------------------===//
326
327// Floating-point zero.
328def fpimm0 : PatLeaf<(fpimm), [{ return N->isExactlyValue(+0.0); }]>;
329
330// Floating point negative zero.
331def fpimmneg0 : PatLeaf<(fpimm), [{ return N->isExactlyValue(-0.0); }]>;
332
333//===----------------------------------------------------------------------===//
334// Symbolic address operands
335//===----------------------------------------------------------------------===//
336
337// PC-relative offsets of a basic block. The offset is sign-extended
338// and multiplied by 2.
339def brtarget16 : Operand<OtherVT> {
340 let EncoderMethod = "getPC16DBLEncoding";
341}
342def brtarget32 : Operand<OtherVT> {
343 let EncoderMethod = "getPC32DBLEncoding";
344}
345
346// A PC-relative offset of a global value. The offset is sign-extended
347// and multiplied by 2.
348def pcrel32 : PCRelAddress<i64, "pcrel32"> {
349 let EncoderMethod = "getPC32DBLEncoding";
350}
351
352// A PC-relative offset of a global value when the value is used as a
353// call target. The offset is sign-extended and multiplied by 2.
354def pcrel16call : PCRelAddress<i64, "pcrel16call"> {
355 let PrintMethod = "printCallOperand";
356 let EncoderMethod = "getPLT16DBLEncoding";
357}
358def pcrel32call : PCRelAddress<i64, "pcrel32call"> {
359 let PrintMethod = "printCallOperand";
360 let EncoderMethod = "getPLT32DBLEncoding";
361}
362
363//===----------------------------------------------------------------------===//
364// Addressing modes
365//===----------------------------------------------------------------------===//
366
367// 12-bit displacement operands.
368def disp12imm32 : Operand<i32>;
369def disp12imm64 : Operand<i64>;
370
371// 20-bit displacement operands.
372def disp20imm32 : Operand<i32>;
373def disp20imm64 : Operand<i64>;
374
375def BDAddr32Disp12 : AddressAsmOperand<"BDAddr", "32", "12">;
376def BDAddr32Disp20 : AddressAsmOperand<"BDAddr", "32", "20">;
377def BDAddr64Disp12 : AddressAsmOperand<"BDAddr", "64", "12">;
378def BDAddr64Disp20 : AddressAsmOperand<"BDAddr", "64", "20">;
379def BDXAddr64Disp12 : AddressAsmOperand<"BDXAddr", "64", "12">;
380def BDXAddr64Disp20 : AddressAsmOperand<"BDXAddr", "64", "20">;
381
382// DAG patterns and operands for addressing modes. Each mode has
383// the form <type><range><group> where:
384//
385// <type> is one of:
386// shift : base + displacement (32-bit)
387// bdaddr : base + displacement
388// bdxaddr : base + displacement + index
389// laaddr : like bdxaddr, but used for Load Address operations
390// dynalloc : base + displacement + index + ADJDYNALLOC
391//
392// <range> is one of:
393// 12 : the displacement is an unsigned 12-bit value
394// 20 : the displacement is a signed 20-bit value
395//
396// <group> is one of:
397// pair : used when there is an equivalent instruction with the opposite
398// range value (12 or 20)
399// only : used when there is no equivalent instruction with the opposite
400// range value
401def shift12only : BDMode <"BDAddr", "32", "12", "Only">;
402def shift20only : BDMode <"BDAddr", "32", "20", "Only">;
403def bdaddr12only : BDMode <"BDAddr", "64", "12", "Only">;
404def bdaddr12pair : BDMode <"BDAddr", "64", "12", "Pair">;
405def bdaddr20only : BDMode <"BDAddr", "64", "20", "Only">;
406def bdaddr20pair : BDMode <"BDAddr", "64", "20", "Pair">;
407def bdxaddr12only : BDXMode<"BDXAddr", "64", "12", "Only">;
408def bdxaddr12pair : BDXMode<"BDXAddr", "64", "12", "Pair">;
409def bdxaddr20only : BDXMode<"BDXAddr", "64", "20", "Only">;
410def bdxaddr20only128 : BDXMode<"BDXAddr", "64", "20", "Only128">;
411def bdxaddr20pair : BDXMode<"BDXAddr", "64", "20", "Pair">;
412def dynalloc12only : BDXMode<"DynAlloc", "64", "12", "Only">;
413def laaddr12pair : BDXMode<"LAAddr", "64", "12", "Pair">;
414def laaddr20pair : BDXMode<"LAAddr", "64", "20", "Pair">;
415
416//===----------------------------------------------------------------------===//
417// Miscellaneous
418//===----------------------------------------------------------------------===//
419
420// Access registers. At present we just use them for accessing the thread
421// pointer, so we don't expose them as register to LLVM.
422def AccessReg : AsmOperandClass {
423 let Name = "AccessReg";
424 let ParserMethod = "parseAccessReg";
425}
426def access_reg : Immediate<i8, [{ return N->getZExtValue() < 16; }],
427 NOOP_SDNodeXForm, "AccessReg"> {
428 let ParserMatchClass = AccessReg;
429}
430
431// A 4-bit condition-code mask.
432def cond4 : PatLeaf<(i8 imm), [{ return (N->getZExtValue() < 16); }]>,
433 Operand<i8> {
434 let PrintMethod = "printCond4Operand";
435}