Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2012 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #include "codegen_x86.h" |
| 18 | #include "dex/quick/mir_to_lir-inl.h" |
Mark Mendell | 67c39c4 | 2014-01-31 17:28:00 -0800 | [diff] [blame] | 19 | #include "dex/dataflow_iterator-inl.h" |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 20 | #include "x86_lir.h" |
| 21 | |
| 22 | namespace art { |
| 23 | |
| 24 | /* This file contains codegen for the X86 ISA */ |
| 25 | |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 26 | LIR* X86Mir2Lir::OpFpRegCopy(RegStorage r_dest, RegStorage r_src) { |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 27 | int opcode; |
| 28 | /* must be both DOUBLE or both not DOUBLE */ |
buzbee | 091cc40 | 2014-03-31 10:14:40 -0700 | [diff] [blame] | 29 | DCHECK(r_dest.IsFloat() || r_src.IsFloat()); |
| 30 | DCHECK_EQ(r_dest.IsDouble(), r_src.IsDouble()); |
| 31 | if (r_dest.IsDouble()) { |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 32 | opcode = kX86MovsdRR; |
| 33 | } else { |
buzbee | 091cc40 | 2014-03-31 10:14:40 -0700 | [diff] [blame] | 34 | if (r_dest.IsSingle()) { |
| 35 | if (r_src.IsSingle()) { |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 36 | opcode = kX86MovssRR; |
| 37 | } else { // Fpr <- Gpr |
| 38 | opcode = kX86MovdxrRR; |
| 39 | } |
| 40 | } else { // Gpr <- Fpr |
buzbee | 091cc40 | 2014-03-31 10:14:40 -0700 | [diff] [blame] | 41 | DCHECK(r_src.IsSingle()) << "Raw: 0x" << std::hex << r_src.GetRawBits(); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 42 | opcode = kX86MovdrxRR; |
| 43 | } |
| 44 | } |
| 45 | DCHECK_NE((EncodingMap[opcode].flags & IS_BINARY_OP), 0ULL); |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 46 | LIR* res = RawLIR(current_dalvik_offset_, opcode, r_dest.GetReg(), r_src.GetReg()); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 47 | if (r_dest == r_src) { |
| 48 | res->flags.is_nop = true; |
| 49 | } |
| 50 | return res; |
| 51 | } |
| 52 | |
Brian Carlstrom | 2ce745c | 2013-07-17 17:44:30 -0700 | [diff] [blame] | 53 | bool X86Mir2Lir::InexpensiveConstantInt(int32_t value) { |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 54 | return true; |
| 55 | } |
| 56 | |
Brian Carlstrom | 2ce745c | 2013-07-17 17:44:30 -0700 | [diff] [blame] | 57 | bool X86Mir2Lir::InexpensiveConstantFloat(int32_t value) { |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 58 | return false; |
| 59 | } |
| 60 | |
Brian Carlstrom | 2ce745c | 2013-07-17 17:44:30 -0700 | [diff] [blame] | 61 | bool X86Mir2Lir::InexpensiveConstantLong(int64_t value) { |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 62 | return true; |
| 63 | } |
| 64 | |
Brian Carlstrom | 2ce745c | 2013-07-17 17:44:30 -0700 | [diff] [blame] | 65 | bool X86Mir2Lir::InexpensiveConstantDouble(int64_t value) { |
Mark Mendell | 67c39c4 | 2014-01-31 17:28:00 -0800 | [diff] [blame] | 66 | return value == 0; |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 67 | } |
| 68 | |
| 69 | /* |
| 70 | * Load a immediate using a shortcut if possible; otherwise |
| 71 | * grab from the per-translation literal pool. If target is |
| 72 | * a high register, build constant into a low register and copy. |
| 73 | * |
| 74 | * No additional register clobbering operation performed. Use this version when |
| 75 | * 1) r_dest is freshly returned from AllocTemp or |
| 76 | * 2) The codegen is under fixed register usage |
| 77 | */ |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 78 | LIR* X86Mir2Lir::LoadConstantNoClobber(RegStorage r_dest, int value) { |
| 79 | RegStorage r_dest_save = r_dest; |
buzbee | 091cc40 | 2014-03-31 10:14:40 -0700 | [diff] [blame] | 80 | if (r_dest.IsFloat()) { |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 81 | if (value == 0) { |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 82 | return NewLIR2(kX86XorpsRR, r_dest.GetReg(), r_dest.GetReg()); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 83 | } |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 84 | r_dest = AllocTemp(); |
| 85 | } |
| 86 | |
| 87 | LIR *res; |
| 88 | if (value == 0) { |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 89 | res = NewLIR2(kX86Xor32RR, r_dest.GetReg(), r_dest.GetReg()); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 90 | } else { |
| 91 | // Note, there is no byte immediate form of a 32 bit immediate move. |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 92 | res = NewLIR2(kX86Mov32RI, r_dest.GetReg(), value); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 93 | } |
| 94 | |
buzbee | 091cc40 | 2014-03-31 10:14:40 -0700 | [diff] [blame] | 95 | if (r_dest_save.IsFloat()) { |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 96 | NewLIR2(kX86MovdxrRR, r_dest_save.GetReg(), r_dest.GetReg()); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 97 | FreeTemp(r_dest); |
| 98 | } |
| 99 | |
| 100 | return res; |
| 101 | } |
| 102 | |
Brian Carlstrom | 2ce745c | 2013-07-17 17:44:30 -0700 | [diff] [blame] | 103 | LIR* X86Mir2Lir::OpUnconditionalBranch(LIR* target) { |
Brian Carlstrom | df62950 | 2013-07-17 22:39:56 -0700 | [diff] [blame] | 104 | LIR* res = NewLIR1(kX86Jmp8, 0 /* offset to be patched during assembly*/); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 105 | res->target = target; |
| 106 | return res; |
| 107 | } |
| 108 | |
Brian Carlstrom | 2ce745c | 2013-07-17 17:44:30 -0700 | [diff] [blame] | 109 | LIR* X86Mir2Lir::OpCondBranch(ConditionCode cc, LIR* target) { |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 110 | LIR* branch = NewLIR2(kX86Jcc8, 0 /* offset to be patched */, |
| 111 | X86ConditionEncoding(cc)); |
| 112 | branch->target = target; |
| 113 | return branch; |
| 114 | } |
| 115 | |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 116 | LIR* X86Mir2Lir::OpReg(OpKind op, RegStorage r_dest_src) { |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 117 | X86OpCode opcode = kX86Bkpt; |
| 118 | switch (op) { |
| 119 | case kOpNeg: opcode = kX86Neg32R; break; |
| 120 | case kOpNot: opcode = kX86Not32R; break; |
Vladimir Marko | a8b4caf | 2013-10-24 15:08:57 +0100 | [diff] [blame] | 121 | case kOpRev: opcode = kX86Bswap32R; break; |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 122 | case kOpBlx: opcode = kX86CallR; break; |
| 123 | default: |
| 124 | LOG(FATAL) << "Bad case in OpReg " << op; |
| 125 | } |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 126 | return NewLIR1(opcode, r_dest_src.GetReg()); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 127 | } |
| 128 | |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 129 | LIR* X86Mir2Lir::OpRegImm(OpKind op, RegStorage r_dest_src1, int value) { |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 130 | X86OpCode opcode = kX86Bkpt; |
| 131 | bool byte_imm = IS_SIMM8(value); |
buzbee | 091cc40 | 2014-03-31 10:14:40 -0700 | [diff] [blame] | 132 | DCHECK(!r_dest_src1.IsFloat()); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 133 | switch (op) { |
| 134 | case kOpLsl: opcode = kX86Sal32RI; break; |
| 135 | case kOpLsr: opcode = kX86Shr32RI; break; |
| 136 | case kOpAsr: opcode = kX86Sar32RI; break; |
| 137 | case kOpAdd: opcode = byte_imm ? kX86Add32RI8 : kX86Add32RI; break; |
| 138 | case kOpOr: opcode = byte_imm ? kX86Or32RI8 : kX86Or32RI; break; |
| 139 | case kOpAdc: opcode = byte_imm ? kX86Adc32RI8 : kX86Adc32RI; break; |
Brian Carlstrom | 7934ac2 | 2013-07-26 10:54:15 -0700 | [diff] [blame] | 140 | // case kOpSbb: opcode = kX86Sbb32RI; break; |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 141 | case kOpAnd: opcode = byte_imm ? kX86And32RI8 : kX86And32RI; break; |
| 142 | case kOpSub: opcode = byte_imm ? kX86Sub32RI8 : kX86Sub32RI; break; |
| 143 | case kOpXor: opcode = byte_imm ? kX86Xor32RI8 : kX86Xor32RI; break; |
| 144 | case kOpCmp: opcode = byte_imm ? kX86Cmp32RI8 : kX86Cmp32RI; break; |
Razvan A Lupusoru | e27b3bf | 2014-01-23 09:41:45 -0800 | [diff] [blame] | 145 | case kOpMov: |
| 146 | /* |
| 147 | * Moving the constant zero into register can be specialized as an xor of the register. |
| 148 | * However, that sets eflags while the move does not. For that reason here, always do |
| 149 | * the move and if caller is flexible, they should be calling LoadConstantNoClobber instead. |
| 150 | */ |
| 151 | opcode = kX86Mov32RI; |
| 152 | break; |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 153 | case kOpMul: |
| 154 | opcode = byte_imm ? kX86Imul32RRI8 : kX86Imul32RRI; |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 155 | return NewLIR3(opcode, r_dest_src1.GetReg(), r_dest_src1.GetReg(), value); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 156 | default: |
| 157 | LOG(FATAL) << "Bad case in OpRegImm " << op; |
| 158 | } |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 159 | return NewLIR2(opcode, r_dest_src1.GetReg(), value); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 160 | } |
| 161 | |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 162 | LIR* X86Mir2Lir::OpRegReg(OpKind op, RegStorage r_dest_src1, RegStorage r_src2) { |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 163 | X86OpCode opcode = kX86Nop; |
| 164 | bool src2_must_be_cx = false; |
| 165 | switch (op) { |
| 166 | // X86 unary opcodes |
| 167 | case kOpMvn: |
| 168 | OpRegCopy(r_dest_src1, r_src2); |
| 169 | return OpReg(kOpNot, r_dest_src1); |
| 170 | case kOpNeg: |
| 171 | OpRegCopy(r_dest_src1, r_src2); |
| 172 | return OpReg(kOpNeg, r_dest_src1); |
Vladimir Marko | a8b4caf | 2013-10-24 15:08:57 +0100 | [diff] [blame] | 173 | case kOpRev: |
| 174 | OpRegCopy(r_dest_src1, r_src2); |
| 175 | return OpReg(kOpRev, r_dest_src1); |
| 176 | case kOpRevsh: |
| 177 | OpRegCopy(r_dest_src1, r_src2); |
| 178 | OpReg(kOpRev, r_dest_src1); |
| 179 | return OpRegImm(kOpAsr, r_dest_src1, 16); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 180 | // X86 binary opcodes |
| 181 | case kOpSub: opcode = kX86Sub32RR; break; |
| 182 | case kOpSbc: opcode = kX86Sbb32RR; break; |
| 183 | case kOpLsl: opcode = kX86Sal32RC; src2_must_be_cx = true; break; |
| 184 | case kOpLsr: opcode = kX86Shr32RC; src2_must_be_cx = true; break; |
| 185 | case kOpAsr: opcode = kX86Sar32RC; src2_must_be_cx = true; break; |
| 186 | case kOpMov: opcode = kX86Mov32RR; break; |
| 187 | case kOpCmp: opcode = kX86Cmp32RR; break; |
| 188 | case kOpAdd: opcode = kX86Add32RR; break; |
| 189 | case kOpAdc: opcode = kX86Adc32RR; break; |
| 190 | case kOpAnd: opcode = kX86And32RR; break; |
| 191 | case kOpOr: opcode = kX86Or32RR; break; |
| 192 | case kOpXor: opcode = kX86Xor32RR; break; |
| 193 | case kOp2Byte: |
buzbee | 091cc40 | 2014-03-31 10:14:40 -0700 | [diff] [blame] | 194 | // TODO: there are several instances of this check. A utility function perhaps? |
| 195 | // TODO: Similar to Arm's reg < 8 check. Perhaps add attribute checks to RegStorage? |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 196 | // Use shifts instead of a byte operand if the source can't be byte accessed. |
buzbee | 091cc40 | 2014-03-31 10:14:40 -0700 | [diff] [blame] | 197 | if (r_src2.GetRegNum() >= rs_rX86_SP.GetRegNum()) { |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 198 | NewLIR2(kX86Mov32RR, r_dest_src1.GetReg(), r_src2.GetReg()); |
| 199 | NewLIR2(kX86Sal32RI, r_dest_src1.GetReg(), 24); |
| 200 | return NewLIR2(kX86Sar32RI, r_dest_src1.GetReg(), 24); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 201 | } else { |
| 202 | opcode = kX86Movsx8RR; |
| 203 | } |
| 204 | break; |
| 205 | case kOp2Short: opcode = kX86Movsx16RR; break; |
| 206 | case kOp2Char: opcode = kX86Movzx16RR; break; |
| 207 | case kOpMul: opcode = kX86Imul32RR; break; |
| 208 | default: |
| 209 | LOG(FATAL) << "Bad case in OpRegReg " << op; |
| 210 | break; |
| 211 | } |
buzbee | 091cc40 | 2014-03-31 10:14:40 -0700 | [diff] [blame] | 212 | CHECK(!src2_must_be_cx || r_src2.GetReg() == rs_rCX.GetReg()); |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 213 | return NewLIR2(opcode, r_dest_src1.GetReg(), r_src2.GetReg()); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 214 | } |
| 215 | |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 216 | LIR* X86Mir2Lir::OpMovRegMem(RegStorage r_dest, RegStorage r_base, int offset, MoveType move_type) { |
buzbee | 091cc40 | 2014-03-31 10:14:40 -0700 | [diff] [blame] | 217 | DCHECK(!r_base.IsFloat()); |
Razvan A Lupusoru | 2c498d1 | 2014-01-29 16:02:57 -0800 | [diff] [blame] | 218 | X86OpCode opcode = kX86Nop; |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 219 | int dest = r_dest.IsPair() ? r_dest.GetLowReg() : r_dest.GetReg(); |
Razvan A Lupusoru | 2c498d1 | 2014-01-29 16:02:57 -0800 | [diff] [blame] | 220 | switch (move_type) { |
| 221 | case kMov8GP: |
buzbee | 091cc40 | 2014-03-31 10:14:40 -0700 | [diff] [blame] | 222 | CHECK(!r_dest.IsFloat()); |
Razvan A Lupusoru | 2c498d1 | 2014-01-29 16:02:57 -0800 | [diff] [blame] | 223 | opcode = kX86Mov8RM; |
| 224 | break; |
| 225 | case kMov16GP: |
buzbee | 091cc40 | 2014-03-31 10:14:40 -0700 | [diff] [blame] | 226 | CHECK(!r_dest.IsFloat()); |
Razvan A Lupusoru | 2c498d1 | 2014-01-29 16:02:57 -0800 | [diff] [blame] | 227 | opcode = kX86Mov16RM; |
| 228 | break; |
| 229 | case kMov32GP: |
buzbee | 091cc40 | 2014-03-31 10:14:40 -0700 | [diff] [blame] | 230 | CHECK(!r_dest.IsFloat()); |
Razvan A Lupusoru | 2c498d1 | 2014-01-29 16:02:57 -0800 | [diff] [blame] | 231 | opcode = kX86Mov32RM; |
| 232 | break; |
| 233 | case kMov32FP: |
buzbee | 091cc40 | 2014-03-31 10:14:40 -0700 | [diff] [blame] | 234 | CHECK(r_dest.IsFloat()); |
Razvan A Lupusoru | 2c498d1 | 2014-01-29 16:02:57 -0800 | [diff] [blame] | 235 | opcode = kX86MovssRM; |
| 236 | break; |
| 237 | case kMov64FP: |
buzbee | 091cc40 | 2014-03-31 10:14:40 -0700 | [diff] [blame] | 238 | CHECK(r_dest.IsFloat()); |
Razvan A Lupusoru | 2c498d1 | 2014-01-29 16:02:57 -0800 | [diff] [blame] | 239 | opcode = kX86MovsdRM; |
| 240 | break; |
| 241 | case kMovU128FP: |
buzbee | 091cc40 | 2014-03-31 10:14:40 -0700 | [diff] [blame] | 242 | CHECK(r_dest.IsFloat()); |
Razvan A Lupusoru | 2c498d1 | 2014-01-29 16:02:57 -0800 | [diff] [blame] | 243 | opcode = kX86MovupsRM; |
| 244 | break; |
| 245 | case kMovA128FP: |
buzbee | 091cc40 | 2014-03-31 10:14:40 -0700 | [diff] [blame] | 246 | CHECK(r_dest.IsFloat()); |
Razvan A Lupusoru | 2c498d1 | 2014-01-29 16:02:57 -0800 | [diff] [blame] | 247 | opcode = kX86MovapsRM; |
| 248 | break; |
| 249 | case kMovLo128FP: |
buzbee | 091cc40 | 2014-03-31 10:14:40 -0700 | [diff] [blame] | 250 | CHECK(r_dest.IsFloat()); |
Razvan A Lupusoru | 2c498d1 | 2014-01-29 16:02:57 -0800 | [diff] [blame] | 251 | opcode = kX86MovlpsRM; |
| 252 | break; |
| 253 | case kMovHi128FP: |
buzbee | 091cc40 | 2014-03-31 10:14:40 -0700 | [diff] [blame] | 254 | CHECK(r_dest.IsFloat()); |
Razvan A Lupusoru | 2c498d1 | 2014-01-29 16:02:57 -0800 | [diff] [blame] | 255 | opcode = kX86MovhpsRM; |
| 256 | break; |
| 257 | case kMov64GP: |
| 258 | case kMovLo64FP: |
| 259 | case kMovHi64FP: |
| 260 | default: |
| 261 | LOG(FATAL) << "Bad case in OpMovRegMem"; |
| 262 | break; |
| 263 | } |
| 264 | |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 265 | return NewLIR3(opcode, dest, r_base.GetReg(), offset); |
Razvan A Lupusoru | 2c498d1 | 2014-01-29 16:02:57 -0800 | [diff] [blame] | 266 | } |
| 267 | |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 268 | LIR* X86Mir2Lir::OpMovMemReg(RegStorage r_base, int offset, RegStorage r_src, MoveType move_type) { |
buzbee | 091cc40 | 2014-03-31 10:14:40 -0700 | [diff] [blame] | 269 | DCHECK(!r_base.IsFloat()); |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 270 | int src = r_src.IsPair() ? r_src.GetLowReg() : r_src.GetReg(); |
Razvan A Lupusoru | 2c498d1 | 2014-01-29 16:02:57 -0800 | [diff] [blame] | 271 | |
| 272 | X86OpCode opcode = kX86Nop; |
| 273 | switch (move_type) { |
| 274 | case kMov8GP: |
buzbee | 091cc40 | 2014-03-31 10:14:40 -0700 | [diff] [blame] | 275 | CHECK(!r_src.IsFloat()); |
Razvan A Lupusoru | 2c498d1 | 2014-01-29 16:02:57 -0800 | [diff] [blame] | 276 | opcode = kX86Mov8MR; |
| 277 | break; |
| 278 | case kMov16GP: |
buzbee | 091cc40 | 2014-03-31 10:14:40 -0700 | [diff] [blame] | 279 | CHECK(!r_src.IsFloat()); |
Razvan A Lupusoru | 2c498d1 | 2014-01-29 16:02:57 -0800 | [diff] [blame] | 280 | opcode = kX86Mov16MR; |
| 281 | break; |
| 282 | case kMov32GP: |
buzbee | 091cc40 | 2014-03-31 10:14:40 -0700 | [diff] [blame] | 283 | CHECK(!r_src.IsFloat()); |
Razvan A Lupusoru | 2c498d1 | 2014-01-29 16:02:57 -0800 | [diff] [blame] | 284 | opcode = kX86Mov32MR; |
| 285 | break; |
| 286 | case kMov32FP: |
buzbee | 091cc40 | 2014-03-31 10:14:40 -0700 | [diff] [blame] | 287 | CHECK(r_src.IsFloat()); |
Razvan A Lupusoru | 2c498d1 | 2014-01-29 16:02:57 -0800 | [diff] [blame] | 288 | opcode = kX86MovssMR; |
| 289 | break; |
| 290 | case kMov64FP: |
buzbee | 091cc40 | 2014-03-31 10:14:40 -0700 | [diff] [blame] | 291 | CHECK(r_src.IsFloat()); |
Razvan A Lupusoru | 2c498d1 | 2014-01-29 16:02:57 -0800 | [diff] [blame] | 292 | opcode = kX86MovsdMR; |
| 293 | break; |
| 294 | case kMovU128FP: |
buzbee | 091cc40 | 2014-03-31 10:14:40 -0700 | [diff] [blame] | 295 | CHECK(r_src.IsFloat()); |
Razvan A Lupusoru | 2c498d1 | 2014-01-29 16:02:57 -0800 | [diff] [blame] | 296 | opcode = kX86MovupsMR; |
| 297 | break; |
| 298 | case kMovA128FP: |
buzbee | 091cc40 | 2014-03-31 10:14:40 -0700 | [diff] [blame] | 299 | CHECK(r_src.IsFloat()); |
Razvan A Lupusoru | 2c498d1 | 2014-01-29 16:02:57 -0800 | [diff] [blame] | 300 | opcode = kX86MovapsMR; |
| 301 | break; |
| 302 | case kMovLo128FP: |
buzbee | 091cc40 | 2014-03-31 10:14:40 -0700 | [diff] [blame] | 303 | CHECK(r_src.IsFloat()); |
Razvan A Lupusoru | 2c498d1 | 2014-01-29 16:02:57 -0800 | [diff] [blame] | 304 | opcode = kX86MovlpsMR; |
| 305 | break; |
| 306 | case kMovHi128FP: |
buzbee | 091cc40 | 2014-03-31 10:14:40 -0700 | [diff] [blame] | 307 | CHECK(r_src.IsFloat()); |
Razvan A Lupusoru | 2c498d1 | 2014-01-29 16:02:57 -0800 | [diff] [blame] | 308 | opcode = kX86MovhpsMR; |
| 309 | break; |
| 310 | case kMov64GP: |
| 311 | case kMovLo64FP: |
| 312 | case kMovHi64FP: |
| 313 | default: |
| 314 | LOG(FATAL) << "Bad case in OpMovMemReg"; |
| 315 | break; |
| 316 | } |
| 317 | |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 318 | return NewLIR3(opcode, r_base.GetReg(), offset, src); |
Razvan A Lupusoru | 2c498d1 | 2014-01-29 16:02:57 -0800 | [diff] [blame] | 319 | } |
| 320 | |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 321 | LIR* X86Mir2Lir::OpCondRegReg(OpKind op, ConditionCode cc, RegStorage r_dest, RegStorage r_src) { |
Razvan A Lupusoru | bd288c2 | 2013-12-20 17:27:23 -0800 | [diff] [blame] | 322 | // The only conditional reg to reg operation supported is Cmov |
| 323 | DCHECK_EQ(op, kOpCmov); |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 324 | return NewLIR3(kX86Cmov32RRC, r_dest.GetReg(), r_src.GetReg(), X86ConditionEncoding(cc)); |
Razvan A Lupusoru | bd288c2 | 2013-12-20 17:27:23 -0800 | [diff] [blame] | 325 | } |
| 326 | |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 327 | LIR* X86Mir2Lir::OpRegMem(OpKind op, RegStorage r_dest, RegStorage r_base, int offset) { |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 328 | X86OpCode opcode = kX86Nop; |
| 329 | switch (op) { |
| 330 | // X86 binary opcodes |
| 331 | case kOpSub: opcode = kX86Sub32RM; break; |
| 332 | case kOpMov: opcode = kX86Mov32RM; break; |
| 333 | case kOpCmp: opcode = kX86Cmp32RM; break; |
| 334 | case kOpAdd: opcode = kX86Add32RM; break; |
| 335 | case kOpAnd: opcode = kX86And32RM; break; |
| 336 | case kOpOr: opcode = kX86Or32RM; break; |
| 337 | case kOpXor: opcode = kX86Xor32RM; break; |
| 338 | case kOp2Byte: opcode = kX86Movsx8RM; break; |
| 339 | case kOp2Short: opcode = kX86Movsx16RM; break; |
| 340 | case kOp2Char: opcode = kX86Movzx16RM; break; |
| 341 | case kOpMul: |
| 342 | default: |
| 343 | LOG(FATAL) << "Bad case in OpRegMem " << op; |
| 344 | break; |
| 345 | } |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 346 | LIR *l = NewLIR3(opcode, r_dest.GetReg(), r_base.GetReg(), offset); |
| 347 | if (r_base == rs_rX86_SP) { |
Mark Mendell | feb2b4e | 2014-01-28 12:59:49 -0800 | [diff] [blame] | 348 | AnnotateDalvikRegAccess(l, offset >> 2, true /* is_load */, false /* is_64bit */); |
| 349 | } |
| 350 | return l; |
| 351 | } |
| 352 | |
| 353 | LIR* X86Mir2Lir::OpMemReg(OpKind op, RegLocation rl_dest, int r_value) { |
| 354 | DCHECK_NE(rl_dest.location, kLocPhysReg); |
| 355 | int displacement = SRegOffset(rl_dest.s_reg_low); |
| 356 | X86OpCode opcode = kX86Nop; |
| 357 | switch (op) { |
| 358 | case kOpSub: opcode = kX86Sub32MR; break; |
| 359 | case kOpMov: opcode = kX86Mov32MR; break; |
| 360 | case kOpCmp: opcode = kX86Cmp32MR; break; |
| 361 | case kOpAdd: opcode = kX86Add32MR; break; |
| 362 | case kOpAnd: opcode = kX86And32MR; break; |
| 363 | case kOpOr: opcode = kX86Or32MR; break; |
| 364 | case kOpXor: opcode = kX86Xor32MR; break; |
| 365 | case kOpLsl: opcode = kX86Sal32MC; break; |
| 366 | case kOpLsr: opcode = kX86Shr32MC; break; |
| 367 | case kOpAsr: opcode = kX86Sar32MC; break; |
| 368 | default: |
| 369 | LOG(FATAL) << "Bad case in OpMemReg " << op; |
| 370 | break; |
| 371 | } |
buzbee | 091cc40 | 2014-03-31 10:14:40 -0700 | [diff] [blame] | 372 | LIR *l = NewLIR3(opcode, rs_rX86_SP.GetReg(), displacement, r_value); |
Serguei Katkov | 217fe73 | 2014-03-27 14:41:56 +0700 | [diff] [blame] | 373 | AnnotateDalvikRegAccess(l, displacement >> 2, true /* is_load */, false /* is_64bit */); |
Mark Mendell | feb2b4e | 2014-01-28 12:59:49 -0800 | [diff] [blame] | 374 | AnnotateDalvikRegAccess(l, displacement >> 2, false /* is_load */, false /* is_64bit */); |
| 375 | return l; |
| 376 | } |
| 377 | |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 378 | LIR* X86Mir2Lir::OpRegMem(OpKind op, RegStorage r_dest, RegLocation rl_value) { |
Mark Mendell | feb2b4e | 2014-01-28 12:59:49 -0800 | [diff] [blame] | 379 | DCHECK_NE(rl_value.location, kLocPhysReg); |
| 380 | int displacement = SRegOffset(rl_value.s_reg_low); |
| 381 | X86OpCode opcode = kX86Nop; |
| 382 | switch (op) { |
| 383 | case kOpSub: opcode = kX86Sub32RM; break; |
| 384 | case kOpMov: opcode = kX86Mov32RM; break; |
| 385 | case kOpCmp: opcode = kX86Cmp32RM; break; |
| 386 | case kOpAdd: opcode = kX86Add32RM; break; |
| 387 | case kOpAnd: opcode = kX86And32RM; break; |
| 388 | case kOpOr: opcode = kX86Or32RM; break; |
| 389 | case kOpXor: opcode = kX86Xor32RM; break; |
| 390 | case kOpMul: opcode = kX86Imul32RM; break; |
| 391 | default: |
| 392 | LOG(FATAL) << "Bad case in OpRegMem " << op; |
| 393 | break; |
| 394 | } |
buzbee | 091cc40 | 2014-03-31 10:14:40 -0700 | [diff] [blame] | 395 | LIR *l = NewLIR3(opcode, r_dest.GetReg(), rs_rX86_SP.GetReg(), displacement); |
Mark Mendell | feb2b4e | 2014-01-28 12:59:49 -0800 | [diff] [blame] | 396 | AnnotateDalvikRegAccess(l, displacement >> 2, true /* is_load */, false /* is_64bit */); |
| 397 | return l; |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 398 | } |
| 399 | |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 400 | LIR* X86Mir2Lir::OpRegRegReg(OpKind op, RegStorage r_dest, RegStorage r_src1, |
| 401 | RegStorage r_src2) { |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 402 | if (r_dest != r_src1 && r_dest != r_src2) { |
Brian Carlstrom | 7934ac2 | 2013-07-26 10:54:15 -0700 | [diff] [blame] | 403 | if (op == kOpAdd) { // lea special case, except can't encode rbp as base |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 404 | if (r_src1 == r_src2) { |
| 405 | OpRegCopy(r_dest, r_src1); |
| 406 | return OpRegImm(kOpLsl, r_dest, 1); |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 407 | } else if (r_src1 != rs_rBP) { |
| 408 | return NewLIR5(kX86Lea32RA, r_dest.GetReg(), r_src1.GetReg() /* base */, |
| 409 | r_src2.GetReg() /* index */, 0 /* scale */, 0 /* disp */); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 410 | } else { |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 411 | return NewLIR5(kX86Lea32RA, r_dest.GetReg(), r_src2.GetReg() /* base */, |
| 412 | r_src1.GetReg() /* index */, 0 /* scale */, 0 /* disp */); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 413 | } |
| 414 | } else { |
| 415 | OpRegCopy(r_dest, r_src1); |
| 416 | return OpRegReg(op, r_dest, r_src2); |
| 417 | } |
| 418 | } else if (r_dest == r_src1) { |
| 419 | return OpRegReg(op, r_dest, r_src2); |
| 420 | } else { // r_dest == r_src2 |
| 421 | switch (op) { |
| 422 | case kOpSub: // non-commutative |
| 423 | OpReg(kOpNeg, r_dest); |
| 424 | op = kOpAdd; |
| 425 | break; |
| 426 | case kOpSbc: |
| 427 | case kOpLsl: case kOpLsr: case kOpAsr: case kOpRor: { |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 428 | RegStorage t_reg = AllocTemp(); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 429 | OpRegCopy(t_reg, r_src1); |
| 430 | OpRegReg(op, t_reg, r_src2); |
buzbee | 7a11ab0 | 2014-04-28 20:02:38 -0700 | [diff] [blame] | 431 | LIR* res = OpRegCopyNoInsert(r_dest, t_reg); |
| 432 | AppendLIR(res); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 433 | FreeTemp(t_reg); |
| 434 | return res; |
| 435 | } |
| 436 | case kOpAdd: // commutative |
| 437 | case kOpOr: |
| 438 | case kOpAdc: |
| 439 | case kOpAnd: |
| 440 | case kOpXor: |
| 441 | break; |
| 442 | default: |
| 443 | LOG(FATAL) << "Bad case in OpRegRegReg " << op; |
| 444 | } |
| 445 | return OpRegReg(op, r_dest, r_src1); |
| 446 | } |
| 447 | } |
| 448 | |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 449 | LIR* X86Mir2Lir::OpRegRegImm(OpKind op, RegStorage r_dest, RegStorage r_src, int value) { |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 450 | if (op == kOpMul) { |
| 451 | X86OpCode opcode = IS_SIMM8(value) ? kX86Imul32RRI8 : kX86Imul32RRI; |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 452 | return NewLIR3(opcode, r_dest.GetReg(), r_src.GetReg(), value); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 453 | } else if (op == kOpAnd) { |
buzbee | 091cc40 | 2014-03-31 10:14:40 -0700 | [diff] [blame] | 454 | if (value == 0xFF && r_src.Low4()) { |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 455 | return NewLIR2(kX86Movzx8RR, r_dest.GetReg(), r_src.GetReg()); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 456 | } else if (value == 0xFFFF) { |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 457 | return NewLIR2(kX86Movzx16RR, r_dest.GetReg(), r_src.GetReg()); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 458 | } |
| 459 | } |
| 460 | if (r_dest != r_src) { |
Brian Carlstrom | 7934ac2 | 2013-07-26 10:54:15 -0700 | [diff] [blame] | 461 | if (false && op == kOpLsl && value >= 0 && value <= 3) { // lea shift special case |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 462 | // TODO: fix bug in LEA encoding when disp == 0 |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 463 | return NewLIR5(kX86Lea32RA, r_dest.GetReg(), r5sib_no_base /* base */, |
| 464 | r_src.GetReg() /* index */, value /* scale */, 0 /* disp */); |
Brian Carlstrom | 7934ac2 | 2013-07-26 10:54:15 -0700 | [diff] [blame] | 465 | } else if (op == kOpAdd) { // lea add special case |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 466 | return NewLIR5(kX86Lea32RA, r_dest.GetReg(), r_src.GetReg() /* base */, |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 467 | r4sib_no_index /* index */, 0 /* scale */, value /* disp */); |
| 468 | } |
| 469 | OpRegCopy(r_dest, r_src); |
| 470 | } |
| 471 | return OpRegImm(op, r_dest, value); |
| 472 | } |
| 473 | |
Ian Rogers | dd7624d | 2014-03-14 17:43:00 -0700 | [diff] [blame] | 474 | LIR* X86Mir2Lir::OpThreadMem(OpKind op, ThreadOffset<4> thread_offset) { |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 475 | X86OpCode opcode = kX86Bkpt; |
| 476 | switch (op) { |
| 477 | case kOpBlx: opcode = kX86CallT; break; |
Brian Carlstrom | 60d7a65 | 2014-03-13 18:10:08 -0700 | [diff] [blame] | 478 | case kOpBx: opcode = kX86JmpT; break; |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 479 | default: |
| 480 | LOG(FATAL) << "Bad opcode: " << op; |
| 481 | break; |
| 482 | } |
Ian Rogers | 468532e | 2013-08-05 10:56:33 -0700 | [diff] [blame] | 483 | return NewLIR1(opcode, thread_offset.Int32Value()); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 484 | } |
| 485 | |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 486 | LIR* X86Mir2Lir::OpMem(OpKind op, RegStorage r_base, int disp) { |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 487 | X86OpCode opcode = kX86Bkpt; |
| 488 | switch (op) { |
| 489 | case kOpBlx: opcode = kX86CallM; break; |
| 490 | default: |
| 491 | LOG(FATAL) << "Bad opcode: " << op; |
| 492 | break; |
| 493 | } |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 494 | return NewLIR2(opcode, r_base.GetReg(), disp); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 495 | } |
| 496 | |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 497 | LIR* X86Mir2Lir::LoadConstantWide(RegStorage r_dest, int64_t value) { |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 498 | int32_t val_lo = Low32Bits(value); |
| 499 | int32_t val_hi = High32Bits(value); |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 500 | int32_t low_reg_val = r_dest.IsPair() ? r_dest.GetLowReg() : r_dest.GetReg(); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 501 | LIR *res; |
buzbee | 091cc40 | 2014-03-31 10:14:40 -0700 | [diff] [blame] | 502 | bool is_fp = RegStorage::IsFloat(low_reg_val); |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 503 | // TODO: clean this up once we fully recognize 64-bit storage containers. |
| 504 | if (is_fp) { |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 505 | if (value == 0) { |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 506 | return NewLIR2(kX86XorpsRR, low_reg_val, low_reg_val); |
Mark Mendell | 67c39c4 | 2014-01-31 17:28:00 -0800 | [diff] [blame] | 507 | } else if (base_of_code_ != nullptr) { |
| 508 | // We will load the value from the literal area. |
| 509 | LIR* data_target = ScanLiteralPoolWide(literal_list_, val_lo, val_hi); |
| 510 | if (data_target == NULL) { |
| 511 | data_target = AddWideData(&literal_list_, val_lo, val_hi); |
| 512 | } |
| 513 | |
| 514 | // Address the start of the method |
| 515 | RegLocation rl_method = mir_graph_->GetRegLocation(base_of_code_->s_reg_low); |
| 516 | rl_method = LoadValue(rl_method, kCoreReg); |
| 517 | |
| 518 | // Load the proper value from the literal area. |
| 519 | // We don't know the proper offset for the value, so pick one that will force |
| 520 | // 4 byte offset. We will fix this up in the assembler later to have the right |
| 521 | // value. |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 522 | res = LoadBaseDisp(rl_method.reg, 256 /* bogus */, RegStorage::Solo64(low_reg_val), |
Vladimir Marko | 3bf7c60 | 2014-05-07 14:55:43 +0100 | [diff] [blame^] | 523 | kDouble); |
Mark Mendell | 67c39c4 | 2014-01-31 17:28:00 -0800 | [diff] [blame] | 524 | res->target = data_target; |
| 525 | res->flags.fixup = kFixupLoad; |
| 526 | SetMemRefType(res, true, kLiteral); |
Mark Mendell | 55d0eac | 2014-02-06 11:02:52 -0800 | [diff] [blame] | 527 | store_method_addr_used_ = true; |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 528 | } else { |
| 529 | if (val_lo == 0) { |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 530 | res = NewLIR2(kX86XorpsRR, low_reg_val, low_reg_val); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 531 | } else { |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 532 | res = LoadConstantNoClobber(RegStorage::Solo32(low_reg_val), val_lo); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 533 | } |
| 534 | if (val_hi != 0) { |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 535 | RegStorage r_dest_hi = AllocTempDouble(); |
buzbee | 091cc40 | 2014-03-31 10:14:40 -0700 | [diff] [blame] | 536 | LoadConstantNoClobber(r_dest_hi, val_hi); |
| 537 | NewLIR2(kX86PunpckldqRR, low_reg_val, r_dest_hi.GetReg()); |
Bill Buzbee | d61ba4b | 2014-01-13 21:44:01 +0000 | [diff] [blame] | 538 | FreeTemp(r_dest_hi); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 539 | } |
| 540 | } |
| 541 | } else { |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 542 | res = LoadConstantNoClobber(r_dest.GetLow(), val_lo); |
| 543 | LoadConstantNoClobber(r_dest.GetHigh(), val_hi); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 544 | } |
| 545 | return res; |
| 546 | } |
| 547 | |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 548 | LIR* X86Mir2Lir::LoadBaseIndexedDisp(RegStorage r_base, RegStorage r_index, int scale, |
Vladimir Marko | 3bf7c60 | 2014-05-07 14:55:43 +0100 | [diff] [blame^] | 549 | int displacement, RegStorage r_dest, OpSize size) { |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 550 | LIR *load = NULL; |
| 551 | LIR *load2 = NULL; |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 552 | bool is_array = r_index.Valid(); |
buzbee | 091cc40 | 2014-03-31 10:14:40 -0700 | [diff] [blame] | 553 | bool pair = r_dest.IsPair(); |
| 554 | bool is64bit = ((size == k64) || (size == kDouble)); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 555 | X86OpCode opcode = kX86Nop; |
| 556 | switch (size) { |
buzbee | 695d13a | 2014-04-19 13:32:20 -0700 | [diff] [blame] | 557 | case k64: |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 558 | case kDouble: |
buzbee | 091cc40 | 2014-03-31 10:14:40 -0700 | [diff] [blame] | 559 | if (r_dest.IsFloat()) { |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 560 | opcode = is_array ? kX86MovsdRA : kX86MovsdRM; |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 561 | } else { |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 562 | opcode = is_array ? kX86Mov32RA : kX86Mov32RM; |
| 563 | } |
| 564 | // TODO: double store is to unaligned address |
| 565 | DCHECK_EQ((displacement & 0x3), 0); |
| 566 | break; |
buzbee | 695d13a | 2014-04-19 13:32:20 -0700 | [diff] [blame] | 567 | case k32: |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 568 | case kSingle: |
buzbee | 695d13a | 2014-04-19 13:32:20 -0700 | [diff] [blame] | 569 | case kReference: // TODO: update for reference decompression on 64-bit targets. |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 570 | opcode = is_array ? kX86Mov32RA : kX86Mov32RM; |
buzbee | 091cc40 | 2014-03-31 10:14:40 -0700 | [diff] [blame] | 571 | if (r_dest.IsFloat()) { |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 572 | opcode = is_array ? kX86MovssRA : kX86MovssRM; |
buzbee | 091cc40 | 2014-03-31 10:14:40 -0700 | [diff] [blame] | 573 | DCHECK(r_dest.IsFloat()); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 574 | } |
| 575 | DCHECK_EQ((displacement & 0x3), 0); |
| 576 | break; |
| 577 | case kUnsignedHalf: |
| 578 | opcode = is_array ? kX86Movzx16RA : kX86Movzx16RM; |
| 579 | DCHECK_EQ((displacement & 0x1), 0); |
| 580 | break; |
| 581 | case kSignedHalf: |
| 582 | opcode = is_array ? kX86Movsx16RA : kX86Movsx16RM; |
| 583 | DCHECK_EQ((displacement & 0x1), 0); |
| 584 | break; |
| 585 | case kUnsignedByte: |
| 586 | opcode = is_array ? kX86Movzx8RA : kX86Movzx8RM; |
| 587 | break; |
| 588 | case kSignedByte: |
| 589 | opcode = is_array ? kX86Movsx8RA : kX86Movsx8RM; |
| 590 | break; |
| 591 | default: |
| 592 | LOG(FATAL) << "Bad case in LoadBaseIndexedDispBody"; |
| 593 | } |
| 594 | |
| 595 | if (!is_array) { |
| 596 | if (!pair) { |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 597 | load = NewLIR3(opcode, r_dest.GetReg(), r_base.GetReg(), displacement + LOWORD_OFFSET); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 598 | } else { |
buzbee | 091cc40 | 2014-03-31 10:14:40 -0700 | [diff] [blame] | 599 | DCHECK(!r_dest.IsFloat()); // Make sure we're not still using a pair here. |
| 600 | if (r_base == r_dest.GetLow()) { |
| 601 | load2 = NewLIR3(opcode, r_dest.GetHighReg(), r_base.GetReg(), |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 602 | displacement + HIWORD_OFFSET); |
buzbee | 091cc40 | 2014-03-31 10:14:40 -0700 | [diff] [blame] | 603 | load = NewLIR3(opcode, r_dest.GetLowReg(), r_base.GetReg(), displacement + LOWORD_OFFSET); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 604 | } else { |
buzbee | 091cc40 | 2014-03-31 10:14:40 -0700 | [diff] [blame] | 605 | load = NewLIR3(opcode, r_dest.GetLowReg(), r_base.GetReg(), displacement + LOWORD_OFFSET); |
| 606 | load2 = NewLIR3(opcode, r_dest.GetHighReg(), r_base.GetReg(), |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 607 | displacement + HIWORD_OFFSET); |
| 608 | } |
| 609 | } |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 610 | if (r_base == rs_rX86_SP) { |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 611 | AnnotateDalvikRegAccess(load, (displacement + (pair ? LOWORD_OFFSET : 0)) >> 2, |
| 612 | true /* is_load */, is64bit); |
| 613 | if (pair) { |
| 614 | AnnotateDalvikRegAccess(load2, (displacement + HIWORD_OFFSET) >> 2, |
| 615 | true /* is_load */, is64bit); |
| 616 | } |
| 617 | } |
| 618 | } else { |
| 619 | if (!pair) { |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 620 | load = NewLIR5(opcode, r_dest.GetReg(), r_base.GetReg(), r_index.GetReg(), scale, |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 621 | displacement + LOWORD_OFFSET); |
| 622 | } else { |
buzbee | 091cc40 | 2014-03-31 10:14:40 -0700 | [diff] [blame] | 623 | DCHECK(!r_dest.IsFloat()); // Make sure we're not still using a pair here. |
| 624 | if (r_base == r_dest.GetLow()) { |
| 625 | if (r_dest.GetHigh() == r_index) { |
Mark Mendell | ae427c3 | 2014-01-24 09:17:22 -0800 | [diff] [blame] | 626 | // We can't use either register for the first load. |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 627 | RegStorage temp = AllocTemp(); |
| 628 | load2 = NewLIR5(opcode, temp.GetReg(), r_base.GetReg(), r_index.GetReg(), scale, |
Mark Mendell | ae427c3 | 2014-01-24 09:17:22 -0800 | [diff] [blame] | 629 | displacement + HIWORD_OFFSET); |
buzbee | 091cc40 | 2014-03-31 10:14:40 -0700 | [diff] [blame] | 630 | load = NewLIR5(opcode, r_dest.GetLowReg(), r_base.GetReg(), r_index.GetReg(), scale, |
Mark Mendell | ae427c3 | 2014-01-24 09:17:22 -0800 | [diff] [blame] | 631 | displacement + LOWORD_OFFSET); |
buzbee | 091cc40 | 2014-03-31 10:14:40 -0700 | [diff] [blame] | 632 | OpRegCopy(r_dest.GetHigh(), temp); |
Mark Mendell | ae427c3 | 2014-01-24 09:17:22 -0800 | [diff] [blame] | 633 | FreeTemp(temp); |
| 634 | } else { |
buzbee | 091cc40 | 2014-03-31 10:14:40 -0700 | [diff] [blame] | 635 | load2 = NewLIR5(opcode, r_dest.GetHighReg(), r_base.GetReg(), r_index.GetReg(), scale, |
Mark Mendell | ae427c3 | 2014-01-24 09:17:22 -0800 | [diff] [blame] | 636 | displacement + HIWORD_OFFSET); |
buzbee | 091cc40 | 2014-03-31 10:14:40 -0700 | [diff] [blame] | 637 | load = NewLIR5(opcode, r_dest.GetLowReg(), r_base.GetReg(), r_index.GetReg(), scale, |
Mark Mendell | ae427c3 | 2014-01-24 09:17:22 -0800 | [diff] [blame] | 638 | displacement + LOWORD_OFFSET); |
| 639 | } |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 640 | } else { |
buzbee | 091cc40 | 2014-03-31 10:14:40 -0700 | [diff] [blame] | 641 | if (r_dest.GetLow() == r_index) { |
Mark Mendell | ae427c3 | 2014-01-24 09:17:22 -0800 | [diff] [blame] | 642 | // We can't use either register for the first load. |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 643 | RegStorage temp = AllocTemp(); |
| 644 | load = NewLIR5(opcode, temp.GetReg(), r_base.GetReg(), r_index.GetReg(), scale, |
Mark Mendell | ae427c3 | 2014-01-24 09:17:22 -0800 | [diff] [blame] | 645 | displacement + LOWORD_OFFSET); |
buzbee | 091cc40 | 2014-03-31 10:14:40 -0700 | [diff] [blame] | 646 | load2 = NewLIR5(opcode, r_dest.GetHighReg(), r_base.GetReg(), r_index.GetReg(), scale, |
Mark Mendell | ae427c3 | 2014-01-24 09:17:22 -0800 | [diff] [blame] | 647 | displacement + HIWORD_OFFSET); |
buzbee | 091cc40 | 2014-03-31 10:14:40 -0700 | [diff] [blame] | 648 | OpRegCopy(r_dest.GetLow(), temp); |
Mark Mendell | ae427c3 | 2014-01-24 09:17:22 -0800 | [diff] [blame] | 649 | FreeTemp(temp); |
| 650 | } else { |
buzbee | 091cc40 | 2014-03-31 10:14:40 -0700 | [diff] [blame] | 651 | load = NewLIR5(opcode, r_dest.GetLowReg(), r_base.GetReg(), r_index.GetReg(), scale, |
Mark Mendell | ae427c3 | 2014-01-24 09:17:22 -0800 | [diff] [blame] | 652 | displacement + LOWORD_OFFSET); |
buzbee | 091cc40 | 2014-03-31 10:14:40 -0700 | [diff] [blame] | 653 | load2 = NewLIR5(opcode, r_dest.GetHighReg(), r_base.GetReg(), r_index.GetReg(), scale, |
Mark Mendell | ae427c3 | 2014-01-24 09:17:22 -0800 | [diff] [blame] | 654 | displacement + HIWORD_OFFSET); |
| 655 | } |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 656 | } |
| 657 | } |
| 658 | } |
| 659 | |
| 660 | return load; |
| 661 | } |
| 662 | |
| 663 | /* Load value from base + scaled index. */ |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 664 | LIR* X86Mir2Lir::LoadBaseIndexed(RegStorage r_base, RegStorage r_index, RegStorage r_dest, |
| 665 | int scale, OpSize size) { |
Vladimir Marko | 3bf7c60 | 2014-05-07 14:55:43 +0100 | [diff] [blame^] | 666 | return LoadBaseIndexedDisp(r_base, r_index, scale, 0, r_dest, size); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 667 | } |
| 668 | |
buzbee | 091cc40 | 2014-03-31 10:14:40 -0700 | [diff] [blame] | 669 | LIR* X86Mir2Lir::LoadBaseDisp(RegStorage r_base, int displacement, RegStorage r_dest, |
Vladimir Marko | 3bf7c60 | 2014-05-07 14:55:43 +0100 | [diff] [blame^] | 670 | OpSize size) { |
buzbee | 695d13a | 2014-04-19 13:32:20 -0700 | [diff] [blame] | 671 | // TODO: base this on target. |
| 672 | if (size == kWord) { |
| 673 | size = k32; |
| 674 | } |
buzbee | 091cc40 | 2014-03-31 10:14:40 -0700 | [diff] [blame] | 675 | return LoadBaseIndexedDisp(r_base, RegStorage::InvalidReg(), 0, displacement, r_dest, |
Vladimir Marko | 3bf7c60 | 2014-05-07 14:55:43 +0100 | [diff] [blame^] | 676 | size); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 677 | } |
| 678 | |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 679 | LIR* X86Mir2Lir::StoreBaseIndexedDisp(RegStorage r_base, RegStorage r_index, int scale, |
Vladimir Marko | 3bf7c60 | 2014-05-07 14:55:43 +0100 | [diff] [blame^] | 680 | int displacement, RegStorage r_src, OpSize size) { |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 681 | LIR *store = NULL; |
| 682 | LIR *store2 = NULL; |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 683 | bool is_array = r_index.Valid(); |
buzbee | 091cc40 | 2014-03-31 10:14:40 -0700 | [diff] [blame] | 684 | bool pair = r_src.IsPair(); |
| 685 | bool is64bit = (size == k64) || (size == kDouble); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 686 | X86OpCode opcode = kX86Nop; |
| 687 | switch (size) { |
buzbee | 695d13a | 2014-04-19 13:32:20 -0700 | [diff] [blame] | 688 | case k64: |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 689 | case kDouble: |
buzbee | 091cc40 | 2014-03-31 10:14:40 -0700 | [diff] [blame] | 690 | if (r_src.IsFloat()) { |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 691 | opcode = is_array ? kX86MovsdAR : kX86MovsdMR; |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 692 | } else { |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 693 | opcode = is_array ? kX86Mov32AR : kX86Mov32MR; |
| 694 | } |
| 695 | // TODO: double store is to unaligned address |
| 696 | DCHECK_EQ((displacement & 0x3), 0); |
| 697 | break; |
buzbee | 695d13a | 2014-04-19 13:32:20 -0700 | [diff] [blame] | 698 | case k32: |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 699 | case kSingle: |
buzbee | 695d13a | 2014-04-19 13:32:20 -0700 | [diff] [blame] | 700 | case kReference: |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 701 | opcode = is_array ? kX86Mov32AR : kX86Mov32MR; |
buzbee | 091cc40 | 2014-03-31 10:14:40 -0700 | [diff] [blame] | 702 | if (r_src.IsFloat()) { |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 703 | opcode = is_array ? kX86MovssAR : kX86MovssMR; |
buzbee | 091cc40 | 2014-03-31 10:14:40 -0700 | [diff] [blame] | 704 | DCHECK(r_src.IsSingle()); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 705 | } |
| 706 | DCHECK_EQ((displacement & 0x3), 0); |
| 707 | break; |
| 708 | case kUnsignedHalf: |
| 709 | case kSignedHalf: |
| 710 | opcode = is_array ? kX86Mov16AR : kX86Mov16MR; |
| 711 | DCHECK_EQ((displacement & 0x1), 0); |
| 712 | break; |
| 713 | case kUnsignedByte: |
| 714 | case kSignedByte: |
| 715 | opcode = is_array ? kX86Mov8AR : kX86Mov8MR; |
| 716 | break; |
| 717 | default: |
Bill Buzbee | 00e1ec6 | 2014-02-27 23:44:13 +0000 | [diff] [blame] | 718 | LOG(FATAL) << "Bad case in StoreBaseIndexedDispBody"; |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 719 | } |
| 720 | |
| 721 | if (!is_array) { |
| 722 | if (!pair) { |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 723 | store = NewLIR3(opcode, r_base.GetReg(), displacement + LOWORD_OFFSET, r_src.GetReg()); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 724 | } else { |
buzbee | 091cc40 | 2014-03-31 10:14:40 -0700 | [diff] [blame] | 725 | DCHECK(!r_src.IsFloat()); // Make sure we're not still using a pair here. |
| 726 | store = NewLIR3(opcode, r_base.GetReg(), displacement + LOWORD_OFFSET, r_src.GetLowReg()); |
| 727 | store2 = NewLIR3(opcode, r_base.GetReg(), displacement + HIWORD_OFFSET, r_src.GetHighReg()); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 728 | } |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 729 | if (r_base == rs_rX86_SP) { |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 730 | AnnotateDalvikRegAccess(store, (displacement + (pair ? LOWORD_OFFSET : 0)) >> 2, |
| 731 | false /* is_load */, is64bit); |
| 732 | if (pair) { |
| 733 | AnnotateDalvikRegAccess(store2, (displacement + HIWORD_OFFSET) >> 2, |
| 734 | false /* is_load */, is64bit); |
| 735 | } |
| 736 | } |
| 737 | } else { |
| 738 | if (!pair) { |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 739 | store = NewLIR5(opcode, r_base.GetReg(), r_index.GetReg(), scale, |
| 740 | displacement + LOWORD_OFFSET, r_src.GetReg()); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 741 | } else { |
buzbee | 091cc40 | 2014-03-31 10:14:40 -0700 | [diff] [blame] | 742 | DCHECK(!r_src.IsFloat()); // Make sure we're not still using a pair here. |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 743 | store = NewLIR5(opcode, r_base.GetReg(), r_index.GetReg(), scale, |
buzbee | 091cc40 | 2014-03-31 10:14:40 -0700 | [diff] [blame] | 744 | displacement + LOWORD_OFFSET, r_src.GetLowReg()); |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 745 | store2 = NewLIR5(opcode, r_base.GetReg(), r_index.GetReg(), scale, |
buzbee | 091cc40 | 2014-03-31 10:14:40 -0700 | [diff] [blame] | 746 | displacement + HIWORD_OFFSET, r_src.GetHighReg()); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 747 | } |
| 748 | } |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 749 | return store; |
| 750 | } |
| 751 | |
| 752 | /* store value base base + scaled index. */ |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 753 | LIR* X86Mir2Lir::StoreBaseIndexed(RegStorage r_base, RegStorage r_index, RegStorage r_src, |
Brian Carlstrom | 2ce745c | 2013-07-17 17:44:30 -0700 | [diff] [blame] | 754 | int scale, OpSize size) { |
Vladimir Marko | 3bf7c60 | 2014-05-07 14:55:43 +0100 | [diff] [blame^] | 755 | return StoreBaseIndexedDisp(r_base, r_index, scale, 0, r_src, size); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 756 | } |
| 757 | |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 758 | LIR* X86Mir2Lir::StoreBaseDisp(RegStorage r_base, int displacement, |
| 759 | RegStorage r_src, OpSize size) { |
buzbee | 695d13a | 2014-04-19 13:32:20 -0700 | [diff] [blame] | 760 | // TODO: base this on target. |
| 761 | if (size == kWord) { |
| 762 | size = k32; |
| 763 | } |
Vladimir Marko | 3bf7c60 | 2014-05-07 14:55:43 +0100 | [diff] [blame^] | 764 | return StoreBaseIndexedDisp(r_base, RegStorage::InvalidReg(), 0, displacement, r_src, size); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 765 | } |
| 766 | |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 767 | LIR* X86Mir2Lir::OpCmpMemImmBranch(ConditionCode cond, RegStorage temp_reg, RegStorage base_reg, |
Mark Mendell | 766e929 | 2014-01-27 07:55:47 -0800 | [diff] [blame] | 768 | int offset, int check_value, LIR* target) { |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 769 | NewLIR3(IS_SIMM8(check_value) ? kX86Cmp32MI8 : kX86Cmp32MI, base_reg.GetReg(), offset, |
Mark Mendell | 766e929 | 2014-01-27 07:55:47 -0800 | [diff] [blame] | 770 | check_value); |
| 771 | LIR* branch = OpCondBranch(cond, target); |
| 772 | return branch; |
| 773 | } |
| 774 | |
Mark Mendell | 67c39c4 | 2014-01-31 17:28:00 -0800 | [diff] [blame] | 775 | void X86Mir2Lir::AnalyzeMIR() { |
| 776 | // Assume we don't need a pointer to the base of the code. |
| 777 | cu_->NewTimingSplit("X86 MIR Analysis"); |
| 778 | store_method_addr_ = false; |
| 779 | |
| 780 | // Walk the MIR looking for interesting items. |
| 781 | PreOrderDfsIterator iter(mir_graph_); |
| 782 | BasicBlock* curr_bb = iter.Next(); |
| 783 | while (curr_bb != NULL) { |
| 784 | AnalyzeBB(curr_bb); |
| 785 | curr_bb = iter.Next(); |
| 786 | } |
| 787 | |
| 788 | // Did we need a pointer to the method code? |
| 789 | if (store_method_addr_) { |
| 790 | base_of_code_ = mir_graph_->GetNewCompilerTemp(kCompilerTempVR, false); |
| 791 | } else { |
| 792 | base_of_code_ = nullptr; |
| 793 | } |
| 794 | } |
| 795 | |
| 796 | void X86Mir2Lir::AnalyzeBB(BasicBlock * bb) { |
| 797 | if (bb->block_type == kDead) { |
| 798 | // Ignore dead blocks |
| 799 | return; |
| 800 | } |
| 801 | |
| 802 | for (MIR *mir = bb->first_mir_insn; mir != NULL; mir = mir->next) { |
| 803 | int opcode = mir->dalvikInsn.opcode; |
| 804 | if (opcode >= kMirOpFirst) { |
| 805 | AnalyzeExtendedMIR(opcode, bb, mir); |
| 806 | } else { |
| 807 | AnalyzeMIR(opcode, bb, mir); |
| 808 | } |
| 809 | } |
| 810 | } |
| 811 | |
| 812 | |
| 813 | void X86Mir2Lir::AnalyzeExtendedMIR(int opcode, BasicBlock * bb, MIR *mir) { |
| 814 | switch (opcode) { |
| 815 | // Instructions referencing doubles. |
| 816 | case kMirOpFusedCmplDouble: |
| 817 | case kMirOpFusedCmpgDouble: |
| 818 | AnalyzeFPInstruction(opcode, bb, mir); |
| 819 | break; |
| 820 | default: |
| 821 | // Ignore the rest. |
| 822 | break; |
| 823 | } |
| 824 | } |
| 825 | |
| 826 | void X86Mir2Lir::AnalyzeMIR(int opcode, BasicBlock * bb, MIR *mir) { |
| 827 | // Looking for |
| 828 | // - Do we need a pointer to the code (used for packed switches and double lits)? |
| 829 | |
| 830 | switch (opcode) { |
| 831 | // Instructions referencing doubles. |
| 832 | case Instruction::CMPL_DOUBLE: |
| 833 | case Instruction::CMPG_DOUBLE: |
| 834 | case Instruction::NEG_DOUBLE: |
| 835 | case Instruction::ADD_DOUBLE: |
| 836 | case Instruction::SUB_DOUBLE: |
| 837 | case Instruction::MUL_DOUBLE: |
| 838 | case Instruction::DIV_DOUBLE: |
| 839 | case Instruction::REM_DOUBLE: |
| 840 | case Instruction::ADD_DOUBLE_2ADDR: |
| 841 | case Instruction::SUB_DOUBLE_2ADDR: |
| 842 | case Instruction::MUL_DOUBLE_2ADDR: |
| 843 | case Instruction::DIV_DOUBLE_2ADDR: |
| 844 | case Instruction::REM_DOUBLE_2ADDR: |
| 845 | AnalyzeFPInstruction(opcode, bb, mir); |
| 846 | break; |
Mark Mendell | 55d0eac | 2014-02-06 11:02:52 -0800 | [diff] [blame] | 847 | |
Mark Mendell | 67c39c4 | 2014-01-31 17:28:00 -0800 | [diff] [blame] | 848 | // Packed switches and array fills need a pointer to the base of the method. |
| 849 | case Instruction::FILL_ARRAY_DATA: |
| 850 | case Instruction::PACKED_SWITCH: |
| 851 | store_method_addr_ = true; |
| 852 | break; |
| 853 | default: |
| 854 | // Other instructions are not interesting yet. |
| 855 | break; |
| 856 | } |
| 857 | } |
| 858 | |
| 859 | void X86Mir2Lir::AnalyzeFPInstruction(int opcode, BasicBlock * bb, MIR *mir) { |
| 860 | // Look at all the uses, and see if they are double constants. |
Jean Christophe Beyler | cc794c3 | 2014-05-02 09:34:13 -0700 | [diff] [blame] | 861 | uint64_t attrs = MIRGraph::GetDataFlowAttributes(static_cast<Instruction::Code>(opcode)); |
Mark Mendell | 67c39c4 | 2014-01-31 17:28:00 -0800 | [diff] [blame] | 862 | int next_sreg = 0; |
| 863 | if (attrs & DF_UA) { |
| 864 | if (attrs & DF_A_WIDE) { |
| 865 | AnalyzeDoubleUse(mir_graph_->GetSrcWide(mir, next_sreg)); |
| 866 | next_sreg += 2; |
| 867 | } else { |
| 868 | next_sreg++; |
| 869 | } |
| 870 | } |
| 871 | if (attrs & DF_UB) { |
| 872 | if (attrs & DF_B_WIDE) { |
| 873 | AnalyzeDoubleUse(mir_graph_->GetSrcWide(mir, next_sreg)); |
| 874 | next_sreg += 2; |
| 875 | } else { |
| 876 | next_sreg++; |
| 877 | } |
| 878 | } |
| 879 | if (attrs & DF_UC) { |
| 880 | if (attrs & DF_C_WIDE) { |
| 881 | AnalyzeDoubleUse(mir_graph_->GetSrcWide(mir, next_sreg)); |
| 882 | } |
| 883 | } |
| 884 | } |
| 885 | |
| 886 | void X86Mir2Lir::AnalyzeDoubleUse(RegLocation use) { |
| 887 | // If this is a double literal, we will want it in the literal pool. |
| 888 | if (use.is_const) { |
| 889 | store_method_addr_ = true; |
| 890 | } |
| 891 | } |
| 892 | |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 893 | } // namespace art |