blob: cbac361891698b5b9ee00d033d4b2ed7c4be8518 [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;
Vladimir Markodc151b22015-10-15 18:02:30 +010026class DexCompilationUnit;
Vladimir Markodc151b22015-10-15 18:02:30 +010027
28// Optimization that tries to improve the way we dispatch methods and access types,
29// fields, etc. Besides actual method sharpening based on receiver type (for example
30// virtual->direct), this includes selecting the best available dispatch for
31// invoke-static/-direct based on code generator support.
32class HSharpening : public HOptimization {
33 public:
34 HSharpening(HGraph* graph,
35 CodeGenerator* codegen,
Aart Bik2ca10eb2017-11-15 15:17:53 -080036 const char* name = kSharpeningPassName)
37 : HOptimization(graph, name),
Vladimir Markobb089b62018-06-28 17:30:16 +010038 codegen_(codegen) { }
Vladimir Markodc151b22015-10-15 18:02:30 +010039
Aart Bik24773202018-04-26 10:28:51 -070040 bool Run() OVERRIDE;
Vladimir Markodc151b22015-10-15 18:02:30 +010041
42 static constexpr const char* kSharpeningPassName = "sharpening";
43
Vladimir Marko175e7862018-03-27 09:03:13 +000044 // Used by Sharpening and InstructionSimplifier.
Vladimir Markobb089b62018-06-28 17:30:16 +010045 static void SharpenInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke, CodeGenerator* codegen);
Vladimir Marko28e012a2017-12-07 11:22:59 +000046
Nicolas Geoffray83c8e272017-01-31 14:36:37 +000047 // Used by the builder and the inliner.
Nicolas Geoffrayc4aa82c2017-03-06 14:38:52 +000048 static HLoadClass::LoadKind ComputeLoadClassKind(HLoadClass* load_class,
49 CodeGenerator* codegen,
Nicolas Geoffrayc4aa82c2017-03-06 14:38:52 +000050 const DexCompilationUnit& dex_compilation_unit)
Vladimir Marko28e012a2017-12-07 11:22:59 +000051 REQUIRES_SHARED(Locks::mutator_lock_);
Nicolas Geoffray56876342016-12-16 16:09:08 +000052
Vladimir Marko175e7862018-03-27 09:03:13 +000053 // Used by the builder.
54 static TypeCheckKind ComputeTypeCheckKind(ObjPtr<mirror::Class> klass,
55 CodeGenerator* codegen,
Vladimir Marko175e7862018-03-27 09:03:13 +000056 bool needs_access_check)
57 REQUIRES_SHARED(Locks::mutator_lock_);
58
59 // Used by the builder.
60 static void ProcessLoadString(HLoadString* load_string,
61 CodeGenerator* codegen,
Vladimir Marko175e7862018-03-27 09:03:13 +000062 const DexCompilationUnit& dex_compilation_unit,
63 VariableSizedHandleScope* handles);
Nicolas Geoffrayc4aa82c2017-03-06 14:38:52 +000064
Vladimir Markodc151b22015-10-15 18:02:30 +010065 private:
Vladimir Markodc151b22015-10-15 18:02:30 +010066 CodeGenerator* codegen_;
Vladimir Markodc151b22015-10-15 18:02:30 +010067};
68
69} // namespace art
70
71#endif // ART_COMPILER_OPTIMIZING_SHARPENING_H_