Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1 | /* |
| 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 Marko | 2aaa4b5 | 2015-09-17 17:03:26 +0100 | [diff] [blame] | 20 | #include "base/arena_containers.h" |
Mathieu Chartier | b666f48 | 2015-02-18 14:33:14 -0800 | [diff] [blame] | 21 | #include "base/arena_object.h" |
David Brazdil | 86ea7ee | 2016-02-16 09:26:07 +0000 | [diff] [blame] | 22 | #include "block_builder.h" |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 23 | #include "dex_file.h" |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 24 | #include "dex_file-inl.h" |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 25 | #include "driver/compiler_driver.h" |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 26 | #include "driver/dex_compilation_unit.h" |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 27 | #include "instruction_builder.h" |
Calin Juravle | 48c2b03 | 2014-12-09 18:11:36 +0000 | [diff] [blame] | 28 | #include "optimizing_compiler_stats.h" |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 29 | #include "primitive.h" |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 30 | #include "nodes.h" |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 31 | #include "ssa_builder.h" |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 32 | |
| 33 | namespace art { |
| 34 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 35 | class HGraphBuilder : public ValueObject { |
| 36 | public: |
David Brazdil | 5e8b137 | 2015-01-23 14:39:08 +0000 | [diff] [blame] | 37 | HGraphBuilder(HGraph* graph, |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 38 | DexCompilationUnit* dex_compilation_unit, |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 39 | const DexCompilationUnit* const outer_compilation_unit, |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 40 | const DexFile* dex_file, |
David Brazdil | 86ea7ee | 2016-02-16 09:26:07 +0000 | [diff] [blame] | 41 | const DexFile::CodeItem& code_item, |
Calin Juravle | 48c2b03 | 2014-12-09 18:11:36 +0000 | [diff] [blame] | 42 | CompilerDriver* driver, |
Nicolas Geoffray | 9523a3e | 2015-07-17 11:51:28 +0000 | [diff] [blame] | 43 | OptimizingCompilerStats* compiler_stats, |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 44 | const uint8_t* interpreter_metadata, |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 45 | Handle<mirror::DexCache> dex_cache, |
| 46 | StackHandleScopeCollection* handles) |
| 47 | : graph_(graph), |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 48 | dex_file_(dex_file), |
David Brazdil | 86ea7ee | 2016-02-16 09:26:07 +0000 | [diff] [blame] | 49 | code_item_(code_item), |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 50 | dex_compilation_unit_(dex_compilation_unit), |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 51 | compiler_driver_(driver), |
David Brazdil | 6032891 | 2016-04-04 17:47:42 +0000 | [diff] [blame] | 52 | compilation_stats_(compiler_stats), |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 53 | block_builder_(graph, dex_file, code_item), |
Vladimir Marko | 456307a | 2016-04-19 14:12:13 +0000 | [diff] [blame] | 54 | ssa_builder_(graph, dex_compilation_unit->GetDexCache(), handles), |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 55 | 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 Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 67 | |
| 68 | // Only for unit testing. |
David Brazdil | 86ea7ee | 2016-02-16 09:26:07 +0000 | [diff] [blame] | 69 | HGraphBuilder(HGraph* graph, |
| 70 | const DexFile::CodeItem& code_item, |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 71 | StackHandleScopeCollection* handles, |
David Brazdil | 86ea7ee | 2016-02-16 09:26:07 +0000 | [diff] [blame] | 72 | Primitive::Type return_type = Primitive::kPrimInt) |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 73 | : graph_(graph), |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 74 | dex_file_(nullptr), |
David Brazdil | 86ea7ee | 2016-02-16 09:26:07 +0000 | [diff] [blame] | 75 | code_item_(code_item), |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 76 | dex_compilation_unit_(nullptr), |
| 77 | compiler_driver_(nullptr), |
David Brazdil | 6032891 | 2016-04-04 17:47:42 +0000 | [diff] [blame] | 78 | null_dex_cache_(), |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 79 | compilation_stats_(nullptr), |
| 80 | block_builder_(graph, nullptr, code_item), |
Vladimir Marko | 456307a | 2016-04-19 14:12:13 +0000 | [diff] [blame] | 81 | ssa_builder_(graph, null_dex_cache_, handles), |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 82 | 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 Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 94 | |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 95 | GraphAnalysisResult BuildGraph(); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 96 | |
Andreas Gampe | 7c3952f | 2015-02-19 18:21:24 -0800 | [diff] [blame] | 97 | static constexpr const char* kBuilderPassName = "builder"; |
| 98 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 99 | private: |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 100 | void MaybeRecordStat(MethodCompilationStat compilation_stat); |
David Brazdil | 86ea7ee | 2016-02-16 09:26:07 +0000 | [diff] [blame] | 101 | bool SkipCompilation(size_t number_of_branches); |
Calin Juravle | 48c2b03 | 2014-12-09 18:11:36 +0000 | [diff] [blame] | 102 | |
David Brazdil | 5e8b137 | 2015-01-23 14:39:08 +0000 | [diff] [blame] | 103 | HGraph* const graph_; |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 104 | const DexFile* const dex_file_; |
David Brazdil | 86ea7ee | 2016-02-16 09:26:07 +0000 | [diff] [blame] | 105 | const DexFile::CodeItem& code_item_; |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 106 | |
| 107 | // The compilation unit of the current method being compiled. Note that |
| 108 | // it can be an inlined method. |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 109 | DexCompilationUnit* const dex_compilation_unit_; |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 110 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 111 | CompilerDriver* const compiler_driver_; |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 112 | |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 113 | ScopedNullHandle<mirror::DexCache> null_dex_cache_; |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 114 | |
Calin Juravle | 48c2b03 | 2014-12-09 18:11:36 +0000 | [diff] [blame] | 115 | OptimizingCompilerStats* compilation_stats_; |
| 116 | |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 117 | HBasicBlockBuilder block_builder_; |
| 118 | SsaBuilder ssa_builder_; |
| 119 | HInstructionBuilder instruction_builder_; |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 120 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 121 | DISALLOW_COPY_AND_ASSIGN(HGraphBuilder); |
| 122 | }; |
| 123 | |
| 124 | } // namespace art |
| 125 | |
| 126 | #endif // ART_COMPILER_OPTIMIZING_BUILDER_H_ |