Add conditional branch instructions and their patterns.
[oota-llvm.git] / lib / Target / Mips / Mips16InstrInfo.td
1 //===- Mips16InstrInfo.td - Target Description for Mips16  -*- 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 // This file describes Mips16 instructions.
11 //
12 //===----------------------------------------------------------------------===//
13 //
14
15 //
16 // Address operand
17 def mem16 : Operand<i32> {
18   let PrintMethod = "printMemOperand";
19   let MIOperandInfo = (ops CPU16Regs, simm16);
20   let EncoderMethod = "getMemEncoding";
21 }
22
23 //
24 // EXT-I instruction format
25 //
26 class FEXT_I16_ins<bits<5> eop, string asmstr, InstrItinClass itin> :
27   FEXT_I16<eop, (outs), (ins brtarget:$imm16),
28            !strconcat(asmstr, "\t$imm16"),[], itin>;
29
30 //
31 // EXT-I8 instruction format
32 //
33
34 class FEXT_I816_ins_base<bits<3> _func, string asmstr,
35                          string asmstr2, InstrItinClass itin>:
36   FEXT_I816<_func, (outs), (ins uimm16:$imm), !strconcat(asmstr, asmstr2),
37             [], itin>;
38
39 class FEXT_I816_ins<bits<3> _func, string asmstr,
40                     InstrItinClass itin>:
41   FEXT_I816_ins_base<_func, asmstr, "\t$imm", itin>;
42
43 //
44 // Assembler formats in alphabetical order.
45 // Natural and pseudos are mixed together.
46 //
47 //
48 // EXT-RI instruction format
49 //
50
51 class FEXT_RI16_ins_base<bits<5> _op, string asmstr, string asmstr2,
52                          InstrItinClass itin>:
53   FEXT_RI16<_op, (outs CPU16Regs:$rx), (ins simm16:$imm),
54                   !strconcat(asmstr, asmstr2), [], itin>;
55
56 class FEXT_RI16_ins<bits<5> _op, string asmstr,
57                     InstrItinClass itin>:
58   FEXT_RI16_ins_base<_op, asmstr, "\t$rx, $imm", itin>;
59
60 class FEXT_RI16_PC_ins<bits<5> _op, string asmstr, InstrItinClass itin>:
61   FEXT_RI16_ins_base<_op, asmstr, "\t$rx, $$pc, $imm", itin>;
62
63 class FEXT_RI16_B_ins<bits<5> _op, string asmstr,
64                       InstrItinClass itin>:
65   FEXT_RI16<_op, (outs), (ins  CPU16Regs:$rx, brtarget:$imm),
66             !strconcat(asmstr, "\t$rx, $imm"), [], itin>;
67
68 class FEXT_2RI16_ins<bits<5> _op, string asmstr,
69                      InstrItinClass itin>:
70   FEXT_RI16<_op, (outs CPU16Regs:$rx), (ins CPU16Regs:$rx_, simm16:$imm),
71             !strconcat(asmstr, "\t$rx, $imm"), [], itin> {
72   let Constraints = "$rx_ = $rx";
73 }
74
75
76 // this has an explicit sp argument that we ignore to work around a problem
77 // in the compiler
78 class FEXT_RI16_SP_explicit_ins<bits<5> _op, string asmstr,
79                                 InstrItinClass itin>:
80   FEXT_RI16<_op, (outs CPU16Regs:$rx), (ins CPUSPReg:$ry, simm16:$imm),
81             !strconcat(asmstr, "\t$rx, $imm ( $ry ); "), [], itin>;
82
83 //
84 // EXT-RRI instruction format
85 //
86
87 class FEXT_RRI16_mem_ins<bits<5> op, string asmstr, Operand MemOpnd,
88                          InstrItinClass itin>:
89   FEXT_RRI16<op, (outs CPU16Regs:$ry), (ins  MemOpnd:$addr),
90              !strconcat(asmstr, "\t$ry, $addr"), [], itin>;
91
92 class FEXT_RRI16_mem2_ins<bits<5> op, string asmstr, Operand MemOpnd,
93                           InstrItinClass itin>:
94   FEXT_RRI16<op, (outs ), (ins  CPU16Regs:$ry, MemOpnd:$addr),
95              !strconcat(asmstr, "\t$ry, $addr"), [], itin>;
96
97 //
98 // EXT-SHIFT instruction format
99 //
100 class FEXT_SHIFT16_ins<bits<2> _f, string asmstr, InstrItinClass itin>:
101   FEXT_SHIFT16<_f, (outs CPU16Regs:$rx), (ins CPU16Regs:$ry, shamt:$sa),
102                !strconcat(asmstr, "\t$rx, $ry, $sa"), [], itin>;
103
104 //
105 // EXT-T8I8
106 //
107 class FEXT_T8I816_ins<bits<3> _func, string asmstr, string asmstr2,
108                       InstrItinClass itin>:
109   FEXT_I816<_func, (outs),
110             (ins CPU16Regs:$rx, CPU16Regs:$ry, brtarget:$imm),
111             !strconcat(asmstr2, !strconcat("\t$rx, $ry\n\t",
112             !strconcat(asmstr, "\t$imm"))),[], itin> {
113   let isCodeGenOnly=1;
114 }
115
116 //
117 // EXT-T8I8I
118 //
119 class FEXT_T8I8I16_ins<bits<3> _func, string asmstr, string asmstr2,
120                        InstrItinClass itin>:
121   FEXT_I816<_func, (outs),
122             (ins CPU16Regs:$rx, simm16:$imm, brtarget:$targ),
123             !strconcat(asmstr2, !strconcat("\t$rx, $imm\n\t",
124             !strconcat(asmstr, "\t$targ"))), [], itin> {
125   let isCodeGenOnly=1;
126 }
127 //
128
129
130 //
131 // I8_MOVR32 instruction format (used only by the MOVR32 instructio
132 //
133 class FI8_MOVR3216_ins<string asmstr, InstrItinClass itin>:
134        FI8_MOVR3216<(outs CPU16Regs:$rz), (ins CPURegs:$r32),
135        !strconcat(asmstr,  "\t$rz, $r32"), [], itin>;
136
137 //
138 // I8_MOV32R instruction format (used only by MOV32R instruction)
139 //
140
141 class FI8_MOV32R16_ins<string asmstr, InstrItinClass itin>:
142   FI8_MOV32R16<(outs CPURegs:$r32), (ins CPU16Regs:$rz),
143                !strconcat(asmstr,  "\t$r32, $rz"), [], itin>;
144
145 //
146 // This are pseudo formats for multiply
147 // This first one can be changed to non pseudo now.
148 //
149 // MULT
150 //
151 class FMULT16_ins<string asmstr, InstrItinClass itin> :
152   MipsPseudo16<(outs), (ins CPU16Regs:$rx, CPU16Regs:$ry),
153                !strconcat(asmstr, "\t$rx, $ry"), []>;
154
155 //
156 // MULT-LO
157 //
158 class FMULT16_LO_ins<string asmstr, InstrItinClass itin> :
159   MipsPseudo16<(outs CPU16Regs:$rz), (ins CPU16Regs:$rx, CPU16Regs:$ry),
160                !strconcat(asmstr, "\t$rx, $ry\n\tmflo\t$rz"), []> {
161   let isCodeGenOnly=1;
162 }
163
164 //
165 // RR-type instruction format
166 //
167
168 class FRR16_ins<bits<5> f, string asmstr, InstrItinClass itin> :
169   FRR16<f, (outs CPU16Regs:$rx), (ins CPU16Regs:$ry),
170         !strconcat(asmstr, "\t$rx, $ry"), [], itin> {
171 }
172
173 //
174 // maybe refactor but need a $zero as a dummy first parameter
175 //
176 class FRR16_div_ins<bits<5> f, string asmstr, InstrItinClass itin> :
177   FRR16<f, (outs ), (ins CPU16Regs:$rx, CPU16Regs:$ry),
178         !strconcat(asmstr, "\t$$zero, $rx, $ry"), [], itin> ;
179
180 class FRR16_M_ins<bits<5> f, string asmstr,
181                   InstrItinClass itin> :
182   FRR16<f, (outs CPU16Regs:$rx), (ins),
183         !strconcat(asmstr, "\t$rx"), [], itin>;
184
185 class FRxRxRy16_ins<bits<5> f, string asmstr,
186                     InstrItinClass itin> :
187   FRR16<f, (outs CPU16Regs:$rz), (ins CPU16Regs:$rx, CPU16Regs:$ry),
188             !strconcat(asmstr, "\t$rz, $ry"),
189             [], itin> {
190   let Constraints = "$rx = $rz";
191 }
192
193 let rx=0 in
194 class FRR16_JALRC_RA_only_ins<bits<1> nd_, bits<1> l_,
195                               string asmstr, InstrItinClass itin>:
196   FRR16_JALRC<nd_, l_, 1, (outs), (ins), !strconcat(asmstr, "\t $$ra"),
197               [], itin> ;
198
199 //
200 // RRR-type instruction format
201 //
202
203 class FRRR16_ins<bits<2> _f, string asmstr,  InstrItinClass itin> :
204   FRRR16<_f, (outs CPU16Regs:$rz), (ins CPU16Regs:$rx, CPU16Regs:$ry),
205          !strconcat(asmstr, "\t$rz, $rx, $ry"), [], itin>;
206
207 //
208 // Some general instruction class info
209 //
210 //
211
212 class ArithLogic16Defs<bit isCom=0> {
213   bits<5> shamt = 0;
214   bit isCommutable = isCom;
215   bit isReMaterializable = 1;
216   bit neverHasSideEffects = 1;
217 }
218
219 class branch16 {
220   bit isBranch = 1;
221   bit isTerminator = 1;
222   bit isBarrier = 1;
223 }
224
225 class cbranch16 {
226   bit isBranch = 1;
227   bit isTerminator = 1;
228 }
229
230 class MayLoad {
231   bit mayLoad = 1;
232 }
233
234 class MayStore {
235   bit mayStore = 1;
236 }
237 //
238
239 // Format: ADDIU rx, immediate MIPS16e
240 // Purpose: Add Immediate Unsigned Word (2-Operand, Extended)
241 // To add a constant to a 32-bit integer.
242 //
243 def AddiuRxImmX16: FEXT_RI16_ins<0b01001, "addiu", IIAlu>;
244
245 def AddiuRxRxImmX16: FEXT_2RI16_ins<0b01001, "addiu", IIAlu>,
246   ArithLogic16Defs<0>;
247
248 //
249
250 // Format: ADDIU rx, pc, immediate MIPS16e
251 // Purpose: Add Immediate Unsigned Word (3-Operand, PC-Relative, Extended)
252 // To add a constant to the program counter.
253 //
254 def AddiuRxPcImmX16: FEXT_RI16_PC_ins<0b00001, "addiu", IIAlu>;
255 //
256 // Format: ADDU rz, rx, ry MIPS16e
257 // Purpose: Add Unsigned Word (3-Operand)
258 // To add 32-bit integers.
259 //
260
261 def AdduRxRyRz16: FRRR16_ins<01, "addu", IIAlu>, ArithLogic16Defs<1>;
262
263 //
264 // Format: AND rx, ry MIPS16e
265 // Purpose: AND
266 // To do a bitwise logical AND.
267
268 def AndRxRxRy16: FRxRxRy16_ins<0b01100, "and", IIAlu>, ArithLogic16Defs<1>;
269
270
271 //
272 // Format: BEQZ rx, offset MIPS16e
273 // Purpose: Branch on Equal to Zero (Extended)
274 // To test a GPR then do a PC-relative conditional branch.
275 //
276 def BeqzRxImmX16: FEXT_RI16_B_ins<0b00100, "beqz", IIAlu>, cbranch16;
277
278 // Format: B offset MIPS16e
279 // Purpose: Unconditional Branch
280 // To do an unconditional PC-relative branch.
281 //
282 def BimmX16: FEXT_I16_ins<0b00010, "b", IIAlu>, branch16;
283
284 //
285 // Format: BNEZ rx, offset MIPS16e
286 // Purpose: Branch on Not Equal to Zero (Extended)
287 // To test a GPR then do a PC-relative conditional branch.
288 //
289 def BnezRxImmX16: FEXT_RI16_B_ins<0b00101, "bnez", IIAlu>, cbranch16;
290
291 //
292 // Format: BTEQZ offset MIPS16e
293 // Purpose: Branch on T Equal to Zero (Extended)
294 // To test special register T then do a PC-relative conditional branch.
295 //
296 def BteqzX16: FEXT_I816_ins<0b000, "bteqz", IIAlu>, cbranch16;
297
298 def BteqzT8CmpX16: FEXT_T8I816_ins<0b000, "bteqz", "cmp", IIAlu>, cbranch16;
299
300 def BteqzT8CmpiX16: FEXT_T8I8I16_ins<0b000, "bteqz", "cmpi", IIAlu>,
301   cbranch16;
302
303 def BteqzT8SltX16: FEXT_T8I816_ins<0b000, "bteqz", "slt", IIAlu>, cbranch16;
304
305 def BteqzT8SltuX16: FEXT_T8I816_ins<0b000, "bteqz", "sltu", IIAlu>, cbranch16;
306
307 def BteqzT8SltiX16: FEXT_T8I8I16_ins<0b000, "bteqz", "slti", IIAlu>, cbranch16;
308
309 def BteqzT8SltiuX16: FEXT_T8I8I16_ins<0b000, "bteqz", "sltiu", IIAlu>,
310   cbranch16;
311
312 //
313 // Format: BTNEZ offset MIPS16e
314 // Purpose: Branch on T Not Equal to Zero (Extended)
315 // To test special register T then do a PC-relative conditional branch.
316 //
317 def BtnezX16: FEXT_I816_ins<0b001, "btnez", IIAlu> ,cbranch16;
318
319 def BtnezT8CmpX16: FEXT_T8I816_ins<0b000, "btnez", "cmp", IIAlu>, cbranch16;
320
321 def BtnezT8CmpiX16: FEXT_T8I8I16_ins<0b000, "btnez", "cmpi", IIAlu>, cbranch16;
322
323 def BtnezT8SltX16: FEXT_T8I816_ins<0b000, "btnez", "slt", IIAlu>, cbranch16;
324
325 def BtnezT8SltuX16: FEXT_T8I816_ins<0b000, "btnez", "sltu", IIAlu>, cbranch16;
326
327 def BtnezT8SltiX16: FEXT_T8I8I16_ins<0b000, "btnez", "slti", IIAlu>, cbranch16;
328
329 def BtnezT8SltiuX16: FEXT_T8I8I16_ins<0b000, "btnez", "sltiu", IIAlu>,
330   cbranch16;
331
332 //
333 // Format: DIV rx, ry MIPS16e
334 // Purpose: Divide Word
335 // To divide 32-bit signed integers.
336 //
337 def DivRxRy16: FRR16_div_ins<0b11010, "div", IIAlu> {
338   let Defs = [HI, LO];
339 }
340
341 //
342 // Format: DIVU rx, ry MIPS16e
343 // Purpose: Divide Unsigned Word
344 // To divide 32-bit unsigned integers.
345 //
346 def DivuRxRy16: FRR16_div_ins<0b11011, "divu", IIAlu> {
347   let Defs = [HI, LO];
348 }
349
350
351 //
352 // Format: JR ra MIPS16e
353 // Purpose: Jump Register Through Register ra
354 // To execute a branch to the instruction address in the return
355 // address register.
356 //
357
358 def JrRa16: FRR16_JALRC_RA_only_ins<0, 0, "jr", IIAlu>;
359
360 //
361 // Format: LB ry, offset(rx) MIPS16e
362 // Purpose: Load Byte (Extended)
363 // To load a byte from memory as a signed value.
364 //
365 def LbRxRyOffMemX16: FEXT_RRI16_mem_ins<0b10011, "lb", mem16, IILoad>, MayLoad;
366
367 //
368 // Format: LBU ry, offset(rx) MIPS16e
369 // Purpose: Load Byte Unsigned (Extended)
370 // To load a byte from memory as a unsigned value.
371 //
372 def LbuRxRyOffMemX16:
373   FEXT_RRI16_mem_ins<0b10100, "lbu", mem16, IILoad>, MayLoad;
374
375 //
376 // Format: LH ry, offset(rx) MIPS16e
377 // Purpose: Load Halfword signed (Extended)
378 // To load a halfword from memory as a signed value.
379 //
380 def LhRxRyOffMemX16: FEXT_RRI16_mem_ins<0b10100, "lh", mem16, IILoad>, MayLoad;
381
382 //
383 // Format: LHU ry, offset(rx) MIPS16e
384 // Purpose: Load Halfword unsigned (Extended)
385 // To load a halfword from memory as an unsigned value.
386 //
387 def LhuRxRyOffMemX16:
388   FEXT_RRI16_mem_ins<0b10100, "lhu", mem16, IILoad>, MayLoad;
389
390 //
391 // Format: LI rx, immediate MIPS16e
392 // Purpose: Load Immediate (Extended)
393 // To load a constant into a GPR.
394 //
395 def LiRxImmX16: FEXT_RI16_ins<0b01101, "li", IIAlu>;
396
397 //
398 // Format: LW ry, offset(rx) MIPS16e
399 // Purpose: Load Word (Extended)
400 // To load a word from memory as a signed value.
401 //
402 def LwRxRyOffMemX16: FEXT_RRI16_mem_ins<0b10011, "lw", mem16, IILoad>, MayLoad;
403
404 // Format: LW rx, offset(sp) MIPS16e
405 // Purpose: Load Word (SP-Relative, Extended)
406 // To load an SP-relative word from memory as a signed value.
407 //
408 def LwRxSpImmX16: FEXT_RI16_SP_explicit_ins<0b10110, "lw", IILoad>, MayLoad;
409
410 //
411 // Format: MOVE r32, rz MIPS16e
412 // Purpose: Move
413 // To move the contents of a GPR to a GPR.
414 //
415 def Move32R16: FI8_MOV32R16_ins<"move", IIAlu>;
416
417 //
418 // Format: MOVE ry, r32 MIPS16e
419 //Purpose: Move
420 // To move the contents of a GPR to a GPR.
421 //
422 def MoveR3216: FI8_MOVR3216_ins<"move", IIAlu>;
423
424 //
425 // Format: MFHI rx MIPS16e
426 // Purpose: Move From HI Register
427 // To copy the special purpose HI register to a GPR.
428 //
429 def Mfhi16: FRR16_M_ins<0b10000, "mfhi", IIAlu> {
430   let Uses = [HI];
431   let neverHasSideEffects = 1;
432 }
433
434 //
435 // Format: MFLO rx MIPS16e
436 // Purpose: Move From LO Register
437 // To copy the special purpose LO register to a GPR.
438 //
439 def Mflo16: FRR16_M_ins<0b10010, "mflo", IIAlu> {
440   let Uses = [LO];
441   let neverHasSideEffects = 1;
442 }
443
444 //
445 // Pseudo Instruction for mult
446 //
447 def MultRxRy16:  FMULT16_ins<"mult",  IIAlu> {
448   let isCommutable = 1;
449   let neverHasSideEffects = 1;
450   let Defs = [HI, LO];
451 }
452
453 def MultuRxRy16: FMULT16_ins<"multu", IIAlu> {
454   let isCommutable = 1;
455   let neverHasSideEffects = 1;
456   let Defs = [HI, LO];
457 }
458
459 //
460 // Format: MULT rx, ry MIPS16e
461 // Purpose: Multiply Word
462 // To multiply 32-bit signed integers.
463 //
464 def MultRxRyRz16: FMULT16_LO_ins<"mult", IIAlu> {
465   let isCommutable = 1;
466   let neverHasSideEffects = 1;
467   let Defs = [HI, LO];
468 }
469
470 //
471 // Format: MULTU rx, ry MIPS16e
472 // Purpose: Multiply Unsigned Word
473 // To multiply 32-bit unsigned integers.
474 //
475 def MultuRxRyRz16: FMULT16_LO_ins<"multu", IIAlu> {
476   let isCommutable = 1;
477   let neverHasSideEffects = 1;
478   let Defs = [HI, LO];
479 }
480
481 //
482 // Format: NEG rx, ry MIPS16e
483 // Purpose: Negate
484 // To negate an integer value.
485 //
486 def NegRxRy16: FRR16_ins<0b11101, "neg", IIAlu>;
487
488 //
489 // Format: NOT rx, ry MIPS16e
490 // Purpose: Not
491 // To complement an integer value
492 //
493 def NotRxRy16: FRR16_ins<0b01111, "not", IIAlu>;
494
495 //
496 // Format: OR rx, ry MIPS16e
497 // Purpose: Or
498 // To do a bitwise logical OR.
499 //
500 def OrRxRxRy16: FRxRxRy16_ins<0b01101, "or", IIAlu>, ArithLogic16Defs<1>;
501
502 //
503 // Format: RESTORE {ra,}{s0/s1/s0-1,}{framesize}
504 // (All args are optional) MIPS16e
505 // Purpose: Restore Registers and Deallocate Stack Frame
506 // To deallocate a stack frame before exit from a subroutine,
507 // restoring return address and static registers, and adjusting
508 // stack
509 //
510
511 // fixed form for restoring RA and the frame
512 // for direct object emitter, encoding needs to be adjusted for the
513 // frame size
514 //
515 let ra=1, s=0,s0=1,s1=1 in
516 def RestoreRaF16:
517   FI8_SVRS16<0b1, (outs), (ins uimm16:$frame_size),
518              "restore \t$$ra,  $$s0, $$s1, $frame_size", [], IILoad >, MayLoad {
519   let isCodeGenOnly = 1;
520 }
521
522 //
523 // Format: SAVE {ra,}{s0/s1/s0-1,}{framesize} (All arguments are optional)
524 // MIPS16e
525 // Purpose: Save Registers and Set Up Stack Frame
526 // To set up a stack frame on entry to a subroutine,
527 // saving return address and static registers, and adjusting stack
528 //
529 let ra=1, s=1,s0=1,s1=1 in
530 def SaveRaF16:
531   FI8_SVRS16<0b1, (outs), (ins uimm16:$frame_size),
532              "save \t$$ra, $$s0, $$s1, $frame_size", [], IIStore >, MayStore {
533   let isCodeGenOnly = 1;
534 }
535 //
536 // Format: SB ry, offset(rx) MIPS16e
537 // Purpose: Store Byte (Extended)
538 // To store a byte to memory.
539 //
540 def SbRxRyOffMemX16:
541   FEXT_RRI16_mem2_ins<0b11000, "sb", mem16, IIStore>, MayStore;
542
543 //
544 // Format: SH ry, offset(rx) MIPS16e
545 // Purpose: Store Halfword (Extended)
546 // To store a halfword to memory.
547 //
548 def ShRxRyOffMemX16:
549   FEXT_RRI16_mem2_ins<0b11001, "sh", mem16, IIStore>, MayStore;
550
551 //
552 // Format: SLL rx, ry, sa MIPS16e
553 // Purpose: Shift Word Left Logical (Extended)
554 // To execute a left-shift of a word by a fixed number of bits—0 to 31 bits.
555 //
556 def SllX16: FEXT_SHIFT16_ins<0b00, "sll", IIAlu>;
557
558 //
559 // Format: SLLV ry, rx MIPS16e
560 // Purpose: Shift Word Left Logical Variable
561 // To execute a left-shift of a word by a variable number of bits.
562 //
563 def SllvRxRy16 : FRxRxRy16_ins<0b00100, "sllv", IIAlu>;
564
565
566 //
567 // Format: SRAV ry, rx MIPS16e
568 // Purpose: Shift Word Right Arithmetic Variable
569 // To execute an arithmetic right-shift of a word by a variable
570 // number of bits.
571 //
572 def SravRxRy16: FRxRxRy16_ins<0b00111, "srav", IIAlu>;
573
574
575 //
576 // Format: SRA rx, ry, sa MIPS16e
577 // Purpose: Shift Word Right Arithmetic (Extended)
578 // To execute an arithmetic right-shift of a word by a fixed
579 // number of bits—1 to 8 bits.
580 //
581 def SraX16: FEXT_SHIFT16_ins<0b11, "sra", IIAlu>;
582
583
584 //
585 // Format: SRLV ry, rx MIPS16e
586 // Purpose: Shift Word Right Logical Variable
587 // To execute a logical right-shift of a word by a variable
588 // number of bits.
589 //
590 def SrlvRxRy16: FRxRxRy16_ins<0b00110, "srlv", IIAlu>;
591
592
593 //
594 // Format: SRL rx, ry, sa MIPS16e
595 // Purpose: Shift Word Right Logical (Extended)
596 // To execute a logical right-shift of a word by a fixed
597 // number of bits—1 to 31 bits.
598 //
599 def SrlX16: FEXT_SHIFT16_ins<0b10, "srl", IIAlu>;
600
601 //
602 // Format: SUBU rz, rx, ry MIPS16e
603 // Purpose: Subtract Unsigned Word
604 // To subtract 32-bit integers
605 //
606 def SubuRxRyRz16: FRRR16_ins<0b11, "subu", IIAlu>, ArithLogic16Defs<0>;
607
608 //
609 // Format: SW ry, offset(rx) MIPS16e
610 // Purpose: Store Word (Extended)
611 // To store a word to memory.
612 //
613 def SwRxRyOffMemX16:
614   FEXT_RRI16_mem2_ins<0b11011, "sw", mem16, IIStore>, MayStore;
615
616 //
617 // Format: SW rx, offset(sp) MIPS16e
618 // Purpose: Store Word rx (SP-Relative)
619 // To store an SP-relative word to memory.
620 //
621 def SwRxSpImmX16: FEXT_RI16_SP_explicit_ins<0b11010, "sw", IIStore>, MayStore;
622
623 //
624 //
625 // Format: XOR rx, ry MIPS16e
626 // Purpose: Xor
627 // To do a bitwise logical XOR.
628 //
629 def XorRxRxRy16: FRxRxRy16_ins<0b01110, "xor", IIAlu>, ArithLogic16Defs<1>;
630
631 class Mips16Pat<dag pattern, dag result> : Pat<pattern, result> {
632   let Predicates = [InMips16Mode];
633 }
634
635 // Unary Arith/Logic
636 //
637 class ArithLogicU_pat<PatFrag OpNode, Instruction I> :
638   Mips16Pat<(OpNode CPU16Regs:$r),
639             (I CPU16Regs:$r)>;
640
641 def: ArithLogicU_pat<not, NotRxRy16>;
642 def: ArithLogicU_pat<ineg, NegRxRy16>;
643
644 class ArithLogic16_pat<SDNode OpNode, Instruction I> :
645   Mips16Pat<(OpNode CPU16Regs:$l, CPU16Regs:$r),
646             (I CPU16Regs:$l, CPU16Regs:$r)>;
647
648 def: ArithLogic16_pat<add, AdduRxRyRz16>;
649 def: ArithLogic16_pat<and, AndRxRxRy16>;
650 def: ArithLogic16_pat<mul, MultRxRyRz16>;
651 def: ArithLogic16_pat<or, OrRxRxRy16>;
652 def: ArithLogic16_pat<sub, SubuRxRyRz16>;
653 def: ArithLogic16_pat<xor, XorRxRxRy16>;
654
655 // Arithmetic and logical instructions with 2 register operands.
656
657 class ArithLogicI16_pat<SDNode OpNode, PatFrag imm_type, Instruction I> :
658   Mips16Pat<(OpNode CPU16Regs:$in, imm_type:$imm),
659             (I CPU16Regs:$in, imm_type:$imm)>;
660
661 def: ArithLogicI16_pat<add, immSExt16, AddiuRxRxImmX16>;
662 def: ArithLogicI16_pat<shl, immZExt5, SllX16>;
663 def: ArithLogicI16_pat<srl, immZExt5, SrlX16>;
664 def: ArithLogicI16_pat<sra, immZExt5, SraX16>;
665
666 class shift_rotate_reg16_pat<SDNode OpNode, Instruction I> :
667   Mips16Pat<(OpNode CPU16Regs:$r, CPU16Regs:$ra),
668             (I CPU16Regs:$r, CPU16Regs:$ra)>;
669
670 def: shift_rotate_reg16_pat<shl, SllvRxRy16>;
671 def: shift_rotate_reg16_pat<sra, SravRxRy16>;
672 def: shift_rotate_reg16_pat<srl, SrlvRxRy16>;
673
674 class LoadM16_pat<PatFrag OpNode, Instruction I> :
675   Mips16Pat<(OpNode addr:$addr), (I addr:$addr)>;
676
677 def: LoadM16_pat<sextloadi8, LbRxRyOffMemX16>;
678 def: LoadM16_pat<zextloadi8, LbuRxRyOffMemX16>;
679 def: LoadM16_pat<sextloadi16, LhRxRyOffMemX16>;
680 def: LoadM16_pat<zextloadi16, LhuRxRyOffMemX16>;
681 def: LoadM16_pat<load, LwRxRyOffMemX16>;
682
683 class StoreM16_pat<PatFrag OpNode, Instruction I> :
684   Mips16Pat<(OpNode CPU16Regs:$r, addr:$addr), (I CPU16Regs:$r, addr:$addr)>;
685
686 def: StoreM16_pat<truncstorei8, SbRxRyOffMemX16>;
687 def: StoreM16_pat<truncstorei16, ShRxRyOffMemX16>;
688 def: StoreM16_pat<store, SwRxRyOffMemX16>;
689
690 // Unconditional branch
691 class UncondBranch16_pat<SDNode OpNode, Instruction I>:
692   Mips16Pat<(OpNode bb:$imm16), (I bb:$imm16)> {
693     let Predicates = [RelocPIC, InMips16Mode];
694   }
695
696 // Jump and Link (Call)
697 let isCall=1, hasDelaySlot=1 in
698 def JumpLinkReg16:
699   FRR16_JALRC<0, 0, 0, (outs), (ins CPU16Regs:$rs),
700               "jalr \t$rs", [(MipsJmpLink CPU16Regs:$rs)], IIBranch>;
701
702 // Mips16 pseudos
703 let isReturn=1, isTerminator=1, hasDelaySlot=1, isBarrier=1, hasCtrlDep=1,
704   hasExtraSrcRegAllocReq = 1 in
705 def RetRA16 : MipsPseudo16<(outs), (ins), "", [(MipsRet)]>;
706
707
708 //
709 // Some branch conditional patterns are not generated by llvm at this time.
710 // Some are for seemingly arbitrary reasons not used: i.e. with signed number
711 // comparison they are used and for unsigned a different pattern is used.
712 // I am pushing upstream from the full mips16 port and it seemed that I needed
713 // these earlier and the mips32 port has these but now I cannot create test
714 // cases that use these patterns. While I sort this all out I will leave these
715 // extra patterns commented out and if I can be sure they are really not used,
716 // I will delete the code. I don't want to check the code in uncommented without
717 // a valid test case. In some cases, the compiler is generating patterns with
718 // setcc instead and earlier I had implemented setcc first so may have masked
719 // the problem. The setcc variants are suboptimal for mips16 so I may wantto
720 // figure out how to enable the brcond patterns or else possibly new
721 // combinations of of brcond and setcc.
722 //
723 //
724 // bcond-seteq
725 //
726 def: Mips16Pat
727   <(brcond (i32 (seteq CPU16Regs:$rx, CPU16Regs:$ry)), bb:$imm16),
728    (BteqzT8CmpX16 CPU16Regs:$rx, CPU16Regs:$ry,  bb:$imm16)
729   >;
730
731
732 def: Mips16Pat
733   <(brcond (i32 (seteq CPU16Regs:$rx, immZExt16:$imm)), bb:$targ16),
734    (BteqzT8CmpiX16 CPU16Regs:$rx, immSExt16:$imm,  bb:$targ16)
735   >;
736
737 def: Mips16Pat
738   <(brcond (i32 (seteq CPU16Regs:$rx, 0)), bb:$targ16),
739    (BeqzRxImmX16 CPU16Regs:$rx, bb:$targ16)
740   >;
741
742 //
743 // bcond-setgt (do we need to have this pair of setlt, setgt??)
744 //
745 def: Mips16Pat
746   <(brcond (i32 (setgt CPU16Regs:$rx, CPU16Regs:$ry)), bb:$imm16),
747    (BtnezT8SltX16 CPU16Regs:$ry, CPU16Regs:$rx,  bb:$imm16)
748   >;
749
750 //
751 // bcond-setge
752 //
753 def: Mips16Pat
754   <(brcond (i32 (setge CPU16Regs:$rx, CPU16Regs:$ry)), bb:$imm16),
755    (BteqzT8SltX16 CPU16Regs:$rx, CPU16Regs:$ry,  bb:$imm16)
756   >;
757
758 //
759 // never called because compiler transforms a >= k to a > (k-1)
760 //def: Mips16Pat
761 //  <(brcond (i32 (setge CPU16Regs:$rx, immSExt16:$imm)), bb:$imm16),
762 //   (BteqzT8SltiX16 CPU16Regs:$rx, immSExt16:$imm,  bb:$imm16)
763 //  >;
764
765 //
766 // bcond-setlt
767 //
768 def: Mips16Pat
769   <(brcond (i32 (setlt CPU16Regs:$rx, CPU16Regs:$ry)), bb:$imm16),
770    (BtnezT8SltX16 CPU16Regs:$rx, CPU16Regs:$ry,  bb:$imm16)
771   >;
772
773 def: Mips16Pat
774   <(brcond (i32 (setlt CPU16Regs:$rx, immSExt16:$imm)), bb:$imm16),
775    (BtnezT8SltiX16 CPU16Regs:$rx, immSExt16:$imm,  bb:$imm16)
776   >;
777
778 //
779 // bcond-setle
780 //
781 def: Mips16Pat
782   <(brcond (i32 (setle CPU16Regs:$rx, CPU16Regs:$ry)), bb:$imm16),
783    (BteqzT8SltX16 CPU16Regs:$ry, CPU16Regs:$rx,  bb:$imm16)
784   >;
785
786 //
787 // bcond-setne
788 //
789 def: Mips16Pat
790   <(brcond (i32 (setne CPU16Regs:$rx, CPU16Regs:$ry)), bb:$imm16),
791    (BtnezT8CmpX16 CPU16Regs:$rx, CPU16Regs:$ry,  bb:$imm16)
792   >;
793
794 def: Mips16Pat
795   <(brcond (i32 (setne CPU16Regs:$rx, immZExt16:$imm)), bb:$targ16),
796    (BtnezT8CmpiX16 CPU16Regs:$rx, immSExt16:$imm,  bb:$targ16)
797   >;
798
799 def: Mips16Pat
800   <(brcond (i32 (setne CPU16Regs:$rx, 0)), bb:$targ16),
801    (BnezRxImmX16 CPU16Regs:$rx, bb:$targ16)
802   >;
803
804 //
805 // This needs to be there but I forget which code will generate it
806 //
807 def: Mips16Pat
808   <(brcond CPU16Regs:$rx, bb:$targ16),
809    (BnezRxImmX16 CPU16Regs:$rx, bb:$targ16)
810   >;
811
812 //
813
814 //
815 // bcond-setugt
816 //
817 //def: Mips16Pat
818 //  <(brcond (i32 (setugt CPU16Regs:$rx, CPU16Regs:$ry)), bb:$imm16),
819 //   (BtnezT8SltuX16 CPU16Regs:$ry, CPU16Regs:$rx,  bb:$imm16)
820 //  >;
821
822 //
823 // bcond-setuge
824 //
825 //def: Mips16Pat
826 //  <(brcond (i32 (setuge CPU16Regs:$rx, CPU16Regs:$ry)), bb:$imm16),
827 //   (BteqzT8SltuX16 CPU16Regs:$rx, CPU16Regs:$ry,  bb:$imm16)
828 //  >;
829
830
831 //
832 // bcond-setult
833 //
834 //def: Mips16Pat
835 //  <(brcond (i32 (setult CPU16Regs:$rx, CPU16Regs:$ry)), bb:$imm16),
836 //   (BtnezT8SltuX16 CPU16Regs:$rx, CPU16Regs:$ry,  bb:$imm16)
837 //  >;
838
839 def: UncondBranch16_pat<br, BimmX16>;
840
841 // Small immediates
842 def: Mips16Pat<(i32 immSExt16:$in),
843                (AddiuRxRxImmX16 (Move32R16 ZERO), immSExt16:$in)>;
844
845 def: Mips16Pat<(i32 immZExt16:$in), (LiRxImmX16 immZExt16:$in)>;
846
847 //
848 // MipsDivRem
849 //
850 def: Mips16Pat
851   <(MipsDivRem CPU16Regs:$rx, CPU16Regs:$ry),
852    (DivRxRy16 CPU16Regs:$rx, CPU16Regs:$ry)>;
853
854 //
855 // MipsDivRemU
856 //
857 def: Mips16Pat
858   <(MipsDivRemU CPU16Regs:$rx, CPU16Regs:$ry),
859    (DivuRxRy16 CPU16Regs:$rx, CPU16Regs:$ry)>;
860
861
862 def: Mips16Pat<(add CPU16Regs:$hi, (MipsLo tglobaladdr:$lo)),
863                (AddiuRxRxImmX16 CPU16Regs:$hi, tglobaladdr:$lo)>;