Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2011 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 "compiler_internals.h" |
| 18 | #include "dex/dataflow_iterator-inl.h" |
| 19 | |
| 20 | namespace art { |
| 21 | |
| 22 | bool MIRGraph::SetFp(int index, bool is_fp) { |
| 23 | bool change = false; |
| 24 | if (is_fp && !reg_location_[index].fp) { |
| 25 | reg_location_[index].fp = true; |
| 26 | reg_location_[index].defined = true; |
| 27 | change = true; |
| 28 | } |
| 29 | return change; |
| 30 | } |
| 31 | |
buzbee | 28c2300 | 2013-09-07 09:12:27 -0700 | [diff] [blame] | 32 | bool MIRGraph::SetFp(int index) { |
| 33 | bool change = false; |
| 34 | if (!reg_location_[index].fp) { |
| 35 | reg_location_[index].fp = true; |
| 36 | reg_location_[index].defined = true; |
| 37 | change = true; |
| 38 | } |
| 39 | return change; |
| 40 | } |
| 41 | |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 42 | bool MIRGraph::SetCore(int index, bool is_core) { |
| 43 | bool change = false; |
| 44 | if (is_core && !reg_location_[index].defined) { |
| 45 | reg_location_[index].core = true; |
| 46 | reg_location_[index].defined = true; |
| 47 | change = true; |
| 48 | } |
| 49 | return change; |
| 50 | } |
| 51 | |
buzbee | 28c2300 | 2013-09-07 09:12:27 -0700 | [diff] [blame] | 52 | bool MIRGraph::SetCore(int index) { |
| 53 | bool change = false; |
| 54 | if (!reg_location_[index].defined) { |
| 55 | reg_location_[index].core = true; |
| 56 | reg_location_[index].defined = true; |
| 57 | change = true; |
| 58 | } |
| 59 | return change; |
| 60 | } |
| 61 | |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 62 | bool MIRGraph::SetRef(int index, bool is_ref) { |
| 63 | bool change = false; |
| 64 | if (is_ref && !reg_location_[index].defined) { |
| 65 | reg_location_[index].ref = true; |
| 66 | reg_location_[index].defined = true; |
| 67 | change = true; |
| 68 | } |
| 69 | return change; |
| 70 | } |
| 71 | |
buzbee | 28c2300 | 2013-09-07 09:12:27 -0700 | [diff] [blame] | 72 | bool MIRGraph::SetRef(int index) { |
| 73 | bool change = false; |
| 74 | if (!reg_location_[index].defined) { |
| 75 | reg_location_[index].ref = true; |
| 76 | reg_location_[index].defined = true; |
| 77 | change = true; |
| 78 | } |
| 79 | return change; |
| 80 | } |
| 81 | |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 82 | bool MIRGraph::SetWide(int index, bool is_wide) { |
| 83 | bool change = false; |
| 84 | if (is_wide && !reg_location_[index].wide) { |
| 85 | reg_location_[index].wide = true; |
| 86 | change = true; |
| 87 | } |
| 88 | return change; |
| 89 | } |
| 90 | |
buzbee | 28c2300 | 2013-09-07 09:12:27 -0700 | [diff] [blame] | 91 | bool MIRGraph::SetWide(int index) { |
| 92 | bool change = false; |
| 93 | if (!reg_location_[index].wide) { |
| 94 | reg_location_[index].wide = true; |
| 95 | change = true; |
| 96 | } |
| 97 | return change; |
| 98 | } |
| 99 | |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 100 | bool MIRGraph::SetHigh(int index, bool is_high) { |
| 101 | bool change = false; |
| 102 | if (is_high && !reg_location_[index].high_word) { |
| 103 | reg_location_[index].high_word = true; |
| 104 | change = true; |
| 105 | } |
| 106 | return change; |
| 107 | } |
| 108 | |
buzbee | 28c2300 | 2013-09-07 09:12:27 -0700 | [diff] [blame] | 109 | bool MIRGraph::SetHigh(int index) { |
| 110 | bool change = false; |
| 111 | if (!reg_location_[index].high_word) { |
| 112 | reg_location_[index].high_word = true; |
| 113 | change = true; |
| 114 | } |
| 115 | return change; |
| 116 | } |
| 117 | |
| 118 | |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 119 | /* |
| 120 | * Infer types and sizes. We don't need to track change on sizes, |
| 121 | * as it doesn't propagate. We're guaranteed at least one pass through |
| 122 | * the cfg. |
| 123 | */ |
buzbee | 1da1e2f | 2013-11-15 13:37:01 -0800 | [diff] [blame] | 124 | bool MIRGraph::InferTypeAndSize(BasicBlock* bb, MIR* mir, bool changed) { |
| 125 | SSARepresentation *ssa_rep = mir->ssa_rep; |
buzbee | 8c7a02a | 2014-06-14 12:33:09 -0700 | [diff] [blame] | 126 | |
| 127 | /* |
| 128 | * The dex bytecode definition does not explicitly outlaw the definition of the same |
| 129 | * virtual register to be used in both a 32-bit and 64-bit pair context. However, dx |
| 130 | * does not generate this pattern (at least recently). Further, in the next revision of |
| 131 | * dex, we will forbid this. To support the few cases in the wild, detect this pattern |
| 132 | * and punt to the interpreter. |
| 133 | */ |
| 134 | bool type_mismatch = false; |
| 135 | |
buzbee | 1da1e2f | 2013-11-15 13:37:01 -0800 | [diff] [blame] | 136 | if (ssa_rep) { |
Jean Christophe Beyler | cc794c3 | 2014-05-02 09:34:13 -0700 | [diff] [blame] | 137 | uint64_t attrs = GetDataFlowAttributes(mir); |
buzbee | 1da1e2f | 2013-11-15 13:37:01 -0800 | [diff] [blame] | 138 | const int* uses = ssa_rep->uses; |
| 139 | const int* defs = ssa_rep->defs; |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 140 | |
buzbee | 1da1e2f | 2013-11-15 13:37:01 -0800 | [diff] [blame] | 141 | // Handle defs |
| 142 | if (attrs & DF_DA) { |
| 143 | if (attrs & DF_CORE_A) { |
| 144 | changed |= SetCore(defs[0]); |
| 145 | } |
| 146 | if (attrs & DF_REF_A) { |
| 147 | changed |= SetRef(defs[0]); |
| 148 | } |
| 149 | if (attrs & DF_A_WIDE) { |
| 150 | reg_location_[defs[0]].wide = true; |
| 151 | reg_location_[defs[1]].wide = true; |
| 152 | reg_location_[defs[1]].high_word = true; |
| 153 | DCHECK_EQ(SRegToVReg(defs[0])+1, |
| 154 | SRegToVReg(defs[1])); |
| 155 | } |
| 156 | } |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 157 | |
buzbee | 8c7a02a | 2014-06-14 12:33:09 -0700 | [diff] [blame] | 158 | |
buzbee | 1da1e2f | 2013-11-15 13:37:01 -0800 | [diff] [blame] | 159 | // Handles uses |
| 160 | int next = 0; |
| 161 | if (attrs & DF_UA) { |
| 162 | if (attrs & DF_CORE_A) { |
| 163 | changed |= SetCore(uses[next]); |
| 164 | } |
| 165 | if (attrs & DF_REF_A) { |
| 166 | changed |= SetRef(uses[next]); |
| 167 | } |
| 168 | if (attrs & DF_A_WIDE) { |
| 169 | reg_location_[uses[next]].wide = true; |
| 170 | reg_location_[uses[next + 1]].wide = true; |
| 171 | reg_location_[uses[next + 1]].high_word = true; |
| 172 | DCHECK_EQ(SRegToVReg(uses[next])+1, |
| 173 | SRegToVReg(uses[next + 1])); |
| 174 | next += 2; |
| 175 | } else { |
buzbee | 8c7a02a | 2014-06-14 12:33:09 -0700 | [diff] [blame] | 176 | type_mismatch |= reg_location_[uses[next]].wide; |
buzbee | 1da1e2f | 2013-11-15 13:37:01 -0800 | [diff] [blame] | 177 | next++; |
| 178 | } |
| 179 | } |
| 180 | if (attrs & DF_UB) { |
| 181 | if (attrs & DF_CORE_B) { |
| 182 | changed |= SetCore(uses[next]); |
| 183 | } |
| 184 | if (attrs & DF_REF_B) { |
| 185 | changed |= SetRef(uses[next]); |
| 186 | } |
| 187 | if (attrs & DF_B_WIDE) { |
| 188 | reg_location_[uses[next]].wide = true; |
| 189 | reg_location_[uses[next + 1]].wide = true; |
| 190 | reg_location_[uses[next + 1]].high_word = true; |
| 191 | DCHECK_EQ(SRegToVReg(uses[next])+1, |
| 192 | SRegToVReg(uses[next + 1])); |
| 193 | next += 2; |
| 194 | } else { |
buzbee | 8c7a02a | 2014-06-14 12:33:09 -0700 | [diff] [blame] | 195 | type_mismatch |= reg_location_[uses[next]].wide; |
buzbee | 1da1e2f | 2013-11-15 13:37:01 -0800 | [diff] [blame] | 196 | next++; |
| 197 | } |
| 198 | } |
| 199 | if (attrs & DF_UC) { |
| 200 | if (attrs & DF_CORE_C) { |
| 201 | changed |= SetCore(uses[next]); |
| 202 | } |
| 203 | if (attrs & DF_REF_C) { |
| 204 | changed |= SetRef(uses[next]); |
| 205 | } |
| 206 | if (attrs & DF_C_WIDE) { |
| 207 | reg_location_[uses[next]].wide = true; |
| 208 | reg_location_[uses[next + 1]].wide = true; |
| 209 | reg_location_[uses[next + 1]].high_word = true; |
| 210 | DCHECK_EQ(SRegToVReg(uses[next])+1, |
| 211 | SRegToVReg(uses[next + 1])); |
buzbee | 8c7a02a | 2014-06-14 12:33:09 -0700 | [diff] [blame] | 212 | } else { |
| 213 | type_mismatch |= reg_location_[uses[next]].wide; |
buzbee | 1da1e2f | 2013-11-15 13:37:01 -0800 | [diff] [blame] | 214 | } |
| 215 | } |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 216 | |
buzbee | 1da1e2f | 2013-11-15 13:37:01 -0800 | [diff] [blame] | 217 | // Special-case return handling |
| 218 | if ((mir->dalvikInsn.opcode == Instruction::RETURN) || |
| 219 | (mir->dalvikInsn.opcode == Instruction::RETURN_WIDE) || |
| 220 | (mir->dalvikInsn.opcode == Instruction::RETURN_OBJECT)) { |
| 221 | switch (cu_->shorty[0]) { |
| 222 | case 'I': |
buzbee | 8c7a02a | 2014-06-14 12:33:09 -0700 | [diff] [blame] | 223 | type_mismatch |= reg_location_[uses[0]].wide; |
buzbee | 1da1e2f | 2013-11-15 13:37:01 -0800 | [diff] [blame] | 224 | changed |= SetCore(uses[0]); |
| 225 | break; |
| 226 | case 'J': |
| 227 | changed |= SetCore(uses[0]); |
| 228 | changed |= SetCore(uses[1]); |
| 229 | reg_location_[uses[0]].wide = true; |
| 230 | reg_location_[uses[1]].wide = true; |
| 231 | reg_location_[uses[1]].high_word = true; |
| 232 | break; |
| 233 | case 'F': |
buzbee | 8c7a02a | 2014-06-14 12:33:09 -0700 | [diff] [blame] | 234 | type_mismatch |= reg_location_[uses[0]].wide; |
buzbee | 1da1e2f | 2013-11-15 13:37:01 -0800 | [diff] [blame] | 235 | changed |= SetFp(uses[0]); |
| 236 | break; |
| 237 | case 'D': |
| 238 | changed |= SetFp(uses[0]); |
| 239 | changed |= SetFp(uses[1]); |
| 240 | reg_location_[uses[0]].wide = true; |
| 241 | reg_location_[uses[1]].wide = true; |
| 242 | reg_location_[uses[1]].high_word = true; |
| 243 | break; |
| 244 | case 'L': |
buzbee | 8c7a02a | 2014-06-14 12:33:09 -0700 | [diff] [blame] | 245 | type_mismatch |= reg_location_[uses[0]].wide; |
buzbee | 1da1e2f | 2013-11-15 13:37:01 -0800 | [diff] [blame] | 246 | changed |= SetRef(uses[0]); |
| 247 | break; |
| 248 | default: break; |
| 249 | } |
| 250 | } |
| 251 | |
| 252 | // Special-case handling for format 35c/3rc invokes |
| 253 | Instruction::Code opcode = mir->dalvikInsn.opcode; |
Jean Christophe Beyler | 2ab40eb | 2014-06-02 09:03:14 -0700 | [diff] [blame] | 254 | int flags = MIR::DecodedInstruction::IsPseudoMirOp(opcode) ? |
Jean Christophe Beyler | fb0ea2d | 2014-07-29 13:20:42 -0700 | [diff] [blame] | 255 | 0 : mir->dalvikInsn.FlagsOf(); |
buzbee | 1da1e2f | 2013-11-15 13:37:01 -0800 | [diff] [blame] | 256 | if ((flags & Instruction::kInvoke) && |
| 257 | (attrs & (DF_FORMAT_35C | DF_FORMAT_3RC))) { |
| 258 | DCHECK_EQ(next, 0); |
| 259 | int target_idx = mir->dalvikInsn.vB; |
| 260 | const char* shorty = GetShortyFromTargetIdx(target_idx); |
| 261 | // Handle result type if floating point |
| 262 | if ((shorty[0] == 'F') || (shorty[0] == 'D')) { |
| 263 | MIR* move_result_mir = FindMoveResult(bb, mir); |
| 264 | // Result might not be used at all, so no move-result |
| 265 | if (move_result_mir && (move_result_mir->dalvikInsn.opcode != |
| 266 | Instruction::MOVE_RESULT_OBJECT)) { |
| 267 | SSARepresentation* tgt_rep = move_result_mir->ssa_rep; |
| 268 | DCHECK(tgt_rep != NULL); |
| 269 | tgt_rep->fp_def[0] = true; |
| 270 | changed |= SetFp(tgt_rep->defs[0]); |
| 271 | if (shorty[0] == 'D') { |
| 272 | tgt_rep->fp_def[1] = true; |
| 273 | changed |= SetFp(tgt_rep->defs[1]); |
| 274 | } |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 275 | } |
| 276 | } |
buzbee | 1da1e2f | 2013-11-15 13:37:01 -0800 | [diff] [blame] | 277 | int num_uses = mir->dalvikInsn.vA; |
| 278 | // If this is a non-static invoke, mark implicit "this" |
Vladimir Marko | 321b987 | 2014-11-24 16:33:51 +0000 | [diff] [blame] | 279 | if (!IsInstructionInvokeStatic(mir->dalvikInsn.opcode)) { |
buzbee | 1da1e2f | 2013-11-15 13:37:01 -0800 | [diff] [blame] | 280 | reg_location_[uses[next]].defined = true; |
| 281 | reg_location_[uses[next]].ref = true; |
buzbee | 8c7a02a | 2014-06-14 12:33:09 -0700 | [diff] [blame] | 282 | type_mismatch |= reg_location_[uses[next]].wide; |
buzbee | 1da1e2f | 2013-11-15 13:37:01 -0800 | [diff] [blame] | 283 | next++; |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 284 | } |
buzbee | 1da1e2f | 2013-11-15 13:37:01 -0800 | [diff] [blame] | 285 | uint32_t cpos = 1; |
| 286 | if (strlen(shorty) > 1) { |
| 287 | for (int i = next; i < num_uses;) { |
| 288 | DCHECK_LT(cpos, strlen(shorty)); |
| 289 | switch (shorty[cpos++]) { |
| 290 | case 'D': |
| 291 | ssa_rep->fp_use[i] = true; |
| 292 | ssa_rep->fp_use[i+1] = true; |
| 293 | reg_location_[uses[i]].wide = true; |
| 294 | reg_location_[uses[i+1]].wide = true; |
| 295 | reg_location_[uses[i+1]].high_word = true; |
| 296 | DCHECK_EQ(SRegToVReg(uses[i])+1, SRegToVReg(uses[i+1])); |
| 297 | i++; |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 298 | break; |
| 299 | case 'J': |
buzbee | 1da1e2f | 2013-11-15 13:37:01 -0800 | [diff] [blame] | 300 | reg_location_[uses[i]].wide = true; |
| 301 | reg_location_[uses[i+1]].wide = true; |
| 302 | reg_location_[uses[i+1]].high_word = true; |
| 303 | DCHECK_EQ(SRegToVReg(uses[i])+1, SRegToVReg(uses[i+1])); |
| 304 | changed |= SetCore(uses[i]); |
| 305 | i++; |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 306 | break; |
| 307 | case 'F': |
buzbee | 8c7a02a | 2014-06-14 12:33:09 -0700 | [diff] [blame] | 308 | type_mismatch |= reg_location_[uses[i]].wide; |
buzbee | 1da1e2f | 2013-11-15 13:37:01 -0800 | [diff] [blame] | 309 | ssa_rep->fp_use[i] = true; |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 310 | break; |
| 311 | case 'L': |
buzbee | 8c7a02a | 2014-06-14 12:33:09 -0700 | [diff] [blame] | 312 | type_mismatch |= reg_location_[uses[i]].wide; |
buzbee | 1da1e2f | 2013-11-15 13:37:01 -0800 | [diff] [blame] | 313 | changed |= SetRef(uses[i]); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 314 | break; |
buzbee | 1da1e2f | 2013-11-15 13:37:01 -0800 | [diff] [blame] | 315 | default: |
buzbee | 8c7a02a | 2014-06-14 12:33:09 -0700 | [diff] [blame] | 316 | type_mismatch |= reg_location_[uses[i]].wide; |
buzbee | 1da1e2f | 2013-11-15 13:37:01 -0800 | [diff] [blame] | 317 | changed |= SetCore(uses[i]); |
| 318 | break; |
| 319 | } |
| 320 | i++; |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 321 | } |
| 322 | } |
buzbee | 1da1e2f | 2013-11-15 13:37:01 -0800 | [diff] [blame] | 323 | } |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 324 | |
buzbee | 1da1e2f | 2013-11-15 13:37:01 -0800 | [diff] [blame] | 325 | for (int i = 0; ssa_rep->fp_use && i< ssa_rep->num_uses; i++) { |
Vladimir Marko | 55fff04 | 2014-07-10 12:42:52 +0100 | [diff] [blame] | 326 | if (ssa_rep->fp_use[i]) { |
buzbee | 1da1e2f | 2013-11-15 13:37:01 -0800 | [diff] [blame] | 327 | changed |= SetFp(uses[i]); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 328 | } |
Vladimir Marko | 55fff04 | 2014-07-10 12:42:52 +0100 | [diff] [blame] | 329 | } |
buzbee | 1da1e2f | 2013-11-15 13:37:01 -0800 | [diff] [blame] | 330 | for (int i = 0; ssa_rep->fp_def && i< ssa_rep->num_defs; i++) { |
Vladimir Marko | 55fff04 | 2014-07-10 12:42:52 +0100 | [diff] [blame] | 331 | if (ssa_rep->fp_def[i]) { |
buzbee | 1da1e2f | 2013-11-15 13:37:01 -0800 | [diff] [blame] | 332 | changed |= SetFp(defs[i]); |
| 333 | } |
Vladimir Marko | 55fff04 | 2014-07-10 12:42:52 +0100 | [diff] [blame] | 334 | } |
buzbee | 1da1e2f | 2013-11-15 13:37:01 -0800 | [diff] [blame] | 335 | // Special-case handling for moves & Phi |
| 336 | if (attrs & (DF_IS_MOVE | DF_NULL_TRANSFER_N)) { |
| 337 | /* |
| 338 | * If any of our inputs or outputs is defined, set all. |
| 339 | * Some ugliness related to Phi nodes and wide values. |
| 340 | * The Phi set will include all low words or all high |
| 341 | * words, so we have to treat them specially. |
| 342 | */ |
buzbee | 35ba7f3 | 2014-05-31 08:59:01 -0700 | [diff] [blame] | 343 | bool is_phi = (static_cast<int>(mir->dalvikInsn.opcode) == kMirOpPhi); |
buzbee | 1da1e2f | 2013-11-15 13:37:01 -0800 | [diff] [blame] | 344 | RegLocation rl_temp = reg_location_[defs[0]]; |
| 345 | bool defined_fp = rl_temp.defined && rl_temp.fp; |
| 346 | bool defined_core = rl_temp.defined && rl_temp.core; |
| 347 | bool defined_ref = rl_temp.defined && rl_temp.ref; |
| 348 | bool is_wide = rl_temp.wide || ((attrs & DF_A_WIDE) != 0); |
| 349 | bool is_high = is_phi && rl_temp.wide && rl_temp.high_word; |
| 350 | for (int i = 0; i < ssa_rep->num_uses; i++) { |
| 351 | rl_temp = reg_location_[uses[i]]; |
| 352 | defined_fp |= rl_temp.defined && rl_temp.fp; |
| 353 | defined_core |= rl_temp.defined && rl_temp.core; |
| 354 | defined_ref |= rl_temp.defined && rl_temp.ref; |
| 355 | is_wide |= rl_temp.wide; |
| 356 | is_high |= is_phi && rl_temp.wide && rl_temp.high_word; |
| 357 | } |
| 358 | /* |
| 359 | * We don't normally expect to see a Dalvik register definition used both as a |
| 360 | * floating point and core value, though technically it could happen with constants. |
| 361 | * Until we have proper typing, detect this situation and disable register promotion |
| 362 | * (which relies on the distinction between core a fp usages). |
| 363 | */ |
| 364 | if ((defined_fp && (defined_core | defined_ref)) && |
| 365 | ((cu_->disable_opt & (1 << kPromoteRegs)) == 0)) { |
| 366 | LOG(WARNING) << PrettyMethod(cu_->method_idx, *cu_->dex_file) |
| 367 | << " op at block " << bb->id |
| 368 | << " has both fp and core/ref uses for same def."; |
| 369 | cu_->disable_opt |= (1 << kPromoteRegs); |
| 370 | } |
| 371 | changed |= SetFp(defs[0], defined_fp); |
| 372 | changed |= SetCore(defs[0], defined_core); |
| 373 | changed |= SetRef(defs[0], defined_ref); |
| 374 | changed |= SetWide(defs[0], is_wide); |
| 375 | changed |= SetHigh(defs[0], is_high); |
| 376 | if (attrs & DF_A_WIDE) { |
| 377 | changed |= SetWide(defs[1]); |
| 378 | changed |= SetHigh(defs[1]); |
| 379 | } |
Stephen Kyle | 8fe0e35 | 2014-10-16 15:02:42 +0100 | [diff] [blame] | 380 | |
| 381 | bool has_ins = (GetNumOfInVRs() > 0); |
| 382 | |
buzbee | 1da1e2f | 2013-11-15 13:37:01 -0800 | [diff] [blame] | 383 | for (int i = 0; i < ssa_rep->num_uses; i++) { |
Stephen Kyle | 8fe0e35 | 2014-10-16 15:02:42 +0100 | [diff] [blame] | 384 | if (has_ins && IsInVReg(uses[i])) { |
| 385 | // NB: The SSA name for the first def of an in-reg will be the same as |
| 386 | // the reg's actual name. |
| 387 | if (!reg_location_[uses[i]].fp && defined_fp) { |
| 388 | // If we were about to infer that this first def of an in-reg is a float |
| 389 | // when it wasn't previously (because float/int is set during SSA initialization), |
| 390 | // do not allow this to happen. |
| 391 | continue; |
| 392 | } |
| 393 | } |
buzbee | 1da1e2f | 2013-11-15 13:37:01 -0800 | [diff] [blame] | 394 | changed |= SetFp(uses[i], defined_fp); |
| 395 | changed |= SetCore(uses[i], defined_core); |
| 396 | changed |= SetRef(uses[i], defined_ref); |
| 397 | changed |= SetWide(uses[i], is_wide); |
| 398 | changed |= SetHigh(uses[i], is_high); |
| 399 | } |
| 400 | if (attrs & DF_A_WIDE) { |
| 401 | DCHECK_EQ(ssa_rep->num_uses, 2); |
| 402 | changed |= SetWide(uses[1]); |
| 403 | changed |= SetHigh(uses[1]); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 404 | } |
| 405 | } |
| 406 | } |
buzbee | 8c7a02a | 2014-06-14 12:33:09 -0700 | [diff] [blame] | 407 | if (type_mismatch) { |
| 408 | LOG(WARNING) << "Deprecated dex type mismatch, interpreting " |
| 409 | << PrettyMethod(cu_->method_idx, *cu_->dex_file); |
| 410 | LOG(INFO) << "@ 0x" << std::hex << mir->offset; |
| 411 | SetPuntToInterpreter(true); |
| 412 | } |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 413 | return changed; |
| 414 | } |
| 415 | |
Razvan A Lupusoru | 8d0d03e | 2014-06-06 17:04:52 -0700 | [diff] [blame] | 416 | static const char* storage_name[] = {" Frame ", "PhysReg", " CompilerTemp "}; |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 417 | |
Brian Carlstrom | 2ce745c | 2013-07-17 17:44:30 -0700 | [diff] [blame] | 418 | void MIRGraph::DumpRegLocTable(RegLocation* table, int count) { |
Andreas Gampe | 53c913b | 2014-08-12 23:19:23 -0700 | [diff] [blame] | 419 | for (int i = 0; i < count; i++) { |
| 420 | LOG(INFO) << StringPrintf("Loc[%02d] : %s, %c %c %c %c %c %c 0x%04x S%d", |
| 421 | table[i].orig_sreg, storage_name[table[i].location], |
| 422 | table[i].wide ? 'W' : 'N', table[i].defined ? 'D' : 'U', |
| 423 | table[i].fp ? 'F' : table[i].ref ? 'R' :'C', |
| 424 | table[i].is_const ? 'c' : 'n', |
| 425 | table[i].high_word ? 'H' : 'L', table[i].home ? 'h' : 't', |
| 426 | table[i].reg.GetRawBits(), |
| 427 | table[i].s_reg_low); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 428 | } |
| 429 | } |
| 430 | |
Bill Buzbee | 00e1ec6 | 2014-02-27 23:44:13 +0000 | [diff] [blame] | 431 | // FIXME - will likely need to revisit all uses of this. |
buzbee | 091cc40 | 2014-03-31 10:14:40 -0700 | [diff] [blame] | 432 | static const RegLocation fresh_loc = {kLocDalvikFrame, 0, 0, 0, 0, 0, 0, 0, 0, |
Bill Buzbee | 00e1ec6 | 2014-02-27 23:44:13 +0000 | [diff] [blame] | 433 | RegStorage(), INVALID_SREG, INVALID_SREG}; |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 434 | |
buzbee | 1da1e2f | 2013-11-15 13:37:01 -0800 | [diff] [blame] | 435 | void MIRGraph::InitRegLocations() { |
Razvan A Lupusoru | 8d0d03e | 2014-06-06 17:04:52 -0700 | [diff] [blame] | 436 | // Allocate the location map. We also include the maximum possible temps because |
| 437 | // the temp allocation initializes reg location as well (in order to deal with |
| 438 | // case when it will be called after this pass). |
Razvan A Lupusoru | da7a69b | 2014-01-08 15:09:50 -0800 | [diff] [blame] | 439 | int max_regs = GetNumSSARegs() + GetMaxPossibleCompilerTemps(); |
| 440 | RegLocation* loc = static_cast<RegLocation*>(arena_->Alloc(max_regs * sizeof(*loc), |
Vladimir Marko | 83cc7ae | 2014-02-12 18:02:05 +0000 | [diff] [blame] | 441 | kArenaAllocRegAlloc)); |
Brian Carlstrom | 38f85e4 | 2013-07-18 14:45:22 -0700 | [diff] [blame] | 442 | for (int i = 0; i < GetNumSSARegs(); i++) { |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 443 | loc[i] = fresh_loc; |
| 444 | loc[i].s_reg_low = i; |
| 445 | loc[i].is_const = is_constant_v_->IsBitSet(i); |
Jean Christophe Beyler | 1ceea7e | 2014-04-15 16:18:48 -0700 | [diff] [blame] | 446 | loc[i].wide = false; |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 447 | } |
| 448 | |
buzbee | f2c3e56 | 2014-05-29 12:37:25 -0700 | [diff] [blame] | 449 | /* Treat Method* as a normal reference */ |
Razvan A Lupusoru | 8d0d03e | 2014-06-06 17:04:52 -0700 | [diff] [blame] | 450 | int method_sreg = GetMethodSReg(); |
| 451 | loc[method_sreg].ref = true; |
| 452 | loc[method_sreg].location = kLocCompilerTemp; |
| 453 | loc[method_sreg].defined = true; |
buzbee | f2c3e56 | 2014-05-29 12:37:25 -0700 | [diff] [blame] | 454 | |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 455 | reg_location_ = loc; |
| 456 | |
Razvan A Lupusoru | 8d0d03e | 2014-06-06 17:04:52 -0700 | [diff] [blame] | 457 | int num_regs = GetNumOfCodeVRs(); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 458 | |
| 459 | /* Add types of incoming arguments based on signature */ |
Razvan A Lupusoru | 8d0d03e | 2014-06-06 17:04:52 -0700 | [diff] [blame] | 460 | int num_ins = GetNumOfInVRs(); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 461 | if (num_ins > 0) { |
| 462 | int s_reg = num_regs - num_ins; |
| 463 | if ((cu_->access_flags & kAccStatic) == 0) { |
| 464 | // For non-static, skip past "this" |
| 465 | reg_location_[s_reg].defined = true; |
| 466 | reg_location_[s_reg].ref = true; |
| 467 | s_reg++; |
| 468 | } |
| 469 | const char* shorty = cu_->shorty; |
| 470 | int shorty_len = strlen(shorty); |
| 471 | for (int i = 1; i < shorty_len; i++) { |
| 472 | switch (shorty[i]) { |
| 473 | case 'D': |
| 474 | reg_location_[s_reg].wide = true; |
| 475 | reg_location_[s_reg+1].high_word = true; |
| 476 | reg_location_[s_reg+1].fp = true; |
| 477 | DCHECK_EQ(SRegToVReg(s_reg)+1, SRegToVReg(s_reg+1)); |
| 478 | reg_location_[s_reg].fp = true; |
| 479 | reg_location_[s_reg].defined = true; |
| 480 | s_reg++; |
| 481 | break; |
| 482 | case 'J': |
| 483 | reg_location_[s_reg].wide = true; |
| 484 | reg_location_[s_reg+1].high_word = true; |
| 485 | DCHECK_EQ(SRegToVReg(s_reg)+1, SRegToVReg(s_reg+1)); |
| 486 | reg_location_[s_reg].core = true; |
| 487 | reg_location_[s_reg].defined = true; |
| 488 | s_reg++; |
| 489 | break; |
| 490 | case 'F': |
| 491 | reg_location_[s_reg].fp = true; |
| 492 | reg_location_[s_reg].defined = true; |
| 493 | break; |
| 494 | case 'L': |
| 495 | reg_location_[s_reg].ref = true; |
| 496 | reg_location_[s_reg].defined = true; |
| 497 | break; |
| 498 | default: |
| 499 | reg_location_[s_reg].core = true; |
| 500 | reg_location_[s_reg].defined = true; |
| 501 | break; |
| 502 | } |
| 503 | s_reg++; |
| 504 | } |
| 505 | } |
buzbee | 1da1e2f | 2013-11-15 13:37:01 -0800 | [diff] [blame] | 506 | } |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 507 | |
buzbee | 1da1e2f | 2013-11-15 13:37:01 -0800 | [diff] [blame] | 508 | /* |
| 509 | * Set the s_reg_low field to refer to the pre-SSA name of the |
| 510 | * base Dalvik virtual register. Once we add a better register |
| 511 | * allocator, remove this remapping. |
| 512 | */ |
| 513 | void MIRGraph::RemapRegLocations() { |
Brian Carlstrom | 38f85e4 | 2013-07-18 14:45:22 -0700 | [diff] [blame] | 514 | for (int i = 0; i < GetNumSSARegs(); i++) { |
Razvan A Lupusoru | 8d0d03e | 2014-06-06 17:04:52 -0700 | [diff] [blame] | 515 | int orig_sreg = reg_location_[i].s_reg_low; |
| 516 | reg_location_[i].orig_sreg = orig_sreg; |
| 517 | reg_location_[i].s_reg_low = SRegToVReg(orig_sreg); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 518 | } |
| 519 | } |
| 520 | |
| 521 | } // namespace art |