Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2014 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 "inliner.h" |
| 18 | |
Mathieu Chartier | 3d21bdf | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 19 | #include "art_method-inl.h" |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 20 | #include "builder.h" |
| 21 | #include "class_linker.h" |
| 22 | #include "constant_folding.h" |
| 23 | #include "dead_code_elimination.h" |
| 24 | #include "driver/compiler_driver-inl.h" |
Calin Juravle | 8f96df8 | 2015-07-29 15:58:48 +0100 | [diff] [blame^] | 25 | #include "driver/compiler_options.h" |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 26 | #include "driver/dex_compilation_unit.h" |
| 27 | #include "instruction_simplifier.h" |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 28 | #include "mirror/class_loader.h" |
| 29 | #include "mirror/dex_cache.h" |
| 30 | #include "nodes.h" |
Nicolas Geoffray | 20d60dd | 2015-06-25 10:01:47 +0100 | [diff] [blame] | 31 | #include "optimizing_compiler.h" |
Nicolas Geoffray | 259136f | 2014-12-17 23:21:58 +0000 | [diff] [blame] | 32 | #include "register_allocator.h" |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 33 | #include "ssa_phi_elimination.h" |
| 34 | #include "scoped_thread_state_change.h" |
| 35 | #include "thread.h" |
Calin Juravle | f1c6d9e | 2015-04-13 18:42:21 +0100 | [diff] [blame] | 36 | #include "dex/verified_method.h" |
| 37 | #include "dex/verification_results.h" |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 38 | |
| 39 | namespace art { |
| 40 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 41 | void HInliner::Run() { |
Calin Juravle | 8f96df8 | 2015-07-29 15:58:48 +0100 | [diff] [blame^] | 42 | const CompilerOptions& compiler_options = compiler_driver_->GetCompilerOptions(); |
| 43 | if ((compiler_options.GetInlineDepthLimit() == 0) |
| 44 | || (compiler_options.GetInlineMaxCodeUnits() == 0)) { |
| 45 | return; |
| 46 | } |
Nicolas Geoffray | e50b8d2 | 2015-03-13 08:57:42 +0000 | [diff] [blame] | 47 | if (graph_->IsDebuggable()) { |
| 48 | // For simplicity, we currently never inline when the graph is debuggable. This avoids |
| 49 | // doing some logic in the runtime to discover if a method could have been inlined. |
| 50 | return; |
| 51 | } |
Nicolas Geoffray | ef87c5d | 2015-01-30 12:41:14 +0000 | [diff] [blame] | 52 | const GrowableArray<HBasicBlock*>& blocks = graph_->GetReversePostOrder(); |
| 53 | for (size_t i = 0; i < blocks.Size(); ++i) { |
| 54 | HBasicBlock* block = blocks.Get(i); |
| 55 | for (HInstruction* instruction = block->GetFirstInstruction(); instruction != nullptr;) { |
| 56 | HInstruction* next = instruction->GetNext(); |
| 57 | HInvokeStaticOrDirect* call = instruction->AsInvokeStaticOrDirect(); |
Razvan A Lupusoru | 3e90a96 | 2015-03-27 13:44:44 -0700 | [diff] [blame] | 58 | // As long as the call is not intrinsified, it is worth trying to inline. |
| 59 | if (call != nullptr && call->GetIntrinsic() == Intrinsics::kNone) { |
Nicolas Geoffray | 7904129 | 2015-03-26 10:05:54 +0000 | [diff] [blame] | 60 | // We use the original invoke type to ensure the resolution of the called method |
| 61 | // works properly. |
Nicolas Geoffray | 8859311 | 2015-06-22 14:15:07 +0000 | [diff] [blame] | 62 | if (!TryInline(call, call->GetDexMethodIndex())) { |
Nicolas Geoffray | 20d60dd | 2015-06-25 10:01:47 +0100 | [diff] [blame] | 63 | if (kIsDebugBuild && IsCompilingWithCoreImage()) { |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 64 | std::string callee_name = |
Nicolas Geoffray | ef87c5d | 2015-01-30 12:41:14 +0000 | [diff] [blame] | 65 | PrettyMethod(call->GetDexMethodIndex(), *outer_compilation_unit_.GetDexFile()); |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 66 | bool should_inline = callee_name.find("$inline$") != std::string::npos; |
| 67 | CHECK(!should_inline) << "Could not inline " << callee_name; |
| 68 | } |
| 69 | } |
| 70 | } |
Nicolas Geoffray | ef87c5d | 2015-01-30 12:41:14 +0000 | [diff] [blame] | 71 | instruction = next; |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 72 | } |
| 73 | } |
| 74 | } |
| 75 | |
Nicolas Geoffray | 8859311 | 2015-06-22 14:15:07 +0000 | [diff] [blame] | 76 | bool HInliner::TryInline(HInvoke* invoke_instruction, uint32_t method_index) const { |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 77 | ScopedObjectAccess soa(Thread::Current()); |
Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 78 | const DexFile& caller_dex_file = *caller_compilation_unit_.GetDexFile(); |
| 79 | VLOG(compiler) << "Try inlining " << PrettyMethod(method_index, caller_dex_file); |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 80 | |
Nicolas Geoffray | 8859311 | 2015-06-22 14:15:07 +0000 | [diff] [blame] | 81 | ClassLinker* class_linker = caller_compilation_unit_.GetClassLinker(); |
| 82 | // We can query the dex cache directly. The verifier has populated it already. |
| 83 | ArtMethod* resolved_method = class_linker->FindDexCache(caller_dex_file)->GetResolvedMethod( |
| 84 | method_index, class_linker->GetImagePointerSize()); |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 85 | |
Mathieu Chartier | 3d21bdf | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 86 | if (resolved_method == nullptr) { |
Nicolas Geoffray | 8859311 | 2015-06-22 14:15:07 +0000 | [diff] [blame] | 87 | // Method cannot be resolved if it is in another dex file we do not have access to. |
Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 88 | VLOG(compiler) << "Method cannot be resolved " << PrettyMethod(method_index, caller_dex_file); |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 89 | return false; |
| 90 | } |
| 91 | |
Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 92 | bool can_use_dex_cache = true; |
| 93 | const DexFile& outer_dex_file = *outer_compilation_unit_.GetDexFile(); |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 94 | if (resolved_method->GetDexFile()->GetLocation().compare(outer_dex_file.GetLocation()) != 0) { |
Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 95 | can_use_dex_cache = false; |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 96 | } |
| 97 | |
| 98 | const DexFile::CodeItem* code_item = resolved_method->GetCodeItem(); |
| 99 | |
| 100 | if (code_item == nullptr) { |
Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 101 | VLOG(compiler) << "Method " << PrettyMethod(method_index, caller_dex_file) |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 102 | << " is not inlined because it is native"; |
| 103 | return false; |
| 104 | } |
| 105 | |
Calin Juravle | 8f96df8 | 2015-07-29 15:58:48 +0100 | [diff] [blame^] | 106 | size_t inline_max_code_units = compiler_driver_->GetCompilerOptions().GetInlineMaxCodeUnits(); |
| 107 | if (code_item->insns_size_in_code_units_ > inline_max_code_units) { |
Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 108 | VLOG(compiler) << "Method " << PrettyMethod(method_index, caller_dex_file) |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 109 | << " is too big to inline"; |
| 110 | return false; |
| 111 | } |
| 112 | |
| 113 | if (code_item->tries_size_ != 0) { |
Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 114 | VLOG(compiler) << "Method " << PrettyMethod(method_index, caller_dex_file) |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 115 | << " is not inlined because of try block"; |
| 116 | return false; |
| 117 | } |
| 118 | |
Calin Juravle | f1c6d9e | 2015-04-13 18:42:21 +0100 | [diff] [blame] | 119 | uint16_t class_def_idx = resolved_method->GetDeclaringClass()->GetDexClassDefIndex(); |
| 120 | if (!compiler_driver_->IsMethodVerifiedWithoutFailures( |
| 121 | resolved_method->GetDexMethodIndex(), class_def_idx, *resolved_method->GetDexFile())) { |
Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 122 | VLOG(compiler) << "Method " << PrettyMethod(method_index, caller_dex_file) |
Calin Juravle | f1c6d9e | 2015-04-13 18:42:21 +0100 | [diff] [blame] | 123 | << " couldn't be verified, so it cannot be inlined"; |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 124 | return false; |
| 125 | } |
| 126 | |
Nicolas Geoffray | c0365b1 | 2015-03-18 18:31:52 +0000 | [diff] [blame] | 127 | if (resolved_method->ShouldNotInline()) { |
Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 128 | VLOG(compiler) << "Method " << PrettyMethod(method_index, caller_dex_file) |
Nicolas Geoffray | c0365b1 | 2015-03-18 18:31:52 +0000 | [diff] [blame] | 129 | << " was already flagged as non inlineable"; |
| 130 | return false; |
| 131 | } |
| 132 | |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 133 | if (invoke_instruction->IsInvokeStaticOrDirect() && |
| 134 | invoke_instruction->AsInvokeStaticOrDirect()->IsStaticWithImplicitClinitCheck()) { |
| 135 | // Case of a static method that cannot be inlined because it implicitly |
| 136 | // requires an initialization check of its declaring class. |
| 137 | VLOG(compiler) << "Method " << PrettyMethod(method_index, caller_dex_file) |
| 138 | << " is not inlined because it is static and requires a clinit" |
| 139 | << " check that cannot be emitted due to Dex cache limitations"; |
| 140 | return false; |
| 141 | } |
| 142 | |
Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 143 | if (!TryBuildAndInline(resolved_method, invoke_instruction, method_index, can_use_dex_cache)) { |
Nicolas Geoffray | c0365b1 | 2015-03-18 18:31:52 +0000 | [diff] [blame] | 144 | return false; |
| 145 | } |
| 146 | |
Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 147 | VLOG(compiler) << "Successfully inlined " << PrettyMethod(method_index, caller_dex_file); |
Nicolas Geoffray | c0365b1 | 2015-03-18 18:31:52 +0000 | [diff] [blame] | 148 | MaybeRecordStat(kInlinedInvoke); |
| 149 | return true; |
| 150 | } |
| 151 | |
Mathieu Chartier | 3d21bdf | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 152 | bool HInliner::TryBuildAndInline(ArtMethod* resolved_method, |
Nicolas Geoffray | c0365b1 | 2015-03-18 18:31:52 +0000 | [diff] [blame] | 153 | HInvoke* invoke_instruction, |
Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 154 | uint32_t method_index, |
| 155 | bool can_use_dex_cache) const { |
Nicolas Geoffray | c0365b1 | 2015-03-18 18:31:52 +0000 | [diff] [blame] | 156 | ScopedObjectAccess soa(Thread::Current()); |
| 157 | const DexFile::CodeItem* code_item = resolved_method->GetCodeItem(); |
Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 158 | const DexFile& caller_dex_file = *caller_compilation_unit_.GetDexFile(); |
Nicolas Geoffray | c0365b1 | 2015-03-18 18:31:52 +0000 | [diff] [blame] | 159 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 160 | DexCompilationUnit dex_compilation_unit( |
| 161 | nullptr, |
Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 162 | caller_compilation_unit_.GetClassLoader(), |
| 163 | caller_compilation_unit_.GetClassLinker(), |
| 164 | *resolved_method->GetDexFile(), |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 165 | code_item, |
| 166 | resolved_method->GetDeclaringClass()->GetDexClassDefIndex(), |
Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 167 | resolved_method->GetDexMethodIndex(), |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 168 | resolved_method->GetAccessFlags(), |
| 169 | nullptr); |
| 170 | |
Nicolas Geoffray | e0fe7ae | 2015-03-09 10:02:49 +0000 | [diff] [blame] | 171 | HGraph* callee_graph = new (graph_->GetArena()) HGraph( |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 172 | graph_->GetArena(), |
| 173 | caller_dex_file, |
| 174 | method_index, |
Mathieu Chartier | 3d21bdf | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 175 | compiler_driver_->GetInstructionSet(), |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 176 | graph_->IsDebuggable(), |
| 177 | graph_->GetCurrentInstructionId()); |
David Brazdil | 5e8b137 | 2015-01-23 14:39:08 +0000 | [diff] [blame] | 178 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 179 | OptimizingCompilerStats inline_stats; |
David Brazdil | 5e8b137 | 2015-01-23 14:39:08 +0000 | [diff] [blame] | 180 | HGraphBuilder builder(callee_graph, |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 181 | &dex_compilation_unit, |
| 182 | &outer_compilation_unit_, |
Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 183 | resolved_method->GetDexFile(), |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 184 | compiler_driver_, |
| 185 | &inline_stats); |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 186 | |
David Brazdil | 5e8b137 | 2015-01-23 14:39:08 +0000 | [diff] [blame] | 187 | if (!builder.BuildGraph(*code_item)) { |
Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 188 | VLOG(compiler) << "Method " << PrettyMethod(method_index, caller_dex_file) |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 189 | << " could not be built, so cannot be inlined"; |
Nicolas Geoffray | 2653149 | 2015-05-27 12:53:36 +0100 | [diff] [blame] | 190 | // There could be multiple reasons why the graph could not be built, including |
| 191 | // unaccessible methods/fields due to using a different dex cache. We do not mark |
| 192 | // the method as non-inlineable so that other callers can still try to inline it. |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 193 | return false; |
| 194 | } |
| 195 | |
Nicolas Geoffray | 259136f | 2014-12-17 23:21:58 +0000 | [diff] [blame] | 196 | if (!RegisterAllocator::CanAllocateRegistersFor(*callee_graph, |
| 197 | compiler_driver_->GetInstructionSet())) { |
Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 198 | VLOG(compiler) << "Method " << PrettyMethod(method_index, caller_dex_file) |
Nicolas Geoffray | 259136f | 2014-12-17 23:21:58 +0000 | [diff] [blame] | 199 | << " cannot be inlined because of the register allocator"; |
Nicolas Geoffray | 4fa04a6 | 2015-05-26 14:35:06 +0100 | [diff] [blame] | 200 | resolved_method->SetShouldNotInline(); |
Nicolas Geoffray | 259136f | 2014-12-17 23:21:58 +0000 | [diff] [blame] | 201 | return false; |
| 202 | } |
| 203 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 204 | if (!callee_graph->TryBuildingSsa()) { |
Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 205 | VLOG(compiler) << "Method " << PrettyMethod(method_index, caller_dex_file) |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 206 | << " could not be transformed to SSA"; |
Nicolas Geoffray | 4fa04a6 | 2015-05-26 14:35:06 +0100 | [diff] [blame] | 207 | resolved_method->SetShouldNotInline(); |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 208 | return false; |
| 209 | } |
| 210 | |
Nicolas Geoffray | ef87c5d | 2015-01-30 12:41:14 +0000 | [diff] [blame] | 211 | // Run simple optimizations on the graph. |
Calin Juravle | 7a9c885 | 2015-04-21 14:07:50 +0100 | [diff] [blame] | 212 | HDeadCodeElimination dce(callee_graph, stats_); |
Nicolas Geoffray | ef87c5d | 2015-01-30 12:41:14 +0000 | [diff] [blame] | 213 | HConstantFolding fold(callee_graph); |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 214 | InstructionSimplifier simplify(callee_graph, stats_); |
Nicolas Geoffray | ef87c5d | 2015-01-30 12:41:14 +0000 | [diff] [blame] | 215 | |
| 216 | HOptimization* optimizations[] = { |
Nicolas Geoffray | ef87c5d | 2015-01-30 12:41:14 +0000 | [diff] [blame] | 217 | &dce, |
| 218 | &fold, |
| 219 | &simplify, |
| 220 | }; |
| 221 | |
| 222 | for (size_t i = 0; i < arraysize(optimizations); ++i) { |
| 223 | HOptimization* optimization = optimizations[i]; |
| 224 | optimization->Run(); |
| 225 | } |
| 226 | |
Calin Juravle | 8f96df8 | 2015-07-29 15:58:48 +0100 | [diff] [blame^] | 227 | if (depth_ + 1 < compiler_driver_->GetCompilerOptions().GetInlineDepthLimit()) { |
Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 228 | HInliner inliner(callee_graph, |
| 229 | outer_compilation_unit_, |
| 230 | dex_compilation_unit, |
| 231 | compiler_driver_, |
| 232 | stats_, |
| 233 | depth_ + 1); |
Nicolas Geoffray | ef87c5d | 2015-01-30 12:41:14 +0000 | [diff] [blame] | 234 | inliner.Run(); |
| 235 | } |
| 236 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 237 | HReversePostOrderIterator it(*callee_graph); |
Nicolas Geoffray | ef87c5d | 2015-01-30 12:41:14 +0000 | [diff] [blame] | 238 | it.Advance(); // Past the entry block, it does not contain instructions that prevent inlining. |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 239 | for (; !it.Done(); it.Advance()) { |
| 240 | HBasicBlock* block = it.Current(); |
| 241 | if (block->IsLoopHeader()) { |
Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 242 | VLOG(compiler) << "Method " << PrettyMethod(method_index, caller_dex_file) |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 243 | << " could not be inlined because it contains a loop"; |
Nicolas Geoffray | 4fa04a6 | 2015-05-26 14:35:06 +0100 | [diff] [blame] | 244 | resolved_method->SetShouldNotInline(); |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 245 | return false; |
| 246 | } |
| 247 | |
| 248 | for (HInstructionIterator instr_it(block->GetInstructions()); |
| 249 | !instr_it.Done(); |
| 250 | instr_it.Advance()) { |
| 251 | HInstruction* current = instr_it.Current(); |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 252 | if (current->IsSuspendCheck()) { |
| 253 | continue; |
| 254 | } |
| 255 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 256 | if (current->CanThrow()) { |
Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 257 | VLOG(compiler) << "Method " << PrettyMethod(method_index, caller_dex_file) |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 258 | << " could not be inlined because " << current->DebugName() |
| 259 | << " can throw"; |
| 260 | return false; |
| 261 | } |
| 262 | |
| 263 | if (current->NeedsEnvironment()) { |
Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 264 | VLOG(compiler) << "Method " << PrettyMethod(method_index, caller_dex_file) |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 265 | << " could not be inlined because " << current->DebugName() |
| 266 | << " needs an environment"; |
| 267 | return false; |
| 268 | } |
Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 269 | |
| 270 | if (!can_use_dex_cache && current->NeedsDexCache()) { |
| 271 | VLOG(compiler) << "Method " << PrettyMethod(method_index, caller_dex_file) |
| 272 | << " could not be inlined because " << current->DebugName() |
| 273 | << " it is in a different dex file and requires access to the dex cache"; |
Nicolas Geoffray | 4fa04a6 | 2015-05-26 14:35:06 +0100 | [diff] [blame] | 274 | // Do not flag the method as not-inlineable. A caller within the same |
| 275 | // dex file could still successfully inline it. |
Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 276 | return false; |
| 277 | } |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 278 | } |
| 279 | } |
| 280 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 281 | callee_graph->InlineInto(graph_, invoke_instruction); |
Nicolas Geoffray | 7c5367b | 2014-12-17 10:13:46 +0000 | [diff] [blame] | 282 | |
Mark Mendell | 1152c92 | 2015-04-24 17:06:35 -0400 | [diff] [blame] | 283 | if (callee_graph->HasBoundsChecks()) { |
| 284 | graph_->SetHasBoundsChecks(true); |
Mingyao Yang | e4335eb | 2015-03-02 15:14:13 -0800 | [diff] [blame] | 285 | } |
| 286 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 287 | return true; |
| 288 | } |
| 289 | |
| 290 | } // namespace art |