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