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 | |
| 19 | #include "class_linker.h" |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 20 | #include "dex_file.h" |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 21 | #include "dex_file-inl.h" |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 22 | #include "dex_instruction.h" |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 23 | #include "dex_instruction-inl.h" |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 24 | #include "driver/compiler_driver-inl.h" |
| 25 | #include "mirror/art_field.h" |
| 26 | #include "mirror/art_field-inl.h" |
| 27 | #include "mirror/class_loader.h" |
| 28 | #include "mirror/dex_cache.h" |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 29 | #include "nodes.h" |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 30 | #include "primitive.h" |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 31 | #include "scoped_thread_state_change.h" |
| 32 | #include "thread.h" |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 33 | |
| 34 | namespace art { |
| 35 | |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 36 | /** |
| 37 | * Helper class to add HTemporary instructions. This class is used when |
| 38 | * converting a DEX instruction to multiple HInstruction, and where those |
| 39 | * instructions do not die at the following instruction, but instead spans |
| 40 | * multiple instructions. |
| 41 | */ |
| 42 | class Temporaries : public ValueObject { |
| 43 | public: |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame^] | 44 | explicit Temporaries(HGraph* graph) : graph_(graph), index_(0) {} |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 45 | |
| 46 | void Add(HInstruction* instruction) { |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame^] | 47 | HInstruction* temp = new (graph_->GetArena()) HTemporary(index_); |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 48 | instruction->GetBlock()->AddInstruction(temp); |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame^] | 49 | |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 50 | DCHECK(temp->GetPrevious() == instruction); |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame^] | 51 | |
| 52 | size_t offset; |
| 53 | if (instruction->GetType() == Primitive::kPrimLong |
| 54 | || instruction->GetType() == Primitive::kPrimDouble) { |
| 55 | offset = 2; |
| 56 | } else { |
| 57 | offset = 1; |
| 58 | } |
| 59 | index_ += offset; |
| 60 | |
| 61 | graph_->UpdateTemporariesVRegSlots(index_); |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 62 | } |
| 63 | |
| 64 | private: |
| 65 | HGraph* const graph_; |
| 66 | |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 67 | // Current index in the temporary stack, updated by `Add`. |
| 68 | size_t index_; |
| 69 | }; |
| 70 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 71 | void HGraphBuilder::InitializeLocals(uint16_t count) { |
| 72 | graph_->SetNumberOfVRegs(count); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 73 | locals_.SetSize(count); |
| 74 | for (int i = 0; i < count; i++) { |
| 75 | HLocal* local = new (arena_) HLocal(i); |
| 76 | entry_block_->AddInstruction(local); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 77 | locals_.Put(i, local); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 78 | } |
| 79 | } |
| 80 | |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 81 | void HGraphBuilder::InitializeParameters(uint16_t number_of_parameters) { |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 82 | // dex_compilation_unit_ is null only when unit testing. |
| 83 | if (dex_compilation_unit_ == nullptr) { |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 84 | return; |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 85 | } |
| 86 | |
| 87 | graph_->SetNumberOfInVRegs(number_of_parameters); |
| 88 | const char* shorty = dex_compilation_unit_->GetShorty(); |
| 89 | int locals_index = locals_.Size() - number_of_parameters; |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 90 | int parameter_index = 0; |
| 91 | |
| 92 | if (!dex_compilation_unit_->IsStatic()) { |
| 93 | // Add the implicit 'this' argument, not expressed in the signature. |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 94 | HParameterValue* parameter = |
| 95 | new (arena_) HParameterValue(parameter_index++, Primitive::kPrimNot); |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 96 | entry_block_->AddInstruction(parameter); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 97 | HLocal* local = GetLocalAt(locals_index++); |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 98 | entry_block_->AddInstruction(new (arena_) HStoreLocal(local, parameter)); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 99 | number_of_parameters--; |
| 100 | } |
| 101 | |
| 102 | uint32_t pos = 1; |
| 103 | for (int i = 0; i < number_of_parameters; i++) { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 104 | HParameterValue* parameter = |
| 105 | new (arena_) HParameterValue(parameter_index++, Primitive::GetType(shorty[pos++])); |
| 106 | entry_block_->AddInstruction(parameter); |
| 107 | HLocal* local = GetLocalAt(locals_index++); |
| 108 | // Store the parameter value in the local that the dex code will use |
| 109 | // to reference that parameter. |
| 110 | entry_block_->AddInstruction(new (arena_) HStoreLocal(local, parameter)); |
| 111 | bool is_wide = (parameter->GetType() == Primitive::kPrimLong) |
| 112 | || (parameter->GetType() == Primitive::kPrimDouble); |
| 113 | if (is_wide) { |
| 114 | i++; |
| 115 | locals_index++; |
| 116 | parameter_index++; |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 117 | } |
| 118 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 119 | } |
| 120 | |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 121 | template<typename T> |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 122 | void HGraphBuilder::If_22t(const Instruction& instruction, uint32_t dex_offset) { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 123 | int32_t target_offset = instruction.GetTargetOffset(); |
| 124 | PotentiallyAddSuspendCheck(target_offset, dex_offset); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 125 | HInstruction* first = LoadLocal(instruction.VRegA(), Primitive::kPrimInt); |
| 126 | HInstruction* second = LoadLocal(instruction.VRegB(), Primitive::kPrimInt); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 127 | T* comparison = new (arena_) T(first, second); |
| 128 | current_block_->AddInstruction(comparison); |
| 129 | HInstruction* ifinst = new (arena_) HIf(comparison); |
| 130 | current_block_->AddInstruction(ifinst); |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 131 | HBasicBlock* target = FindBlockStartingAt(dex_offset + target_offset); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 132 | DCHECK(target != nullptr); |
| 133 | current_block_->AddSuccessor(target); |
| 134 | target = FindBlockStartingAt(dex_offset + instruction.SizeInCodeUnits()); |
| 135 | DCHECK(target != nullptr); |
| 136 | current_block_->AddSuccessor(target); |
| 137 | current_block_ = nullptr; |
| 138 | } |
| 139 | |
| 140 | template<typename T> |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 141 | void HGraphBuilder::If_21t(const Instruction& instruction, uint32_t dex_offset) { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 142 | int32_t target_offset = instruction.GetTargetOffset(); |
| 143 | PotentiallyAddSuspendCheck(target_offset, dex_offset); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 144 | HInstruction* value = LoadLocal(instruction.VRegA(), Primitive::kPrimInt); |
| 145 | T* comparison = new (arena_) T(value, GetIntConstant(0)); |
| 146 | current_block_->AddInstruction(comparison); |
| 147 | HInstruction* ifinst = new (arena_) HIf(comparison); |
| 148 | current_block_->AddInstruction(ifinst); |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 149 | HBasicBlock* target = FindBlockStartingAt(dex_offset + target_offset); |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 150 | DCHECK(target != nullptr); |
| 151 | current_block_->AddSuccessor(target); |
| 152 | target = FindBlockStartingAt(dex_offset + instruction.SizeInCodeUnits()); |
| 153 | DCHECK(target != nullptr); |
| 154 | current_block_->AddSuccessor(target); |
| 155 | current_block_ = nullptr; |
| 156 | } |
| 157 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 158 | HGraph* HGraphBuilder::BuildGraph(const DexFile::CodeItem& code_item) { |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 159 | const uint16_t* code_ptr = code_item.insns_; |
| 160 | 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] | 161 | code_start_ = code_ptr; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 162 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 163 | // Setup the graph with the entry block and exit block. |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 164 | graph_ = new (arena_) HGraph(arena_); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 165 | entry_block_ = new (arena_) HBasicBlock(graph_, 0); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 166 | graph_->AddBlock(entry_block_); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 167 | exit_block_ = new (arena_) HBasicBlock(graph_, kNoDexPc); |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 168 | graph_->SetEntryBlock(entry_block_); |
| 169 | graph_->SetExitBlock(exit_block_); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 170 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 171 | InitializeLocals(code_item.registers_size_); |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 172 | graph_->UpdateMaximumNumberOfOutVRegs(code_item.outs_size_); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 173 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 174 | // To avoid splitting blocks, we compute ahead of time the instructions that |
| 175 | // start a new block, and create these blocks. |
| 176 | ComputeBranchTargets(code_ptr, code_end); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 177 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 178 | // Also create blocks for catch handlers. |
| 179 | if (code_item.tries_size_ != 0) { |
| 180 | const uint8_t* handlers_ptr = DexFile::GetCatchHandlerData(code_item, 0); |
| 181 | uint32_t handlers_size = DecodeUnsignedLeb128(&handlers_ptr); |
| 182 | for (uint32_t idx = 0; idx < handlers_size; ++idx) { |
| 183 | CatchHandlerIterator iterator(handlers_ptr); |
| 184 | for (; iterator.HasNext(); iterator.Next()) { |
| 185 | uint32_t address = iterator.GetHandlerAddress(); |
| 186 | HBasicBlock* block = FindBlockStartingAt(address); |
| 187 | if (block == nullptr) { |
| 188 | block = new (arena_) HBasicBlock(graph_, address); |
| 189 | branch_targets_.Put(address, block); |
| 190 | } |
| 191 | block->SetIsCatchBlock(); |
| 192 | } |
| 193 | handlers_ptr = iterator.EndDataPointer(); |
| 194 | } |
| 195 | } |
| 196 | |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 197 | InitializeParameters(code_item.ins_size_); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 198 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 199 | size_t dex_offset = 0; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 200 | while (code_ptr < code_end) { |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 201 | // Update the current block if dex_offset starts a new block. |
| 202 | MaybeUpdateCurrentBlock(dex_offset); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 203 | const Instruction& instruction = *Instruction::At(code_ptr); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 204 | if (!AnalyzeDexInstruction(instruction, dex_offset)) return nullptr; |
| 205 | dex_offset += instruction.SizeInCodeUnits(); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 206 | code_ptr += instruction.SizeInCodeUnits(); |
| 207 | } |
| 208 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 209 | // 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] | 210 | graph_->AddBlock(exit_block_); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 211 | exit_block_->AddInstruction(new (arena_) HExit()); |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 212 | // Add the suspend check to the entry block. |
| 213 | entry_block_->AddInstruction(new (arena_) HSuspendCheck(0)); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 214 | entry_block_->AddInstruction(new (arena_) HGoto()); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 215 | return graph_; |
| 216 | } |
| 217 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 218 | void HGraphBuilder::MaybeUpdateCurrentBlock(size_t index) { |
| 219 | HBasicBlock* block = FindBlockStartingAt(index); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 220 | if (block == nullptr) { |
| 221 | return; |
| 222 | } |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 223 | |
| 224 | if (current_block_ != nullptr) { |
| 225 | // Branching instructions clear current_block, so we know |
| 226 | // the last instruction of the current block is not a branching |
| 227 | // instruction. We add an unconditional goto to the found block. |
| 228 | current_block_->AddInstruction(new (arena_) HGoto()); |
| 229 | current_block_->AddSuccessor(block); |
| 230 | } |
| 231 | graph_->AddBlock(block); |
| 232 | current_block_ = block; |
| 233 | } |
| 234 | |
| 235 | void HGraphBuilder::ComputeBranchTargets(const uint16_t* code_ptr, const uint16_t* code_end) { |
| 236 | // TODO: Support switch instructions. |
| 237 | branch_targets_.SetSize(code_end - code_ptr); |
| 238 | |
| 239 | // 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] | 240 | HBasicBlock* block = new (arena_) HBasicBlock(graph_, 0); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 241 | branch_targets_.Put(0, block); |
| 242 | entry_block_->AddSuccessor(block); |
| 243 | |
| 244 | // Iterate over all instructions and find branching instructions. Create blocks for |
| 245 | // the locations these instructions branch to. |
| 246 | size_t dex_offset = 0; |
| 247 | while (code_ptr < code_end) { |
| 248 | const Instruction& instruction = *Instruction::At(code_ptr); |
| 249 | if (instruction.IsBranch()) { |
| 250 | int32_t target = instruction.GetTargetOffset() + dex_offset; |
| 251 | // Create a block for the target instruction. |
| 252 | if (FindBlockStartingAt(target) == nullptr) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 253 | block = new (arena_) HBasicBlock(graph_, target); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 254 | branch_targets_.Put(target, block); |
| 255 | } |
| 256 | dex_offset += instruction.SizeInCodeUnits(); |
| 257 | code_ptr += instruction.SizeInCodeUnits(); |
| 258 | if ((code_ptr < code_end) && (FindBlockStartingAt(dex_offset) == nullptr)) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 259 | block = new (arena_) HBasicBlock(graph_, dex_offset); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 260 | branch_targets_.Put(dex_offset, block); |
| 261 | } |
| 262 | } else { |
| 263 | code_ptr += instruction.SizeInCodeUnits(); |
| 264 | dex_offset += instruction.SizeInCodeUnits(); |
| 265 | } |
| 266 | } |
| 267 | } |
| 268 | |
| 269 | HBasicBlock* HGraphBuilder::FindBlockStartingAt(int32_t index) const { |
| 270 | DCHECK_GE(index, 0); |
| 271 | return branch_targets_.Get(index); |
| 272 | } |
| 273 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 274 | template<typename T> |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 275 | void HGraphBuilder::Unop_12x(const Instruction& instruction, Primitive::Type type) { |
| 276 | HInstruction* first = LoadLocal(instruction.VRegB(), type); |
| 277 | current_block_->AddInstruction(new (arena_) T(type, first)); |
| 278 | UpdateLocal(instruction.VRegA(), current_block_->GetLastInstruction()); |
| 279 | } |
| 280 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 281 | void HGraphBuilder::Conversion_12x(const Instruction& instruction, |
| 282 | Primitive::Type input_type, |
| 283 | Primitive::Type result_type) { |
| 284 | HInstruction* first = LoadLocal(instruction.VRegB(), input_type); |
| 285 | current_block_->AddInstruction(new (arena_) HTypeConversion(result_type, first)); |
| 286 | UpdateLocal(instruction.VRegA(), current_block_->GetLastInstruction()); |
| 287 | } |
| 288 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 289 | template<typename T> |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 290 | void HGraphBuilder::Binop_23x(const Instruction& instruction, Primitive::Type type) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 291 | HInstruction* first = LoadLocal(instruction.VRegB(), type); |
| 292 | HInstruction* second = LoadLocal(instruction.VRegC(), type); |
| 293 | current_block_->AddInstruction(new (arena_) T(type, first, second)); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 294 | UpdateLocal(instruction.VRegA(), current_block_->GetLastInstruction()); |
| 295 | } |
| 296 | |
| 297 | template<typename T> |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 298 | void HGraphBuilder::Binop_12x(const Instruction& instruction, Primitive::Type type) { |
| 299 | HInstruction* first = LoadLocal(instruction.VRegA(), type); |
| 300 | HInstruction* second = LoadLocal(instruction.VRegB(), type); |
| 301 | current_block_->AddInstruction(new (arena_) T(type, first, second)); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 302 | UpdateLocal(instruction.VRegA(), current_block_->GetLastInstruction()); |
| 303 | } |
| 304 | |
| 305 | template<typename T> |
| 306 | void HGraphBuilder::Binop_22s(const Instruction& instruction, bool reverse) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 307 | HInstruction* first = LoadLocal(instruction.VRegB(), Primitive::kPrimInt); |
| 308 | HInstruction* second = GetIntConstant(instruction.VRegC_22s()); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 309 | if (reverse) { |
| 310 | std::swap(first, second); |
| 311 | } |
| 312 | current_block_->AddInstruction(new (arena_) T(Primitive::kPrimInt, first, second)); |
| 313 | UpdateLocal(instruction.VRegA(), current_block_->GetLastInstruction()); |
| 314 | } |
| 315 | |
| 316 | template<typename T> |
| 317 | void HGraphBuilder::Binop_22b(const Instruction& instruction, bool reverse) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 318 | HInstruction* first = LoadLocal(instruction.VRegB(), Primitive::kPrimInt); |
| 319 | HInstruction* second = GetIntConstant(instruction.VRegC_22b()); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 320 | if (reverse) { |
| 321 | std::swap(first, second); |
| 322 | } |
| 323 | current_block_->AddInstruction(new (arena_) T(Primitive::kPrimInt, first, second)); |
| 324 | UpdateLocal(instruction.VRegA(), current_block_->GetLastInstruction()); |
| 325 | } |
| 326 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 327 | void HGraphBuilder::BuildReturn(const Instruction& instruction, Primitive::Type type) { |
| 328 | if (type == Primitive::kPrimVoid) { |
| 329 | current_block_->AddInstruction(new (arena_) HReturnVoid()); |
| 330 | } else { |
| 331 | HInstruction* value = LoadLocal(instruction.VRegA(), type); |
| 332 | current_block_->AddInstruction(new (arena_) HReturn(value)); |
| 333 | } |
| 334 | current_block_->AddSuccessor(exit_block_); |
| 335 | current_block_ = nullptr; |
| 336 | } |
| 337 | |
| 338 | bool HGraphBuilder::BuildInvoke(const Instruction& instruction, |
| 339 | uint32_t dex_offset, |
| 340 | uint32_t method_idx, |
| 341 | uint32_t number_of_vreg_arguments, |
| 342 | bool is_range, |
| 343 | uint32_t* args, |
| 344 | uint32_t register_index) { |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 345 | Instruction::Code opcode = instruction.Opcode(); |
| 346 | InvokeType invoke_type; |
| 347 | switch (opcode) { |
| 348 | case Instruction::INVOKE_STATIC: |
| 349 | case Instruction::INVOKE_STATIC_RANGE: |
| 350 | invoke_type = kStatic; |
| 351 | break; |
| 352 | case Instruction::INVOKE_DIRECT: |
| 353 | case Instruction::INVOKE_DIRECT_RANGE: |
| 354 | invoke_type = kDirect; |
| 355 | break; |
| 356 | case Instruction::INVOKE_VIRTUAL: |
| 357 | case Instruction::INVOKE_VIRTUAL_RANGE: |
| 358 | invoke_type = kVirtual; |
| 359 | break; |
| 360 | case Instruction::INVOKE_INTERFACE: |
| 361 | case Instruction::INVOKE_INTERFACE_RANGE: |
| 362 | invoke_type = kInterface; |
| 363 | break; |
| 364 | case Instruction::INVOKE_SUPER_RANGE: |
| 365 | case Instruction::INVOKE_SUPER: |
| 366 | invoke_type = kSuper; |
| 367 | break; |
| 368 | default: |
| 369 | LOG(FATAL) << "Unexpected invoke op: " << opcode; |
| 370 | return false; |
| 371 | } |
| 372 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 373 | const DexFile::MethodId& method_id = dex_file_->GetMethodId(method_idx); |
| 374 | const DexFile::ProtoId& proto_id = dex_file_->GetProtoId(method_id.proto_idx_); |
| 375 | const char* descriptor = dex_file_->StringDataByIdx(proto_id.shorty_idx_); |
| 376 | Primitive::Type return_type = Primitive::GetType(descriptor[0]); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 377 | bool is_instance_call = invoke_type != kStatic; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 378 | const size_t number_of_arguments = strlen(descriptor) - (is_instance_call ? 0 : 1); |
| 379 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 380 | HInvoke* invoke = nullptr; |
Nicolas Geoffray | 0d8db99 | 2014-11-11 14:40:10 +0000 | [diff] [blame] | 381 | if (invoke_type == kVirtual || invoke_type == kInterface || invoke_type == kSuper) { |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 382 | MethodReference target_method(dex_file_, method_idx); |
| 383 | uintptr_t direct_code; |
| 384 | uintptr_t direct_method; |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 385 | int table_index; |
| 386 | InvokeType optimized_invoke_type = invoke_type; |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 387 | compiler_driver_->ComputeInvokeInfo(dex_compilation_unit_, dex_offset, true, true, |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 388 | &optimized_invoke_type, &target_method, &table_index, |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 389 | &direct_code, &direct_method); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 390 | if (table_index == -1) { |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 391 | return false; |
| 392 | } |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 393 | |
Nicolas Geoffray | 0d8db99 | 2014-11-11 14:40:10 +0000 | [diff] [blame] | 394 | if (optimized_invoke_type == kVirtual) { |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 395 | invoke = new (arena_) HInvokeVirtual( |
| 396 | arena_, number_of_arguments, return_type, dex_offset, table_index); |
Nicolas Geoffray | 0d8db99 | 2014-11-11 14:40:10 +0000 | [diff] [blame] | 397 | } else if (optimized_invoke_type == kInterface) { |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 398 | invoke = new (arena_) HInvokeInterface( |
| 399 | arena_, number_of_arguments, return_type, dex_offset, method_idx, table_index); |
Nicolas Geoffray | 0d8db99 | 2014-11-11 14:40:10 +0000 | [diff] [blame] | 400 | } else if (optimized_invoke_type == kDirect) { |
| 401 | // For this compiler, sharpening only works if we compile PIC. |
| 402 | DCHECK(compiler_driver_->GetCompilerOptions().GetCompilePic()); |
| 403 | // Treat invoke-direct like static calls for now. |
| 404 | invoke = new (arena_) HInvokeStatic( |
| 405 | arena_, number_of_arguments, return_type, dex_offset, target_method.dex_method_index); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 406 | } |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 407 | } else { |
Nicolas Geoffray | 0d8db99 | 2014-11-11 14:40:10 +0000 | [diff] [blame] | 408 | DCHECK(invoke_type == kDirect || invoke_type == kStatic); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 409 | // Treat invoke-direct like static calls for now. |
| 410 | invoke = new (arena_) HInvokeStatic( |
| 411 | arena_, number_of_arguments, return_type, dex_offset, method_idx); |
| 412 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 413 | |
| 414 | size_t start_index = 0; |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame^] | 415 | Temporaries temps(graph_); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 416 | if (is_instance_call) { |
| 417 | HInstruction* arg = LoadLocal(is_range ? register_index : args[0], Primitive::kPrimNot); |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 418 | HNullCheck* null_check = new (arena_) HNullCheck(arg, dex_offset); |
| 419 | current_block_->AddInstruction(null_check); |
| 420 | temps.Add(null_check); |
| 421 | invoke->SetArgumentAt(0, null_check); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 422 | start_index = 1; |
| 423 | } |
| 424 | |
| 425 | uint32_t descriptor_index = 1; |
| 426 | uint32_t argument_index = start_index; |
| 427 | for (size_t i = start_index; i < number_of_vreg_arguments; i++, argument_index++) { |
| 428 | Primitive::Type type = Primitive::GetType(descriptor[descriptor_index++]); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 429 | bool is_wide = (type == Primitive::kPrimLong) || (type == Primitive::kPrimDouble); |
| 430 | if (!is_range && is_wide && args[i] + 1 != args[i + 1]) { |
Nicolas Geoffray | abed4d0 | 2014-07-14 15:24:11 +0100 | [diff] [blame] | 431 | LOG(WARNING) << "Non sequential register pair in " << dex_compilation_unit_->GetSymbol() |
| 432 | << " at " << dex_offset; |
| 433 | // We do not implement non sequential register pair. |
| 434 | return false; |
| 435 | } |
| 436 | HInstruction* arg = LoadLocal(is_range ? register_index + i : args[i], type); |
| 437 | invoke->SetArgumentAt(argument_index, arg); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 438 | if (is_wide) { |
Nicolas Geoffray | abed4d0 | 2014-07-14 15:24:11 +0100 | [diff] [blame] | 439 | i++; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 440 | } |
| 441 | } |
| 442 | |
| 443 | DCHECK_EQ(argument_index, number_of_arguments); |
| 444 | current_block_->AddInstruction(invoke); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 445 | latest_result_ = invoke; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 446 | return true; |
| 447 | } |
| 448 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 449 | bool HGraphBuilder::BuildInstanceFieldAccess(const Instruction& instruction, |
| 450 | uint32_t dex_offset, |
| 451 | bool is_put) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 452 | uint32_t source_or_dest_reg = instruction.VRegA_22c(); |
| 453 | uint32_t obj_reg = instruction.VRegB_22c(); |
| 454 | uint16_t field_index = instruction.VRegC_22c(); |
| 455 | |
| 456 | ScopedObjectAccess soa(Thread::Current()); |
| 457 | StackHandleScope<1> hs(soa.Self()); |
| 458 | Handle<mirror::ArtField> resolved_field(hs.NewHandle( |
| 459 | compiler_driver_->ComputeInstanceFieldInfo(field_index, dex_compilation_unit_, is_put, soa))); |
| 460 | |
| 461 | if (resolved_field.Get() == nullptr) { |
| 462 | return false; |
| 463 | } |
| 464 | if (resolved_field->IsVolatile()) { |
| 465 | return false; |
| 466 | } |
| 467 | |
Nicolas Geoffray | abed4d0 | 2014-07-14 15:24:11 +0100 | [diff] [blame] | 468 | Primitive::Type field_type = resolved_field->GetTypeAsPrimitiveType(); |
Nicolas Geoffray | abed4d0 | 2014-07-14 15:24:11 +0100 | [diff] [blame] | 469 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 470 | HInstruction* object = LoadLocal(obj_reg, Primitive::kPrimNot); |
| 471 | current_block_->AddInstruction(new (arena_) HNullCheck(object, dex_offset)); |
| 472 | if (is_put) { |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame^] | 473 | Temporaries temps(graph_); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 474 | HInstruction* null_check = current_block_->GetLastInstruction(); |
| 475 | // We need one temporary for the null check. |
| 476 | temps.Add(null_check); |
Nicolas Geoffray | abed4d0 | 2014-07-14 15:24:11 +0100 | [diff] [blame] | 477 | HInstruction* value = LoadLocal(source_or_dest_reg, field_type); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 478 | current_block_->AddInstruction(new (arena_) HInstanceFieldSet( |
| 479 | null_check, |
| 480 | value, |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 481 | field_type, |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 482 | resolved_field->GetOffset())); |
| 483 | } else { |
| 484 | current_block_->AddInstruction(new (arena_) HInstanceFieldGet( |
| 485 | current_block_->GetLastInstruction(), |
Nicolas Geoffray | abed4d0 | 2014-07-14 15:24:11 +0100 | [diff] [blame] | 486 | field_type, |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 487 | resolved_field->GetOffset())); |
| 488 | |
| 489 | UpdateLocal(source_or_dest_reg, current_block_->GetLastInstruction()); |
| 490 | } |
| 491 | return true; |
| 492 | } |
| 493 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 494 | |
| 495 | |
| 496 | bool HGraphBuilder::BuildStaticFieldAccess(const Instruction& instruction, |
| 497 | uint32_t dex_offset, |
| 498 | bool is_put) { |
| 499 | uint32_t source_or_dest_reg = instruction.VRegA_21c(); |
| 500 | uint16_t field_index = instruction.VRegB_21c(); |
| 501 | |
| 502 | uint32_t storage_index; |
| 503 | bool is_referrers_class; |
| 504 | bool is_initialized; |
| 505 | bool is_volatile; |
| 506 | MemberOffset field_offset(0u); |
| 507 | Primitive::Type field_type; |
| 508 | |
| 509 | bool fast_path = compiler_driver_->ComputeStaticFieldInfo(field_index, |
| 510 | dex_compilation_unit_, |
| 511 | is_put, |
| 512 | &field_offset, |
| 513 | &storage_index, |
| 514 | &is_referrers_class, |
| 515 | &is_volatile, |
| 516 | &is_initialized, |
| 517 | &field_type); |
| 518 | if (!fast_path) { |
| 519 | return false; |
| 520 | } |
| 521 | |
| 522 | if (is_volatile) { |
| 523 | return false; |
| 524 | } |
| 525 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 526 | HLoadClass* constant = new (arena_) HLoadClass( |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 527 | storage_index, is_referrers_class, dex_offset); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 528 | current_block_->AddInstruction(constant); |
| 529 | |
| 530 | HInstruction* cls = constant; |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 531 | if (!is_initialized) { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 532 | cls = new (arena_) HClinitCheck(constant, dex_offset); |
| 533 | current_block_->AddInstruction(cls); |
| 534 | } |
| 535 | |
| 536 | if (is_put) { |
| 537 | // We need to keep the class alive before loading the value. |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame^] | 538 | Temporaries temps(graph_); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 539 | temps.Add(cls); |
| 540 | HInstruction* value = LoadLocal(source_or_dest_reg, field_type); |
| 541 | DCHECK_EQ(value->GetType(), field_type); |
| 542 | current_block_->AddInstruction( |
| 543 | new (arena_) HStaticFieldSet(cls, value, field_type, field_offset)); |
| 544 | } else { |
| 545 | current_block_->AddInstruction(new (arena_) HStaticFieldGet(cls, field_type, field_offset)); |
| 546 | UpdateLocal(source_or_dest_reg, current_block_->GetLastInstruction()); |
| 547 | } |
| 548 | return true; |
| 549 | } |
| 550 | |
Calin Juravle | 865fc88 | 2014-11-06 17:09:03 +0000 | [diff] [blame] | 551 | void HGraphBuilder::BuildCheckedDiv(uint16_t out_reg, |
| 552 | uint16_t first_reg, |
Calin Juravle | 0f00db7 | 2014-11-06 18:19:23 +0000 | [diff] [blame] | 553 | int32_t second_reg, |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 554 | uint32_t dex_offset, |
| 555 | Primitive::Type type, |
| 556 | bool second_is_lit) { |
| 557 | DCHECK(type == Primitive::kPrimInt); |
| 558 | |
Calin Juravle | 865fc88 | 2014-11-06 17:09:03 +0000 | [diff] [blame] | 559 | HInstruction* first = LoadLocal(first_reg, type); |
| 560 | HInstruction* second = second_is_lit ? GetIntConstant(second_reg) : LoadLocal(second_reg, type); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 561 | if (!second->IsIntConstant() || (second->AsIntConstant()->GetValue() == 0)) { |
| 562 | second = new (arena_) HDivZeroCheck(second, dex_offset); |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame^] | 563 | Temporaries temps(graph_); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 564 | current_block_->AddInstruction(second); |
| 565 | temps.Add(current_block_->GetLastInstruction()); |
| 566 | } |
| 567 | |
| 568 | current_block_->AddInstruction(new (arena_) HDiv(type, first, second)); |
Calin Juravle | 865fc88 | 2014-11-06 17:09:03 +0000 | [diff] [blame] | 569 | UpdateLocal(out_reg, current_block_->GetLastInstruction()); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 570 | } |
| 571 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 572 | void HGraphBuilder::BuildArrayAccess(const Instruction& instruction, |
| 573 | uint32_t dex_offset, |
| 574 | bool is_put, |
| 575 | Primitive::Type anticipated_type) { |
| 576 | uint8_t source_or_dest_reg = instruction.VRegA_23x(); |
| 577 | uint8_t array_reg = instruction.VRegB_23x(); |
| 578 | uint8_t index_reg = instruction.VRegC_23x(); |
| 579 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 580 | // 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^] | 581 | Temporaries temps(graph_); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 582 | |
| 583 | HInstruction* object = LoadLocal(array_reg, Primitive::kPrimNot); |
| 584 | object = new (arena_) HNullCheck(object, dex_offset); |
| 585 | current_block_->AddInstruction(object); |
| 586 | temps.Add(object); |
| 587 | |
| 588 | HInstruction* length = new (arena_) HArrayLength(object); |
| 589 | current_block_->AddInstruction(length); |
| 590 | temps.Add(length); |
| 591 | HInstruction* index = LoadLocal(index_reg, Primitive::kPrimInt); |
| 592 | index = new (arena_) HBoundsCheck(index, length, dex_offset); |
| 593 | current_block_->AddInstruction(index); |
| 594 | temps.Add(index); |
| 595 | if (is_put) { |
| 596 | HInstruction* value = LoadLocal(source_or_dest_reg, anticipated_type); |
| 597 | // TODO: Insert a type check node if the type is Object. |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 598 | current_block_->AddInstruction(new (arena_) HArraySet( |
| 599 | object, index, value, anticipated_type, dex_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 600 | } else { |
| 601 | current_block_->AddInstruction(new (arena_) HArrayGet(object, index, anticipated_type)); |
| 602 | UpdateLocal(source_or_dest_reg, current_block_->GetLastInstruction()); |
| 603 | } |
| 604 | } |
| 605 | |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 606 | void HGraphBuilder::BuildFilledNewArray(uint32_t dex_offset, |
| 607 | uint32_t type_index, |
| 608 | uint32_t number_of_vreg_arguments, |
| 609 | bool is_range, |
| 610 | uint32_t* args, |
| 611 | uint32_t register_index) { |
| 612 | HInstruction* length = GetIntConstant(number_of_vreg_arguments); |
| 613 | HInstruction* object = new (arena_) HNewArray(length, dex_offset, type_index); |
| 614 | current_block_->AddInstruction(object); |
| 615 | |
| 616 | const char* descriptor = dex_file_->StringByTypeIdx(type_index); |
| 617 | DCHECK_EQ(descriptor[0], '[') << descriptor; |
| 618 | char primitive = descriptor[1]; |
| 619 | DCHECK(primitive == 'I' |
| 620 | || primitive == 'L' |
| 621 | || primitive == '[') << descriptor; |
| 622 | bool is_reference_array = (primitive == 'L') || (primitive == '['); |
| 623 | Primitive::Type type = is_reference_array ? Primitive::kPrimNot : Primitive::kPrimInt; |
| 624 | |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame^] | 625 | Temporaries temps(graph_); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 626 | temps.Add(object); |
| 627 | for (size_t i = 0; i < number_of_vreg_arguments; ++i) { |
| 628 | HInstruction* value = LoadLocal(is_range ? register_index + i : args[i], type); |
| 629 | HInstruction* index = GetIntConstant(i); |
| 630 | current_block_->AddInstruction( |
| 631 | new (arena_) HArraySet(object, index, value, type, dex_offset)); |
| 632 | } |
| 633 | latest_result_ = object; |
| 634 | } |
| 635 | |
| 636 | template <typename T> |
| 637 | void HGraphBuilder::BuildFillArrayData(HInstruction* object, |
| 638 | const T* data, |
| 639 | uint32_t element_count, |
| 640 | Primitive::Type anticipated_type, |
| 641 | uint32_t dex_offset) { |
| 642 | for (uint32_t i = 0; i < element_count; ++i) { |
| 643 | HInstruction* index = GetIntConstant(i); |
| 644 | HInstruction* value = GetIntConstant(data[i]); |
| 645 | current_block_->AddInstruction(new (arena_) HArraySet( |
| 646 | object, index, value, anticipated_type, dex_offset)); |
| 647 | } |
| 648 | } |
| 649 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 650 | void HGraphBuilder::BuildFillArrayData(const Instruction& instruction, uint32_t dex_offset) { |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame^] | 651 | Temporaries temps(graph_); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 652 | HInstruction* array = LoadLocal(instruction.VRegA_31t(), Primitive::kPrimNot); |
| 653 | HNullCheck* null_check = new (arena_) HNullCheck(array, dex_offset); |
| 654 | current_block_->AddInstruction(null_check); |
| 655 | temps.Add(null_check); |
| 656 | |
| 657 | HInstruction* length = new (arena_) HArrayLength(null_check); |
| 658 | current_block_->AddInstruction(length); |
| 659 | |
| 660 | int32_t payload_offset = instruction.VRegB_31t() + dex_offset; |
| 661 | const Instruction::ArrayDataPayload* payload = |
| 662 | reinterpret_cast<const Instruction::ArrayDataPayload*>(code_start_ + payload_offset); |
| 663 | const uint8_t* data = payload->data; |
| 664 | uint32_t element_count = payload->element_count; |
| 665 | |
| 666 | // Implementation of this DEX instruction seems to be that the bounds check is |
| 667 | // done before doing any stores. |
| 668 | HInstruction* last_index = GetIntConstant(payload->element_count - 1); |
| 669 | current_block_->AddInstruction(new (arena_) HBoundsCheck(last_index, length, dex_offset)); |
| 670 | |
| 671 | switch (payload->element_width) { |
| 672 | case 1: |
| 673 | BuildFillArrayData(null_check, |
| 674 | reinterpret_cast<const int8_t*>(data), |
| 675 | element_count, |
| 676 | Primitive::kPrimByte, |
| 677 | dex_offset); |
| 678 | break; |
| 679 | case 2: |
| 680 | BuildFillArrayData(null_check, |
| 681 | reinterpret_cast<const int16_t*>(data), |
| 682 | element_count, |
| 683 | Primitive::kPrimShort, |
| 684 | dex_offset); |
| 685 | break; |
| 686 | case 4: |
| 687 | BuildFillArrayData(null_check, |
| 688 | reinterpret_cast<const int32_t*>(data), |
| 689 | element_count, |
| 690 | Primitive::kPrimInt, |
| 691 | dex_offset); |
| 692 | break; |
| 693 | case 8: |
| 694 | BuildFillWideArrayData(null_check, |
| 695 | reinterpret_cast<const int64_t*>(data), |
| 696 | element_count, |
| 697 | dex_offset); |
| 698 | break; |
| 699 | default: |
| 700 | LOG(FATAL) << "Unknown element width for " << payload->element_width; |
| 701 | } |
| 702 | } |
| 703 | |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 704 | void HGraphBuilder::BuildFillWideArrayData(HInstruction* object, |
Nicolas Geoffray | 8d6ae52 | 2014-10-23 18:32:13 +0100 | [diff] [blame] | 705 | const int64_t* data, |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 706 | uint32_t element_count, |
| 707 | uint32_t dex_offset) { |
| 708 | for (uint32_t i = 0; i < element_count; ++i) { |
| 709 | HInstruction* index = GetIntConstant(i); |
| 710 | HInstruction* value = GetLongConstant(data[i]); |
| 711 | current_block_->AddInstruction(new (arena_) HArraySet( |
| 712 | object, index, value, Primitive::kPrimLong, dex_offset)); |
| 713 | } |
| 714 | } |
| 715 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 716 | bool HGraphBuilder::BuildTypeCheck(const Instruction& instruction, |
| 717 | uint8_t destination, |
| 718 | uint8_t reference, |
| 719 | uint16_t type_index, |
| 720 | uint32_t dex_offset) { |
| 721 | bool type_known_final; |
| 722 | bool type_known_abstract; |
| 723 | bool is_referrers_class; |
| 724 | bool can_access = compiler_driver_->CanAccessTypeWithoutChecks( |
| 725 | dex_compilation_unit_->GetDexMethodIndex(), *dex_file_, type_index, |
| 726 | &type_known_final, &type_known_abstract, &is_referrers_class); |
| 727 | if (!can_access) { |
| 728 | return false; |
| 729 | } |
| 730 | HInstruction* object = LoadLocal(reference, Primitive::kPrimNot); |
| 731 | HLoadClass* cls = new (arena_) HLoadClass(type_index, is_referrers_class, dex_offset); |
| 732 | current_block_->AddInstruction(cls); |
| 733 | // The class needs a temporary before being used by the type check. |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame^] | 734 | Temporaries temps(graph_); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 735 | temps.Add(cls); |
| 736 | if (instruction.Opcode() == Instruction::INSTANCE_OF) { |
| 737 | current_block_->AddInstruction( |
| 738 | new (arena_) HInstanceOf(object, cls, type_known_final, dex_offset)); |
| 739 | UpdateLocal(destination, current_block_->GetLastInstruction()); |
| 740 | } else { |
| 741 | DCHECK_EQ(instruction.Opcode(), Instruction::CHECK_CAST); |
| 742 | current_block_->AddInstruction( |
| 743 | new (arena_) HCheckCast(object, cls, type_known_final, dex_offset)); |
| 744 | } |
| 745 | return true; |
| 746 | } |
| 747 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 748 | void HGraphBuilder::PotentiallyAddSuspendCheck(int32_t target_offset, uint32_t dex_offset) { |
| 749 | if (target_offset <= 0) { |
| 750 | // Unconditionnally add a suspend check to backward branches. We can remove |
| 751 | // them after we recognize loops in the graph. |
| 752 | current_block_->AddInstruction(new (arena_) HSuspendCheck(dex_offset)); |
| 753 | } |
| 754 | } |
| 755 | |
| 756 | bool HGraphBuilder::AnalyzeDexInstruction(const Instruction& instruction, uint32_t dex_offset) { |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 757 | if (current_block_ == nullptr) { |
| 758 | return true; // Dead code |
| 759 | } |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 760 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 761 | switch (instruction.Opcode()) { |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 762 | case Instruction::CONST_4: { |
| 763 | int32_t register_index = instruction.VRegA(); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 764 | HIntConstant* constant = GetIntConstant(instruction.VRegB_11n()); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 765 | UpdateLocal(register_index, constant); |
| 766 | break; |
| 767 | } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 768 | |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 769 | case Instruction::CONST_16: { |
| 770 | int32_t register_index = instruction.VRegA(); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 771 | HIntConstant* constant = GetIntConstant(instruction.VRegB_21s()); |
| 772 | UpdateLocal(register_index, constant); |
| 773 | break; |
| 774 | } |
| 775 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 776 | case Instruction::CONST: { |
| 777 | int32_t register_index = instruction.VRegA(); |
| 778 | HIntConstant* constant = GetIntConstant(instruction.VRegB_31i()); |
| 779 | UpdateLocal(register_index, constant); |
| 780 | break; |
| 781 | } |
| 782 | |
| 783 | case Instruction::CONST_HIGH16: { |
| 784 | int32_t register_index = instruction.VRegA(); |
| 785 | HIntConstant* constant = GetIntConstant(instruction.VRegB_21h() << 16); |
| 786 | UpdateLocal(register_index, constant); |
| 787 | break; |
| 788 | } |
| 789 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 790 | case Instruction::CONST_WIDE_16: { |
| 791 | int32_t register_index = instruction.VRegA(); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 792 | // Get 16 bits of constant value, sign extended to 64 bits. |
| 793 | int64_t value = instruction.VRegB_21s(); |
| 794 | value <<= 48; |
| 795 | value >>= 48; |
| 796 | HLongConstant* constant = GetLongConstant(value); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 797 | UpdateLocal(register_index, constant); |
| 798 | break; |
| 799 | } |
| 800 | |
| 801 | case Instruction::CONST_WIDE_32: { |
| 802 | int32_t register_index = instruction.VRegA(); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 803 | // Get 32 bits of constant value, sign extended to 64 bits. |
| 804 | int64_t value = instruction.VRegB_31i(); |
| 805 | value <<= 32; |
| 806 | value >>= 32; |
| 807 | HLongConstant* constant = GetLongConstant(value); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 808 | UpdateLocal(register_index, constant); |
| 809 | break; |
| 810 | } |
| 811 | |
| 812 | case Instruction::CONST_WIDE: { |
| 813 | int32_t register_index = instruction.VRegA(); |
| 814 | HLongConstant* constant = GetLongConstant(instruction.VRegB_51l()); |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 815 | UpdateLocal(register_index, constant); |
| 816 | break; |
| 817 | } |
| 818 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 819 | case Instruction::CONST_WIDE_HIGH16: { |
| 820 | int32_t register_index = instruction.VRegA(); |
| 821 | int64_t value = static_cast<int64_t>(instruction.VRegB_21h()) << 48; |
| 822 | HLongConstant* constant = GetLongConstant(value); |
| 823 | UpdateLocal(register_index, constant); |
| 824 | break; |
| 825 | } |
| 826 | |
Nicolas Geoffray | dadf317 | 2014-11-07 16:36:02 +0000 | [diff] [blame] | 827 | // Note that the SSA building will refine the types. |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 828 | case Instruction::MOVE: |
| 829 | case Instruction::MOVE_FROM16: |
| 830 | case Instruction::MOVE_16: { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 831 | HInstruction* value = LoadLocal(instruction.VRegB(), Primitive::kPrimInt); |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 832 | UpdateLocal(instruction.VRegA(), value); |
| 833 | break; |
| 834 | } |
| 835 | |
Nicolas Geoffray | dadf317 | 2014-11-07 16:36:02 +0000 | [diff] [blame] | 836 | // Note that the SSA building will refine the types. |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 837 | case Instruction::MOVE_WIDE: |
| 838 | case Instruction::MOVE_WIDE_FROM16: |
| 839 | case Instruction::MOVE_WIDE_16: { |
| 840 | HInstruction* value = LoadLocal(instruction.VRegB(), Primitive::kPrimLong); |
| 841 | UpdateLocal(instruction.VRegA(), value); |
| 842 | break; |
| 843 | } |
| 844 | |
| 845 | case Instruction::MOVE_OBJECT: |
| 846 | case Instruction::MOVE_OBJECT_16: |
| 847 | case Instruction::MOVE_OBJECT_FROM16: { |
| 848 | HInstruction* value = LoadLocal(instruction.VRegB(), Primitive::kPrimNot); |
| 849 | UpdateLocal(instruction.VRegA(), value); |
| 850 | break; |
| 851 | } |
| 852 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 853 | case Instruction::RETURN_VOID: { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 854 | BuildReturn(instruction, Primitive::kPrimVoid); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 855 | break; |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 856 | } |
| 857 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 858 | #define IF_XX(comparison, cond) \ |
| 859 | case Instruction::IF_##cond: If_22t<comparison>(instruction, dex_offset); break; \ |
| 860 | case Instruction::IF_##cond##Z: If_21t<comparison>(instruction, dex_offset); break |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 861 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 862 | IF_XX(HEqual, EQ); |
| 863 | IF_XX(HNotEqual, NE); |
| 864 | IF_XX(HLessThan, LT); |
| 865 | IF_XX(HLessThanOrEqual, LE); |
| 866 | IF_XX(HGreaterThan, GT); |
| 867 | IF_XX(HGreaterThanOrEqual, GE); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 868 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 869 | case Instruction::GOTO: |
| 870 | case Instruction::GOTO_16: |
| 871 | case Instruction::GOTO_32: { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 872 | int32_t offset = instruction.GetTargetOffset(); |
| 873 | PotentiallyAddSuspendCheck(offset, dex_offset); |
| 874 | HBasicBlock* target = FindBlockStartingAt(offset + dex_offset); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 875 | DCHECK(target != nullptr); |
| 876 | current_block_->AddInstruction(new (arena_) HGoto()); |
| 877 | current_block_->AddSuccessor(target); |
| 878 | current_block_ = nullptr; |
| 879 | break; |
| 880 | } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 881 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 882 | case Instruction::RETURN: { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 883 | DCHECK_NE(return_type_, Primitive::kPrimNot); |
| 884 | DCHECK_NE(return_type_, Primitive::kPrimLong); |
| 885 | DCHECK_NE(return_type_, Primitive::kPrimDouble); |
| 886 | BuildReturn(instruction, return_type_); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 887 | break; |
| 888 | } |
| 889 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 890 | case Instruction::RETURN_OBJECT: { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 891 | DCHECK(return_type_ == Primitive::kPrimNot); |
| 892 | BuildReturn(instruction, return_type_); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 893 | break; |
| 894 | } |
| 895 | |
| 896 | case Instruction::RETURN_WIDE: { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 897 | DCHECK(return_type_ == Primitive::kPrimDouble || return_type_ == Primitive::kPrimLong); |
| 898 | BuildReturn(instruction, return_type_); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 899 | break; |
| 900 | } |
| 901 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 902 | case Instruction::INVOKE_DIRECT: |
Nicolas Geoffray | 0d8db99 | 2014-11-11 14:40:10 +0000 | [diff] [blame] | 903 | case Instruction::INVOKE_INTERFACE: |
| 904 | case Instruction::INVOKE_STATIC: |
| 905 | case Instruction::INVOKE_SUPER: |
| 906 | case Instruction::INVOKE_VIRTUAL: { |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 907 | uint32_t method_idx = instruction.VRegB_35c(); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 908 | uint32_t number_of_vreg_arguments = instruction.VRegA_35c(); |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 909 | uint32_t args[5]; |
Ian Rogers | 29a2648 | 2014-05-02 15:27:29 -0700 | [diff] [blame] | 910 | instruction.GetVarArgs(args); |
Nicolas Geoffray | dadf317 | 2014-11-07 16:36:02 +0000 | [diff] [blame] | 911 | if (!BuildInvoke(instruction, dex_offset, method_idx, |
| 912 | number_of_vreg_arguments, false, args, -1)) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 913 | return false; |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 914 | } |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 915 | break; |
| 916 | } |
| 917 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 918 | case Instruction::INVOKE_DIRECT_RANGE: |
Nicolas Geoffray | 0d8db99 | 2014-11-11 14:40:10 +0000 | [diff] [blame] | 919 | case Instruction::INVOKE_INTERFACE_RANGE: |
| 920 | case Instruction::INVOKE_STATIC_RANGE: |
| 921 | case Instruction::INVOKE_SUPER_RANGE: |
| 922 | case Instruction::INVOKE_VIRTUAL_RANGE: { |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 923 | uint32_t method_idx = instruction.VRegB_3rc(); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 924 | uint32_t number_of_vreg_arguments = instruction.VRegA_3rc(); |
| 925 | uint32_t register_index = instruction.VRegC(); |
| 926 | if (!BuildInvoke(instruction, dex_offset, method_idx, |
| 927 | number_of_vreg_arguments, true, nullptr, register_index)) { |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 928 | return false; |
| 929 | } |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 930 | break; |
| 931 | } |
| 932 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 933 | case Instruction::NEG_INT: { |
| 934 | Unop_12x<HNeg>(instruction, Primitive::kPrimInt); |
| 935 | break; |
| 936 | } |
| 937 | |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 938 | case Instruction::NEG_LONG: { |
| 939 | Unop_12x<HNeg>(instruction, Primitive::kPrimLong); |
| 940 | break; |
| 941 | } |
| 942 | |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 943 | case Instruction::NEG_FLOAT: { |
| 944 | Unop_12x<HNeg>(instruction, Primitive::kPrimFloat); |
| 945 | break; |
| 946 | } |
| 947 | |
| 948 | case Instruction::NEG_DOUBLE: { |
| 949 | Unop_12x<HNeg>(instruction, Primitive::kPrimDouble); |
| 950 | break; |
| 951 | } |
| 952 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 953 | case Instruction::NOT_INT: { |
| 954 | Unop_12x<HNot>(instruction, Primitive::kPrimInt); |
| 955 | break; |
| 956 | } |
| 957 | |
Roland Levillain | 7056643 | 2014-10-24 16:20:17 +0100 | [diff] [blame] | 958 | case Instruction::NOT_LONG: { |
| 959 | Unop_12x<HNot>(instruction, Primitive::kPrimLong); |
| 960 | break; |
| 961 | } |
| 962 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 963 | case Instruction::INT_TO_LONG: { |
| 964 | Conversion_12x(instruction, Primitive::kPrimInt, Primitive::kPrimLong); |
| 965 | break; |
| 966 | } |
| 967 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 968 | case Instruction::LONG_TO_INT: { |
| 969 | Conversion_12x(instruction, Primitive::kPrimLong, Primitive::kPrimInt); |
| 970 | break; |
| 971 | } |
| 972 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 973 | case Instruction::ADD_INT: { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 974 | Binop_23x<HAdd>(instruction, Primitive::kPrimInt); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 975 | break; |
| 976 | } |
| 977 | |
| 978 | case Instruction::ADD_LONG: { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 979 | Binop_23x<HAdd>(instruction, Primitive::kPrimLong); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 980 | break; |
| 981 | } |
| 982 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 983 | case Instruction::ADD_DOUBLE: { |
| 984 | Binop_23x<HAdd>(instruction, Primitive::kPrimDouble); |
| 985 | break; |
| 986 | } |
| 987 | |
| 988 | case Instruction::ADD_FLOAT: { |
| 989 | Binop_23x<HAdd>(instruction, Primitive::kPrimFloat); |
| 990 | break; |
| 991 | } |
| 992 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 993 | case Instruction::SUB_INT: { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 994 | Binop_23x<HSub>(instruction, Primitive::kPrimInt); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 995 | break; |
| 996 | } |
| 997 | |
| 998 | case Instruction::SUB_LONG: { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 999 | Binop_23x<HSub>(instruction, Primitive::kPrimLong); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 1000 | break; |
| 1001 | } |
| 1002 | |
Calin Juravle | 096cc02 | 2014-10-23 17:01:13 +0100 | [diff] [blame] | 1003 | case Instruction::SUB_FLOAT: { |
| 1004 | Binop_23x<HSub>(instruction, Primitive::kPrimFloat); |
| 1005 | break; |
| 1006 | } |
| 1007 | |
| 1008 | case Instruction::SUB_DOUBLE: { |
| 1009 | Binop_23x<HSub>(instruction, Primitive::kPrimDouble); |
| 1010 | break; |
| 1011 | } |
| 1012 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 1013 | case Instruction::ADD_INT_2ADDR: { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1014 | Binop_12x<HAdd>(instruction, Primitive::kPrimInt); |
| 1015 | break; |
| 1016 | } |
| 1017 | |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 1018 | case Instruction::MUL_INT: { |
| 1019 | Binop_23x<HMul>(instruction, Primitive::kPrimInt); |
| 1020 | break; |
| 1021 | } |
| 1022 | |
| 1023 | case Instruction::MUL_LONG: { |
| 1024 | Binop_23x<HMul>(instruction, Primitive::kPrimLong); |
| 1025 | break; |
| 1026 | } |
| 1027 | |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 1028 | case Instruction::MUL_FLOAT: { |
| 1029 | Binop_23x<HMul>(instruction, Primitive::kPrimFloat); |
| 1030 | break; |
| 1031 | } |
| 1032 | |
| 1033 | case Instruction::MUL_DOUBLE: { |
| 1034 | Binop_23x<HMul>(instruction, Primitive::kPrimDouble); |
| 1035 | break; |
| 1036 | } |
| 1037 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 1038 | case Instruction::DIV_INT: { |
Calin Juravle | 865fc88 | 2014-11-06 17:09:03 +0000 | [diff] [blame] | 1039 | BuildCheckedDiv(instruction.VRegA(), instruction.VRegB(), instruction.VRegC(), |
| 1040 | dex_offset, Primitive::kPrimInt, false); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 1041 | break; |
| 1042 | } |
| 1043 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1044 | case Instruction::DIV_FLOAT: { |
| 1045 | Binop_23x<HDiv>(instruction, Primitive::kPrimFloat); |
| 1046 | break; |
| 1047 | } |
| 1048 | |
| 1049 | case Instruction::DIV_DOUBLE: { |
| 1050 | Binop_23x<HDiv>(instruction, Primitive::kPrimDouble); |
| 1051 | break; |
| 1052 | } |
| 1053 | |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 1054 | case Instruction::AND_INT: { |
| 1055 | Binop_23x<HAnd>(instruction, Primitive::kPrimInt); |
| 1056 | break; |
| 1057 | } |
| 1058 | |
| 1059 | case Instruction::AND_LONG: { |
| 1060 | Binop_23x<HAnd>(instruction, Primitive::kPrimLong); |
| 1061 | break; |
| 1062 | } |
| 1063 | |
| 1064 | case Instruction::OR_INT: { |
| 1065 | Binop_23x<HOr>(instruction, Primitive::kPrimInt); |
| 1066 | break; |
| 1067 | } |
| 1068 | |
| 1069 | case Instruction::OR_LONG: { |
| 1070 | Binop_23x<HOr>(instruction, Primitive::kPrimLong); |
| 1071 | break; |
| 1072 | } |
| 1073 | |
| 1074 | case Instruction::XOR_INT: { |
| 1075 | Binop_23x<HXor>(instruction, Primitive::kPrimInt); |
| 1076 | break; |
| 1077 | } |
| 1078 | |
| 1079 | case Instruction::XOR_LONG: { |
| 1080 | Binop_23x<HXor>(instruction, Primitive::kPrimLong); |
| 1081 | break; |
| 1082 | } |
| 1083 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1084 | case Instruction::ADD_LONG_2ADDR: { |
| 1085 | Binop_12x<HAdd>(instruction, Primitive::kPrimLong); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 1086 | break; |
| 1087 | } |
| 1088 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1089 | case Instruction::ADD_DOUBLE_2ADDR: { |
| 1090 | Binop_12x<HAdd>(instruction, Primitive::kPrimDouble); |
| 1091 | break; |
| 1092 | } |
| 1093 | |
| 1094 | case Instruction::ADD_FLOAT_2ADDR: { |
| 1095 | Binop_12x<HAdd>(instruction, Primitive::kPrimFloat); |
| 1096 | break; |
| 1097 | } |
| 1098 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 1099 | case Instruction::SUB_INT_2ADDR: { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1100 | Binop_12x<HSub>(instruction, Primitive::kPrimInt); |
| 1101 | break; |
| 1102 | } |
| 1103 | |
| 1104 | case Instruction::SUB_LONG_2ADDR: { |
| 1105 | Binop_12x<HSub>(instruction, Primitive::kPrimLong); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 1106 | break; |
| 1107 | } |
| 1108 | |
Calin Juravle | 096cc02 | 2014-10-23 17:01:13 +0100 | [diff] [blame] | 1109 | case Instruction::SUB_FLOAT_2ADDR: { |
| 1110 | Binop_12x<HSub>(instruction, Primitive::kPrimFloat); |
| 1111 | break; |
| 1112 | } |
| 1113 | |
| 1114 | case Instruction::SUB_DOUBLE_2ADDR: { |
| 1115 | Binop_12x<HSub>(instruction, Primitive::kPrimDouble); |
| 1116 | break; |
| 1117 | } |
| 1118 | |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 1119 | case Instruction::MUL_INT_2ADDR: { |
| 1120 | Binop_12x<HMul>(instruction, Primitive::kPrimInt); |
| 1121 | break; |
| 1122 | } |
| 1123 | |
| 1124 | case Instruction::MUL_LONG_2ADDR: { |
| 1125 | Binop_12x<HMul>(instruction, Primitive::kPrimLong); |
| 1126 | break; |
| 1127 | } |
| 1128 | |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 1129 | case Instruction::MUL_FLOAT_2ADDR: { |
| 1130 | Binop_12x<HMul>(instruction, Primitive::kPrimFloat); |
| 1131 | break; |
| 1132 | } |
| 1133 | |
| 1134 | case Instruction::MUL_DOUBLE_2ADDR: { |
| 1135 | Binop_12x<HMul>(instruction, Primitive::kPrimDouble); |
| 1136 | break; |
| 1137 | } |
| 1138 | |
Calin Juravle | 865fc88 | 2014-11-06 17:09:03 +0000 | [diff] [blame] | 1139 | case Instruction::DIV_INT_2ADDR: { |
| 1140 | BuildCheckedDiv(instruction.VRegA(), instruction.VRegA(), instruction.VRegB(), |
| 1141 | dex_offset, Primitive::kPrimInt, false); |
| 1142 | break; |
| 1143 | } |
| 1144 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1145 | case Instruction::DIV_FLOAT_2ADDR: { |
| 1146 | Binop_12x<HDiv>(instruction, Primitive::kPrimFloat); |
| 1147 | break; |
| 1148 | } |
| 1149 | |
| 1150 | case Instruction::DIV_DOUBLE_2ADDR: { |
| 1151 | Binop_12x<HDiv>(instruction, Primitive::kPrimDouble); |
| 1152 | break; |
| 1153 | } |
| 1154 | |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 1155 | case Instruction::AND_INT_2ADDR: { |
| 1156 | Binop_12x<HAnd>(instruction, Primitive::kPrimInt); |
| 1157 | break; |
| 1158 | } |
| 1159 | |
| 1160 | case Instruction::AND_LONG_2ADDR: { |
| 1161 | Binop_12x<HAnd>(instruction, Primitive::kPrimLong); |
| 1162 | break; |
| 1163 | } |
| 1164 | |
| 1165 | case Instruction::OR_INT_2ADDR: { |
| 1166 | Binop_12x<HOr>(instruction, Primitive::kPrimInt); |
| 1167 | break; |
| 1168 | } |
| 1169 | |
| 1170 | case Instruction::OR_LONG_2ADDR: { |
| 1171 | Binop_12x<HOr>(instruction, Primitive::kPrimLong); |
| 1172 | break; |
| 1173 | } |
| 1174 | |
| 1175 | case Instruction::XOR_INT_2ADDR: { |
| 1176 | Binop_12x<HXor>(instruction, Primitive::kPrimInt); |
| 1177 | break; |
| 1178 | } |
| 1179 | |
| 1180 | case Instruction::XOR_LONG_2ADDR: { |
| 1181 | Binop_12x<HXor>(instruction, Primitive::kPrimLong); |
| 1182 | break; |
| 1183 | } |
| 1184 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 1185 | case Instruction::ADD_INT_LIT16: { |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 1186 | Binop_22s<HAdd>(instruction, false); |
| 1187 | break; |
| 1188 | } |
| 1189 | |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 1190 | case Instruction::AND_INT_LIT16: { |
| 1191 | Binop_22s<HAnd>(instruction, false); |
| 1192 | break; |
| 1193 | } |
| 1194 | |
| 1195 | case Instruction::OR_INT_LIT16: { |
| 1196 | Binop_22s<HOr>(instruction, false); |
| 1197 | break; |
| 1198 | } |
| 1199 | |
| 1200 | case Instruction::XOR_INT_LIT16: { |
| 1201 | Binop_22s<HXor>(instruction, false); |
| 1202 | break; |
| 1203 | } |
| 1204 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 1205 | case Instruction::RSUB_INT: { |
| 1206 | Binop_22s<HSub>(instruction, true); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 1207 | break; |
| 1208 | } |
| 1209 | |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 1210 | case Instruction::MUL_INT_LIT16: { |
| 1211 | Binop_22s<HMul>(instruction, false); |
| 1212 | break; |
| 1213 | } |
| 1214 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 1215 | case Instruction::ADD_INT_LIT8: { |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 1216 | Binop_22b<HAdd>(instruction, false); |
| 1217 | break; |
| 1218 | } |
| 1219 | |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 1220 | case Instruction::AND_INT_LIT8: { |
| 1221 | Binop_22b<HAnd>(instruction, false); |
| 1222 | break; |
| 1223 | } |
| 1224 | |
| 1225 | case Instruction::OR_INT_LIT8: { |
| 1226 | Binop_22b<HOr>(instruction, false); |
| 1227 | break; |
| 1228 | } |
| 1229 | |
| 1230 | case Instruction::XOR_INT_LIT8: { |
| 1231 | Binop_22b<HXor>(instruction, false); |
| 1232 | break; |
| 1233 | } |
| 1234 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 1235 | case Instruction::RSUB_INT_LIT8: { |
| 1236 | Binop_22b<HSub>(instruction, true); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 1237 | break; |
| 1238 | } |
| 1239 | |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 1240 | case Instruction::MUL_INT_LIT8: { |
| 1241 | Binop_22b<HMul>(instruction, false); |
| 1242 | break; |
| 1243 | } |
| 1244 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 1245 | case Instruction::DIV_INT_LIT16: |
| 1246 | case Instruction::DIV_INT_LIT8: { |
Calin Juravle | 865fc88 | 2014-11-06 17:09:03 +0000 | [diff] [blame] | 1247 | BuildCheckedDiv(instruction.VRegA(), instruction.VRegB(), instruction.VRegC(), |
| 1248 | dex_offset, Primitive::kPrimInt, true); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 1249 | break; |
| 1250 | } |
| 1251 | |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 1252 | case Instruction::NEW_INSTANCE: { |
| 1253 | current_block_->AddInstruction( |
| 1254 | new (arena_) HNewInstance(dex_offset, instruction.VRegB_21c())); |
| 1255 | UpdateLocal(instruction.VRegA(), current_block_->GetLastInstruction()); |
| 1256 | break; |
| 1257 | } |
| 1258 | |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 1259 | case Instruction::NEW_ARRAY: { |
| 1260 | HInstruction* length = LoadLocal(instruction.VRegB_22c(), Primitive::kPrimInt); |
| 1261 | current_block_->AddInstruction( |
| 1262 | new (arena_) HNewArray(length, dex_offset, instruction.VRegC_22c())); |
| 1263 | UpdateLocal(instruction.VRegA_22c(), current_block_->GetLastInstruction()); |
| 1264 | break; |
| 1265 | } |
| 1266 | |
| 1267 | case Instruction::FILLED_NEW_ARRAY: { |
| 1268 | uint32_t number_of_vreg_arguments = instruction.VRegA_35c(); |
| 1269 | uint32_t type_index = instruction.VRegB_35c(); |
| 1270 | uint32_t args[5]; |
| 1271 | instruction.GetVarArgs(args); |
| 1272 | BuildFilledNewArray(dex_offset, type_index, number_of_vreg_arguments, false, args, 0); |
| 1273 | break; |
| 1274 | } |
| 1275 | |
| 1276 | case Instruction::FILLED_NEW_ARRAY_RANGE: { |
| 1277 | uint32_t number_of_vreg_arguments = instruction.VRegA_3rc(); |
| 1278 | uint32_t type_index = instruction.VRegB_3rc(); |
| 1279 | uint32_t register_index = instruction.VRegC_3rc(); |
| 1280 | BuildFilledNewArray( |
| 1281 | dex_offset, type_index, number_of_vreg_arguments, true, nullptr, register_index); |
| 1282 | break; |
| 1283 | } |
| 1284 | |
| 1285 | case Instruction::FILL_ARRAY_DATA: { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 1286 | BuildFillArrayData(instruction, dex_offset); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 1287 | break; |
| 1288 | } |
| 1289 | |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 1290 | case Instruction::MOVE_RESULT: |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1291 | case Instruction::MOVE_RESULT_WIDE: |
| 1292 | case Instruction::MOVE_RESULT_OBJECT: |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 1293 | UpdateLocal(instruction.VRegA(), latest_result_); |
| 1294 | latest_result_ = nullptr; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1295 | break; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1296 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1297 | case Instruction::CMP_LONG: { |
| 1298 | Binop_23x<HCompare>(instruction, Primitive::kPrimLong); |
| 1299 | break; |
| 1300 | } |
| 1301 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 1302 | case Instruction::NOP: |
| 1303 | break; |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1304 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1305 | case Instruction::IGET: |
| 1306 | case Instruction::IGET_WIDE: |
| 1307 | case Instruction::IGET_OBJECT: |
| 1308 | case Instruction::IGET_BOOLEAN: |
| 1309 | case Instruction::IGET_BYTE: |
| 1310 | case Instruction::IGET_CHAR: |
| 1311 | case Instruction::IGET_SHORT: { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 1312 | if (!BuildInstanceFieldAccess(instruction, dex_offset, false)) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1313 | return false; |
| 1314 | } |
| 1315 | break; |
| 1316 | } |
| 1317 | |
| 1318 | case Instruction::IPUT: |
| 1319 | case Instruction::IPUT_WIDE: |
| 1320 | case Instruction::IPUT_OBJECT: |
| 1321 | case Instruction::IPUT_BOOLEAN: |
| 1322 | case Instruction::IPUT_BYTE: |
| 1323 | case Instruction::IPUT_CHAR: |
| 1324 | case Instruction::IPUT_SHORT: { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 1325 | if (!BuildInstanceFieldAccess(instruction, dex_offset, true)) { |
| 1326 | return false; |
| 1327 | } |
| 1328 | break; |
| 1329 | } |
| 1330 | |
| 1331 | case Instruction::SGET: |
| 1332 | case Instruction::SGET_WIDE: |
| 1333 | case Instruction::SGET_OBJECT: |
| 1334 | case Instruction::SGET_BOOLEAN: |
| 1335 | case Instruction::SGET_BYTE: |
| 1336 | case Instruction::SGET_CHAR: |
| 1337 | case Instruction::SGET_SHORT: { |
| 1338 | if (!BuildStaticFieldAccess(instruction, dex_offset, false)) { |
| 1339 | return false; |
| 1340 | } |
| 1341 | break; |
| 1342 | } |
| 1343 | |
| 1344 | case Instruction::SPUT: |
| 1345 | case Instruction::SPUT_WIDE: |
| 1346 | case Instruction::SPUT_OBJECT: |
| 1347 | case Instruction::SPUT_BOOLEAN: |
| 1348 | case Instruction::SPUT_BYTE: |
| 1349 | case Instruction::SPUT_CHAR: |
| 1350 | case Instruction::SPUT_SHORT: { |
| 1351 | if (!BuildStaticFieldAccess(instruction, dex_offset, true)) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1352 | return false; |
| 1353 | } |
| 1354 | break; |
| 1355 | } |
| 1356 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1357 | #define ARRAY_XX(kind, anticipated_type) \ |
| 1358 | case Instruction::AGET##kind: { \ |
| 1359 | BuildArrayAccess(instruction, dex_offset, false, anticipated_type); \ |
| 1360 | break; \ |
| 1361 | } \ |
| 1362 | case Instruction::APUT##kind: { \ |
| 1363 | BuildArrayAccess(instruction, dex_offset, true, anticipated_type); \ |
| 1364 | break; \ |
| 1365 | } |
| 1366 | |
| 1367 | ARRAY_XX(, Primitive::kPrimInt); |
| 1368 | ARRAY_XX(_WIDE, Primitive::kPrimLong); |
| 1369 | ARRAY_XX(_OBJECT, Primitive::kPrimNot); |
| 1370 | ARRAY_XX(_BOOLEAN, Primitive::kPrimBoolean); |
| 1371 | ARRAY_XX(_BYTE, Primitive::kPrimByte); |
| 1372 | ARRAY_XX(_CHAR, Primitive::kPrimChar); |
| 1373 | ARRAY_XX(_SHORT, Primitive::kPrimShort); |
| 1374 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1375 | case Instruction::ARRAY_LENGTH: { |
| 1376 | HInstruction* object = LoadLocal(instruction.VRegB_12x(), Primitive::kPrimNot); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 1377 | // No need for a temporary for the null check, it is the only input of the following |
| 1378 | // instruction. |
| 1379 | object = new (arena_) HNullCheck(object, dex_offset); |
| 1380 | current_block_->AddInstruction(object); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1381 | current_block_->AddInstruction(new (arena_) HArrayLength(object)); |
| 1382 | UpdateLocal(instruction.VRegA_12x(), current_block_->GetLastInstruction()); |
| 1383 | break; |
| 1384 | } |
| 1385 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 1386 | case Instruction::CONST_STRING: { |
| 1387 | current_block_->AddInstruction(new (arena_) HLoadString(instruction.VRegB_21c(), dex_offset)); |
| 1388 | UpdateLocal(instruction.VRegA_21c(), current_block_->GetLastInstruction()); |
| 1389 | break; |
| 1390 | } |
| 1391 | |
| 1392 | case Instruction::CONST_STRING_JUMBO: { |
| 1393 | current_block_->AddInstruction(new (arena_) HLoadString(instruction.VRegB_31c(), dex_offset)); |
| 1394 | UpdateLocal(instruction.VRegA_31c(), current_block_->GetLastInstruction()); |
| 1395 | break; |
| 1396 | } |
| 1397 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 1398 | case Instruction::CONST_CLASS: { |
| 1399 | uint16_t type_index = instruction.VRegB_21c(); |
| 1400 | bool type_known_final; |
| 1401 | bool type_known_abstract; |
| 1402 | bool is_referrers_class; |
| 1403 | bool can_access = compiler_driver_->CanAccessTypeWithoutChecks( |
| 1404 | dex_compilation_unit_->GetDexMethodIndex(), *dex_file_, type_index, |
| 1405 | &type_known_final, &type_known_abstract, &is_referrers_class); |
| 1406 | if (!can_access) { |
| 1407 | return false; |
| 1408 | } |
| 1409 | current_block_->AddInstruction( |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 1410 | new (arena_) HLoadClass(type_index, is_referrers_class, dex_offset)); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 1411 | UpdateLocal(instruction.VRegA_21c(), current_block_->GetLastInstruction()); |
| 1412 | break; |
| 1413 | } |
| 1414 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 1415 | case Instruction::MOVE_EXCEPTION: { |
| 1416 | current_block_->AddInstruction(new (arena_) HLoadException()); |
| 1417 | UpdateLocal(instruction.VRegA_11x(), current_block_->GetLastInstruction()); |
| 1418 | break; |
| 1419 | } |
| 1420 | |
| 1421 | case Instruction::THROW: { |
| 1422 | HInstruction* exception = LoadLocal(instruction.VRegA_11x(), Primitive::kPrimNot); |
| 1423 | current_block_->AddInstruction(new (arena_) HThrow(exception, dex_offset)); |
| 1424 | // A throw instruction must branch to the exit block. |
| 1425 | current_block_->AddSuccessor(exit_block_); |
| 1426 | // We finished building this block. Set the current block to null to avoid |
| 1427 | // adding dead instructions to it. |
| 1428 | current_block_ = nullptr; |
| 1429 | break; |
| 1430 | } |
| 1431 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 1432 | case Instruction::INSTANCE_OF: { |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 1433 | uint8_t destination = instruction.VRegA_22c(); |
| 1434 | uint8_t reference = instruction.VRegB_22c(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 1435 | uint16_t type_index = instruction.VRegC_22c(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 1436 | if (!BuildTypeCheck(instruction, destination, reference, type_index, dex_offset)) { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 1437 | return false; |
| 1438 | } |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 1439 | break; |
| 1440 | } |
| 1441 | |
| 1442 | case Instruction::CHECK_CAST: { |
| 1443 | uint8_t reference = instruction.VRegA_21c(); |
| 1444 | uint16_t type_index = instruction.VRegB_21c(); |
| 1445 | if (!BuildTypeCheck(instruction, -1, reference, type_index, dex_offset)) { |
| 1446 | return false; |
| 1447 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 1448 | break; |
| 1449 | } |
| 1450 | |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 1451 | case Instruction::MONITOR_ENTER: { |
| 1452 | current_block_->AddInstruction(new (arena_) HMonitorOperation( |
| 1453 | LoadLocal(instruction.VRegA_11x(), Primitive::kPrimNot), |
| 1454 | HMonitorOperation::kEnter, |
| 1455 | dex_offset)); |
| 1456 | break; |
| 1457 | } |
| 1458 | |
| 1459 | case Instruction::MONITOR_EXIT: { |
| 1460 | current_block_->AddInstruction(new (arena_) HMonitorOperation( |
| 1461 | LoadLocal(instruction.VRegA_11x(), Primitive::kPrimNot), |
| 1462 | HMonitorOperation::kExit, |
| 1463 | dex_offset)); |
| 1464 | break; |
| 1465 | } |
| 1466 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1467 | default: |
| 1468 | return false; |
| 1469 | } |
| 1470 | return true; |
Nicolas Geoffray | dadf317 | 2014-11-07 16:36:02 +0000 | [diff] [blame] | 1471 | } // NOLINT(readability/fn_size) |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1472 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1473 | HIntConstant* HGraphBuilder::GetIntConstant0() { |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1474 | if (constant0_ != nullptr) { |
| 1475 | return constant0_; |
| 1476 | } |
| 1477 | constant0_ = new(arena_) HIntConstant(0); |
| 1478 | entry_block_->AddInstruction(constant0_); |
| 1479 | return constant0_; |
| 1480 | } |
| 1481 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1482 | HIntConstant* HGraphBuilder::GetIntConstant1() { |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1483 | if (constant1_ != nullptr) { |
| 1484 | return constant1_; |
| 1485 | } |
| 1486 | constant1_ = new(arena_) HIntConstant(1); |
| 1487 | entry_block_->AddInstruction(constant1_); |
| 1488 | return constant1_; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1489 | } |
| 1490 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1491 | HIntConstant* HGraphBuilder::GetIntConstant(int32_t constant) { |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1492 | switch (constant) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1493 | case 0: return GetIntConstant0(); |
| 1494 | case 1: return GetIntConstant1(); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1495 | default: { |
| 1496 | HIntConstant* instruction = new (arena_) HIntConstant(constant); |
| 1497 | entry_block_->AddInstruction(instruction); |
| 1498 | return instruction; |
| 1499 | } |
| 1500 | } |
| 1501 | } |
| 1502 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1503 | HLongConstant* HGraphBuilder::GetLongConstant(int64_t constant) { |
| 1504 | HLongConstant* instruction = new (arena_) HLongConstant(constant); |
| 1505 | entry_block_->AddInstruction(instruction); |
| 1506 | return instruction; |
| 1507 | } |
| 1508 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1509 | HLocal* HGraphBuilder::GetLocalAt(int register_index) const { |
| 1510 | return locals_.Get(register_index); |
| 1511 | } |
| 1512 | |
| 1513 | void HGraphBuilder::UpdateLocal(int register_index, HInstruction* instruction) const { |
| 1514 | HLocal* local = GetLocalAt(register_index); |
| 1515 | current_block_->AddInstruction(new (arena_) HStoreLocal(local, instruction)); |
| 1516 | } |
| 1517 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1518 | HInstruction* HGraphBuilder::LoadLocal(int register_index, Primitive::Type type) const { |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1519 | HLocal* local = GetLocalAt(register_index); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1520 | current_block_->AddInstruction(new (arena_) HLoadLocal(local, type)); |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1521 | return current_block_->GetLastInstruction(); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1522 | } |
| 1523 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1524 | } // namespace art |