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