Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1 | /* |
| 2 | * |
| 3 | * Copyright (C) 2014 The Android Open Source Project |
| 4 | * |
| 5 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | * you may not use this file except in compliance with the License. |
| 7 | * You may obtain a copy of the License at |
| 8 | * |
| 9 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | * |
| 11 | * Unless required by applicable law or agreed to in writing, software |
| 12 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | * See the License for the specific language governing permissions and |
| 15 | * limitations under the License. |
| 16 | */ |
| 17 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 18 | #include "builder.h" |
| 19 | |
| 20 | #include "class_linker.h" |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 21 | #include "dex_file.h" |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 22 | #include "dex_file-inl.h" |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 23 | #include "dex_instruction.h" |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 24 | #include "dex_instruction-inl.h" |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 25 | #include "driver/compiler_driver-inl.h" |
| 26 | #include "mirror/art_field.h" |
| 27 | #include "mirror/art_field-inl.h" |
| 28 | #include "mirror/class_loader.h" |
| 29 | #include "mirror/dex_cache.h" |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 30 | #include "nodes.h" |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 31 | #include "primitive.h" |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 32 | #include "scoped_thread_state_change.h" |
| 33 | #include "thread.h" |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 34 | |
| 35 | namespace art { |
| 36 | |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 37 | /** |
| 38 | * Helper class to add HTemporary instructions. This class is used when |
| 39 | * converting a DEX instruction to multiple HInstruction, and where those |
| 40 | * instructions do not die at the following instruction, but instead spans |
| 41 | * multiple instructions. |
| 42 | */ |
| 43 | class Temporaries : public ValueObject { |
| 44 | public: |
| 45 | Temporaries(HGraph* graph, size_t count) : graph_(graph), count_(count), index_(0) { |
| 46 | graph_->UpdateNumberOfTemporaries(count_); |
| 47 | } |
| 48 | |
| 49 | void Add(HInstruction* instruction) { |
| 50 | // We currently only support vreg size temps. |
| 51 | DCHECK(instruction->GetType() != Primitive::kPrimLong |
| 52 | && instruction->GetType() != Primitive::kPrimDouble); |
| 53 | HInstruction* temp = new (graph_->GetArena()) HTemporary(index_++); |
| 54 | instruction->GetBlock()->AddInstruction(temp); |
| 55 | DCHECK(temp->GetPrevious() == instruction); |
| 56 | } |
| 57 | |
| 58 | private: |
| 59 | HGraph* const graph_; |
| 60 | |
| 61 | // The total number of temporaries that will be used. |
| 62 | const size_t count_; |
| 63 | |
| 64 | // Current index in the temporary stack, updated by `Add`. |
| 65 | size_t index_; |
| 66 | }; |
| 67 | |
Nicolas Geoffray | abed4d0 | 2014-07-14 15:24:11 +0100 | [diff] [blame] | 68 | static bool IsTypeSupported(Primitive::Type type) { |
| 69 | return type != Primitive::kPrimFloat && type != Primitive::kPrimDouble; |
| 70 | } |
| 71 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 72 | void HGraphBuilder::InitializeLocals(uint16_t count) { |
| 73 | graph_->SetNumberOfVRegs(count); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 74 | locals_.SetSize(count); |
| 75 | for (int i = 0; i < count; i++) { |
| 76 | HLocal* local = new (arena_) HLocal(i); |
| 77 | entry_block_->AddInstruction(local); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 78 | locals_.Put(i, local); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 79 | } |
| 80 | } |
| 81 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 82 | bool HGraphBuilder::InitializeParameters(uint16_t number_of_parameters) { |
| 83 | // dex_compilation_unit_ is null only when unit testing. |
| 84 | if (dex_compilation_unit_ == nullptr) { |
| 85 | return true; |
| 86 | } |
| 87 | |
| 88 | graph_->SetNumberOfInVRegs(number_of_parameters); |
| 89 | const char* shorty = dex_compilation_unit_->GetShorty(); |
| 90 | int locals_index = locals_.Size() - number_of_parameters; |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 91 | int parameter_index = 0; |
| 92 | |
| 93 | if (!dex_compilation_unit_->IsStatic()) { |
| 94 | // Add the implicit 'this' argument, not expressed in the signature. |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 95 | HParameterValue* parameter = |
| 96 | new (arena_) HParameterValue(parameter_index++, Primitive::kPrimNot); |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 97 | entry_block_->AddInstruction(parameter); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 98 | HLocal* local = GetLocalAt(locals_index++); |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 99 | entry_block_->AddInstruction(new (arena_) HStoreLocal(local, parameter)); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 100 | number_of_parameters--; |
| 101 | } |
| 102 | |
| 103 | uint32_t pos = 1; |
| 104 | for (int i = 0; i < number_of_parameters; i++) { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 105 | HParameterValue* parameter = |
| 106 | new (arena_) HParameterValue(parameter_index++, Primitive::GetType(shorty[pos++])); |
| 107 | entry_block_->AddInstruction(parameter); |
| 108 | HLocal* local = GetLocalAt(locals_index++); |
| 109 | // Store the parameter value in the local that the dex code will use |
| 110 | // to reference that parameter. |
| 111 | entry_block_->AddInstruction(new (arena_) HStoreLocal(local, parameter)); |
| 112 | bool is_wide = (parameter->GetType() == Primitive::kPrimLong) |
| 113 | || (parameter->GetType() == Primitive::kPrimDouble); |
| 114 | if (is_wide) { |
| 115 | i++; |
| 116 | locals_index++; |
| 117 | parameter_index++; |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 118 | } |
| 119 | } |
| 120 | return true; |
| 121 | } |
| 122 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 123 | static bool CanHandleCodeItem(const DexFile::CodeItem& code_item) { |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 124 | if (code_item.tries_size_ > 0) { |
| 125 | return false; |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 126 | } |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 127 | return true; |
| 128 | } |
| 129 | |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 130 | template<typename T> |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 131 | void HGraphBuilder::If_22t(const Instruction& instruction, uint32_t dex_offset) { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 132 | int32_t target_offset = instruction.GetTargetOffset(); |
| 133 | PotentiallyAddSuspendCheck(target_offset, dex_offset); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 134 | HInstruction* first = LoadLocal(instruction.VRegA(), Primitive::kPrimInt); |
| 135 | HInstruction* second = LoadLocal(instruction.VRegB(), Primitive::kPrimInt); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 136 | T* comparison = new (arena_) T(first, second); |
| 137 | current_block_->AddInstruction(comparison); |
| 138 | HInstruction* ifinst = new (arena_) HIf(comparison); |
| 139 | current_block_->AddInstruction(ifinst); |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 140 | HBasicBlock* target = FindBlockStartingAt(dex_offset + target_offset); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 141 | DCHECK(target != nullptr); |
| 142 | current_block_->AddSuccessor(target); |
| 143 | target = FindBlockStartingAt(dex_offset + instruction.SizeInCodeUnits()); |
| 144 | DCHECK(target != nullptr); |
| 145 | current_block_->AddSuccessor(target); |
| 146 | current_block_ = nullptr; |
| 147 | } |
| 148 | |
| 149 | template<typename T> |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 150 | void HGraphBuilder::If_21t(const Instruction& instruction, uint32_t dex_offset) { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 151 | int32_t target_offset = instruction.GetTargetOffset(); |
| 152 | PotentiallyAddSuspendCheck(target_offset, dex_offset); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 153 | HInstruction* value = LoadLocal(instruction.VRegA(), Primitive::kPrimInt); |
| 154 | T* comparison = new (arena_) T(value, GetIntConstant(0)); |
| 155 | current_block_->AddInstruction(comparison); |
| 156 | HInstruction* ifinst = new (arena_) HIf(comparison); |
| 157 | current_block_->AddInstruction(ifinst); |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 158 | HBasicBlock* target = FindBlockStartingAt(dex_offset + target_offset); |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 159 | DCHECK(target != nullptr); |
| 160 | current_block_->AddSuccessor(target); |
| 161 | target = FindBlockStartingAt(dex_offset + instruction.SizeInCodeUnits()); |
| 162 | DCHECK(target != nullptr); |
| 163 | current_block_->AddSuccessor(target); |
| 164 | current_block_ = nullptr; |
| 165 | } |
| 166 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 167 | HGraph* HGraphBuilder::BuildGraph(const DexFile::CodeItem& code_item) { |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 168 | if (!CanHandleCodeItem(code_item)) { |
| 169 | return nullptr; |
| 170 | } |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 171 | |
| 172 | const uint16_t* code_ptr = code_item.insns_; |
| 173 | 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] | 174 | code_start_ = code_ptr; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 175 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 176 | // Setup the graph with the entry block and exit block. |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 177 | graph_ = new (arena_) HGraph(arena_); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 178 | entry_block_ = new (arena_) HBasicBlock(graph_, 0); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 179 | graph_->AddBlock(entry_block_); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 180 | exit_block_ = new (arena_) HBasicBlock(graph_, kNoDexPc); |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 181 | graph_->SetEntryBlock(entry_block_); |
| 182 | graph_->SetExitBlock(exit_block_); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 183 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 184 | InitializeLocals(code_item.registers_size_); |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 185 | graph_->UpdateMaximumNumberOfOutVRegs(code_item.outs_size_); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 186 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 187 | // To avoid splitting blocks, we compute ahead of time the instructions that |
| 188 | // start a new block, and create these blocks. |
| 189 | ComputeBranchTargets(code_ptr, code_end); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 190 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 191 | if (!InitializeParameters(code_item.ins_size_)) { |
| 192 | return nullptr; |
| 193 | } |
| 194 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 195 | size_t dex_offset = 0; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 196 | while (code_ptr < code_end) { |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 197 | // Update the current block if dex_offset starts a new block. |
| 198 | MaybeUpdateCurrentBlock(dex_offset); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 199 | const Instruction& instruction = *Instruction::At(code_ptr); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 200 | if (!AnalyzeDexInstruction(instruction, dex_offset)) return nullptr; |
| 201 | dex_offset += instruction.SizeInCodeUnits(); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 202 | code_ptr += instruction.SizeInCodeUnits(); |
| 203 | } |
| 204 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 205 | // 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] | 206 | graph_->AddBlock(exit_block_); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 207 | exit_block_->AddInstruction(new (arena_) HExit()); |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 208 | // Add the suspend check to the entry block. |
| 209 | entry_block_->AddInstruction(new (arena_) HSuspendCheck(0)); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 210 | entry_block_->AddInstruction(new (arena_) HGoto()); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 211 | return graph_; |
| 212 | } |
| 213 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 214 | void HGraphBuilder::MaybeUpdateCurrentBlock(size_t index) { |
| 215 | HBasicBlock* block = FindBlockStartingAt(index); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 216 | if (block == nullptr) { |
| 217 | return; |
| 218 | } |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 219 | |
| 220 | if (current_block_ != nullptr) { |
| 221 | // Branching instructions clear current_block, so we know |
| 222 | // the last instruction of the current block is not a branching |
| 223 | // instruction. We add an unconditional goto to the found block. |
| 224 | current_block_->AddInstruction(new (arena_) HGoto()); |
| 225 | current_block_->AddSuccessor(block); |
| 226 | } |
| 227 | graph_->AddBlock(block); |
| 228 | current_block_ = block; |
| 229 | } |
| 230 | |
| 231 | void HGraphBuilder::ComputeBranchTargets(const uint16_t* code_ptr, const uint16_t* code_end) { |
| 232 | // TODO: Support switch instructions. |
| 233 | branch_targets_.SetSize(code_end - code_ptr); |
| 234 | |
| 235 | // 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] | 236 | HBasicBlock* block = new (arena_) HBasicBlock(graph_, 0); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 237 | branch_targets_.Put(0, block); |
| 238 | entry_block_->AddSuccessor(block); |
| 239 | |
| 240 | // Iterate over all instructions and find branching instructions. Create blocks for |
| 241 | // the locations these instructions branch to. |
| 242 | size_t dex_offset = 0; |
| 243 | while (code_ptr < code_end) { |
| 244 | const Instruction& instruction = *Instruction::At(code_ptr); |
| 245 | if (instruction.IsBranch()) { |
| 246 | int32_t target = instruction.GetTargetOffset() + dex_offset; |
| 247 | // Create a block for the target instruction. |
| 248 | if (FindBlockStartingAt(target) == nullptr) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 249 | block = new (arena_) HBasicBlock(graph_, target); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 250 | branch_targets_.Put(target, block); |
| 251 | } |
| 252 | dex_offset += instruction.SizeInCodeUnits(); |
| 253 | code_ptr += instruction.SizeInCodeUnits(); |
| 254 | if ((code_ptr < code_end) && (FindBlockStartingAt(dex_offset) == nullptr)) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 255 | block = new (arena_) HBasicBlock(graph_, dex_offset); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 256 | branch_targets_.Put(dex_offset, block); |
| 257 | } |
| 258 | } else { |
| 259 | code_ptr += instruction.SizeInCodeUnits(); |
| 260 | dex_offset += instruction.SizeInCodeUnits(); |
| 261 | } |
| 262 | } |
| 263 | } |
| 264 | |
| 265 | HBasicBlock* HGraphBuilder::FindBlockStartingAt(int32_t index) const { |
| 266 | DCHECK_GE(index, 0); |
| 267 | return branch_targets_.Get(index); |
| 268 | } |
| 269 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 270 | template<typename T> |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 271 | void HGraphBuilder::Unop_12x(const Instruction& instruction, Primitive::Type type) { |
| 272 | HInstruction* first = LoadLocal(instruction.VRegB(), type); |
| 273 | current_block_->AddInstruction(new (arena_) T(type, first)); |
| 274 | UpdateLocal(instruction.VRegA(), current_block_->GetLastInstruction()); |
| 275 | } |
| 276 | |
| 277 | template<typename T> |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 278 | void HGraphBuilder::Binop_23x(const Instruction& instruction, Primitive::Type type) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 279 | HInstruction* first = LoadLocal(instruction.VRegB(), type); |
| 280 | HInstruction* second = LoadLocal(instruction.VRegC(), type); |
| 281 | current_block_->AddInstruction(new (arena_) T(type, first, second)); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 282 | UpdateLocal(instruction.VRegA(), current_block_->GetLastInstruction()); |
| 283 | } |
| 284 | |
| 285 | template<typename T> |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 286 | void HGraphBuilder::Binop_12x(const Instruction& instruction, Primitive::Type type) { |
| 287 | HInstruction* first = LoadLocal(instruction.VRegA(), type); |
| 288 | HInstruction* second = LoadLocal(instruction.VRegB(), type); |
| 289 | current_block_->AddInstruction(new (arena_) T(type, first, second)); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 290 | UpdateLocal(instruction.VRegA(), current_block_->GetLastInstruction()); |
| 291 | } |
| 292 | |
| 293 | template<typename T> |
| 294 | void HGraphBuilder::Binop_22s(const Instruction& instruction, bool reverse) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 295 | HInstruction* first = LoadLocal(instruction.VRegB(), Primitive::kPrimInt); |
| 296 | HInstruction* second = GetIntConstant(instruction.VRegC_22s()); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 297 | if (reverse) { |
| 298 | std::swap(first, second); |
| 299 | } |
| 300 | current_block_->AddInstruction(new (arena_) T(Primitive::kPrimInt, first, second)); |
| 301 | UpdateLocal(instruction.VRegA(), current_block_->GetLastInstruction()); |
| 302 | } |
| 303 | |
| 304 | template<typename T> |
| 305 | void HGraphBuilder::Binop_22b(const Instruction& instruction, bool reverse) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 306 | HInstruction* first = LoadLocal(instruction.VRegB(), Primitive::kPrimInt); |
| 307 | HInstruction* second = GetIntConstant(instruction.VRegC_22b()); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 308 | if (reverse) { |
| 309 | std::swap(first, second); |
| 310 | } |
| 311 | current_block_->AddInstruction(new (arena_) T(Primitive::kPrimInt, first, second)); |
| 312 | UpdateLocal(instruction.VRegA(), current_block_->GetLastInstruction()); |
| 313 | } |
| 314 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 315 | void HGraphBuilder::BuildReturn(const Instruction& instruction, Primitive::Type type) { |
| 316 | if (type == Primitive::kPrimVoid) { |
| 317 | current_block_->AddInstruction(new (arena_) HReturnVoid()); |
| 318 | } else { |
| 319 | HInstruction* value = LoadLocal(instruction.VRegA(), type); |
| 320 | current_block_->AddInstruction(new (arena_) HReturn(value)); |
| 321 | } |
| 322 | current_block_->AddSuccessor(exit_block_); |
| 323 | current_block_ = nullptr; |
| 324 | } |
| 325 | |
| 326 | bool HGraphBuilder::BuildInvoke(const Instruction& instruction, |
| 327 | uint32_t dex_offset, |
| 328 | uint32_t method_idx, |
| 329 | uint32_t number_of_vreg_arguments, |
| 330 | bool is_range, |
| 331 | uint32_t* args, |
| 332 | uint32_t register_index) { |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 333 | Instruction::Code opcode = instruction.Opcode(); |
| 334 | InvokeType invoke_type; |
| 335 | switch (opcode) { |
| 336 | case Instruction::INVOKE_STATIC: |
| 337 | case Instruction::INVOKE_STATIC_RANGE: |
| 338 | invoke_type = kStatic; |
| 339 | break; |
| 340 | case Instruction::INVOKE_DIRECT: |
| 341 | case Instruction::INVOKE_DIRECT_RANGE: |
| 342 | invoke_type = kDirect; |
| 343 | break; |
| 344 | case Instruction::INVOKE_VIRTUAL: |
| 345 | case Instruction::INVOKE_VIRTUAL_RANGE: |
| 346 | invoke_type = kVirtual; |
| 347 | break; |
| 348 | case Instruction::INVOKE_INTERFACE: |
| 349 | case Instruction::INVOKE_INTERFACE_RANGE: |
| 350 | invoke_type = kInterface; |
| 351 | break; |
| 352 | case Instruction::INVOKE_SUPER_RANGE: |
| 353 | case Instruction::INVOKE_SUPER: |
| 354 | invoke_type = kSuper; |
| 355 | break; |
| 356 | default: |
| 357 | LOG(FATAL) << "Unexpected invoke op: " << opcode; |
| 358 | return false; |
| 359 | } |
| 360 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 361 | const DexFile::MethodId& method_id = dex_file_->GetMethodId(method_idx); |
| 362 | const DexFile::ProtoId& proto_id = dex_file_->GetProtoId(method_id.proto_idx_); |
| 363 | const char* descriptor = dex_file_->StringDataByIdx(proto_id.shorty_idx_); |
| 364 | Primitive::Type return_type = Primitive::GetType(descriptor[0]); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 365 | bool is_instance_call = invoke_type != kStatic; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 366 | const size_t number_of_arguments = strlen(descriptor) - (is_instance_call ? 0 : 1); |
| 367 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 368 | HInvoke* invoke = nullptr; |
| 369 | if (invoke_type == kVirtual) { |
| 370 | MethodReference target_method(dex_file_, method_idx); |
| 371 | uintptr_t direct_code; |
| 372 | uintptr_t direct_method; |
| 373 | int vtable_index; |
| 374 | // TODO: Add devirtualization support. |
| 375 | compiler_driver_->ComputeInvokeInfo(dex_compilation_unit_, dex_offset, true, true, |
| 376 | &invoke_type, &target_method, &vtable_index, |
| 377 | &direct_code, &direct_method); |
| 378 | if (vtable_index == -1) { |
| 379 | return false; |
| 380 | } |
| 381 | invoke = new (arena_) HInvokeVirtual( |
| 382 | arena_, number_of_arguments, return_type, dex_offset, vtable_index); |
| 383 | } else { |
| 384 | // Treat invoke-direct like static calls for now. |
| 385 | invoke = new (arena_) HInvokeStatic( |
| 386 | arena_, number_of_arguments, return_type, dex_offset, method_idx); |
| 387 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 388 | |
| 389 | size_t start_index = 0; |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 390 | Temporaries temps(graph_, is_instance_call ? 1 : 0); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 391 | if (is_instance_call) { |
| 392 | HInstruction* arg = LoadLocal(is_range ? register_index : args[0], Primitive::kPrimNot); |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 393 | HNullCheck* null_check = new (arena_) HNullCheck(arg, dex_offset); |
| 394 | current_block_->AddInstruction(null_check); |
| 395 | temps.Add(null_check); |
| 396 | invoke->SetArgumentAt(0, null_check); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 397 | start_index = 1; |
| 398 | } |
| 399 | |
| 400 | uint32_t descriptor_index = 1; |
| 401 | uint32_t argument_index = start_index; |
| 402 | for (size_t i = start_index; i < number_of_vreg_arguments; i++, argument_index++) { |
| 403 | Primitive::Type type = Primitive::GetType(descriptor[descriptor_index++]); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 404 | bool is_wide = (type == Primitive::kPrimLong) || (type == Primitive::kPrimDouble); |
| 405 | if (!is_range && is_wide && args[i] + 1 != args[i + 1]) { |
Nicolas Geoffray | abed4d0 | 2014-07-14 15:24:11 +0100 | [diff] [blame] | 406 | LOG(WARNING) << "Non sequential register pair in " << dex_compilation_unit_->GetSymbol() |
| 407 | << " at " << dex_offset; |
| 408 | // We do not implement non sequential register pair. |
| 409 | return false; |
| 410 | } |
| 411 | HInstruction* arg = LoadLocal(is_range ? register_index + i : args[i], type); |
| 412 | invoke->SetArgumentAt(argument_index, arg); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 413 | if (is_wide) { |
Nicolas Geoffray | abed4d0 | 2014-07-14 15:24:11 +0100 | [diff] [blame] | 414 | i++; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 415 | } |
| 416 | } |
| 417 | |
| 418 | DCHECK_EQ(argument_index, number_of_arguments); |
| 419 | current_block_->AddInstruction(invoke); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 420 | latest_result_ = invoke; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 421 | return true; |
| 422 | } |
| 423 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 424 | bool HGraphBuilder::BuildFieldAccess(const Instruction& instruction, |
| 425 | uint32_t dex_offset, |
| 426 | bool is_put) { |
| 427 | uint32_t source_or_dest_reg = instruction.VRegA_22c(); |
| 428 | uint32_t obj_reg = instruction.VRegB_22c(); |
| 429 | uint16_t field_index = instruction.VRegC_22c(); |
| 430 | |
| 431 | ScopedObjectAccess soa(Thread::Current()); |
| 432 | StackHandleScope<1> hs(soa.Self()); |
| 433 | Handle<mirror::ArtField> resolved_field(hs.NewHandle( |
| 434 | compiler_driver_->ComputeInstanceFieldInfo(field_index, dex_compilation_unit_, is_put, soa))); |
| 435 | |
| 436 | if (resolved_field.Get() == nullptr) { |
| 437 | return false; |
| 438 | } |
| 439 | if (resolved_field->IsVolatile()) { |
| 440 | return false; |
| 441 | } |
| 442 | |
Nicolas Geoffray | abed4d0 | 2014-07-14 15:24:11 +0100 | [diff] [blame] | 443 | Primitive::Type field_type = resolved_field->GetTypeAsPrimitiveType(); |
| 444 | if (!IsTypeSupported(field_type)) { |
| 445 | return false; |
| 446 | } |
| 447 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 448 | HInstruction* object = LoadLocal(obj_reg, Primitive::kPrimNot); |
| 449 | current_block_->AddInstruction(new (arena_) HNullCheck(object, dex_offset)); |
| 450 | if (is_put) { |
| 451 | Temporaries temps(graph_, 1); |
| 452 | HInstruction* null_check = current_block_->GetLastInstruction(); |
| 453 | // We need one temporary for the null check. |
| 454 | temps.Add(null_check); |
Nicolas Geoffray | abed4d0 | 2014-07-14 15:24:11 +0100 | [diff] [blame] | 455 | HInstruction* value = LoadLocal(source_or_dest_reg, field_type); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 456 | current_block_->AddInstruction(new (arena_) HInstanceFieldSet( |
| 457 | null_check, |
| 458 | value, |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 459 | field_type, |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 460 | resolved_field->GetOffset())); |
| 461 | } else { |
| 462 | current_block_->AddInstruction(new (arena_) HInstanceFieldGet( |
| 463 | current_block_->GetLastInstruction(), |
Nicolas Geoffray | abed4d0 | 2014-07-14 15:24:11 +0100 | [diff] [blame] | 464 | field_type, |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 465 | resolved_field->GetOffset())); |
| 466 | |
| 467 | UpdateLocal(source_or_dest_reg, current_block_->GetLastInstruction()); |
| 468 | } |
| 469 | return true; |
| 470 | } |
| 471 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 472 | void HGraphBuilder::BuildArrayAccess(const Instruction& instruction, |
| 473 | uint32_t dex_offset, |
| 474 | bool is_put, |
| 475 | Primitive::Type anticipated_type) { |
| 476 | uint8_t source_or_dest_reg = instruction.VRegA_23x(); |
| 477 | uint8_t array_reg = instruction.VRegB_23x(); |
| 478 | uint8_t index_reg = instruction.VRegC_23x(); |
| 479 | |
| 480 | DCHECK(IsTypeSupported(anticipated_type)); |
| 481 | |
| 482 | // We need one temporary for the null check, one for the index, and one for the length. |
| 483 | Temporaries temps(graph_, 3); |
| 484 | |
| 485 | HInstruction* object = LoadLocal(array_reg, Primitive::kPrimNot); |
| 486 | object = new (arena_) HNullCheck(object, dex_offset); |
| 487 | current_block_->AddInstruction(object); |
| 488 | temps.Add(object); |
| 489 | |
| 490 | HInstruction* length = new (arena_) HArrayLength(object); |
| 491 | current_block_->AddInstruction(length); |
| 492 | temps.Add(length); |
| 493 | HInstruction* index = LoadLocal(index_reg, Primitive::kPrimInt); |
| 494 | index = new (arena_) HBoundsCheck(index, length, dex_offset); |
| 495 | current_block_->AddInstruction(index); |
| 496 | temps.Add(index); |
| 497 | if (is_put) { |
| 498 | HInstruction* value = LoadLocal(source_or_dest_reg, anticipated_type); |
| 499 | // TODO: Insert a type check node if the type is Object. |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 500 | current_block_->AddInstruction(new (arena_) HArraySet( |
| 501 | object, index, value, anticipated_type, dex_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 502 | } else { |
| 503 | current_block_->AddInstruction(new (arena_) HArrayGet(object, index, anticipated_type)); |
| 504 | UpdateLocal(source_or_dest_reg, current_block_->GetLastInstruction()); |
| 505 | } |
| 506 | } |
| 507 | |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 508 | void HGraphBuilder::BuildFilledNewArray(uint32_t dex_offset, |
| 509 | uint32_t type_index, |
| 510 | uint32_t number_of_vreg_arguments, |
| 511 | bool is_range, |
| 512 | uint32_t* args, |
| 513 | uint32_t register_index) { |
| 514 | HInstruction* length = GetIntConstant(number_of_vreg_arguments); |
| 515 | HInstruction* object = new (arena_) HNewArray(length, dex_offset, type_index); |
| 516 | current_block_->AddInstruction(object); |
| 517 | |
| 518 | const char* descriptor = dex_file_->StringByTypeIdx(type_index); |
| 519 | DCHECK_EQ(descriptor[0], '[') << descriptor; |
| 520 | char primitive = descriptor[1]; |
| 521 | DCHECK(primitive == 'I' |
| 522 | || primitive == 'L' |
| 523 | || primitive == '[') << descriptor; |
| 524 | bool is_reference_array = (primitive == 'L') || (primitive == '['); |
| 525 | Primitive::Type type = is_reference_array ? Primitive::kPrimNot : Primitive::kPrimInt; |
| 526 | |
| 527 | Temporaries temps(graph_, 1); |
| 528 | temps.Add(object); |
| 529 | for (size_t i = 0; i < number_of_vreg_arguments; ++i) { |
| 530 | HInstruction* value = LoadLocal(is_range ? register_index + i : args[i], type); |
| 531 | HInstruction* index = GetIntConstant(i); |
| 532 | current_block_->AddInstruction( |
| 533 | new (arena_) HArraySet(object, index, value, type, dex_offset)); |
| 534 | } |
| 535 | latest_result_ = object; |
| 536 | } |
| 537 | |
| 538 | template <typename T> |
| 539 | void HGraphBuilder::BuildFillArrayData(HInstruction* object, |
| 540 | const T* data, |
| 541 | uint32_t element_count, |
| 542 | Primitive::Type anticipated_type, |
| 543 | uint32_t dex_offset) { |
| 544 | for (uint32_t i = 0; i < element_count; ++i) { |
| 545 | HInstruction* index = GetIntConstant(i); |
| 546 | HInstruction* value = GetIntConstant(data[i]); |
| 547 | current_block_->AddInstruction(new (arena_) HArraySet( |
| 548 | object, index, value, anticipated_type, dex_offset)); |
| 549 | } |
| 550 | } |
| 551 | |
| 552 | void HGraphBuilder::BuildFillWideArrayData(HInstruction* object, |
Nicolas Geoffray | 8d6ae52 | 2014-10-23 18:32:13 +0100 | [diff] [blame] | 553 | const int64_t* data, |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 554 | uint32_t element_count, |
| 555 | uint32_t dex_offset) { |
| 556 | for (uint32_t i = 0; i < element_count; ++i) { |
| 557 | HInstruction* index = GetIntConstant(i); |
| 558 | HInstruction* value = GetLongConstant(data[i]); |
| 559 | current_block_->AddInstruction(new (arena_) HArraySet( |
| 560 | object, index, value, Primitive::kPrimLong, dex_offset)); |
| 561 | } |
| 562 | } |
| 563 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 564 | void HGraphBuilder::PotentiallyAddSuspendCheck(int32_t target_offset, uint32_t dex_offset) { |
| 565 | if (target_offset <= 0) { |
| 566 | // Unconditionnally add a suspend check to backward branches. We can remove |
| 567 | // them after we recognize loops in the graph. |
| 568 | current_block_->AddInstruction(new (arena_) HSuspendCheck(dex_offset)); |
| 569 | } |
| 570 | } |
| 571 | |
| 572 | bool HGraphBuilder::AnalyzeDexInstruction(const Instruction& instruction, uint32_t dex_offset) { |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 573 | if (current_block_ == nullptr) { |
| 574 | return true; // Dead code |
| 575 | } |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 576 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 577 | switch (instruction.Opcode()) { |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 578 | case Instruction::CONST_4: { |
| 579 | int32_t register_index = instruction.VRegA(); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 580 | HIntConstant* constant = GetIntConstant(instruction.VRegB_11n()); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 581 | UpdateLocal(register_index, constant); |
| 582 | break; |
| 583 | } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 584 | |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 585 | case Instruction::CONST_16: { |
| 586 | int32_t register_index = instruction.VRegA(); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 587 | HIntConstant* constant = GetIntConstant(instruction.VRegB_21s()); |
| 588 | UpdateLocal(register_index, constant); |
| 589 | break; |
| 590 | } |
| 591 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 592 | case Instruction::CONST: { |
| 593 | int32_t register_index = instruction.VRegA(); |
| 594 | HIntConstant* constant = GetIntConstant(instruction.VRegB_31i()); |
| 595 | UpdateLocal(register_index, constant); |
| 596 | break; |
| 597 | } |
| 598 | |
| 599 | case Instruction::CONST_HIGH16: { |
| 600 | int32_t register_index = instruction.VRegA(); |
| 601 | HIntConstant* constant = GetIntConstant(instruction.VRegB_21h() << 16); |
| 602 | UpdateLocal(register_index, constant); |
| 603 | break; |
| 604 | } |
| 605 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 606 | case Instruction::CONST_WIDE_16: { |
| 607 | int32_t register_index = instruction.VRegA(); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 608 | // Get 16 bits of constant value, sign extended to 64 bits. |
| 609 | int64_t value = instruction.VRegB_21s(); |
| 610 | value <<= 48; |
| 611 | value >>= 48; |
| 612 | HLongConstant* constant = GetLongConstant(value); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 613 | UpdateLocal(register_index, constant); |
| 614 | break; |
| 615 | } |
| 616 | |
| 617 | case Instruction::CONST_WIDE_32: { |
| 618 | int32_t register_index = instruction.VRegA(); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 619 | // Get 32 bits of constant value, sign extended to 64 bits. |
| 620 | int64_t value = instruction.VRegB_31i(); |
| 621 | value <<= 32; |
| 622 | value >>= 32; |
| 623 | HLongConstant* constant = GetLongConstant(value); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 624 | UpdateLocal(register_index, constant); |
| 625 | break; |
| 626 | } |
| 627 | |
| 628 | case Instruction::CONST_WIDE: { |
| 629 | int32_t register_index = instruction.VRegA(); |
| 630 | HLongConstant* constant = GetLongConstant(instruction.VRegB_51l()); |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 631 | UpdateLocal(register_index, constant); |
| 632 | break; |
| 633 | } |
| 634 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 635 | case Instruction::CONST_WIDE_HIGH16: { |
| 636 | int32_t register_index = instruction.VRegA(); |
| 637 | int64_t value = static_cast<int64_t>(instruction.VRegB_21h()) << 48; |
| 638 | HLongConstant* constant = GetLongConstant(value); |
| 639 | UpdateLocal(register_index, constant); |
| 640 | break; |
| 641 | } |
| 642 | |
| 643 | // TODO: these instructions are also used to move floating point values, so what is |
| 644 | // the type (int or float)? |
| 645 | case Instruction::MOVE: |
| 646 | case Instruction::MOVE_FROM16: |
| 647 | case Instruction::MOVE_16: { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 648 | HInstruction* value = LoadLocal(instruction.VRegB(), Primitive::kPrimInt); |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 649 | UpdateLocal(instruction.VRegA(), value); |
| 650 | break; |
| 651 | } |
| 652 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 653 | // TODO: these instructions are also used to move floating point values, so what is |
| 654 | // the type (long or double)? |
| 655 | case Instruction::MOVE_WIDE: |
| 656 | case Instruction::MOVE_WIDE_FROM16: |
| 657 | case Instruction::MOVE_WIDE_16: { |
| 658 | HInstruction* value = LoadLocal(instruction.VRegB(), Primitive::kPrimLong); |
| 659 | UpdateLocal(instruction.VRegA(), value); |
| 660 | break; |
| 661 | } |
| 662 | |
| 663 | case Instruction::MOVE_OBJECT: |
| 664 | case Instruction::MOVE_OBJECT_16: |
| 665 | case Instruction::MOVE_OBJECT_FROM16: { |
| 666 | HInstruction* value = LoadLocal(instruction.VRegB(), Primitive::kPrimNot); |
| 667 | UpdateLocal(instruction.VRegA(), value); |
| 668 | break; |
| 669 | } |
| 670 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 671 | case Instruction::RETURN_VOID: { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 672 | BuildReturn(instruction, Primitive::kPrimVoid); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 673 | break; |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 674 | } |
| 675 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 676 | #define IF_XX(comparison, cond) \ |
| 677 | case Instruction::IF_##cond: If_22t<comparison>(instruction, dex_offset); break; \ |
| 678 | case Instruction::IF_##cond##Z: If_21t<comparison>(instruction, dex_offset); break |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 679 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 680 | IF_XX(HEqual, EQ); |
| 681 | IF_XX(HNotEqual, NE); |
| 682 | IF_XX(HLessThan, LT); |
| 683 | IF_XX(HLessThanOrEqual, LE); |
| 684 | IF_XX(HGreaterThan, GT); |
| 685 | IF_XX(HGreaterThanOrEqual, GE); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 686 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 687 | case Instruction::GOTO: |
| 688 | case Instruction::GOTO_16: |
| 689 | case Instruction::GOTO_32: { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 690 | int32_t offset = instruction.GetTargetOffset(); |
| 691 | PotentiallyAddSuspendCheck(offset, dex_offset); |
| 692 | HBasicBlock* target = FindBlockStartingAt(offset + dex_offset); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 693 | DCHECK(target != nullptr); |
| 694 | current_block_->AddInstruction(new (arena_) HGoto()); |
| 695 | current_block_->AddSuccessor(target); |
| 696 | current_block_ = nullptr; |
| 697 | break; |
| 698 | } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 699 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 700 | case Instruction::RETURN: { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 701 | DCHECK_NE(return_type_, Primitive::kPrimNot); |
| 702 | DCHECK_NE(return_type_, Primitive::kPrimLong); |
| 703 | DCHECK_NE(return_type_, Primitive::kPrimDouble); |
| 704 | BuildReturn(instruction, return_type_); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 705 | break; |
| 706 | } |
| 707 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 708 | case Instruction::RETURN_OBJECT: { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 709 | DCHECK(return_type_ == Primitive::kPrimNot); |
| 710 | BuildReturn(instruction, return_type_); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 711 | break; |
| 712 | } |
| 713 | |
| 714 | case Instruction::RETURN_WIDE: { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 715 | DCHECK(return_type_ == Primitive::kPrimDouble || return_type_ == Primitive::kPrimLong); |
| 716 | BuildReturn(instruction, return_type_); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 717 | break; |
| 718 | } |
| 719 | |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 720 | case Instruction::INVOKE_STATIC: |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 721 | case Instruction::INVOKE_DIRECT: |
| 722 | case Instruction::INVOKE_VIRTUAL: { |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 723 | uint32_t method_idx = instruction.VRegB_35c(); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 724 | uint32_t number_of_vreg_arguments = instruction.VRegA_35c(); |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 725 | uint32_t args[5]; |
Ian Rogers | 29a2648 | 2014-05-02 15:27:29 -0700 | [diff] [blame] | 726 | instruction.GetVarArgs(args); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 727 | if (!BuildInvoke(instruction, dex_offset, method_idx, number_of_vreg_arguments, false, args, -1)) { |
| 728 | return false; |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 729 | } |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 730 | break; |
| 731 | } |
| 732 | |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 733 | case Instruction::INVOKE_STATIC_RANGE: |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 734 | case Instruction::INVOKE_DIRECT_RANGE: |
| 735 | case Instruction::INVOKE_VIRTUAL_RANGE: { |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 736 | uint32_t method_idx = instruction.VRegB_3rc(); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 737 | uint32_t number_of_vreg_arguments = instruction.VRegA_3rc(); |
| 738 | uint32_t register_index = instruction.VRegC(); |
| 739 | if (!BuildInvoke(instruction, dex_offset, method_idx, |
| 740 | number_of_vreg_arguments, true, nullptr, register_index)) { |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 741 | return false; |
| 742 | } |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 743 | break; |
| 744 | } |
| 745 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 746 | case Instruction::NEG_INT: { |
| 747 | Unop_12x<HNeg>(instruction, Primitive::kPrimInt); |
| 748 | break; |
| 749 | } |
| 750 | |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 751 | case Instruction::NEG_LONG: { |
| 752 | Unop_12x<HNeg>(instruction, Primitive::kPrimLong); |
| 753 | break; |
| 754 | } |
| 755 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 756 | case Instruction::NOT_INT: { |
| 757 | Unop_12x<HNot>(instruction, Primitive::kPrimInt); |
| 758 | break; |
| 759 | } |
| 760 | |
Roland Levillain | 7056643 | 2014-10-24 16:20:17 +0100 | [diff] [blame] | 761 | case Instruction::NOT_LONG: { |
| 762 | Unop_12x<HNot>(instruction, Primitive::kPrimLong); |
| 763 | break; |
| 764 | } |
| 765 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 766 | case Instruction::ADD_INT: { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 767 | Binop_23x<HAdd>(instruction, Primitive::kPrimInt); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 768 | break; |
| 769 | } |
| 770 | |
| 771 | case Instruction::ADD_LONG: { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 772 | Binop_23x<HAdd>(instruction, Primitive::kPrimLong); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 773 | break; |
| 774 | } |
| 775 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 776 | case Instruction::ADD_DOUBLE: { |
| 777 | Binop_23x<HAdd>(instruction, Primitive::kPrimDouble); |
| 778 | break; |
| 779 | } |
| 780 | |
| 781 | case Instruction::ADD_FLOAT: { |
| 782 | Binop_23x<HAdd>(instruction, Primitive::kPrimFloat); |
| 783 | break; |
| 784 | } |
| 785 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 786 | case Instruction::SUB_INT: { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 787 | Binop_23x<HSub>(instruction, Primitive::kPrimInt); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 788 | break; |
| 789 | } |
| 790 | |
| 791 | case Instruction::SUB_LONG: { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 792 | Binop_23x<HSub>(instruction, Primitive::kPrimLong); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 793 | break; |
| 794 | } |
| 795 | |
Calin Juravle | 096cc02 | 2014-10-23 17:01:13 +0100 | [diff] [blame] | 796 | case Instruction::SUB_FLOAT: { |
| 797 | Binop_23x<HSub>(instruction, Primitive::kPrimFloat); |
| 798 | break; |
| 799 | } |
| 800 | |
| 801 | case Instruction::SUB_DOUBLE: { |
| 802 | Binop_23x<HSub>(instruction, Primitive::kPrimDouble); |
| 803 | break; |
| 804 | } |
| 805 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 806 | case Instruction::ADD_INT_2ADDR: { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 807 | Binop_12x<HAdd>(instruction, Primitive::kPrimInt); |
| 808 | break; |
| 809 | } |
| 810 | |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 811 | case Instruction::MUL_INT: { |
| 812 | Binop_23x<HMul>(instruction, Primitive::kPrimInt); |
| 813 | break; |
| 814 | } |
| 815 | |
| 816 | case Instruction::MUL_LONG: { |
| 817 | Binop_23x<HMul>(instruction, Primitive::kPrimLong); |
| 818 | break; |
| 819 | } |
| 820 | |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 821 | case Instruction::MUL_FLOAT: { |
| 822 | Binop_23x<HMul>(instruction, Primitive::kPrimFloat); |
| 823 | break; |
| 824 | } |
| 825 | |
| 826 | case Instruction::MUL_DOUBLE: { |
| 827 | Binop_23x<HMul>(instruction, Primitive::kPrimDouble); |
| 828 | break; |
| 829 | } |
| 830 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 831 | case Instruction::DIV_FLOAT: { |
| 832 | Binop_23x<HDiv>(instruction, Primitive::kPrimFloat); |
| 833 | break; |
| 834 | } |
| 835 | |
| 836 | case Instruction::DIV_DOUBLE: { |
| 837 | Binop_23x<HDiv>(instruction, Primitive::kPrimDouble); |
| 838 | break; |
| 839 | } |
| 840 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 841 | case Instruction::ADD_LONG_2ADDR: { |
| 842 | Binop_12x<HAdd>(instruction, Primitive::kPrimLong); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 843 | break; |
| 844 | } |
| 845 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 846 | case Instruction::ADD_DOUBLE_2ADDR: { |
| 847 | Binop_12x<HAdd>(instruction, Primitive::kPrimDouble); |
| 848 | break; |
| 849 | } |
| 850 | |
| 851 | case Instruction::ADD_FLOAT_2ADDR: { |
| 852 | Binop_12x<HAdd>(instruction, Primitive::kPrimFloat); |
| 853 | break; |
| 854 | } |
| 855 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 856 | case Instruction::SUB_INT_2ADDR: { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 857 | Binop_12x<HSub>(instruction, Primitive::kPrimInt); |
| 858 | break; |
| 859 | } |
| 860 | |
| 861 | case Instruction::SUB_LONG_2ADDR: { |
| 862 | Binop_12x<HSub>(instruction, Primitive::kPrimLong); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 863 | break; |
| 864 | } |
| 865 | |
Calin Juravle | 096cc02 | 2014-10-23 17:01:13 +0100 | [diff] [blame] | 866 | case Instruction::SUB_FLOAT_2ADDR: { |
| 867 | Binop_12x<HSub>(instruction, Primitive::kPrimFloat); |
| 868 | break; |
| 869 | } |
| 870 | |
| 871 | case Instruction::SUB_DOUBLE_2ADDR: { |
| 872 | Binop_12x<HSub>(instruction, Primitive::kPrimDouble); |
| 873 | break; |
| 874 | } |
| 875 | |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 876 | case Instruction::MUL_INT_2ADDR: { |
| 877 | Binop_12x<HMul>(instruction, Primitive::kPrimInt); |
| 878 | break; |
| 879 | } |
| 880 | |
| 881 | case Instruction::MUL_LONG_2ADDR: { |
| 882 | Binop_12x<HMul>(instruction, Primitive::kPrimLong); |
| 883 | break; |
| 884 | } |
| 885 | |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 886 | case Instruction::MUL_FLOAT_2ADDR: { |
| 887 | Binop_12x<HMul>(instruction, Primitive::kPrimFloat); |
| 888 | break; |
| 889 | } |
| 890 | |
| 891 | case Instruction::MUL_DOUBLE_2ADDR: { |
| 892 | Binop_12x<HMul>(instruction, Primitive::kPrimDouble); |
| 893 | break; |
| 894 | } |
| 895 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 896 | case Instruction::DIV_FLOAT_2ADDR: { |
| 897 | Binop_12x<HDiv>(instruction, Primitive::kPrimFloat); |
| 898 | break; |
| 899 | } |
| 900 | |
| 901 | case Instruction::DIV_DOUBLE_2ADDR: { |
| 902 | Binop_12x<HDiv>(instruction, Primitive::kPrimDouble); |
| 903 | break; |
| 904 | } |
| 905 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 906 | case Instruction::ADD_INT_LIT16: { |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 907 | Binop_22s<HAdd>(instruction, false); |
| 908 | break; |
| 909 | } |
| 910 | |
| 911 | case Instruction::RSUB_INT: { |
| 912 | Binop_22s<HSub>(instruction, true); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 913 | break; |
| 914 | } |
| 915 | |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 916 | case Instruction::MUL_INT_LIT16: { |
| 917 | Binop_22s<HMul>(instruction, false); |
| 918 | break; |
| 919 | } |
| 920 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 921 | case Instruction::ADD_INT_LIT8: { |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 922 | Binop_22b<HAdd>(instruction, false); |
| 923 | break; |
| 924 | } |
| 925 | |
| 926 | case Instruction::RSUB_INT_LIT8: { |
| 927 | Binop_22b<HSub>(instruction, true); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 928 | break; |
| 929 | } |
| 930 | |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 931 | case Instruction::MUL_INT_LIT8: { |
| 932 | Binop_22b<HMul>(instruction, false); |
| 933 | break; |
| 934 | } |
| 935 | |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 936 | case Instruction::NEW_INSTANCE: { |
| 937 | current_block_->AddInstruction( |
| 938 | new (arena_) HNewInstance(dex_offset, instruction.VRegB_21c())); |
| 939 | UpdateLocal(instruction.VRegA(), current_block_->GetLastInstruction()); |
| 940 | break; |
| 941 | } |
| 942 | |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 943 | case Instruction::NEW_ARRAY: { |
| 944 | HInstruction* length = LoadLocal(instruction.VRegB_22c(), Primitive::kPrimInt); |
| 945 | current_block_->AddInstruction( |
| 946 | new (arena_) HNewArray(length, dex_offset, instruction.VRegC_22c())); |
| 947 | UpdateLocal(instruction.VRegA_22c(), current_block_->GetLastInstruction()); |
| 948 | break; |
| 949 | } |
| 950 | |
| 951 | case Instruction::FILLED_NEW_ARRAY: { |
| 952 | uint32_t number_of_vreg_arguments = instruction.VRegA_35c(); |
| 953 | uint32_t type_index = instruction.VRegB_35c(); |
| 954 | uint32_t args[5]; |
| 955 | instruction.GetVarArgs(args); |
| 956 | BuildFilledNewArray(dex_offset, type_index, number_of_vreg_arguments, false, args, 0); |
| 957 | break; |
| 958 | } |
| 959 | |
| 960 | case Instruction::FILLED_NEW_ARRAY_RANGE: { |
| 961 | uint32_t number_of_vreg_arguments = instruction.VRegA_3rc(); |
| 962 | uint32_t type_index = instruction.VRegB_3rc(); |
| 963 | uint32_t register_index = instruction.VRegC_3rc(); |
| 964 | BuildFilledNewArray( |
| 965 | dex_offset, type_index, number_of_vreg_arguments, true, nullptr, register_index); |
| 966 | break; |
| 967 | } |
| 968 | |
| 969 | case Instruction::FILL_ARRAY_DATA: { |
| 970 | Temporaries temps(graph_, 1); |
| 971 | HInstruction* array = LoadLocal(instruction.VRegA_31t(), Primitive::kPrimNot); |
| 972 | HNullCheck* null_check = new (arena_) HNullCheck(array, dex_offset); |
| 973 | current_block_->AddInstruction(null_check); |
| 974 | temps.Add(null_check); |
| 975 | |
| 976 | HInstruction* length = new (arena_) HArrayLength(null_check); |
| 977 | current_block_->AddInstruction(length); |
| 978 | |
| 979 | int32_t payload_offset = instruction.VRegB_31t() + dex_offset; |
| 980 | const Instruction::ArrayDataPayload* payload = |
| 981 | reinterpret_cast<const Instruction::ArrayDataPayload*>(code_start_ + payload_offset); |
| 982 | const uint8_t* data = payload->data; |
| 983 | uint32_t element_count = payload->element_count; |
| 984 | |
| 985 | // Implementation of this DEX instruction seems to be that the bounds check is |
| 986 | // done before doing any stores. |
| 987 | HInstruction* last_index = GetIntConstant(payload->element_count - 1); |
| 988 | current_block_->AddInstruction(new (arena_) HBoundsCheck(last_index, length, dex_offset)); |
| 989 | |
| 990 | switch (payload->element_width) { |
| 991 | case 1: |
Nicolas Geoffray | 8d6ae52 | 2014-10-23 18:32:13 +0100 | [diff] [blame] | 992 | BuildFillArrayData(null_check, |
| 993 | reinterpret_cast<const int8_t*>(data), |
| 994 | element_count, |
| 995 | Primitive::kPrimByte, |
| 996 | dex_offset); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 997 | break; |
| 998 | case 2: |
| 999 | BuildFillArrayData(null_check, |
Nicolas Geoffray | 8d6ae52 | 2014-10-23 18:32:13 +0100 | [diff] [blame] | 1000 | reinterpret_cast<const int16_t*>(data), |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 1001 | element_count, |
| 1002 | Primitive::kPrimShort, |
| 1003 | dex_offset); |
| 1004 | break; |
| 1005 | case 4: |
| 1006 | BuildFillArrayData(null_check, |
Nicolas Geoffray | 8d6ae52 | 2014-10-23 18:32:13 +0100 | [diff] [blame] | 1007 | reinterpret_cast<const int32_t*>(data), |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 1008 | element_count, |
| 1009 | Primitive::kPrimInt, |
| 1010 | dex_offset); |
| 1011 | break; |
| 1012 | case 8: |
| 1013 | BuildFillWideArrayData(null_check, |
Nicolas Geoffray | 8d6ae52 | 2014-10-23 18:32:13 +0100 | [diff] [blame] | 1014 | reinterpret_cast<const int64_t*>(data), |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 1015 | element_count, |
| 1016 | dex_offset); |
| 1017 | break; |
| 1018 | default: |
| 1019 | LOG(FATAL) << "Unknown element width for " << payload->element_width; |
| 1020 | } |
| 1021 | break; |
| 1022 | } |
| 1023 | |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 1024 | case Instruction::MOVE_RESULT: |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1025 | case Instruction::MOVE_RESULT_WIDE: |
| 1026 | case Instruction::MOVE_RESULT_OBJECT: |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 1027 | UpdateLocal(instruction.VRegA(), latest_result_); |
| 1028 | latest_result_ = nullptr; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1029 | break; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1030 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1031 | case Instruction::CMP_LONG: { |
| 1032 | Binop_23x<HCompare>(instruction, Primitive::kPrimLong); |
| 1033 | break; |
| 1034 | } |
| 1035 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 1036 | case Instruction::NOP: |
| 1037 | break; |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1038 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1039 | case Instruction::IGET: |
| 1040 | case Instruction::IGET_WIDE: |
| 1041 | case Instruction::IGET_OBJECT: |
| 1042 | case Instruction::IGET_BOOLEAN: |
| 1043 | case Instruction::IGET_BYTE: |
| 1044 | case Instruction::IGET_CHAR: |
| 1045 | case Instruction::IGET_SHORT: { |
| 1046 | if (!BuildFieldAccess(instruction, dex_offset, false)) { |
| 1047 | return false; |
| 1048 | } |
| 1049 | break; |
| 1050 | } |
| 1051 | |
| 1052 | case Instruction::IPUT: |
| 1053 | case Instruction::IPUT_WIDE: |
| 1054 | case Instruction::IPUT_OBJECT: |
| 1055 | case Instruction::IPUT_BOOLEAN: |
| 1056 | case Instruction::IPUT_BYTE: |
| 1057 | case Instruction::IPUT_CHAR: |
| 1058 | case Instruction::IPUT_SHORT: { |
| 1059 | if (!BuildFieldAccess(instruction, dex_offset, true)) { |
| 1060 | return false; |
| 1061 | } |
| 1062 | break; |
| 1063 | } |
| 1064 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1065 | #define ARRAY_XX(kind, anticipated_type) \ |
| 1066 | case Instruction::AGET##kind: { \ |
| 1067 | BuildArrayAccess(instruction, dex_offset, false, anticipated_type); \ |
| 1068 | break; \ |
| 1069 | } \ |
| 1070 | case Instruction::APUT##kind: { \ |
| 1071 | BuildArrayAccess(instruction, dex_offset, true, anticipated_type); \ |
| 1072 | break; \ |
| 1073 | } |
| 1074 | |
| 1075 | ARRAY_XX(, Primitive::kPrimInt); |
| 1076 | ARRAY_XX(_WIDE, Primitive::kPrimLong); |
| 1077 | ARRAY_XX(_OBJECT, Primitive::kPrimNot); |
| 1078 | ARRAY_XX(_BOOLEAN, Primitive::kPrimBoolean); |
| 1079 | ARRAY_XX(_BYTE, Primitive::kPrimByte); |
| 1080 | ARRAY_XX(_CHAR, Primitive::kPrimChar); |
| 1081 | ARRAY_XX(_SHORT, Primitive::kPrimShort); |
| 1082 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1083 | case Instruction::ARRAY_LENGTH: { |
| 1084 | HInstruction* object = LoadLocal(instruction.VRegB_12x(), Primitive::kPrimNot); |
| 1085 | current_block_->AddInstruction(new (arena_) HArrayLength(object)); |
| 1086 | UpdateLocal(instruction.VRegA_12x(), current_block_->GetLastInstruction()); |
| 1087 | break; |
| 1088 | } |
| 1089 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1090 | default: |
| 1091 | return false; |
| 1092 | } |
| 1093 | return true; |
| 1094 | } |
| 1095 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1096 | HIntConstant* HGraphBuilder::GetIntConstant0() { |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1097 | if (constant0_ != nullptr) { |
| 1098 | return constant0_; |
| 1099 | } |
| 1100 | constant0_ = new(arena_) HIntConstant(0); |
| 1101 | entry_block_->AddInstruction(constant0_); |
| 1102 | return constant0_; |
| 1103 | } |
| 1104 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1105 | HIntConstant* HGraphBuilder::GetIntConstant1() { |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1106 | if (constant1_ != nullptr) { |
| 1107 | return constant1_; |
| 1108 | } |
| 1109 | constant1_ = new(arena_) HIntConstant(1); |
| 1110 | entry_block_->AddInstruction(constant1_); |
| 1111 | return constant1_; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1112 | } |
| 1113 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1114 | HIntConstant* HGraphBuilder::GetIntConstant(int32_t constant) { |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1115 | switch (constant) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1116 | case 0: return GetIntConstant0(); |
| 1117 | case 1: return GetIntConstant1(); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1118 | default: { |
| 1119 | HIntConstant* instruction = new (arena_) HIntConstant(constant); |
| 1120 | entry_block_->AddInstruction(instruction); |
| 1121 | return instruction; |
| 1122 | } |
| 1123 | } |
| 1124 | } |
| 1125 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1126 | HLongConstant* HGraphBuilder::GetLongConstant(int64_t constant) { |
| 1127 | HLongConstant* instruction = new (arena_) HLongConstant(constant); |
| 1128 | entry_block_->AddInstruction(instruction); |
| 1129 | return instruction; |
| 1130 | } |
| 1131 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1132 | HLocal* HGraphBuilder::GetLocalAt(int register_index) const { |
| 1133 | return locals_.Get(register_index); |
| 1134 | } |
| 1135 | |
| 1136 | void HGraphBuilder::UpdateLocal(int register_index, HInstruction* instruction) const { |
| 1137 | HLocal* local = GetLocalAt(register_index); |
| 1138 | current_block_->AddInstruction(new (arena_) HStoreLocal(local, instruction)); |
| 1139 | } |
| 1140 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1141 | HInstruction* HGraphBuilder::LoadLocal(int register_index, Primitive::Type type) const { |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1142 | HLocal* local = GetLocalAt(register_index); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1143 | current_block_->AddInstruction(new (arena_) HLoadLocal(local, type)); |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1144 | return current_block_->GetLastInstruction(); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1145 | } |
| 1146 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1147 | } // namespace art |