blob: 17c0b928cf2c4669196ff3622a43442a3c8c6e08 [file] [log] [blame]
Aart Bik96fd51d2016-11-28 11:22:35 -08001/*
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
Vladimir Markoe2727152019-10-10 10:46:42 +010020#include "base/macros.h"
21
22namespace art HIDDEN {
Aart Bik96fd51d2016-11-28 11:22:35 -080023
24class HInstruction;
25
26/*
27 * Methods related to escape analysis, i.e. determining whether an object
28 * allocation is visible outside ('escapes') its immediate method context.
29 */
30
31/*
32 * Performs escape analysis on the given instruction, typically a reference to an
33 * allocation. The method assigns true to parameter 'is_singleton' if the reference
34 * is the only name that can refer to its value during the lifetime of the method,
35 * meaning that the reference is not aliased with something else, is not stored to
Aart Bik71bf7b42016-11-16 10:17:46 -080036 * heap memory, and not passed to another method. In addition, the method assigns
37 * true to parameter 'is_singleton_and_not_returned' if the reference is a singleton
38 * and not returned to the caller and to parameter 'is_singleton_and_not_deopt_visible'
39 * if the reference is a singleton and not used as an environment local of an
40 * HDeoptimize instruction (clients of the final value must run after BCE to ensure
41 * all such instructions have been introduced already).
42 *
43 * Note that being visible to a HDeoptimize instruction does not count for ordinary
44 * escape analysis, since switching between compiled code and interpreted code keeps
45 * non escaping references restricted to the lifetime of the method and the thread
46 * executing it. This property only concerns optimizations that are interested in
47 * escape analysis with respect to the *compiled* code (such as LSE).
Aart Bik96fd51d2016-11-28 11:22:35 -080048 *
49 * When set, the no_escape function is applied to any use of the allocation instruction
50 * prior to any built-in escape analysis. This allows clients to define better escape
51 * analysis in certain case-specific circumstances. If 'no_escape(reference, user)'
52 * returns true, the user is assumed *not* to cause any escape right away. The return
53 * value false means the client cannot provide a definite answer and built-in escape
54 * analysis is applied to the user instead.
55 */
56void CalculateEscape(HInstruction* reference,
57 bool (*no_escape)(HInstruction*, HInstruction*),
58 /*out*/ bool* is_singleton,
Aart Bik71bf7b42016-11-16 10:17:46 -080059 /*out*/ bool* is_singleton_and_not_returned,
60 /*out*/ bool* is_singleton_and_not_deopt_visible);
Aart Bik96fd51d2016-11-28 11:22:35 -080061
62/*
Aart Bik71bf7b42016-11-16 10:17:46 -080063 * Convenience method for testing the singleton and not returned properties at once.
Aart Bik96fd51d2016-11-28 11:22:35 -080064 * Callers should be aware that this method invokes the full analysis at each call.
65 */
Aart Bik71bf7b42016-11-16 10:17:46 -080066bool DoesNotEscape(HInstruction* reference, bool (*no_escape)(HInstruction*, HInstruction*));
Aart Bik96fd51d2016-11-28 11:22:35 -080067
68} // namespace art
69
70#endif // ART_COMPILER_OPTIMIZING_ESCAPE_H_