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