blob: c4ead5b0380d7a78047f6927a2d305acc7e3e54d [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
Mathieu Chartierc7853442015-03-27 14:35:38 -070019#include "art_field-inl.h"
Andreas Gamped881df52014-11-24 23:28:39 -080020#include "base/logging.h"
Nicolas Geoffraye5038322014-07-04 09:41:32 +010021#include "class_linker.h"
Jeff Hao848f70a2014-01-15 13:49:50 -080022#include "dex/verified_method.h"
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +000023#include "dex_file-inl.h"
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +000024#include "dex_instruction-inl.h"
Roland Levillain4c0eb422015-04-24 16:43:49 +010025#include "dex/verified_method.h"
Nicolas Geoffraye5038322014-07-04 09:41:32 +010026#include "driver/compiler_driver-inl.h"
Vladimir Marko20f85592015-03-19 10:07:02 +000027#include "driver/compiler_options.h"
Nicolas Geoffraye5038322014-07-04 09:41:32 +010028#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:
Calin Juravlef97f9fb2014-11-11 15:38:19 +000045 explicit Temporaries(HGraph* graph) : graph_(graph), index_(0) {}
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +010046
47 void Add(HInstruction* instruction) {
Calin Juravlef97f9fb2014-11-11 15:38:19 +000048 HInstruction* temp = new (graph_->GetArena()) HTemporary(index_);
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +010049 instruction->GetBlock()->AddInstruction(temp);
Calin Juravlef97f9fb2014-11-11 15:38:19 +000050
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +010051 DCHECK(temp->GetPrevious() == instruction);
Calin Juravlef97f9fb2014-11-11 15:38:19 +000052
53 size_t offset;
54 if (instruction->GetType() == Primitive::kPrimLong
55 || instruction->GetType() == Primitive::kPrimDouble) {
56 offset = 2;
57 } else {
58 offset = 1;
59 }
60 index_ += offset;
61
62 graph_->UpdateTemporariesVRegSlots(index_);
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +010063 }
64
65 private:
66 HGraph* const graph_;
67
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +010068 // Current index in the temporary stack, updated by `Add`.
69 size_t index_;
70};
71
Andreas Gamped881df52014-11-24 23:28:39 -080072class SwitchTable : public ValueObject {
73 public:
74 SwitchTable(const Instruction& instruction, uint32_t dex_pc, bool sparse)
75 : instruction_(instruction), dex_pc_(dex_pc), sparse_(sparse) {
76 int32_t table_offset = instruction.VRegB_31t();
77 const uint16_t* table = reinterpret_cast<const uint16_t*>(&instruction) + table_offset;
78 if (sparse) {
79 CHECK_EQ(table[0], static_cast<uint16_t>(Instruction::kSparseSwitchSignature));
80 } else {
81 CHECK_EQ(table[0], static_cast<uint16_t>(Instruction::kPackedSwitchSignature));
82 }
83 num_entries_ = table[1];
84 values_ = reinterpret_cast<const int32_t*>(&table[2]);
85 }
86
87 uint16_t GetNumEntries() const {
88 return num_entries_;
89 }
90
Andreas Gampee4d4d322014-12-04 09:09:57 -080091 void CheckIndex(size_t index) const {
92 if (sparse_) {
93 // In a sparse table, we have num_entries_ keys and num_entries_ values, in that order.
94 DCHECK_LT(index, 2 * static_cast<size_t>(num_entries_));
95 } else {
96 // In a packed table, we have the starting key and num_entries_ values.
97 DCHECK_LT(index, 1 + static_cast<size_t>(num_entries_));
98 }
99 }
100
Andreas Gamped881df52014-11-24 23:28:39 -0800101 int32_t GetEntryAt(size_t index) const {
Andreas Gampee4d4d322014-12-04 09:09:57 -0800102 CheckIndex(index);
Andreas Gamped881df52014-11-24 23:28:39 -0800103 return values_[index];
104 }
105
106 uint32_t GetDexPcForIndex(size_t index) const {
Andreas Gampee4d4d322014-12-04 09:09:57 -0800107 CheckIndex(index);
Andreas Gamped881df52014-11-24 23:28:39 -0800108 return dex_pc_ +
109 (reinterpret_cast<const int16_t*>(values_ + index) -
110 reinterpret_cast<const int16_t*>(&instruction_));
111 }
112
Andreas Gampee4d4d322014-12-04 09:09:57 -0800113 // Index of the first value in the table.
114 size_t GetFirstValueIndex() const {
115 if (sparse_) {
116 // In a sparse table, we have num_entries_ keys and num_entries_ values, in that order.
117 return num_entries_;
118 } else {
119 // In a packed table, we have the starting key and num_entries_ values.
120 return 1;
121 }
122 }
123
Andreas Gamped881df52014-11-24 23:28:39 -0800124 private:
125 const Instruction& instruction_;
126 const uint32_t dex_pc_;
127
128 // Whether this is a sparse-switch table (or a packed-switch one).
129 const bool sparse_;
130
131 // This can't be const as it needs to be computed off of the given instruction, and complicated
132 // expressions in the initializer list seemed very ugly.
133 uint16_t num_entries_;
134
135 const int32_t* values_;
136
137 DISALLOW_COPY_AND_ASSIGN(SwitchTable);
138};
139
Nicolas Geoffrayf583e592014-04-07 13:20:42 +0100140void HGraphBuilder::InitializeLocals(uint16_t count) {
141 graph_->SetNumberOfVRegs(count);
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +0000142 locals_.SetSize(count);
143 for (int i = 0; i < count; i++) {
144 HLocal* local = new (arena_) HLocal(i);
145 entry_block_->AddInstruction(local);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000146 locals_.Put(i, local);
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +0000147 }
148}
149
Nicolas Geoffray52e832b2014-11-06 15:15:31 +0000150void HGraphBuilder::InitializeParameters(uint16_t number_of_parameters) {
Nicolas Geoffrayf583e592014-04-07 13:20:42 +0100151 // dex_compilation_unit_ is null only when unit testing.
152 if (dex_compilation_unit_ == nullptr) {
Nicolas Geoffray52e832b2014-11-06 15:15:31 +0000153 return;
Nicolas Geoffrayf583e592014-04-07 13:20:42 +0100154 }
155
156 graph_->SetNumberOfInVRegs(number_of_parameters);
157 const char* shorty = dex_compilation_unit_->GetShorty();
158 int locals_index = locals_.Size() - number_of_parameters;
Nicolas Geoffrayf583e592014-04-07 13:20:42 +0100159 int parameter_index = 0;
160
161 if (!dex_compilation_unit_->IsStatic()) {
162 // Add the implicit 'this' argument, not expressed in the signature.
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100163 HParameterValue* parameter =
Calin Juravle10e244f2015-01-26 18:54:32 +0000164 new (arena_) HParameterValue(parameter_index++, Primitive::kPrimNot, true);
Nicolas Geoffrayb55f8352014-04-07 15:26:35 +0100165 entry_block_->AddInstruction(parameter);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +0100166 HLocal* local = GetLocalAt(locals_index++);
Nicolas Geoffrayb55f8352014-04-07 15:26:35 +0100167 entry_block_->AddInstruction(new (arena_) HStoreLocal(local, parameter));
Nicolas Geoffrayf583e592014-04-07 13:20:42 +0100168 number_of_parameters--;
169 }
170
171 uint32_t pos = 1;
172 for (int i = 0; i < number_of_parameters; i++) {
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100173 HParameterValue* parameter =
174 new (arena_) HParameterValue(parameter_index++, Primitive::GetType(shorty[pos++]));
175 entry_block_->AddInstruction(parameter);
176 HLocal* local = GetLocalAt(locals_index++);
177 // Store the parameter value in the local that the dex code will use
178 // to reference that parameter.
179 entry_block_->AddInstruction(new (arena_) HStoreLocal(local, parameter));
180 bool is_wide = (parameter->GetType() == Primitive::kPrimLong)
181 || (parameter->GetType() == Primitive::kPrimDouble);
182 if (is_wide) {
183 i++;
184 locals_index++;
185 parameter_index++;
Nicolas Geoffrayf583e592014-04-07 13:20:42 +0100186 }
187 }
Nicolas Geoffrayf583e592014-04-07 13:20:42 +0100188}
189
Nicolas Geoffrayb55f8352014-04-07 15:26:35 +0100190template<typename T>
Calin Juravle225ff812014-11-13 16:46:39 +0000191void HGraphBuilder::If_22t(const Instruction& instruction, uint32_t dex_pc) {
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000192 int32_t target_offset = instruction.GetTargetOffset();
David Brazdil852eaff2015-02-02 15:23:05 +0000193 HBasicBlock* branch_target = FindBlockStartingAt(dex_pc + target_offset);
194 HBasicBlock* fallthrough_target = FindBlockStartingAt(dex_pc + instruction.SizeInCodeUnits());
195 DCHECK(branch_target != nullptr);
196 DCHECK(fallthrough_target != nullptr);
197 PotentiallyAddSuspendCheck(branch_target, dex_pc);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100198 HInstruction* first = LoadLocal(instruction.VRegA(), Primitive::kPrimInt);
199 HInstruction* second = LoadLocal(instruction.VRegB(), Primitive::kPrimInt);
Dave Allison20dfc792014-06-16 20:44:29 -0700200 T* comparison = new (arena_) T(first, second);
201 current_block_->AddInstruction(comparison);
202 HInstruction* ifinst = new (arena_) HIf(comparison);
203 current_block_->AddInstruction(ifinst);
David Brazdil852eaff2015-02-02 15:23:05 +0000204 current_block_->AddSuccessor(branch_target);
205 current_block_->AddSuccessor(fallthrough_target);
Dave Allison20dfc792014-06-16 20:44:29 -0700206 current_block_ = nullptr;
207}
208
209template<typename T>
Calin Juravle225ff812014-11-13 16:46:39 +0000210void HGraphBuilder::If_21t(const Instruction& instruction, uint32_t dex_pc) {
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000211 int32_t target_offset = instruction.GetTargetOffset();
David Brazdil852eaff2015-02-02 15:23:05 +0000212 HBasicBlock* branch_target = FindBlockStartingAt(dex_pc + target_offset);
213 HBasicBlock* fallthrough_target = FindBlockStartingAt(dex_pc + instruction.SizeInCodeUnits());
214 DCHECK(branch_target != nullptr);
215 DCHECK(fallthrough_target != nullptr);
216 PotentiallyAddSuspendCheck(branch_target, dex_pc);
Dave Allison20dfc792014-06-16 20:44:29 -0700217 HInstruction* value = LoadLocal(instruction.VRegA(), Primitive::kPrimInt);
David Brazdil8d5b8b22015-03-24 10:51:52 +0000218 T* comparison = new (arena_) T(value, graph_->GetIntConstant(0));
Dave Allison20dfc792014-06-16 20:44:29 -0700219 current_block_->AddInstruction(comparison);
220 HInstruction* ifinst = new (arena_) HIf(comparison);
221 current_block_->AddInstruction(ifinst);
David Brazdil852eaff2015-02-02 15:23:05 +0000222 current_block_->AddSuccessor(branch_target);
223 current_block_->AddSuccessor(fallthrough_target);
Nicolas Geoffrayb55f8352014-04-07 15:26:35 +0100224 current_block_ = nullptr;
225}
226
Calin Juravle48c2b032014-12-09 18:11:36 +0000227void HGraphBuilder::MaybeRecordStat(MethodCompilationStat compilation_stat) {
228 if (compilation_stats_ != nullptr) {
229 compilation_stats_->RecordStat(compilation_stat);
230 }
231}
232
David Brazdil1b498722015-03-31 11:37:18 +0100233bool HGraphBuilder::SkipCompilation(const DexFile::CodeItem& code_item,
Calin Juravle48c2b032014-12-09 18:11:36 +0000234 size_t number_of_branches) {
235 const CompilerOptions& compiler_options = compiler_driver_->GetCompilerOptions();
Nicolas Geoffray43a539f2014-12-02 10:19:51 +0000236 CompilerOptions::CompilerFilter compiler_filter = compiler_options.GetCompilerFilter();
237 if (compiler_filter == CompilerOptions::kEverything) {
238 return false;
239 }
240
David Brazdil1b498722015-03-31 11:37:18 +0100241 if (compiler_options.IsHugeMethod(code_item.insns_size_in_code_units_)) {
Calin Juravle48c2b032014-12-09 18:11:36 +0000242 VLOG(compiler) << "Skip compilation of huge method "
243 << PrettyMethod(dex_compilation_unit_->GetDexMethodIndex(), *dex_file_)
David Brazdil1b498722015-03-31 11:37:18 +0100244 << ": " << code_item.insns_size_in_code_units_ << " code units";
Calin Juravle48c2b032014-12-09 18:11:36 +0000245 MaybeRecordStat(MethodCompilationStat::kNotCompiledHugeMethod);
Nicolas Geoffray43a539f2014-12-02 10:19:51 +0000246 return true;
247 }
248
249 // If it's large and contains no branches, it's likely to be machine generated initialization.
David Brazdil1b498722015-03-31 11:37:18 +0100250 if (compiler_options.IsLargeMethod(code_item.insns_size_in_code_units_)
251 && (number_of_branches == 0)) {
Calin Juravle48c2b032014-12-09 18:11:36 +0000252 VLOG(compiler) << "Skip compilation of large method with no branch "
253 << PrettyMethod(dex_compilation_unit_->GetDexMethodIndex(), *dex_file_)
David Brazdil1b498722015-03-31 11:37:18 +0100254 << ": " << code_item.insns_size_in_code_units_ << " code units";
Calin Juravle48c2b032014-12-09 18:11:36 +0000255 MaybeRecordStat(MethodCompilationStat::kNotCompiledLargeMethodNoBranches);
Nicolas Geoffray43a539f2014-12-02 10:19:51 +0000256 return true;
257 }
258
259 return false;
260}
261
David Brazdilbff75032015-07-08 17:26:51 +0000262static const DexFile::TryItem* GetTryItem(HBasicBlock* block,
263 const DexFile::CodeItem& code_item,
264 const ArenaBitVector& can_block_throw) {
265 DCHECK(!block->IsSingleTryBoundary());
266
267 // Block does not contain throwing instructions. Even if it is covered by
268 // a TryItem, we will consider it not in a try block.
269 if (!can_block_throw.IsBitSet(block->GetBlockId())) {
270 return nullptr;
271 }
272
273 // Instructions in the block may throw. Find a TryItem covering this block.
274 int32_t try_item_idx = DexFile::FindTryItem(code_item, block->GetDexPc());
David Brazdil6cd788f2015-07-08 16:44:00 +0100275 return (try_item_idx == -1) ? nullptr : DexFile::GetTryItems(code_item, try_item_idx);
David Brazdilfc6a86a2015-06-26 10:33:45 +0000276}
277
278void HGraphBuilder::CreateBlocksForTryCatch(const DexFile::CodeItem& code_item) {
279 if (code_item.tries_size_ == 0) {
280 return;
281 }
282
283 // Create branch targets at the start/end of the TryItem range. These are
284 // places where the program might fall through into/out of the a block and
285 // where TryBoundary instructions will be inserted later. Other edges which
286 // enter/exit the try blocks are a result of branches/switches.
287 for (size_t idx = 0; idx < code_item.tries_size_; ++idx) {
288 const DexFile::TryItem* try_item = DexFile::GetTryItems(code_item, idx);
289 uint32_t dex_pc_start = try_item->start_addr_;
290 uint32_t dex_pc_end = dex_pc_start + try_item->insn_count_;
291 FindOrCreateBlockStartingAt(dex_pc_start);
292 if (dex_pc_end < code_item.insns_size_in_code_units_) {
293 // TODO: Do not create block if the last instruction cannot fall through.
294 FindOrCreateBlockStartingAt(dex_pc_end);
295 } else {
296 // The TryItem spans until the very end of the CodeItem (or beyond if
297 // invalid) and therefore cannot have any code afterwards.
298 }
299 }
300
301 // Create branch targets for exception handlers.
302 const uint8_t* handlers_ptr = DexFile::GetCatchHandlerData(code_item, 0);
303 uint32_t handlers_size = DecodeUnsignedLeb128(&handlers_ptr);
304 for (uint32_t idx = 0; idx < handlers_size; ++idx) {
305 CatchHandlerIterator iterator(handlers_ptr);
306 for (; iterator.HasNext(); iterator.Next()) {
307 uint32_t address = iterator.GetHandlerAddress();
308 HBasicBlock* block = FindOrCreateBlockStartingAt(address);
David Brazdilec16f792015-08-19 15:04:01 +0100309 block->SetTryCatchInformation(
310 new (arena_) TryCatchInformation(iterator.GetHandlerTypeIndex(), *dex_file_));
David Brazdilfc6a86a2015-06-26 10:33:45 +0000311 }
312 handlers_ptr = iterator.EndDataPointer();
313 }
314}
315
David Brazdil56e1acc2015-06-30 15:41:36 +0100316void HGraphBuilder::SplitTryBoundaryEdge(HBasicBlock* predecessor,
317 HBasicBlock* successor,
318 HTryBoundary::BoundaryKind kind,
319 const DexFile::CodeItem& code_item,
320 const DexFile::TryItem& try_item) {
321 // Split the edge with a single TryBoundary instruction.
322 HTryBoundary* try_boundary = new (arena_) HTryBoundary(kind);
323 HBasicBlock* try_entry_block = graph_->SplitEdge(predecessor, successor);
324 try_entry_block->AddInstruction(try_boundary);
325
326 // Link the TryBoundary to the handlers of `try_item`.
327 for (CatchHandlerIterator it(code_item, try_item); it.HasNext(); it.Next()) {
328 try_boundary->AddExceptionHandler(FindBlockStartingAt(it.GetHandlerAddress()));
329 }
330}
331
David Brazdilfc6a86a2015-06-26 10:33:45 +0000332void HGraphBuilder::InsertTryBoundaryBlocks(const DexFile::CodeItem& code_item) {
333 if (code_item.tries_size_ == 0) {
334 return;
335 }
336
David Brazdil72783ff2015-07-09 14:36:05 +0100337 // Bit vector stores information on which blocks contain throwing instructions.
338 // Must be expandable because catch blocks may be split into two.
339 ArenaBitVector can_block_throw(arena_, graph_->GetBlocks().Size(), /* expandable */ true);
David Brazdilbff75032015-07-08 17:26:51 +0000340
341 // Scan blocks and mark those which contain throwing instructions.
David Brazdil72783ff2015-07-09 14:36:05 +0100342 for (size_t block_id = 0, e = graph_->GetBlocks().Size(); block_id < e; ++block_id) {
David Brazdilbff75032015-07-08 17:26:51 +0000343 HBasicBlock* block = graph_->GetBlocks().Get(block_id);
David Brazdil72783ff2015-07-09 14:36:05 +0100344 bool can_throw = false;
David Brazdilbff75032015-07-08 17:26:51 +0000345 for (HInstructionIterator insn(block->GetInstructions()); !insn.Done(); insn.Advance()) {
346 if (insn.Current()->CanThrow()) {
David Brazdil72783ff2015-07-09 14:36:05 +0100347 can_throw = true;
David Brazdilbff75032015-07-08 17:26:51 +0000348 break;
349 }
350 }
David Brazdil72783ff2015-07-09 14:36:05 +0100351
352 if (can_throw) {
353 if (block->IsCatchBlock()) {
354 // Catch blocks are always considered an entry point into the TryItem in
355 // order to avoid splitting exceptional edges. We split the block after
356 // the move-exception (if present) and mark the first part non-throwing.
357 // Later on, a TryBoundary will be inserted between the two blocks.
358 HInstruction* first_insn = block->GetFirstInstruction();
359 if (first_insn->IsLoadException()) {
360 // Catch block starts with a LoadException. Split the block after the
David Brazdilcb1c0552015-08-04 16:22:25 +0100361 // StoreLocal and ClearException which must come after the load.
David Brazdil72783ff2015-07-09 14:36:05 +0100362 DCHECK(first_insn->GetNext()->IsStoreLocal());
David Brazdilcb1c0552015-08-04 16:22:25 +0100363 DCHECK(first_insn->GetNext()->GetNext()->IsClearException());
364 block = block->SplitBefore(first_insn->GetNext()->GetNext()->GetNext());
David Brazdil72783ff2015-07-09 14:36:05 +0100365 } else {
366 // Catch block does not load the exception. Split at the beginning to
367 // create an empty catch block.
368 block = block->SplitBefore(first_insn);
369 }
370 }
371 can_block_throw.SetBit(block->GetBlockId());
372 }
David Brazdilbff75032015-07-08 17:26:51 +0000373 }
374
David Brazdil281a6322015-07-03 10:34:57 +0100375 // Iterate over all blocks, find those covered by some TryItem and:
376 // (a) split edges which enter/exit the try range,
377 // (b) create TryBoundary instructions in the new blocks,
378 // (c) link the new blocks to corresponding exception handlers.
379 // We cannot iterate only over blocks in `branch_targets_` because switch-case
380 // blocks share the same dex_pc.
David Brazdil72783ff2015-07-09 14:36:05 +0100381 for (size_t block_id = 0, e = graph_->GetBlocks().Size(); block_id < e; ++block_id) {
David Brazdil281a6322015-07-03 10:34:57 +0100382 HBasicBlock* try_block = graph_->GetBlocks().Get(block_id);
David Brazdilfc6a86a2015-06-26 10:33:45 +0000383
David Brazdil281a6322015-07-03 10:34:57 +0100384 // TryBoundary blocks are added at the end of the list and not iterated over.
385 DCHECK(!try_block->IsSingleTryBoundary());
David Brazdilfc6a86a2015-06-26 10:33:45 +0000386
David Brazdil281a6322015-07-03 10:34:57 +0100387 // Find the TryItem for this block.
David Brazdilbff75032015-07-08 17:26:51 +0000388 const DexFile::TryItem* try_item = GetTryItem(try_block, code_item, can_block_throw);
389 if (try_item == nullptr) {
David Brazdil281a6322015-07-03 10:34:57 +0100390 continue;
391 }
David Brazdil281a6322015-07-03 10:34:57 +0100392
David Brazdil72783ff2015-07-09 14:36:05 +0100393 // Catch blocks were split earlier and cannot throw.
394 DCHECK(!try_block->IsCatchBlock());
395
396 // Find predecessors which are not covered by the same TryItem range. Such
397 // edges enter the try block and will have a TryBoundary inserted.
398 for (size_t i = 0; i < try_block->GetPredecessors().Size(); ++i) {
399 HBasicBlock* predecessor = try_block->GetPredecessors().Get(i);
400 if (predecessor->IsSingleTryBoundary()) {
401 // The edge was already split because of an exit from a neighbouring
402 // TryItem. We split it again and insert an entry point.
403 if (kIsDebugBuild) {
404 HTryBoundary* last_insn = predecessor->GetLastInstruction()->AsTryBoundary();
405 const DexFile::TryItem* predecessor_try_item =
406 GetTryItem(predecessor->GetSinglePredecessor(), code_item, can_block_throw);
407 DCHECK(!last_insn->IsEntry());
408 DCHECK_EQ(last_insn->GetNormalFlowSuccessor(), try_block);
409 DCHECK(try_block->IsFirstIndexOfPredecessor(predecessor, i));
410 DCHECK_NE(try_item, predecessor_try_item);
David Brazdilfc6a86a2015-06-26 10:33:45 +0000411 }
David Brazdil72783ff2015-07-09 14:36:05 +0100412 } else if (GetTryItem(predecessor, code_item, can_block_throw) != try_item) {
413 // This is an entry point into the TryItem and the edge has not been
414 // split yet. That means that `predecessor` is not in a TryItem, or
415 // it is in a different TryItem and we happened to iterate over this
416 // block first. We split the edge and insert an entry point.
417 } else {
418 // Not an edge on the boundary of the try block.
419 continue;
David Brazdilfc6a86a2015-06-26 10:33:45 +0000420 }
David Brazdil72783ff2015-07-09 14:36:05 +0100421 SplitTryBoundaryEdge(predecessor, try_block, HTryBoundary::kEntry, code_item, *try_item);
David Brazdilfc6a86a2015-06-26 10:33:45 +0000422 }
David Brazdil281a6322015-07-03 10:34:57 +0100423
424 // Find successors which are not covered by the same TryItem range. Such
425 // edges exit the try block and will have a TryBoundary inserted.
426 for (size_t i = 0; i < try_block->GetSuccessors().Size(); ++i) {
427 HBasicBlock* successor = try_block->GetSuccessors().Get(i);
428 if (successor->IsCatchBlock()) {
429 // A catch block is always considered an entry point into its TryItem.
430 // We therefore assume this is an exit point, regardless of whether
431 // the catch block is in a different TryItem or not.
432 } else if (successor->IsSingleTryBoundary()) {
433 // The edge was already split because of an entry into a neighbouring
434 // TryItem. We split it again and insert an exit.
435 if (kIsDebugBuild) {
436 HTryBoundary* last_insn = successor->GetLastInstruction()->AsTryBoundary();
David Brazdilbff75032015-07-08 17:26:51 +0000437 const DexFile::TryItem* successor_try_item =
438 GetTryItem(last_insn->GetNormalFlowSuccessor(), code_item, can_block_throw);
David Brazdil281a6322015-07-03 10:34:57 +0100439 DCHECK_EQ(try_block, successor->GetSinglePredecessor());
440 DCHECK(last_insn->IsEntry());
David Brazdilbff75032015-07-08 17:26:51 +0000441 DCHECK_NE(try_item, successor_try_item);
David Brazdil281a6322015-07-03 10:34:57 +0100442 }
David Brazdilbff75032015-07-08 17:26:51 +0000443 } else if (GetTryItem(successor, code_item, can_block_throw) != try_item) {
David Brazdil281a6322015-07-03 10:34:57 +0100444 // This is an exit out of the TryItem and the edge has not been split
445 // yet. That means that either `successor` is not in a TryItem, or it
446 // is in a different TryItem and we happened to iterate over this
447 // block first. We split the edge and insert an exit.
448 HInstruction* last_instruction = try_block->GetLastInstruction();
449 if (last_instruction->IsReturn() || last_instruction->IsReturnVoid()) {
450 DCHECK_EQ(successor, exit_block_);
451 // Control flow exits the try block with a Return(Void). Because
452 // splitting the edge would invalidate the invariant that Return
453 // always jumps to Exit, we move the Return outside the try block.
454 successor = try_block->SplitBefore(last_instruction);
455 }
456 } else {
457 // Not an edge on the boundary of the try block.
458 continue;
459 }
David Brazdilbff75032015-07-08 17:26:51 +0000460 SplitTryBoundaryEdge(try_block, successor, HTryBoundary::kExit, code_item, *try_item);
David Brazdil281a6322015-07-03 10:34:57 +0100461 }
David Brazdilfc6a86a2015-06-26 10:33:45 +0000462 }
463}
464
David Brazdil5e8b1372015-01-23 14:39:08 +0000465bool HGraphBuilder::BuildGraph(const DexFile::CodeItem& code_item) {
466 DCHECK(graph_->GetBlocks().IsEmpty());
467
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +0000468 const uint16_t* code_ptr = code_item.insns_;
469 const uint16_t* code_end = code_item.insns_ + code_item.insns_size_in_code_units_;
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +0100470 code_start_ = code_ptr;
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +0000471
Nicolas Geoffraybe9a92a2014-02-25 14:22:56 +0000472 // Setup the graph with the entry block and exit block.
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100473 entry_block_ = new (arena_) HBasicBlock(graph_, 0);
Nicolas Geoffray818f2102014-02-18 16:43:35 +0000474 graph_->AddBlock(entry_block_);
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100475 exit_block_ = new (arena_) HBasicBlock(graph_, kNoDexPc);
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000476 graph_->SetEntryBlock(entry_block_);
477 graph_->SetExitBlock(exit_block_);
Nicolas Geoffray818f2102014-02-18 16:43:35 +0000478
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +0000479 InitializeLocals(code_item.registers_size_);
Nicolas Geoffraye53798a2014-12-01 10:31:54 +0000480 graph_->SetMaximumNumberOfOutVRegs(code_item.outs_size_);
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +0000481
Nicolas Geoffray43a539f2014-12-02 10:19:51 +0000482 // Compute the number of dex instructions, blocks, and branches. We will
483 // check these values against limits given to the compiler.
Nicolas Geoffray43a539f2014-12-02 10:19:51 +0000484 size_t number_of_branches = 0;
485
Nicolas Geoffraybe9a92a2014-02-25 14:22:56 +0000486 // To avoid splitting blocks, we compute ahead of time the instructions that
487 // start a new block, and create these blocks.
Calin Juravle702d2602015-04-30 19:28:21 +0100488 if (!ComputeBranchTargets(code_ptr, code_end, &number_of_branches)) {
489 MaybeRecordStat(MethodCompilationStat::kNotCompiledBranchOutsideMethodCode);
490 return false;
491 }
Nicolas Geoffray43a539f2014-12-02 10:19:51 +0000492
493 // Note that the compiler driver is null when unit testing.
David Brazdil1b498722015-03-31 11:37:18 +0100494 if ((compiler_driver_ != nullptr) && SkipCompilation(code_item, number_of_branches)) {
David Brazdil5e8b1372015-01-23 14:39:08 +0000495 return false;
Nicolas Geoffray43a539f2014-12-02 10:19:51 +0000496 }
Nicolas Geoffray818f2102014-02-18 16:43:35 +0000497
David Brazdilfc6a86a2015-06-26 10:33:45 +0000498 CreateBlocksForTryCatch(code_item);
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +0000499
Nicolas Geoffray52e832b2014-11-06 15:15:31 +0000500 InitializeParameters(code_item.ins_size_);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +0100501
Calin Juravle225ff812014-11-13 16:46:39 +0000502 size_t dex_pc = 0;
Nicolas Geoffray818f2102014-02-18 16:43:35 +0000503 while (code_ptr < code_end) {
Calin Juravle225ff812014-11-13 16:46:39 +0000504 // Update the current block if dex_pc starts a new block.
505 MaybeUpdateCurrentBlock(dex_pc);
Nicolas Geoffray818f2102014-02-18 16:43:35 +0000506 const Instruction& instruction = *Instruction::At(code_ptr);
Calin Juravle48c2b032014-12-09 18:11:36 +0000507 if (!AnalyzeDexInstruction(instruction, dex_pc)) {
David Brazdil5e8b1372015-01-23 14:39:08 +0000508 return false;
Calin Juravle48c2b032014-12-09 18:11:36 +0000509 }
Calin Juravle225ff812014-11-13 16:46:39 +0000510 dex_pc += instruction.SizeInCodeUnits();
Nicolas Geoffray818f2102014-02-18 16:43:35 +0000511 code_ptr += instruction.SizeInCodeUnits();
512 }
513
David Brazdilfc6a86a2015-06-26 10:33:45 +0000514 // Add Exit to the exit block.
David Brazdil3e187382015-06-26 09:59:52 +0000515 exit_block_->AddInstruction(new (arena_) HExit());
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000516 // Add the suspend check to the entry block.
517 entry_block_->AddInstruction(new (arena_) HSuspendCheck(0));
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +0000518 entry_block_->AddInstruction(new (arena_) HGoto());
David Brazdilbff75032015-07-08 17:26:51 +0000519 // Add the exit block at the end.
520 graph_->AddBlock(exit_block_);
David Brazdil5e8b1372015-01-23 14:39:08 +0000521
David Brazdilfc6a86a2015-06-26 10:33:45 +0000522 // Iterate over blocks covered by TryItems and insert TryBoundaries at entry
523 // and exit points. This requires all control-flow instructions and
524 // non-exceptional edges to have been created.
525 InsertTryBoundaryBlocks(code_item);
526
David Brazdil5e8b1372015-01-23 14:39:08 +0000527 return true;
Nicolas Geoffray818f2102014-02-18 16:43:35 +0000528}
529
David Brazdilfc6a86a2015-06-26 10:33:45 +0000530void HGraphBuilder::MaybeUpdateCurrentBlock(size_t dex_pc) {
531 HBasicBlock* block = FindBlockStartingAt(dex_pc);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000532 if (block == nullptr) {
533 return;
534 }
Nicolas Geoffraybe9a92a2014-02-25 14:22:56 +0000535
536 if (current_block_ != nullptr) {
537 // Branching instructions clear current_block, so we know
538 // the last instruction of the current block is not a branching
539 // instruction. We add an unconditional goto to the found block.
540 current_block_->AddInstruction(new (arena_) HGoto());
541 current_block_->AddSuccessor(block);
542 }
543 graph_->AddBlock(block);
544 current_block_ = block;
545}
546
Calin Juravle702d2602015-04-30 19:28:21 +0100547bool HGraphBuilder::ComputeBranchTargets(const uint16_t* code_ptr,
Nicolas Geoffray43a539f2014-12-02 10:19:51 +0000548 const uint16_t* code_end,
Nicolas Geoffray43a539f2014-12-02 10:19:51 +0000549 size_t* number_of_branches) {
Nicolas Geoffraybe9a92a2014-02-25 14:22:56 +0000550 branch_targets_.SetSize(code_end - code_ptr);
551
552 // Create the first block for the dex instructions, single successor of the entry block.
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100553 HBasicBlock* block = new (arena_) HBasicBlock(graph_, 0);
Nicolas Geoffraybe9a92a2014-02-25 14:22:56 +0000554 branch_targets_.Put(0, block);
555 entry_block_->AddSuccessor(block);
556
557 // Iterate over all instructions and find branching instructions. Create blocks for
558 // the locations these instructions branch to.
Andreas Gamped881df52014-11-24 23:28:39 -0800559 uint32_t dex_pc = 0;
Nicolas Geoffraybe9a92a2014-02-25 14:22:56 +0000560 while (code_ptr < code_end) {
561 const Instruction& instruction = *Instruction::At(code_ptr);
562 if (instruction.IsBranch()) {
Nicolas Geoffray43a539f2014-12-02 10:19:51 +0000563 (*number_of_branches)++;
Calin Juravle225ff812014-11-13 16:46:39 +0000564 int32_t target = instruction.GetTargetOffset() + dex_pc;
Nicolas Geoffraybe9a92a2014-02-25 14:22:56 +0000565 // Create a block for the target instruction.
David Brazdilfc6a86a2015-06-26 10:33:45 +0000566 FindOrCreateBlockStartingAt(target);
567
Calin Juravle225ff812014-11-13 16:46:39 +0000568 dex_pc += instruction.SizeInCodeUnits();
Nicolas Geoffraybe9a92a2014-02-25 14:22:56 +0000569 code_ptr += instruction.SizeInCodeUnits();
Calin Juravle702d2602015-04-30 19:28:21 +0100570
David Brazdilfe659462015-06-24 14:23:56 +0100571 if (instruction.CanFlowThrough()) {
572 if (code_ptr >= code_end) {
Calin Juravle702d2602015-04-30 19:28:21 +0100573 // In the normal case we should never hit this but someone can artificially forge a dex
574 // file to fall-through out the method code. In this case we bail out compilation.
575 return false;
David Brazdilfc6a86a2015-06-26 10:33:45 +0000576 } else {
577 FindOrCreateBlockStartingAt(dex_pc);
Calin Juravle702d2602015-04-30 19:28:21 +0100578 }
Nicolas Geoffraybe9a92a2014-02-25 14:22:56 +0000579 }
Andreas Gampee4d4d322014-12-04 09:09:57 -0800580 } else if (instruction.IsSwitch()) {
581 SwitchTable table(instruction, dex_pc, instruction.Opcode() == Instruction::SPARSE_SWITCH);
Andreas Gamped881df52014-11-24 23:28:39 -0800582
583 uint16_t num_entries = table.GetNumEntries();
584
Andreas Gampee4d4d322014-12-04 09:09:57 -0800585 // In a packed-switch, the entry at index 0 is the starting key. In a sparse-switch, the
586 // entry at index 0 is the first key, and values are after *all* keys.
587 size_t offset = table.GetFirstValueIndex();
588
589 // Use a larger loop counter type to avoid overflow issues.
590 for (size_t i = 0; i < num_entries; ++i) {
Andreas Gamped881df52014-11-24 23:28:39 -0800591 // The target of the case.
Andreas Gampee4d4d322014-12-04 09:09:57 -0800592 uint32_t target = dex_pc + table.GetEntryAt(i + offset);
David Brazdilfc6a86a2015-06-26 10:33:45 +0000593 FindOrCreateBlockStartingAt(target);
Andreas Gamped881df52014-11-24 23:28:39 -0800594
David Brazdil281a6322015-07-03 10:34:57 +0100595 // Create a block for the switch-case logic. The block gets the dex_pc
596 // of the SWITCH instruction because it is part of its semantics.
597 block = new (arena_) HBasicBlock(graph_, dex_pc);
598 branch_targets_.Put(table.GetDexPcForIndex(i), block);
Andreas Gamped881df52014-11-24 23:28:39 -0800599 }
600
601 // Fall-through. Add a block if there is more code afterwards.
602 dex_pc += instruction.SizeInCodeUnits();
603 code_ptr += instruction.SizeInCodeUnits();
Calin Juravle702d2602015-04-30 19:28:21 +0100604 if (code_ptr >= code_end) {
605 // In the normal case we should never hit this but someone can artificially forge a dex
606 // file to fall-through out the method code. In this case we bail out compilation.
607 // (A switch can fall-through so we don't need to check CanFlowThrough().)
608 return false;
David Brazdilfc6a86a2015-06-26 10:33:45 +0000609 } else {
610 FindOrCreateBlockStartingAt(dex_pc);
Andreas Gamped881df52014-11-24 23:28:39 -0800611 }
Nicolas Geoffraybe9a92a2014-02-25 14:22:56 +0000612 } else {
613 code_ptr += instruction.SizeInCodeUnits();
Calin Juravle225ff812014-11-13 16:46:39 +0000614 dex_pc += instruction.SizeInCodeUnits();
Nicolas Geoffraybe9a92a2014-02-25 14:22:56 +0000615 }
616 }
Calin Juravle702d2602015-04-30 19:28:21 +0100617 return true;
Nicolas Geoffraybe9a92a2014-02-25 14:22:56 +0000618}
619
David Brazdilfc6a86a2015-06-26 10:33:45 +0000620HBasicBlock* HGraphBuilder::FindBlockStartingAt(int32_t dex_pc) const {
621 DCHECK_GE(dex_pc, 0);
622 DCHECK_LT(static_cast<size_t>(dex_pc), branch_targets_.Size());
623 return branch_targets_.Get(dex_pc);
624}
625
626HBasicBlock* HGraphBuilder::FindOrCreateBlockStartingAt(int32_t dex_pc) {
627 HBasicBlock* block = FindBlockStartingAt(dex_pc);
628 if (block == nullptr) {
629 block = new (arena_) HBasicBlock(graph_, dex_pc);
630 branch_targets_.Put(dex_pc, block);
631 }
632 return block;
Nicolas Geoffraybe9a92a2014-02-25 14:22:56 +0000633}
634
Nicolas Geoffrayf583e592014-04-07 13:20:42 +0100635template<typename T>
Roland Levillain88cb1752014-10-20 16:36:47 +0100636void HGraphBuilder::Unop_12x(const Instruction& instruction, Primitive::Type type) {
637 HInstruction* first = LoadLocal(instruction.VRegB(), type);
638 current_block_->AddInstruction(new (arena_) T(type, first));
639 UpdateLocal(instruction.VRegA(), current_block_->GetLastInstruction());
640}
641
Roland Levillaindff1f282014-11-05 14:15:05 +0000642void HGraphBuilder::Conversion_12x(const Instruction& instruction,
643 Primitive::Type input_type,
Roland Levillain624279f2014-12-04 11:54:28 +0000644 Primitive::Type result_type,
645 uint32_t dex_pc) {
Roland Levillaindff1f282014-11-05 14:15:05 +0000646 HInstruction* first = LoadLocal(instruction.VRegB(), input_type);
Roland Levillain624279f2014-12-04 11:54:28 +0000647 current_block_->AddInstruction(new (arena_) HTypeConversion(result_type, first, dex_pc));
Roland Levillaindff1f282014-11-05 14:15:05 +0000648 UpdateLocal(instruction.VRegA(), current_block_->GetLastInstruction());
649}
650
Roland Levillain88cb1752014-10-20 16:36:47 +0100651template<typename T>
Nicolas Geoffray412f10c2014-06-19 10:00:34 +0100652void HGraphBuilder::Binop_23x(const Instruction& instruction, Primitive::Type type) {
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100653 HInstruction* first = LoadLocal(instruction.VRegB(), type);
654 HInstruction* second = LoadLocal(instruction.VRegC(), type);
655 current_block_->AddInstruction(new (arena_) T(type, first, second));
Nicolas Geoffrayf583e592014-04-07 13:20:42 +0100656 UpdateLocal(instruction.VRegA(), current_block_->GetLastInstruction());
657}
658
659template<typename T>
Calin Juravled6fb6cf2014-11-11 19:07:44 +0000660void HGraphBuilder::Binop_23x(const Instruction& instruction,
661 Primitive::Type type,
662 uint32_t dex_pc) {
663 HInstruction* first = LoadLocal(instruction.VRegB(), type);
664 HInstruction* second = LoadLocal(instruction.VRegC(), type);
665 current_block_->AddInstruction(new (arena_) T(type, first, second, dex_pc));
666 UpdateLocal(instruction.VRegA(), current_block_->GetLastInstruction());
667}
668
669template<typename T>
Calin Juravle9aec02f2014-11-18 23:06:35 +0000670void HGraphBuilder::Binop_23x_shift(const Instruction& instruction,
671 Primitive::Type type) {
672 HInstruction* first = LoadLocal(instruction.VRegB(), type);
673 HInstruction* second = LoadLocal(instruction.VRegC(), Primitive::kPrimInt);
674 current_block_->AddInstruction(new (arena_) T(type, first, second));
675 UpdateLocal(instruction.VRegA(), current_block_->GetLastInstruction());
676}
677
Calin Juravleddb7df22014-11-25 20:56:51 +0000678void HGraphBuilder::Binop_23x_cmp(const Instruction& instruction,
679 Primitive::Type type,
Mark Mendellc4701932015-04-10 13:18:51 -0400680 ComparisonBias bias,
Alexey Frunze4dda3372015-06-01 18:31:49 -0700681 uint32_t dex_pc) {
Calin Juravleddb7df22014-11-25 20:56:51 +0000682 HInstruction* first = LoadLocal(instruction.VRegB(), type);
683 HInstruction* second = LoadLocal(instruction.VRegC(), type);
Alexey Frunze4dda3372015-06-01 18:31:49 -0700684 current_block_->AddInstruction(new (arena_) HCompare(type, first, second, bias, dex_pc));
Calin Juravleddb7df22014-11-25 20:56:51 +0000685 UpdateLocal(instruction.VRegA(), current_block_->GetLastInstruction());
686}
687
Calin Juravle9aec02f2014-11-18 23:06:35 +0000688template<typename T>
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100689void HGraphBuilder::Binop_12x(const Instruction& instruction, Primitive::Type type) {
690 HInstruction* first = LoadLocal(instruction.VRegA(), type);
691 HInstruction* second = LoadLocal(instruction.VRegB(), type);
692 current_block_->AddInstruction(new (arena_) T(type, first, second));
Nicolas Geoffrayf583e592014-04-07 13:20:42 +0100693 UpdateLocal(instruction.VRegA(), current_block_->GetLastInstruction());
694}
695
696template<typename T>
Calin Juravle9aec02f2014-11-18 23:06:35 +0000697void HGraphBuilder::Binop_12x_shift(const Instruction& instruction, Primitive::Type type) {
698 HInstruction* first = LoadLocal(instruction.VRegA(), type);
699 HInstruction* second = LoadLocal(instruction.VRegB(), Primitive::kPrimInt);
700 current_block_->AddInstruction(new (arena_) T(type, first, second));
701 UpdateLocal(instruction.VRegA(), current_block_->GetLastInstruction());
702}
703
704template<typename T>
Calin Juravled6fb6cf2014-11-11 19:07:44 +0000705void HGraphBuilder::Binop_12x(const Instruction& instruction,
706 Primitive::Type type,
707 uint32_t dex_pc) {
708 HInstruction* first = LoadLocal(instruction.VRegA(), type);
709 HInstruction* second = LoadLocal(instruction.VRegB(), type);
710 current_block_->AddInstruction(new (arena_) T(type, first, second, dex_pc));
711 UpdateLocal(instruction.VRegA(), current_block_->GetLastInstruction());
712}
713
714template<typename T>
Nicolas Geoffrayf583e592014-04-07 13:20:42 +0100715void HGraphBuilder::Binop_22s(const Instruction& instruction, bool reverse) {
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100716 HInstruction* first = LoadLocal(instruction.VRegB(), Primitive::kPrimInt);
David Brazdil8d5b8b22015-03-24 10:51:52 +0000717 HInstruction* second = graph_->GetIntConstant(instruction.VRegC_22s());
Nicolas Geoffrayf583e592014-04-07 13:20:42 +0100718 if (reverse) {
719 std::swap(first, second);
720 }
721 current_block_->AddInstruction(new (arena_) T(Primitive::kPrimInt, first, second));
722 UpdateLocal(instruction.VRegA(), current_block_->GetLastInstruction());
723}
724
725template<typename T>
726void HGraphBuilder::Binop_22b(const Instruction& instruction, bool reverse) {
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100727 HInstruction* first = LoadLocal(instruction.VRegB(), Primitive::kPrimInt);
David Brazdil8d5b8b22015-03-24 10:51:52 +0000728 HInstruction* second = graph_->GetIntConstant(instruction.VRegC_22b());
Nicolas Geoffrayf583e592014-04-07 13:20:42 +0100729 if (reverse) {
730 std::swap(first, second);
731 }
732 current_block_->AddInstruction(new (arena_) T(Primitive::kPrimInt, first, second));
733 UpdateLocal(instruction.VRegA(), current_block_->GetLastInstruction());
734}
735
Calin Juravle0c25d102015-04-20 14:49:09 +0100736static bool RequiresConstructorBarrier(const DexCompilationUnit* cu, const CompilerDriver& driver) {
Calin Juravle27df7582015-04-17 19:12:31 +0100737 Thread* self = Thread::Current();
Calin Juravle0c25d102015-04-20 14:49:09 +0100738 return cu->IsConstructor()
739 && driver.RequiresConstructorBarrier(self, cu->GetDexFile(), cu->GetClassDefIndex());
Calin Juravle27df7582015-04-17 19:12:31 +0100740}
741
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100742void HGraphBuilder::BuildReturn(const Instruction& instruction, Primitive::Type type) {
743 if (type == Primitive::kPrimVoid) {
Calin Juravle3cd4fc82015-05-14 15:15:42 +0100744 if (graph_->ShouldGenerateConstructorBarrier()) {
745 // The compilation unit is null during testing.
746 if (dex_compilation_unit_ != nullptr) {
747 DCHECK(RequiresConstructorBarrier(dex_compilation_unit_, *compiler_driver_))
748 << "Inconsistent use of ShouldGenerateConstructorBarrier. Should not generate a barrier.";
749 }
Calin Juravle27df7582015-04-17 19:12:31 +0100750 current_block_->AddInstruction(new (arena_) HMemoryBarrier(kStoreStore));
751 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100752 current_block_->AddInstruction(new (arena_) HReturnVoid());
753 } else {
754 HInstruction* value = LoadLocal(instruction.VRegA(), type);
755 current_block_->AddInstruction(new (arena_) HReturn(value));
756 }
757 current_block_->AddSuccessor(exit_block_);
758 current_block_ = nullptr;
759}
760
Nicolas Geoffray2e7cd752015-07-10 11:38:52 +0100761void HGraphBuilder::PotentiallySimplifyFakeString(uint16_t original_dex_register,
762 uint32_t dex_pc,
763 HInvoke* actual_string) {
764 if (!graph_->IsDebuggable()) {
765 // Notify that we cannot compile with baseline. The dex registers aliasing
766 // with `original_dex_register` will be handled when we optimize
767 // (see HInstructionSimplifer::VisitFakeString).
768 can_use_baseline_for_string_init_ = false;
769 return;
770 }
771 const VerifiedMethod* verified_method =
772 compiler_driver_->GetVerifiedMethod(dex_file_, dex_compilation_unit_->GetDexMethodIndex());
773 if (verified_method != nullptr) {
774 UpdateLocal(original_dex_register, actual_string);
775 const SafeMap<uint32_t, std::set<uint32_t>>& string_init_map =
776 verified_method->GetStringInitPcRegMap();
777 auto map_it = string_init_map.find(dex_pc);
778 if (map_it != string_init_map.end()) {
779 std::set<uint32_t> reg_set = map_it->second;
780 for (auto set_it = reg_set.begin(); set_it != reg_set.end(); ++set_it) {
781 HInstruction* load_local = LoadLocal(original_dex_register, Primitive::kPrimNot);
782 UpdateLocal(*set_it, load_local);
783 }
784 }
785 } else {
786 can_use_baseline_for_string_init_ = false;
787 }
788}
789
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100790bool HGraphBuilder::BuildInvoke(const Instruction& instruction,
Calin Juravle225ff812014-11-13 16:46:39 +0000791 uint32_t dex_pc,
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100792 uint32_t method_idx,
793 uint32_t number_of_vreg_arguments,
794 bool is_range,
795 uint32_t* args,
796 uint32_t register_index) {
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +0100797 Instruction::Code opcode = instruction.Opcode();
798 InvokeType invoke_type;
799 switch (opcode) {
800 case Instruction::INVOKE_STATIC:
801 case Instruction::INVOKE_STATIC_RANGE:
802 invoke_type = kStatic;
803 break;
804 case Instruction::INVOKE_DIRECT:
805 case Instruction::INVOKE_DIRECT_RANGE:
806 invoke_type = kDirect;
807 break;
808 case Instruction::INVOKE_VIRTUAL:
Nicolas Geoffray9523a3e2015-07-17 11:51:28 +0000809 case Instruction::INVOKE_VIRTUAL_QUICK:
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +0100810 case Instruction::INVOKE_VIRTUAL_RANGE:
Nicolas Geoffray9523a3e2015-07-17 11:51:28 +0000811 case Instruction::INVOKE_VIRTUAL_RANGE_QUICK:
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +0100812 invoke_type = kVirtual;
813 break;
814 case Instruction::INVOKE_INTERFACE:
815 case Instruction::INVOKE_INTERFACE_RANGE:
816 invoke_type = kInterface;
817 break;
818 case Instruction::INVOKE_SUPER_RANGE:
819 case Instruction::INVOKE_SUPER:
820 invoke_type = kSuper;
821 break;
822 default:
823 LOG(FATAL) << "Unexpected invoke op: " << opcode;
824 return false;
825 }
826
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100827 const DexFile::MethodId& method_id = dex_file_->GetMethodId(method_idx);
828 const DexFile::ProtoId& proto_id = dex_file_->GetProtoId(method_id.proto_idx_);
829 const char* descriptor = dex_file_->StringDataByIdx(proto_id.shorty_idx_);
830 Primitive::Type return_type = Primitive::GetType(descriptor[0]);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +0100831 bool is_instance_call = invoke_type != kStatic;
Nicolas Geoffray2e335252015-06-18 11:11:27 +0100832 // Remove the return type from the 'proto'.
833 size_t number_of_arguments = strlen(descriptor) - 1;
834 if (is_instance_call) {
835 // One extra argument for 'this'.
836 ++number_of_arguments;
837 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100838
Calin Juravlec7c8fe22014-12-02 11:42:34 +0000839 MethodReference target_method(dex_file_, method_idx);
840 uintptr_t direct_code;
841 uintptr_t direct_method;
842 int table_index;
843 InvokeType optimized_invoke_type = invoke_type;
Nicolas Geoffray52839d12014-11-07 17:47:25 +0000844
Calin Juravlec7c8fe22014-12-02 11:42:34 +0000845 if (!compiler_driver_->ComputeInvokeInfo(dex_compilation_unit_, dex_pc, true, true,
846 &optimized_invoke_type, &target_method, &table_index,
847 &direct_code, &direct_method)) {
Nicolas Geoffray2e335252015-06-18 11:11:27 +0100848 VLOG(compiler) << "Did not compile "
849 << PrettyMethod(dex_compilation_unit_->GetDexMethodIndex(), *dex_file_)
Calin Juravle48c2b032014-12-09 18:11:36 +0000850 << " because a method call could not be resolved";
851 MaybeRecordStat(MethodCompilationStat::kNotCompiledUnresolvedMethod);
Calin Juravlec7c8fe22014-12-02 11:42:34 +0000852 return false;
853 }
854 DCHECK(optimized_invoke_type != kSuper);
855
Roland Levillain4c0eb422015-04-24 16:43:49 +0100856 // By default, consider that the called method implicitly requires
857 // an initialization check of its declaring method.
858 HInvokeStaticOrDirect::ClinitCheckRequirement clinit_check_requirement =
859 HInvokeStaticOrDirect::ClinitCheckRequirement::kImplicit;
860 // Potential class initialization check, in the case of a static method call.
861 HClinitCheck* clinit_check = nullptr;
Jeff Hao848f70a2014-01-15 13:49:50 -0800862 // Replace calls to String.<init> with StringFactory.
863 int32_t string_init_offset = 0;
864 bool is_string_init = compiler_driver_->IsStringInit(method_idx, dex_file_, &string_init_offset);
865 if (is_string_init) {
866 return_type = Primitive::kPrimNot;
867 is_instance_call = false;
868 number_of_arguments--;
869 invoke_type = kStatic;
870 optimized_invoke_type = kStatic;
871 }
Roland Levillain4c0eb422015-04-24 16:43:49 +0100872
Calin Juravlec7c8fe22014-12-02 11:42:34 +0000873 HInvoke* invoke = nullptr;
Roland Levillain4c0eb422015-04-24 16:43:49 +0100874
Calin Juravlec7c8fe22014-12-02 11:42:34 +0000875 if (optimized_invoke_type == kVirtual) {
876 invoke = new (arena_) HInvokeVirtual(
Andreas Gampe71fb52f2014-12-29 17:43:08 -0800877 arena_, number_of_arguments, return_type, dex_pc, method_idx, table_index);
Calin Juravlec7c8fe22014-12-02 11:42:34 +0000878 } else if (optimized_invoke_type == kInterface) {
879 invoke = new (arena_) HInvokeInterface(
880 arena_, number_of_arguments, return_type, dex_pc, method_idx, table_index);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +0100881 } else {
Calin Juravlec7c8fe22014-12-02 11:42:34 +0000882 DCHECK(optimized_invoke_type == kDirect || optimized_invoke_type == kStatic);
Vladimir Markob2c431e2015-08-19 12:45:42 +0000883 // Sharpening to kDirect only works if we compile PIC.
884 DCHECK((optimized_invoke_type == invoke_type) || (optimized_invoke_type != kDirect)
885 || compiler_driver_->GetCompilerOptions().GetCompilePic());
886 bool is_recursive =
887 (target_method.dex_method_index == outer_compilation_unit_->GetDexMethodIndex())
888 && (target_method.dex_file == outer_compilation_unit_->GetDexFile());
Roland Levillain4c0eb422015-04-24 16:43:49 +0100889
Jeff Haocad65422015-06-18 21:16:08 -0700890 if (optimized_invoke_type == kStatic && !is_string_init) {
Roland Levillain4c0eb422015-04-24 16:43:49 +0100891 ScopedObjectAccess soa(Thread::Current());
892 StackHandleScope<4> hs(soa.Self());
893 Handle<mirror::DexCache> dex_cache(hs.NewHandle(
894 dex_compilation_unit_->GetClassLinker()->FindDexCache(
895 *dex_compilation_unit_->GetDexFile())));
896 Handle<mirror::ClassLoader> class_loader(hs.NewHandle(
897 soa.Decode<mirror::ClassLoader*>(dex_compilation_unit_->GetClassLoader())));
Mathieu Chartiere401d142015-04-22 13:56:20 -0700898 ArtMethod* resolved_method = compiler_driver_->ResolveMethod(
899 soa, dex_cache, class_loader, dex_compilation_unit_, method_idx, optimized_invoke_type);
Roland Levillain4c0eb422015-04-24 16:43:49 +0100900
901 if (resolved_method == nullptr) {
902 MaybeRecordStat(MethodCompilationStat::kNotCompiledUnresolvedMethod);
903 return false;
904 }
905
906 const DexFile& outer_dex_file = *outer_compilation_unit_->GetDexFile();
907 Handle<mirror::DexCache> outer_dex_cache(hs.NewHandle(
908 outer_compilation_unit_->GetClassLinker()->FindDexCache(outer_dex_file)));
Nicolas Geoffrayafd06412015-06-20 22:44:47 +0100909 Handle<mirror::Class> outer_class(hs.NewHandle(GetOutermostCompilingClass()));
Roland Levillain4c0eb422015-04-24 16:43:49 +0100910
911 // The index at which the method's class is stored in the DexCache's type array.
912 uint32_t storage_index = DexFile::kDexNoIndex;
Nicolas Geoffrayafd06412015-06-20 22:44:47 +0100913 bool is_outer_class = (resolved_method->GetDeclaringClass() == outer_class.Get());
914 if (is_outer_class) {
915 storage_index = outer_class->GetDexTypeIndex();
Roland Levillain4c0eb422015-04-24 16:43:49 +0100916 } else if (outer_dex_cache.Get() == dex_cache.Get()) {
917 // Get `storage_index` from IsClassOfStaticMethodAvailableToReferrer.
918 compiler_driver_->IsClassOfStaticMethodAvailableToReferrer(outer_dex_cache.Get(),
Nicolas Geoffrayafd06412015-06-20 22:44:47 +0100919 GetCompilingClass(),
Roland Levillain4c0eb422015-04-24 16:43:49 +0100920 resolved_method,
921 method_idx,
922 &storage_index);
923 }
924
Nicolas Geoffrayb783b402015-06-22 11:06:43 +0100925 if (!outer_class->IsInterface()
926 && outer_class->IsSubClass(resolved_method->GetDeclaringClass())) {
Nicolas Geoffrayafd06412015-06-20 22:44:47 +0100927 // If the outer class is the declaring class or a subclass
Roland Levillain5f02c6c2015-04-24 19:14:22 +0100928 // of the declaring class, no class initialization is needed
929 // before the static method call.
Nicolas Geoffrayafd06412015-06-20 22:44:47 +0100930 // Note that in case of inlining, we do not need to add clinit checks
931 // to calls that satisfy this subclass check with any inlined methods. This
932 // will be detected by the optimization passes.
Roland Levillain4c0eb422015-04-24 16:43:49 +0100933 clinit_check_requirement = HInvokeStaticOrDirect::ClinitCheckRequirement::kNone;
934 } else if (storage_index != DexFile::kDexNoIndex) {
935 // If the method's class type index is available, check
936 // whether we should add an explicit class initialization
937 // check for its declaring class before the static method call.
938
939 // TODO: find out why this check is needed.
940 bool is_in_dex_cache = compiler_driver_->CanAssumeTypeIsPresentInDexCache(
941 *outer_compilation_unit_->GetDexFile(), storage_index);
942 bool is_initialized =
943 resolved_method->GetDeclaringClass()->IsInitialized() && is_in_dex_cache;
944
945 if (is_initialized) {
946 clinit_check_requirement = HInvokeStaticOrDirect::ClinitCheckRequirement::kNone;
947 } else {
948 clinit_check_requirement = HInvokeStaticOrDirect::ClinitCheckRequirement::kExplicit;
Nicolas Geoffrayd5111bf2015-05-22 15:37:09 +0100949 HLoadClass* load_class = new (arena_) HLoadClass(
Nicolas Geoffray76b1e172015-05-27 17:18:33 +0100950 graph_->GetCurrentMethod(),
951 storage_index,
952 *dex_compilation_unit_->GetDexFile(),
Nicolas Geoffrayafd06412015-06-20 22:44:47 +0100953 is_outer_class,
Nicolas Geoffray76b1e172015-05-27 17:18:33 +0100954 dex_pc);
Roland Levillain4c0eb422015-04-24 16:43:49 +0100955 current_block_->AddInstruction(load_class);
956 clinit_check = new (arena_) HClinitCheck(load_class, dex_pc);
957 current_block_->AddInstruction(clinit_check);
Roland Levillain4c0eb422015-04-24 16:43:49 +0100958 }
959 }
960 }
961
Guillaume "Vermeille" Sanchezae09d2d2015-05-29 10:52:55 +0100962 invoke = new (arena_) HInvokeStaticOrDirect(arena_,
963 number_of_arguments,
964 return_type,
965 dex_pc,
Vladimir Markob2c431e2015-08-19 12:45:42 +0000966 target_method.dex_method_index,
967 is_recursive,
968 string_init_offset,
Guillaume "Vermeille" Sanchezae09d2d2015-05-29 10:52:55 +0100969 invoke_type,
970 optimized_invoke_type,
971 clinit_check_requirement);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +0100972 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100973
974 size_t start_index = 0;
Calin Juravlef97f9fb2014-11-11 15:38:19 +0000975 Temporaries temps(graph_);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100976 if (is_instance_call) {
977 HInstruction* arg = LoadLocal(is_range ? register_index : args[0], Primitive::kPrimNot);
Calin Juravle225ff812014-11-13 16:46:39 +0000978 HNullCheck* null_check = new (arena_) HNullCheck(arg, dex_pc);
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +0100979 current_block_->AddInstruction(null_check);
980 temps.Add(null_check);
981 invoke->SetArgumentAt(0, null_check);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100982 start_index = 1;
983 }
984
Nicolas Geoffray2e335252015-06-18 11:11:27 +0100985 uint32_t descriptor_index = 1; // Skip the return type.
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100986 uint32_t argument_index = start_index;
Jeff Hao848f70a2014-01-15 13:49:50 -0800987 if (is_string_init) {
988 start_index = 1;
989 }
Nicolas Geoffray2e335252015-06-18 11:11:27 +0100990 for (size_t i = start_index;
991 // Make sure we don't go over the expected arguments or over the number of
992 // dex registers given. If the instruction was seen as dead by the verifier,
993 // it hasn't been properly checked.
994 (i < number_of_vreg_arguments) && (argument_index < number_of_arguments);
995 i++, argument_index++) {
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100996 Primitive::Type type = Primitive::GetType(descriptor[descriptor_index++]);
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100997 bool is_wide = (type == Primitive::kPrimLong) || (type == Primitive::kPrimDouble);
Nicolas Geoffray2e335252015-06-18 11:11:27 +0100998 if (!is_range
999 && is_wide
1000 && ((i + 1 == number_of_vreg_arguments) || (args[i] + 1 != args[i + 1]))) {
1001 // Longs and doubles should be in pairs, that is, sequential registers. The verifier should
1002 // reject any class where this is violated. However, the verifier only does these checks
1003 // on non trivially dead instructions, so we just bailout the compilation.
1004 VLOG(compiler) << "Did not compile "
1005 << PrettyMethod(dex_compilation_unit_->GetDexMethodIndex(), *dex_file_)
1006 << " because of non-sequential dex register pair in wide argument";
1007 MaybeRecordStat(MethodCompilationStat::kNotCompiledMalformedOpcode);
1008 return false;
1009 }
Nicolas Geoffrayabed4d02014-07-14 15:24:11 +01001010 HInstruction* arg = LoadLocal(is_range ? register_index + i : args[i], type);
1011 invoke->SetArgumentAt(argument_index, arg);
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001012 if (is_wide) {
Nicolas Geoffrayabed4d02014-07-14 15:24:11 +01001013 i++;
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001014 }
1015 }
Nicolas Geoffray2e335252015-06-18 11:11:27 +01001016
1017 if (argument_index != number_of_arguments) {
1018 VLOG(compiler) << "Did not compile "
1019 << PrettyMethod(dex_compilation_unit_->GetDexMethodIndex(), *dex_file_)
1020 << " because of wrong number of arguments in invoke instruction";
1021 MaybeRecordStat(MethodCompilationStat::kNotCompiledMalformedOpcode);
1022 return false;
1023 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001024
Nicolas Geoffray38207af2015-06-01 15:46:22 +01001025 if (invoke->IsInvokeStaticOrDirect()) {
1026 invoke->SetArgumentAt(argument_index, graph_->GetCurrentMethod());
1027 argument_index++;
1028 }
1029
Roland Levillain4c0eb422015-04-24 16:43:49 +01001030 if (clinit_check_requirement == HInvokeStaticOrDirect::ClinitCheckRequirement::kExplicit) {
1031 // Add the class initialization check as last input of `invoke`.
1032 DCHECK(clinit_check != nullptr);
Nicolas Geoffray2e7cd752015-07-10 11:38:52 +01001033 DCHECK(!is_string_init);
Roland Levillain3e3d7332015-04-28 11:00:54 +01001034 invoke->SetArgumentAt(argument_index, clinit_check);
Nicolas Geoffray2e7cd752015-07-10 11:38:52 +01001035 argument_index++;
Roland Levillain4c0eb422015-04-24 16:43:49 +01001036 }
1037
Jeff Hao848f70a2014-01-15 13:49:50 -08001038 // Add move-result for StringFactory method.
1039 if (is_string_init) {
1040 uint32_t orig_this_reg = is_range ? register_index : args[0];
Nicolas Geoffray2e7cd752015-07-10 11:38:52 +01001041 HInstruction* fake_string = LoadLocal(orig_this_reg, Primitive::kPrimNot);
1042 invoke->SetArgumentAt(argument_index, fake_string);
1043 current_block_->AddInstruction(invoke);
1044 PotentiallySimplifyFakeString(orig_this_reg, dex_pc, invoke);
1045 } else {
1046 current_block_->AddInstruction(invoke);
Jeff Hao848f70a2014-01-15 13:49:50 -08001047 }
Nicolas Geoffray2e7cd752015-07-10 11:38:52 +01001048 latest_result_ = invoke;
1049
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001050 return true;
1051}
1052
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01001053bool HGraphBuilder::BuildInstanceFieldAccess(const Instruction& instruction,
Calin Juravle225ff812014-11-13 16:46:39 +00001054 uint32_t dex_pc,
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01001055 bool is_put) {
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001056 uint32_t source_or_dest_reg = instruction.VRegA_22c();
1057 uint32_t obj_reg = instruction.VRegB_22c();
Nicolas Geoffray9523a3e2015-07-17 11:51:28 +00001058 uint16_t field_index;
1059 if (instruction.IsQuickened()) {
1060 if (!CanDecodeQuickenedInfo()) {
1061 return false;
1062 }
1063 field_index = LookupQuickenedInfo(dex_pc);
1064 } else {
1065 field_index = instruction.VRegC_22c();
1066 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001067
1068 ScopedObjectAccess soa(Thread::Current());
Mathieu Chartierc7853442015-03-27 14:35:38 -07001069 ArtField* resolved_field =
1070 compiler_driver_->ComputeInstanceFieldInfo(field_index, dex_compilation_unit_, is_put, soa);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001071
Mathieu Chartierc7853442015-03-27 14:35:38 -07001072 if (resolved_field == nullptr) {
Calin Juravle48c2b032014-12-09 18:11:36 +00001073 MaybeRecordStat(MethodCompilationStat::kNotCompiledUnresolvedField);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001074 return false;
1075 }
Calin Juravle52c48962014-12-16 17:02:57 +00001076
Nicolas Geoffrayabed4d02014-07-14 15:24:11 +01001077 Primitive::Type field_type = resolved_field->GetTypeAsPrimitiveType();
Nicolas Geoffrayabed4d02014-07-14 15:24:11 +01001078
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001079 HInstruction* object = LoadLocal(obj_reg, Primitive::kPrimNot);
Calin Juravle225ff812014-11-13 16:46:39 +00001080 current_block_->AddInstruction(new (arena_) HNullCheck(object, dex_pc));
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001081 if (is_put) {
Calin Juravlef97f9fb2014-11-11 15:38:19 +00001082 Temporaries temps(graph_);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001083 HInstruction* null_check = current_block_->GetLastInstruction();
1084 // We need one temporary for the null check.
1085 temps.Add(null_check);
Nicolas Geoffrayabed4d02014-07-14 15:24:11 +01001086 HInstruction* value = LoadLocal(source_or_dest_reg, field_type);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001087 current_block_->AddInstruction(new (arena_) HInstanceFieldSet(
1088 null_check,
1089 value,
Nicolas Geoffray39468442014-09-02 15:17:15 +01001090 field_type,
Calin Juravle52c48962014-12-16 17:02:57 +00001091 resolved_field->GetOffset(),
Guillaume "Vermeille" Sanchez104fd8a2015-05-20 17:52:13 +01001092 resolved_field->IsVolatile(),
1093 field_index,
1094 *dex_file_));
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001095 } else {
1096 current_block_->AddInstruction(new (arena_) HInstanceFieldGet(
1097 current_block_->GetLastInstruction(),
Nicolas Geoffrayabed4d02014-07-14 15:24:11 +01001098 field_type,
Calin Juravle52c48962014-12-16 17:02:57 +00001099 resolved_field->GetOffset(),
Guillaume "Vermeille" Sanchez104fd8a2015-05-20 17:52:13 +01001100 resolved_field->IsVolatile(),
1101 field_index,
1102 *dex_file_));
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001103
1104 UpdateLocal(source_or_dest_reg, current_block_->GetLastInstruction());
1105 }
1106 return true;
1107}
1108
Nicolas Geoffray30451742015-06-19 13:32:41 +01001109static mirror::Class* GetClassFrom(CompilerDriver* driver,
1110 const DexCompilationUnit& compilation_unit) {
Nicolas Geoffray9437b782015-03-25 10:08:51 +00001111 ScopedObjectAccess soa(Thread::Current());
1112 StackHandleScope<2> hs(soa.Self());
Nicolas Geoffray30451742015-06-19 13:32:41 +01001113 const DexFile& dex_file = *compilation_unit.GetDexFile();
Nicolas Geoffray9437b782015-03-25 10:08:51 +00001114 Handle<mirror::ClassLoader> class_loader(hs.NewHandle(
Nicolas Geoffray30451742015-06-19 13:32:41 +01001115 soa.Decode<mirror::ClassLoader*>(compilation_unit.GetClassLoader())));
1116 Handle<mirror::DexCache> dex_cache(hs.NewHandle(
1117 compilation_unit.GetClassLinker()->FindDexCache(dex_file)));
Nicolas Geoffray9437b782015-03-25 10:08:51 +00001118
Nicolas Geoffray30451742015-06-19 13:32:41 +01001119 return driver->ResolveCompilingMethodsClass(soa, dex_cache, class_loader, &compilation_unit);
1120}
1121
1122mirror::Class* HGraphBuilder::GetOutermostCompilingClass() const {
1123 return GetClassFrom(compiler_driver_, *outer_compilation_unit_);
1124}
1125
1126mirror::Class* HGraphBuilder::GetCompilingClass() const {
1127 return GetClassFrom(compiler_driver_, *dex_compilation_unit_);
Nicolas Geoffray9437b782015-03-25 10:08:51 +00001128}
1129
1130bool HGraphBuilder::IsOutermostCompilingClass(uint16_t type_index) const {
1131 ScopedObjectAccess soa(Thread::Current());
1132 StackHandleScope<4> hs(soa.Self());
1133 Handle<mirror::DexCache> dex_cache(hs.NewHandle(
1134 dex_compilation_unit_->GetClassLinker()->FindDexCache(*dex_compilation_unit_->GetDexFile())));
1135 Handle<mirror::ClassLoader> class_loader(hs.NewHandle(
1136 soa.Decode<mirror::ClassLoader*>(dex_compilation_unit_->GetClassLoader())));
1137 Handle<mirror::Class> cls(hs.NewHandle(compiler_driver_->ResolveClass(
1138 soa, dex_cache, class_loader, type_index, dex_compilation_unit_)));
Nicolas Geoffrayafd06412015-06-20 22:44:47 +01001139 Handle<mirror::Class> outer_class(hs.NewHandle(GetOutermostCompilingClass()));
Nicolas Geoffray9437b782015-03-25 10:08:51 +00001140
Nicolas Geoffrayafd06412015-06-20 22:44:47 +01001141 return outer_class.Get() == cls.Get();
Nicolas Geoffray9437b782015-03-25 10:08:51 +00001142}
1143
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01001144bool HGraphBuilder::BuildStaticFieldAccess(const Instruction& instruction,
Calin Juravle225ff812014-11-13 16:46:39 +00001145 uint32_t dex_pc,
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01001146 bool is_put) {
1147 uint32_t source_or_dest_reg = instruction.VRegA_21c();
1148 uint16_t field_index = instruction.VRegB_21c();
1149
Nicolas Geoffraye53798a2014-12-01 10:31:54 +00001150 ScopedObjectAccess soa(Thread::Current());
Mathieu Chartierc7853442015-03-27 14:35:38 -07001151 StackHandleScope<4> hs(soa.Self());
Nicolas Geoffraye53798a2014-12-01 10:31:54 +00001152 Handle<mirror::DexCache> dex_cache(hs.NewHandle(
1153 dex_compilation_unit_->GetClassLinker()->FindDexCache(*dex_compilation_unit_->GetDexFile())));
1154 Handle<mirror::ClassLoader> class_loader(hs.NewHandle(
1155 soa.Decode<mirror::ClassLoader*>(dex_compilation_unit_->GetClassLoader())));
Mathieu Chartierc7853442015-03-27 14:35:38 -07001156 ArtField* resolved_field = compiler_driver_->ResolveField(
1157 soa, dex_cache, class_loader, dex_compilation_unit_, field_index, true);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01001158
Mathieu Chartierc7853442015-03-27 14:35:38 -07001159 if (resolved_field == nullptr) {
Calin Juravle48c2b032014-12-09 18:11:36 +00001160 MaybeRecordStat(MethodCompilationStat::kNotCompiledUnresolvedField);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01001161 return false;
1162 }
1163
Nicolas Geoffray9437b782015-03-25 10:08:51 +00001164 const DexFile& outer_dex_file = *outer_compilation_unit_->GetDexFile();
1165 Handle<mirror::DexCache> outer_dex_cache(hs.NewHandle(
1166 outer_compilation_unit_->GetClassLinker()->FindDexCache(outer_dex_file)));
Nicolas Geoffray30451742015-06-19 13:32:41 +01001167 Handle<mirror::Class> outer_class(hs.NewHandle(GetOutermostCompilingClass()));
Nicolas Geoffraye53798a2014-12-01 10:31:54 +00001168
1169 // The index at which the field's class is stored in the DexCache's type array.
1170 uint32_t storage_index;
Nicolas Geoffray30451742015-06-19 13:32:41 +01001171 bool is_outer_class = (outer_class.Get() == resolved_field->GetDeclaringClass());
1172 if (is_outer_class) {
1173 storage_index = outer_class->GetDexTypeIndex();
Nicolas Geoffray9437b782015-03-25 10:08:51 +00001174 } else if (outer_dex_cache.Get() != dex_cache.Get()) {
Roland Levillain4c0eb422015-04-24 16:43:49 +01001175 // The compiler driver cannot currently understand multiple dex caches involved. Just bailout.
Nicolas Geoffraye53798a2014-12-01 10:31:54 +00001176 return false;
Nicolas Geoffray9437b782015-03-25 10:08:51 +00001177 } else {
1178 std::pair<bool, bool> pair = compiler_driver_->IsFastStaticField(
1179 outer_dex_cache.Get(),
Nicolas Geoffray30451742015-06-19 13:32:41 +01001180 GetCompilingClass(),
Mathieu Chartierc7853442015-03-27 14:35:38 -07001181 resolved_field,
Nicolas Geoffray9437b782015-03-25 10:08:51 +00001182 field_index,
1183 &storage_index);
1184 bool can_easily_access = is_put ? pair.second : pair.first;
1185 if (!can_easily_access) {
1186 return false;
1187 }
Nicolas Geoffraye53798a2014-12-01 10:31:54 +00001188 }
1189
1190 // TODO: find out why this check is needed.
1191 bool is_in_dex_cache = compiler_driver_->CanAssumeTypeIsPresentInDexCache(
Nicolas Geoffray6a816cf2015-03-24 16:17:56 +00001192 *outer_compilation_unit_->GetDexFile(), storage_index);
Nicolas Geoffraye53798a2014-12-01 10:31:54 +00001193 bool is_initialized = resolved_field->GetDeclaringClass()->IsInitialized() && is_in_dex_cache;
Nicolas Geoffraye53798a2014-12-01 10:31:54 +00001194
Nicolas Geoffray76b1e172015-05-27 17:18:33 +01001195 HLoadClass* constant = new (arena_) HLoadClass(graph_->GetCurrentMethod(),
1196 storage_index,
1197 *dex_compilation_unit_->GetDexFile(),
Nicolas Geoffray30451742015-06-19 13:32:41 +01001198 is_outer_class,
Nicolas Geoffray76b1e172015-05-27 17:18:33 +01001199 dex_pc);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01001200 current_block_->AddInstruction(constant);
1201
1202 HInstruction* cls = constant;
Nicolas Geoffray30451742015-06-19 13:32:41 +01001203 if (!is_initialized && !is_outer_class) {
Calin Juravle225ff812014-11-13 16:46:39 +00001204 cls = new (arena_) HClinitCheck(constant, dex_pc);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01001205 current_block_->AddInstruction(cls);
1206 }
1207
Nicolas Geoffraye53798a2014-12-01 10:31:54 +00001208 Primitive::Type field_type = resolved_field->GetTypeAsPrimitiveType();
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01001209 if (is_put) {
1210 // We need to keep the class alive before loading the value.
Calin Juravlef97f9fb2014-11-11 15:38:19 +00001211 Temporaries temps(graph_);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01001212 temps.Add(cls);
1213 HInstruction* value = LoadLocal(source_or_dest_reg, field_type);
1214 DCHECK_EQ(value->GetType(), field_type);
Guillaume "Vermeille" Sanchez104fd8a2015-05-20 17:52:13 +01001215 current_block_->AddInstruction(new (arena_) HStaticFieldSet(cls,
1216 value,
1217 field_type,
1218 resolved_field->GetOffset(),
1219 resolved_field->IsVolatile(),
1220 field_index,
1221 *dex_file_));
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01001222 } else {
Guillaume "Vermeille" Sanchez104fd8a2015-05-20 17:52:13 +01001223 current_block_->AddInstruction(new (arena_) HStaticFieldGet(cls,
1224 field_type,
1225 resolved_field->GetOffset(),
1226 resolved_field->IsVolatile(),
1227 field_index,
1228 *dex_file_));
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01001229 UpdateLocal(source_or_dest_reg, current_block_->GetLastInstruction());
1230 }
1231 return true;
1232}
1233
Calin Juravlebacfec32014-11-14 15:54:36 +00001234void HGraphBuilder::BuildCheckedDivRem(uint16_t out_vreg,
1235 uint16_t first_vreg,
1236 int64_t second_vreg_or_constant,
1237 uint32_t dex_pc,
1238 Primitive::Type type,
1239 bool second_is_constant,
1240 bool isDiv) {
Calin Juravled6fb6cf2014-11-11 19:07:44 +00001241 DCHECK(type == Primitive::kPrimInt || type == Primitive::kPrimLong);
Calin Juravled0d48522014-11-04 16:40:20 +00001242
Calin Juravled6fb6cf2014-11-11 19:07:44 +00001243 HInstruction* first = LoadLocal(first_vreg, type);
1244 HInstruction* second = nullptr;
1245 if (second_is_constant) {
1246 if (type == Primitive::kPrimInt) {
David Brazdil8d5b8b22015-03-24 10:51:52 +00001247 second = graph_->GetIntConstant(second_vreg_or_constant);
Calin Juravled6fb6cf2014-11-11 19:07:44 +00001248 } else {
David Brazdil8d5b8b22015-03-24 10:51:52 +00001249 second = graph_->GetLongConstant(second_vreg_or_constant);
Calin Juravled6fb6cf2014-11-11 19:07:44 +00001250 }
1251 } else {
1252 second = LoadLocal(second_vreg_or_constant, type);
1253 }
1254
1255 if (!second_is_constant
1256 || (type == Primitive::kPrimInt && second->AsIntConstant()->GetValue() == 0)
1257 || (type == Primitive::kPrimLong && second->AsLongConstant()->GetValue() == 0)) {
1258 second = new (arena_) HDivZeroCheck(second, dex_pc);
Calin Juravlef97f9fb2014-11-11 15:38:19 +00001259 Temporaries temps(graph_);
Calin Juravled0d48522014-11-04 16:40:20 +00001260 current_block_->AddInstruction(second);
1261 temps.Add(current_block_->GetLastInstruction());
1262 }
1263
Calin Juravlebacfec32014-11-14 15:54:36 +00001264 if (isDiv) {
1265 current_block_->AddInstruction(new (arena_) HDiv(type, first, second, dex_pc));
1266 } else {
1267 current_block_->AddInstruction(new (arena_) HRem(type, first, second, dex_pc));
1268 }
Calin Juravled6fb6cf2014-11-11 19:07:44 +00001269 UpdateLocal(out_vreg, current_block_->GetLastInstruction());
Calin Juravled0d48522014-11-04 16:40:20 +00001270}
1271
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001272void HGraphBuilder::BuildArrayAccess(const Instruction& instruction,
Calin Juravle225ff812014-11-13 16:46:39 +00001273 uint32_t dex_pc,
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001274 bool is_put,
1275 Primitive::Type anticipated_type) {
1276 uint8_t source_or_dest_reg = instruction.VRegA_23x();
1277 uint8_t array_reg = instruction.VRegB_23x();
1278 uint8_t index_reg = instruction.VRegC_23x();
1279
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001280 // We need one temporary for the null check, one for the index, and one for the length.
Calin Juravlef97f9fb2014-11-11 15:38:19 +00001281 Temporaries temps(graph_);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001282
1283 HInstruction* object = LoadLocal(array_reg, Primitive::kPrimNot);
Calin Juravle225ff812014-11-13 16:46:39 +00001284 object = new (arena_) HNullCheck(object, dex_pc);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001285 current_block_->AddInstruction(object);
1286 temps.Add(object);
1287
1288 HInstruction* length = new (arena_) HArrayLength(object);
1289 current_block_->AddInstruction(length);
1290 temps.Add(length);
1291 HInstruction* index = LoadLocal(index_reg, Primitive::kPrimInt);
Calin Juravle225ff812014-11-13 16:46:39 +00001292 index = new (arena_) HBoundsCheck(index, length, dex_pc);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001293 current_block_->AddInstruction(index);
1294 temps.Add(index);
1295 if (is_put) {
1296 HInstruction* value = LoadLocal(source_or_dest_reg, anticipated_type);
1297 // TODO: Insert a type check node if the type is Object.
Nicolas Geoffray39468442014-09-02 15:17:15 +01001298 current_block_->AddInstruction(new (arena_) HArraySet(
Calin Juravle225ff812014-11-13 16:46:39 +00001299 object, index, value, anticipated_type, dex_pc));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001300 } else {
1301 current_block_->AddInstruction(new (arena_) HArrayGet(object, index, anticipated_type));
1302 UpdateLocal(source_or_dest_reg, current_block_->GetLastInstruction());
1303 }
Mark Mendell1152c922015-04-24 17:06:35 -04001304 graph_->SetHasBoundsChecks(true);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001305}
1306
Calin Juravle225ff812014-11-13 16:46:39 +00001307void HGraphBuilder::BuildFilledNewArray(uint32_t dex_pc,
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01001308 uint32_t type_index,
1309 uint32_t number_of_vreg_arguments,
1310 bool is_range,
1311 uint32_t* args,
1312 uint32_t register_index) {
David Brazdil8d5b8b22015-03-24 10:51:52 +00001313 HInstruction* length = graph_->GetIntConstant(number_of_vreg_arguments);
Nicolas Geoffraycb1b00a2015-01-28 14:50:01 +00001314 QuickEntrypointEnum entrypoint = NeedsAccessCheck(type_index)
1315 ? kQuickAllocArrayWithAccessCheck
1316 : kQuickAllocArray;
Guillaume "Vermeille" Sanchez81d804a2015-05-20 12:42:25 +01001317 HInstruction* object = new (arena_) HNewArray(length,
Nicolas Geoffray69aa6012015-06-09 10:34:25 +01001318 graph_->GetCurrentMethod(),
Guillaume "Vermeille" Sanchez81d804a2015-05-20 12:42:25 +01001319 dex_pc,
1320 type_index,
1321 *dex_compilation_unit_->GetDexFile(),
1322 entrypoint);
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01001323 current_block_->AddInstruction(object);
1324
1325 const char* descriptor = dex_file_->StringByTypeIdx(type_index);
1326 DCHECK_EQ(descriptor[0], '[') << descriptor;
1327 char primitive = descriptor[1];
1328 DCHECK(primitive == 'I'
1329 || primitive == 'L'
1330 || primitive == '[') << descriptor;
1331 bool is_reference_array = (primitive == 'L') || (primitive == '[');
1332 Primitive::Type type = is_reference_array ? Primitive::kPrimNot : Primitive::kPrimInt;
1333
Calin Juravlef97f9fb2014-11-11 15:38:19 +00001334 Temporaries temps(graph_);
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01001335 temps.Add(object);
1336 for (size_t i = 0; i < number_of_vreg_arguments; ++i) {
1337 HInstruction* value = LoadLocal(is_range ? register_index + i : args[i], type);
David Brazdil8d5b8b22015-03-24 10:51:52 +00001338 HInstruction* index = graph_->GetIntConstant(i);
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01001339 current_block_->AddInstruction(
Calin Juravle225ff812014-11-13 16:46:39 +00001340 new (arena_) HArraySet(object, index, value, type, dex_pc));
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01001341 }
1342 latest_result_ = object;
1343}
1344
1345template <typename T>
1346void HGraphBuilder::BuildFillArrayData(HInstruction* object,
1347 const T* data,
1348 uint32_t element_count,
1349 Primitive::Type anticipated_type,
Calin Juravle225ff812014-11-13 16:46:39 +00001350 uint32_t dex_pc) {
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01001351 for (uint32_t i = 0; i < element_count; ++i) {
David Brazdil8d5b8b22015-03-24 10:51:52 +00001352 HInstruction* index = graph_->GetIntConstant(i);
1353 HInstruction* value = graph_->GetIntConstant(data[i]);
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01001354 current_block_->AddInstruction(new (arena_) HArraySet(
Calin Juravle225ff812014-11-13 16:46:39 +00001355 object, index, value, anticipated_type, dex_pc));
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01001356 }
1357}
1358
Calin Juravle225ff812014-11-13 16:46:39 +00001359void HGraphBuilder::BuildFillArrayData(const Instruction& instruction, uint32_t dex_pc) {
Calin Juravlef97f9fb2014-11-11 15:38:19 +00001360 Temporaries temps(graph_);
Calin Juravled0d48522014-11-04 16:40:20 +00001361 HInstruction* array = LoadLocal(instruction.VRegA_31t(), Primitive::kPrimNot);
Calin Juravle225ff812014-11-13 16:46:39 +00001362 HNullCheck* null_check = new (arena_) HNullCheck(array, dex_pc);
Calin Juravled0d48522014-11-04 16:40:20 +00001363 current_block_->AddInstruction(null_check);
1364 temps.Add(null_check);
1365
1366 HInstruction* length = new (arena_) HArrayLength(null_check);
1367 current_block_->AddInstruction(length);
1368
Calin Juravle225ff812014-11-13 16:46:39 +00001369 int32_t payload_offset = instruction.VRegB_31t() + dex_pc;
Calin Juravled0d48522014-11-04 16:40:20 +00001370 const Instruction::ArrayDataPayload* payload =
1371 reinterpret_cast<const Instruction::ArrayDataPayload*>(code_start_ + payload_offset);
1372 const uint8_t* data = payload->data;
1373 uint32_t element_count = payload->element_count;
1374
1375 // Implementation of this DEX instruction seems to be that the bounds check is
1376 // done before doing any stores.
David Brazdil8d5b8b22015-03-24 10:51:52 +00001377 HInstruction* last_index = graph_->GetIntConstant(payload->element_count - 1);
Calin Juravle225ff812014-11-13 16:46:39 +00001378 current_block_->AddInstruction(new (arena_) HBoundsCheck(last_index, length, dex_pc));
Calin Juravled0d48522014-11-04 16:40:20 +00001379
1380 switch (payload->element_width) {
1381 case 1:
1382 BuildFillArrayData(null_check,
1383 reinterpret_cast<const int8_t*>(data),
1384 element_count,
1385 Primitive::kPrimByte,
Calin Juravle225ff812014-11-13 16:46:39 +00001386 dex_pc);
Calin Juravled0d48522014-11-04 16:40:20 +00001387 break;
1388 case 2:
1389 BuildFillArrayData(null_check,
1390 reinterpret_cast<const int16_t*>(data),
1391 element_count,
1392 Primitive::kPrimShort,
Calin Juravle225ff812014-11-13 16:46:39 +00001393 dex_pc);
Calin Juravled0d48522014-11-04 16:40:20 +00001394 break;
1395 case 4:
1396 BuildFillArrayData(null_check,
1397 reinterpret_cast<const int32_t*>(data),
1398 element_count,
1399 Primitive::kPrimInt,
Calin Juravle225ff812014-11-13 16:46:39 +00001400 dex_pc);
Calin Juravled0d48522014-11-04 16:40:20 +00001401 break;
1402 case 8:
1403 BuildFillWideArrayData(null_check,
1404 reinterpret_cast<const int64_t*>(data),
1405 element_count,
Calin Juravle225ff812014-11-13 16:46:39 +00001406 dex_pc);
Calin Juravled0d48522014-11-04 16:40:20 +00001407 break;
1408 default:
1409 LOG(FATAL) << "Unknown element width for " << payload->element_width;
1410 }
Mark Mendell1152c922015-04-24 17:06:35 -04001411 graph_->SetHasBoundsChecks(true);
Calin Juravled0d48522014-11-04 16:40:20 +00001412}
1413
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01001414void HGraphBuilder::BuildFillWideArrayData(HInstruction* object,
Nicolas Geoffray8d6ae522014-10-23 18:32:13 +01001415 const int64_t* data,
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01001416 uint32_t element_count,
Calin Juravle225ff812014-11-13 16:46:39 +00001417 uint32_t dex_pc) {
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01001418 for (uint32_t i = 0; i < element_count; ++i) {
David Brazdil8d5b8b22015-03-24 10:51:52 +00001419 HInstruction* index = graph_->GetIntConstant(i);
1420 HInstruction* value = graph_->GetLongConstant(data[i]);
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01001421 current_block_->AddInstruction(new (arena_) HArraySet(
Calin Juravle225ff812014-11-13 16:46:39 +00001422 object, index, value, Primitive::kPrimLong, dex_pc));
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01001423 }
1424}
1425
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00001426bool HGraphBuilder::BuildTypeCheck(const Instruction& instruction,
1427 uint8_t destination,
1428 uint8_t reference,
1429 uint16_t type_index,
Calin Juravle225ff812014-11-13 16:46:39 +00001430 uint32_t dex_pc) {
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00001431 bool type_known_final;
1432 bool type_known_abstract;
Nicolas Geoffraye53798a2014-12-01 10:31:54 +00001433 // `CanAccessTypeWithoutChecks` will tell whether the method being
1434 // built is trying to access its own class, so that the generated
1435 // code can optimize for this case. However, the optimization does not
Nicolas Geoffray9437b782015-03-25 10:08:51 +00001436 // work for inlining, so we use `IsOutermostCompilingClass` instead.
Nicolas Geoffraye53798a2014-12-01 10:31:54 +00001437 bool dont_use_is_referrers_class;
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00001438 bool can_access = compiler_driver_->CanAccessTypeWithoutChecks(
1439 dex_compilation_unit_->GetDexMethodIndex(), *dex_file_, type_index,
Nicolas Geoffraye53798a2014-12-01 10:31:54 +00001440 &type_known_final, &type_known_abstract, &dont_use_is_referrers_class);
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00001441 if (!can_access) {
Calin Juravle48c2b032014-12-09 18:11:36 +00001442 MaybeRecordStat(MethodCompilationStat::kNotCompiledCantAccesType);
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00001443 return false;
1444 }
1445 HInstruction* object = LoadLocal(reference, Primitive::kPrimNot);
Nicolas Geoffray9437b782015-03-25 10:08:51 +00001446 HLoadClass* cls = new (arena_) HLoadClass(
Nicolas Geoffray76b1e172015-05-27 17:18:33 +01001447 graph_->GetCurrentMethod(),
Nicolas Geoffrayd5111bf2015-05-22 15:37:09 +01001448 type_index,
1449 *dex_compilation_unit_->GetDexFile(),
1450 IsOutermostCompilingClass(type_index),
1451 dex_pc);
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00001452 current_block_->AddInstruction(cls);
1453 // The class needs a temporary before being used by the type check.
Calin Juravlef97f9fb2014-11-11 15:38:19 +00001454 Temporaries temps(graph_);
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00001455 temps.Add(cls);
1456 if (instruction.Opcode() == Instruction::INSTANCE_OF) {
1457 current_block_->AddInstruction(
Calin Juravle225ff812014-11-13 16:46:39 +00001458 new (arena_) HInstanceOf(object, cls, type_known_final, dex_pc));
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00001459 UpdateLocal(destination, current_block_->GetLastInstruction());
1460 } else {
1461 DCHECK_EQ(instruction.Opcode(), Instruction::CHECK_CAST);
1462 current_block_->AddInstruction(
Calin Juravle225ff812014-11-13 16:46:39 +00001463 new (arena_) HCheckCast(object, cls, type_known_final, dex_pc));
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00001464 }
1465 return true;
1466}
1467
Nicolas Geoffraycb1b00a2015-01-28 14:50:01 +00001468bool HGraphBuilder::NeedsAccessCheck(uint32_t type_index) const {
1469 return !compiler_driver_->CanAccessInstantiableTypeWithoutChecks(
1470 dex_compilation_unit_->GetDexMethodIndex(), *dex_file_, type_index);
1471}
1472
Calin Juravle48c2b032014-12-09 18:11:36 +00001473void HGraphBuilder::BuildPackedSwitch(const Instruction& instruction, uint32_t dex_pc) {
David Brazdil2ef645b2015-06-17 18:20:52 +01001474 // Verifier guarantees that the payload for PackedSwitch contains:
1475 // (a) number of entries (may be zero)
1476 // (b) first and lowest switch case value (entry 0, always present)
1477 // (c) list of target pcs (entries 1 <= i <= N)
Andreas Gamped881df52014-11-24 23:28:39 -08001478 SwitchTable table(instruction, dex_pc, false);
1479
1480 // Value to test against.
1481 HInstruction* value = LoadLocal(instruction.VRegA(), Primitive::kPrimInt);
1482
David Brazdil2ef645b2015-06-17 18:20:52 +01001483 // Retrieve number of entries.
Andreas Gampee4d4d322014-12-04 09:09:57 -08001484 uint16_t num_entries = table.GetNumEntries();
David Brazdil2ef645b2015-06-17 18:20:52 +01001485 if (num_entries == 0) {
1486 return;
1487 }
Andreas Gampee4d4d322014-12-04 09:09:57 -08001488
Andreas Gamped881df52014-11-24 23:28:39 -08001489 // Chained cmp-and-branch, starting from starting_key.
1490 int32_t starting_key = table.GetEntryAt(0);
1491
Andreas Gamped881df52014-11-24 23:28:39 -08001492 for (size_t i = 1; i <= num_entries; i++) {
Andreas Gampee4d4d322014-12-04 09:09:57 -08001493 BuildSwitchCaseHelper(instruction, i, i == num_entries, table, value, starting_key + i - 1,
1494 table.GetEntryAt(i), dex_pc);
Andreas Gamped881df52014-11-24 23:28:39 -08001495 }
Andreas Gamped881df52014-11-24 23:28:39 -08001496}
1497
Calin Juravle48c2b032014-12-09 18:11:36 +00001498void HGraphBuilder::BuildSparseSwitch(const Instruction& instruction, uint32_t dex_pc) {
David Brazdil2ef645b2015-06-17 18:20:52 +01001499 // Verifier guarantees that the payload for SparseSwitch contains:
1500 // (a) number of entries (may be zero)
1501 // (b) sorted key values (entries 0 <= i < N)
1502 // (c) target pcs corresponding to the switch values (entries N <= i < 2*N)
Andreas Gampee4d4d322014-12-04 09:09:57 -08001503 SwitchTable table(instruction, dex_pc, true);
1504
1505 // Value to test against.
1506 HInstruction* value = LoadLocal(instruction.VRegA(), Primitive::kPrimInt);
1507
1508 uint16_t num_entries = table.GetNumEntries();
Andreas Gampee4d4d322014-12-04 09:09:57 -08001509
1510 for (size_t i = 0; i < num_entries; i++) {
1511 BuildSwitchCaseHelper(instruction, i, i == static_cast<size_t>(num_entries) - 1, table, value,
1512 table.GetEntryAt(i), table.GetEntryAt(i + num_entries), dex_pc);
1513 }
Andreas Gampee4d4d322014-12-04 09:09:57 -08001514}
1515
1516void HGraphBuilder::BuildSwitchCaseHelper(const Instruction& instruction, size_t index,
1517 bool is_last_case, const SwitchTable& table,
1518 HInstruction* value, int32_t case_value_int,
1519 int32_t target_offset, uint32_t dex_pc) {
David Brazdil852eaff2015-02-02 15:23:05 +00001520 HBasicBlock* case_target = FindBlockStartingAt(dex_pc + target_offset);
1521 DCHECK(case_target != nullptr);
1522 PotentiallyAddSuspendCheck(case_target, dex_pc);
Andreas Gampee4d4d322014-12-04 09:09:57 -08001523
1524 // The current case's value.
David Brazdil8d5b8b22015-03-24 10:51:52 +00001525 HInstruction* this_case_value = graph_->GetIntConstant(case_value_int);
Andreas Gampee4d4d322014-12-04 09:09:57 -08001526
1527 // Compare value and this_case_value.
1528 HEqual* comparison = new (arena_) HEqual(value, this_case_value);
1529 current_block_->AddInstruction(comparison);
1530 HInstruction* ifinst = new (arena_) HIf(comparison);
1531 current_block_->AddInstruction(ifinst);
1532
1533 // Case hit: use the target offset to determine where to go.
Andreas Gampee4d4d322014-12-04 09:09:57 -08001534 current_block_->AddSuccessor(case_target);
1535
1536 // Case miss: go to the next case (or default fall-through).
1537 // When there is a next case, we use the block stored with the table offset representing this
1538 // case (that is where we registered them in ComputeBranchTargets).
1539 // When there is no next case, we use the following instruction.
1540 // TODO: Find a good way to peel the last iteration to avoid conditional, but still have re-use.
1541 if (!is_last_case) {
1542 HBasicBlock* next_case_target = FindBlockStartingAt(table.GetDexPcForIndex(index));
1543 DCHECK(next_case_target != nullptr);
1544 current_block_->AddSuccessor(next_case_target);
1545
1546 // Need to manually add the block, as there is no dex-pc transition for the cases.
1547 graph_->AddBlock(next_case_target);
1548
1549 current_block_ = next_case_target;
1550 } else {
1551 HBasicBlock* default_target = FindBlockStartingAt(dex_pc + instruction.SizeInCodeUnits());
1552 DCHECK(default_target != nullptr);
1553 current_block_->AddSuccessor(default_target);
1554 current_block_ = nullptr;
1555 }
1556}
1557
David Brazdil852eaff2015-02-02 15:23:05 +00001558void HGraphBuilder::PotentiallyAddSuspendCheck(HBasicBlock* target, uint32_t dex_pc) {
1559 int32_t target_offset = target->GetDexPc() - dex_pc;
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00001560 if (target_offset <= 0) {
David Brazdil852eaff2015-02-02 15:23:05 +00001561 // DX generates back edges to the first encountered return. We can save
1562 // time of later passes by not adding redundant suspend checks.
David Brazdil2fd6aa52015-02-02 18:58:27 +00001563 HInstruction* last_in_target = target->GetLastInstruction();
1564 if (last_in_target != nullptr &&
1565 (last_in_target->IsReturn() || last_in_target->IsReturnVoid())) {
1566 return;
David Brazdil852eaff2015-02-02 15:23:05 +00001567 }
1568
1569 // Add a suspend check to backward branches which may potentially loop. We
1570 // can remove them after we recognize loops in the graph.
Calin Juravle225ff812014-11-13 16:46:39 +00001571 current_block_->AddInstruction(new (arena_) HSuspendCheck(dex_pc));
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00001572 }
1573}
1574
Nicolas Geoffray9523a3e2015-07-17 11:51:28 +00001575bool HGraphBuilder::CanDecodeQuickenedInfo() const {
1576 return interpreter_metadata_ != nullptr;
1577}
1578
1579uint16_t HGraphBuilder::LookupQuickenedInfo(uint32_t dex_pc) {
1580 DCHECK(interpreter_metadata_ != nullptr);
1581 uint32_t dex_pc_in_map = DecodeUnsignedLeb128(&interpreter_metadata_);
1582 DCHECK_EQ(dex_pc, dex_pc_in_map);
1583 return DecodeUnsignedLeb128(&interpreter_metadata_);
1584}
1585
Calin Juravle225ff812014-11-13 16:46:39 +00001586bool HGraphBuilder::AnalyzeDexInstruction(const Instruction& instruction, uint32_t dex_pc) {
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001587 if (current_block_ == nullptr) {
1588 return true; // Dead code
1589 }
Nicolas Geoffraybe9a92a2014-02-25 14:22:56 +00001590
Nicolas Geoffray818f2102014-02-18 16:43:35 +00001591 switch (instruction.Opcode()) {
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00001592 case Instruction::CONST_4: {
1593 int32_t register_index = instruction.VRegA();
David Brazdil8d5b8b22015-03-24 10:51:52 +00001594 HIntConstant* constant = graph_->GetIntConstant(instruction.VRegB_11n());
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00001595 UpdateLocal(register_index, constant);
1596 break;
1597 }
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001598
Nicolas Geoffrayb55f8352014-04-07 15:26:35 +01001599 case Instruction::CONST_16: {
1600 int32_t register_index = instruction.VRegA();
David Brazdil8d5b8b22015-03-24 10:51:52 +00001601 HIntConstant* constant = graph_->GetIntConstant(instruction.VRegB_21s());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001602 UpdateLocal(register_index, constant);
1603 break;
1604 }
1605
Dave Allison20dfc792014-06-16 20:44:29 -07001606 case Instruction::CONST: {
1607 int32_t register_index = instruction.VRegA();
David Brazdil8d5b8b22015-03-24 10:51:52 +00001608 HIntConstant* constant = graph_->GetIntConstant(instruction.VRegB_31i());
Dave Allison20dfc792014-06-16 20:44:29 -07001609 UpdateLocal(register_index, constant);
1610 break;
1611 }
1612
1613 case Instruction::CONST_HIGH16: {
1614 int32_t register_index = instruction.VRegA();
David Brazdil8d5b8b22015-03-24 10:51:52 +00001615 HIntConstant* constant = graph_->GetIntConstant(instruction.VRegB_21h() << 16);
Dave Allison20dfc792014-06-16 20:44:29 -07001616 UpdateLocal(register_index, constant);
1617 break;
1618 }
1619
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001620 case Instruction::CONST_WIDE_16: {
1621 int32_t register_index = instruction.VRegA();
Dave Allison20dfc792014-06-16 20:44:29 -07001622 // Get 16 bits of constant value, sign extended to 64 bits.
1623 int64_t value = instruction.VRegB_21s();
1624 value <<= 48;
1625 value >>= 48;
David Brazdil8d5b8b22015-03-24 10:51:52 +00001626 HLongConstant* constant = graph_->GetLongConstant(value);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001627 UpdateLocal(register_index, constant);
1628 break;
1629 }
1630
1631 case Instruction::CONST_WIDE_32: {
1632 int32_t register_index = instruction.VRegA();
Dave Allison20dfc792014-06-16 20:44:29 -07001633 // Get 32 bits of constant value, sign extended to 64 bits.
1634 int64_t value = instruction.VRegB_31i();
1635 value <<= 32;
1636 value >>= 32;
David Brazdil8d5b8b22015-03-24 10:51:52 +00001637 HLongConstant* constant = graph_->GetLongConstant(value);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001638 UpdateLocal(register_index, constant);
1639 break;
1640 }
1641
1642 case Instruction::CONST_WIDE: {
1643 int32_t register_index = instruction.VRegA();
David Brazdil8d5b8b22015-03-24 10:51:52 +00001644 HLongConstant* constant = graph_->GetLongConstant(instruction.VRegB_51l());
Nicolas Geoffrayb55f8352014-04-07 15:26:35 +01001645 UpdateLocal(register_index, constant);
1646 break;
1647 }
1648
Dave Allison20dfc792014-06-16 20:44:29 -07001649 case Instruction::CONST_WIDE_HIGH16: {
1650 int32_t register_index = instruction.VRegA();
1651 int64_t value = static_cast<int64_t>(instruction.VRegB_21h()) << 48;
David Brazdil8d5b8b22015-03-24 10:51:52 +00001652 HLongConstant* constant = graph_->GetLongConstant(value);
Dave Allison20dfc792014-06-16 20:44:29 -07001653 UpdateLocal(register_index, constant);
1654 break;
1655 }
1656
Nicolas Geoffraydadf3172014-11-07 16:36:02 +00001657 // Note that the SSA building will refine the types.
Dave Allison20dfc792014-06-16 20:44:29 -07001658 case Instruction::MOVE:
1659 case Instruction::MOVE_FROM16:
1660 case Instruction::MOVE_16: {
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001661 HInstruction* value = LoadLocal(instruction.VRegB(), Primitive::kPrimInt);
Nicolas Geoffrayb55f8352014-04-07 15:26:35 +01001662 UpdateLocal(instruction.VRegA(), value);
1663 break;
1664 }
1665
Nicolas Geoffraydadf3172014-11-07 16:36:02 +00001666 // Note that the SSA building will refine the types.
Dave Allison20dfc792014-06-16 20:44:29 -07001667 case Instruction::MOVE_WIDE:
1668 case Instruction::MOVE_WIDE_FROM16:
1669 case Instruction::MOVE_WIDE_16: {
1670 HInstruction* value = LoadLocal(instruction.VRegB(), Primitive::kPrimLong);
1671 UpdateLocal(instruction.VRegA(), value);
1672 break;
1673 }
1674
1675 case Instruction::MOVE_OBJECT:
1676 case Instruction::MOVE_OBJECT_16:
1677 case Instruction::MOVE_OBJECT_FROM16: {
1678 HInstruction* value = LoadLocal(instruction.VRegB(), Primitive::kPrimNot);
1679 UpdateLocal(instruction.VRegA(), value);
1680 break;
1681 }
1682
Nicolas Geoffray9523a3e2015-07-17 11:51:28 +00001683 case Instruction::RETURN_VOID_NO_BARRIER:
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001684 case Instruction::RETURN_VOID: {
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001685 BuildReturn(instruction, Primitive::kPrimVoid);
Nicolas Geoffray818f2102014-02-18 16:43:35 +00001686 break;
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001687 }
1688
Dave Allison20dfc792014-06-16 20:44:29 -07001689#define IF_XX(comparison, cond) \
Calin Juravle225ff812014-11-13 16:46:39 +00001690 case Instruction::IF_##cond: If_22t<comparison>(instruction, dex_pc); break; \
1691 case Instruction::IF_##cond##Z: If_21t<comparison>(instruction, dex_pc); break
Nicolas Geoffrayb55f8352014-04-07 15:26:35 +01001692
Dave Allison20dfc792014-06-16 20:44:29 -07001693 IF_XX(HEqual, EQ);
1694 IF_XX(HNotEqual, NE);
1695 IF_XX(HLessThan, LT);
1696 IF_XX(HLessThanOrEqual, LE);
1697 IF_XX(HGreaterThan, GT);
1698 IF_XX(HGreaterThanOrEqual, GE);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001699
Nicolas Geoffraybe9a92a2014-02-25 14:22:56 +00001700 case Instruction::GOTO:
1701 case Instruction::GOTO_16:
1702 case Instruction::GOTO_32: {
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00001703 int32_t offset = instruction.GetTargetOffset();
Calin Juravle225ff812014-11-13 16:46:39 +00001704 HBasicBlock* target = FindBlockStartingAt(offset + dex_pc);
Nicolas Geoffraybe9a92a2014-02-25 14:22:56 +00001705 DCHECK(target != nullptr);
David Brazdil852eaff2015-02-02 15:23:05 +00001706 PotentiallyAddSuspendCheck(target, dex_pc);
Nicolas Geoffraybe9a92a2014-02-25 14:22:56 +00001707 current_block_->AddInstruction(new (arena_) HGoto());
1708 current_block_->AddSuccessor(target);
1709 current_block_ = nullptr;
1710 break;
1711 }
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001712
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001713 case Instruction::RETURN: {
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001714 BuildReturn(instruction, return_type_);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001715 break;
1716 }
1717
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001718 case Instruction::RETURN_OBJECT: {
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001719 BuildReturn(instruction, return_type_);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001720 break;
1721 }
1722
1723 case Instruction::RETURN_WIDE: {
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001724 BuildReturn(instruction, return_type_);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001725 break;
1726 }
1727
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001728 case Instruction::INVOKE_DIRECT:
Nicolas Geoffray0d8db992014-11-11 14:40:10 +00001729 case Instruction::INVOKE_INTERFACE:
1730 case Instruction::INVOKE_STATIC:
1731 case Instruction::INVOKE_SUPER:
Nicolas Geoffray9523a3e2015-07-17 11:51:28 +00001732 case Instruction::INVOKE_VIRTUAL:
1733 case Instruction::INVOKE_VIRTUAL_QUICK: {
1734 uint16_t method_idx;
1735 if (instruction.Opcode() == Instruction::INVOKE_VIRTUAL_QUICK) {
1736 if (!CanDecodeQuickenedInfo()) {
1737 return false;
1738 }
1739 method_idx = LookupQuickenedInfo(dex_pc);
1740 } else {
1741 method_idx = instruction.VRegB_35c();
1742 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001743 uint32_t number_of_vreg_arguments = instruction.VRegA_35c();
Nicolas Geoffray4a34a422014-04-03 10:38:37 +01001744 uint32_t args[5];
Ian Rogers29a26482014-05-02 15:27:29 -07001745 instruction.GetVarArgs(args);
Calin Juravle225ff812014-11-13 16:46:39 +00001746 if (!BuildInvoke(instruction, dex_pc, method_idx,
Nicolas Geoffraydadf3172014-11-07 16:36:02 +00001747 number_of_vreg_arguments, false, args, -1)) {
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001748 return false;
Nicolas Geoffray4a34a422014-04-03 10:38:37 +01001749 }
Nicolas Geoffray4a34a422014-04-03 10:38:37 +01001750 break;
1751 }
1752
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001753 case Instruction::INVOKE_DIRECT_RANGE:
Nicolas Geoffray0d8db992014-11-11 14:40:10 +00001754 case Instruction::INVOKE_INTERFACE_RANGE:
1755 case Instruction::INVOKE_STATIC_RANGE:
1756 case Instruction::INVOKE_SUPER_RANGE:
Nicolas Geoffray9523a3e2015-07-17 11:51:28 +00001757 case Instruction::INVOKE_VIRTUAL_RANGE:
1758 case Instruction::INVOKE_VIRTUAL_RANGE_QUICK: {
1759 uint16_t method_idx;
1760 if (instruction.Opcode() == Instruction::INVOKE_VIRTUAL_RANGE_QUICK) {
1761 if (!CanDecodeQuickenedInfo()) {
1762 return false;
1763 }
1764 method_idx = LookupQuickenedInfo(dex_pc);
1765 } else {
1766 method_idx = instruction.VRegB_3rc();
1767 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001768 uint32_t number_of_vreg_arguments = instruction.VRegA_3rc();
1769 uint32_t register_index = instruction.VRegC();
Calin Juravle225ff812014-11-13 16:46:39 +00001770 if (!BuildInvoke(instruction, dex_pc, method_idx,
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001771 number_of_vreg_arguments, true, nullptr, register_index)) {
Nicolas Geoffray4a34a422014-04-03 10:38:37 +01001772 return false;
1773 }
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001774 break;
1775 }
1776
Roland Levillain88cb1752014-10-20 16:36:47 +01001777 case Instruction::NEG_INT: {
1778 Unop_12x<HNeg>(instruction, Primitive::kPrimInt);
1779 break;
1780 }
1781
Roland Levillain2e07b4f2014-10-23 18:12:09 +01001782 case Instruction::NEG_LONG: {
1783 Unop_12x<HNeg>(instruction, Primitive::kPrimLong);
1784 break;
1785 }
1786
Roland Levillain3dbcb382014-10-28 17:30:07 +00001787 case Instruction::NEG_FLOAT: {
1788 Unop_12x<HNeg>(instruction, Primitive::kPrimFloat);
1789 break;
1790 }
1791
1792 case Instruction::NEG_DOUBLE: {
1793 Unop_12x<HNeg>(instruction, Primitive::kPrimDouble);
1794 break;
1795 }
1796
Roland Levillain1cc5f2512014-10-22 18:06:21 +01001797 case Instruction::NOT_INT: {
1798 Unop_12x<HNot>(instruction, Primitive::kPrimInt);
1799 break;
1800 }
1801
Roland Levillain70566432014-10-24 16:20:17 +01001802 case Instruction::NOT_LONG: {
1803 Unop_12x<HNot>(instruction, Primitive::kPrimLong);
1804 break;
1805 }
1806
Roland Levillaindff1f282014-11-05 14:15:05 +00001807 case Instruction::INT_TO_LONG: {
Roland Levillain624279f2014-12-04 11:54:28 +00001808 Conversion_12x(instruction, Primitive::kPrimInt, Primitive::kPrimLong, dex_pc);
Roland Levillaindff1f282014-11-05 14:15:05 +00001809 break;
1810 }
1811
Roland Levillaincff13742014-11-17 14:32:17 +00001812 case Instruction::INT_TO_FLOAT: {
Roland Levillain624279f2014-12-04 11:54:28 +00001813 Conversion_12x(instruction, Primitive::kPrimInt, Primitive::kPrimFloat, dex_pc);
Roland Levillaincff13742014-11-17 14:32:17 +00001814 break;
1815 }
1816
1817 case Instruction::INT_TO_DOUBLE: {
Roland Levillain624279f2014-12-04 11:54:28 +00001818 Conversion_12x(instruction, Primitive::kPrimInt, Primitive::kPrimDouble, dex_pc);
Roland Levillaincff13742014-11-17 14:32:17 +00001819 break;
1820 }
1821
Roland Levillain946e1432014-11-11 17:35:19 +00001822 case Instruction::LONG_TO_INT: {
Roland Levillain624279f2014-12-04 11:54:28 +00001823 Conversion_12x(instruction, Primitive::kPrimLong, Primitive::kPrimInt, dex_pc);
Roland Levillain946e1432014-11-11 17:35:19 +00001824 break;
1825 }
1826
Roland Levillain6d0e4832014-11-27 18:31:21 +00001827 case Instruction::LONG_TO_FLOAT: {
Roland Levillain624279f2014-12-04 11:54:28 +00001828 Conversion_12x(instruction, Primitive::kPrimLong, Primitive::kPrimFloat, dex_pc);
Roland Levillain6d0e4832014-11-27 18:31:21 +00001829 break;
1830 }
1831
Roland Levillain647b9ed2014-11-27 12:06:00 +00001832 case Instruction::LONG_TO_DOUBLE: {
Roland Levillain624279f2014-12-04 11:54:28 +00001833 Conversion_12x(instruction, Primitive::kPrimLong, Primitive::kPrimDouble, dex_pc);
Roland Levillain647b9ed2014-11-27 12:06:00 +00001834 break;
1835 }
1836
Roland Levillain3f8f9362014-12-02 17:45:01 +00001837 case Instruction::FLOAT_TO_INT: {
Roland Levillain624279f2014-12-04 11:54:28 +00001838 Conversion_12x(instruction, Primitive::kPrimFloat, Primitive::kPrimInt, dex_pc);
1839 break;
1840 }
1841
1842 case Instruction::FLOAT_TO_LONG: {
1843 Conversion_12x(instruction, Primitive::kPrimFloat, Primitive::kPrimLong, dex_pc);
Roland Levillain3f8f9362014-12-02 17:45:01 +00001844 break;
1845 }
1846
Roland Levillain8964e2b2014-12-04 12:10:50 +00001847 case Instruction::FLOAT_TO_DOUBLE: {
1848 Conversion_12x(instruction, Primitive::kPrimFloat, Primitive::kPrimDouble, dex_pc);
1849 break;
1850 }
1851
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001852 case Instruction::DOUBLE_TO_INT: {
1853 Conversion_12x(instruction, Primitive::kPrimDouble, Primitive::kPrimInt, dex_pc);
1854 break;
1855 }
1856
1857 case Instruction::DOUBLE_TO_LONG: {
1858 Conversion_12x(instruction, Primitive::kPrimDouble, Primitive::kPrimLong, dex_pc);
1859 break;
1860 }
1861
Roland Levillain8964e2b2014-12-04 12:10:50 +00001862 case Instruction::DOUBLE_TO_FLOAT: {
1863 Conversion_12x(instruction, Primitive::kPrimDouble, Primitive::kPrimFloat, dex_pc);
1864 break;
1865 }
1866
Roland Levillain51d3fc42014-11-13 14:11:42 +00001867 case Instruction::INT_TO_BYTE: {
Roland Levillain624279f2014-12-04 11:54:28 +00001868 Conversion_12x(instruction, Primitive::kPrimInt, Primitive::kPrimByte, dex_pc);
Roland Levillain51d3fc42014-11-13 14:11:42 +00001869 break;
1870 }
1871
Roland Levillain01a8d712014-11-14 16:27:39 +00001872 case Instruction::INT_TO_SHORT: {
Roland Levillain624279f2014-12-04 11:54:28 +00001873 Conversion_12x(instruction, Primitive::kPrimInt, Primitive::kPrimShort, dex_pc);
Roland Levillain01a8d712014-11-14 16:27:39 +00001874 break;
1875 }
1876
Roland Levillain981e4542014-11-14 11:47:14 +00001877 case Instruction::INT_TO_CHAR: {
Roland Levillain624279f2014-12-04 11:54:28 +00001878 Conversion_12x(instruction, Primitive::kPrimInt, Primitive::kPrimChar, dex_pc);
Roland Levillain981e4542014-11-14 11:47:14 +00001879 break;
1880 }
1881
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001882 case Instruction::ADD_INT: {
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01001883 Binop_23x<HAdd>(instruction, Primitive::kPrimInt);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001884 break;
1885 }
1886
1887 case Instruction::ADD_LONG: {
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01001888 Binop_23x<HAdd>(instruction, Primitive::kPrimLong);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001889 break;
1890 }
1891
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001892 case Instruction::ADD_DOUBLE: {
1893 Binop_23x<HAdd>(instruction, Primitive::kPrimDouble);
1894 break;
1895 }
1896
1897 case Instruction::ADD_FLOAT: {
1898 Binop_23x<HAdd>(instruction, Primitive::kPrimFloat);
1899 break;
1900 }
1901
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001902 case Instruction::SUB_INT: {
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01001903 Binop_23x<HSub>(instruction, Primitive::kPrimInt);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001904 break;
1905 }
1906
1907 case Instruction::SUB_LONG: {
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01001908 Binop_23x<HSub>(instruction, Primitive::kPrimLong);
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001909 break;
1910 }
1911
Calin Juravle096cc022014-10-23 17:01:13 +01001912 case Instruction::SUB_FLOAT: {
1913 Binop_23x<HSub>(instruction, Primitive::kPrimFloat);
1914 break;
1915 }
1916
1917 case Instruction::SUB_DOUBLE: {
1918 Binop_23x<HSub>(instruction, Primitive::kPrimDouble);
1919 break;
1920 }
1921
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001922 case Instruction::ADD_INT_2ADDR: {
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001923 Binop_12x<HAdd>(instruction, Primitive::kPrimInt);
1924 break;
1925 }
1926
Calin Juravle34bacdf2014-10-07 20:23:36 +01001927 case Instruction::MUL_INT: {
1928 Binop_23x<HMul>(instruction, Primitive::kPrimInt);
1929 break;
1930 }
1931
1932 case Instruction::MUL_LONG: {
1933 Binop_23x<HMul>(instruction, Primitive::kPrimLong);
1934 break;
1935 }
1936
Calin Juravleb5bfa962014-10-21 18:02:24 +01001937 case Instruction::MUL_FLOAT: {
1938 Binop_23x<HMul>(instruction, Primitive::kPrimFloat);
1939 break;
1940 }
1941
1942 case Instruction::MUL_DOUBLE: {
1943 Binop_23x<HMul>(instruction, Primitive::kPrimDouble);
1944 break;
1945 }
1946
Calin Juravled0d48522014-11-04 16:40:20 +00001947 case Instruction::DIV_INT: {
Calin Juravlebacfec32014-11-14 15:54:36 +00001948 BuildCheckedDivRem(instruction.VRegA(), instruction.VRegB(), instruction.VRegC(),
1949 dex_pc, Primitive::kPrimInt, false, true);
Calin Juravled0d48522014-11-04 16:40:20 +00001950 break;
1951 }
1952
Calin Juravled6fb6cf2014-11-11 19:07:44 +00001953 case Instruction::DIV_LONG: {
Calin Juravlebacfec32014-11-14 15:54:36 +00001954 BuildCheckedDivRem(instruction.VRegA(), instruction.VRegB(), instruction.VRegC(),
1955 dex_pc, Primitive::kPrimLong, false, true);
Calin Juravled6fb6cf2014-11-11 19:07:44 +00001956 break;
1957 }
1958
Calin Juravle7c4954d2014-10-28 16:57:40 +00001959 case Instruction::DIV_FLOAT: {
Calin Juravle225ff812014-11-13 16:46:39 +00001960 Binop_23x<HDiv>(instruction, Primitive::kPrimFloat, dex_pc);
Calin Juravle7c4954d2014-10-28 16:57:40 +00001961 break;
1962 }
1963
1964 case Instruction::DIV_DOUBLE: {
Calin Juravle225ff812014-11-13 16:46:39 +00001965 Binop_23x<HDiv>(instruction, Primitive::kPrimDouble, dex_pc);
Calin Juravle7c4954d2014-10-28 16:57:40 +00001966 break;
1967 }
1968
Calin Juravlebacfec32014-11-14 15:54:36 +00001969 case Instruction::REM_INT: {
1970 BuildCheckedDivRem(instruction.VRegA(), instruction.VRegB(), instruction.VRegC(),
1971 dex_pc, Primitive::kPrimInt, false, false);
1972 break;
1973 }
1974
1975 case Instruction::REM_LONG: {
1976 BuildCheckedDivRem(instruction.VRegA(), instruction.VRegB(), instruction.VRegC(),
1977 dex_pc, Primitive::kPrimLong, false, false);
1978 break;
1979 }
1980
Calin Juravled2ec87d2014-12-08 14:24:46 +00001981 case Instruction::REM_FLOAT: {
1982 Binop_23x<HRem>(instruction, Primitive::kPrimFloat, dex_pc);
1983 break;
1984 }
1985
1986 case Instruction::REM_DOUBLE: {
1987 Binop_23x<HRem>(instruction, Primitive::kPrimDouble, dex_pc);
1988 break;
1989 }
1990
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00001991 case Instruction::AND_INT: {
1992 Binop_23x<HAnd>(instruction, Primitive::kPrimInt);
1993 break;
1994 }
1995
1996 case Instruction::AND_LONG: {
1997 Binop_23x<HAnd>(instruction, Primitive::kPrimLong);
1998 break;
1999 }
2000
Calin Juravle9aec02f2014-11-18 23:06:35 +00002001 case Instruction::SHL_INT: {
2002 Binop_23x_shift<HShl>(instruction, Primitive::kPrimInt);
2003 break;
2004 }
2005
2006 case Instruction::SHL_LONG: {
2007 Binop_23x_shift<HShl>(instruction, Primitive::kPrimLong);
2008 break;
2009 }
2010
2011 case Instruction::SHR_INT: {
2012 Binop_23x_shift<HShr>(instruction, Primitive::kPrimInt);
2013 break;
2014 }
2015
2016 case Instruction::SHR_LONG: {
2017 Binop_23x_shift<HShr>(instruction, Primitive::kPrimLong);
2018 break;
2019 }
2020
2021 case Instruction::USHR_INT: {
2022 Binop_23x_shift<HUShr>(instruction, Primitive::kPrimInt);
2023 break;
2024 }
2025
2026 case Instruction::USHR_LONG: {
2027 Binop_23x_shift<HUShr>(instruction, Primitive::kPrimLong);
2028 break;
2029 }
2030
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00002031 case Instruction::OR_INT: {
2032 Binop_23x<HOr>(instruction, Primitive::kPrimInt);
2033 break;
2034 }
2035
2036 case Instruction::OR_LONG: {
2037 Binop_23x<HOr>(instruction, Primitive::kPrimLong);
2038 break;
2039 }
2040
2041 case Instruction::XOR_INT: {
2042 Binop_23x<HXor>(instruction, Primitive::kPrimInt);
2043 break;
2044 }
2045
2046 case Instruction::XOR_LONG: {
2047 Binop_23x<HXor>(instruction, Primitive::kPrimLong);
2048 break;
2049 }
2050
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002051 case Instruction::ADD_LONG_2ADDR: {
2052 Binop_12x<HAdd>(instruction, Primitive::kPrimLong);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002053 break;
2054 }
2055
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01002056 case Instruction::ADD_DOUBLE_2ADDR: {
2057 Binop_12x<HAdd>(instruction, Primitive::kPrimDouble);
2058 break;
2059 }
2060
2061 case Instruction::ADD_FLOAT_2ADDR: {
2062 Binop_12x<HAdd>(instruction, Primitive::kPrimFloat);
2063 break;
2064 }
2065
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002066 case Instruction::SUB_INT_2ADDR: {
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002067 Binop_12x<HSub>(instruction, Primitive::kPrimInt);
2068 break;
2069 }
2070
2071 case Instruction::SUB_LONG_2ADDR: {
2072 Binop_12x<HSub>(instruction, Primitive::kPrimLong);
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00002073 break;
2074 }
2075
Calin Juravle096cc022014-10-23 17:01:13 +01002076 case Instruction::SUB_FLOAT_2ADDR: {
2077 Binop_12x<HSub>(instruction, Primitive::kPrimFloat);
2078 break;
2079 }
2080
2081 case Instruction::SUB_DOUBLE_2ADDR: {
2082 Binop_12x<HSub>(instruction, Primitive::kPrimDouble);
2083 break;
2084 }
2085
Calin Juravle34bacdf2014-10-07 20:23:36 +01002086 case Instruction::MUL_INT_2ADDR: {
2087 Binop_12x<HMul>(instruction, Primitive::kPrimInt);
2088 break;
2089 }
2090
2091 case Instruction::MUL_LONG_2ADDR: {
2092 Binop_12x<HMul>(instruction, Primitive::kPrimLong);
2093 break;
2094 }
2095
Calin Juravleb5bfa962014-10-21 18:02:24 +01002096 case Instruction::MUL_FLOAT_2ADDR: {
2097 Binop_12x<HMul>(instruction, Primitive::kPrimFloat);
2098 break;
2099 }
2100
2101 case Instruction::MUL_DOUBLE_2ADDR: {
2102 Binop_12x<HMul>(instruction, Primitive::kPrimDouble);
2103 break;
2104 }
2105
Calin Juravle865fc882014-11-06 17:09:03 +00002106 case Instruction::DIV_INT_2ADDR: {
Calin Juravlebacfec32014-11-14 15:54:36 +00002107 BuildCheckedDivRem(instruction.VRegA(), instruction.VRegA(), instruction.VRegB(),
2108 dex_pc, Primitive::kPrimInt, false, true);
Calin Juravle865fc882014-11-06 17:09:03 +00002109 break;
2110 }
2111
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002112 case Instruction::DIV_LONG_2ADDR: {
Calin Juravlebacfec32014-11-14 15:54:36 +00002113 BuildCheckedDivRem(instruction.VRegA(), instruction.VRegA(), instruction.VRegB(),
2114 dex_pc, Primitive::kPrimLong, false, true);
2115 break;
2116 }
2117
2118 case Instruction::REM_INT_2ADDR: {
2119 BuildCheckedDivRem(instruction.VRegA(), instruction.VRegA(), instruction.VRegB(),
2120 dex_pc, Primitive::kPrimInt, false, false);
2121 break;
2122 }
2123
2124 case Instruction::REM_LONG_2ADDR: {
2125 BuildCheckedDivRem(instruction.VRegA(), instruction.VRegA(), instruction.VRegB(),
2126 dex_pc, Primitive::kPrimLong, false, false);
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002127 break;
2128 }
2129
Calin Juravled2ec87d2014-12-08 14:24:46 +00002130 case Instruction::REM_FLOAT_2ADDR: {
2131 Binop_12x<HRem>(instruction, Primitive::kPrimFloat, dex_pc);
2132 break;
2133 }
2134
2135 case Instruction::REM_DOUBLE_2ADDR: {
2136 Binop_12x<HRem>(instruction, Primitive::kPrimDouble, dex_pc);
2137 break;
2138 }
2139
Calin Juravle9aec02f2014-11-18 23:06:35 +00002140 case Instruction::SHL_INT_2ADDR: {
2141 Binop_12x_shift<HShl>(instruction, Primitive::kPrimInt);
2142 break;
2143 }
2144
2145 case Instruction::SHL_LONG_2ADDR: {
2146 Binop_12x_shift<HShl>(instruction, Primitive::kPrimLong);
2147 break;
2148 }
2149
2150 case Instruction::SHR_INT_2ADDR: {
2151 Binop_12x_shift<HShr>(instruction, Primitive::kPrimInt);
2152 break;
2153 }
2154
2155 case Instruction::SHR_LONG_2ADDR: {
2156 Binop_12x_shift<HShr>(instruction, Primitive::kPrimLong);
2157 break;
2158 }
2159
2160 case Instruction::USHR_INT_2ADDR: {
2161 Binop_12x_shift<HUShr>(instruction, Primitive::kPrimInt);
2162 break;
2163 }
2164
2165 case Instruction::USHR_LONG_2ADDR: {
2166 Binop_12x_shift<HUShr>(instruction, Primitive::kPrimLong);
2167 break;
2168 }
2169
Calin Juravle7c4954d2014-10-28 16:57:40 +00002170 case Instruction::DIV_FLOAT_2ADDR: {
Calin Juravle225ff812014-11-13 16:46:39 +00002171 Binop_12x<HDiv>(instruction, Primitive::kPrimFloat, dex_pc);
Calin Juravle7c4954d2014-10-28 16:57:40 +00002172 break;
2173 }
2174
2175 case Instruction::DIV_DOUBLE_2ADDR: {
Calin Juravle225ff812014-11-13 16:46:39 +00002176 Binop_12x<HDiv>(instruction, Primitive::kPrimDouble, dex_pc);
Calin Juravle7c4954d2014-10-28 16:57:40 +00002177 break;
2178 }
2179
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00002180 case Instruction::AND_INT_2ADDR: {
2181 Binop_12x<HAnd>(instruction, Primitive::kPrimInt);
2182 break;
2183 }
2184
2185 case Instruction::AND_LONG_2ADDR: {
2186 Binop_12x<HAnd>(instruction, Primitive::kPrimLong);
2187 break;
2188 }
2189
2190 case Instruction::OR_INT_2ADDR: {
2191 Binop_12x<HOr>(instruction, Primitive::kPrimInt);
2192 break;
2193 }
2194
2195 case Instruction::OR_LONG_2ADDR: {
2196 Binop_12x<HOr>(instruction, Primitive::kPrimLong);
2197 break;
2198 }
2199
2200 case Instruction::XOR_INT_2ADDR: {
2201 Binop_12x<HXor>(instruction, Primitive::kPrimInt);
2202 break;
2203 }
2204
2205 case Instruction::XOR_LONG_2ADDR: {
2206 Binop_12x<HXor>(instruction, Primitive::kPrimLong);
2207 break;
2208 }
2209
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00002210 case Instruction::ADD_INT_LIT16: {
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002211 Binop_22s<HAdd>(instruction, false);
2212 break;
2213 }
2214
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00002215 case Instruction::AND_INT_LIT16: {
2216 Binop_22s<HAnd>(instruction, false);
2217 break;
2218 }
2219
2220 case Instruction::OR_INT_LIT16: {
2221 Binop_22s<HOr>(instruction, false);
2222 break;
2223 }
2224
2225 case Instruction::XOR_INT_LIT16: {
2226 Binop_22s<HXor>(instruction, false);
2227 break;
2228 }
2229
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002230 case Instruction::RSUB_INT: {
2231 Binop_22s<HSub>(instruction, true);
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00002232 break;
2233 }
2234
Calin Juravle34bacdf2014-10-07 20:23:36 +01002235 case Instruction::MUL_INT_LIT16: {
2236 Binop_22s<HMul>(instruction, false);
2237 break;
2238 }
2239
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00002240 case Instruction::ADD_INT_LIT8: {
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002241 Binop_22b<HAdd>(instruction, false);
2242 break;
2243 }
2244
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00002245 case Instruction::AND_INT_LIT8: {
2246 Binop_22b<HAnd>(instruction, false);
2247 break;
2248 }
2249
2250 case Instruction::OR_INT_LIT8: {
2251 Binop_22b<HOr>(instruction, false);
2252 break;
2253 }
2254
2255 case Instruction::XOR_INT_LIT8: {
2256 Binop_22b<HXor>(instruction, false);
2257 break;
2258 }
2259
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002260 case Instruction::RSUB_INT_LIT8: {
2261 Binop_22b<HSub>(instruction, true);
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00002262 break;
2263 }
2264
Calin Juravle34bacdf2014-10-07 20:23:36 +01002265 case Instruction::MUL_INT_LIT8: {
2266 Binop_22b<HMul>(instruction, false);
2267 break;
2268 }
2269
Calin Juravled0d48522014-11-04 16:40:20 +00002270 case Instruction::DIV_INT_LIT16:
2271 case Instruction::DIV_INT_LIT8: {
Calin Juravlebacfec32014-11-14 15:54:36 +00002272 BuildCheckedDivRem(instruction.VRegA(), instruction.VRegB(), instruction.VRegC(),
2273 dex_pc, Primitive::kPrimInt, true, true);
2274 break;
2275 }
2276
2277 case Instruction::REM_INT_LIT16:
2278 case Instruction::REM_INT_LIT8: {
2279 BuildCheckedDivRem(instruction.VRegA(), instruction.VRegB(), instruction.VRegC(),
2280 dex_pc, Primitive::kPrimInt, true, false);
Calin Juravled0d48522014-11-04 16:40:20 +00002281 break;
2282 }
2283
Calin Juravle9aec02f2014-11-18 23:06:35 +00002284 case Instruction::SHL_INT_LIT8: {
2285 Binop_22b<HShl>(instruction, false);
2286 break;
2287 }
2288
2289 case Instruction::SHR_INT_LIT8: {
2290 Binop_22b<HShr>(instruction, false);
2291 break;
2292 }
2293
2294 case Instruction::USHR_INT_LIT8: {
2295 Binop_22b<HUShr>(instruction, false);
2296 break;
2297 }
2298
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01002299 case Instruction::NEW_INSTANCE: {
Nicolas Geoffraycb1b00a2015-01-28 14:50:01 +00002300 uint16_t type_index = instruction.VRegB_21c();
Jeff Hao848f70a2014-01-15 13:49:50 -08002301 if (compiler_driver_->IsStringTypeIndex(type_index, dex_file_)) {
Jeff Hao848f70a2014-01-15 13:49:50 -08002302 int32_t register_index = instruction.VRegA();
Nicolas Geoffray2e7cd752015-07-10 11:38:52 +01002303 HFakeString* fake_string = new (arena_) HFakeString();
2304 current_block_->AddInstruction(fake_string);
2305 UpdateLocal(register_index, fake_string);
Jeff Hao848f70a2014-01-15 13:49:50 -08002306 } else {
2307 QuickEntrypointEnum entrypoint = NeedsAccessCheck(type_index)
2308 ? kQuickAllocObjectWithAccessCheck
2309 : kQuickAllocObject;
Nicolas Geoffraycb1b00a2015-01-28 14:50:01 +00002310
Nicolas Geoffrayd5111bf2015-05-22 15:37:09 +01002311 current_block_->AddInstruction(new (arena_) HNewInstance(
Nicolas Geoffray69aa6012015-06-09 10:34:25 +01002312 graph_->GetCurrentMethod(),
2313 dex_pc,
2314 type_index,
2315 *dex_compilation_unit_->GetDexFile(),
2316 entrypoint));
Jeff Hao848f70a2014-01-15 13:49:50 -08002317 UpdateLocal(instruction.VRegA(), current_block_->GetLastInstruction());
2318 }
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01002319 break;
2320 }
2321
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01002322 case Instruction::NEW_ARRAY: {
Nicolas Geoffraycb1b00a2015-01-28 14:50:01 +00002323 uint16_t type_index = instruction.VRegC_22c();
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01002324 HInstruction* length = LoadLocal(instruction.VRegB_22c(), Primitive::kPrimInt);
Nicolas Geoffraycb1b00a2015-01-28 14:50:01 +00002325 QuickEntrypointEnum entrypoint = NeedsAccessCheck(type_index)
2326 ? kQuickAllocArrayWithAccessCheck
2327 : kQuickAllocArray;
Nicolas Geoffray69aa6012015-06-09 10:34:25 +01002328 current_block_->AddInstruction(new (arena_) HNewArray(length,
2329 graph_->GetCurrentMethod(),
2330 dex_pc,
2331 type_index,
2332 *dex_compilation_unit_->GetDexFile(),
2333 entrypoint));
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01002334 UpdateLocal(instruction.VRegA_22c(), current_block_->GetLastInstruction());
2335 break;
2336 }
2337
2338 case Instruction::FILLED_NEW_ARRAY: {
2339 uint32_t number_of_vreg_arguments = instruction.VRegA_35c();
2340 uint32_t type_index = instruction.VRegB_35c();
2341 uint32_t args[5];
2342 instruction.GetVarArgs(args);
Calin Juravle225ff812014-11-13 16:46:39 +00002343 BuildFilledNewArray(dex_pc, type_index, number_of_vreg_arguments, false, args, 0);
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01002344 break;
2345 }
2346
2347 case Instruction::FILLED_NEW_ARRAY_RANGE: {
2348 uint32_t number_of_vreg_arguments = instruction.VRegA_3rc();
2349 uint32_t type_index = instruction.VRegB_3rc();
2350 uint32_t register_index = instruction.VRegC_3rc();
2351 BuildFilledNewArray(
Calin Juravle225ff812014-11-13 16:46:39 +00002352 dex_pc, type_index, number_of_vreg_arguments, true, nullptr, register_index);
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01002353 break;
2354 }
2355
2356 case Instruction::FILL_ARRAY_DATA: {
Calin Juravle225ff812014-11-13 16:46:39 +00002357 BuildFillArrayData(instruction, dex_pc);
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01002358 break;
2359 }
2360
Nicolas Geoffrayddb311f2014-05-16 09:28:54 +01002361 case Instruction::MOVE_RESULT:
Dave Allison20dfc792014-06-16 20:44:29 -07002362 case Instruction::MOVE_RESULT_WIDE:
David Brazdilfc6a86a2015-06-26 10:33:45 +00002363 case Instruction::MOVE_RESULT_OBJECT: {
Nicolas Geoffray1efcc222015-06-24 12:41:20 +01002364 if (latest_result_ == nullptr) {
2365 // Only dead code can lead to this situation, where the verifier
2366 // does not reject the method.
2367 } else {
David Brazdilfc6a86a2015-06-26 10:33:45 +00002368 // An Invoke/FilledNewArray and its MoveResult could have landed in
2369 // different blocks if there was a try/catch block boundary between
2370 // them. For Invoke, we insert a StoreLocal after the instruction. For
2371 // FilledNewArray, the local needs to be updated after the array was
2372 // filled, otherwise we might overwrite an input vreg.
2373 HStoreLocal* update_local =
2374 new (arena_) HStoreLocal(GetLocalAt(instruction.VRegA()), latest_result_);
2375 HBasicBlock* block = latest_result_->GetBlock();
2376 if (block == current_block_) {
2377 // MoveResult and the previous instruction are in the same block.
2378 current_block_->AddInstruction(update_local);
2379 } else {
2380 // The two instructions are in different blocks. Insert the MoveResult
2381 // before the final control-flow instruction of the previous block.
2382 DCHECK(block->EndsWithControlFlowInstruction());
2383 DCHECK(current_block_->GetInstructions().IsEmpty());
2384 block->InsertInstructionBefore(update_local, block->GetLastInstruction());
2385 }
Nicolas Geoffray1efcc222015-06-24 12:41:20 +01002386 latest_result_ = nullptr;
2387 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002388 break;
David Brazdilfc6a86a2015-06-26 10:33:45 +00002389 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002390
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002391 case Instruction::CMP_LONG: {
Roland Levillain4fa13f62015-07-06 18:11:54 +01002392 Binop_23x_cmp(instruction, Primitive::kPrimLong, ComparisonBias::kNoBias, dex_pc);
Calin Juravleddb7df22014-11-25 20:56:51 +00002393 break;
2394 }
2395
2396 case Instruction::CMPG_FLOAT: {
Roland Levillain4fa13f62015-07-06 18:11:54 +01002397 Binop_23x_cmp(instruction, Primitive::kPrimFloat, ComparisonBias::kGtBias, dex_pc);
Calin Juravleddb7df22014-11-25 20:56:51 +00002398 break;
2399 }
2400
2401 case Instruction::CMPG_DOUBLE: {
Roland Levillain4fa13f62015-07-06 18:11:54 +01002402 Binop_23x_cmp(instruction, Primitive::kPrimDouble, ComparisonBias::kGtBias, dex_pc);
Calin Juravleddb7df22014-11-25 20:56:51 +00002403 break;
2404 }
2405
2406 case Instruction::CMPL_FLOAT: {
Roland Levillain4fa13f62015-07-06 18:11:54 +01002407 Binop_23x_cmp(instruction, Primitive::kPrimFloat, ComparisonBias::kLtBias, dex_pc);
Calin Juravleddb7df22014-11-25 20:56:51 +00002408 break;
2409 }
2410
2411 case Instruction::CMPL_DOUBLE: {
Roland Levillain4fa13f62015-07-06 18:11:54 +01002412 Binop_23x_cmp(instruction, Primitive::kPrimDouble, ComparisonBias::kLtBias, dex_pc);
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002413 break;
2414 }
2415
Nicolas Geoffraybe9a92a2014-02-25 14:22:56 +00002416 case Instruction::NOP:
2417 break;
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00002418
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002419 case Instruction::IGET:
Nicolas Geoffray9523a3e2015-07-17 11:51:28 +00002420 case Instruction::IGET_QUICK:
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002421 case Instruction::IGET_WIDE:
Nicolas Geoffray9523a3e2015-07-17 11:51:28 +00002422 case Instruction::IGET_WIDE_QUICK:
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002423 case Instruction::IGET_OBJECT:
Nicolas Geoffray9523a3e2015-07-17 11:51:28 +00002424 case Instruction::IGET_OBJECT_QUICK:
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002425 case Instruction::IGET_BOOLEAN:
Nicolas Geoffray9523a3e2015-07-17 11:51:28 +00002426 case Instruction::IGET_BOOLEAN_QUICK:
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002427 case Instruction::IGET_BYTE:
Nicolas Geoffray9523a3e2015-07-17 11:51:28 +00002428 case Instruction::IGET_BYTE_QUICK:
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002429 case Instruction::IGET_CHAR:
Nicolas Geoffray9523a3e2015-07-17 11:51:28 +00002430 case Instruction::IGET_CHAR_QUICK:
2431 case Instruction::IGET_SHORT:
2432 case Instruction::IGET_SHORT_QUICK: {
Calin Juravle225ff812014-11-13 16:46:39 +00002433 if (!BuildInstanceFieldAccess(instruction, dex_pc, false)) {
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002434 return false;
2435 }
2436 break;
2437 }
2438
2439 case Instruction::IPUT:
Nicolas Geoffray9523a3e2015-07-17 11:51:28 +00002440 case Instruction::IPUT_QUICK:
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002441 case Instruction::IPUT_WIDE:
Nicolas Geoffray9523a3e2015-07-17 11:51:28 +00002442 case Instruction::IPUT_WIDE_QUICK:
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002443 case Instruction::IPUT_OBJECT:
Nicolas Geoffray9523a3e2015-07-17 11:51:28 +00002444 case Instruction::IPUT_OBJECT_QUICK:
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002445 case Instruction::IPUT_BOOLEAN:
Nicolas Geoffray9523a3e2015-07-17 11:51:28 +00002446 case Instruction::IPUT_BOOLEAN_QUICK:
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002447 case Instruction::IPUT_BYTE:
Nicolas Geoffray9523a3e2015-07-17 11:51:28 +00002448 case Instruction::IPUT_BYTE_QUICK:
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002449 case Instruction::IPUT_CHAR:
Nicolas Geoffray9523a3e2015-07-17 11:51:28 +00002450 case Instruction::IPUT_CHAR_QUICK:
2451 case Instruction::IPUT_SHORT:
2452 case Instruction::IPUT_SHORT_QUICK: {
Calin Juravle225ff812014-11-13 16:46:39 +00002453 if (!BuildInstanceFieldAccess(instruction, dex_pc, true)) {
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01002454 return false;
2455 }
2456 break;
2457 }
2458
2459 case Instruction::SGET:
2460 case Instruction::SGET_WIDE:
2461 case Instruction::SGET_OBJECT:
2462 case Instruction::SGET_BOOLEAN:
2463 case Instruction::SGET_BYTE:
2464 case Instruction::SGET_CHAR:
2465 case Instruction::SGET_SHORT: {
Calin Juravle225ff812014-11-13 16:46:39 +00002466 if (!BuildStaticFieldAccess(instruction, dex_pc, false)) {
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01002467 return false;
2468 }
2469 break;
2470 }
2471
2472 case Instruction::SPUT:
2473 case Instruction::SPUT_WIDE:
2474 case Instruction::SPUT_OBJECT:
2475 case Instruction::SPUT_BOOLEAN:
2476 case Instruction::SPUT_BYTE:
2477 case Instruction::SPUT_CHAR:
2478 case Instruction::SPUT_SHORT: {
Calin Juravle225ff812014-11-13 16:46:39 +00002479 if (!BuildStaticFieldAccess(instruction, dex_pc, true)) {
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002480 return false;
2481 }
2482 break;
2483 }
2484
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002485#define ARRAY_XX(kind, anticipated_type) \
2486 case Instruction::AGET##kind: { \
Calin Juravle225ff812014-11-13 16:46:39 +00002487 BuildArrayAccess(instruction, dex_pc, false, anticipated_type); \
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002488 break; \
2489 } \
2490 case Instruction::APUT##kind: { \
Calin Juravle225ff812014-11-13 16:46:39 +00002491 BuildArrayAccess(instruction, dex_pc, true, anticipated_type); \
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002492 break; \
2493 }
2494
2495 ARRAY_XX(, Primitive::kPrimInt);
2496 ARRAY_XX(_WIDE, Primitive::kPrimLong);
2497 ARRAY_XX(_OBJECT, Primitive::kPrimNot);
2498 ARRAY_XX(_BOOLEAN, Primitive::kPrimBoolean);
2499 ARRAY_XX(_BYTE, Primitive::kPrimByte);
2500 ARRAY_XX(_CHAR, Primitive::kPrimChar);
2501 ARRAY_XX(_SHORT, Primitive::kPrimShort);
2502
Nicolas Geoffray39468442014-09-02 15:17:15 +01002503 case Instruction::ARRAY_LENGTH: {
2504 HInstruction* object = LoadLocal(instruction.VRegB_12x(), Primitive::kPrimNot);
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +00002505 // No need for a temporary for the null check, it is the only input of the following
2506 // instruction.
Calin Juravle225ff812014-11-13 16:46:39 +00002507 object = new (arena_) HNullCheck(object, dex_pc);
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +00002508 current_block_->AddInstruction(object);
Nicolas Geoffray39468442014-09-02 15:17:15 +01002509 current_block_->AddInstruction(new (arena_) HArrayLength(object));
2510 UpdateLocal(instruction.VRegA_12x(), current_block_->GetLastInstruction());
2511 break;
2512 }
2513
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +00002514 case Instruction::CONST_STRING: {
Nicolas Geoffrayfbdaa302015-05-29 12:06:56 +01002515 current_block_->AddInstruction(
2516 new (arena_) HLoadString(graph_->GetCurrentMethod(), instruction.VRegB_21c(), dex_pc));
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +00002517 UpdateLocal(instruction.VRegA_21c(), current_block_->GetLastInstruction());
2518 break;
2519 }
2520
2521 case Instruction::CONST_STRING_JUMBO: {
Nicolas Geoffrayfbdaa302015-05-29 12:06:56 +01002522 current_block_->AddInstruction(
2523 new (arena_) HLoadString(graph_->GetCurrentMethod(), instruction.VRegB_31c(), dex_pc));
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +00002524 UpdateLocal(instruction.VRegA_31c(), current_block_->GetLastInstruction());
2525 break;
2526 }
2527
Nicolas Geoffray424f6762014-11-03 14:51:25 +00002528 case Instruction::CONST_CLASS: {
2529 uint16_t type_index = instruction.VRegB_21c();
2530 bool type_known_final;
2531 bool type_known_abstract;
Nicolas Geoffraye53798a2014-12-01 10:31:54 +00002532 bool dont_use_is_referrers_class;
2533 // `CanAccessTypeWithoutChecks` will tell whether the method being
2534 // built is trying to access its own class, so that the generated
2535 // code can optimize for this case. However, the optimization does not
Nicolas Geoffray9437b782015-03-25 10:08:51 +00002536 // work for inlining, so we use `IsOutermostCompilingClass` instead.
Nicolas Geoffray424f6762014-11-03 14:51:25 +00002537 bool can_access = compiler_driver_->CanAccessTypeWithoutChecks(
2538 dex_compilation_unit_->GetDexMethodIndex(), *dex_file_, type_index,
Nicolas Geoffraye53798a2014-12-01 10:31:54 +00002539 &type_known_final, &type_known_abstract, &dont_use_is_referrers_class);
Nicolas Geoffray424f6762014-11-03 14:51:25 +00002540 if (!can_access) {
Calin Juravle48c2b032014-12-09 18:11:36 +00002541 MaybeRecordStat(MethodCompilationStat::kNotCompiledCantAccesType);
Nicolas Geoffray424f6762014-11-03 14:51:25 +00002542 return false;
2543 }
Nicolas Geoffrayd5111bf2015-05-22 15:37:09 +01002544 current_block_->AddInstruction(new (arena_) HLoadClass(
Nicolas Geoffray76b1e172015-05-27 17:18:33 +01002545 graph_->GetCurrentMethod(),
Nicolas Geoffrayd5111bf2015-05-22 15:37:09 +01002546 type_index,
2547 *dex_compilation_unit_->GetDexFile(),
2548 IsOutermostCompilingClass(type_index),
2549 dex_pc));
Nicolas Geoffray424f6762014-11-03 14:51:25 +00002550 UpdateLocal(instruction.VRegA_21c(), current_block_->GetLastInstruction());
2551 break;
2552 }
2553
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +00002554 case Instruction::MOVE_EXCEPTION: {
2555 current_block_->AddInstruction(new (arena_) HLoadException());
2556 UpdateLocal(instruction.VRegA_11x(), current_block_->GetLastInstruction());
David Brazdilcb1c0552015-08-04 16:22:25 +01002557 current_block_->AddInstruction(new (arena_) HClearException());
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +00002558 break;
2559 }
2560
2561 case Instruction::THROW: {
2562 HInstruction* exception = LoadLocal(instruction.VRegA_11x(), Primitive::kPrimNot);
Calin Juravle225ff812014-11-13 16:46:39 +00002563 current_block_->AddInstruction(new (arena_) HThrow(exception, dex_pc));
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +00002564 // A throw instruction must branch to the exit block.
2565 current_block_->AddSuccessor(exit_block_);
2566 // We finished building this block. Set the current block to null to avoid
2567 // adding dead instructions to it.
2568 current_block_ = nullptr;
2569 break;
2570 }
2571
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00002572 case Instruction::INSTANCE_OF: {
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00002573 uint8_t destination = instruction.VRegA_22c();
2574 uint8_t reference = instruction.VRegB_22c();
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00002575 uint16_t type_index = instruction.VRegC_22c();
Calin Juravle225ff812014-11-13 16:46:39 +00002576 if (!BuildTypeCheck(instruction, destination, reference, type_index, dex_pc)) {
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00002577 return false;
2578 }
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00002579 break;
2580 }
2581
2582 case Instruction::CHECK_CAST: {
2583 uint8_t reference = instruction.VRegA_21c();
2584 uint16_t type_index = instruction.VRegB_21c();
Calin Juravle225ff812014-11-13 16:46:39 +00002585 if (!BuildTypeCheck(instruction, -1, reference, type_index, dex_pc)) {
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00002586 return false;
2587 }
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00002588 break;
2589 }
2590
Nicolas Geoffrayb7baf5c2014-11-11 16:29:44 +00002591 case Instruction::MONITOR_ENTER: {
2592 current_block_->AddInstruction(new (arena_) HMonitorOperation(
2593 LoadLocal(instruction.VRegA_11x(), Primitive::kPrimNot),
2594 HMonitorOperation::kEnter,
Calin Juravle225ff812014-11-13 16:46:39 +00002595 dex_pc));
Nicolas Geoffrayb7baf5c2014-11-11 16:29:44 +00002596 break;
2597 }
2598
2599 case Instruction::MONITOR_EXIT: {
2600 current_block_->AddInstruction(new (arena_) HMonitorOperation(
2601 LoadLocal(instruction.VRegA_11x(), Primitive::kPrimNot),
2602 HMonitorOperation::kExit,
Calin Juravle225ff812014-11-13 16:46:39 +00002603 dex_pc));
Nicolas Geoffrayb7baf5c2014-11-11 16:29:44 +00002604 break;
2605 }
2606
Andreas Gamped881df52014-11-24 23:28:39 -08002607 case Instruction::PACKED_SWITCH: {
Calin Juravle48c2b032014-12-09 18:11:36 +00002608 BuildPackedSwitch(instruction, dex_pc);
Andreas Gamped881df52014-11-24 23:28:39 -08002609 break;
2610 }
2611
Andreas Gampee4d4d322014-12-04 09:09:57 -08002612 case Instruction::SPARSE_SWITCH: {
Calin Juravle48c2b032014-12-09 18:11:36 +00002613 BuildSparseSwitch(instruction, dex_pc);
Andreas Gampee4d4d322014-12-04 09:09:57 -08002614 break;
2615 }
2616
Nicolas Geoffray818f2102014-02-18 16:43:35 +00002617 default:
Calin Juravle48c2b032014-12-09 18:11:36 +00002618 VLOG(compiler) << "Did not compile "
2619 << PrettyMethod(dex_compilation_unit_->GetDexMethodIndex(), *dex_file_)
2620 << " because of unhandled instruction "
2621 << instruction.Name();
2622 MaybeRecordStat(MethodCompilationStat::kNotCompiledUnhandledInstruction);
Nicolas Geoffray818f2102014-02-18 16:43:35 +00002623 return false;
2624 }
2625 return true;
Nicolas Geoffraydadf3172014-11-07 16:36:02 +00002626} // NOLINT(readability/fn_size)
Nicolas Geoffray818f2102014-02-18 16:43:35 +00002627
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00002628HLocal* HGraphBuilder::GetLocalAt(int register_index) const {
2629 return locals_.Get(register_index);
2630}
2631
2632void HGraphBuilder::UpdateLocal(int register_index, HInstruction* instruction) const {
2633 HLocal* local = GetLocalAt(register_index);
2634 current_block_->AddInstruction(new (arena_) HStoreLocal(local, instruction));
2635}
2636
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002637HInstruction* HGraphBuilder::LoadLocal(int register_index, Primitive::Type type) const {
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00002638 HLocal* local = GetLocalAt(register_index);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002639 current_block_->AddInstruction(new (arena_) HLoadLocal(local, type));
Nicolas Geoffray787c3072014-03-17 10:20:19 +00002640 return current_block_->GetLastInstruction();
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00002641}
2642
Nicolas Geoffray818f2102014-02-18 16:43:35 +00002643} // namespace art