blob: 5a860f1e43d4976ccafa366a53da74fe061d74a6 [file] [log] [blame]
Nicolas Geoffray818f2102014-02-18 16:43:35 +00001/*
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
Mathieu Chartierb666f482015-02-18 14:33:14 -080020#include "base/arena_object.h"
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +010021#include "dex_file-inl.h"
Andreas Gampe8cf9cb32017-07-19 09:28:38 -070022#include "dex_file.h"
Nicolas Geoffraye5038322014-07-04 09:41:32 +010023#include "driver/compiler_driver.h"
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +000024#include "driver/dex_compilation_unit.h"
Andreas Gampe8cf9cb32017-07-19 09:28:38 -070025#include "nodes.h"
Nicolas Geoffray818f2102014-02-18 16:43:35 +000026
27namespace art {
28
Nicolas Geoffray83c8e272017-01-31 14:36:37 +000029class CodeGenerator;
Vladimir Marko69d310e2017-10-09 14:12:23 +010030class OptimizingCompilerStats;
Nicolas Geoffray83c8e272017-01-31 14:36:37 +000031
Nicolas Geoffray818f2102014-02-18 16:43:35 +000032class HGraphBuilder : public ValueObject {
33 public:
David Brazdil5e8b1372015-01-23 14:39:08 +000034 HGraphBuilder(HGraph* graph,
Vladimir Markoca6fff82017-10-03 14:49:14 +010035 const DexCompilationUnit* dex_compilation_unit,
36 const DexCompilationUnit* outer_compilation_unit,
Calin Juravle48c2b032014-12-09 18:11:36 +000037 CompilerDriver* driver,
Nicolas Geoffray83c8e272017-01-31 14:36:37 +000038 CodeGenerator* code_generator,
Nicolas Geoffray9523a3e2015-07-17 11:51:28 +000039 OptimizingCompilerStats* compiler_stats,
Mathieu Chartier736b5602015-09-02 14:54:11 -070040 const uint8_t* interpreter_metadata,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +010041 VariableSizedHandleScope* handles);
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +010042
43 // Only for unit testing.
David Brazdil86ea7ee2016-02-16 09:26:07 +000044 HGraphBuilder(HGraph* graph,
Vladimir Marko69d310e2017-10-09 14:12:23 +010045 const DexCompilationUnit* dex_compilation_unit,
David Brazdil86ea7ee2016-02-16 09:26:07 +000046 const DexFile::CodeItem& code_item,
Mathieu Chartiere8a3c572016-10-11 16:52:17 -070047 VariableSizedHandleScope* handles,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +010048 DataType::Type return_type = DataType::Type::kInt32)
David Brazdildee58d62016-04-07 09:54:26 +000049 : graph_(graph),
Vladimir Marko69d310e2017-10-09 14:12:23 +010050 dex_file_(dex_compilation_unit->GetDexFile()),
David Brazdil86ea7ee2016-02-16 09:26:07 +000051 code_item_(code_item),
Vladimir Marko69d310e2017-10-09 14:12:23 +010052 dex_compilation_unit_(dex_compilation_unit),
53 outer_compilation_unit_(nullptr),
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +010054 compiler_driver_(nullptr),
Vladimir Marko69d310e2017-10-09 14:12:23 +010055 code_generator_(nullptr),
David Brazdildee58d62016-04-07 09:54:26 +000056 compilation_stats_(nullptr),
Vladimir Marko69d310e2017-10-09 14:12:23 +010057 interpreter_metadata_(nullptr),
58 handles_(handles),
59 return_type_(return_type) {}
Nicolas Geoffray818f2102014-02-18 16:43:35 +000060
David Brazdildee58d62016-04-07 09:54:26 +000061 GraphAnalysisResult BuildGraph();
Nicolas Geoffray818f2102014-02-18 16:43:35 +000062
Andreas Gampe7c3952f2015-02-19 18:21:24 -080063 static constexpr const char* kBuilderPassName = "builder";
64
Nicolas Geoffray818f2102014-02-18 16:43:35 +000065 private:
David Brazdil86ea7ee2016-02-16 09:26:07 +000066 bool SkipCompilation(size_t number_of_branches);
Calin Juravle48c2b032014-12-09 18:11:36 +000067
David Brazdil5e8b1372015-01-23 14:39:08 +000068 HGraph* const graph_;
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +000069 const DexFile* const dex_file_;
David Brazdil86ea7ee2016-02-16 09:26:07 +000070 const DexFile::CodeItem& code_item_;
Nicolas Geoffraye53798a2014-12-01 10:31:54 +000071
72 // The compilation unit of the current method being compiled. Note that
73 // it can be an inlined method.
Vladimir Markoca6fff82017-10-03 14:49:14 +010074 const DexCompilationUnit* const dex_compilation_unit_;
Nicolas Geoffraye53798a2014-12-01 10:31:54 +000075
Vladimir Marko69d310e2017-10-09 14:12:23 +010076 // The compilation unit of the enclosing method being compiled.
77 const DexCompilationUnit* const outer_compilation_unit_;
78
Nicolas Geoffraye5038322014-07-04 09:41:32 +010079 CompilerDriver* const compiler_driver_;
Vladimir Marko69d310e2017-10-09 14:12:23 +010080 CodeGenerator* const code_generator_;
Nicolas Geoffraye53798a2014-12-01 10:31:54 +000081
Vladimir Marko69d310e2017-10-09 14:12:23 +010082 OptimizingCompilerStats* const compilation_stats_;
83 const uint8_t* const interpreter_metadata_;
84 VariableSizedHandleScope* const handles_;
85 const DataType::Type return_type_;
Mathieu Chartier736b5602015-09-02 14:54:11 -070086
Nicolas Geoffray818f2102014-02-18 16:43:35 +000087 DISALLOW_COPY_AND_ASSIGN(HGraphBuilder);
88};
89
90} // namespace art
91
92#endif // ART_COMPILER_OPTIMIZING_BUILDER_H_