Chris Lattner | 23e70eb | 2010-08-17 16:20:04 +0000 | [diff] [blame] | 1 | //===- MipsInstrInfo.td - Mips Register defs ---------------*- tablegen -*-===// |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | 4ee451d | 2007-12-29 20:36:04 +0000 | [diff] [blame] | 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | //===----------------------------------------------------------------------===// |
| 11 | // Instruction format superclass |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | include "MipsInstrFormats.td" |
| 15 | |
| 16 | //===----------------------------------------------------------------------===// |
| 17 | // Mips profiles and nodes |
| 18 | //===----------------------------------------------------------------------===// |
| 19 | |
Bruno Cardoso Lopes | 225ca9c | 2008-07-05 19:05:21 +0000 | [diff] [blame] | 20 | def SDT_MipsRet : SDTypeProfile<0, 1, [SDTCisInt<0>]>; |
| 21 | def SDT_MipsJmpLink : SDTypeProfile<0, 1, [SDTCisVT<0, iPTR>]>; |
Bruno Cardoso Lopes | 9e03061 | 2010-11-09 17:25:34 +0000 | [diff] [blame] | 22 | def SDT_MipsCMov : SDTypeProfile<1, 4, [SDTCisSameAs<0, 1>, |
Bruno Cardoso Lopes | 739e441 | 2008-08-13 07:13:40 +0000 | [diff] [blame] | 23 | SDTCisSameAs<1, 2>, SDTCisSameAs<3, 4>, |
| 24 | SDTCisInt<4>]>; |
Bruno Cardoso Lopes | 225ca9c | 2008-07-05 19:05:21 +0000 | [diff] [blame] | 25 | def SDT_MipsCallSeqStart : SDCallSeqStart<[SDTCisVT<0, i32>]>; |
| 26 | def SDT_MipsCallSeqEnd : SDCallSeqEnd<[SDTCisVT<0, i32>, SDTCisVT<1, i32>]>; |
Bruno Cardoso Lopes | 81092dc | 2011-03-04 17:51:39 +0000 | [diff] [blame] | 27 | def SDT_MipsMAddMSub : SDTypeProfile<0, 4, |
Bruno Cardoso Lopes | 8be7611 | 2011-01-18 19:29:17 +0000 | [diff] [blame] | 28 | [SDTCisVT<0, i32>, SDTCisSameAs<0, 1>, |
Bruno Cardoso Lopes | 81092dc | 2011-03-04 17:51:39 +0000 | [diff] [blame] | 29 | SDTCisSameAs<1, 2>, |
Bruno Cardoso Lopes | 8be7611 | 2011-01-18 19:29:17 +0000 | [diff] [blame] | 30 | SDTCisSameAs<2, 3>]>; |
Bruno Cardoso Lopes | 38b5e86 | 2011-03-04 21:03:24 +0000 | [diff] [blame] | 31 | def SDT_MipsDivRem : SDTypeProfile<0, 2, |
| 32 | [SDTCisVT<0, i32>, |
| 33 | SDTCisSameAs<0, 1>]>; |
Bruno Cardoso Lopes | 225ca9c | 2008-07-05 19:05:21 +0000 | [diff] [blame] | 34 | |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 35 | // Call |
Bruno Cardoso Lopes | 9e03061 | 2010-11-09 17:25:34 +0000 | [diff] [blame] | 36 | def MipsJmpLink : SDNode<"MipsISD::JmpLink",SDT_MipsJmpLink, |
Chris Lattner | 036609b | 2010-12-23 18:28:41 +0000 | [diff] [blame] | 37 | [SDNPHasChain, SDNPOutGlue, SDNPOptInGlue, |
Chris Lattner | 60e9eac | 2010-03-19 05:33:51 +0000 | [diff] [blame] | 38 | SDNPVariadic]>; |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 39 | |
Bruno Cardoso Lopes | 9e03061 | 2010-11-09 17:25:34 +0000 | [diff] [blame] | 40 | // Hi and Lo nodes are used to handle global addresses. Used on |
| 41 | // MipsISelLowering to lower stuff like GlobalAddress, ExternalSymbol |
Bruno Cardoso Lopes | c7db561 | 2007-11-05 03:02:32 +0000 | [diff] [blame] | 42 | // static model. (nothing to do with Mips Registers Hi and Lo) |
Bruno Cardoso Lopes | 91fd532 | 2008-07-21 18:52:34 +0000 | [diff] [blame] | 43 | def MipsHi : SDNode<"MipsISD::Hi", SDTIntUnaryOp>; |
| 44 | def MipsLo : SDNode<"MipsISD::Lo", SDTIntUnaryOp>; |
| 45 | def MipsGPRel : SDNode<"MipsISD::GPRel", SDTIntUnaryOp>; |
Bruno Cardoso Lopes | e78080c | 2007-10-09 02:55:31 +0000 | [diff] [blame] | 46 | |
Eric Christopher | 3c999a2 | 2007-10-26 04:00:13 +0000 | [diff] [blame] | 47 | // Return |
Bruno Cardoso Lopes | 9e03061 | 2010-11-09 17:25:34 +0000 | [diff] [blame] | 48 | def MipsRet : SDNode<"MipsISD::Ret", SDT_MipsRet, [SDNPHasChain, |
Chris Lattner | 036609b | 2010-12-23 18:28:41 +0000 | [diff] [blame] | 49 | SDNPOptInGlue]>; |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 50 | |
| 51 | // These are target-independent nodes, but have target-specific formats. |
Bruno Cardoso Lopes | 225ca9c | 2008-07-05 19:05:21 +0000 | [diff] [blame] | 52 | def callseq_start : SDNode<"ISD::CALLSEQ_START", SDT_MipsCallSeqStart, |
Chris Lattner | 036609b | 2010-12-23 18:28:41 +0000 | [diff] [blame] | 53 | [SDNPHasChain, SDNPOutGlue]>; |
Bruno Cardoso Lopes | 225ca9c | 2008-07-05 19:05:21 +0000 | [diff] [blame] | 54 | def callseq_end : SDNode<"ISD::CALLSEQ_END", SDT_MipsCallSeqEnd, |
Chris Lattner | 036609b | 2010-12-23 18:28:41 +0000 | [diff] [blame] | 55 | [SDNPHasChain, SDNPOptInGlue, SDNPOutGlue]>; |
Bill Wendling | 0f8d9c0 | 2007-11-13 00:44:25 +0000 | [diff] [blame] | 56 | |
Bruno Cardoso Lopes | 8be7611 | 2011-01-18 19:29:17 +0000 | [diff] [blame] | 57 | // MAdd*/MSub* nodes |
| 58 | def MipsMAdd : SDNode<"MipsISD::MAdd", SDT_MipsMAddMSub, |
| 59 | [SDNPOptInGlue, SDNPOutGlue]>; |
| 60 | def MipsMAddu : SDNode<"MipsISD::MAddu", SDT_MipsMAddMSub, |
| 61 | [SDNPOptInGlue, SDNPOutGlue]>; |
| 62 | def MipsMSub : SDNode<"MipsISD::MSub", SDT_MipsMAddMSub, |
| 63 | [SDNPOptInGlue, SDNPOutGlue]>; |
| 64 | def MipsMSubu : SDNode<"MipsISD::MSubu", SDT_MipsMAddMSub, |
| 65 | [SDNPOptInGlue, SDNPOutGlue]>; |
| 66 | |
Bruno Cardoso Lopes | 38b5e86 | 2011-03-04 21:03:24 +0000 | [diff] [blame] | 67 | // DivRem(u) nodes |
| 68 | def MipsDivRem : SDNode<"MipsISD::DivRem", SDT_MipsDivRem, |
| 69 | [SDNPOutGlue]>; |
| 70 | def MipsDivRemU : SDNode<"MipsISD::DivRemU", SDT_MipsDivRem, |
| 71 | [SDNPOutGlue]>; |
| 72 | |
Bruno Cardoso Lopes | e78080c | 2007-10-09 02:55:31 +0000 | [diff] [blame] | 73 | //===----------------------------------------------------------------------===// |
| 74 | // Mips Instruction Predicate Definitions. |
| 75 | //===----------------------------------------------------------------------===// |
Bruno Cardoso Lopes | 65ad452 | 2008-08-08 06:16:31 +0000 | [diff] [blame] | 76 | def HasSEInReg : Predicate<"Subtarget.hasSEInReg()">; |
| 77 | def HasBitCount : Predicate<"Subtarget.hasBitCount()">; |
Bruno Cardoso Lopes | 739e441 | 2008-08-13 07:13:40 +0000 | [diff] [blame] | 78 | def HasSwap : Predicate<"Subtarget.hasSwap()">; |
| 79 | def HasCondMov : Predicate<"Subtarget.hasCondMov()">; |
Bruno Cardoso Lopes | 7d5652d | 2010-11-12 00:38:32 +0000 | [diff] [blame] | 80 | def IsMips32 : Predicate<"Subtarget.isMips32()">; |
Bruno Cardoso Lopes | 908b6dd | 2010-12-09 17:32:30 +0000 | [diff] [blame] | 81 | def IsMips32r2 : Predicate<"Subtarget.isMips32r2()">; |
Bruno Cardoso Lopes | e78080c | 2007-10-09 02:55:31 +0000 | [diff] [blame] | 82 | |
| 83 | //===----------------------------------------------------------------------===// |
| 84 | // Mips Operand, Complex Patterns and Transformations Definitions. |
| 85 | //===----------------------------------------------------------------------===// |
| 86 | |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 87 | // Instruction operand types |
| 88 | def brtarget : Operand<OtherVT>; |
| 89 | def calltarget : Operand<i32>; |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 90 | def simm16 : Operand<i32>; |
Eric Christopher | 3c999a2 | 2007-10-26 04:00:13 +0000 | [diff] [blame] | 91 | def shamt : Operand<i32>; |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 92 | |
Bruno Cardoso Lopes | 739e441 | 2008-08-13 07:13:40 +0000 | [diff] [blame] | 93 | // Unsigned Operand |
| 94 | def uimm16 : Operand<i32> { |
| 95 | let PrintMethod = "printUnsignedImm"; |
| 96 | } |
| 97 | |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 98 | // Address operand |
| 99 | def mem : Operand<i32> { |
| 100 | let PrintMethod = "printMemOperand"; |
| 101 | let MIOperandInfo = (ops simm16, CPURegs); |
| 102 | } |
| 103 | |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 104 | // Transformation Function - get the lower 16 bits. |
| 105 | def LO16 : SDNodeXForm<imm, [{ |
Dan Gohman | f5aeb1a | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 106 | return getI32Imm((unsigned)N->getZExtValue() & 0xFFFF); |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 107 | }]>; |
| 108 | |
| 109 | // Transformation Function - get the higher 16 bits. |
| 110 | def HI16 : SDNodeXForm<imm, [{ |
Dan Gohman | f5aeb1a | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 111 | return getI32Imm((unsigned)N->getZExtValue() >> 16); |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 112 | }]>; |
| 113 | |
| 114 | // Node immediate fits as 16-bit sign extended on target immediate. |
| 115 | // e.g. addi, andi |
Jakob Stoklund Olesen | 7552a3d | 2010-08-18 23:56:46 +0000 | [diff] [blame] | 116 | def immSExt16 : PatLeaf<(imm), [{ return isInt<16>(N->getSExtValue()); }]>; |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 117 | |
| 118 | // Node immediate fits as 16-bit zero extended on target immediate. |
| 119 | // The LO16 param means that only the lower 16 bits of the node |
| 120 | // immediate are caught. |
| 121 | // e.g. addiu, sltiu |
| 122 | def immZExt16 : PatLeaf<(imm), [{ |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 123 | if (N->getValueType(0) == MVT::i32) |
Dan Gohman | f5aeb1a | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 124 | return (uint32_t)N->getZExtValue() == (unsigned short)N->getZExtValue(); |
Eric Christopher | 3c999a2 | 2007-10-26 04:00:13 +0000 | [diff] [blame] | 125 | else |
Dan Gohman | f5aeb1a | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 126 | return (uint64_t)N->getZExtValue() == (unsigned short)N->getZExtValue(); |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 127 | }], LO16>; |
| 128 | |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 129 | // shamt field must fit in 5 bits. |
| 130 | def immZExt5 : PatLeaf<(imm), [{ |
Dan Gohman | f5aeb1a | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 131 | return N->getZExtValue() == ((N->getZExtValue()) & 0x1f) ; |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 132 | }]>; |
| 133 | |
Eric Christopher | 3c999a2 | 2007-10-26 04:00:13 +0000 | [diff] [blame] | 134 | // Mips Address Mode! SDNode frameindex could possibily be a match |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 135 | // since load and store instructions from stack used it. |
Chris Lattner | eb079a3 | 2010-02-14 21:53:19 +0000 | [diff] [blame] | 136 | def addr : ComplexPattern<iPTR, 2, "SelectAddr", [frameindex], []>; |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 137 | |
| 138 | //===----------------------------------------------------------------------===// |
| 139 | // Instructions specific format |
| 140 | //===----------------------------------------------------------------------===// |
| 141 | |
| 142 | // Arithmetic 3 register operands |
Eric Christopher | 3c999a2 | 2007-10-26 04:00:13 +0000 | [diff] [blame] | 143 | let isCommutable = 1 in |
Bruno Cardoso Lopes | 9710536 | 2007-08-18 02:37:46 +0000 | [diff] [blame] | 144 | class ArithR<bits<6> op, bits<6> func, string instr_asm, SDNode OpNode, |
Eric Christopher | 3c999a2 | 2007-10-26 04:00:13 +0000 | [diff] [blame] | 145 | InstrItinClass itin>: |
Bruno Cardoso Lopes | 9e03061 | 2010-11-09 17:25:34 +0000 | [diff] [blame] | 146 | FR<op, func, (outs CPURegs:$dst), (ins CPURegs:$b, CPURegs:$c), |
| 147 | !strconcat(instr_asm, "\t$dst, $b, $c"), |
| 148 | [(set CPURegs:$dst, (OpNode CPURegs:$b, CPURegs:$c))], itin>; |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 149 | |
Eric Christopher | 3c999a2 | 2007-10-26 04:00:13 +0000 | [diff] [blame] | 150 | let isCommutable = 1 in |
| 151 | class ArithOverflowR<bits<6> op, bits<6> func, string instr_asm>: |
Bruno Cardoso Lopes | 9e03061 | 2010-11-09 17:25:34 +0000 | [diff] [blame] | 152 | FR<op, func, (outs CPURegs:$dst), (ins CPURegs:$b, CPURegs:$c), |
| 153 | !strconcat(instr_asm, "\t$dst, $b, $c"), [], IIAlu>; |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 154 | |
| 155 | // Arithmetic 2 register operands |
Eric Christopher | 3c999a2 | 2007-10-26 04:00:13 +0000 | [diff] [blame] | 156 | class ArithI<bits<6> op, string instr_asm, SDNode OpNode, |
| 157 | Operand Od, PatLeaf imm_type> : |
Bruno Cardoso Lopes | 9e03061 | 2010-11-09 17:25:34 +0000 | [diff] [blame] | 158 | FI<op, (outs CPURegs:$dst), (ins CPURegs:$b, Od:$c), |
| 159 | !strconcat(instr_asm, "\t$dst, $b, $c"), |
| 160 | [(set CPURegs:$dst, (OpNode CPURegs:$b, imm_type:$c))], IIAlu>; |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 161 | |
Bruno Cardoso Lopes | 739e441 | 2008-08-13 07:13:40 +0000 | [diff] [blame] | 162 | class ArithOverflowI<bits<6> op, string instr_asm, SDNode OpNode, |
| 163 | Operand Od, PatLeaf imm_type> : |
Bruno Cardoso Lopes | 9e03061 | 2010-11-09 17:25:34 +0000 | [diff] [blame] | 164 | FI<op, (outs CPURegs:$dst), (ins CPURegs:$b, Od:$c), |
| 165 | !strconcat(instr_asm, "\t$dst, $b, $c"), [], IIAlu>; |
Bruno Cardoso Lopes | 739e441 | 2008-08-13 07:13:40 +0000 | [diff] [blame] | 166 | |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 167 | // Arithmetic Multiply ADD/SUB |
Bruno Cardoso Lopes | 8be7611 | 2011-01-18 19:29:17 +0000 | [diff] [blame] | 168 | let rd = 0, shamt = 0, Defs = [HI, LO], Uses = [HI, LO] in |
| 169 | class MArithR<bits<6> func, string instr_asm, SDNode op> : |
| 170 | FR<0x1c, func, (outs), (ins CPURegs:$rs, CPURegs:$rt), |
Bruno Cardoso Lopes | 81092dc | 2011-03-04 17:51:39 +0000 | [diff] [blame] | 171 | !strconcat(instr_asm, "\t$rs, $rt"), |
Bruno Cardoso Lopes | 8be7611 | 2011-01-18 19:29:17 +0000 | [diff] [blame] | 172 | [(op CPURegs:$rs, CPURegs:$rt, LO, HI)], IIImul>; |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 173 | |
| 174 | // Logical |
| 175 | class LogicR<bits<6> func, string instr_asm, SDNode OpNode>: |
Bruno Cardoso Lopes | 9e03061 | 2010-11-09 17:25:34 +0000 | [diff] [blame] | 176 | FR<0x00, func, (outs CPURegs:$dst), (ins CPURegs:$b, CPURegs:$c), |
| 177 | !strconcat(instr_asm, "\t$dst, $b, $c"), |
| 178 | [(set CPURegs:$dst, (OpNode CPURegs:$b, CPURegs:$c))], IIAlu>; |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 179 | |
| 180 | class LogicI<bits<6> op, string instr_asm, SDNode OpNode>: |
Bruno Cardoso Lopes | 9e03061 | 2010-11-09 17:25:34 +0000 | [diff] [blame] | 181 | FI<op, (outs CPURegs:$dst), (ins CPURegs:$b, uimm16:$c), |
| 182 | !strconcat(instr_asm, "\t$dst, $b, $c"), |
| 183 | [(set CPURegs:$dst, (OpNode CPURegs:$b, immZExt16:$c))], IIAlu>; |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 184 | |
| 185 | class LogicNOR<bits<6> op, bits<6> func, string instr_asm>: |
Bruno Cardoso Lopes | 9e03061 | 2010-11-09 17:25:34 +0000 | [diff] [blame] | 186 | FR<op, func, (outs CPURegs:$dst), (ins CPURegs:$b, CPURegs:$c), |
| 187 | !strconcat(instr_asm, "\t$dst, $b, $c"), |
| 188 | [(set CPURegs:$dst, (not (or CPURegs:$b, CPURegs:$c)))], IIAlu>; |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 189 | |
| 190 | // Shifts |
Bruno Cardoso Lopes | 81092dc | 2011-03-04 17:51:39 +0000 | [diff] [blame] | 191 | class LogicR_shift_rotate_imm<bits<6> func, bits<5> _rs, string instr_asm, |
Bruno Cardoso Lopes | 908b6dd | 2010-12-09 17:32:30 +0000 | [diff] [blame] | 192 | SDNode OpNode>: |
Bruno Cardoso Lopes | 9e03061 | 2010-11-09 17:25:34 +0000 | [diff] [blame] | 193 | FR<0x00, func, (outs CPURegs:$dst), (ins CPURegs:$b, shamt:$c), |
| 194 | !strconcat(instr_asm, "\t$dst, $b, $c"), |
Bruno Cardoso Lopes | 908b6dd | 2010-12-09 17:32:30 +0000 | [diff] [blame] | 195 | [(set CPURegs:$dst, (OpNode CPURegs:$b, immZExt5:$c))], IIAlu> { |
| 196 | let rs = _rs; |
| 197 | } |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 198 | |
Bruno Cardoso Lopes | 81092dc | 2011-03-04 17:51:39 +0000 | [diff] [blame] | 199 | class LogicR_shift_rotate_reg<bits<6> func, bits<5> _shamt, string instr_asm, |
Bruno Cardoso Lopes | 908b6dd | 2010-12-09 17:32:30 +0000 | [diff] [blame] | 200 | SDNode OpNode>: |
| 201 | FR<0x00, func, (outs CPURegs:$dst), (ins CPURegs:$c, CPURegs:$b), |
Bruno Cardoso Lopes | 9e03061 | 2010-11-09 17:25:34 +0000 | [diff] [blame] | 202 | !strconcat(instr_asm, "\t$dst, $b, $c"), |
Bruno Cardoso Lopes | 908b6dd | 2010-12-09 17:32:30 +0000 | [diff] [blame] | 203 | [(set CPURegs:$dst, (OpNode CPURegs:$b, CPURegs:$c))], IIAlu> { |
| 204 | let shamt = _shamt; |
| 205 | } |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 206 | |
| 207 | // Load Upper Imediate |
| 208 | class LoadUpper<bits<6> op, string instr_asm>: |
| 209 | FI< op, |
Evan Cheng | 64d80e3 | 2007-07-19 01:14:50 +0000 | [diff] [blame] | 210 | (outs CPURegs:$dst), |
| 211 | (ins uimm16:$imm), |
Bruno Cardoso Lopes | 43d526d | 2008-07-14 14:42:54 +0000 | [diff] [blame] | 212 | !strconcat(instr_asm, "\t$dst, $imm"), |
Bruno Cardoso Lopes | 9710536 | 2007-08-18 02:37:46 +0000 | [diff] [blame] | 213 | [], IIAlu>; |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 214 | |
Eric Christopher | 3c999a2 | 2007-10-26 04:00:13 +0000 | [diff] [blame] | 215 | // Memory Load/Store |
Dan Gohman | 15511cf | 2008-12-03 18:15:48 +0000 | [diff] [blame] | 216 | let canFoldAsLoad = 1, hasDelaySlot = 1 in |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 217 | class LoadM<bits<6> op, string instr_asm, PatFrag OpNode>: |
Bruno Cardoso Lopes | 9e03061 | 2010-11-09 17:25:34 +0000 | [diff] [blame] | 218 | FI<op, (outs CPURegs:$dst), (ins mem:$addr), |
| 219 | !strconcat(instr_asm, "\t$dst, $addr"), |
| 220 | [(set CPURegs:$dst, (OpNode addr:$addr))], IILoad>; |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 221 | |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 222 | class StoreM<bits<6> op, string instr_asm, PatFrag OpNode>: |
Bruno Cardoso Lopes | 9e03061 | 2010-11-09 17:25:34 +0000 | [diff] [blame] | 223 | FI<op, (outs), (ins CPURegs:$dst, mem:$addr), |
| 224 | !strconcat(instr_asm, "\t$dst, $addr"), |
| 225 | [(OpNode CPURegs:$dst, addr:$addr)], IIStore>; |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 226 | |
| 227 | // Conditional Branch |
Bruno Cardoso Lopes | 9710536 | 2007-08-18 02:37:46 +0000 | [diff] [blame] | 228 | let isBranch = 1, isTerminator=1, hasDelaySlot = 1 in { |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 229 | class CBranch<bits<6> op, string instr_asm, PatFrag cond_op>: |
Bruno Cardoso Lopes | 9e03061 | 2010-11-09 17:25:34 +0000 | [diff] [blame] | 230 | FI<op, (outs), (ins CPURegs:$a, CPURegs:$b, brtarget:$offset), |
| 231 | !strconcat(instr_asm, "\t$a, $b, $offset"), |
| 232 | [(brcond (cond_op CPURegs:$a, CPURegs:$b), bb:$offset)], |
| 233 | IIBranch>; |
Bruno Cardoso Lopes | 9710536 | 2007-08-18 02:37:46 +0000 | [diff] [blame] | 234 | |
| 235 | class CBranchZero<bits<6> op, string instr_asm, PatFrag cond_op>: |
Bruno Cardoso Lopes | 9e03061 | 2010-11-09 17:25:34 +0000 | [diff] [blame] | 236 | FI<op, (outs), (ins CPURegs:$src, brtarget:$offset), |
| 237 | !strconcat(instr_asm, "\t$src, $offset"), |
| 238 | [(brcond (cond_op CPURegs:$src, 0), bb:$offset)], |
| 239 | IIBranch>; |
Eric Christopher | 3c999a2 | 2007-10-26 04:00:13 +0000 | [diff] [blame] | 240 | } |
Bruno Cardoso Lopes | 9710536 | 2007-08-18 02:37:46 +0000 | [diff] [blame] | 241 | |
Eric Christopher | 3c999a2 | 2007-10-26 04:00:13 +0000 | [diff] [blame] | 242 | // SetCC |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 243 | class SetCC_R<bits<6> op, bits<6> func, string instr_asm, |
| 244 | PatFrag cond_op>: |
Bruno Cardoso Lopes | 9e03061 | 2010-11-09 17:25:34 +0000 | [diff] [blame] | 245 | FR<op, func, (outs CPURegs:$dst), (ins CPURegs:$b, CPURegs:$c), |
| 246 | !strconcat(instr_asm, "\t$dst, $b, $c"), |
| 247 | [(set CPURegs:$dst, (cond_op CPURegs:$b, CPURegs:$c))], |
| 248 | IIAlu>; |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 249 | |
| 250 | class SetCC_I<bits<6> op, string instr_asm, PatFrag cond_op, |
| 251 | Operand Od, PatLeaf imm_type>: |
Bruno Cardoso Lopes | 9e03061 | 2010-11-09 17:25:34 +0000 | [diff] [blame] | 252 | FI<op, (outs CPURegs:$dst), (ins CPURegs:$b, Od:$c), |
| 253 | !strconcat(instr_asm, "\t$dst, $b, $c"), |
| 254 | [(set CPURegs:$dst, (cond_op CPURegs:$b, imm_type:$c))], |
| 255 | IIAlu>; |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 256 | |
| 257 | // Unconditional branch |
Bruno Cardoso Lopes | 9710536 | 2007-08-18 02:37:46 +0000 | [diff] [blame] | 258 | let isBranch=1, isTerminator=1, isBarrier=1, hasDelaySlot = 1 in |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 259 | class JumpFJ<bits<6> op, string instr_asm>: |
Bruno Cardoso Lopes | 9e03061 | 2010-11-09 17:25:34 +0000 | [diff] [blame] | 260 | FJ<op, (outs), (ins brtarget:$target), |
| 261 | !strconcat(instr_asm, "\t$target"), [(br bb:$target)], IIBranch>; |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 262 | |
Bruno Cardoso Lopes | 9710536 | 2007-08-18 02:37:46 +0000 | [diff] [blame] | 263 | let isBranch=1, isTerminator=1, isBarrier=1, rd=0, hasDelaySlot = 1 in |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 264 | class JumpFR<bits<6> op, bits<6> func, string instr_asm>: |
Bruno Cardoso Lopes | 9e03061 | 2010-11-09 17:25:34 +0000 | [diff] [blame] | 265 | FR<op, func, (outs), (ins CPURegs:$target), |
| 266 | !strconcat(instr_asm, "\t$target"), [(brind CPURegs:$target)], IIBranch>; |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 267 | |
| 268 | // Jump and Link (Call) |
Eric Christopher | 3c999a2 | 2007-10-26 04:00:13 +0000 | [diff] [blame] | 269 | let isCall=1, hasDelaySlot=1, |
Bruno Cardoso Lopes | 9710536 | 2007-08-18 02:37:46 +0000 | [diff] [blame] | 270 | // All calls clobber the non-callee saved registers... |
Jakob Stoklund Olesen | de12e43 | 2010-02-17 20:18:50 +0000 | [diff] [blame] | 271 | Defs = [AT, V0, V1, A0, A1, A2, A3, T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, |
| 272 | K0, K1, D0, D1, D2, D3, D4, D5, D6, D7, D8, D9], Uses = [GP] in { |
Eric Christopher | 3c999a2 | 2007-10-26 04:00:13 +0000 | [diff] [blame] | 273 | class JumpLink<bits<6> op, string instr_asm>: |
Bruno Cardoso Lopes | 9e03061 | 2010-11-09 17:25:34 +0000 | [diff] [blame] | 274 | FJ<op, (outs), (ins calltarget:$target, variable_ops), |
| 275 | !strconcat(instr_asm, "\t$target"), [(MipsJmpLink imm:$target)], |
| 276 | IIBranch>; |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 277 | |
Bruno Cardoso Lopes | 9710536 | 2007-08-18 02:37:46 +0000 | [diff] [blame] | 278 | let rd=31 in |
| 279 | class JumpLinkReg<bits<6> op, bits<6> func, string instr_asm>: |
Bruno Cardoso Lopes | 9e03061 | 2010-11-09 17:25:34 +0000 | [diff] [blame] | 280 | FR<op, func, (outs), (ins CPURegs:$rs, variable_ops), |
| 281 | !strconcat(instr_asm, "\t$rs"), [(MipsJmpLink CPURegs:$rs)], IIBranch>; |
Bruno Cardoso Lopes | 9710536 | 2007-08-18 02:37:46 +0000 | [diff] [blame] | 282 | |
| 283 | class BranchLink<string instr_asm>: |
Bruno Cardoso Lopes | 9e03061 | 2010-11-09 17:25:34 +0000 | [diff] [blame] | 284 | FI<0x1, (outs), (ins CPURegs:$rs, brtarget:$target, variable_ops), |
| 285 | !strconcat(instr_asm, "\t$rs, $target"), [], IIBranch>; |
Bruno Cardoso Lopes | 9710536 | 2007-08-18 02:37:46 +0000 | [diff] [blame] | 286 | } |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 287 | |
Eric Christopher | 3c999a2 | 2007-10-26 04:00:13 +0000 | [diff] [blame] | 288 | // Mul, Div |
Bruno Cardoso Lopes | 38b5e86 | 2011-03-04 21:03:24 +0000 | [diff] [blame] | 289 | let Defs = [HI, LO] in { |
| 290 | class Mul<bits<6> func, string instr_asm, InstrItinClass itin>: |
| 291 | FR<0x00, func, (outs), (ins CPURegs:$a, CPURegs:$b), |
| 292 | !strconcat(instr_asm, "\t$a, $b"), [], itin>; |
| 293 | |
| 294 | class Div<SDNode op, bits<6> func, string instr_asm, InstrItinClass itin>: |
| 295 | FR<0x00, func, (outs), (ins CPURegs:$a, CPURegs:$b), |
| 296 | !strconcat(instr_asm, "\t$$zero, $a, $b"), |
| 297 | [(op CPURegs:$a, CPURegs:$b)], itin>; |
| 298 | } |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 299 | |
Eric Christopher | 3c999a2 | 2007-10-26 04:00:13 +0000 | [diff] [blame] | 300 | // Move from Hi/Lo |
Bruno Cardoso Lopes | 91ef849 | 2008-08-02 19:42:36 +0000 | [diff] [blame] | 301 | class MoveFromLOHI<bits<6> func, string instr_asm>: |
Bruno Cardoso Lopes | 9e03061 | 2010-11-09 17:25:34 +0000 | [diff] [blame] | 302 | FR<0x00, func, (outs CPURegs:$dst), (ins), |
| 303 | !strconcat(instr_asm, "\t$dst"), [], IIHiLo>; |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 304 | |
Bruno Cardoso Lopes | 91ef849 | 2008-08-02 19:42:36 +0000 | [diff] [blame] | 305 | class MoveToLOHI<bits<6> func, string instr_asm>: |
Bruno Cardoso Lopes | 9e03061 | 2010-11-09 17:25:34 +0000 | [diff] [blame] | 306 | FR<0x00, func, (outs), (ins CPURegs:$src), |
| 307 | !strconcat(instr_asm, "\t$src"), [], IIHiLo>; |
Bruno Cardoso Lopes | 91ef849 | 2008-08-02 19:42:36 +0000 | [diff] [blame] | 308 | |
Eric Christopher | 3c999a2 | 2007-10-26 04:00:13 +0000 | [diff] [blame] | 309 | class EffectiveAddress<string instr_asm> : |
Bruno Cardoso Lopes | 9e03061 | 2010-11-09 17:25:34 +0000 | [diff] [blame] | 310 | FI<0x09, (outs CPURegs:$dst), (ins mem:$addr), |
| 311 | instr_asm, [(set CPURegs:$dst, addr:$addr)], IIAlu>; |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 312 | |
Bruno Cardoso Lopes | 65ad452 | 2008-08-08 06:16:31 +0000 | [diff] [blame] | 313 | // Count Leading Ones/Zeros in Word |
Bruno Cardoso Lopes | c4bb67c | 2010-11-10 02:13:22 +0000 | [diff] [blame] | 314 | class CountLeading<bits<6> func, string instr_asm, list<dag> pattern>: |
Bruno Cardoso Lopes | 9e03061 | 2010-11-09 17:25:34 +0000 | [diff] [blame] | 315 | FR<0x1c, func, (outs CPURegs:$dst), (ins CPURegs:$src), |
Bruno Cardoso Lopes | c4bb67c | 2010-11-10 02:13:22 +0000 | [diff] [blame] | 316 | !strconcat(instr_asm, "\t$dst, $src"), pattern, IIAlu>, |
| 317 | Requires<[HasBitCount]> { |
| 318 | let shamt = 0; |
| 319 | let rt = rd; |
| 320 | } |
Bruno Cardoso Lopes | 65ad452 | 2008-08-08 06:16:31 +0000 | [diff] [blame] | 321 | |
| 322 | // Sign Extend in Register. |
Bruno Cardoso Lopes | 225ca9c | 2008-07-05 19:05:21 +0000 | [diff] [blame] | 323 | class SignExtInReg<bits<6> func, string instr_asm, ValueType vt>: |
Bruno Cardoso Lopes | 9e03061 | 2010-11-09 17:25:34 +0000 | [diff] [blame] | 324 | FR<0x3f, func, (outs CPURegs:$dst), (ins CPURegs:$src), |
| 325 | !strconcat(instr_asm, "\t$dst, $src"), |
| 326 | [(set CPURegs:$dst, (sext_inreg CPURegs:$src, vt))], NoItinerary>; |
Bruno Cardoso Lopes | 225ca9c | 2008-07-05 19:05:21 +0000 | [diff] [blame] | 327 | |
Bruno Cardoso Lopes | 739e441 | 2008-08-13 07:13:40 +0000 | [diff] [blame] | 328 | // Byte Swap |
| 329 | class ByteSwap<bits<6> func, string instr_asm>: |
Bruno Cardoso Lopes | 9e03061 | 2010-11-09 17:25:34 +0000 | [diff] [blame] | 330 | FR<0x1f, func, (outs CPURegs:$dst), (ins CPURegs:$src), |
| 331 | !strconcat(instr_asm, "\t$dst, $src"), |
| 332 | [(set CPURegs:$dst, (bswap CPURegs:$src))], NoItinerary>; |
Bruno Cardoso Lopes | 739e441 | 2008-08-13 07:13:40 +0000 | [diff] [blame] | 333 | |
| 334 | // Conditional Move |
| 335 | class CondMov<bits<6> func, string instr_asm, PatLeaf MovCode>: |
Bruno Cardoso Lopes | 9e03061 | 2010-11-09 17:25:34 +0000 | [diff] [blame] | 336 | FR<0x00, func, (outs CPURegs:$dst), (ins CPURegs:$F, CPURegs:$T, |
| 337 | CPURegs:$cond), !strconcat(instr_asm, "\t$dst, $T, $cond"), |
Bruno Cardoso Lopes | bd3af09c | 2010-12-07 19:04:14 +0000 | [diff] [blame] | 338 | [], NoItinerary>; |
Bruno Cardoso Lopes | 225ca9c | 2008-07-05 19:05:21 +0000 | [diff] [blame] | 339 | |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 340 | //===----------------------------------------------------------------------===// |
| 341 | // Pseudo instructions |
| 342 | //===----------------------------------------------------------------------===// |
| 343 | |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 344 | // As stack alignment is always done with addiu, we need a 16-bit immediate |
Evan Cheng | 071a279 | 2007-09-11 19:55:27 +0000 | [diff] [blame] | 345 | let Defs = [SP], Uses = [SP] in { |
Bruno Cardoso Lopes | 07cec75 | 2008-06-06 00:58:26 +0000 | [diff] [blame] | 346 | def ADJCALLSTACKDOWN : MipsPseudo<(outs), (ins uimm16:$amt), |
Bruno Cardoso Lopes | 225ca9c | 2008-07-05 19:05:21 +0000 | [diff] [blame] | 347 | "!ADJCALLSTACKDOWN $amt", |
Chris Lattner | e563bbc | 2008-10-11 22:08:30 +0000 | [diff] [blame] | 348 | [(callseq_start timm:$amt)]>; |
Bruno Cardoso Lopes | 07cec75 | 2008-06-06 00:58:26 +0000 | [diff] [blame] | 349 | def ADJCALLSTACKUP : MipsPseudo<(outs), (ins uimm16:$amt1, uimm16:$amt2), |
Bruno Cardoso Lopes | 225ca9c | 2008-07-05 19:05:21 +0000 | [diff] [blame] | 350 | "!ADJCALLSTACKUP $amt1", |
Chris Lattner | e563bbc | 2008-10-11 22:08:30 +0000 | [diff] [blame] | 351 | [(callseq_end timm:$amt1, timm:$amt2)]>; |
Evan Cheng | 071a279 | 2007-09-11 19:55:27 +0000 | [diff] [blame] | 352 | } |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 353 | |
Bruno Cardoso Lopes | 43d526d | 2008-07-14 14:42:54 +0000 | [diff] [blame] | 354 | // Some assembly macros need to avoid pseudoinstructions and assembler |
| 355 | // automatic reodering, we should reorder ourselves. |
| 356 | def MACRO : MipsPseudo<(outs), (ins), ".set\tmacro", []>; |
| 357 | def REORDER : MipsPseudo<(outs), (ins), ".set\treorder", []>; |
| 358 | def NOMACRO : MipsPseudo<(outs), (ins), ".set\tnomacro", []>; |
| 359 | def NOREORDER : MipsPseudo<(outs), (ins), ".set\tnoreorder", []>; |
| 360 | |
Akira Hatanaka | 1d6b38d | 2011-03-31 18:26:17 +0000 | [diff] [blame^] | 361 | // These macros are inserted to prevent GAS from complaining |
Bruno Cardoso Lopes | 99027d7 | 2011-03-04 20:48:08 +0000 | [diff] [blame] | 362 | // when using the AT register. |
| 363 | def NOAT : MipsPseudo<(outs), (ins), ".set\tnoat", []>; |
| 364 | def ATMACRO : MipsPseudo<(outs), (ins), ".set\tat", []>; |
| 365 | |
Eric Christopher | 3c999a2 | 2007-10-26 04:00:13 +0000 | [diff] [blame] | 366 | // When handling PIC code the assembler needs .cpload and .cprestore |
| 367 | // directives. If the real instructions corresponding these directives |
| 368 | // are used, we have the same behavior, but get also a bunch of warnings |
Bruno Cardoso Lopes | e78080c | 2007-10-09 02:55:31 +0000 | [diff] [blame] | 369 | // from the assembler. |
Bruno Cardoso Lopes | 43d526d | 2008-07-14 14:42:54 +0000 | [diff] [blame] | 370 | def CPLOAD : MipsPseudo<(outs), (ins CPURegs:$picreg), ".cpload\t$picreg", []>; |
| 371 | def CPRESTORE : MipsPseudo<(outs), (ins uimm16:$loc), ".cprestore\t$loc\n", []>; |
Bruno Cardoso Lopes | 07cec75 | 2008-06-06 00:58:26 +0000 | [diff] [blame] | 372 | |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 373 | //===----------------------------------------------------------------------===// |
| 374 | // Instruction definition |
| 375 | //===----------------------------------------------------------------------===// |
| 376 | |
| 377 | //===----------------------------------------------------------------------===// |
Bruno Cardoso Lopes | 9710536 | 2007-08-18 02:37:46 +0000 | [diff] [blame] | 378 | // MipsI Instructions |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 379 | //===----------------------------------------------------------------------===// |
| 380 | |
Bruno Cardoso Lopes | f7d66f7 | 2008-07-30 16:58:59 +0000 | [diff] [blame] | 381 | /// Arithmetic Instructions (ALU Immediate) |
Bruno Cardoso Lopes | 739e441 | 2008-08-13 07:13:40 +0000 | [diff] [blame] | 382 | def ADDiu : ArithI<0x09, "addiu", add, simm16, immSExt16>; |
| 383 | def ADDi : ArithOverflowI<0x08, "addi", add, simm16, immSExt16>; |
Bruno Cardoso Lopes | f7d66f7 | 2008-07-30 16:58:59 +0000 | [diff] [blame] | 384 | def SLTi : SetCC_I<0x0a, "slti", setlt, simm16, immSExt16>; |
Bruno Cardoso Lopes | 739e441 | 2008-08-13 07:13:40 +0000 | [diff] [blame] | 385 | def SLTiu : SetCC_I<0x0b, "sltiu", setult, simm16, immSExt16>; |
Bruno Cardoso Lopes | f7d66f7 | 2008-07-30 16:58:59 +0000 | [diff] [blame] | 386 | def ANDi : LogicI<0x0c, "andi", and>; |
| 387 | def ORi : LogicI<0x0d, "ori", or>; |
| 388 | def XORi : LogicI<0x0e, "xori", xor>; |
| 389 | def LUi : LoadUpper<0x0f, "lui">; |
| 390 | |
| 391 | /// Arithmetic Instructions (3-Operand, R-Type) |
Bruno Cardoso Lopes | 9710536 | 2007-08-18 02:37:46 +0000 | [diff] [blame] | 392 | def ADDu : ArithR<0x00, 0x21, "addu", add, IIAlu>; |
| 393 | def SUBu : ArithR<0x00, 0x23, "subu", sub, IIAlu>; |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 394 | def ADD : ArithOverflowR<0x00, 0x20, "add">; |
| 395 | def SUB : ArithOverflowR<0x00, 0x22, "sub">; |
Bruno Cardoso Lopes | f7d66f7 | 2008-07-30 16:58:59 +0000 | [diff] [blame] | 396 | def SLT : SetCC_R<0x00, 0x2a, "slt", setlt>; |
| 397 | def SLTu : SetCC_R<0x00, 0x2b, "sltu", setult>; |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 398 | def AND : LogicR<0x24, "and", and>; |
| 399 | def OR : LogicR<0x25, "or", or>; |
| 400 | def XOR : LogicR<0x26, "xor", xor>; |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 401 | def NOR : LogicNOR<0x00, 0x27, "nor">; |
| 402 | |
Bruno Cardoso Lopes | f7d66f7 | 2008-07-30 16:58:59 +0000 | [diff] [blame] | 403 | /// Shift Instructions |
Bruno Cardoso Lopes | 908b6dd | 2010-12-09 17:32:30 +0000 | [diff] [blame] | 404 | def SLL : LogicR_shift_rotate_imm<0x00, 0x00, "sll", shl>; |
| 405 | def SRL : LogicR_shift_rotate_imm<0x02, 0x00, "srl", srl>; |
| 406 | def SRA : LogicR_shift_rotate_imm<0x03, 0x00, "sra", sra>; |
| 407 | def SLLV : LogicR_shift_rotate_reg<0x04, 0x00, "sllv", shl>; |
| 408 | def SRLV : LogicR_shift_rotate_reg<0x06, 0x00, "srlv", srl>; |
| 409 | def SRAV : LogicR_shift_rotate_reg<0x07, 0x00, "srav", sra>; |
| 410 | |
| 411 | // Rotate Instructions |
| 412 | let Predicates = [IsMips32r2] in { |
| 413 | def ROTR : LogicR_shift_rotate_imm<0x02, 0x01, "rotr", rotr>; |
| 414 | def ROTRV : LogicR_shift_rotate_reg<0x06, 0x01, "rotrv", rotr>; |
| 415 | } |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 416 | |
Bruno Cardoso Lopes | f7d66f7 | 2008-07-30 16:58:59 +0000 | [diff] [blame] | 417 | /// Load and Store Instructions |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 418 | def LB : LoadM<0x20, "lb", sextloadi8>; |
| 419 | def LBu : LoadM<0x24, "lbu", zextloadi8>; |
| 420 | def LH : LoadM<0x21, "lh", sextloadi16>; |
| 421 | def LHu : LoadM<0x25, "lhu", zextloadi16>; |
| 422 | def LW : LoadM<0x23, "lw", load>; |
| 423 | def SB : StoreM<0x28, "sb", truncstorei8>; |
| 424 | def SH : StoreM<0x29, "sh", truncstorei16>; |
| 425 | def SW : StoreM<0x2b, "sw", store>; |
| 426 | |
Bruno Cardoso Lopes | f7d66f7 | 2008-07-30 16:58:59 +0000 | [diff] [blame] | 427 | /// Jump and Branch Instructions |
| 428 | def J : JumpFJ<0x02, "j">; |
| 429 | def JR : JumpFR<0x00, 0x08, "jr">; |
| 430 | def JAL : JumpLink<0x03, "jal">; |
| 431 | def JALR : JumpLinkReg<0x00, 0x09, "jalr">; |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 432 | def BEQ : CBranch<0x04, "beq", seteq>; |
| 433 | def BNE : CBranch<0x05, "bne", setne>; |
Bruno Cardoso Lopes | 9710536 | 2007-08-18 02:37:46 +0000 | [diff] [blame] | 434 | |
Eric Christopher | 3c999a2 | 2007-10-26 04:00:13 +0000 | [diff] [blame] | 435 | let rt=1 in |
Bruno Cardoso Lopes | f7d66f7 | 2008-07-30 16:58:59 +0000 | [diff] [blame] | 436 | def BGEZ : CBranchZero<0x01, "bgez", setge>; |
Bruno Cardoso Lopes | 9710536 | 2007-08-18 02:37:46 +0000 | [diff] [blame] | 437 | |
| 438 | let rt=0 in { |
Bruno Cardoso Lopes | f7d66f7 | 2008-07-30 16:58:59 +0000 | [diff] [blame] | 439 | def BGTZ : CBranchZero<0x07, "bgtz", setgt>; |
| 440 | def BLEZ : CBranchZero<0x07, "blez", setle>; |
| 441 | def BLTZ : CBranchZero<0x01, "bltz", setlt>; |
Bruno Cardoso Lopes | 9710536 | 2007-08-18 02:37:46 +0000 | [diff] [blame] | 442 | } |
| 443 | |
Bruno Cardoso Lopes | 9710536 | 2007-08-18 02:37:46 +0000 | [diff] [blame] | 444 | def BGEZAL : BranchLink<"bgezal">; |
| 445 | def BLTZAL : BranchLink<"bltzal">; |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 446 | |
Bruno Cardoso Lopes | f7d66f7 | 2008-07-30 16:58:59 +0000 | [diff] [blame] | 447 | let isReturn=1, isTerminator=1, hasDelaySlot=1, |
| 448 | isBarrier=1, hasCtrlDep=1, rs=0, rt=0, shamt=0 in |
| 449 | def RET : FR <0x00, 0x02, (outs), (ins CPURegs:$target), |
| 450 | "jr\t$target", [(MipsRet CPURegs:$target)], IIBranch>; |
| 451 | |
Bruno Cardoso Lopes | 9e03061 | 2010-11-09 17:25:34 +0000 | [diff] [blame] | 452 | /// Multiply and Divide Instructions. |
Bruno Cardoso Lopes | 38b5e86 | 2011-03-04 21:03:24 +0000 | [diff] [blame] | 453 | def MULT : Mul<0x18, "mult", IIImul>; |
| 454 | def MULTu : Mul<0x19, "multu", IIImul>; |
| 455 | def SDIV : Div<MipsDivRem, 0x1a, "div", IIIdiv>; |
| 456 | def UDIV : Div<MipsDivRemU, 0x1b, "divu", IIIdiv>; |
Bruno Cardoso Lopes | 91ef849 | 2008-08-02 19:42:36 +0000 | [diff] [blame] | 457 | |
| 458 | let Defs = [HI] in |
| 459 | def MTHI : MoveToLOHI<0x11, "mthi">; |
| 460 | let Defs = [LO] in |
| 461 | def MTLO : MoveToLOHI<0x13, "mtlo">; |
| 462 | |
| 463 | let Uses = [HI] in |
| 464 | def MFHI : MoveFromLOHI<0x10, "mfhi">; |
| 465 | let Uses = [LO] in |
| 466 | def MFLO : MoveFromLOHI<0x12, "mflo">; |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 467 | |
Bruno Cardoso Lopes | f7d66f7 | 2008-07-30 16:58:59 +0000 | [diff] [blame] | 468 | /// Sign Ext In Register Instructions. |
| 469 | let Predicates = [HasSEInReg] in { |
Bruno Cardoso Lopes | d3bdf19 | 2009-05-27 17:23:44 +0000 | [diff] [blame] | 470 | let shamt = 0x10, rs = 0 in |
Bruno Cardoso Lopes | f7d66f7 | 2008-07-30 16:58:59 +0000 | [diff] [blame] | 471 | def SEB : SignExtInReg<0x21, "seb", i8>; |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 472 | |
Bruno Cardoso Lopes | d3bdf19 | 2009-05-27 17:23:44 +0000 | [diff] [blame] | 473 | let shamt = 0x18, rs = 0 in |
Bruno Cardoso Lopes | f7d66f7 | 2008-07-30 16:58:59 +0000 | [diff] [blame] | 474 | def SEH : SignExtInReg<0x20, "seh", i16>; |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 475 | } |
| 476 | |
Bruno Cardoso Lopes | 65ad452 | 2008-08-08 06:16:31 +0000 | [diff] [blame] | 477 | /// Count Leading |
Bruno Cardoso Lopes | c4bb67c | 2010-11-10 02:13:22 +0000 | [diff] [blame] | 478 | def CLZ : CountLeading<0b100000, "clz", |
| 479 | [(set CPURegs:$dst, (ctlz CPURegs:$src))]>; |
| 480 | def CLO : CountLeading<0b100001, "clo", |
| 481 | [(set CPURegs:$dst, (ctlz (not CPURegs:$src)))]>; |
Bruno Cardoso Lopes | 739e441 | 2008-08-13 07:13:40 +0000 | [diff] [blame] | 482 | |
| 483 | /// Byte Swap |
| 484 | let Predicates = [HasSwap] in { |
| 485 | let shamt = 0x3, rs = 0 in |
| 486 | def WSBW : ByteSwap<0x20, "wsbw">; |
| 487 | } |
| 488 | |
| 489 | /// Conditional Move |
| 490 | def MIPS_CMOV_ZERO : PatLeaf<(i32 0)>; |
| 491 | def MIPS_CMOV_NZERO : PatLeaf<(i32 1)>; |
| 492 | |
Akira Hatanaka | 1d6b38d | 2011-03-31 18:26:17 +0000 | [diff] [blame^] | 493 | // Conditional moves: |
| 494 | // These instructions are expanded in MipsISelLowering::EmitInstrWithCustomInserter |
| 495 | // if target does not have conditional move instructions. |
| 496 | // flag:int, data:int |
| 497 | let usesCustomInserter = 1, shamt = 0, Constraints = "$F = $dst" in |
| 498 | class CondMovIntInt<bits<6> funct, string instr_asm> : |
| 499 | FR<0, funct, (outs CPURegs:$dst), |
| 500 | (ins CPURegs:$T, CPURegs:$cond, CPURegs:$F), |
| 501 | !strconcat(instr_asm, "\t$dst, $T, $cond"), [], NoItinerary>; |
| 502 | |
| 503 | def MOVZ_I : CondMovIntInt<0x0a, "movz">; |
| 504 | def MOVN_I : CondMovIntInt<0x0b, "movn">; |
Bruno Cardoso Lopes | 65ad452 | 2008-08-08 06:16:31 +0000 | [diff] [blame] | 505 | |
Bruno Cardoso Lopes | f7d66f7 | 2008-07-30 16:58:59 +0000 | [diff] [blame] | 506 | /// No operation |
| 507 | let addr=0 in |
| 508 | def NOP : FJ<0, (outs), (ins), "nop", [], IIAlu>; |
| 509 | |
Eric Christopher | 3c999a2 | 2007-10-26 04:00:13 +0000 | [diff] [blame] | 510 | // FrameIndexes are legalized when they are operands from load/store |
Bruno Cardoso Lopes | b42abeb | 2007-09-24 20:15:11 +0000 | [diff] [blame] | 511 | // instructions. The same not happens for stack address copies, so an |
| 512 | // add op with mem ComplexPattern is used and the stack address copy |
| 513 | // can be matched. It's similar to Sparc LEA_ADDRi |
Bruno Cardoso Lopes | 43d526d | 2008-07-14 14:42:54 +0000 | [diff] [blame] | 514 | def LEA_ADDiu : EffectiveAddress<"addiu\t$dst, ${addr:stackloc}">; |
Bruno Cardoso Lopes | b42abeb | 2007-09-24 20:15:11 +0000 | [diff] [blame] | 515 | |
Bruno Cardoso Lopes | 8be7611 | 2011-01-18 19:29:17 +0000 | [diff] [blame] | 516 | // MADD*/MSUB* |
| 517 | def MADD : MArithR<0, "madd", MipsMAdd>; |
| 518 | def MADDU : MArithR<1, "maddu", MipsMAddu>; |
| 519 | def MSUB : MArithR<4, "msub", MipsMSub>; |
| 520 | def MSUBU : MArithR<5, "msubu", MipsMSubu>; |
Bruno Cardoso Lopes | 225ca9c | 2008-07-05 19:05:21 +0000 | [diff] [blame] | 521 | |
Bruno Cardoso Lopes | f7d66f7 | 2008-07-30 16:58:59 +0000 | [diff] [blame] | 522 | // MUL is a assembly macro in the current used ISAs. In recent ISA's |
| 523 | // it is a real instruction. |
Bruno Cardoso Lopes | 7d5652d | 2010-11-12 00:38:32 +0000 | [diff] [blame] | 524 | def MUL : ArithR<0x1c, 0x02, "mul", mul, IIImul>, Requires<[IsMips32]>; |
Bruno Cardoso Lopes | 225ca9c | 2008-07-05 19:05:21 +0000 | [diff] [blame] | 525 | |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 526 | //===----------------------------------------------------------------------===// |
| 527 | // Arbitrary patterns that map to one or more instructions |
| 528 | //===----------------------------------------------------------------------===// |
| 529 | |
| 530 | // Small immediates |
Eric Christopher | 3c999a2 | 2007-10-26 04:00:13 +0000 | [diff] [blame] | 531 | def : Pat<(i32 immSExt16:$in), |
Bruno Cardoso Lopes | 332a3d2 | 2007-07-11 22:47:02 +0000 | [diff] [blame] | 532 | (ADDiu ZERO, imm:$in)>; |
Eric Christopher | 3c999a2 | 2007-10-26 04:00:13 +0000 | [diff] [blame] | 533 | def : Pat<(i32 immZExt16:$in), |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 534 | (ORi ZERO, imm:$in)>; |
| 535 | |
| 536 | // Arbitrary immediates |
| 537 | def : Pat<(i32 imm:$imm), |
| 538 | (ORi (LUi (HI16 imm:$imm)), (LO16 imm:$imm))>; |
| 539 | |
Bruno Cardoso Lopes | 07cec75 | 2008-06-06 00:58:26 +0000 | [diff] [blame] | 540 | // Carry patterns |
| 541 | def : Pat<(subc CPURegs:$lhs, CPURegs:$rhs), |
| 542 | (SUBu CPURegs:$lhs, CPURegs:$rhs)>; |
| 543 | def : Pat<(addc CPURegs:$lhs, CPURegs:$rhs), |
| 544 | (ADDu CPURegs:$lhs, CPURegs:$rhs)>; |
Bruno Cardoso Lopes | 911a992 | 2011-03-04 17:59:18 +0000 | [diff] [blame] | 545 | def : Pat<(addc CPURegs:$src, immSExt16:$imm), |
Bruno Cardoso Lopes | 07cec75 | 2008-06-06 00:58:26 +0000 | [diff] [blame] | 546 | (ADDiu CPURegs:$src, imm:$imm)>; |
| 547 | |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 548 | // Call |
| 549 | def : Pat<(MipsJmpLink (i32 tglobaladdr:$dst)), |
| 550 | (JAL tglobaladdr:$dst)>; |
| 551 | def : Pat<(MipsJmpLink (i32 texternalsym:$dst)), |
| 552 | (JAL texternalsym:$dst)>; |
Chris Lattner | e0d2753 | 2010-02-28 07:23:21 +0000 | [diff] [blame] | 553 | //def : Pat<(MipsJmpLink CPURegs:$dst), |
| 554 | // (JALR CPURegs:$dst)>; |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 555 | |
Bruno Cardoso Lopes | 92e87f2 | 2008-07-23 16:01:50 +0000 | [diff] [blame] | 556 | // hi/lo relocs |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 557 | def : Pat<(MipsHi tglobaladdr:$in), (LUi tglobaladdr:$in)>; |
Bruno Cardoso Lopes | c7db561 | 2007-11-05 03:02:32 +0000 | [diff] [blame] | 558 | def : Pat<(add CPURegs:$hi, (MipsLo tglobaladdr:$lo)), |
Bruno Cardoso Lopes | 9710536 | 2007-08-18 02:37:46 +0000 | [diff] [blame] | 559 | (ADDiu CPURegs:$hi, tglobaladdr:$lo)>; |
Bruno Cardoso Lopes | ca8a2aa | 2011-03-04 20:01:52 +0000 | [diff] [blame] | 560 | def : Pat<(add CPURegs:$hi, (MipsLo tblockaddress:$lo)), |
| 561 | (ADDiu CPURegs:$hi, tblockaddress:$lo)>; |
Bruno Cardoso Lopes | 92e87f2 | 2008-07-23 16:01:50 +0000 | [diff] [blame] | 562 | |
Bruno Cardoso Lopes | 753a987 | 2007-11-12 19:49:57 +0000 | [diff] [blame] | 563 | def : Pat<(MipsHi tjumptable:$in), (LUi tjumptable:$in)>; |
Bruno Cardoso Lopes | 753a987 | 2007-11-12 19:49:57 +0000 | [diff] [blame] | 564 | def : Pat<(add CPURegs:$hi, (MipsLo tjumptable:$lo)), |
| 565 | (ADDiu CPURegs:$hi, tjumptable:$lo)>; |
Bruno Cardoso Lopes | 92e87f2 | 2008-07-23 16:01:50 +0000 | [diff] [blame] | 566 | |
| 567 | def : Pat<(MipsHi tconstpool:$in), (LUi tconstpool:$in)>; |
| 568 | def : Pat<(add CPURegs:$hi, (MipsLo tconstpool:$lo)), |
| 569 | (ADDiu CPURegs:$hi, tconstpool:$lo)>; |
| 570 | |
| 571 | // gp_rel relocs |
Bruno Cardoso Lopes | 9e03061 | 2010-11-09 17:25:34 +0000 | [diff] [blame] | 572 | def : Pat<(add CPURegs:$gp, (MipsGPRel tglobaladdr:$in)), |
Bruno Cardoso Lopes | 91fd532 | 2008-07-21 18:52:34 +0000 | [diff] [blame] | 573 | (ADDiu CPURegs:$gp, tglobaladdr:$in)>; |
Bruno Cardoso Lopes | 9e03061 | 2010-11-09 17:25:34 +0000 | [diff] [blame] | 574 | def : Pat<(add CPURegs:$gp, (MipsGPRel tconstpool:$in)), |
Bruno Cardoso Lopes | 92e87f2 | 2008-07-23 16:01:50 +0000 | [diff] [blame] | 575 | (ADDiu CPURegs:$gp, tconstpool:$in)>; |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 576 | |
Bruno Cardoso Lopes | 225ca9c | 2008-07-05 19:05:21 +0000 | [diff] [blame] | 577 | // Mips does not have "not", so we expand our way |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 578 | def : Pat<(not CPURegs:$in), |
Bruno Cardoso Lopes | 9710536 | 2007-08-18 02:37:46 +0000 | [diff] [blame] | 579 | (NOR CPURegs:$in, ZERO)>; |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 580 | |
Eric Christopher | 3c999a2 | 2007-10-26 04:00:13 +0000 | [diff] [blame] | 581 | // extended load and stores |
Bruno Cardoso Lopes | 739e441 | 2008-08-13 07:13:40 +0000 | [diff] [blame] | 582 | def : Pat<(extloadi1 addr:$src), (LBu addr:$src)>; |
| 583 | def : Pat<(extloadi8 addr:$src), (LBu addr:$src)>; |
| 584 | def : Pat<(extloadi16 addr:$src), (LHu addr:$src)>; |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 585 | |
Bruno Cardoso Lopes | 07cec75 | 2008-06-06 00:58:26 +0000 | [diff] [blame] | 586 | // peepholes |
Bruno Cardoso Lopes | c7db561 | 2007-11-05 03:02:32 +0000 | [diff] [blame] | 587 | def : Pat<(store (i32 0), addr:$dst), (SW ZERO, addr:$dst)>; |
| 588 | |
Bruno Cardoso Lopes | 225ca9c | 2008-07-05 19:05:21 +0000 | [diff] [blame] | 589 | // brcond patterns |
Bruno Cardoso Lopes | 9710536 | 2007-08-18 02:37:46 +0000 | [diff] [blame] | 590 | def : Pat<(brcond (setne CPURegs:$lhs, 0), bb:$dst), |
Bruno Cardoso Lopes | 332a3d2 | 2007-07-11 22:47:02 +0000 | [diff] [blame] | 591 | (BNE CPURegs:$lhs, ZERO, bb:$dst)>; |
Bruno Cardoso Lopes | 9710536 | 2007-08-18 02:37:46 +0000 | [diff] [blame] | 592 | def : Pat<(brcond (seteq CPURegs:$lhs, 0), bb:$dst), |
| 593 | (BEQ CPURegs:$lhs, ZERO, bb:$dst)>; |
Bruno Cardoso Lopes | 332a3d2 | 2007-07-11 22:47:02 +0000 | [diff] [blame] | 594 | |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 595 | def : Pat<(brcond (setge CPURegs:$lhs, CPURegs:$rhs), bb:$dst), |
Bruno Cardoso Lopes | 739e441 | 2008-08-13 07:13:40 +0000 | [diff] [blame] | 596 | (BEQ (SLT CPURegs:$lhs, CPURegs:$rhs), ZERO, bb:$dst)>; |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 597 | def : Pat<(brcond (setuge CPURegs:$lhs, CPURegs:$rhs), bb:$dst), |
Bruno Cardoso Lopes | 739e441 | 2008-08-13 07:13:40 +0000 | [diff] [blame] | 598 | (BEQ (SLTu CPURegs:$lhs, CPURegs:$rhs), ZERO, bb:$dst)>; |
| 599 | def : Pat<(brcond (setge CPURegs:$lhs, immSExt16:$rhs), bb:$dst), |
| 600 | (BEQ (SLTi CPURegs:$lhs, immSExt16:$rhs), ZERO, bb:$dst)>; |
| 601 | def : Pat<(brcond (setuge CPURegs:$lhs, immSExt16:$rhs), bb:$dst), |
| 602 | (BEQ (SLTiu CPURegs:$lhs, immSExt16:$rhs), ZERO, bb:$dst)>; |
Bruno Cardoso Lopes | 9710536 | 2007-08-18 02:37:46 +0000 | [diff] [blame] | 603 | |
| 604 | def : Pat<(brcond (setle CPURegs:$lhs, CPURegs:$rhs), bb:$dst), |
Bruno Cardoso Lopes | 739e441 | 2008-08-13 07:13:40 +0000 | [diff] [blame] | 605 | (BEQ (SLT CPURegs:$rhs, CPURegs:$lhs), ZERO, bb:$dst)>; |
Bruno Cardoso Lopes | 9710536 | 2007-08-18 02:37:46 +0000 | [diff] [blame] | 606 | def : Pat<(brcond (setule CPURegs:$lhs, CPURegs:$rhs), bb:$dst), |
Bruno Cardoso Lopes | 739e441 | 2008-08-13 07:13:40 +0000 | [diff] [blame] | 607 | (BEQ (SLTu CPURegs:$rhs, CPURegs:$lhs), ZERO, bb:$dst)>; |
Bruno Cardoso Lopes | 9710536 | 2007-08-18 02:37:46 +0000 | [diff] [blame] | 608 | |
Bruno Cardoso Lopes | 9710536 | 2007-08-18 02:37:46 +0000 | [diff] [blame] | 609 | def : Pat<(brcond CPURegs:$cond, bb:$dst), |
| 610 | (BNE CPURegs:$cond, ZERO, bb:$dst)>; |
| 611 | |
Bruno Cardoso Lopes | 739e441 | 2008-08-13 07:13:40 +0000 | [diff] [blame] | 612 | // select patterns |
Akira Hatanaka | 1d6b38d | 2011-03-31 18:26:17 +0000 | [diff] [blame^] | 613 | multiclass MovzPats<RegisterClass RC, Instruction MOVZInst> { |
| 614 | def : Pat<(select (setge CPURegs:$lhs, CPURegs:$rhs), RC:$T, RC:$F), |
| 615 | (MOVZInst RC:$T, (SLT CPURegs:$lhs, CPURegs:$rhs), RC:$F)>; |
| 616 | def : Pat<(select (setuge CPURegs:$lhs, CPURegs:$rhs), RC:$T, RC:$F), |
| 617 | (MOVZInst RC:$T, (SLTu CPURegs:$lhs, CPURegs:$rhs), RC:$F)>; |
| 618 | def : Pat<(select (setge CPURegs:$lhs, immSExt16:$rhs), RC:$T, RC:$F), |
| 619 | (MOVZInst RC:$T, (SLTi CPURegs:$lhs, immSExt16:$rhs), RC:$F)>; |
| 620 | def : Pat<(select (setuge CPURegs:$lh, immSExt16:$rh), RC:$T, RC:$F), |
| 621 | (MOVZInst RC:$T, (SLTiu CPURegs:$lh, immSExt16:$rh), RC:$F)>; |
| 622 | def : Pat<(select (setle CPURegs:$lhs, CPURegs:$rhs), RC:$T, RC:$F), |
| 623 | (MOVZInst RC:$T, (SLT CPURegs:$rhs, CPURegs:$lhs), RC:$F)>; |
| 624 | def : Pat<(select (setule CPURegs:$lhs, CPURegs:$rhs), RC:$T, RC:$F), |
| 625 | (MOVZInst RC:$T, (SLTu CPURegs:$rhs, CPURegs:$lhs), RC:$F)>; |
| 626 | def : Pat<(select (seteq CPURegs:$lhs, CPURegs:$rhs), RC:$T, RC:$F), |
| 627 | (MOVZInst RC:$T, (XOR CPURegs:$lhs, CPURegs:$rhs), RC:$F)>; |
| 628 | def : Pat<(select (seteq CPURegs:$lhs, 0), RC:$T, RC:$F), |
| 629 | (MOVZInst RC:$T, CPURegs:$lhs, RC:$F)>; |
| 630 | } |
Bruno Cardoso Lopes | 739e441 | 2008-08-13 07:13:40 +0000 | [diff] [blame] | 631 | |
Akira Hatanaka | 1d6b38d | 2011-03-31 18:26:17 +0000 | [diff] [blame^] | 632 | multiclass MovnPats<RegisterClass RC, Instruction MOVNInst> { |
| 633 | def : Pat<(select (setne CPURegs:$lhs, CPURegs:$rhs), RC:$T, RC:$F), |
| 634 | (MOVNInst RC:$T, (XOR CPURegs:$lhs, CPURegs:$rhs), RC:$F)>; |
| 635 | def : Pat<(select CPURegs:$cond, RC:$T, RC:$F), |
| 636 | (MOVNInst RC:$T, CPURegs:$cond, RC:$F)>; |
| 637 | def : Pat<(select (setne CPURegs:$lhs, 0), RC:$T, RC:$F), |
| 638 | (MOVNInst RC:$T, CPURegs:$lhs, RC:$F)>; |
| 639 | } |
Bruno Cardoso Lopes | 739e441 | 2008-08-13 07:13:40 +0000 | [diff] [blame] | 640 | |
Akira Hatanaka | 1d6b38d | 2011-03-31 18:26:17 +0000 | [diff] [blame^] | 641 | defm : MovzPats<CPURegs, MOVZ_I>; |
| 642 | defm : MovnPats<CPURegs, MOVN_I>; |
Bruno Cardoso Lopes | 739e441 | 2008-08-13 07:13:40 +0000 | [diff] [blame] | 643 | |
Bruno Cardoso Lopes | ab8d53a | 2010-12-07 19:00:20 +0000 | [diff] [blame] | 644 | // select patterns with got access |
Akira Hatanaka | 1d6b38d | 2011-03-31 18:26:17 +0000 | [diff] [blame^] | 645 | let AddedComplexity = 10 in |
| 646 | def : Pat<(select (setne CPURegs:$lhs, CPURegs:$rhs), |
| 647 | (i32 tglobaladdr:$T), CPURegs:$F), |
| 648 | (MOVN_I CPURegs:$F, (ADDiu GP, tglobaladdr:$T), |
| 649 | (XOR CPURegs:$lhs, CPURegs:$rhs))>; |
Bruno Cardoso Lopes | ab8d53a | 2010-12-07 19:00:20 +0000 | [diff] [blame] | 650 | |
Bruno Cardoso Lopes | 739e441 | 2008-08-13 07:13:40 +0000 | [diff] [blame] | 651 | // setcc patterns |
| 652 | def : Pat<(seteq CPURegs:$lhs, CPURegs:$rhs), |
| 653 | (SLTu (XOR CPURegs:$lhs, CPURegs:$rhs), 1)>; |
| 654 | def : Pat<(setne CPURegs:$lhs, CPURegs:$rhs), |
| 655 | (SLTu ZERO, (XOR CPURegs:$lhs, CPURegs:$rhs))>; |
| 656 | |
Bruno Cardoso Lopes | 9710536 | 2007-08-18 02:37:46 +0000 | [diff] [blame] | 657 | def : Pat<(setle CPURegs:$lhs, CPURegs:$rhs), |
| 658 | (XORi (SLT CPURegs:$rhs, CPURegs:$lhs), 1)>; |
| 659 | def : Pat<(setule CPURegs:$lhs, CPURegs:$rhs), |
| 660 | (XORi (SLTu CPURegs:$rhs, CPURegs:$lhs), 1)>; |
| 661 | |
| 662 | def : Pat<(setgt CPURegs:$lhs, CPURegs:$rhs), |
| 663 | (SLT CPURegs:$rhs, CPURegs:$lhs)>; |
| 664 | def : Pat<(setugt CPURegs:$lhs, CPURegs:$rhs), |
| 665 | (SLTu CPURegs:$rhs, CPURegs:$lhs)>; |
| 666 | |
| 667 | def : Pat<(setge CPURegs:$lhs, CPURegs:$rhs), |
| 668 | (XORi (SLT CPURegs:$lhs, CPURegs:$rhs), 1)>; |
| 669 | def : Pat<(setuge CPURegs:$lhs, CPURegs:$rhs), |
| 670 | (XORi (SLTu CPURegs:$lhs, CPURegs:$rhs), 1)>; |
| 671 | |
Bruno Cardoso Lopes | 9710536 | 2007-08-18 02:37:46 +0000 | [diff] [blame] | 672 | def : Pat<(setge CPURegs:$lhs, immSExt16:$rhs), |
| 673 | (XORi (SLTi CPURegs:$lhs, immSExt16:$rhs), 1)>; |
Bruno Cardoso Lopes | 739e441 | 2008-08-13 07:13:40 +0000 | [diff] [blame] | 674 | def : Pat<(setuge CPURegs:$lhs, immSExt16:$rhs), |
| 675 | (XORi (SLTiu CPURegs:$lhs, immSExt16:$rhs), 1)>; |
Bruno Cardoso Lopes | 225ca9c | 2008-07-05 19:05:21 +0000 | [diff] [blame] | 676 | |
| 677 | //===----------------------------------------------------------------------===// |
| 678 | // Floating Point Support |
| 679 | //===----------------------------------------------------------------------===// |
| 680 | |
| 681 | include "MipsInstrFPU.td" |
| 682 | |