buzbee | ee17e0a | 2013-07-31 10:47:37 -0700 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright (C) 2013 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 "dataflow_iterator-inl.h" |
| 19 | |
| 20 | namespace art { |
| 21 | |
| 22 | // Instruction characteristics used to statically identify computation-intensive methods. |
| 23 | const uint32_t MIRGraph::analysis_attributes_[kMirOpLast] = { |
| 24 | // 00 NOP |
| 25 | AN_NONE, |
| 26 | |
| 27 | // 01 MOVE vA, vB |
| 28 | AN_MOVE, |
| 29 | |
| 30 | // 02 MOVE_FROM16 vAA, vBBBB |
| 31 | AN_MOVE, |
| 32 | |
| 33 | // 03 MOVE_16 vAAAA, vBBBB |
| 34 | AN_MOVE, |
| 35 | |
| 36 | // 04 MOVE_WIDE vA, vB |
| 37 | AN_MOVE, |
| 38 | |
| 39 | // 05 MOVE_WIDE_FROM16 vAA, vBBBB |
| 40 | AN_MOVE, |
| 41 | |
| 42 | // 06 MOVE_WIDE_16 vAAAA, vBBBB |
| 43 | AN_MOVE, |
| 44 | |
| 45 | // 07 MOVE_OBJECT vA, vB |
| 46 | AN_MOVE, |
| 47 | |
| 48 | // 08 MOVE_OBJECT_FROM16 vAA, vBBBB |
| 49 | AN_MOVE, |
| 50 | |
| 51 | // 09 MOVE_OBJECT_16 vAAAA, vBBBB |
| 52 | AN_MOVE, |
| 53 | |
| 54 | // 0A MOVE_RESULT vAA |
| 55 | AN_MOVE, |
| 56 | |
| 57 | // 0B MOVE_RESULT_WIDE vAA |
| 58 | AN_MOVE, |
| 59 | |
| 60 | // 0C MOVE_RESULT_OBJECT vAA |
| 61 | AN_MOVE, |
| 62 | |
| 63 | // 0D MOVE_EXCEPTION vAA |
| 64 | AN_MOVE, |
| 65 | |
| 66 | // 0E RETURN_VOID |
| 67 | AN_BRANCH, |
| 68 | |
| 69 | // 0F RETURN vAA |
| 70 | AN_BRANCH, |
| 71 | |
| 72 | // 10 RETURN_WIDE vAA |
| 73 | AN_BRANCH, |
| 74 | |
| 75 | // 11 RETURN_OBJECT vAA |
| 76 | AN_BRANCH, |
| 77 | |
| 78 | // 12 CONST_4 vA, #+B |
| 79 | AN_SIMPLECONST, |
| 80 | |
| 81 | // 13 CONST_16 vAA, #+BBBB |
| 82 | AN_SIMPLECONST, |
| 83 | |
| 84 | // 14 CONST vAA, #+BBBBBBBB |
| 85 | AN_SIMPLECONST, |
| 86 | |
| 87 | // 15 CONST_HIGH16 VAA, #+BBBB0000 |
| 88 | AN_SIMPLECONST, |
| 89 | |
| 90 | // 16 CONST_WIDE_16 vAA, #+BBBB |
| 91 | AN_SIMPLECONST, |
| 92 | |
| 93 | // 17 CONST_WIDE_32 vAA, #+BBBBBBBB |
| 94 | AN_SIMPLECONST, |
| 95 | |
| 96 | // 18 CONST_WIDE vAA, #+BBBBBBBBBBBBBBBB |
| 97 | AN_SIMPLECONST, |
| 98 | |
| 99 | // 19 CONST_WIDE_HIGH16 vAA, #+BBBB000000000000 |
| 100 | AN_SIMPLECONST, |
| 101 | |
| 102 | // 1A CONST_STRING vAA, string@BBBB |
| 103 | AN_NONE, |
| 104 | |
| 105 | // 1B CONST_STRING_JUMBO vAA, string@BBBBBBBB |
| 106 | AN_NONE, |
| 107 | |
| 108 | // 1C CONST_CLASS vAA, type@BBBB |
| 109 | AN_NONE, |
| 110 | |
| 111 | // 1D MONITOR_ENTER vAA |
| 112 | AN_NONE, |
| 113 | |
| 114 | // 1E MONITOR_EXIT vAA |
| 115 | AN_NONE, |
| 116 | |
| 117 | // 1F CHK_CAST vAA, type@BBBB |
| 118 | AN_NONE, |
| 119 | |
| 120 | // 20 INSTANCE_OF vA, vB, type@CCCC |
| 121 | AN_NONE, |
| 122 | |
| 123 | // 21 ARRAY_LENGTH vA, vB |
| 124 | AN_ARRAYOP, |
| 125 | |
| 126 | // 22 NEW_INSTANCE vAA, type@BBBB |
| 127 | AN_HEAVYWEIGHT, |
| 128 | |
| 129 | // 23 NEW_ARRAY vA, vB, type@CCCC |
| 130 | AN_HEAVYWEIGHT, |
| 131 | |
| 132 | // 24 FILLED_NEW_ARRAY {vD, vE, vF, vG, vA} |
| 133 | AN_HEAVYWEIGHT, |
| 134 | |
| 135 | // 25 FILLED_NEW_ARRAY_RANGE {vCCCC .. vNNNN}, type@BBBB |
| 136 | AN_HEAVYWEIGHT, |
| 137 | |
| 138 | // 26 FILL_ARRAY_DATA vAA, +BBBBBBBB |
| 139 | AN_NONE, |
| 140 | |
| 141 | // 27 THROW vAA |
| 142 | AN_HEAVYWEIGHT | AN_BRANCH, |
| 143 | |
| 144 | // 28 GOTO |
| 145 | AN_BRANCH, |
| 146 | |
| 147 | // 29 GOTO_16 |
| 148 | AN_BRANCH, |
| 149 | |
| 150 | // 2A GOTO_32 |
| 151 | AN_BRANCH, |
| 152 | |
| 153 | // 2B PACKED_SWITCH vAA, +BBBBBBBB |
| 154 | AN_NONE, |
| 155 | |
| 156 | // 2C SPARSE_SWITCH vAA, +BBBBBBBB |
| 157 | AN_NONE, |
| 158 | |
| 159 | // 2D CMPL_FLOAT vAA, vBB, vCC |
| 160 | AN_MATH | AN_FP | AN_SINGLE, |
| 161 | |
| 162 | // 2E CMPG_FLOAT vAA, vBB, vCC |
| 163 | AN_MATH | AN_FP | AN_SINGLE, |
| 164 | |
| 165 | // 2F CMPL_DOUBLE vAA, vBB, vCC |
| 166 | AN_MATH | AN_FP | AN_DOUBLE, |
| 167 | |
| 168 | // 30 CMPG_DOUBLE vAA, vBB, vCC |
| 169 | AN_MATH | AN_FP | AN_DOUBLE, |
| 170 | |
| 171 | // 31 CMP_LONG vAA, vBB, vCC |
| 172 | AN_MATH | AN_LONG, |
| 173 | |
| 174 | // 32 IF_EQ vA, vB, +CCCC |
| 175 | AN_MATH | AN_BRANCH | AN_INT, |
| 176 | |
| 177 | // 33 IF_NE vA, vB, +CCCC |
| 178 | AN_MATH | AN_BRANCH | AN_INT, |
| 179 | |
| 180 | // 34 IF_LT vA, vB, +CCCC |
| 181 | AN_MATH | AN_BRANCH | AN_INT, |
| 182 | |
| 183 | // 35 IF_GE vA, vB, +CCCC |
| 184 | AN_MATH | AN_BRANCH | AN_INT, |
| 185 | |
| 186 | // 36 IF_GT vA, vB, +CCCC |
| 187 | AN_MATH | AN_BRANCH | AN_INT, |
| 188 | |
| 189 | // 37 IF_LE vA, vB, +CCCC |
| 190 | AN_MATH | AN_BRANCH | AN_INT, |
| 191 | |
| 192 | // 38 IF_EQZ vAA, +BBBB |
| 193 | AN_MATH | AN_BRANCH | AN_INT, |
| 194 | |
| 195 | // 39 IF_NEZ vAA, +BBBB |
| 196 | AN_MATH | AN_BRANCH | AN_INT, |
| 197 | |
| 198 | // 3A IF_LTZ vAA, +BBBB |
| 199 | AN_MATH | AN_BRANCH | AN_INT, |
| 200 | |
| 201 | // 3B IF_GEZ vAA, +BBBB |
| 202 | AN_MATH | AN_BRANCH | AN_INT, |
| 203 | |
| 204 | // 3C IF_GTZ vAA, +BBBB |
| 205 | AN_MATH | AN_BRANCH | AN_INT, |
| 206 | |
| 207 | // 3D IF_LEZ vAA, +BBBB |
| 208 | AN_MATH | AN_BRANCH | AN_INT, |
| 209 | |
| 210 | // 3E UNUSED_3E |
| 211 | AN_NONE, |
| 212 | |
| 213 | // 3F UNUSED_3F |
| 214 | AN_NONE, |
| 215 | |
| 216 | // 40 UNUSED_40 |
| 217 | AN_NONE, |
| 218 | |
| 219 | // 41 UNUSED_41 |
| 220 | AN_NONE, |
| 221 | |
| 222 | // 42 UNUSED_42 |
| 223 | AN_NONE, |
| 224 | |
| 225 | // 43 UNUSED_43 |
| 226 | AN_NONE, |
| 227 | |
| 228 | // 44 AGET vAA, vBB, vCC |
| 229 | AN_ARRAYOP, |
| 230 | |
| 231 | // 45 AGET_WIDE vAA, vBB, vCC |
| 232 | AN_ARRAYOP, |
| 233 | |
| 234 | // 46 AGET_OBJECT vAA, vBB, vCC |
| 235 | AN_ARRAYOP, |
| 236 | |
| 237 | // 47 AGET_BOOLEAN vAA, vBB, vCC |
| 238 | AN_ARRAYOP, |
| 239 | |
| 240 | // 48 AGET_BYTE vAA, vBB, vCC |
| 241 | AN_ARRAYOP, |
| 242 | |
| 243 | // 49 AGET_CHAR vAA, vBB, vCC |
| 244 | AN_ARRAYOP, |
| 245 | |
| 246 | // 4A AGET_SHORT vAA, vBB, vCC |
| 247 | AN_ARRAYOP, |
| 248 | |
| 249 | // 4B APUT vAA, vBB, vCC |
| 250 | AN_ARRAYOP, |
| 251 | |
| 252 | // 4C APUT_WIDE vAA, vBB, vCC |
| 253 | AN_ARRAYOP, |
| 254 | |
| 255 | // 4D APUT_OBJECT vAA, vBB, vCC |
| 256 | AN_ARRAYOP, |
| 257 | |
| 258 | // 4E APUT_BOOLEAN vAA, vBB, vCC |
| 259 | AN_ARRAYOP, |
| 260 | |
| 261 | // 4F APUT_BYTE vAA, vBB, vCC |
| 262 | AN_ARRAYOP, |
| 263 | |
| 264 | // 50 APUT_CHAR vAA, vBB, vCC |
| 265 | AN_ARRAYOP, |
| 266 | |
| 267 | // 51 APUT_SHORT vAA, vBB, vCC |
| 268 | AN_ARRAYOP, |
| 269 | |
| 270 | // 52 IGET vA, vB, field@CCCC |
| 271 | AN_NONE, |
| 272 | |
| 273 | // 53 IGET_WIDE vA, vB, field@CCCC |
| 274 | AN_NONE, |
| 275 | |
| 276 | // 54 IGET_OBJECT vA, vB, field@CCCC |
| 277 | AN_NONE, |
| 278 | |
| 279 | // 55 IGET_BOOLEAN vA, vB, field@CCCC |
| 280 | AN_NONE, |
| 281 | |
| 282 | // 56 IGET_BYTE vA, vB, field@CCCC |
| 283 | AN_NONE, |
| 284 | |
| 285 | // 57 IGET_CHAR vA, vB, field@CCCC |
| 286 | AN_NONE, |
| 287 | |
| 288 | // 58 IGET_SHORT vA, vB, field@CCCC |
| 289 | AN_NONE, |
| 290 | |
| 291 | // 59 IPUT vA, vB, field@CCCC |
| 292 | AN_NONE, |
| 293 | |
| 294 | // 5A IPUT_WIDE vA, vB, field@CCCC |
| 295 | AN_NONE, |
| 296 | |
| 297 | // 5B IPUT_OBJECT vA, vB, field@CCCC |
| 298 | AN_NONE, |
| 299 | |
| 300 | // 5C IPUT_BOOLEAN vA, vB, field@CCCC |
| 301 | AN_NONE, |
| 302 | |
| 303 | // 5D IPUT_BYTE vA, vB, field@CCCC |
| 304 | AN_NONE, |
| 305 | |
| 306 | // 5E IPUT_CHAR vA, vB, field@CCCC |
| 307 | AN_NONE, |
| 308 | |
| 309 | // 5F IPUT_SHORT vA, vB, field@CCCC |
| 310 | AN_NONE, |
| 311 | |
| 312 | // 60 SGET vAA, field@BBBB |
| 313 | AN_NONE, |
| 314 | |
| 315 | // 61 SGET_WIDE vAA, field@BBBB |
| 316 | AN_NONE, |
| 317 | |
| 318 | // 62 SGET_OBJECT vAA, field@BBBB |
| 319 | AN_NONE, |
| 320 | |
| 321 | // 63 SGET_BOOLEAN vAA, field@BBBB |
| 322 | AN_NONE, |
| 323 | |
| 324 | // 64 SGET_BYTE vAA, field@BBBB |
| 325 | AN_NONE, |
| 326 | |
| 327 | // 65 SGET_CHAR vAA, field@BBBB |
| 328 | AN_NONE, |
| 329 | |
| 330 | // 66 SGET_SHORT vAA, field@BBBB |
| 331 | AN_NONE, |
| 332 | |
| 333 | // 67 SPUT vAA, field@BBBB |
| 334 | AN_NONE, |
| 335 | |
| 336 | // 68 SPUT_WIDE vAA, field@BBBB |
| 337 | AN_NONE, |
| 338 | |
| 339 | // 69 SPUT_OBJECT vAA, field@BBBB |
| 340 | AN_NONE, |
| 341 | |
| 342 | // 6A SPUT_BOOLEAN vAA, field@BBBB |
| 343 | AN_NONE, |
| 344 | |
| 345 | // 6B SPUT_BYTE vAA, field@BBBB |
| 346 | AN_NONE, |
| 347 | |
| 348 | // 6C SPUT_CHAR vAA, field@BBBB |
| 349 | AN_NONE, |
| 350 | |
| 351 | // 6D SPUT_SHORT vAA, field@BBBB |
| 352 | AN_NONE, |
| 353 | |
| 354 | // 6E INVOKE_VIRTUAL {vD, vE, vF, vG, vA} |
| 355 | AN_INVOKE | AN_HEAVYWEIGHT, |
| 356 | |
| 357 | // 6F INVOKE_SUPER {vD, vE, vF, vG, vA} |
| 358 | AN_INVOKE | AN_HEAVYWEIGHT, |
| 359 | |
| 360 | // 70 INVOKE_DIRECT {vD, vE, vF, vG, vA} |
| 361 | AN_INVOKE | AN_HEAVYWEIGHT, |
| 362 | |
| 363 | // 71 INVOKE_STATIC {vD, vE, vF, vG, vA} |
| 364 | AN_INVOKE | AN_HEAVYWEIGHT, |
| 365 | |
| 366 | // 72 INVOKE_INTERFACE {vD, vE, vF, vG, vA} |
| 367 | AN_INVOKE | AN_HEAVYWEIGHT, |
| 368 | |
| 369 | // 73 UNUSED_73 |
| 370 | AN_NONE, |
| 371 | |
| 372 | // 74 INVOKE_VIRTUAL_RANGE {vCCCC .. vNNNN} |
| 373 | AN_INVOKE | AN_HEAVYWEIGHT, |
| 374 | |
| 375 | // 75 INVOKE_SUPER_RANGE {vCCCC .. vNNNN} |
| 376 | AN_INVOKE | AN_HEAVYWEIGHT, |
| 377 | |
| 378 | // 76 INVOKE_DIRECT_RANGE {vCCCC .. vNNNN} |
| 379 | AN_INVOKE | AN_HEAVYWEIGHT, |
| 380 | |
| 381 | // 77 INVOKE_STATIC_RANGE {vCCCC .. vNNNN} |
| 382 | AN_INVOKE | AN_HEAVYWEIGHT, |
| 383 | |
| 384 | // 78 INVOKE_INTERFACE_RANGE {vCCCC .. vNNNN} |
| 385 | AN_INVOKE | AN_HEAVYWEIGHT, |
| 386 | |
| 387 | // 79 UNUSED_79 |
| 388 | AN_NONE, |
| 389 | |
| 390 | // 7A UNUSED_7A |
| 391 | AN_NONE, |
| 392 | |
| 393 | // 7B NEG_INT vA, vB |
| 394 | AN_MATH | AN_INT, |
| 395 | |
| 396 | // 7C NOT_INT vA, vB |
| 397 | AN_MATH | AN_INT, |
| 398 | |
| 399 | // 7D NEG_LONG vA, vB |
| 400 | AN_MATH | AN_LONG, |
| 401 | |
| 402 | // 7E NOT_LONG vA, vB |
| 403 | AN_MATH | AN_LONG, |
| 404 | |
| 405 | // 7F NEG_FLOAT vA, vB |
| 406 | AN_MATH | AN_FP | AN_SINGLE, |
| 407 | |
| 408 | // 80 NEG_DOUBLE vA, vB |
| 409 | AN_MATH | AN_FP | AN_DOUBLE, |
| 410 | |
| 411 | // 81 INT_TO_LONG vA, vB |
| 412 | AN_MATH | AN_INT | AN_LONG, |
| 413 | |
| 414 | // 82 INT_TO_FLOAT vA, vB |
| 415 | AN_MATH | AN_FP | AN_INT | AN_SINGLE, |
| 416 | |
| 417 | // 83 INT_TO_DOUBLE vA, vB |
| 418 | AN_MATH | AN_FP | AN_INT | AN_DOUBLE, |
| 419 | |
| 420 | // 84 LONG_TO_INT vA, vB |
| 421 | AN_MATH | AN_INT | AN_LONG, |
| 422 | |
| 423 | // 85 LONG_TO_FLOAT vA, vB |
| 424 | AN_MATH | AN_FP | AN_LONG | AN_SINGLE, |
| 425 | |
| 426 | // 86 LONG_TO_DOUBLE vA, vB |
| 427 | AN_MATH | AN_FP | AN_LONG | AN_DOUBLE, |
| 428 | |
| 429 | // 87 FLOAT_TO_INT vA, vB |
| 430 | AN_MATH | AN_FP | AN_INT | AN_SINGLE, |
| 431 | |
| 432 | // 88 FLOAT_TO_LONG vA, vB |
| 433 | AN_MATH | AN_FP | AN_LONG | AN_SINGLE, |
| 434 | |
| 435 | // 89 FLOAT_TO_DOUBLE vA, vB |
| 436 | AN_MATH | AN_FP | AN_SINGLE | AN_DOUBLE, |
| 437 | |
| 438 | // 8A DOUBLE_TO_INT vA, vB |
| 439 | AN_MATH | AN_FP | AN_INT | AN_DOUBLE, |
| 440 | |
| 441 | // 8B DOUBLE_TO_LONG vA, vB |
| 442 | AN_MATH | AN_FP | AN_LONG | AN_DOUBLE, |
| 443 | |
| 444 | // 8C DOUBLE_TO_FLOAT vA, vB |
| 445 | AN_MATH | AN_FP | AN_SINGLE | AN_DOUBLE, |
| 446 | |
| 447 | // 8D INT_TO_BYTE vA, vB |
| 448 | AN_MATH | AN_INT, |
| 449 | |
| 450 | // 8E INT_TO_CHAR vA, vB |
| 451 | AN_MATH | AN_INT, |
| 452 | |
| 453 | // 8F INT_TO_SHORT vA, vB |
| 454 | AN_MATH | AN_INT, |
| 455 | |
| 456 | // 90 ADD_INT vAA, vBB, vCC |
| 457 | AN_MATH | AN_INT, |
| 458 | |
| 459 | // 91 SUB_INT vAA, vBB, vCC |
| 460 | AN_MATH | AN_INT, |
| 461 | |
| 462 | // 92 MUL_INT vAA, vBB, vCC |
| 463 | AN_MATH | AN_INT, |
| 464 | |
| 465 | // 93 DIV_INT vAA, vBB, vCC |
| 466 | AN_MATH | AN_INT, |
| 467 | |
| 468 | // 94 REM_INT vAA, vBB, vCC |
| 469 | AN_MATH | AN_INT, |
| 470 | |
| 471 | // 95 AND_INT vAA, vBB, vCC |
| 472 | AN_MATH | AN_INT, |
| 473 | |
| 474 | // 96 OR_INT vAA, vBB, vCC |
| 475 | AN_MATH | AN_INT, |
| 476 | |
| 477 | // 97 XOR_INT vAA, vBB, vCC |
| 478 | AN_MATH | AN_INT, |
| 479 | |
| 480 | // 98 SHL_INT vAA, vBB, vCC |
| 481 | AN_MATH | AN_INT, |
| 482 | |
| 483 | // 99 SHR_INT vAA, vBB, vCC |
| 484 | AN_MATH | AN_INT, |
| 485 | |
| 486 | // 9A USHR_INT vAA, vBB, vCC |
| 487 | AN_MATH | AN_INT, |
| 488 | |
| 489 | // 9B ADD_LONG vAA, vBB, vCC |
| 490 | AN_MATH | AN_LONG, |
| 491 | |
| 492 | // 9C SUB_LONG vAA, vBB, vCC |
| 493 | AN_MATH | AN_LONG, |
| 494 | |
| 495 | // 9D MUL_LONG vAA, vBB, vCC |
| 496 | AN_MATH | AN_LONG, |
| 497 | |
| 498 | // 9E DIV_LONG vAA, vBB, vCC |
| 499 | AN_MATH | AN_LONG, |
| 500 | |
| 501 | // 9F REM_LONG vAA, vBB, vCC |
| 502 | AN_MATH | AN_LONG, |
| 503 | |
| 504 | // A0 AND_LONG vAA, vBB, vCC |
| 505 | AN_MATH | AN_LONG, |
| 506 | |
| 507 | // A1 OR_LONG vAA, vBB, vCC |
| 508 | AN_MATH | AN_LONG, |
| 509 | |
| 510 | // A2 XOR_LONG vAA, vBB, vCC |
| 511 | AN_MATH | AN_LONG, |
| 512 | |
| 513 | // A3 SHL_LONG vAA, vBB, vCC |
| 514 | AN_MATH | AN_LONG, |
| 515 | |
| 516 | // A4 SHR_LONG vAA, vBB, vCC |
| 517 | AN_MATH | AN_LONG, |
| 518 | |
| 519 | // A5 USHR_LONG vAA, vBB, vCC |
| 520 | AN_MATH | AN_LONG, |
| 521 | |
| 522 | // A6 ADD_FLOAT vAA, vBB, vCC |
| 523 | AN_MATH | AN_FP | AN_SINGLE, |
| 524 | |
| 525 | // A7 SUB_FLOAT vAA, vBB, vCC |
| 526 | AN_MATH | AN_FP | AN_SINGLE, |
| 527 | |
| 528 | // A8 MUL_FLOAT vAA, vBB, vCC |
| 529 | AN_MATH | AN_FP | AN_SINGLE, |
| 530 | |
| 531 | // A9 DIV_FLOAT vAA, vBB, vCC |
| 532 | AN_MATH | AN_FP | AN_SINGLE, |
| 533 | |
| 534 | // AA REM_FLOAT vAA, vBB, vCC |
| 535 | AN_MATH | AN_FP | AN_SINGLE, |
| 536 | |
| 537 | // AB ADD_DOUBLE vAA, vBB, vCC |
| 538 | AN_MATH | AN_FP | AN_DOUBLE, |
| 539 | |
| 540 | // AC SUB_DOUBLE vAA, vBB, vCC |
| 541 | AN_MATH | AN_FP | AN_DOUBLE, |
| 542 | |
| 543 | // AD MUL_DOUBLE vAA, vBB, vCC |
| 544 | AN_MATH | AN_FP | AN_DOUBLE, |
| 545 | |
| 546 | // AE DIV_DOUBLE vAA, vBB, vCC |
| 547 | AN_MATH | AN_FP | AN_DOUBLE, |
| 548 | |
| 549 | // AF REM_DOUBLE vAA, vBB, vCC |
| 550 | AN_MATH | AN_FP | AN_DOUBLE, |
| 551 | |
| 552 | // B0 ADD_INT_2ADDR vA, vB |
| 553 | AN_MATH | AN_INT, |
| 554 | |
| 555 | // B1 SUB_INT_2ADDR vA, vB |
| 556 | AN_MATH | AN_INT, |
| 557 | |
| 558 | // B2 MUL_INT_2ADDR vA, vB |
| 559 | AN_MATH | AN_INT, |
| 560 | |
| 561 | // B3 DIV_INT_2ADDR vA, vB |
| 562 | AN_MATH | AN_INT, |
| 563 | |
| 564 | // B4 REM_INT_2ADDR vA, vB |
| 565 | AN_MATH | AN_INT, |
| 566 | |
| 567 | // B5 AND_INT_2ADDR vA, vB |
| 568 | AN_MATH | AN_INT, |
| 569 | |
| 570 | // B6 OR_INT_2ADDR vA, vB |
| 571 | AN_MATH | AN_INT, |
| 572 | |
| 573 | // B7 XOR_INT_2ADDR vA, vB |
| 574 | AN_MATH | AN_INT, |
| 575 | |
| 576 | // B8 SHL_INT_2ADDR vA, vB |
| 577 | AN_MATH | AN_INT, |
| 578 | |
| 579 | // B9 SHR_INT_2ADDR vA, vB |
| 580 | AN_MATH | AN_INT, |
| 581 | |
| 582 | // BA USHR_INT_2ADDR vA, vB |
| 583 | AN_MATH | AN_INT, |
| 584 | |
| 585 | // BB ADD_LONG_2ADDR vA, vB |
| 586 | AN_MATH | AN_LONG, |
| 587 | |
| 588 | // BC SUB_LONG_2ADDR vA, vB |
| 589 | AN_MATH | AN_LONG, |
| 590 | |
| 591 | // BD MUL_LONG_2ADDR vA, vB |
| 592 | AN_MATH | AN_LONG, |
| 593 | |
| 594 | // BE DIV_LONG_2ADDR vA, vB |
| 595 | AN_MATH | AN_LONG, |
| 596 | |
| 597 | // BF REM_LONG_2ADDR vA, vB |
| 598 | AN_MATH | AN_LONG, |
| 599 | |
| 600 | // C0 AND_LONG_2ADDR vA, vB |
| 601 | AN_MATH | AN_LONG, |
| 602 | |
| 603 | // C1 OR_LONG_2ADDR vA, vB |
| 604 | AN_MATH | AN_LONG, |
| 605 | |
| 606 | // C2 XOR_LONG_2ADDR vA, vB |
| 607 | AN_MATH | AN_LONG, |
| 608 | |
| 609 | // C3 SHL_LONG_2ADDR vA, vB |
| 610 | AN_MATH | AN_LONG, |
| 611 | |
| 612 | // C4 SHR_LONG_2ADDR vA, vB |
| 613 | AN_MATH | AN_LONG, |
| 614 | |
| 615 | // C5 USHR_LONG_2ADDR vA, vB |
| 616 | AN_MATH | AN_LONG, |
| 617 | |
| 618 | // C6 ADD_FLOAT_2ADDR vA, vB |
| 619 | AN_MATH | AN_FP | AN_SINGLE, |
| 620 | |
| 621 | // C7 SUB_FLOAT_2ADDR vA, vB |
| 622 | AN_MATH | AN_FP | AN_SINGLE, |
| 623 | |
| 624 | // C8 MUL_FLOAT_2ADDR vA, vB |
| 625 | AN_MATH | AN_FP | AN_SINGLE, |
| 626 | |
| 627 | // C9 DIV_FLOAT_2ADDR vA, vB |
| 628 | AN_MATH | AN_FP | AN_SINGLE, |
| 629 | |
| 630 | // CA REM_FLOAT_2ADDR vA, vB |
| 631 | AN_MATH | AN_FP | AN_SINGLE, |
| 632 | |
| 633 | // CB ADD_DOUBLE_2ADDR vA, vB |
| 634 | AN_MATH | AN_FP | AN_DOUBLE, |
| 635 | |
| 636 | // CC SUB_DOUBLE_2ADDR vA, vB |
| 637 | AN_MATH | AN_FP | AN_DOUBLE, |
| 638 | |
| 639 | // CD MUL_DOUBLE_2ADDR vA, vB |
| 640 | AN_MATH | AN_FP | AN_DOUBLE, |
| 641 | |
| 642 | // CE DIV_DOUBLE_2ADDR vA, vB |
| 643 | AN_MATH | AN_FP | AN_DOUBLE, |
| 644 | |
| 645 | // CF REM_DOUBLE_2ADDR vA, vB |
| 646 | AN_MATH | AN_FP | AN_DOUBLE, |
| 647 | |
| 648 | // D0 ADD_INT_LIT16 vA, vB, #+CCCC |
| 649 | AN_MATH | AN_INT, |
| 650 | |
| 651 | // D1 RSUB_INT vA, vB, #+CCCC |
| 652 | AN_MATH | AN_INT, |
| 653 | |
| 654 | // D2 MUL_INT_LIT16 vA, vB, #+CCCC |
| 655 | AN_MATH | AN_INT, |
| 656 | |
| 657 | // D3 DIV_INT_LIT16 vA, vB, #+CCCC |
| 658 | AN_MATH | AN_INT, |
| 659 | |
| 660 | // D4 REM_INT_LIT16 vA, vB, #+CCCC |
| 661 | AN_MATH | AN_INT, |
| 662 | |
| 663 | // D5 AND_INT_LIT16 vA, vB, #+CCCC |
| 664 | AN_MATH | AN_INT, |
| 665 | |
| 666 | // D6 OR_INT_LIT16 vA, vB, #+CCCC |
| 667 | AN_MATH | AN_INT, |
| 668 | |
| 669 | // D7 XOR_INT_LIT16 vA, vB, #+CCCC |
| 670 | AN_MATH | AN_INT, |
| 671 | |
| 672 | // D8 ADD_INT_LIT8 vAA, vBB, #+CC |
| 673 | AN_MATH | AN_INT, |
| 674 | |
| 675 | // D9 RSUB_INT_LIT8 vAA, vBB, #+CC |
| 676 | AN_MATH | AN_INT, |
| 677 | |
| 678 | // DA MUL_INT_LIT8 vAA, vBB, #+CC |
| 679 | AN_MATH | AN_INT, |
| 680 | |
| 681 | // DB DIV_INT_LIT8 vAA, vBB, #+CC |
| 682 | AN_MATH | AN_INT, |
| 683 | |
| 684 | // DC REM_INT_LIT8 vAA, vBB, #+CC |
| 685 | AN_MATH | AN_INT, |
| 686 | |
| 687 | // DD AND_INT_LIT8 vAA, vBB, #+CC |
| 688 | AN_MATH | AN_INT, |
| 689 | |
| 690 | // DE OR_INT_LIT8 vAA, vBB, #+CC |
| 691 | AN_MATH | AN_INT, |
| 692 | |
| 693 | // DF XOR_INT_LIT8 vAA, vBB, #+CC |
| 694 | AN_MATH | AN_INT, |
| 695 | |
| 696 | // E0 SHL_INT_LIT8 vAA, vBB, #+CC |
| 697 | AN_MATH | AN_INT, |
| 698 | |
| 699 | // E1 SHR_INT_LIT8 vAA, vBB, #+CC |
| 700 | AN_MATH | AN_INT, |
| 701 | |
| 702 | // E2 USHR_INT_LIT8 vAA, vBB, #+CC |
| 703 | AN_MATH | AN_INT, |
| 704 | |
| 705 | // E3 IGET_VOLATILE |
| 706 | AN_NONE, |
| 707 | |
| 708 | // E4 IPUT_VOLATILE |
| 709 | AN_NONE, |
| 710 | |
| 711 | // E5 SGET_VOLATILE |
| 712 | AN_NONE, |
| 713 | |
| 714 | // E6 SPUT_VOLATILE |
| 715 | AN_NONE, |
| 716 | |
| 717 | // E7 IGET_OBJECT_VOLATILE |
| 718 | AN_NONE, |
| 719 | |
| 720 | // E8 IGET_WIDE_VOLATILE |
| 721 | AN_NONE, |
| 722 | |
| 723 | // E9 IPUT_WIDE_VOLATILE |
| 724 | AN_NONE, |
| 725 | |
| 726 | // EA SGET_WIDE_VOLATILE |
| 727 | AN_NONE, |
| 728 | |
| 729 | // EB SPUT_WIDE_VOLATILE |
| 730 | AN_NONE, |
| 731 | |
| 732 | // EC BREAKPOINT |
| 733 | AN_NONE, |
| 734 | |
| 735 | // ED THROW_VERIFICATION_ERROR |
| 736 | AN_HEAVYWEIGHT | AN_BRANCH, |
| 737 | |
| 738 | // EE EXECUTE_INLINE |
| 739 | AN_NONE, |
| 740 | |
| 741 | // EF EXECUTE_INLINE_RANGE |
| 742 | AN_NONE, |
| 743 | |
| 744 | // F0 INVOKE_OBJECT_INIT_RANGE |
| 745 | AN_INVOKE | AN_HEAVYWEIGHT, |
| 746 | |
| 747 | // F1 RETURN_VOID_BARRIER |
| 748 | AN_BRANCH, |
| 749 | |
| 750 | // F2 IGET_QUICK |
| 751 | AN_NONE, |
| 752 | |
| 753 | // F3 IGET_WIDE_QUICK |
| 754 | AN_NONE, |
| 755 | |
| 756 | // F4 IGET_OBJECT_QUICK |
| 757 | AN_NONE, |
| 758 | |
| 759 | // F5 IPUT_QUICK |
| 760 | AN_NONE, |
| 761 | |
| 762 | // F6 IPUT_WIDE_QUICK |
| 763 | AN_NONE, |
| 764 | |
| 765 | // F7 IPUT_OBJECT_QUICK |
| 766 | AN_NONE, |
| 767 | |
| 768 | // F8 INVOKE_VIRTUAL_QUICK |
| 769 | AN_INVOKE | AN_HEAVYWEIGHT, |
| 770 | |
| 771 | // F9 INVOKE_VIRTUAL_QUICK_RANGE |
| 772 | AN_INVOKE | AN_HEAVYWEIGHT, |
| 773 | |
| 774 | // FA INVOKE_SUPER_QUICK |
| 775 | AN_INVOKE | AN_HEAVYWEIGHT, |
| 776 | |
| 777 | // FB INVOKE_SUPER_QUICK_RANGE |
| 778 | AN_INVOKE | AN_HEAVYWEIGHT, |
| 779 | |
| 780 | // FC IPUT_OBJECT_VOLATILE |
| 781 | AN_NONE, |
| 782 | |
| 783 | // FD SGET_OBJECT_VOLATILE |
| 784 | AN_NONE, |
| 785 | |
| 786 | // FE SPUT_OBJECT_VOLATILE |
| 787 | AN_NONE, |
| 788 | |
| 789 | // FF UNUSED_FF |
| 790 | AN_NONE, |
| 791 | |
| 792 | // Beginning of extended MIR opcodes |
| 793 | // 100 MIR_PHI |
| 794 | AN_NONE, |
| 795 | |
| 796 | // 101 MIR_COPY |
| 797 | AN_NONE, |
| 798 | |
| 799 | // 102 MIR_FUSED_CMPL_FLOAT |
| 800 | AN_NONE, |
| 801 | |
| 802 | // 103 MIR_FUSED_CMPG_FLOAT |
| 803 | AN_NONE, |
| 804 | |
| 805 | // 104 MIR_FUSED_CMPL_DOUBLE |
| 806 | AN_NONE, |
| 807 | |
| 808 | // 105 MIR_FUSED_CMPG_DOUBLE |
| 809 | AN_NONE, |
| 810 | |
| 811 | // 106 MIR_FUSED_CMP_LONG |
| 812 | AN_NONE, |
| 813 | |
| 814 | // 107 MIR_NOP |
| 815 | AN_NONE, |
| 816 | |
| 817 | // 108 MIR_NULL_CHECK |
| 818 | AN_NONE, |
| 819 | |
| 820 | // 109 MIR_RANGE_CHECK |
| 821 | AN_NONE, |
| 822 | |
| 823 | // 110 MIR_DIV_ZERO_CHECK |
| 824 | AN_NONE, |
| 825 | |
| 826 | // 111 MIR_CHECK |
| 827 | AN_NONE, |
| 828 | |
| 829 | // 112 MIR_CHECKPART2 |
| 830 | AN_NONE, |
| 831 | |
| 832 | // 113 MIR_SELECT |
| 833 | AN_NONE, |
| 834 | }; |
| 835 | |
| 836 | struct MethodStats { |
| 837 | int dex_instructions; |
| 838 | int math_ops; |
| 839 | int fp_ops; |
| 840 | int array_ops; |
| 841 | int branch_ops; |
| 842 | int heavyweight_ops; |
| 843 | bool has_computational_loop; |
| 844 | float math_ratio; |
| 845 | float fp_ratio; |
| 846 | float array_ratio; |
| 847 | float branch_ratio; |
| 848 | float heavyweight_ratio; |
| 849 | }; |
| 850 | |
| 851 | void MIRGraph::AnalyzeBlock(BasicBlock* bb, MethodStats* stats) { |
| 852 | if (bb->visited || (bb->block_type != kDalvikByteCode)) { |
| 853 | return; |
| 854 | } |
| 855 | bool computational_block = true; |
| 856 | bool has_math = false; |
| 857 | /* |
| 858 | * For the purposes of this scan, we want to treat the set of basic blocks broken |
| 859 | * by an exception edge as a single basic block. We'll scan forward along the fallthrough |
| 860 | * edges until we reach an explicit branch or return. |
| 861 | */ |
| 862 | BasicBlock* ending_bb = bb; |
| 863 | if (ending_bb->last_mir_insn != NULL) { |
| 864 | uint32_t ending_flags = analysis_attributes_[ending_bb->last_mir_insn->dalvikInsn.opcode]; |
| 865 | while ((ending_flags & AN_BRANCH) == 0) { |
| 866 | ending_bb = ending_bb->fall_through; |
| 867 | ending_flags = analysis_attributes_[ending_bb->last_mir_insn->dalvikInsn.opcode]; |
| 868 | } |
| 869 | } |
| 870 | /* |
| 871 | * Ideally, we'd weight the operations by loop nesting level, but to do so we'd |
| 872 | * first need to do some expensive loop detection - and the point of this is to make |
| 873 | * an informed guess before investing in computation. However, we can cheaply detect |
| 874 | * many simple loop forms without having to do full dataflow analysis. |
| 875 | */ |
| 876 | int loop_scale_factor = 1; |
| 877 | // Simple for and while loops |
| 878 | if ((ending_bb->taken != NULL) && (ending_bb->fall_through == NULL)) { |
| 879 | if ((ending_bb->taken->taken == bb) || (ending_bb->taken->fall_through == bb)) { |
| 880 | loop_scale_factor = 25; |
| 881 | } |
| 882 | } |
| 883 | // Simple do-while loop |
| 884 | if ((ending_bb->taken != NULL) && (ending_bb->taken == bb)) { |
| 885 | loop_scale_factor = 25; |
| 886 | } |
| 887 | |
| 888 | BasicBlock* tbb = bb; |
| 889 | bool done = false; |
| 890 | while (!done) { |
| 891 | tbb->visited = true; |
| 892 | for (MIR* mir = tbb->first_mir_insn; mir != NULL; mir = mir->next) { |
| 893 | if (static_cast<uint32_t>(mir->dalvikInsn.opcode) >= kMirOpFirst) { |
| 894 | // Skip any MIR pseudo-op. |
| 895 | continue; |
| 896 | } |
| 897 | uint32_t flags = analysis_attributes_[mir->dalvikInsn.opcode]; |
| 898 | stats->dex_instructions += loop_scale_factor; |
| 899 | if ((flags & AN_BRANCH) == 0) { |
| 900 | computational_block &= ((flags & AN_COMPUTATIONAL) != 0); |
| 901 | } else { |
| 902 | stats->branch_ops += loop_scale_factor; |
| 903 | } |
| 904 | if ((flags & AN_MATH) != 0) { |
| 905 | stats->math_ops += loop_scale_factor; |
| 906 | has_math = true; |
| 907 | } |
| 908 | if ((flags & AN_FP) != 0) { |
| 909 | stats->fp_ops += loop_scale_factor; |
| 910 | } |
| 911 | if ((flags & AN_ARRAYOP) != 0) { |
| 912 | stats->array_ops += loop_scale_factor; |
| 913 | } |
| 914 | if ((flags & AN_HEAVYWEIGHT) != 0) { |
| 915 | stats->heavyweight_ops += loop_scale_factor; |
| 916 | } |
| 917 | } |
| 918 | if (tbb == ending_bb) { |
| 919 | done = true; |
| 920 | } else { |
| 921 | tbb = tbb->fall_through; |
| 922 | } |
| 923 | } |
| 924 | if (has_math && computational_block && (loop_scale_factor > 1)) { |
| 925 | stats->has_computational_loop = true; |
| 926 | } |
| 927 | } |
| 928 | |
| 929 | bool MIRGraph::ComputeSkipCompilation(MethodStats* stats, bool skip_default) { |
| 930 | float count = stats->dex_instructions; |
| 931 | stats->math_ratio = stats->math_ops / count; |
| 932 | stats->fp_ratio = stats->fp_ops / count; |
| 933 | stats->branch_ratio = stats->branch_ops / count; |
| 934 | stats->array_ratio = stats->array_ops / count; |
| 935 | stats->heavyweight_ratio = stats->heavyweight_ops / count; |
| 936 | |
| 937 | if (cu_->enable_debug & (1 << kDebugShowFilterStats)) { |
| 938 | LOG(INFO) << "STATS " << stats->dex_instructions << ", math:" |
| 939 | << stats->math_ratio << ", fp:" |
| 940 | << stats->fp_ratio << ", br:" |
| 941 | << stats->branch_ratio << ", hw:" |
| 942 | << stats-> heavyweight_ratio << ", arr:" |
| 943 | << stats->array_ratio << ", hot:" |
| 944 | << stats->has_computational_loop << ", " |
| 945 | << PrettyMethod(cu_->method_idx, *cu_->dex_file); |
| 946 | } |
| 947 | |
| 948 | // Computation intensive? |
| 949 | if (stats->has_computational_loop && (stats->heavyweight_ratio < 0.04)) { |
| 950 | return false; |
| 951 | } |
| 952 | |
| 953 | // Complex, logic-intensive? |
| 954 | if ((GetNumDalvikInsns() > Runtime::Current()->GetSmallMethodThreshold()) && |
| 955 | stats->branch_ratio > 0.3) { |
| 956 | return false; |
| 957 | } |
| 958 | |
| 959 | // Significant floating point? |
| 960 | if (stats->fp_ratio > 0.05) { |
| 961 | return false; |
| 962 | } |
| 963 | |
| 964 | // Significant generic math? |
| 965 | if (stats->math_ratio > 0.3) { |
| 966 | return false; |
| 967 | } |
| 968 | |
| 969 | // If array-intensive, compiling is probably worthwhile. |
| 970 | if (stats->array_ratio > 0.1) { |
| 971 | return false; |
| 972 | } |
| 973 | |
| 974 | // If high proportion of expensive operations, skip. |
| 975 | if (stats->heavyweight_ratio > 0.3) { |
| 976 | return true; |
| 977 | } |
| 978 | |
| 979 | return skip_default; |
| 980 | } |
| 981 | |
| 982 | /* |
| 983 | * Will eventually want this to be a bit more sophisticated and happen at verification time. |
| 984 | * Ultimate goal is to drive with profile data. |
| 985 | */ |
| 986 | bool MIRGraph::SkipCompilation(Runtime::CompilerFilter compiler_filter) { |
| 987 | if (compiler_filter == Runtime::kSpeed) { |
| 988 | // If going for speed, compile everything. |
| 989 | return false; |
| 990 | } |
| 991 | |
| 992 | if (compiler_filter == Runtime::kInterpretOnly) { |
| 993 | LOG(WARNING) << "InterpretOnly should ideally be filtered out prior to parsing."; |
| 994 | return true; |
| 995 | } |
| 996 | |
| 997 | // Filter 1: Skip huge methods (generally machine-generated initialization methods). |
| 998 | if (GetNumDalvikInsns() > Runtime::Current()->GetHugeMethodThreshold()) { |
| 999 | // Ain't nobody got time for that. |
| 1000 | return true; |
| 1001 | } |
| 1002 | |
| 1003 | // Filter 2: Skip class initializers. |
| 1004 | if (((cu_->access_flags & kAccConstructor) != 0) && ((cu_->access_flags & kAccStatic) != 0)) { |
| 1005 | return true; |
| 1006 | } |
| 1007 | |
| 1008 | // Filter 3: if this method is a special pattern, go ahead and emit the canned pattern. |
| 1009 | if (IsSpecialCase()) { |
| 1010 | return false; |
| 1011 | } |
| 1012 | |
| 1013 | /* In balanced mode, we generally assume that we'll be compiling, and then detect |
| 1014 | * methods that won't benefit and remove them. In space or deferred mode, we do the |
| 1015 | * opposite: assume no compilation and then add back presumed hot methods. |
| 1016 | */ |
| 1017 | bool skip_compilation = (compiler_filter == Runtime::kBalanced) ? false : true; |
| 1018 | |
| 1019 | |
| 1020 | // Filter 4: go ahead and compile the small ones. |
| 1021 | size_t small_cutoff = 0; |
| 1022 | switch (compiler_filter) { |
| 1023 | case Runtime::kBalanced: |
| 1024 | small_cutoff = Runtime::Current()->GetSmallMethodThreshold(); |
| 1025 | break; |
| 1026 | case Runtime::kSpace: |
| 1027 | small_cutoff = Runtime::Current()->GetTinyMethodThreshold(); |
| 1028 | break; |
| 1029 | case Runtime::kDeferCompilation: |
| 1030 | small_cutoff = 0; |
| 1031 | break; |
| 1032 | default: |
| 1033 | LOG(FATAL) << "Unexpected compiler_filter_: " << compiler_filter; |
| 1034 | } |
| 1035 | if (GetNumDalvikInsns() < small_cutoff) { |
| 1036 | return false; |
| 1037 | } |
| 1038 | |
| 1039 | // Analyze graph for: |
| 1040 | // o floating point computation |
| 1041 | // o basic blocks contained in loop with heavy arithmetic. |
| 1042 | // o proportion of conditional branches. |
| 1043 | |
| 1044 | MethodStats stats; |
| 1045 | memset(&stats, 0, sizeof(stats)); |
| 1046 | |
| 1047 | ClearAllVisitedFlags(); |
| 1048 | AllNodesIterator iter(this, false /* not iterative */); |
| 1049 | for (BasicBlock* bb = iter.Next(); bb != NULL; bb = iter.Next()) { |
| 1050 | AnalyzeBlock(bb, &stats); |
| 1051 | } |
| 1052 | |
| 1053 | return ComputeSkipCompilation(&stats, skip_compilation); |
| 1054 | } |
| 1055 | |
| 1056 | } // namespace art |