Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2015 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_SHARPENING_H_ |
| 18 | #define ART_COMPILER_OPTIMIZING_SHARPENING_H_ |
| 19 | |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 20 | #include "nodes.h" |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 21 | #include "optimization.h" |
| 22 | |
| 23 | namespace art { |
| 24 | |
| 25 | class CodeGenerator; |
| 26 | class CompilerDriver; |
| 27 | class DexCompilationUnit; |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 28 | |
| 29 | // Optimization that tries to improve the way we dispatch methods and access types, |
| 30 | // fields, etc. Besides actual method sharpening based on receiver type (for example |
| 31 | // virtual->direct), this includes selecting the best available dispatch for |
| 32 | // invoke-static/-direct based on code generator support. |
| 33 | class HSharpening : public HOptimization { |
| 34 | public: |
| 35 | HSharpening(HGraph* graph, |
| 36 | CodeGenerator* codegen, |
| 37 | const DexCompilationUnit& compilation_unit, |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 38 | CompilerDriver* compiler_driver, |
| 39 | VariableSizedHandleScope* handles) |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 40 | : HOptimization(graph, kSharpeningPassName), |
| 41 | codegen_(codegen), |
| 42 | compilation_unit_(compilation_unit), |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 43 | compiler_driver_(compiler_driver), |
| 44 | handles_(handles) { } |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 45 | |
| 46 | void Run() OVERRIDE; |
| 47 | |
| 48 | static constexpr const char* kSharpeningPassName = "sharpening"; |
| 49 | |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 50 | // Used by the builder and the inliner. |
Nicolas Geoffray | c4aa82c | 2017-03-06 14:38:52 +0000 | [diff] [blame] | 51 | static HLoadClass::LoadKind ComputeLoadClassKind(HLoadClass* load_class, |
| 52 | CodeGenerator* codegen, |
| 53 | CompilerDriver* compiler_driver, |
| 54 | const DexCompilationUnit& dex_compilation_unit) |
Nicolas Geoffray | 5687634 | 2016-12-16 16:09:08 +0000 | [diff] [blame] | 55 | REQUIRES_SHARED(Locks::mutator_lock_); |
| 56 | |
Nicolas Geoffray | c4aa82c | 2017-03-06 14:38:52 +0000 | [diff] [blame] | 57 | // Used by Sharpening and InstructionSimplifier. |
| 58 | static void SharpenInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke, CodeGenerator* codegen); |
| 59 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 60 | private: |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 61 | void ProcessLoadString(HLoadString* load_string); |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 62 | |
| 63 | CodeGenerator* codegen_; |
| 64 | const DexCompilationUnit& compilation_unit_; |
| 65 | CompilerDriver* compiler_driver_; |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 66 | VariableSizedHandleScope* handles_; |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 67 | }; |
| 68 | |
| 69 | } // namespace art |
| 70 | |
| 71 | #endif // ART_COMPILER_OPTIMIZING_SHARPENING_H_ |