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 //===----------------------------------------------------------------------===//
18 ComplexPattern<iPTR, 3, "selectAddr16", [frameindex], [SDNPWantParent]>;
22 def mem16 : Operand<i32> {
23 let PrintMethod = "printMemOperand";
24 let MIOperandInfo = (ops CPU16Regs, simm16, CPU16RegsPlusSP);
25 let EncoderMethod = "getMemEncoding";
28 def mem16_ea : Operand<i32> {
29 let PrintMethod = "printMemOperandEA";
30 let MIOperandInfo = (ops CPU16RegsPlusSP, simm16);
31 let EncoderMethod = "getMemEncoding";
36 // I8 instruction format
39 class FI816_ins_base<bits<3> _func, string asmstr,
40 string asmstr2, InstrItinClass itin>:
41 FI816<_func, (outs), (ins simm16:$imm), !strconcat(asmstr, asmstr2),
45 class FI816_SP_ins<bits<3> _func, string asmstr,
47 FI816_ins_base<_func, asmstr, "\t$$sp, $imm # 16 bit inst", itin>;
50 // RI instruction format
54 class FRI16_ins_base<bits<5> op, string asmstr, string asmstr2,
56 FRI16<op, (outs CPU16Regs:$rx), (ins simm16:$imm),
57 !strconcat(asmstr, asmstr2), [], itin>;
59 class FRI16_ins<bits<5> op, string asmstr,
61 FRI16_ins_base<op, asmstr, "\t$rx, $imm \t# 16 bit inst", itin>;
63 class FRI16_TCP_ins<bits<5> _op, string asmstr,
65 FRI16<_op, (outs CPU16Regs:$rx), (ins pcrel16:$imm, i32imm:$size),
66 !strconcat(asmstr, "\t$rx, $imm\t# 16 bit inst"), [], itin>;
68 class FRI16R_ins_base<bits<5> op, string asmstr, string asmstr2,
70 FRI16<op, (outs), (ins CPU16Regs:$rx, simm16:$imm),
71 !strconcat(asmstr, asmstr2), [], itin>;
73 class FRI16R_ins<bits<5> op, string asmstr,
75 FRI16R_ins_base<op, asmstr, "\t$rx, $imm \t# 16 bit inst", itin>;
77 class F2RI16_ins<bits<5> _op, string asmstr,
79 FRI16<_op, (outs CPU16Regs:$rx), (ins CPU16Regs:$rx_, simm16:$imm),
80 !strconcat(asmstr, "\t$rx, $imm\t# 16 bit inst"), [], itin> {
81 let Constraints = "$rx_ = $rx";
84 class FRI16_B_ins<bits<5> _op, string asmstr,
86 FRI16<_op, (outs), (ins CPU16Regs:$rx, brtarget:$imm),
87 !strconcat(asmstr, "\t$rx, $imm # 16 bit inst"), [], itin>;
89 // Compare a register and immediate and place result in CC
92 // EXT-CCRR Instruction format
94 class FEXT_CCRXI16_ins<string asmstr>:
95 MipsPseudo16<(outs CPU16Regs:$cc), (ins CPU16Regs:$rx, simm16:$imm),
96 !strconcat(asmstr, "\t$rx, $imm\n\tmove\t$cc, $$t8"), []> {
98 let usesCustomInserter = 1;
101 // JAL and JALX instruction format
103 class FJAL16_ins<bits<1> _X, string asmstr,
104 InstrItinClass itin>:
105 FJAL16<_X, (outs), (ins simm20:$imm),
106 !strconcat(asmstr, "\t$imm\n\tnop"),[],
111 // EXT-I instruction format
113 class FEXT_I16_ins<bits<5> eop, string asmstr, InstrItinClass itin> :
114 FEXT_I16<eop, (outs), (ins brtarget:$imm16),
115 !strconcat(asmstr, "\t$imm16"),[], itin>;
118 // EXT-I8 instruction format
121 class FEXT_I816_ins_base<bits<3> _func, string asmstr,
122 string asmstr2, InstrItinClass itin>:
123 FEXT_I816<_func, (outs), (ins simm16:$imm), !strconcat(asmstr, asmstr2),
126 class FEXT_I816_ins<bits<3> _func, string asmstr,
127 InstrItinClass itin>:
128 FEXT_I816_ins_base<_func, asmstr, "\t$imm", itin>;
130 class FEXT_I816_SP_ins<bits<3> _func, string asmstr,
131 InstrItinClass itin>:
132 FEXT_I816_ins_base<_func, asmstr, "\t$$sp, $imm", itin>;
135 // Assembler formats in alphabetical order.
136 // Natural and pseudos are mixed together.
138 // Compare two registers and place result in CC
139 // Implicit use of T8
141 // CC-RR Instruction format
143 class FCCRR16_ins<string asmstr> :
144 MipsPseudo16<(outs CPU16Regs:$cc), (ins CPU16Regs:$rx, CPU16Regs:$ry),
145 !strconcat(asmstr, "\t$rx, $ry\n\tmove\t$cc, $$t8"), []> {
147 let usesCustomInserter = 1;
151 // EXT-RI instruction format
154 class FEXT_RI16_ins_base<bits<5> _op, string asmstr, string asmstr2,
155 InstrItinClass itin>:
156 FEXT_RI16<_op, (outs CPU16Regs:$rx), (ins simm16:$imm),
157 !strconcat(asmstr, asmstr2), [], itin>;
159 class FEXT_RI16_ins<bits<5> _op, string asmstr,
160 InstrItinClass itin>:
161 FEXT_RI16_ins_base<_op, asmstr, "\t$rx, $imm", itin>;
163 class FEXT_RI16R_ins_base<bits<5> _op, string asmstr, string asmstr2,
164 InstrItinClass itin>:
165 FEXT_RI16<_op, (outs ), (ins CPU16Regs:$rx, simm16:$imm),
166 !strconcat(asmstr, asmstr2), [], itin>;
168 class FEXT_RI16R_ins<bits<5> _op, string asmstr,
169 InstrItinClass itin>:
170 FEXT_RI16R_ins_base<_op, asmstr, "\t$rx, $imm", itin>;
172 class FEXT_RI16_PC_ins<bits<5> _op, string asmstr, InstrItinClass itin>:
173 FEXT_RI16_ins_base<_op, asmstr, "\t$rx, $$pc, $imm", itin>;
175 class FEXT_RI16_B_ins<bits<5> _op, string asmstr,
176 InstrItinClass itin>:
177 FEXT_RI16<_op, (outs), (ins CPU16Regs:$rx, brtarget:$imm),
178 !strconcat(asmstr, "\t$rx, $imm"), [], itin>;
180 class FEXT_RI16_TCP_ins<bits<5> _op, string asmstr,
181 InstrItinClass itin>:
182 FEXT_RI16<_op, (outs CPU16Regs:$rx), (ins pcrel16:$imm, i32imm:$size),
183 !strconcat(asmstr, "\t$rx, $imm"), [], itin>;
185 class FEXT_2RI16_ins<bits<5> _op, string asmstr,
186 InstrItinClass itin>:
187 FEXT_RI16<_op, (outs CPU16Regs:$rx), (ins CPU16Regs:$rx_, simm16:$imm),
188 !strconcat(asmstr, "\t$rx, $imm"), [], itin> {
189 let Constraints = "$rx_ = $rx";
193 // this has an explicit sp argument that we ignore to work around a problem
195 class FEXT_RI16_SP_explicit_ins<bits<5> _op, string asmstr,
196 InstrItinClass itin>:
197 FEXT_RI16<_op, (outs CPU16Regs:$rx), (ins CPUSPReg:$ry, simm16:$imm),
198 !strconcat(asmstr, "\t$rx, $imm ( $ry ); "), [], itin>;
200 class FEXT_RI16_SP_Store_explicit_ins<bits<5> _op, string asmstr,
201 InstrItinClass itin>:
202 FEXT_RI16<_op, (outs), (ins CPU16Regs:$rx, CPUSPReg:$ry, simm16:$imm),
203 !strconcat(asmstr, "\t$rx, $imm ( $ry ); "), [], itin>;
206 // EXT-RRI instruction format
209 class FEXT_RRI16_mem_ins<bits<5> op, string asmstr, Operand MemOpnd,
210 InstrItinClass itin>:
211 FEXT_RRI16<op, (outs CPU16Regs:$ry), (ins MemOpnd:$addr),
212 !strconcat(asmstr, "\t$ry, $addr"), [], itin>;
214 class FEXT_RRI16_mem2_ins<bits<5> op, string asmstr, Operand MemOpnd,
215 InstrItinClass itin>:
216 FEXT_RRI16<op, (outs ), (ins CPU16Regs:$ry, MemOpnd:$addr),
217 !strconcat(asmstr, "\t$ry, $addr"), [], itin>;
221 // EXT-RRI-A instruction format
224 class FEXT_RRI_A16_mem_ins<bits<1> op, string asmstr, Operand MemOpnd,
225 InstrItinClass itin>:
226 FEXT_RRI_A16<op, (outs CPU16Regs:$ry), (ins MemOpnd:$addr),
227 !strconcat(asmstr, "\t$ry, $addr"), [], itin>;
230 // EXT-SHIFT instruction format
232 class FEXT_SHIFT16_ins<bits<2> _f, string asmstr, InstrItinClass itin>:
233 FEXT_SHIFT16<_f, (outs CPU16Regs:$rx), (ins CPU16Regs:$ry, uimm5:$sa),
234 !strconcat(asmstr, "\t$rx, $ry, $sa"), [], itin>;
239 class FEXT_T8I816_ins<string asmstr, string asmstr2>:
241 (ins CPU16Regs:$rx, CPU16Regs:$ry, brtarget:$imm),
242 !strconcat(asmstr2, !strconcat("\t$rx, $ry\n\t",
243 !strconcat(asmstr, "\t$imm"))),[]> {
245 let usesCustomInserter = 1;
251 class FEXT_T8I8I16_ins<string asmstr, string asmstr2>:
253 (ins CPU16Regs:$rx, simm16:$imm, brtarget:$targ),
254 !strconcat(asmstr2, !strconcat("\t$rx, $imm\n\t",
255 !strconcat(asmstr, "\t$targ"))), []> {
257 let usesCustomInserter = 1;
263 // I8_MOVR32 instruction format (used only by the MOVR32 instructio
265 class FI8_MOVR3216_ins<string asmstr, InstrItinClass itin>:
266 FI8_MOVR3216<(outs CPU16Regs:$rz), (ins GPR32:$r32),
267 !strconcat(asmstr, "\t$rz, $r32"), [], itin>;
270 // I8_MOV32R instruction format (used only by MOV32R instruction)
273 class FI8_MOV32R16_ins<string asmstr, InstrItinClass itin>:
274 FI8_MOV32R16<(outs GPR32:$r32), (ins CPU16Regs:$rz),
275 !strconcat(asmstr, "\t$r32, $rz"), [], itin>;
278 // This are pseudo formats for multiply
279 // This first one can be changed to non pseudo now.
283 class FMULT16_ins<string asmstr, InstrItinClass itin> :
284 MipsPseudo16<(outs), (ins CPU16Regs:$rx, CPU16Regs:$ry),
285 !strconcat(asmstr, "\t$rx, $ry"), []>;
290 class FMULT16_LO_ins<string asmstr, InstrItinClass itin> :
291 MipsPseudo16<(outs CPU16Regs:$rz), (ins CPU16Regs:$rx, CPU16Regs:$ry),
292 !strconcat(asmstr, "\t$rx, $ry\n\tmflo\t$rz"), []> {
297 // RR-type instruction format
300 class FRR16_ins<bits<5> f, string asmstr, InstrItinClass itin> :
301 FRR16<f, (outs CPU16Regs:$rx), (ins CPU16Regs:$ry),
302 !strconcat(asmstr, "\t$rx, $ry"), [], itin> {
305 class FRRBreakNull16_ins<string asmstr, InstrItinClass itin> :
306 FRRBreak16<(outs), (ins), asmstr, [], itin> {
310 class FRR16R_ins<bits<5> f, string asmstr, InstrItinClass itin> :
311 FRR16<f, (outs), (ins CPU16Regs:$rx, CPU16Regs:$ry),
312 !strconcat(asmstr, "\t$rx, $ry"), [], itin> {
315 class FRRTR16_ins<string asmstr> :
316 MipsPseudo16<(outs CPU16Regs:$rz), (ins CPU16Regs:$rx, CPU16Regs:$ry),
317 !strconcat(asmstr, "\t$rx, $ry\n\tmove\t$rz, $$t8"), []> ;
320 // maybe refactor but need a $zero as a dummy first parameter
322 class FRR16_div_ins<bits<5> f, string asmstr, InstrItinClass itin> :
323 FRR16<f, (outs ), (ins CPU16Regs:$rx, CPU16Regs:$ry),
324 !strconcat(asmstr, "\t$$zero, $rx, $ry"), [], itin> ;
326 class FUnaryRR16_ins<bits<5> f, string asmstr, InstrItinClass itin> :
327 FRR16<f, (outs CPU16Regs:$rx), (ins CPU16Regs:$ry),
328 !strconcat(asmstr, "\t$rx, $ry"), [], itin> ;
331 class FRR16_M_ins<bits<5> f, string asmstr,
332 InstrItinClass itin> :
333 FRR16<f, (outs CPU16Regs:$rx), (ins),
334 !strconcat(asmstr, "\t$rx"), [], itin>;
336 class FRxRxRy16_ins<bits<5> f, string asmstr,
337 InstrItinClass itin> :
338 FRR16<f, (outs CPU16Regs:$rz), (ins CPU16Regs:$rx, CPU16Regs:$ry),
339 !strconcat(asmstr, "\t$rz, $ry"),
341 let Constraints = "$rx = $rz";
345 class FRR16_JALRC_RA_only_ins<bits<1> nd_, bits<1> l_,
346 string asmstr, InstrItinClass itin>:
347 FRR16_JALRC<nd_, l_, 1, (outs), (ins), !strconcat(asmstr, "\t $$ra"),
351 class FRR16_JALRC_ins<bits<1> nd, bits<1> l, bits<1> ra,
352 string asmstr, InstrItinClass itin>:
353 FRR16_JALRC<nd, l, ra, (outs), (ins CPU16Regs:$rx),
354 !strconcat(asmstr, "\t $rx"), [], itin> ;
357 <bits<5> _funct, bits<3> _subfunc,
358 string asmstr, InstrItinClass itin>:
359 FRR_SF16<_funct, _subfunc, (outs CPU16Regs:$rx), (ins CPU16Regs:$rx_),
360 !strconcat(asmstr, "\t $rx"),
362 let Constraints = "$rx_ = $rx";
365 // RRR-type instruction format
368 class FRRR16_ins<bits<2> _f, string asmstr, InstrItinClass itin> :
369 FRRR16<_f, (outs CPU16Regs:$rz), (ins CPU16Regs:$rx, CPU16Regs:$ry),
370 !strconcat(asmstr, "\t$rz, $rx, $ry"), [], itin>;
373 // These Sel patterns support the generation of conditional move
374 // pseudo instructions.
376 // The nomenclature uses the components making up the pseudo and may
377 // be a bit counter intuitive when compared with the end result we seek.
378 // For example using a bqez in the example directly below results in the
379 // conditional move being done if the tested register is not zero.
380 // I considered in easier to check by keeping the pseudo consistent with
381 // it's components but it could have been done differently.
383 // The simplest case is when can test and operand directly and do the
384 // conditional move based on a simple mips16 conditional
385 // branch instruction.
387 // if $op == beqz or bnez:
392 // if $op == beqz, then if $rt != 0, then the conditional assignment
393 // $rd = $rs is done.
395 // if $op == bnez, then if $rt == 0, then the conditional assignment
396 // $rd = $rs is done.
398 // So this pseudo class only has one operand, i.e. op
400 class Sel<string op>:
401 MipsPseudo16<(outs CPU16Regs:$rd_), (ins CPU16Regs:$rd, CPU16Regs:$rs,
403 !strconcat(op, "\t$rt, .+4\n\t\n\tmove $rd, $rs"), []> {
404 //let isCodeGenOnly=1;
405 let Constraints = "$rd = $rd_";
406 let usesCustomInserter = 1;
410 // The next two instruction classes allow for an operand which tests
411 // two operands and returns a value in register T8 and
412 //then does a conditional branch based on the value of T8
415 // op2 can be cmpi or slti/sltiu
416 // op1 can bteqz or btnez
417 // the operands for op2 are a register and a signed constant
419 // $op2 $t, $imm ;test register t and branch conditionally
420 // $op1 .+4 ;op1 is a conditional branch
424 class SeliT<string op1, string op2>:
425 MipsPseudo16<(outs CPU16Regs:$rd_), (ins CPU16Regs:$rd, CPU16Regs:$rs,
426 CPU16Regs:$rl, simm16:$imm),
428 !strconcat("\t$rl, $imm\n\t",
429 !strconcat(op1, "\t.+4\n\tmove $rd, $rs"))), []> {
431 let Constraints = "$rd = $rd_";
432 let usesCustomInserter = 1;
436 // op2 can be cmp or slt/sltu
437 // op1 can be bteqz or btnez
438 // the operands for op2 are two registers
439 // op1 is a conditional branch
442 // $op2 $rl, $rr ;test registers rl,rr
443 // $op1 .+4 ;op2 is a conditional branch
447 class SelT<string op1, string op2>:
448 MipsPseudo16<(outs CPU16Regs:$rd_),
449 (ins CPU16Regs:$rd, CPU16Regs:$rs,
450 CPU16Regs:$rl, CPU16Regs:$rr),
452 !strconcat("\t$rl, $rr\n\t",
453 !strconcat(op1, "\t.+4\n\tmove $rd, $rs"))), []> {
455 let Constraints = "$rd = $rd_";
456 let usesCustomInserter = 1;
462 def imm32: Operand<i32>;
465 MipsPseudo16<(outs), (ins imm32:$imm), "\t.word $imm", []>;
468 MipsPseudo16<(outs CPU16Regs:$rx), (ins imm32:$imm, imm32:$constid),
469 "lw\t$rx, 1f\n\tb\t2f\n\t.align\t2\n1: \t.word\t$imm\n2:", []>;
473 // Some general instruction class info
477 class ArithLogic16Defs<bit isCom=0> {
479 bit isCommutable = isCom;
480 bit isReMaterializable = 1;
481 bit neverHasSideEffects = 1;
486 bit isTerminator = 1;
492 bit isTerminator = 1;
505 // Format: ADDIU rx, immediate MIPS16e
506 // Purpose: Add Immediate Unsigned Word (2-Operand, Extended)
507 // To add a constant to a 32-bit integer.
509 def AddiuRxImmX16: FEXT_RI16_ins<0b01001, "addiu", IIAlu>;
511 def AddiuRxRxImm16: F2RI16_ins<0b01001, "addiu", IIAlu>,
512 ArithLogic16Defs<0> {
513 let AddedComplexity = 5;
515 def AddiuRxRxImmX16: FEXT_2RI16_ins<0b01001, "addiu", IIAlu>,
516 ArithLogic16Defs<0> {
517 let isCodeGenOnly = 1;
520 def AddiuRxRyOffMemX16:
521 FEXT_RRI_A16_mem_ins<0, "addiu", mem16_ea, IIAlu>;
525 // Format: ADDIU rx, pc, immediate MIPS16e
526 // Purpose: Add Immediate Unsigned Word (3-Operand, PC-Relative, Extended)
527 // To add a constant to the program counter.
529 def AddiuRxPcImmX16: FEXT_RI16_PC_ins<0b00001, "addiu", IIAlu>;
532 // Format: ADDIU sp, immediate MIPS16e
533 // Purpose: Add Immediate Unsigned Word (2-Operand, SP-Relative, Extended)
534 // To add a constant to the stack pointer.
537 : FI816_SP_ins<0b011, "addiu", IIAlu> {
540 let AddedComplexity = 5;
544 : FEXT_I816_SP_ins<0b011, "addiu", IIAlu> {
550 // Format: ADDU rz, rx, ry MIPS16e
551 // Purpose: Add Unsigned Word (3-Operand)
552 // To add 32-bit integers.
555 def AdduRxRyRz16: FRRR16_ins<01, "addu", IIAlu>, ArithLogic16Defs<1>;
558 // Format: AND rx, ry MIPS16e
560 // To do a bitwise logical AND.
562 def AndRxRxRy16: FRxRxRy16_ins<0b01100, "and", IIAlu>, ArithLogic16Defs<1>;
566 // Format: BEQZ rx, offset MIPS16e
567 // Purpose: Branch on Equal to Zero
568 // To test a GPR then do a PC-relative conditional branch.
570 def BeqzRxImm16: FRI16_B_ins<0b00100, "beqz", IIAlu>, cbranch16;
574 // Format: BEQZ rx, offset MIPS16e
575 // Purpose: Branch on Equal to Zero (Extended)
576 // To test a GPR then do a PC-relative conditional branch.
578 def BeqzRxImmX16: FEXT_RI16_B_ins<0b00100, "beqz", IIAlu>, cbranch16;
580 // Format: B offset MIPS16e
581 // Purpose: Unconditional Branch
582 // To do an unconditional PC-relative branch.
584 def BimmX16: FEXT_I16_ins<0b00010, "b", IIAlu>, branch16;
587 // Format: BNEZ rx, offset MIPS16e
588 // Purpose: Branch on Not Equal to Zero
589 // To test a GPR then do a PC-relative conditional branch.
591 def BnezRxImm16: FRI16_B_ins<0b00101, "bnez", IIAlu>, cbranch16;
594 // Format: BNEZ rx, offset MIPS16e
595 // Purpose: Branch on Not Equal to Zero (Extended)
596 // To test a GPR then do a PC-relative conditional branch.
598 def BnezRxImmX16: FEXT_RI16_B_ins<0b00101, "bnez", IIAlu>, cbranch16;
602 //Format: BREAK immediate
603 // Purpose: Breakpoint
604 // To cause a Breakpoint exception.
606 def Break16: FRRBreakNull16_ins<"break 0", NoItinerary>;
608 // Format: BTEQZ offset MIPS16e
609 // Purpose: Branch on T Equal to Zero (Extended)
610 // To test special register T then do a PC-relative conditional branch.
612 def BteqzX16: FEXT_I816_ins<0b000, "bteqz", IIAlu>, cbranch16 {
616 def BteqzT8CmpX16: FEXT_T8I816_ins<"bteqz", "cmp">, cbranch16;
618 def BteqzT8CmpiX16: FEXT_T8I8I16_ins<"bteqz", "cmpi">,
621 def BteqzT8SltX16: FEXT_T8I816_ins<"bteqz", "slt">, cbranch16;
623 def BteqzT8SltuX16: FEXT_T8I816_ins<"bteqz", "sltu">, cbranch16;
625 def BteqzT8SltiX16: FEXT_T8I8I16_ins<"bteqz", "slti">, cbranch16;
627 def BteqzT8SltiuX16: FEXT_T8I8I16_ins<"bteqz", "sltiu">,
631 // Format: BTNEZ offset MIPS16e
632 // Purpose: Branch on T Not Equal to Zero (Extended)
633 // To test special register T then do a PC-relative conditional branch.
635 def BtnezX16: FEXT_I816_ins<0b001, "btnez", IIAlu> ,cbranch16 {
639 def BtnezT8CmpX16: FEXT_T8I816_ins<"btnez", "cmp">, cbranch16;
641 def BtnezT8CmpiX16: FEXT_T8I8I16_ins<"btnez", "cmpi">, cbranch16;
643 def BtnezT8SltX16: FEXT_T8I816_ins<"btnez", "slt">, cbranch16;
645 def BtnezT8SltuX16: FEXT_T8I816_ins<"btnez", "sltu">, cbranch16;
647 def BtnezT8SltiX16: FEXT_T8I8I16_ins<"btnez", "slti">, cbranch16;
649 def BtnezT8SltiuX16: FEXT_T8I8I16_ins<"btnez", "sltiu">,
653 // Format: CMP rx, ry MIPS16e
655 // To compare the contents of two GPRs.
657 def CmpRxRy16: FRR16R_ins<0b01010, "cmp", IIAlu> {
662 // Format: CMPI rx, immediate MIPS16e
663 // Purpose: Compare Immediate
664 // To compare a constant with the contents of a GPR.
666 def CmpiRxImm16: FRI16R_ins<0b01110, "cmpi", IIAlu> {
671 // Format: CMPI rx, immediate MIPS16e
672 // Purpose: Compare Immediate (Extended)
673 // To compare a constant with the contents of a GPR.
675 def CmpiRxImmX16: FEXT_RI16R_ins<0b01110, "cmpi", IIAlu> {
681 // Format: DIV rx, ry MIPS16e
682 // Purpose: Divide Word
683 // To divide 32-bit signed integers.
685 def DivRxRy16: FRR16_div_ins<0b11010, "div", IIAlu> {
686 let Defs = [HI0, LO0];
690 // Format: DIVU rx, ry MIPS16e
691 // Purpose: Divide Unsigned Word
692 // To divide 32-bit unsigned integers.
694 def DivuRxRy16: FRR16_div_ins<0b11011, "divu", IIAlu> {
695 let Defs = [HI0, LO0];
698 // Format: JAL target MIPS16e
699 // Purpose: Jump and Link
700 // To execute a procedure call within the current 256 MB-aligned
701 // region and preserve the current ISA.
704 def Jal16 : FJAL16_ins<0b0, "jal", IIAlu> {
705 let hasDelaySlot = 0; // not true, but we add the nop for now
710 // Format: JR ra MIPS16e
711 // Purpose: Jump Register Through Register ra
712 // To execute a branch to the instruction address in the return
716 def JrRa16: FRR16_JALRC_RA_only_ins<0, 0, "jr", IIAlu> {
718 let isIndirectBranch = 1;
719 let hasDelaySlot = 1;
724 def JrcRa16: FRR16_JALRC_RA_only_ins<1, 1, "jrc", IIAlu> {
726 let isIndirectBranch = 1;
731 def JrcRx16: FRR16_JALRC_ins<1, 1, 0, "jrc", IIAlu> {
733 let isIndirectBranch = 1;
738 // Format: LB ry, offset(rx) MIPS16e
739 // Purpose: Load Byte (Extended)
740 // To load a byte from memory as a signed value.
742 def LbRxRyOffMemX16: FEXT_RRI16_mem_ins<0b10011, "lb", mem16, IILoad>, MayLoad{
743 let isCodeGenOnly = 1;
747 // Format: LBU ry, offset(rx) MIPS16e
748 // Purpose: Load Byte Unsigned (Extended)
749 // To load a byte from memory as a unsigned value.
751 def LbuRxRyOffMemX16:
752 FEXT_RRI16_mem_ins<0b10100, "lbu", mem16, IILoad>, MayLoad {
753 let isCodeGenOnly = 1;
757 // Format: LH ry, offset(rx) MIPS16e
758 // Purpose: Load Halfword signed (Extended)
759 // To load a halfword from memory as a signed value.
761 def LhRxRyOffMemX16: FEXT_RRI16_mem_ins<0b10100, "lh", mem16, IILoad>, MayLoad{
762 let isCodeGenOnly = 1;
766 // Format: LHU ry, offset(rx) MIPS16e
767 // Purpose: Load Halfword unsigned (Extended)
768 // To load a halfword from memory as an unsigned value.
770 def LhuRxRyOffMemX16:
771 FEXT_RRI16_mem_ins<0b10100, "lhu", mem16, IILoad>, MayLoad {
772 let isCodeGenOnly = 1;
776 // Format: LI rx, immediate MIPS16e
777 // Purpose: Load Immediate
778 // To load a constant into a GPR.
780 def LiRxImm16: FRI16_ins<0b01101, "li", IIAlu>;
783 // Format: LI rx, immediate MIPS16e
784 // Purpose: Load Immediate (Extended)
785 // To load a constant into a GPR.
787 def LiRxImmX16: FEXT_RI16_ins<0b01101, "li", IIAlu>;
789 def LiRxImmAlignX16: FEXT_RI16_ins<0b01101, ".align 2\n\tli", IIAlu> {
790 let isCodeGenOnly = 1;
794 // Format: LW ry, offset(rx) MIPS16e
795 // Purpose: Load Word (Extended)
796 // To load a word from memory as a signed value.
798 def LwRxRyOffMemX16: FEXT_RRI16_mem_ins<0b10011, "lw", mem16, IILoad>, MayLoad{
799 let isCodeGenOnly = 1;
802 // Format: LW rx, offset(sp) MIPS16e
803 // Purpose: Load Word (SP-Relative, Extended)
804 // To load an SP-relative word from memory as a signed value.
806 def LwRxSpImmX16: FEXT_RI16_SP_explicit_ins<0b10010, "lw", IILoad>, MayLoad{
810 def LwRxPcTcp16: FRI16_TCP_ins<0b10110, "lw", IILoad>, MayLoad;
812 def LwRxPcTcpX16: FEXT_RI16_TCP_ins<0b10110, "lw", IILoad>, MayLoad;
814 // Format: MOVE r32, rz MIPS16e
816 // To move the contents of a GPR to a GPR.
818 def Move32R16: FI8_MOV32R16_ins<"move", IIAlu>;
821 // Format: MOVE ry, r32 MIPS16e
823 // To move the contents of a GPR to a GPR.
825 def MoveR3216: FI8_MOVR3216_ins<"move", IIAlu>;
828 // Format: MFHI rx MIPS16e
829 // Purpose: Move From HI Register
830 // To copy the special purpose HI register to a GPR.
832 def Mfhi16: FRR16_M_ins<0b10000, "mfhi", IIAlu> {
834 let neverHasSideEffects = 1;
838 // Format: MFLO rx MIPS16e
839 // Purpose: Move From LO Register
840 // To copy the special purpose LO register to a GPR.
842 def Mflo16: FRR16_M_ins<0b10010, "mflo", IIAlu> {
844 let neverHasSideEffects = 1;
848 // Pseudo Instruction for mult
850 def MultRxRy16: FMULT16_ins<"mult", IIAlu> {
851 let isCommutable = 1;
852 let neverHasSideEffects = 1;
853 let Defs = [HI0, LO0];
856 def MultuRxRy16: FMULT16_ins<"multu", IIAlu> {
857 let isCommutable = 1;
858 let neverHasSideEffects = 1;
859 let Defs = [HI0, LO0];
863 // Format: MULT rx, ry MIPS16e
864 // Purpose: Multiply Word
865 // To multiply 32-bit signed integers.
867 def MultRxRyRz16: FMULT16_LO_ins<"mult", IIAlu> {
868 let isCommutable = 1;
869 let neverHasSideEffects = 1;
870 let Defs = [HI0, LO0];
874 // Format: MULTU rx, ry MIPS16e
875 // Purpose: Multiply Unsigned Word
876 // To multiply 32-bit unsigned integers.
878 def MultuRxRyRz16: FMULT16_LO_ins<"multu", IIAlu> {
879 let isCommutable = 1;
880 let neverHasSideEffects = 1;
881 let Defs = [HI0, LO0];
885 // Format: NEG rx, ry MIPS16e
887 // To negate an integer value.
889 def NegRxRy16: FUnaryRR16_ins<0b11101, "neg", IIAlu>;
892 // Format: NOT rx, ry MIPS16e
894 // To complement an integer value
896 def NotRxRy16: FUnaryRR16_ins<0b01111, "not", IIAlu>;
899 // Format: OR rx, ry MIPS16e
901 // To do a bitwise logical OR.
903 def OrRxRxRy16: FRxRxRy16_ins<0b01101, "or", IIAlu>, ArithLogic16Defs<1>;
906 // Format: RESTORE {ra,}{s0/s1/s0-1,}{framesize}
907 // (All args are optional) MIPS16e
908 // Purpose: Restore Registers and Deallocate Stack Frame
909 // To deallocate a stack frame before exit from a subroutine,
910 // restoring return address and static registers, and adjusting
914 // fixed form for restoring RA and the frame
915 // for direct object emitter, encoding needs to be adjusted for the
918 let ra=1, s=0,s0=1,s1=1 in
920 FI8_SVRS16<0b1, (outs), (ins uimm16:$frame_size),
921 "restore\t$$ra, $$s0, $$s1, $$s2, $frame_size", [], IILoad >, MayLoad {
922 let isCodeGenOnly = 1;
923 let Defs = [S0, S1, S2, RA, SP];
927 // Use Restore to increment SP since SP is not a Mip 16 register, this
928 // is an easy way to do that which does not require a register.
930 let ra=0, s=0,s0=0,s1=0 in
932 FI8_SVRS16<0b1, (outs), (ins uimm16:$frame_size),
933 "restore\t$frame_size", [], IILoad >, MayLoad {
934 let isCodeGenOnly = 1;
940 // Format: SAVE {ra,}{s0/s1/s0-1,}{framesize} (All arguments are optional)
942 // Purpose: Save Registers and Set Up Stack Frame
943 // To set up a stack frame on entry to a subroutine,
944 // saving return address and static registers, and adjusting stack
946 let ra=1, s=1,s0=1,s1=1 in
948 FI8_SVRS16<0b1, (outs), (ins uimm16:$frame_size),
949 "save\t$$ra, $$s0, $$s1, $$s2, $frame_size", [], IIStore >, MayStore {
950 let isCodeGenOnly = 1;
951 let Uses = [RA, SP, S0, S1, S2];
956 // Use Save to decrement the SP by a constant since SP is not
957 // a Mips16 register.
959 let ra=0, s=0,s0=0,s1=0 in
961 FI8_SVRS16<0b1, (outs), (ins uimm16:$frame_size),
962 "save\t$frame_size", [], IIStore >, MayStore {
963 let isCodeGenOnly = 1;
968 // Format: SB ry, offset(rx) MIPS16e
969 // Purpose: Store Byte (Extended)
970 // To store a byte to memory.
973 FEXT_RRI16_mem2_ins<0b11000, "sb", mem16, IIStore>, MayStore;
976 // Format: SEB rx MIPS16e
977 // Purpose: Sign-Extend Byte
978 // Sign-extend least significant byte in register rx.
981 : FRR_SF16_ins<0b10001, 0b100, "seb", IIAlu>;
984 // Format: SEH rx MIPS16e
985 // Purpose: Sign-Extend Halfword
986 // Sign-extend least significant word in register rx.
989 : FRR_SF16_ins<0b10001, 0b101, "seh", IIAlu>;
992 // The Sel(T) instructions are pseudos
993 // T means that they use T8 implicitly.
996 // Format: SelBeqZ rd, rs, rt
997 // Purpose: if rt==0, do nothing
1000 def SelBeqZ: Sel<"beqz">;
1003 // Format: SelTBteqZCmp rd, rs, rl, rr
1004 // Purpose: b = Cmp rl, rr.
1005 // If b==0 then do nothing.
1006 // if b!=0 then rd = rs
1008 def SelTBteqZCmp: SelT<"bteqz", "cmp">;
1011 // Format: SelTBteqZCmpi rd, rs, rl, rr
1012 // Purpose: b = Cmpi rl, imm.
1013 // If b==0 then do nothing.
1014 // if b!=0 then rd = rs
1016 def SelTBteqZCmpi: SeliT<"bteqz", "cmpi">;
1019 // Format: SelTBteqZSlt rd, rs, rl, rr
1020 // Purpose: b = Slt rl, rr.
1021 // If b==0 then do nothing.
1022 // if b!=0 then rd = rs
1024 def SelTBteqZSlt: SelT<"bteqz", "slt">;
1027 // Format: SelTBteqZSlti rd, rs, rl, rr
1028 // Purpose: b = Slti rl, imm.
1029 // If b==0 then do nothing.
1030 // if b!=0 then rd = rs
1032 def SelTBteqZSlti: SeliT<"bteqz", "slti">;
1035 // Format: SelTBteqZSltu rd, rs, rl, rr
1036 // Purpose: b = Sltu rl, rr.
1037 // If b==0 then do nothing.
1038 // if b!=0 then rd = rs
1040 def SelTBteqZSltu: SelT<"bteqz", "sltu">;
1043 // Format: SelTBteqZSltiu rd, rs, rl, rr
1044 // Purpose: b = Sltiu rl, imm.
1045 // If b==0 then do nothing.
1046 // if b!=0 then rd = rs
1048 def SelTBteqZSltiu: SeliT<"bteqz", "sltiu">;
1051 // Format: SelBnez rd, rs, rt
1052 // Purpose: if rt!=0, do nothing
1055 def SelBneZ: Sel<"bnez">;
1058 // Format: SelTBtneZCmp rd, rs, rl, rr
1059 // Purpose: b = Cmp rl, rr.
1060 // If b!=0 then do nothing.
1061 // if b0=0 then rd = rs
1063 def SelTBtneZCmp: SelT<"btnez", "cmp">;
1066 // Format: SelTBtnezCmpi rd, rs, rl, rr
1067 // Purpose: b = Cmpi rl, imm.
1068 // If b!=0 then do nothing.
1069 // if b==0 then rd = rs
1071 def SelTBtneZCmpi: SeliT<"btnez", "cmpi">;
1074 // Format: SelTBtneZSlt rd, rs, rl, rr
1075 // Purpose: b = Slt rl, rr.
1076 // If b!=0 then do nothing.
1077 // if b==0 then rd = rs
1079 def SelTBtneZSlt: SelT<"btnez", "slt">;
1082 // Format: SelTBtneZSlti rd, rs, rl, rr
1083 // Purpose: b = Slti rl, imm.
1084 // If b!=0 then do nothing.
1085 // if b==0 then rd = rs
1087 def SelTBtneZSlti: SeliT<"btnez", "slti">;
1090 // Format: SelTBtneZSltu rd, rs, rl, rr
1091 // Purpose: b = Sltu rl, rr.
1092 // If b!=0 then do nothing.
1093 // if b==0 then rd = rs
1095 def SelTBtneZSltu: SelT<"btnez", "sltu">;
1098 // Format: SelTBtneZSltiu rd, rs, rl, rr
1099 // Purpose: b = Slti rl, imm.
1100 // If b!=0 then do nothing.
1101 // if b==0 then rd = rs
1103 def SelTBtneZSltiu: SeliT<"btnez", "sltiu">;
1106 // Format: SH ry, offset(rx) MIPS16e
1107 // Purpose: Store Halfword (Extended)
1108 // To store a halfword to memory.
1110 def ShRxRyOffMemX16:
1111 FEXT_RRI16_mem2_ins<0b11001, "sh", mem16, IIStore>, MayStore;
1114 // Format: SLL rx, ry, sa MIPS16e
1115 // Purpose: Shift Word Left Logical (Extended)
1116 // To execute a left-shift of a word by a fixed number of bits-0 to 31 bits.
1118 def SllX16: FEXT_SHIFT16_ins<0b00, "sll", IIAlu>;
1121 // Format: SLLV ry, rx MIPS16e
1122 // Purpose: Shift Word Left Logical Variable
1123 // To execute a left-shift of a word by a variable number of bits.
1125 def SllvRxRy16 : FRxRxRy16_ins<0b00100, "sllv", IIAlu>;
1127 // Format: SLTI rx, immediate MIPS16e
1128 // Purpose: Set on Less Than Immediate
1129 // To record the result of a less-than comparison with a constant.
1132 def SltiRxImm16: FRI16R_ins<0b01010, "slti", IIAlu> {
1137 // Format: SLTI rx, immediate MIPS16e
1138 // Purpose: Set on Less Than Immediate (Extended)
1139 // To record the result of a less-than comparison with a constant.
1142 def SltiRxImmX16: FEXT_RI16R_ins<0b01010, "slti", IIAlu> {
1146 def SltiCCRxImmX16: FEXT_CCRXI16_ins<"slti">;
1148 // Format: SLTIU rx, immediate MIPS16e
1149 // Purpose: Set on Less Than Immediate Unsigned
1150 // To record the result of a less-than comparison with a constant.
1153 def SltiuRxImm16: FRI16R_ins<0b01011, "sltiu", IIAlu> {
1158 // Format: SLTI rx, immediate MIPS16e
1159 // Purpose: Set on Less Than Immediate Unsigned (Extended)
1160 // To record the result of a less-than comparison with a constant.
1163 def SltiuRxImmX16: FEXT_RI16R_ins<0b01011, "sltiu", IIAlu> {
1167 // Format: SLTIU rx, immediate MIPS16e
1168 // Purpose: Set on Less Than Immediate Unsigned (Extended)
1169 // To record the result of a less-than comparison with a constant.
1171 def SltiuCCRxImmX16: FEXT_CCRXI16_ins<"sltiu">;
1174 // Format: SLT rx, ry MIPS16e
1175 // Purpose: Set on Less Than
1176 // To record the result of a less-than comparison.
1178 def SltRxRy16: FRR16R_ins<0b00010, "slt", IIAlu>{
1182 def SltCCRxRy16: FCCRR16_ins<"slt">;
1184 // Format: SLTU rx, ry MIPS16e
1185 // Purpose: Set on Less Than Unsigned
1186 // To record the result of an unsigned less-than comparison.
1188 def SltuRxRy16: FRR16R_ins<0b00011, "sltu", IIAlu>{
1192 def SltuRxRyRz16: FRRTR16_ins<"sltu"> {
1193 let isCodeGenOnly=1;
1198 def SltuCCRxRy16: FCCRR16_ins<"sltu">;
1200 // Format: SRAV ry, rx MIPS16e
1201 // Purpose: Shift Word Right Arithmetic Variable
1202 // To execute an arithmetic right-shift of a word by a variable
1205 def SravRxRy16: FRxRxRy16_ins<0b00111, "srav", IIAlu>;
1209 // Format: SRA rx, ry, sa MIPS16e
1210 // Purpose: Shift Word Right Arithmetic (Extended)
1211 // To execute an arithmetic right-shift of a word by a fixed
1212 // number of bits-1 to 8 bits.
1214 def SraX16: FEXT_SHIFT16_ins<0b11, "sra", IIAlu>;
1218 // Format: SRLV ry, rx MIPS16e
1219 // Purpose: Shift Word Right Logical Variable
1220 // To execute a logical right-shift of a word by a variable
1223 def SrlvRxRy16: FRxRxRy16_ins<0b00110, "srlv", IIAlu>;
1227 // Format: SRL rx, ry, sa MIPS16e
1228 // Purpose: Shift Word Right Logical (Extended)
1229 // To execute a logical right-shift of a word by a fixed
1230 // number of bits-1 to 31 bits.
1232 def SrlX16: FEXT_SHIFT16_ins<0b10, "srl", IIAlu>;
1235 // Format: SUBU rz, rx, ry MIPS16e
1236 // Purpose: Subtract Unsigned Word
1237 // To subtract 32-bit integers
1239 def SubuRxRyRz16: FRRR16_ins<0b11, "subu", IIAlu>, ArithLogic16Defs<0>;
1242 // Format: SW ry, offset(rx) MIPS16e
1243 // Purpose: Store Word (Extended)
1244 // To store a word to memory.
1246 def SwRxRyOffMemX16:
1247 FEXT_RRI16_mem2_ins<0b11011, "sw", mem16, IIStore>, MayStore;
1250 // Format: SW rx, offset(sp) MIPS16e
1251 // Purpose: Store Word rx (SP-Relative)
1252 // To store an SP-relative word to memory.
1254 def SwRxSpImmX16: FEXT_RI16_SP_Store_explicit_ins
1255 <0b11010, "sw", IIStore>, MayStore;
1259 // Format: XOR rx, ry MIPS16e
1261 // To do a bitwise logical XOR.
1263 def XorRxRxRy16: FRxRxRy16_ins<0b01110, "xor", IIAlu>, ArithLogic16Defs<1>;
1265 class Mips16Pat<dag pattern, dag result> : Pat<pattern, result> {
1266 let Predicates = [InMips16Mode];
1269 // Unary Arith/Logic
1271 class ArithLogicU_pat<PatFrag OpNode, Instruction I> :
1272 Mips16Pat<(OpNode CPU16Regs:$r),
1275 def: ArithLogicU_pat<not, NotRxRy16>;
1276 def: ArithLogicU_pat<ineg, NegRxRy16>;
1278 class ArithLogic16_pat<SDNode OpNode, Instruction I> :
1279 Mips16Pat<(OpNode CPU16Regs:$l, CPU16Regs:$r),
1280 (I CPU16Regs:$l, CPU16Regs:$r)>;
1282 def: ArithLogic16_pat<add, AdduRxRyRz16>;
1283 def: ArithLogic16_pat<and, AndRxRxRy16>;
1284 def: ArithLogic16_pat<mul, MultRxRyRz16>;
1285 def: ArithLogic16_pat<or, OrRxRxRy16>;
1286 def: ArithLogic16_pat<sub, SubuRxRyRz16>;
1287 def: ArithLogic16_pat<xor, XorRxRxRy16>;
1289 // Arithmetic and logical instructions with 2 register operands.
1291 class ArithLogicI16_pat<SDNode OpNode, PatFrag imm_type, Instruction I> :
1292 Mips16Pat<(OpNode CPU16Regs:$in, imm_type:$imm),
1293 (I CPU16Regs:$in, imm_type:$imm)>;
1295 def: ArithLogicI16_pat<add, immSExt8, AddiuRxRxImm16>;
1296 def: ArithLogicI16_pat<add, immSExt16, AddiuRxRxImmX16>;
1297 def: ArithLogicI16_pat<shl, immZExt5, SllX16>;
1298 def: ArithLogicI16_pat<srl, immZExt5, SrlX16>;
1299 def: ArithLogicI16_pat<sra, immZExt5, SraX16>;
1301 class shift_rotate_reg16_pat<SDNode OpNode, Instruction I> :
1302 Mips16Pat<(OpNode CPU16Regs:$r, CPU16Regs:$ra),
1303 (I CPU16Regs:$r, CPU16Regs:$ra)>;
1305 def: shift_rotate_reg16_pat<shl, SllvRxRy16>;
1306 def: shift_rotate_reg16_pat<sra, SravRxRy16>;
1307 def: shift_rotate_reg16_pat<srl, SrlvRxRy16>;
1309 class LoadM16_pat<PatFrag OpNode, Instruction I> :
1310 Mips16Pat<(OpNode addr16:$addr), (I addr16:$addr)>;
1312 def: LoadM16_pat<sextloadi8, LbRxRyOffMemX16>;
1313 def: LoadM16_pat<zextloadi8, LbuRxRyOffMemX16>;
1314 def: LoadM16_pat<sextloadi16, LhRxRyOffMemX16>;
1315 def: LoadM16_pat<zextloadi16, LhuRxRyOffMemX16>;
1316 def: LoadM16_pat<load, LwRxRyOffMemX16>;
1318 class StoreM16_pat<PatFrag OpNode, Instruction I> :
1319 Mips16Pat<(OpNode CPU16Regs:$r, addr16:$addr),
1320 (I CPU16Regs:$r, addr16:$addr)>;
1322 def: StoreM16_pat<truncstorei8, SbRxRyOffMemX16>;
1323 def: StoreM16_pat<truncstorei16, ShRxRyOffMemX16>;
1324 def: StoreM16_pat<store, SwRxRyOffMemX16>;
1326 // Unconditional branch
1327 class UncondBranch16_pat<SDNode OpNode, Instruction I>:
1328 Mips16Pat<(OpNode bb:$imm16), (I bb:$imm16)> {
1329 let Predicates = [InMips16Mode];
1332 def : Mips16Pat<(MipsJmpLink (i32 tglobaladdr:$dst)),
1333 (Jal16 tglobaladdr:$dst)>;
1335 def : Mips16Pat<(MipsJmpLink (i32 texternalsym:$dst)),
1336 (Jal16 texternalsym:$dst)>;
1340 (brind CPU16Regs:$rs),
1341 (JrcRx16 CPU16Regs:$rs)>;
1343 // Jump and Link (Call)
1344 let isCall=1, hasDelaySlot=0 in
1346 FRR16_JALRC<0, 0, 0, (outs), (ins CPU16Regs:$rs),
1347 "jalrc \t$rs", [(MipsJmpLink CPU16Regs:$rs)], IIBranch>;
1350 let isReturn=1, isTerminator=1, hasDelaySlot=1, isBarrier=1, hasCtrlDep=1,
1351 hasExtraSrcRegAllocReq = 1 in
1352 def RetRA16 : MipsPseudo16<(outs), (ins), "", [(MipsRet)]>;
1357 class SetCC_R16<PatFrag cond_op, Instruction I>:
1358 Mips16Pat<(cond_op CPU16Regs:$rx, CPU16Regs:$ry),
1359 (I CPU16Regs:$rx, CPU16Regs:$ry)>;
1361 class SetCC_I16<PatFrag cond_op, PatLeaf imm_type, Instruction I>:
1362 Mips16Pat<(cond_op CPU16Regs:$rx, imm_type:$imm16),
1363 (I CPU16Regs:$rx, imm_type:$imm16)>;
1366 def: Mips16Pat<(i32 addr16:$addr),
1367 (AddiuRxRyOffMemX16 addr16:$addr)>;
1370 // Large (>16 bit) immediate loads
1371 def : Mips16Pat<(i32 imm:$imm), (LwConstant32 imm:$imm, -1)>;
1373 // Carry MipsPatterns
1374 def : Mips16Pat<(subc CPU16Regs:$lhs, CPU16Regs:$rhs),
1375 (SubuRxRyRz16 CPU16Regs:$lhs, CPU16Regs:$rhs)>;
1376 def : Mips16Pat<(addc CPU16Regs:$lhs, CPU16Regs:$rhs),
1377 (AdduRxRyRz16 CPU16Regs:$lhs, CPU16Regs:$rhs)>;
1378 def : Mips16Pat<(addc CPU16Regs:$src, immSExt16:$imm),
1379 (AddiuRxRxImmX16 CPU16Regs:$src, imm:$imm)>;
1382 // Some branch conditional patterns are not generated by llvm at this time.
1383 // Some are for seemingly arbitrary reasons not used: i.e. with signed number
1384 // comparison they are used and for unsigned a different pattern is used.
1385 // I am pushing upstream from the full mips16 port and it seemed that I needed
1386 // these earlier and the mips32 port has these but now I cannot create test
1387 // cases that use these patterns. While I sort this all out I will leave these
1388 // extra patterns commented out and if I can be sure they are really not used,
1389 // I will delete the code. I don't want to check the code in uncommented without
1390 // a valid test case. In some cases, the compiler is generating patterns with
1391 // setcc instead and earlier I had implemented setcc first so may have masked
1392 // the problem. The setcc variants are suboptimal for mips16 so I may wantto
1393 // figure out how to enable the brcond patterns or else possibly new
1394 // combinations of of brcond and setcc.
1400 <(brcond (i32 (seteq CPU16Regs:$rx, CPU16Regs:$ry)), bb:$imm16),
1401 (BteqzT8CmpX16 CPU16Regs:$rx, CPU16Regs:$ry, bb:$imm16)
1406 <(brcond (i32 (seteq CPU16Regs:$rx, immZExt16:$imm)), bb:$targ16),
1407 (BteqzT8CmpiX16 CPU16Regs:$rx, immSExt16:$imm, bb:$targ16)
1411 <(brcond (i32 (seteq CPU16Regs:$rx, 0)), bb:$targ16),
1412 (BeqzRxImmX16 CPU16Regs:$rx, bb:$targ16)
1416 // bcond-setgt (do we need to have this pair of setlt, setgt??)
1419 <(brcond (i32 (setgt CPU16Regs:$rx, CPU16Regs:$ry)), bb:$imm16),
1420 (BtnezT8SltX16 CPU16Regs:$ry, CPU16Regs:$rx, bb:$imm16)
1427 <(brcond (i32 (setge CPU16Regs:$rx, CPU16Regs:$ry)), bb:$imm16),
1428 (BteqzT8SltX16 CPU16Regs:$rx, CPU16Regs:$ry, bb:$imm16)
1432 // never called because compiler transforms a >= k to a > (k-1)
1434 <(brcond (i32 (setge CPU16Regs:$rx, immSExt16:$imm)), bb:$imm16),
1435 (BteqzT8SltiX16 CPU16Regs:$rx, immSExt16:$imm, bb:$imm16)
1442 <(brcond (i32 (setlt CPU16Regs:$rx, CPU16Regs:$ry)), bb:$imm16),
1443 (BtnezT8SltX16 CPU16Regs:$rx, CPU16Regs:$ry, bb:$imm16)
1447 <(brcond (i32 (setlt CPU16Regs:$rx, immSExt16:$imm)), bb:$imm16),
1448 (BtnezT8SltiX16 CPU16Regs:$rx, immSExt16:$imm, bb:$imm16)
1455 <(brcond (i32 (setle CPU16Regs:$rx, CPU16Regs:$ry)), bb:$imm16),
1456 (BteqzT8SltX16 CPU16Regs:$ry, CPU16Regs:$rx, bb:$imm16)
1463 <(brcond (i32 (setne CPU16Regs:$rx, CPU16Regs:$ry)), bb:$imm16),
1464 (BtnezT8CmpX16 CPU16Regs:$rx, CPU16Regs:$ry, bb:$imm16)
1468 <(brcond (i32 (setne CPU16Regs:$rx, immZExt16:$imm)), bb:$targ16),
1469 (BtnezT8CmpiX16 CPU16Regs:$rx, immSExt16:$imm, bb:$targ16)
1473 <(brcond (i32 (setne CPU16Regs:$rx, 0)), bb:$targ16),
1474 (BnezRxImmX16 CPU16Regs:$rx, bb:$targ16)
1478 // This needs to be there but I forget which code will generate it
1481 <(brcond CPU16Regs:$rx, bb:$targ16),
1482 (BnezRxImmX16 CPU16Regs:$rx, bb:$targ16)
1491 // <(brcond (i32 (setugt CPU16Regs:$rx, CPU16Regs:$ry)), bb:$imm16),
1492 // (BtnezT8SltuX16 CPU16Regs:$ry, CPU16Regs:$rx, bb:$imm16)
1499 // <(brcond (i32 (setuge CPU16Regs:$rx, CPU16Regs:$ry)), bb:$imm16),
1500 // (BteqzT8SltuX16 CPU16Regs:$rx, CPU16Regs:$ry, bb:$imm16)
1508 // <(brcond (i32 (setult CPU16Regs:$rx, CPU16Regs:$ry)), bb:$imm16),
1509 // (BtnezT8SltuX16 CPU16Regs:$rx, CPU16Regs:$ry, bb:$imm16)
1512 def: UncondBranch16_pat<br, BimmX16>;
1515 def: Mips16Pat<(i32 immSExt16:$in),
1516 (AddiuRxRxImmX16 (Move32R16 ZERO), immSExt16:$in)>;
1518 def: Mips16Pat<(i32 immZExt16:$in), (LiRxImmX16 immZExt16:$in)>;
1524 <(MipsDivRem16 CPU16Regs:$rx, CPU16Regs:$ry),
1525 (DivRxRy16 CPU16Regs:$rx, CPU16Regs:$ry)>;
1531 <(MipsDivRemU16 CPU16Regs:$rx, CPU16Regs:$ry),
1532 (DivuRxRy16 CPU16Regs:$rx, CPU16Regs:$ry)>;
1537 // if !(a < b) x = y
1539 def : Mips16Pat<(select (i32 (setge CPU16Regs:$a, CPU16Regs:$b)),
1540 CPU16Regs:$x, CPU16Regs:$y),
1541 (SelTBteqZSlt CPU16Regs:$x, CPU16Regs:$y,
1542 CPU16Regs:$a, CPU16Regs:$b)>;
1549 def : Mips16Pat<(select (i32 (setgt CPU16Regs:$a, CPU16Regs:$b)),
1550 CPU16Regs:$x, CPU16Regs:$y),
1551 (SelTBtneZSlt CPU16Regs:$x, CPU16Regs:$y,
1552 CPU16Regs:$b, CPU16Regs:$a)>;
1557 // if !(a < b) x = y;
1560 (select (i32 (setuge CPU16Regs:$a, CPU16Regs:$b)),
1561 CPU16Regs:$x, CPU16Regs:$y),
1562 (SelTBteqZSltu CPU16Regs:$x, CPU16Regs:$y,
1563 CPU16Regs:$a, CPU16Regs:$b)>;
1570 def : Mips16Pat<(select (i32 (setugt CPU16Regs:$a, CPU16Regs:$b)),
1571 CPU16Regs:$x, CPU16Regs:$y),
1572 (SelTBtneZSltu CPU16Regs:$x, CPU16Regs:$y,
1573 CPU16Regs:$b, CPU16Regs:$a)>;
1577 // due to an llvm optimization, i don't think that this will ever
1578 // be used. This is transformed into x = (a > k-1)?x:y
1583 // (select (i32 (setge CPU16Regs:$lhs, immSExt16:$rhs)),
1584 // CPU16Regs:$T, CPU16Regs:$F),
1585 // (SelTBteqZSlti CPU16Regs:$T, CPU16Regs:$F,
1586 // CPU16Regs:$lhs, immSExt16:$rhs)>;
1589 // (select (i32 (setuge CPU16Regs:$lhs, immSExt16:$rhs)),
1590 // CPU16Regs:$T, CPU16Regs:$F),
1591 // (SelTBteqZSltiu CPU16Regs:$T, CPU16Regs:$F,
1592 // CPU16Regs:$lhs, immSExt16:$rhs)>;
1597 // if !(a < k) x = y;
1600 (select (i32 (setlt CPU16Regs:$a, immSExt16:$b)),
1601 CPU16Regs:$x, CPU16Regs:$y),
1602 (SelTBtneZSlti CPU16Regs:$x, CPU16Regs:$y,
1603 CPU16Regs:$a, immSExt16:$b)>;
1609 // x = (a <= b)? x : y
1613 def : Mips16Pat<(select (i32 (setle CPU16Regs:$a, CPU16Regs:$b)),
1614 CPU16Regs:$x, CPU16Regs:$y),
1615 (SelTBteqZSlt CPU16Regs:$x, CPU16Regs:$y,
1616 CPU16Regs:$b, CPU16Regs:$a)>;
1620 // x = (a <= b)? x : y
1624 def : Mips16Pat<(select (i32 (setule CPU16Regs:$a, CPU16Regs:$b)),
1625 CPU16Regs:$x, CPU16Regs:$y),
1626 (SelTBteqZSltu CPU16Regs:$x, CPU16Regs:$y,
1627 CPU16Regs:$b, CPU16Regs:$a)>;
1631 // x = (a == b)? x : y
1633 // if (a != b) x = y
1635 def : Mips16Pat<(select (i32 (seteq CPU16Regs:$a, CPU16Regs:$b)),
1636 CPU16Regs:$x, CPU16Regs:$y),
1637 (SelTBteqZCmp CPU16Regs:$x, CPU16Regs:$y,
1638 CPU16Regs:$b, CPU16Regs:$a)>;
1642 // x = (a == 0)? x : y
1644 // if (a != 0) x = y
1646 def : Mips16Pat<(select (i32 (seteq CPU16Regs:$a, 0)),
1647 CPU16Regs:$x, CPU16Regs:$y),
1648 (SelBeqZ CPU16Regs:$x, CPU16Regs:$y,
1654 // x = (a == k)? x : y
1656 // if (a != k) x = y
1658 def : Mips16Pat<(select (i32 (seteq CPU16Regs:$a, immZExt16:$k)),
1659 CPU16Regs:$x, CPU16Regs:$y),
1660 (SelTBteqZCmpi CPU16Regs:$x, CPU16Regs:$y,
1661 CPU16Regs:$a, immZExt16:$k)>;
1666 // x = (a != b)? x : y
1668 // if (a == b) x = y
1671 def : Mips16Pat<(select (i32 (setne CPU16Regs:$a, CPU16Regs:$b)),
1672 CPU16Regs:$x, CPU16Regs:$y),
1673 (SelTBtneZCmp CPU16Regs:$x, CPU16Regs:$y,
1674 CPU16Regs:$b, CPU16Regs:$a)>;
1678 // x = (a != 0)? x : y
1680 // if (a == 0) x = y
1682 def : Mips16Pat<(select (i32 (setne CPU16Regs:$a, 0)),
1683 CPU16Regs:$x, CPU16Regs:$y),
1684 (SelBneZ CPU16Regs:$x, CPU16Regs:$y,
1692 def : Mips16Pat<(select CPU16Regs:$a,
1693 CPU16Regs:$x, CPU16Regs:$y),
1694 (SelBneZ CPU16Regs:$x, CPU16Regs:$y,
1700 // x = (a != k)? x : y
1702 // if (a == k) x = y
1704 def : Mips16Pat<(select (i32 (setne CPU16Regs:$a, immZExt16:$k)),
1705 CPU16Regs:$x, CPU16Regs:$y),
1706 (SelTBtneZCmpi CPU16Regs:$x, CPU16Regs:$y,
1707 CPU16Regs:$a, immZExt16:$k)>;
1710 // When writing C code to test setxx these patterns,
1711 // some will be transformed into
1712 // other things. So we test using C code but using -O3 and -O0
1717 <(seteq CPU16Regs:$lhs,CPU16Regs:$rhs),
1718 (SltiuCCRxImmX16 (XorRxRxRy16 CPU16Regs:$lhs, CPU16Regs:$rhs), 1)>;
1721 <(seteq CPU16Regs:$lhs, 0),
1722 (SltiuCCRxImmX16 CPU16Regs:$lhs, 1)>;
1730 <(setge CPU16Regs:$lhs, CPU16Regs:$rhs),
1731 (XorRxRxRy16 (SltCCRxRy16 CPU16Regs:$lhs, CPU16Regs:$rhs),
1735 // For constants, llvm transforms this to:
1736 // x > (k -1) and then reverses the operands to use setlt. So this pattern
1737 // is not used now by the compiler. (Presumably checking that k-1 does not
1738 // overflow). The compiler never uses this at a the current time, due to
1739 // other optimizations.
1742 // <(setge CPU16Regs:$lhs, immSExt16:$rhs),
1743 // (XorRxRxRy16 (SltiCCRxImmX16 CPU16Regs:$lhs, immSExt16:$rhs),
1744 // (LiRxImmX16 1))>;
1746 // This catches the x >= -32768 case by transforming it to x > -32769
1749 <(setgt CPU16Regs:$lhs, -32769),
1750 (XorRxRxRy16 (SltiCCRxImmX16 CPU16Regs:$lhs, -32768),
1759 <(setgt CPU16Regs:$lhs, CPU16Regs:$rhs),
1760 (SltCCRxRy16 CPU16Regs:$rhs, CPU16Regs:$lhs)>;
1766 <(setle CPU16Regs:$lhs, CPU16Regs:$rhs),
1767 (XorRxRxRy16 (SltCCRxRy16 CPU16Regs:$rhs, CPU16Regs:$lhs), (LiRxImm16 1))>;
1772 def: SetCC_R16<setlt, SltCCRxRy16>;
1774 def: SetCC_I16<setlt, immSExt16, SltiCCRxImmX16>;
1780 <(setne CPU16Regs:$lhs,CPU16Regs:$rhs),
1781 (SltuCCRxRy16 (LiRxImmX16 0),
1782 (XorRxRxRy16 CPU16Regs:$lhs, CPU16Regs:$rhs))>;
1789 <(setuge CPU16Regs:$lhs, CPU16Regs:$rhs),
1790 (XorRxRxRy16 (SltuCCRxRy16 CPU16Regs:$lhs, CPU16Regs:$rhs),
1793 // this pattern will never be used because the compiler will transform
1794 // x >= k to x > (k - 1) and then use SLT
1797 // <(setuge CPU16Regs:$lhs, immZExt16:$rhs),
1798 // (XorRxRxRy16 (SltiuCCRxImmX16 CPU16Regs:$lhs, immZExt16:$rhs),
1799 // (LiRxImmX16 1))>;
1805 <(setugt CPU16Regs:$lhs, CPU16Regs:$rhs),
1806 (SltuCCRxRy16 CPU16Regs:$rhs, CPU16Regs:$lhs)>;
1812 <(setule CPU16Regs:$lhs, CPU16Regs:$rhs),
1813 (XorRxRxRy16 (SltuCCRxRy16 CPU16Regs:$rhs, CPU16Regs:$lhs), (LiRxImmX16 1))>;
1818 def: SetCC_R16<setult, SltuCCRxRy16>;
1820 def: SetCC_I16<setult, immSExt16, SltiuCCRxImmX16>;
1822 def: Mips16Pat<(add CPU16Regs:$hi, (MipsLo tglobaladdr:$lo)),
1823 (AddiuRxRxImmX16 CPU16Regs:$hi, tglobaladdr:$lo)>;
1826 def : Mips16Pat<(MipsHi tblockaddress:$in),
1827 (SllX16 (LiRxImmX16 tblockaddress:$in), 16)>;
1828 def : Mips16Pat<(MipsHi tglobaladdr:$in),
1829 (SllX16 (LiRxImmX16 tglobaladdr:$in), 16)>;
1830 def : Mips16Pat<(MipsHi tjumptable:$in),
1831 (SllX16 (LiRxImmX16 tjumptable:$in), 16)>;
1832 def : Mips16Pat<(MipsHi tglobaltlsaddr:$in),
1833 (SllX16 (LiRxImmX16 tglobaltlsaddr:$in), 16)>;
1835 def : Mips16Pat<(MipsLo tblockaddress:$in), (LiRxImmX16 tblockaddress:$in)>;
1838 class Wrapper16Pat<SDNode node, Instruction ADDiuOp, RegisterClass RC>:
1839 Mips16Pat<(MipsWrapper RC:$gp, node:$in),
1840 (ADDiuOp RC:$gp, node:$in)>;
1843 def : Wrapper16Pat<tglobaladdr, AddiuRxRxImmX16, CPU16Regs>;
1844 def : Wrapper16Pat<tglobaltlsaddr, AddiuRxRxImmX16, CPU16Regs>;
1846 def : Mips16Pat<(i32 (extloadi8 addr16:$src)),
1847 (LbuRxRyOffMemX16 addr16:$src)>;
1848 def : Mips16Pat<(i32 (extloadi16 addr16:$src)),
1849 (LhuRxRyOffMemX16 addr16:$src)>;
1851 def: Mips16Pat<(trap), (Break16)>;
1853 def : Mips16Pat<(sext_inreg CPU16Regs:$val, i8),
1854 (SebRx16 CPU16Regs:$val)>;
1856 def : Mips16Pat<(sext_inreg CPU16Regs:$val, i16),
1857 (SehRx16 CPU16Regs:$val)>;
1861 (outs CPU16Regs:$rh, CPU16Regs:$rl),
1862 (ins simm16:$immHi, simm16:$immLo),
1863 ".align 2\n\tli\t$rh, $immHi\n\taddiu\t$rl, $$pc, $immLo\n ",[]> ;
1865 // An operand for the CONSTPOOL_ENTRY pseudo-instruction.
1866 def cpinst_operand : Operand<i32> {
1867 // let PrintMethod = "printCPInstOperand";
1870 // CONSTPOOL_ENTRY - This instruction represents a floating constant pool in
1871 // the function. The first operand is the ID# for this instruction, the second
1872 // is the index into the MachineConstantPool that this is, the third is the
1873 // size in bytes of this constant pool entry.
1875 let neverHasSideEffects = 1, isNotDuplicable = 1 in
1876 def CONSTPOOL_ENTRY :
1877 MipsPseudo16<(outs), (ins cpinst_operand:$instid, cpinst_operand:$cpidx,
1878 i32imm:$size), "foo", []>;