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 
20 #include "nodes.h"
21 #include "optimization.h"
22 
23 namespace art {
24 
25 class CodeGenerator;
26 class CompilerDriver;
27 class DexCompilationUnit;
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               CompilerDriver* compiler_driver,
38               const char* name = kSharpeningPassName)
HOptimization(graph,name)39       : HOptimization(graph, name),
40         codegen_(codegen),
41         compiler_driver_(compiler_driver) { }
42 
43   void Run() OVERRIDE;
44 
45   static constexpr const char* kSharpeningPassName = "sharpening";
46 
47   // Used by the builder.
48   static void ProcessLoadString(HLoadString* load_string,
49                                 CodeGenerator* codegen,
50                                 CompilerDriver* compiler_driver,
51                                 const DexCompilationUnit& dex_compilation_unit,
52                                 VariableSizedHandleScope* handles);
53 
54   // Used by the builder and the inliner.
55   static HLoadClass::LoadKind ComputeLoadClassKind(HLoadClass* load_class,
56                                                    CodeGenerator* codegen,
57                                                    CompilerDriver* compiler_driver,
58                                                    const DexCompilationUnit& dex_compilation_unit)
59       REQUIRES_SHARED(Locks::mutator_lock_);
60 
61   // Used by Sharpening and InstructionSimplifier.
62   static void SharpenInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke,
63                                           CodeGenerator* codegen,
64                                           CompilerDriver* compiler_driver);
65 
66  private:
67   CodeGenerator* codegen_;
68   CompilerDriver* compiler_driver_;
69 };
70 
71 }  // namespace art
72 
73 #endif  // ART_COMPILER_OPTIMIZING_SHARPENING_H_
74