xref: /freebsd/contrib/llvm-project/llvm/lib/Target/SystemZ/SystemZOperands.td (revision ece7a5e9849032f4a31e725714c2db89d055b706)
1//===-- SystemZOperands.td - SystemZ instruction operands ----*- tblgen-*--===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9//===----------------------------------------------------------------------===//
10// Class definitions
11//===----------------------------------------------------------------------===//
12
13class ImmediateAsmOperand<string name>
14  : AsmOperandClass {
15  let Name = name;
16  let RenderMethod = "addImmOperands";
17}
18class ImmediateTLSAsmOperand<string name>
19  : AsmOperandClass {
20  let Name = name;
21  let RenderMethod = "addImmTLSOperands";
22}
23
24// Constructs both a DAG pattern and instruction operand for an immediate
25// of type VT.  PRED returns true if a node is acceptable and XFORM returns
26// the operand value associated with the node.  ASMOP is the name of the
27// associated asm operand, and also forms the basis of the asm print method.
28class Immediate<ValueType vt, code pred, SDNodeXForm xform, string asmop>
29  : PatLeaf<(vt imm), pred, xform>, Operand<vt> {
30  let PrintMethod = "print"##asmop##"Operand";
31  let DecoderMethod = "decode"##asmop##"Operand";
32  let ParserMatchClass = !cast<AsmOperandClass>(asmop);
33}
34
35// Constructs an asm operand for a PC-relative address.  SIZE says how
36// many bits there are.
37class PCRelAsmOperand<string size> : ImmediateAsmOperand<"PCRel"##size> {
38  let PredicateMethod = "isImm";
39  let ParserMethod = "parsePCRel"##size;
40}
41class PCRelTLSAsmOperand<string size>
42  : ImmediateTLSAsmOperand<"PCRelTLS"##size> {
43  let PredicateMethod = "isImmTLS";
44  let ParserMethod = "parsePCRelTLS"##size;
45}
46
47// Constructs an operand for a PC-relative address with address type VT.
48// ASMOP is the associated asm operand.
49class PCRelOperand<ValueType vt, AsmOperandClass asmop> : Operand<vt> {
50  let PrintMethod = "printPCRelOperand";
51  let ParserMatchClass = asmop;
52}
53class PCRelTLSOperand<ValueType vt, AsmOperandClass asmop> : Operand<vt> {
54  let PrintMethod = "printPCRelTLSOperand";
55  let ParserMatchClass = asmop;
56}
57
58// Constructs both a DAG pattern and instruction operand for a PC-relative
59// address with address size VT.  SELF is the name of the operand and
60// ASMOP is the associated asm operand.
61class PCRelAddress<ValueType vt, string self, AsmOperandClass asmop>
62  : ComplexPattern<vt, 1, "selectPCRelAddress",
63                   [z_pcrel_wrapper, z_pcrel_offset]>,
64    PCRelOperand<vt, asmop> {
65  let MIOperandInfo = (ops !cast<Operand>(self));
66}
67
68// Constructs an AsmOperandClass for addressing mode FORMAT, treating the
69// registers as having BITSIZE bits and displacements as having DISPSIZE bits.
70// LENGTH is "LenN" for addresses with an N-bit length field, otherwise it
71// is "".
72class AddressAsmOperand<string format, string bitsize, string dispsize,
73                        string length = "">
74  : AsmOperandClass {
75  let Name = format##bitsize##"Disp"##dispsize##length;
76  let ParserMethod = "parse"##format##bitsize;
77  let RenderMethod = "add"##format##"Operands";
78}
79
80// Constructs an instruction operand for an addressing mode.  FORMAT,
81// BITSIZE, DISPSIZE and LENGTH are the parameters to an associated
82// AddressAsmOperand.  OPERANDS is a list of individual operands
83// (base register, displacement, etc.).
84class AddressOperand<string bitsize, string dispsize, string length,
85                     string format, dag operands>
86  : Operand<!cast<ValueType>("i"##bitsize)> {
87  let PrintMethod = "print"##format##"Operand";
88  let EncoderMethod = "get"##format##dispsize##length##"Encoding";
89  let DecoderMethod =
90    "decode"##format##bitsize##"Disp"##dispsize##length##"Operand";
91  let MIOperandInfo = operands;
92  let ParserMatchClass =
93    !cast<AddressAsmOperand>(format##bitsize##"Disp"##dispsize##length);
94}
95
96// Constructs both a DAG pattern and instruction operand for an addressing mode.
97// FORMAT, BITSIZE, DISPSIZE and LENGTH are the parameters to an associated
98// AddressAsmOperand.  OPERANDS is a list of NUMOPS individual operands
99// (base register, displacement, etc.).  SELTYPE is the type of the memory
100// operand for selection purposes; sometimes we want different selection
101// choices for the same underlying addressing mode.  SUFFIX is similarly
102// a suffix appended to the displacement for selection purposes;
103// e.g. we want to reject small 20-bit displacements if a 12-bit form
104// also exists, but we want to accept them otherwise.
105class AddressingMode<string seltype, string bitsize, string dispsize,
106                     string suffix, string length, int numops, string format,
107                     dag operands>
108  : ComplexPattern<!cast<ValueType>("i"##bitsize), numops,
109                   "select"##seltype##dispsize##suffix##length,
110                   [add, sub, or, frameindex, z_adjdynalloc]>,
111    AddressOperand<bitsize, dispsize, length, format, operands>;
112
113// An addressing mode with a base and displacement but no index.
114class BDMode<string type, string bitsize, string dispsize, string suffix>
115  : AddressingMode<type, bitsize, dispsize, suffix, "", 2, "BDAddr",
116                   (ops !cast<RegisterOperand>("ADDR"##bitsize),
117                        !cast<Operand>("disp"##dispsize##"imm"##bitsize))>;
118
119// An addressing mode with a base, displacement and index.
120class BDXMode<string type, string bitsize, string dispsize, string suffix>
121  : AddressingMode<type, bitsize, dispsize, suffix, "", 3, "BDXAddr",
122                   (ops !cast<RegisterOperand>("ADDR"##bitsize),
123                        !cast<Operand>("disp"##dispsize##"imm"##bitsize),
124                        !cast<RegisterOperand>("ADDR"##bitsize))>;
125
126// A BDMode paired with an immediate length operand of LENSIZE bits.
127class BDLMode<string type, string bitsize, string dispsize, string suffix,
128              string lensize>
129  : AddressingMode<type, bitsize, dispsize, suffix, "Len"##lensize, 3,
130                   "BDLAddr",
131                   (ops !cast<RegisterOperand>("ADDR"##bitsize),
132                        !cast<Operand>("disp"##dispsize##"imm"##bitsize),
133                        !cast<Operand>("imm"##bitsize))>;
134
135// A BDMode paired with a register length operand.
136class BDRMode<string type, string bitsize, string dispsize, string suffix>
137  : AddressingMode<type, bitsize, dispsize, suffix, "", 3, "BDRAddr",
138                   (ops !cast<RegisterOperand>("ADDR"##bitsize),
139                        !cast<Operand>("disp"##dispsize##"imm"##bitsize),
140                        !cast<RegisterOperand>("GR"##bitsize))>;
141
142// An addressing mode with a base, displacement and a vector index.
143class BDVMode<string bitsize, string dispsize>
144  : AddressOperand<bitsize, dispsize, "", "BDVAddr",
145                   (ops !cast<RegisterOperand>("ADDR"##bitsize),
146                        !cast<Operand>("disp"##dispsize##"imm"##bitsize),
147                        !cast<RegisterOperand>("VR128"))>;
148
149//===----------------------------------------------------------------------===//
150// Extracting immediate operands from nodes
151// These all create MVT::i64 nodes to ensure the value is not sign-extended
152// when converted from an SDNode to a MachineOperand later on.
153//===----------------------------------------------------------------------===//
154
155// Bits 0-15 (counting from the lsb).
156def LL16 : SDNodeXForm<imm, [{
157  uint64_t Value = N->getZExtValue() & 0x000000000000FFFFULL;
158  return CurDAG->getTargetConstant(Value, SDLoc(N), MVT::i64);
159}]>;
160
161// Bits 16-31 (counting from the lsb).
162def LH16 : SDNodeXForm<imm, [{
163  uint64_t Value = (N->getZExtValue() & 0x00000000FFFF0000ULL) >> 16;
164  return CurDAG->getTargetConstant(Value, SDLoc(N), MVT::i64);
165}]>;
166
167// Bits 32-47 (counting from the lsb).
168def HL16 : SDNodeXForm<imm, [{
169  uint64_t Value = (N->getZExtValue() & 0x0000FFFF00000000ULL) >> 32;
170  return CurDAG->getTargetConstant(Value, SDLoc(N), MVT::i64);
171}]>;
172
173// Bits 48-63 (counting from the lsb).
174def HH16 : SDNodeXForm<imm, [{
175  uint64_t Value = (N->getZExtValue() & 0xFFFF000000000000ULL) >> 48;
176  return CurDAG->getTargetConstant(Value, SDLoc(N), MVT::i64);
177}]>;
178
179// Low 32 bits.
180def LF32 : SDNodeXForm<imm, [{
181  uint64_t Value = N->getZExtValue() & 0x00000000FFFFFFFFULL;
182  return CurDAG->getTargetConstant(Value, SDLoc(N), MVT::i64);
183}]>;
184
185// High 32 bits.
186def HF32 : SDNodeXForm<imm, [{
187  uint64_t Value = N->getZExtValue() >> 32;
188  return CurDAG->getTargetConstant(Value, SDLoc(N), MVT::i64);
189}]>;
190
191// Negated variants.
192def NEGLH16 : SDNodeXForm<imm, [{
193  uint64_t Value = (-N->getZExtValue() & 0x00000000FFFF0000ULL) >> 16;
194  return CurDAG->getTargetConstant(Value, SDLoc(N), MVT::i64);
195}]>;
196
197def NEGLF32 : SDNodeXForm<imm, [{
198  uint64_t Value = -N->getZExtValue() & 0x00000000FFFFFFFFULL;
199  return CurDAG->getTargetConstant(Value, SDLoc(N), MVT::i64);
200}]>;
201
202// Truncate an immediate to a 8-bit signed quantity.
203def SIMM8 : SDNodeXForm<imm, [{
204  return CurDAG->getTargetConstant(int8_t(N->getZExtValue()), SDLoc(N),
205                                   MVT::i64);
206}]>;
207
208// Truncate an immediate to a 8-bit unsigned quantity.
209def UIMM8 : SDNodeXForm<imm, [{
210  return CurDAG->getTargetConstant(uint8_t(N->getZExtValue()), SDLoc(N),
211                                   MVT::i64);
212}]>;
213
214// Truncate an immediate to a 8-bit unsigned quantity and mask off low bit.
215def UIMM8EVEN : SDNodeXForm<imm, [{
216  return CurDAG->getTargetConstant(N->getZExtValue() & 0xfe, SDLoc(N),
217                                   MVT::i64);
218}]>;
219
220// Truncate an immediate to a 12-bit unsigned quantity.
221def UIMM12 : SDNodeXForm<imm, [{
222  return CurDAG->getTargetConstant(N->getZExtValue() & 0xfff, SDLoc(N),
223                                   MVT::i64);
224}]>;
225
226// Truncate an immediate to a 16-bit signed quantity.
227def SIMM16 : SDNodeXForm<imm, [{
228  return CurDAG->getTargetConstant(int16_t(N->getZExtValue()), SDLoc(N),
229                                   MVT::i64);
230}]>;
231
232// Negate and then truncate an immediate to a 16-bit signed quantity.
233def NEGSIMM16 : SDNodeXForm<imm, [{
234  return CurDAG->getTargetConstant(int16_t(-N->getZExtValue()), SDLoc(N),
235                                   MVT::i64);
236}]>;
237
238// Truncate an immediate to a 16-bit unsigned quantity.
239def UIMM16 : SDNodeXForm<imm, [{
240  return CurDAG->getTargetConstant(uint16_t(N->getZExtValue()), SDLoc(N),
241                                   MVT::i64);
242}]>;
243
244// Truncate an immediate to a 32-bit signed quantity.
245def SIMM32 : SDNodeXForm<imm, [{
246  return CurDAG->getTargetConstant(int32_t(N->getZExtValue()), SDLoc(N),
247                                   MVT::i64);
248}]>;
249
250// Negate and then truncate an immediate to a 32-bit unsigned quantity.
251def NEGSIMM32 : SDNodeXForm<imm, [{
252  return CurDAG->getTargetConstant(int32_t(-N->getZExtValue()), SDLoc(N),
253                                   MVT::i64);
254}]>;
255
256// Truncate an immediate to a 32-bit unsigned quantity.
257def UIMM32 : SDNodeXForm<imm, [{
258  return CurDAG->getTargetConstant(uint32_t(N->getZExtValue()), SDLoc(N),
259                                   MVT::i64);
260}]>;
261
262// Negate and then truncate an immediate to a 32-bit unsigned quantity.
263def NEGUIMM32 : SDNodeXForm<imm, [{
264  return CurDAG->getTargetConstant(uint32_t(-N->getZExtValue()), SDLoc(N),
265                                   MVT::i64);
266}]>;
267
268// Truncate an immediate to a 48-bit unsigned quantity.
269def UIMM48 : SDNodeXForm<imm, [{
270  return CurDAG->getTargetConstant(uint64_t(N->getZExtValue()) & 0xffffffffffff,
271                                   SDLoc(N), MVT::i64);
272}]>;
273
274//===----------------------------------------------------------------------===//
275// Immediate asm operands.
276//===----------------------------------------------------------------------===//
277
278def U1Imm  : ImmediateAsmOperand<"U1Imm">;
279def U2Imm  : ImmediateAsmOperand<"U2Imm">;
280def U3Imm  : ImmediateAsmOperand<"U3Imm">;
281def U4Imm  : ImmediateAsmOperand<"U4Imm">;
282def U6Imm  : ImmediateAsmOperand<"U6Imm">;
283def S8Imm  : ImmediateAsmOperand<"S8Imm">;
284def U8Imm  : ImmediateAsmOperand<"U8Imm">;
285def U12Imm : ImmediateAsmOperand<"U12Imm">;
286def S16Imm : ImmediateAsmOperand<"S16Imm">;
287def U16Imm : ImmediateAsmOperand<"U16Imm">;
288def S32Imm : ImmediateAsmOperand<"S32Imm">;
289def U32Imm : ImmediateAsmOperand<"U32Imm">;
290def U48Imm : ImmediateAsmOperand<"U48Imm">;
291
292//===----------------------------------------------------------------------===//
293// i32 immediates
294//===----------------------------------------------------------------------===//
295
296// Immediates for the lower and upper 16 bits of an i32, with the other
297// bits of the i32 being zero.
298def imm32ll16 : Immediate<i32, [{
299  return SystemZ::isImmLL(N->getZExtValue());
300}], LL16, "U16Imm">;
301
302def imm32lh16 : Immediate<i32, [{
303  return SystemZ::isImmLH(N->getZExtValue());
304}], LH16, "U16Imm">;
305
306// Immediates for the lower and upper 16 bits of an i32, with the other
307// bits of the i32 being one.
308def imm32ll16c : Immediate<i32, [{
309  return SystemZ::isImmLL(uint32_t(~N->getZExtValue()));
310}], LL16, "U16Imm">;
311
312def imm32lh16c : Immediate<i32, [{
313  return SystemZ::isImmLH(uint32_t(~N->getZExtValue()));
314}], LH16, "U16Imm">;
315
316// Short immediates
317def imm32zx1 : Immediate<i32, [{
318  return isUInt<1>(N->getZExtValue());
319}], NOOP_SDNodeXForm, "U1Imm">;
320
321def imm32zx2 : Immediate<i32, [{
322  return isUInt<2>(N->getZExtValue());
323}], NOOP_SDNodeXForm, "U2Imm">;
324
325def imm32zx3 : Immediate<i32, [{
326  return isUInt<3>(N->getZExtValue());
327}], NOOP_SDNodeXForm, "U3Imm">;
328
329def imm32zx4 : Immediate<i32, [{
330  return isUInt<4>(N->getZExtValue());
331}], NOOP_SDNodeXForm, "U4Imm">;
332
333// Note: this enforces an even value during code generation only.
334// When used from the assembler, any 4-bit value is allowed.
335def imm32zx4even : Immediate<i32, [{
336  return isUInt<4>(N->getZExtValue());
337}], UIMM8EVEN, "U4Imm">;
338
339def imm32zx6 : Immediate<i32, [{
340  return isUInt<6>(N->getZExtValue());
341}], NOOP_SDNodeXForm, "U6Imm">;
342
343def imm32sx8 : Immediate<i32, [{
344  return isInt<8>(N->getSExtValue());
345}], SIMM8, "S8Imm">;
346
347def imm32zx8 : Immediate<i32, [{
348  return isUInt<8>(N->getZExtValue());
349}], UIMM8, "U8Imm">;
350
351def imm32zx8trunc : Immediate<i32, [{}], UIMM8, "U8Imm">;
352
353def imm32zx12 : Immediate<i32, [{
354  return isUInt<12>(N->getZExtValue());
355}], UIMM12, "U12Imm">;
356
357def imm32sx16 : Immediate<i32, [{
358  return isInt<16>(N->getSExtValue());
359}], SIMM16, "S16Imm">;
360
361def imm32sx16n : Immediate<i32, [{
362  return isInt<16>(-N->getSExtValue());
363}], NEGSIMM16, "S16Imm">;
364
365def imm32zx16 : Immediate<i32, [{
366  return isUInt<16>(N->getZExtValue());
367}], UIMM16, "U16Imm">;
368
369def imm32sx16trunc : Immediate<i32, [{}], SIMM16, "S16Imm">;
370def imm32zx16trunc : Immediate<i32, [{}], UIMM16, "U16Imm">;
371
372// Full 32-bit immediates.  we need both signed and unsigned versions
373// because the assembler is picky.  E.g. AFI requires signed operands
374// while NILF requires unsigned ones.
375def simm32 : Immediate<i32, [{}], SIMM32, "S32Imm">;
376def uimm32 : Immediate<i32, [{}], UIMM32, "U32Imm">;
377
378def simm32n : Immediate<i32, [{
379  return isInt<32>(-N->getSExtValue());
380}], NEGSIMM32, "S32Imm">;
381
382def imm32 : ImmLeaf<i32, [{}]>;
383
384//===----------------------------------------------------------------------===//
385// 64-bit immediates
386//===----------------------------------------------------------------------===//
387
388// Immediates for 16-bit chunks of an i64, with the other bits of the
389// i32 being zero.
390def imm64ll16 : Immediate<i64, [{
391  return SystemZ::isImmLL(N->getZExtValue());
392}], LL16, "U16Imm">;
393
394def imm64lh16 : Immediate<i64, [{
395  return SystemZ::isImmLH(N->getZExtValue());
396}], LH16, "U16Imm">;
397
398def imm64hl16 : Immediate<i64, [{
399  return SystemZ::isImmHL(N->getZExtValue());
400}], HL16, "U16Imm">;
401
402def imm64hh16 : Immediate<i64, [{
403  return SystemZ::isImmHH(N->getZExtValue());
404}], HH16, "U16Imm">;
405
406// Immediates for 16-bit chunks of an i64, with the other bits of the
407// i32 being one.
408def imm64ll16c : Immediate<i64, [{
409  return SystemZ::isImmLL(uint64_t(~N->getZExtValue()));
410}], LL16, "U16Imm">;
411
412def imm64lh16c : Immediate<i64, [{
413  return SystemZ::isImmLH(uint64_t(~N->getZExtValue()));
414}], LH16, "U16Imm">;
415
416def imm64hl16c : Immediate<i64, [{
417  return SystemZ::isImmHL(uint64_t(~N->getZExtValue()));
418}], HL16, "U16Imm">;
419
420def imm64hh16c : Immediate<i64, [{
421  return SystemZ::isImmHH(uint64_t(~N->getZExtValue()));
422}], HH16, "U16Imm">;
423
424// Immediates for the lower and upper 32 bits of an i64, with the other
425// bits of the i32 being zero.
426def imm64lf32 : Immediate<i64, [{
427  return SystemZ::isImmLF(N->getZExtValue());
428}], LF32, "U32Imm">;
429
430def imm64hf32 : Immediate<i64, [{
431  return SystemZ::isImmHF(N->getZExtValue());
432}], HF32, "U32Imm">;
433
434// Immediates for the lower and upper 32 bits of an i64, with the other
435// bits of the i32 being one.
436def imm64lf32c : Immediate<i64, [{
437  return SystemZ::isImmLF(uint64_t(~N->getZExtValue()));
438}], LF32, "U32Imm">;
439
440def imm64hf32c : Immediate<i64, [{
441  return SystemZ::isImmHF(uint64_t(~N->getZExtValue()));
442}], HF32, "U32Imm">;
443
444// Negated immediates that fit LF32 or LH16.
445def imm64lh16n : Immediate<i64, [{
446  return SystemZ::isImmLH(uint64_t(-N->getZExtValue()));
447}], NEGLH16, "U16Imm">;
448
449def imm64lf32n : Immediate<i64, [{
450  return SystemZ::isImmLF(uint64_t(-N->getZExtValue()));
451}], NEGLF32, "U32Imm">;
452
453// Short immediates.
454def imm64sx8 : Immediate<i64, [{
455  return isInt<8>(N->getSExtValue());
456}], SIMM8, "S8Imm">;
457
458def imm64zx8 : Immediate<i64, [{
459  return isUInt<8>(N->getSExtValue());
460}], UIMM8, "U8Imm">;
461
462def imm64sx16 : Immediate<i64, [{
463  return isInt<16>(N->getSExtValue());
464}], SIMM16, "S16Imm">;
465
466def imm64sx16n : Immediate<i64, [{
467  return isInt<16>(-N->getSExtValue());
468}], NEGSIMM16, "S16Imm">;
469
470def imm64zx16 : Immediate<i64, [{
471  return isUInt<16>(N->getZExtValue());
472}], UIMM16, "U16Imm">;
473
474def imm64sx32 : Immediate<i64, [{
475  return isInt<32>(N->getSExtValue());
476}], SIMM32, "S32Imm">;
477
478def imm64sx32n : Immediate<i64, [{
479  return isInt<32>(-N->getSExtValue());
480}], NEGSIMM32, "S32Imm">;
481
482def imm64zx32 : Immediate<i64, [{
483  return isUInt<32>(N->getZExtValue());
484}], UIMM32, "U32Imm">;
485
486def imm64zx32n : Immediate<i64, [{
487  return isUInt<32>(-N->getSExtValue());
488}], NEGUIMM32, "U32Imm">;
489
490def imm64zx48 : Immediate<i64, [{
491  return isUInt<64>(N->getZExtValue());
492}], UIMM48, "U48Imm">;
493
494def imm64 : ImmLeaf<i64, [{}]>, Operand<i64>;
495
496//===----------------------------------------------------------------------===//
497// Floating-point immediates
498//===----------------------------------------------------------------------===//
499
500// Floating-point zero.
501def fpimm0 : PatLeaf<(fpimm), [{ return N->isExactlyValue(+0.0); }]>;
502
503// Floating point negative zero.
504def fpimmneg0 : PatLeaf<(fpimm), [{ return N->isExactlyValue(-0.0); }]>;
505
506//===----------------------------------------------------------------------===//
507// Symbolic address operands
508//===----------------------------------------------------------------------===//
509
510// PC-relative asm operands.
511def PCRel12 : PCRelAsmOperand<"12">;
512def PCRel16 : PCRelAsmOperand<"16">;
513def PCRel24 : PCRelAsmOperand<"24">;
514def PCRel32 : PCRelAsmOperand<"32">;
515def PCRelTLS16 : PCRelTLSAsmOperand<"16">;
516def PCRelTLS32 : PCRelTLSAsmOperand<"32">;
517
518// PC-relative offsets of a basic block.  The offset is sign-extended
519// and multiplied by 2.
520def brtarget16 : PCRelOperand<OtherVT, PCRel16> {
521  let EncoderMethod = "getPC16DBLEncoding";
522  let DecoderMethod = "decodePC16DBLBranchOperand";
523}
524def brtarget32 : PCRelOperand<OtherVT, PCRel32> {
525  let EncoderMethod = "getPC32DBLEncoding";
526  let DecoderMethod = "decodePC32DBLBranchOperand";
527}
528
529// Variants of brtarget for use with branch prediction preload.
530def brtarget12bpp : PCRelOperand<OtherVT, PCRel12> {
531  let EncoderMethod = "getPC12DBLBPPEncoding";
532  let DecoderMethod = "decodePC12DBLBranchOperand";
533}
534def brtarget16bpp : PCRelOperand<OtherVT, PCRel16> {
535  let EncoderMethod = "getPC16DBLBPPEncoding";
536  let DecoderMethod = "decodePC16DBLBranchOperand";
537}
538def brtarget24bpp : PCRelOperand<OtherVT, PCRel24> {
539  let EncoderMethod = "getPC24DBLBPPEncoding";
540  let DecoderMethod = "decodePC24DBLBranchOperand";
541}
542
543// Variants of brtarget16/32 with an optional additional TLS symbol.
544// These are used to annotate calls to __tls_get_offset.
545def tlssym : Operand<i64> { }
546def brtarget16tls : PCRelTLSOperand<OtherVT, PCRelTLS16> {
547  let MIOperandInfo = (ops brtarget16:$func, tlssym:$sym);
548  let EncoderMethod = "getPC16DBLTLSEncoding";
549  let DecoderMethod = "decodePC16DBLBranchOperand";
550}
551def brtarget32tls : PCRelTLSOperand<OtherVT, PCRelTLS32> {
552  let MIOperandInfo = (ops brtarget32:$func, tlssym:$sym);
553  let EncoderMethod = "getPC32DBLTLSEncoding";
554  let DecoderMethod = "decodePC32DBLBranchOperand";
555}
556
557// A PC-relative offset of a global value.  The offset is sign-extended
558// and multiplied by 2.
559def pcrel32 : PCRelAddress<i64, "pcrel32", PCRel32> {
560  let EncoderMethod = "getPC32DBLEncoding";
561  let DecoderMethod = "decodePC32DBLOperand";
562}
563
564//===----------------------------------------------------------------------===//
565// Addressing modes
566//===----------------------------------------------------------------------===//
567
568// 12-bit displacement operands.
569def disp12imm32 : Operand<i32>;
570def disp12imm64 : Operand<i64>;
571
572// 20-bit displacement operands.
573def disp20imm32 : Operand<i32>;
574def disp20imm64 : Operand<i64>;
575
576def BDAddr32Disp12      : AddressAsmOperand<"BDAddr",   "32", "12">;
577def BDAddr32Disp20      : AddressAsmOperand<"BDAddr",   "32", "20">;
578def BDAddr64Disp12      : AddressAsmOperand<"BDAddr",   "64", "12">;
579def BDAddr64Disp20      : AddressAsmOperand<"BDAddr",   "64", "20">;
580def BDXAddr64Disp12     : AddressAsmOperand<"BDXAddr",  "64", "12">;
581def BDXAddr64Disp20     : AddressAsmOperand<"BDXAddr",  "64", "20">;
582def BDLAddr64Disp12Len4 : AddressAsmOperand<"BDLAddr",  "64", "12", "Len4">;
583def BDLAddr64Disp12Len8 : AddressAsmOperand<"BDLAddr",  "64", "12", "Len8">;
584def BDRAddr64Disp12     : AddressAsmOperand<"BDRAddr",  "64", "12">;
585def BDVAddr64Disp12     : AddressAsmOperand<"BDVAddr",  "64", "12">;
586
587// DAG patterns and operands for addressing modes.  Each mode has
588// the form <type><range><group>[<len>] where:
589//
590// <type> is one of:
591//   shift    : base + displacement (32-bit)
592//   bdaddr   : base + displacement
593//   mviaddr  : like bdaddr, but reject cases with a natural index
594//   bdxaddr  : base + displacement + index
595//   laaddr   : like bdxaddr, but used for Load Address operations
596//   dynalloc : base + displacement + index + ADJDYNALLOC
597//   bdladdr  : base + displacement with a length field
598//   bdvaddr  : base + displacement with a vector index
599//
600// <range> is one of:
601//   12       : the displacement is an unsigned 12-bit value
602//   20       : the displacement is a signed 20-bit value
603//
604// <group> is one of:
605//   pair     : used when there is an equivalent instruction with the opposite
606//              range value (12 or 20)
607//   only     : used when there is no equivalent instruction with the opposite
608//              range value
609//
610// <len> is one of:
611//
612//   <empty>  : there is no length field
613//   len8     : the length field is 8 bits, with a range of [1, 0x100].
614def shift12only       : BDMode <"BDAddr",   "32", "12", "Only">;
615def shift20only       : BDMode <"BDAddr",   "32", "20", "Only">;
616def bdaddr12only      : BDMode <"BDAddr",   "64", "12", "Only">;
617def bdaddr12pair      : BDMode <"BDAddr",   "64", "12", "Pair">;
618def bdaddr20only      : BDMode <"BDAddr",   "64", "20", "Only">;
619def bdaddr20pair      : BDMode <"BDAddr",   "64", "20", "Pair">;
620def mviaddr12pair     : BDMode <"MVIAddr",  "64", "12", "Pair">;
621def mviaddr20pair     : BDMode <"MVIAddr",  "64", "20", "Pair">;
622def bdxaddr12only     : BDXMode<"BDXAddr",  "64", "12", "Only">;
623def bdxaddr12pair     : BDXMode<"BDXAddr",  "64", "12", "Pair">;
624def bdxaddr20only     : BDXMode<"BDXAddr",  "64", "20", "Only">;
625def bdxaddr20only128  : BDXMode<"BDXAddr",  "64", "20", "Only128">;
626def bdxaddr20pair     : BDXMode<"BDXAddr",  "64", "20", "Pair">;
627def dynalloc12only    : BDXMode<"DynAlloc", "64", "12", "Only">;
628def laaddr12pair      : BDXMode<"LAAddr",   "64", "12", "Pair">;
629def laaddr20pair      : BDXMode<"LAAddr",   "64", "20", "Pair">;
630def bdladdr12onlylen4 : BDLMode<"BDLAddr",  "64", "12", "Only", "4">;
631def bdladdr12onlylen8 : BDLMode<"BDLAddr",  "64", "12", "Only", "8">;
632def bdraddr12only     : BDRMode<"BDRAddr",  "64", "12", "Only">;
633def bdvaddr12only     : BDVMode<            "64", "12">;
634
635//===----------------------------------------------------------------------===//
636// Miscellaneous
637//===----------------------------------------------------------------------===//
638
639// A 4-bit condition-code mask.
640def cond4 : PatLeaf<(i32 imm), [{ return (N->getZExtValue() < 16); }]>,
641            Operand<i32> {
642  let PrintMethod = "printCond4Operand";
643}
644