Aart Bik | 96fd51d | 2016-11-28 11:22:35 -0800 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright (C) 2016 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_ESCAPE_H_ |
| 18 | #define ART_COMPILER_OPTIMIZING_ESCAPE_H_ |
| 19 | |
| 20 | namespace art { |
| 21 | |
| 22 | class HInstruction; |
| 23 | |
| 24 | /* |
| 25 | * Methods related to escape analysis, i.e. determining whether an object |
| 26 | * allocation is visible outside ('escapes') its immediate method context. |
| 27 | */ |
| 28 | |
| 29 | /* |
| 30 | * Performs escape analysis on the given instruction, typically a reference to an |
| 31 | * allocation. The method assigns true to parameter 'is_singleton' if the reference |
| 32 | * is the only name that can refer to its value during the lifetime of the method, |
| 33 | * meaning that the reference is not aliased with something else, is not stored to |
| 34 | * heap memory, and not passed to another method. The method assigns true to parameter |
| 35 | * 'is_singleton_and_non_escaping' if the reference is a singleton and is not returned |
| 36 | * to the caller or used as an environment local of an HDeoptimize instruction. |
| 37 | * |
| 38 | * When set, the no_escape function is applied to any use of the allocation instruction |
| 39 | * prior to any built-in escape analysis. This allows clients to define better escape |
| 40 | * analysis in certain case-specific circumstances. If 'no_escape(reference, user)' |
| 41 | * returns true, the user is assumed *not* to cause any escape right away. The return |
| 42 | * value false means the client cannot provide a definite answer and built-in escape |
| 43 | * analysis is applied to the user instead. |
| 44 | */ |
| 45 | void CalculateEscape(HInstruction* reference, |
| 46 | bool (*no_escape)(HInstruction*, HInstruction*), |
| 47 | /*out*/ bool* is_singleton, |
| 48 | /*out*/ bool* is_singleton_and_non_escaping); |
| 49 | |
| 50 | /* |
| 51 | * Convenience method for testing singleton and non-escaping property at once. |
| 52 | * Callers should be aware that this method invokes the full analysis at each call. |
| 53 | */ |
| 54 | bool IsNonEscapingSingleton(HInstruction* reference, |
| 55 | bool (*no_escape)(HInstruction*, HInstruction*)); |
| 56 | |
| 57 | } // namespace art |
| 58 | |
| 59 | #endif // ART_COMPILER_OPTIMIZING_ESCAPE_H_ |