[SystemZ] Prefer LHI;ST... over LAY;MV...
[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   // 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.
103 def 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.
112 def 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.
121 def 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.
130 def 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
158 class 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
172 class 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
191 class 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
209 class 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
226 class 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
246 class 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
260 class 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
273 class 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
289 class 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
303 class 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   bits<4> R4;
312
313   let Inst{31-16} = op;
314   let Inst{15-12} = R3;
315   let Inst{11-8}  = R4;
316   let Inst{7-4}   = R1;
317   let Inst{3-0}   = R2;
318 }
319
320 class InstRX<bits<8> op, dag outs, dag ins, string asmstr, list<dag> pattern>
321   : InstSystemZ<4, outs, ins, asmstr, pattern> {
322   field bits<32> Inst;
323   field bits<32> SoftFail = 0;
324
325   bits<4> R1;
326   bits<20> XBD2;
327
328   let Inst{31-24} = op;
329   let Inst{23-20} = R1;
330   let Inst{19-0}  = XBD2;
331
332   let HasIndex = 1;
333 }
334
335 class InstRXE<bits<16> op, dag outs, dag ins, string asmstr, list<dag> pattern>
336   : InstSystemZ<6, outs, ins, asmstr, pattern> {
337   field bits<48> Inst;
338   field bits<48> SoftFail = 0;
339
340   bits<4> R1;
341   bits<20> XBD2;
342
343   let Inst{47-40} = op{15-8};
344   let Inst{39-36} = R1;
345   let Inst{35-16} = XBD2;
346   let Inst{15-8}  = 0;
347   let Inst{7-0}   = op{7-0};
348
349   let HasIndex = 1;
350 }
351
352 class InstRXF<bits<16> op, dag outs, dag ins, string asmstr, list<dag> pattern>
353   : InstSystemZ<6, outs, ins, asmstr, pattern> {
354   field bits<48> Inst;
355   field bits<48> SoftFail = 0;
356
357   bits<4> R1;
358   bits<4> R3;
359   bits<20> XBD2;
360
361   let Inst{47-40} = op{15-8};
362   let Inst{39-36} = R3;
363   let Inst{35-16} = XBD2;
364   let Inst{15-12} = R1;
365   let Inst{11-8}  = 0;
366   let Inst{7-0}   = op{7-0};
367
368   let HasIndex = 1;
369 }
370
371 class InstRXY<bits<16> op, dag outs, dag ins, string asmstr, list<dag> pattern>
372   : InstSystemZ<6, outs, ins, asmstr, pattern> {
373   field bits<48> Inst;
374   field bits<48> SoftFail = 0;
375
376   bits<4> R1;
377   bits<28> XBD2;
378
379   let Inst{47-40} = op{15-8};
380   let Inst{39-36} = R1;
381   let Inst{35-8}  = XBD2;
382   let Inst{7-0}   = op{7-0};
383
384   let Has20BitOffset = 1;
385   let HasIndex = 1;
386 }
387
388 class InstRS<bits<8> op, dag outs, dag ins, string asmstr, list<dag> pattern>
389   : InstSystemZ<4, outs, ins, asmstr, pattern> {
390   field bits<32> Inst;
391   field bits<32> SoftFail = 0;
392
393   bits<4> R1;
394   bits<4> R3;
395   bits<16> BD2;
396
397   let Inst{31-24} = op;
398   let Inst{23-20} = R1;
399   let Inst{19-16} = R3;
400   let Inst{15-0}  = BD2;
401 }
402
403 class InstRSY<bits<16> op, dag outs, dag ins, string asmstr, list<dag> pattern>
404   : InstSystemZ<6, outs, ins, asmstr, pattern> {
405   field bits<48> Inst;
406   field bits<48> SoftFail = 0;
407
408   bits<4> R1;
409   bits<4> R3;
410   bits<24> BD2;
411
412   let Inst{47-40} = op{15-8};
413   let Inst{39-36} = R1;
414   let Inst{35-32} = R3;
415   let Inst{31-8}  = BD2;
416   let Inst{7-0}   = op{7-0};
417
418   let Has20BitOffset = 1;
419 }
420
421 class InstSI<bits<8> op, dag outs, dag ins, string asmstr, list<dag> pattern>
422   : InstSystemZ<4, outs, ins, asmstr, pattern> {
423   field bits<32> Inst;
424   field bits<32> SoftFail = 0;
425
426   bits<16> BD1;
427   bits<8> I2;
428
429   let Inst{31-24} = op;
430   let Inst{23-16} = I2;
431   let Inst{15-0}  = BD1;
432 }
433
434 class InstSIL<bits<16> op, dag outs, dag ins, string asmstr, list<dag> pattern>
435   : InstSystemZ<6, outs, ins, asmstr, pattern> {
436   field bits<48> Inst;
437   field bits<48> SoftFail = 0;
438
439   bits<16> BD1;
440   bits<16> I2;
441
442   let Inst{47-32} = op;
443   let Inst{31-16} = BD1;
444   let Inst{15-0}  = I2;
445 }
446
447 class InstSIY<bits<16> op, dag outs, dag ins, string asmstr, list<dag> pattern>
448   : InstSystemZ<6, outs, ins, asmstr, pattern> {
449   field bits<48> Inst;
450   field bits<48> SoftFail = 0;
451
452   bits<24> BD1;
453   bits<8> I2;
454
455   let Inst{47-40} = op{15-8};
456   let Inst{39-32} = I2;
457   let Inst{31-8}  = BD1;
458   let Inst{7-0}   = op{7-0};
459
460   let Has20BitOffset = 1;
461 }
462
463 class InstSS<bits<8> op, dag outs, dag ins, string asmstr, list<dag> pattern>
464   : InstSystemZ<6, outs, ins, asmstr, pattern> {
465   field bits<48> Inst;
466   field bits<48> SoftFail = 0;
467
468   bits<24> BDL1;
469   bits<16> BD2;
470
471   let Inst{47-40} = op;
472   let Inst{39-16} = BDL1;
473   let Inst{15-0}  = BD2;
474 }
475
476 //===----------------------------------------------------------------------===//
477 // Instruction definitions with semantics
478 //===----------------------------------------------------------------------===//
479 //
480 // These classes have the form [Cond]<Category><Format>, where <Format> is one
481 // of the formats defined above and where <Category> describes the inputs
482 // and outputs.  "Cond" is used if the instruction is conditional,
483 // in which case the 4-bit condition-code mask is added as a final operand.
484 // <Category> can be one of:
485 //
486 //   Inherent:
487 //     One register output operand and no input operands.
488 //
489 //   BranchUnary:
490 //     One register output operand, one register input operand and
491 //     one branch displacement.  The instructions stores a modified
492 //     form of the source register in the destination register and
493 //     branches on the result.
494 //
495 //   Store:
496 //     One register or immediate input operand and one address input operand.
497 //     The instruction stores the first operand to the address.
498 //
499 //     This category is used for both pure and truncating stores.
500 //
501 //   LoadMultiple:
502 //     One address input operand and two explicit output operands.
503 //     The instruction loads a range of registers from the address,
504 //     with the explicit operands giving the first and last register
505 //     to load.  Other loaded registers are added as implicit definitions.
506 //
507 //   StoreMultiple:
508 //     Two explicit input register operands and an address operand.
509 //     The instruction stores a range of registers to the address,
510 //     with the explicit operands giving the first and last register
511 //     to store.  Other stored registers are added as implicit uses.
512 //
513 //   Unary:
514 //     One register output operand and one input operand.  The input
515 //     operand may be a register, immediate or memory.
516 //
517 //   Binary:
518 //     One register output operand and two input operands.  The first
519 //     input operand is always a register and he second may be a register,
520 //     immediate or memory.
521 //
522 //   Shift:
523 //     One register output operand and two input operands.  The first
524 //     input operand is a register and the second has the same form as
525 //     an address (although it isn't actually used to address memory).
526 //
527 //   Compare:
528 //     Two input operands.  The first operand is always a register,
529 //     the second may be a register, immediate or memory.
530 //
531 //   Ternary:
532 //     One register output operand and three register input operands.
533 //
534 //   CmpSwap:
535 //     One output operand and three input operands.  The first two
536 //     operands are registers and the third is an address.  The instruction
537 //     both reads from and writes to the address.
538 //
539 //   RotateSelect:
540 //     One output operand and five input operands.  The first two operands
541 //     are registers and the other three are immediates.
542 //
543 // The format determines which input operands are tied to output operands,
544 // and also determines the shape of any address operand.
545 //
546 // Multiclasses of the form <Category><Format>Pair define two instructions,
547 // one with <Category><Format> and one with <Category><Format>Y.  The name
548 // of the first instruction has no suffix, the name of the second has
549 // an extra "y".
550 //
551 //===----------------------------------------------------------------------===//
552
553 class InherentRRE<string mnemonic, bits<16> opcode, RegisterOperand cls,
554                   dag src>
555   : InstRRE<opcode, (outs cls:$R1), (ins),
556             mnemonic#"\t$R1",
557             [(set cls:$R1, src)]> {
558   let R2 = 0;
559 }
560
561 class BranchUnaryRI<string mnemonic, bits<12> opcode, RegisterOperand cls>
562   : InstRI<opcode, (outs cls:$R1), (ins cls:$R1src, brtarget16:$I2),
563            mnemonic##"\t$R1, $I2", []> {
564   let isBranch = 1;
565   let isTerminator = 1;
566   let Constraints = "$R1 = $R1src";
567   let DisableEncoding = "$R1src";
568 }
569
570 class LoadMultipleRSY<string mnemonic, bits<16> opcode, RegisterOperand cls>
571   : InstRSY<opcode, (outs cls:$R1, cls:$R3), (ins bdaddr20only:$BD2),
572             mnemonic#"\t$R1, $R3, $BD2", []> {
573   let mayLoad = 1;
574 }
575
576 class StoreRILPC<string mnemonic, bits<12> opcode, SDPatternOperator operator,
577                  RegisterOperand cls>
578   : InstRIL<opcode, (outs), (ins cls:$R1, pcrel32:$I2),
579             mnemonic#"\t$R1, $I2",
580             [(operator cls:$R1, pcrel32:$I2)]> {
581   let mayStore = 1;
582   // We want PC-relative addresses to be tried ahead of BD and BDX addresses.
583   // However, BDXs have two extra operands and are therefore 6 units more
584   // complex.
585   let AddedComplexity = 7;
586 }
587
588 class StoreRX<string mnemonic, bits<8> opcode, SDPatternOperator operator,
589               RegisterOperand cls, bits<5> bytes,
590               AddressingMode mode = bdxaddr12only>
591   : InstRX<opcode, (outs), (ins cls:$R1, mode:$XBD2),
592            mnemonic#"\t$R1, $XBD2",
593            [(operator cls:$R1, mode:$XBD2)]> {
594   let OpKey = mnemonic ## cls;
595   let OpType = "mem";
596   let mayStore = 1;
597   let AccessBytes = bytes;
598 }
599
600 class StoreRXY<string mnemonic, bits<16> opcode, SDPatternOperator operator,
601                RegisterOperand cls, bits<5> bytes,
602                AddressingMode mode = bdxaddr20only>
603   : InstRXY<opcode, (outs), (ins cls:$R1, mode:$XBD2),
604             mnemonic#"\t$R1, $XBD2",
605             [(operator cls:$R1, mode:$XBD2)]> {
606   let OpKey = mnemonic ## cls;
607   let OpType = "mem";
608   let mayStore = 1;
609   let AccessBytes = bytes;
610 }
611
612 multiclass StoreRXPair<string mnemonic, bits<8> rxOpcode, bits<16> rxyOpcode,
613                        SDPatternOperator operator, RegisterOperand cls,
614                        bits<5> bytes> {
615   let DispKey = mnemonic ## #cls in {
616     let DispSize = "12" in
617       def "" : StoreRX<mnemonic, rxOpcode, operator, cls, bytes, bdxaddr12pair>;
618     let DispSize = "20" in
619       def Y  : StoreRXY<mnemonic#"y", rxyOpcode, operator, cls, bytes,
620                         bdxaddr20pair>;
621   }
622 }
623
624 class StoreMultipleRSY<string mnemonic, bits<16> opcode, RegisterOperand cls>
625   : InstRSY<opcode, (outs), (ins cls:$R1, cls:$R3, bdaddr20only:$BD2),
626             mnemonic#"\t$R1, $R3, $BD2", []> {
627   let mayStore = 1;
628 }
629
630 // StoreSI* instructions are used to store an integer to memory, but the
631 // addresses are more restricted than for normal stores.  If we are in the
632 // situation of having to force either the address into a register or the
633 // constant into a register, it's usually better to do the latter.
634 // We therefore match the address in the same way as a normal store and
635 // only use the StoreSI* instruction if the matched address is suitable.
636 class StoreSI<string mnemonic, bits<8> opcode, SDPatternOperator operator,
637               Immediate imm>
638   : InstSI<opcode, (outs), (ins mviaddr12pair:$BD1, imm:$I2),
639            mnemonic#"\t$BD1, $I2",
640            [(operator imm:$I2, mviaddr12pair:$BD1)]> {
641   let mayStore = 1;
642 }
643
644 class StoreSIY<string mnemonic, bits<16> opcode, SDPatternOperator operator,
645                Immediate imm>
646   : InstSIY<opcode, (outs), (ins mviaddr20pair:$BD1, imm:$I2),
647             mnemonic#"\t$BD1, $I2",
648             [(operator imm:$I2, mviaddr20pair:$BD1)]> {
649   let mayStore = 1;
650 }
651
652 class StoreSIL<string mnemonic, bits<16> opcode, SDPatternOperator operator,
653                Immediate imm>
654   : InstSIL<opcode, (outs), (ins mviaddr12pair:$BD1, imm:$I2),
655             mnemonic#"\t$BD1, $I2",
656             [(operator imm:$I2, mviaddr12pair:$BD1)]> {
657   let mayStore = 1;
658 }
659
660 multiclass StoreSIPair<string mnemonic, bits<8> siOpcode, bits<16> siyOpcode,
661                        SDPatternOperator operator, Immediate imm> {
662   let DispKey = mnemonic in {
663     let DispSize = "12" in
664       def "" : StoreSI<mnemonic, siOpcode, operator, imm>;
665     let DispSize = "20" in
666       def Y  : StoreSIY<mnemonic#"y", siyOpcode, operator, imm>;
667   }
668 }
669
670 class CondStoreRSY<string mnemonic, bits<16> opcode,
671                    RegisterOperand cls, bits<5> bytes,
672                    AddressingMode mode = bdaddr20only>
673   : InstRSY<opcode, (outs), (ins cls:$R1, mode:$BD2, cond4:$valid, cond4:$R3),
674             mnemonic#"$R3\t$R1, $BD2", []>,
675     Requires<[FeatureLoadStoreOnCond]> {
676   let mayStore = 1;
677   let AccessBytes = bytes;
678   let CCMaskLast = 1;
679 }
680
681 // Like CondStoreRSY, but used for the raw assembly form.  The condition-code
682 // mask is the third operand rather than being part of the mnemonic.
683 class AsmCondStoreRSY<string mnemonic, bits<16> opcode,
684                       RegisterOperand cls, bits<5> bytes,
685                       AddressingMode mode = bdaddr20only>
686   : InstRSY<opcode, (outs), (ins cls:$R1, mode:$BD2, uimm8zx4:$R3),
687             mnemonic#"\t$R1, $BD2, $R3", []>,
688     Requires<[FeatureLoadStoreOnCond]> {
689   let mayStore = 1;
690   let AccessBytes = bytes;
691 }
692
693 // Like CondStoreRSY, but with a fixed CC mask.
694 class FixedCondStoreRSY<string mnemonic, bits<16> opcode,
695                         RegisterOperand cls, bits<4> ccmask, bits<5> bytes,
696                         AddressingMode mode = bdaddr20only>
697   : InstRSY<opcode, (outs), (ins cls:$R1, mode:$BD2),
698             mnemonic#"\t$R1, $BD2", []>,
699     Requires<[FeatureLoadStoreOnCond]> {
700   let mayStore = 1;
701   let AccessBytes = bytes;
702   let R3 = ccmask;
703 }
704
705 class UnaryRR<string mnemonic, bits<8> opcode, SDPatternOperator operator,
706               RegisterOperand cls1, RegisterOperand cls2>
707   : InstRR<opcode, (outs cls1:$R1), (ins cls2:$R2),
708            mnemonic#"r\t$R1, $R2",
709            [(set cls1:$R1, (operator cls2:$R2))]> {
710   let OpKey = mnemonic ## cls1;
711   let OpType = "reg";
712 }
713
714 class UnaryRRE<string mnemonic, bits<16> opcode, SDPatternOperator operator,
715                RegisterOperand cls1, RegisterOperand cls2>
716   : InstRRE<opcode, (outs cls1:$R1), (ins cls2:$R2),
717             mnemonic#"r\t$R1, $R2",
718             [(set cls1:$R1, (operator cls2:$R2))]> {
719   let OpKey = mnemonic ## cls1;
720   let OpType = "reg";
721 }
722
723 class UnaryRRF<string mnemonic, bits<16> opcode, RegisterOperand cls1,
724                RegisterOperand cls2>
725   : InstRRF<opcode, (outs cls1:$R1), (ins uimm8zx4:$R3, cls2:$R2),
726             mnemonic#"r\t$R1, $R3, $R2", []> {
727   let OpKey = mnemonic ## cls1;
728   let OpType = "reg";
729   let R4 = 0;
730 }
731
732 class UnaryRRF4<string mnemonic, bits<16> opcode, RegisterOperand cls1,
733                 RegisterOperand cls2>
734   : InstRRF<opcode, (outs cls1:$R1), (ins uimm8zx4:$R3, cls2:$R2, uimm8zx4:$R4),
735             mnemonic#"\t$R1, $R3, $R2, $R4", []>;
736
737 // These instructions are generated by if conversion.  The old value of R1
738 // is added as an implicit use.
739 class CondUnaryRRF<string mnemonic, bits<16> opcode, RegisterOperand cls1,
740                    RegisterOperand cls2>
741   : InstRRF<opcode, (outs cls1:$R1), (ins cls2:$R2, cond4:$valid, cond4:$R3),
742             mnemonic#"r$R3\t$R1, $R2", []>,
743     Requires<[FeatureLoadStoreOnCond]> {
744   let CCMaskLast = 1;
745   let R4 = 0;
746 }
747
748 // Like CondUnaryRRF, but used for the raw assembly form.  The condition-code
749 // mask is the third operand rather than being part of the mnemonic.
750 class AsmCondUnaryRRF<string mnemonic, bits<16> opcode, RegisterOperand cls1,
751                       RegisterOperand cls2>
752   : InstRRF<opcode, (outs cls1:$R1), (ins cls1:$R1src, cls2:$R2, uimm8zx4:$R3),
753             mnemonic#"r\t$R1, $R2, $R3", []>,
754     Requires<[FeatureLoadStoreOnCond]> {
755   let Constraints = "$R1 = $R1src";
756   let DisableEncoding = "$R1src";
757   let R4 = 0;
758 }
759
760 // Like CondUnaryRRF, but with a fixed CC mask.
761 class FixedCondUnaryRRF<string mnemonic, bits<16> opcode, RegisterOperand cls1,
762                         RegisterOperand cls2, bits<4> ccmask>
763   : InstRRF<opcode, (outs cls1:$R1), (ins cls1:$R1src, cls2:$R2),
764             mnemonic#"\t$R1, $R2", []>,
765     Requires<[FeatureLoadStoreOnCond]> {
766   let Constraints = "$R1 = $R1src";
767   let DisableEncoding = "$R1src";
768   let R3 = ccmask;
769   let R4 = 0;
770 }
771
772 class UnaryRI<string mnemonic, bits<12> opcode, SDPatternOperator operator,
773               RegisterOperand cls, Immediate imm>
774   : InstRI<opcode, (outs cls:$R1), (ins imm:$I2),
775            mnemonic#"\t$R1, $I2",
776            [(set cls:$R1, (operator imm:$I2))]>;
777
778 class UnaryRIL<string mnemonic, bits<12> opcode, SDPatternOperator operator,
779                RegisterOperand cls, Immediate imm>
780   : InstRIL<opcode, (outs cls:$R1), (ins imm:$I2),
781             mnemonic#"\t$R1, $I2",
782             [(set cls:$R1, (operator imm:$I2))]>;
783
784 class UnaryRILPC<string mnemonic, bits<12> opcode, SDPatternOperator operator,
785                  RegisterOperand cls>
786   : InstRIL<opcode, (outs cls:$R1), (ins pcrel32:$I2),
787             mnemonic#"\t$R1, $I2",
788             [(set cls:$R1, (operator pcrel32:$I2))]> {
789   let mayLoad = 1;
790   // We want PC-relative addresses to be tried ahead of BD and BDX addresses.
791   // However, BDXs have two extra operands and are therefore 6 units more
792   // complex.
793   let AddedComplexity = 7;
794 }
795
796 class CondUnaryRSY<string mnemonic, bits<16> opcode,
797                    SDPatternOperator operator, RegisterOperand cls,
798                    bits<5> bytes, AddressingMode mode = bdaddr20only>
799   : InstRSY<opcode, (outs cls:$R1),
800             (ins cls:$R1src, mode:$BD2, cond4:$valid, cond4:$R3),
801             mnemonic#"$R3\t$R1, $BD2",
802             [(set cls:$R1,
803                   (z_select_ccmask (load bdaddr20only:$BD2), cls:$R1src,
804                                    cond4:$valid, cond4:$R3))]>,
805     Requires<[FeatureLoadStoreOnCond]> {
806   let Constraints = "$R1 = $R1src";
807   let DisableEncoding = "$R1src";
808   let mayLoad = 1;
809   let AccessBytes = bytes;
810   let CCMaskLast = 1;
811 }
812
813 // Like CondUnaryRSY, but used for the raw assembly form.  The condition-code
814 // mask is the third operand rather than being part of the mnemonic.
815 class AsmCondUnaryRSY<string mnemonic, bits<16> opcode,
816                       RegisterOperand cls, bits<5> bytes,
817                       AddressingMode mode = bdaddr20only>
818   : InstRSY<opcode, (outs cls:$R1), (ins cls:$R1src, mode:$BD2, uimm8zx4:$R3),
819             mnemonic#"\t$R1, $BD2, $R3", []>,
820     Requires<[FeatureLoadStoreOnCond]> {
821   let mayLoad = 1;
822   let AccessBytes = bytes;
823   let Constraints = "$R1 = $R1src";
824   let DisableEncoding = "$R1src";
825 }
826
827 // Like CondUnaryRSY, but with a fixed CC mask.
828 class FixedCondUnaryRSY<string mnemonic, bits<16> opcode,
829                         RegisterOperand cls, bits<4> ccmask, bits<5> bytes,
830                         AddressingMode mode = bdaddr20only>
831   : InstRSY<opcode, (outs cls:$R1), (ins cls:$R1src, mode:$BD2),
832             mnemonic#"\t$R1, $BD2", []>,
833     Requires<[FeatureLoadStoreOnCond]> {
834   let Constraints = "$R1 = $R1src";
835   let DisableEncoding = "$R1src";
836   let R3 = ccmask;
837   let mayLoad = 1;
838   let AccessBytes = bytes;
839 }
840
841 class UnaryRX<string mnemonic, bits<8> opcode, SDPatternOperator operator,
842               RegisterOperand cls, bits<5> bytes,
843               AddressingMode mode = bdxaddr12only>
844   : InstRX<opcode, (outs cls:$R1), (ins mode:$XBD2),
845            mnemonic#"\t$R1, $XBD2",
846            [(set cls:$R1, (operator mode:$XBD2))]> {
847   let OpKey = mnemonic ## cls;
848   let OpType = "mem";
849   let mayLoad = 1;
850   let AccessBytes = bytes;
851 }
852
853 class UnaryRXE<string mnemonic, bits<16> opcode, SDPatternOperator operator,
854                RegisterOperand cls, bits<5> bytes>
855   : InstRXE<opcode, (outs cls:$R1), (ins bdxaddr12only:$XBD2),
856             mnemonic#"\t$R1, $XBD2",
857             [(set cls:$R1, (operator bdxaddr12only:$XBD2))]> {
858   let OpKey = mnemonic ## cls;
859   let OpType = "mem";
860   let mayLoad = 1;
861   let AccessBytes = bytes;
862 }
863
864 class UnaryRXY<string mnemonic, bits<16> opcode, SDPatternOperator operator,
865                RegisterOperand cls, bits<5> bytes,
866                AddressingMode mode = bdxaddr20only>
867   : InstRXY<opcode, (outs cls:$R1), (ins mode:$XBD2),
868             mnemonic#"\t$R1, $XBD2",
869             [(set cls:$R1, (operator mode:$XBD2))]> {
870   let OpKey = mnemonic ## cls;
871   let OpType = "mem";
872   let mayLoad = 1;
873   let AccessBytes = bytes;
874 }
875
876 multiclass UnaryRXPair<string mnemonic, bits<8> rxOpcode, bits<16> rxyOpcode,
877                        SDPatternOperator operator, RegisterOperand cls,
878                        bits<5> bytes> {
879   let DispKey = mnemonic ## #cls in {
880     let DispSize = "12" in
881       def "" : UnaryRX<mnemonic, rxOpcode, operator, cls, bytes, bdxaddr12pair>;
882     let DispSize = "20" in
883       def Y  : UnaryRXY<mnemonic#"y", rxyOpcode, operator, cls, bytes,
884                         bdxaddr20pair>;
885   }
886 }
887
888 class BinaryRR<string mnemonic, bits<8> opcode, SDPatternOperator operator,
889                RegisterOperand cls1, RegisterOperand cls2>
890   : InstRR<opcode, (outs cls1:$R1), (ins cls1:$R1src, cls2:$R2),
891            mnemonic#"r\t$R1, $R2",
892            [(set cls1:$R1, (operator cls1:$R1src, cls2:$R2))]> {
893   let OpKey = mnemonic ## cls1;
894   let OpType = "reg";
895   let Constraints = "$R1 = $R1src";
896   let DisableEncoding = "$R1src";
897 }
898
899 class BinaryRRE<string mnemonic, bits<16> opcode, SDPatternOperator operator,
900                 RegisterOperand cls1, RegisterOperand cls2>
901   : InstRRE<opcode, (outs cls1:$R1), (ins cls1:$R1src, cls2:$R2),
902             mnemonic#"r\t$R1, $R2",
903             [(set cls1:$R1, (operator cls1:$R1src, cls2:$R2))]> {
904   let OpKey = mnemonic ## cls1;
905   let OpType = "reg";
906   let Constraints = "$R1 = $R1src";
907   let DisableEncoding = "$R1src";
908 }
909
910 class BinaryRRF<string mnemonic, bits<16> opcode, SDPatternOperator operator,
911                 RegisterOperand cls1, RegisterOperand cls2>
912   : InstRRF<opcode, (outs cls1:$R1), (ins cls1:$R3, cls2:$R2),
913             mnemonic#"r\t$R1, $R3, $R2",
914             [(set cls1:$R1, (operator cls1:$R3, cls2:$R2))]> {
915   let OpKey = mnemonic ## cls1;
916   let OpType = "reg";
917   let R4 = 0;
918 }
919
920 class BinaryRRFK<string mnemonic, bits<16> opcode, SDPatternOperator operator,
921                  RegisterOperand cls1, RegisterOperand cls2>
922   : InstRRF<opcode, (outs cls1:$R1), (ins cls1:$R2, cls2:$R3),
923             mnemonic#"rk\t$R1, $R2, $R3",
924             [(set cls1:$R1, (operator cls1:$R2, cls2:$R3))]> {
925   let R4 = 0;
926 }
927
928 multiclass BinaryRRAndK<string mnemonic, bits<8> opcode1, bits<16> opcode2,
929                         SDPatternOperator operator, RegisterOperand cls1,
930                         RegisterOperand cls2> {
931   let NumOpsKey = mnemonic in {
932     let NumOpsValue = "3" in
933       def K : BinaryRRFK<mnemonic, opcode2, null_frag, cls1, cls2>,
934               Requires<[FeatureDistinctOps]>;
935     let NumOpsValue = "2", isConvertibleToThreeAddress = 1 in
936       def "" : BinaryRR<mnemonic, opcode1, operator, cls1, cls2>;
937   }
938 }
939
940 multiclass BinaryRREAndK<string mnemonic, bits<16> opcode1, bits<16> opcode2,
941                          SDPatternOperator operator, RegisterOperand cls1,
942                          RegisterOperand cls2> {
943   let NumOpsKey = mnemonic in {
944     let NumOpsValue = "3" in
945       def K : BinaryRRFK<mnemonic, opcode2, null_frag, cls1, cls2>,
946               Requires<[FeatureDistinctOps]>;
947     let NumOpsValue = "2", isConvertibleToThreeAddress = 1 in
948       def "" : BinaryRRE<mnemonic, opcode1, operator, cls1, cls2>;
949   }
950 }
951
952 class BinaryRI<string mnemonic, bits<12> opcode, SDPatternOperator operator,
953                RegisterOperand cls, Immediate imm>
954   : InstRI<opcode, (outs cls:$R1), (ins cls:$R1src, imm:$I2),
955            mnemonic#"\t$R1, $I2",
956            [(set cls:$R1, (operator cls:$R1src, imm:$I2))]> {
957   let Constraints = "$R1 = $R1src";
958   let DisableEncoding = "$R1src";
959 }
960
961 class BinaryRIE<string mnemonic, bits<16> opcode, SDPatternOperator operator,
962                 RegisterOperand cls, Immediate imm>
963   : InstRIEd<opcode, (outs cls:$R1), (ins cls:$R3, imm:$I2),
964              mnemonic#"\t$R1, $R3, $I2",
965              [(set cls:$R1, (operator cls:$R3, imm:$I2))]>;
966
967 multiclass BinaryRIAndK<string mnemonic, bits<12> opcode1, bits<16> opcode2,
968                         SDPatternOperator operator, RegisterOperand cls,
969                         Immediate imm> {
970   let NumOpsKey = mnemonic in {
971     let NumOpsValue = "3" in
972       def K : BinaryRIE<mnemonic##"k", opcode2, null_frag, cls, imm>,
973               Requires<[FeatureDistinctOps]>;
974     let NumOpsValue = "2", isConvertibleToThreeAddress = 1 in
975       def "" : BinaryRI<mnemonic, opcode1, operator, cls, imm>;
976   }
977 }
978
979 class BinaryRIL<string mnemonic, bits<12> opcode, SDPatternOperator operator,
980                 RegisterOperand cls, Immediate imm>
981   : InstRIL<opcode, (outs cls:$R1), (ins cls:$R1src, imm:$I2),
982             mnemonic#"\t$R1, $I2",
983             [(set cls:$R1, (operator cls:$R1src, imm:$I2))]> {
984   let Constraints = "$R1 = $R1src";
985   let DisableEncoding = "$R1src";
986 }
987
988 class BinaryRX<string mnemonic, bits<8> opcode, SDPatternOperator operator,
989                RegisterOperand cls, SDPatternOperator load, bits<5> bytes,
990                AddressingMode mode = bdxaddr12only>
991   : InstRX<opcode, (outs cls:$R1), (ins cls:$R1src, mode:$XBD2),
992            mnemonic#"\t$R1, $XBD2",
993            [(set cls:$R1, (operator cls:$R1src, (load mode:$XBD2)))]> {
994   let OpKey = mnemonic ## cls;
995   let OpType = "mem";
996   let Constraints = "$R1 = $R1src";
997   let DisableEncoding = "$R1src";
998   let mayLoad = 1;
999   let AccessBytes = bytes;
1000 }
1001
1002 class BinaryRXE<string mnemonic, bits<16> opcode, SDPatternOperator operator,
1003                   RegisterOperand cls, SDPatternOperator load, bits<5> bytes>
1004   : InstRXE<opcode, (outs cls:$R1), (ins cls:$R1src, bdxaddr12only:$XBD2),
1005             mnemonic#"\t$R1, $XBD2",
1006             [(set cls:$R1, (operator cls:$R1src,
1007                                      (load bdxaddr12only:$XBD2)))]> {
1008   let OpKey = mnemonic ## cls;
1009   let OpType = "mem";
1010   let Constraints = "$R1 = $R1src";
1011   let DisableEncoding = "$R1src";
1012   let mayLoad = 1;
1013   let AccessBytes = bytes;
1014 }
1015
1016 class BinaryRXY<string mnemonic, bits<16> opcode, SDPatternOperator operator,
1017                 RegisterOperand cls, SDPatternOperator load, bits<5> bytes,
1018                 AddressingMode mode = bdxaddr20only>
1019   : InstRXY<opcode, (outs cls:$R1), (ins cls:$R1src, mode:$XBD2),
1020             mnemonic#"\t$R1, $XBD2",
1021             [(set cls:$R1, (operator cls:$R1src, (load mode:$XBD2)))]> {
1022   let OpKey = mnemonic ## cls;
1023   let OpType = "mem";
1024   let Constraints = "$R1 = $R1src";
1025   let DisableEncoding = "$R1src";
1026   let mayLoad = 1;
1027   let AccessBytes = bytes;
1028 }
1029
1030 multiclass BinaryRXPair<string mnemonic, bits<8> rxOpcode, bits<16> rxyOpcode,
1031                         SDPatternOperator operator, RegisterOperand cls,
1032                         SDPatternOperator load, bits<5> bytes> {
1033   let DispKey = mnemonic ## #cls in {
1034     let DispSize = "12" in
1035       def "" : BinaryRX<mnemonic, rxOpcode, operator, cls, load, bytes,
1036                         bdxaddr12pair>;
1037     let DispSize = "20" in
1038       def Y  : BinaryRXY<mnemonic#"y", rxyOpcode, operator, cls, load, bytes,
1039                          bdxaddr20pair>;
1040   }
1041 }
1042
1043 class BinarySI<string mnemonic, bits<8> opcode, SDPatternOperator operator,
1044                Operand imm, AddressingMode mode = bdaddr12only>
1045   : InstSI<opcode, (outs), (ins mode:$BD1, imm:$I2),
1046            mnemonic#"\t$BD1, $I2",
1047            [(store (operator (load mode:$BD1), imm:$I2), mode:$BD1)]> {
1048   let mayLoad = 1;
1049   let mayStore = 1;
1050 }
1051
1052 class BinarySIY<string mnemonic, bits<16> opcode, SDPatternOperator operator,
1053                 Operand imm, AddressingMode mode = bdaddr20only>
1054   : InstSIY<opcode, (outs), (ins mode:$BD1, imm:$I2),
1055             mnemonic#"\t$BD1, $I2",
1056             [(store (operator (load mode:$BD1), imm:$I2), mode:$BD1)]> {
1057   let mayLoad = 1;
1058   let mayStore = 1;
1059 }
1060
1061 multiclass BinarySIPair<string mnemonic, bits<8> siOpcode,
1062                         bits<16> siyOpcode, SDPatternOperator operator,
1063                         Operand imm> {
1064   let DispKey = mnemonic ## #cls in {
1065     let DispSize = "12" in
1066       def "" : BinarySI<mnemonic, siOpcode, operator, imm, bdaddr12pair>;
1067     let DispSize = "20" in
1068       def Y  : BinarySIY<mnemonic#"y", siyOpcode, operator, imm, bdaddr20pair>;
1069   }
1070 }
1071
1072 class ShiftRS<string mnemonic, bits<8> opcode, SDPatternOperator operator,
1073               RegisterOperand cls>
1074   : InstRS<opcode, (outs cls:$R1), (ins cls:$R1src, shift12only:$BD2),
1075            mnemonic#"\t$R1, $BD2",
1076            [(set cls:$R1, (operator cls:$R1src, shift12only:$BD2))]> {
1077   let R3 = 0;
1078   let Constraints = "$R1 = $R1src";
1079   let DisableEncoding = "$R1src";
1080 }
1081
1082 class ShiftRSY<string mnemonic, bits<16> opcode, SDPatternOperator operator,
1083                RegisterOperand cls>
1084   : InstRSY<opcode, (outs cls:$R1), (ins cls:$R3, shift20only:$BD2),
1085             mnemonic#"\t$R1, $R3, $BD2",
1086             [(set cls:$R1, (operator cls:$R3, shift20only:$BD2))]>;
1087
1088 multiclass ShiftRSAndK<string mnemonic, bits<8> opcode1, bits<16> opcode2,
1089                        SDPatternOperator operator, RegisterOperand cls> {
1090   let NumOpsKey = mnemonic in {
1091     let NumOpsValue = "3" in
1092       def K  : ShiftRSY<mnemonic##"k", opcode2, null_frag, cls>,
1093                Requires<[FeatureDistinctOps]>;
1094     let NumOpsValue = "2", isConvertibleToThreeAddress = 1 in
1095       def "" : ShiftRS<mnemonic, opcode1, operator, cls>;
1096   }
1097 }
1098
1099 class CompareRR<string mnemonic, bits<8> opcode, SDPatternOperator operator,
1100                 RegisterOperand cls1, RegisterOperand cls2>
1101   : InstRR<opcode, (outs), (ins cls1:$R1, cls2:$R2),
1102            mnemonic#"r\t$R1, $R2",
1103            [(operator cls1:$R1, cls2:$R2)]> {
1104   let OpKey = mnemonic ## cls1;
1105   let OpType = "reg";
1106   let isCompare = 1;
1107 }
1108
1109 class CompareRRE<string mnemonic, bits<16> opcode, SDPatternOperator operator,
1110                  RegisterOperand cls1, RegisterOperand cls2>
1111   : InstRRE<opcode, (outs), (ins cls1:$R1, cls2:$R2),
1112             mnemonic#"r\t$R1, $R2",
1113             [(operator cls1:$R1, cls2:$R2)]> {
1114   let OpKey = mnemonic ## cls1;
1115   let OpType = "reg";
1116   let isCompare = 1;
1117 }
1118
1119 class CompareRI<string mnemonic, bits<12> opcode, SDPatternOperator operator,
1120                 RegisterOperand cls, Immediate imm>
1121   : InstRI<opcode, (outs), (ins cls:$R1, imm:$I2),
1122            mnemonic#"\t$R1, $I2",
1123            [(operator cls:$R1, imm:$I2)]> {
1124   let isCompare = 1;
1125 }
1126
1127 class CompareRIL<string mnemonic, bits<12> opcode, SDPatternOperator operator,
1128                  RegisterOperand cls, Immediate imm>
1129   : InstRIL<opcode, (outs), (ins cls:$R1, imm:$I2),
1130             mnemonic#"\t$R1, $I2",
1131             [(operator cls:$R1, imm:$I2)]> {
1132   let isCompare = 1;
1133 }
1134
1135 class CompareRILPC<string mnemonic, bits<12> opcode, SDPatternOperator operator,
1136                    RegisterOperand cls, SDPatternOperator load>
1137   : InstRIL<opcode, (outs), (ins cls:$R1, pcrel32:$I2),
1138             mnemonic#"\t$R1, $I2",
1139             [(operator cls:$R1, (load pcrel32:$I2))]> {
1140   let isCompare = 1;
1141   let mayLoad = 1;
1142   // We want PC-relative addresses to be tried ahead of BD and BDX addresses.
1143   // However, BDXs have two extra operands and are therefore 6 units more
1144   // complex.
1145   let AddedComplexity = 7;
1146 }
1147
1148 class CompareRX<string mnemonic, bits<8> opcode, SDPatternOperator operator,
1149                 RegisterOperand cls, SDPatternOperator load, bits<5> bytes,
1150                 AddressingMode mode = bdxaddr12only>
1151   : InstRX<opcode, (outs), (ins cls:$R1, mode:$XBD2),
1152            mnemonic#"\t$R1, $XBD2",
1153            [(operator cls:$R1, (load mode:$XBD2))]> {
1154   let OpKey = mnemonic ## cls;
1155   let OpType = "mem";
1156   let isCompare = 1;
1157   let mayLoad = 1;
1158   let AccessBytes = bytes;
1159 }
1160
1161 class CompareRXE<string mnemonic, bits<16> opcode, SDPatternOperator operator,
1162                  RegisterOperand cls, SDPatternOperator load, bits<5> bytes>
1163   : InstRXE<opcode, (outs), (ins cls:$R1, bdxaddr12only:$XBD2),
1164             mnemonic#"\t$R1, $XBD2",
1165             [(operator cls:$R1, (load bdxaddr12only:$XBD2))]> {
1166   let OpKey = mnemonic ## cls;
1167   let OpType = "mem";
1168   let isCompare = 1;
1169   let mayLoad = 1;
1170   let AccessBytes = bytes;
1171 }
1172
1173 class CompareRXY<string mnemonic, bits<16> opcode, SDPatternOperator operator,
1174                  RegisterOperand cls, SDPatternOperator load, bits<5> bytes,
1175                  AddressingMode mode = bdxaddr20only>
1176   : InstRXY<opcode, (outs), (ins cls:$R1, mode:$XBD2),
1177             mnemonic#"\t$R1, $XBD2",
1178             [(operator cls:$R1, (load mode:$XBD2))]> {
1179   let OpKey = mnemonic ## cls;
1180   let OpType = "mem";
1181   let isCompare = 1;
1182   let mayLoad = 1;
1183   let AccessBytes = bytes;
1184 }
1185
1186 multiclass CompareRXPair<string mnemonic, bits<8> rxOpcode, bits<16> rxyOpcode,
1187                          SDPatternOperator operator, RegisterOperand cls,
1188                          SDPatternOperator load, bits<5> bytes> {
1189   let DispKey = mnemonic ## #cls in {
1190     let DispSize = "12" in
1191       def "" : CompareRX<mnemonic, rxOpcode, operator, cls,
1192                          load, bytes, bdxaddr12pair>;
1193     let DispSize = "20" in
1194       def Y  : CompareRXY<mnemonic#"y", rxyOpcode, operator, cls,
1195                           load, bytes, bdxaddr20pair>;
1196   }
1197 }
1198
1199 class CompareSI<string mnemonic, bits<8> opcode, SDPatternOperator operator,
1200                 SDPatternOperator load, Immediate imm,
1201                 AddressingMode mode = bdaddr12only>
1202   : InstSI<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
1209 class CompareSIL<string mnemonic, bits<16> opcode, SDPatternOperator operator,
1210                  SDPatternOperator load, Immediate imm>
1211   : InstSIL<opcode, (outs), (ins bdaddr12only:$BD1, imm:$I2),
1212             mnemonic#"\t$BD1, $I2",
1213             [(operator (load bdaddr12only:$BD1), imm:$I2)]> {
1214   let isCompare = 1;
1215   let mayLoad = 1;
1216 }
1217
1218 class CompareSIY<string mnemonic, bits<16> opcode, SDPatternOperator operator,
1219                  SDPatternOperator load, Immediate imm,
1220                  AddressingMode mode = bdaddr20only>
1221   : InstSIY<opcode, (outs), (ins mode:$BD1, imm:$I2),
1222             mnemonic#"\t$BD1, $I2",
1223             [(operator (load mode:$BD1), imm:$I2)]> {
1224   let isCompare = 1;
1225   let mayLoad = 1;
1226 }
1227
1228 multiclass CompareSIPair<string mnemonic, bits<8> siOpcode, bits<16> siyOpcode,
1229                          SDPatternOperator operator, SDPatternOperator load,
1230                          Immediate imm> {
1231   let DispKey = mnemonic in {
1232     let DispSize = "12" in
1233       def "" : CompareSI<mnemonic, siOpcode, operator, load, imm, bdaddr12pair>;
1234     let DispSize = "20" in
1235       def Y  : CompareSIY<mnemonic#"y", siyOpcode, operator, load, imm,
1236                           bdaddr20pair>;
1237   }
1238 }
1239
1240 class TernaryRRD<string mnemonic, bits<16> opcode,
1241                  SDPatternOperator operator, RegisterOperand cls>
1242   : InstRRD<opcode, (outs cls:$R1), (ins cls:$R1src, cls:$R3, cls:$R2),
1243             mnemonic#"r\t$R1, $R3, $R2",
1244             [(set cls:$R1, (operator cls:$R1src, cls:$R3, cls:$R2))]> {
1245   let OpKey = mnemonic ## cls;
1246   let OpType = "reg";
1247   let Constraints = "$R1 = $R1src";
1248   let DisableEncoding = "$R1src";
1249 }
1250
1251 class TernaryRXF<string mnemonic, bits<16> opcode, SDPatternOperator operator,
1252                  RegisterOperand cls, SDPatternOperator load, bits<5> bytes>
1253   : InstRXF<opcode, (outs cls:$R1),
1254             (ins cls:$R1src, cls:$R3, bdxaddr12only:$XBD2),
1255             mnemonic#"\t$R1, $R3, $XBD2",
1256             [(set cls:$R1, (operator cls:$R1src, cls:$R3,
1257                                      (load bdxaddr12only:$XBD2)))]> {
1258   let OpKey = mnemonic ## cls;
1259   let OpType = "mem";
1260   let Constraints = "$R1 = $R1src";
1261   let DisableEncoding = "$R1src";
1262   let mayLoad = 1;
1263   let AccessBytes = bytes;
1264 }
1265
1266 class CmpSwapRS<string mnemonic, bits<8> opcode, SDPatternOperator operator,
1267                 RegisterOperand cls, AddressingMode mode = bdaddr12only>
1268   : InstRS<opcode, (outs cls:$R1), (ins cls:$R1src, cls:$R3, mode:$BD2),
1269            mnemonic#"\t$R1, $R3, $BD2",
1270            [(set cls:$R1, (operator mode:$BD2, cls:$R1src, cls:$R3))]> {
1271   let Constraints = "$R1 = $R1src";
1272   let DisableEncoding = "$R1src";
1273   let mayLoad = 1;
1274   let mayStore = 1;
1275 }
1276
1277 class CmpSwapRSY<string mnemonic, bits<16> opcode, SDPatternOperator operator,
1278                  RegisterOperand cls, AddressingMode mode = bdaddr20only>
1279   : InstRSY<opcode, (outs cls:$R1), (ins cls:$R1src, cls:$R3, mode:$BD2),
1280             mnemonic#"\t$R1, $R3, $BD2",
1281             [(set cls:$R1, (operator mode:$BD2, cls:$R1src, cls:$R3))]> {
1282   let Constraints = "$R1 = $R1src";
1283   let DisableEncoding = "$R1src";
1284   let mayLoad = 1;
1285   let mayStore = 1;
1286 }
1287
1288 multiclass CmpSwapRSPair<string mnemonic, bits<8> rsOpcode, bits<16> rsyOpcode,
1289                          SDPatternOperator operator, RegisterOperand cls> {
1290   let DispKey = mnemonic ## #cls in {
1291     let DispSize = "12" in
1292       def "" : CmpSwapRS<mnemonic, rsOpcode, operator, cls, bdaddr12pair>;
1293     let DispSize = "20" in
1294       def Y  : CmpSwapRSY<mnemonic#"y", rsyOpcode, operator, cls, bdaddr20pair>;
1295   }
1296 }
1297
1298 class RotateSelectRIEf<string mnemonic, bits<16> opcode, RegisterOperand cls1,
1299                        RegisterOperand cls2>
1300   : InstRIEf<opcode, (outs cls1:$R1),
1301              (ins cls1:$R1src, cls2:$R2, uimm8:$I3, uimm8:$I4, uimm8zx6:$I5),
1302              mnemonic#"\t$R1, $R2, $I3, $I4, $I5", []> {
1303   let Constraints = "$R1 = $R1src";
1304   let DisableEncoding = "$R1src";
1305 }
1306
1307 // A floating-point load-and test operation.  Create both a normal unary
1308 // operation and one that acts as a comparison against zero.
1309 multiclass LoadAndTestRRE<string mnemonic, bits<16> opcode,
1310                           RegisterOperand cls> {
1311   def "" : UnaryRRE<mnemonic, opcode, null_frag, cls, cls>;
1312   let isCodeGenOnly = 1 in
1313     def Compare : CompareRRE<mnemonic, opcode, null_frag, cls, cls>;
1314 }
1315
1316 //===----------------------------------------------------------------------===//
1317 // Pseudo instructions
1318 //===----------------------------------------------------------------------===//
1319 //
1320 // Convenience instructions that get lowered to real instructions
1321 // by either SystemZTargetLowering::EmitInstrWithCustomInserter()
1322 // or SystemZInstrInfo::expandPostRAPseudo().
1323 //
1324 //===----------------------------------------------------------------------===//
1325
1326 class Pseudo<dag outs, dag ins, list<dag> pattern>
1327   : InstSystemZ<0, outs, ins, "", pattern> {
1328   let isPseudo = 1;
1329   let isCodeGenOnly = 1;
1330 }
1331
1332 // Implements "$dst = $cc & (8 >> CC) ? $src1 : $src2", where CC is
1333 // the value of the PSW's 2-bit condition code field.
1334 class SelectWrapper<RegisterOperand cls>
1335   : Pseudo<(outs cls:$dst),
1336            (ins cls:$src1, cls:$src2, uimm8zx4:$valid, uimm8zx4:$cc),
1337            [(set cls:$dst, (z_select_ccmask cls:$src1, cls:$src2,
1338                                             uimm8zx4:$valid, uimm8zx4:$cc))]> {
1339   let usesCustomInserter = 1;
1340   // Although the instructions used by these nodes do not in themselves
1341   // change CC, the insertion requires new blocks, and CC cannot be live
1342   // across them.
1343   let Defs = [CC];
1344   let Uses = [CC];
1345 }
1346
1347 // Stores $new to $addr if $cc is true ("" case) or false (Inv case).
1348 multiclass CondStores<RegisterOperand cls, SDPatternOperator store,
1349                       SDPatternOperator load, AddressingMode mode> {
1350   let Defs = [CC], Uses = [CC], usesCustomInserter = 1 in {
1351     def "" : Pseudo<(outs),
1352                     (ins cls:$new, mode:$addr, uimm8zx4:$valid, uimm8zx4:$cc),
1353                     [(store (z_select_ccmask cls:$new, (load mode:$addr),
1354                                              uimm8zx4:$valid, uimm8zx4:$cc),
1355                             mode:$addr)]>;
1356     def Inv : Pseudo<(outs),
1357                      (ins cls:$new, mode:$addr, uimm8zx4:$valid, uimm8zx4:$cc),
1358                      [(store (z_select_ccmask (load mode:$addr), cls:$new,
1359                                               uimm8zx4:$valid, uimm8zx4:$cc),
1360                               mode:$addr)]>;
1361   }
1362 }
1363
1364 // OPERATOR is ATOMIC_SWAP or an ATOMIC_LOAD_* operation.  PAT and OPERAND
1365 // describe the second (non-memory) operand.
1366 class AtomicLoadBinary<SDPatternOperator operator, RegisterOperand cls,
1367                        dag pat, DAGOperand operand>
1368   : Pseudo<(outs cls:$dst), (ins bdaddr20only:$ptr, operand:$src2),
1369            [(set cls:$dst, (operator bdaddr20only:$ptr, pat))]> {
1370   let Defs = [CC];
1371   let Has20BitOffset = 1;
1372   let mayLoad = 1;
1373   let mayStore = 1;
1374   let usesCustomInserter = 1;
1375 }
1376
1377 // Specializations of AtomicLoadWBinary.
1378 class AtomicLoadBinaryReg32<SDPatternOperator operator>
1379   : AtomicLoadBinary<operator, GR32, (i32 GR32:$src2), GR32>;
1380 class AtomicLoadBinaryImm32<SDPatternOperator operator, Immediate imm>
1381   : AtomicLoadBinary<operator, GR32, (i32 imm:$src2), imm>;
1382 class AtomicLoadBinaryReg64<SDPatternOperator operator>
1383   : AtomicLoadBinary<operator, GR64, (i64 GR64:$src2), GR64>;
1384 class AtomicLoadBinaryImm64<SDPatternOperator operator, Immediate imm>
1385   : AtomicLoadBinary<operator, GR64, (i64 imm:$src2), imm>;
1386
1387 // OPERATOR is ATOMIC_SWAPW or an ATOMIC_LOADW_* operation.  PAT and OPERAND
1388 // describe the second (non-memory) operand.
1389 class AtomicLoadWBinary<SDPatternOperator operator, dag pat,
1390                         DAGOperand operand>
1391   : Pseudo<(outs GR32:$dst),
1392            (ins bdaddr20only:$ptr, operand:$src2, ADDR32:$bitshift,
1393                 ADDR32:$negbitshift, uimm32:$bitsize),
1394            [(set GR32:$dst, (operator bdaddr20only:$ptr, pat, ADDR32:$bitshift,
1395                                       ADDR32:$negbitshift, uimm32:$bitsize))]> {
1396   let Defs = [CC];
1397   let Has20BitOffset = 1;
1398   let mayLoad = 1;
1399   let mayStore = 1;
1400   let usesCustomInserter = 1;
1401 }
1402
1403 // Specializations of AtomicLoadWBinary.
1404 class AtomicLoadWBinaryReg<SDPatternOperator operator>
1405   : AtomicLoadWBinary<operator, (i32 GR32:$src2), GR32>;
1406 class AtomicLoadWBinaryImm<SDPatternOperator operator, Immediate imm>
1407   : AtomicLoadWBinary<operator, (i32 imm:$src2), imm>;
1408
1409 // Define an instruction that operates on two fixed-length blocks of memory.
1410 // The real instruction uses a bdladdr12onlylen8 for the first operand and a
1411 // bdaddr12only for the second, with the length of the second operand being
1412 // implicitly the same as the first.  This arrangement matches the underlying
1413 // assembly syntax.  However, for instruction selection it's easier to have
1414 // two normal bdaddr12onlys and a separate length operand, so define a pseudo
1415 // instruction for that too.
1416 multiclass MemorySS<string mnemonic, bits<8> opcode,
1417                     SDPatternOperator operator> {
1418   def "" : InstSS<opcode, (outs), (ins bdladdr12onlylen8:$BDL1,
1419                                        bdaddr12only:$BD2),
1420                   mnemonic##"\t$BDL1, $BD2", []>;
1421   let usesCustomInserter = 1 in
1422     def Wrapper : Pseudo<(outs), (ins bdaddr12only:$dest, bdaddr12only:$src,
1423                                       imm32len8:$length),
1424                          [(operator bdaddr12only:$dest, bdaddr12only:$src,
1425                                     imm32len8:$length)]>;
1426 }
1427
1428 // Define an instruction that operates on two strings, both terminated
1429 // by the character in R0.  The instruction processes a CPU-determinated
1430 // number of bytes at a time and sets CC to 3 if the instruction needs
1431 // to be repeated.  Also define a pseudo instruction that represents
1432 // the full loop (the main instruction plus the branch on CC==3).
1433 multiclass StringRRE<string mnemonic, bits<16> opcode,
1434                      SDPatternOperator operator> {
1435   def "" : InstRRE<opcode, (outs GR64:$R1, GR64:$R2),
1436                    (ins GR64:$R1src, GR64:$R2src),
1437                    mnemonic#"\t$R1, $R2", []> {
1438     let Constraints = "$R1 = $R1src, $R2 = $R2src";
1439     let DisableEncoding = "$R1src, $R2src";
1440   }
1441   let usesCustomInserter = 1 in
1442     def Loop : Pseudo<(outs GR64:$end),
1443                       (ins GR64:$start1, GR64:$start2, GR32:$char),
1444                       [(set GR64:$end, (operator GR64:$start1, GR64:$start2,
1445                                                  GR32:$char))]>;
1446 }