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