• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1//==- SystemZInstrFormats.td - SystemZ Instruction Formats --*- tablegen -*-==//
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// Basic SystemZ instruction definition
12//===----------------------------------------------------------------------===//
13
14class InstSystemZ<int size, dag outs, dag ins, string asmstr,
15                  list<dag> pattern> : Instruction {
16  let Namespace = "SystemZ";
17
18  dag OutOperandList = outs;
19  dag InOperandList = ins;
20  let Size = size;
21  let Pattern = pattern;
22  let AsmString = asmstr;
23
24  // Some instructions come in pairs, one having a 12-bit displacement
25  // and the other having a 20-bit displacement.  Both instructions in
26  // the pair have the same DispKey and their DispSizes are "12" and "20"
27  // respectively.
28  string DispKey = "";
29  string DispSize = "none";
30
31  // Many register-based <INSN>R instructions have a memory-based <INSN>
32  // counterpart.  OpKey uniquely identifies <INSN>, while OpType is
33  // "reg" for <INSN>R and "mem" for <INSN>.
34  string OpKey = "";
35  string OpType = "none";
36
37  // Many distinct-operands instructions have older 2-operand equivalents.
38  // NumOpsKey uniquely identifies one of these 2-operand and 3-operand pairs,
39  // with NumOpsValue being "2" or "3" as appropriate.
40  string NumOpsKey = "";
41  string NumOpsValue = "none";
42
43  // True if this instruction is a simple D(X,B) load of a register
44  // (with no sign or zero extension).
45  bit SimpleBDXLoad = 0;
46
47  // True if this instruction is a simple D(X,B) store of a register
48  // (with no truncation).
49  bit SimpleBDXStore = 0;
50
51  // True if this instruction has a 20-bit displacement field.
52  bit Has20BitOffset = 0;
53
54  // True if addresses in this instruction have an index register.
55  bit HasIndex = 0;
56
57  // True if this is a 128-bit pseudo instruction that combines two 64-bit
58  // operations.
59  bit Is128Bit = 0;
60
61  // The access size of all memory operands in bytes, or 0 if not known.
62  bits<5> AccessBytes = 0;
63
64  // If the instruction sets CC to a useful value, this gives the mask
65  // of all possible CC results.  The mask has the same form as
66  // SystemZ::CCMASK_*.
67  bits<4> CCValues = 0;
68
69  // The subset of CCValues that have the same meaning as they would after
70  // a comparison of the first operand against zero.
71  bits<4> CompareZeroCCMask = 0;
72
73  // True if the instruction is conditional and if the CC mask operand
74  // comes first (as for BRC, etc.).
75  bit CCMaskFirst = 0;
76
77  // Similar, but true if the CC mask operand comes last (as for LOC, etc.).
78  bit CCMaskLast = 0;
79
80  // True if the instruction is the "logical" rather than "arithmetic" form,
81  // in cases where a distinction exists.
82  bit IsLogical = 0;
83
84  let TSFlags{0}     = SimpleBDXLoad;
85  let TSFlags{1}     = SimpleBDXStore;
86  let TSFlags{2}     = Has20BitOffset;
87  let TSFlags{3}     = HasIndex;
88  let TSFlags{4}     = Is128Bit;
89  let TSFlags{9-5}   = AccessBytes;
90  let TSFlags{13-10} = CCValues;
91  let TSFlags{17-14} = CompareZeroCCMask;
92  let TSFlags{18}    = CCMaskFirst;
93  let TSFlags{19}    = CCMaskLast;
94  let TSFlags{20}    = IsLogical;
95}
96
97//===----------------------------------------------------------------------===//
98// Mappings between instructions
99//===----------------------------------------------------------------------===//
100
101// Return the version of an instruction that has an unsigned 12-bit
102// displacement.
103def getDisp12Opcode : InstrMapping {
104  let FilterClass = "InstSystemZ";
105  let RowFields = ["DispKey"];
106  let ColFields = ["DispSize"];
107  let KeyCol = ["20"];
108  let ValueCols = [["12"]];
109}
110
111// Return the version of an instruction that has a signed 20-bit displacement.
112def getDisp20Opcode : InstrMapping {
113  let FilterClass = "InstSystemZ";
114  let RowFields = ["DispKey"];
115  let ColFields = ["DispSize"];
116  let KeyCol = ["12"];
117  let ValueCols = [["20"]];
118}
119
120// Return the memory form of a register instruction.
121def getMemOpcode : InstrMapping {
122  let FilterClass = "InstSystemZ";
123  let RowFields = ["OpKey"];
124  let ColFields = ["OpType"];
125  let KeyCol = ["reg"];
126  let ValueCols = [["mem"]];
127}
128
129// Return the 3-operand form of a 2-operand instruction.
130def getThreeOperandOpcode : InstrMapping {
131  let FilterClass = "InstSystemZ";
132  let RowFields = ["NumOpsKey"];
133  let ColFields = ["NumOpsValue"];
134  let KeyCol = ["2"];
135  let ValueCols = [["3"]];
136}
137
138//===----------------------------------------------------------------------===//
139// Instruction formats
140//===----------------------------------------------------------------------===//
141//
142// Formats are specified using operand field declarations of the form:
143//
144//   bits<4> Rn   : register input or output for operand n
145//   bits<m> In   : immediate value of width m for operand n
146//   bits<4> BDn  : address operand n, which has a base and a displacement
147//   bits<m> XBDn : address operand n, which has an index, a base and a
148//                  displacement
149//   bits<4> Xn   : index register for address operand n
150//   bits<4> Mn   : mode value for operand n
151//
152// The operand numbers ("n" in the list above) follow the architecture manual.
153// Assembly operands sometimes have a different order; in particular, R3 often
154// is often written between operands 1 and 2.
155//
156//===----------------------------------------------------------------------===//
157
158class InstRI<bits<12> op, dag outs, dag ins, string asmstr, list<dag> pattern>
159  : InstSystemZ<4, outs, ins, asmstr, pattern> {
160  field bits<32> Inst;
161  field bits<32> SoftFail = 0;
162
163  bits<4> R1;
164  bits<16> I2;
165
166  let Inst{31-24} = op{11-4};
167  let Inst{23-20} = R1;
168  let Inst{19-16} = op{3-0};
169  let Inst{15-0}  = I2;
170}
171
172class InstRIEb<bits<16> op, dag outs, dag ins, string asmstr, list<dag> pattern>
173  : InstSystemZ<6, outs, ins, asmstr, pattern> {
174  field bits<48> Inst;
175  field bits<48> SoftFail = 0;
176
177  bits<4> R1;
178  bits<4> R2;
179  bits<4> M3;
180  bits<16> RI4;
181
182  let Inst{47-40} = op{15-8};
183  let Inst{39-36} = R1;
184  let Inst{35-32} = R2;
185  let Inst{31-16} = RI4;
186  let Inst{15-12} = M3;
187  let Inst{11-8}  = 0;
188  let Inst{7-0}   = op{7-0};
189}
190
191class InstRIEc<bits<16> op, dag outs, dag ins, string asmstr, list<dag> pattern>
192  : InstSystemZ<6, outs, ins, asmstr, pattern> {
193  field bits<48> Inst;
194  field bits<48> SoftFail = 0;
195
196  bits<4> R1;
197  bits<8> I2;
198  bits<4> M3;
199  bits<16> RI4;
200
201  let Inst{47-40} = op{15-8};
202  let Inst{39-36} = R1;
203  let Inst{35-32} = M3;
204  let Inst{31-16} = RI4;
205  let Inst{15-8}  = I2;
206  let Inst{7-0}   = op{7-0};
207}
208
209class InstRIEd<bits<16> op, dag outs, dag ins, string asmstr, list<dag> pattern>
210  : InstSystemZ<6, outs, ins, asmstr, pattern> {
211  field bits<48> Inst;
212  field bits<48> SoftFail = 0;
213
214  bits<4> R1;
215  bits<4> R3;
216  bits<16> I2;
217
218  let Inst{47-40} = op{15-8};
219  let Inst{39-36} = R1;
220  let Inst{35-32} = R3;
221  let Inst{31-16} = I2;
222  let Inst{15-8}  = 0;
223  let Inst{7-0}   = op{7-0};
224}
225
226class InstRIEf<bits<16> op, dag outs, dag ins, string asmstr, list<dag> pattern>
227  : InstSystemZ<6, outs, ins, asmstr, pattern> {
228  field bits<48> Inst;
229  field bits<48> SoftFail = 0;
230
231  bits<4> R1;
232  bits<4> R2;
233  bits<8> I3;
234  bits<8> I4;
235  bits<8> I5;
236
237  let Inst{47-40} = op{15-8};
238  let Inst{39-36} = R1;
239  let Inst{35-32} = R2;
240  let Inst{31-24} = I3;
241  let Inst{23-16} = I4;
242  let Inst{15-8}  = I5;
243  let Inst{7-0}   = op{7-0};
244}
245
246class InstRIL<bits<12> op, dag outs, dag ins, string asmstr, list<dag> pattern>
247  : InstSystemZ<6, outs, ins, asmstr, pattern> {
248  field bits<48> Inst;
249  field bits<48> SoftFail = 0;
250
251  bits<4> R1;
252  bits<32> I2;
253
254  let Inst{47-40} = op{11-4};
255  let Inst{39-36} = R1;
256  let Inst{35-32} = op{3-0};
257  let Inst{31-0}  = I2;
258}
259
260class InstRR<bits<8> op, dag outs, dag ins, string asmstr, list<dag> pattern>
261  : InstSystemZ<2, outs, ins, asmstr, pattern> {
262  field bits<16> Inst;
263  field bits<16> SoftFail = 0;
264
265  bits<4> R1;
266  bits<4> R2;
267
268  let Inst{15-8} = op;
269  let Inst{7-4}  = R1;
270  let Inst{3-0}  = R2;
271}
272
273class InstRRD<bits<16> op, dag outs, dag ins, string asmstr, list<dag> pattern>
274  : InstSystemZ<4, outs, ins, asmstr, pattern> {
275  field bits<32> Inst;
276  field bits<32> SoftFail = 0;
277
278  bits<4> R1;
279  bits<4> R3;
280  bits<4> R2;
281
282  let Inst{31-16} = op;
283  let Inst{15-12} = R1;
284  let Inst{11-8}  = 0;
285  let Inst{7-4}   = R3;
286  let Inst{3-0}   = R2;
287}
288
289class InstRRE<bits<16> op, dag outs, dag ins, string asmstr, list<dag> pattern>
290  : InstSystemZ<4, outs, ins, asmstr, pattern> {
291  field bits<32> Inst;
292  field bits<32> SoftFail = 0;
293
294  bits<4> R1;
295  bits<4> R2;
296
297  let Inst{31-16} = op;
298  let Inst{15-8}  = 0;
299  let Inst{7-4}   = R1;
300  let Inst{3-0}   = R2;
301}
302
303class InstRRF<bits<16> op, dag outs, dag ins, string asmstr, list<dag> pattern>
304  : InstSystemZ<4, outs, ins, asmstr, pattern> {
305  field bits<32> Inst;
306  field bits<32> SoftFail = 0;
307
308  bits<4> R1;
309  bits<4> R2;
310  bits<4> R3;
311
312  let Inst{31-16} = op;
313  let Inst{15-12} = R3;
314  let Inst{11-8}  = 0;
315  let Inst{7-4}   = R1;
316  let Inst{3-0}   = R2;
317}
318
319class InstRX<bits<8> op, dag outs, dag ins, string asmstr, list<dag> pattern>
320  : InstSystemZ<4, outs, ins, asmstr, pattern> {
321  field bits<32> Inst;
322  field bits<32> SoftFail = 0;
323
324  bits<4> R1;
325  bits<20> XBD2;
326
327  let Inst{31-24} = op;
328  let Inst{23-20} = R1;
329  let Inst{19-0}  = XBD2;
330
331  let HasIndex = 1;
332}
333
334class InstRXE<bits<16> op, dag outs, dag ins, string asmstr, list<dag> pattern>
335  : InstSystemZ<6, outs, ins, asmstr, pattern> {
336  field bits<48> Inst;
337  field bits<48> SoftFail = 0;
338
339  bits<4> R1;
340  bits<20> XBD2;
341
342  let Inst{47-40} = op{15-8};
343  let Inst{39-36} = R1;
344  let Inst{35-16} = XBD2;
345  let Inst{15-8}  = 0;
346  let Inst{7-0}   = op{7-0};
347
348  let HasIndex = 1;
349}
350
351class InstRXF<bits<16> op, dag outs, dag ins, string asmstr, list<dag> pattern>
352  : InstSystemZ<6, outs, ins, asmstr, pattern> {
353  field bits<48> Inst;
354  field bits<48> SoftFail = 0;
355
356  bits<4> R1;
357  bits<4> R3;
358  bits<20> XBD2;
359
360  let Inst{47-40} = op{15-8};
361  let Inst{39-36} = R3;
362  let Inst{35-16} = XBD2;
363  let Inst{15-12} = R1;
364  let Inst{11-8}  = 0;
365  let Inst{7-0}   = op{7-0};
366
367  let HasIndex = 1;
368}
369
370class InstRXY<bits<16> op, dag outs, dag ins, string asmstr, list<dag> pattern>
371  : InstSystemZ<6, outs, ins, asmstr, pattern> {
372  field bits<48> Inst;
373  field bits<48> SoftFail = 0;
374
375  bits<4> R1;
376  bits<28> XBD2;
377
378  let Inst{47-40} = op{15-8};
379  let Inst{39-36} = R1;
380  let Inst{35-8}  = XBD2;
381  let Inst{7-0}   = op{7-0};
382
383  let Has20BitOffset = 1;
384  let HasIndex = 1;
385}
386
387class InstRS<bits<8> op, dag outs, dag ins, string asmstr, list<dag> pattern>
388  : InstSystemZ<4, outs, ins, asmstr, pattern> {
389  field bits<32> Inst;
390  field bits<32> SoftFail = 0;
391
392  bits<4> R1;
393  bits<4> R3;
394  bits<16> BD2;
395
396  let Inst{31-24} = op;
397  let Inst{23-20} = R1;
398  let Inst{19-16} = R3;
399  let Inst{15-0}  = BD2;
400}
401
402class InstRSY<bits<16> op, dag outs, dag ins, string asmstr, list<dag> pattern>
403  : InstSystemZ<6, outs, ins, asmstr, pattern> {
404  field bits<48> Inst;
405  field bits<48> SoftFail = 0;
406
407  bits<4> R1;
408  bits<4> R3;
409  bits<24> BD2;
410
411  let Inst{47-40} = op{15-8};
412  let Inst{39-36} = R1;
413  let Inst{35-32} = R3;
414  let Inst{31-8}  = BD2;
415  let Inst{7-0}   = op{7-0};
416
417  let Has20BitOffset = 1;
418}
419
420class InstSI<bits<8> op, dag outs, dag ins, string asmstr, list<dag> pattern>
421  : InstSystemZ<4, outs, ins, asmstr, pattern> {
422  field bits<32> Inst;
423  field bits<32> SoftFail = 0;
424
425  bits<16> BD1;
426  bits<8> I2;
427
428  let Inst{31-24} = op;
429  let Inst{23-16} = I2;
430  let Inst{15-0}  = BD1;
431}
432
433class InstSIL<bits<16> op, dag outs, dag ins, string asmstr, list<dag> pattern>
434  : InstSystemZ<6, outs, ins, asmstr, pattern> {
435  field bits<48> Inst;
436  field bits<48> SoftFail = 0;
437
438  bits<16> BD1;
439  bits<16> I2;
440
441  let Inst{47-32} = op;
442  let Inst{31-16} = BD1;
443  let Inst{15-0}  = I2;
444}
445
446class InstSIY<bits<16> op, dag outs, dag ins, string asmstr, list<dag> pattern>
447  : InstSystemZ<6, outs, ins, asmstr, pattern> {
448  field bits<48> Inst;
449  field bits<48> SoftFail = 0;
450
451  bits<24> BD1;
452  bits<8> I2;
453
454  let Inst{47-40} = op{15-8};
455  let Inst{39-32} = I2;
456  let Inst{31-8}  = BD1;
457  let Inst{7-0}   = op{7-0};
458
459  let Has20BitOffset = 1;
460}
461
462class InstSS<bits<8> op, dag outs, dag ins, string asmstr, list<dag> pattern>
463  : InstSystemZ<6, outs, ins, asmstr, pattern> {
464  field bits<48> Inst;
465  field bits<48> SoftFail = 0;
466
467  bits<24> BDL1;
468  bits<16> BD2;
469
470  let Inst{47-40} = op;
471  let Inst{39-16} = BDL1;
472  let Inst{15-0}  = BD2;
473}
474
475//===----------------------------------------------------------------------===//
476// Instruction definitions with semantics
477//===----------------------------------------------------------------------===//
478//
479// These classes have the form [Cond]<Category><Format>, where <Format> is one
480// of the formats defined above and where <Category> describes the inputs
481// and outputs.  "Cond" is used if the instruction is conditional,
482// in which case the 4-bit condition-code mask is added as a final operand.
483// <Category> can be one of:
484//
485//   Inherent:
486//     One register output operand and no input operands.
487//
488//   BranchUnary:
489//     One register output operand, one register input operand and
490//     one branch displacement.  The instructions stores a modified
491//     form of the source register in the destination register and
492//     branches on the result.
493//
494//   Store:
495//     One register or immediate input operand and one address input operand.
496//     The instruction stores the first operand to the address.
497//
498//     This category is used for both pure and truncating stores.
499//
500//   LoadMultiple:
501//     One address input operand and two explicit output operands.
502//     The instruction loads a range of registers from the address,
503//     with the explicit operands giving the first and last register
504//     to load.  Other loaded registers are added as implicit definitions.
505//
506//   StoreMultiple:
507//     Two explicit input register operands and an address operand.
508//     The instruction stores a range of registers to the address,
509//     with the explicit operands giving the first and last register
510//     to store.  Other stored registers are added as implicit uses.
511//
512//   Unary:
513//     One register output operand and one input operand.  The input
514//     operand may be a register, immediate or memory.
515//
516//   Binary:
517//     One register output operand and two input operands.  The first
518//     input operand is always a register and he second may be a register,
519//     immediate or memory.
520//
521//   Shift:
522//     One register output operand and two input operands.  The first
523//     input operand is a register and the second has the same form as
524//     an address (although it isn't actually used to address memory).
525//
526//   Compare:
527//     Two input operands.  The first operand is always a register,
528//     the second may be a register, immediate or memory.
529//
530//   Ternary:
531//     One register output operand and three register input operands.
532//
533//   CmpSwap:
534//     One output operand and three input operands.  The first two
535//     operands are registers and the third is an address.  The instruction
536//     both reads from and writes to the address.
537//
538//   RotateSelect:
539//     One output operand and five input operands.  The first two operands
540//     are registers and the other three are immediates.
541//
542// The format determines which input operands are tied to output operands,
543// and also determines the shape of any address operand.
544//
545// Multiclasses of the form <Category><Format>Pair define two instructions,
546// one with <Category><Format> and one with <Category><Format>Y.  The name
547// of the first instruction has no suffix, the name of the second has
548// an extra "y".
549//
550//===----------------------------------------------------------------------===//
551
552class InherentRRE<string mnemonic, bits<16> opcode, RegisterOperand cls,
553                  dag src>
554  : InstRRE<opcode, (outs cls:$R1), (ins),
555            mnemonic#"r\t$R1",
556            [(set cls:$R1, src)]> {
557  let R2 = 0;
558}
559
560class BranchUnaryRI<string mnemonic, bits<12> opcode, RegisterOperand cls>
561  : InstRI<opcode, (outs cls:$R1), (ins cls:$R1src, brtarget16:$I2),
562           mnemonic##"\t$R1, $I2", []> {
563  let isBranch = 1;
564  let isTerminator = 1;
565  let Constraints = "$R1 = $R1src";
566  let DisableEncoding = "$R1src";
567}
568
569class LoadMultipleRSY<string mnemonic, bits<16> opcode, RegisterOperand cls>
570  : InstRSY<opcode, (outs cls:$R1, cls:$R3), (ins bdaddr20only:$BD2),
571            mnemonic#"\t$R1, $R3, $BD2", []> {
572  let mayLoad = 1;
573}
574
575class StoreRILPC<string mnemonic, bits<12> opcode, SDPatternOperator operator,
576                 RegisterOperand cls>
577  : InstRIL<opcode, (outs), (ins cls:$R1, pcrel32:$I2),
578            mnemonic#"\t$R1, $I2",
579            [(operator cls:$R1, pcrel32:$I2)]> {
580  let mayStore = 1;
581  // We want PC-relative addresses to be tried ahead of BD and BDX addresses.
582  // However, BDXs have two extra operands and are therefore 6 units more
583  // complex.
584  let AddedComplexity = 7;
585}
586
587class StoreRX<string mnemonic, bits<8> opcode, SDPatternOperator operator,
588              RegisterOperand cls, bits<5> bytes,
589              AddressingMode mode = bdxaddr12only>
590  : InstRX<opcode, (outs), (ins cls:$R1, mode:$XBD2),
591           mnemonic#"\t$R1, $XBD2",
592           [(operator cls:$R1, mode:$XBD2)]> {
593  let OpKey = mnemonic ## cls;
594  let OpType = "mem";
595  let mayStore = 1;
596  let AccessBytes = bytes;
597}
598
599class StoreRXY<string mnemonic, bits<16> opcode, SDPatternOperator operator,
600               RegisterOperand cls, bits<5> bytes,
601               AddressingMode mode = bdxaddr20only>
602  : InstRXY<opcode, (outs), (ins cls:$R1, mode:$XBD2),
603            mnemonic#"\t$R1, $XBD2",
604            [(operator cls:$R1, mode:$XBD2)]> {
605  let OpKey = mnemonic ## cls;
606  let OpType = "mem";
607  let mayStore = 1;
608  let AccessBytes = bytes;
609}
610
611multiclass StoreRXPair<string mnemonic, bits<8> rxOpcode, bits<16> rxyOpcode,
612                       SDPatternOperator operator, RegisterOperand cls,
613                       bits<5> bytes> {
614  let DispKey = mnemonic ## #cls in {
615    let DispSize = "12" in
616      def "" : StoreRX<mnemonic, rxOpcode, operator, cls, bytes, bdxaddr12pair>;
617    let DispSize = "20" in
618      def Y  : StoreRXY<mnemonic#"y", rxyOpcode, operator, cls, bytes,
619                        bdxaddr20pair>;
620  }
621}
622
623class StoreMultipleRSY<string mnemonic, bits<16> opcode, RegisterOperand cls>
624  : InstRSY<opcode, (outs), (ins cls:$R1, cls:$R3, bdaddr20only:$BD2),
625            mnemonic#"\t$R1, $R3, $BD2", []> {
626  let mayStore = 1;
627}
628
629class StoreSI<string mnemonic, bits<8> opcode, SDPatternOperator operator,
630              Immediate imm, AddressingMode mode = bdaddr12only>
631  : InstSI<opcode, (outs), (ins mode:$BD1, imm:$I2),
632           mnemonic#"\t$BD1, $I2",
633           [(operator imm:$I2, mode:$BD1)]> {
634  let mayStore = 1;
635}
636
637class StoreSIY<string mnemonic, bits<16> opcode, SDPatternOperator operator,
638               Immediate imm, AddressingMode mode = bdaddr20only>
639  : InstSIY<opcode, (outs), (ins mode:$BD1, imm:$I2),
640            mnemonic#"\t$BD1, $I2",
641            [(operator imm:$I2, mode:$BD1)]> {
642  let mayStore = 1;
643}
644
645class StoreSIL<string mnemonic, bits<16> opcode, SDPatternOperator operator,
646               Immediate imm>
647  : InstSIL<opcode, (outs), (ins bdaddr12only:$BD1, imm:$I2),
648            mnemonic#"\t$BD1, $I2",
649            [(operator imm:$I2, bdaddr12only:$BD1)]> {
650  let mayStore = 1;
651}
652
653multiclass StoreSIPair<string mnemonic, bits<8> siOpcode, bits<16> siyOpcode,
654                       SDPatternOperator operator, Immediate imm> {
655  let DispKey = mnemonic in {
656    let DispSize = "12" in
657      def "" : StoreSI<mnemonic, siOpcode, operator, imm, bdaddr12pair>;
658    let DispSize = "20" in
659      def Y  : StoreSIY<mnemonic#"y", siyOpcode, operator, imm, bdaddr20pair>;
660  }
661}
662
663class CondStoreRSY<string mnemonic, bits<16> opcode,
664                   RegisterOperand cls, bits<5> bytes,
665                   AddressingMode mode = bdaddr20only>
666  : InstRSY<opcode, (outs), (ins cls:$R1, mode:$BD2, cond4:$valid, cond4:$R3),
667            mnemonic#"$R3\t$R1, $BD2", []>,
668    Requires<[FeatureLoadStoreOnCond]> {
669  let mayStore = 1;
670  let AccessBytes = bytes;
671  let CCMaskLast = 1;
672}
673
674// Like CondStoreRSY, but used for the raw assembly form.  The condition-code
675// mask is the third operand rather than being part of the mnemonic.
676class AsmCondStoreRSY<string mnemonic, bits<16> opcode,
677                      RegisterOperand cls, bits<5> bytes,
678                      AddressingMode mode = bdaddr20only>
679  : InstRSY<opcode, (outs), (ins cls:$R1, mode:$BD2, uimm8zx4:$R3),
680            mnemonic#"\t$R1, $BD2, $R3", []>,
681    Requires<[FeatureLoadStoreOnCond]> {
682  let mayStore = 1;
683  let AccessBytes = bytes;
684}
685
686// Like CondStoreRSY, but with a fixed CC mask.
687class FixedCondStoreRSY<string mnemonic, bits<16> opcode,
688                        RegisterOperand cls, bits<4> ccmask, bits<5> bytes,
689                        AddressingMode mode = bdaddr20only>
690  : InstRSY<opcode, (outs), (ins cls:$R1, mode:$BD2),
691            mnemonic#"\t$R1, $BD2", []>,
692    Requires<[FeatureLoadStoreOnCond]> {
693  let mayStore = 1;
694  let AccessBytes = bytes;
695  let R3 = ccmask;
696}
697
698class UnaryRR<string mnemonic, bits<8> opcode, SDPatternOperator operator,
699              RegisterOperand cls1, RegisterOperand cls2>
700  : InstRR<opcode, (outs cls1:$R1), (ins cls2:$R2),
701           mnemonic#"r\t$R1, $R2",
702           [(set cls1:$R1, (operator cls2:$R2))]> {
703  let OpKey = mnemonic ## cls1;
704  let OpType = "reg";
705}
706
707class UnaryRRE<string mnemonic, bits<16> opcode, SDPatternOperator operator,
708               RegisterOperand cls1, RegisterOperand cls2>
709  : InstRRE<opcode, (outs cls1:$R1), (ins cls2:$R2),
710            mnemonic#"r\t$R1, $R2",
711            [(set cls1:$R1, (operator cls2:$R2))]> {
712  let OpKey = mnemonic ## cls1;
713  let OpType = "reg";
714}
715
716class UnaryRRF<string mnemonic, bits<16> opcode, RegisterOperand cls1,
717               RegisterOperand cls2>
718  : InstRRF<opcode, (outs cls1:$R1), (ins uimm8zx4:$R3, cls2:$R2),
719            mnemonic#"r\t$R1, $R3, $R2", []> {
720  let OpKey = mnemonic ## cls1;
721  let OpType = "reg";
722}
723
724// These instructions are generated by if conversion.  The old value of R1
725// is added as an implicit use.
726class CondUnaryRRF<string mnemonic, bits<16> opcode, RegisterOperand cls1,
727                   RegisterOperand cls2>
728  : InstRRF<opcode, (outs cls1:$R1), (ins cls2:$R2, cond4:$valid, cond4:$R3),
729            mnemonic#"r$R3\t$R1, $R2", []>,
730    Requires<[FeatureLoadStoreOnCond]> {
731  let CCMaskLast = 1;
732}
733
734// Like CondUnaryRRF, but used for the raw assembly form.  The condition-code
735// mask is the third operand rather than being part of the mnemonic.
736class AsmCondUnaryRRF<string mnemonic, bits<16> opcode, RegisterOperand cls1,
737                      RegisterOperand cls2>
738  : InstRRF<opcode, (outs cls1:$R1), (ins cls1:$R1src, cls2:$R2, uimm8zx4:$R3),
739            mnemonic#"r\t$R1, $R2, $R3", []>,
740    Requires<[FeatureLoadStoreOnCond]> {
741  let Constraints = "$R1 = $R1src";
742  let DisableEncoding = "$R1src";
743}
744
745// Like CondUnaryRRF, but with a fixed CC mask.
746class FixedCondUnaryRRF<string mnemonic, bits<16> opcode, RegisterOperand cls1,
747                        RegisterOperand cls2, bits<4> ccmask>
748  : InstRRF<opcode, (outs cls1:$R1), (ins cls1:$R1src, cls2:$R2),
749            mnemonic#"\t$R1, $R2", []>,
750    Requires<[FeatureLoadStoreOnCond]> {
751  let Constraints = "$R1 = $R1src";
752  let DisableEncoding = "$R1src";
753  let R3 = ccmask;
754}
755
756class UnaryRI<string mnemonic, bits<12> opcode, SDPatternOperator operator,
757              RegisterOperand cls, Immediate imm>
758  : InstRI<opcode, (outs cls:$R1), (ins imm:$I2),
759           mnemonic#"\t$R1, $I2",
760           [(set cls:$R1, (operator imm:$I2))]>;
761
762class UnaryRIL<string mnemonic, bits<12> opcode, SDPatternOperator operator,
763               RegisterOperand cls, Immediate imm>
764  : InstRIL<opcode, (outs cls:$R1), (ins imm:$I2),
765            mnemonic#"\t$R1, $I2",
766            [(set cls:$R1, (operator imm:$I2))]>;
767
768class UnaryRILPC<string mnemonic, bits<12> opcode, SDPatternOperator operator,
769                 RegisterOperand cls>
770  : InstRIL<opcode, (outs cls:$R1), (ins pcrel32:$I2),
771            mnemonic#"\t$R1, $I2",
772            [(set cls:$R1, (operator pcrel32:$I2))]> {
773  let mayLoad = 1;
774  // We want PC-relative addresses to be tried ahead of BD and BDX addresses.
775  // However, BDXs have two extra operands and are therefore 6 units more
776  // complex.
777  let AddedComplexity = 7;
778}
779
780class CondUnaryRSY<string mnemonic, bits<16> opcode,
781                   SDPatternOperator operator, RegisterOperand cls,
782                   bits<5> bytes, AddressingMode mode = bdaddr20only>
783  : InstRSY<opcode, (outs cls:$R1),
784            (ins cls:$R1src, mode:$BD2, cond4:$valid, cond4:$R3),
785            mnemonic#"$R3\t$R1, $BD2",
786            [(set cls:$R1,
787                  (z_select_ccmask (load bdaddr20only:$BD2), cls:$R1src,
788                                   cond4:$valid, cond4:$R3))]>,
789    Requires<[FeatureLoadStoreOnCond]> {
790  let Constraints = "$R1 = $R1src";
791  let DisableEncoding = "$R1src";
792  let mayLoad = 1;
793  let AccessBytes = bytes;
794  let CCMaskLast = 1;
795}
796
797// Like CondUnaryRSY, but used for the raw assembly form.  The condition-code
798// mask is the third operand rather than being part of the mnemonic.
799class AsmCondUnaryRSY<string mnemonic, bits<16> opcode,
800                      RegisterOperand cls, bits<5> bytes,
801                      AddressingMode mode = bdaddr20only>
802  : InstRSY<opcode, (outs cls:$R1), (ins cls:$R1src, mode:$BD2, uimm8zx4:$R3),
803            mnemonic#"\t$R1, $BD2, $R3", []>,
804    Requires<[FeatureLoadStoreOnCond]> {
805  let mayLoad = 1;
806  let AccessBytes = bytes;
807  let Constraints = "$R1 = $R1src";
808  let DisableEncoding = "$R1src";
809}
810
811// Like CondUnaryRSY, but with a fixed CC mask.
812class FixedCondUnaryRSY<string mnemonic, bits<16> opcode,
813                        RegisterOperand cls, bits<4> ccmask, bits<5> bytes,
814                        AddressingMode mode = bdaddr20only>
815  : InstRSY<opcode, (outs cls:$R1), (ins cls:$R1src, mode:$BD2),
816            mnemonic#"\t$R1, $BD2", []>,
817    Requires<[FeatureLoadStoreOnCond]> {
818  let Constraints = "$R1 = $R1src";
819  let DisableEncoding = "$R1src";
820  let R3 = ccmask;
821  let mayLoad = 1;
822  let AccessBytes = bytes;
823}
824
825class UnaryRX<string mnemonic, bits<8> opcode, SDPatternOperator operator,
826              RegisterOperand cls, bits<5> bytes,
827              AddressingMode mode = bdxaddr12only>
828  : InstRX<opcode, (outs cls:$R1), (ins mode:$XBD2),
829           mnemonic#"\t$R1, $XBD2",
830           [(set cls:$R1, (operator mode:$XBD2))]> {
831  let OpKey = mnemonic ## cls;
832  let OpType = "mem";
833  let mayLoad = 1;
834  let AccessBytes = bytes;
835}
836
837class UnaryRXE<string mnemonic, bits<16> opcode, SDPatternOperator operator,
838               RegisterOperand cls, bits<5> bytes>
839  : InstRXE<opcode, (outs cls:$R1), (ins bdxaddr12only:$XBD2),
840            mnemonic#"\t$R1, $XBD2",
841            [(set cls:$R1, (operator bdxaddr12only:$XBD2))]> {
842  let OpKey = mnemonic ## cls;
843  let OpType = "mem";
844  let mayLoad = 1;
845  let AccessBytes = bytes;
846}
847
848class UnaryRXY<string mnemonic, bits<16> opcode, SDPatternOperator operator,
849               RegisterOperand cls, bits<5> bytes,
850               AddressingMode mode = bdxaddr20only>
851  : InstRXY<opcode, (outs cls:$R1), (ins mode:$XBD2),
852            mnemonic#"\t$R1, $XBD2",
853            [(set cls:$R1, (operator mode:$XBD2))]> {
854  let OpKey = mnemonic ## cls;
855  let OpType = "mem";
856  let mayLoad = 1;
857  let AccessBytes = bytes;
858}
859
860multiclass UnaryRXPair<string mnemonic, bits<8> rxOpcode, bits<16> rxyOpcode,
861                       SDPatternOperator operator, RegisterOperand cls,
862                       bits<5> bytes> {
863  let DispKey = mnemonic ## #cls in {
864    let DispSize = "12" in
865      def "" : UnaryRX<mnemonic, rxOpcode, operator, cls, bytes, bdxaddr12pair>;
866    let DispSize = "20" in
867      def Y  : UnaryRXY<mnemonic#"y", rxyOpcode, operator, cls, bytes,
868                        bdxaddr20pair>;
869  }
870}
871
872class BinaryRR<string mnemonic, bits<8> opcode, SDPatternOperator operator,
873               RegisterOperand cls1, RegisterOperand cls2>
874  : InstRR<opcode, (outs cls1:$R1), (ins cls1:$R1src, cls2:$R2),
875           mnemonic#"r\t$R1, $R2",
876           [(set cls1:$R1, (operator cls1:$R1src, cls2:$R2))]> {
877  let OpKey = mnemonic ## cls1;
878  let OpType = "reg";
879  let Constraints = "$R1 = $R1src";
880  let DisableEncoding = "$R1src";
881}
882
883class BinaryRRE<string mnemonic, bits<16> opcode, SDPatternOperator operator,
884                RegisterOperand cls1, RegisterOperand cls2>
885  : InstRRE<opcode, (outs cls1:$R1), (ins cls1:$R1src, cls2:$R2),
886            mnemonic#"r\t$R1, $R2",
887            [(set cls1:$R1, (operator cls1:$R1src, cls2:$R2))]> {
888  let OpKey = mnemonic ## cls1;
889  let OpType = "reg";
890  let Constraints = "$R1 = $R1src";
891  let DisableEncoding = "$R1src";
892}
893
894class BinaryRRF<string mnemonic, bits<16> opcode, SDPatternOperator operator,
895                RegisterOperand cls1, RegisterOperand cls2>
896  : InstRRF<opcode, (outs cls1:$R1), (ins cls1:$R3, cls2:$R2),
897            mnemonic#"r\t$R1, $R3, $R2",
898            [(set cls1:$R1, (operator cls1:$R3, cls2:$R2))]> {
899  let OpKey = mnemonic ## cls1;
900  let OpType = "reg";
901}
902
903class BinaryRRFK<string mnemonic, bits<16> opcode, SDPatternOperator operator,
904                 RegisterOperand cls1, RegisterOperand cls2>
905  : InstRRF<opcode, (outs cls1:$R1), (ins cls1:$R2, cls2:$R3),
906            mnemonic#"rk\t$R1, $R2, $R3",
907            [(set cls1:$R1, (operator cls1:$R2, cls2:$R3))]>;
908
909multiclass BinaryRRAndK<string mnemonic, bits<8> opcode1, bits<16> opcode2,
910                        SDPatternOperator operator, RegisterOperand cls1,
911                        RegisterOperand cls2> {
912  let NumOpsKey = mnemonic in {
913    let NumOpsValue = "3" in
914      def K : BinaryRRFK<mnemonic, opcode2, null_frag, cls1, cls2>,
915              Requires<[FeatureDistinctOps]>;
916    let NumOpsValue = "2", isConvertibleToThreeAddress = 1 in
917      def "" : BinaryRR<mnemonic, opcode1, operator, cls1, cls2>;
918  }
919}
920
921multiclass BinaryRREAndK<string mnemonic, bits<16> opcode1, bits<16> opcode2,
922                         SDPatternOperator operator, RegisterOperand cls1,
923                         RegisterOperand cls2> {
924  let NumOpsKey = mnemonic in {
925    let NumOpsValue = "3" in
926      def K : BinaryRRFK<mnemonic, opcode2, null_frag, cls1, cls2>,
927              Requires<[FeatureDistinctOps]>;
928    let NumOpsValue = "2", isConvertibleToThreeAddress = 1 in
929      def "" : BinaryRRE<mnemonic, opcode1, operator, cls1, cls2>;
930  }
931}
932
933class BinaryRI<string mnemonic, bits<12> opcode, SDPatternOperator operator,
934               RegisterOperand cls, Immediate imm>
935  : InstRI<opcode, (outs cls:$R1), (ins cls:$R1src, imm:$I2),
936           mnemonic#"\t$R1, $I2",
937           [(set cls:$R1, (operator cls:$R1src, imm:$I2))]> {
938  let Constraints = "$R1 = $R1src";
939  let DisableEncoding = "$R1src";
940}
941
942class BinaryRIE<string mnemonic, bits<16> opcode, SDPatternOperator operator,
943                RegisterOperand cls, Immediate imm>
944  : InstRIEd<opcode, (outs cls:$R1), (ins cls:$R3, imm:$I2),
945             mnemonic#"\t$R1, $R3, $I2",
946             [(set cls:$R1, (operator cls:$R3, imm:$I2))]>;
947
948multiclass BinaryRIAndK<string mnemonic, bits<12> opcode1, bits<16> opcode2,
949                        SDPatternOperator operator, RegisterOperand cls,
950                        Immediate imm> {
951  let NumOpsKey = mnemonic in {
952    let NumOpsValue = "3" in
953      def K : BinaryRIE<mnemonic##"k", opcode2, null_frag, cls, imm>,
954              Requires<[FeatureDistinctOps]>;
955    let NumOpsValue = "2", isConvertibleToThreeAddress = 1 in
956      def "" : BinaryRI<mnemonic, opcode1, operator, cls, imm>;
957  }
958}
959
960class BinaryRIL<string mnemonic, bits<12> opcode, SDPatternOperator operator,
961                RegisterOperand cls, Immediate imm>
962  : InstRIL<opcode, (outs cls:$R1), (ins cls:$R1src, imm:$I2),
963            mnemonic#"\t$R1, $I2",
964            [(set cls:$R1, (operator cls:$R1src, imm:$I2))]> {
965  let Constraints = "$R1 = $R1src";
966  let DisableEncoding = "$R1src";
967}
968
969class BinaryRX<string mnemonic, bits<8> opcode, SDPatternOperator operator,
970               RegisterOperand cls, SDPatternOperator load, bits<5> bytes,
971               AddressingMode mode = bdxaddr12only>
972  : InstRX<opcode, (outs cls:$R1), (ins cls:$R1src, mode:$XBD2),
973           mnemonic#"\t$R1, $XBD2",
974           [(set cls:$R1, (operator cls:$R1src, (load mode:$XBD2)))]> {
975  let OpKey = mnemonic ## cls;
976  let OpType = "mem";
977  let Constraints = "$R1 = $R1src";
978  let DisableEncoding = "$R1src";
979  let mayLoad = 1;
980  let AccessBytes = bytes;
981}
982
983class BinaryRXE<string mnemonic, bits<16> opcode, SDPatternOperator operator,
984                  RegisterOperand cls, SDPatternOperator load, bits<5> bytes>
985  : InstRXE<opcode, (outs cls:$R1), (ins cls:$R1src, bdxaddr12only:$XBD2),
986            mnemonic#"\t$R1, $XBD2",
987            [(set cls:$R1, (operator cls:$R1src,
988                                     (load bdxaddr12only:$XBD2)))]> {
989  let OpKey = mnemonic ## cls;
990  let OpType = "mem";
991  let Constraints = "$R1 = $R1src";
992  let DisableEncoding = "$R1src";
993  let mayLoad = 1;
994  let AccessBytes = bytes;
995}
996
997class BinaryRXY<string mnemonic, bits<16> opcode, SDPatternOperator operator,
998                RegisterOperand cls, SDPatternOperator load, bits<5> bytes,
999                AddressingMode mode = bdxaddr20only>
1000  : InstRXY<opcode, (outs cls:$R1), (ins cls:$R1src, mode:$XBD2),
1001            mnemonic#"\t$R1, $XBD2",
1002            [(set cls:$R1, (operator cls:$R1src, (load mode:$XBD2)))]> {
1003  let OpKey = mnemonic ## cls;
1004  let OpType = "mem";
1005  let Constraints = "$R1 = $R1src";
1006  let DisableEncoding = "$R1src";
1007  let mayLoad = 1;
1008  let AccessBytes = bytes;
1009}
1010
1011multiclass BinaryRXPair<string mnemonic, bits<8> rxOpcode, bits<16> rxyOpcode,
1012                        SDPatternOperator operator, RegisterOperand cls,
1013                        SDPatternOperator load, bits<5> bytes> {
1014  let DispKey = mnemonic ## #cls in {
1015    let DispSize = "12" in
1016      def "" : BinaryRX<mnemonic, rxOpcode, operator, cls, load, bytes,
1017                        bdxaddr12pair>;
1018    let DispSize = "20" in
1019      def Y  : BinaryRXY<mnemonic#"y", rxyOpcode, operator, cls, load, bytes,
1020                         bdxaddr20pair>;
1021  }
1022}
1023
1024class BinarySI<string mnemonic, bits<8> opcode, SDPatternOperator operator,
1025               Operand imm, AddressingMode mode = bdaddr12only>
1026  : InstSI<opcode, (outs), (ins mode:$BD1, imm:$I2),
1027           mnemonic#"\t$BD1, $I2",
1028           [(store (operator (load mode:$BD1), imm:$I2), mode:$BD1)]> {
1029  let mayLoad = 1;
1030  let mayStore = 1;
1031}
1032
1033class BinarySIY<string mnemonic, bits<16> opcode, SDPatternOperator operator,
1034                Operand imm, AddressingMode mode = bdaddr20only>
1035  : InstSIY<opcode, (outs), (ins mode:$BD1, imm:$I2),
1036            mnemonic#"\t$BD1, $I2",
1037            [(store (operator (load mode:$BD1), imm:$I2), mode:$BD1)]> {
1038  let mayLoad = 1;
1039  let mayStore = 1;
1040}
1041
1042multiclass BinarySIPair<string mnemonic, bits<8> siOpcode,
1043                        bits<16> siyOpcode, SDPatternOperator operator,
1044                        Operand imm> {
1045  let DispKey = mnemonic ## #cls in {
1046    let DispSize = "12" in
1047      def "" : BinarySI<mnemonic, siOpcode, operator, imm, bdaddr12pair>;
1048    let DispSize = "20" in
1049      def Y  : BinarySIY<mnemonic#"y", siyOpcode, operator, imm, bdaddr20pair>;
1050  }
1051}
1052
1053class ShiftRS<string mnemonic, bits<8> opcode, SDPatternOperator operator,
1054              RegisterOperand cls>
1055  : InstRS<opcode, (outs cls:$R1), (ins cls:$R1src, shift12only:$BD2),
1056           mnemonic#"\t$R1, $BD2",
1057           [(set cls:$R1, (operator cls:$R1src, shift12only:$BD2))]> {
1058  let R3 = 0;
1059  let Constraints = "$R1 = $R1src";
1060  let DisableEncoding = "$R1src";
1061}
1062
1063class ShiftRSY<string mnemonic, bits<16> opcode, SDPatternOperator operator,
1064               RegisterOperand cls>
1065  : InstRSY<opcode, (outs cls:$R1), (ins cls:$R3, shift20only:$BD2),
1066            mnemonic#"\t$R1, $R3, $BD2",
1067            [(set cls:$R1, (operator cls:$R3, shift20only:$BD2))]>;
1068
1069multiclass ShiftRSAndK<string mnemonic, bits<8> opcode1, bits<16> opcode2,
1070                       SDPatternOperator operator, RegisterOperand cls> {
1071  let NumOpsKey = mnemonic in {
1072    let NumOpsValue = "3" in
1073      def K  : ShiftRSY<mnemonic##"k", opcode2, null_frag, cls>,
1074               Requires<[FeatureDistinctOps]>;
1075    let NumOpsValue = "2", isConvertibleToThreeAddress = 1 in
1076      def "" : ShiftRS<mnemonic, opcode1, operator, cls>;
1077  }
1078}
1079
1080class CompareRR<string mnemonic, bits<8> opcode, SDPatternOperator operator,
1081                RegisterOperand cls1, RegisterOperand cls2>
1082  : InstRR<opcode, (outs), (ins cls1:$R1, cls2:$R2),
1083           mnemonic#"r\t$R1, $R2",
1084           [(operator cls1:$R1, cls2:$R2)]> {
1085  let OpKey = mnemonic ## cls1;
1086  let OpType = "reg";
1087  let isCompare = 1;
1088}
1089
1090class CompareRRE<string mnemonic, bits<16> opcode, SDPatternOperator operator,
1091                 RegisterOperand cls1, RegisterOperand cls2>
1092  : InstRRE<opcode, (outs), (ins cls1:$R1, cls2:$R2),
1093            mnemonic#"r\t$R1, $R2",
1094            [(operator cls1:$R1, cls2:$R2)]> {
1095  let OpKey = mnemonic ## cls1;
1096  let OpType = "reg";
1097  let isCompare = 1;
1098}
1099
1100class CompareRI<string mnemonic, bits<12> opcode, SDPatternOperator operator,
1101                RegisterOperand cls, Immediate imm>
1102  : InstRI<opcode, (outs), (ins cls:$R1, imm:$I2),
1103           mnemonic#"\t$R1, $I2",
1104           [(operator cls:$R1, imm:$I2)]> {
1105  let isCompare = 1;
1106}
1107
1108class CompareRIL<string mnemonic, bits<12> opcode, SDPatternOperator operator,
1109                 RegisterOperand cls, Immediate imm>
1110  : InstRIL<opcode, (outs), (ins cls:$R1, imm:$I2),
1111            mnemonic#"\t$R1, $I2",
1112            [(operator cls:$R1, imm:$I2)]> {
1113  let isCompare = 1;
1114}
1115
1116class CompareRILPC<string mnemonic, bits<12> opcode, SDPatternOperator operator,
1117                   RegisterOperand cls, SDPatternOperator load>
1118  : InstRIL<opcode, (outs), (ins cls:$R1, pcrel32:$I2),
1119            mnemonic#"\t$R1, $I2",
1120            [(operator cls:$R1, (load pcrel32:$I2))]> {
1121  let isCompare = 1;
1122  let mayLoad = 1;
1123  // We want PC-relative addresses to be tried ahead of BD and BDX addresses.
1124  // However, BDXs have two extra operands and are therefore 6 units more
1125  // complex.
1126  let AddedComplexity = 7;
1127}
1128
1129class CompareRX<string mnemonic, bits<8> opcode, SDPatternOperator operator,
1130                RegisterOperand cls, SDPatternOperator load, bits<5> bytes,
1131                AddressingMode mode = bdxaddr12only>
1132  : InstRX<opcode, (outs), (ins cls:$R1, mode:$XBD2),
1133           mnemonic#"\t$R1, $XBD2",
1134           [(operator cls:$R1, (load mode:$XBD2))]> {
1135  let OpKey = mnemonic ## cls;
1136  let OpType = "mem";
1137  let isCompare = 1;
1138  let mayLoad = 1;
1139  let AccessBytes = bytes;
1140}
1141
1142class CompareRXE<string mnemonic, bits<16> opcode, SDPatternOperator operator,
1143                 RegisterOperand cls, SDPatternOperator load, bits<5> bytes>
1144  : InstRXE<opcode, (outs), (ins cls:$R1, bdxaddr12only:$XBD2),
1145            mnemonic#"\t$R1, $XBD2",
1146            [(operator cls:$R1, (load bdxaddr12only:$XBD2))]> {
1147  let OpKey = mnemonic ## cls;
1148  let OpType = "mem";
1149  let isCompare = 1;
1150  let mayLoad = 1;
1151  let AccessBytes = bytes;
1152}
1153
1154class CompareRXY<string mnemonic, bits<16> opcode, SDPatternOperator operator,
1155                 RegisterOperand cls, SDPatternOperator load, bits<5> bytes,
1156                 AddressingMode mode = bdxaddr20only>
1157  : InstRXY<opcode, (outs), (ins cls:$R1, mode:$XBD2),
1158            mnemonic#"\t$R1, $XBD2",
1159            [(operator cls:$R1, (load mode:$XBD2))]> {
1160  let OpKey = mnemonic ## cls;
1161  let OpType = "mem";
1162  let isCompare = 1;
1163  let mayLoad = 1;
1164  let AccessBytes = bytes;
1165}
1166
1167multiclass CompareRXPair<string mnemonic, bits<8> rxOpcode, bits<16> rxyOpcode,
1168                         SDPatternOperator operator, RegisterOperand cls,
1169                         SDPatternOperator load, bits<5> bytes> {
1170  let DispKey = mnemonic ## #cls in {
1171    let DispSize = "12" in
1172      def "" : CompareRX<mnemonic, rxOpcode, operator, cls,
1173                         load, bytes, bdxaddr12pair>;
1174    let DispSize = "20" in
1175      def Y  : CompareRXY<mnemonic#"y", rxyOpcode, operator, cls,
1176                          load, bytes, bdxaddr20pair>;
1177  }
1178}
1179
1180class CompareSI<string mnemonic, bits<8> opcode, SDPatternOperator operator,
1181                SDPatternOperator load, Immediate imm,
1182                AddressingMode mode = bdaddr12only>
1183  : InstSI<opcode, (outs), (ins mode:$BD1, imm:$I2),
1184           mnemonic#"\t$BD1, $I2",
1185           [(operator (load mode:$BD1), imm:$I2)]> {
1186  let isCompare = 1;
1187  let mayLoad = 1;
1188}
1189
1190class CompareSIL<string mnemonic, bits<16> opcode, SDPatternOperator operator,
1191                 SDPatternOperator load, Immediate imm>
1192  : InstSIL<opcode, (outs), (ins bdaddr12only:$BD1, imm:$I2),
1193            mnemonic#"\t$BD1, $I2",
1194            [(operator (load bdaddr12only:$BD1), imm:$I2)]> {
1195  let isCompare = 1;
1196  let mayLoad = 1;
1197}
1198
1199class CompareSIY<string mnemonic, bits<16> opcode, SDPatternOperator operator,
1200                 SDPatternOperator load, Immediate imm,
1201                 AddressingMode mode = bdaddr20only>
1202  : InstSIY<opcode, (outs), (ins mode:$BD1, imm:$I2),
1203            mnemonic#"\t$BD1, $I2",
1204            [(operator (load mode:$BD1), imm:$I2)]> {
1205  let isCompare = 1;
1206  let mayLoad = 1;
1207}
1208
1209multiclass CompareSIPair<string mnemonic, bits<8> siOpcode, bits<16> siyOpcode,
1210                         SDPatternOperator operator, SDPatternOperator load,
1211                         Immediate imm> {
1212  let DispKey = mnemonic in {
1213    let DispSize = "12" in
1214      def "" : CompareSI<mnemonic, siOpcode, operator, load, imm, bdaddr12pair>;
1215    let DispSize = "20" in
1216      def Y  : CompareSIY<mnemonic#"y", siyOpcode, operator, load, imm,
1217                          bdaddr20pair>;
1218  }
1219}
1220
1221class TernaryRRD<string mnemonic, bits<16> opcode,
1222                 SDPatternOperator operator, RegisterOperand cls>
1223  : InstRRD<opcode, (outs cls:$R1), (ins cls:$R1src, cls:$R3, cls:$R2),
1224            mnemonic#"r\t$R1, $R3, $R2",
1225            [(set cls:$R1, (operator cls:$R1src, cls:$R3, cls:$R2))]> {
1226  let OpKey = mnemonic ## cls;
1227  let OpType = "reg";
1228  let Constraints = "$R1 = $R1src";
1229  let DisableEncoding = "$R1src";
1230}
1231
1232class TernaryRXF<string mnemonic, bits<16> opcode, SDPatternOperator operator,
1233                 RegisterOperand cls, SDPatternOperator load, bits<5> bytes>
1234  : InstRXF<opcode, (outs cls:$R1),
1235            (ins cls:$R1src, cls:$R3, bdxaddr12only:$XBD2),
1236            mnemonic#"\t$R1, $R3, $XBD2",
1237            [(set cls:$R1, (operator cls:$R1src, cls:$R3,
1238                                     (load bdxaddr12only:$XBD2)))]> {
1239  let OpKey = mnemonic ## cls;
1240  let OpType = "mem";
1241  let Constraints = "$R1 = $R1src";
1242  let DisableEncoding = "$R1src";
1243  let mayLoad = 1;
1244  let AccessBytes = bytes;
1245}
1246
1247class CmpSwapRS<string mnemonic, bits<8> opcode, SDPatternOperator operator,
1248                RegisterOperand cls, AddressingMode mode = bdaddr12only>
1249  : InstRS<opcode, (outs cls:$R1), (ins cls:$R1src, cls:$R3, mode:$BD2),
1250           mnemonic#"\t$R1, $R3, $BD2",
1251           [(set cls:$R1, (operator mode:$BD2, cls:$R1src, cls:$R3))]> {
1252  let Constraints = "$R1 = $R1src";
1253  let DisableEncoding = "$R1src";
1254  let mayLoad = 1;
1255  let mayStore = 1;
1256}
1257
1258class CmpSwapRSY<string mnemonic, bits<16> opcode, SDPatternOperator operator,
1259                 RegisterOperand cls, AddressingMode mode = bdaddr20only>
1260  : InstRSY<opcode, (outs cls:$R1), (ins cls:$R1src, cls:$R3, mode:$BD2),
1261            mnemonic#"\t$R1, $R3, $BD2",
1262            [(set cls:$R1, (operator mode:$BD2, cls:$R1src, cls:$R3))]> {
1263  let Constraints = "$R1 = $R1src";
1264  let DisableEncoding = "$R1src";
1265  let mayLoad = 1;
1266  let mayStore = 1;
1267}
1268
1269multiclass CmpSwapRSPair<string mnemonic, bits<8> rsOpcode, bits<16> rsyOpcode,
1270                         SDPatternOperator operator, RegisterOperand cls> {
1271  let DispKey = mnemonic ## #cls in {
1272    let DispSize = "12" in
1273      def "" : CmpSwapRS<mnemonic, rsOpcode, operator, cls, bdaddr12pair>;
1274    let DispSize = "20" in
1275      def Y  : CmpSwapRSY<mnemonic#"y", rsyOpcode, operator, cls, bdaddr20pair>;
1276  }
1277}
1278
1279class RotateSelectRIEf<string mnemonic, bits<16> opcode, RegisterOperand cls1,
1280                       RegisterOperand cls2>
1281  : InstRIEf<opcode, (outs cls1:$R1),
1282             (ins cls1:$R1src, cls2:$R2, uimm8:$I3, uimm8:$I4, uimm8zx6:$I5),
1283             mnemonic#"\t$R1, $R2, $I3, $I4, $I5", []> {
1284  let Constraints = "$R1 = $R1src";
1285  let DisableEncoding = "$R1src";
1286}
1287
1288// A floating-point load-and test operation.  Create both a normal unary
1289// operation and one that acts as a comparison against zero.
1290multiclass LoadAndTestRRE<string mnemonic, bits<16> opcode,
1291                          RegisterOperand cls> {
1292  def "" : UnaryRRE<mnemonic, opcode, null_frag, cls, cls>;
1293  let isCodeGenOnly = 1 in
1294    def Compare : CompareRRE<mnemonic, opcode, null_frag, cls, cls>;
1295}
1296
1297//===----------------------------------------------------------------------===//
1298// Pseudo instructions
1299//===----------------------------------------------------------------------===//
1300//
1301// Convenience instructions that get lowered to real instructions
1302// by either SystemZTargetLowering::EmitInstrWithCustomInserter()
1303// or SystemZInstrInfo::expandPostRAPseudo().
1304//
1305//===----------------------------------------------------------------------===//
1306
1307class Pseudo<dag outs, dag ins, list<dag> pattern>
1308  : InstSystemZ<0, outs, ins, "", pattern> {
1309  let isPseudo = 1;
1310  let isCodeGenOnly = 1;
1311}
1312
1313// Implements "$dst = $cc & (8 >> CC) ? $src1 : $src2", where CC is
1314// the value of the PSW's 2-bit condition code field.
1315class SelectWrapper<RegisterOperand cls>
1316  : Pseudo<(outs cls:$dst),
1317           (ins cls:$src1, cls:$src2, uimm8zx4:$valid, uimm8zx4:$cc),
1318           [(set cls:$dst, (z_select_ccmask cls:$src1, cls:$src2,
1319                                            uimm8zx4:$valid, uimm8zx4:$cc))]> {
1320  let usesCustomInserter = 1;
1321  // Although the instructions used by these nodes do not in themselves
1322  // change CC, the insertion requires new blocks, and CC cannot be live
1323  // across them.
1324  let Defs = [CC];
1325  let Uses = [CC];
1326}
1327
1328// Stores $new to $addr if $cc is true ("" case) or false (Inv case).
1329multiclass CondStores<RegisterOperand cls, SDPatternOperator store,
1330                      SDPatternOperator load, AddressingMode mode> {
1331  let Defs = [CC], Uses = [CC], usesCustomInserter = 1 in {
1332    def "" : Pseudo<(outs),
1333                    (ins cls:$new, mode:$addr, uimm8zx4:$valid, uimm8zx4:$cc),
1334                    [(store (z_select_ccmask cls:$new, (load mode:$addr),
1335                                             uimm8zx4:$valid, uimm8zx4:$cc),
1336                            mode:$addr)]>;
1337    def Inv : Pseudo<(outs),
1338                     (ins cls:$new, mode:$addr, uimm8zx4:$valid, uimm8zx4:$cc),
1339                     [(store (z_select_ccmask (load mode:$addr), cls:$new,
1340                                              uimm8zx4:$valid, uimm8zx4:$cc),
1341                              mode:$addr)]>;
1342  }
1343}
1344
1345// OPERATOR is ATOMIC_SWAP or an ATOMIC_LOAD_* operation.  PAT and OPERAND
1346// describe the second (non-memory) operand.
1347class AtomicLoadBinary<SDPatternOperator operator, RegisterOperand cls,
1348                       dag pat, DAGOperand operand>
1349  : Pseudo<(outs cls:$dst), (ins bdaddr20only:$ptr, operand:$src2),
1350           [(set cls:$dst, (operator bdaddr20only:$ptr, pat))]> {
1351  let Defs = [CC];
1352  let Has20BitOffset = 1;
1353  let mayLoad = 1;
1354  let mayStore = 1;
1355  let usesCustomInserter = 1;
1356}
1357
1358// Specializations of AtomicLoadWBinary.
1359class AtomicLoadBinaryReg32<SDPatternOperator operator>
1360  : AtomicLoadBinary<operator, GR32, (i32 GR32:$src2), GR32>;
1361class AtomicLoadBinaryImm32<SDPatternOperator operator, Immediate imm>
1362  : AtomicLoadBinary<operator, GR32, (i32 imm:$src2), imm>;
1363class AtomicLoadBinaryReg64<SDPatternOperator operator>
1364  : AtomicLoadBinary<operator, GR64, (i64 GR64:$src2), GR64>;
1365class AtomicLoadBinaryImm64<SDPatternOperator operator, Immediate imm>
1366  : AtomicLoadBinary<operator, GR64, (i64 imm:$src2), imm>;
1367
1368// OPERATOR is ATOMIC_SWAPW or an ATOMIC_LOADW_* operation.  PAT and OPERAND
1369// describe the second (non-memory) operand.
1370class AtomicLoadWBinary<SDPatternOperator operator, dag pat,
1371                        DAGOperand operand>
1372  : Pseudo<(outs GR32:$dst),
1373           (ins bdaddr20only:$ptr, operand:$src2, ADDR32:$bitshift,
1374                ADDR32:$negbitshift, uimm32:$bitsize),
1375           [(set GR32:$dst, (operator bdaddr20only:$ptr, pat, ADDR32:$bitshift,
1376                                      ADDR32:$negbitshift, uimm32:$bitsize))]> {
1377  let Defs = [CC];
1378  let Has20BitOffset = 1;
1379  let mayLoad = 1;
1380  let mayStore = 1;
1381  let usesCustomInserter = 1;
1382}
1383
1384// Specializations of AtomicLoadWBinary.
1385class AtomicLoadWBinaryReg<SDPatternOperator operator>
1386  : AtomicLoadWBinary<operator, (i32 GR32:$src2), GR32>;
1387class AtomicLoadWBinaryImm<SDPatternOperator operator, Immediate imm>
1388  : AtomicLoadWBinary<operator, (i32 imm:$src2), imm>;
1389