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