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 | #ifndef ART_COMPILER_OPTIMIZING_INLINER_H_ |
| 18 | #define ART_COMPILER_OPTIMIZING_INLINER_H_ |
| 19 | |
David Sehr | 9e734c7 | 2018-01-04 17:56:19 -0800 | [diff] [blame] | 20 | #include "dex/dex_file_types.h" |
David Sehr | 8c0961f | 2018-01-23 16:11:38 -0800 | [diff] [blame] | 21 | #include "dex/invoke_type.h" |
Andreas Gampe | 8cf9cb3 | 2017-07-19 09:28:38 -0700 | [diff] [blame] | 22 | #include "optimization.h" |
David Sehr | 82d046e | 2018-04-23 08:14:19 -0700 | [diff] [blame] | 23 | #include "profile/profile_compilation_info.h" |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 24 | |
Vladimir Marko | 0a51605 | 2019-10-14 13:00:44 +0000 | [diff] [blame] | 25 | namespace art { |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 26 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 27 | class CodeGenerator; |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 28 | class DexCompilationUnit; |
| 29 | class HGraph; |
| 30 | class HInvoke; |
| 31 | class OptimizingCompilerStats; |
| 32 | |
| 33 | class HInliner : public HOptimization { |
| 34 | public: |
| 35 | HInliner(HGraph* outer_graph, |
Nicolas Geoffray | 73be1e8 | 2015-09-17 15:22:56 +0100 | [diff] [blame] | 36 | HGraph* outermost_graph, |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 37 | CodeGenerator* codegen, |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 38 | const DexCompilationUnit& outer_compilation_unit, |
Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 39 | const DexCompilationUnit& caller_compilation_unit, |
Nicolas Geoffray | ef87c5d | 2015-01-30 12:41:14 +0000 | [diff] [blame] | 40 | OptimizingCompilerStats* stats, |
Nicolas Geoffray | 5949fa0 | 2015-12-18 10:57:10 +0000 | [diff] [blame] | 41 | size_t total_number_of_dex_registers, |
Nicolas Geoffray | f6d4668 | 2017-02-28 17:41:45 +0000 | [diff] [blame] | 42 | size_t total_number_of_instructions, |
| 43 | HInliner* parent, |
Aart Bik | 2ca10eb | 2017-11-15 15:17:53 -0800 | [diff] [blame] | 44 | size_t depth = 0, |
| 45 | const char* name = kInlinerPassName) |
| 46 | : HOptimization(outer_graph, name, stats), |
Nicolas Geoffray | 73be1e8 | 2015-09-17 15:22:56 +0100 | [diff] [blame] | 47 | outermost_graph_(outermost_graph), |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 48 | outer_compilation_unit_(outer_compilation_unit), |
Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 49 | caller_compilation_unit_(caller_compilation_unit), |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 50 | codegen_(codegen), |
Nicolas Geoffray | 5949fa0 | 2015-12-18 10:57:10 +0000 | [diff] [blame] | 51 | total_number_of_dex_registers_(total_number_of_dex_registers), |
Nicolas Geoffray | f6d4668 | 2017-02-28 17:41:45 +0000 | [diff] [blame] | 52 | total_number_of_instructions_(total_number_of_instructions), |
| 53 | parent_(parent), |
Nicolas Geoffray | 454a481 | 2015-06-09 10:37:32 +0100 | [diff] [blame] | 54 | depth_(depth), |
Nicolas Geoffray | f6d4668 | 2017-02-28 17:41:45 +0000 | [diff] [blame] | 55 | inlining_budget_(0), |
Vladimir Marko | 438709f | 2017-02-23 18:56:13 +0000 | [diff] [blame] | 56 | inline_stats_(nullptr) {} |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 57 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 58 | bool Run() override; |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 59 | |
Andreas Gampe | 7c3952f | 2015-02-19 18:21:24 -0800 | [diff] [blame] | 60 | static constexpr const char* kInlinerPassName = "inliner"; |
| 61 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 62 | private: |
Calin Juravle | 13439f0 | 2017-02-21 01:17:21 -0800 | [diff] [blame] | 63 | enum InlineCacheType { |
| 64 | kInlineCacheNoData = 0, |
| 65 | kInlineCacheUninitialized = 1, |
| 66 | kInlineCacheMonomorphic = 2, |
| 67 | kInlineCachePolymorphic = 3, |
| 68 | kInlineCacheMegamorphic = 4, |
| 69 | kInlineCacheMissingTypes = 5 |
| 70 | }; |
| 71 | |
Nicolas Geoffray | e418dda | 2015-08-11 20:03:09 -0700 | [diff] [blame] | 72 | bool TryInline(HInvoke* invoke_instruction); |
Nicolas Geoffray | 73be1e8 | 2015-09-17 15:22:56 +0100 | [diff] [blame] | 73 | |
Eric Holk | 1868de9 | 2020-02-12 09:10:21 -0800 | [diff] [blame] | 74 | // Attempt to resolve the target of the invoke instruction to an acutal call |
| 75 | // target. |
| 76 | // |
| 77 | // Returns the target directly in the case of static or direct invokes. |
| 78 | // Otherwise, uses CHA devirtualization or other methods to try to find the |
| 79 | // call target. |
| 80 | ArtMethod* FindActualCallTarget(HInvoke* invoke_instruction, bool* cha_devirtualize) |
| 81 | REQUIRES_SHARED(Locks::mutator_lock_); |
| 82 | |
Nicolas Geoffray | 73be1e8 | 2015-09-17 15:22:56 +0100 | [diff] [blame] | 83 | // Try to inline `resolved_method` in place of `invoke_instruction`. `do_rtp` is whether |
Nicolas Geoffray | 55bd749 | 2016-02-16 15:37:12 +0000 | [diff] [blame] | 84 | // reference type propagation can run after the inlining. If the inlining is successful, this |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 85 | // method will replace and remove the `invoke_instruction`. If `cha_devirtualize` is true, |
| 86 | // a CHA guard needs to be added for the inlining. |
| 87 | bool TryInlineAndReplace(HInvoke* invoke_instruction, |
| 88 | ArtMethod* resolved_method, |
Nicolas Geoffray | 0f001b7 | 2017-01-04 16:46:23 +0000 | [diff] [blame] | 89 | ReferenceTypeInfo receiver_type, |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 90 | bool do_rtp, |
| 91 | bool cha_devirtualize) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 92 | REQUIRES_SHARED(Locks::mutator_lock_); |
Nicolas Geoffray | 73be1e8 | 2015-09-17 15:22:56 +0100 | [diff] [blame] | 93 | |
Nicolas Geoffray | 55bd749 | 2016-02-16 15:37:12 +0000 | [diff] [blame] | 94 | bool TryBuildAndInline(HInvoke* invoke_instruction, |
| 95 | ArtMethod* resolved_method, |
Nicolas Geoffray | 0f001b7 | 2017-01-04 16:46:23 +0000 | [diff] [blame] | 96 | ReferenceTypeInfo receiver_type, |
Nicolas Geoffray | 55bd749 | 2016-02-16 15:37:12 +0000 | [diff] [blame] | 97 | HInstruction** return_replacement) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 98 | REQUIRES_SHARED(Locks::mutator_lock_); |
Nicolas Geoffray | 55bd749 | 2016-02-16 15:37:12 +0000 | [diff] [blame] | 99 | |
| 100 | bool TryBuildAndInlineHelper(HInvoke* invoke_instruction, |
| 101 | ArtMethod* resolved_method, |
Nicolas Geoffray | 0f001b7 | 2017-01-04 16:46:23 +0000 | [diff] [blame] | 102 | ReferenceTypeInfo receiver_type, |
Eric Holk | 1868de9 | 2020-02-12 09:10:21 -0800 | [diff] [blame] | 103 | HInstruction** return_replacement) |
| 104 | REQUIRES_SHARED(Locks::mutator_lock_); |
| 105 | |
| 106 | // Substitutes parameters in the callee graph with their values from the caller. |
| 107 | void SubstituteArguments(HGraph* callee_graph, |
| 108 | HInvoke* invoke_instruction, |
| 109 | ReferenceTypeInfo receiver_type, |
| 110 | const DexCompilationUnit& dex_compilation_unit) |
| 111 | REQUIRES_SHARED(Locks::mutator_lock_); |
Nicolas Geoffray | 55bd749 | 2016-02-16 15:37:12 +0000 | [diff] [blame] | 112 | |
Roland Levillain | a3aef2e | 2016-04-06 17:45:58 +0100 | [diff] [blame] | 113 | // Run simple optimizations on `callee_graph`. |
Nicolas Geoffray | f6d4668 | 2017-02-28 17:41:45 +0000 | [diff] [blame] | 114 | void RunOptimizations(HGraph* callee_graph, |
Andreas Gampe | 3f1dcd3 | 2018-12-28 09:39:56 -0800 | [diff] [blame] | 115 | const dex::CodeItem* code_item, |
Nicolas Geoffray | f6d4668 | 2017-02-28 17:41:45 +0000 | [diff] [blame] | 116 | const DexCompilationUnit& dex_compilation_unit) |
| 117 | REQUIRES_SHARED(Locks::mutator_lock_); |
Roland Levillain | a3aef2e | 2016-04-06 17:45:58 +0100 | [diff] [blame] | 118 | |
Vladimir Marko | be10e8e | 2016-01-22 12:09:44 +0000 | [diff] [blame] | 119 | // Try to recognize known simple patterns and replace invoke call with appropriate instructions. |
Nicolas Geoffray | 55bd749 | 2016-02-16 15:37:12 +0000 | [diff] [blame] | 120 | bool TryPatternSubstitution(HInvoke* invoke_instruction, |
Nicolas Geoffray | e6c0f2a | 2020-09-07 08:30:52 +0100 | [diff] [blame] | 121 | ArtMethod* method, |
Nicolas Geoffray | 55bd749 | 2016-02-16 15:37:12 +0000 | [diff] [blame] | 122 | HInstruction** return_replacement) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 123 | REQUIRES_SHARED(Locks::mutator_lock_); |
Vladimir Marko | be10e8e | 2016-01-22 12:09:44 +0000 | [diff] [blame] | 124 | |
Eric Holk | 1868de9 | 2020-02-12 09:10:21 -0800 | [diff] [blame] | 125 | // Returns whether inlining is allowed based on ART semantics. |
| 126 | bool IsInliningAllowed(art::ArtMethod* method, const CodeItemDataAccessor& accessor) const |
| 127 | REQUIRES_SHARED(Locks::mutator_lock_); |
| 128 | |
| 129 | |
| 130 | // Returns whether ART supports inlining this method. |
| 131 | // |
| 132 | // Some methods are not supported because they have features for which inlining |
| 133 | // is not implemented. For example, we do not currently support inlining throw |
| 134 | // instructions into a try block. |
| 135 | bool IsInliningSupported(const HInvoke* invoke_instruction, |
| 136 | art::ArtMethod* method, |
| 137 | const CodeItemDataAccessor& accessor) const |
| 138 | REQUIRES_SHARED(Locks::mutator_lock_); |
| 139 | |
| 140 | // Returns whether the inlining budget allows inlining method. |
| 141 | // |
| 142 | // For example, this checks whether the function has grown too large and |
| 143 | // inlining should be prevented. |
| 144 | bool IsInliningBudgetAvailable(art::ArtMethod* method, const CodeItemDataAccessor& accessor) const |
| 145 | REQUIRES_SHARED(Locks::mutator_lock_); |
| 146 | |
| 147 | // Inspects the body of a method (callee_graph) and returns whether it can be |
| 148 | // inlined. |
| 149 | // |
| 150 | // This checks for instructions and constructs that we do not support |
| 151 | // inlining, such as inlining a throw instruction into a try block. |
| 152 | bool CanInlineBody(const HGraph* callee_graph, |
| 153 | const HBasicBlock* target_block, |
| 154 | size_t* out_number_of_instructions) const |
| 155 | REQUIRES_SHARED(Locks::mutator_lock_); |
| 156 | |
Vladimir Marko | be10e8e | 2016-01-22 12:09:44 +0000 | [diff] [blame] | 157 | // Create a new HInstanceFieldGet. |
Vladimir Marko | f44d36c | 2017-03-14 14:18:46 +0000 | [diff] [blame] | 158 | HInstanceFieldGet* CreateInstanceFieldGet(uint32_t field_index, |
| 159 | ArtMethod* referrer, |
Vladimir Marko | be10e8e | 2016-01-22 12:09:44 +0000 | [diff] [blame] | 160 | HInstruction* obj); |
| 161 | // Create a new HInstanceFieldSet. |
Vladimir Marko | f44d36c | 2017-03-14 14:18:46 +0000 | [diff] [blame] | 162 | HInstanceFieldSet* CreateInstanceFieldSet(uint32_t field_index, |
| 163 | ArtMethod* referrer, |
Vladimir Marko | be10e8e | 2016-01-22 12:09:44 +0000 | [diff] [blame] | 164 | HInstruction* obj, |
Vladimir Marko | f44d36c | 2017-03-14 14:18:46 +0000 | [diff] [blame] | 165 | HInstruction* value, |
| 166 | bool* is_final = nullptr); |
Vladimir Marko | be10e8e | 2016-01-22 12:09:44 +0000 | [diff] [blame] | 167 | |
Calin Juravle | 13439f0 | 2017-02-21 01:17:21 -0800 | [diff] [blame] | 168 | // Try inlining the invoke instruction using inline caches. |
Nicolas Geoffray | e6c0f2a | 2020-09-07 08:30:52 +0100 | [diff] [blame] | 169 | bool TryInlineFromInlineCache(HInvoke* invoke_instruction) |
Calin Juravle | 13439f0 | 2017-02-21 01:17:21 -0800 | [diff] [blame] | 170 | REQUIRES_SHARED(Locks::mutator_lock_); |
| 171 | |
| 172 | // Try getting the inline cache from JIT code cache. |
| 173 | // Return true if the inline cache was successfully allocated and the |
| 174 | // invoke info was found in the profile info. |
| 175 | InlineCacheType GetInlineCacheJIT( |
| 176 | HInvoke* invoke_instruction, |
| 177 | StackHandleScope<1>* hs, |
| 178 | /*out*/Handle<mirror::ObjectArray<mirror::Class>>* inline_cache) |
| 179 | REQUIRES_SHARED(Locks::mutator_lock_); |
| 180 | |
| 181 | // Try getting the inline cache from AOT offline profile. |
| 182 | // Return true if the inline cache was successfully allocated and the |
| 183 | // invoke info was found in the profile info. |
Nicolas Geoffray | e6c0f2a | 2020-09-07 08:30:52 +0100 | [diff] [blame] | 184 | InlineCacheType GetInlineCacheAOT( |
Calin Juravle | 13439f0 | 2017-02-21 01:17:21 -0800 | [diff] [blame] | 185 | HInvoke* invoke_instruction, |
| 186 | StackHandleScope<1>* hs, |
| 187 | /*out*/Handle<mirror::ObjectArray<mirror::Class>>* inline_cache) |
| 188 | REQUIRES_SHARED(Locks::mutator_lock_); |
| 189 | |
| 190 | // Extract the mirror classes from the offline profile and add them to the `inline_cache`. |
| 191 | // Note that even if we have profile data for the invoke the inline_cache might contain |
| 192 | // only null entries if the types cannot be resolved. |
| 193 | InlineCacheType ExtractClassesFromOfflineProfile( |
| 194 | const HInvoke* invoke_instruction, |
| 195 | const ProfileCompilationInfo::OfflineProfileMethodInfo& offline_profile, |
| 196 | /*out*/Handle<mirror::ObjectArray<mirror::Class>> inline_cache) |
| 197 | REQUIRES_SHARED(Locks::mutator_lock_); |
| 198 | |
| 199 | // Compute the inline cache type. |
| 200 | InlineCacheType GetInlineCacheType( |
| 201 | const Handle<mirror::ObjectArray<mirror::Class>>& classes) |
| 202 | REQUIRES_SHARED(Locks::mutator_lock_); |
| 203 | |
Nicolas Geoffray | 73be1e8 | 2015-09-17 15:22:56 +0100 | [diff] [blame] | 204 | // Try to inline the target of a monomorphic call. If successful, the code |
| 205 | // in the graph will look like: |
| 206 | // if (receiver.getClass() != ic.GetMonomorphicType()) deopt |
| 207 | // ... // inlined code |
| 208 | bool TryInlineMonomorphicCall(HInvoke* invoke_instruction, |
Nicolas Geoffray | e51ca8b | 2016-11-22 14:49:31 +0000 | [diff] [blame] | 209 | Handle<mirror::ObjectArray<mirror::Class>> classes) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 210 | REQUIRES_SHARED(Locks::mutator_lock_); |
Nicolas Geoffray | 73be1e8 | 2015-09-17 15:22:56 +0100 | [diff] [blame] | 211 | |
Nicolas Geoffray | 916cc1d | 2016-02-18 11:12:31 +0000 | [diff] [blame] | 212 | // Try to inline targets of a polymorphic call. |
Nicolas Geoffray | 73be1e8 | 2015-09-17 15:22:56 +0100 | [diff] [blame] | 213 | bool TryInlinePolymorphicCall(HInvoke* invoke_instruction, |
Nicolas Geoffray | e51ca8b | 2016-11-22 14:49:31 +0000 | [diff] [blame] | 214 | Handle<mirror::ObjectArray<mirror::Class>> classes) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 215 | REQUIRES_SHARED(Locks::mutator_lock_); |
Nicolas Geoffray | 73be1e8 | 2015-09-17 15:22:56 +0100 | [diff] [blame] | 216 | |
Nicolas Geoffray | 916cc1d | 2016-02-18 11:12:31 +0000 | [diff] [blame] | 217 | bool TryInlinePolymorphicCallToSameTarget(HInvoke* invoke_instruction, |
Nicolas Geoffray | e51ca8b | 2016-11-22 14:49:31 +0000 | [diff] [blame] | 218 | Handle<mirror::ObjectArray<mirror::Class>> classes) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 219 | REQUIRES_SHARED(Locks::mutator_lock_); |
Nicolas Geoffray | 916cc1d | 2016-02-18 11:12:31 +0000 | [diff] [blame] | 220 | |
Calin Juravle | af44e6c | 2017-05-23 14:24:55 -0700 | [diff] [blame] | 221 | // Returns whether or not we should use only polymorphic inlining with no deoptimizations. |
| 222 | bool UseOnlyPolymorphicInliningWithNoDeopt(); |
| 223 | |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 224 | // Try CHA-based devirtualization to change virtual method calls into |
| 225 | // direct calls. |
| 226 | // Returns the actual method that resolved_method can be devirtualized to. |
| 227 | ArtMethod* TryCHADevirtualization(ArtMethod* resolved_method) |
| 228 | REQUIRES_SHARED(Locks::mutator_lock_); |
| 229 | |
| 230 | // Add a CHA guard for a CHA-based devirtualized call. A CHA guard checks a |
| 231 | // should_deoptimize flag and if it's true, does deoptimization. |
| 232 | void AddCHAGuard(HInstruction* invoke_instruction, |
| 233 | uint32_t dex_pc, |
| 234 | HInstruction* cursor, |
| 235 | HBasicBlock* bb_cursor); |
Nicolas Geoffray | 916cc1d | 2016-02-18 11:12:31 +0000 | [diff] [blame] | 236 | |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 237 | HInstanceFieldGet* BuildGetReceiverClass(ClassLinker* class_linker, |
| 238 | HInstruction* receiver, |
| 239 | uint32_t dex_pc) const |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 240 | REQUIRES_SHARED(Locks::mutator_lock_); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 241 | |
David Brazdil | 94ab38f | 2016-06-21 17:48:19 +0100 | [diff] [blame] | 242 | void FixUpReturnReferenceType(ArtMethod* resolved_method, HInstruction* return_replacement) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 243 | REQUIRES_SHARED(Locks::mutator_lock_); |
David Brazdil | 94ab38f | 2016-06-21 17:48:19 +0100 | [diff] [blame] | 244 | |
David Brazdil | 94ab38f | 2016-06-21 17:48:19 +0100 | [diff] [blame] | 245 | bool ArgumentTypesMoreSpecific(HInvoke* invoke_instruction, ArtMethod* resolved_method) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 246 | REQUIRES_SHARED(Locks::mutator_lock_); |
David Brazdil | 94ab38f | 2016-06-21 17:48:19 +0100 | [diff] [blame] | 247 | |
| 248 | bool ReturnTypeMoreSpecific(HInvoke* invoke_instruction, HInstruction* return_replacement) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 249 | REQUIRES_SHARED(Locks::mutator_lock_); |
Vladimir Marko | be10e8e | 2016-01-22 12:09:44 +0000 | [diff] [blame] | 250 | |
Nicolas Geoffray | 916cc1d | 2016-02-18 11:12:31 +0000 | [diff] [blame] | 251 | // Add a type guard on the given `receiver`. This will add to the graph: |
| 252 | // i0 = HFieldGet(receiver, klass) |
| 253 | // i1 = HLoadClass(class_index, is_referrer) |
| 254 | // i2 = HNotEqual(i0, i1) |
| 255 | // |
| 256 | // And if `with_deoptimization` is true: |
| 257 | // HDeoptimize(i2) |
| 258 | // |
| 259 | // The method returns the `HNotEqual`, that will be used for polymorphic inlining. |
| 260 | HInstruction* AddTypeGuard(HInstruction* receiver, |
| 261 | HInstruction* cursor, |
| 262 | HBasicBlock* bb_cursor, |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 263 | dex::TypeIndex class_index, |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 264 | Handle<mirror::Class> klass, |
Nicolas Geoffray | 916cc1d | 2016-02-18 11:12:31 +0000 | [diff] [blame] | 265 | HInstruction* invoke_instruction, |
| 266 | bool with_deoptimization) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 267 | REQUIRES_SHARED(Locks::mutator_lock_); |
Nicolas Geoffray | 916cc1d | 2016-02-18 11:12:31 +0000 | [diff] [blame] | 268 | |
| 269 | /* |
| 270 | * Ad-hoc implementation for implementing a diamond pattern in the graph for |
| 271 | * polymorphic inlining: |
| 272 | * 1) `compare` becomes the input of the new `HIf`. |
| 273 | * 2) Everything up until `invoke_instruction` is in the then branch (could |
| 274 | * contain multiple blocks). |
| 275 | * 3) `invoke_instruction` is moved to the otherwise block. |
| 276 | * 4) If `return_replacement` is not null, the merge block will have |
| 277 | * a phi whose inputs are `return_replacement` and `invoke_instruction`. |
| 278 | * |
| 279 | * Before: |
| 280 | * Block1 |
| 281 | * compare |
| 282 | * ... |
| 283 | * invoke_instruction |
| 284 | * |
| 285 | * After: |
| 286 | * Block1 |
| 287 | * compare |
| 288 | * if |
| 289 | * / \ |
| 290 | * / \ |
| 291 | * Then block Otherwise block |
| 292 | * ... invoke_instruction |
| 293 | * \ / |
| 294 | * \ / |
| 295 | * Merge block |
| 296 | * phi(return_replacement, invoke_instruction) |
| 297 | */ |
| 298 | void CreateDiamondPatternForPolymorphicInline(HInstruction* compare, |
| 299 | HInstruction* return_replacement, |
| 300 | HInstruction* invoke_instruction); |
| 301 | |
Nicolas Geoffray | f6d4668 | 2017-02-28 17:41:45 +0000 | [diff] [blame] | 302 | // Update the inlining budget based on `total_number_of_instructions_`. |
| 303 | void UpdateInliningBudget(); |
| 304 | |
| 305 | // Count the number of calls of `method` being inlined recursively. |
| 306 | size_t CountRecursiveCallsOf(ArtMethod* method) const; |
| 307 | |
| 308 | // Pretty-print for spaces during logging. |
| 309 | std::string DepthString(int line) const; |
| 310 | |
Nicolas Geoffray | 73be1e8 | 2015-09-17 15:22:56 +0100 | [diff] [blame] | 311 | HGraph* const outermost_graph_; |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 312 | const DexCompilationUnit& outer_compilation_unit_; |
Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 313 | const DexCompilationUnit& caller_compilation_unit_; |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 314 | CodeGenerator* const codegen_; |
Nicolas Geoffray | 5949fa0 | 2015-12-18 10:57:10 +0000 | [diff] [blame] | 315 | const size_t total_number_of_dex_registers_; |
Nicolas Geoffray | f6d4668 | 2017-02-28 17:41:45 +0000 | [diff] [blame] | 316 | size_t total_number_of_instructions_; |
| 317 | |
| 318 | // The 'parent' inliner, that means the inlinigng optimization that requested |
| 319 | // `graph_` to be inlined. |
| 320 | const HInliner* const parent_; |
Nicolas Geoffray | ef87c5d | 2015-01-30 12:41:14 +0000 | [diff] [blame] | 321 | const size_t depth_; |
Nicolas Geoffray | f6d4668 | 2017-02-28 17:41:45 +0000 | [diff] [blame] | 322 | |
| 323 | // The budget left for inlining, in number of instructions. |
| 324 | size_t inlining_budget_; |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 325 | |
Vladimir Marko | 438709f | 2017-02-23 18:56:13 +0000 | [diff] [blame] | 326 | // Used to record stats about optimizations on the inlined graph. |
| 327 | // If the inlining is successful, these stats are merged to the caller graph's stats. |
| 328 | OptimizingCompilerStats* inline_stats_; |
| 329 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 330 | DISALLOW_COPY_AND_ASSIGN(HInliner); |
| 331 | }; |
| 332 | |
| 333 | } // namespace art |
| 334 | |
| 335 | #endif // ART_COMPILER_OPTIMIZING_INLINER_H_ |