blob: dce3d9dc8ec0af2551c1c3cb897c85684fa3a5a0 [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"
Mathieu Chartier210531f2018-01-12 10:15:51 -080021#include "base/array_ref.h"
Vladimir Markoe2727152019-10-10 10:46:42 +010022#include "base/macros.h"
David Sehr9e734c72018-01-04 17:56:19 -080023#include "dex/code_item_accessors.h"
24#include "dex/dex_file-inl.h"
25#include "dex/dex_file.h"
Andreas Gampe8cf9cb32017-07-19 09:28:38 -070026#include "nodes.h"
Nicolas Geoffray818f2102014-02-18 16:43:35 +000027
Vladimir Markoe2727152019-10-10 10:46:42 +010028namespace art HIDDEN {
Nicolas Geoffray818f2102014-02-18 16:43:35 +000029
Vladimir Marko92f7f3c2017-10-31 11:38:30 +000030class ArtMethod;
Nicolas Geoffray83c8e272017-01-31 14:36:37 +000031class CodeGenerator;
Vladimir Marko92f7f3c2017-10-31 11:38:30 +000032class DexCompilationUnit;
Vladimir Marko69d310e2017-10-09 14:12:23 +010033class OptimizingCompilerStats;
Nicolas Geoffray83c8e272017-01-31 14:36:37 +000034
Nicolas Geoffray818f2102014-02-18 16:43:35 +000035class HGraphBuilder : public ValueObject {
36 public:
David Brazdil5e8b1372015-01-23 14:39:08 +000037 HGraphBuilder(HGraph* graph,
Mathieu Chartier808c7a52017-12-15 11:19:33 -080038 const CodeItemDebugInfoAccessor& accessor,
Vladimir Markoca6fff82017-10-03 14:49:14 +010039 const DexCompilationUnit* dex_compilation_unit,
40 const DexCompilationUnit* outer_compilation_unit,
Nicolas Geoffray83c8e272017-01-31 14:36:37 +000041 CodeGenerator* code_generator,
Nicolas Geoffray9523a3e2015-07-17 11:51:28 +000042 OptimizingCompilerStats* compiler_stats,
Mathieu Chartier210531f2018-01-12 10:15:51 -080043 ArrayRef<const uint8_t> interpreter_metadata,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +010044 VariableSizedHandleScope* handles);
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +010045
46 // Only for unit testing.
David Brazdil86ea7ee2016-02-16 09:26:07 +000047 HGraphBuilder(HGraph* graph,
Vladimir Marko69d310e2017-10-09 14:12:23 +010048 const DexCompilationUnit* dex_compilation_unit,
Mathieu Chartier808c7a52017-12-15 11:19:33 -080049 const CodeItemDebugInfoAccessor& accessor,
Mathieu Chartiere8a3c572016-10-11 16:52:17 -070050 VariableSizedHandleScope* handles,
Mathieu Chartier808c7a52017-12-15 11:19:33 -080051 DataType::Type return_type = DataType::Type::kInt32);
Nicolas Geoffray818f2102014-02-18 16:43:35 +000052
David Brazdildee58d62016-04-07 09:54:26 +000053 GraphAnalysisResult BuildGraph();
Vladimir Marko92f7f3c2017-10-31 11:38:30 +000054 void BuildIntrinsicGraph(ArtMethod* method);
Nicolas Geoffray818f2102014-02-18 16:43:35 +000055
Andreas Gampe7c3952f2015-02-19 18:21:24 -080056 static constexpr const char* kBuilderPassName = "builder";
57
Nicolas Geoffray818f2102014-02-18 16:43:35 +000058 private:
David Brazdil86ea7ee2016-02-16 09:26:07 +000059 bool SkipCompilation(size_t number_of_branches);
Calin Juravle48c2b032014-12-09 18:11:36 +000060
David Brazdil5e8b1372015-01-23 14:39:08 +000061 HGraph* const graph_;
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +000062 const DexFile* const dex_file_;
Mathieu Chartier808c7a52017-12-15 11:19:33 -080063 const CodeItemDebugInfoAccessor code_item_accessor_; // null for intrinsic graph.
Nicolas Geoffraye53798a2014-12-01 10:31:54 +000064
65 // The compilation unit of the current method being compiled. Note that
66 // it can be an inlined method.
Vladimir Markoca6fff82017-10-03 14:49:14 +010067 const DexCompilationUnit* const dex_compilation_unit_;
Nicolas Geoffraye53798a2014-12-01 10:31:54 +000068
Vladimir Marko69d310e2017-10-09 14:12:23 +010069 // The compilation unit of the enclosing method being compiled.
70 const DexCompilationUnit* const outer_compilation_unit_;
71
Vladimir Marko69d310e2017-10-09 14:12:23 +010072 CodeGenerator* const code_generator_;
Nicolas Geoffraye53798a2014-12-01 10:31:54 +000073
Vladimir Marko69d310e2017-10-09 14:12:23 +010074 OptimizingCompilerStats* const compilation_stats_;
Mathieu Chartier210531f2018-01-12 10:15:51 -080075 const ArrayRef<const uint8_t> interpreter_metadata_;
Vladimir Marko69d310e2017-10-09 14:12:23 +010076 VariableSizedHandleScope* const handles_;
77 const DataType::Type return_type_;
Mathieu Chartier736b5602015-09-02 14:54:11 -070078
Nicolas Geoffray818f2102014-02-18 16:43:35 +000079 DISALLOW_COPY_AND_ASSIGN(HGraphBuilder);
80};
81
82} // namespace art
83
84#endif // ART_COMPILER_OPTIMIZING_BUILDER_H_