blob: 9ccbcaf22010c73bae3f74c1add881d6dc918409 [file] [log] [blame]
Vladimir Markodc151b22015-10-15 18:02:30 +01001/*
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 Geoffray83c8e272017-01-31 14:36:37 +000020#include "nodes.h"
Vladimir Markodc151b22015-10-15 18:02:30 +010021#include "optimization.h"
22
23namespace art {
24
25class CodeGenerator;
26class CompilerDriver;
27class DexCompilationUnit;
Vladimir Markodc151b22015-10-15 18:02:30 +010028
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.
33class HSharpening : public HOptimization {
34 public:
35 HSharpening(HGraph* graph,
36 CodeGenerator* codegen,
Nicolas Geoffray22384ae2016-12-12 22:33:36 +000037 CompilerDriver* compiler_driver,
Aart Bik2ca10eb2017-11-15 15:17:53 -080038 const char* name = kSharpeningPassName)
39 : HOptimization(graph, name),
Vladimir Markodc151b22015-10-15 18:02:30 +010040 codegen_(codegen),
Vladimir Marko28e012a2017-12-07 11:22:59 +000041 compiler_driver_(compiler_driver) { }
Vladimir Markodc151b22015-10-15 18:02:30 +010042
Aart Bik24773202018-04-26 10:28:51 -070043 bool Run() OVERRIDE;
Vladimir Markodc151b22015-10-15 18:02:30 +010044
45 static constexpr const char* kSharpeningPassName = "sharpening";
46
Vladimir Marko175e7862018-03-27 09:03:13 +000047 // Used by Sharpening and InstructionSimplifier.
48 static void SharpenInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke,
49 CodeGenerator* codegen,
50 CompilerDriver* compiler_driver);
Vladimir Marko28e012a2017-12-07 11:22:59 +000051
Nicolas Geoffray83c8e272017-01-31 14:36:37 +000052 // Used by the builder and the inliner.
Nicolas Geoffrayc4aa82c2017-03-06 14:38:52 +000053 static HLoadClass::LoadKind ComputeLoadClassKind(HLoadClass* load_class,
54 CodeGenerator* codegen,
55 CompilerDriver* compiler_driver,
56 const DexCompilationUnit& dex_compilation_unit)
Vladimir Marko28e012a2017-12-07 11:22:59 +000057 REQUIRES_SHARED(Locks::mutator_lock_);
Nicolas Geoffray56876342016-12-16 16:09:08 +000058
Vladimir Marko175e7862018-03-27 09:03:13 +000059 // Used by the builder.
60 static TypeCheckKind ComputeTypeCheckKind(ObjPtr<mirror::Class> klass,
61 CodeGenerator* codegen,
62 CompilerDriver* compiler_driver,
63 bool needs_access_check)
64 REQUIRES_SHARED(Locks::mutator_lock_);
65
66 // Used by the builder.
67 static void ProcessLoadString(HLoadString* load_string,
68 CodeGenerator* codegen,
69 CompilerDriver* compiler_driver,
70 const DexCompilationUnit& dex_compilation_unit,
71 VariableSizedHandleScope* handles);
Nicolas Geoffrayc4aa82c2017-03-06 14:38:52 +000072
Vladimir Markodc151b22015-10-15 18:02:30 +010073 private:
Vladimir Markodc151b22015-10-15 18:02:30 +010074 CodeGenerator* codegen_;
Vladimir Markodc151b22015-10-15 18:02:30 +010075 CompilerDriver* compiler_driver_;
Vladimir Markodc151b22015-10-15 18:02:30 +010076};
77
78} // namespace art
79
80#endif // ART_COMPILER_OPTIMIZING_SHARPENING_H_