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 | |
Mathieu Chartier | b666f48 | 2015-02-18 14:33:14 -0800 | [diff] [blame] | 20 | #include "base/arena_object.h" |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 21 | #include "dex_file-inl.h" |
Andreas Gampe | 8cf9cb3 | 2017-07-19 09:28:38 -0700 | [diff] [blame] | 22 | #include "dex_file.h" |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 23 | #include "driver/compiler_driver.h" |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 24 | #include "driver/dex_compilation_unit.h" |
Andreas Gampe | 8cf9cb3 | 2017-07-19 09:28:38 -0700 | [diff] [blame] | 25 | #include "nodes.h" |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 26 | |
| 27 | namespace art { |
| 28 | |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 29 | class CodeGenerator; |
Vladimir Marko | 69d310e | 2017-10-09 14:12:23 +0100 | [diff] [blame^] | 30 | class OptimizingCompilerStats; |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 31 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 32 | class HGraphBuilder : public ValueObject { |
| 33 | public: |
David Brazdil | 5e8b137 | 2015-01-23 14:39:08 +0000 | [diff] [blame] | 34 | HGraphBuilder(HGraph* graph, |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 35 | const DexCompilationUnit* dex_compilation_unit, |
| 36 | const DexCompilationUnit* outer_compilation_unit, |
Calin Juravle | 48c2b03 | 2014-12-09 18:11:36 +0000 | [diff] [blame] | 37 | CompilerDriver* driver, |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 38 | CodeGenerator* code_generator, |
Nicolas Geoffray | 9523a3e | 2015-07-17 11:51:28 +0000 | [diff] [blame] | 39 | OptimizingCompilerStats* compiler_stats, |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 40 | const uint8_t* interpreter_metadata, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 41 | VariableSizedHandleScope* handles); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 42 | |
| 43 | // Only for unit testing. |
David Brazdil | 86ea7ee | 2016-02-16 09:26:07 +0000 | [diff] [blame] | 44 | HGraphBuilder(HGraph* graph, |
Vladimir Marko | 69d310e | 2017-10-09 14:12:23 +0100 | [diff] [blame^] | 45 | const DexCompilationUnit* dex_compilation_unit, |
David Brazdil | 86ea7ee | 2016-02-16 09:26:07 +0000 | [diff] [blame] | 46 | const DexFile::CodeItem& code_item, |
Mathieu Chartier | e8a3c57 | 2016-10-11 16:52:17 -0700 | [diff] [blame] | 47 | VariableSizedHandleScope* handles, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 48 | DataType::Type return_type = DataType::Type::kInt32) |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 49 | : graph_(graph), |
Vladimir Marko | 69d310e | 2017-10-09 14:12:23 +0100 | [diff] [blame^] | 50 | dex_file_(dex_compilation_unit->GetDexFile()), |
David Brazdil | 86ea7ee | 2016-02-16 09:26:07 +0000 | [diff] [blame] | 51 | code_item_(code_item), |
Vladimir Marko | 69d310e | 2017-10-09 14:12:23 +0100 | [diff] [blame^] | 52 | dex_compilation_unit_(dex_compilation_unit), |
| 53 | outer_compilation_unit_(nullptr), |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 54 | compiler_driver_(nullptr), |
Vladimir Marko | 69d310e | 2017-10-09 14:12:23 +0100 | [diff] [blame^] | 55 | code_generator_(nullptr), |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 56 | compilation_stats_(nullptr), |
Vladimir Marko | 69d310e | 2017-10-09 14:12:23 +0100 | [diff] [blame^] | 57 | interpreter_metadata_(nullptr), |
| 58 | handles_(handles), |
| 59 | return_type_(return_type) {} |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 60 | |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 61 | GraphAnalysisResult BuildGraph(); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 62 | |
Andreas Gampe | 7c3952f | 2015-02-19 18:21:24 -0800 | [diff] [blame] | 63 | static constexpr const char* kBuilderPassName = "builder"; |
| 64 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 65 | private: |
David Brazdil | 86ea7ee | 2016-02-16 09:26:07 +0000 | [diff] [blame] | 66 | bool SkipCompilation(size_t number_of_branches); |
Calin Juravle | 48c2b03 | 2014-12-09 18:11:36 +0000 | [diff] [blame] | 67 | |
David Brazdil | 5e8b137 | 2015-01-23 14:39:08 +0000 | [diff] [blame] | 68 | HGraph* const graph_; |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 69 | const DexFile* const dex_file_; |
David Brazdil | 86ea7ee | 2016-02-16 09:26:07 +0000 | [diff] [blame] | 70 | const DexFile::CodeItem& code_item_; |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 71 | |
| 72 | // The compilation unit of the current method being compiled. Note that |
| 73 | // it can be an inlined method. |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 74 | const DexCompilationUnit* const dex_compilation_unit_; |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 75 | |
Vladimir Marko | 69d310e | 2017-10-09 14:12:23 +0100 | [diff] [blame^] | 76 | // The compilation unit of the enclosing method being compiled. |
| 77 | const DexCompilationUnit* const outer_compilation_unit_; |
| 78 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 79 | CompilerDriver* const compiler_driver_; |
Vladimir Marko | 69d310e | 2017-10-09 14:12:23 +0100 | [diff] [blame^] | 80 | CodeGenerator* const code_generator_; |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 81 | |
Vladimir Marko | 69d310e | 2017-10-09 14:12:23 +0100 | [diff] [blame^] | 82 | OptimizingCompilerStats* const compilation_stats_; |
| 83 | const uint8_t* const interpreter_metadata_; |
| 84 | VariableSizedHandleScope* const handles_; |
| 85 | const DataType::Type return_type_; |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 86 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 87 | DISALLOW_COPY_AND_ASSIGN(HGraphBuilder); |
| 88 | }; |
| 89 | |
| 90 | } // namespace art |
| 91 | |
| 92 | #endif // ART_COMPILER_OPTIMIZING_BUILDER_H_ |