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 | |
| 20 | #include "invoke_type.h" |
| 21 | #include "optimization.h" |
| 22 | |
| 23 | namespace art { |
| 24 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 25 | class CodeGenerator; |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 26 | class CompilerDriver; |
| 27 | class DexCompilationUnit; |
| 28 | class HGraph; |
| 29 | class HInvoke; |
Nicolas Geoffray | 73be1e8 | 2015-09-17 15:22:56 +0100 | [diff] [blame] | 30 | class InlineCache; |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 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 | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 40 | CompilerDriver* compiler_driver, |
Nicolas Geoffray | 454a481 | 2015-06-09 10:37:32 +0100 | [diff] [blame] | 41 | StackHandleScopeCollection* handles, |
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, |
| 44 | size_t depth) |
David Brazdil | 69ba7b7 | 2015-06-23 18:27:30 +0100 | [diff] [blame] | 45 | : HOptimization(outer_graph, kInlinerPassName, stats), |
Nicolas Geoffray | 73be1e8 | 2015-09-17 15:22:56 +0100 | [diff] [blame] | 46 | outermost_graph_(outermost_graph), |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 47 | outer_compilation_unit_(outer_compilation_unit), |
Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 48 | caller_compilation_unit_(caller_compilation_unit), |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 49 | codegen_(codegen), |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 50 | compiler_driver_(compiler_driver), |
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 | 454a481 | 2015-06-09 10:37:32 +0100 | [diff] [blame] | 52 | depth_(depth), |
Nicolas Geoffray | e418dda | 2015-08-11 20:03:09 -0700 | [diff] [blame] | 53 | number_of_inlined_instructions_(0), |
Nicolas Geoffray | 454a481 | 2015-06-09 10:37:32 +0100 | [diff] [blame] | 54 | handles_(handles) {} |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 55 | |
| 56 | void Run() OVERRIDE; |
| 57 | |
Andreas Gampe | 7c3952f | 2015-02-19 18:21:24 -0800 | [diff] [blame] | 58 | static constexpr const char* kInlinerPassName = "inliner"; |
| 59 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 60 | private: |
Nicolas Geoffray | e418dda | 2015-08-11 20:03:09 -0700 | [diff] [blame] | 61 | bool TryInline(HInvoke* invoke_instruction); |
Nicolas Geoffray | 73be1e8 | 2015-09-17 15:22:56 +0100 | [diff] [blame] | 62 | |
| 63 | // Try to inline `resolved_method` in place of `invoke_instruction`. `do_rtp` is whether |
| 64 | // reference type propagation can run after the inlining. |
| 65 | bool TryInline(HInvoke* invoke_instruction, ArtMethod* resolved_method, bool do_rtp = true) |
| 66 | SHARED_REQUIRES(Locks::mutator_lock_); |
| 67 | |
| 68 | // Try to inline the target of a monomorphic call. If successful, the code |
| 69 | // in the graph will look like: |
| 70 | // if (receiver.getClass() != ic.GetMonomorphicType()) deopt |
| 71 | // ... // inlined code |
| 72 | bool TryInlineMonomorphicCall(HInvoke* invoke_instruction, |
| 73 | ArtMethod* resolved_method, |
| 74 | const InlineCache& ic) |
| 75 | SHARED_REQUIRES(Locks::mutator_lock_); |
| 76 | |
| 77 | // Try to inline targets of a polymorphic call. Currently unimplemented. |
| 78 | bool TryInlinePolymorphicCall(HInvoke* invoke_instruction, |
| 79 | ArtMethod* resolved_method, |
| 80 | const InlineCache& ic) |
| 81 | SHARED_REQUIRES(Locks::mutator_lock_); |
| 82 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 83 | bool TryBuildAndInline(ArtMethod* resolved_method, |
Nicolas Geoffray | c0365b1 | 2015-03-18 18:31:52 +0000 | [diff] [blame] | 84 | HInvoke* invoke_instruction, |
Nicolas Geoffray | 73be1e8 | 2015-09-17 15:22:56 +0100 | [diff] [blame] | 85 | bool same_dex_file, |
| 86 | bool do_rtp = true); |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 87 | |
Nicolas Geoffray | 73be1e8 | 2015-09-17 15:22:56 +0100 | [diff] [blame] | 88 | HGraph* const outermost_graph_; |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 89 | const DexCompilationUnit& outer_compilation_unit_; |
Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 90 | const DexCompilationUnit& caller_compilation_unit_; |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 91 | CodeGenerator* const codegen_; |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 92 | CompilerDriver* const compiler_driver_; |
Nicolas Geoffray | 5949fa0 | 2015-12-18 10:57:10 +0000 | [diff] [blame] | 93 | const size_t total_number_of_dex_registers_; |
Nicolas Geoffray | ef87c5d | 2015-01-30 12:41:14 +0000 | [diff] [blame] | 94 | const size_t depth_; |
Nicolas Geoffray | e418dda | 2015-08-11 20:03:09 -0700 | [diff] [blame] | 95 | size_t number_of_inlined_instructions_; |
Nicolas Geoffray | 454a481 | 2015-06-09 10:37:32 +0100 | [diff] [blame] | 96 | StackHandleScopeCollection* const handles_; |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 97 | |
| 98 | DISALLOW_COPY_AND_ASSIGN(HInliner); |
| 99 | }; |
| 100 | |
| 101 | } // namespace art |
| 102 | |
| 103 | #endif // ART_COMPILER_OPTIMIZING_INLINER_H_ |