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 | |
Nicolas Geoffray | b34f69a | 2014-03-07 15:28:39 +0000 | [diff] [blame] | 17 | #include "compiler.h" |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 18 | #include "compiler_internals.h" |
| 19 | #include "driver/compiler_driver.h" |
Dave Allison | 39c3bfb | 2014-01-28 18:33:52 -0800 | [diff] [blame] | 20 | #include "driver/compiler_options.h" |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 21 | #include "dataflow_iterator-inl.h" |
| 22 | #include "leb128.h" |
| 23 | #include "mirror/object.h" |
Jean Christophe Beyler | 2469e60 | 2014-05-06 20:36:55 -0700 | [diff] [blame] | 24 | #include "pass_driver_me_opts.h" |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 25 | #include "runtime.h" |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 26 | #include "base/logging.h" |
buzbee | a61f495 | 2013-08-23 14:27:06 -0700 | [diff] [blame] | 27 | #include "base/timing_logger.h" |
Dave Allison | 39c3bfb | 2014-01-28 18:33:52 -0800 | [diff] [blame] | 28 | #include "driver/compiler_options.h" |
Vladimir Marko | 5c96e6b | 2013-11-14 15:34:17 +0000 | [diff] [blame] | 29 | #include "dex/quick/dex_file_to_method_inliner_map.h" |
| 30 | |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 31 | namespace art { |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 32 | |
Ian Rogers | 72d3262 | 2014-05-06 16:20:11 -0700 | [diff] [blame] | 33 | extern "C" void ArtInitQuickCompilerContext(art::CompilerDriver* driver) { |
| 34 | CHECK(driver->GetCompilerContext() == nullptr); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 35 | } |
| 36 | |
Ian Rogers | 72d3262 | 2014-05-06 16:20:11 -0700 | [diff] [blame] | 37 | extern "C" void ArtUnInitQuickCompilerContext(art::CompilerDriver* driver) { |
| 38 | CHECK(driver->GetCompilerContext() == nullptr); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 39 | } |
| 40 | |
| 41 | /* Default optimizer/debug setting for the compiler. */ |
Brian Carlstrom | 7934ac2 | 2013-07-26 10:54:15 -0700 | [diff] [blame] | 42 | static uint32_t kCompilerOptimizerDisableFlags = 0 | // Disable specific optimizations |
buzbee | 091cc40 | 2014-03-31 10:14:40 -0700 | [diff] [blame] | 43 | (1 << kLoadStoreElimination) | // TODO: this pass has been broken for awhile - fix or delete. |
Brian Carlstrom | 7934ac2 | 2013-07-26 10:54:15 -0700 | [diff] [blame] | 44 | // (1 << kLoadHoisting) | |
| 45 | // (1 << kSuppressLoads) | |
| 46 | // (1 << kNullCheckElimination) | |
Vladimir Marko | bfea9c2 | 2014-01-17 17:49:33 +0000 | [diff] [blame] | 47 | // (1 << kClassInitCheckElimination) | |
Vladimir Marko | 95a0597 | 2014-05-30 10:01:32 +0100 | [diff] [blame] | 48 | // (1 << kGlobalValueNumbering) | |
Brian Carlstrom | 7934ac2 | 2013-07-26 10:54:15 -0700 | [diff] [blame] | 49 | // (1 << kPromoteRegs) | |
buzbee | 30adc73 | 2014-05-09 15:10:18 -0700 | [diff] [blame] | 50 | // (1 << kTrackLiveTemps) | |
Brian Carlstrom | 7934ac2 | 2013-07-26 10:54:15 -0700 | [diff] [blame] | 51 | // (1 << kSafeOptimizations) | |
| 52 | // (1 << kBBOpt) | |
| 53 | // (1 << kMatch) | |
| 54 | // (1 << kPromoteCompilerTemps) | |
buzbee | 17189ac | 2013-11-08 11:07:02 -0800 | [diff] [blame] | 55 | // (1 << kSuppressExceptionEdges) | |
Vladimir Marko | 9820b7c | 2014-01-02 16:40:37 +0000 | [diff] [blame] | 56 | // (1 << kSuppressMethodInlining) | |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 57 | 0; |
| 58 | |
| 59 | static uint32_t kCompilerDebugFlags = 0 | // Enable debug/testing modes |
Brian Carlstrom | 7934ac2 | 2013-07-26 10:54:15 -0700 | [diff] [blame] | 60 | // (1 << kDebugDisplayMissingTargets) | |
| 61 | // (1 << kDebugVerbose) | |
| 62 | // (1 << kDebugDumpCFG) | |
| 63 | // (1 << kDebugSlowFieldPath) | |
| 64 | // (1 << kDebugSlowInvokePath) | |
| 65 | // (1 << kDebugSlowStringPath) | |
| 66 | // (1 << kDebugSlowestFieldPath) | |
| 67 | // (1 << kDebugSlowestStringPath) | |
| 68 | // (1 << kDebugExerciseResolveMethod) | |
| 69 | // (1 << kDebugVerifyDataflow) | |
| 70 | // (1 << kDebugShowMemoryUsage) | |
| 71 | // (1 << kDebugShowNops) | |
| 72 | // (1 << kDebugCountOpcodes) | |
| 73 | // (1 << kDebugDumpCheckStats) | |
| 74 | // (1 << kDebugDumpBitcodeFile) | |
| 75 | // (1 << kDebugVerifyBitcode) | |
| 76 | // (1 << kDebugShowSummaryMemoryUsage) | |
buzbee | ee17e0a | 2013-07-31 10:47:37 -0700 | [diff] [blame] | 77 | // (1 << kDebugShowFilterStats) | |
buzbee | a61f495 | 2013-08-23 14:27:06 -0700 | [diff] [blame] | 78 | // (1 << kDebugTimings) | |
buzbee | b01bf15 | 2014-05-13 15:59:07 -0700 | [diff] [blame] | 79 | // (1 << kDebugCodegenDump) | |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 80 | 0; |
| 81 | |
Andreas Gampe | 00caeed | 2014-07-10 01:43:08 -0700 | [diff] [blame] | 82 | COMPILE_ASSERT(0U == static_cast<size_t>(kNone), kNone_not_0); |
| 83 | COMPILE_ASSERT(1U == static_cast<size_t>(kArm), kArm_not_1); |
| 84 | COMPILE_ASSERT(2U == static_cast<size_t>(kArm64), kArm64_not_2); |
| 85 | COMPILE_ASSERT(3U == static_cast<size_t>(kThumb2), kThumb2_not_3); |
| 86 | COMPILE_ASSERT(4U == static_cast<size_t>(kX86), kX86_not_4); |
| 87 | COMPILE_ASSERT(5U == static_cast<size_t>(kX86_64), kX86_64_not_5); |
| 88 | COMPILE_ASSERT(6U == static_cast<size_t>(kMips), kMips_not_6); |
| 89 | COMPILE_ASSERT(7U == static_cast<size_t>(kMips64), kMips64_not_7); |
Vladimir Marko | 25724ef | 2013-11-12 15:09:20 +0000 | [diff] [blame] | 90 | |
Andreas Gampe | 00caeed | 2014-07-10 01:43:08 -0700 | [diff] [blame] | 91 | // Additional disabled optimizations (over generally disabled) per instruction set. |
| 92 | static constexpr uint32_t kDisabledOptimizationsPerISA[] = { |
| 93 | // 0 = kNone. |
| 94 | ~0U, |
| 95 | // 1 = kArm, unused (will use kThumb2). |
| 96 | ~0U, |
| 97 | // 2 = kArm64. TODO(Arm64): enable optimizations once backend is mature enough. |
| 98 | (1 << kLoadStoreElimination) | |
| 99 | (1 << kLoadHoisting) | |
Andreas Gampe | 00caeed | 2014-07-10 01:43:08 -0700 | [diff] [blame] | 100 | (1 << kBBOpt) | |
Andreas Gampe | 00caeed | 2014-07-10 01:43:08 -0700 | [diff] [blame] | 101 | 0, |
| 102 | // 3 = kThumb2. |
| 103 | 0, |
| 104 | // 4 = kX86. |
| 105 | 0, |
| 106 | // 5 = kX86_64. |
| 107 | (1 << kLoadStoreElimination) | |
| 108 | 0, |
| 109 | // 6 = kMips. |
| 110 | (1 << kLoadStoreElimination) | |
| 111 | (1 << kLoadHoisting) | |
| 112 | (1 << kSuppressLoads) | |
| 113 | (1 << kNullCheckElimination) | |
| 114 | (1 << kPromoteRegs) | |
| 115 | (1 << kTrackLiveTemps) | |
| 116 | (1 << kSafeOptimizations) | |
| 117 | (1 << kBBOpt) | |
| 118 | (1 << kMatch) | |
| 119 | (1 << kPromoteCompilerTemps) | |
| 120 | 0, |
| 121 | // 7 = kMips64. |
| 122 | ~0U |
| 123 | }; |
| 124 | COMPILE_ASSERT(sizeof(kDisabledOptimizationsPerISA) == 8 * sizeof(uint32_t), kDisabledOpts_unexp); |
Vladimir Marko | 25724ef | 2013-11-12 15:09:20 +0000 | [diff] [blame] | 125 | |
Andreas Gampe | 00caeed | 2014-07-10 01:43:08 -0700 | [diff] [blame] | 126 | // Supported shorty types per instruction set. nullptr means that all are available. |
| 127 | // Z : boolean |
| 128 | // B : byte |
| 129 | // S : short |
| 130 | // C : char |
| 131 | // I : int |
| 132 | // J : long |
| 133 | // F : float |
| 134 | // D : double |
| 135 | // L : reference(object, array) |
| 136 | // V : void |
| 137 | static const char* kSupportedTypes[] = { |
| 138 | // 0 = kNone. |
| 139 | "", |
| 140 | // 1 = kArm, unused (will use kThumb2). |
| 141 | "", |
| 142 | // 2 = kArm64. |
| 143 | nullptr, |
| 144 | // 3 = kThumb2. |
| 145 | nullptr, |
| 146 | // 4 = kX86. |
| 147 | nullptr, |
| 148 | // 5 = kX86_64. |
| 149 | nullptr, |
| 150 | // 6 = kMips. |
| 151 | nullptr, |
| 152 | // 7 = kMips64. |
| 153 | "" |
| 154 | }; |
| 155 | COMPILE_ASSERT(sizeof(kSupportedTypes) == 8 * sizeof(char*), kSupportedTypes_unexp); |
buzbee | a61f495 | 2013-08-23 14:27:06 -0700 | [diff] [blame] | 156 | |
Andreas Gampe | 00caeed | 2014-07-10 01:43:08 -0700 | [diff] [blame] | 157 | static int kAllOpcodes[] = { |
Zheng Xu | 9e06c8c | 2014-05-06 18:06:07 +0100 | [diff] [blame] | 158 | Instruction::NOP, |
Serban Constantinescu | ed65c5e | 2014-05-22 15:10:18 +0100 | [diff] [blame] | 159 | Instruction::MOVE, |
| 160 | Instruction::MOVE_FROM16, |
| 161 | Instruction::MOVE_16, |
Zheng Xu | e2eb29e | 2014-06-12 10:22:33 +0800 | [diff] [blame] | 162 | Instruction::MOVE_WIDE, |
| 163 | Instruction::MOVE_WIDE_FROM16, |
| 164 | Instruction::MOVE_WIDE_16, |
| 165 | Instruction::MOVE_OBJECT, |
| 166 | Instruction::MOVE_OBJECT_FROM16, |
| 167 | Instruction::MOVE_OBJECT_16, |
buzbee | 54ee444 | 2014-06-19 15:04:12 -0700 | [diff] [blame] | 168 | Instruction::MOVE_RESULT, |
| 169 | Instruction::MOVE_RESULT_WIDE, |
| 170 | Instruction::MOVE_RESULT_OBJECT, |
Matteo Franchin | ec3f3d1 | 2014-05-29 14:24:10 +0100 | [diff] [blame] | 171 | Instruction::MOVE_EXCEPTION, |
| 172 | Instruction::RETURN_VOID, |
| 173 | Instruction::RETURN, |
| 174 | Instruction::RETURN_WIDE, |
Matteo Franchin | fd2e291 | 2014-06-06 10:09:56 +0100 | [diff] [blame] | 175 | Instruction::RETURN_OBJECT, |
Matteo Franchin | ec3f3d1 | 2014-05-29 14:24:10 +0100 | [diff] [blame] | 176 | Instruction::CONST_4, |
| 177 | Instruction::CONST_16, |
| 178 | Instruction::CONST, |
Zheng Xu | e2eb29e | 2014-06-12 10:22:33 +0800 | [diff] [blame] | 179 | Instruction::CONST_HIGH16, |
| 180 | Instruction::CONST_WIDE_16, |
| 181 | Instruction::CONST_WIDE_32, |
| 182 | Instruction::CONST_WIDE, |
| 183 | Instruction::CONST_WIDE_HIGH16, |
Matteo Franchin | ec3f3d1 | 2014-05-29 14:24:10 +0100 | [diff] [blame] | 184 | Instruction::CONST_STRING, |
buzbee | 54ee444 | 2014-06-19 15:04:12 -0700 | [diff] [blame] | 185 | Instruction::CONST_STRING_JUMBO, |
| 186 | Instruction::CONST_CLASS, |
Matteo Franchin | ec3f3d1 | 2014-05-29 14:24:10 +0100 | [diff] [blame] | 187 | Instruction::MONITOR_ENTER, |
| 188 | Instruction::MONITOR_EXIT, |
buzbee | 54ee444 | 2014-06-19 15:04:12 -0700 | [diff] [blame] | 189 | Instruction::CHECK_CAST, |
| 190 | Instruction::INSTANCE_OF, |
| 191 | Instruction::ARRAY_LENGTH, |
| 192 | Instruction::NEW_INSTANCE, |
| 193 | Instruction::NEW_ARRAY, |
| 194 | Instruction::FILLED_NEW_ARRAY, |
| 195 | Instruction::FILLED_NEW_ARRAY_RANGE, |
| 196 | Instruction::FILL_ARRAY_DATA, |
| 197 | Instruction::THROW, |
Matteo Franchin | ec3f3d1 | 2014-05-29 14:24:10 +0100 | [diff] [blame] | 198 | Instruction::GOTO, |
| 199 | Instruction::GOTO_16, |
| 200 | Instruction::GOTO_32, |
Matteo Franchin | 5acc8b0 | 2014-06-05 15:10:35 +0100 | [diff] [blame] | 201 | Instruction::PACKED_SWITCH, |
| 202 | Instruction::SPARSE_SWITCH, |
Zheng Xu | e2eb29e | 2014-06-12 10:22:33 +0800 | [diff] [blame] | 203 | Instruction::CMPL_FLOAT, |
| 204 | Instruction::CMPG_FLOAT, |
| 205 | Instruction::CMPL_DOUBLE, |
| 206 | Instruction::CMPG_DOUBLE, |
| 207 | Instruction::CMP_LONG, |
Matteo Franchin | ec3f3d1 | 2014-05-29 14:24:10 +0100 | [diff] [blame] | 208 | Instruction::IF_EQ, |
| 209 | Instruction::IF_NE, |
| 210 | Instruction::IF_LT, |
| 211 | Instruction::IF_GE, |
| 212 | Instruction::IF_GT, |
| 213 | Instruction::IF_LE, |
| 214 | Instruction::IF_EQZ, |
| 215 | Instruction::IF_NEZ, |
| 216 | Instruction::IF_LTZ, |
| 217 | Instruction::IF_GEZ, |
| 218 | Instruction::IF_GTZ, |
| 219 | Instruction::IF_LEZ, |
buzbee | 54ee444 | 2014-06-19 15:04:12 -0700 | [diff] [blame] | 220 | Instruction::UNUSED_3E, |
| 221 | Instruction::UNUSED_3F, |
| 222 | Instruction::UNUSED_40, |
| 223 | Instruction::UNUSED_41, |
| 224 | Instruction::UNUSED_42, |
| 225 | Instruction::UNUSED_43, |
| 226 | Instruction::AGET, |
| 227 | Instruction::AGET_WIDE, |
| 228 | Instruction::AGET_OBJECT, |
| 229 | Instruction::AGET_BOOLEAN, |
| 230 | Instruction::AGET_BYTE, |
| 231 | Instruction::AGET_CHAR, |
| 232 | Instruction::AGET_SHORT, |
| 233 | Instruction::APUT, |
| 234 | Instruction::APUT_WIDE, |
| 235 | Instruction::APUT_OBJECT, |
| 236 | Instruction::APUT_BOOLEAN, |
| 237 | Instruction::APUT_BYTE, |
| 238 | Instruction::APUT_CHAR, |
| 239 | Instruction::APUT_SHORT, |
| 240 | Instruction::IGET, |
| 241 | Instruction::IGET_WIDE, |
| 242 | Instruction::IGET_OBJECT, |
| 243 | Instruction::IGET_BOOLEAN, |
| 244 | Instruction::IGET_BYTE, |
| 245 | Instruction::IGET_CHAR, |
| 246 | Instruction::IGET_SHORT, |
| 247 | Instruction::IPUT, |
| 248 | Instruction::IPUT_WIDE, |
| 249 | Instruction::IPUT_OBJECT, |
| 250 | Instruction::IPUT_BOOLEAN, |
| 251 | Instruction::IPUT_BYTE, |
| 252 | Instruction::IPUT_CHAR, |
| 253 | Instruction::IPUT_SHORT, |
| 254 | Instruction::SGET, |
| 255 | Instruction::SGET_WIDE, |
| 256 | Instruction::SGET_OBJECT, |
| 257 | Instruction::SGET_BOOLEAN, |
| 258 | Instruction::SGET_BYTE, |
| 259 | Instruction::SGET_CHAR, |
| 260 | Instruction::SGET_SHORT, |
| 261 | Instruction::SPUT, |
| 262 | Instruction::SPUT_WIDE, |
| 263 | Instruction::SPUT_OBJECT, |
| 264 | Instruction::SPUT_BOOLEAN, |
| 265 | Instruction::SPUT_BYTE, |
| 266 | Instruction::SPUT_CHAR, |
| 267 | Instruction::SPUT_SHORT, |
| 268 | Instruction::INVOKE_VIRTUAL, |
| 269 | Instruction::INVOKE_SUPER, |
| 270 | Instruction::INVOKE_DIRECT, |
| 271 | Instruction::INVOKE_STATIC, |
| 272 | Instruction::INVOKE_INTERFACE, |
| 273 | Instruction::RETURN_VOID_BARRIER, |
| 274 | Instruction::INVOKE_VIRTUAL_RANGE, |
| 275 | Instruction::INVOKE_SUPER_RANGE, |
| 276 | Instruction::INVOKE_DIRECT_RANGE, |
| 277 | Instruction::INVOKE_STATIC_RANGE, |
| 278 | Instruction::INVOKE_INTERFACE_RANGE, |
| 279 | Instruction::UNUSED_79, |
| 280 | Instruction::UNUSED_7A, |
Matteo Franchin | ec3f3d1 | 2014-05-29 14:24:10 +0100 | [diff] [blame] | 281 | Instruction::NEG_INT, |
| 282 | Instruction::NOT_INT, |
buzbee | 54ee444 | 2014-06-19 15:04:12 -0700 | [diff] [blame] | 283 | Instruction::NEG_LONG, |
| 284 | Instruction::NOT_LONG, |
Matteo Franchin | ec3f3d1 | 2014-05-29 14:24:10 +0100 | [diff] [blame] | 285 | Instruction::NEG_FLOAT, |
buzbee | 54ee444 | 2014-06-19 15:04:12 -0700 | [diff] [blame] | 286 | Instruction::NEG_DOUBLE, |
| 287 | Instruction::INT_TO_LONG, |
| 288 | Instruction::INT_TO_FLOAT, |
| 289 | Instruction::INT_TO_DOUBLE, |
| 290 | Instruction::LONG_TO_INT, |
| 291 | Instruction::LONG_TO_FLOAT, |
| 292 | Instruction::LONG_TO_DOUBLE, |
| 293 | Instruction::FLOAT_TO_INT, |
| 294 | Instruction::FLOAT_TO_LONG, |
| 295 | Instruction::FLOAT_TO_DOUBLE, |
| 296 | Instruction::DOUBLE_TO_INT, |
| 297 | Instruction::DOUBLE_TO_LONG, |
| 298 | Instruction::DOUBLE_TO_FLOAT, |
Matteo Franchin | ec3f3d1 | 2014-05-29 14:24:10 +0100 | [diff] [blame] | 299 | Instruction::INT_TO_BYTE, |
| 300 | Instruction::INT_TO_CHAR, |
| 301 | Instruction::INT_TO_SHORT, |
| 302 | Instruction::ADD_INT, |
| 303 | Instruction::SUB_INT, |
| 304 | Instruction::MUL_INT, |
| 305 | Instruction::DIV_INT, |
| 306 | Instruction::REM_INT, |
| 307 | Instruction::AND_INT, |
| 308 | Instruction::OR_INT, |
| 309 | Instruction::XOR_INT, |
| 310 | Instruction::SHL_INT, |
| 311 | Instruction::SHR_INT, |
| 312 | Instruction::USHR_INT, |
buzbee | 54ee444 | 2014-06-19 15:04:12 -0700 | [diff] [blame] | 313 | Instruction::ADD_LONG, |
| 314 | Instruction::SUB_LONG, |
| 315 | Instruction::MUL_LONG, |
| 316 | Instruction::DIV_LONG, |
| 317 | Instruction::REM_LONG, |
| 318 | Instruction::AND_LONG, |
| 319 | Instruction::OR_LONG, |
| 320 | Instruction::XOR_LONG, |
| 321 | Instruction::SHL_LONG, |
| 322 | Instruction::SHR_LONG, |
| 323 | Instruction::USHR_LONG, |
Matteo Franchin | ec3f3d1 | 2014-05-29 14:24:10 +0100 | [diff] [blame] | 324 | Instruction::ADD_FLOAT, |
| 325 | Instruction::SUB_FLOAT, |
| 326 | Instruction::MUL_FLOAT, |
| 327 | Instruction::DIV_FLOAT, |
buzbee | 54ee444 | 2014-06-19 15:04:12 -0700 | [diff] [blame] | 328 | Instruction::REM_FLOAT, |
| 329 | Instruction::ADD_DOUBLE, |
| 330 | Instruction::SUB_DOUBLE, |
| 331 | Instruction::MUL_DOUBLE, |
| 332 | Instruction::DIV_DOUBLE, |
| 333 | Instruction::REM_DOUBLE, |
Matteo Franchin | ec3f3d1 | 2014-05-29 14:24:10 +0100 | [diff] [blame] | 334 | Instruction::ADD_INT_2ADDR, |
| 335 | Instruction::SUB_INT_2ADDR, |
| 336 | Instruction::MUL_INT_2ADDR, |
| 337 | Instruction::DIV_INT_2ADDR, |
| 338 | Instruction::REM_INT_2ADDR, |
| 339 | Instruction::AND_INT_2ADDR, |
| 340 | Instruction::OR_INT_2ADDR, |
| 341 | Instruction::XOR_INT_2ADDR, |
| 342 | Instruction::SHL_INT_2ADDR, |
| 343 | Instruction::SHR_INT_2ADDR, |
| 344 | Instruction::USHR_INT_2ADDR, |
buzbee | 54ee444 | 2014-06-19 15:04:12 -0700 | [diff] [blame] | 345 | Instruction::ADD_LONG_2ADDR, |
| 346 | Instruction::SUB_LONG_2ADDR, |
| 347 | Instruction::MUL_LONG_2ADDR, |
| 348 | Instruction::DIV_LONG_2ADDR, |
| 349 | Instruction::REM_LONG_2ADDR, |
| 350 | Instruction::AND_LONG_2ADDR, |
| 351 | Instruction::OR_LONG_2ADDR, |
| 352 | Instruction::XOR_LONG_2ADDR, |
| 353 | Instruction::SHL_LONG_2ADDR, |
| 354 | Instruction::SHR_LONG_2ADDR, |
| 355 | Instruction::USHR_LONG_2ADDR, |
Matteo Franchin | ec3f3d1 | 2014-05-29 14:24:10 +0100 | [diff] [blame] | 356 | Instruction::ADD_FLOAT_2ADDR, |
| 357 | Instruction::SUB_FLOAT_2ADDR, |
| 358 | Instruction::MUL_FLOAT_2ADDR, |
| 359 | Instruction::DIV_FLOAT_2ADDR, |
buzbee | 54ee444 | 2014-06-19 15:04:12 -0700 | [diff] [blame] | 360 | Instruction::REM_FLOAT_2ADDR, |
| 361 | Instruction::ADD_DOUBLE_2ADDR, |
| 362 | Instruction::SUB_DOUBLE_2ADDR, |
| 363 | Instruction::MUL_DOUBLE_2ADDR, |
| 364 | Instruction::DIV_DOUBLE_2ADDR, |
| 365 | Instruction::REM_DOUBLE_2ADDR, |
Matteo Franchin | ec3f3d1 | 2014-05-29 14:24:10 +0100 | [diff] [blame] | 366 | Instruction::ADD_INT_LIT16, |
| 367 | Instruction::RSUB_INT, |
| 368 | Instruction::MUL_INT_LIT16, |
| 369 | Instruction::DIV_INT_LIT16, |
| 370 | Instruction::REM_INT_LIT16, |
| 371 | Instruction::AND_INT_LIT16, |
| 372 | Instruction::OR_INT_LIT16, |
| 373 | Instruction::XOR_INT_LIT16, |
| 374 | Instruction::ADD_INT_LIT8, |
| 375 | Instruction::RSUB_INT_LIT8, |
| 376 | Instruction::MUL_INT_LIT8, |
| 377 | Instruction::DIV_INT_LIT8, |
| 378 | Instruction::REM_INT_LIT8, |
| 379 | Instruction::AND_INT_LIT8, |
| 380 | Instruction::OR_INT_LIT8, |
| 381 | Instruction::XOR_INT_LIT8, |
| 382 | Instruction::SHL_INT_LIT8, |
| 383 | Instruction::SHR_INT_LIT8, |
| 384 | Instruction::USHR_INT_LIT8, |
buzbee | 54ee444 | 2014-06-19 15:04:12 -0700 | [diff] [blame] | 385 | Instruction::IGET_QUICK, |
| 386 | Instruction::IGET_WIDE_QUICK, |
| 387 | Instruction::IGET_OBJECT_QUICK, |
| 388 | Instruction::IPUT_QUICK, |
| 389 | Instruction::IPUT_WIDE_QUICK, |
| 390 | Instruction::IPUT_OBJECT_QUICK, |
| 391 | Instruction::INVOKE_VIRTUAL_QUICK, |
| 392 | Instruction::INVOKE_VIRTUAL_RANGE_QUICK, |
| 393 | Instruction::UNUSED_EB, |
| 394 | Instruction::UNUSED_EC, |
| 395 | Instruction::UNUSED_ED, |
| 396 | Instruction::UNUSED_EE, |
| 397 | Instruction::UNUSED_EF, |
| 398 | Instruction::UNUSED_F0, |
| 399 | Instruction::UNUSED_F1, |
| 400 | Instruction::UNUSED_F2, |
| 401 | Instruction::UNUSED_F3, |
| 402 | Instruction::UNUSED_F4, |
| 403 | Instruction::UNUSED_F5, |
| 404 | Instruction::UNUSED_F6, |
| 405 | Instruction::UNUSED_F7, |
| 406 | Instruction::UNUSED_F8, |
| 407 | Instruction::UNUSED_F9, |
| 408 | Instruction::UNUSED_FA, |
| 409 | Instruction::UNUSED_FB, |
| 410 | Instruction::UNUSED_FC, |
| 411 | Instruction::UNUSED_FD, |
| 412 | Instruction::UNUSED_FE, |
| 413 | Instruction::UNUSED_FF, |
Matteo Franchin | ec3f3d1 | 2014-05-29 14:24:10 +0100 | [diff] [blame] | 414 | // ----- ExtendedMIROpcode ----- |
| 415 | kMirOpPhi, |
| 416 | kMirOpCopy, |
| 417 | kMirOpFusedCmplFloat, |
| 418 | kMirOpFusedCmpgFloat, |
| 419 | kMirOpFusedCmplDouble, |
| 420 | kMirOpFusedCmpgDouble, |
| 421 | kMirOpFusedCmpLong, |
| 422 | kMirOpNop, |
| 423 | kMirOpNullCheck, |
| 424 | kMirOpRangeCheck, |
| 425 | kMirOpDivZeroCheck, |
| 426 | kMirOpCheck, |
| 427 | kMirOpCheckPart2, |
| 428 | kMirOpSelect, |
Zheng Xu | 9e06c8c | 2014-05-06 18:06:07 +0100 | [diff] [blame] | 429 | }; |
| 430 | |
Andreas Gampe | 00caeed | 2014-07-10 01:43:08 -0700 | [diff] [blame] | 431 | // Unsupported opcodes. nullptr can be used when everything is supported. Size of the lists is |
| 432 | // recorded below. |
| 433 | static const int* kUnsupportedOpcodes[] = { |
| 434 | // 0 = kNone. |
| 435 | kAllOpcodes, |
| 436 | // 1 = kArm, unused (will use kThumb2). |
| 437 | kAllOpcodes, |
| 438 | // 2 = kArm64. |
| 439 | nullptr, |
| 440 | // 3 = kThumb2. |
| 441 | nullptr, |
| 442 | // 4 = kX86. |
| 443 | nullptr, |
| 444 | // 5 = kX86_64. |
| 445 | nullptr, |
| 446 | // 6 = kMips. |
| 447 | nullptr, |
| 448 | // 7 = kMips64. |
| 449 | kAllOpcodes |
Vladimir Kostyukov | 5678455 | 2014-05-13 12:12:00 +0700 | [diff] [blame] | 450 | }; |
Andreas Gampe | 00caeed | 2014-07-10 01:43:08 -0700 | [diff] [blame] | 451 | COMPILE_ASSERT(sizeof(kUnsupportedOpcodes) == 8 * sizeof(int*), kUnsupportedOpcodes_unexp); |
Vladimir Kostyukov | 5678455 | 2014-05-13 12:12:00 +0700 | [diff] [blame] | 452 | |
Andreas Gampe | 00caeed | 2014-07-10 01:43:08 -0700 | [diff] [blame] | 453 | // Size of the arrays stored above. |
| 454 | static const size_t kUnsupportedOpcodesSize[] = { |
| 455 | // 0 = kNone. |
| 456 | arraysize(kAllOpcodes), |
| 457 | // 1 = kArm, unused (will use kThumb2). |
| 458 | arraysize(kAllOpcodes), |
| 459 | // 2 = kArm64. |
| 460 | 0, |
| 461 | // 3 = kThumb2. |
| 462 | 0, |
| 463 | // 4 = kX86. |
| 464 | 0, |
| 465 | // 5 = kX86_64. |
| 466 | 0, |
| 467 | // 6 = kMips. |
| 468 | 0, |
| 469 | // 7 = kMips64. |
| 470 | arraysize(kAllOpcodes), |
| 471 | }; |
| 472 | COMPILE_ASSERT(sizeof(kUnsupportedOpcodesSize) == 8 * sizeof(size_t), |
| 473 | kUnsupportedOpcodesSize_unexp); |
Vladimir Kostyukov | 5678455 | 2014-05-13 12:12:00 +0700 | [diff] [blame] | 474 | |
Andreas Gampe | 00caeed | 2014-07-10 01:43:08 -0700 | [diff] [blame] | 475 | CompilationUnit::CompilationUnit(ArenaPool* pool) |
| 476 | : compiler_driver(nullptr), |
| 477 | class_linker(nullptr), |
| 478 | dex_file(nullptr), |
| 479 | class_loader(nullptr), |
| 480 | class_def_idx(0), |
| 481 | method_idx(0), |
| 482 | code_item(nullptr), |
| 483 | access_flags(0), |
| 484 | invoke_type(kDirect), |
| 485 | shorty(nullptr), |
| 486 | disable_opt(0), |
| 487 | enable_debug(0), |
| 488 | verbose(false), |
| 489 | compiler(nullptr), |
| 490 | instruction_set(kNone), |
| 491 | target64(false), |
| 492 | num_dalvik_registers(0), |
| 493 | insns(nullptr), |
| 494 | num_ins(0), |
| 495 | num_outs(0), |
| 496 | num_regs(0), |
| 497 | compiler_flip_match(false), |
| 498 | arena(pool), |
| 499 | arena_stack(pool), |
| 500 | mir_graph(nullptr), |
| 501 | cg(nullptr), |
| 502 | timings("QuickCompiler", true, false), |
| 503 | print_pass(false) { |
| 504 | } |
| 505 | |
| 506 | CompilationUnit::~CompilationUnit() { |
| 507 | } |
| 508 | |
| 509 | void CompilationUnit::StartTimingSplit(const char* label) { |
| 510 | if (compiler_driver->GetDumpPasses()) { |
| 511 | timings.StartTiming(label); |
| 512 | } |
| 513 | } |
| 514 | |
| 515 | void CompilationUnit::NewTimingSplit(const char* label) { |
| 516 | if (compiler_driver->GetDumpPasses()) { |
| 517 | timings.EndTiming(); |
| 518 | timings.StartTiming(label); |
| 519 | } |
| 520 | } |
| 521 | |
| 522 | void CompilationUnit::EndTiming() { |
| 523 | if (compiler_driver->GetDumpPasses()) { |
| 524 | timings.EndTiming(); |
| 525 | if (enable_debug & (1 << kDebugTimings)) { |
| 526 | LOG(INFO) << "TIMINGS " << PrettyMethod(method_idx, *dex_file); |
| 527 | LOG(INFO) << Dumpable<TimingLogger>(timings); |
| 528 | } |
| 529 | } |
| 530 | } |
| 531 | |
Vladimir Kostyukov | 5678455 | 2014-05-13 12:12:00 +0700 | [diff] [blame] | 532 | static bool CanCompileShorty(const char* shorty, InstructionSet instruction_set) { |
Andreas Gampe | 00caeed | 2014-07-10 01:43:08 -0700 | [diff] [blame] | 533 | const char* supported_types = kSupportedTypes[instruction_set]; |
| 534 | if (supported_types == nullptr) { |
| 535 | // Everything available. |
| 536 | return true; |
| 537 | } |
| 538 | |
Zheng Xu | 9e06c8c | 2014-05-06 18:06:07 +0100 | [diff] [blame] | 539 | uint32_t shorty_size = strlen(shorty); |
| 540 | CHECK_GE(shorty_size, 1u); |
Vladimir Kostyukov | 5678455 | 2014-05-13 12:12:00 +0700 | [diff] [blame] | 541 | |
Zheng Xu | 9e06c8c | 2014-05-06 18:06:07 +0100 | [diff] [blame] | 542 | for (uint32_t i = 0; i < shorty_size; i++) { |
| 543 | if (strchr(supported_types, shorty[i]) == nullptr) { |
| 544 | return false; |
| 545 | } |
| 546 | } |
| 547 | return true; |
| 548 | }; |
| 549 | |
Zheng Xu | 9e06c8c | 2014-05-06 18:06:07 +0100 | [diff] [blame] | 550 | // Skip the method that we do not support currently. |
| 551 | static bool CanCompileMethod(uint32_t method_idx, const DexFile& dex_file, |
| 552 | CompilationUnit& cu) { |
Andreas Gampe | 00caeed | 2014-07-10 01:43:08 -0700 | [diff] [blame] | 553 | // Check whether we do have limitations at all. |
| 554 | if (kSupportedTypes[cu.instruction_set] == nullptr && |
| 555 | kUnsupportedOpcodesSize[cu.instruction_set] == 0U) { |
| 556 | return true; |
| 557 | } |
Zheng Xu | 9e06c8c | 2014-05-06 18:06:07 +0100 | [diff] [blame] | 558 | |
Andreas Gampe | 00caeed | 2014-07-10 01:43:08 -0700 | [diff] [blame] | 559 | // Check if we can compile the prototype. |
| 560 | const char* shorty = dex_file.GetMethodShorty(dex_file.GetMethodId(method_idx)); |
| 561 | if (!CanCompileShorty(shorty, cu.instruction_set)) { |
| 562 | VLOG(compiler) << "Unsupported shorty : " << shorty; |
| 563 | return false; |
| 564 | } |
Vladimir Kostyukov | 5678455 | 2014-05-13 12:12:00 +0700 | [diff] [blame] | 565 | |
Andreas Gampe | 00caeed | 2014-07-10 01:43:08 -0700 | [diff] [blame] | 566 | const int *unsupport_list = kUnsupportedOpcodes[cu.instruction_set]; |
| 567 | int unsupport_list_size = kUnsupportedOpcodesSize[cu.instruction_set]; |
| 568 | |
| 569 | for (unsigned int idx = 0; idx < cu.mir_graph->GetNumBlocks(); idx++) { |
| 570 | BasicBlock* bb = cu.mir_graph->GetBasicBlock(idx); |
| 571 | if (bb == NULL) continue; |
| 572 | if (bb->block_type == kDead) continue; |
| 573 | for (MIR* mir = bb->first_mir_insn; mir != nullptr; mir = mir->next) { |
| 574 | int opcode = mir->dalvikInsn.opcode; |
| 575 | // Check if we support the byte code. |
| 576 | if (std::find(unsupport_list, unsupport_list + unsupport_list_size, |
| 577 | opcode) != unsupport_list + unsupport_list_size) { |
Jean Christophe Beyler | 2ab40eb | 2014-06-02 09:03:14 -0700 | [diff] [blame^] | 578 | if (!MIR::DecodedInstruction::IsPseudoMirOp(opcode)) { |
Andreas Gampe | 00caeed | 2014-07-10 01:43:08 -0700 | [diff] [blame] | 579 | VLOG(compiler) << "Unsupported dalvik byte code : " |
| 580 | << mir->dalvikInsn.opcode; |
| 581 | } else { |
| 582 | VLOG(compiler) << "Unsupported extended MIR opcode : " |
| 583 | << MIRGraph::extended_mir_op_names_[opcode - kMirOpFirst]; |
Zheng Xu | 9e06c8c | 2014-05-06 18:06:07 +0100 | [diff] [blame] | 584 | } |
Andreas Gampe | 00caeed | 2014-07-10 01:43:08 -0700 | [diff] [blame] | 585 | return false; |
| 586 | } |
| 587 | // Check if it invokes a prototype that we cannot support. |
| 588 | if (Instruction::INVOKE_VIRTUAL == opcode || |
| 589 | Instruction::INVOKE_SUPER == opcode || |
| 590 | Instruction::INVOKE_DIRECT == opcode || |
| 591 | Instruction::INVOKE_STATIC == opcode || |
| 592 | Instruction::INVOKE_INTERFACE == opcode) { |
| 593 | uint32_t invoke_method_idx = mir->dalvikInsn.vB; |
| 594 | const char* invoke_method_shorty = dex_file.GetMethodShorty( |
| 595 | dex_file.GetMethodId(invoke_method_idx)); |
| 596 | if (!CanCompileShorty(invoke_method_shorty, cu.instruction_set)) { |
| 597 | VLOG(compiler) << "Unsupported to invoke '" |
| 598 | << PrettyMethod(invoke_method_idx, dex_file) |
| 599 | << "' with shorty : " << invoke_method_shorty; |
| 600 | return false; |
Zheng Xu | 9e06c8c | 2014-05-06 18:06:07 +0100 | [diff] [blame] | 601 | } |
| 602 | } |
| 603 | } |
Zheng Xu | 9e06c8c | 2014-05-06 18:06:07 +0100 | [diff] [blame] | 604 | } |
| 605 | return true; |
| 606 | } |
| 607 | |
Ian Rogers | 3d50407 | 2014-03-01 09:16:49 -0800 | [diff] [blame] | 608 | static CompiledMethod* CompileMethod(CompilerDriver& driver, |
Nicolas Geoffray | b34f69a | 2014-03-07 15:28:39 +0000 | [diff] [blame] | 609 | Compiler* compiler, |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 610 | const DexFile::CodeItem* code_item, |
| 611 | uint32_t access_flags, InvokeType invoke_type, |
Ian Rogers | 8b2c0b9 | 2013-09-19 02:56:49 -0700 | [diff] [blame] | 612 | uint16_t class_def_idx, uint32_t method_idx, |
Nicolas Geoffray | f5df897 | 2014-02-14 18:37:08 +0000 | [diff] [blame] | 613 | jobject class_loader, const DexFile& dex_file, |
| 614 | void* llvm_compilation_unit) { |
Calin Juravle | 38a0904 | 2014-06-23 14:40:31 +0100 | [diff] [blame] | 615 | std::string method_name = PrettyMethod(method_idx, dex_file); |
| 616 | VLOG(compiler) << "Compiling " << method_name << "..."; |
buzbee | b48819d | 2013-09-14 16:15:25 -0700 | [diff] [blame] | 617 | if (code_item->insns_size_in_code_units_ >= 0x10000) { |
| 618 | LOG(INFO) << "Method size exceeds compiler limits: " << code_item->insns_size_in_code_units_ |
Calin Juravle | 38a0904 | 2014-06-23 14:40:31 +0100 | [diff] [blame] | 619 | << " in " << method_name; |
buzbee | b48819d | 2013-09-14 16:15:25 -0700 | [diff] [blame] | 620 | return NULL; |
| 621 | } |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 622 | |
Jeff Hao | 4a200f5 | 2014-04-01 14:58:49 -0700 | [diff] [blame] | 623 | if (!driver.GetCompilerOptions().IsCompilationEnabled()) { |
Ian Rogers | a03de6d | 2014-03-08 23:37:07 +0000 | [diff] [blame] | 624 | return nullptr; |
| 625 | } |
| 626 | |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 627 | ClassLinker* class_linker = Runtime::Current()->GetClassLinker(); |
Ian Rogers | 3d50407 | 2014-03-01 09:16:49 -0800 | [diff] [blame] | 628 | CompilationUnit cu(driver.GetArenaPool()); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 629 | |
Ian Rogers | 3d50407 | 2014-03-01 09:16:49 -0800 | [diff] [blame] | 630 | cu.compiler_driver = &driver; |
Mathieu Chartier | f6c4b3b | 2013-08-24 16:11:37 -0700 | [diff] [blame] | 631 | cu.class_linker = class_linker; |
Ian Rogers | 3d50407 | 2014-03-01 09:16:49 -0800 | [diff] [blame] | 632 | cu.instruction_set = driver.GetInstructionSet(); |
Mathieu Chartier | 53bee42 | 2014-04-04 16:10:05 -0700 | [diff] [blame] | 633 | if (cu.instruction_set == kArm) { |
| 634 | cu.instruction_set = kThumb2; |
| 635 | } |
Andreas Gampe | af13ad9 | 2014-04-11 12:07:48 -0700 | [diff] [blame] | 636 | cu.target64 = Is64BitInstructionSet(cu.instruction_set); |
Nicolas Geoffray | b34f69a | 2014-03-07 15:28:39 +0000 | [diff] [blame] | 637 | cu.compiler = compiler; |
Andreas Gampe | 00caeed | 2014-07-10 01:43:08 -0700 | [diff] [blame] | 638 | // TODO: Mips64 is not yet implemented. |
Mathieu Chartier | 53bee42 | 2014-04-04 16:10:05 -0700 | [diff] [blame] | 639 | CHECK((cu.instruction_set == kThumb2) || |
Zheng Xu | 9e06c8c | 2014-05-06 18:06:07 +0100 | [diff] [blame] | 640 | (cu.instruction_set == kArm64) || |
Mathieu Chartier | 53bee42 | 2014-04-04 16:10:05 -0700 | [diff] [blame] | 641 | (cu.instruction_set == kX86) || |
| 642 | (cu.instruction_set == kX86_64) || |
| 643 | (cu.instruction_set == kMips)); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 644 | |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 645 | /* Adjust this value accordingly once inlining is performed */ |
Mathieu Chartier | f6c4b3b | 2013-08-24 16:11:37 -0700 | [diff] [blame] | 646 | cu.num_dalvik_registers = code_item->registers_size_; |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 647 | // TODO: set this from command line |
Mathieu Chartier | f6c4b3b | 2013-08-24 16:11:37 -0700 | [diff] [blame] | 648 | cu.compiler_flip_match = false; |
| 649 | bool use_match = !cu.compiler_method_match.empty(); |
| 650 | bool match = use_match && (cu.compiler_flip_match ^ |
Calin Juravle | 38a0904 | 2014-06-23 14:40:31 +0100 | [diff] [blame] | 651 | (method_name.find(cu.compiler_method_match) != std::string::npos)); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 652 | if (!use_match || match) { |
Mathieu Chartier | f6c4b3b | 2013-08-24 16:11:37 -0700 | [diff] [blame] | 653 | cu.disable_opt = kCompilerOptimizerDisableFlags; |
| 654 | cu.enable_debug = kCompilerDebugFlags; |
| 655 | cu.verbose = VLOG_IS_ON(compiler) || |
| 656 | (cu.enable_debug & (1 << kDebugVerbose)); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 657 | } |
| 658 | |
Mingyao Yang | 42d65c5 | 2014-04-18 16:49:39 -0700 | [diff] [blame] | 659 | if (gVerboseMethods.size() != 0) { |
| 660 | cu.verbose = false; |
| 661 | for (size_t i = 0; i < gVerboseMethods.size(); ++i) { |
Calin Juravle | 38a0904 | 2014-06-23 14:40:31 +0100 | [diff] [blame] | 662 | if (method_name.find(gVerboseMethods[i]) |
Mingyao Yang | 42d65c5 | 2014-04-18 16:49:39 -0700 | [diff] [blame] | 663 | != std::string::npos) { |
| 664 | cu.verbose = true; |
| 665 | break; |
| 666 | } |
| 667 | } |
| 668 | } |
| 669 | |
buzbee | b01bf15 | 2014-05-13 15:59:07 -0700 | [diff] [blame] | 670 | if (cu.verbose) { |
| 671 | cu.enable_debug |= (1 << kDebugCodegenDump); |
| 672 | } |
| 673 | |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 674 | /* |
| 675 | * TODO: rework handling of optimization and debug flags. Should we split out |
| 676 | * MIR and backend flags? Need command-line setting as well. |
| 677 | */ |
| 678 | |
Nicolas Geoffray | b34f69a | 2014-03-07 15:28:39 +0000 | [diff] [blame] | 679 | compiler->InitCompilationUnit(cu); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 680 | |
Andreas Gampe | 00caeed | 2014-07-10 01:43:08 -0700 | [diff] [blame] | 681 | // Disable optimizations according to instruction set. |
| 682 | cu.disable_opt |= kDisabledOptimizationsPerISA[cu.instruction_set]; |
Zheng Xu | 9e06c8c | 2014-05-06 18:06:07 +0100 | [diff] [blame] | 683 | |
buzbee | a61f495 | 2013-08-23 14:27:06 -0700 | [diff] [blame] | 684 | cu.StartTimingSplit("BuildMIRGraph"); |
Mathieu Chartier | f6c4b3b | 2013-08-24 16:11:37 -0700 | [diff] [blame] | 685 | cu.mir_graph.reset(new MIRGraph(&cu, &cu.arena)); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 686 | |
Razvan A Lupusoru | da7a69b | 2014-01-08 15:09:50 -0800 | [diff] [blame] | 687 | /* |
| 688 | * After creation of the MIR graph, also create the code generator. |
| 689 | * The reason we do this is that optimizations on the MIR graph may need to get information |
| 690 | * that is only available if a CG exists. |
| 691 | */ |
Nicolas Geoffray | b34f69a | 2014-03-07 15:28:39 +0000 | [diff] [blame] | 692 | cu.cg.reset(compiler->GetCodeGenerator(&cu, llvm_compilation_unit)); |
Razvan A Lupusoru | da7a69b | 2014-01-08 15:09:50 -0800 | [diff] [blame] | 693 | |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 694 | /* Gathering opcode stats? */ |
| 695 | if (kCompilerDebugFlags & (1 << kDebugCountOpcodes)) { |
Mathieu Chartier | f6c4b3b | 2013-08-24 16:11:37 -0700 | [diff] [blame] | 696 | cu.mir_graph->EnableOpcodeCounting(); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 697 | } |
| 698 | |
| 699 | /* Build the raw MIR graph */ |
Mathieu Chartier | f6c4b3b | 2013-08-24 16:11:37 -0700 | [diff] [blame] | 700 | cu.mir_graph->InlineMethod(code_item, access_flags, invoke_type, class_def_idx, method_idx, |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 701 | class_loader, dex_file); |
| 702 | |
Zheng Xu | 9e06c8c | 2014-05-06 18:06:07 +0100 | [diff] [blame] | 703 | if (!CanCompileMethod(method_idx, dex_file, cu)) { |
Calin Juravle | 38a0904 | 2014-06-23 14:40:31 +0100 | [diff] [blame] | 704 | VLOG(compiler) << cu.instruction_set << ": Cannot compile method : " << method_name; |
Zheng Xu | 9e06c8c | 2014-05-06 18:06:07 +0100 | [diff] [blame] | 705 | return nullptr; |
| 706 | } |
| 707 | |
buzbee | 1da1e2f | 2013-11-15 13:37:01 -0800 | [diff] [blame] | 708 | cu.NewTimingSplit("MIROpt:CheckFilters"); |
Andreas Gampe | 060e6fe | 2014-06-19 11:34:06 -0700 | [diff] [blame] | 709 | std::string skip_message; |
| 710 | if (cu.mir_graph->SkipCompilation(&skip_message)) { |
| 711 | VLOG(compiler) << cu.instruction_set << ": Skipping method : " |
Calin Juravle | 38a0904 | 2014-06-23 14:40:31 +0100 | [diff] [blame] | 712 | << method_name << " Reason = " << skip_message; |
buzbee | 33ae558 | 2014-06-12 14:56:32 -0700 | [diff] [blame] | 713 | return nullptr; |
buzbee | ee17e0a | 2013-07-31 10:47:37 -0700 | [diff] [blame] | 714 | } |
| 715 | |
Jean Christophe Beyler | 4e97c53 | 2014-01-07 10:07:18 -0800 | [diff] [blame] | 716 | /* Create the pass driver and launch it */ |
Jean Christophe Beyler | 2469e60 | 2014-05-06 20:36:55 -0700 | [diff] [blame] | 717 | PassDriverMEOpts pass_driver(&cu); |
Ian Rogers | 3d50407 | 2014-03-01 09:16:49 -0800 | [diff] [blame] | 718 | pass_driver.Launch(); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 719 | |
Calin Juravle | 38a0904 | 2014-06-23 14:40:31 +0100 | [diff] [blame] | 720 | /* For non-leaf methods check if we should skip compilation when the profiler is enabled. */ |
| 721 | if (cu.compiler_driver->ProfilePresent() |
| 722 | && !cu.mir_graph->MethodIsLeaf() |
| 723 | && cu.mir_graph->SkipCompilationByName(method_name)) { |
| 724 | return nullptr; |
| 725 | } |
| 726 | |
Mathieu Chartier | f6c4b3b | 2013-08-24 16:11:37 -0700 | [diff] [blame] | 727 | if (cu.enable_debug & (1 << kDebugDumpCheckStats)) { |
| 728 | cu.mir_graph->DumpCheckStats(); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 729 | } |
| 730 | |
| 731 | if (kCompilerDebugFlags & (1 << kDebugCountOpcodes)) { |
Mathieu Chartier | f6c4b3b | 2013-08-24 16:11:37 -0700 | [diff] [blame] | 732 | cu.mir_graph->ShowOpcodeStats(); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 733 | } |
| 734 | |
buzbee | 1da1e2f | 2013-11-15 13:37:01 -0800 | [diff] [blame] | 735 | /* Reassociate sreg names with original Dalvik vreg names. */ |
| 736 | cu.mir_graph->RemapRegLocations(); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 737 | |
Vladimir Marko | 53b6afc | 2014-03-21 14:21:20 +0000 | [diff] [blame] | 738 | /* Free Arenas from the cu.arena_stack for reuse by the cu.arena in the codegen. */ |
| 739 | if (cu.enable_debug & (1 << kDebugShowMemoryUsage)) { |
| 740 | if (cu.arena_stack.PeakBytesAllocated() > 256 * 1024) { |
| 741 | MemStats stack_stats(cu.arena_stack.GetPeakStats()); |
Calin Juravle | 38a0904 | 2014-06-23 14:40:31 +0100 | [diff] [blame] | 742 | LOG(INFO) << method_name << " " << Dumpable<MemStats>(stack_stats); |
Vladimir Marko | 53b6afc | 2014-03-21 14:21:20 +0000 | [diff] [blame] | 743 | } |
| 744 | } |
| 745 | cu.arena_stack.Reset(); |
| 746 | |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 747 | CompiledMethod* result = NULL; |
| 748 | |
buzbee | 8c7a02a | 2014-06-14 12:33:09 -0700 | [diff] [blame] | 749 | if (cu.mir_graph->PuntToInterpreter()) { |
Calin Juravle | 38a0904 | 2014-06-23 14:40:31 +0100 | [diff] [blame] | 750 | VLOG(compiler) << cu.instruction_set << ": Punted method to interpreter: " << method_name; |
Andreas Gampe | 060e6fe | 2014-06-19 11:34:06 -0700 | [diff] [blame] | 751 | return nullptr; |
buzbee | 8c7a02a | 2014-06-14 12:33:09 -0700 | [diff] [blame] | 752 | } |
| 753 | |
Mathieu Chartier | f6c4b3b | 2013-08-24 16:11:37 -0700 | [diff] [blame] | 754 | cu.cg->Materialize(); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 755 | |
buzbee | 1da1e2f | 2013-11-15 13:37:01 -0800 | [diff] [blame] | 756 | cu.NewTimingSplit("Dedupe"); /* deduping takes up the vast majority of time in GetCompiledMethod(). */ |
Mathieu Chartier | f6c4b3b | 2013-08-24 16:11:37 -0700 | [diff] [blame] | 757 | result = cu.cg->GetCompiledMethod(); |
buzbee | 1da1e2f | 2013-11-15 13:37:01 -0800 | [diff] [blame] | 758 | cu.NewTimingSplit("Cleanup"); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 759 | |
| 760 | if (result) { |
Calin Juravle | 38a0904 | 2014-06-23 14:40:31 +0100 | [diff] [blame] | 761 | VLOG(compiler) << cu.instruction_set << ": Compiled " << method_name; |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 762 | } else { |
Calin Juravle | 38a0904 | 2014-06-23 14:40:31 +0100 | [diff] [blame] | 763 | VLOG(compiler) << cu.instruction_set << ": Deferred " << method_name; |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 764 | } |
| 765 | |
Mathieu Chartier | f6c4b3b | 2013-08-24 16:11:37 -0700 | [diff] [blame] | 766 | if (cu.enable_debug & (1 << kDebugShowMemoryUsage)) { |
Vladimir Marko | 53b6afc | 2014-03-21 14:21:20 +0000 | [diff] [blame] | 767 | if (cu.arena.BytesAllocated() > (1 * 1024 *1024)) { |
Vladimir Marko | 83cc7ae | 2014-02-12 18:02:05 +0000 | [diff] [blame] | 768 | MemStats mem_stats(cu.arena.GetMemStats()); |
Calin Juravle | 38a0904 | 2014-06-23 14:40:31 +0100 | [diff] [blame] | 769 | LOG(INFO) << method_name << " " << Dumpable<MemStats>(mem_stats); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 770 | } |
| 771 | } |
| 772 | |
Mathieu Chartier | f6c4b3b | 2013-08-24 16:11:37 -0700 | [diff] [blame] | 773 | if (cu.enable_debug & (1 << kDebugShowSummaryMemoryUsage)) { |
| 774 | LOG(INFO) << "MEMINFO " << cu.arena.BytesAllocated() << " " << cu.mir_graph->GetNumBlocks() |
Calin Juravle | 38a0904 | 2014-06-23 14:40:31 +0100 | [diff] [blame] | 775 | << " " << method_name; |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 776 | } |
| 777 | |
buzbee | a61f495 | 2013-08-23 14:27:06 -0700 | [diff] [blame] | 778 | cu.EndTiming(); |
Ian Rogers | 3d50407 | 2014-03-01 09:16:49 -0800 | [diff] [blame] | 779 | driver.GetTimingsLogger()->AddLogger(cu.timings); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 780 | return result; |
| 781 | } |
| 782 | |
Nicolas Geoffray | b34f69a | 2014-03-07 15:28:39 +0000 | [diff] [blame] | 783 | CompiledMethod* CompileOneMethod(CompilerDriver& driver, |
| 784 | Compiler* compiler, |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 785 | const DexFile::CodeItem* code_item, |
| 786 | uint32_t access_flags, |
| 787 | InvokeType invoke_type, |
Ian Rogers | 8b2c0b9 | 2013-09-19 02:56:49 -0700 | [diff] [blame] | 788 | uint16_t class_def_idx, |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 789 | uint32_t method_idx, |
| 790 | jobject class_loader, |
| 791 | const DexFile& dex_file, |
Nicolas Geoffray | f5df897 | 2014-02-14 18:37:08 +0000 | [diff] [blame] | 792 | void* compilation_unit) { |
Nicolas Geoffray | b34f69a | 2014-03-07 15:28:39 +0000 | [diff] [blame] | 793 | return CompileMethod(driver, compiler, code_item, access_flags, invoke_type, class_def_idx, |
Nicolas Geoffray | f5df897 | 2014-02-14 18:37:08 +0000 | [diff] [blame] | 794 | method_idx, class_loader, dex_file, compilation_unit); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 795 | } |
| 796 | |
| 797 | } // namespace art |
| 798 | |
| 799 | extern "C" art::CompiledMethod* |
Nicolas Geoffray | b34f69a | 2014-03-07 15:28:39 +0000 | [diff] [blame] | 800 | ArtQuickCompileMethod(art::CompilerDriver& driver, |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 801 | const art::DexFile::CodeItem* code_item, |
| 802 | uint32_t access_flags, art::InvokeType invoke_type, |
Ian Rogers | 8b2c0b9 | 2013-09-19 02:56:49 -0700 | [diff] [blame] | 803 | uint16_t class_def_idx, uint32_t method_idx, jobject class_loader, |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 804 | const art::DexFile& dex_file) { |
Andreas Gampe | 00caeed | 2014-07-10 01:43:08 -0700 | [diff] [blame] | 805 | // TODO: check method fingerprint here to determine appropriate backend type. Until then, use |
| 806 | // build default. |
Nicolas Geoffray | b34f69a | 2014-03-07 15:28:39 +0000 | [diff] [blame] | 807 | art::Compiler* compiler = driver.GetCompiler(); |
| 808 | return art::CompileOneMethod(driver, compiler, code_item, access_flags, invoke_type, |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 809 | class_def_idx, method_idx, class_loader, dex_file, |
| 810 | NULL /* use thread llvm_info */); |
| 811 | } |