blob: f896f1199e9d2288407457d93dcfbd8c55baae7d [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 Geoffray3ff386a2014-03-04 14:46:47 +000023#include "dex_file.h"
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +010024#include "dex_file-inl.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"
Calin Juravle48c2b032014-12-09 18:11:36 +000028#include "optimizing_compiler_stats.h"
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +010029#include "primitive.h"
Dave Allison20dfc792014-06-16 20:44:29 -070030#include "nodes.h"
David Brazdildee58d62016-04-07 09:54:26 +000031#include "ssa_builder.h"
Nicolas Geoffray818f2102014-02-18 16:43:35 +000032
33namespace art {
34
Nicolas Geoffray818f2102014-02-18 16:43:35 +000035class HGraphBuilder : public ValueObject {
36 public:
David Brazdil5e8b1372015-01-23 14:39:08 +000037 HGraphBuilder(HGraph* graph,
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +010038 DexCompilationUnit* dex_compilation_unit,
Nicolas Geoffraye53798a2014-12-01 10:31:54 +000039 const DexCompilationUnit* const outer_compilation_unit,
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +010040 const DexFile* dex_file,
David Brazdil86ea7ee2016-02-16 09:26:07 +000041 const DexFile::CodeItem& code_item,
Calin Juravle48c2b032014-12-09 18:11:36 +000042 CompilerDriver* driver,
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,
Mathieu Chartiere8a3c572016-10-11 16:52:17 -070046 VariableSizedHandleScope* handles)
David Brazdildee58d62016-04-07 09:54:26 +000047 : graph_(graph),
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +000048 dex_file_(dex_file),
David Brazdil86ea7ee2016-02-16 09:26:07 +000049 code_item_(code_item),
Nicolas Geoffraye5038322014-07-04 09:41:32 +010050 dex_compilation_unit_(dex_compilation_unit),
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +010051 compiler_driver_(driver),
David Brazdil60328912016-04-04 17:47:42 +000052 compilation_stats_(compiler_stats),
David Brazdildee58d62016-04-07 09:54:26 +000053 block_builder_(graph, dex_file, code_item),
Vladimir Marko456307a2016-04-19 14:12:13 +000054 ssa_builder_(graph, dex_compilation_unit->GetDexCache(), handles),
David Brazdildee58d62016-04-07 09:54:26 +000055 instruction_builder_(graph,
56 &block_builder_,
57 &ssa_builder_,
58 dex_file,
59 code_item_,
60 Primitive::GetType(dex_compilation_unit_->GetShorty()[0]),
61 dex_compilation_unit,
62 outer_compilation_unit,
63 driver,
64 interpreter_metadata,
65 compiler_stats,
66 dex_cache) {}
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +010067
68 // Only for unit testing.
David Brazdil86ea7ee2016-02-16 09:26:07 +000069 HGraphBuilder(HGraph* graph,
70 const DexFile::CodeItem& code_item,
Mathieu Chartiere8a3c572016-10-11 16:52:17 -070071 VariableSizedHandleScope* handles,
David Brazdil86ea7ee2016-02-16 09:26:07 +000072 Primitive::Type return_type = Primitive::kPrimInt)
David Brazdildee58d62016-04-07 09:54:26 +000073 : graph_(graph),
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +010074 dex_file_(nullptr),
David Brazdil86ea7ee2016-02-16 09:26:07 +000075 code_item_(code_item),
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +010076 dex_compilation_unit_(nullptr),
77 compiler_driver_(nullptr),
David Brazdil60328912016-04-04 17:47:42 +000078 null_dex_cache_(),
David Brazdildee58d62016-04-07 09:54:26 +000079 compilation_stats_(nullptr),
80 block_builder_(graph, nullptr, code_item),
Vladimir Marko456307a2016-04-19 14:12:13 +000081 ssa_builder_(graph, null_dex_cache_, handles),
David Brazdildee58d62016-04-07 09:54:26 +000082 instruction_builder_(graph,
83 &block_builder_,
84 &ssa_builder_,
85 /* dex_file */ nullptr,
86 code_item_,
87 return_type,
88 /* dex_compilation_unit */ nullptr,
89 /* outer_compilation_unit */ nullptr,
90 /* compiler_driver */ nullptr,
91 /* interpreter_metadata */ nullptr,
92 /* compiler_stats */ nullptr,
93 null_dex_cache_) {}
Nicolas Geoffray818f2102014-02-18 16:43:35 +000094
David Brazdildee58d62016-04-07 09:54:26 +000095 GraphAnalysisResult BuildGraph();
Nicolas Geoffray818f2102014-02-18 16:43:35 +000096
Andreas Gampe7c3952f2015-02-19 18:21:24 -080097 static constexpr const char* kBuilderPassName = "builder";
98
Nicolas Geoffray818f2102014-02-18 16:43:35 +000099 private:
David Brazdildee58d62016-04-07 09:54:26 +0000100 void MaybeRecordStat(MethodCompilationStat compilation_stat);
David Brazdil86ea7ee2016-02-16 09:26:07 +0000101 bool SkipCompilation(size_t number_of_branches);
Calin Juravle48c2b032014-12-09 18:11:36 +0000102
David Brazdil5e8b1372015-01-23 14:39:08 +0000103 HGraph* const graph_;
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +0000104 const DexFile* const dex_file_;
David Brazdil86ea7ee2016-02-16 09:26:07 +0000105 const DexFile::CodeItem& code_item_;
Nicolas Geoffraye53798a2014-12-01 10:31:54 +0000106
107 // The compilation unit of the current method being compiled. Note that
108 // it can be an inlined method.
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100109 DexCompilationUnit* const dex_compilation_unit_;
Nicolas Geoffraye53798a2014-12-01 10:31:54 +0000110
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100111 CompilerDriver* const compiler_driver_;
Nicolas Geoffraye53798a2014-12-01 10:31:54 +0000112
David Brazdildee58d62016-04-07 09:54:26 +0000113 ScopedNullHandle<mirror::DexCache> null_dex_cache_;
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +0100114
Calin Juravle48c2b032014-12-09 18:11:36 +0000115 OptimizingCompilerStats* compilation_stats_;
116
David Brazdildee58d62016-04-07 09:54:26 +0000117 HBasicBlockBuilder block_builder_;
118 SsaBuilder ssa_builder_;
119 HInstructionBuilder instruction_builder_;
Mathieu Chartier736b5602015-09-02 14:54:11 -0700120
Nicolas Geoffray818f2102014-02-18 16:43:35 +0000121 DISALLOW_COPY_AND_ASSIGN(HGraphBuilder);
122};
123
124} // namespace art
125
126#endif // ART_COMPILER_OPTIMIZING_BUILDER_H_