Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1 | //===- MipsInstrInfo.td - Mips Register defs --------------------*- C++ -*-===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | 081ce94 | 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. |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +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 | |
| 20 | // Call |
| 21 | def SDT_MipsJmpLink : SDTypeProfile<0, 1, [SDTCisVT<0, iPTR>]>; |
| 22 | def MipsJmpLink : SDNode<"MipsISD::JmpLink",SDT_MipsJmpLink, [SDNPHasChain, |
| 23 | SDNPOutFlag]>; |
| 24 | |
Bruno Cardoso Lopes | 218d582 | 2007-11-05 03:02:32 +0000 | [diff] [blame] | 25 | // Hi and Lo nodes are used to handle global addresses. Used on |
| 26 | // MipsISelLowering to lower stuff like GlobalAddress, ExternalSymbol |
| 27 | // static model. (nothing to do with Mips Registers Hi and Lo) |
| 28 | def MipsHi : SDNode<"MipsISD::Hi", SDTIntUnaryOp, [SDNPOutFlag]>; |
| 29 | def MipsLo : SDNode<"MipsISD::Lo", SDTIntUnaryOp>; |
Bruno Cardoso Lopes | 2cacce9 | 2007-10-09 02:55:31 +0000 | [diff] [blame] | 30 | |
Eric Christopher | 7300ac1 | 2007-10-26 04:00:13 +0000 | [diff] [blame] | 31 | // Return |
| 32 | def SDT_MipsRet : SDTypeProfile<0, 1, [SDTCisInt<0>]>; |
| 33 | def MipsRet : SDNode<"MipsISD::Ret", SDT_MipsRet, [SDNPHasChain, |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 34 | SDNPOptInFlag]>; |
| 35 | |
| 36 | // These are target-independent nodes, but have target-specific formats. |
Bill Wendling | 7173da5 | 2007-11-13 09:19:02 +0000 | [diff] [blame] | 37 | def SDT_MipsCallSeqStart : SDCallSeqStart<[SDTCisVT<0, i32>]>; |
| 38 | def SDT_MipsCallSeqEnd : SDCallSeqEnd<[SDTCisVT<0, i32>, |
| 39 | SDTCisVT<1, i32>]>; |
Bill Wendling | 22f8deb | 2007-11-13 00:44:25 +0000 | [diff] [blame] | 40 | |
Bill Wendling | 7173da5 | 2007-11-13 09:19:02 +0000 | [diff] [blame] | 41 | def callseq_start : SDNode<"ISD::CALLSEQ_START", SDT_MipsCallSeqStart, |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 42 | [SDNPHasChain, SDNPOutFlag]>; |
Bill Wendling | 7173da5 | 2007-11-13 09:19:02 +0000 | [diff] [blame] | 43 | def callseq_end : SDNode<"ISD::CALLSEQ_END", SDT_MipsCallSeqEnd, |
Bill Wendling | 22f8deb | 2007-11-13 00:44:25 +0000 | [diff] [blame] | 44 | [SDNPHasChain, SDNPOptInFlag, SDNPOutFlag]>; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 45 | |
Bruno Cardoso Lopes | ed7723d | 2008-06-06 00:58:26 +0000 | [diff] [blame] | 46 | // Select CC |
| 47 | def SDT_MipsSelectCC : SDTypeProfile<1, 3, [SDTCisSameAs<0, 1>, |
| 48 | SDTCisSameAs<1, 2>, SDTCisInt<3>]>; |
| 49 | def MipsSelectCC : SDNode<"MipsISD::SelectCC", SDT_MipsSelectCC>; |
| 50 | |
Bruno Cardoso Lopes | 2cacce9 | 2007-10-09 02:55:31 +0000 | [diff] [blame] | 51 | //===----------------------------------------------------------------------===// |
| 52 | // Mips Instruction Predicate Definitions. |
| 53 | //===----------------------------------------------------------------------===// |
| 54 | def IsStatic : Predicate<"TM.getRelocationModel() == Reloc::Static">; |
| 55 | |
| 56 | //===----------------------------------------------------------------------===// |
| 57 | // Mips Operand, Complex Patterns and Transformations Definitions. |
| 58 | //===----------------------------------------------------------------------===// |
| 59 | |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 60 | // Instruction operand types |
| 61 | def brtarget : Operand<OtherVT>; |
| 62 | def calltarget : Operand<i32>; |
| 63 | def uimm16 : Operand<i32>; |
| 64 | def simm16 : Operand<i32>; |
Eric Christopher | 7300ac1 | 2007-10-26 04:00:13 +0000 | [diff] [blame] | 65 | def shamt : Operand<i32>; |
Bruno Cardoso Lopes | 2cacce9 | 2007-10-09 02:55:31 +0000 | [diff] [blame] | 66 | def addrlabel : Operand<i32>; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 67 | |
| 68 | // Address operand |
| 69 | def mem : Operand<i32> { |
| 70 | let PrintMethod = "printMemOperand"; |
| 71 | let MIOperandInfo = (ops simm16, CPURegs); |
| 72 | } |
| 73 | |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 74 | // Transformation Function - get the lower 16 bits. |
| 75 | def LO16 : SDNodeXForm<imm, [{ |
| 76 | return getI32Imm((unsigned)N->getValue() & 0xFFFF); |
| 77 | }]>; |
| 78 | |
| 79 | // Transformation Function - get the higher 16 bits. |
| 80 | def HI16 : SDNodeXForm<imm, [{ |
| 81 | return getI32Imm((unsigned)N->getValue() >> 16); |
| 82 | }]>; |
| 83 | |
| 84 | // Node immediate fits as 16-bit sign extended on target immediate. |
| 85 | // e.g. addi, andi |
| 86 | def immSExt16 : PatLeaf<(imm), [{ |
| 87 | if (N->getValueType(0) == MVT::i32) |
| 88 | return (int32_t)N->getValue() == (short)N->getValue(); |
Eric Christopher | 7300ac1 | 2007-10-26 04:00:13 +0000 | [diff] [blame] | 89 | else |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 90 | return (int64_t)N->getValue() == (short)N->getValue(); |
| 91 | }]>; |
| 92 | |
| 93 | // Node immediate fits as 16-bit zero extended on target immediate. |
| 94 | // The LO16 param means that only the lower 16 bits of the node |
| 95 | // immediate are caught. |
| 96 | // e.g. addiu, sltiu |
| 97 | def immZExt16 : PatLeaf<(imm), [{ |
| 98 | if (N->getValueType(0) == MVT::i32) |
| 99 | return (uint32_t)N->getValue() == (unsigned short)N->getValue(); |
Eric Christopher | 7300ac1 | 2007-10-26 04:00:13 +0000 | [diff] [blame] | 100 | else |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 101 | return (uint64_t)N->getValue() == (unsigned short)N->getValue(); |
| 102 | }], LO16>; |
| 103 | |
Bruno Cardoso Lopes | 3419055 | 2007-08-18 02:37:46 +0000 | [diff] [blame] | 104 | // Node immediate fits as 32-bit zero extended on target immediate. |
| 105 | //def immZExt32 : PatLeaf<(imm), [{ |
| 106 | // return (uint64_t)N->getValue() == (uint32_t)N->getValue(); |
| 107 | //}], LO16>; |
| 108 | |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 109 | // shamt field must fit in 5 bits. |
| 110 | def immZExt5 : PatLeaf<(imm), [{ |
| 111 | return N->getValue() == ((N->getValue()) & 0x1f) ; |
| 112 | }]>; |
| 113 | |
Eric Christopher | 7300ac1 | 2007-10-26 04:00:13 +0000 | [diff] [blame] | 114 | // Mips Address Mode! SDNode frameindex could possibily be a match |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 115 | // since load and store instructions from stack used it. |
| 116 | def addr : ComplexPattern<i32, 2, "SelectAddr", [frameindex], []>; |
| 117 | |
| 118 | //===----------------------------------------------------------------------===// |
| 119 | // Instructions specific format |
| 120 | //===----------------------------------------------------------------------===// |
| 121 | |
| 122 | // Arithmetic 3 register operands |
Eric Christopher | 7300ac1 | 2007-10-26 04:00:13 +0000 | [diff] [blame] | 123 | let isCommutable = 1 in |
Bruno Cardoso Lopes | 3419055 | 2007-08-18 02:37:46 +0000 | [diff] [blame] | 124 | class ArithR<bits<6> op, bits<6> func, string instr_asm, SDNode OpNode, |
Eric Christopher | 7300ac1 | 2007-10-26 04:00:13 +0000 | [diff] [blame] | 125 | InstrItinClass itin>: |
| 126 | FR< op, |
| 127 | func, |
| 128 | (outs CPURegs:$dst), |
| 129 | (ins CPURegs:$b, CPURegs:$c), |
| 130 | !strconcat(instr_asm, " $dst, $b, $c"), |
Bruno Cardoso Lopes | 3419055 | 2007-08-18 02:37:46 +0000 | [diff] [blame] | 131 | [(set CPURegs:$dst, (OpNode CPURegs:$b, CPURegs:$c))], itin>; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 132 | |
Eric Christopher | 7300ac1 | 2007-10-26 04:00:13 +0000 | [diff] [blame] | 133 | let isCommutable = 1 in |
| 134 | class ArithOverflowR<bits<6> op, bits<6> func, string instr_asm>: |
| 135 | FR< op, |
| 136 | func, |
| 137 | (outs CPURegs:$dst), |
| 138 | (ins CPURegs:$b, CPURegs:$c), |
| 139 | !strconcat(instr_asm, " $dst, $b, $c"), |
Bruno Cardoso Lopes | 3419055 | 2007-08-18 02:37:46 +0000 | [diff] [blame] | 140 | [], IIAlu>; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 141 | |
| 142 | // Arithmetic 2 register operands |
Eric Christopher | 7300ac1 | 2007-10-26 04:00:13 +0000 | [diff] [blame] | 143 | class ArithI<bits<6> op, string instr_asm, SDNode OpNode, |
| 144 | Operand Od, PatLeaf imm_type> : |
| 145 | FI< op, |
| 146 | (outs CPURegs:$dst), |
| 147 | (ins CPURegs:$b, Od:$c), |
| 148 | !strconcat(instr_asm, " $dst, $b, $c"), |
Bruno Cardoso Lopes | 3419055 | 2007-08-18 02:37:46 +0000 | [diff] [blame] | 149 | [(set CPURegs:$dst, (OpNode CPURegs:$b, imm_type:$c))], IIAlu>; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 150 | |
| 151 | // Arithmetic Multiply ADD/SUB |
| 152 | let rd=0 in |
Eric Christopher | 7300ac1 | 2007-10-26 04:00:13 +0000 | [diff] [blame] | 153 | class MArithR<bits<6> func, string instr_asm> : |
| 154 | FR< 0x1c, |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 155 | func, |
Eric Christopher | 7300ac1 | 2007-10-26 04:00:13 +0000 | [diff] [blame] | 156 | (outs CPURegs:$rs), |
| 157 | (ins CPURegs:$rt), |
| 158 | !strconcat(instr_asm, " $rs, $rt"), |
Bruno Cardoso Lopes | 3419055 | 2007-08-18 02:37:46 +0000 | [diff] [blame] | 159 | [], IIImul>; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 160 | |
| 161 | // Logical |
| 162 | class LogicR<bits<6> func, string instr_asm, SDNode OpNode>: |
Eric Christopher | 7300ac1 | 2007-10-26 04:00:13 +0000 | [diff] [blame] | 163 | FR< 0x00, |
| 164 | func, |
| 165 | (outs CPURegs:$dst), |
| 166 | (ins CPURegs:$b, CPURegs:$c), |
| 167 | !strconcat(instr_asm, " $dst, $b, $c"), |
Bruno Cardoso Lopes | 3419055 | 2007-08-18 02:37:46 +0000 | [diff] [blame] | 168 | [(set CPURegs:$dst, (OpNode CPURegs:$b, CPURegs:$c))], IIAlu>; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 169 | |
| 170 | class LogicI<bits<6> op, string instr_asm, SDNode OpNode>: |
| 171 | FI< op, |
Evan Cheng | b783fa3 | 2007-07-19 01:14:50 +0000 | [diff] [blame] | 172 | (outs CPURegs:$dst), |
| 173 | (ins CPURegs:$b, uimm16:$c), |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 174 | !strconcat(instr_asm, " $dst, $b, $c"), |
Bruno Cardoso Lopes | f237755 | 2008-06-06 06:37:31 +0000 | [diff] [blame] | 175 | [(set CPURegs:$dst, (OpNode CPURegs:$b, immZExt16:$c))], IIAlu>; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 176 | |
| 177 | class LogicNOR<bits<6> op, bits<6> func, string instr_asm>: |
Eric Christopher | 7300ac1 | 2007-10-26 04:00:13 +0000 | [diff] [blame] | 178 | FR< op, |
| 179 | func, |
| 180 | (outs CPURegs:$dst), |
| 181 | (ins CPURegs:$b, CPURegs:$c), |
| 182 | !strconcat(instr_asm, " $dst, $b, $c"), |
Bruno Cardoso Lopes | 3419055 | 2007-08-18 02:37:46 +0000 | [diff] [blame] | 183 | [(set CPURegs:$dst, (not (or CPURegs:$b, CPURegs:$c)))], IIAlu>; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 184 | |
| 185 | // Shifts |
| 186 | let rt = 0 in |
| 187 | class LogicR_shift_imm<bits<6> func, string instr_asm, SDNode OpNode>: |
Eric Christopher | 7300ac1 | 2007-10-26 04:00:13 +0000 | [diff] [blame] | 188 | FR< 0x00, |
| 189 | func, |
Evan Cheng | b783fa3 | 2007-07-19 01:14:50 +0000 | [diff] [blame] | 190 | (outs CPURegs:$dst), |
| 191 | (ins CPURegs:$b, shamt:$c), |
Eric Christopher | 7300ac1 | 2007-10-26 04:00:13 +0000 | [diff] [blame] | 192 | !strconcat(instr_asm, " $dst, $b, $c"), |
Bruno Cardoso Lopes | 3419055 | 2007-08-18 02:37:46 +0000 | [diff] [blame] | 193 | [(set CPURegs:$dst, (OpNode CPURegs:$b, immZExt5:$c))], IIAlu>; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 194 | |
| 195 | class LogicR_shift_reg<bits<6> func, string instr_asm, SDNode OpNode>: |
Eric Christopher | 7300ac1 | 2007-10-26 04:00:13 +0000 | [diff] [blame] | 196 | FR< 0x00, |
| 197 | func, |
Evan Cheng | b783fa3 | 2007-07-19 01:14:50 +0000 | [diff] [blame] | 198 | (outs CPURegs:$dst), |
| 199 | (ins CPURegs:$b, CPURegs:$c), |
Eric Christopher | 7300ac1 | 2007-10-26 04:00:13 +0000 | [diff] [blame] | 200 | !strconcat(instr_asm, " $dst, $b, $c"), |
Bruno Cardoso Lopes | 3419055 | 2007-08-18 02:37:46 +0000 | [diff] [blame] | 201 | [(set CPURegs:$dst, (OpNode CPURegs:$b, CPURegs:$c))], IIAlu>; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 202 | |
| 203 | // Load Upper Imediate |
| 204 | class LoadUpper<bits<6> op, string instr_asm>: |
| 205 | FI< op, |
Evan Cheng | b783fa3 | 2007-07-19 01:14:50 +0000 | [diff] [blame] | 206 | (outs CPURegs:$dst), |
| 207 | (ins uimm16:$imm), |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 208 | !strconcat(instr_asm, " $dst, $imm"), |
Bruno Cardoso Lopes | 3419055 | 2007-08-18 02:37:46 +0000 | [diff] [blame] | 209 | [], IIAlu>; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 210 | |
Eric Christopher | 7300ac1 | 2007-10-26 04:00:13 +0000 | [diff] [blame] | 211 | // Memory Load/Store |
Chris Lattner | 1a1932c | 2008-01-06 23:38:27 +0000 | [diff] [blame] | 212 | let isSimpleLoad = 1, hasDelaySlot = 1 in |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 213 | class LoadM<bits<6> op, string instr_asm, PatFrag OpNode>: |
| 214 | FI< op, |
Evan Cheng | b783fa3 | 2007-07-19 01:14:50 +0000 | [diff] [blame] | 215 | (outs CPURegs:$dst), |
| 216 | (ins mem:$addr), |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 217 | !strconcat(instr_asm, " $dst, $addr"), |
Bruno Cardoso Lopes | 3419055 | 2007-08-18 02:37:46 +0000 | [diff] [blame] | 218 | [(set CPURegs:$dst, (OpNode addr:$addr))], IILoad>; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 219 | |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 220 | class StoreM<bits<6> op, string instr_asm, PatFrag OpNode>: |
| 221 | FI< op, |
Evan Cheng | b783fa3 | 2007-07-19 01:14:50 +0000 | [diff] [blame] | 222 | (outs), |
| 223 | (ins CPURegs:$dst, mem:$addr), |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 224 | !strconcat(instr_asm, " $dst, $addr"), |
Bruno Cardoso Lopes | 3419055 | 2007-08-18 02:37:46 +0000 | [diff] [blame] | 225 | [(OpNode CPURegs:$dst, addr:$addr)], IIStore>; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 226 | |
| 227 | // Conditional Branch |
Bruno Cardoso Lopes | 3419055 | 2007-08-18 02:37:46 +0000 | [diff] [blame] | 228 | let isBranch = 1, isTerminator=1, hasDelaySlot = 1 in { |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 229 | class CBranch<bits<6> op, string instr_asm, PatFrag cond_op>: |
| 230 | FI< op, |
Evan Cheng | b783fa3 | 2007-07-19 01:14:50 +0000 | [diff] [blame] | 231 | (outs), |
| 232 | (ins CPURegs:$a, CPURegs:$b, brtarget:$offset), |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 233 | !strconcat(instr_asm, " $a, $b, $offset"), |
Bruno Cardoso Lopes | 3419055 | 2007-08-18 02:37:46 +0000 | [diff] [blame] | 234 | [(brcond (cond_op CPURegs:$a, CPURegs:$b), bb:$offset)], |
| 235 | IIBranch>; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 236 | |
Bruno Cardoso Lopes | 3419055 | 2007-08-18 02:37:46 +0000 | [diff] [blame] | 237 | |
| 238 | class CBranchZero<bits<6> op, string instr_asm, PatFrag cond_op>: |
| 239 | FI< op, |
| 240 | (outs), |
| 241 | (ins CPURegs:$src, brtarget:$offset), |
| 242 | !strconcat(instr_asm, " $src, $offset"), |
| 243 | [(brcond (cond_op CPURegs:$src, 0), bb:$offset)], |
| 244 | IIBranch>; |
Eric Christopher | 7300ac1 | 2007-10-26 04:00:13 +0000 | [diff] [blame] | 245 | } |
Bruno Cardoso Lopes | 3419055 | 2007-08-18 02:37:46 +0000 | [diff] [blame] | 246 | |
Eric Christopher | 7300ac1 | 2007-10-26 04:00:13 +0000 | [diff] [blame] | 247 | // SetCC |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 248 | class SetCC_R<bits<6> op, bits<6> func, string instr_asm, |
| 249 | PatFrag cond_op>: |
| 250 | FR< op, |
| 251 | func, |
Evan Cheng | b783fa3 | 2007-07-19 01:14:50 +0000 | [diff] [blame] | 252 | (outs CPURegs:$dst), |
| 253 | (ins CPURegs:$b, CPURegs:$c), |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 254 | !strconcat(instr_asm, " $dst, $b, $c"), |
Bruno Cardoso Lopes | 3419055 | 2007-08-18 02:37:46 +0000 | [diff] [blame] | 255 | [(set CPURegs:$dst, (cond_op CPURegs:$b, CPURegs:$c))], |
| 256 | IIAlu>; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 257 | |
| 258 | class SetCC_I<bits<6> op, string instr_asm, PatFrag cond_op, |
| 259 | Operand Od, PatLeaf imm_type>: |
| 260 | FI< op, |
Evan Cheng | b783fa3 | 2007-07-19 01:14:50 +0000 | [diff] [blame] | 261 | (outs CPURegs:$dst), |
| 262 | (ins CPURegs:$b, Od:$c), |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 263 | !strconcat(instr_asm, " $dst, $b, $c"), |
Bruno Cardoso Lopes | 3419055 | 2007-08-18 02:37:46 +0000 | [diff] [blame] | 264 | [(set CPURegs:$dst, (cond_op CPURegs:$b, imm_type:$c))], |
| 265 | IIAlu>; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 266 | |
| 267 | // Unconditional branch |
Bruno Cardoso Lopes | 3419055 | 2007-08-18 02:37:46 +0000 | [diff] [blame] | 268 | let isBranch=1, isTerminator=1, isBarrier=1, hasDelaySlot = 1 in |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 269 | class JumpFJ<bits<6> op, string instr_asm>: |
| 270 | FJ< op, |
Evan Cheng | b783fa3 | 2007-07-19 01:14:50 +0000 | [diff] [blame] | 271 | (outs), |
| 272 | (ins brtarget:$target), |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 273 | !strconcat(instr_asm, " $target"), |
Bruno Cardoso Lopes | 3419055 | 2007-08-18 02:37:46 +0000 | [diff] [blame] | 274 | [(br bb:$target)], IIBranch>; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 275 | |
Bruno Cardoso Lopes | 3419055 | 2007-08-18 02:37:46 +0000 | [diff] [blame] | 276 | let isBranch=1, isTerminator=1, isBarrier=1, rd=0, hasDelaySlot = 1 in |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 277 | class JumpFR<bits<6> op, bits<6> func, string instr_asm>: |
| 278 | FR< op, |
| 279 | func, |
Evan Cheng | b783fa3 | 2007-07-19 01:14:50 +0000 | [diff] [blame] | 280 | (outs), |
| 281 | (ins CPURegs:$target), |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 282 | !strconcat(instr_asm, " $target"), |
Bruno Cardoso Lopes | ea37730 | 2007-11-12 19:49:57 +0000 | [diff] [blame] | 283 | [(brind CPURegs:$target)], IIBranch>; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 284 | |
| 285 | // Jump and Link (Call) |
Eric Christopher | 7300ac1 | 2007-10-26 04:00:13 +0000 | [diff] [blame] | 286 | let isCall=1, hasDelaySlot=1, |
Bruno Cardoso Lopes | 3419055 | 2007-08-18 02:37:46 +0000 | [diff] [blame] | 287 | // All calls clobber the non-callee saved registers... |
Eric Christopher | 7300ac1 | 2007-10-26 04:00:13 +0000 | [diff] [blame] | 288 | Defs = [AT, V0, V1, A0, A1, A2, A3, T0, T1, T2, |
Bruno Cardoso Lopes | ea37730 | 2007-11-12 19:49:57 +0000 | [diff] [blame] | 289 | T3, T4, T5, T6, T7, T8, T9, K0, K1], Uses = [GP] in { |
Eric Christopher | 7300ac1 | 2007-10-26 04:00:13 +0000 | [diff] [blame] | 290 | class JumpLink<bits<6> op, string instr_asm>: |
Bruno Cardoso Lopes | 3419055 | 2007-08-18 02:37:46 +0000 | [diff] [blame] | 291 | FJ< op, |
| 292 | (outs), |
| 293 | (ins calltarget:$target), |
| 294 | !strconcat(instr_asm, " $target"), |
| 295 | [(MipsJmpLink imm:$target)], IIBranch>; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 296 | |
Bruno Cardoso Lopes | 3419055 | 2007-08-18 02:37:46 +0000 | [diff] [blame] | 297 | let rd=31 in |
| 298 | class JumpLinkReg<bits<6> op, bits<6> func, string instr_asm>: |
| 299 | FR< op, |
| 300 | func, |
| 301 | (outs), |
| 302 | (ins CPURegs:$rs), |
| 303 | !strconcat(instr_asm, " $rs"), |
| 304 | [(MipsJmpLink CPURegs:$rs)], IIBranch>; |
| 305 | |
| 306 | class BranchLink<string instr_asm>: |
| 307 | FI< 0x1, |
| 308 | (outs), |
| 309 | (ins CPURegs:$rs, brtarget:$target), |
| 310 | !strconcat(instr_asm, " $rs, $target"), |
| 311 | [], IIBranch>; |
| 312 | } |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 313 | |
Eric Christopher | 7300ac1 | 2007-10-26 04:00:13 +0000 | [diff] [blame] | 314 | // Mul, Div |
| 315 | class MulDiv<bits<6> func, string instr_asm, InstrItinClass itin>: |
| 316 | FR< 0x00, |
| 317 | func, |
Evan Cheng | b783fa3 | 2007-07-19 01:14:50 +0000 | [diff] [blame] | 318 | (outs), |
Eric Christopher | 7300ac1 | 2007-10-26 04:00:13 +0000 | [diff] [blame] | 319 | (ins CPURegs:$a, CPURegs:$b), |
| 320 | !strconcat(instr_asm, " $a, $b"), |
Bruno Cardoso Lopes | 3419055 | 2007-08-18 02:37:46 +0000 | [diff] [blame] | 321 | [], itin>; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 322 | |
Eric Christopher | 7300ac1 | 2007-10-26 04:00:13 +0000 | [diff] [blame] | 323 | // Move from Hi/Lo |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 324 | class MoveFromTo<bits<6> func, string instr_asm>: |
Eric Christopher | 7300ac1 | 2007-10-26 04:00:13 +0000 | [diff] [blame] | 325 | FR< 0x00, |
| 326 | func, |
| 327 | (outs CPURegs:$dst), |
Evan Cheng | b783fa3 | 2007-07-19 01:14:50 +0000 | [diff] [blame] | 328 | (ins), |
Eric Christopher | 7300ac1 | 2007-10-26 04:00:13 +0000 | [diff] [blame] | 329 | !strconcat(instr_asm, " $dst"), |
Bruno Cardoso Lopes | 3419055 | 2007-08-18 02:37:46 +0000 | [diff] [blame] | 330 | [], IIHiLo>; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 331 | |
| 332 | // Count Leading Ones/Zeros in Word |
| 333 | class CountLeading<bits<6> func, string instr_asm>: |
Eric Christopher | 7300ac1 | 2007-10-26 04:00:13 +0000 | [diff] [blame] | 334 | FR< 0x1c, |
| 335 | func, |
| 336 | (outs CPURegs:$dst), |
| 337 | (ins CPURegs:$src), |
| 338 | !strconcat(instr_asm, " $dst, $src"), |
Bruno Cardoso Lopes | 3419055 | 2007-08-18 02:37:46 +0000 | [diff] [blame] | 339 | [], IIAlu>; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 340 | |
Eric Christopher | 7300ac1 | 2007-10-26 04:00:13 +0000 | [diff] [blame] | 341 | class EffectiveAddress<string instr_asm> : |
| 342 | FI<0x09, |
| 343 | (outs CPURegs:$dst), |
Bruno Cardoso Lopes | 9643366 | 2007-09-24 20:15:11 +0000 | [diff] [blame] | 344 | (ins mem:$addr), |
| 345 | instr_asm, |
| 346 | [(set CPURegs:$dst, addr:$addr)], IIAlu>; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 347 | |
| 348 | //===----------------------------------------------------------------------===// |
| 349 | // Pseudo instructions |
| 350 | //===----------------------------------------------------------------------===// |
| 351 | |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 352 | // As stack alignment is always done with addiu, we need a 16-bit immediate |
Evan Cheng | 6e4d1d9 | 2007-09-11 19:55:27 +0000 | [diff] [blame] | 353 | let Defs = [SP], Uses = [SP] in { |
Bruno Cardoso Lopes | ed7723d | 2008-06-06 00:58:26 +0000 | [diff] [blame] | 354 | def ADJCALLSTACKDOWN : MipsPseudo<(outs), (ins uimm16:$amt), |
Bruno Cardoso Lopes | 2cacce9 | 2007-10-09 02:55:31 +0000 | [diff] [blame] | 355 | "!ADJCALLSTACKDOWN $amt", |
| 356 | [(callseq_start imm:$amt)]>; |
Bruno Cardoso Lopes | ed7723d | 2008-06-06 00:58:26 +0000 | [diff] [blame] | 357 | def ADJCALLSTACKUP : MipsPseudo<(outs), (ins uimm16:$amt1, uimm16:$amt2), |
Bill Wendling | 22f8deb | 2007-11-13 00:44:25 +0000 | [diff] [blame] | 358 | "!ADJCALLSTACKUP $amt1", |
| 359 | [(callseq_end imm:$amt1, imm:$amt2)]>; |
Evan Cheng | 6e4d1d9 | 2007-09-11 19:55:27 +0000 | [diff] [blame] | 360 | } |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 361 | |
Eric Christopher | 7300ac1 | 2007-10-26 04:00:13 +0000 | [diff] [blame] | 362 | // When handling PIC code the assembler needs .cpload and .cprestore |
| 363 | // directives. If the real instructions corresponding these directives |
| 364 | // are used, we have the same behavior, but get also a bunch of warnings |
Bruno Cardoso Lopes | 2cacce9 | 2007-10-09 02:55:31 +0000 | [diff] [blame] | 365 | // from the assembler. |
Bruno Cardoso Lopes | ed7723d | 2008-06-06 00:58:26 +0000 | [diff] [blame] | 366 | def CPLOAD : MipsPseudo<(outs), (ins CPURegs:$reg), |
| 367 | ".set noreorder\n\t.cpload $reg\n\t.set reorder\n", |
| 368 | []>; |
| 369 | def CPRESTORE : MipsPseudo<(outs), (ins uimm16:$loc), |
| 370 | ".cprestore $loc\n", []>; |
| 371 | |
| 372 | // The supported Mips ISAs dont have any instruction close to the SELECT_CC |
| 373 | // operation. The solution is to create a Mips pseudo SELECT_CC instruction |
| 374 | // (MipsSelectCC), use LowerSELECT_CC to generate this instruction and finally |
| 375 | // replace it for real supported nodes into EmitInstrWithCustomInserter |
| 376 | let usesCustomDAGSchedInserter = 1 in { |
| 377 | def Select_CC : MipsPseudo<(outs CPURegs:$dst), |
| 378 | (ins CPURegs:$CmpRes, CPURegs:$T, CPURegs:$F), "# MipsSelect_CC", |
| 379 | [(set CPURegs:$dst, (MipsSelectCC CPURegs:$CmpRes, |
| 380 | CPURegs:$T, CPURegs:$F))]>; |
| 381 | } |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 382 | |
| 383 | //===----------------------------------------------------------------------===// |
| 384 | // Instruction definition |
| 385 | //===----------------------------------------------------------------------===// |
| 386 | |
| 387 | //===----------------------------------------------------------------------===// |
Bruno Cardoso Lopes | 3419055 | 2007-08-18 02:37:46 +0000 | [diff] [blame] | 388 | // MipsI Instructions |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 389 | //===----------------------------------------------------------------------===// |
| 390 | |
| 391 | // Arithmetic |
Bruno Cardoso Lopes | 3419055 | 2007-08-18 02:37:46 +0000 | [diff] [blame] | 392 | |
| 393 | // ADDiu just accept 16-bit immediates but we handle this on Pat's. |
| 394 | // immZExt32 is used here so it can match GlobalAddress immediates. |
Bruno Cardoso Lopes | f237755 | 2008-06-06 06:37:31 +0000 | [diff] [blame] | 395 | // MUL is a assembly macro in the current used ISAs. |
Bruno Cardoso Lopes | 218d582 | 2007-11-05 03:02:32 +0000 | [diff] [blame] | 396 | def ADDiu : ArithI<0x09, "addiu", add, uimm16, immZExt16>; |
Bruno Cardoso Lopes | 3419055 | 2007-08-18 02:37:46 +0000 | [diff] [blame] | 397 | def ADDi : ArithI<0x08, "addi", add, simm16, immSExt16>; |
Bruno Cardoso Lopes | f237755 | 2008-06-06 06:37:31 +0000 | [diff] [blame] | 398 | //def MUL : ArithR<0x1c, 0x02, "mul", mul, IIImul>; |
Bruno Cardoso Lopes | 3419055 | 2007-08-18 02:37:46 +0000 | [diff] [blame] | 399 | def ADDu : ArithR<0x00, 0x21, "addu", add, IIAlu>; |
| 400 | def SUBu : ArithR<0x00, 0x23, "subu", sub, IIAlu>; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 401 | def ADD : ArithOverflowR<0x00, 0x20, "add">; |
| 402 | def SUB : ArithOverflowR<0x00, 0x22, "sub">; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 403 | |
| 404 | // Logical |
| 405 | def AND : LogicR<0x24, "and", and>; |
| 406 | def OR : LogicR<0x25, "or", or>; |
| 407 | def XOR : LogicR<0x26, "xor", xor>; |
| 408 | def ANDi : LogicI<0x0c, "andi", and>; |
| 409 | def ORi : LogicI<0x0d, "ori", or>; |
| 410 | def XORi : LogicI<0x0e, "xori", xor>; |
| 411 | def NOR : LogicNOR<0x00, 0x27, "nor">; |
| 412 | |
Eric Christopher | 7300ac1 | 2007-10-26 04:00:13 +0000 | [diff] [blame] | 413 | // Shifts |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 414 | def SLL : LogicR_shift_imm<0x00, "sll", shl>; |
| 415 | def SRL : LogicR_shift_imm<0x02, "srl", srl>; |
| 416 | def SRA : LogicR_shift_imm<0x03, "sra", sra>; |
| 417 | def SLLV : LogicR_shift_reg<0x04, "sllv", shl>; |
| 418 | def SRLV : LogicR_shift_reg<0x06, "srlv", srl>; |
| 419 | def SRAV : LogicR_shift_reg<0x07, "srav", sra>; |
| 420 | |
| 421 | // Load Upper Immediate |
| 422 | def LUi : LoadUpper<0x0f, "lui">; |
| 423 | |
| 424 | // Load/Store |
| 425 | def LB : LoadM<0x20, "lb", sextloadi8>; |
| 426 | def LBu : LoadM<0x24, "lbu", zextloadi8>; |
| 427 | def LH : LoadM<0x21, "lh", sextloadi16>; |
| 428 | def LHu : LoadM<0x25, "lhu", zextloadi16>; |
| 429 | def LW : LoadM<0x23, "lw", load>; |
| 430 | def SB : StoreM<0x28, "sb", truncstorei8>; |
| 431 | def SH : StoreM<0x29, "sh", truncstorei16>; |
| 432 | def SW : StoreM<0x2b, "sw", store>; |
| 433 | |
| 434 | // Conditional Branch |
| 435 | def BEQ : CBranch<0x04, "beq", seteq>; |
| 436 | def BNE : CBranch<0x05, "bne", setne>; |
Bruno Cardoso Lopes | 3419055 | 2007-08-18 02:37:46 +0000 | [diff] [blame] | 437 | |
Eric Christopher | 7300ac1 | 2007-10-26 04:00:13 +0000 | [diff] [blame] | 438 | let rt=1 in |
Bruno Cardoso Lopes | 3419055 | 2007-08-18 02:37:46 +0000 | [diff] [blame] | 439 | def BGEZ : CBranchZero<0x01, "bgez", setge>; |
| 440 | |
| 441 | let rt=0 in { |
| 442 | def BGTZ : CBranchZero<0x07, "bgtz", setgt>; |
| 443 | def BLEZ : CBranchZero<0x07, "blez", setle>; |
| 444 | def BLTZ : CBranchZero<0x01, "bltz", setlt>; |
| 445 | } |
| 446 | |
| 447 | // Set Condition Code |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 448 | def SLT : SetCC_R<0x00, 0x2a, "slt", setlt>; |
| 449 | def SLTu : SetCC_R<0x00, 0x2b, "sltu", setult>; |
| 450 | def SLTi : SetCC_I<0x0a, "slti", setlt, simm16, immSExt16>; |
| 451 | def SLTiu : SetCC_I<0x0b, "sltiu", setult, uimm16, immZExt16>; |
| 452 | |
| 453 | // Unconditional jump |
| 454 | def J : JumpFJ<0x02, "j">; |
| 455 | def JR : JumpFR<0x00, 0x08, "jr">; |
| 456 | |
| 457 | // Jump and Link (Call) |
| 458 | def JAL : JumpLink<0x03, "jal">; |
| 459 | def JALR : JumpLinkReg<0x00, 0x09, "jalr">; |
Bruno Cardoso Lopes | 3419055 | 2007-08-18 02:37:46 +0000 | [diff] [blame] | 460 | def BGEZAL : BranchLink<"bgezal">; |
| 461 | def BLTZAL : BranchLink<"bltzal">; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 462 | |
| 463 | // MulDiv and Move From Hi/Lo operations, have |
| 464 | // their correpondent SDNodes created on ISelDAG. |
| 465 | // Special Mul, Div operations |
Bruno Cardoso Lopes | 3419055 | 2007-08-18 02:37:46 +0000 | [diff] [blame] | 466 | def MULT : MulDiv<0x18, "mult", IIImul>; |
| 467 | def MULTu : MulDiv<0x19, "multu", IIImul>; |
| 468 | def DIV : MulDiv<0x1a, "div", IIIdiv>; |
| 469 | def DIVu : MulDiv<0x1b, "divu", IIIdiv>; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 470 | |
Eric Christopher | 7300ac1 | 2007-10-26 04:00:13 +0000 | [diff] [blame] | 471 | // Move From Hi/Lo |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 472 | def MFHI : MoveFromTo<0x10, "mfhi">; |
| 473 | def MFLO : MoveFromTo<0x12, "mflo">; |
| 474 | def MTHI : MoveFromTo<0x11, "mthi">; |
| 475 | def MTLO : MoveFromTo<0x13, "mtlo">; |
| 476 | |
| 477 | // Count Leading |
Eric Christopher | 7300ac1 | 2007-10-26 04:00:13 +0000 | [diff] [blame] | 478 | // CLO/CLZ are part of the newer MIPS32(tm) instruction |
| 479 | // set and not older Mips I keep this for future use |
Bruno Cardoso Lopes | 218d582 | 2007-11-05 03:02:32 +0000 | [diff] [blame] | 480 | // though. |
Eric Christopher | 7300ac1 | 2007-10-26 04:00:13 +0000 | [diff] [blame] | 481 | //def CLO : CountLeading<0x21, "clo">; |
| 482 | //def CLZ : CountLeading<0x20, "clz">; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 483 | |
Bruno Cardoso Lopes | 218d582 | 2007-11-05 03:02:32 +0000 | [diff] [blame] | 484 | // MADD*/MSUB* are not part of MipsI either. |
| 485 | //def MADD : MArithR<0x00, "madd">; |
| 486 | //def MADDU : MArithR<0x01, "maddu">; |
| 487 | //def MSUB : MArithR<0x04, "msub">; |
| 488 | //def MSUBU : MArithR<0x05, "msubu">; |
| 489 | |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 490 | // No operation |
| 491 | let addr=0 in |
Bruno Cardoso Lopes | 3419055 | 2007-08-18 02:37:46 +0000 | [diff] [blame] | 492 | def NOP : FJ<0, (outs), (ins), "nop", [], IIAlu>; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 493 | |
Eric Christopher | 7300ac1 | 2007-10-26 04:00:13 +0000 | [diff] [blame] | 494 | // Ret instruction - as mips does not have "ret" a |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 495 | // jr $ra must be generated. |
Evan Cheng | 37e7c75 | 2007-07-21 00:34:19 +0000 | [diff] [blame] | 496 | let isReturn=1, isTerminator=1, hasDelaySlot=1, |
Eric Christopher | 7300ac1 | 2007-10-26 04:00:13 +0000 | [diff] [blame] | 497 | isBarrier=1, hasCtrlDep=1, rs=0, rt=0, shamt=0 in |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 498 | { |
Evan Cheng | b783fa3 | 2007-07-19 01:14:50 +0000 | [diff] [blame] | 499 | def RET : FR <0x00, 0x02, (outs), (ins CPURegs:$target), |
Bruno Cardoso Lopes | 3419055 | 2007-08-18 02:37:46 +0000 | [diff] [blame] | 500 | "jr $target", [(MipsRet CPURegs:$target)], IIBranch>; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 501 | } |
| 502 | |
Eric Christopher | 7300ac1 | 2007-10-26 04:00:13 +0000 | [diff] [blame] | 503 | // FrameIndexes are legalized when they are operands from load/store |
Bruno Cardoso Lopes | 9643366 | 2007-09-24 20:15:11 +0000 | [diff] [blame] | 504 | // instructions. The same not happens for stack address copies, so an |
| 505 | // add op with mem ComplexPattern is used and the stack address copy |
| 506 | // can be matched. It's similar to Sparc LEA_ADDRi |
| 507 | def LEA_ADDiu : EffectiveAddress<"addiu $dst, ${addr:stackloc}">; |
| 508 | |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 509 | //===----------------------------------------------------------------------===// |
| 510 | // Arbitrary patterns that map to one or more instructions |
| 511 | //===----------------------------------------------------------------------===// |
| 512 | |
| 513 | // Small immediates |
Eric Christopher | 7300ac1 | 2007-10-26 04:00:13 +0000 | [diff] [blame] | 514 | def : Pat<(i32 immSExt16:$in), |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 515 | (ADDiu ZERO, imm:$in)>; |
Eric Christopher | 7300ac1 | 2007-10-26 04:00:13 +0000 | [diff] [blame] | 516 | def : Pat<(i32 immZExt16:$in), |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 517 | (ORi ZERO, imm:$in)>; |
| 518 | |
| 519 | // Arbitrary immediates |
| 520 | def : Pat<(i32 imm:$imm), |
| 521 | (ORi (LUi (HI16 imm:$imm)), (LO16 imm:$imm))>; |
| 522 | |
Bruno Cardoso Lopes | ed7723d | 2008-06-06 00:58:26 +0000 | [diff] [blame] | 523 | // Carry patterns |
| 524 | def : Pat<(subc CPURegs:$lhs, CPURegs:$rhs), |
| 525 | (SUBu CPURegs:$lhs, CPURegs:$rhs)>; |
| 526 | def : Pat<(addc CPURegs:$lhs, CPURegs:$rhs), |
| 527 | (ADDu CPURegs:$lhs, CPURegs:$rhs)>; |
| 528 | def : Pat<(addc CPURegs:$src, imm:$imm), |
| 529 | (ADDiu CPURegs:$src, imm:$imm)>; |
| 530 | |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 531 | // Call |
| 532 | def : Pat<(MipsJmpLink (i32 tglobaladdr:$dst)), |
| 533 | (JAL tglobaladdr:$dst)>; |
| 534 | def : Pat<(MipsJmpLink (i32 texternalsym:$dst)), |
| 535 | (JAL texternalsym:$dst)>; |
Bruno Cardoso Lopes | 3419055 | 2007-08-18 02:37:46 +0000 | [diff] [blame] | 536 | def : Pat<(MipsJmpLink CPURegs:$dst), |
| 537 | (JALR CPURegs:$dst)>; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 538 | |
| 539 | // GlobalAddress, Constant Pool, ExternalSymbol, and JumpTable |
| 540 | def : Pat<(MipsHi tglobaladdr:$in), (LUi tglobaladdr:$in)>; |
| 541 | def : Pat<(MipsLo tglobaladdr:$in), (ADDiu ZERO, tglobaladdr:$in)>; |
Bruno Cardoso Lopes | 218d582 | 2007-11-05 03:02:32 +0000 | [diff] [blame] | 542 | def : Pat<(add CPURegs:$hi, (MipsLo tglobaladdr:$lo)), |
Bruno Cardoso Lopes | 3419055 | 2007-08-18 02:37:46 +0000 | [diff] [blame] | 543 | (ADDiu CPURegs:$hi, tglobaladdr:$lo)>; |
Bruno Cardoso Lopes | ea37730 | 2007-11-12 19:49:57 +0000 | [diff] [blame] | 544 | def : Pat<(MipsHi tjumptable:$in), (LUi tjumptable:$in)>; |
| 545 | def : Pat<(MipsLo tjumptable:$in), (ADDiu ZERO, tjumptable:$in)>; |
| 546 | def : Pat<(add CPURegs:$hi, (MipsLo tjumptable:$lo)), |
| 547 | (ADDiu CPURegs:$hi, tjumptable:$lo)>; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 548 | |
Eric Christopher | 7300ac1 | 2007-10-26 04:00:13 +0000 | [diff] [blame] | 549 | // Mips does not have not, so we increase the operation |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 550 | def : Pat<(not CPURegs:$in), |
Bruno Cardoso Lopes | 3419055 | 2007-08-18 02:37:46 +0000 | [diff] [blame] | 551 | (NOR CPURegs:$in, ZERO)>; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 552 | |
Eric Christopher | 7300ac1 | 2007-10-26 04:00:13 +0000 | [diff] [blame] | 553 | // extended load and stores |
Bruno Cardoso Lopes | 3419055 | 2007-08-18 02:37:46 +0000 | [diff] [blame] | 554 | def : Pat<(i32 (extloadi1 addr:$src)), (LBu addr:$src)>; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 555 | def : Pat<(i32 (extloadi8 addr:$src)), (LBu addr:$src)>; |
| 556 | def : Pat<(i32 (extloadi16 addr:$src)), (LHu addr:$src)>; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 557 | |
Bruno Cardoso Lopes | ed7723d | 2008-06-06 00:58:26 +0000 | [diff] [blame] | 558 | // peepholes |
Bruno Cardoso Lopes | 218d582 | 2007-11-05 03:02:32 +0000 | [diff] [blame] | 559 | def : Pat<(store (i32 0), addr:$dst), (SW ZERO, addr:$dst)>; |
| 560 | |
Bruno Cardoso Lopes | 3419055 | 2007-08-18 02:37:46 +0000 | [diff] [blame] | 561 | /// |
| 562 | /// brcond patterns |
| 563 | /// |
| 564 | |
| 565 | // direct match equal/notequal zero branches |
| 566 | def : Pat<(brcond (setne CPURegs:$lhs, 0), bb:$dst), |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 567 | (BNE CPURegs:$lhs, ZERO, bb:$dst)>; |
Bruno Cardoso Lopes | 3419055 | 2007-08-18 02:37:46 +0000 | [diff] [blame] | 568 | def : Pat<(brcond (seteq CPURegs:$lhs, 0), bb:$dst), |
| 569 | (BEQ CPURegs:$lhs, ZERO, bb:$dst)>; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 570 | |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 571 | def : Pat<(brcond (setge CPURegs:$lhs, CPURegs:$rhs), bb:$dst), |
Bruno Cardoso Lopes | 3419055 | 2007-08-18 02:37:46 +0000 | [diff] [blame] | 572 | (BGEZ (SUB CPURegs:$lhs, CPURegs:$rhs), bb:$dst)>; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 573 | def : Pat<(brcond (setuge CPURegs:$lhs, CPURegs:$rhs), bb:$dst), |
Bruno Cardoso Lopes | 3419055 | 2007-08-18 02:37:46 +0000 | [diff] [blame] | 574 | (BGEZ (SUBu CPURegs:$lhs, CPURegs:$rhs), bb:$dst)>; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 575 | |
Bruno Cardoso Lopes | 3419055 | 2007-08-18 02:37:46 +0000 | [diff] [blame] | 576 | def : Pat<(brcond (setgt CPURegs:$lhs, CPURegs:$rhs), bb:$dst), |
| 577 | (BGTZ (SUB CPURegs:$lhs, CPURegs:$rhs), bb:$dst)>; |
| 578 | def : Pat<(brcond (setugt CPURegs:$lhs, CPURegs:$rhs), bb:$dst), |
| 579 | (BGTZ (SUBu CPURegs:$lhs, CPURegs:$rhs), bb:$dst)>; |
| 580 | |
| 581 | def : Pat<(brcond (setle CPURegs:$lhs, CPURegs:$rhs), bb:$dst), |
| 582 | (BLEZ (SUB CPURegs:$lhs, CPURegs:$rhs), bb:$dst)>; |
| 583 | def : Pat<(brcond (setule CPURegs:$lhs, CPURegs:$rhs), bb:$dst), |
| 584 | (BLEZ (SUBu CPURegs:$lhs, CPURegs:$rhs), bb:$dst)>; |
| 585 | |
| 586 | def : Pat<(brcond (setlt CPURegs:$lhs, immSExt16:$rhs), bb:$dst), |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 587 | (BNE (SLTi CPURegs:$lhs, immSExt16:$rhs), ZERO, bb:$dst)>; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 588 | def : Pat<(brcond (setult CPURegs:$lhs, immZExt16:$rhs), bb:$dst), |
| 589 | (BNE (SLTiu CPURegs:$lhs, immZExt16:$rhs), ZERO, bb:$dst)>; |
Bruno Cardoso Lopes | 3419055 | 2007-08-18 02:37:46 +0000 | [diff] [blame] | 590 | def : Pat<(brcond (setlt CPURegs:$lhs, CPURegs:$rhs), bb:$dst), |
| 591 | (BNE (SLT CPURegs:$lhs, CPURegs:$rhs), ZERO, bb:$dst)>; |
| 592 | def : Pat<(brcond (setult CPURegs:$lhs, CPURegs:$rhs), bb:$dst), |
| 593 | (BNE (SLTu CPURegs:$lhs, CPURegs:$rhs), ZERO, bb:$dst)>; |
| 594 | |
| 595 | def : Pat<(brcond (setlt CPURegs:$lhs, CPURegs:$rhs), bb:$dst), |
| 596 | (BLTZ (SUB CPURegs:$lhs, CPURegs:$rhs), bb:$dst)>; |
| 597 | def : Pat<(brcond (setult CPURegs:$lhs, CPURegs:$rhs), bb:$dst), |
| 598 | (BLTZ (SUBu CPURegs:$lhs, CPURegs:$rhs), bb:$dst)>; |
| 599 | |
| 600 | // generic brcond pattern |
| 601 | def : Pat<(brcond CPURegs:$cond, bb:$dst), |
| 602 | (BNE CPURegs:$cond, ZERO, bb:$dst)>; |
| 603 | |
| 604 | /// |
Eric Christopher | 7300ac1 | 2007-10-26 04:00:13 +0000 | [diff] [blame] | 605 | /// setcc patterns, only matched when there |
Bruno Cardoso Lopes | 3419055 | 2007-08-18 02:37:46 +0000 | [diff] [blame] | 606 | /// is no brcond following a setcc operation |
| 607 | /// |
| 608 | |
| 609 | // setcc 2 register operands |
| 610 | def : Pat<(setle CPURegs:$lhs, CPURegs:$rhs), |
| 611 | (XORi (SLT CPURegs:$rhs, CPURegs:$lhs), 1)>; |
| 612 | def : Pat<(setule CPURegs:$lhs, CPURegs:$rhs), |
| 613 | (XORi (SLTu CPURegs:$rhs, CPURegs:$lhs), 1)>; |
| 614 | |
| 615 | def : Pat<(setgt CPURegs:$lhs, CPURegs:$rhs), |
| 616 | (SLT CPURegs:$rhs, CPURegs:$lhs)>; |
| 617 | def : Pat<(setugt CPURegs:$lhs, CPURegs:$rhs), |
| 618 | (SLTu CPURegs:$rhs, CPURegs:$lhs)>; |
| 619 | |
| 620 | def : Pat<(setge CPURegs:$lhs, CPURegs:$rhs), |
| 621 | (XORi (SLT CPURegs:$lhs, CPURegs:$rhs), 1)>; |
| 622 | def : Pat<(setuge CPURegs:$lhs, CPURegs:$rhs), |
| 623 | (XORi (SLTu CPURegs:$lhs, CPURegs:$rhs), 1)>; |
| 624 | |
| 625 | def : Pat<(setne CPURegs:$lhs, CPURegs:$rhs), |
Eric Christopher | 7300ac1 | 2007-10-26 04:00:13 +0000 | [diff] [blame] | 626 | (OR (SLT CPURegs:$lhs, CPURegs:$rhs), |
Bruno Cardoso Lopes | 3419055 | 2007-08-18 02:37:46 +0000 | [diff] [blame] | 627 | (SLT CPURegs:$rhs, CPURegs:$lhs))>; |
| 628 | |
| 629 | def : Pat<(seteq CPURegs:$lhs, CPURegs:$rhs), |
Eric Christopher | 7300ac1 | 2007-10-26 04:00:13 +0000 | [diff] [blame] | 630 | (XORi (OR (SLT CPURegs:$lhs, CPURegs:$rhs), |
Bruno Cardoso Lopes | 3419055 | 2007-08-18 02:37:46 +0000 | [diff] [blame] | 631 | (SLT CPURegs:$rhs, CPURegs:$lhs)), 1)>; |
Eric Christopher | 7300ac1 | 2007-10-26 04:00:13 +0000 | [diff] [blame] | 632 | |
Bruno Cardoso Lopes | 3419055 | 2007-08-18 02:37:46 +0000 | [diff] [blame] | 633 | // setcc reg/imm operands |
| 634 | def : Pat<(setge CPURegs:$lhs, immSExt16:$rhs), |
| 635 | (XORi (SLTi CPURegs:$lhs, immSExt16:$rhs), 1)>; |
| 636 | def : Pat<(setuge CPURegs:$lhs, immZExt16:$rhs), |
| 637 | (XORi (SLTiu CPURegs:$lhs, immZExt16:$rhs), 1)>; |