blob: 7b9fb73ccf92b92e2219d1e00e3924497caaab72 [file] [log] [blame]
Nicolas Geoffraye53798a2014-12-01 10:31:54 +00001/*
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
20#include "invoke_type.h"
21#include "optimization.h"
22
23namespace art {
24
Vladimir Markodc151b22015-10-15 18:02:30 +010025class CodeGenerator;
Nicolas Geoffraye53798a2014-12-01 10:31:54 +000026class CompilerDriver;
27class DexCompilationUnit;
28class HGraph;
29class HInvoke;
Nicolas Geoffray73be1e82015-09-17 15:22:56 +010030class InlineCache;
Nicolas Geoffraye53798a2014-12-01 10:31:54 +000031class OptimizingCompilerStats;
32
33class HInliner : public HOptimization {
34 public:
35 HInliner(HGraph* outer_graph,
Nicolas Geoffray73be1e82015-09-17 15:22:56 +010036 HGraph* outermost_graph,
Vladimir Markodc151b22015-10-15 18:02:30 +010037 CodeGenerator* codegen,
Nicolas Geoffraye53798a2014-12-01 10:31:54 +000038 const DexCompilationUnit& outer_compilation_unit,
Nicolas Geoffray9437b782015-03-25 10:08:51 +000039 const DexCompilationUnit& caller_compilation_unit,
Nicolas Geoffraye53798a2014-12-01 10:31:54 +000040 CompilerDriver* compiler_driver,
Nicolas Geoffray454a4812015-06-09 10:37:32 +010041 StackHandleScopeCollection* handles,
Nicolas Geoffrayef87c5d2015-01-30 12:41:14 +000042 OptimizingCompilerStats* stats,
Nicolas Geoffrayb17d1cc2015-12-17 15:26:21 +000043 size_t depth = 0)
David Brazdil69ba7b72015-06-23 18:27:30 +010044 : HOptimization(outer_graph, kInlinerPassName, stats),
Nicolas Geoffray73be1e82015-09-17 15:22:56 +010045 outermost_graph_(outermost_graph),
Nicolas Geoffraye53798a2014-12-01 10:31:54 +000046 outer_compilation_unit_(outer_compilation_unit),
Nicolas Geoffray9437b782015-03-25 10:08:51 +000047 caller_compilation_unit_(caller_compilation_unit),
Vladimir Markodc151b22015-10-15 18:02:30 +010048 codegen_(codegen),
Nicolas Geoffraye53798a2014-12-01 10:31:54 +000049 compiler_driver_(compiler_driver),
Nicolas Geoffray454a4812015-06-09 10:37:32 +010050 depth_(depth),
Nicolas Geoffraye418dda2015-08-11 20:03:09 -070051 number_of_inlined_instructions_(0),
Nicolas Geoffray454a4812015-06-09 10:37:32 +010052 handles_(handles) {}
Nicolas Geoffraye53798a2014-12-01 10:31:54 +000053
54 void Run() OVERRIDE;
55
Andreas Gampe7c3952f2015-02-19 18:21:24 -080056 static constexpr const char* kInlinerPassName = "inliner";
57
Nicolas Geoffraye53798a2014-12-01 10:31:54 +000058 private:
Nicolas Geoffraye418dda2015-08-11 20:03:09 -070059 bool TryInline(HInvoke* invoke_instruction);
Nicolas Geoffray73be1e82015-09-17 15:22:56 +010060
61 // Try to inline `resolved_method` in place of `invoke_instruction`. `do_rtp` is whether
62 // reference type propagation can run after the inlining.
63 bool TryInline(HInvoke* invoke_instruction, ArtMethod* resolved_method, bool do_rtp = true)
64 SHARED_REQUIRES(Locks::mutator_lock_);
65
66 // Try to inline the target of a monomorphic call. If successful, the code
67 // in the graph will look like:
68 // if (receiver.getClass() != ic.GetMonomorphicType()) deopt
69 // ... // inlined code
70 bool TryInlineMonomorphicCall(HInvoke* invoke_instruction,
71 ArtMethod* resolved_method,
72 const InlineCache& ic)
73 SHARED_REQUIRES(Locks::mutator_lock_);
74
75 // Try to inline targets of a polymorphic call. Currently unimplemented.
76 bool TryInlinePolymorphicCall(HInvoke* invoke_instruction,
77 ArtMethod* resolved_method,
78 const InlineCache& ic)
79 SHARED_REQUIRES(Locks::mutator_lock_);
80
Mathieu Chartiere401d142015-04-22 13:56:20 -070081 bool TryBuildAndInline(ArtMethod* resolved_method,
Nicolas Geoffrayc0365b12015-03-18 18:31:52 +000082 HInvoke* invoke_instruction,
Nicolas Geoffray73be1e82015-09-17 15:22:56 +010083 bool same_dex_file,
84 bool do_rtp = true);
Nicolas Geoffraye53798a2014-12-01 10:31:54 +000085
Nicolas Geoffray73be1e82015-09-17 15:22:56 +010086 HGraph* const outermost_graph_;
Nicolas Geoffraye53798a2014-12-01 10:31:54 +000087 const DexCompilationUnit& outer_compilation_unit_;
Nicolas Geoffray9437b782015-03-25 10:08:51 +000088 const DexCompilationUnit& caller_compilation_unit_;
Vladimir Markodc151b22015-10-15 18:02:30 +010089 CodeGenerator* const codegen_;
Nicolas Geoffraye53798a2014-12-01 10:31:54 +000090 CompilerDriver* const compiler_driver_;
Nicolas Geoffrayef87c5d2015-01-30 12:41:14 +000091 const size_t depth_;
Nicolas Geoffraye418dda2015-08-11 20:03:09 -070092 size_t number_of_inlined_instructions_;
Nicolas Geoffray454a4812015-06-09 10:37:32 +010093 StackHandleScopeCollection* const handles_;
Nicolas Geoffraye53798a2014-12-01 10:31:54 +000094
95 DISALLOW_COPY_AND_ASSIGN(HInliner);
96};
97
98} // namespace art
99
100#endif // ART_COMPILER_OPTIMIZING_INLINER_H_