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 "base/macros.h"
23 #include "dex/code_item_accessors.h"
24 #include "dex/dex_file-inl.h"
25 #include "dex/dex_file.h"
26 #include "nodes.h"
27 
28 namespace art HIDDEN {
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                 CodeGenerator* code_generator,
42                 OptimizingCompilerStats* compiler_stats);
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();
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 DataType::Type return_type_;
73 
74   DISALLOW_COPY_AND_ASSIGN(HGraphBuilder);
75 };
76 
77 }  // namespace art
78 
79 #endif  // ART_COMPILER_OPTIMIZING_BUILDER_H_
80