Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1 | /* |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 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 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 17 | #include "builder.h" |
| 18 | |
Andreas Gampe | d881df5 | 2014-11-24 23:28:39 -0800 | [diff] [blame] | 19 | #include "base/logging.h" |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 20 | #include "class_linker.h" |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 21 | #include "dex_file.h" |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 22 | #include "dex_file-inl.h" |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 23 | #include "dex_instruction.h" |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 24 | #include "dex_instruction-inl.h" |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 25 | #include "driver/compiler_driver-inl.h" |
| 26 | #include "mirror/art_field.h" |
| 27 | #include "mirror/art_field-inl.h" |
| 28 | #include "mirror/class_loader.h" |
| 29 | #include "mirror/dex_cache.h" |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 30 | #include "nodes.h" |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 31 | #include "primitive.h" |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 32 | #include "scoped_thread_state_change.h" |
| 33 | #include "thread.h" |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 34 | |
| 35 | namespace art { |
| 36 | |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 37 | /** |
| 38 | * Helper class to add HTemporary instructions. This class is used when |
| 39 | * converting a DEX instruction to multiple HInstruction, and where those |
| 40 | * instructions do not die at the following instruction, but instead spans |
| 41 | * multiple instructions. |
| 42 | */ |
| 43 | class Temporaries : public ValueObject { |
| 44 | public: |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 45 | explicit Temporaries(HGraph* graph) : graph_(graph), index_(0) {} |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 46 | |
| 47 | void Add(HInstruction* instruction) { |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 48 | HInstruction* temp = new (graph_->GetArena()) HTemporary(index_); |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 49 | instruction->GetBlock()->AddInstruction(temp); |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 50 | |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 51 | DCHECK(temp->GetPrevious() == instruction); |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 52 | |
| 53 | size_t offset; |
| 54 | if (instruction->GetType() == Primitive::kPrimLong |
| 55 | || instruction->GetType() == Primitive::kPrimDouble) { |
| 56 | offset = 2; |
| 57 | } else { |
| 58 | offset = 1; |
| 59 | } |
| 60 | index_ += offset; |
| 61 | |
| 62 | graph_->UpdateTemporariesVRegSlots(index_); |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 63 | } |
| 64 | |
| 65 | private: |
| 66 | HGraph* const graph_; |
| 67 | |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 68 | // Current index in the temporary stack, updated by `Add`. |
| 69 | size_t index_; |
| 70 | }; |
| 71 | |
Andreas Gampe | d881df5 | 2014-11-24 23:28:39 -0800 | [diff] [blame] | 72 | class SwitchTable : public ValueObject { |
| 73 | public: |
| 74 | SwitchTable(const Instruction& instruction, uint32_t dex_pc, bool sparse) |
| 75 | : instruction_(instruction), dex_pc_(dex_pc), sparse_(sparse) { |
| 76 | int32_t table_offset = instruction.VRegB_31t(); |
| 77 | const uint16_t* table = reinterpret_cast<const uint16_t*>(&instruction) + table_offset; |
| 78 | if (sparse) { |
| 79 | CHECK_EQ(table[0], static_cast<uint16_t>(Instruction::kSparseSwitchSignature)); |
| 80 | } else { |
| 81 | CHECK_EQ(table[0], static_cast<uint16_t>(Instruction::kPackedSwitchSignature)); |
| 82 | } |
| 83 | num_entries_ = table[1]; |
| 84 | values_ = reinterpret_cast<const int32_t*>(&table[2]); |
| 85 | } |
| 86 | |
| 87 | uint16_t GetNumEntries() const { |
| 88 | return num_entries_; |
| 89 | } |
| 90 | |
Andreas Gampe | e4d4d32 | 2014-12-04 09:09:57 -0800 | [diff] [blame] | 91 | void CheckIndex(size_t index) const { |
| 92 | if (sparse_) { |
| 93 | // In a sparse table, we have num_entries_ keys and num_entries_ values, in that order. |
| 94 | DCHECK_LT(index, 2 * static_cast<size_t>(num_entries_)); |
| 95 | } else { |
| 96 | // In a packed table, we have the starting key and num_entries_ values. |
| 97 | DCHECK_LT(index, 1 + static_cast<size_t>(num_entries_)); |
| 98 | } |
| 99 | } |
| 100 | |
Andreas Gampe | d881df5 | 2014-11-24 23:28:39 -0800 | [diff] [blame] | 101 | int32_t GetEntryAt(size_t index) const { |
Andreas Gampe | e4d4d32 | 2014-12-04 09:09:57 -0800 | [diff] [blame] | 102 | CheckIndex(index); |
Andreas Gampe | d881df5 | 2014-11-24 23:28:39 -0800 | [diff] [blame] | 103 | return values_[index]; |
| 104 | } |
| 105 | |
| 106 | uint32_t GetDexPcForIndex(size_t index) const { |
Andreas Gampe | e4d4d32 | 2014-12-04 09:09:57 -0800 | [diff] [blame] | 107 | CheckIndex(index); |
Andreas Gampe | d881df5 | 2014-11-24 23:28:39 -0800 | [diff] [blame] | 108 | return dex_pc_ + |
| 109 | (reinterpret_cast<const int16_t*>(values_ + index) - |
| 110 | reinterpret_cast<const int16_t*>(&instruction_)); |
| 111 | } |
| 112 | |
Andreas Gampe | e4d4d32 | 2014-12-04 09:09:57 -0800 | [diff] [blame] | 113 | // Index of the first value in the table. |
| 114 | size_t GetFirstValueIndex() const { |
| 115 | if (sparse_) { |
| 116 | // In a sparse table, we have num_entries_ keys and num_entries_ values, in that order. |
| 117 | return num_entries_; |
| 118 | } else { |
| 119 | // In a packed table, we have the starting key and num_entries_ values. |
| 120 | return 1; |
| 121 | } |
| 122 | } |
| 123 | |
Andreas Gampe | d881df5 | 2014-11-24 23:28:39 -0800 | [diff] [blame] | 124 | private: |
| 125 | const Instruction& instruction_; |
| 126 | const uint32_t dex_pc_; |
| 127 | |
| 128 | // Whether this is a sparse-switch table (or a packed-switch one). |
| 129 | const bool sparse_; |
| 130 | |
| 131 | // This can't be const as it needs to be computed off of the given instruction, and complicated |
| 132 | // expressions in the initializer list seemed very ugly. |
| 133 | uint16_t num_entries_; |
| 134 | |
| 135 | const int32_t* values_; |
| 136 | |
| 137 | DISALLOW_COPY_AND_ASSIGN(SwitchTable); |
| 138 | }; |
| 139 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 140 | void HGraphBuilder::InitializeLocals(uint16_t count) { |
| 141 | graph_->SetNumberOfVRegs(count); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 142 | locals_.SetSize(count); |
| 143 | for (int i = 0; i < count; i++) { |
| 144 | HLocal* local = new (arena_) HLocal(i); |
| 145 | entry_block_->AddInstruction(local); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 146 | locals_.Put(i, local); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 147 | } |
| 148 | } |
| 149 | |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 150 | void HGraphBuilder::InitializeParameters(uint16_t number_of_parameters) { |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 151 | // dex_compilation_unit_ is null only when unit testing. |
| 152 | if (dex_compilation_unit_ == nullptr) { |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 153 | return; |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 154 | } |
| 155 | |
| 156 | graph_->SetNumberOfInVRegs(number_of_parameters); |
| 157 | const char* shorty = dex_compilation_unit_->GetShorty(); |
| 158 | int locals_index = locals_.Size() - number_of_parameters; |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 159 | int parameter_index = 0; |
| 160 | |
| 161 | if (!dex_compilation_unit_->IsStatic()) { |
| 162 | // Add the implicit 'this' argument, not expressed in the signature. |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 163 | HParameterValue* parameter = |
| 164 | new (arena_) HParameterValue(parameter_index++, Primitive::kPrimNot); |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 165 | entry_block_->AddInstruction(parameter); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 166 | HLocal* local = GetLocalAt(locals_index++); |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 167 | entry_block_->AddInstruction(new (arena_) HStoreLocal(local, parameter)); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 168 | number_of_parameters--; |
| 169 | } |
| 170 | |
| 171 | uint32_t pos = 1; |
| 172 | for (int i = 0; i < number_of_parameters; i++) { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 173 | HParameterValue* parameter = |
| 174 | new (arena_) HParameterValue(parameter_index++, Primitive::GetType(shorty[pos++])); |
| 175 | entry_block_->AddInstruction(parameter); |
| 176 | HLocal* local = GetLocalAt(locals_index++); |
| 177 | // Store the parameter value in the local that the dex code will use |
| 178 | // to reference that parameter. |
| 179 | entry_block_->AddInstruction(new (arena_) HStoreLocal(local, parameter)); |
| 180 | bool is_wide = (parameter->GetType() == Primitive::kPrimLong) |
| 181 | || (parameter->GetType() == Primitive::kPrimDouble); |
| 182 | if (is_wide) { |
| 183 | i++; |
| 184 | locals_index++; |
| 185 | parameter_index++; |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 186 | } |
| 187 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 188 | } |
| 189 | |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 190 | template<typename T> |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 191 | void HGraphBuilder::If_22t(const Instruction& instruction, uint32_t dex_pc) { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 192 | int32_t target_offset = instruction.GetTargetOffset(); |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 193 | PotentiallyAddSuspendCheck(target_offset, dex_pc); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 194 | HInstruction* first = LoadLocal(instruction.VRegA(), Primitive::kPrimInt); |
| 195 | HInstruction* second = LoadLocal(instruction.VRegB(), Primitive::kPrimInt); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 196 | T* comparison = new (arena_) T(first, second); |
| 197 | current_block_->AddInstruction(comparison); |
| 198 | HInstruction* ifinst = new (arena_) HIf(comparison); |
| 199 | current_block_->AddInstruction(ifinst); |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 200 | HBasicBlock* target = FindBlockStartingAt(dex_pc + target_offset); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 201 | DCHECK(target != nullptr); |
| 202 | current_block_->AddSuccessor(target); |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 203 | target = FindBlockStartingAt(dex_pc + instruction.SizeInCodeUnits()); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 204 | DCHECK(target != nullptr); |
| 205 | current_block_->AddSuccessor(target); |
| 206 | current_block_ = nullptr; |
| 207 | } |
| 208 | |
| 209 | template<typename T> |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 210 | void HGraphBuilder::If_21t(const Instruction& instruction, uint32_t dex_pc) { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 211 | int32_t target_offset = instruction.GetTargetOffset(); |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 212 | PotentiallyAddSuspendCheck(target_offset, dex_pc); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 213 | HInstruction* value = LoadLocal(instruction.VRegA(), Primitive::kPrimInt); |
| 214 | T* comparison = new (arena_) T(value, GetIntConstant(0)); |
| 215 | current_block_->AddInstruction(comparison); |
| 216 | HInstruction* ifinst = new (arena_) HIf(comparison); |
| 217 | current_block_->AddInstruction(ifinst); |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 218 | HBasicBlock* target = FindBlockStartingAt(dex_pc + target_offset); |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 219 | DCHECK(target != nullptr); |
| 220 | current_block_->AddSuccessor(target); |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 221 | target = FindBlockStartingAt(dex_pc + instruction.SizeInCodeUnits()); |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 222 | DCHECK(target != nullptr); |
| 223 | current_block_->AddSuccessor(target); |
| 224 | current_block_ = nullptr; |
| 225 | } |
| 226 | |
Nicolas Geoffray | 43a539f | 2014-12-02 10:19:51 +0000 | [diff] [blame] | 227 | static bool ShouldSkipCompilation(const CompilerDriver& compiler_driver, |
| 228 | const DexCompilationUnit& dex_compilation_unit, |
| 229 | size_t number_of_dex_instructions, |
| 230 | size_t number_of_blocks ATTRIBUTE_UNUSED, |
| 231 | size_t number_of_branches) { |
| 232 | const CompilerOptions& compiler_options = compiler_driver.GetCompilerOptions(); |
| 233 | CompilerOptions::CompilerFilter compiler_filter = compiler_options.GetCompilerFilter(); |
| 234 | if (compiler_filter == CompilerOptions::kEverything) { |
| 235 | return false; |
| 236 | } |
| 237 | |
| 238 | if (compiler_options.IsHugeMethod(number_of_dex_instructions)) { |
| 239 | LOG(INFO) << "Skip compilation of huge method " |
| 240 | << PrettyMethod(dex_compilation_unit.GetDexMethodIndex(), |
| 241 | *dex_compilation_unit.GetDexFile()) |
| 242 | << ": " << number_of_dex_instructions << " dex instructions"; |
| 243 | return true; |
| 244 | } |
| 245 | |
| 246 | // If it's large and contains no branches, it's likely to be machine generated initialization. |
| 247 | if (compiler_options.IsLargeMethod(number_of_dex_instructions) && (number_of_branches == 0)) { |
| 248 | LOG(INFO) << "Skip compilation of large method with no branch " |
| 249 | << PrettyMethod(dex_compilation_unit.GetDexMethodIndex(), |
| 250 | *dex_compilation_unit.GetDexFile()) |
| 251 | << ": " << number_of_dex_instructions << " dex instructions"; |
| 252 | return true; |
| 253 | } |
| 254 | |
| 255 | return false; |
| 256 | } |
| 257 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 258 | HGraph* HGraphBuilder::BuildGraph(const DexFile::CodeItem& code_item) { |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 259 | const uint16_t* code_ptr = code_item.insns_; |
| 260 | const uint16_t* code_end = code_item.insns_ + code_item.insns_size_in_code_units_; |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 261 | code_start_ = code_ptr; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 262 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 263 | // Setup the graph with the entry block and exit block. |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 264 | graph_ = new (arena_) HGraph(arena_); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 265 | entry_block_ = new (arena_) HBasicBlock(graph_, 0); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 266 | graph_->AddBlock(entry_block_); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 267 | exit_block_ = new (arena_) HBasicBlock(graph_, kNoDexPc); |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 268 | graph_->SetEntryBlock(entry_block_); |
| 269 | graph_->SetExitBlock(exit_block_); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 270 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 271 | InitializeLocals(code_item.registers_size_); |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 272 | graph_->UpdateMaximumNumberOfOutVRegs(code_item.outs_size_); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 273 | |
Nicolas Geoffray | 43a539f | 2014-12-02 10:19:51 +0000 | [diff] [blame] | 274 | // Compute the number of dex instructions, blocks, and branches. We will |
| 275 | // check these values against limits given to the compiler. |
| 276 | size_t number_of_dex_instructions = 0; |
| 277 | size_t number_of_blocks = 0; |
| 278 | size_t number_of_branches = 0; |
| 279 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 280 | // To avoid splitting blocks, we compute ahead of time the instructions that |
| 281 | // start a new block, and create these blocks. |
Nicolas Geoffray | 43a539f | 2014-12-02 10:19:51 +0000 | [diff] [blame] | 282 | ComputeBranchTargets( |
| 283 | code_ptr, code_end, &number_of_dex_instructions, &number_of_blocks, &number_of_branches); |
| 284 | |
| 285 | // Note that the compiler driver is null when unit testing. |
| 286 | if (compiler_driver_ != nullptr) { |
| 287 | if (ShouldSkipCompilation(*compiler_driver_, |
| 288 | *dex_compilation_unit_, |
| 289 | number_of_dex_instructions, |
| 290 | number_of_blocks, |
| 291 | number_of_branches)) { |
| 292 | return nullptr; |
| 293 | } |
| 294 | } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 295 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 296 | // Also create blocks for catch handlers. |
| 297 | if (code_item.tries_size_ != 0) { |
| 298 | const uint8_t* handlers_ptr = DexFile::GetCatchHandlerData(code_item, 0); |
| 299 | uint32_t handlers_size = DecodeUnsignedLeb128(&handlers_ptr); |
| 300 | for (uint32_t idx = 0; idx < handlers_size; ++idx) { |
| 301 | CatchHandlerIterator iterator(handlers_ptr); |
| 302 | for (; iterator.HasNext(); iterator.Next()) { |
| 303 | uint32_t address = iterator.GetHandlerAddress(); |
| 304 | HBasicBlock* block = FindBlockStartingAt(address); |
| 305 | if (block == nullptr) { |
| 306 | block = new (arena_) HBasicBlock(graph_, address); |
| 307 | branch_targets_.Put(address, block); |
| 308 | } |
| 309 | block->SetIsCatchBlock(); |
| 310 | } |
| 311 | handlers_ptr = iterator.EndDataPointer(); |
| 312 | } |
| 313 | } |
| 314 | |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 315 | InitializeParameters(code_item.ins_size_); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 316 | |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 317 | size_t dex_pc = 0; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 318 | while (code_ptr < code_end) { |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 319 | // Update the current block if dex_pc starts a new block. |
| 320 | MaybeUpdateCurrentBlock(dex_pc); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 321 | const Instruction& instruction = *Instruction::At(code_ptr); |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 322 | if (!AnalyzeDexInstruction(instruction, dex_pc)) return nullptr; |
| 323 | dex_pc += instruction.SizeInCodeUnits(); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 324 | code_ptr += instruction.SizeInCodeUnits(); |
| 325 | } |
| 326 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 327 | // Add the exit block at the end to give it the highest id. |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 328 | graph_->AddBlock(exit_block_); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 329 | exit_block_->AddInstruction(new (arena_) HExit()); |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 330 | // Add the suspend check to the entry block. |
| 331 | entry_block_->AddInstruction(new (arena_) HSuspendCheck(0)); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 332 | entry_block_->AddInstruction(new (arena_) HGoto()); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 333 | return graph_; |
| 334 | } |
| 335 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 336 | void HGraphBuilder::MaybeUpdateCurrentBlock(size_t index) { |
| 337 | HBasicBlock* block = FindBlockStartingAt(index); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 338 | if (block == nullptr) { |
| 339 | return; |
| 340 | } |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 341 | |
| 342 | if (current_block_ != nullptr) { |
| 343 | // Branching instructions clear current_block, so we know |
| 344 | // the last instruction of the current block is not a branching |
| 345 | // instruction. We add an unconditional goto to the found block. |
| 346 | current_block_->AddInstruction(new (arena_) HGoto()); |
| 347 | current_block_->AddSuccessor(block); |
| 348 | } |
| 349 | graph_->AddBlock(block); |
| 350 | current_block_ = block; |
| 351 | } |
| 352 | |
Nicolas Geoffray | 43a539f | 2014-12-02 10:19:51 +0000 | [diff] [blame] | 353 | void HGraphBuilder::ComputeBranchTargets(const uint16_t* code_ptr, |
| 354 | const uint16_t* code_end, |
| 355 | size_t* number_of_dex_instructions, |
| 356 | size_t* number_of_blocks, |
| 357 | size_t* number_of_branches) { |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 358 | branch_targets_.SetSize(code_end - code_ptr); |
| 359 | |
| 360 | // Create the first block for the dex instructions, single successor of the entry block. |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 361 | HBasicBlock* block = new (arena_) HBasicBlock(graph_, 0); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 362 | branch_targets_.Put(0, block); |
| 363 | entry_block_->AddSuccessor(block); |
| 364 | |
| 365 | // Iterate over all instructions and find branching instructions. Create blocks for |
| 366 | // the locations these instructions branch to. |
Andreas Gampe | d881df5 | 2014-11-24 23:28:39 -0800 | [diff] [blame] | 367 | uint32_t dex_pc = 0; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 368 | while (code_ptr < code_end) { |
Nicolas Geoffray | 43a539f | 2014-12-02 10:19:51 +0000 | [diff] [blame] | 369 | (*number_of_dex_instructions)++; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 370 | const Instruction& instruction = *Instruction::At(code_ptr); |
| 371 | if (instruction.IsBranch()) { |
Nicolas Geoffray | 43a539f | 2014-12-02 10:19:51 +0000 | [diff] [blame] | 372 | (*number_of_branches)++; |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 373 | int32_t target = instruction.GetTargetOffset() + dex_pc; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 374 | // Create a block for the target instruction. |
| 375 | if (FindBlockStartingAt(target) == nullptr) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 376 | block = new (arena_) HBasicBlock(graph_, target); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 377 | branch_targets_.Put(target, block); |
Nicolas Geoffray | 43a539f | 2014-12-02 10:19:51 +0000 | [diff] [blame] | 378 | (*number_of_blocks)++; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 379 | } |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 380 | dex_pc += instruction.SizeInCodeUnits(); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 381 | code_ptr += instruction.SizeInCodeUnits(); |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 382 | if ((code_ptr < code_end) && (FindBlockStartingAt(dex_pc) == nullptr)) { |
| 383 | block = new (arena_) HBasicBlock(graph_, dex_pc); |
| 384 | branch_targets_.Put(dex_pc, block); |
Nicolas Geoffray | 43a539f | 2014-12-02 10:19:51 +0000 | [diff] [blame] | 385 | (*number_of_blocks)++; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 386 | } |
Andreas Gampe | e4d4d32 | 2014-12-04 09:09:57 -0800 | [diff] [blame] | 387 | } else if (instruction.IsSwitch()) { |
| 388 | SwitchTable table(instruction, dex_pc, instruction.Opcode() == Instruction::SPARSE_SWITCH); |
Andreas Gampe | d881df5 | 2014-11-24 23:28:39 -0800 | [diff] [blame] | 389 | |
| 390 | uint16_t num_entries = table.GetNumEntries(); |
| 391 | |
Andreas Gampe | e4d4d32 | 2014-12-04 09:09:57 -0800 | [diff] [blame] | 392 | // In a packed-switch, the entry at index 0 is the starting key. In a sparse-switch, the |
| 393 | // entry at index 0 is the first key, and values are after *all* keys. |
| 394 | size_t offset = table.GetFirstValueIndex(); |
| 395 | |
| 396 | // Use a larger loop counter type to avoid overflow issues. |
| 397 | for (size_t i = 0; i < num_entries; ++i) { |
Andreas Gampe | d881df5 | 2014-11-24 23:28:39 -0800 | [diff] [blame] | 398 | // The target of the case. |
Andreas Gampe | e4d4d32 | 2014-12-04 09:09:57 -0800 | [diff] [blame] | 399 | uint32_t target = dex_pc + table.GetEntryAt(i + offset); |
Andreas Gampe | d881df5 | 2014-11-24 23:28:39 -0800 | [diff] [blame] | 400 | if (FindBlockStartingAt(target) == nullptr) { |
| 401 | block = new (arena_) HBasicBlock(graph_, target); |
| 402 | branch_targets_.Put(target, block); |
| 403 | (*number_of_blocks)++; |
| 404 | } |
| 405 | |
| 406 | // The next case gets its own block. |
| 407 | if (i < num_entries) { |
| 408 | block = new (arena_) HBasicBlock(graph_, target); |
| 409 | branch_targets_.Put(table.GetDexPcForIndex(i), block); |
| 410 | (*number_of_blocks)++; |
| 411 | } |
| 412 | } |
| 413 | |
| 414 | // Fall-through. Add a block if there is more code afterwards. |
| 415 | dex_pc += instruction.SizeInCodeUnits(); |
| 416 | code_ptr += instruction.SizeInCodeUnits(); |
| 417 | if ((code_ptr < code_end) && (FindBlockStartingAt(dex_pc) == nullptr)) { |
| 418 | block = new (arena_) HBasicBlock(graph_, dex_pc); |
| 419 | branch_targets_.Put(dex_pc, block); |
| 420 | (*number_of_blocks)++; |
| 421 | } |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 422 | } else { |
| 423 | code_ptr += instruction.SizeInCodeUnits(); |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 424 | dex_pc += instruction.SizeInCodeUnits(); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 425 | } |
| 426 | } |
| 427 | } |
| 428 | |
| 429 | HBasicBlock* HGraphBuilder::FindBlockStartingAt(int32_t index) const { |
| 430 | DCHECK_GE(index, 0); |
| 431 | return branch_targets_.Get(index); |
| 432 | } |
| 433 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 434 | template<typename T> |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 435 | void HGraphBuilder::Unop_12x(const Instruction& instruction, Primitive::Type type) { |
| 436 | HInstruction* first = LoadLocal(instruction.VRegB(), type); |
| 437 | current_block_->AddInstruction(new (arena_) T(type, first)); |
| 438 | UpdateLocal(instruction.VRegA(), current_block_->GetLastInstruction()); |
| 439 | } |
| 440 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 441 | void HGraphBuilder::Conversion_12x(const Instruction& instruction, |
| 442 | Primitive::Type input_type, |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 443 | Primitive::Type result_type, |
| 444 | uint32_t dex_pc) { |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 445 | HInstruction* first = LoadLocal(instruction.VRegB(), input_type); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 446 | current_block_->AddInstruction(new (arena_) HTypeConversion(result_type, first, dex_pc)); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 447 | UpdateLocal(instruction.VRegA(), current_block_->GetLastInstruction()); |
| 448 | } |
| 449 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 450 | template<typename T> |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 451 | void HGraphBuilder::Binop_23x(const Instruction& instruction, Primitive::Type type) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 452 | HInstruction* first = LoadLocal(instruction.VRegB(), type); |
| 453 | HInstruction* second = LoadLocal(instruction.VRegC(), type); |
| 454 | current_block_->AddInstruction(new (arena_) T(type, first, second)); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 455 | UpdateLocal(instruction.VRegA(), current_block_->GetLastInstruction()); |
| 456 | } |
| 457 | |
| 458 | template<typename T> |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 459 | void HGraphBuilder::Binop_23x(const Instruction& instruction, |
| 460 | Primitive::Type type, |
| 461 | uint32_t dex_pc) { |
| 462 | HInstruction* first = LoadLocal(instruction.VRegB(), type); |
| 463 | HInstruction* second = LoadLocal(instruction.VRegC(), type); |
| 464 | current_block_->AddInstruction(new (arena_) T(type, first, second, dex_pc)); |
| 465 | UpdateLocal(instruction.VRegA(), current_block_->GetLastInstruction()); |
| 466 | } |
| 467 | |
| 468 | template<typename T> |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 469 | void HGraphBuilder::Binop_23x_shift(const Instruction& instruction, |
| 470 | Primitive::Type type) { |
| 471 | HInstruction* first = LoadLocal(instruction.VRegB(), type); |
| 472 | HInstruction* second = LoadLocal(instruction.VRegC(), Primitive::kPrimInt); |
| 473 | current_block_->AddInstruction(new (arena_) T(type, first, second)); |
| 474 | UpdateLocal(instruction.VRegA(), current_block_->GetLastInstruction()); |
| 475 | } |
| 476 | |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 477 | void HGraphBuilder::Binop_23x_cmp(const Instruction& instruction, |
| 478 | Primitive::Type type, |
| 479 | HCompare::Bias bias) { |
| 480 | HInstruction* first = LoadLocal(instruction.VRegB(), type); |
| 481 | HInstruction* second = LoadLocal(instruction.VRegC(), type); |
| 482 | current_block_->AddInstruction(new (arena_) HCompare(type, first, second, bias)); |
| 483 | UpdateLocal(instruction.VRegA(), current_block_->GetLastInstruction()); |
| 484 | } |
| 485 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 486 | template<typename T> |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 487 | void HGraphBuilder::Binop_12x(const Instruction& instruction, Primitive::Type type) { |
| 488 | HInstruction* first = LoadLocal(instruction.VRegA(), type); |
| 489 | HInstruction* second = LoadLocal(instruction.VRegB(), type); |
| 490 | current_block_->AddInstruction(new (arena_) T(type, first, second)); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 491 | UpdateLocal(instruction.VRegA(), current_block_->GetLastInstruction()); |
| 492 | } |
| 493 | |
| 494 | template<typename T> |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 495 | void HGraphBuilder::Binop_12x_shift(const Instruction& instruction, Primitive::Type type) { |
| 496 | HInstruction* first = LoadLocal(instruction.VRegA(), type); |
| 497 | HInstruction* second = LoadLocal(instruction.VRegB(), Primitive::kPrimInt); |
| 498 | current_block_->AddInstruction(new (arena_) T(type, first, second)); |
| 499 | UpdateLocal(instruction.VRegA(), current_block_->GetLastInstruction()); |
| 500 | } |
| 501 | |
| 502 | template<typename T> |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 503 | void HGraphBuilder::Binop_12x(const Instruction& instruction, |
| 504 | Primitive::Type type, |
| 505 | uint32_t dex_pc) { |
| 506 | HInstruction* first = LoadLocal(instruction.VRegA(), type); |
| 507 | HInstruction* second = LoadLocal(instruction.VRegB(), type); |
| 508 | current_block_->AddInstruction(new (arena_) T(type, first, second, dex_pc)); |
| 509 | UpdateLocal(instruction.VRegA(), current_block_->GetLastInstruction()); |
| 510 | } |
| 511 | |
| 512 | template<typename T> |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 513 | void HGraphBuilder::Binop_22s(const Instruction& instruction, bool reverse) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 514 | HInstruction* first = LoadLocal(instruction.VRegB(), Primitive::kPrimInt); |
| 515 | HInstruction* second = GetIntConstant(instruction.VRegC_22s()); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 516 | if (reverse) { |
| 517 | std::swap(first, second); |
| 518 | } |
| 519 | current_block_->AddInstruction(new (arena_) T(Primitive::kPrimInt, first, second)); |
| 520 | UpdateLocal(instruction.VRegA(), current_block_->GetLastInstruction()); |
| 521 | } |
| 522 | |
| 523 | template<typename T> |
| 524 | void HGraphBuilder::Binop_22b(const Instruction& instruction, bool reverse) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 525 | HInstruction* first = LoadLocal(instruction.VRegB(), Primitive::kPrimInt); |
| 526 | HInstruction* second = GetIntConstant(instruction.VRegC_22b()); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 527 | if (reverse) { |
| 528 | std::swap(first, second); |
| 529 | } |
| 530 | current_block_->AddInstruction(new (arena_) T(Primitive::kPrimInt, first, second)); |
| 531 | UpdateLocal(instruction.VRegA(), current_block_->GetLastInstruction()); |
| 532 | } |
| 533 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 534 | void HGraphBuilder::BuildReturn(const Instruction& instruction, Primitive::Type type) { |
| 535 | if (type == Primitive::kPrimVoid) { |
| 536 | current_block_->AddInstruction(new (arena_) HReturnVoid()); |
| 537 | } else { |
| 538 | HInstruction* value = LoadLocal(instruction.VRegA(), type); |
| 539 | current_block_->AddInstruction(new (arena_) HReturn(value)); |
| 540 | } |
| 541 | current_block_->AddSuccessor(exit_block_); |
| 542 | current_block_ = nullptr; |
| 543 | } |
| 544 | |
| 545 | bool HGraphBuilder::BuildInvoke(const Instruction& instruction, |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 546 | uint32_t dex_pc, |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 547 | uint32_t method_idx, |
| 548 | uint32_t number_of_vreg_arguments, |
| 549 | bool is_range, |
| 550 | uint32_t* args, |
| 551 | uint32_t register_index) { |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 552 | Instruction::Code opcode = instruction.Opcode(); |
| 553 | InvokeType invoke_type; |
| 554 | switch (opcode) { |
| 555 | case Instruction::INVOKE_STATIC: |
| 556 | case Instruction::INVOKE_STATIC_RANGE: |
| 557 | invoke_type = kStatic; |
| 558 | break; |
| 559 | case Instruction::INVOKE_DIRECT: |
| 560 | case Instruction::INVOKE_DIRECT_RANGE: |
| 561 | invoke_type = kDirect; |
| 562 | break; |
| 563 | case Instruction::INVOKE_VIRTUAL: |
| 564 | case Instruction::INVOKE_VIRTUAL_RANGE: |
| 565 | invoke_type = kVirtual; |
| 566 | break; |
| 567 | case Instruction::INVOKE_INTERFACE: |
| 568 | case Instruction::INVOKE_INTERFACE_RANGE: |
| 569 | invoke_type = kInterface; |
| 570 | break; |
| 571 | case Instruction::INVOKE_SUPER_RANGE: |
| 572 | case Instruction::INVOKE_SUPER: |
| 573 | invoke_type = kSuper; |
| 574 | break; |
| 575 | default: |
| 576 | LOG(FATAL) << "Unexpected invoke op: " << opcode; |
| 577 | return false; |
| 578 | } |
| 579 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 580 | const DexFile::MethodId& method_id = dex_file_->GetMethodId(method_idx); |
| 581 | const DexFile::ProtoId& proto_id = dex_file_->GetProtoId(method_id.proto_idx_); |
| 582 | const char* descriptor = dex_file_->StringDataByIdx(proto_id.shorty_idx_); |
| 583 | Primitive::Type return_type = Primitive::GetType(descriptor[0]); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 584 | bool is_instance_call = invoke_type != kStatic; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 585 | const size_t number_of_arguments = strlen(descriptor) - (is_instance_call ? 0 : 1); |
| 586 | |
Calin Juravle | c7c8fe2 | 2014-12-02 11:42:34 +0000 | [diff] [blame] | 587 | MethodReference target_method(dex_file_, method_idx); |
| 588 | uintptr_t direct_code; |
| 589 | uintptr_t direct_method; |
| 590 | int table_index; |
| 591 | InvokeType optimized_invoke_type = invoke_type; |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 592 | |
Calin Juravle | c7c8fe2 | 2014-12-02 11:42:34 +0000 | [diff] [blame] | 593 | if (!compiler_driver_->ComputeInvokeInfo(dex_compilation_unit_, dex_pc, true, true, |
| 594 | &optimized_invoke_type, &target_method, &table_index, |
| 595 | &direct_code, &direct_method)) { |
| 596 | LOG(INFO) << "Did not compile " << PrettyMethod(method_idx, *dex_file_) |
| 597 | << " because a method call could not be resolved"; |
| 598 | return false; |
| 599 | } |
| 600 | DCHECK(optimized_invoke_type != kSuper); |
| 601 | |
| 602 | HInvoke* invoke = nullptr; |
| 603 | if (optimized_invoke_type == kVirtual) { |
| 604 | invoke = new (arena_) HInvokeVirtual( |
| 605 | arena_, number_of_arguments, return_type, dex_pc, table_index); |
| 606 | } else if (optimized_invoke_type == kInterface) { |
| 607 | invoke = new (arena_) HInvokeInterface( |
| 608 | arena_, number_of_arguments, return_type, dex_pc, method_idx, table_index); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 609 | } else { |
Calin Juravle | c7c8fe2 | 2014-12-02 11:42:34 +0000 | [diff] [blame] | 610 | DCHECK(optimized_invoke_type == kDirect || optimized_invoke_type == kStatic); |
| 611 | // Sharpening to kDirect only works if we compile PIC. |
| 612 | DCHECK((optimized_invoke_type == invoke_type) || (optimized_invoke_type != kDirect) |
| 613 | || compiler_driver_->GetCompilerOptions().GetCompilePic()); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 614 | // Treat invoke-direct like static calls for now. |
| 615 | invoke = new (arena_) HInvokeStatic( |
Calin Juravle | c7c8fe2 | 2014-12-02 11:42:34 +0000 | [diff] [blame] | 616 | arena_, number_of_arguments, return_type, dex_pc, target_method.dex_method_index); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 617 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 618 | |
| 619 | size_t start_index = 0; |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 620 | Temporaries temps(graph_); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 621 | if (is_instance_call) { |
| 622 | HInstruction* arg = LoadLocal(is_range ? register_index : args[0], Primitive::kPrimNot); |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 623 | HNullCheck* null_check = new (arena_) HNullCheck(arg, dex_pc); |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 624 | current_block_->AddInstruction(null_check); |
| 625 | temps.Add(null_check); |
| 626 | invoke->SetArgumentAt(0, null_check); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 627 | start_index = 1; |
| 628 | } |
| 629 | |
| 630 | uint32_t descriptor_index = 1; |
| 631 | uint32_t argument_index = start_index; |
| 632 | for (size_t i = start_index; i < number_of_vreg_arguments; i++, argument_index++) { |
| 633 | Primitive::Type type = Primitive::GetType(descriptor[descriptor_index++]); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 634 | bool is_wide = (type == Primitive::kPrimLong) || (type == Primitive::kPrimDouble); |
| 635 | if (!is_range && is_wide && args[i] + 1 != args[i + 1]) { |
Nicolas Geoffray | abed4d0 | 2014-07-14 15:24:11 +0100 | [diff] [blame] | 636 | LOG(WARNING) << "Non sequential register pair in " << dex_compilation_unit_->GetSymbol() |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 637 | << " at " << dex_pc; |
Nicolas Geoffray | abed4d0 | 2014-07-14 15:24:11 +0100 | [diff] [blame] | 638 | // We do not implement non sequential register pair. |
| 639 | return false; |
| 640 | } |
| 641 | HInstruction* arg = LoadLocal(is_range ? register_index + i : args[i], type); |
| 642 | invoke->SetArgumentAt(argument_index, arg); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 643 | if (is_wide) { |
Nicolas Geoffray | abed4d0 | 2014-07-14 15:24:11 +0100 | [diff] [blame] | 644 | i++; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 645 | } |
| 646 | } |
| 647 | |
| 648 | DCHECK_EQ(argument_index, number_of_arguments); |
| 649 | current_block_->AddInstruction(invoke); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 650 | latest_result_ = invoke; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 651 | return true; |
| 652 | } |
| 653 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 654 | bool HGraphBuilder::BuildInstanceFieldAccess(const Instruction& instruction, |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 655 | uint32_t dex_pc, |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 656 | bool is_put) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 657 | uint32_t source_or_dest_reg = instruction.VRegA_22c(); |
| 658 | uint32_t obj_reg = instruction.VRegB_22c(); |
| 659 | uint16_t field_index = instruction.VRegC_22c(); |
| 660 | |
| 661 | ScopedObjectAccess soa(Thread::Current()); |
| 662 | StackHandleScope<1> hs(soa.Self()); |
| 663 | Handle<mirror::ArtField> resolved_field(hs.NewHandle( |
| 664 | compiler_driver_->ComputeInstanceFieldInfo(field_index, dex_compilation_unit_, is_put, soa))); |
| 665 | |
| 666 | if (resolved_field.Get() == nullptr) { |
| 667 | return false; |
| 668 | } |
| 669 | if (resolved_field->IsVolatile()) { |
| 670 | return false; |
| 671 | } |
| 672 | |
Nicolas Geoffray | abed4d0 | 2014-07-14 15:24:11 +0100 | [diff] [blame] | 673 | Primitive::Type field_type = resolved_field->GetTypeAsPrimitiveType(); |
Nicolas Geoffray | abed4d0 | 2014-07-14 15:24:11 +0100 | [diff] [blame] | 674 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 675 | HInstruction* object = LoadLocal(obj_reg, Primitive::kPrimNot); |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 676 | current_block_->AddInstruction(new (arena_) HNullCheck(object, dex_pc)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 677 | if (is_put) { |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 678 | Temporaries temps(graph_); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 679 | HInstruction* null_check = current_block_->GetLastInstruction(); |
| 680 | // We need one temporary for the null check. |
| 681 | temps.Add(null_check); |
Nicolas Geoffray | abed4d0 | 2014-07-14 15:24:11 +0100 | [diff] [blame] | 682 | HInstruction* value = LoadLocal(source_or_dest_reg, field_type); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 683 | current_block_->AddInstruction(new (arena_) HInstanceFieldSet( |
| 684 | null_check, |
| 685 | value, |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 686 | field_type, |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 687 | resolved_field->GetOffset())); |
| 688 | } else { |
| 689 | current_block_->AddInstruction(new (arena_) HInstanceFieldGet( |
| 690 | current_block_->GetLastInstruction(), |
Nicolas Geoffray | abed4d0 | 2014-07-14 15:24:11 +0100 | [diff] [blame] | 691 | field_type, |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 692 | resolved_field->GetOffset())); |
| 693 | |
| 694 | UpdateLocal(source_or_dest_reg, current_block_->GetLastInstruction()); |
| 695 | } |
| 696 | return true; |
| 697 | } |
| 698 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 699 | |
| 700 | |
| 701 | bool HGraphBuilder::BuildStaticFieldAccess(const Instruction& instruction, |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 702 | uint32_t dex_pc, |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 703 | bool is_put) { |
| 704 | uint32_t source_or_dest_reg = instruction.VRegA_21c(); |
| 705 | uint16_t field_index = instruction.VRegB_21c(); |
| 706 | |
| 707 | uint32_t storage_index; |
| 708 | bool is_referrers_class; |
| 709 | bool is_initialized; |
| 710 | bool is_volatile; |
| 711 | MemberOffset field_offset(0u); |
| 712 | Primitive::Type field_type; |
| 713 | |
| 714 | bool fast_path = compiler_driver_->ComputeStaticFieldInfo(field_index, |
| 715 | dex_compilation_unit_, |
| 716 | is_put, |
| 717 | &field_offset, |
| 718 | &storage_index, |
| 719 | &is_referrers_class, |
| 720 | &is_volatile, |
| 721 | &is_initialized, |
| 722 | &field_type); |
| 723 | if (!fast_path) { |
| 724 | return false; |
| 725 | } |
| 726 | |
| 727 | if (is_volatile) { |
| 728 | return false; |
| 729 | } |
| 730 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 731 | HLoadClass* constant = new (arena_) HLoadClass( |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 732 | storage_index, is_referrers_class, dex_pc); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 733 | current_block_->AddInstruction(constant); |
| 734 | |
| 735 | HInstruction* cls = constant; |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 736 | if (!is_initialized) { |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 737 | cls = new (arena_) HClinitCheck(constant, dex_pc); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 738 | current_block_->AddInstruction(cls); |
| 739 | } |
| 740 | |
| 741 | if (is_put) { |
| 742 | // We need to keep the class alive before loading the value. |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 743 | Temporaries temps(graph_); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 744 | temps.Add(cls); |
| 745 | HInstruction* value = LoadLocal(source_or_dest_reg, field_type); |
| 746 | DCHECK_EQ(value->GetType(), field_type); |
| 747 | current_block_->AddInstruction( |
| 748 | new (arena_) HStaticFieldSet(cls, value, field_type, field_offset)); |
| 749 | } else { |
| 750 | current_block_->AddInstruction(new (arena_) HStaticFieldGet(cls, field_type, field_offset)); |
| 751 | UpdateLocal(source_or_dest_reg, current_block_->GetLastInstruction()); |
| 752 | } |
| 753 | return true; |
| 754 | } |
| 755 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 756 | void HGraphBuilder::BuildCheckedDivRem(uint16_t out_vreg, |
| 757 | uint16_t first_vreg, |
| 758 | int64_t second_vreg_or_constant, |
| 759 | uint32_t dex_pc, |
| 760 | Primitive::Type type, |
| 761 | bool second_is_constant, |
| 762 | bool isDiv) { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 763 | DCHECK(type == Primitive::kPrimInt || type == Primitive::kPrimLong); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 764 | |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 765 | HInstruction* first = LoadLocal(first_vreg, type); |
| 766 | HInstruction* second = nullptr; |
| 767 | if (second_is_constant) { |
| 768 | if (type == Primitive::kPrimInt) { |
| 769 | second = GetIntConstant(second_vreg_or_constant); |
| 770 | } else { |
| 771 | second = GetLongConstant(second_vreg_or_constant); |
| 772 | } |
| 773 | } else { |
| 774 | second = LoadLocal(second_vreg_or_constant, type); |
| 775 | } |
| 776 | |
| 777 | if (!second_is_constant |
| 778 | || (type == Primitive::kPrimInt && second->AsIntConstant()->GetValue() == 0) |
| 779 | || (type == Primitive::kPrimLong && second->AsLongConstant()->GetValue() == 0)) { |
| 780 | second = new (arena_) HDivZeroCheck(second, dex_pc); |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 781 | Temporaries temps(graph_); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 782 | current_block_->AddInstruction(second); |
| 783 | temps.Add(current_block_->GetLastInstruction()); |
| 784 | } |
| 785 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 786 | if (isDiv) { |
| 787 | current_block_->AddInstruction(new (arena_) HDiv(type, first, second, dex_pc)); |
| 788 | } else { |
| 789 | current_block_->AddInstruction(new (arena_) HRem(type, first, second, dex_pc)); |
| 790 | } |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 791 | UpdateLocal(out_vreg, current_block_->GetLastInstruction()); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 792 | } |
| 793 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 794 | void HGraphBuilder::BuildArrayAccess(const Instruction& instruction, |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 795 | uint32_t dex_pc, |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 796 | bool is_put, |
| 797 | Primitive::Type anticipated_type) { |
| 798 | uint8_t source_or_dest_reg = instruction.VRegA_23x(); |
| 799 | uint8_t array_reg = instruction.VRegB_23x(); |
| 800 | uint8_t index_reg = instruction.VRegC_23x(); |
| 801 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 802 | // We need one temporary for the null check, one for the index, and one for the length. |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 803 | Temporaries temps(graph_); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 804 | |
| 805 | HInstruction* object = LoadLocal(array_reg, Primitive::kPrimNot); |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 806 | object = new (arena_) HNullCheck(object, dex_pc); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 807 | current_block_->AddInstruction(object); |
| 808 | temps.Add(object); |
| 809 | |
| 810 | HInstruction* length = new (arena_) HArrayLength(object); |
| 811 | current_block_->AddInstruction(length); |
| 812 | temps.Add(length); |
| 813 | HInstruction* index = LoadLocal(index_reg, Primitive::kPrimInt); |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 814 | index = new (arena_) HBoundsCheck(index, length, dex_pc); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 815 | current_block_->AddInstruction(index); |
| 816 | temps.Add(index); |
| 817 | if (is_put) { |
| 818 | HInstruction* value = LoadLocal(source_or_dest_reg, anticipated_type); |
| 819 | // TODO: Insert a type check node if the type is Object. |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 820 | current_block_->AddInstruction(new (arena_) HArraySet( |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 821 | object, index, value, anticipated_type, dex_pc)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 822 | } else { |
| 823 | current_block_->AddInstruction(new (arena_) HArrayGet(object, index, anticipated_type)); |
| 824 | UpdateLocal(source_or_dest_reg, current_block_->GetLastInstruction()); |
| 825 | } |
| 826 | } |
| 827 | |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 828 | void HGraphBuilder::BuildFilledNewArray(uint32_t dex_pc, |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 829 | uint32_t type_index, |
| 830 | uint32_t number_of_vreg_arguments, |
| 831 | bool is_range, |
| 832 | uint32_t* args, |
| 833 | uint32_t register_index) { |
| 834 | HInstruction* length = GetIntConstant(number_of_vreg_arguments); |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 835 | HInstruction* object = new (arena_) HNewArray(length, dex_pc, type_index); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 836 | current_block_->AddInstruction(object); |
| 837 | |
| 838 | const char* descriptor = dex_file_->StringByTypeIdx(type_index); |
| 839 | DCHECK_EQ(descriptor[0], '[') << descriptor; |
| 840 | char primitive = descriptor[1]; |
| 841 | DCHECK(primitive == 'I' |
| 842 | || primitive == 'L' |
| 843 | || primitive == '[') << descriptor; |
| 844 | bool is_reference_array = (primitive == 'L') || (primitive == '['); |
| 845 | Primitive::Type type = is_reference_array ? Primitive::kPrimNot : Primitive::kPrimInt; |
| 846 | |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 847 | Temporaries temps(graph_); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 848 | temps.Add(object); |
| 849 | for (size_t i = 0; i < number_of_vreg_arguments; ++i) { |
| 850 | HInstruction* value = LoadLocal(is_range ? register_index + i : args[i], type); |
| 851 | HInstruction* index = GetIntConstant(i); |
| 852 | current_block_->AddInstruction( |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 853 | new (arena_) HArraySet(object, index, value, type, dex_pc)); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 854 | } |
| 855 | latest_result_ = object; |
| 856 | } |
| 857 | |
| 858 | template <typename T> |
| 859 | void HGraphBuilder::BuildFillArrayData(HInstruction* object, |
| 860 | const T* data, |
| 861 | uint32_t element_count, |
| 862 | Primitive::Type anticipated_type, |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 863 | uint32_t dex_pc) { |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 864 | for (uint32_t i = 0; i < element_count; ++i) { |
| 865 | HInstruction* index = GetIntConstant(i); |
| 866 | HInstruction* value = GetIntConstant(data[i]); |
| 867 | current_block_->AddInstruction(new (arena_) HArraySet( |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 868 | object, index, value, anticipated_type, dex_pc)); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 869 | } |
| 870 | } |
| 871 | |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 872 | void HGraphBuilder::BuildFillArrayData(const Instruction& instruction, uint32_t dex_pc) { |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 873 | Temporaries temps(graph_); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 874 | HInstruction* array = LoadLocal(instruction.VRegA_31t(), Primitive::kPrimNot); |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 875 | HNullCheck* null_check = new (arena_) HNullCheck(array, dex_pc); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 876 | current_block_->AddInstruction(null_check); |
| 877 | temps.Add(null_check); |
| 878 | |
| 879 | HInstruction* length = new (arena_) HArrayLength(null_check); |
| 880 | current_block_->AddInstruction(length); |
| 881 | |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 882 | int32_t payload_offset = instruction.VRegB_31t() + dex_pc; |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 883 | const Instruction::ArrayDataPayload* payload = |
| 884 | reinterpret_cast<const Instruction::ArrayDataPayload*>(code_start_ + payload_offset); |
| 885 | const uint8_t* data = payload->data; |
| 886 | uint32_t element_count = payload->element_count; |
| 887 | |
| 888 | // Implementation of this DEX instruction seems to be that the bounds check is |
| 889 | // done before doing any stores. |
| 890 | HInstruction* last_index = GetIntConstant(payload->element_count - 1); |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 891 | current_block_->AddInstruction(new (arena_) HBoundsCheck(last_index, length, dex_pc)); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 892 | |
| 893 | switch (payload->element_width) { |
| 894 | case 1: |
| 895 | BuildFillArrayData(null_check, |
| 896 | reinterpret_cast<const int8_t*>(data), |
| 897 | element_count, |
| 898 | Primitive::kPrimByte, |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 899 | dex_pc); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 900 | break; |
| 901 | case 2: |
| 902 | BuildFillArrayData(null_check, |
| 903 | reinterpret_cast<const int16_t*>(data), |
| 904 | element_count, |
| 905 | Primitive::kPrimShort, |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 906 | dex_pc); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 907 | break; |
| 908 | case 4: |
| 909 | BuildFillArrayData(null_check, |
| 910 | reinterpret_cast<const int32_t*>(data), |
| 911 | element_count, |
| 912 | Primitive::kPrimInt, |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 913 | dex_pc); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 914 | break; |
| 915 | case 8: |
| 916 | BuildFillWideArrayData(null_check, |
| 917 | reinterpret_cast<const int64_t*>(data), |
| 918 | element_count, |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 919 | dex_pc); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 920 | break; |
| 921 | default: |
| 922 | LOG(FATAL) << "Unknown element width for " << payload->element_width; |
| 923 | } |
| 924 | } |
| 925 | |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 926 | void HGraphBuilder::BuildFillWideArrayData(HInstruction* object, |
Nicolas Geoffray | 8d6ae52 | 2014-10-23 18:32:13 +0100 | [diff] [blame] | 927 | const int64_t* data, |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 928 | uint32_t element_count, |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 929 | uint32_t dex_pc) { |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 930 | for (uint32_t i = 0; i < element_count; ++i) { |
| 931 | HInstruction* index = GetIntConstant(i); |
| 932 | HInstruction* value = GetLongConstant(data[i]); |
| 933 | current_block_->AddInstruction(new (arena_) HArraySet( |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 934 | object, index, value, Primitive::kPrimLong, dex_pc)); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 935 | } |
| 936 | } |
| 937 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 938 | bool HGraphBuilder::BuildTypeCheck(const Instruction& instruction, |
| 939 | uint8_t destination, |
| 940 | uint8_t reference, |
| 941 | uint16_t type_index, |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 942 | uint32_t dex_pc) { |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 943 | bool type_known_final; |
| 944 | bool type_known_abstract; |
| 945 | bool is_referrers_class; |
| 946 | bool can_access = compiler_driver_->CanAccessTypeWithoutChecks( |
| 947 | dex_compilation_unit_->GetDexMethodIndex(), *dex_file_, type_index, |
| 948 | &type_known_final, &type_known_abstract, &is_referrers_class); |
| 949 | if (!can_access) { |
| 950 | return false; |
| 951 | } |
| 952 | HInstruction* object = LoadLocal(reference, Primitive::kPrimNot); |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 953 | HLoadClass* cls = new (arena_) HLoadClass(type_index, is_referrers_class, dex_pc); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 954 | current_block_->AddInstruction(cls); |
| 955 | // The class needs a temporary before being used by the type check. |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 956 | Temporaries temps(graph_); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 957 | temps.Add(cls); |
| 958 | if (instruction.Opcode() == Instruction::INSTANCE_OF) { |
| 959 | current_block_->AddInstruction( |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 960 | new (arena_) HInstanceOf(object, cls, type_known_final, dex_pc)); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 961 | UpdateLocal(destination, current_block_->GetLastInstruction()); |
| 962 | } else { |
| 963 | DCHECK_EQ(instruction.Opcode(), Instruction::CHECK_CAST); |
| 964 | current_block_->AddInstruction( |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 965 | new (arena_) HCheckCast(object, cls, type_known_final, dex_pc)); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 966 | } |
| 967 | return true; |
| 968 | } |
| 969 | |
Andreas Gampe | d881df5 | 2014-11-24 23:28:39 -0800 | [diff] [blame] | 970 | bool HGraphBuilder::BuildPackedSwitch(const Instruction& instruction, uint32_t dex_pc) { |
| 971 | SwitchTable table(instruction, dex_pc, false); |
| 972 | |
| 973 | // Value to test against. |
| 974 | HInstruction* value = LoadLocal(instruction.VRegA(), Primitive::kPrimInt); |
| 975 | |
Andreas Gampe | e4d4d32 | 2014-12-04 09:09:57 -0800 | [diff] [blame] | 976 | uint16_t num_entries = table.GetNumEntries(); |
| 977 | // There should be at least one entry here. |
| 978 | DCHECK_GT(num_entries, 0U); |
| 979 | |
Andreas Gampe | d881df5 | 2014-11-24 23:28:39 -0800 | [diff] [blame] | 980 | // Chained cmp-and-branch, starting from starting_key. |
| 981 | int32_t starting_key = table.GetEntryAt(0); |
| 982 | |
Andreas Gampe | d881df5 | 2014-11-24 23:28:39 -0800 | [diff] [blame] | 983 | for (size_t i = 1; i <= num_entries; i++) { |
Andreas Gampe | e4d4d32 | 2014-12-04 09:09:57 -0800 | [diff] [blame] | 984 | BuildSwitchCaseHelper(instruction, i, i == num_entries, table, value, starting_key + i - 1, |
| 985 | table.GetEntryAt(i), dex_pc); |
Andreas Gampe | d881df5 | 2014-11-24 23:28:39 -0800 | [diff] [blame] | 986 | } |
| 987 | return true; |
| 988 | } |
| 989 | |
Andreas Gampe | e4d4d32 | 2014-12-04 09:09:57 -0800 | [diff] [blame] | 990 | bool HGraphBuilder::BuildSparseSwitch(const Instruction& instruction, uint32_t dex_pc) { |
| 991 | SwitchTable table(instruction, dex_pc, true); |
| 992 | |
| 993 | // Value to test against. |
| 994 | HInstruction* value = LoadLocal(instruction.VRegA(), Primitive::kPrimInt); |
| 995 | |
| 996 | uint16_t num_entries = table.GetNumEntries(); |
| 997 | // There should be at least one entry here. |
| 998 | DCHECK_GT(num_entries, 0U); |
| 999 | |
| 1000 | for (size_t i = 0; i < num_entries; i++) { |
| 1001 | BuildSwitchCaseHelper(instruction, i, i == static_cast<size_t>(num_entries) - 1, table, value, |
| 1002 | table.GetEntryAt(i), table.GetEntryAt(i + num_entries), dex_pc); |
| 1003 | } |
| 1004 | return true; |
| 1005 | } |
| 1006 | |
| 1007 | void HGraphBuilder::BuildSwitchCaseHelper(const Instruction& instruction, size_t index, |
| 1008 | bool is_last_case, const SwitchTable& table, |
| 1009 | HInstruction* value, int32_t case_value_int, |
| 1010 | int32_t target_offset, uint32_t dex_pc) { |
| 1011 | PotentiallyAddSuspendCheck(target_offset, dex_pc); |
| 1012 | |
| 1013 | // The current case's value. |
| 1014 | HInstruction* this_case_value = GetIntConstant(case_value_int); |
| 1015 | |
| 1016 | // Compare value and this_case_value. |
| 1017 | HEqual* comparison = new (arena_) HEqual(value, this_case_value); |
| 1018 | current_block_->AddInstruction(comparison); |
| 1019 | HInstruction* ifinst = new (arena_) HIf(comparison); |
| 1020 | current_block_->AddInstruction(ifinst); |
| 1021 | |
| 1022 | // Case hit: use the target offset to determine where to go. |
| 1023 | HBasicBlock* case_target = FindBlockStartingAt(dex_pc + target_offset); |
| 1024 | DCHECK(case_target != nullptr); |
| 1025 | current_block_->AddSuccessor(case_target); |
| 1026 | |
| 1027 | // Case miss: go to the next case (or default fall-through). |
| 1028 | // When there is a next case, we use the block stored with the table offset representing this |
| 1029 | // case (that is where we registered them in ComputeBranchTargets). |
| 1030 | // When there is no next case, we use the following instruction. |
| 1031 | // TODO: Find a good way to peel the last iteration to avoid conditional, but still have re-use. |
| 1032 | if (!is_last_case) { |
| 1033 | HBasicBlock* next_case_target = FindBlockStartingAt(table.GetDexPcForIndex(index)); |
| 1034 | DCHECK(next_case_target != nullptr); |
| 1035 | current_block_->AddSuccessor(next_case_target); |
| 1036 | |
| 1037 | // Need to manually add the block, as there is no dex-pc transition for the cases. |
| 1038 | graph_->AddBlock(next_case_target); |
| 1039 | |
| 1040 | current_block_ = next_case_target; |
| 1041 | } else { |
| 1042 | HBasicBlock* default_target = FindBlockStartingAt(dex_pc + instruction.SizeInCodeUnits()); |
| 1043 | DCHECK(default_target != nullptr); |
| 1044 | current_block_->AddSuccessor(default_target); |
| 1045 | current_block_ = nullptr; |
| 1046 | } |
| 1047 | } |
| 1048 | |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1049 | void HGraphBuilder::PotentiallyAddSuspendCheck(int32_t target_offset, uint32_t dex_pc) { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 1050 | if (target_offset <= 0) { |
| 1051 | // Unconditionnally add a suspend check to backward branches. We can remove |
| 1052 | // them after we recognize loops in the graph. |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1053 | current_block_->AddInstruction(new (arena_) HSuspendCheck(dex_pc)); |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 1054 | } |
| 1055 | } |
| 1056 | |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1057 | bool HGraphBuilder::AnalyzeDexInstruction(const Instruction& instruction, uint32_t dex_pc) { |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1058 | if (current_block_ == nullptr) { |
| 1059 | return true; // Dead code |
| 1060 | } |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 1061 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1062 | switch (instruction.Opcode()) { |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1063 | case Instruction::CONST_4: { |
| 1064 | int32_t register_index = instruction.VRegA(); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1065 | HIntConstant* constant = GetIntConstant(instruction.VRegB_11n()); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1066 | UpdateLocal(register_index, constant); |
| 1067 | break; |
| 1068 | } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1069 | |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 1070 | case Instruction::CONST_16: { |
| 1071 | int32_t register_index = instruction.VRegA(); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1072 | HIntConstant* constant = GetIntConstant(instruction.VRegB_21s()); |
| 1073 | UpdateLocal(register_index, constant); |
| 1074 | break; |
| 1075 | } |
| 1076 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1077 | case Instruction::CONST: { |
| 1078 | int32_t register_index = instruction.VRegA(); |
| 1079 | HIntConstant* constant = GetIntConstant(instruction.VRegB_31i()); |
| 1080 | UpdateLocal(register_index, constant); |
| 1081 | break; |
| 1082 | } |
| 1083 | |
| 1084 | case Instruction::CONST_HIGH16: { |
| 1085 | int32_t register_index = instruction.VRegA(); |
| 1086 | HIntConstant* constant = GetIntConstant(instruction.VRegB_21h() << 16); |
| 1087 | UpdateLocal(register_index, constant); |
| 1088 | break; |
| 1089 | } |
| 1090 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1091 | case Instruction::CONST_WIDE_16: { |
| 1092 | int32_t register_index = instruction.VRegA(); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1093 | // Get 16 bits of constant value, sign extended to 64 bits. |
| 1094 | int64_t value = instruction.VRegB_21s(); |
| 1095 | value <<= 48; |
| 1096 | value >>= 48; |
| 1097 | HLongConstant* constant = GetLongConstant(value); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1098 | UpdateLocal(register_index, constant); |
| 1099 | break; |
| 1100 | } |
| 1101 | |
| 1102 | case Instruction::CONST_WIDE_32: { |
| 1103 | int32_t register_index = instruction.VRegA(); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1104 | // Get 32 bits of constant value, sign extended to 64 bits. |
| 1105 | int64_t value = instruction.VRegB_31i(); |
| 1106 | value <<= 32; |
| 1107 | value >>= 32; |
| 1108 | HLongConstant* constant = GetLongConstant(value); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1109 | UpdateLocal(register_index, constant); |
| 1110 | break; |
| 1111 | } |
| 1112 | |
| 1113 | case Instruction::CONST_WIDE: { |
| 1114 | int32_t register_index = instruction.VRegA(); |
| 1115 | HLongConstant* constant = GetLongConstant(instruction.VRegB_51l()); |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 1116 | UpdateLocal(register_index, constant); |
| 1117 | break; |
| 1118 | } |
| 1119 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1120 | case Instruction::CONST_WIDE_HIGH16: { |
| 1121 | int32_t register_index = instruction.VRegA(); |
| 1122 | int64_t value = static_cast<int64_t>(instruction.VRegB_21h()) << 48; |
| 1123 | HLongConstant* constant = GetLongConstant(value); |
| 1124 | UpdateLocal(register_index, constant); |
| 1125 | break; |
| 1126 | } |
| 1127 | |
Nicolas Geoffray | dadf317 | 2014-11-07 16:36:02 +0000 | [diff] [blame] | 1128 | // Note that the SSA building will refine the types. |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1129 | case Instruction::MOVE: |
| 1130 | case Instruction::MOVE_FROM16: |
| 1131 | case Instruction::MOVE_16: { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1132 | HInstruction* value = LoadLocal(instruction.VRegB(), Primitive::kPrimInt); |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 1133 | UpdateLocal(instruction.VRegA(), value); |
| 1134 | break; |
| 1135 | } |
| 1136 | |
Nicolas Geoffray | dadf317 | 2014-11-07 16:36:02 +0000 | [diff] [blame] | 1137 | // Note that the SSA building will refine the types. |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1138 | case Instruction::MOVE_WIDE: |
| 1139 | case Instruction::MOVE_WIDE_FROM16: |
| 1140 | case Instruction::MOVE_WIDE_16: { |
| 1141 | HInstruction* value = LoadLocal(instruction.VRegB(), Primitive::kPrimLong); |
| 1142 | UpdateLocal(instruction.VRegA(), value); |
| 1143 | break; |
| 1144 | } |
| 1145 | |
| 1146 | case Instruction::MOVE_OBJECT: |
| 1147 | case Instruction::MOVE_OBJECT_16: |
| 1148 | case Instruction::MOVE_OBJECT_FROM16: { |
| 1149 | HInstruction* value = LoadLocal(instruction.VRegB(), Primitive::kPrimNot); |
| 1150 | UpdateLocal(instruction.VRegA(), value); |
| 1151 | break; |
| 1152 | } |
| 1153 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1154 | case Instruction::RETURN_VOID: { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1155 | BuildReturn(instruction, Primitive::kPrimVoid); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1156 | break; |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1157 | } |
| 1158 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1159 | #define IF_XX(comparison, cond) \ |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1160 | case Instruction::IF_##cond: If_22t<comparison>(instruction, dex_pc); break; \ |
| 1161 | case Instruction::IF_##cond##Z: If_21t<comparison>(instruction, dex_pc); break |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 1162 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1163 | IF_XX(HEqual, EQ); |
| 1164 | IF_XX(HNotEqual, NE); |
| 1165 | IF_XX(HLessThan, LT); |
| 1166 | IF_XX(HLessThanOrEqual, LE); |
| 1167 | IF_XX(HGreaterThan, GT); |
| 1168 | IF_XX(HGreaterThanOrEqual, GE); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1169 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 1170 | case Instruction::GOTO: |
| 1171 | case Instruction::GOTO_16: |
| 1172 | case Instruction::GOTO_32: { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 1173 | int32_t offset = instruction.GetTargetOffset(); |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1174 | PotentiallyAddSuspendCheck(offset, dex_pc); |
| 1175 | HBasicBlock* target = FindBlockStartingAt(offset + dex_pc); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 1176 | DCHECK(target != nullptr); |
| 1177 | current_block_->AddInstruction(new (arena_) HGoto()); |
| 1178 | current_block_->AddSuccessor(target); |
| 1179 | current_block_ = nullptr; |
| 1180 | break; |
| 1181 | } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1182 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1183 | case Instruction::RETURN: { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1184 | DCHECK_NE(return_type_, Primitive::kPrimNot); |
| 1185 | DCHECK_NE(return_type_, Primitive::kPrimLong); |
| 1186 | DCHECK_NE(return_type_, Primitive::kPrimDouble); |
| 1187 | BuildReturn(instruction, return_type_); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1188 | break; |
| 1189 | } |
| 1190 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 1191 | case Instruction::RETURN_OBJECT: { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1192 | DCHECK(return_type_ == Primitive::kPrimNot); |
| 1193 | BuildReturn(instruction, return_type_); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1194 | break; |
| 1195 | } |
| 1196 | |
| 1197 | case Instruction::RETURN_WIDE: { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1198 | DCHECK(return_type_ == Primitive::kPrimDouble || return_type_ == Primitive::kPrimLong); |
| 1199 | BuildReturn(instruction, return_type_); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1200 | break; |
| 1201 | } |
| 1202 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1203 | case Instruction::INVOKE_DIRECT: |
Nicolas Geoffray | 0d8db99 | 2014-11-11 14:40:10 +0000 | [diff] [blame] | 1204 | case Instruction::INVOKE_INTERFACE: |
| 1205 | case Instruction::INVOKE_STATIC: |
| 1206 | case Instruction::INVOKE_SUPER: |
| 1207 | case Instruction::INVOKE_VIRTUAL: { |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 1208 | uint32_t method_idx = instruction.VRegB_35c(); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1209 | uint32_t number_of_vreg_arguments = instruction.VRegA_35c(); |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 1210 | uint32_t args[5]; |
Ian Rogers | 29a2648 | 2014-05-02 15:27:29 -0700 | [diff] [blame] | 1211 | instruction.GetVarArgs(args); |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1212 | if (!BuildInvoke(instruction, dex_pc, method_idx, |
Nicolas Geoffray | dadf317 | 2014-11-07 16:36:02 +0000 | [diff] [blame] | 1213 | number_of_vreg_arguments, false, args, -1)) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1214 | return false; |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 1215 | } |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 1216 | break; |
| 1217 | } |
| 1218 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1219 | case Instruction::INVOKE_DIRECT_RANGE: |
Nicolas Geoffray | 0d8db99 | 2014-11-11 14:40:10 +0000 | [diff] [blame] | 1220 | case Instruction::INVOKE_INTERFACE_RANGE: |
| 1221 | case Instruction::INVOKE_STATIC_RANGE: |
| 1222 | case Instruction::INVOKE_SUPER_RANGE: |
| 1223 | case Instruction::INVOKE_VIRTUAL_RANGE: { |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 1224 | uint32_t method_idx = instruction.VRegB_3rc(); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1225 | uint32_t number_of_vreg_arguments = instruction.VRegA_3rc(); |
| 1226 | uint32_t register_index = instruction.VRegC(); |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1227 | if (!BuildInvoke(instruction, dex_pc, method_idx, |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1228 | number_of_vreg_arguments, true, nullptr, register_index)) { |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 1229 | return false; |
| 1230 | } |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 1231 | break; |
| 1232 | } |
| 1233 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1234 | case Instruction::NEG_INT: { |
| 1235 | Unop_12x<HNeg>(instruction, Primitive::kPrimInt); |
| 1236 | break; |
| 1237 | } |
| 1238 | |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 1239 | case Instruction::NEG_LONG: { |
| 1240 | Unop_12x<HNeg>(instruction, Primitive::kPrimLong); |
| 1241 | break; |
| 1242 | } |
| 1243 | |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 1244 | case Instruction::NEG_FLOAT: { |
| 1245 | Unop_12x<HNeg>(instruction, Primitive::kPrimFloat); |
| 1246 | break; |
| 1247 | } |
| 1248 | |
| 1249 | case Instruction::NEG_DOUBLE: { |
| 1250 | Unop_12x<HNeg>(instruction, Primitive::kPrimDouble); |
| 1251 | break; |
| 1252 | } |
| 1253 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 1254 | case Instruction::NOT_INT: { |
| 1255 | Unop_12x<HNot>(instruction, Primitive::kPrimInt); |
| 1256 | break; |
| 1257 | } |
| 1258 | |
Roland Levillain | 7056643 | 2014-10-24 16:20:17 +0100 | [diff] [blame] | 1259 | case Instruction::NOT_LONG: { |
| 1260 | Unop_12x<HNot>(instruction, Primitive::kPrimLong); |
| 1261 | break; |
| 1262 | } |
| 1263 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1264 | case Instruction::INT_TO_LONG: { |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 1265 | Conversion_12x(instruction, Primitive::kPrimInt, Primitive::kPrimLong, dex_pc); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1266 | break; |
| 1267 | } |
| 1268 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 1269 | case Instruction::INT_TO_FLOAT: { |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 1270 | Conversion_12x(instruction, Primitive::kPrimInt, Primitive::kPrimFloat, dex_pc); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 1271 | break; |
| 1272 | } |
| 1273 | |
| 1274 | case Instruction::INT_TO_DOUBLE: { |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 1275 | Conversion_12x(instruction, Primitive::kPrimInt, Primitive::kPrimDouble, dex_pc); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 1276 | break; |
| 1277 | } |
| 1278 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 1279 | case Instruction::LONG_TO_INT: { |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 1280 | Conversion_12x(instruction, Primitive::kPrimLong, Primitive::kPrimInt, dex_pc); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 1281 | break; |
| 1282 | } |
| 1283 | |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 1284 | case Instruction::LONG_TO_FLOAT: { |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 1285 | Conversion_12x(instruction, Primitive::kPrimLong, Primitive::kPrimFloat, dex_pc); |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 1286 | break; |
| 1287 | } |
| 1288 | |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 1289 | case Instruction::LONG_TO_DOUBLE: { |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 1290 | Conversion_12x(instruction, Primitive::kPrimLong, Primitive::kPrimDouble, dex_pc); |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 1291 | break; |
| 1292 | } |
| 1293 | |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 1294 | case Instruction::FLOAT_TO_INT: { |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 1295 | Conversion_12x(instruction, Primitive::kPrimFloat, Primitive::kPrimInt, dex_pc); |
| 1296 | break; |
| 1297 | } |
| 1298 | |
| 1299 | case Instruction::FLOAT_TO_LONG: { |
| 1300 | Conversion_12x(instruction, Primitive::kPrimFloat, Primitive::kPrimLong, dex_pc); |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 1301 | break; |
| 1302 | } |
| 1303 | |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 1304 | case Instruction::FLOAT_TO_DOUBLE: { |
| 1305 | Conversion_12x(instruction, Primitive::kPrimFloat, Primitive::kPrimDouble, dex_pc); |
| 1306 | break; |
| 1307 | } |
| 1308 | |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 1309 | case Instruction::DOUBLE_TO_INT: { |
| 1310 | Conversion_12x(instruction, Primitive::kPrimDouble, Primitive::kPrimInt, dex_pc); |
| 1311 | break; |
| 1312 | } |
| 1313 | |
| 1314 | case Instruction::DOUBLE_TO_LONG: { |
| 1315 | Conversion_12x(instruction, Primitive::kPrimDouble, Primitive::kPrimLong, dex_pc); |
| 1316 | break; |
| 1317 | } |
| 1318 | |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 1319 | case Instruction::DOUBLE_TO_FLOAT: { |
| 1320 | Conversion_12x(instruction, Primitive::kPrimDouble, Primitive::kPrimFloat, dex_pc); |
| 1321 | break; |
| 1322 | } |
| 1323 | |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 1324 | case Instruction::INT_TO_BYTE: { |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 1325 | Conversion_12x(instruction, Primitive::kPrimInt, Primitive::kPrimByte, dex_pc); |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 1326 | break; |
| 1327 | } |
| 1328 | |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 1329 | case Instruction::INT_TO_SHORT: { |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 1330 | Conversion_12x(instruction, Primitive::kPrimInt, Primitive::kPrimShort, dex_pc); |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 1331 | break; |
| 1332 | } |
| 1333 | |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 1334 | case Instruction::INT_TO_CHAR: { |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 1335 | Conversion_12x(instruction, Primitive::kPrimInt, Primitive::kPrimChar, dex_pc); |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 1336 | break; |
| 1337 | } |
| 1338 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 1339 | case Instruction::ADD_INT: { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1340 | Binop_23x<HAdd>(instruction, Primitive::kPrimInt); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1341 | break; |
| 1342 | } |
| 1343 | |
| 1344 | case Instruction::ADD_LONG: { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1345 | Binop_23x<HAdd>(instruction, Primitive::kPrimLong); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 1346 | break; |
| 1347 | } |
| 1348 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1349 | case Instruction::ADD_DOUBLE: { |
| 1350 | Binop_23x<HAdd>(instruction, Primitive::kPrimDouble); |
| 1351 | break; |
| 1352 | } |
| 1353 | |
| 1354 | case Instruction::ADD_FLOAT: { |
| 1355 | Binop_23x<HAdd>(instruction, Primitive::kPrimFloat); |
| 1356 | break; |
| 1357 | } |
| 1358 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 1359 | case Instruction::SUB_INT: { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1360 | Binop_23x<HSub>(instruction, Primitive::kPrimInt); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1361 | break; |
| 1362 | } |
| 1363 | |
| 1364 | case Instruction::SUB_LONG: { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1365 | Binop_23x<HSub>(instruction, Primitive::kPrimLong); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 1366 | break; |
| 1367 | } |
| 1368 | |
Calin Juravle | 096cc02 | 2014-10-23 17:01:13 +0100 | [diff] [blame] | 1369 | case Instruction::SUB_FLOAT: { |
| 1370 | Binop_23x<HSub>(instruction, Primitive::kPrimFloat); |
| 1371 | break; |
| 1372 | } |
| 1373 | |
| 1374 | case Instruction::SUB_DOUBLE: { |
| 1375 | Binop_23x<HSub>(instruction, Primitive::kPrimDouble); |
| 1376 | break; |
| 1377 | } |
| 1378 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 1379 | case Instruction::ADD_INT_2ADDR: { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1380 | Binop_12x<HAdd>(instruction, Primitive::kPrimInt); |
| 1381 | break; |
| 1382 | } |
| 1383 | |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 1384 | case Instruction::MUL_INT: { |
| 1385 | Binop_23x<HMul>(instruction, Primitive::kPrimInt); |
| 1386 | break; |
| 1387 | } |
| 1388 | |
| 1389 | case Instruction::MUL_LONG: { |
| 1390 | Binop_23x<HMul>(instruction, Primitive::kPrimLong); |
| 1391 | break; |
| 1392 | } |
| 1393 | |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 1394 | case Instruction::MUL_FLOAT: { |
| 1395 | Binop_23x<HMul>(instruction, Primitive::kPrimFloat); |
| 1396 | break; |
| 1397 | } |
| 1398 | |
| 1399 | case Instruction::MUL_DOUBLE: { |
| 1400 | Binop_23x<HMul>(instruction, Primitive::kPrimDouble); |
| 1401 | break; |
| 1402 | } |
| 1403 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 1404 | case Instruction::DIV_INT: { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 1405 | BuildCheckedDivRem(instruction.VRegA(), instruction.VRegB(), instruction.VRegC(), |
| 1406 | dex_pc, Primitive::kPrimInt, false, true); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 1407 | break; |
| 1408 | } |
| 1409 | |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 1410 | case Instruction::DIV_LONG: { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 1411 | BuildCheckedDivRem(instruction.VRegA(), instruction.VRegB(), instruction.VRegC(), |
| 1412 | dex_pc, Primitive::kPrimLong, false, true); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 1413 | break; |
| 1414 | } |
| 1415 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1416 | case Instruction::DIV_FLOAT: { |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1417 | Binop_23x<HDiv>(instruction, Primitive::kPrimFloat, dex_pc); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1418 | break; |
| 1419 | } |
| 1420 | |
| 1421 | case Instruction::DIV_DOUBLE: { |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1422 | Binop_23x<HDiv>(instruction, Primitive::kPrimDouble, dex_pc); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1423 | break; |
| 1424 | } |
| 1425 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 1426 | case Instruction::REM_INT: { |
| 1427 | BuildCheckedDivRem(instruction.VRegA(), instruction.VRegB(), instruction.VRegC(), |
| 1428 | dex_pc, Primitive::kPrimInt, false, false); |
| 1429 | break; |
| 1430 | } |
| 1431 | |
| 1432 | case Instruction::REM_LONG: { |
| 1433 | BuildCheckedDivRem(instruction.VRegA(), instruction.VRegB(), instruction.VRegC(), |
| 1434 | dex_pc, Primitive::kPrimLong, false, false); |
| 1435 | break; |
| 1436 | } |
| 1437 | |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame^] | 1438 | case Instruction::REM_FLOAT: { |
| 1439 | Binop_23x<HRem>(instruction, Primitive::kPrimFloat, dex_pc); |
| 1440 | break; |
| 1441 | } |
| 1442 | |
| 1443 | case Instruction::REM_DOUBLE: { |
| 1444 | Binop_23x<HRem>(instruction, Primitive::kPrimDouble, dex_pc); |
| 1445 | break; |
| 1446 | } |
| 1447 | |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 1448 | case Instruction::AND_INT: { |
| 1449 | Binop_23x<HAnd>(instruction, Primitive::kPrimInt); |
| 1450 | break; |
| 1451 | } |
| 1452 | |
| 1453 | case Instruction::AND_LONG: { |
| 1454 | Binop_23x<HAnd>(instruction, Primitive::kPrimLong); |
| 1455 | break; |
| 1456 | } |
| 1457 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 1458 | case Instruction::SHL_INT: { |
| 1459 | Binop_23x_shift<HShl>(instruction, Primitive::kPrimInt); |
| 1460 | break; |
| 1461 | } |
| 1462 | |
| 1463 | case Instruction::SHL_LONG: { |
| 1464 | Binop_23x_shift<HShl>(instruction, Primitive::kPrimLong); |
| 1465 | break; |
| 1466 | } |
| 1467 | |
| 1468 | case Instruction::SHR_INT: { |
| 1469 | Binop_23x_shift<HShr>(instruction, Primitive::kPrimInt); |
| 1470 | break; |
| 1471 | } |
| 1472 | |
| 1473 | case Instruction::SHR_LONG: { |
| 1474 | Binop_23x_shift<HShr>(instruction, Primitive::kPrimLong); |
| 1475 | break; |
| 1476 | } |
| 1477 | |
| 1478 | case Instruction::USHR_INT: { |
| 1479 | Binop_23x_shift<HUShr>(instruction, Primitive::kPrimInt); |
| 1480 | break; |
| 1481 | } |
| 1482 | |
| 1483 | case Instruction::USHR_LONG: { |
| 1484 | Binop_23x_shift<HUShr>(instruction, Primitive::kPrimLong); |
| 1485 | break; |
| 1486 | } |
| 1487 | |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 1488 | case Instruction::OR_INT: { |
| 1489 | Binop_23x<HOr>(instruction, Primitive::kPrimInt); |
| 1490 | break; |
| 1491 | } |
| 1492 | |
| 1493 | case Instruction::OR_LONG: { |
| 1494 | Binop_23x<HOr>(instruction, Primitive::kPrimLong); |
| 1495 | break; |
| 1496 | } |
| 1497 | |
| 1498 | case Instruction::XOR_INT: { |
| 1499 | Binop_23x<HXor>(instruction, Primitive::kPrimInt); |
| 1500 | break; |
| 1501 | } |
| 1502 | |
| 1503 | case Instruction::XOR_LONG: { |
| 1504 | Binop_23x<HXor>(instruction, Primitive::kPrimLong); |
| 1505 | break; |
| 1506 | } |
| 1507 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1508 | case Instruction::ADD_LONG_2ADDR: { |
| 1509 | Binop_12x<HAdd>(instruction, Primitive::kPrimLong); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 1510 | break; |
| 1511 | } |
| 1512 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1513 | case Instruction::ADD_DOUBLE_2ADDR: { |
| 1514 | Binop_12x<HAdd>(instruction, Primitive::kPrimDouble); |
| 1515 | break; |
| 1516 | } |
| 1517 | |
| 1518 | case Instruction::ADD_FLOAT_2ADDR: { |
| 1519 | Binop_12x<HAdd>(instruction, Primitive::kPrimFloat); |
| 1520 | break; |
| 1521 | } |
| 1522 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 1523 | case Instruction::SUB_INT_2ADDR: { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1524 | Binop_12x<HSub>(instruction, Primitive::kPrimInt); |
| 1525 | break; |
| 1526 | } |
| 1527 | |
| 1528 | case Instruction::SUB_LONG_2ADDR: { |
| 1529 | Binop_12x<HSub>(instruction, Primitive::kPrimLong); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 1530 | break; |
| 1531 | } |
| 1532 | |
Calin Juravle | 096cc02 | 2014-10-23 17:01:13 +0100 | [diff] [blame] | 1533 | case Instruction::SUB_FLOAT_2ADDR: { |
| 1534 | Binop_12x<HSub>(instruction, Primitive::kPrimFloat); |
| 1535 | break; |
| 1536 | } |
| 1537 | |
| 1538 | case Instruction::SUB_DOUBLE_2ADDR: { |
| 1539 | Binop_12x<HSub>(instruction, Primitive::kPrimDouble); |
| 1540 | break; |
| 1541 | } |
| 1542 | |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 1543 | case Instruction::MUL_INT_2ADDR: { |
| 1544 | Binop_12x<HMul>(instruction, Primitive::kPrimInt); |
| 1545 | break; |
| 1546 | } |
| 1547 | |
| 1548 | case Instruction::MUL_LONG_2ADDR: { |
| 1549 | Binop_12x<HMul>(instruction, Primitive::kPrimLong); |
| 1550 | break; |
| 1551 | } |
| 1552 | |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 1553 | case Instruction::MUL_FLOAT_2ADDR: { |
| 1554 | Binop_12x<HMul>(instruction, Primitive::kPrimFloat); |
| 1555 | break; |
| 1556 | } |
| 1557 | |
| 1558 | case Instruction::MUL_DOUBLE_2ADDR: { |
| 1559 | Binop_12x<HMul>(instruction, Primitive::kPrimDouble); |
| 1560 | break; |
| 1561 | } |
| 1562 | |
Calin Juravle | 865fc88 | 2014-11-06 17:09:03 +0000 | [diff] [blame] | 1563 | case Instruction::DIV_INT_2ADDR: { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 1564 | BuildCheckedDivRem(instruction.VRegA(), instruction.VRegA(), instruction.VRegB(), |
| 1565 | dex_pc, Primitive::kPrimInt, false, true); |
Calin Juravle | 865fc88 | 2014-11-06 17:09:03 +0000 | [diff] [blame] | 1566 | break; |
| 1567 | } |
| 1568 | |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 1569 | case Instruction::DIV_LONG_2ADDR: { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 1570 | BuildCheckedDivRem(instruction.VRegA(), instruction.VRegA(), instruction.VRegB(), |
| 1571 | dex_pc, Primitive::kPrimLong, false, true); |
| 1572 | break; |
| 1573 | } |
| 1574 | |
| 1575 | case Instruction::REM_INT_2ADDR: { |
| 1576 | BuildCheckedDivRem(instruction.VRegA(), instruction.VRegA(), instruction.VRegB(), |
| 1577 | dex_pc, Primitive::kPrimInt, false, false); |
| 1578 | break; |
| 1579 | } |
| 1580 | |
| 1581 | case Instruction::REM_LONG_2ADDR: { |
| 1582 | BuildCheckedDivRem(instruction.VRegA(), instruction.VRegA(), instruction.VRegB(), |
| 1583 | dex_pc, Primitive::kPrimLong, false, false); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 1584 | break; |
| 1585 | } |
| 1586 | |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame^] | 1587 | case Instruction::REM_FLOAT_2ADDR: { |
| 1588 | Binop_12x<HRem>(instruction, Primitive::kPrimFloat, dex_pc); |
| 1589 | break; |
| 1590 | } |
| 1591 | |
| 1592 | case Instruction::REM_DOUBLE_2ADDR: { |
| 1593 | Binop_12x<HRem>(instruction, Primitive::kPrimDouble, dex_pc); |
| 1594 | break; |
| 1595 | } |
| 1596 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 1597 | case Instruction::SHL_INT_2ADDR: { |
| 1598 | Binop_12x_shift<HShl>(instruction, Primitive::kPrimInt); |
| 1599 | break; |
| 1600 | } |
| 1601 | |
| 1602 | case Instruction::SHL_LONG_2ADDR: { |
| 1603 | Binop_12x_shift<HShl>(instruction, Primitive::kPrimLong); |
| 1604 | break; |
| 1605 | } |
| 1606 | |
| 1607 | case Instruction::SHR_INT_2ADDR: { |
| 1608 | Binop_12x_shift<HShr>(instruction, Primitive::kPrimInt); |
| 1609 | break; |
| 1610 | } |
| 1611 | |
| 1612 | case Instruction::SHR_LONG_2ADDR: { |
| 1613 | Binop_12x_shift<HShr>(instruction, Primitive::kPrimLong); |
| 1614 | break; |
| 1615 | } |
| 1616 | |
| 1617 | case Instruction::USHR_INT_2ADDR: { |
| 1618 | Binop_12x_shift<HUShr>(instruction, Primitive::kPrimInt); |
| 1619 | break; |
| 1620 | } |
| 1621 | |
| 1622 | case Instruction::USHR_LONG_2ADDR: { |
| 1623 | Binop_12x_shift<HUShr>(instruction, Primitive::kPrimLong); |
| 1624 | break; |
| 1625 | } |
| 1626 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1627 | case Instruction::DIV_FLOAT_2ADDR: { |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1628 | Binop_12x<HDiv>(instruction, Primitive::kPrimFloat, dex_pc); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1629 | break; |
| 1630 | } |
| 1631 | |
| 1632 | case Instruction::DIV_DOUBLE_2ADDR: { |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1633 | Binop_12x<HDiv>(instruction, Primitive::kPrimDouble, dex_pc); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1634 | break; |
| 1635 | } |
| 1636 | |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 1637 | case Instruction::AND_INT_2ADDR: { |
| 1638 | Binop_12x<HAnd>(instruction, Primitive::kPrimInt); |
| 1639 | break; |
| 1640 | } |
| 1641 | |
| 1642 | case Instruction::AND_LONG_2ADDR: { |
| 1643 | Binop_12x<HAnd>(instruction, Primitive::kPrimLong); |
| 1644 | break; |
| 1645 | } |
| 1646 | |
| 1647 | case Instruction::OR_INT_2ADDR: { |
| 1648 | Binop_12x<HOr>(instruction, Primitive::kPrimInt); |
| 1649 | break; |
| 1650 | } |
| 1651 | |
| 1652 | case Instruction::OR_LONG_2ADDR: { |
| 1653 | Binop_12x<HOr>(instruction, Primitive::kPrimLong); |
| 1654 | break; |
| 1655 | } |
| 1656 | |
| 1657 | case Instruction::XOR_INT_2ADDR: { |
| 1658 | Binop_12x<HXor>(instruction, Primitive::kPrimInt); |
| 1659 | break; |
| 1660 | } |
| 1661 | |
| 1662 | case Instruction::XOR_LONG_2ADDR: { |
| 1663 | Binop_12x<HXor>(instruction, Primitive::kPrimLong); |
| 1664 | break; |
| 1665 | } |
| 1666 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 1667 | case Instruction::ADD_INT_LIT16: { |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 1668 | Binop_22s<HAdd>(instruction, false); |
| 1669 | break; |
| 1670 | } |
| 1671 | |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 1672 | case Instruction::AND_INT_LIT16: { |
| 1673 | Binop_22s<HAnd>(instruction, false); |
| 1674 | break; |
| 1675 | } |
| 1676 | |
| 1677 | case Instruction::OR_INT_LIT16: { |
| 1678 | Binop_22s<HOr>(instruction, false); |
| 1679 | break; |
| 1680 | } |
| 1681 | |
| 1682 | case Instruction::XOR_INT_LIT16: { |
| 1683 | Binop_22s<HXor>(instruction, false); |
| 1684 | break; |
| 1685 | } |
| 1686 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 1687 | case Instruction::RSUB_INT: { |
| 1688 | Binop_22s<HSub>(instruction, true); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 1689 | break; |
| 1690 | } |
| 1691 | |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 1692 | case Instruction::MUL_INT_LIT16: { |
| 1693 | Binop_22s<HMul>(instruction, false); |
| 1694 | break; |
| 1695 | } |
| 1696 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 1697 | case Instruction::ADD_INT_LIT8: { |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 1698 | Binop_22b<HAdd>(instruction, false); |
| 1699 | break; |
| 1700 | } |
| 1701 | |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 1702 | case Instruction::AND_INT_LIT8: { |
| 1703 | Binop_22b<HAnd>(instruction, false); |
| 1704 | break; |
| 1705 | } |
| 1706 | |
| 1707 | case Instruction::OR_INT_LIT8: { |
| 1708 | Binop_22b<HOr>(instruction, false); |
| 1709 | break; |
| 1710 | } |
| 1711 | |
| 1712 | case Instruction::XOR_INT_LIT8: { |
| 1713 | Binop_22b<HXor>(instruction, false); |
| 1714 | break; |
| 1715 | } |
| 1716 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 1717 | case Instruction::RSUB_INT_LIT8: { |
| 1718 | Binop_22b<HSub>(instruction, true); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 1719 | break; |
| 1720 | } |
| 1721 | |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 1722 | case Instruction::MUL_INT_LIT8: { |
| 1723 | Binop_22b<HMul>(instruction, false); |
| 1724 | break; |
| 1725 | } |
| 1726 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 1727 | case Instruction::DIV_INT_LIT16: |
| 1728 | case Instruction::DIV_INT_LIT8: { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 1729 | BuildCheckedDivRem(instruction.VRegA(), instruction.VRegB(), instruction.VRegC(), |
| 1730 | dex_pc, Primitive::kPrimInt, true, true); |
| 1731 | break; |
| 1732 | } |
| 1733 | |
| 1734 | case Instruction::REM_INT_LIT16: |
| 1735 | case Instruction::REM_INT_LIT8: { |
| 1736 | BuildCheckedDivRem(instruction.VRegA(), instruction.VRegB(), instruction.VRegC(), |
| 1737 | dex_pc, Primitive::kPrimInt, true, false); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 1738 | break; |
| 1739 | } |
| 1740 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 1741 | case Instruction::SHL_INT_LIT8: { |
| 1742 | Binop_22b<HShl>(instruction, false); |
| 1743 | break; |
| 1744 | } |
| 1745 | |
| 1746 | case Instruction::SHR_INT_LIT8: { |
| 1747 | Binop_22b<HShr>(instruction, false); |
| 1748 | break; |
| 1749 | } |
| 1750 | |
| 1751 | case Instruction::USHR_INT_LIT8: { |
| 1752 | Binop_22b<HUShr>(instruction, false); |
| 1753 | break; |
| 1754 | } |
| 1755 | |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 1756 | case Instruction::NEW_INSTANCE: { |
| 1757 | current_block_->AddInstruction( |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1758 | new (arena_) HNewInstance(dex_pc, instruction.VRegB_21c())); |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 1759 | UpdateLocal(instruction.VRegA(), current_block_->GetLastInstruction()); |
| 1760 | break; |
| 1761 | } |
| 1762 | |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 1763 | case Instruction::NEW_ARRAY: { |
| 1764 | HInstruction* length = LoadLocal(instruction.VRegB_22c(), Primitive::kPrimInt); |
| 1765 | current_block_->AddInstruction( |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1766 | new (arena_) HNewArray(length, dex_pc, instruction.VRegC_22c())); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 1767 | UpdateLocal(instruction.VRegA_22c(), current_block_->GetLastInstruction()); |
| 1768 | break; |
| 1769 | } |
| 1770 | |
| 1771 | case Instruction::FILLED_NEW_ARRAY: { |
| 1772 | uint32_t number_of_vreg_arguments = instruction.VRegA_35c(); |
| 1773 | uint32_t type_index = instruction.VRegB_35c(); |
| 1774 | uint32_t args[5]; |
| 1775 | instruction.GetVarArgs(args); |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1776 | BuildFilledNewArray(dex_pc, type_index, number_of_vreg_arguments, false, args, 0); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 1777 | break; |
| 1778 | } |
| 1779 | |
| 1780 | case Instruction::FILLED_NEW_ARRAY_RANGE: { |
| 1781 | uint32_t number_of_vreg_arguments = instruction.VRegA_3rc(); |
| 1782 | uint32_t type_index = instruction.VRegB_3rc(); |
| 1783 | uint32_t register_index = instruction.VRegC_3rc(); |
| 1784 | BuildFilledNewArray( |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1785 | dex_pc, type_index, number_of_vreg_arguments, true, nullptr, register_index); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 1786 | break; |
| 1787 | } |
| 1788 | |
| 1789 | case Instruction::FILL_ARRAY_DATA: { |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1790 | BuildFillArrayData(instruction, dex_pc); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 1791 | break; |
| 1792 | } |
| 1793 | |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 1794 | case Instruction::MOVE_RESULT: |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1795 | case Instruction::MOVE_RESULT_WIDE: |
| 1796 | case Instruction::MOVE_RESULT_OBJECT: |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 1797 | UpdateLocal(instruction.VRegA(), latest_result_); |
| 1798 | latest_result_ = nullptr; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1799 | break; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1800 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1801 | case Instruction::CMP_LONG: { |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1802 | Binop_23x_cmp(instruction, Primitive::kPrimLong, HCompare::kNoBias); |
| 1803 | break; |
| 1804 | } |
| 1805 | |
| 1806 | case Instruction::CMPG_FLOAT: { |
| 1807 | Binop_23x_cmp(instruction, Primitive::kPrimFloat, HCompare::kGtBias); |
| 1808 | break; |
| 1809 | } |
| 1810 | |
| 1811 | case Instruction::CMPG_DOUBLE: { |
| 1812 | Binop_23x_cmp(instruction, Primitive::kPrimDouble, HCompare::kGtBias); |
| 1813 | break; |
| 1814 | } |
| 1815 | |
| 1816 | case Instruction::CMPL_FLOAT: { |
| 1817 | Binop_23x_cmp(instruction, Primitive::kPrimFloat, HCompare::kLtBias); |
| 1818 | break; |
| 1819 | } |
| 1820 | |
| 1821 | case Instruction::CMPL_DOUBLE: { |
| 1822 | Binop_23x_cmp(instruction, Primitive::kPrimDouble, HCompare::kLtBias); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1823 | break; |
| 1824 | } |
| 1825 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 1826 | case Instruction::NOP: |
| 1827 | break; |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1828 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1829 | case Instruction::IGET: |
| 1830 | case Instruction::IGET_WIDE: |
| 1831 | case Instruction::IGET_OBJECT: |
| 1832 | case Instruction::IGET_BOOLEAN: |
| 1833 | case Instruction::IGET_BYTE: |
| 1834 | case Instruction::IGET_CHAR: |
| 1835 | case Instruction::IGET_SHORT: { |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1836 | if (!BuildInstanceFieldAccess(instruction, dex_pc, false)) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1837 | return false; |
| 1838 | } |
| 1839 | break; |
| 1840 | } |
| 1841 | |
| 1842 | case Instruction::IPUT: |
| 1843 | case Instruction::IPUT_WIDE: |
| 1844 | case Instruction::IPUT_OBJECT: |
| 1845 | case Instruction::IPUT_BOOLEAN: |
| 1846 | case Instruction::IPUT_BYTE: |
| 1847 | case Instruction::IPUT_CHAR: |
| 1848 | case Instruction::IPUT_SHORT: { |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1849 | if (!BuildInstanceFieldAccess(instruction, dex_pc, true)) { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 1850 | return false; |
| 1851 | } |
| 1852 | break; |
| 1853 | } |
| 1854 | |
| 1855 | case Instruction::SGET: |
| 1856 | case Instruction::SGET_WIDE: |
| 1857 | case Instruction::SGET_OBJECT: |
| 1858 | case Instruction::SGET_BOOLEAN: |
| 1859 | case Instruction::SGET_BYTE: |
| 1860 | case Instruction::SGET_CHAR: |
| 1861 | case Instruction::SGET_SHORT: { |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1862 | if (!BuildStaticFieldAccess(instruction, dex_pc, false)) { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 1863 | return false; |
| 1864 | } |
| 1865 | break; |
| 1866 | } |
| 1867 | |
| 1868 | case Instruction::SPUT: |
| 1869 | case Instruction::SPUT_WIDE: |
| 1870 | case Instruction::SPUT_OBJECT: |
| 1871 | case Instruction::SPUT_BOOLEAN: |
| 1872 | case Instruction::SPUT_BYTE: |
| 1873 | case Instruction::SPUT_CHAR: |
| 1874 | case Instruction::SPUT_SHORT: { |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1875 | if (!BuildStaticFieldAccess(instruction, dex_pc, true)) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1876 | return false; |
| 1877 | } |
| 1878 | break; |
| 1879 | } |
| 1880 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1881 | #define ARRAY_XX(kind, anticipated_type) \ |
| 1882 | case Instruction::AGET##kind: { \ |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1883 | BuildArrayAccess(instruction, dex_pc, false, anticipated_type); \ |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1884 | break; \ |
| 1885 | } \ |
| 1886 | case Instruction::APUT##kind: { \ |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1887 | BuildArrayAccess(instruction, dex_pc, true, anticipated_type); \ |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1888 | break; \ |
| 1889 | } |
| 1890 | |
| 1891 | ARRAY_XX(, Primitive::kPrimInt); |
| 1892 | ARRAY_XX(_WIDE, Primitive::kPrimLong); |
| 1893 | ARRAY_XX(_OBJECT, Primitive::kPrimNot); |
| 1894 | ARRAY_XX(_BOOLEAN, Primitive::kPrimBoolean); |
| 1895 | ARRAY_XX(_BYTE, Primitive::kPrimByte); |
| 1896 | ARRAY_XX(_CHAR, Primitive::kPrimChar); |
| 1897 | ARRAY_XX(_SHORT, Primitive::kPrimShort); |
| 1898 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1899 | case Instruction::ARRAY_LENGTH: { |
| 1900 | HInstruction* object = LoadLocal(instruction.VRegB_12x(), Primitive::kPrimNot); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 1901 | // No need for a temporary for the null check, it is the only input of the following |
| 1902 | // instruction. |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1903 | object = new (arena_) HNullCheck(object, dex_pc); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 1904 | current_block_->AddInstruction(object); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1905 | current_block_->AddInstruction(new (arena_) HArrayLength(object)); |
| 1906 | UpdateLocal(instruction.VRegA_12x(), current_block_->GetLastInstruction()); |
| 1907 | break; |
| 1908 | } |
| 1909 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 1910 | case Instruction::CONST_STRING: { |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1911 | current_block_->AddInstruction(new (arena_) HLoadString(instruction.VRegB_21c(), dex_pc)); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 1912 | UpdateLocal(instruction.VRegA_21c(), current_block_->GetLastInstruction()); |
| 1913 | break; |
| 1914 | } |
| 1915 | |
| 1916 | case Instruction::CONST_STRING_JUMBO: { |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1917 | current_block_->AddInstruction(new (arena_) HLoadString(instruction.VRegB_31c(), dex_pc)); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 1918 | UpdateLocal(instruction.VRegA_31c(), current_block_->GetLastInstruction()); |
| 1919 | break; |
| 1920 | } |
| 1921 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 1922 | case Instruction::CONST_CLASS: { |
| 1923 | uint16_t type_index = instruction.VRegB_21c(); |
| 1924 | bool type_known_final; |
| 1925 | bool type_known_abstract; |
| 1926 | bool is_referrers_class; |
| 1927 | bool can_access = compiler_driver_->CanAccessTypeWithoutChecks( |
| 1928 | dex_compilation_unit_->GetDexMethodIndex(), *dex_file_, type_index, |
| 1929 | &type_known_final, &type_known_abstract, &is_referrers_class); |
| 1930 | if (!can_access) { |
| 1931 | return false; |
| 1932 | } |
| 1933 | current_block_->AddInstruction( |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1934 | new (arena_) HLoadClass(type_index, is_referrers_class, dex_pc)); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 1935 | UpdateLocal(instruction.VRegA_21c(), current_block_->GetLastInstruction()); |
| 1936 | break; |
| 1937 | } |
| 1938 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 1939 | case Instruction::MOVE_EXCEPTION: { |
| 1940 | current_block_->AddInstruction(new (arena_) HLoadException()); |
| 1941 | UpdateLocal(instruction.VRegA_11x(), current_block_->GetLastInstruction()); |
| 1942 | break; |
| 1943 | } |
| 1944 | |
| 1945 | case Instruction::THROW: { |
| 1946 | HInstruction* exception = LoadLocal(instruction.VRegA_11x(), Primitive::kPrimNot); |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1947 | current_block_->AddInstruction(new (arena_) HThrow(exception, dex_pc)); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 1948 | // A throw instruction must branch to the exit block. |
| 1949 | current_block_->AddSuccessor(exit_block_); |
| 1950 | // We finished building this block. Set the current block to null to avoid |
| 1951 | // adding dead instructions to it. |
| 1952 | current_block_ = nullptr; |
| 1953 | break; |
| 1954 | } |
| 1955 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 1956 | case Instruction::INSTANCE_OF: { |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 1957 | uint8_t destination = instruction.VRegA_22c(); |
| 1958 | uint8_t reference = instruction.VRegB_22c(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 1959 | uint16_t type_index = instruction.VRegC_22c(); |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1960 | if (!BuildTypeCheck(instruction, destination, reference, type_index, dex_pc)) { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 1961 | return false; |
| 1962 | } |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 1963 | break; |
| 1964 | } |
| 1965 | |
| 1966 | case Instruction::CHECK_CAST: { |
| 1967 | uint8_t reference = instruction.VRegA_21c(); |
| 1968 | uint16_t type_index = instruction.VRegB_21c(); |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1969 | if (!BuildTypeCheck(instruction, -1, reference, type_index, dex_pc)) { |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 1970 | return false; |
| 1971 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 1972 | break; |
| 1973 | } |
| 1974 | |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 1975 | case Instruction::MONITOR_ENTER: { |
| 1976 | current_block_->AddInstruction(new (arena_) HMonitorOperation( |
| 1977 | LoadLocal(instruction.VRegA_11x(), Primitive::kPrimNot), |
| 1978 | HMonitorOperation::kEnter, |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1979 | dex_pc)); |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 1980 | break; |
| 1981 | } |
| 1982 | |
| 1983 | case Instruction::MONITOR_EXIT: { |
| 1984 | current_block_->AddInstruction(new (arena_) HMonitorOperation( |
| 1985 | LoadLocal(instruction.VRegA_11x(), Primitive::kPrimNot), |
| 1986 | HMonitorOperation::kExit, |
Calin Juravle | 225ff81 | 2014-11-13 16:46:39 +0000 | [diff] [blame] | 1987 | dex_pc)); |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 1988 | break; |
| 1989 | } |
| 1990 | |
Andreas Gampe | d881df5 | 2014-11-24 23:28:39 -0800 | [diff] [blame] | 1991 | case Instruction::PACKED_SWITCH: { |
| 1992 | if (!BuildPackedSwitch(instruction, dex_pc)) { |
| 1993 | return false; |
| 1994 | } |
| 1995 | break; |
| 1996 | } |
| 1997 | |
Andreas Gampe | e4d4d32 | 2014-12-04 09:09:57 -0800 | [diff] [blame] | 1998 | case Instruction::SPARSE_SWITCH: { |
| 1999 | if (!BuildSparseSwitch(instruction, dex_pc)) { |
| 2000 | return false; |
| 2001 | } |
| 2002 | break; |
| 2003 | } |
| 2004 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2005 | default: |
| 2006 | return false; |
| 2007 | } |
| 2008 | return true; |
Nicolas Geoffray | dadf317 | 2014-11-07 16:36:02 +0000 | [diff] [blame] | 2009 | } // NOLINT(readability/fn_size) |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2010 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2011 | HIntConstant* HGraphBuilder::GetIntConstant0() { |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2012 | if (constant0_ != nullptr) { |
| 2013 | return constant0_; |
| 2014 | } |
| 2015 | constant0_ = new(arena_) HIntConstant(0); |
| 2016 | entry_block_->AddInstruction(constant0_); |
| 2017 | return constant0_; |
| 2018 | } |
| 2019 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2020 | HIntConstant* HGraphBuilder::GetIntConstant1() { |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2021 | if (constant1_ != nullptr) { |
| 2022 | return constant1_; |
| 2023 | } |
| 2024 | constant1_ = new(arena_) HIntConstant(1); |
| 2025 | entry_block_->AddInstruction(constant1_); |
| 2026 | return constant1_; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2027 | } |
| 2028 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2029 | HIntConstant* HGraphBuilder::GetIntConstant(int32_t constant) { |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2030 | switch (constant) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2031 | case 0: return GetIntConstant0(); |
| 2032 | case 1: return GetIntConstant1(); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2033 | default: { |
| 2034 | HIntConstant* instruction = new (arena_) HIntConstant(constant); |
| 2035 | entry_block_->AddInstruction(instruction); |
| 2036 | return instruction; |
| 2037 | } |
| 2038 | } |
| 2039 | } |
| 2040 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2041 | HLongConstant* HGraphBuilder::GetLongConstant(int64_t constant) { |
| 2042 | HLongConstant* instruction = new (arena_) HLongConstant(constant); |
| 2043 | entry_block_->AddInstruction(instruction); |
| 2044 | return instruction; |
| 2045 | } |
| 2046 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2047 | HLocal* HGraphBuilder::GetLocalAt(int register_index) const { |
| 2048 | return locals_.Get(register_index); |
| 2049 | } |
| 2050 | |
| 2051 | void HGraphBuilder::UpdateLocal(int register_index, HInstruction* instruction) const { |
| 2052 | HLocal* local = GetLocalAt(register_index); |
| 2053 | current_block_->AddInstruction(new (arena_) HStoreLocal(local, instruction)); |
| 2054 | } |
| 2055 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2056 | HInstruction* HGraphBuilder::LoadLocal(int register_index, Primitive::Type type) const { |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2057 | HLocal* local = GetLocalAt(register_index); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2058 | current_block_->AddInstruction(new (arena_) HLoadLocal(local, type)); |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2059 | return current_block_->GetLastInstruction(); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2060 | } |
| 2061 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2062 | } // namespace art |