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