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 
44   // Only for unit testing.
45   HGraphBuilder(HGraph* graph,
46                 const DexCompilationUnit* dex_compilation_unit,
47                 const CodeItemDebugInfoAccessor& accessor,
48                 DataType::Type return_type = DataType::Type::kInt32);
49 
50   GraphAnalysisResult BuildGraph();
51   void BuildIntrinsicGraph(ArtMethod* method);
52 
53   static constexpr const char* kBuilderPassName = "builder";
54 
55  private:
56   bool SkipCompilation(size_t number_of_branches);
57 
58   HGraph* const graph_;
59   const DexFile* const dex_file_;
60   const CodeItemDebugInfoAccessor code_item_accessor_;  // null for intrinsic graph.
61 
62   // The compilation unit of the current method being compiled. Note that
63   // it can be an inlined method.
64   const DexCompilationUnit* const dex_compilation_unit_;
65 
66   // The compilation unit of the enclosing method being compiled.
67   const DexCompilationUnit* const outer_compilation_unit_;
68 
69   CodeGenerator* const code_generator_;
70 
71   OptimizingCompilerStats* const compilation_stats_;
72   const ArrayRef<const uint8_t> interpreter_metadata_;
73   const DataType::Type return_type_;
74 
75   DISALLOW_COPY_AND_ASSIGN(HGraphBuilder);
76 };
77 
78 }  // namespace art
79 
80 #endif  // ART_COMPILER_OPTIMIZING_BUILDER_H_
81