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 | abed4d0 | 2014-07-14 15:24:11 +0100 | [diff] [blame] | 37 | static bool IsTypeSupported(Primitive::Type type) { |
| 38 | return type != Primitive::kPrimFloat && type != Primitive::kPrimDouble; |
| 39 | } |
| 40 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 41 | void HGraphBuilder::InitializeLocals(uint16_t count) { |
| 42 | graph_->SetNumberOfVRegs(count); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 43 | locals_.SetSize(count); |
| 44 | for (int i = 0; i < count; i++) { |
| 45 | HLocal* local = new (arena_) HLocal(i); |
| 46 | entry_block_->AddInstruction(local); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 47 | locals_.Put(i, local); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 48 | } |
| 49 | } |
| 50 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 51 | bool HGraphBuilder::InitializeParameters(uint16_t number_of_parameters) { |
| 52 | // dex_compilation_unit_ is null only when unit testing. |
| 53 | if (dex_compilation_unit_ == nullptr) { |
| 54 | return true; |
| 55 | } |
| 56 | |
| 57 | graph_->SetNumberOfInVRegs(number_of_parameters); |
| 58 | const char* shorty = dex_compilation_unit_->GetShorty(); |
| 59 | int locals_index = locals_.Size() - number_of_parameters; |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 60 | int parameter_index = 0; |
| 61 | |
| 62 | if (!dex_compilation_unit_->IsStatic()) { |
| 63 | // Add the implicit 'this' argument, not expressed in the signature. |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 64 | HParameterValue* parameter = |
| 65 | new (arena_) HParameterValue(parameter_index++, Primitive::kPrimNot); |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 66 | entry_block_->AddInstruction(parameter); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 67 | HLocal* local = GetLocalAt(locals_index++); |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 68 | entry_block_->AddInstruction(new (arena_) HStoreLocal(local, parameter)); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 69 | number_of_parameters--; |
| 70 | } |
| 71 | |
| 72 | uint32_t pos = 1; |
| 73 | for (int i = 0; i < number_of_parameters; i++) { |
| 74 | switch (shorty[pos++]) { |
| 75 | case 'F': |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 76 | case 'D': { |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 77 | return false; |
| 78 | } |
| 79 | |
| 80 | default: { |
| 81 | // integer and reference parameters. |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 82 | HParameterValue* parameter = |
| 83 | new (arena_) HParameterValue(parameter_index++, Primitive::GetType(shorty[pos - 1])); |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 84 | entry_block_->AddInstruction(parameter); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 85 | HLocal* local = GetLocalAt(locals_index++); |
| 86 | // Store the parameter value in the local that the dex code will use |
| 87 | // to reference that parameter. |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 88 | entry_block_->AddInstruction(new (arena_) HStoreLocal(local, parameter)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 89 | if (parameter->GetType() == Primitive::kPrimLong) { |
| 90 | i++; |
| 91 | locals_index++; |
| 92 | parameter_index++; |
| 93 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 94 | break; |
| 95 | } |
| 96 | } |
| 97 | } |
| 98 | return true; |
| 99 | } |
| 100 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 101 | static bool CanHandleCodeItem(const DexFile::CodeItem& code_item) { |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 102 | if (code_item.tries_size_ > 0) { |
| 103 | return false; |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 104 | } |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 105 | return true; |
| 106 | } |
| 107 | |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 108 | template<typename T> |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 109 | void HGraphBuilder::If_22t(const Instruction& instruction, uint32_t dex_offset) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 110 | HInstruction* first = LoadLocal(instruction.VRegA(), Primitive::kPrimInt); |
| 111 | HInstruction* second = LoadLocal(instruction.VRegB(), Primitive::kPrimInt); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 112 | T* comparison = new (arena_) T(first, second); |
| 113 | current_block_->AddInstruction(comparison); |
| 114 | HInstruction* ifinst = new (arena_) HIf(comparison); |
| 115 | current_block_->AddInstruction(ifinst); |
| 116 | HBasicBlock* target = FindBlockStartingAt(dex_offset + instruction.GetTargetOffset()); |
| 117 | DCHECK(target != nullptr); |
| 118 | current_block_->AddSuccessor(target); |
| 119 | target = FindBlockStartingAt(dex_offset + instruction.SizeInCodeUnits()); |
| 120 | DCHECK(target != nullptr); |
| 121 | current_block_->AddSuccessor(target); |
| 122 | current_block_ = nullptr; |
| 123 | } |
| 124 | |
| 125 | template<typename T> |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 126 | void HGraphBuilder::If_21t(const Instruction& instruction, uint32_t dex_offset) { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 127 | HInstruction* value = LoadLocal(instruction.VRegA(), Primitive::kPrimInt); |
| 128 | T* comparison = new (arena_) T(value, GetIntConstant(0)); |
| 129 | current_block_->AddInstruction(comparison); |
| 130 | HInstruction* ifinst = new (arena_) HIf(comparison); |
| 131 | current_block_->AddInstruction(ifinst); |
| 132 | HBasicBlock* target = FindBlockStartingAt(dex_offset + instruction.GetTargetOffset()); |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 133 | DCHECK(target != nullptr); |
| 134 | current_block_->AddSuccessor(target); |
| 135 | target = FindBlockStartingAt(dex_offset + instruction.SizeInCodeUnits()); |
| 136 | DCHECK(target != nullptr); |
| 137 | current_block_->AddSuccessor(target); |
| 138 | current_block_ = nullptr; |
| 139 | } |
| 140 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 141 | HGraph* HGraphBuilder::BuildGraph(const DexFile::CodeItem& code_item) { |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 142 | if (!CanHandleCodeItem(code_item)) { |
| 143 | return nullptr; |
| 144 | } |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 145 | |
| 146 | const uint16_t* code_ptr = code_item.insns_; |
| 147 | const uint16_t* code_end = code_item.insns_ + code_item.insns_size_in_code_units_; |
| 148 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 149 | // Setup the graph with the entry block and exit block. |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 150 | graph_ = new (arena_) HGraph(arena_); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 151 | entry_block_ = new (arena_) HBasicBlock(graph_); |
| 152 | graph_->AddBlock(entry_block_); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 153 | exit_block_ = new (arena_) HBasicBlock(graph_); |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 154 | graph_->SetEntryBlock(entry_block_); |
| 155 | graph_->SetExitBlock(exit_block_); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 156 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 157 | InitializeLocals(code_item.registers_size_); |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 158 | graph_->UpdateMaximumNumberOfOutVRegs(code_item.outs_size_); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 159 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 160 | // To avoid splitting blocks, we compute ahead of time the instructions that |
| 161 | // start a new block, and create these blocks. |
| 162 | ComputeBranchTargets(code_ptr, code_end); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 163 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 164 | if (!InitializeParameters(code_item.ins_size_)) { |
| 165 | return nullptr; |
| 166 | } |
| 167 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 168 | size_t dex_offset = 0; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 169 | while (code_ptr < code_end) { |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 170 | // Update the current block if dex_offset starts a new block. |
| 171 | MaybeUpdateCurrentBlock(dex_offset); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 172 | const Instruction& instruction = *Instruction::At(code_ptr); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 173 | if (!AnalyzeDexInstruction(instruction, dex_offset)) return nullptr; |
| 174 | dex_offset += instruction.SizeInCodeUnits(); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 175 | code_ptr += instruction.SizeInCodeUnits(); |
| 176 | } |
| 177 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 178 | // 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] | 179 | graph_->AddBlock(exit_block_); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 180 | exit_block_->AddInstruction(new (arena_) HExit()); |
| 181 | entry_block_->AddInstruction(new (arena_) HGoto()); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 182 | return graph_; |
| 183 | } |
| 184 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 185 | void HGraphBuilder::MaybeUpdateCurrentBlock(size_t index) { |
| 186 | HBasicBlock* block = FindBlockStartingAt(index); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 187 | if (block == nullptr) { |
| 188 | return; |
| 189 | } |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 190 | |
| 191 | if (current_block_ != nullptr) { |
| 192 | // Branching instructions clear current_block, so we know |
| 193 | // the last instruction of the current block is not a branching |
| 194 | // instruction. We add an unconditional goto to the found block. |
| 195 | current_block_->AddInstruction(new (arena_) HGoto()); |
| 196 | current_block_->AddSuccessor(block); |
| 197 | } |
| 198 | graph_->AddBlock(block); |
| 199 | current_block_ = block; |
| 200 | } |
| 201 | |
| 202 | void HGraphBuilder::ComputeBranchTargets(const uint16_t* code_ptr, const uint16_t* code_end) { |
| 203 | // TODO: Support switch instructions. |
| 204 | branch_targets_.SetSize(code_end - code_ptr); |
| 205 | |
| 206 | // Create the first block for the dex instructions, single successor of the entry block. |
| 207 | HBasicBlock* block = new (arena_) HBasicBlock(graph_); |
| 208 | branch_targets_.Put(0, block); |
| 209 | entry_block_->AddSuccessor(block); |
| 210 | |
| 211 | // Iterate over all instructions and find branching instructions. Create blocks for |
| 212 | // the locations these instructions branch to. |
| 213 | size_t dex_offset = 0; |
| 214 | while (code_ptr < code_end) { |
| 215 | const Instruction& instruction = *Instruction::At(code_ptr); |
| 216 | if (instruction.IsBranch()) { |
| 217 | int32_t target = instruction.GetTargetOffset() + dex_offset; |
| 218 | // Create a block for the target instruction. |
| 219 | if (FindBlockStartingAt(target) == nullptr) { |
| 220 | block = new (arena_) HBasicBlock(graph_); |
| 221 | branch_targets_.Put(target, block); |
| 222 | } |
| 223 | dex_offset += instruction.SizeInCodeUnits(); |
| 224 | code_ptr += instruction.SizeInCodeUnits(); |
| 225 | if ((code_ptr < code_end) && (FindBlockStartingAt(dex_offset) == nullptr)) { |
| 226 | block = new (arena_) HBasicBlock(graph_); |
| 227 | branch_targets_.Put(dex_offset, block); |
| 228 | } |
| 229 | } else { |
| 230 | code_ptr += instruction.SizeInCodeUnits(); |
| 231 | dex_offset += instruction.SizeInCodeUnits(); |
| 232 | } |
| 233 | } |
| 234 | } |
| 235 | |
| 236 | HBasicBlock* HGraphBuilder::FindBlockStartingAt(int32_t index) const { |
| 237 | DCHECK_GE(index, 0); |
| 238 | return branch_targets_.Get(index); |
| 239 | } |
| 240 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 241 | template<typename T> |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 242 | void HGraphBuilder::Binop_23x(const Instruction& instruction, Primitive::Type type) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 243 | HInstruction* first = LoadLocal(instruction.VRegB(), type); |
| 244 | HInstruction* second = LoadLocal(instruction.VRegC(), type); |
| 245 | current_block_->AddInstruction(new (arena_) T(type, first, second)); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 246 | UpdateLocal(instruction.VRegA(), current_block_->GetLastInstruction()); |
| 247 | } |
| 248 | |
| 249 | template<typename T> |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 250 | void HGraphBuilder::Binop_12x(const Instruction& instruction, Primitive::Type type) { |
| 251 | HInstruction* first = LoadLocal(instruction.VRegA(), type); |
| 252 | HInstruction* second = LoadLocal(instruction.VRegB(), type); |
| 253 | current_block_->AddInstruction(new (arena_) T(type, first, second)); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 254 | UpdateLocal(instruction.VRegA(), current_block_->GetLastInstruction()); |
| 255 | } |
| 256 | |
| 257 | template<typename T> |
| 258 | void HGraphBuilder::Binop_22s(const Instruction& instruction, bool reverse) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 259 | HInstruction* first = LoadLocal(instruction.VRegB(), Primitive::kPrimInt); |
| 260 | HInstruction* second = GetIntConstant(instruction.VRegC_22s()); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 261 | if (reverse) { |
| 262 | std::swap(first, second); |
| 263 | } |
| 264 | current_block_->AddInstruction(new (arena_) T(Primitive::kPrimInt, first, second)); |
| 265 | UpdateLocal(instruction.VRegA(), current_block_->GetLastInstruction()); |
| 266 | } |
| 267 | |
| 268 | template<typename T> |
| 269 | void HGraphBuilder::Binop_22b(const Instruction& instruction, bool reverse) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 270 | HInstruction* first = LoadLocal(instruction.VRegB(), Primitive::kPrimInt); |
| 271 | HInstruction* second = GetIntConstant(instruction.VRegC_22b()); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 272 | if (reverse) { |
| 273 | std::swap(first, second); |
| 274 | } |
| 275 | current_block_->AddInstruction(new (arena_) T(Primitive::kPrimInt, first, second)); |
| 276 | UpdateLocal(instruction.VRegA(), current_block_->GetLastInstruction()); |
| 277 | } |
| 278 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 279 | void HGraphBuilder::BuildReturn(const Instruction& instruction, Primitive::Type type) { |
| 280 | if (type == Primitive::kPrimVoid) { |
| 281 | current_block_->AddInstruction(new (arena_) HReturnVoid()); |
| 282 | } else { |
| 283 | HInstruction* value = LoadLocal(instruction.VRegA(), type); |
| 284 | current_block_->AddInstruction(new (arena_) HReturn(value)); |
| 285 | } |
| 286 | current_block_->AddSuccessor(exit_block_); |
| 287 | current_block_ = nullptr; |
| 288 | } |
| 289 | |
| 290 | bool HGraphBuilder::BuildInvoke(const Instruction& instruction, |
| 291 | uint32_t dex_offset, |
| 292 | uint32_t method_idx, |
| 293 | uint32_t number_of_vreg_arguments, |
| 294 | bool is_range, |
| 295 | uint32_t* args, |
| 296 | uint32_t register_index) { |
| 297 | const DexFile::MethodId& method_id = dex_file_->GetMethodId(method_idx); |
| 298 | const DexFile::ProtoId& proto_id = dex_file_->GetProtoId(method_id.proto_idx_); |
| 299 | const char* descriptor = dex_file_->StringDataByIdx(proto_id.shorty_idx_); |
| 300 | Primitive::Type return_type = Primitive::GetType(descriptor[0]); |
| 301 | bool is_instance_call = |
| 302 | instruction.Opcode() != Instruction::INVOKE_STATIC |
| 303 | && instruction.Opcode() != Instruction::INVOKE_STATIC_RANGE; |
| 304 | const size_t number_of_arguments = strlen(descriptor) - (is_instance_call ? 0 : 1); |
| 305 | |
| 306 | // Treat invoke-direct like static calls for now. |
| 307 | HInvoke* invoke = new (arena_) HInvokeStatic( |
| 308 | arena_, number_of_arguments, return_type, dex_offset, method_idx); |
| 309 | |
| 310 | size_t start_index = 0; |
| 311 | if (is_instance_call) { |
| 312 | HInstruction* arg = LoadLocal(is_range ? register_index : args[0], Primitive::kPrimNot); |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 313 | invoke->SetArgumentAt(0, arg); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 314 | start_index = 1; |
| 315 | } |
| 316 | |
| 317 | uint32_t descriptor_index = 1; |
| 318 | uint32_t argument_index = start_index; |
| 319 | for (size_t i = start_index; i < number_of_vreg_arguments; i++, argument_index++) { |
| 320 | Primitive::Type type = Primitive::GetType(descriptor[descriptor_index++]); |
Nicolas Geoffray | abed4d0 | 2014-07-14 15:24:11 +0100 | [diff] [blame] | 321 | if (!IsTypeSupported(type)) { |
| 322 | return false; |
| 323 | } |
| 324 | if (!is_range && type == Primitive::kPrimLong && args[i] + 1 != args[i + 1]) { |
| 325 | LOG(WARNING) << "Non sequential register pair in " << dex_compilation_unit_->GetSymbol() |
| 326 | << " at " << dex_offset; |
| 327 | // We do not implement non sequential register pair. |
| 328 | return false; |
| 329 | } |
| 330 | HInstruction* arg = LoadLocal(is_range ? register_index + i : args[i], type); |
| 331 | invoke->SetArgumentAt(argument_index, arg); |
| 332 | if (type == Primitive::kPrimLong) { |
| 333 | i++; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 334 | } |
| 335 | } |
| 336 | |
Nicolas Geoffray | abed4d0 | 2014-07-14 15:24:11 +0100 | [diff] [blame] | 337 | if (!IsTypeSupported(return_type)) { |
Nicolas Geoffray | f635e63 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 338 | return false; |
| 339 | } |
| 340 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 341 | DCHECK_EQ(argument_index, number_of_arguments); |
| 342 | current_block_->AddInstruction(invoke); |
| 343 | return true; |
| 344 | } |
| 345 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 346 | /** |
| 347 | * Helper class to add HTemporary instructions. This class is used when |
| 348 | * converting a DEX instruction to multiple HInstruction, and where those |
| 349 | * instructions do not die at the following instruction, but instead spans |
| 350 | * multiple instructions. |
| 351 | */ |
| 352 | class Temporaries : public ValueObject { |
| 353 | public: |
| 354 | Temporaries(HGraph* graph, size_t count) : graph_(graph), count_(count), index_(0) { |
| 355 | graph_->UpdateNumberOfTemporaries(count_); |
| 356 | } |
| 357 | |
| 358 | void Add(HInstruction* instruction) { |
| 359 | // We currently only support vreg size temps. |
| 360 | DCHECK(instruction->GetType() != Primitive::kPrimLong |
| 361 | && instruction->GetType() != Primitive::kPrimDouble); |
| 362 | HInstruction* temp = new (graph_->GetArena()) HTemporary(index_++); |
| 363 | instruction->GetBlock()->AddInstruction(temp); |
| 364 | DCHECK(temp->GetPrevious() == instruction); |
| 365 | } |
| 366 | |
| 367 | private: |
| 368 | HGraph* const graph_; |
| 369 | |
| 370 | // The total number of temporaries that will be used. |
| 371 | const size_t count_; |
| 372 | |
| 373 | // Current index in the temporary stack, updated by `Add`. |
| 374 | size_t index_; |
| 375 | }; |
| 376 | |
| 377 | bool HGraphBuilder::BuildFieldAccess(const Instruction& instruction, |
| 378 | uint32_t dex_offset, |
| 379 | bool is_put) { |
| 380 | uint32_t source_or_dest_reg = instruction.VRegA_22c(); |
| 381 | uint32_t obj_reg = instruction.VRegB_22c(); |
| 382 | uint16_t field_index = instruction.VRegC_22c(); |
| 383 | |
| 384 | ScopedObjectAccess soa(Thread::Current()); |
| 385 | StackHandleScope<1> hs(soa.Self()); |
| 386 | Handle<mirror::ArtField> resolved_field(hs.NewHandle( |
| 387 | compiler_driver_->ComputeInstanceFieldInfo(field_index, dex_compilation_unit_, is_put, soa))); |
| 388 | |
| 389 | if (resolved_field.Get() == nullptr) { |
| 390 | return false; |
| 391 | } |
| 392 | if (resolved_field->IsVolatile()) { |
| 393 | return false; |
| 394 | } |
| 395 | |
Nicolas Geoffray | abed4d0 | 2014-07-14 15:24:11 +0100 | [diff] [blame] | 396 | Primitive::Type field_type = resolved_field->GetTypeAsPrimitiveType(); |
| 397 | if (!IsTypeSupported(field_type)) { |
| 398 | return false; |
| 399 | } |
| 400 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 401 | HInstruction* object = LoadLocal(obj_reg, Primitive::kPrimNot); |
| 402 | current_block_->AddInstruction(new (arena_) HNullCheck(object, dex_offset)); |
| 403 | if (is_put) { |
| 404 | Temporaries temps(graph_, 1); |
| 405 | HInstruction* null_check = current_block_->GetLastInstruction(); |
| 406 | // We need one temporary for the null check. |
| 407 | temps.Add(null_check); |
Nicolas Geoffray | abed4d0 | 2014-07-14 15:24:11 +0100 | [diff] [blame] | 408 | HInstruction* value = LoadLocal(source_or_dest_reg, field_type); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 409 | current_block_->AddInstruction(new (arena_) HInstanceFieldSet( |
| 410 | null_check, |
| 411 | value, |
| 412 | resolved_field->GetOffset())); |
| 413 | } else { |
| 414 | current_block_->AddInstruction(new (arena_) HInstanceFieldGet( |
| 415 | current_block_->GetLastInstruction(), |
Nicolas Geoffray | abed4d0 | 2014-07-14 15:24:11 +0100 | [diff] [blame] | 416 | field_type, |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 417 | resolved_field->GetOffset())); |
| 418 | |
| 419 | UpdateLocal(source_or_dest_reg, current_block_->GetLastInstruction()); |
| 420 | } |
| 421 | return true; |
| 422 | } |
| 423 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 424 | bool HGraphBuilder::AnalyzeDexInstruction(const Instruction& instruction, int32_t dex_offset) { |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 425 | if (current_block_ == nullptr) { |
| 426 | return true; // Dead code |
| 427 | } |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 428 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 429 | switch (instruction.Opcode()) { |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 430 | case Instruction::CONST_4: { |
| 431 | int32_t register_index = instruction.VRegA(); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 432 | HIntConstant* constant = GetIntConstant(instruction.VRegB_11n()); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 433 | UpdateLocal(register_index, constant); |
| 434 | break; |
| 435 | } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 436 | |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 437 | case Instruction::CONST_16: { |
| 438 | int32_t register_index = instruction.VRegA(); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 439 | HIntConstant* constant = GetIntConstant(instruction.VRegB_21s()); |
| 440 | UpdateLocal(register_index, constant); |
| 441 | break; |
| 442 | } |
| 443 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 444 | case Instruction::CONST: { |
| 445 | int32_t register_index = instruction.VRegA(); |
| 446 | HIntConstant* constant = GetIntConstant(instruction.VRegB_31i()); |
| 447 | UpdateLocal(register_index, constant); |
| 448 | break; |
| 449 | } |
| 450 | |
| 451 | case Instruction::CONST_HIGH16: { |
| 452 | int32_t register_index = instruction.VRegA(); |
| 453 | HIntConstant* constant = GetIntConstant(instruction.VRegB_21h() << 16); |
| 454 | UpdateLocal(register_index, constant); |
| 455 | break; |
| 456 | } |
| 457 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 458 | case Instruction::CONST_WIDE_16: { |
| 459 | int32_t register_index = instruction.VRegA(); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 460 | // Get 16 bits of constant value, sign extended to 64 bits. |
| 461 | int64_t value = instruction.VRegB_21s(); |
| 462 | value <<= 48; |
| 463 | value >>= 48; |
| 464 | HLongConstant* constant = GetLongConstant(value); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 465 | UpdateLocal(register_index, constant); |
| 466 | break; |
| 467 | } |
| 468 | |
| 469 | case Instruction::CONST_WIDE_32: { |
| 470 | int32_t register_index = instruction.VRegA(); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 471 | // Get 32 bits of constant value, sign extended to 64 bits. |
| 472 | int64_t value = instruction.VRegB_31i(); |
| 473 | value <<= 32; |
| 474 | value >>= 32; |
| 475 | HLongConstant* constant = GetLongConstant(value); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 476 | UpdateLocal(register_index, constant); |
| 477 | break; |
| 478 | } |
| 479 | |
| 480 | case Instruction::CONST_WIDE: { |
| 481 | int32_t register_index = instruction.VRegA(); |
| 482 | HLongConstant* constant = GetLongConstant(instruction.VRegB_51l()); |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 483 | UpdateLocal(register_index, constant); |
| 484 | break; |
| 485 | } |
| 486 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 487 | case Instruction::CONST_WIDE_HIGH16: { |
| 488 | int32_t register_index = instruction.VRegA(); |
| 489 | int64_t value = static_cast<int64_t>(instruction.VRegB_21h()) << 48; |
| 490 | HLongConstant* constant = GetLongConstant(value); |
| 491 | UpdateLocal(register_index, constant); |
| 492 | break; |
| 493 | } |
| 494 | |
| 495 | // TODO: these instructions are also used to move floating point values, so what is |
| 496 | // the type (int or float)? |
| 497 | case Instruction::MOVE: |
| 498 | case Instruction::MOVE_FROM16: |
| 499 | case Instruction::MOVE_16: { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 500 | HInstruction* value = LoadLocal(instruction.VRegB(), Primitive::kPrimInt); |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 501 | UpdateLocal(instruction.VRegA(), value); |
| 502 | break; |
| 503 | } |
| 504 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 505 | // TODO: these instructions are also used to move floating point values, so what is |
| 506 | // the type (long or double)? |
| 507 | case Instruction::MOVE_WIDE: |
| 508 | case Instruction::MOVE_WIDE_FROM16: |
| 509 | case Instruction::MOVE_WIDE_16: { |
| 510 | HInstruction* value = LoadLocal(instruction.VRegB(), Primitive::kPrimLong); |
| 511 | UpdateLocal(instruction.VRegA(), value); |
| 512 | break; |
| 513 | } |
| 514 | |
| 515 | case Instruction::MOVE_OBJECT: |
| 516 | case Instruction::MOVE_OBJECT_16: |
| 517 | case Instruction::MOVE_OBJECT_FROM16: { |
| 518 | HInstruction* value = LoadLocal(instruction.VRegB(), Primitive::kPrimNot); |
| 519 | UpdateLocal(instruction.VRegA(), value); |
| 520 | break; |
| 521 | } |
| 522 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 523 | case Instruction::RETURN_VOID: { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 524 | BuildReturn(instruction, Primitive::kPrimVoid); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 525 | break; |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 526 | } |
| 527 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 528 | #define IF_XX(comparison, cond) \ |
| 529 | case Instruction::IF_##cond: If_22t<comparison>(instruction, dex_offset); break; \ |
| 530 | case Instruction::IF_##cond##Z: If_21t<comparison>(instruction, dex_offset); break |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 531 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 532 | IF_XX(HEqual, EQ); |
| 533 | IF_XX(HNotEqual, NE); |
| 534 | IF_XX(HLessThan, LT); |
| 535 | IF_XX(HLessThanOrEqual, LE); |
| 536 | IF_XX(HGreaterThan, GT); |
| 537 | IF_XX(HGreaterThanOrEqual, GE); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 538 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 539 | case Instruction::GOTO: |
| 540 | case Instruction::GOTO_16: |
| 541 | case Instruction::GOTO_32: { |
| 542 | HBasicBlock* target = FindBlockStartingAt(instruction.GetTargetOffset() + dex_offset); |
| 543 | DCHECK(target != nullptr); |
| 544 | current_block_->AddInstruction(new (arena_) HGoto()); |
| 545 | current_block_->AddSuccessor(target); |
| 546 | current_block_ = nullptr; |
| 547 | break; |
| 548 | } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 549 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 550 | case Instruction::RETURN: { |
| 551 | BuildReturn(instruction, Primitive::kPrimInt); |
| 552 | break; |
| 553 | } |
| 554 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 555 | case Instruction::RETURN_OBJECT: { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 556 | BuildReturn(instruction, Primitive::kPrimNot); |
| 557 | break; |
| 558 | } |
| 559 | |
| 560 | case Instruction::RETURN_WIDE: { |
| 561 | BuildReturn(instruction, Primitive::kPrimLong); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 562 | break; |
| 563 | } |
| 564 | |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 565 | case Instruction::INVOKE_STATIC: |
| 566 | case Instruction::INVOKE_DIRECT: { |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 567 | uint32_t method_idx = instruction.VRegB_35c(); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 568 | uint32_t number_of_vreg_arguments = instruction.VRegA_35c(); |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 569 | uint32_t args[5]; |
Ian Rogers | 29a2648 | 2014-05-02 15:27:29 -0700 | [diff] [blame] | 570 | instruction.GetVarArgs(args); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 571 | if (!BuildInvoke(instruction, dex_offset, method_idx, number_of_vreg_arguments, false, args, -1)) { |
| 572 | return false; |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 573 | } |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 574 | break; |
| 575 | } |
| 576 | |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 577 | case Instruction::INVOKE_STATIC_RANGE: |
| 578 | case Instruction::INVOKE_DIRECT_RANGE: { |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 579 | uint32_t method_idx = instruction.VRegB_3rc(); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 580 | uint32_t number_of_vreg_arguments = instruction.VRegA_3rc(); |
| 581 | uint32_t register_index = instruction.VRegC(); |
| 582 | if (!BuildInvoke(instruction, dex_offset, method_idx, |
| 583 | number_of_vreg_arguments, true, nullptr, register_index)) { |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 584 | return false; |
| 585 | } |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 586 | break; |
| 587 | } |
| 588 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 589 | case Instruction::ADD_INT: { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 590 | Binop_23x<HAdd>(instruction, Primitive::kPrimInt); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 591 | break; |
| 592 | } |
| 593 | |
| 594 | case Instruction::ADD_LONG: { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 595 | Binop_23x<HAdd>(instruction, Primitive::kPrimLong); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 596 | break; |
| 597 | } |
| 598 | |
| 599 | case Instruction::SUB_INT: { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 600 | Binop_23x<HSub>(instruction, Primitive::kPrimInt); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 601 | break; |
| 602 | } |
| 603 | |
| 604 | case Instruction::SUB_LONG: { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 605 | Binop_23x<HSub>(instruction, Primitive::kPrimLong); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 606 | break; |
| 607 | } |
| 608 | |
| 609 | case Instruction::ADD_INT_2ADDR: { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 610 | Binop_12x<HAdd>(instruction, Primitive::kPrimInt); |
| 611 | break; |
| 612 | } |
| 613 | |
| 614 | case Instruction::ADD_LONG_2ADDR: { |
| 615 | Binop_12x<HAdd>(instruction, Primitive::kPrimLong); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 616 | break; |
| 617 | } |
| 618 | |
| 619 | case Instruction::SUB_INT_2ADDR: { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 620 | Binop_12x<HSub>(instruction, Primitive::kPrimInt); |
| 621 | break; |
| 622 | } |
| 623 | |
| 624 | case Instruction::SUB_LONG_2ADDR: { |
| 625 | Binop_12x<HSub>(instruction, Primitive::kPrimLong); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 626 | break; |
| 627 | } |
| 628 | |
| 629 | case Instruction::ADD_INT_LIT16: { |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 630 | Binop_22s<HAdd>(instruction, false); |
| 631 | break; |
| 632 | } |
| 633 | |
| 634 | case Instruction::RSUB_INT: { |
| 635 | Binop_22s<HSub>(instruction, true); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 636 | break; |
| 637 | } |
| 638 | |
| 639 | case Instruction::ADD_INT_LIT8: { |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 640 | Binop_22b<HAdd>(instruction, false); |
| 641 | break; |
| 642 | } |
| 643 | |
| 644 | case Instruction::RSUB_INT_LIT8: { |
| 645 | Binop_22b<HSub>(instruction, true); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 646 | break; |
| 647 | } |
| 648 | |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 649 | case Instruction::NEW_INSTANCE: { |
| 650 | current_block_->AddInstruction( |
| 651 | new (arena_) HNewInstance(dex_offset, instruction.VRegB_21c())); |
| 652 | UpdateLocal(instruction.VRegA(), current_block_->GetLastInstruction()); |
| 653 | break; |
| 654 | } |
| 655 | |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 656 | case Instruction::MOVE_RESULT: |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 657 | case Instruction::MOVE_RESULT_WIDE: |
| 658 | case Instruction::MOVE_RESULT_OBJECT: |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 659 | UpdateLocal(instruction.VRegA(), current_block_->GetLastInstruction()); |
| 660 | break; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 661 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 662 | case Instruction::CMP_LONG: { |
| 663 | Binop_23x<HCompare>(instruction, Primitive::kPrimLong); |
| 664 | break; |
| 665 | } |
| 666 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 667 | case Instruction::NOP: |
| 668 | break; |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 669 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 670 | case Instruction::IGET: |
| 671 | case Instruction::IGET_WIDE: |
| 672 | case Instruction::IGET_OBJECT: |
| 673 | case Instruction::IGET_BOOLEAN: |
| 674 | case Instruction::IGET_BYTE: |
| 675 | case Instruction::IGET_CHAR: |
| 676 | case Instruction::IGET_SHORT: { |
| 677 | if (!BuildFieldAccess(instruction, dex_offset, false)) { |
| 678 | return false; |
| 679 | } |
| 680 | break; |
| 681 | } |
| 682 | |
| 683 | case Instruction::IPUT: |
| 684 | case Instruction::IPUT_WIDE: |
| 685 | case Instruction::IPUT_OBJECT: |
| 686 | case Instruction::IPUT_BOOLEAN: |
| 687 | case Instruction::IPUT_BYTE: |
| 688 | case Instruction::IPUT_CHAR: |
| 689 | case Instruction::IPUT_SHORT: { |
| 690 | if (!BuildFieldAccess(instruction, dex_offset, true)) { |
| 691 | return false; |
| 692 | } |
| 693 | break; |
| 694 | } |
| 695 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 696 | default: |
| 697 | return false; |
| 698 | } |
| 699 | return true; |
| 700 | } |
| 701 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 702 | HIntConstant* HGraphBuilder::GetIntConstant0() { |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 703 | if (constant0_ != nullptr) { |
| 704 | return constant0_; |
| 705 | } |
| 706 | constant0_ = new(arena_) HIntConstant(0); |
| 707 | entry_block_->AddInstruction(constant0_); |
| 708 | return constant0_; |
| 709 | } |
| 710 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 711 | HIntConstant* HGraphBuilder::GetIntConstant1() { |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 712 | if (constant1_ != nullptr) { |
| 713 | return constant1_; |
| 714 | } |
| 715 | constant1_ = new(arena_) HIntConstant(1); |
| 716 | entry_block_->AddInstruction(constant1_); |
| 717 | return constant1_; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 718 | } |
| 719 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 720 | HIntConstant* HGraphBuilder::GetIntConstant(int32_t constant) { |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 721 | switch (constant) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 722 | case 0: return GetIntConstant0(); |
| 723 | case 1: return GetIntConstant1(); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 724 | default: { |
| 725 | HIntConstant* instruction = new (arena_) HIntConstant(constant); |
| 726 | entry_block_->AddInstruction(instruction); |
| 727 | return instruction; |
| 728 | } |
| 729 | } |
| 730 | } |
| 731 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 732 | HLongConstant* HGraphBuilder::GetLongConstant(int64_t constant) { |
| 733 | HLongConstant* instruction = new (arena_) HLongConstant(constant); |
| 734 | entry_block_->AddInstruction(instruction); |
| 735 | return instruction; |
| 736 | } |
| 737 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 738 | HLocal* HGraphBuilder::GetLocalAt(int register_index) const { |
| 739 | return locals_.Get(register_index); |
| 740 | } |
| 741 | |
| 742 | void HGraphBuilder::UpdateLocal(int register_index, HInstruction* instruction) const { |
| 743 | HLocal* local = GetLocalAt(register_index); |
| 744 | current_block_->AddInstruction(new (arena_) HStoreLocal(local, instruction)); |
| 745 | } |
| 746 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 747 | HInstruction* HGraphBuilder::LoadLocal(int register_index, Primitive::Type type) const { |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 748 | HLocal* local = GetLocalAt(register_index); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 749 | current_block_->AddInstruction(new (arena_) HLoadLocal(local, type)); |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 750 | return current_block_->GetLastInstruction(); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 751 | } |
| 752 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 753 | } // namespace art |