blob: 3a4c9dbd1669834096abc92e49877a31e1bb45de [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 Geoffray83c8e272017-01-31 14:36:37 +000035class CodeGenerator;
36
Nicolas Geoffray818f2102014-02-18 16:43:35 +000037class HGraphBuilder : public ValueObject {
38 public:
David Brazdil5e8b1372015-01-23 14:39:08 +000039 HGraphBuilder(HGraph* graph,
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +010040 DexCompilationUnit* dex_compilation_unit,
Nicolas Geoffraye53798a2014-12-01 10:31:54 +000041 const DexCompilationUnit* const outer_compilation_unit,
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +010042 const DexFile* dex_file,
David Brazdil86ea7ee2016-02-16 09:26:07 +000043 const DexFile::CodeItem& code_item,
Calin Juravle48c2b032014-12-09 18:11:36 +000044 CompilerDriver* driver,
Nicolas Geoffray83c8e272017-01-31 14:36:37 +000045 CodeGenerator* code_generator,
Nicolas Geoffray9523a3e2015-07-17 11:51:28 +000046 OptimizingCompilerStats* compiler_stats,
Mathieu Chartier736b5602015-09-02 14:54:11 -070047 const uint8_t* interpreter_metadata,
David Brazdildee58d62016-04-07 09:54:26 +000048 Handle<mirror::DexCache> dex_cache,
Mathieu Chartiere8a3c572016-10-11 16:52:17 -070049 VariableSizedHandleScope* handles)
David Brazdildee58d62016-04-07 09:54:26 +000050 : graph_(graph),
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +000051 dex_file_(dex_file),
David Brazdil86ea7ee2016-02-16 09:26:07 +000052 code_item_(code_item),
Nicolas Geoffraye5038322014-07-04 09:41:32 +010053 dex_compilation_unit_(dex_compilation_unit),
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +010054 compiler_driver_(driver),
David Brazdil60328912016-04-04 17:47:42 +000055 compilation_stats_(compiler_stats),
David Brazdildee58d62016-04-07 09:54:26 +000056 block_builder_(graph, dex_file, code_item),
Vladimir Markobfb80d22017-02-14 14:08:12 +000057 ssa_builder_(graph,
58 dex_compilation_unit->GetClassLoader(),
59 dex_compilation_unit->GetDexCache(),
60 handles),
David Brazdildee58d62016-04-07 09:54:26 +000061 instruction_builder_(graph,
62 &block_builder_,
63 &ssa_builder_,
64 dex_file,
65 code_item_,
66 Primitive::GetType(dex_compilation_unit_->GetShorty()[0]),
67 dex_compilation_unit,
68 outer_compilation_unit,
69 driver,
Nicolas Geoffray83c8e272017-01-31 14:36:37 +000070 code_generator,
David Brazdildee58d62016-04-07 09:54:26 +000071 interpreter_metadata,
72 compiler_stats,
Nicolas Geoffray5247c082017-01-13 14:17:29 +000073 dex_cache,
74 handles) {}
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +010075
76 // Only for unit testing.
David Brazdil86ea7ee2016-02-16 09:26:07 +000077 HGraphBuilder(HGraph* graph,
78 const DexFile::CodeItem& code_item,
Mathieu Chartiere8a3c572016-10-11 16:52:17 -070079 VariableSizedHandleScope* handles,
David Brazdil86ea7ee2016-02-16 09:26:07 +000080 Primitive::Type return_type = Primitive::kPrimInt)
David Brazdildee58d62016-04-07 09:54:26 +000081 : graph_(graph),
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +010082 dex_file_(nullptr),
David Brazdil86ea7ee2016-02-16 09:26:07 +000083 code_item_(code_item),
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +010084 dex_compilation_unit_(nullptr),
85 compiler_driver_(nullptr),
David Brazdildee58d62016-04-07 09:54:26 +000086 compilation_stats_(nullptr),
87 block_builder_(graph, nullptr, code_item),
Vladimir Markobfb80d22017-02-14 14:08:12 +000088 ssa_builder_(graph,
89 handles->NewHandle<mirror::ClassLoader>(nullptr),
90 handles->NewHandle<mirror::DexCache>(nullptr),
91 handles),
David Brazdildee58d62016-04-07 09:54:26 +000092 instruction_builder_(graph,
93 &block_builder_,
94 &ssa_builder_,
95 /* dex_file */ nullptr,
96 code_item_,
97 return_type,
98 /* dex_compilation_unit */ nullptr,
99 /* outer_compilation_unit */ nullptr,
100 /* compiler_driver */ nullptr,
Nicolas Geoffray83c8e272017-01-31 14:36:37 +0000101 /* code_generator */ nullptr,
David Brazdildee58d62016-04-07 09:54:26 +0000102 /* interpreter_metadata */ nullptr,
103 /* compiler_stats */ nullptr,
Vladimir Markobfb80d22017-02-14 14:08:12 +0000104 handles->NewHandle<mirror::DexCache>(nullptr),
Nicolas Geoffray5247c082017-01-13 14:17:29 +0000105 handles) {}
Nicolas Geoffray818f2102014-02-18 16:43:35 +0000106
David Brazdildee58d62016-04-07 09:54:26 +0000107 GraphAnalysisResult BuildGraph();
Nicolas Geoffray818f2102014-02-18 16:43:35 +0000108
Andreas Gampe7c3952f2015-02-19 18:21:24 -0800109 static constexpr const char* kBuilderPassName = "builder";
110
Nicolas Geoffray818f2102014-02-18 16:43:35 +0000111 private:
David Brazdildee58d62016-04-07 09:54:26 +0000112 void MaybeRecordStat(MethodCompilationStat compilation_stat);
David Brazdil86ea7ee2016-02-16 09:26:07 +0000113 bool SkipCompilation(size_t number_of_branches);
Calin Juravle48c2b032014-12-09 18:11:36 +0000114
David Brazdil5e8b1372015-01-23 14:39:08 +0000115 HGraph* const graph_;
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +0000116 const DexFile* const dex_file_;
David Brazdil86ea7ee2016-02-16 09:26:07 +0000117 const DexFile::CodeItem& code_item_;
Nicolas Geoffraye53798a2014-12-01 10:31:54 +0000118
119 // The compilation unit of the current method being compiled. Note that
120 // it can be an inlined method.
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100121 DexCompilationUnit* const dex_compilation_unit_;
Nicolas Geoffraye53798a2014-12-01 10:31:54 +0000122
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100123 CompilerDriver* const compiler_driver_;
Nicolas Geoffraye53798a2014-12-01 10:31:54 +0000124
Calin Juravle48c2b032014-12-09 18:11:36 +0000125 OptimizingCompilerStats* compilation_stats_;
126
David Brazdildee58d62016-04-07 09:54:26 +0000127 HBasicBlockBuilder block_builder_;
128 SsaBuilder ssa_builder_;
129 HInstructionBuilder instruction_builder_;
Mathieu Chartier736b5602015-09-02 14:54:11 -0700130
Nicolas Geoffray818f2102014-02-18 16:43:35 +0000131 DISALLOW_COPY_AND_ASSIGN(HGraphBuilder);
132};
133
134} // namespace art
135
136#endif // ART_COMPILER_OPTIMIZING_BUILDER_H_