1 /*
2  * Copyright (C) 2014 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_BUILDER_H_
18 #define ART_COMPILER_OPTIMIZING_BUILDER_H_
19 
20 #include "base/arena_object.h"
21 #include "base/array_ref.h"
22 #include "dex/code_item_accessors.h"
23 #include "dex/dex_file-inl.h"
24 #include "dex/dex_file.h"
25 #include "driver/compiler_driver.h"
26 #include "nodes.h"
27 
28 namespace art {
29 
30 class ArtMethod;
31 class CodeGenerator;
32 class DexCompilationUnit;
33 class OptimizingCompilerStats;
34 
35 class HGraphBuilder : public ValueObject {
36  public:
37   HGraphBuilder(HGraph* graph,
38                 const CodeItemDebugInfoAccessor& accessor,
39                 const DexCompilationUnit* dex_compilation_unit,
40                 const DexCompilationUnit* outer_compilation_unit,
41                 CompilerDriver* driver,
42                 CodeGenerator* code_generator,
43                 OptimizingCompilerStats* compiler_stats,
44                 ArrayRef<const uint8_t> interpreter_metadata,
45                 VariableSizedHandleScope* handles);
46 
47   // Only for unit testing.
48   HGraphBuilder(HGraph* graph,
49                 const DexCompilationUnit* dex_compilation_unit,
50                 const CodeItemDebugInfoAccessor& accessor,
51                 VariableSizedHandleScope* handles,
52                 DataType::Type return_type = DataType::Type::kInt32);
53 
54   GraphAnalysisResult BuildGraph();
55   void BuildIntrinsicGraph(ArtMethod* method);
56 
57   static constexpr const char* kBuilderPassName = "builder";
58 
59  private:
60   bool SkipCompilation(size_t number_of_branches);
61 
62   HGraph* const graph_;
63   const DexFile* const dex_file_;
64   const CodeItemDebugInfoAccessor code_item_accessor_;  // null for intrinsic graph.
65 
66   // The compilation unit of the current method being compiled. Note that
67   // it can be an inlined method.
68   const DexCompilationUnit* const dex_compilation_unit_;
69 
70   // The compilation unit of the enclosing method being compiled.
71   const DexCompilationUnit* const outer_compilation_unit_;
72 
73   CompilerDriver* const compiler_driver_;
74   CodeGenerator* const code_generator_;
75 
76   OptimizingCompilerStats* const compilation_stats_;
77   const ArrayRef<const uint8_t> interpreter_metadata_;
78   VariableSizedHandleScope* const handles_;
79   const DataType::Type return_type_;
80 
81   DISALLOW_COPY_AND_ASSIGN(HGraphBuilder);
82 };
83 
84 }  // namespace art
85 
86 #endif  // ART_COMPILER_OPTIMIZING_BUILDER_H_
87