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