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