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" |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 22 | #include "dex_file.h" |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 23 | #include "dex_file-inl.h" |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 24 | #include "driver/compiler_driver.h" |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 25 | #include "driver/dex_compilation_unit.h" |
Calin Juravle | 48c2b03 | 2014-12-09 18:11:36 +0000 | [diff] [blame] | 26 | #include "optimizing_compiler_stats.h" |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 27 | #include "primitive.h" |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 28 | #include "nodes.h" |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 29 | |
| 30 | namespace art { |
| 31 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 32 | class Instruction; |
Andreas Gampe | e4d4d32 | 2014-12-04 09:09:57 -0800 | [diff] [blame] | 33 | class SwitchTable; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 34 | |
| 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, |
Calin Juravle | 48c2b03 | 2014-12-09 18:11:36 +0000 | [diff] [blame] | 41 | CompilerDriver* driver, |
Nicolas Geoffray | 9523a3e | 2015-07-17 11:51:28 +0000 | [diff] [blame] | 42 | OptimizingCompilerStats* compiler_stats, |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 43 | const uint8_t* interpreter_metadata, |
| 44 | Handle<mirror::DexCache> dex_cache) |
David Brazdil | 5e8b137 | 2015-01-23 14:39:08 +0000 | [diff] [blame] | 45 | : arena_(graph->GetArena()), |
Vladimir Marko | 2aaa4b5 | 2015-09-17 17:03:26 +0100 | [diff] [blame] | 46 | branch_targets_(graph->GetArena()->Adapter(kArenaAllocGraphBuilder)), |
| 47 | locals_(graph->GetArena()->Adapter(kArenaAllocGraphBuilder)), |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 48 | entry_block_(nullptr), |
| 49 | exit_block_(nullptr), |
| 50 | current_block_(nullptr), |
David Brazdil | 5e8b137 | 2015-01-23 14:39:08 +0000 | [diff] [blame] | 51 | graph_(graph), |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 52 | dex_file_(dex_file), |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 53 | dex_compilation_unit_(dex_compilation_unit), |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 54 | compiler_driver_(driver), |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 55 | outer_compilation_unit_(outer_compilation_unit), |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 56 | return_type_(Primitive::GetType(dex_compilation_unit_->GetShorty()[0])), |
| 57 | code_start_(nullptr), |
Calin Juravle | 48c2b03 | 2014-12-09 18:11:36 +0000 | [diff] [blame] | 58 | latest_result_(nullptr), |
Nicolas Geoffray | 2e7cd75 | 2015-07-10 11:38:52 +0100 | [diff] [blame] | 59 | can_use_baseline_for_string_init_(true), |
Nicolas Geoffray | 9523a3e | 2015-07-17 11:51:28 +0000 | [diff] [blame] | 60 | compilation_stats_(compiler_stats), |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 61 | interpreter_metadata_(interpreter_metadata), |
| 62 | dex_cache_(dex_cache) {} |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 63 | |
| 64 | // Only for unit testing. |
David Brazdil | 5e8b137 | 2015-01-23 14:39:08 +0000 | [diff] [blame] | 65 | HGraphBuilder(HGraph* graph, Primitive::Type return_type = Primitive::kPrimInt) |
| 66 | : arena_(graph->GetArena()), |
Vladimir Marko | 2aaa4b5 | 2015-09-17 17:03:26 +0100 | [diff] [blame] | 67 | branch_targets_(graph->GetArena()->Adapter(kArenaAllocGraphBuilder)), |
| 68 | locals_(graph->GetArena()->Adapter(kArenaAllocGraphBuilder)), |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 69 | entry_block_(nullptr), |
| 70 | exit_block_(nullptr), |
| 71 | current_block_(nullptr), |
David Brazdil | 5e8b137 | 2015-01-23 14:39:08 +0000 | [diff] [blame] | 72 | graph_(graph), |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 73 | dex_file_(nullptr), |
| 74 | dex_compilation_unit_(nullptr), |
| 75 | compiler_driver_(nullptr), |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 76 | outer_compilation_unit_(nullptr), |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 77 | return_type_(return_type), |
| 78 | code_start_(nullptr), |
Calin Juravle | 48c2b03 | 2014-12-09 18:11:36 +0000 | [diff] [blame] | 79 | latest_result_(nullptr), |
Nicolas Geoffray | 2e7cd75 | 2015-07-10 11:38:52 +0100 | [diff] [blame] | 80 | can_use_baseline_for_string_init_(true), |
Sebastien Hertz | aa50d3a | 2015-08-25 15:25:41 +0200 | [diff] [blame] | 81 | compilation_stats_(nullptr), |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 82 | interpreter_metadata_(nullptr), |
Mathieu Chartier | 9865bde | 2015-12-21 09:58:16 -0800 | [diff] [blame^] | 83 | null_dex_cache_(), |
| 84 | dex_cache_(null_dex_cache_) {} |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 85 | |
David Brazdil | 5e8b137 | 2015-01-23 14:39:08 +0000 | [diff] [blame] | 86 | bool BuildGraph(const DexFile::CodeItem& code); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 87 | |
Nicolas Geoffray | 2e7cd75 | 2015-07-10 11:38:52 +0100 | [diff] [blame] | 88 | bool CanUseBaselineForStringInit() const { |
| 89 | return can_use_baseline_for_string_init_; |
| 90 | } |
| 91 | |
Andreas Gampe | 7c3952f | 2015-02-19 18:21:24 -0800 | [diff] [blame] | 92 | static constexpr const char* kBuilderPassName = "builder"; |
| 93 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 94 | // The number of entries in a packed switch before we use a jump table or specified |
| 95 | // compare/jump series. |
| 96 | static constexpr uint16_t kSmallSwitchThreshold = 3; |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 97 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 98 | private: |
| 99 | // Analyzes the dex instruction and adds HInstruction to the graph |
| 100 | // to execute that instruction. Returns whether the instruction can |
| 101 | // be handled. |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 102 | bool AnalyzeDexInstruction(const Instruction& instruction, uint32_t dex_pc); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 103 | |
| 104 | // Finds all instructions that start a new block, and populates branch_targets_ with |
| 105 | // the newly created blocks. |
Nicolas Geoffray | 43a539f | 2014-12-02 10:19:51 +0000 | [diff] [blame] | 106 | // As a side effect, also compute the number of dex instructions, blocks, and |
| 107 | // branches. |
Calin Juravle | 702d260 | 2015-04-30 19:28:21 +0100 | [diff] [blame] | 108 | // Returns true if all the branches fall inside the method code, false otherwise. |
| 109 | // (In normal cases this should always return true but someone can artificially |
| 110 | // create a code unit in which branches fall-through out of it). |
| 111 | bool ComputeBranchTargets(const uint16_t* start, |
Nicolas Geoffray | 43a539f | 2014-12-02 10:19:51 +0000 | [diff] [blame] | 112 | const uint16_t* end, |
Nicolas Geoffray | 43a539f | 2014-12-02 10:19:51 +0000 | [diff] [blame] | 113 | size_t* number_of_branches); |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 114 | void MaybeUpdateCurrentBlock(size_t dex_pc); |
| 115 | HBasicBlock* FindBlockStartingAt(int32_t dex_pc) const; |
| 116 | HBasicBlock* FindOrCreateBlockStartingAt(int32_t dex_pc); |
David Brazdil | 56e1acc | 2015-06-30 15:41:36 +0100 | [diff] [blame] | 117 | |
David Brazdil | 49bace1 | 2015-07-01 15:28:26 +0100 | [diff] [blame] | 118 | // Adds new blocks to `branch_targets_` starting at the limits of TryItems and |
| 119 | // their exception handlers. |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 120 | void CreateBlocksForTryCatch(const DexFile::CodeItem& code_item); |
David Brazdil | 49bace1 | 2015-07-01 15:28:26 +0100 | [diff] [blame] | 121 | |
| 122 | // Splits edges which cross the boundaries of TryItems, inserts TryBoundary |
| 123 | // instructions and links them to the corresponding catch blocks. |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 124 | void InsertTryBoundaryBlocks(const DexFile::CodeItem& code_item); |
David Brazdil | 49bace1 | 2015-07-01 15:28:26 +0100 | [diff] [blame] | 125 | |
David Brazdil | d7558da | 2015-09-22 13:04:14 +0100 | [diff] [blame] | 126 | // Iterates over the exception handlers of `try_item`, finds the corresponding |
| 127 | // catch blocks and makes them successors of `try_boundary`. The order of |
| 128 | // successors matches the order in which runtime exception delivery searches |
| 129 | // for a handler. |
| 130 | void LinkToCatchBlocks(HTryBoundary* try_boundary, |
| 131 | const DexFile::CodeItem& code_item, |
| 132 | const DexFile::TryItem* try_item); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 133 | |
Nicolas Geoffray | 9523a3e | 2015-07-17 11:51:28 +0000 | [diff] [blame] | 134 | bool CanDecodeQuickenedInfo() const; |
| 135 | uint16_t LookupQuickenedInfo(uint32_t dex_pc); |
| 136 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 137 | void InitializeLocals(uint16_t count); |
Vladimir Marko | 2aaa4b5 | 2015-09-17 17:03:26 +0100 | [diff] [blame] | 138 | HLocal* GetLocalAt(uint32_t register_index) const; |
| 139 | void UpdateLocal(uint32_t register_index, HInstruction* instruction, uint32_t dex_pc) const; |
| 140 | HInstruction* LoadLocal(uint32_t register_index, Primitive::Type type, uint32_t dex_pc) const; |
David Brazdil | 852eaff | 2015-02-02 15:23:05 +0000 | [diff] [blame] | 141 | void PotentiallyAddSuspendCheck(HBasicBlock* target, uint32_t dex_pc); |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 142 | void InitializeParameters(uint16_t number_of_parameters); |
Mingyao Yang | fb8464a | 2015-11-02 10:56:59 -0800 | [diff] [blame] | 143 | |
| 144 | // Returns whether the current method needs access check for the type. |
| 145 | // Output parameter finalizable is set to whether the type is finalizable. |
| 146 | bool NeedsAccessCheck(uint32_t type_index, /*out*/bool* finalizable) const; |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 147 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 148 | template<typename T> |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 149 | void Unop_12x(const Instruction& instruction, Primitive::Type type, uint32_t dex_pc); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 150 | |
| 151 | template<typename T> |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 152 | void Binop_23x(const Instruction& instruction, Primitive::Type type, uint32_t dex_pc); |
| 153 | |
| 154 | template<typename T> |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 155 | void Binop_23x_shift(const Instruction& instruction, Primitive::Type type, uint32_t dex_pc); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 156 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 157 | void Binop_23x_cmp(const Instruction& instruction, |
| 158 | Primitive::Type type, |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 159 | ComparisonBias bias, |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 160 | uint32_t dex_pc); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 161 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 162 | template<typename T> |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 163 | void Binop_12x(const Instruction& instruction, Primitive::Type type, uint32_t dex_pc); |
| 164 | |
| 165 | template<typename T> |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 166 | void Binop_12x_shift(const Instruction& instruction, Primitive::Type type, uint32_t dex_pc); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 167 | |
| 168 | template<typename T> |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 169 | void Binop_22b(const Instruction& instruction, bool reverse, uint32_t dex_pc); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 170 | |
| 171 | template<typename T> |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 172 | void Binop_22s(const Instruction& instruction, bool reverse, uint32_t dex_pc); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 173 | |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 174 | template<typename T> void If_21t(const Instruction& instruction, uint32_t dex_pc); |
| 175 | template<typename T> void If_22t(const Instruction& instruction, uint32_t dex_pc); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 176 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 177 | void Conversion_12x(const Instruction& instruction, |
| 178 | Primitive::Type input_type, |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 179 | Primitive::Type result_type, |
| 180 | uint32_t dex_pc); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 181 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 182 | void BuildCheckedDivRem(uint16_t out_reg, |
| 183 | uint16_t first_reg, |
| 184 | int64_t second_reg_or_constant, |
| 185 | uint32_t dex_pc, |
| 186 | Primitive::Type type, |
| 187 | bool second_is_lit, |
| 188 | bool is_div); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 189 | |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 190 | void BuildReturn(const Instruction& instruction, Primitive::Type type, uint32_t dex_pc); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 191 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 192 | // Builds an instance field access node and returns whether the instruction is supported. |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 193 | bool BuildInstanceFieldAccess(const Instruction& instruction, uint32_t dex_pc, bool is_put); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 194 | |
Calin Juravle | 07380a2 | 2015-09-17 14:15:12 +0100 | [diff] [blame] | 195 | void BuildUnresolvedStaticFieldAccess(const Instruction& instruction, |
| 196 | uint32_t dex_pc, |
| 197 | bool is_put, |
| 198 | Primitive::Type field_type); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 199 | // Builds a static field access node and returns whether the instruction is supported. |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 200 | bool BuildStaticFieldAccess(const Instruction& instruction, uint32_t dex_pc, bool is_put); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 201 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 202 | void BuildArrayAccess(const Instruction& instruction, |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 203 | uint32_t dex_pc, |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 204 | bool is_get, |
| 205 | Primitive::Type anticipated_type); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 206 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 207 | // Builds an invocation node and returns whether the instruction is supported. |
| 208 | bool BuildInvoke(const Instruction& instruction, |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 209 | uint32_t dex_pc, |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 210 | uint32_t method_idx, |
| 211 | uint32_t number_of_vreg_arguments, |
| 212 | bool is_range, |
| 213 | uint32_t* args, |
| 214 | uint32_t register_index); |
| 215 | |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 216 | // Builds a new array node and the instructions that fill it. |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 217 | void BuildFilledNewArray(uint32_t dex_pc, |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 218 | uint32_t type_index, |
| 219 | uint32_t number_of_vreg_arguments, |
| 220 | bool is_range, |
| 221 | uint32_t* args, |
| 222 | uint32_t register_index); |
| 223 | |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 224 | void BuildFillArrayData(const Instruction& instruction, uint32_t dex_pc); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 225 | |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 226 | // Fills the given object with data as specified in the fill-array-data |
| 227 | // instruction. Currently only used for non-reference and non-floating point |
| 228 | // arrays. |
| 229 | template <typename T> |
| 230 | void BuildFillArrayData(HInstruction* object, |
| 231 | const T* data, |
| 232 | uint32_t element_count, |
| 233 | Primitive::Type anticipated_type, |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 234 | uint32_t dex_pc); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 235 | |
| 236 | // Fills the given object with data as specified in the fill-array-data |
| 237 | // instruction. The data must be for long and double arrays. |
| 238 | void BuildFillWideArrayData(HInstruction* object, |
Nicolas Geoffray | 8d6ae52 | 2014-10-23 18:32:13 +0100 | [diff] [blame] | 239 | const int64_t* data, |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 240 | uint32_t element_count, |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 241 | uint32_t dex_pc); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 242 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 243 | // Builds a `HInstanceOf`, or a `HCheckCast` instruction. |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 244 | void BuildTypeCheck(const Instruction& instruction, |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 245 | uint8_t destination, |
| 246 | uint8_t reference, |
| 247 | uint16_t type_index, |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 248 | uint32_t dex_pc); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 249 | |
Andreas Gampe | e4d4d32 | 2014-12-04 09:09:57 -0800 | [diff] [blame] | 250 | // Builds an instruction sequence for a packed switch statement. |
Calin Juravle | 48c2b03 | 2014-12-09 18:11:36 +0000 | [diff] [blame] | 251 | void BuildPackedSwitch(const Instruction& instruction, uint32_t dex_pc); |
Andreas Gampe | d881df5 | 2014-11-24 23:28:39 -0800 | [diff] [blame] | 252 | |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 253 | // Build a switch instruction from a packed switch statement. |
| 254 | void BuildSwitchJumpTable(const SwitchTable& table, |
| 255 | const Instruction& instruction, |
| 256 | HInstruction* value, |
| 257 | uint32_t dex_pc); |
| 258 | |
Andreas Gampe | e4d4d32 | 2014-12-04 09:09:57 -0800 | [diff] [blame] | 259 | // Builds an instruction sequence for a sparse switch statement. |
Calin Juravle | 48c2b03 | 2014-12-09 18:11:36 +0000 | [diff] [blame] | 260 | void BuildSparseSwitch(const Instruction& instruction, uint32_t dex_pc); |
Andreas Gampe | e4d4d32 | 2014-12-04 09:09:57 -0800 | [diff] [blame] | 261 | |
| 262 | void BuildSwitchCaseHelper(const Instruction& instruction, size_t index, |
| 263 | bool is_last_case, const SwitchTable& table, |
| 264 | HInstruction* value, int32_t case_value_int, |
| 265 | int32_t target_offset, uint32_t dex_pc); |
| 266 | |
David Brazdil | 1b49872 | 2015-03-31 11:37:18 +0100 | [diff] [blame] | 267 | bool SkipCompilation(const DexFile::CodeItem& code_item, size_t number_of_branches); |
Calin Juravle | 48c2b03 | 2014-12-09 18:11:36 +0000 | [diff] [blame] | 268 | |
| 269 | void MaybeRecordStat(MethodCompilationStat compilation_stat); |
| 270 | |
Nicolas Geoffray | 3045174 | 2015-06-19 13:32:41 +0100 | [diff] [blame] | 271 | // Returns the outer-most compiling method's class. |
Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 272 | mirror::Class* GetOutermostCompilingClass() const; |
| 273 | |
Nicolas Geoffray | 3045174 | 2015-06-19 13:32:41 +0100 | [diff] [blame] | 274 | // Returns the class whose method is being compiled. |
| 275 | mirror::Class* GetCompilingClass() const; |
| 276 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 277 | // Returns whether `type_index` points to the outer-most compiling method's class. |
Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 278 | bool IsOutermostCompilingClass(uint16_t type_index) const; |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 279 | |
Nicolas Geoffray | 2e7cd75 | 2015-07-10 11:38:52 +0100 | [diff] [blame] | 280 | void PotentiallySimplifyFakeString(uint16_t original_dex_register, |
| 281 | uint32_t dex_pc, |
| 282 | HInvoke* invoke); |
| 283 | |
Calin Juravle | 5d01db1 | 2015-08-25 15:02:42 +0100 | [diff] [blame] | 284 | bool SetupInvokeArguments(HInvoke* invoke, |
| 285 | uint32_t number_of_vreg_arguments, |
| 286 | uint32_t* args, |
| 287 | uint32_t register_index, |
| 288 | bool is_range, |
| 289 | const char* descriptor, |
| 290 | size_t start_index, |
| 291 | size_t* argument_index); |
| 292 | |
| 293 | bool HandleInvoke(HInvoke* invoke, |
| 294 | uint32_t number_of_vreg_arguments, |
| 295 | uint32_t* args, |
| 296 | uint32_t register_index, |
| 297 | bool is_range, |
| 298 | const char* descriptor, |
| 299 | HClinitCheck* clinit_check); |
| 300 | |
| 301 | bool HandleStringInit(HInvoke* invoke, |
| 302 | uint32_t number_of_vreg_arguments, |
| 303 | uint32_t* args, |
| 304 | uint32_t register_index, |
| 305 | bool is_range, |
| 306 | const char* descriptor); |
Calin Juravle | 68ad649 | 2015-08-18 17:08:12 +0100 | [diff] [blame] | 307 | |
| 308 | HClinitCheck* ProcessClinitCheckForInvoke( |
| 309 | uint32_t dex_pc, |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 310 | ArtMethod* method, |
Calin Juravle | 68ad649 | 2015-08-18 17:08:12 +0100 | [diff] [blame] | 311 | uint32_t method_idx, |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 312 | HInvokeStaticOrDirect::ClinitCheckRequirement* clinit_check_requirement) |
| 313 | SHARED_REQUIRES(Locks::mutator_lock_); |
Calin Juravle | 68ad649 | 2015-08-18 17:08:12 +0100 | [diff] [blame] | 314 | |
Nicolas Geoffray | 729645a | 2015-11-19 13:29:02 +0000 | [diff] [blame] | 315 | // Build a HNewInstance instruction. |
| 316 | bool BuildNewInstance(uint16_t type_index, uint32_t dex_pc); |
| 317 | |
Nicolas Geoffray | d9dc6f4 | 2015-11-24 14:06:57 +0000 | [diff] [blame] | 318 | // Return whether the compiler can assume `cls` is initialized. |
| 319 | bool IsInitialized(Handle<mirror::Class> cls) const |
Nicolas Geoffray | 729645a | 2015-11-19 13:29:02 +0000 | [diff] [blame] | 320 | SHARED_REQUIRES(Locks::mutator_lock_); |
| 321 | |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 322 | // Try to resolve a method using the class linker. Return null if a method could |
| 323 | // not be resolved. |
| 324 | ArtMethod* ResolveMethod(uint16_t method_idx, InvokeType invoke_type); |
| 325 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 326 | ArenaAllocator* const arena_; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 327 | |
| 328 | // A list of the size of the dex code holding block information for |
| 329 | // the method. If an entry contains a block, then the dex instruction |
| 330 | // starting at that entry is the first instruction of a new block. |
Vladimir Marko | 2aaa4b5 | 2015-09-17 17:03:26 +0100 | [diff] [blame] | 331 | ArenaVector<HBasicBlock*> branch_targets_; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 332 | |
Vladimir Marko | 2aaa4b5 | 2015-09-17 17:03:26 +0100 | [diff] [blame] | 333 | ArenaVector<HLocal*> locals_; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 334 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 335 | HBasicBlock* entry_block_; |
| 336 | HBasicBlock* exit_block_; |
| 337 | HBasicBlock* current_block_; |
David Brazdil | 5e8b137 | 2015-01-23 14:39:08 +0000 | [diff] [blame] | 338 | HGraph* const graph_; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 339 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 340 | // The dex file where the method being compiled is. |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 341 | const DexFile* const dex_file_; |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 342 | |
| 343 | // The compilation unit of the current method being compiled. Note that |
| 344 | // it can be an inlined method. |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 345 | DexCompilationUnit* const dex_compilation_unit_; |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 346 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 347 | CompilerDriver* const compiler_driver_; |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 348 | |
| 349 | // The compilation unit of the outermost method being compiled. That is the |
| 350 | // method being compiled (and not inlined), and potentially inlining other |
| 351 | // methods. |
| 352 | const DexCompilationUnit* const outer_compilation_unit_; |
| 353 | |
| 354 | // The return type of the method being compiled. |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 355 | const Primitive::Type return_type_; |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 356 | |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 357 | // The pointer in the dex file where the instructions of the code item |
| 358 | // being currently compiled start. |
| 359 | const uint16_t* code_start_; |
| 360 | |
| 361 | // The last invoke or fill-new-array being built. Only to be |
| 362 | // used by move-result instructions. |
| 363 | HInstruction* latest_result_; |
| 364 | |
Nicolas Geoffray | 2e7cd75 | 2015-07-10 11:38:52 +0100 | [diff] [blame] | 365 | // We need to know whether we have built a graph that has calls to StringFactory |
| 366 | // and hasn't gone through the verifier. If the following flag is `false`, then |
| 367 | // we cannot compile with baseline. |
| 368 | bool can_use_baseline_for_string_init_; |
| 369 | |
Calin Juravle | 48c2b03 | 2014-12-09 18:11:36 +0000 | [diff] [blame] | 370 | OptimizingCompilerStats* compilation_stats_; |
| 371 | |
Nicolas Geoffray | 9523a3e | 2015-07-17 11:51:28 +0000 | [diff] [blame] | 372 | const uint8_t* interpreter_metadata_; |
| 373 | |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 374 | // Dex cache for dex_file_. |
Mathieu Chartier | 9865bde | 2015-12-21 09:58:16 -0800 | [diff] [blame^] | 375 | ScopedNullHandle<mirror::DexCache> null_dex_cache_; |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 376 | Handle<mirror::DexCache> dex_cache_; |
| 377 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 378 | DISALLOW_COPY_AND_ASSIGN(HGraphBuilder); |
| 379 | }; |
| 380 | |
| 381 | } // namespace art |
| 382 | |
| 383 | #endif // ART_COMPILER_OPTIMIZING_BUILDER_H_ |