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