blob: bb1954eeebe4222b86d3772d4654f7bb4ffc2ae6 [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,
37 const DexCompilationUnit& compilation_unit,
Nicolas Geoffray22384ae2016-12-12 22:33:36 +000038 CompilerDriver* compiler_driver,
Aart Bik2ca10eb2017-11-15 15:17:53 -080039 VariableSizedHandleScope* handles,
40 const char* name = kSharpeningPassName)
41 : HOptimization(graph, name),
Vladimir Markodc151b22015-10-15 18:02:30 +010042 codegen_(codegen),
43 compilation_unit_(compilation_unit),
Nicolas Geoffray22384ae2016-12-12 22:33:36 +000044 compiler_driver_(compiler_driver),
45 handles_(handles) { }
Vladimir Markodc151b22015-10-15 18:02:30 +010046
47 void Run() OVERRIDE;
48
49 static constexpr const char* kSharpeningPassName = "sharpening";
50
Nicolas Geoffray83c8e272017-01-31 14:36:37 +000051 // Used by the builder and the inliner.
Nicolas Geoffrayc4aa82c2017-03-06 14:38:52 +000052 static HLoadClass::LoadKind ComputeLoadClassKind(HLoadClass* load_class,
53 CodeGenerator* codegen,
54 CompilerDriver* compiler_driver,
55 const DexCompilationUnit& dex_compilation_unit)
Nicolas Geoffray56876342016-12-16 16:09:08 +000056 REQUIRES_SHARED(Locks::mutator_lock_);
57
Nicolas Geoffrayc4aa82c2017-03-06 14:38:52 +000058 // Used by Sharpening and InstructionSimplifier.
Vladimir Marko65979462017-05-19 17:25:12 +010059 static void SharpenInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke,
60 CodeGenerator* codegen,
61 CompilerDriver* compiler_driver);
Nicolas Geoffrayc4aa82c2017-03-06 14:38:52 +000062
Vladimir Markodc151b22015-10-15 18:02:30 +010063 private:
Vladimir Markocac5a7e2016-02-22 10:39:50 +000064 void ProcessLoadString(HLoadString* load_string);
Vladimir Markodc151b22015-10-15 18:02:30 +010065
66 CodeGenerator* codegen_;
67 const DexCompilationUnit& compilation_unit_;
68 CompilerDriver* compiler_driver_;
Nicolas Geoffray22384ae2016-12-12 22:33:36 +000069 VariableSizedHandleScope* handles_;
Vladimir Markodc151b22015-10-15 18:02:30 +010070};
71
72} // namespace art
73
74#endif // ART_COMPILER_OPTIMIZING_SHARPENING_H_