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