blob: be8631ad423244c931214ce9f1735f92a1daa9c6 [file] [log] [blame]
Nicolas Geoffray818f2102014-02-18 16:43:35 +00001/*
Nicolas Geoffray818f2102014-02-18 16:43:35 +00002 * Copyright (C) 2014 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Nicolas Geoffraye5038322014-07-04 09:41:32 +010017#include "builder.h"
18
19#include "class_linker.h"
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +000020#include "dex_file.h"
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +000021#include "dex_file-inl.h"
Nicolas Geoffray818f2102014-02-18 16:43:35 +000022#include "dex_instruction.h"
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +000023#include "dex_instruction-inl.h"
Nicolas Geoffraye5038322014-07-04 09:41:32 +010024#include "driver/compiler_driver-inl.h"
25#include "mirror/art_field.h"
26#include "mirror/art_field-inl.h"
27#include "mirror/class_loader.h"
28#include "mirror/dex_cache.h"
Nicolas Geoffray818f2102014-02-18 16:43:35 +000029#include "nodes.h"
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +000030#include "primitive.h"
Nicolas Geoffraye5038322014-07-04 09:41:32 +010031#include "scoped_thread_state_change.h"
32#include "thread.h"
Nicolas Geoffray818f2102014-02-18 16:43:35 +000033
34namespace art {
35
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +010036/**
37 * Helper class to add HTemporary instructions. This class is used when
38 * converting a DEX instruction to multiple HInstruction, and where those
39 * instructions do not die at the following instruction, but instead spans
40 * multiple instructions.
41 */
42class Temporaries : public ValueObject {
43 public:
Calin Juravlef97f9fb2014-11-11 15:38:19 +000044 explicit Temporaries(HGraph* graph) : graph_(graph), index_(0) {}
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +010045
46 void Add(HInstruction* instruction) {
Calin Juravlef97f9fb2014-11-11 15:38:19 +000047 HInstruction* temp = new (graph_->GetArena()) HTemporary(index_);
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +010048 instruction->GetBlock()->AddInstruction(temp);
Calin Juravlef97f9fb2014-11-11 15:38:19 +000049
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +010050 DCHECK(temp->GetPrevious() == instruction);
Calin Juravlef97f9fb2014-11-11 15:38:19 +000051
52 size_t offset;
53 if (instruction->GetType() == Primitive::kPrimLong
54 || instruction->GetType() == Primitive::kPrimDouble) {
55 offset = 2;
56 } else {
57 offset = 1;
58 }
59 index_ += offset;
60
61 graph_->UpdateTemporariesVRegSlots(index_);
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +010062 }
63
64 private:
65 HGraph* const graph_;
66
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +010067 // Current index in the temporary stack, updated by `Add`.
68 size_t index_;
69};
70
Nicolas Geoffrayf583e592014-04-07 13:20:42 +010071void HGraphBuilder::InitializeLocals(uint16_t count) {
72 graph_->SetNumberOfVRegs(count);
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +000073 locals_.SetSize(count);
74 for (int i = 0; i < count; i++) {
75 HLocal* local = new (arena_) HLocal(i);
76 entry_block_->AddInstruction(local);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +000077 locals_.Put(i, local);
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +000078 }
79}
80
Nicolas Geoffray52e832b2014-11-06 15:15:31 +000081void HGraphBuilder::InitializeParameters(uint16_t number_of_parameters) {
Nicolas Geoffrayf583e592014-04-07 13:20:42 +010082 // dex_compilation_unit_ is null only when unit testing.
83 if (dex_compilation_unit_ == nullptr) {
Nicolas Geoffray52e832b2014-11-06 15:15:31 +000084 return;
Nicolas Geoffrayf583e592014-04-07 13:20:42 +010085 }
86
87 graph_->SetNumberOfInVRegs(number_of_parameters);
88 const char* shorty = dex_compilation_unit_->GetShorty();
89 int locals_index = locals_.Size() - number_of_parameters;
Nicolas Geoffrayf583e592014-04-07 13:20:42 +010090 int parameter_index = 0;
91
92 if (!dex_compilation_unit_->IsStatic()) {
93 // Add the implicit 'this' argument, not expressed in the signature.
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +010094 HParameterValue* parameter =
95 new (arena_) HParameterValue(parameter_index++, Primitive::kPrimNot);
Nicolas Geoffrayb55f8352014-04-07 15:26:35 +010096 entry_block_->AddInstruction(parameter);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +010097 HLocal* local = GetLocalAt(locals_index++);
Nicolas Geoffrayb55f8352014-04-07 15:26:35 +010098 entry_block_->AddInstruction(new (arena_) HStoreLocal(local, parameter));
Nicolas Geoffrayf583e592014-04-07 13:20:42 +010099 number_of_parameters--;
100 }
101
102 uint32_t pos = 1;
103 for (int i = 0; i < number_of_parameters; i++) {
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100104 HParameterValue* parameter =
105 new (arena_) HParameterValue(parameter_index++, Primitive::GetType(shorty[pos++]));
106 entry_block_->AddInstruction(parameter);
107 HLocal* local = GetLocalAt(locals_index++);
108 // Store the parameter value in the local that the dex code will use
109 // to reference that parameter.
110 entry_block_->AddInstruction(new (arena_) HStoreLocal(local, parameter));
111 bool is_wide = (parameter->GetType() == Primitive::kPrimLong)
112 || (parameter->GetType() == Primitive::kPrimDouble);
113 if (is_wide) {
114 i++;
115 locals_index++;
116 parameter_index++;
Nicolas Geoffrayf583e592014-04-07 13:20:42 +0100117 }
118 }
Nicolas Geoffrayf583e592014-04-07 13:20:42 +0100119}
120
Nicolas Geoffrayb55f8352014-04-07 15:26:35 +0100121template<typename T>
Calin Juravle225ff812014-11-13 16:46:39 +0000122void HGraphBuilder::If_22t(const Instruction& instruction, uint32_t dex_pc) {
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000123 int32_t target_offset = instruction.GetTargetOffset();
Calin Juravle225ff812014-11-13 16:46:39 +0000124 PotentiallyAddSuspendCheck(target_offset, dex_pc);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100125 HInstruction* first = LoadLocal(instruction.VRegA(), Primitive::kPrimInt);
126 HInstruction* second = LoadLocal(instruction.VRegB(), Primitive::kPrimInt);
Dave Allison20dfc792014-06-16 20:44:29 -0700127 T* comparison = new (arena_) T(first, second);
128 current_block_->AddInstruction(comparison);
129 HInstruction* ifinst = new (arena_) HIf(comparison);
130 current_block_->AddInstruction(ifinst);
Calin Juravle225ff812014-11-13 16:46:39 +0000131 HBasicBlock* target = FindBlockStartingAt(dex_pc + target_offset);
Dave Allison20dfc792014-06-16 20:44:29 -0700132 DCHECK(target != nullptr);
133 current_block_->AddSuccessor(target);
Calin Juravle225ff812014-11-13 16:46:39 +0000134 target = FindBlockStartingAt(dex_pc + instruction.SizeInCodeUnits());
Dave Allison20dfc792014-06-16 20:44:29 -0700135 DCHECK(target != nullptr);
136 current_block_->AddSuccessor(target);
137 current_block_ = nullptr;
138}
139
140template<typename T>
Calin Juravle225ff812014-11-13 16:46:39 +0000141void HGraphBuilder::If_21t(const Instruction& instruction, uint32_t dex_pc) {
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000142 int32_t target_offset = instruction.GetTargetOffset();
Calin Juravle225ff812014-11-13 16:46:39 +0000143 PotentiallyAddSuspendCheck(target_offset, dex_pc);
Dave Allison20dfc792014-06-16 20:44:29 -0700144 HInstruction* value = LoadLocal(instruction.VRegA(), Primitive::kPrimInt);
145 T* comparison = new (arena_) T(value, GetIntConstant(0));
146 current_block_->AddInstruction(comparison);
147 HInstruction* ifinst = new (arena_) HIf(comparison);
148 current_block_->AddInstruction(ifinst);
Calin Juravle225ff812014-11-13 16:46:39 +0000149 HBasicBlock* target = FindBlockStartingAt(dex_pc + target_offset);
Nicolas Geoffrayb55f8352014-04-07 15:26:35 +0100150 DCHECK(target != nullptr);
151 current_block_->AddSuccessor(target);
Calin Juravle225ff812014-11-13 16:46:39 +0000152 target = FindBlockStartingAt(dex_pc + instruction.SizeInCodeUnits());
Nicolas Geoffrayb55f8352014-04-07 15:26:35 +0100153 DCHECK(target != nullptr);
154 current_block_->AddSuccessor(target);
155 current_block_ = nullptr;
156}
157
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +0000158HGraph* HGraphBuilder::BuildGraph(const DexFile::CodeItem& code_item) {
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +0000159 const uint16_t* code_ptr = code_item.insns_;
160 const uint16_t* code_end = code_item.insns_ + code_item.insns_size_in_code_units_;
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +0100161 code_start_ = code_ptr;
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +0000162
Nicolas Geoffraybe9a92a2014-02-25 14:22:56 +0000163 // Setup the graph with the entry block and exit block.
Nicolas Geoffray818f2102014-02-18 16:43:35 +0000164 graph_ = new (arena_) HGraph(arena_);
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100165 entry_block_ = new (arena_) HBasicBlock(graph_, 0);
Nicolas Geoffray818f2102014-02-18 16:43:35 +0000166 graph_->AddBlock(entry_block_);
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100167 exit_block_ = new (arena_) HBasicBlock(graph_, kNoDexPc);
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000168 graph_->SetEntryBlock(entry_block_);
169 graph_->SetExitBlock(exit_block_);
Nicolas Geoffray818f2102014-02-18 16:43:35 +0000170
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +0000171 InitializeLocals(code_item.registers_size_);
Nicolas Geoffray4a34a422014-04-03 10:38:37 +0100172 graph_->UpdateMaximumNumberOfOutVRegs(code_item.outs_size_);
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +0000173
Nicolas Geoffraybe9a92a2014-02-25 14:22:56 +0000174 // To avoid splitting blocks, we compute ahead of time the instructions that
175 // start a new block, and create these blocks.
176 ComputeBranchTargets(code_ptr, code_end);
Nicolas Geoffray818f2102014-02-18 16:43:35 +0000177
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +0000178 // Also create blocks for catch handlers.
179 if (code_item.tries_size_ != 0) {
180 const uint8_t* handlers_ptr = DexFile::GetCatchHandlerData(code_item, 0);
181 uint32_t handlers_size = DecodeUnsignedLeb128(&handlers_ptr);
182 for (uint32_t idx = 0; idx < handlers_size; ++idx) {
183 CatchHandlerIterator iterator(handlers_ptr);
184 for (; iterator.HasNext(); iterator.Next()) {
185 uint32_t address = iterator.GetHandlerAddress();
186 HBasicBlock* block = FindBlockStartingAt(address);
187 if (block == nullptr) {
188 block = new (arena_) HBasicBlock(graph_, address);
189 branch_targets_.Put(address, block);
190 }
191 block->SetIsCatchBlock();
192 }
193 handlers_ptr = iterator.EndDataPointer();
194 }
195 }
196
Nicolas Geoffray52e832b2014-11-06 15:15:31 +0000197 InitializeParameters(code_item.ins_size_);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +0100198
Calin Juravle225ff812014-11-13 16:46:39 +0000199 size_t dex_pc = 0;
Nicolas Geoffray818f2102014-02-18 16:43:35 +0000200 while (code_ptr < code_end) {
Calin Juravle225ff812014-11-13 16:46:39 +0000201 // Update the current block if dex_pc starts a new block.
202 MaybeUpdateCurrentBlock(dex_pc);
Nicolas Geoffray818f2102014-02-18 16:43:35 +0000203 const Instruction& instruction = *Instruction::At(code_ptr);
Calin Juravle225ff812014-11-13 16:46:39 +0000204 if (!AnalyzeDexInstruction(instruction, dex_pc)) return nullptr;
205 dex_pc += instruction.SizeInCodeUnits();
Nicolas Geoffray818f2102014-02-18 16:43:35 +0000206 code_ptr += instruction.SizeInCodeUnits();
207 }
208
Nicolas Geoffraybe9a92a2014-02-25 14:22:56 +0000209 // Add the exit block at the end to give it the highest id.
Nicolas Geoffray818f2102014-02-18 16:43:35 +0000210 graph_->AddBlock(exit_block_);
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +0000211 exit_block_->AddInstruction(new (arena_) HExit());
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000212 // Add the suspend check to the entry block.
213 entry_block_->AddInstruction(new (arena_) HSuspendCheck(0));
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +0000214 entry_block_->AddInstruction(new (arena_) HGoto());
Nicolas Geoffray818f2102014-02-18 16:43:35 +0000215 return graph_;
216}
217
Nicolas Geoffraybe9a92a2014-02-25 14:22:56 +0000218void HGraphBuilder::MaybeUpdateCurrentBlock(size_t index) {
219 HBasicBlock* block = FindBlockStartingAt(index);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000220 if (block == nullptr) {
221 return;
222 }
Nicolas Geoffraybe9a92a2014-02-25 14:22:56 +0000223
224 if (current_block_ != nullptr) {
225 // Branching instructions clear current_block, so we know
226 // the last instruction of the current block is not a branching
227 // instruction. We add an unconditional goto to the found block.
228 current_block_->AddInstruction(new (arena_) HGoto());
229 current_block_->AddSuccessor(block);
230 }
231 graph_->AddBlock(block);
232 current_block_ = block;
233}
234
235void HGraphBuilder::ComputeBranchTargets(const uint16_t* code_ptr, const uint16_t* code_end) {
236 // TODO: Support switch instructions.
237 branch_targets_.SetSize(code_end - code_ptr);
238
239 // Create the first block for the dex instructions, single successor of the entry block.
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100240 HBasicBlock* block = new (arena_) HBasicBlock(graph_, 0);
Nicolas Geoffraybe9a92a2014-02-25 14:22:56 +0000241 branch_targets_.Put(0, block);
242 entry_block_->AddSuccessor(block);
243
244 // Iterate over all instructions and find branching instructions. Create blocks for
245 // the locations these instructions branch to.
Calin Juravle225ff812014-11-13 16:46:39 +0000246 size_t dex_pc = 0;
Nicolas Geoffraybe9a92a2014-02-25 14:22:56 +0000247 while (code_ptr < code_end) {
248 const Instruction& instruction = *Instruction::At(code_ptr);
249 if (instruction.IsBranch()) {
Calin Juravle225ff812014-11-13 16:46:39 +0000250 int32_t target = instruction.GetTargetOffset() + dex_pc;
Nicolas Geoffraybe9a92a2014-02-25 14:22:56 +0000251 // Create a block for the target instruction.
252 if (FindBlockStartingAt(target) == nullptr) {
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100253 block = new (arena_) HBasicBlock(graph_, target);
Nicolas Geoffraybe9a92a2014-02-25 14:22:56 +0000254 branch_targets_.Put(target, block);
255 }
Calin Juravle225ff812014-11-13 16:46:39 +0000256 dex_pc += instruction.SizeInCodeUnits();
Nicolas Geoffraybe9a92a2014-02-25 14:22:56 +0000257 code_ptr += instruction.SizeInCodeUnits();
Calin Juravle225ff812014-11-13 16:46:39 +0000258 if ((code_ptr < code_end) && (FindBlockStartingAt(dex_pc) == nullptr)) {
259 block = new (arena_) HBasicBlock(graph_, dex_pc);
260 branch_targets_.Put(dex_pc, block);
Nicolas Geoffraybe9a92a2014-02-25 14:22:56 +0000261 }
262 } else {
263 code_ptr += instruction.SizeInCodeUnits();
Calin Juravle225ff812014-11-13 16:46:39 +0000264 dex_pc += instruction.SizeInCodeUnits();
Nicolas Geoffraybe9a92a2014-02-25 14:22:56 +0000265 }
266 }
267}
268
269HBasicBlock* HGraphBuilder::FindBlockStartingAt(int32_t index) const {
270 DCHECK_GE(index, 0);
271 return branch_targets_.Get(index);
272}
273
Nicolas Geoffrayf583e592014-04-07 13:20:42 +0100274template<typename T>
Roland Levillain88cb1752014-10-20 16:36:47 +0100275void HGraphBuilder::Unop_12x(const Instruction& instruction, Primitive::Type type) {
276 HInstruction* first = LoadLocal(instruction.VRegB(), type);
277 current_block_->AddInstruction(new (arena_) T(type, first));
278 UpdateLocal(instruction.VRegA(), current_block_->GetLastInstruction());
279}
280
Roland Levillaindff1f282014-11-05 14:15:05 +0000281void HGraphBuilder::Conversion_12x(const Instruction& instruction,
282 Primitive::Type input_type,
283 Primitive::Type result_type) {
284 HInstruction* first = LoadLocal(instruction.VRegB(), input_type);
285 current_block_->AddInstruction(new (arena_) HTypeConversion(result_type, first));
286 UpdateLocal(instruction.VRegA(), current_block_->GetLastInstruction());
287}
288
Roland Levillain88cb1752014-10-20 16:36:47 +0100289template<typename T>
Nicolas Geoffray412f10c2014-06-19 10:00:34 +0100290void HGraphBuilder::Binop_23x(const Instruction& instruction, Primitive::Type type) {
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100291 HInstruction* first = LoadLocal(instruction.VRegB(), type);
292 HInstruction* second = LoadLocal(instruction.VRegC(), type);
293 current_block_->AddInstruction(new (arena_) T(type, first, second));
Nicolas Geoffrayf583e592014-04-07 13:20:42 +0100294 UpdateLocal(instruction.VRegA(), current_block_->GetLastInstruction());
295}
296
297template<typename T>
Calin Juravled6fb6cf2014-11-11 19:07:44 +0000298void HGraphBuilder::Binop_23x(const Instruction& instruction,
299 Primitive::Type type,
300 uint32_t dex_pc) {
301 HInstruction* first = LoadLocal(instruction.VRegB(), type);
302 HInstruction* second = LoadLocal(instruction.VRegC(), type);
303 current_block_->AddInstruction(new (arena_) T(type, first, second, dex_pc));
304 UpdateLocal(instruction.VRegA(), current_block_->GetLastInstruction());
305}
306
307template<typename T>
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100308void HGraphBuilder::Binop_12x(const Instruction& instruction, Primitive::Type type) {
309 HInstruction* first = LoadLocal(instruction.VRegA(), type);
310 HInstruction* second = LoadLocal(instruction.VRegB(), type);
311 current_block_->AddInstruction(new (arena_) T(type, first, second));
Nicolas Geoffrayf583e592014-04-07 13:20:42 +0100312 UpdateLocal(instruction.VRegA(), current_block_->GetLastInstruction());
313}
314
315template<typename T>
Calin Juravled6fb6cf2014-11-11 19:07:44 +0000316void HGraphBuilder::Binop_12x(const Instruction& instruction,
317 Primitive::Type type,
318 uint32_t dex_pc) {
319 HInstruction* first = LoadLocal(instruction.VRegA(), type);
320 HInstruction* second = LoadLocal(instruction.VRegB(), type);
321 current_block_->AddInstruction(new (arena_) T(type, first, second, dex_pc));
322 UpdateLocal(instruction.VRegA(), current_block_->GetLastInstruction());
323}
324
325template<typename T>
Nicolas Geoffrayf583e592014-04-07 13:20:42 +0100326void HGraphBuilder::Binop_22s(const Instruction& instruction, bool reverse) {
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100327 HInstruction* first = LoadLocal(instruction.VRegB(), Primitive::kPrimInt);
328 HInstruction* second = GetIntConstant(instruction.VRegC_22s());
Nicolas Geoffrayf583e592014-04-07 13:20:42 +0100329 if (reverse) {
330 std::swap(first, second);
331 }
332 current_block_->AddInstruction(new (arena_) T(Primitive::kPrimInt, first, second));
333 UpdateLocal(instruction.VRegA(), current_block_->GetLastInstruction());
334}
335
336template<typename T>
337void HGraphBuilder::Binop_22b(const Instruction& instruction, bool reverse) {
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100338 HInstruction* first = LoadLocal(instruction.VRegB(), Primitive::kPrimInt);
339 HInstruction* second = GetIntConstant(instruction.VRegC_22b());
Nicolas Geoffrayf583e592014-04-07 13:20:42 +0100340 if (reverse) {
341 std::swap(first, second);
342 }
343 current_block_->AddInstruction(new (arena_) T(Primitive::kPrimInt, first, second));
344 UpdateLocal(instruction.VRegA(), current_block_->GetLastInstruction());
345}
346
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100347void HGraphBuilder::BuildReturn(const Instruction& instruction, Primitive::Type type) {
348 if (type == Primitive::kPrimVoid) {
349 current_block_->AddInstruction(new (arena_) HReturnVoid());
350 } else {
351 HInstruction* value = LoadLocal(instruction.VRegA(), type);
352 current_block_->AddInstruction(new (arena_) HReturn(value));
353 }
354 current_block_->AddSuccessor(exit_block_);
355 current_block_ = nullptr;
356}
357
358bool HGraphBuilder::BuildInvoke(const Instruction& instruction,
Calin Juravle225ff812014-11-13 16:46:39 +0000359 uint32_t dex_pc,
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100360 uint32_t method_idx,
361 uint32_t number_of_vreg_arguments,
362 bool is_range,
363 uint32_t* args,
364 uint32_t register_index) {
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +0100365 Instruction::Code opcode = instruction.Opcode();
366 InvokeType invoke_type;
367 switch (opcode) {
368 case Instruction::INVOKE_STATIC:
369 case Instruction::INVOKE_STATIC_RANGE:
370 invoke_type = kStatic;
371 break;
372 case Instruction::INVOKE_DIRECT:
373 case Instruction::INVOKE_DIRECT_RANGE:
374 invoke_type = kDirect;
375 break;
376 case Instruction::INVOKE_VIRTUAL:
377 case Instruction::INVOKE_VIRTUAL_RANGE:
378 invoke_type = kVirtual;
379 break;
380 case Instruction::INVOKE_INTERFACE:
381 case Instruction::INVOKE_INTERFACE_RANGE:
382 invoke_type = kInterface;
383 break;
384 case Instruction::INVOKE_SUPER_RANGE:
385 case Instruction::INVOKE_SUPER:
386 invoke_type = kSuper;
387 break;
388 default:
389 LOG(FATAL) << "Unexpected invoke op: " << opcode;
390 return false;
391 }
392
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100393 const DexFile::MethodId& method_id = dex_file_->GetMethodId(method_idx);
394 const DexFile::ProtoId& proto_id = dex_file_->GetProtoId(method_id.proto_idx_);
395 const char* descriptor = dex_file_->StringDataByIdx(proto_id.shorty_idx_);
396 Primitive::Type return_type = Primitive::GetType(descriptor[0]);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +0100397 bool is_instance_call = invoke_type != kStatic;
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100398 const size_t number_of_arguments = strlen(descriptor) - (is_instance_call ? 0 : 1);
399
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +0100400 HInvoke* invoke = nullptr;
Nicolas Geoffray0d8db992014-11-11 14:40:10 +0000401 if (invoke_type == kVirtual || invoke_type == kInterface || invoke_type == kSuper) {
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +0100402 MethodReference target_method(dex_file_, method_idx);
403 uintptr_t direct_code;
404 uintptr_t direct_method;
Nicolas Geoffray52839d12014-11-07 17:47:25 +0000405 int table_index;
406 InvokeType optimized_invoke_type = invoke_type;
Calin Juravle225ff812014-11-13 16:46:39 +0000407 compiler_driver_->ComputeInvokeInfo(dex_compilation_unit_, dex_pc, true, true,
Nicolas Geoffray52839d12014-11-07 17:47:25 +0000408 &optimized_invoke_type, &target_method, &table_index,
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +0100409 &direct_code, &direct_method);
Nicolas Geoffray52839d12014-11-07 17:47:25 +0000410 if (table_index == -1) {
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +0100411 return false;
412 }
Nicolas Geoffray52839d12014-11-07 17:47:25 +0000413
Nicolas Geoffray0d8db992014-11-11 14:40:10 +0000414 if (optimized_invoke_type == kVirtual) {
Nicolas Geoffray52839d12014-11-07 17:47:25 +0000415 invoke = new (arena_) HInvokeVirtual(
Calin Juravle225ff812014-11-13 16:46:39 +0000416 arena_, number_of_arguments, return_type, dex_pc, table_index);
Nicolas Geoffray0d8db992014-11-11 14:40:10 +0000417 } else if (optimized_invoke_type == kInterface) {
Nicolas Geoffray52839d12014-11-07 17:47:25 +0000418 invoke = new (arena_) HInvokeInterface(
Calin Juravle225ff812014-11-13 16:46:39 +0000419 arena_, number_of_arguments, return_type, dex_pc, method_idx, table_index);
Nicolas Geoffray0d8db992014-11-11 14:40:10 +0000420 } else if (optimized_invoke_type == kDirect) {
421 // For this compiler, sharpening only works if we compile PIC.
422 DCHECK(compiler_driver_->GetCompilerOptions().GetCompilePic());
423 // Treat invoke-direct like static calls for now.
424 invoke = new (arena_) HInvokeStatic(
Calin Juravle225ff812014-11-13 16:46:39 +0000425 arena_, number_of_arguments, return_type, dex_pc, target_method.dex_method_index);
Nicolas Geoffray52839d12014-11-07 17:47:25 +0000426 }
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +0100427 } else {
Nicolas Geoffray0d8db992014-11-11 14:40:10 +0000428 DCHECK(invoke_type == kDirect || invoke_type == kStatic);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +0100429 // Treat invoke-direct like static calls for now.
430 invoke = new (arena_) HInvokeStatic(
Calin Juravle225ff812014-11-13 16:46:39 +0000431 arena_, number_of_arguments, return_type, dex_pc, method_idx);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +0100432 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100433
434 size_t start_index = 0;
Calin Juravlef97f9fb2014-11-11 15:38:19 +0000435 Temporaries temps(graph_);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100436 if (is_instance_call) {
437 HInstruction* arg = LoadLocal(is_range ? register_index : args[0], Primitive::kPrimNot);
Calin Juravle225ff812014-11-13 16:46:39 +0000438 HNullCheck* null_check = new (arena_) HNullCheck(arg, dex_pc);
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +0100439 current_block_->AddInstruction(null_check);
440 temps.Add(null_check);
441 invoke->SetArgumentAt(0, null_check);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100442 start_index = 1;
443 }
444
445 uint32_t descriptor_index = 1;
446 uint32_t argument_index = start_index;
447 for (size_t i = start_index; i < number_of_vreg_arguments; i++, argument_index++) {
448 Primitive::Type type = Primitive::GetType(descriptor[descriptor_index++]);
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100449 bool is_wide = (type == Primitive::kPrimLong) || (type == Primitive::kPrimDouble);
450 if (!is_range && is_wide && args[i] + 1 != args[i + 1]) {
Nicolas Geoffrayabed4d02014-07-14 15:24:11 +0100451 LOG(WARNING) << "Non sequential register pair in " << dex_compilation_unit_->GetSymbol()
Calin Juravle225ff812014-11-13 16:46:39 +0000452 << " at " << dex_pc;
Nicolas Geoffrayabed4d02014-07-14 15:24:11 +0100453 // We do not implement non sequential register pair.
454 return false;
455 }
456 HInstruction* arg = LoadLocal(is_range ? register_index + i : args[i], type);
457 invoke->SetArgumentAt(argument_index, arg);
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100458 if (is_wide) {
Nicolas Geoffrayabed4d02014-07-14 15:24:11 +0100459 i++;
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100460 }
461 }
462
463 DCHECK_EQ(argument_index, number_of_arguments);
464 current_block_->AddInstruction(invoke);
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +0100465 latest_result_ = invoke;
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100466 return true;
467}
468
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100469bool HGraphBuilder::BuildInstanceFieldAccess(const Instruction& instruction,
Calin Juravle225ff812014-11-13 16:46:39 +0000470 uint32_t dex_pc,
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100471 bool is_put) {
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100472 uint32_t source_or_dest_reg = instruction.VRegA_22c();
473 uint32_t obj_reg = instruction.VRegB_22c();
474 uint16_t field_index = instruction.VRegC_22c();
475
476 ScopedObjectAccess soa(Thread::Current());
477 StackHandleScope<1> hs(soa.Self());
478 Handle<mirror::ArtField> resolved_field(hs.NewHandle(
479 compiler_driver_->ComputeInstanceFieldInfo(field_index, dex_compilation_unit_, is_put, soa)));
480
481 if (resolved_field.Get() == nullptr) {
482 return false;
483 }
484 if (resolved_field->IsVolatile()) {
485 return false;
486 }
487
Nicolas Geoffrayabed4d02014-07-14 15:24:11 +0100488 Primitive::Type field_type = resolved_field->GetTypeAsPrimitiveType();
Nicolas Geoffrayabed4d02014-07-14 15:24:11 +0100489
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100490 HInstruction* object = LoadLocal(obj_reg, Primitive::kPrimNot);
Calin Juravle225ff812014-11-13 16:46:39 +0000491 current_block_->AddInstruction(new (arena_) HNullCheck(object, dex_pc));
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100492 if (is_put) {
Calin Juravlef97f9fb2014-11-11 15:38:19 +0000493 Temporaries temps(graph_);
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100494 HInstruction* null_check = current_block_->GetLastInstruction();
495 // We need one temporary for the null check.
496 temps.Add(null_check);
Nicolas Geoffrayabed4d02014-07-14 15:24:11 +0100497 HInstruction* value = LoadLocal(source_or_dest_reg, field_type);
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100498 current_block_->AddInstruction(new (arena_) HInstanceFieldSet(
499 null_check,
500 value,
Nicolas Geoffray39468442014-09-02 15:17:15 +0100501 field_type,
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100502 resolved_field->GetOffset()));
503 } else {
504 current_block_->AddInstruction(new (arena_) HInstanceFieldGet(
505 current_block_->GetLastInstruction(),
Nicolas Geoffrayabed4d02014-07-14 15:24:11 +0100506 field_type,
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100507 resolved_field->GetOffset()));
508
509 UpdateLocal(source_or_dest_reg, current_block_->GetLastInstruction());
510 }
511 return true;
512}
513
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100514
515
516bool HGraphBuilder::BuildStaticFieldAccess(const Instruction& instruction,
Calin Juravle225ff812014-11-13 16:46:39 +0000517 uint32_t dex_pc,
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100518 bool is_put) {
519 uint32_t source_or_dest_reg = instruction.VRegA_21c();
520 uint16_t field_index = instruction.VRegB_21c();
521
522 uint32_t storage_index;
523 bool is_referrers_class;
524 bool is_initialized;
525 bool is_volatile;
526 MemberOffset field_offset(0u);
527 Primitive::Type field_type;
528
529 bool fast_path = compiler_driver_->ComputeStaticFieldInfo(field_index,
530 dex_compilation_unit_,
531 is_put,
532 &field_offset,
533 &storage_index,
534 &is_referrers_class,
535 &is_volatile,
536 &is_initialized,
537 &field_type);
538 if (!fast_path) {
539 return false;
540 }
541
542 if (is_volatile) {
543 return false;
544 }
545
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100546 HLoadClass* constant = new (arena_) HLoadClass(
Calin Juravle225ff812014-11-13 16:46:39 +0000547 storage_index, is_referrers_class, dex_pc);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100548 current_block_->AddInstruction(constant);
549
550 HInstruction* cls = constant;
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000551 if (!is_initialized) {
Calin Juravle225ff812014-11-13 16:46:39 +0000552 cls = new (arena_) HClinitCheck(constant, dex_pc);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100553 current_block_->AddInstruction(cls);
554 }
555
556 if (is_put) {
557 // We need to keep the class alive before loading the value.
Calin Juravlef97f9fb2014-11-11 15:38:19 +0000558 Temporaries temps(graph_);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100559 temps.Add(cls);
560 HInstruction* value = LoadLocal(source_or_dest_reg, field_type);
561 DCHECK_EQ(value->GetType(), field_type);
562 current_block_->AddInstruction(
563 new (arena_) HStaticFieldSet(cls, value, field_type, field_offset));
564 } else {
565 current_block_->AddInstruction(new (arena_) HStaticFieldGet(cls, field_type, field_offset));
566 UpdateLocal(source_or_dest_reg, current_block_->GetLastInstruction());
567 }
568 return true;
569}
570
Calin Juravlebacfec32014-11-14 15:54:36 +0000571void HGraphBuilder::BuildCheckedDivRem(uint16_t out_vreg,
572 uint16_t first_vreg,
573 int64_t second_vreg_or_constant,
574 uint32_t dex_pc,
575 Primitive::Type type,
576 bool second_is_constant,
577 bool isDiv) {
Calin Juravled6fb6cf2014-11-11 19:07:44 +0000578 DCHECK(type == Primitive::kPrimInt || type == Primitive::kPrimLong);
Calin Juravled0d48522014-11-04 16:40:20 +0000579
Calin Juravled6fb6cf2014-11-11 19:07:44 +0000580 HInstruction* first = LoadLocal(first_vreg, type);
581 HInstruction* second = nullptr;
582 if (second_is_constant) {
583 if (type == Primitive::kPrimInt) {
584 second = GetIntConstant(second_vreg_or_constant);
585 } else {
586 second = GetLongConstant(second_vreg_or_constant);
587 }
588 } else {
589 second = LoadLocal(second_vreg_or_constant, type);
590 }
591
592 if (!second_is_constant
593 || (type == Primitive::kPrimInt && second->AsIntConstant()->GetValue() == 0)
594 || (type == Primitive::kPrimLong && second->AsLongConstant()->GetValue() == 0)) {
595 second = new (arena_) HDivZeroCheck(second, dex_pc);
Calin Juravlef97f9fb2014-11-11 15:38:19 +0000596 Temporaries temps(graph_);
Calin Juravled0d48522014-11-04 16:40:20 +0000597 current_block_->AddInstruction(second);
598 temps.Add(current_block_->GetLastInstruction());
599 }
600
Calin Juravlebacfec32014-11-14 15:54:36 +0000601 if (isDiv) {
602 current_block_->AddInstruction(new (arena_) HDiv(type, first, second, dex_pc));
603 } else {
604 current_block_->AddInstruction(new (arena_) HRem(type, first, second, dex_pc));
605 }
Calin Juravled6fb6cf2014-11-11 19:07:44 +0000606 UpdateLocal(out_vreg, current_block_->GetLastInstruction());
Calin Juravled0d48522014-11-04 16:40:20 +0000607}
608
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100609void HGraphBuilder::BuildArrayAccess(const Instruction& instruction,
Calin Juravle225ff812014-11-13 16:46:39 +0000610 uint32_t dex_pc,
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100611 bool is_put,
612 Primitive::Type anticipated_type) {
613 uint8_t source_or_dest_reg = instruction.VRegA_23x();
614 uint8_t array_reg = instruction.VRegB_23x();
615 uint8_t index_reg = instruction.VRegC_23x();
616
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100617 // We need one temporary for the null check, one for the index, and one for the length.
Calin Juravlef97f9fb2014-11-11 15:38:19 +0000618 Temporaries temps(graph_);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100619
620 HInstruction* object = LoadLocal(array_reg, Primitive::kPrimNot);
Calin Juravle225ff812014-11-13 16:46:39 +0000621 object = new (arena_) HNullCheck(object, dex_pc);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100622 current_block_->AddInstruction(object);
623 temps.Add(object);
624
625 HInstruction* length = new (arena_) HArrayLength(object);
626 current_block_->AddInstruction(length);
627 temps.Add(length);
628 HInstruction* index = LoadLocal(index_reg, Primitive::kPrimInt);
Calin Juravle225ff812014-11-13 16:46:39 +0000629 index = new (arena_) HBoundsCheck(index, length, dex_pc);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100630 current_block_->AddInstruction(index);
631 temps.Add(index);
632 if (is_put) {
633 HInstruction* value = LoadLocal(source_or_dest_reg, anticipated_type);
634 // TODO: Insert a type check node if the type is Object.
Nicolas Geoffray39468442014-09-02 15:17:15 +0100635 current_block_->AddInstruction(new (arena_) HArraySet(
Calin Juravle225ff812014-11-13 16:46:39 +0000636 object, index, value, anticipated_type, dex_pc));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100637 } else {
638 current_block_->AddInstruction(new (arena_) HArrayGet(object, index, anticipated_type));
639 UpdateLocal(source_or_dest_reg, current_block_->GetLastInstruction());
640 }
641}
642
Calin Juravle225ff812014-11-13 16:46:39 +0000643void HGraphBuilder::BuildFilledNewArray(uint32_t dex_pc,
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +0100644 uint32_t type_index,
645 uint32_t number_of_vreg_arguments,
646 bool is_range,
647 uint32_t* args,
648 uint32_t register_index) {
649 HInstruction* length = GetIntConstant(number_of_vreg_arguments);
Calin Juravle225ff812014-11-13 16:46:39 +0000650 HInstruction* object = new (arena_) HNewArray(length, dex_pc, type_index);
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +0100651 current_block_->AddInstruction(object);
652
653 const char* descriptor = dex_file_->StringByTypeIdx(type_index);
654 DCHECK_EQ(descriptor[0], '[') << descriptor;
655 char primitive = descriptor[1];
656 DCHECK(primitive == 'I'
657 || primitive == 'L'
658 || primitive == '[') << descriptor;
659 bool is_reference_array = (primitive == 'L') || (primitive == '[');
660 Primitive::Type type = is_reference_array ? Primitive::kPrimNot : Primitive::kPrimInt;
661
Calin Juravlef97f9fb2014-11-11 15:38:19 +0000662 Temporaries temps(graph_);
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +0100663 temps.Add(object);
664 for (size_t i = 0; i < number_of_vreg_arguments; ++i) {
665 HInstruction* value = LoadLocal(is_range ? register_index + i : args[i], type);
666 HInstruction* index = GetIntConstant(i);
667 current_block_->AddInstruction(
Calin Juravle225ff812014-11-13 16:46:39 +0000668 new (arena_) HArraySet(object, index, value, type, dex_pc));
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +0100669 }
670 latest_result_ = object;
671}
672
673template <typename T>
674void HGraphBuilder::BuildFillArrayData(HInstruction* object,
675 const T* data,
676 uint32_t element_count,
677 Primitive::Type anticipated_type,
Calin Juravle225ff812014-11-13 16:46:39 +0000678 uint32_t dex_pc) {
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +0100679 for (uint32_t i = 0; i < element_count; ++i) {
680 HInstruction* index = GetIntConstant(i);
681 HInstruction* value = GetIntConstant(data[i]);
682 current_block_->AddInstruction(new (arena_) HArraySet(
Calin Juravle225ff812014-11-13 16:46:39 +0000683 object, index, value, anticipated_type, dex_pc));
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +0100684 }
685}
686
Calin Juravle225ff812014-11-13 16:46:39 +0000687void HGraphBuilder::BuildFillArrayData(const Instruction& instruction, uint32_t dex_pc) {
Calin Juravlef97f9fb2014-11-11 15:38:19 +0000688 Temporaries temps(graph_);
Calin Juravled0d48522014-11-04 16:40:20 +0000689 HInstruction* array = LoadLocal(instruction.VRegA_31t(), Primitive::kPrimNot);
Calin Juravle225ff812014-11-13 16:46:39 +0000690 HNullCheck* null_check = new (arena_) HNullCheck(array, dex_pc);
Calin Juravled0d48522014-11-04 16:40:20 +0000691 current_block_->AddInstruction(null_check);
692 temps.Add(null_check);
693
694 HInstruction* length = new (arena_) HArrayLength(null_check);
695 current_block_->AddInstruction(length);
696
Calin Juravle225ff812014-11-13 16:46:39 +0000697 int32_t payload_offset = instruction.VRegB_31t() + dex_pc;
Calin Juravled0d48522014-11-04 16:40:20 +0000698 const Instruction::ArrayDataPayload* payload =
699 reinterpret_cast<const Instruction::ArrayDataPayload*>(code_start_ + payload_offset);
700 const uint8_t* data = payload->data;
701 uint32_t element_count = payload->element_count;
702
703 // Implementation of this DEX instruction seems to be that the bounds check is
704 // done before doing any stores.
705 HInstruction* last_index = GetIntConstant(payload->element_count - 1);
Calin Juravle225ff812014-11-13 16:46:39 +0000706 current_block_->AddInstruction(new (arena_) HBoundsCheck(last_index, length, dex_pc));
Calin Juravled0d48522014-11-04 16:40:20 +0000707
708 switch (payload->element_width) {
709 case 1:
710 BuildFillArrayData(null_check,
711 reinterpret_cast<const int8_t*>(data),
712 element_count,
713 Primitive::kPrimByte,
Calin Juravle225ff812014-11-13 16:46:39 +0000714 dex_pc);
Calin Juravled0d48522014-11-04 16:40:20 +0000715 break;
716 case 2:
717 BuildFillArrayData(null_check,
718 reinterpret_cast<const int16_t*>(data),
719 element_count,
720 Primitive::kPrimShort,
Calin Juravle225ff812014-11-13 16:46:39 +0000721 dex_pc);
Calin Juravled0d48522014-11-04 16:40:20 +0000722 break;
723 case 4:
724 BuildFillArrayData(null_check,
725 reinterpret_cast<const int32_t*>(data),
726 element_count,
727 Primitive::kPrimInt,
Calin Juravle225ff812014-11-13 16:46:39 +0000728 dex_pc);
Calin Juravled0d48522014-11-04 16:40:20 +0000729 break;
730 case 8:
731 BuildFillWideArrayData(null_check,
732 reinterpret_cast<const int64_t*>(data),
733 element_count,
Calin Juravle225ff812014-11-13 16:46:39 +0000734 dex_pc);
Calin Juravled0d48522014-11-04 16:40:20 +0000735 break;
736 default:
737 LOG(FATAL) << "Unknown element width for " << payload->element_width;
738 }
739}
740
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +0100741void HGraphBuilder::BuildFillWideArrayData(HInstruction* object,
Nicolas Geoffray8d6ae522014-10-23 18:32:13 +0100742 const int64_t* data,
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +0100743 uint32_t element_count,
Calin Juravle225ff812014-11-13 16:46:39 +0000744 uint32_t dex_pc) {
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +0100745 for (uint32_t i = 0; i < element_count; ++i) {
746 HInstruction* index = GetIntConstant(i);
747 HInstruction* value = GetLongConstant(data[i]);
748 current_block_->AddInstruction(new (arena_) HArraySet(
Calin Juravle225ff812014-11-13 16:46:39 +0000749 object, index, value, Primitive::kPrimLong, dex_pc));
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +0100750 }
751}
752
Nicolas Geoffray57a88d42014-11-10 15:09:21 +0000753bool HGraphBuilder::BuildTypeCheck(const Instruction& instruction,
754 uint8_t destination,
755 uint8_t reference,
756 uint16_t type_index,
Calin Juravle225ff812014-11-13 16:46:39 +0000757 uint32_t dex_pc) {
Nicolas Geoffray57a88d42014-11-10 15:09:21 +0000758 bool type_known_final;
759 bool type_known_abstract;
760 bool is_referrers_class;
761 bool can_access = compiler_driver_->CanAccessTypeWithoutChecks(
762 dex_compilation_unit_->GetDexMethodIndex(), *dex_file_, type_index,
763 &type_known_final, &type_known_abstract, &is_referrers_class);
764 if (!can_access) {
765 return false;
766 }
767 HInstruction* object = LoadLocal(reference, Primitive::kPrimNot);
Calin Juravle225ff812014-11-13 16:46:39 +0000768 HLoadClass* cls = new (arena_) HLoadClass(type_index, is_referrers_class, dex_pc);
Nicolas Geoffray57a88d42014-11-10 15:09:21 +0000769 current_block_->AddInstruction(cls);
770 // The class needs a temporary before being used by the type check.
Calin Juravlef97f9fb2014-11-11 15:38:19 +0000771 Temporaries temps(graph_);
Nicolas Geoffray57a88d42014-11-10 15:09:21 +0000772 temps.Add(cls);
773 if (instruction.Opcode() == Instruction::INSTANCE_OF) {
774 current_block_->AddInstruction(
Calin Juravle225ff812014-11-13 16:46:39 +0000775 new (arena_) HInstanceOf(object, cls, type_known_final, dex_pc));
Nicolas Geoffray57a88d42014-11-10 15:09:21 +0000776 UpdateLocal(destination, current_block_->GetLastInstruction());
777 } else {
778 DCHECK_EQ(instruction.Opcode(), Instruction::CHECK_CAST);
779 current_block_->AddInstruction(
Calin Juravle225ff812014-11-13 16:46:39 +0000780 new (arena_) HCheckCast(object, cls, type_known_final, dex_pc));
Nicolas Geoffray57a88d42014-11-10 15:09:21 +0000781 }
782 return true;
783}
784
Calin Juravle225ff812014-11-13 16:46:39 +0000785void HGraphBuilder::PotentiallyAddSuspendCheck(int32_t target_offset, uint32_t dex_pc) {
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000786 if (target_offset <= 0) {
787 // Unconditionnally add a suspend check to backward branches. We can remove
788 // them after we recognize loops in the graph.
Calin Juravle225ff812014-11-13 16:46:39 +0000789 current_block_->AddInstruction(new (arena_) HSuspendCheck(dex_pc));
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000790 }
791}
792
Calin Juravle225ff812014-11-13 16:46:39 +0000793bool HGraphBuilder::AnalyzeDexInstruction(const Instruction& instruction, uint32_t dex_pc) {
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000794 if (current_block_ == nullptr) {
795 return true; // Dead code
796 }
Nicolas Geoffraybe9a92a2014-02-25 14:22:56 +0000797
Nicolas Geoffray818f2102014-02-18 16:43:35 +0000798 switch (instruction.Opcode()) {
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +0000799 case Instruction::CONST_4: {
800 int32_t register_index = instruction.VRegA();
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100801 HIntConstant* constant = GetIntConstant(instruction.VRegB_11n());
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +0000802 UpdateLocal(register_index, constant);
803 break;
804 }
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000805
Nicolas Geoffrayb55f8352014-04-07 15:26:35 +0100806 case Instruction::CONST_16: {
807 int32_t register_index = instruction.VRegA();
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100808 HIntConstant* constant = GetIntConstant(instruction.VRegB_21s());
809 UpdateLocal(register_index, constant);
810 break;
811 }
812
Dave Allison20dfc792014-06-16 20:44:29 -0700813 case Instruction::CONST: {
814 int32_t register_index = instruction.VRegA();
815 HIntConstant* constant = GetIntConstant(instruction.VRegB_31i());
816 UpdateLocal(register_index, constant);
817 break;
818 }
819
820 case Instruction::CONST_HIGH16: {
821 int32_t register_index = instruction.VRegA();
822 HIntConstant* constant = GetIntConstant(instruction.VRegB_21h() << 16);
823 UpdateLocal(register_index, constant);
824 break;
825 }
826
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100827 case Instruction::CONST_WIDE_16: {
828 int32_t register_index = instruction.VRegA();
Dave Allison20dfc792014-06-16 20:44:29 -0700829 // Get 16 bits of constant value, sign extended to 64 bits.
830 int64_t value = instruction.VRegB_21s();
831 value <<= 48;
832 value >>= 48;
833 HLongConstant* constant = GetLongConstant(value);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100834 UpdateLocal(register_index, constant);
835 break;
836 }
837
838 case Instruction::CONST_WIDE_32: {
839 int32_t register_index = instruction.VRegA();
Dave Allison20dfc792014-06-16 20:44:29 -0700840 // Get 32 bits of constant value, sign extended to 64 bits.
841 int64_t value = instruction.VRegB_31i();
842 value <<= 32;
843 value >>= 32;
844 HLongConstant* constant = GetLongConstant(value);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100845 UpdateLocal(register_index, constant);
846 break;
847 }
848
849 case Instruction::CONST_WIDE: {
850 int32_t register_index = instruction.VRegA();
851 HLongConstant* constant = GetLongConstant(instruction.VRegB_51l());
Nicolas Geoffrayb55f8352014-04-07 15:26:35 +0100852 UpdateLocal(register_index, constant);
853 break;
854 }
855
Dave Allison20dfc792014-06-16 20:44:29 -0700856 case Instruction::CONST_WIDE_HIGH16: {
857 int32_t register_index = instruction.VRegA();
858 int64_t value = static_cast<int64_t>(instruction.VRegB_21h()) << 48;
859 HLongConstant* constant = GetLongConstant(value);
860 UpdateLocal(register_index, constant);
861 break;
862 }
863
Nicolas Geoffraydadf3172014-11-07 16:36:02 +0000864 // Note that the SSA building will refine the types.
Dave Allison20dfc792014-06-16 20:44:29 -0700865 case Instruction::MOVE:
866 case Instruction::MOVE_FROM16:
867 case Instruction::MOVE_16: {
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100868 HInstruction* value = LoadLocal(instruction.VRegB(), Primitive::kPrimInt);
Nicolas Geoffrayb55f8352014-04-07 15:26:35 +0100869 UpdateLocal(instruction.VRegA(), value);
870 break;
871 }
872
Nicolas Geoffraydadf3172014-11-07 16:36:02 +0000873 // Note that the SSA building will refine the types.
Dave Allison20dfc792014-06-16 20:44:29 -0700874 case Instruction::MOVE_WIDE:
875 case Instruction::MOVE_WIDE_FROM16:
876 case Instruction::MOVE_WIDE_16: {
877 HInstruction* value = LoadLocal(instruction.VRegB(), Primitive::kPrimLong);
878 UpdateLocal(instruction.VRegA(), value);
879 break;
880 }
881
882 case Instruction::MOVE_OBJECT:
883 case Instruction::MOVE_OBJECT_16:
884 case Instruction::MOVE_OBJECT_FROM16: {
885 HInstruction* value = LoadLocal(instruction.VRegB(), Primitive::kPrimNot);
886 UpdateLocal(instruction.VRegA(), value);
887 break;
888 }
889
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000890 case Instruction::RETURN_VOID: {
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100891 BuildReturn(instruction, Primitive::kPrimVoid);
Nicolas Geoffray818f2102014-02-18 16:43:35 +0000892 break;
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000893 }
894
Dave Allison20dfc792014-06-16 20:44:29 -0700895#define IF_XX(comparison, cond) \
Calin Juravle225ff812014-11-13 16:46:39 +0000896 case Instruction::IF_##cond: If_22t<comparison>(instruction, dex_pc); break; \
897 case Instruction::IF_##cond##Z: If_21t<comparison>(instruction, dex_pc); break
Nicolas Geoffrayb55f8352014-04-07 15:26:35 +0100898
Dave Allison20dfc792014-06-16 20:44:29 -0700899 IF_XX(HEqual, EQ);
900 IF_XX(HNotEqual, NE);
901 IF_XX(HLessThan, LT);
902 IF_XX(HLessThanOrEqual, LE);
903 IF_XX(HGreaterThan, GT);
904 IF_XX(HGreaterThanOrEqual, GE);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000905
Nicolas Geoffraybe9a92a2014-02-25 14:22:56 +0000906 case Instruction::GOTO:
907 case Instruction::GOTO_16:
908 case Instruction::GOTO_32: {
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000909 int32_t offset = instruction.GetTargetOffset();
Calin Juravle225ff812014-11-13 16:46:39 +0000910 PotentiallyAddSuspendCheck(offset, dex_pc);
911 HBasicBlock* target = FindBlockStartingAt(offset + dex_pc);
Nicolas Geoffraybe9a92a2014-02-25 14:22:56 +0000912 DCHECK(target != nullptr);
913 current_block_->AddInstruction(new (arena_) HGoto());
914 current_block_->AddSuccessor(target);
915 current_block_ = nullptr;
916 break;
917 }
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000918
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100919 case Instruction::RETURN: {
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100920 DCHECK_NE(return_type_, Primitive::kPrimNot);
921 DCHECK_NE(return_type_, Primitive::kPrimLong);
922 DCHECK_NE(return_type_, Primitive::kPrimDouble);
923 BuildReturn(instruction, return_type_);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100924 break;
925 }
926
Nicolas Geoffrayf583e592014-04-07 13:20:42 +0100927 case Instruction::RETURN_OBJECT: {
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100928 DCHECK(return_type_ == Primitive::kPrimNot);
929 BuildReturn(instruction, return_type_);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100930 break;
931 }
932
933 case Instruction::RETURN_WIDE: {
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100934 DCHECK(return_type_ == Primitive::kPrimDouble || return_type_ == Primitive::kPrimLong);
935 BuildReturn(instruction, return_type_);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000936 break;
937 }
938
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +0100939 case Instruction::INVOKE_DIRECT:
Nicolas Geoffray0d8db992014-11-11 14:40:10 +0000940 case Instruction::INVOKE_INTERFACE:
941 case Instruction::INVOKE_STATIC:
942 case Instruction::INVOKE_SUPER:
943 case Instruction::INVOKE_VIRTUAL: {
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +0000944 uint32_t method_idx = instruction.VRegB_35c();
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100945 uint32_t number_of_vreg_arguments = instruction.VRegA_35c();
Nicolas Geoffray4a34a422014-04-03 10:38:37 +0100946 uint32_t args[5];
Ian Rogers29a26482014-05-02 15:27:29 -0700947 instruction.GetVarArgs(args);
Calin Juravle225ff812014-11-13 16:46:39 +0000948 if (!BuildInvoke(instruction, dex_pc, method_idx,
Nicolas Geoffraydadf3172014-11-07 16:36:02 +0000949 number_of_vreg_arguments, false, args, -1)) {
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100950 return false;
Nicolas Geoffray4a34a422014-04-03 10:38:37 +0100951 }
Nicolas Geoffray4a34a422014-04-03 10:38:37 +0100952 break;
953 }
954
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +0100955 case Instruction::INVOKE_DIRECT_RANGE:
Nicolas Geoffray0d8db992014-11-11 14:40:10 +0000956 case Instruction::INVOKE_INTERFACE_RANGE:
957 case Instruction::INVOKE_STATIC_RANGE:
958 case Instruction::INVOKE_SUPER_RANGE:
959 case Instruction::INVOKE_VIRTUAL_RANGE: {
Nicolas Geoffray4a34a422014-04-03 10:38:37 +0100960 uint32_t method_idx = instruction.VRegB_3rc();
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100961 uint32_t number_of_vreg_arguments = instruction.VRegA_3rc();
962 uint32_t register_index = instruction.VRegC();
Calin Juravle225ff812014-11-13 16:46:39 +0000963 if (!BuildInvoke(instruction, dex_pc, method_idx,
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100964 number_of_vreg_arguments, true, nullptr, register_index)) {
Nicolas Geoffray4a34a422014-04-03 10:38:37 +0100965 return false;
966 }
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +0000967 break;
968 }
969
Roland Levillain88cb1752014-10-20 16:36:47 +0100970 case Instruction::NEG_INT: {
971 Unop_12x<HNeg>(instruction, Primitive::kPrimInt);
972 break;
973 }
974
Roland Levillain2e07b4f2014-10-23 18:12:09 +0100975 case Instruction::NEG_LONG: {
976 Unop_12x<HNeg>(instruction, Primitive::kPrimLong);
977 break;
978 }
979
Roland Levillain3dbcb382014-10-28 17:30:07 +0000980 case Instruction::NEG_FLOAT: {
981 Unop_12x<HNeg>(instruction, Primitive::kPrimFloat);
982 break;
983 }
984
985 case Instruction::NEG_DOUBLE: {
986 Unop_12x<HNeg>(instruction, Primitive::kPrimDouble);
987 break;
988 }
989
Roland Levillain1cc5f2512014-10-22 18:06:21 +0100990 case Instruction::NOT_INT: {
991 Unop_12x<HNot>(instruction, Primitive::kPrimInt);
992 break;
993 }
994
Roland Levillain70566432014-10-24 16:20:17 +0100995 case Instruction::NOT_LONG: {
996 Unop_12x<HNot>(instruction, Primitive::kPrimLong);
997 break;
998 }
999
Roland Levillaindff1f282014-11-05 14:15:05 +00001000 case Instruction::INT_TO_LONG: {
1001 Conversion_12x(instruction, Primitive::kPrimInt, Primitive::kPrimLong);
1002 break;
1003 }
1004
Roland Levillaincff13742014-11-17 14:32:17 +00001005 case Instruction::INT_TO_FLOAT: {
1006 Conversion_12x(instruction, Primitive::kPrimInt, Primitive::kPrimFloat);
1007 break;
1008 }
1009
1010 case Instruction::INT_TO_DOUBLE: {
1011 Conversion_12x(instruction, Primitive::kPrimInt, Primitive::kPrimDouble);
1012 break;
1013 }
1014
Roland Levillain946e1432014-11-11 17:35:19 +00001015 case Instruction::LONG_TO_INT: {
1016 Conversion_12x(instruction, Primitive::kPrimLong, Primitive::kPrimInt);
1017 break;
1018 }
1019
Roland Levillain51d3fc42014-11-13 14:11:42 +00001020 case Instruction::INT_TO_BYTE: {
1021 Conversion_12x(instruction, Primitive::kPrimInt, Primitive::kPrimByte);
1022 break;
1023 }
1024
Roland Levillain01a8d712014-11-14 16:27:39 +00001025 case Instruction::INT_TO_SHORT: {
1026 Conversion_12x(instruction, Primitive::kPrimInt, Primitive::kPrimShort);
1027 break;
1028 }
1029
Roland Levillain981e4542014-11-14 11:47:14 +00001030 case Instruction::INT_TO_CHAR: {
1031 Conversion_12x(instruction, Primitive::kPrimInt, Primitive::kPrimChar);
1032 break;
1033 }
1034
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001035 case Instruction::ADD_INT: {
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01001036 Binop_23x<HAdd>(instruction, Primitive::kPrimInt);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001037 break;
1038 }
1039
1040 case Instruction::ADD_LONG: {
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01001041 Binop_23x<HAdd>(instruction, Primitive::kPrimLong);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001042 break;
1043 }
1044
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001045 case Instruction::ADD_DOUBLE: {
1046 Binop_23x<HAdd>(instruction, Primitive::kPrimDouble);
1047 break;
1048 }
1049
1050 case Instruction::ADD_FLOAT: {
1051 Binop_23x<HAdd>(instruction, Primitive::kPrimFloat);
1052 break;
1053 }
1054
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001055 case Instruction::SUB_INT: {
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01001056 Binop_23x<HSub>(instruction, Primitive::kPrimInt);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001057 break;
1058 }
1059
1060 case Instruction::SUB_LONG: {
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01001061 Binop_23x<HSub>(instruction, Primitive::kPrimLong);
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001062 break;
1063 }
1064
Calin Juravle096cc022014-10-23 17:01:13 +01001065 case Instruction::SUB_FLOAT: {
1066 Binop_23x<HSub>(instruction, Primitive::kPrimFloat);
1067 break;
1068 }
1069
1070 case Instruction::SUB_DOUBLE: {
1071 Binop_23x<HSub>(instruction, Primitive::kPrimDouble);
1072 break;
1073 }
1074
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001075 case Instruction::ADD_INT_2ADDR: {
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001076 Binop_12x<HAdd>(instruction, Primitive::kPrimInt);
1077 break;
1078 }
1079
Calin Juravle34bacdf2014-10-07 20:23:36 +01001080 case Instruction::MUL_INT: {
1081 Binop_23x<HMul>(instruction, Primitive::kPrimInt);
1082 break;
1083 }
1084
1085 case Instruction::MUL_LONG: {
1086 Binop_23x<HMul>(instruction, Primitive::kPrimLong);
1087 break;
1088 }
1089
Calin Juravleb5bfa962014-10-21 18:02:24 +01001090 case Instruction::MUL_FLOAT: {
1091 Binop_23x<HMul>(instruction, Primitive::kPrimFloat);
1092 break;
1093 }
1094
1095 case Instruction::MUL_DOUBLE: {
1096 Binop_23x<HMul>(instruction, Primitive::kPrimDouble);
1097 break;
1098 }
1099
Calin Juravled0d48522014-11-04 16:40:20 +00001100 case Instruction::DIV_INT: {
Calin Juravlebacfec32014-11-14 15:54:36 +00001101 BuildCheckedDivRem(instruction.VRegA(), instruction.VRegB(), instruction.VRegC(),
1102 dex_pc, Primitive::kPrimInt, false, true);
Calin Juravled0d48522014-11-04 16:40:20 +00001103 break;
1104 }
1105
Calin Juravled6fb6cf2014-11-11 19:07:44 +00001106 case Instruction::DIV_LONG: {
Calin Juravlebacfec32014-11-14 15:54:36 +00001107 BuildCheckedDivRem(instruction.VRegA(), instruction.VRegB(), instruction.VRegC(),
1108 dex_pc, Primitive::kPrimLong, false, true);
Calin Juravled6fb6cf2014-11-11 19:07:44 +00001109 break;
1110 }
1111
Calin Juravle7c4954d2014-10-28 16:57:40 +00001112 case Instruction::DIV_FLOAT: {
Calin Juravle225ff812014-11-13 16:46:39 +00001113 Binop_23x<HDiv>(instruction, Primitive::kPrimFloat, dex_pc);
Calin Juravle7c4954d2014-10-28 16:57:40 +00001114 break;
1115 }
1116
1117 case Instruction::DIV_DOUBLE: {
Calin Juravle225ff812014-11-13 16:46:39 +00001118 Binop_23x<HDiv>(instruction, Primitive::kPrimDouble, dex_pc);
Calin Juravle7c4954d2014-10-28 16:57:40 +00001119 break;
1120 }
1121
Calin Juravlebacfec32014-11-14 15:54:36 +00001122 case Instruction::REM_INT: {
1123 BuildCheckedDivRem(instruction.VRegA(), instruction.VRegB(), instruction.VRegC(),
1124 dex_pc, Primitive::kPrimInt, false, false);
1125 break;
1126 }
1127
1128 case Instruction::REM_LONG: {
1129 BuildCheckedDivRem(instruction.VRegA(), instruction.VRegB(), instruction.VRegC(),
1130 dex_pc, Primitive::kPrimLong, false, false);
1131 break;
1132 }
1133
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00001134 case Instruction::AND_INT: {
1135 Binop_23x<HAnd>(instruction, Primitive::kPrimInt);
1136 break;
1137 }
1138
1139 case Instruction::AND_LONG: {
1140 Binop_23x<HAnd>(instruction, Primitive::kPrimLong);
1141 break;
1142 }
1143
1144 case Instruction::OR_INT: {
1145 Binop_23x<HOr>(instruction, Primitive::kPrimInt);
1146 break;
1147 }
1148
1149 case Instruction::OR_LONG: {
1150 Binop_23x<HOr>(instruction, Primitive::kPrimLong);
1151 break;
1152 }
1153
1154 case Instruction::XOR_INT: {
1155 Binop_23x<HXor>(instruction, Primitive::kPrimInt);
1156 break;
1157 }
1158
1159 case Instruction::XOR_LONG: {
1160 Binop_23x<HXor>(instruction, Primitive::kPrimLong);
1161 break;
1162 }
1163
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001164 case Instruction::ADD_LONG_2ADDR: {
1165 Binop_12x<HAdd>(instruction, Primitive::kPrimLong);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001166 break;
1167 }
1168
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001169 case Instruction::ADD_DOUBLE_2ADDR: {
1170 Binop_12x<HAdd>(instruction, Primitive::kPrimDouble);
1171 break;
1172 }
1173
1174 case Instruction::ADD_FLOAT_2ADDR: {
1175 Binop_12x<HAdd>(instruction, Primitive::kPrimFloat);
1176 break;
1177 }
1178
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001179 case Instruction::SUB_INT_2ADDR: {
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001180 Binop_12x<HSub>(instruction, Primitive::kPrimInt);
1181 break;
1182 }
1183
1184 case Instruction::SUB_LONG_2ADDR: {
1185 Binop_12x<HSub>(instruction, Primitive::kPrimLong);
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001186 break;
1187 }
1188
Calin Juravle096cc022014-10-23 17:01:13 +01001189 case Instruction::SUB_FLOAT_2ADDR: {
1190 Binop_12x<HSub>(instruction, Primitive::kPrimFloat);
1191 break;
1192 }
1193
1194 case Instruction::SUB_DOUBLE_2ADDR: {
1195 Binop_12x<HSub>(instruction, Primitive::kPrimDouble);
1196 break;
1197 }
1198
Calin Juravle34bacdf2014-10-07 20:23:36 +01001199 case Instruction::MUL_INT_2ADDR: {
1200 Binop_12x<HMul>(instruction, Primitive::kPrimInt);
1201 break;
1202 }
1203
1204 case Instruction::MUL_LONG_2ADDR: {
1205 Binop_12x<HMul>(instruction, Primitive::kPrimLong);
1206 break;
1207 }
1208
Calin Juravleb5bfa962014-10-21 18:02:24 +01001209 case Instruction::MUL_FLOAT_2ADDR: {
1210 Binop_12x<HMul>(instruction, Primitive::kPrimFloat);
1211 break;
1212 }
1213
1214 case Instruction::MUL_DOUBLE_2ADDR: {
1215 Binop_12x<HMul>(instruction, Primitive::kPrimDouble);
1216 break;
1217 }
1218
Calin Juravle865fc882014-11-06 17:09:03 +00001219 case Instruction::DIV_INT_2ADDR: {
Calin Juravlebacfec32014-11-14 15:54:36 +00001220 BuildCheckedDivRem(instruction.VRegA(), instruction.VRegA(), instruction.VRegB(),
1221 dex_pc, Primitive::kPrimInt, false, true);
Calin Juravle865fc882014-11-06 17:09:03 +00001222 break;
1223 }
1224
Calin Juravled6fb6cf2014-11-11 19:07:44 +00001225 case Instruction::DIV_LONG_2ADDR: {
Calin Juravlebacfec32014-11-14 15:54:36 +00001226 BuildCheckedDivRem(instruction.VRegA(), instruction.VRegA(), instruction.VRegB(),
1227 dex_pc, Primitive::kPrimLong, false, true);
1228 break;
1229 }
1230
1231 case Instruction::REM_INT_2ADDR: {
1232 BuildCheckedDivRem(instruction.VRegA(), instruction.VRegA(), instruction.VRegB(),
1233 dex_pc, Primitive::kPrimInt, false, false);
1234 break;
1235 }
1236
1237 case Instruction::REM_LONG_2ADDR: {
1238 BuildCheckedDivRem(instruction.VRegA(), instruction.VRegA(), instruction.VRegB(),
1239 dex_pc, Primitive::kPrimLong, false, false);
Calin Juravled6fb6cf2014-11-11 19:07:44 +00001240 break;
1241 }
1242
Calin Juravle7c4954d2014-10-28 16:57:40 +00001243 case Instruction::DIV_FLOAT_2ADDR: {
Calin Juravle225ff812014-11-13 16:46:39 +00001244 Binop_12x<HDiv>(instruction, Primitive::kPrimFloat, dex_pc);
Calin Juravle7c4954d2014-10-28 16:57:40 +00001245 break;
1246 }
1247
1248 case Instruction::DIV_DOUBLE_2ADDR: {
Calin Juravle225ff812014-11-13 16:46:39 +00001249 Binop_12x<HDiv>(instruction, Primitive::kPrimDouble, dex_pc);
Calin Juravle7c4954d2014-10-28 16:57:40 +00001250 break;
1251 }
1252
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00001253 case Instruction::AND_INT_2ADDR: {
1254 Binop_12x<HAnd>(instruction, Primitive::kPrimInt);
1255 break;
1256 }
1257
1258 case Instruction::AND_LONG_2ADDR: {
1259 Binop_12x<HAnd>(instruction, Primitive::kPrimLong);
1260 break;
1261 }
1262
1263 case Instruction::OR_INT_2ADDR: {
1264 Binop_12x<HOr>(instruction, Primitive::kPrimInt);
1265 break;
1266 }
1267
1268 case Instruction::OR_LONG_2ADDR: {
1269 Binop_12x<HOr>(instruction, Primitive::kPrimLong);
1270 break;
1271 }
1272
1273 case Instruction::XOR_INT_2ADDR: {
1274 Binop_12x<HXor>(instruction, Primitive::kPrimInt);
1275 break;
1276 }
1277
1278 case Instruction::XOR_LONG_2ADDR: {
1279 Binop_12x<HXor>(instruction, Primitive::kPrimLong);
1280 break;
1281 }
1282
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001283 case Instruction::ADD_INT_LIT16: {
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001284 Binop_22s<HAdd>(instruction, false);
1285 break;
1286 }
1287
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00001288 case Instruction::AND_INT_LIT16: {
1289 Binop_22s<HAnd>(instruction, false);
1290 break;
1291 }
1292
1293 case Instruction::OR_INT_LIT16: {
1294 Binop_22s<HOr>(instruction, false);
1295 break;
1296 }
1297
1298 case Instruction::XOR_INT_LIT16: {
1299 Binop_22s<HXor>(instruction, false);
1300 break;
1301 }
1302
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001303 case Instruction::RSUB_INT: {
1304 Binop_22s<HSub>(instruction, true);
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001305 break;
1306 }
1307
Calin Juravle34bacdf2014-10-07 20:23:36 +01001308 case Instruction::MUL_INT_LIT16: {
1309 Binop_22s<HMul>(instruction, false);
1310 break;
1311 }
1312
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001313 case Instruction::ADD_INT_LIT8: {
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001314 Binop_22b<HAdd>(instruction, false);
1315 break;
1316 }
1317
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00001318 case Instruction::AND_INT_LIT8: {
1319 Binop_22b<HAnd>(instruction, false);
1320 break;
1321 }
1322
1323 case Instruction::OR_INT_LIT8: {
1324 Binop_22b<HOr>(instruction, false);
1325 break;
1326 }
1327
1328 case Instruction::XOR_INT_LIT8: {
1329 Binop_22b<HXor>(instruction, false);
1330 break;
1331 }
1332
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001333 case Instruction::RSUB_INT_LIT8: {
1334 Binop_22b<HSub>(instruction, true);
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001335 break;
1336 }
1337
Calin Juravle34bacdf2014-10-07 20:23:36 +01001338 case Instruction::MUL_INT_LIT8: {
1339 Binop_22b<HMul>(instruction, false);
1340 break;
1341 }
1342
Calin Juravled0d48522014-11-04 16:40:20 +00001343 case Instruction::DIV_INT_LIT16:
1344 case Instruction::DIV_INT_LIT8: {
Calin Juravlebacfec32014-11-14 15:54:36 +00001345 BuildCheckedDivRem(instruction.VRegA(), instruction.VRegB(), instruction.VRegC(),
1346 dex_pc, Primitive::kPrimInt, true, true);
1347 break;
1348 }
1349
1350 case Instruction::REM_INT_LIT16:
1351 case Instruction::REM_INT_LIT8: {
1352 BuildCheckedDivRem(instruction.VRegA(), instruction.VRegB(), instruction.VRegC(),
1353 dex_pc, Primitive::kPrimInt, true, false);
Calin Juravled0d48522014-11-04 16:40:20 +00001354 break;
1355 }
1356
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01001357 case Instruction::NEW_INSTANCE: {
1358 current_block_->AddInstruction(
Calin Juravle225ff812014-11-13 16:46:39 +00001359 new (arena_) HNewInstance(dex_pc, instruction.VRegB_21c()));
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01001360 UpdateLocal(instruction.VRegA(), current_block_->GetLastInstruction());
1361 break;
1362 }
1363
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01001364 case Instruction::NEW_ARRAY: {
1365 HInstruction* length = LoadLocal(instruction.VRegB_22c(), Primitive::kPrimInt);
1366 current_block_->AddInstruction(
Calin Juravle225ff812014-11-13 16:46:39 +00001367 new (arena_) HNewArray(length, dex_pc, instruction.VRegC_22c()));
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01001368 UpdateLocal(instruction.VRegA_22c(), current_block_->GetLastInstruction());
1369 break;
1370 }
1371
1372 case Instruction::FILLED_NEW_ARRAY: {
1373 uint32_t number_of_vreg_arguments = instruction.VRegA_35c();
1374 uint32_t type_index = instruction.VRegB_35c();
1375 uint32_t args[5];
1376 instruction.GetVarArgs(args);
Calin Juravle225ff812014-11-13 16:46:39 +00001377 BuildFilledNewArray(dex_pc, type_index, number_of_vreg_arguments, false, args, 0);
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01001378 break;
1379 }
1380
1381 case Instruction::FILLED_NEW_ARRAY_RANGE: {
1382 uint32_t number_of_vreg_arguments = instruction.VRegA_3rc();
1383 uint32_t type_index = instruction.VRegB_3rc();
1384 uint32_t register_index = instruction.VRegC_3rc();
1385 BuildFilledNewArray(
Calin Juravle225ff812014-11-13 16:46:39 +00001386 dex_pc, type_index, number_of_vreg_arguments, true, nullptr, register_index);
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01001387 break;
1388 }
1389
1390 case Instruction::FILL_ARRAY_DATA: {
Calin Juravle225ff812014-11-13 16:46:39 +00001391 BuildFillArrayData(instruction, dex_pc);
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01001392 break;
1393 }
1394
Nicolas Geoffrayddb311f2014-05-16 09:28:54 +01001395 case Instruction::MOVE_RESULT:
Dave Allison20dfc792014-06-16 20:44:29 -07001396 case Instruction::MOVE_RESULT_WIDE:
1397 case Instruction::MOVE_RESULT_OBJECT:
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01001398 UpdateLocal(instruction.VRegA(), latest_result_);
1399 latest_result_ = nullptr;
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001400 break;
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001401
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01001402 case Instruction::CMP_LONG: {
1403 Binop_23x<HCompare>(instruction, Primitive::kPrimLong);
1404 break;
1405 }
1406
Nicolas Geoffraybe9a92a2014-02-25 14:22:56 +00001407 case Instruction::NOP:
1408 break;
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001409
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001410 case Instruction::IGET:
1411 case Instruction::IGET_WIDE:
1412 case Instruction::IGET_OBJECT:
1413 case Instruction::IGET_BOOLEAN:
1414 case Instruction::IGET_BYTE:
1415 case Instruction::IGET_CHAR:
1416 case Instruction::IGET_SHORT: {
Calin Juravle225ff812014-11-13 16:46:39 +00001417 if (!BuildInstanceFieldAccess(instruction, dex_pc, false)) {
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001418 return false;
1419 }
1420 break;
1421 }
1422
1423 case Instruction::IPUT:
1424 case Instruction::IPUT_WIDE:
1425 case Instruction::IPUT_OBJECT:
1426 case Instruction::IPUT_BOOLEAN:
1427 case Instruction::IPUT_BYTE:
1428 case Instruction::IPUT_CHAR:
1429 case Instruction::IPUT_SHORT: {
Calin Juravle225ff812014-11-13 16:46:39 +00001430 if (!BuildInstanceFieldAccess(instruction, dex_pc, true)) {
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01001431 return false;
1432 }
1433 break;
1434 }
1435
1436 case Instruction::SGET:
1437 case Instruction::SGET_WIDE:
1438 case Instruction::SGET_OBJECT:
1439 case Instruction::SGET_BOOLEAN:
1440 case Instruction::SGET_BYTE:
1441 case Instruction::SGET_CHAR:
1442 case Instruction::SGET_SHORT: {
Calin Juravle225ff812014-11-13 16:46:39 +00001443 if (!BuildStaticFieldAccess(instruction, dex_pc, false)) {
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01001444 return false;
1445 }
1446 break;
1447 }
1448
1449 case Instruction::SPUT:
1450 case Instruction::SPUT_WIDE:
1451 case Instruction::SPUT_OBJECT:
1452 case Instruction::SPUT_BOOLEAN:
1453 case Instruction::SPUT_BYTE:
1454 case Instruction::SPUT_CHAR:
1455 case Instruction::SPUT_SHORT: {
Calin Juravle225ff812014-11-13 16:46:39 +00001456 if (!BuildStaticFieldAccess(instruction, dex_pc, true)) {
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001457 return false;
1458 }
1459 break;
1460 }
1461
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001462#define ARRAY_XX(kind, anticipated_type) \
1463 case Instruction::AGET##kind: { \
Calin Juravle225ff812014-11-13 16:46:39 +00001464 BuildArrayAccess(instruction, dex_pc, false, anticipated_type); \
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001465 break; \
1466 } \
1467 case Instruction::APUT##kind: { \
Calin Juravle225ff812014-11-13 16:46:39 +00001468 BuildArrayAccess(instruction, dex_pc, true, anticipated_type); \
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001469 break; \
1470 }
1471
1472 ARRAY_XX(, Primitive::kPrimInt);
1473 ARRAY_XX(_WIDE, Primitive::kPrimLong);
1474 ARRAY_XX(_OBJECT, Primitive::kPrimNot);
1475 ARRAY_XX(_BOOLEAN, Primitive::kPrimBoolean);
1476 ARRAY_XX(_BYTE, Primitive::kPrimByte);
1477 ARRAY_XX(_CHAR, Primitive::kPrimChar);
1478 ARRAY_XX(_SHORT, Primitive::kPrimShort);
1479
Nicolas Geoffray39468442014-09-02 15:17:15 +01001480 case Instruction::ARRAY_LENGTH: {
1481 HInstruction* object = LoadLocal(instruction.VRegB_12x(), Primitive::kPrimNot);
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +00001482 // No need for a temporary for the null check, it is the only input of the following
1483 // instruction.
Calin Juravle225ff812014-11-13 16:46:39 +00001484 object = new (arena_) HNullCheck(object, dex_pc);
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +00001485 current_block_->AddInstruction(object);
Nicolas Geoffray39468442014-09-02 15:17:15 +01001486 current_block_->AddInstruction(new (arena_) HArrayLength(object));
1487 UpdateLocal(instruction.VRegA_12x(), current_block_->GetLastInstruction());
1488 break;
1489 }
1490
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +00001491 case Instruction::CONST_STRING: {
Calin Juravle225ff812014-11-13 16:46:39 +00001492 current_block_->AddInstruction(new (arena_) HLoadString(instruction.VRegB_21c(), dex_pc));
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +00001493 UpdateLocal(instruction.VRegA_21c(), current_block_->GetLastInstruction());
1494 break;
1495 }
1496
1497 case Instruction::CONST_STRING_JUMBO: {
Calin Juravle225ff812014-11-13 16:46:39 +00001498 current_block_->AddInstruction(new (arena_) HLoadString(instruction.VRegB_31c(), dex_pc));
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +00001499 UpdateLocal(instruction.VRegA_31c(), current_block_->GetLastInstruction());
1500 break;
1501 }
1502
Nicolas Geoffray424f6762014-11-03 14:51:25 +00001503 case Instruction::CONST_CLASS: {
1504 uint16_t type_index = instruction.VRegB_21c();
1505 bool type_known_final;
1506 bool type_known_abstract;
1507 bool is_referrers_class;
1508 bool can_access = compiler_driver_->CanAccessTypeWithoutChecks(
1509 dex_compilation_unit_->GetDexMethodIndex(), *dex_file_, type_index,
1510 &type_known_final, &type_known_abstract, &is_referrers_class);
1511 if (!can_access) {
1512 return false;
1513 }
1514 current_block_->AddInstruction(
Calin Juravle225ff812014-11-13 16:46:39 +00001515 new (arena_) HLoadClass(type_index, is_referrers_class, dex_pc));
Nicolas Geoffray424f6762014-11-03 14:51:25 +00001516 UpdateLocal(instruction.VRegA_21c(), current_block_->GetLastInstruction());
1517 break;
1518 }
1519
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +00001520 case Instruction::MOVE_EXCEPTION: {
1521 current_block_->AddInstruction(new (arena_) HLoadException());
1522 UpdateLocal(instruction.VRegA_11x(), current_block_->GetLastInstruction());
1523 break;
1524 }
1525
1526 case Instruction::THROW: {
1527 HInstruction* exception = LoadLocal(instruction.VRegA_11x(), Primitive::kPrimNot);
Calin Juravle225ff812014-11-13 16:46:39 +00001528 current_block_->AddInstruction(new (arena_) HThrow(exception, dex_pc));
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +00001529 // A throw instruction must branch to the exit block.
1530 current_block_->AddSuccessor(exit_block_);
1531 // We finished building this block. Set the current block to null to avoid
1532 // adding dead instructions to it.
1533 current_block_ = nullptr;
1534 break;
1535 }
1536
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00001537 case Instruction::INSTANCE_OF: {
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00001538 uint8_t destination = instruction.VRegA_22c();
1539 uint8_t reference = instruction.VRegB_22c();
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00001540 uint16_t type_index = instruction.VRegC_22c();
Calin Juravle225ff812014-11-13 16:46:39 +00001541 if (!BuildTypeCheck(instruction, destination, reference, type_index, dex_pc)) {
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00001542 return false;
1543 }
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00001544 break;
1545 }
1546
1547 case Instruction::CHECK_CAST: {
1548 uint8_t reference = instruction.VRegA_21c();
1549 uint16_t type_index = instruction.VRegB_21c();
Calin Juravle225ff812014-11-13 16:46:39 +00001550 if (!BuildTypeCheck(instruction, -1, reference, type_index, dex_pc)) {
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00001551 return false;
1552 }
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00001553 break;
1554 }
1555
Nicolas Geoffrayb7baf5c2014-11-11 16:29:44 +00001556 case Instruction::MONITOR_ENTER: {
1557 current_block_->AddInstruction(new (arena_) HMonitorOperation(
1558 LoadLocal(instruction.VRegA_11x(), Primitive::kPrimNot),
1559 HMonitorOperation::kEnter,
Calin Juravle225ff812014-11-13 16:46:39 +00001560 dex_pc));
Nicolas Geoffrayb7baf5c2014-11-11 16:29:44 +00001561 break;
1562 }
1563
1564 case Instruction::MONITOR_EXIT: {
1565 current_block_->AddInstruction(new (arena_) HMonitorOperation(
1566 LoadLocal(instruction.VRegA_11x(), Primitive::kPrimNot),
1567 HMonitorOperation::kExit,
Calin Juravle225ff812014-11-13 16:46:39 +00001568 dex_pc));
Nicolas Geoffrayb7baf5c2014-11-11 16:29:44 +00001569 break;
1570 }
1571
Nicolas Geoffray818f2102014-02-18 16:43:35 +00001572 default:
1573 return false;
1574 }
1575 return true;
Nicolas Geoffraydadf3172014-11-07 16:36:02 +00001576} // NOLINT(readability/fn_size)
Nicolas Geoffray818f2102014-02-18 16:43:35 +00001577
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001578HIntConstant* HGraphBuilder::GetIntConstant0() {
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001579 if (constant0_ != nullptr) {
1580 return constant0_;
1581 }
1582 constant0_ = new(arena_) HIntConstant(0);
1583 entry_block_->AddInstruction(constant0_);
1584 return constant0_;
1585}
1586
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001587HIntConstant* HGraphBuilder::GetIntConstant1() {
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001588 if (constant1_ != nullptr) {
1589 return constant1_;
1590 }
1591 constant1_ = new(arena_) HIntConstant(1);
1592 entry_block_->AddInstruction(constant1_);
1593 return constant1_;
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00001594}
1595
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001596HIntConstant* HGraphBuilder::GetIntConstant(int32_t constant) {
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00001597 switch (constant) {
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001598 case 0: return GetIntConstant0();
1599 case 1: return GetIntConstant1();
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00001600 default: {
1601 HIntConstant* instruction = new (arena_) HIntConstant(constant);
1602 entry_block_->AddInstruction(instruction);
1603 return instruction;
1604 }
1605 }
1606}
1607
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001608HLongConstant* HGraphBuilder::GetLongConstant(int64_t constant) {
1609 HLongConstant* instruction = new (arena_) HLongConstant(constant);
1610 entry_block_->AddInstruction(instruction);
1611 return instruction;
1612}
1613
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00001614HLocal* HGraphBuilder::GetLocalAt(int register_index) const {
1615 return locals_.Get(register_index);
1616}
1617
1618void HGraphBuilder::UpdateLocal(int register_index, HInstruction* instruction) const {
1619 HLocal* local = GetLocalAt(register_index);
1620 current_block_->AddInstruction(new (arena_) HStoreLocal(local, instruction));
1621}
1622
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001623HInstruction* HGraphBuilder::LoadLocal(int register_index, Primitive::Type type) const {
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00001624 HLocal* local = GetLocalAt(register_index);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001625 current_block_->AddInstruction(new (arena_) HLoadLocal(local, type));
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001626 return current_block_->GetLastInstruction();
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00001627}
1628
Nicolas Geoffray818f2102014-02-18 16:43:35 +00001629} // namespace art