blob: 9524fe25346a4265091222245d7176d93e3cb340 [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
Vladimir Marko2aaa4b52015-09-17 17:03:26 +010020#include "base/arena_containers.h"
Mathieu Chartierb666f482015-02-18 14:33:14 -080021#include "base/arena_object.h"
David Brazdil86ea7ee2016-02-16 09:26:07 +000022#include "block_builder.h"
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +010023#include "dex_file-inl.h"
Andreas Gampe8cf9cb32017-07-19 09:28:38 -070024#include "dex_file.h"
Nicolas Geoffraye5038322014-07-04 09:41:32 +010025#include "driver/compiler_driver.h"
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +000026#include "driver/dex_compilation_unit.h"
David Brazdildee58d62016-04-07 09:54:26 +000027#include "instruction_builder.h"
Andreas Gampe8cf9cb32017-07-19 09:28:38 -070028#include "nodes.h"
Calin Juravle48c2b032014-12-09 18:11:36 +000029#include "optimizing_compiler_stats.h"
David Brazdildee58d62016-04-07 09:54:26 +000030#include "ssa_builder.h"
Nicolas Geoffray818f2102014-02-18 16:43:35 +000031
32namespace art {
33
Nicolas Geoffray83c8e272017-01-31 14:36:37 +000034class CodeGenerator;
35
Nicolas Geoffray818f2102014-02-18 16:43:35 +000036class HGraphBuilder : public ValueObject {
37 public:
David Brazdil5e8b1372015-01-23 14:39:08 +000038 HGraphBuilder(HGraph* graph,
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +010039 DexCompilationUnit* dex_compilation_unit,
Nicolas Geoffraye53798a2014-12-01 10:31:54 +000040 const DexCompilationUnit* const outer_compilation_unit,
Calin Juravle48c2b032014-12-09 18:11:36 +000041 CompilerDriver* driver,
Nicolas Geoffray83c8e272017-01-31 14:36:37 +000042 CodeGenerator* code_generator,
Nicolas Geoffray9523a3e2015-07-17 11:51:28 +000043 OptimizingCompilerStats* compiler_stats,
Mathieu Chartier736b5602015-09-02 14:54:11 -070044 const uint8_t* interpreter_metadata,
David Brazdildee58d62016-04-07 09:54:26 +000045 Handle<mirror::DexCache> dex_cache,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +010046 VariableSizedHandleScope* handles);
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +010047
48 // Only for unit testing.
David Brazdil86ea7ee2016-02-16 09:26:07 +000049 HGraphBuilder(HGraph* graph,
50 const DexFile::CodeItem& code_item,
Mathieu Chartiere8a3c572016-10-11 16:52:17 -070051 VariableSizedHandleScope* handles,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +010052 DataType::Type return_type = DataType::Type::kInt32)
David Brazdildee58d62016-04-07 09:54:26 +000053 : graph_(graph),
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +010054 dex_file_(nullptr),
David Brazdil86ea7ee2016-02-16 09:26:07 +000055 code_item_(code_item),
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +010056 dex_compilation_unit_(nullptr),
57 compiler_driver_(nullptr),
David Brazdildee58d62016-04-07 09:54:26 +000058 compilation_stats_(nullptr),
59 block_builder_(graph, nullptr, code_item),
Vladimir Marko8d6768d2017-03-14 10:13:21 +000060 ssa_builder_(graph,
61 handles->NewHandle<mirror::ClassLoader>(nullptr),
62 handles->NewHandle<mirror::DexCache>(nullptr),
63 handles),
David Brazdildee58d62016-04-07 09:54:26 +000064 instruction_builder_(graph,
65 &block_builder_,
66 &ssa_builder_,
67 /* dex_file */ nullptr,
68 code_item_,
69 return_type,
70 /* dex_compilation_unit */ nullptr,
71 /* outer_compilation_unit */ nullptr,
72 /* compiler_driver */ nullptr,
Nicolas Geoffray83c8e272017-01-31 14:36:37 +000073 /* code_generator */ nullptr,
David Brazdildee58d62016-04-07 09:54:26 +000074 /* interpreter_metadata */ nullptr,
75 /* compiler_stats */ nullptr,
Vladimir Marko8d6768d2017-03-14 10:13:21 +000076 handles->NewHandle<mirror::DexCache>(nullptr),
Nicolas Geoffray5247c082017-01-13 14:17:29 +000077 handles) {}
Nicolas Geoffray818f2102014-02-18 16:43:35 +000078
David Brazdildee58d62016-04-07 09:54:26 +000079 GraphAnalysisResult BuildGraph();
Nicolas Geoffray818f2102014-02-18 16:43:35 +000080
Andreas Gampe7c3952f2015-02-19 18:21:24 -080081 static constexpr const char* kBuilderPassName = "builder";
82
Nicolas Geoffray818f2102014-02-18 16:43:35 +000083 private:
David Brazdil86ea7ee2016-02-16 09:26:07 +000084 bool SkipCompilation(size_t number_of_branches);
Calin Juravle48c2b032014-12-09 18:11:36 +000085
David Brazdil5e8b1372015-01-23 14:39:08 +000086 HGraph* const graph_;
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +000087 const DexFile* const dex_file_;
David Brazdil86ea7ee2016-02-16 09:26:07 +000088 const DexFile::CodeItem& code_item_;
Nicolas Geoffraye53798a2014-12-01 10:31:54 +000089
90 // The compilation unit of the current method being compiled. Note that
91 // it can be an inlined method.
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +010092 DexCompilationUnit* const dex_compilation_unit_;
Nicolas Geoffraye53798a2014-12-01 10:31:54 +000093
Nicolas Geoffraye5038322014-07-04 09:41:32 +010094 CompilerDriver* const compiler_driver_;
Nicolas Geoffraye53798a2014-12-01 10:31:54 +000095
Calin Juravle48c2b032014-12-09 18:11:36 +000096 OptimizingCompilerStats* compilation_stats_;
97
David Brazdildee58d62016-04-07 09:54:26 +000098 HBasicBlockBuilder block_builder_;
99 SsaBuilder ssa_builder_;
100 HInstructionBuilder instruction_builder_;
Mathieu Chartier736b5602015-09-02 14:54:11 -0700101
Nicolas Geoffray818f2102014-02-18 16:43:35 +0000102 DISALLOW_COPY_AND_ASSIGN(HGraphBuilder);
103};
104
105} // namespace art
106
107#endif // ART_COMPILER_OPTIMIZING_BUILDER_H_