1 //===- Mips16InstrInfo.td - Target Description for Mips16 -*- tablegen -*-=//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file describes Mips16 instructions.
12 //===----------------------------------------------------------------------===//
17 def addr16 : ComplexPattern<iPTR, 2, "selectAddr16", [frameindex]>;
18 def addr16sp : ComplexPattern<iPTR, 2, "selectAddr16SP", [frameindex]>;
22 def mem16 : Operand<i32> {
23 let PrintMethod = "printMemOperand";
24 let MIOperandInfo = (ops CPU16Regs, simm16);
25 let EncoderMethod = "getMemEncoding";
28 def mem16sp : Operand<i32> {
29 let PrintMethod = "printMemOperand";
30 // This should be CPUSPReg but the MIPS16 subtarget isn't good enough at
31 // keeping the sp-relative load and the other varieties separate at the
32 // moment. This lie fixes the problem sufficiently well to fix the errors
33 // emitted by -verify-machineinstrs and the output ends up correct as long
34 // as we use an external assembler (which is already a requirement for MIPS16
35 // for several other reasons).
36 let MIOperandInfo = (ops CPU16RegsPlusSP, simm16);
37 let EncoderMethod = "getMemEncoding";
40 def mem16_ea : Operand<i32> {
41 let PrintMethod = "printMemOperandEA";
42 let MIOperandInfo = (ops CPU16RegsPlusSP, simm16);
43 let EncoderMethod = "getMemEncoding";
46 def pcrel16 : Operand<i32>;
49 // I-type instruction format
51 // this is only used by bimm. the actual assembly value is a 12 bit signed
54 class FI16_ins<bits<5> op, string asmstr, InstrItinClass itin>:
55 FI16<op, (outs), (ins brtarget:$imm16),
56 !strconcat(asmstr, "\t$imm16 # 16 bit inst"), [], itin>;
60 // I8 instruction format
63 class FI816_ins_base<bits<3> _func, string asmstr,
64 string asmstr2, InstrItinClass itin>:
65 FI816<_func, (outs), (ins simm16:$imm), !strconcat(asmstr, asmstr2),
68 class FI816_ins<bits<3> _func, string asmstr,
70 FI816_ins_base<_func, asmstr, "\t$imm # 16 bit inst", itin>;
72 class FI816_SP_ins<bits<3> _func, string asmstr,
74 FI816_ins_base<_func, asmstr, "\t$$sp, $imm # 16 bit inst", itin>;
77 // RI instruction format
81 class FRI16_ins_base<bits<5> op, string asmstr, string asmstr2,
83 FRI16<op, (outs CPU16Regs:$rx), (ins simm16:$imm),
84 !strconcat(asmstr, asmstr2), [], itin>;
86 class FRI16_ins<bits<5> op, string asmstr,
88 FRI16_ins_base<op, asmstr, "\t$rx, $imm \t# 16 bit inst", itin>;
90 class FRI16_TCP_ins<bits<5> _op, string asmstr,
92 FRI16<_op, (outs CPU16Regs:$rx), (ins pcrel16:$imm, i32imm:$size),
93 !strconcat(asmstr, "\t$rx, $imm\t# 16 bit inst"), [], itin>;
95 class FRI16R_ins_base<bits<5> op, string asmstr, string asmstr2,
97 FRI16<op, (outs), (ins CPU16Regs:$rx, simm16:$imm),
98 !strconcat(asmstr, asmstr2), [], itin>;
100 class FRI16R_ins<bits<5> op, string asmstr,
101 InstrItinClass itin>:
102 FRI16R_ins_base<op, asmstr, "\t$rx, $imm \t# 16 bit inst", itin>;
104 class F2RI16_ins<bits<5> _op, string asmstr,
105 InstrItinClass itin>:
106 FRI16<_op, (outs CPU16Regs:$rx), (ins CPU16Regs:$rx_, simm16:$imm),
107 !strconcat(asmstr, "\t$rx, $imm\t# 16 bit inst"), [], itin> {
108 let Constraints = "$rx_ = $rx";
111 class FRI16_B_ins<bits<5> _op, string asmstr,
112 InstrItinClass itin>:
113 FRI16<_op, (outs), (ins CPU16Regs:$rx, brtarget:$imm),
114 !strconcat(asmstr, "\t$rx, $imm # 16 bit inst"), [], itin>;
116 // Compare a register and immediate and place result in CC
117 // Implicit use of T8
119 // EXT-CCRR Instruction format
121 class FEXT_CCRXI16_ins<string asmstr>:
122 MipsPseudo16<(outs CPU16Regs:$cc), (ins CPU16Regs:$rx, simm16:$imm),
123 !strconcat(asmstr, "\t$rx, $imm\n\tmove\t$cc, $$t8"), []> {
125 let usesCustomInserter = 1;
128 // JAL and JALX instruction format
130 class FJAL16_ins<bits<1> _X, string asmstr,
131 InstrItinClass itin>:
132 FJAL16<_X, (outs), (ins uimm26:$imm),
133 !strconcat(asmstr, "\t$imm\n\tnop"),[],
139 class FJALB16_ins<bits<1> _X, string asmstr,
140 InstrItinClass itin>:
141 FJAL16<_X, (outs), (ins uimm26:$imm),
142 !strconcat(asmstr, "\t$imm\t# branch\n\tnop"),[],
149 // EXT-I instruction format
151 class FEXT_I16_ins<bits<5> eop, string asmstr, InstrItinClass itin> :
152 FEXT_I16<eop, (outs), (ins brtarget:$imm16),
153 !strconcat(asmstr, "\t$imm16"),[], itin>;
156 // EXT-I8 instruction format
159 class FEXT_I816_ins_base<bits<3> _func, string asmstr,
160 string asmstr2, InstrItinClass itin>:
161 FEXT_I816<_func, (outs), (ins simm16:$imm), !strconcat(asmstr, asmstr2),
164 class FEXT_I816_ins<bits<3> _func, string asmstr,
165 InstrItinClass itin>:
166 FEXT_I816_ins_base<_func, asmstr, "\t$imm", itin>;
168 class FEXT_I816_SP_ins<bits<3> _func, string asmstr,
169 InstrItinClass itin>:
170 FEXT_I816_ins_base<_func, asmstr, "\t$$sp, $imm", itin>;
173 // Assembler formats in alphabetical order.
174 // Natural and pseudos are mixed together.
176 // Compare two registers and place result in CC
177 // Implicit use of T8
179 // CC-RR Instruction format
181 class FCCRR16_ins<string asmstr> :
182 MipsPseudo16<(outs CPU16Regs:$cc), (ins CPU16Regs:$rx, CPU16Regs:$ry),
183 !strconcat(asmstr, "\t$rx, $ry\n\tmove\t$cc, $$t8"), []> {
185 let usesCustomInserter = 1;
189 // EXT-RI instruction format
192 class FEXT_RI16_ins_base<bits<5> _op, string asmstr, string asmstr2,
193 InstrItinClass itin>:
194 FEXT_RI16<_op, (outs CPU16Regs:$rx), (ins simm16:$imm),
195 !strconcat(asmstr, asmstr2), [], itin>;
197 class FEXT_RI16_ins<bits<5> _op, string asmstr,
198 InstrItinClass itin>:
199 FEXT_RI16_ins_base<_op, asmstr, "\t$rx, $imm", itin>;
201 class FEXT_RI16R_ins_base<bits<5> _op, string asmstr, string asmstr2,
202 InstrItinClass itin>:
203 FEXT_RI16<_op, (outs ), (ins CPU16Regs:$rx, simm16:$imm),
204 !strconcat(asmstr, asmstr2), [], itin>;
206 class FEXT_RI16R_ins<bits<5> _op, string asmstr,
207 InstrItinClass itin>:
208 FEXT_RI16R_ins_base<_op, asmstr, "\t$rx, $imm", itin>;
210 class FEXT_RI16_PC_ins<bits<5> _op, string asmstr, InstrItinClass itin>:
211 FEXT_RI16_ins_base<_op, asmstr, "\t$rx, $$pc, $imm", itin>;
213 class FEXT_RI16_B_ins<bits<5> _op, string asmstr,
214 InstrItinClass itin>:
215 FEXT_RI16<_op, (outs), (ins CPU16Regs:$rx, brtarget:$imm),
216 !strconcat(asmstr, "\t$rx, $imm"), [], itin>;
218 class FEXT_RI16_TCP_ins<bits<5> _op, string asmstr,
219 InstrItinClass itin>:
220 FEXT_RI16<_op, (outs CPU16Regs:$rx), (ins pcrel16:$imm, i32imm:$size),
221 !strconcat(asmstr, "\t$rx, $imm"), [], itin>;
223 class FEXT_2RI16_ins<bits<5> _op, string asmstr,
224 InstrItinClass itin>:
225 FEXT_RI16<_op, (outs CPU16Regs:$rx), (ins CPU16Regs:$rx_, simm16:$imm),
226 !strconcat(asmstr, "\t$rx, $imm"), [], itin> {
227 let Constraints = "$rx_ = $rx";
231 // EXT-RRI instruction format
234 class FEXT_RRI16_mem_ins<bits<5> op, string asmstr, Operand MemOpnd,
235 InstrItinClass itin>:
236 FEXT_RRI16<op, (outs CPU16Regs:$ry), (ins MemOpnd:$addr),
237 !strconcat(asmstr, "\t$ry, $addr"), [], itin>;
239 class FEXT_RRI16_mem2_ins<bits<5> op, string asmstr, Operand MemOpnd,
240 InstrItinClass itin>:
241 FEXT_RRI16<op, (outs ), (ins CPU16Regs:$ry, MemOpnd:$addr),
242 !strconcat(asmstr, "\t$ry, $addr"), [], itin>;
246 // EXT-RRI-A instruction format
249 class FEXT_RRI_A16_mem_ins<bits<1> op, string asmstr, Operand MemOpnd,
250 InstrItinClass itin>:
251 FEXT_RRI_A16<op, (outs CPU16Regs:$ry), (ins MemOpnd:$addr),
252 !strconcat(asmstr, "\t$ry, $addr"), [], itin>;
255 // EXT-SHIFT instruction format
257 class FEXT_SHIFT16_ins<bits<2> _f, string asmstr, InstrItinClass itin>:
258 FEXT_SHIFT16<_f, (outs CPU16Regs:$rx), (ins CPU16Regs:$ry, uimm5:$sa),
259 !strconcat(asmstr, "\t$rx, $ry, $sa"), [], itin>;
264 class FEXT_T8I816_ins<string asmstr, string asmstr2>:
266 (ins CPU16Regs:$rx, CPU16Regs:$ry, brtarget:$imm),
267 !strconcat(asmstr2, !strconcat("\t$rx, $ry\n\t",
268 !strconcat(asmstr, "\t$imm"))),[]> {
270 let usesCustomInserter = 1;
276 class FEXT_T8I8I16_ins<string asmstr, string asmstr2>:
278 (ins CPU16Regs:$rx, simm16:$imm, brtarget:$targ),
279 !strconcat(asmstr2, !strconcat("\t$rx, $imm\n\t",
280 !strconcat(asmstr, "\t$targ"))), []> {
282 let usesCustomInserter = 1;
288 // I8_MOVR32 instruction format (used only by the MOVR32 instructio
290 class FI8_MOVR3216_ins<string asmstr, InstrItinClass itin>:
291 FI8_MOVR3216<(outs CPU16Regs:$rz), (ins GPR32:$r32),
292 !strconcat(asmstr, "\t$rz, $r32"), [], itin>;
295 // I8_MOV32R instruction format (used only by MOV32R instruction)
298 class FI8_MOV32R16_ins<string asmstr, InstrItinClass itin>:
299 FI8_MOV32R16<(outs GPR32:$r32), (ins CPU16Regs:$rz),
300 !strconcat(asmstr, "\t$r32, $rz"), [], itin>;
303 // This are pseudo formats for multiply
304 // This first one can be changed to non-pseudo now.
308 class FMULT16_ins<string asmstr, InstrItinClass itin> :
309 MipsPseudo16<(outs), (ins CPU16Regs:$rx, CPU16Regs:$ry),
310 !strconcat(asmstr, "\t$rx, $ry"), []>;
315 class FMULT16_LO_ins<string asmstr, InstrItinClass itin> :
316 MipsPseudo16<(outs CPU16Regs:$rz), (ins CPU16Regs:$rx, CPU16Regs:$ry),
317 !strconcat(asmstr, "\t$rx, $ry\n\tmflo\t$rz"), []> {
322 // RR-type instruction format
325 class FRR16_ins<bits<5> f, string asmstr, InstrItinClass itin> :
326 FRR16<f, (outs CPU16Regs:$rx), (ins CPU16Regs:$ry),
327 !strconcat(asmstr, "\t$rx, $ry"), [], itin> {
330 class FRRBreakNull16_ins<string asmstr, InstrItinClass itin> :
331 FRRBreak16<(outs), (ins), asmstr, [], itin> {
335 class FRR16R_ins<bits<5> f, string asmstr, InstrItinClass itin> :
336 FRR16<f, (outs), (ins CPU16Regs:$rx, CPU16Regs:$ry),
337 !strconcat(asmstr, "\t$rx, $ry"), [], itin> {
340 class FRRTR16_ins<string asmstr> :
341 MipsPseudo16<(outs CPU16Regs:$rz), (ins CPU16Regs:$rx, CPU16Regs:$ry),
342 !strconcat(asmstr, "\t$rx, $ry\n\tmove\t$rz, $$t8"), []> ;
345 // maybe refactor but need a $zero as a dummy first parameter
347 class FRR16_div_ins<bits<5> f, string asmstr, InstrItinClass itin> :
348 FRR16<f, (outs ), (ins CPU16Regs:$rx, CPU16Regs:$ry),
349 !strconcat(asmstr, "\t$$zero, $rx, $ry"), [], itin> ;
351 class FUnaryRR16_ins<bits<5> f, string asmstr, InstrItinClass itin> :
352 FRR16<f, (outs CPU16Regs:$rx), (ins CPU16Regs:$ry),
353 !strconcat(asmstr, "\t$rx, $ry"), [], itin> ;
356 class FRR16_M_ins<bits<5> f, string asmstr,
357 InstrItinClass itin> :
358 FRR16<f, (outs CPU16Regs:$rx), (ins),
359 !strconcat(asmstr, "\t$rx"), [], itin>;
361 class FRxRxRy16_ins<bits<5> f, string asmstr,
362 InstrItinClass itin> :
363 FRR16<f, (outs CPU16Regs:$rz), (ins CPU16Regs:$rx, CPU16Regs:$ry),
364 !strconcat(asmstr, "\t$rz, $ry"),
366 let Constraints = "$rx = $rz";
370 class FRR16_JALRC_RA_only_ins<bits<1> nd_, bits<1> l_,
371 string asmstr, InstrItinClass itin>:
372 FRR16_JALRC<nd_, l_, 1, (outs), (ins), !strconcat(asmstr, "\t$$ra"),
376 class FRR16_JALRC_ins<bits<1> nd, bits<1> l, bits<1> ra,
377 string asmstr, InstrItinClass itin>:
378 FRR16_JALRC<nd, l, ra, (outs), (ins CPU16Regs:$rx),
379 !strconcat(asmstr, "\t$rx"), [], itin> ;
382 <bits<5> _funct, bits<3> _subfunc,
383 string asmstr, InstrItinClass itin>:
384 FRR_SF16<_funct, _subfunc, (outs CPU16Regs:$rx), (ins CPU16Regs:$rx_),
385 !strconcat(asmstr, "\t $rx"),
387 let Constraints = "$rx_ = $rx";
390 // RRR-type instruction format
393 class FRRR16_ins<bits<2> _f, string asmstr, InstrItinClass itin> :
394 FRRR16<_f, (outs CPU16Regs:$rz), (ins CPU16Regs:$rx, CPU16Regs:$ry),
395 !strconcat(asmstr, "\t$rz, $rx, $ry"), [], itin>;
398 // These Sel patterns support the generation of conditional move
399 // pseudo instructions.
401 // The nomenclature uses the components making up the pseudo and may
402 // be a bit counter intuitive when compared with the end result we seek.
403 // For example using a bqez in the example directly below results in the
404 // conditional move being done if the tested register is not zero.
405 // I considered in easier to check by keeping the pseudo consistent with
406 // it's components but it could have been done differently.
408 // The simplest case is when can test and operand directly and do the
409 // conditional move based on a simple mips16 conditional
410 // branch instruction.
412 // if $op == beqz or bnez:
417 // if $op == beqz, then if $rt != 0, then the conditional assignment
418 // $rd = $rs is done.
420 // if $op == bnez, then if $rt == 0, then the conditional assignment
421 // $rd = $rs is done.
423 // So this pseudo class only has one operand, i.e. op
425 class Sel<string op>:
426 MipsPseudo16<(outs CPU16Regs:$rd_), (ins CPU16Regs:$rd, CPU16Regs:$rs,
428 !strconcat(op, "\t$rt, .+4\n\t\n\tmove $rd, $rs"), []> {
429 //let isCodeGenOnly=1;
430 let Constraints = "$rd = $rd_";
431 let usesCustomInserter = 1;
435 // The next two instruction classes allow for an operand which tests
436 // two operands and returns a value in register T8 and
437 //then does a conditional branch based on the value of T8
440 // op2 can be cmpi or slti/sltiu
441 // op1 can bteqz or btnez
442 // the operands for op2 are a register and a signed constant
444 // $op2 $t, $imm ;test register t and branch conditionally
445 // $op1 .+4 ;op1 is a conditional branch
449 class SeliT<string op1, string op2>:
450 MipsPseudo16<(outs CPU16Regs:$rd_), (ins CPU16Regs:$rd, CPU16Regs:$rs,
451 CPU16Regs:$rl, simm16:$imm),
453 !strconcat("\t$rl, $imm\n\t",
454 !strconcat(op1, "\t.+4\n\tmove $rd, $rs"))), []> {
456 let Constraints = "$rd = $rd_";
457 let usesCustomInserter = 1;
461 // op2 can be cmp or slt/sltu
462 // op1 can be bteqz or btnez
463 // the operands for op2 are two registers
464 // op1 is a conditional branch
467 // $op2 $rl, $rr ;test registers rl,rr
468 // $op1 .+4 ;op2 is a conditional branch
472 class SelT<string op1, string op2>:
473 MipsPseudo16<(outs CPU16Regs:$rd_),
474 (ins CPU16Regs:$rd, CPU16Regs:$rs,
475 CPU16Regs:$rl, CPU16Regs:$rr),
477 !strconcat("\t$rl, $rr\n\t",
478 !strconcat(op1, "\t.+4\n\tmove $rd, $rs"))), []> {
480 let Constraints = "$rd = $rd_";
481 let usesCustomInserter = 1;
488 MipsPseudo16<(outs), (ins simm32:$imm), "\t.word $imm", []>;
491 MipsPseudo16<(outs CPU16Regs:$rx), (ins simm32:$imm, simm32:$constid),
492 "lw\t$rx, 1f\n\tb\t2f\n\t.align\t2\n1: \t.word\t$imm\n2:", []>;
496 // Some general instruction class info
500 class ArithLogic16Defs<bit isCom=0> {
502 bit isCommutable = isCom;
503 bit isReMaterializable = 1;
504 bit hasSideEffects = 0;
509 bit isTerminator = 1;
515 bit isTerminator = 1;
528 // Format: ADDIU rx, immediate MIPS16e
529 // Purpose: Add Immediate Unsigned Word (2-Operand, Extended)
530 // To add a constant to a 32-bit integer.
532 def AddiuRxImmX16: FEXT_RI16_ins<0b01001, "addiu", IIM16Alu>;
534 def AddiuRxRxImm16: F2RI16_ins<0b01001, "addiu", IIM16Alu>,
535 ArithLogic16Defs<0> {
536 let AddedComplexity = 5;
538 def AddiuRxRxImmX16: FEXT_2RI16_ins<0b01001, "addiu", IIM16Alu>,
539 ArithLogic16Defs<0> {
540 let isCodeGenOnly = 1;
543 def AddiuRxRyOffMemX16:
544 FEXT_RRI_A16_mem_ins<0, "addiu", mem16_ea, IIM16Alu>;
548 // Format: ADDIU rx, pc, immediate MIPS16e
549 // Purpose: Add Immediate Unsigned Word (3-Operand, PC-Relative, Extended)
550 // To add a constant to the program counter.
552 def AddiuRxPcImmX16: FEXT_RI16_PC_ins<0b00001, "addiu", IIM16Alu>;
555 // Format: ADDIU sp, immediate MIPS16e
556 // Purpose: Add Immediate Unsigned Word (2-Operand, SP-Relative, Extended)
557 // To add a constant to the stack pointer.
560 : FI816_SP_ins<0b011, "addiu", IIM16Alu> {
563 let AddedComplexity = 5;
567 : FEXT_I816_SP_ins<0b011, "addiu", IIM16Alu> {
573 // Format: ADDU rz, rx, ry MIPS16e
574 // Purpose: Add Unsigned Word (3-Operand)
575 // To add 32-bit integers.
578 def AdduRxRyRz16: FRRR16_ins<01, "addu", IIM16Alu>, ArithLogic16Defs<1>;
581 // Format: AND rx, ry MIPS16e
583 // To do a bitwise logical AND.
585 def AndRxRxRy16: FRxRxRy16_ins<0b01100, "and", IIM16Alu>, ArithLogic16Defs<1>;
589 // Format: BEQZ rx, offset MIPS16e
590 // Purpose: Branch on Equal to Zero
591 // To test a GPR then do a PC-relative conditional branch.
593 def BeqzRxImm16: FRI16_B_ins<0b00100, "beqz", IIM16Alu>, cbranch16;
597 // Format: BEQZ rx, offset MIPS16e
598 // Purpose: Branch on Equal to Zero (Extended)
599 // To test a GPR then do a PC-relative conditional branch.
601 def BeqzRxImmX16: FEXT_RI16_B_ins<0b00100, "beqz", IIM16Alu>, cbranch16;
604 // Format: B offset MIPS16e
605 // Purpose: Unconditional Branch (Extended)
606 // To do an unconditional PC-relative branch.
609 def Bimm16: FI16_ins<0b00010, "b", IIM16Alu>, branch16;
611 // Format: B offset MIPS16e
612 // Purpose: Unconditional Branch
613 // To do an unconditional PC-relative branch.
615 def BimmX16: FEXT_I16_ins<0b00010, "b", IIM16Alu>, branch16;
618 // Format: BNEZ rx, offset MIPS16e
619 // Purpose: Branch on Not Equal to Zero
620 // To test a GPR then do a PC-relative conditional branch.
622 def BnezRxImm16: FRI16_B_ins<0b00101, "bnez", IIM16Alu>, cbranch16;
625 // Format: BNEZ rx, offset MIPS16e
626 // Purpose: Branch on Not Equal to Zero (Extended)
627 // To test a GPR then do a PC-relative conditional branch.
629 def BnezRxImmX16: FEXT_RI16_B_ins<0b00101, "bnez", IIM16Alu>, cbranch16;
633 //Format: BREAK immediate
634 // Purpose: Breakpoint
635 // To cause a Breakpoint exception.
637 def Break16: FRRBreakNull16_ins<"break 0", IIM16Alu>;
639 // Format: BTEQZ offset MIPS16e
640 // Purpose: Branch on T Equal to Zero (Extended)
641 // To test special register T then do a PC-relative conditional branch.
643 def Bteqz16: FI816_ins<0b000, "bteqz", IIM16Alu>, cbranch16 {
647 def BteqzX16: FEXT_I816_ins<0b000, "bteqz", IIM16Alu>, cbranch16 {
651 def BteqzT8CmpX16: FEXT_T8I816_ins<"bteqz", "cmp">, cbranch16;
653 def BteqzT8CmpiX16: FEXT_T8I8I16_ins<"bteqz", "cmpi">,
656 def BteqzT8SltX16: FEXT_T8I816_ins<"bteqz", "slt">, cbranch16;
658 def BteqzT8SltuX16: FEXT_T8I816_ins<"bteqz", "sltu">, cbranch16;
660 def BteqzT8SltiX16: FEXT_T8I8I16_ins<"bteqz", "slti">, cbranch16;
662 def BteqzT8SltiuX16: FEXT_T8I8I16_ins<"bteqz", "sltiu">,
666 // Format: BTNEZ offset MIPS16e
667 // Purpose: Branch on T Not Equal to Zero (Extended)
668 // To test special register T then do a PC-relative conditional branch.
671 def Btnez16: FI816_ins<0b001, "btnez", IIM16Alu>, cbranch16 {
675 def BtnezX16: FEXT_I816_ins<0b001, "btnez", IIM16Alu> ,cbranch16 {
679 def BtnezT8CmpX16: FEXT_T8I816_ins<"btnez", "cmp">, cbranch16;
681 def BtnezT8CmpiX16: FEXT_T8I8I16_ins<"btnez", "cmpi">, cbranch16;
683 def BtnezT8SltX16: FEXT_T8I816_ins<"btnez", "slt">, cbranch16;
685 def BtnezT8SltuX16: FEXT_T8I816_ins<"btnez", "sltu">, cbranch16;
687 def BtnezT8SltiX16: FEXT_T8I8I16_ins<"btnez", "slti">, cbranch16;
689 def BtnezT8SltiuX16: FEXT_T8I8I16_ins<"btnez", "sltiu">,
693 // Format: CMP rx, ry MIPS16e
695 // To compare the contents of two GPRs.
697 def CmpRxRy16: FRR16R_ins<0b01010, "cmp", IIM16Alu> {
702 // Format: CMPI rx, immediate MIPS16e
703 // Purpose: Compare Immediate
704 // To compare a constant with the contents of a GPR.
706 def CmpiRxImm16: FRI16R_ins<0b01110, "cmpi", IIM16Alu> {
711 // Format: CMPI rx, immediate MIPS16e
712 // Purpose: Compare Immediate (Extended)
713 // To compare a constant with the contents of a GPR.
715 def CmpiRxImmX16: FEXT_RI16R_ins<0b01110, "cmpi", IIM16Alu> {
721 // Format: DIV rx, ry MIPS16e
722 // Purpose: Divide Word
723 // To divide 32-bit signed integers.
725 def DivRxRy16: FRR16_div_ins<0b11010, "div", IIM16Alu> {
726 let Defs = [HI0, LO0];
730 // Format: DIVU rx, ry MIPS16e
731 // Purpose: Divide Unsigned Word
732 // To divide 32-bit unsigned integers.
734 def DivuRxRy16: FRR16_div_ins<0b11011, "divu", IIM16Alu> {
735 let Defs = [HI0, LO0];
738 // Format: JAL target MIPS16e
739 // Purpose: Jump and Link
740 // To execute a procedure call within the current 256 MB-aligned
741 // region and preserve the current ISA.
744 def Jal16 : FJAL16_ins<0b0, "jal", IIM16Alu> {
745 let hasDelaySlot = 0; // not true, but we add the nop for now
750 def JalB16 : FJALB16_ins<0b0, "jal", IIM16Alu>, branch16 {
751 let hasDelaySlot = 0; // not true, but we add the nop for now
757 // Format: JR ra MIPS16e
758 // Purpose: Jump Register Through Register ra
759 // To execute a branch to the instruction address in the return
763 def JrRa16: FRR16_JALRC_RA_only_ins<0, 0, "jr", IIM16Alu> {
765 let isIndirectBranch = 1;
766 let hasDelaySlot = 1;
772 def JrcRa16: FRR16_JALRC_RA_only_ins<1, 1, "jrc", IIM16Alu> {
774 let isIndirectBranch = 1;
780 def JrcRx16: FRR16_JALRC_ins<1, 1, 0, "jrc", IIM16Alu> {
782 let isIndirectBranch = 1;
787 // Format: LB ry, offset(rx) MIPS16e
788 // Purpose: Load Byte (Extended)
789 // To load a byte from memory as a signed value.
791 def LbRxRyOffMemX16: FEXT_RRI16_mem_ins<0b10011, "lb", mem16, II_LB>, MayLoad{
792 let isCodeGenOnly = 1;
796 // Format: LBU ry, offset(rx) MIPS16e
797 // Purpose: Load Byte Unsigned (Extended)
798 // To load a byte from memory as a unsigned value.
800 def LbuRxRyOffMemX16:
801 FEXT_RRI16_mem_ins<0b10100, "lbu", mem16, II_LBU>, MayLoad {
802 let isCodeGenOnly = 1;
806 // Format: LH ry, offset(rx) MIPS16e
807 // Purpose: Load Halfword signed (Extended)
808 // To load a halfword from memory as a signed value.
810 def LhRxRyOffMemX16: FEXT_RRI16_mem_ins<0b10100, "lh", mem16, II_LH>, MayLoad{
811 let isCodeGenOnly = 1;
815 // Format: LHU ry, offset(rx) MIPS16e
816 // Purpose: Load Halfword unsigned (Extended)
817 // To load a halfword from memory as an unsigned value.
819 def LhuRxRyOffMemX16:
820 FEXT_RRI16_mem_ins<0b10100, "lhu", mem16, II_LHU>, MayLoad {
821 let isCodeGenOnly = 1;
825 // Format: LI rx, immediate MIPS16e
826 // Purpose: Load Immediate
827 // To load a constant into a GPR.
829 def LiRxImm16: FRI16_ins<0b01101, "li", IIM16Alu>;
832 // Format: LI rx, immediate MIPS16e
833 // Purpose: Load Immediate (Extended)
834 // To load a constant into a GPR.
836 def LiRxImmX16: FEXT_RI16_ins<0b01101, "li", IIM16Alu>;
838 def LiRxImmAlignX16: FEXT_RI16_ins<0b01101, ".align 2\n\tli", IIM16Alu> {
839 let isCodeGenOnly = 1;
843 // Format: LW ry, offset(rx) MIPS16e
844 // Purpose: Load Word (Extended)
845 // To load a word from memory as a signed value.
847 def LwRxRyOffMemX16: FEXT_RRI16_mem_ins<0b10011, "lw", mem16, II_LW>, MayLoad{
848 let isCodeGenOnly = 1;
851 // Format: LW rx, offset(sp) MIPS16e
852 // Purpose: Load Word (SP-Relative, Extended)
853 // To load an SP-relative word from memory as a signed value.
855 def LwRxSpImmX16: FEXT_RRI16_mem_ins<0b10010, "lw", mem16sp, II_LW>, MayLoad;
857 def LwRxPcTcp16: FRI16_TCP_ins<0b10110, "lw", II_LW>, MayLoad;
859 def LwRxPcTcpX16: FEXT_RI16_TCP_ins<0b10110, "lw", II_LW>, MayLoad;
861 // Format: MOVE r32, rz MIPS16e
863 // To move the contents of a GPR to a GPR.
865 def Move32R16: FI8_MOV32R16_ins<"move", IIM16Alu>;
868 // Format: MOVE ry, r32 MIPS16e
870 // To move the contents of a GPR to a GPR.
872 def MoveR3216: FI8_MOVR3216_ins<"move", IIM16Alu>;
875 // Format: MFHI rx MIPS16e
876 // Purpose: Move From HI Register
877 // To copy the special purpose HI register to a GPR.
879 def Mfhi16: FRR16_M_ins<0b10000, "mfhi", IIM16Alu> {
881 let hasSideEffects = 0;
885 // Format: MFLO rx MIPS16e
886 // Purpose: Move From LO Register
887 // To copy the special purpose LO register to a GPR.
889 def Mflo16: FRR16_M_ins<0b10010, "mflo", IIM16Alu> {
891 let hasSideEffects = 0;
895 // Pseudo Instruction for mult
897 def MultRxRy16: FMULT16_ins<"mult", IIM16Alu> {
898 let isCommutable = 1;
899 let hasSideEffects = 0;
900 let Defs = [HI0, LO0];
903 def MultuRxRy16: FMULT16_ins<"multu", IIM16Alu> {
904 let isCommutable = 1;
905 let hasSideEffects = 0;
906 let Defs = [HI0, LO0];
910 // Format: MULT rx, ry MIPS16e
911 // Purpose: Multiply Word
912 // To multiply 32-bit signed integers.
914 def MultRxRyRz16: FMULT16_LO_ins<"mult", IIM16Alu> {
915 let isCommutable = 1;
916 let hasSideEffects = 0;
917 let Defs = [HI0, LO0];
921 // Format: MULTU rx, ry MIPS16e
922 // Purpose: Multiply Unsigned Word
923 // To multiply 32-bit unsigned integers.
925 def MultuRxRyRz16: FMULT16_LO_ins<"multu", IIM16Alu> {
926 let isCommutable = 1;
927 let hasSideEffects = 0;
928 let Defs = [HI0, LO0];
932 // Format: NEG rx, ry MIPS16e
934 // To negate an integer value.
936 def NegRxRy16: FUnaryRR16_ins<0b11101, "neg", IIM16Alu>;
939 // Format: NOT rx, ry MIPS16e
941 // To complement an integer value
943 def NotRxRy16: FUnaryRR16_ins<0b01111, "not", IIM16Alu>;
946 // Format: OR rx, ry MIPS16e
948 // To do a bitwise logical OR.
950 def OrRxRxRy16: FRxRxRy16_ins<0b01101, "or", IIM16Alu>, ArithLogic16Defs<1>;
953 // Format: RESTORE {ra,}{s0/s1/s0-1,}{framesize}
954 // (All args are optional) MIPS16e
955 // Purpose: Restore Registers and Deallocate Stack Frame
956 // To deallocate a stack frame before exit from a subroutine,
957 // restoring return address and static registers, and adjusting
962 FI8_SVRS16<0b1, (outs), (ins variable_ops),
963 "", [], II_RESTORE >, MayLoad {
964 let isCodeGenOnly = 1;
971 FI8_SVRS16<0b1, (outs), (ins variable_ops),
972 "", [], II_RESTORE >, MayLoad {
973 let isCodeGenOnly = 1;
979 // Format: SAVE {ra,}{s0/s1/s0-1,}{framesize} (All arguments are optional)
981 // Purpose: Save Registers and Set Up Stack Frame
982 // To set up a stack frame on entry to a subroutine,
983 // saving return address and static registers, and adjusting stack
986 FI8_SVRS16<0b1, (outs), (ins variable_ops),
987 "", [], II_SAVE >, MayStore {
988 let isCodeGenOnly = 1;
994 FI8_SVRS16<0b1, (outs), (ins variable_ops),
995 "", [], II_SAVE >, MayStore {
996 let isCodeGenOnly = 1;
1001 // Format: SB ry, offset(rx) MIPS16e
1002 // Purpose: Store Byte (Extended)
1003 // To store a byte to memory.
1005 def SbRxRyOffMemX16:
1006 FEXT_RRI16_mem2_ins<0b11000, "sb", mem16, II_SB>, MayStore;
1009 // Format: SEB rx MIPS16e
1010 // Purpose: Sign-Extend Byte
1011 // Sign-extend least significant byte in register rx.
1014 : FRR_SF16_ins<0b10001, 0b100, "seb", IIM16Alu>;
1017 // Format: SEH rx MIPS16e
1018 // Purpose: Sign-Extend Halfword
1019 // Sign-extend least significant word in register rx.
1022 : FRR_SF16_ins<0b10001, 0b101, "seh", IIM16Alu>;
1025 // The Sel(T) instructions are pseudos
1026 // T means that they use T8 implicitly.
1029 // Format: SelBeqZ rd, rs, rt
1030 // Purpose: if rt==0, do nothing
1033 def SelBeqZ: Sel<"beqz">;
1036 // Format: SelTBteqZCmp rd, rs, rl, rr
1037 // Purpose: b = Cmp rl, rr.
1038 // If b==0 then do nothing.
1039 // if b!=0 then rd = rs
1041 def SelTBteqZCmp: SelT<"bteqz", "cmp">;
1044 // Format: SelTBteqZCmpi rd, rs, rl, rr
1045 // Purpose: b = Cmpi rl, imm.
1046 // If b==0 then do nothing.
1047 // if b!=0 then rd = rs
1049 def SelTBteqZCmpi: SeliT<"bteqz", "cmpi">;
1052 // Format: SelTBteqZSlt rd, rs, rl, rr
1053 // Purpose: b = Slt rl, rr.
1054 // If b==0 then do nothing.
1055 // if b!=0 then rd = rs
1057 def SelTBteqZSlt: SelT<"bteqz", "slt">;
1060 // Format: SelTBteqZSlti rd, rs, rl, rr
1061 // Purpose: b = Slti rl, imm.
1062 // If b==0 then do nothing.
1063 // if b!=0 then rd = rs
1065 def SelTBteqZSlti: SeliT<"bteqz", "slti">;
1068 // Format: SelTBteqZSltu rd, rs, rl, rr
1069 // Purpose: b = Sltu rl, rr.
1070 // If b==0 then do nothing.
1071 // if b!=0 then rd = rs
1073 def SelTBteqZSltu: SelT<"bteqz", "sltu">;
1076 // Format: SelTBteqZSltiu rd, rs, rl, rr
1077 // Purpose: b = Sltiu rl, imm.
1078 // If b==0 then do nothing.
1079 // if b!=0 then rd = rs
1081 def SelTBteqZSltiu: SeliT<"bteqz", "sltiu">;
1084 // Format: SelBnez rd, rs, rt
1085 // Purpose: if rt!=0, do nothing
1088 def SelBneZ: Sel<"bnez">;
1091 // Format: SelTBtneZCmp rd, rs, rl, rr
1092 // Purpose: b = Cmp rl, rr.
1093 // If b!=0 then do nothing.
1094 // if b0=0 then rd = rs
1096 def SelTBtneZCmp: SelT<"btnez", "cmp">;
1099 // Format: SelTBtnezCmpi rd, rs, rl, rr
1100 // Purpose: b = Cmpi rl, imm.
1101 // If b!=0 then do nothing.
1102 // if b==0 then rd = rs
1104 def SelTBtneZCmpi: SeliT<"btnez", "cmpi">;
1107 // Format: SelTBtneZSlt rd, rs, rl, rr
1108 // Purpose: b = Slt rl, rr.
1109 // If b!=0 then do nothing.
1110 // if b==0 then rd = rs
1112 def SelTBtneZSlt: SelT<"btnez", "slt">;
1115 // Format: SelTBtneZSlti rd, rs, rl, rr
1116 // Purpose: b = Slti rl, imm.
1117 // If b!=0 then do nothing.
1118 // if b==0 then rd = rs
1120 def SelTBtneZSlti: SeliT<"btnez", "slti">;
1123 // Format: SelTBtneZSltu rd, rs, rl, rr
1124 // Purpose: b = Sltu rl, rr.
1125 // If b!=0 then do nothing.
1126 // if b==0 then rd = rs
1128 def SelTBtneZSltu: SelT<"btnez", "sltu">;
1131 // Format: SelTBtneZSltiu rd, rs, rl, rr
1132 // Purpose: b = Slti rl, imm.
1133 // If b!=0 then do nothing.
1134 // if b==0 then rd = rs
1136 def SelTBtneZSltiu: SeliT<"btnez", "sltiu">;
1139 // Format: SH ry, offset(rx) MIPS16e
1140 // Purpose: Store Halfword (Extended)
1141 // To store a halfword to memory.
1143 def ShRxRyOffMemX16:
1144 FEXT_RRI16_mem2_ins<0b11001, "sh", mem16, II_SH>, MayStore;
1147 // Format: SLL rx, ry, sa MIPS16e
1148 // Purpose: Shift Word Left Logical (Extended)
1149 // To execute a left-shift of a word by a fixed number of bits-0 to 31 bits.
1151 def SllX16: FEXT_SHIFT16_ins<0b00, "sll", IIM16Alu>;
1154 // Format: SLLV ry, rx MIPS16e
1155 // Purpose: Shift Word Left Logical Variable
1156 // To execute a left-shift of a word by a variable number of bits.
1158 def SllvRxRy16 : FRxRxRy16_ins<0b00100, "sllv", IIM16Alu>;
1160 // Format: SLTI rx, immediate MIPS16e
1161 // Purpose: Set on Less Than Immediate
1162 // To record the result of a less-than comparison with a constant.
1165 def SltiRxImm16: FRI16R_ins<0b01010, "slti", IIM16Alu> {
1170 // Format: SLTI rx, immediate MIPS16e
1171 // Purpose: Set on Less Than Immediate (Extended)
1172 // To record the result of a less-than comparison with a constant.
1175 def SltiRxImmX16: FEXT_RI16R_ins<0b01010, "slti", IIM16Alu> {
1179 def SltiCCRxImmX16: FEXT_CCRXI16_ins<"slti">;
1181 // Format: SLTIU rx, immediate MIPS16e
1182 // Purpose: Set on Less Than Immediate Unsigned
1183 // To record the result of a less-than comparison with a constant.
1186 def SltiuRxImm16: FRI16R_ins<0b01011, "sltiu", IIM16Alu> {
1191 // Format: SLTI rx, immediate MIPS16e
1192 // Purpose: Set on Less Than Immediate Unsigned (Extended)
1193 // To record the result of a less-than comparison with a constant.
1196 def SltiuRxImmX16: FEXT_RI16R_ins<0b01011, "sltiu", IIM16Alu> {
1200 // Format: SLTIU rx, immediate MIPS16e
1201 // Purpose: Set on Less Than Immediate Unsigned (Extended)
1202 // To record the result of a less-than comparison with a constant.
1204 def SltiuCCRxImmX16: FEXT_CCRXI16_ins<"sltiu">;
1207 // Format: SLT rx, ry MIPS16e
1208 // Purpose: Set on Less Than
1209 // To record the result of a less-than comparison.
1211 def SltRxRy16: FRR16R_ins<0b00010, "slt", IIM16Alu>{
1215 def SltCCRxRy16: FCCRR16_ins<"slt">;
1217 // Format: SLTU rx, ry MIPS16e
1218 // Purpose: Set on Less Than Unsigned
1219 // To record the result of an unsigned less-than comparison.
1221 def SltuRxRy16: FRR16R_ins<0b00011, "sltu", IIM16Alu>{
1225 def SltuRxRyRz16: FRRTR16_ins<"sltu"> {
1226 let isCodeGenOnly=1;
1231 def SltuCCRxRy16: FCCRR16_ins<"sltu">;
1233 // Format: SRAV ry, rx MIPS16e
1234 // Purpose: Shift Word Right Arithmetic Variable
1235 // To execute an arithmetic right-shift of a word by a variable
1238 def SravRxRy16: FRxRxRy16_ins<0b00111, "srav", IIM16Alu>;
1242 // Format: SRA rx, ry, sa MIPS16e
1243 // Purpose: Shift Word Right Arithmetic (Extended)
1244 // To execute an arithmetic right-shift of a word by a fixed
1245 // number of bits-1 to 8 bits.
1247 def SraX16: FEXT_SHIFT16_ins<0b11, "sra", IIM16Alu>;
1251 // Format: SRLV ry, rx MIPS16e
1252 // Purpose: Shift Word Right Logical Variable
1253 // To execute a logical right-shift of a word by a variable
1256 def SrlvRxRy16: FRxRxRy16_ins<0b00110, "srlv", IIM16Alu>;
1260 // Format: SRL rx, ry, sa MIPS16e
1261 // Purpose: Shift Word Right Logical (Extended)
1262 // To execute a logical right-shift of a word by a fixed
1263 // number of bits-1 to 31 bits.
1265 def SrlX16: FEXT_SHIFT16_ins<0b10, "srl", IIM16Alu>;
1268 // Format: SUBU rz, rx, ry MIPS16e
1269 // Purpose: Subtract Unsigned Word
1270 // To subtract 32-bit integers
1272 def SubuRxRyRz16: FRRR16_ins<0b11, "subu", IIM16Alu>, ArithLogic16Defs<0>;
1275 // Format: SW ry, offset(rx) MIPS16e
1276 // Purpose: Store Word (Extended)
1277 // To store a word to memory.
1279 def SwRxRyOffMemX16: FEXT_RRI16_mem2_ins<0b11011, "sw", mem16, II_SW>, MayStore;
1282 // Format: SW rx, offset(sp) MIPS16e
1283 // Purpose: Store Word rx (SP-Relative)
1284 // To store an SP-relative word to memory.
1286 def SwRxSpImmX16: FEXT_RRI16_mem2_ins<0b11010, "sw", mem16sp, II_SW>, MayStore;
1290 // Format: XOR rx, ry MIPS16e
1292 // To do a bitwise logical XOR.
1294 def XorRxRxRy16: FRxRxRy16_ins<0b01110, "xor", IIM16Alu>, ArithLogic16Defs<1>;
1296 class Mips16Pat<dag pattern, dag result> : Pat<pattern, result> {
1297 let Predicates = [InMips16Mode];
1300 // Unary Arith/Logic
1302 class ArithLogicU_pat<PatFrag OpNode, Instruction I> :
1303 Mips16Pat<(OpNode CPU16Regs:$r),
1306 def: ArithLogicU_pat<not, NotRxRy16>;
1307 def: ArithLogicU_pat<ineg, NegRxRy16>;
1309 class ArithLogic16_pat<SDNode OpNode, Instruction I> :
1310 Mips16Pat<(OpNode CPU16Regs:$l, CPU16Regs:$r),
1311 (I CPU16Regs:$l, CPU16Regs:$r)>;
1313 def: ArithLogic16_pat<add, AdduRxRyRz16>;
1314 def: ArithLogic16_pat<and, AndRxRxRy16>;
1315 def: ArithLogic16_pat<mul, MultRxRyRz16>;
1316 def: ArithLogic16_pat<or, OrRxRxRy16>;
1317 def: ArithLogic16_pat<sub, SubuRxRyRz16>;
1318 def: ArithLogic16_pat<xor, XorRxRxRy16>;
1320 // Arithmetic and logical instructions with 2 register operands.
1322 class ArithLogicI16_pat<SDNode OpNode, PatFrag imm_type, Instruction I> :
1323 Mips16Pat<(OpNode CPU16Regs:$in, imm_type:$imm),
1324 (I CPU16Regs:$in, imm_type:$imm)>;
1326 def: ArithLogicI16_pat<add, immSExt8, AddiuRxRxImm16>;
1327 def: ArithLogicI16_pat<add, immSExt16, AddiuRxRxImmX16>;
1328 def: ArithLogicI16_pat<shl, immZExt5, SllX16>;
1329 def: ArithLogicI16_pat<srl, immZExt5, SrlX16>;
1330 def: ArithLogicI16_pat<sra, immZExt5, SraX16>;
1332 class shift_rotate_reg16_pat<SDNode OpNode, Instruction I> :
1333 Mips16Pat<(OpNode CPU16Regs:$r, CPU16Regs:$ra),
1334 (I CPU16Regs:$r, CPU16Regs:$ra)>;
1336 def: shift_rotate_reg16_pat<shl, SllvRxRy16>;
1337 def: shift_rotate_reg16_pat<sra, SravRxRy16>;
1338 def: shift_rotate_reg16_pat<srl, SrlvRxRy16>;
1340 class LoadM16_pat<PatFrag OpNode, Instruction I, ComplexPattern Addr> :
1341 Mips16Pat<(OpNode Addr:$addr), (I Addr:$addr)>;
1343 def: LoadM16_pat<sextloadi8, LbRxRyOffMemX16, addr16>;
1344 def: LoadM16_pat<zextloadi8, LbuRxRyOffMemX16, addr16>;
1345 def: LoadM16_pat<sextloadi16, LhRxRyOffMemX16, addr16>;
1346 def: LoadM16_pat<zextloadi16, LhuRxRyOffMemX16, addr16>;
1347 def: LoadM16_pat<load, LwRxSpImmX16, addr16sp>;
1349 class StoreM16_pat<PatFrag OpNode, Instruction I, ComplexPattern Addr> :
1350 Mips16Pat<(OpNode CPU16Regs:$r, Addr:$addr), (I CPU16Regs:$r, Addr:$addr)>;
1352 def: StoreM16_pat<truncstorei8, SbRxRyOffMemX16, addr16>;
1353 def: StoreM16_pat<truncstorei16, ShRxRyOffMemX16, addr16>;
1354 def: StoreM16_pat<store, SwRxSpImmX16, addr16sp>;
1356 // Unconditional branch
1357 class UncondBranch16_pat<SDNode OpNode, Instruction I>:
1358 Mips16Pat<(OpNode bb:$imm16), (I bb:$imm16)> {
1359 let Predicates = [InMips16Mode];
1362 def : Mips16Pat<(MipsJmpLink (i32 tglobaladdr:$dst)),
1363 (Jal16 tglobaladdr:$dst)>;
1365 def : Mips16Pat<(MipsJmpLink (i32 texternalsym:$dst)),
1366 (Jal16 texternalsym:$dst)>;
1369 def: Mips16Pat<(brind CPU16Regs:$rs), (JrcRx16 CPU16Regs:$rs)> {
1370 // Ensure that the addition of MIPS32r6/MIPS64r6 support does not change
1371 // MIPS16's behaviour.
1372 let AddedComplexity = 1;
1375 // Jump and Link (Call)
1376 let isCall=1, hasDelaySlot=0 in
1378 FRR16_JALRC<0, 0, 0, (outs), (ins CPU16Regs:$rs),
1379 "jalrc\t$rs", [(MipsJmpLink CPU16Regs:$rs)], II_JALRC> {
1384 let isReturn=1, isTerminator=1, hasDelaySlot=1, isBarrier=1, hasCtrlDep=1,
1385 hasExtraSrcRegAllocReq = 1 in
1386 def RetRA16 : MipsPseudo16<(outs), (ins), "", [(MipsRet)]>;
1391 class SetCC_R16<PatFrag cond_op, Instruction I>:
1392 Mips16Pat<(cond_op CPU16Regs:$rx, CPU16Regs:$ry),
1393 (I CPU16Regs:$rx, CPU16Regs:$ry)>;
1395 class SetCC_I16<PatFrag cond_op, PatLeaf imm_type, Instruction I>:
1396 Mips16Pat<(cond_op CPU16Regs:$rx, imm_type:$imm16),
1397 (I CPU16Regs:$rx, imm_type:$imm16)>;
1400 def: Mips16Pat<(i32 addr16sp:$addr), (AddiuRxRyOffMemX16 addr16sp:$addr)>;
1403 // Large (>16 bit) immediate loads
1404 def : Mips16Pat<(i32 imm:$imm), (LwConstant32 imm:$imm, -1)>;
1406 // Carry MipsPatterns
1407 def : Mips16Pat<(subc CPU16Regs:$lhs, CPU16Regs:$rhs),
1408 (SubuRxRyRz16 CPU16Regs:$lhs, CPU16Regs:$rhs)>;
1409 def : Mips16Pat<(addc CPU16Regs:$lhs, CPU16Regs:$rhs),
1410 (AdduRxRyRz16 CPU16Regs:$lhs, CPU16Regs:$rhs)>;
1411 def : Mips16Pat<(addc CPU16Regs:$src, immSExt16:$imm),
1412 (AddiuRxRxImmX16 CPU16Regs:$src, imm:$imm)>;
1415 // Some branch conditional patterns are not generated by llvm at this time.
1416 // Some are for seemingly arbitrary reasons not used: i.e. with signed number
1417 // comparison they are used and for unsigned a different pattern is used.
1418 // I am pushing upstream from the full mips16 port and it seemed that I needed
1419 // these earlier and the mips32 port has these but now I cannot create test
1420 // cases that use these patterns. While I sort this all out I will leave these
1421 // extra patterns commented out and if I can be sure they are really not used,
1422 // I will delete the code. I don't want to check the code in uncommented without
1423 // a valid test case. In some cases, the compiler is generating patterns with
1424 // setcc instead and earlier I had implemented setcc first so may have masked
1425 // the problem. The setcc variants are suboptimal for mips16 so I may wantto
1426 // figure out how to enable the brcond patterns or else possibly new
1427 // combinations of of brcond and setcc.
1433 <(brcond (i32 (seteq CPU16Regs:$rx, CPU16Regs:$ry)), bb:$imm16),
1434 (BteqzT8CmpX16 CPU16Regs:$rx, CPU16Regs:$ry, bb:$imm16)
1439 <(brcond (i32 (seteq CPU16Regs:$rx, immZExt16:$imm)), bb:$targ16),
1440 (BteqzT8CmpiX16 CPU16Regs:$rx, immSExt16:$imm, bb:$targ16)
1444 <(brcond (i32 (seteq CPU16Regs:$rx, 0)), bb:$targ16),
1445 (BeqzRxImm16 CPU16Regs:$rx, bb:$targ16)
1449 // bcond-setgt (do we need to have this pair of setlt, setgt??)
1452 <(brcond (i32 (setgt CPU16Regs:$rx, CPU16Regs:$ry)), bb:$imm16),
1453 (BtnezT8SltX16 CPU16Regs:$ry, CPU16Regs:$rx, bb:$imm16)
1460 <(brcond (i32 (setge CPU16Regs:$rx, CPU16Regs:$ry)), bb:$imm16),
1461 (BteqzT8SltX16 CPU16Regs:$rx, CPU16Regs:$ry, bb:$imm16)
1465 // never called because compiler transforms a >= k to a > (k-1)
1467 <(brcond (i32 (setge CPU16Regs:$rx, immSExt16:$imm)), bb:$imm16),
1468 (BteqzT8SltiX16 CPU16Regs:$rx, immSExt16:$imm, bb:$imm16)
1475 <(brcond (i32 (setlt CPU16Regs:$rx, CPU16Regs:$ry)), bb:$imm16),
1476 (BtnezT8SltX16 CPU16Regs:$rx, CPU16Regs:$ry, bb:$imm16)
1480 <(brcond (i32 (setlt CPU16Regs:$rx, immSExt16:$imm)), bb:$imm16),
1481 (BtnezT8SltiX16 CPU16Regs:$rx, immSExt16:$imm, bb:$imm16)
1488 <(brcond (i32 (setle CPU16Regs:$rx, CPU16Regs:$ry)), bb:$imm16),
1489 (BteqzT8SltX16 CPU16Regs:$ry, CPU16Regs:$rx, bb:$imm16)
1496 <(brcond (i32 (setne CPU16Regs:$rx, CPU16Regs:$ry)), bb:$imm16),
1497 (BtnezT8CmpX16 CPU16Regs:$rx, CPU16Regs:$ry, bb:$imm16)
1501 <(brcond (i32 (setne CPU16Regs:$rx, immZExt16:$imm)), bb:$targ16),
1502 (BtnezT8CmpiX16 CPU16Regs:$rx, immSExt16:$imm, bb:$targ16)
1506 <(brcond (i32 (setne CPU16Regs:$rx, 0)), bb:$targ16),
1507 (BnezRxImm16 CPU16Regs:$rx, bb:$targ16)
1511 // This needs to be there but I forget which code will generate it
1514 <(brcond CPU16Regs:$rx, bb:$targ16),
1515 (BnezRxImm16 CPU16Regs:$rx, bb:$targ16)
1524 // <(brcond (i32 (setugt CPU16Regs:$rx, CPU16Regs:$ry)), bb:$imm16),
1525 // (BtnezT8SltuX16 CPU16Regs:$ry, CPU16Regs:$rx, bb:$imm16)
1532 // <(brcond (i32 (setuge CPU16Regs:$rx, CPU16Regs:$ry)), bb:$imm16),
1533 // (BteqzT8SltuX16 CPU16Regs:$rx, CPU16Regs:$ry, bb:$imm16)
1541 // <(brcond (i32 (setult CPU16Regs:$rx, CPU16Regs:$ry)), bb:$imm16),
1542 // (BtnezT8SltuX16 CPU16Regs:$rx, CPU16Regs:$ry, bb:$imm16)
1545 def: UncondBranch16_pat<br, Bimm16>;
1548 def: Mips16Pat<(i32 immSExt16:$in),
1549 (AddiuRxRxImmX16 (MoveR3216 ZERO), immSExt16:$in)>;
1551 def: Mips16Pat<(i32 immZExt16:$in), (LiRxImmX16 immZExt16:$in)>;
1557 <(MipsDivRem16 CPU16Regs:$rx, CPU16Regs:$ry),
1558 (DivRxRy16 CPU16Regs:$rx, CPU16Regs:$ry)>;
1564 <(MipsDivRemU16 CPU16Regs:$rx, CPU16Regs:$ry),
1565 (DivuRxRy16 CPU16Regs:$rx, CPU16Regs:$ry)>;
1570 // if !(a < b) x = y
1572 def : Mips16Pat<(select (i32 (setge CPU16Regs:$a, CPU16Regs:$b)),
1573 CPU16Regs:$x, CPU16Regs:$y),
1574 (SelTBteqZSlt CPU16Regs:$x, CPU16Regs:$y,
1575 CPU16Regs:$a, CPU16Regs:$b)>;
1582 def : Mips16Pat<(select (i32 (setgt CPU16Regs:$a, CPU16Regs:$b)),
1583 CPU16Regs:$x, CPU16Regs:$y),
1584 (SelTBtneZSlt CPU16Regs:$x, CPU16Regs:$y,
1585 CPU16Regs:$b, CPU16Regs:$a)>;
1590 // if !(a < b) x = y;
1593 (select (i32 (setuge CPU16Regs:$a, CPU16Regs:$b)),
1594 CPU16Regs:$x, CPU16Regs:$y),
1595 (SelTBteqZSltu CPU16Regs:$x, CPU16Regs:$y,
1596 CPU16Regs:$a, CPU16Regs:$b)>;
1603 def : Mips16Pat<(select (i32 (setugt CPU16Regs:$a, CPU16Regs:$b)),
1604 CPU16Regs:$x, CPU16Regs:$y),
1605 (SelTBtneZSltu CPU16Regs:$x, CPU16Regs:$y,
1606 CPU16Regs:$b, CPU16Regs:$a)>;
1610 // due to an llvm optimization, i don't think that this will ever
1611 // be used. This is transformed into x = (a > k-1)?x:y
1616 // (select (i32 (setge CPU16Regs:$lhs, immSExt16:$rhs)),
1617 // CPU16Regs:$T, CPU16Regs:$F),
1618 // (SelTBteqZSlti CPU16Regs:$T, CPU16Regs:$F,
1619 // CPU16Regs:$lhs, immSExt16:$rhs)>;
1622 // (select (i32 (setuge CPU16Regs:$lhs, immSExt16:$rhs)),
1623 // CPU16Regs:$T, CPU16Regs:$F),
1624 // (SelTBteqZSltiu CPU16Regs:$T, CPU16Regs:$F,
1625 // CPU16Regs:$lhs, immSExt16:$rhs)>;
1630 // if !(a < k) x = y;
1633 (select (i32 (setlt CPU16Regs:$a, immSExt16:$b)),
1634 CPU16Regs:$x, CPU16Regs:$y),
1635 (SelTBtneZSlti CPU16Regs:$x, CPU16Regs:$y,
1636 CPU16Regs:$a, immSExt16:$b)>;
1642 // x = (a <= b)? x : y
1646 def : Mips16Pat<(select (i32 (setle CPU16Regs:$a, CPU16Regs:$b)),
1647 CPU16Regs:$x, CPU16Regs:$y),
1648 (SelTBteqZSlt CPU16Regs:$x, CPU16Regs:$y,
1649 CPU16Regs:$b, CPU16Regs:$a)>;
1653 // x = (a <= b)? x : y
1657 def : Mips16Pat<(select (i32 (setule CPU16Regs:$a, CPU16Regs:$b)),
1658 CPU16Regs:$x, CPU16Regs:$y),
1659 (SelTBteqZSltu CPU16Regs:$x, CPU16Regs:$y,
1660 CPU16Regs:$b, CPU16Regs:$a)>;
1664 // x = (a == b)? x : y
1666 // if (a != b) x = y
1668 def : Mips16Pat<(select (i32 (seteq CPU16Regs:$a, CPU16Regs:$b)),
1669 CPU16Regs:$x, CPU16Regs:$y),
1670 (SelTBteqZCmp CPU16Regs:$x, CPU16Regs:$y,
1671 CPU16Regs:$b, CPU16Regs:$a)>;
1675 // x = (a == 0)? x : y
1677 // if (a != 0) x = y
1679 def : Mips16Pat<(select (i32 (seteq CPU16Regs:$a, 0)),
1680 CPU16Regs:$x, CPU16Regs:$y),
1681 (SelBeqZ CPU16Regs:$x, CPU16Regs:$y,
1687 // x = (a == k)? x : y
1689 // if (a != k) x = y
1691 def : Mips16Pat<(select (i32 (seteq CPU16Regs:$a, immZExt16:$k)),
1692 CPU16Regs:$x, CPU16Regs:$y),
1693 (SelTBteqZCmpi CPU16Regs:$x, CPU16Regs:$y,
1694 CPU16Regs:$a, immZExt16:$k)>;
1699 // x = (a != b)? x : y
1701 // if (a == b) x = y
1704 def : Mips16Pat<(select (i32 (setne CPU16Regs:$a, CPU16Regs:$b)),
1705 CPU16Regs:$x, CPU16Regs:$y),
1706 (SelTBtneZCmp CPU16Regs:$x, CPU16Regs:$y,
1707 CPU16Regs:$b, CPU16Regs:$a)>;
1711 // x = (a != 0)? x : y
1713 // if (a == 0) x = y
1715 def : Mips16Pat<(select (i32 (setne CPU16Regs:$a, 0)),
1716 CPU16Regs:$x, CPU16Regs:$y),
1717 (SelBneZ CPU16Regs:$x, CPU16Regs:$y,
1725 def : Mips16Pat<(select CPU16Regs:$a,
1726 CPU16Regs:$x, CPU16Regs:$y),
1727 (SelBneZ CPU16Regs:$x, CPU16Regs:$y,
1733 // x = (a != k)? x : y
1735 // if (a == k) x = y
1737 def : Mips16Pat<(select (i32 (setne CPU16Regs:$a, immZExt16:$k)),
1738 CPU16Regs:$x, CPU16Regs:$y),
1739 (SelTBtneZCmpi CPU16Regs:$x, CPU16Regs:$y,
1740 CPU16Regs:$a, immZExt16:$k)>;
1743 // When writing C code to test setxx these patterns,
1744 // some will be transformed into
1745 // other things. So we test using C code but using -O3 and -O0
1750 <(seteq CPU16Regs:$lhs,CPU16Regs:$rhs),
1751 (SltiuCCRxImmX16 (XorRxRxRy16 CPU16Regs:$lhs, CPU16Regs:$rhs), 1)>;
1754 <(seteq CPU16Regs:$lhs, 0),
1755 (SltiuCCRxImmX16 CPU16Regs:$lhs, 1)>;
1763 <(setge CPU16Regs:$lhs, CPU16Regs:$rhs),
1764 (XorRxRxRy16 (SltCCRxRy16 CPU16Regs:$lhs, CPU16Regs:$rhs),
1768 // For constants, llvm transforms this to:
1769 // x > (k - 1) and then reverses the operands to use setlt. So this pattern
1770 // is not used now by the compiler. (Presumably checking that k-1 does not
1771 // overflow). The compiler never uses this at the current time, due to
1772 // other optimizations.
1775 // <(setge CPU16Regs:$lhs, immSExt16:$rhs),
1776 // (XorRxRxRy16 (SltiCCRxImmX16 CPU16Regs:$lhs, immSExt16:$rhs),
1777 // (LiRxImmX16 1))>;
1779 // This catches the x >= -32768 case by transforming it to x > -32769
1782 <(setgt CPU16Regs:$lhs, -32769),
1783 (XorRxRxRy16 (SltiCCRxImmX16 CPU16Regs:$lhs, -32768),
1792 <(setgt CPU16Regs:$lhs, CPU16Regs:$rhs),
1793 (SltCCRxRy16 CPU16Regs:$rhs, CPU16Regs:$lhs)>;
1799 <(setle CPU16Regs:$lhs, CPU16Regs:$rhs),
1800 (XorRxRxRy16 (SltCCRxRy16 CPU16Regs:$rhs, CPU16Regs:$lhs), (LiRxImm16 1))>;
1805 def: SetCC_R16<setlt, SltCCRxRy16>;
1807 def: SetCC_I16<setlt, immSExt16, SltiCCRxImmX16>;
1813 <(setne CPU16Regs:$lhs,CPU16Regs:$rhs),
1814 (SltuCCRxRy16 (LiRxImmX16 0),
1815 (XorRxRxRy16 CPU16Regs:$lhs, CPU16Regs:$rhs))>;
1822 <(setuge CPU16Regs:$lhs, CPU16Regs:$rhs),
1823 (XorRxRxRy16 (SltuCCRxRy16 CPU16Regs:$lhs, CPU16Regs:$rhs),
1826 // this pattern will never be used because the compiler will transform
1827 // x >= k to x > (k - 1) and then use SLT
1830 // <(setuge CPU16Regs:$lhs, immZExt16:$rhs),
1831 // (XorRxRxRy16 (SltiuCCRxImmX16 CPU16Regs:$lhs, immZExt16:$rhs),
1832 // (LiRxImmX16 1))>;
1838 <(setugt CPU16Regs:$lhs, CPU16Regs:$rhs),
1839 (SltuCCRxRy16 CPU16Regs:$rhs, CPU16Regs:$lhs)>;
1845 <(setule CPU16Regs:$lhs, CPU16Regs:$rhs),
1846 (XorRxRxRy16 (SltuCCRxRy16 CPU16Regs:$rhs, CPU16Regs:$lhs), (LiRxImmX16 1))>;
1851 def: SetCC_R16<setult, SltuCCRxRy16>;
1853 def: SetCC_I16<setult, immSExt16, SltiuCCRxImmX16>;
1855 def: Mips16Pat<(add CPU16Regs:$hi, (MipsLo tglobaladdr:$lo)),
1856 (AddiuRxRxImmX16 CPU16Regs:$hi, tglobaladdr:$lo)>;
1859 def : Mips16Pat<(MipsHi tblockaddress:$in),
1860 (SllX16 (LiRxImmX16 tblockaddress:$in), 16)>;
1861 def : Mips16Pat<(MipsHi tglobaladdr:$in),
1862 (SllX16 (LiRxImmX16 tglobaladdr:$in), 16)>;
1863 def : Mips16Pat<(MipsHi tjumptable:$in),
1864 (SllX16 (LiRxImmX16 tjumptable:$in), 16)>;
1865 def : Mips16Pat<(MipsHi tglobaltlsaddr:$in),
1866 (SllX16 (LiRxImmX16 tglobaltlsaddr:$in), 16)>;
1868 def : Mips16Pat<(MipsLo tblockaddress:$in), (LiRxImmX16 tblockaddress:$in)>;
1871 class Wrapper16Pat<SDNode node, Instruction ADDiuOp, RegisterClass RC>:
1872 Mips16Pat<(MipsWrapper RC:$gp, node:$in),
1873 (ADDiuOp RC:$gp, node:$in)>;
1876 def : Wrapper16Pat<tglobaladdr, AddiuRxRxImmX16, CPU16Regs>;
1877 def : Wrapper16Pat<tglobaltlsaddr, AddiuRxRxImmX16, CPU16Regs>;
1879 def : Mips16Pat<(i32 (extloadi8 addr16:$src)),
1880 (LbuRxRyOffMemX16 addr16:$src)>;
1881 def : Mips16Pat<(i32 (extloadi16 addr16:$src)),
1882 (LhuRxRyOffMemX16 addr16:$src)>;
1884 def: Mips16Pat<(trap), (Break16)>;
1886 def : Mips16Pat<(sext_inreg CPU16Regs:$val, i8),
1887 (SebRx16 CPU16Regs:$val)>;
1889 def : Mips16Pat<(sext_inreg CPU16Regs:$val, i16),
1890 (SehRx16 CPU16Regs:$val)>;
1894 (outs CPU16Regs:$rh, CPU16Regs:$rl),
1895 (ins simm16:$immHi, simm16:$immLo),
1896 "li\t$rh, $immHi\n\taddiu\t$rl, $$pc, $immLo\n ",[]> ;
1898 // An operand for the CONSTPOOL_ENTRY pseudo-instruction.
1899 def cpinst_operand : Operand<i32> {
1900 // let PrintMethod = "printCPInstOperand";
1903 // CONSTPOOL_ENTRY - This instruction represents a floating constant pool in
1904 // the function. The first operand is the ID# for this instruction, the second
1905 // is the index into the MachineConstantPool that this is, the third is the
1906 // size in bytes of this constant pool entry.
1908 let hasSideEffects = 0, isNotDuplicable = 1 in
1909 def CONSTPOOL_ENTRY :
1910 MipsPseudo16<(outs), (ins cpinst_operand:$instid, cpinst_operand:$cpidx,
1911 i32imm:$size), "foo", []>;