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