blob: 33b00d2ac9d03b4026bcfdd34d812ad81c166e1f [file] [log] [blame]
Nicolas Geoffray818f2102014-02-18 16:43:35 +00001/*
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 Geoffraye5038322014-07-04 09:41:32 +010018#include "builder.h"
19
20#include "class_linker.h"
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +000021#include "dex_file.h"
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +000022#include "dex_file-inl.h"
Nicolas Geoffray818f2102014-02-18 16:43:35 +000023#include "dex_instruction.h"
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +000024#include "dex_instruction-inl.h"
Nicolas Geoffraye5038322014-07-04 09:41:32 +010025#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 Geoffray818f2102014-02-18 16:43:35 +000030#include "nodes.h"
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +000031#include "primitive.h"
Nicolas Geoffraye5038322014-07-04 09:41:32 +010032#include "scoped_thread_state_change.h"
33#include "thread.h"
Nicolas Geoffray818f2102014-02-18 16:43:35 +000034
35namespace art {
36
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +010037/**
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 */
43class 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 Geoffrayabed4d02014-07-14 15:24:11 +010068static bool IsTypeSupported(Primitive::Type type) {
69 return type != Primitive::kPrimFloat && type != Primitive::kPrimDouble;
70}
71
Nicolas Geoffrayf583e592014-04-07 13:20:42 +010072void HGraphBuilder::InitializeLocals(uint16_t count) {
73 graph_->SetNumberOfVRegs(count);
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +000074 locals_.SetSize(count);
75 for (int i = 0; i < count; i++) {
76 HLocal* local = new (arena_) HLocal(i);
77 entry_block_->AddInstruction(local);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +000078 locals_.Put(i, local);
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +000079 }
80}
81
Nicolas Geoffrayf583e592014-04-07 13:20:42 +010082bool 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 Geoffrayf583e592014-04-07 13:20:42 +010091 int parameter_index = 0;
92
93 if (!dex_compilation_unit_->IsStatic()) {
94 // Add the implicit 'this' argument, not expressed in the signature.
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +010095 HParameterValue* parameter =
96 new (arena_) HParameterValue(parameter_index++, Primitive::kPrimNot);
Nicolas Geoffrayb55f8352014-04-07 15:26:35 +010097 entry_block_->AddInstruction(parameter);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +010098 HLocal* local = GetLocalAt(locals_index++);
Nicolas Geoffrayb55f8352014-04-07 15:26:35 +010099 entry_block_->AddInstruction(new (arena_) HStoreLocal(local, parameter));
Nicolas Geoffrayf583e592014-04-07 13:20:42 +0100100 number_of_parameters--;
101 }
102
103 uint32_t pos = 1;
104 for (int i = 0; i < number_of_parameters; i++) {
105 switch (shorty[pos++]) {
106 case 'F':
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100107 case 'D': {
Nicolas Geoffrayf583e592014-04-07 13:20:42 +0100108 return false;
109 }
110
111 default: {
112 // integer and reference parameters.
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100113 HParameterValue* parameter =
114 new (arena_) HParameterValue(parameter_index++, Primitive::GetType(shorty[pos - 1]));
Nicolas Geoffrayb55f8352014-04-07 15:26:35 +0100115 entry_block_->AddInstruction(parameter);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +0100116 HLocal* local = GetLocalAt(locals_index++);
117 // Store the parameter value in the local that the dex code will use
118 // to reference that parameter.
Nicolas Geoffrayb55f8352014-04-07 15:26:35 +0100119 entry_block_->AddInstruction(new (arena_) HStoreLocal(local, parameter));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100120 if (parameter->GetType() == Primitive::kPrimLong) {
121 i++;
122 locals_index++;
123 parameter_index++;
124 }
Nicolas Geoffrayf583e592014-04-07 13:20:42 +0100125 break;
126 }
127 }
128 }
129 return true;
130}
131
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +0000132static bool CanHandleCodeItem(const DexFile::CodeItem& code_item) {
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000133 if (code_item.tries_size_ > 0) {
134 return false;
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000135 }
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +0000136 return true;
137}
138
Nicolas Geoffrayb55f8352014-04-07 15:26:35 +0100139template<typename T>
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100140void HGraphBuilder::If_22t(const Instruction& instruction, uint32_t dex_offset) {
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000141 int32_t target_offset = instruction.GetTargetOffset();
142 PotentiallyAddSuspendCheck(target_offset, dex_offset);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100143 HInstruction* first = LoadLocal(instruction.VRegA(), Primitive::kPrimInt);
144 HInstruction* second = LoadLocal(instruction.VRegB(), Primitive::kPrimInt);
Dave Allison20dfc792014-06-16 20:44:29 -0700145 T* comparison = new (arena_) T(first, second);
146 current_block_->AddInstruction(comparison);
147 HInstruction* ifinst = new (arena_) HIf(comparison);
148 current_block_->AddInstruction(ifinst);
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000149 HBasicBlock* target = FindBlockStartingAt(dex_offset + target_offset);
Dave Allison20dfc792014-06-16 20:44:29 -0700150 DCHECK(target != nullptr);
151 current_block_->AddSuccessor(target);
152 target = FindBlockStartingAt(dex_offset + instruction.SizeInCodeUnits());
153 DCHECK(target != nullptr);
154 current_block_->AddSuccessor(target);
155 current_block_ = nullptr;
156}
157
158template<typename T>
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100159void HGraphBuilder::If_21t(const Instruction& instruction, uint32_t dex_offset) {
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000160 int32_t target_offset = instruction.GetTargetOffset();
161 PotentiallyAddSuspendCheck(target_offset, dex_offset);
Dave Allison20dfc792014-06-16 20:44:29 -0700162 HInstruction* value = LoadLocal(instruction.VRegA(), Primitive::kPrimInt);
163 T* comparison = new (arena_) T(value, GetIntConstant(0));
164 current_block_->AddInstruction(comparison);
165 HInstruction* ifinst = new (arena_) HIf(comparison);
166 current_block_->AddInstruction(ifinst);
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000167 HBasicBlock* target = FindBlockStartingAt(dex_offset + target_offset);
Nicolas Geoffrayb55f8352014-04-07 15:26:35 +0100168 DCHECK(target != nullptr);
169 current_block_->AddSuccessor(target);
170 target = FindBlockStartingAt(dex_offset + instruction.SizeInCodeUnits());
171 DCHECK(target != nullptr);
172 current_block_->AddSuccessor(target);
173 current_block_ = nullptr;
174}
175
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +0000176HGraph* HGraphBuilder::BuildGraph(const DexFile::CodeItem& code_item) {
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000177 if (!CanHandleCodeItem(code_item)) {
178 return nullptr;
179 }
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +0000180
181 const uint16_t* code_ptr = code_item.insns_;
182 const uint16_t* code_end = code_item.insns_ + code_item.insns_size_in_code_units_;
183
Nicolas Geoffraybe9a92a2014-02-25 14:22:56 +0000184 // Setup the graph with the entry block and exit block.
Nicolas Geoffray818f2102014-02-18 16:43:35 +0000185 graph_ = new (arena_) HGraph(arena_);
Nicolas Geoffray818f2102014-02-18 16:43:35 +0000186 entry_block_ = new (arena_) HBasicBlock(graph_);
187 graph_->AddBlock(entry_block_);
Nicolas Geoffray818f2102014-02-18 16:43:35 +0000188 exit_block_ = new (arena_) HBasicBlock(graph_);
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000189 graph_->SetEntryBlock(entry_block_);
190 graph_->SetExitBlock(exit_block_);
Nicolas Geoffray818f2102014-02-18 16:43:35 +0000191
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +0000192 InitializeLocals(code_item.registers_size_);
Nicolas Geoffray4a34a422014-04-03 10:38:37 +0100193 graph_->UpdateMaximumNumberOfOutVRegs(code_item.outs_size_);
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +0000194
Nicolas Geoffraybe9a92a2014-02-25 14:22:56 +0000195 // To avoid splitting blocks, we compute ahead of time the instructions that
196 // start a new block, and create these blocks.
197 ComputeBranchTargets(code_ptr, code_end);
Nicolas Geoffray818f2102014-02-18 16:43:35 +0000198
Nicolas Geoffrayf583e592014-04-07 13:20:42 +0100199 if (!InitializeParameters(code_item.ins_size_)) {
200 return nullptr;
201 }
202
Nicolas Geoffraybe9a92a2014-02-25 14:22:56 +0000203 size_t dex_offset = 0;
Nicolas Geoffray818f2102014-02-18 16:43:35 +0000204 while (code_ptr < code_end) {
Nicolas Geoffraybe9a92a2014-02-25 14:22:56 +0000205 // Update the current block if dex_offset starts a new block.
206 MaybeUpdateCurrentBlock(dex_offset);
Nicolas Geoffray818f2102014-02-18 16:43:35 +0000207 const Instruction& instruction = *Instruction::At(code_ptr);
Nicolas Geoffraybe9a92a2014-02-25 14:22:56 +0000208 if (!AnalyzeDexInstruction(instruction, dex_offset)) return nullptr;
209 dex_offset += instruction.SizeInCodeUnits();
Nicolas Geoffray818f2102014-02-18 16:43:35 +0000210 code_ptr += instruction.SizeInCodeUnits();
211 }
212
Nicolas Geoffraybe9a92a2014-02-25 14:22:56 +0000213 // Add the exit block at the end to give it the highest id.
Nicolas Geoffray818f2102014-02-18 16:43:35 +0000214 graph_->AddBlock(exit_block_);
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +0000215 exit_block_->AddInstruction(new (arena_) HExit());
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000216 // Add the suspend check to the entry block.
217 entry_block_->AddInstruction(new (arena_) HSuspendCheck(0));
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +0000218 entry_block_->AddInstruction(new (arena_) HGoto());
Nicolas Geoffray818f2102014-02-18 16:43:35 +0000219 return graph_;
220}
221
Nicolas Geoffraybe9a92a2014-02-25 14:22:56 +0000222void HGraphBuilder::MaybeUpdateCurrentBlock(size_t index) {
223 HBasicBlock* block = FindBlockStartingAt(index);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000224 if (block == nullptr) {
225 return;
226 }
Nicolas Geoffraybe9a92a2014-02-25 14:22:56 +0000227
228 if (current_block_ != nullptr) {
229 // Branching instructions clear current_block, so we know
230 // the last instruction of the current block is not a branching
231 // instruction. We add an unconditional goto to the found block.
232 current_block_->AddInstruction(new (arena_) HGoto());
233 current_block_->AddSuccessor(block);
234 }
235 graph_->AddBlock(block);
236 current_block_ = block;
237}
238
239void HGraphBuilder::ComputeBranchTargets(const uint16_t* code_ptr, const uint16_t* code_end) {
240 // TODO: Support switch instructions.
241 branch_targets_.SetSize(code_end - code_ptr);
242
243 // Create the first block for the dex instructions, single successor of the entry block.
244 HBasicBlock* block = new (arena_) HBasicBlock(graph_);
245 branch_targets_.Put(0, block);
246 entry_block_->AddSuccessor(block);
247
248 // Iterate over all instructions and find branching instructions. Create blocks for
249 // the locations these instructions branch to.
250 size_t dex_offset = 0;
251 while (code_ptr < code_end) {
252 const Instruction& instruction = *Instruction::At(code_ptr);
253 if (instruction.IsBranch()) {
254 int32_t target = instruction.GetTargetOffset() + dex_offset;
255 // Create a block for the target instruction.
256 if (FindBlockStartingAt(target) == nullptr) {
257 block = new (arena_) HBasicBlock(graph_);
258 branch_targets_.Put(target, block);
259 }
260 dex_offset += instruction.SizeInCodeUnits();
261 code_ptr += instruction.SizeInCodeUnits();
262 if ((code_ptr < code_end) && (FindBlockStartingAt(dex_offset) == nullptr)) {
263 block = new (arena_) HBasicBlock(graph_);
264 branch_targets_.Put(dex_offset, block);
265 }
266 } else {
267 code_ptr += instruction.SizeInCodeUnits();
268 dex_offset += instruction.SizeInCodeUnits();
269 }
270 }
271}
272
273HBasicBlock* HGraphBuilder::FindBlockStartingAt(int32_t index) const {
274 DCHECK_GE(index, 0);
275 return branch_targets_.Get(index);
276}
277
Nicolas Geoffrayf583e592014-04-07 13:20:42 +0100278template<typename T>
Nicolas Geoffray412f10c2014-06-19 10:00:34 +0100279void HGraphBuilder::Binop_23x(const Instruction& instruction, Primitive::Type type) {
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100280 HInstruction* first = LoadLocal(instruction.VRegB(), type);
281 HInstruction* second = LoadLocal(instruction.VRegC(), type);
282 current_block_->AddInstruction(new (arena_) T(type, first, second));
Nicolas Geoffrayf583e592014-04-07 13:20:42 +0100283 UpdateLocal(instruction.VRegA(), current_block_->GetLastInstruction());
284}
285
286template<typename T>
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100287void HGraphBuilder::Binop_12x(const Instruction& instruction, Primitive::Type type) {
288 HInstruction* first = LoadLocal(instruction.VRegA(), type);
289 HInstruction* second = LoadLocal(instruction.VRegB(), type);
290 current_block_->AddInstruction(new (arena_) T(type, first, second));
Nicolas Geoffrayf583e592014-04-07 13:20:42 +0100291 UpdateLocal(instruction.VRegA(), current_block_->GetLastInstruction());
292}
293
294template<typename T>
295void HGraphBuilder::Binop_22s(const Instruction& instruction, bool reverse) {
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100296 HInstruction* first = LoadLocal(instruction.VRegB(), Primitive::kPrimInt);
297 HInstruction* second = GetIntConstant(instruction.VRegC_22s());
Nicolas Geoffrayf583e592014-04-07 13:20:42 +0100298 if (reverse) {
299 std::swap(first, second);
300 }
301 current_block_->AddInstruction(new (arena_) T(Primitive::kPrimInt, first, second));
302 UpdateLocal(instruction.VRegA(), current_block_->GetLastInstruction());
303}
304
305template<typename T>
306void HGraphBuilder::Binop_22b(const Instruction& instruction, bool reverse) {
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100307 HInstruction* first = LoadLocal(instruction.VRegB(), Primitive::kPrimInt);
308 HInstruction* second = GetIntConstant(instruction.VRegC_22b());
Nicolas Geoffrayf583e592014-04-07 13:20:42 +0100309 if (reverse) {
310 std::swap(first, second);
311 }
312 current_block_->AddInstruction(new (arena_) T(Primitive::kPrimInt, first, second));
313 UpdateLocal(instruction.VRegA(), current_block_->GetLastInstruction());
314}
315
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100316void HGraphBuilder::BuildReturn(const Instruction& instruction, Primitive::Type type) {
317 if (type == Primitive::kPrimVoid) {
318 current_block_->AddInstruction(new (arena_) HReturnVoid());
319 } else {
320 HInstruction* value = LoadLocal(instruction.VRegA(), type);
321 current_block_->AddInstruction(new (arena_) HReturn(value));
322 }
323 current_block_->AddSuccessor(exit_block_);
324 current_block_ = nullptr;
325}
326
327bool HGraphBuilder::BuildInvoke(const Instruction& instruction,
328 uint32_t dex_offset,
329 uint32_t method_idx,
330 uint32_t number_of_vreg_arguments,
331 bool is_range,
332 uint32_t* args,
333 uint32_t register_index) {
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +0100334 Instruction::Code opcode = instruction.Opcode();
335 InvokeType invoke_type;
336 switch (opcode) {
337 case Instruction::INVOKE_STATIC:
338 case Instruction::INVOKE_STATIC_RANGE:
339 invoke_type = kStatic;
340 break;
341 case Instruction::INVOKE_DIRECT:
342 case Instruction::INVOKE_DIRECT_RANGE:
343 invoke_type = kDirect;
344 break;
345 case Instruction::INVOKE_VIRTUAL:
346 case Instruction::INVOKE_VIRTUAL_RANGE:
347 invoke_type = kVirtual;
348 break;
349 case Instruction::INVOKE_INTERFACE:
350 case Instruction::INVOKE_INTERFACE_RANGE:
351 invoke_type = kInterface;
352 break;
353 case Instruction::INVOKE_SUPER_RANGE:
354 case Instruction::INVOKE_SUPER:
355 invoke_type = kSuper;
356 break;
357 default:
358 LOG(FATAL) << "Unexpected invoke op: " << opcode;
359 return false;
360 }
361
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100362 const DexFile::MethodId& method_id = dex_file_->GetMethodId(method_idx);
363 const DexFile::ProtoId& proto_id = dex_file_->GetProtoId(method_id.proto_idx_);
364 const char* descriptor = dex_file_->StringDataByIdx(proto_id.shorty_idx_);
365 Primitive::Type return_type = Primitive::GetType(descriptor[0]);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +0100366 bool is_instance_call = invoke_type != kStatic;
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100367 const size_t number_of_arguments = strlen(descriptor) - (is_instance_call ? 0 : 1);
368
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +0100369 HInvoke* invoke = nullptr;
370 if (invoke_type == kVirtual) {
371 MethodReference target_method(dex_file_, method_idx);
372 uintptr_t direct_code;
373 uintptr_t direct_method;
374 int vtable_index;
375 // TODO: Add devirtualization support.
376 compiler_driver_->ComputeInvokeInfo(dex_compilation_unit_, dex_offset, true, true,
377 &invoke_type, &target_method, &vtable_index,
378 &direct_code, &direct_method);
379 if (vtable_index == -1) {
380 return false;
381 }
382 invoke = new (arena_) HInvokeVirtual(
383 arena_, number_of_arguments, return_type, dex_offset, vtable_index);
384 } else {
385 // Treat invoke-direct like static calls for now.
386 invoke = new (arena_) HInvokeStatic(
387 arena_, number_of_arguments, return_type, dex_offset, method_idx);
388 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100389
390 size_t start_index = 0;
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +0100391 Temporaries temps(graph_, is_instance_call ? 1 : 0);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100392 if (is_instance_call) {
393 HInstruction* arg = LoadLocal(is_range ? register_index : args[0], Primitive::kPrimNot);
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +0100394 HNullCheck* null_check = new (arena_) HNullCheck(arg, dex_offset);
395 current_block_->AddInstruction(null_check);
396 temps.Add(null_check);
397 invoke->SetArgumentAt(0, null_check);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100398 start_index = 1;
399 }
400
401 uint32_t descriptor_index = 1;
402 uint32_t argument_index = start_index;
403 for (size_t i = start_index; i < number_of_vreg_arguments; i++, argument_index++) {
404 Primitive::Type type = Primitive::GetType(descriptor[descriptor_index++]);
Nicolas Geoffrayabed4d02014-07-14 15:24:11 +0100405 if (!IsTypeSupported(type)) {
406 return false;
407 }
408 if (!is_range && type == Primitive::kPrimLong && args[i] + 1 != args[i + 1]) {
409 LOG(WARNING) << "Non sequential register pair in " << dex_compilation_unit_->GetSymbol()
410 << " at " << dex_offset;
411 // We do not implement non sequential register pair.
412 return false;
413 }
414 HInstruction* arg = LoadLocal(is_range ? register_index + i : args[i], type);
415 invoke->SetArgumentAt(argument_index, arg);
416 if (type == Primitive::kPrimLong) {
417 i++;
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100418 }
419 }
420
Nicolas Geoffrayabed4d02014-07-14 15:24:11 +0100421 if (!IsTypeSupported(return_type)) {
Nicolas Geoffrayf635e632014-05-14 09:43:38 +0100422 return false;
423 }
424
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100425 DCHECK_EQ(argument_index, number_of_arguments);
426 current_block_->AddInstruction(invoke);
427 return true;
428}
429
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100430bool HGraphBuilder::BuildFieldAccess(const Instruction& instruction,
431 uint32_t dex_offset,
432 bool is_put) {
433 uint32_t source_or_dest_reg = instruction.VRegA_22c();
434 uint32_t obj_reg = instruction.VRegB_22c();
435 uint16_t field_index = instruction.VRegC_22c();
436
437 ScopedObjectAccess soa(Thread::Current());
438 StackHandleScope<1> hs(soa.Self());
439 Handle<mirror::ArtField> resolved_field(hs.NewHandle(
440 compiler_driver_->ComputeInstanceFieldInfo(field_index, dex_compilation_unit_, is_put, soa)));
441
442 if (resolved_field.Get() == nullptr) {
443 return false;
444 }
445 if (resolved_field->IsVolatile()) {
446 return false;
447 }
448
Nicolas Geoffrayabed4d02014-07-14 15:24:11 +0100449 Primitive::Type field_type = resolved_field->GetTypeAsPrimitiveType();
450 if (!IsTypeSupported(field_type)) {
451 return false;
452 }
453
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100454 HInstruction* object = LoadLocal(obj_reg, Primitive::kPrimNot);
455 current_block_->AddInstruction(new (arena_) HNullCheck(object, dex_offset));
456 if (is_put) {
457 Temporaries temps(graph_, 1);
458 HInstruction* null_check = current_block_->GetLastInstruction();
459 // We need one temporary for the null check.
460 temps.Add(null_check);
Nicolas Geoffrayabed4d02014-07-14 15:24:11 +0100461 HInstruction* value = LoadLocal(source_or_dest_reg, field_type);
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100462 current_block_->AddInstruction(new (arena_) HInstanceFieldSet(
463 null_check,
464 value,
Nicolas Geoffray39468442014-09-02 15:17:15 +0100465 field_type,
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100466 resolved_field->GetOffset()));
467 } else {
468 current_block_->AddInstruction(new (arena_) HInstanceFieldGet(
469 current_block_->GetLastInstruction(),
Nicolas Geoffrayabed4d02014-07-14 15:24:11 +0100470 field_type,
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100471 resolved_field->GetOffset()));
472
473 UpdateLocal(source_or_dest_reg, current_block_->GetLastInstruction());
474 }
475 return true;
476}
477
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100478void HGraphBuilder::BuildArrayAccess(const Instruction& instruction,
479 uint32_t dex_offset,
480 bool is_put,
481 Primitive::Type anticipated_type) {
482 uint8_t source_or_dest_reg = instruction.VRegA_23x();
483 uint8_t array_reg = instruction.VRegB_23x();
484 uint8_t index_reg = instruction.VRegC_23x();
485
486 DCHECK(IsTypeSupported(anticipated_type));
487
488 // We need one temporary for the null check, one for the index, and one for the length.
489 Temporaries temps(graph_, 3);
490
491 HInstruction* object = LoadLocal(array_reg, Primitive::kPrimNot);
492 object = new (arena_) HNullCheck(object, dex_offset);
493 current_block_->AddInstruction(object);
494 temps.Add(object);
495
496 HInstruction* length = new (arena_) HArrayLength(object);
497 current_block_->AddInstruction(length);
498 temps.Add(length);
499 HInstruction* index = LoadLocal(index_reg, Primitive::kPrimInt);
500 index = new (arena_) HBoundsCheck(index, length, dex_offset);
501 current_block_->AddInstruction(index);
502 temps.Add(index);
503 if (is_put) {
504 HInstruction* value = LoadLocal(source_or_dest_reg, anticipated_type);
505 // TODO: Insert a type check node if the type is Object.
Nicolas Geoffray39468442014-09-02 15:17:15 +0100506 current_block_->AddInstruction(new (arena_) HArraySet(
507 object, index, value, anticipated_type, dex_offset));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100508 } else {
509 current_block_->AddInstruction(new (arena_) HArrayGet(object, index, anticipated_type));
510 UpdateLocal(source_or_dest_reg, current_block_->GetLastInstruction());
511 }
512}
513
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000514void HGraphBuilder::PotentiallyAddSuspendCheck(int32_t target_offset, uint32_t dex_offset) {
515 if (target_offset <= 0) {
516 // Unconditionnally add a suspend check to backward branches. We can remove
517 // them after we recognize loops in the graph.
518 current_block_->AddInstruction(new (arena_) HSuspendCheck(dex_offset));
519 }
520}
521
522bool HGraphBuilder::AnalyzeDexInstruction(const Instruction& instruction, uint32_t dex_offset) {
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000523 if (current_block_ == nullptr) {
524 return true; // Dead code
525 }
Nicolas Geoffraybe9a92a2014-02-25 14:22:56 +0000526
Nicolas Geoffray818f2102014-02-18 16:43:35 +0000527 switch (instruction.Opcode()) {
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +0000528 case Instruction::CONST_4: {
529 int32_t register_index = instruction.VRegA();
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100530 HIntConstant* constant = GetIntConstant(instruction.VRegB_11n());
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +0000531 UpdateLocal(register_index, constant);
532 break;
533 }
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000534
Nicolas Geoffrayb55f8352014-04-07 15:26:35 +0100535 case Instruction::CONST_16: {
536 int32_t register_index = instruction.VRegA();
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100537 HIntConstant* constant = GetIntConstant(instruction.VRegB_21s());
538 UpdateLocal(register_index, constant);
539 break;
540 }
541
Dave Allison20dfc792014-06-16 20:44:29 -0700542 case Instruction::CONST: {
543 int32_t register_index = instruction.VRegA();
544 HIntConstant* constant = GetIntConstant(instruction.VRegB_31i());
545 UpdateLocal(register_index, constant);
546 break;
547 }
548
549 case Instruction::CONST_HIGH16: {
550 int32_t register_index = instruction.VRegA();
551 HIntConstant* constant = GetIntConstant(instruction.VRegB_21h() << 16);
552 UpdateLocal(register_index, constant);
553 break;
554 }
555
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100556 case Instruction::CONST_WIDE_16: {
557 int32_t register_index = instruction.VRegA();
Dave Allison20dfc792014-06-16 20:44:29 -0700558 // Get 16 bits of constant value, sign extended to 64 bits.
559 int64_t value = instruction.VRegB_21s();
560 value <<= 48;
561 value >>= 48;
562 HLongConstant* constant = GetLongConstant(value);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100563 UpdateLocal(register_index, constant);
564 break;
565 }
566
567 case Instruction::CONST_WIDE_32: {
568 int32_t register_index = instruction.VRegA();
Dave Allison20dfc792014-06-16 20:44:29 -0700569 // Get 32 bits of constant value, sign extended to 64 bits.
570 int64_t value = instruction.VRegB_31i();
571 value <<= 32;
572 value >>= 32;
573 HLongConstant* constant = GetLongConstant(value);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100574 UpdateLocal(register_index, constant);
575 break;
576 }
577
578 case Instruction::CONST_WIDE: {
579 int32_t register_index = instruction.VRegA();
580 HLongConstant* constant = GetLongConstant(instruction.VRegB_51l());
Nicolas Geoffrayb55f8352014-04-07 15:26:35 +0100581 UpdateLocal(register_index, constant);
582 break;
583 }
584
Dave Allison20dfc792014-06-16 20:44:29 -0700585 case Instruction::CONST_WIDE_HIGH16: {
586 int32_t register_index = instruction.VRegA();
587 int64_t value = static_cast<int64_t>(instruction.VRegB_21h()) << 48;
588 HLongConstant* constant = GetLongConstant(value);
589 UpdateLocal(register_index, constant);
590 break;
591 }
592
593 // TODO: these instructions are also used to move floating point values, so what is
594 // the type (int or float)?
595 case Instruction::MOVE:
596 case Instruction::MOVE_FROM16:
597 case Instruction::MOVE_16: {
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100598 HInstruction* value = LoadLocal(instruction.VRegB(), Primitive::kPrimInt);
Nicolas Geoffrayb55f8352014-04-07 15:26:35 +0100599 UpdateLocal(instruction.VRegA(), value);
600 break;
601 }
602
Dave Allison20dfc792014-06-16 20:44:29 -0700603 // TODO: these instructions are also used to move floating point values, so what is
604 // the type (long or double)?
605 case Instruction::MOVE_WIDE:
606 case Instruction::MOVE_WIDE_FROM16:
607 case Instruction::MOVE_WIDE_16: {
608 HInstruction* value = LoadLocal(instruction.VRegB(), Primitive::kPrimLong);
609 UpdateLocal(instruction.VRegA(), value);
610 break;
611 }
612
613 case Instruction::MOVE_OBJECT:
614 case Instruction::MOVE_OBJECT_16:
615 case Instruction::MOVE_OBJECT_FROM16: {
616 HInstruction* value = LoadLocal(instruction.VRegB(), Primitive::kPrimNot);
617 UpdateLocal(instruction.VRegA(), value);
618 break;
619 }
620
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000621 case Instruction::RETURN_VOID: {
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100622 BuildReturn(instruction, Primitive::kPrimVoid);
Nicolas Geoffray818f2102014-02-18 16:43:35 +0000623 break;
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000624 }
625
Dave Allison20dfc792014-06-16 20:44:29 -0700626#define IF_XX(comparison, cond) \
627 case Instruction::IF_##cond: If_22t<comparison>(instruction, dex_offset); break; \
628 case Instruction::IF_##cond##Z: If_21t<comparison>(instruction, dex_offset); break
Nicolas Geoffrayb55f8352014-04-07 15:26:35 +0100629
Dave Allison20dfc792014-06-16 20:44:29 -0700630 IF_XX(HEqual, EQ);
631 IF_XX(HNotEqual, NE);
632 IF_XX(HLessThan, LT);
633 IF_XX(HLessThanOrEqual, LE);
634 IF_XX(HGreaterThan, GT);
635 IF_XX(HGreaterThanOrEqual, GE);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000636
Nicolas Geoffraybe9a92a2014-02-25 14:22:56 +0000637 case Instruction::GOTO:
638 case Instruction::GOTO_16:
639 case Instruction::GOTO_32: {
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000640 int32_t offset = instruction.GetTargetOffset();
641 PotentiallyAddSuspendCheck(offset, dex_offset);
642 HBasicBlock* target = FindBlockStartingAt(offset + dex_offset);
Nicolas Geoffraybe9a92a2014-02-25 14:22:56 +0000643 DCHECK(target != nullptr);
644 current_block_->AddInstruction(new (arena_) HGoto());
645 current_block_->AddSuccessor(target);
646 current_block_ = nullptr;
647 break;
648 }
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000649
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100650 case Instruction::RETURN: {
651 BuildReturn(instruction, Primitive::kPrimInt);
652 break;
653 }
654
Nicolas Geoffrayf583e592014-04-07 13:20:42 +0100655 case Instruction::RETURN_OBJECT: {
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100656 BuildReturn(instruction, Primitive::kPrimNot);
657 break;
658 }
659
660 case Instruction::RETURN_WIDE: {
661 BuildReturn(instruction, Primitive::kPrimLong);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000662 break;
663 }
664
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +0100665 case Instruction::INVOKE_STATIC:
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +0100666 case Instruction::INVOKE_DIRECT:
667 case Instruction::INVOKE_VIRTUAL: {
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +0000668 uint32_t method_idx = instruction.VRegB_35c();
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100669 uint32_t number_of_vreg_arguments = instruction.VRegA_35c();
Nicolas Geoffray4a34a422014-04-03 10:38:37 +0100670 uint32_t args[5];
Ian Rogers29a26482014-05-02 15:27:29 -0700671 instruction.GetVarArgs(args);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100672 if (!BuildInvoke(instruction, dex_offset, method_idx, number_of_vreg_arguments, false, args, -1)) {
673 return false;
Nicolas Geoffray4a34a422014-04-03 10:38:37 +0100674 }
Nicolas Geoffray4a34a422014-04-03 10:38:37 +0100675 break;
676 }
677
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +0100678 case Instruction::INVOKE_STATIC_RANGE:
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +0100679 case Instruction::INVOKE_DIRECT_RANGE:
680 case Instruction::INVOKE_VIRTUAL_RANGE: {
Nicolas Geoffray4a34a422014-04-03 10:38:37 +0100681 uint32_t method_idx = instruction.VRegB_3rc();
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100682 uint32_t number_of_vreg_arguments = instruction.VRegA_3rc();
683 uint32_t register_index = instruction.VRegC();
684 if (!BuildInvoke(instruction, dex_offset, method_idx,
685 number_of_vreg_arguments, true, nullptr, register_index)) {
Nicolas Geoffray4a34a422014-04-03 10:38:37 +0100686 return false;
687 }
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +0000688 break;
689 }
690
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +0000691 case Instruction::ADD_INT: {
Nicolas Geoffray412f10c2014-06-19 10:00:34 +0100692 Binop_23x<HAdd>(instruction, Primitive::kPrimInt);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100693 break;
694 }
695
696 case Instruction::ADD_LONG: {
Nicolas Geoffray412f10c2014-06-19 10:00:34 +0100697 Binop_23x<HAdd>(instruction, Primitive::kPrimLong);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +0100698 break;
699 }
700
701 case Instruction::SUB_INT: {
Nicolas Geoffray412f10c2014-06-19 10:00:34 +0100702 Binop_23x<HSub>(instruction, Primitive::kPrimInt);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100703 break;
704 }
705
706 case Instruction::SUB_LONG: {
Nicolas Geoffray412f10c2014-06-19 10:00:34 +0100707 Binop_23x<HSub>(instruction, Primitive::kPrimLong);
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +0000708 break;
709 }
710
711 case Instruction::ADD_INT_2ADDR: {
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100712 Binop_12x<HAdd>(instruction, Primitive::kPrimInt);
713 break;
714 }
715
716 case Instruction::ADD_LONG_2ADDR: {
717 Binop_12x<HAdd>(instruction, Primitive::kPrimLong);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +0100718 break;
719 }
720
721 case Instruction::SUB_INT_2ADDR: {
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100722 Binop_12x<HSub>(instruction, Primitive::kPrimInt);
723 break;
724 }
725
726 case Instruction::SUB_LONG_2ADDR: {
727 Binop_12x<HSub>(instruction, Primitive::kPrimLong);
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +0000728 break;
729 }
730
731 case Instruction::ADD_INT_LIT16: {
Nicolas Geoffrayf583e592014-04-07 13:20:42 +0100732 Binop_22s<HAdd>(instruction, false);
733 break;
734 }
735
736 case Instruction::RSUB_INT: {
737 Binop_22s<HSub>(instruction, true);
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +0000738 break;
739 }
740
741 case Instruction::ADD_INT_LIT8: {
Nicolas Geoffrayf583e592014-04-07 13:20:42 +0100742 Binop_22b<HAdd>(instruction, false);
743 break;
744 }
745
746 case Instruction::RSUB_INT_LIT8: {
747 Binop_22b<HSub>(instruction, true);
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +0000748 break;
749 }
750
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +0100751 case Instruction::NEW_INSTANCE: {
752 current_block_->AddInstruction(
753 new (arena_) HNewInstance(dex_offset, instruction.VRegB_21c()));
754 UpdateLocal(instruction.VRegA(), current_block_->GetLastInstruction());
755 break;
756 }
757
Nicolas Geoffrayddb311f2014-05-16 09:28:54 +0100758 case Instruction::MOVE_RESULT:
Dave Allison20dfc792014-06-16 20:44:29 -0700759 case Instruction::MOVE_RESULT_WIDE:
760 case Instruction::MOVE_RESULT_OBJECT:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100761 UpdateLocal(instruction.VRegA(), current_block_->GetLastInstruction());
762 break;
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100763
Nicolas Geoffray412f10c2014-06-19 10:00:34 +0100764 case Instruction::CMP_LONG: {
765 Binop_23x<HCompare>(instruction, Primitive::kPrimLong);
766 break;
767 }
768
Nicolas Geoffraybe9a92a2014-02-25 14:22:56 +0000769 case Instruction::NOP:
770 break;
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000771
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100772 case Instruction::IGET:
773 case Instruction::IGET_WIDE:
774 case Instruction::IGET_OBJECT:
775 case Instruction::IGET_BOOLEAN:
776 case Instruction::IGET_BYTE:
777 case Instruction::IGET_CHAR:
778 case Instruction::IGET_SHORT: {
779 if (!BuildFieldAccess(instruction, dex_offset, false)) {
780 return false;
781 }
782 break;
783 }
784
785 case Instruction::IPUT:
786 case Instruction::IPUT_WIDE:
787 case Instruction::IPUT_OBJECT:
788 case Instruction::IPUT_BOOLEAN:
789 case Instruction::IPUT_BYTE:
790 case Instruction::IPUT_CHAR:
791 case Instruction::IPUT_SHORT: {
792 if (!BuildFieldAccess(instruction, dex_offset, true)) {
793 return false;
794 }
795 break;
796 }
797
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100798#define ARRAY_XX(kind, anticipated_type) \
799 case Instruction::AGET##kind: { \
800 BuildArrayAccess(instruction, dex_offset, false, anticipated_type); \
801 break; \
802 } \
803 case Instruction::APUT##kind: { \
804 BuildArrayAccess(instruction, dex_offset, true, anticipated_type); \
805 break; \
806 }
807
808 ARRAY_XX(, Primitive::kPrimInt);
809 ARRAY_XX(_WIDE, Primitive::kPrimLong);
810 ARRAY_XX(_OBJECT, Primitive::kPrimNot);
811 ARRAY_XX(_BOOLEAN, Primitive::kPrimBoolean);
812 ARRAY_XX(_BYTE, Primitive::kPrimByte);
813 ARRAY_XX(_CHAR, Primitive::kPrimChar);
814 ARRAY_XX(_SHORT, Primitive::kPrimShort);
815
Nicolas Geoffray39468442014-09-02 15:17:15 +0100816 case Instruction::ARRAY_LENGTH: {
817 HInstruction* object = LoadLocal(instruction.VRegB_12x(), Primitive::kPrimNot);
818 current_block_->AddInstruction(new (arena_) HArrayLength(object));
819 UpdateLocal(instruction.VRegA_12x(), current_block_->GetLastInstruction());
820 break;
821 }
822
Nicolas Geoffray818f2102014-02-18 16:43:35 +0000823 default:
824 return false;
825 }
826 return true;
827}
828
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100829HIntConstant* HGraphBuilder::GetIntConstant0() {
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000830 if (constant0_ != nullptr) {
831 return constant0_;
832 }
833 constant0_ = new(arena_) HIntConstant(0);
834 entry_block_->AddInstruction(constant0_);
835 return constant0_;
836}
837
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100838HIntConstant* HGraphBuilder::GetIntConstant1() {
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000839 if (constant1_ != nullptr) {
840 return constant1_;
841 }
842 constant1_ = new(arena_) HIntConstant(1);
843 entry_block_->AddInstruction(constant1_);
844 return constant1_;
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +0000845}
846
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100847HIntConstant* HGraphBuilder::GetIntConstant(int32_t constant) {
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +0000848 switch (constant) {
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100849 case 0: return GetIntConstant0();
850 case 1: return GetIntConstant1();
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +0000851 default: {
852 HIntConstant* instruction = new (arena_) HIntConstant(constant);
853 entry_block_->AddInstruction(instruction);
854 return instruction;
855 }
856 }
857}
858
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100859HLongConstant* HGraphBuilder::GetLongConstant(int64_t constant) {
860 HLongConstant* instruction = new (arena_) HLongConstant(constant);
861 entry_block_->AddInstruction(instruction);
862 return instruction;
863}
864
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +0000865HLocal* HGraphBuilder::GetLocalAt(int register_index) const {
866 return locals_.Get(register_index);
867}
868
869void HGraphBuilder::UpdateLocal(int register_index, HInstruction* instruction) const {
870 HLocal* local = GetLocalAt(register_index);
871 current_block_->AddInstruction(new (arena_) HStoreLocal(local, instruction));
872}
873
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100874HInstruction* HGraphBuilder::LoadLocal(int register_index, Primitive::Type type) const {
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +0000875 HLocal* local = GetLocalAt(register_index);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100876 current_block_->AddInstruction(new (arena_) HLoadLocal(local, type));
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000877 return current_block_->GetLastInstruction();
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +0000878}
879
Nicolas Geoffray818f2102014-02-18 16:43:35 +0000880} // namespace art