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