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