blob: 6831e9b6aa56e0abc1c80756f1c43e1c9475ca15 [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"
Vladimir Marko58155012015-08-19 12:49:41 +000034#include "utils/dex_cache_arrays_layout-inl.h"
Nicolas Geoffray818f2102014-02-18 16:43:35 +000035
36namespace art {
37
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +010038/**
39 * Helper class to add HTemporary instructions. This class is used when
40 * converting a DEX instruction to multiple HInstruction, and where those
41 * instructions do not die at the following instruction, but instead spans
42 * multiple instructions.
43 */
44class Temporaries : public ValueObject {
45 public:
Calin Juravlef97f9fb2014-11-11 15:38:19 +000046 explicit Temporaries(HGraph* graph) : graph_(graph), index_(0) {}
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +010047
48 void Add(HInstruction* instruction) {
Yevgeny Rouban3ecfd652015-09-07 17:57:00 +060049 HInstruction* temp = new (graph_->GetArena()) HTemporary(index_, instruction->GetDexPc());
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +010050 instruction->GetBlock()->AddInstruction(temp);
Calin Juravlef97f9fb2014-11-11 15:38:19 +000051
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +010052 DCHECK(temp->GetPrevious() == instruction);
Calin Juravlef97f9fb2014-11-11 15:38:19 +000053
54 size_t offset;
55 if (instruction->GetType() == Primitive::kPrimLong
56 || instruction->GetType() == Primitive::kPrimDouble) {
57 offset = 2;
58 } else {
59 offset = 1;
60 }
61 index_ += offset;
62
63 graph_->UpdateTemporariesVRegSlots(index_);
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +010064 }
65
66 private:
67 HGraph* const graph_;
68
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +010069 // Current index in the temporary stack, updated by `Add`.
70 size_t index_;
71};
72
Andreas Gamped881df52014-11-24 23:28:39 -080073class SwitchTable : public ValueObject {
74 public:
75 SwitchTable(const Instruction& instruction, uint32_t dex_pc, bool sparse)
76 : instruction_(instruction), dex_pc_(dex_pc), sparse_(sparse) {
77 int32_t table_offset = instruction.VRegB_31t();
78 const uint16_t* table = reinterpret_cast<const uint16_t*>(&instruction) + table_offset;
79 if (sparse) {
80 CHECK_EQ(table[0], static_cast<uint16_t>(Instruction::kSparseSwitchSignature));
81 } else {
82 CHECK_EQ(table[0], static_cast<uint16_t>(Instruction::kPackedSwitchSignature));
83 }
84 num_entries_ = table[1];
85 values_ = reinterpret_cast<const int32_t*>(&table[2]);
86 }
87
88 uint16_t GetNumEntries() const {
89 return num_entries_;
90 }
91
Andreas Gampee4d4d322014-12-04 09:09:57 -080092 void CheckIndex(size_t index) const {
93 if (sparse_) {
94 // In a sparse table, we have num_entries_ keys and num_entries_ values, in that order.
95 DCHECK_LT(index, 2 * static_cast<size_t>(num_entries_));
96 } else {
97 // In a packed table, we have the starting key and num_entries_ values.
98 DCHECK_LT(index, 1 + static_cast<size_t>(num_entries_));
99 }
100 }
101
Andreas Gamped881df52014-11-24 23:28:39 -0800102 int32_t GetEntryAt(size_t index) const {
Andreas Gampee4d4d322014-12-04 09:09:57 -0800103 CheckIndex(index);
Andreas Gamped881df52014-11-24 23:28:39 -0800104 return values_[index];
105 }
106
107 uint32_t GetDexPcForIndex(size_t index) const {
Andreas Gampee4d4d322014-12-04 09:09:57 -0800108 CheckIndex(index);
Andreas Gamped881df52014-11-24 23:28:39 -0800109 return dex_pc_ +
110 (reinterpret_cast<const int16_t*>(values_ + index) -
111 reinterpret_cast<const int16_t*>(&instruction_));
112 }
113
Andreas Gampee4d4d322014-12-04 09:09:57 -0800114 // Index of the first value in the table.
115 size_t GetFirstValueIndex() const {
116 if (sparse_) {
117 // In a sparse table, we have num_entries_ keys and num_entries_ values, in that order.
118 return num_entries_;
119 } else {
120 // In a packed table, we have the starting key and num_entries_ values.
121 return 1;
122 }
123 }
124
Andreas Gamped881df52014-11-24 23:28:39 -0800125 private:
126 const Instruction& instruction_;
127 const uint32_t dex_pc_;
128
129 // Whether this is a sparse-switch table (or a packed-switch one).
130 const bool sparse_;
131
132 // This can't be const as it needs to be computed off of the given instruction, and complicated
133 // expressions in the initializer list seemed very ugly.
134 uint16_t num_entries_;
135
136 const int32_t* values_;
137
138 DISALLOW_COPY_AND_ASSIGN(SwitchTable);
139};
140
Nicolas Geoffrayf583e592014-04-07 13:20:42 +0100141void HGraphBuilder::InitializeLocals(uint16_t count) {
142 graph_->SetNumberOfVRegs(count);
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +0000143 locals_.SetSize(count);
144 for (int i = 0; i < count; i++) {
145 HLocal* local = new (arena_) HLocal(i);
146 entry_block_->AddInstruction(local);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000147 locals_.Put(i, local);
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +0000148 }
149}
150
Nicolas Geoffray52e832b2014-11-06 15:15:31 +0000151void HGraphBuilder::InitializeParameters(uint16_t number_of_parameters) {
Nicolas Geoffrayf583e592014-04-07 13:20:42 +0100152 // dex_compilation_unit_ is null only when unit testing.
153 if (dex_compilation_unit_ == nullptr) {
Nicolas Geoffray52e832b2014-11-06 15:15:31 +0000154 return;
Nicolas Geoffrayf583e592014-04-07 13:20:42 +0100155 }
156
157 graph_->SetNumberOfInVRegs(number_of_parameters);
158 const char* shorty = dex_compilation_unit_->GetShorty();
159 int locals_index = locals_.Size() - number_of_parameters;
Nicolas Geoffrayf583e592014-04-07 13:20:42 +0100160 int parameter_index = 0;
161
162 if (!dex_compilation_unit_->IsStatic()) {
163 // Add the implicit 'this' argument, not expressed in the signature.
Yevgeny Rouban3ecfd652015-09-07 17:57:00 +0600164 HParameterValue* parameter = new (arena_) HParameterValue(parameter_index++,
165 Primitive::kPrimNot,
166 true);
Nicolas Geoffrayb55f8352014-04-07 15:26:35 +0100167 entry_block_->AddInstruction(parameter);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +0100168 HLocal* local = GetLocalAt(locals_index++);
Yevgeny Rouban3ecfd652015-09-07 17:57:00 +0600169 entry_block_->AddInstruction(new (arena_) HStoreLocal(local, parameter, local->GetDexPc()));
Nicolas Geoffrayf583e592014-04-07 13:20:42 +0100170 number_of_parameters--;
171 }
172
173 uint32_t pos = 1;
174 for (int i = 0; i < number_of_parameters; i++) {
Yevgeny Rouban3ecfd652015-09-07 17:57:00 +0600175 HParameterValue* parameter = new (arena_) HParameterValue(parameter_index++,
176 Primitive::GetType(shorty[pos++]),
177 false);
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100178 entry_block_->AddInstruction(parameter);
179 HLocal* local = GetLocalAt(locals_index++);
180 // Store the parameter value in the local that the dex code will use
181 // to reference that parameter.
Yevgeny Rouban3ecfd652015-09-07 17:57:00 +0600182 entry_block_->AddInstruction(new (arena_) HStoreLocal(local, parameter, local->GetDexPc()));
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100183 bool is_wide = (parameter->GetType() == Primitive::kPrimLong)
184 || (parameter->GetType() == Primitive::kPrimDouble);
185 if (is_wide) {
186 i++;
187 locals_index++;
188 parameter_index++;
Nicolas Geoffrayf583e592014-04-07 13:20:42 +0100189 }
190 }
Nicolas Geoffrayf583e592014-04-07 13:20:42 +0100191}
192
Nicolas Geoffrayb55f8352014-04-07 15:26:35 +0100193template<typename T>
Calin Juravle225ff812014-11-13 16:46:39 +0000194void HGraphBuilder::If_22t(const Instruction& instruction, uint32_t dex_pc) {
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000195 int32_t target_offset = instruction.GetTargetOffset();
David Brazdil852eaff2015-02-02 15:23:05 +0000196 HBasicBlock* branch_target = FindBlockStartingAt(dex_pc + target_offset);
197 HBasicBlock* fallthrough_target = FindBlockStartingAt(dex_pc + instruction.SizeInCodeUnits());
198 DCHECK(branch_target != nullptr);
199 DCHECK(fallthrough_target != nullptr);
200 PotentiallyAddSuspendCheck(branch_target, dex_pc);
Yevgeny Rouban3ecfd652015-09-07 17:57:00 +0600201 HInstruction* first = LoadLocal(instruction.VRegA(), Primitive::kPrimInt, dex_pc);
202 HInstruction* second = LoadLocal(instruction.VRegB(), Primitive::kPrimInt, dex_pc);
203 T* comparison = new (arena_) T(first, second, dex_pc);
Dave Allison20dfc792014-06-16 20:44:29 -0700204 current_block_->AddInstruction(comparison);
Yevgeny Rouban3ecfd652015-09-07 17:57:00 +0600205 HInstruction* ifinst = new (arena_) HIf(comparison, dex_pc);
Dave Allison20dfc792014-06-16 20:44:29 -0700206 current_block_->AddInstruction(ifinst);
David Brazdil852eaff2015-02-02 15:23:05 +0000207 current_block_->AddSuccessor(branch_target);
208 current_block_->AddSuccessor(fallthrough_target);
Dave Allison20dfc792014-06-16 20:44:29 -0700209 current_block_ = nullptr;
210}
211
212template<typename T>
Calin Juravle225ff812014-11-13 16:46:39 +0000213void HGraphBuilder::If_21t(const Instruction& instruction, uint32_t dex_pc) {
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000214 int32_t target_offset = instruction.GetTargetOffset();
David Brazdil852eaff2015-02-02 15:23:05 +0000215 HBasicBlock* branch_target = FindBlockStartingAt(dex_pc + target_offset);
216 HBasicBlock* fallthrough_target = FindBlockStartingAt(dex_pc + instruction.SizeInCodeUnits());
217 DCHECK(branch_target != nullptr);
218 DCHECK(fallthrough_target != nullptr);
219 PotentiallyAddSuspendCheck(branch_target, dex_pc);
Yevgeny Rouban3ecfd652015-09-07 17:57:00 +0600220 HInstruction* value = LoadLocal(instruction.VRegA(), Primitive::kPrimInt, dex_pc);
221 T* comparison = new (arena_) T(value, graph_->GetIntConstant(0, dex_pc), dex_pc);
Dave Allison20dfc792014-06-16 20:44:29 -0700222 current_block_->AddInstruction(comparison);
Yevgeny Rouban3ecfd652015-09-07 17:57:00 +0600223 HInstruction* ifinst = new (arena_) HIf(comparison, dex_pc);
Dave Allison20dfc792014-06-16 20:44:29 -0700224 current_block_->AddInstruction(ifinst);
David Brazdil852eaff2015-02-02 15:23:05 +0000225 current_block_->AddSuccessor(branch_target);
226 current_block_->AddSuccessor(fallthrough_target);
Nicolas Geoffrayb55f8352014-04-07 15:26:35 +0100227 current_block_ = nullptr;
228}
229
Calin Juravle48c2b032014-12-09 18:11:36 +0000230void HGraphBuilder::MaybeRecordStat(MethodCompilationStat compilation_stat) {
231 if (compilation_stats_ != nullptr) {
232 compilation_stats_->RecordStat(compilation_stat);
233 }
234}
235
David Brazdil1b498722015-03-31 11:37:18 +0100236bool HGraphBuilder::SkipCompilation(const DexFile::CodeItem& code_item,
Calin Juravle48c2b032014-12-09 18:11:36 +0000237 size_t number_of_branches) {
238 const CompilerOptions& compiler_options = compiler_driver_->GetCompilerOptions();
Nicolas Geoffray43a539f2014-12-02 10:19:51 +0000239 CompilerOptions::CompilerFilter compiler_filter = compiler_options.GetCompilerFilter();
240 if (compiler_filter == CompilerOptions::kEverything) {
241 return false;
242 }
243
David Brazdil1b498722015-03-31 11:37:18 +0100244 if (compiler_options.IsHugeMethod(code_item.insns_size_in_code_units_)) {
Calin Juravle48c2b032014-12-09 18:11:36 +0000245 VLOG(compiler) << "Skip compilation of huge method "
246 << PrettyMethod(dex_compilation_unit_->GetDexMethodIndex(), *dex_file_)
David Brazdil1b498722015-03-31 11:37:18 +0100247 << ": " << code_item.insns_size_in_code_units_ << " code units";
Calin Juravle48c2b032014-12-09 18:11:36 +0000248 MaybeRecordStat(MethodCompilationStat::kNotCompiledHugeMethod);
Nicolas Geoffray43a539f2014-12-02 10:19:51 +0000249 return true;
250 }
251
252 // If it's large and contains no branches, it's likely to be machine generated initialization.
David Brazdil1b498722015-03-31 11:37:18 +0100253 if (compiler_options.IsLargeMethod(code_item.insns_size_in_code_units_)
254 && (number_of_branches == 0)) {
Calin Juravle48c2b032014-12-09 18:11:36 +0000255 VLOG(compiler) << "Skip compilation of large method with no branch "
256 << PrettyMethod(dex_compilation_unit_->GetDexMethodIndex(), *dex_file_)
David Brazdil1b498722015-03-31 11:37:18 +0100257 << ": " << code_item.insns_size_in_code_units_ << " code units";
Calin Juravle48c2b032014-12-09 18:11:36 +0000258 MaybeRecordStat(MethodCompilationStat::kNotCompiledLargeMethodNoBranches);
Nicolas Geoffray43a539f2014-12-02 10:19:51 +0000259 return true;
260 }
261
262 return false;
263}
264
David Brazdilbff75032015-07-08 17:26:51 +0000265static const DexFile::TryItem* GetTryItem(HBasicBlock* block,
266 const DexFile::CodeItem& code_item,
267 const ArenaBitVector& can_block_throw) {
268 DCHECK(!block->IsSingleTryBoundary());
269
270 // Block does not contain throwing instructions. Even if it is covered by
271 // a TryItem, we will consider it not in a try block.
272 if (!can_block_throw.IsBitSet(block->GetBlockId())) {
273 return nullptr;
274 }
275
276 // Instructions in the block may throw. Find a TryItem covering this block.
277 int32_t try_item_idx = DexFile::FindTryItem(code_item, block->GetDexPc());
David Brazdil6cd788f2015-07-08 16:44:00 +0100278 return (try_item_idx == -1) ? nullptr : DexFile::GetTryItems(code_item, try_item_idx);
David Brazdilfc6a86a2015-06-26 10:33:45 +0000279}
280
281void HGraphBuilder::CreateBlocksForTryCatch(const DexFile::CodeItem& code_item) {
282 if (code_item.tries_size_ == 0) {
283 return;
284 }
285
286 // Create branch targets at the start/end of the TryItem range. These are
287 // places where the program might fall through into/out of the a block and
288 // where TryBoundary instructions will be inserted later. Other edges which
289 // enter/exit the try blocks are a result of branches/switches.
290 for (size_t idx = 0; idx < code_item.tries_size_; ++idx) {
291 const DexFile::TryItem* try_item = DexFile::GetTryItems(code_item, idx);
292 uint32_t dex_pc_start = try_item->start_addr_;
293 uint32_t dex_pc_end = dex_pc_start + try_item->insn_count_;
294 FindOrCreateBlockStartingAt(dex_pc_start);
295 if (dex_pc_end < code_item.insns_size_in_code_units_) {
296 // TODO: Do not create block if the last instruction cannot fall through.
297 FindOrCreateBlockStartingAt(dex_pc_end);
298 } else {
299 // The TryItem spans until the very end of the CodeItem (or beyond if
300 // invalid) and therefore cannot have any code afterwards.
301 }
302 }
303
304 // Create branch targets for exception handlers.
305 const uint8_t* handlers_ptr = DexFile::GetCatchHandlerData(code_item, 0);
306 uint32_t handlers_size = DecodeUnsignedLeb128(&handlers_ptr);
307 for (uint32_t idx = 0; idx < handlers_size; ++idx) {
308 CatchHandlerIterator iterator(handlers_ptr);
309 for (; iterator.HasNext(); iterator.Next()) {
310 uint32_t address = iterator.GetHandlerAddress();
311 HBasicBlock* block = FindOrCreateBlockStartingAt(address);
David Brazdilec16f792015-08-19 15:04:01 +0100312 block->SetTryCatchInformation(
313 new (arena_) TryCatchInformation(iterator.GetHandlerTypeIndex(), *dex_file_));
David Brazdilfc6a86a2015-06-26 10:33:45 +0000314 }
315 handlers_ptr = iterator.EndDataPointer();
316 }
317}
318
David Brazdil56e1acc2015-06-30 15:41:36 +0100319void HGraphBuilder::SplitTryBoundaryEdge(HBasicBlock* predecessor,
320 HBasicBlock* successor,
321 HTryBoundary::BoundaryKind kind,
322 const DexFile::CodeItem& code_item,
323 const DexFile::TryItem& try_item) {
324 // Split the edge with a single TryBoundary instruction.
Yevgeny Rouban3ecfd652015-09-07 17:57:00 +0600325 HTryBoundary* try_boundary = new (arena_) HTryBoundary(kind, successor->GetDexPc());
David Brazdil56e1acc2015-06-30 15:41:36 +0100326 HBasicBlock* try_entry_block = graph_->SplitEdge(predecessor, successor);
327 try_entry_block->AddInstruction(try_boundary);
328
329 // Link the TryBoundary to the handlers of `try_item`.
330 for (CatchHandlerIterator it(code_item, try_item); it.HasNext(); it.Next()) {
331 try_boundary->AddExceptionHandler(FindBlockStartingAt(it.GetHandlerAddress()));
332 }
333}
334
David Brazdilfc6a86a2015-06-26 10:33:45 +0000335void HGraphBuilder::InsertTryBoundaryBlocks(const DexFile::CodeItem& code_item) {
336 if (code_item.tries_size_ == 0) {
337 return;
338 }
339
David Brazdil72783ff2015-07-09 14:36:05 +0100340 // Bit vector stores information on which blocks contain throwing instructions.
341 // Must be expandable because catch blocks may be split into two.
Vladimir Markofa6b93c2015-09-15 10:15:55 +0100342 ArenaBitVector can_block_throw(arena_, graph_->GetBlocks().size(), /* expandable */ true);
David Brazdilbff75032015-07-08 17:26:51 +0000343
344 // Scan blocks and mark those which contain throwing instructions.
Vladimir Markofa6b93c2015-09-15 10:15:55 +0100345 for (HBasicBlock* block : graph_->GetBlocks()) {
David Brazdil72783ff2015-07-09 14:36:05 +0100346 bool can_throw = false;
David Brazdilbff75032015-07-08 17:26:51 +0000347 for (HInstructionIterator insn(block->GetInstructions()); !insn.Done(); insn.Advance()) {
348 if (insn.Current()->CanThrow()) {
David Brazdil72783ff2015-07-09 14:36:05 +0100349 can_throw = true;
David Brazdilbff75032015-07-08 17:26:51 +0000350 break;
351 }
352 }
David Brazdil72783ff2015-07-09 14:36:05 +0100353
354 if (can_throw) {
355 if (block->IsCatchBlock()) {
356 // Catch blocks are always considered an entry point into the TryItem in
357 // order to avoid splitting exceptional edges. We split the block after
358 // the move-exception (if present) and mark the first part non-throwing.
359 // Later on, a TryBoundary will be inserted between the two blocks.
360 HInstruction* first_insn = block->GetFirstInstruction();
361 if (first_insn->IsLoadException()) {
362 // Catch block starts with a LoadException. Split the block after the
David Brazdilcb1c0552015-08-04 16:22:25 +0100363 // StoreLocal and ClearException which must come after the load.
David Brazdil72783ff2015-07-09 14:36:05 +0100364 DCHECK(first_insn->GetNext()->IsStoreLocal());
David Brazdilcb1c0552015-08-04 16:22:25 +0100365 DCHECK(first_insn->GetNext()->GetNext()->IsClearException());
366 block = block->SplitBefore(first_insn->GetNext()->GetNext()->GetNext());
David Brazdil72783ff2015-07-09 14:36:05 +0100367 } else {
368 // Catch block does not load the exception. Split at the beginning to
369 // create an empty catch block.
370 block = block->SplitBefore(first_insn);
371 }
372 }
373 can_block_throw.SetBit(block->GetBlockId());
374 }
David Brazdilbff75032015-07-08 17:26:51 +0000375 }
376
David Brazdil281a6322015-07-03 10:34:57 +0100377 // Iterate over all blocks, find those covered by some TryItem and:
378 // (a) split edges which enter/exit the try range,
379 // (b) create TryBoundary instructions in the new blocks,
380 // (c) link the new blocks to corresponding exception handlers.
381 // We cannot iterate only over blocks in `branch_targets_` because switch-case
382 // blocks share the same dex_pc.
Vladimir Markofa6b93c2015-09-15 10:15:55 +0100383 for (HBasicBlock* try_block : graph_->GetBlocks()) {
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.
Vladimir Marko60584552015-09-03 13:35:12 +0000398 for (size_t i = 0; i < try_block->GetPredecessors().size(); ++i) {
399 HBasicBlock* predecessor = try_block->GetPredecessor(i);
David Brazdil72783ff2015-07-09 14:36:05 +0100400 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.
Vladimir Marko60584552015-09-03 13:35:12 +0000426 for (HBasicBlock* successor : try_block->GetSuccessors()) {
David Brazdil281a6322015-07-03 10:34:57 +0100427 if (successor->IsCatchBlock()) {
428 // A catch block is always considered an entry point into its TryItem.
429 // We therefore assume this is an exit point, regardless of whether
430 // the catch block is in a different TryItem or not.
431 } else if (successor->IsSingleTryBoundary()) {
432 // The edge was already split because of an entry into a neighbouring
433 // TryItem. We split it again and insert an exit.
434 if (kIsDebugBuild) {
435 HTryBoundary* last_insn = successor->GetLastInstruction()->AsTryBoundary();
David Brazdilbff75032015-07-08 17:26:51 +0000436 const DexFile::TryItem* successor_try_item =
437 GetTryItem(last_insn->GetNormalFlowSuccessor(), code_item, can_block_throw);
David Brazdil281a6322015-07-03 10:34:57 +0100438 DCHECK_EQ(try_block, successor->GetSinglePredecessor());
439 DCHECK(last_insn->IsEntry());
David Brazdilbff75032015-07-08 17:26:51 +0000440 DCHECK_NE(try_item, successor_try_item);
David Brazdil281a6322015-07-03 10:34:57 +0100441 }
David Brazdilbff75032015-07-08 17:26:51 +0000442 } else if (GetTryItem(successor, code_item, can_block_throw) != try_item) {
David Brazdil281a6322015-07-03 10:34:57 +0100443 // This is an exit out of the TryItem and the edge has not been split
444 // yet. That means that either `successor` is not in a TryItem, or it
445 // is in a different TryItem and we happened to iterate over this
446 // block first. We split the edge and insert an exit.
447 HInstruction* last_instruction = try_block->GetLastInstruction();
448 if (last_instruction->IsReturn() || last_instruction->IsReturnVoid()) {
449 DCHECK_EQ(successor, exit_block_);
450 // Control flow exits the try block with a Return(Void). Because
451 // splitting the edge would invalidate the invariant that Return
452 // always jumps to Exit, we move the Return outside the try block.
453 successor = try_block->SplitBefore(last_instruction);
454 }
455 } else {
456 // Not an edge on the boundary of the try block.
457 continue;
458 }
David Brazdilbff75032015-07-08 17:26:51 +0000459 SplitTryBoundaryEdge(try_block, successor, HTryBoundary::kExit, code_item, *try_item);
David Brazdil281a6322015-07-03 10:34:57 +0100460 }
David Brazdilfc6a86a2015-06-26 10:33:45 +0000461 }
462}
463
David Brazdil5e8b1372015-01-23 14:39:08 +0000464bool HGraphBuilder::BuildGraph(const DexFile::CodeItem& code_item) {
Vladimir Markofa6b93c2015-09-15 10:15:55 +0100465 DCHECK(graph_->GetBlocks().empty());
David Brazdil5e8b1372015-01-23 14:39:08 +0000466
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +0000467 const uint16_t* code_ptr = code_item.insns_;
468 const uint16_t* code_end = code_item.insns_ + code_item.insns_size_in_code_units_;
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +0100469 code_start_ = code_ptr;
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +0000470
Nicolas Geoffraybe9a92a2014-02-25 14:22:56 +0000471 // Setup the graph with the entry block and exit block.
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100472 entry_block_ = new (arena_) HBasicBlock(graph_, 0);
Nicolas Geoffray818f2102014-02-18 16:43:35 +0000473 graph_->AddBlock(entry_block_);
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100474 exit_block_ = new (arena_) HBasicBlock(graph_, kNoDexPc);
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000475 graph_->SetEntryBlock(entry_block_);
476 graph_->SetExitBlock(exit_block_);
Nicolas Geoffray818f2102014-02-18 16:43:35 +0000477
David Brazdil77a48ae2015-09-15 12:34:04 +0000478 graph_->SetHasTryCatch(code_item.tries_size_ != 0);
479
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +0000480 InitializeLocals(code_item.registers_size_);
Nicolas Geoffraye53798a2014-12-01 10:31:54 +0000481 graph_->SetMaximumNumberOfOutVRegs(code_item.outs_size_);
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +0000482
Nicolas Geoffray43a539f2014-12-02 10:19:51 +0000483 // Compute the number of dex instructions, blocks, and branches. We will
484 // check these values against limits given to the compiler.
Nicolas Geoffray43a539f2014-12-02 10:19:51 +0000485 size_t number_of_branches = 0;
486
Nicolas Geoffraybe9a92a2014-02-25 14:22:56 +0000487 // To avoid splitting blocks, we compute ahead of time the instructions that
488 // start a new block, and create these blocks.
Calin Juravle702d2602015-04-30 19:28:21 +0100489 if (!ComputeBranchTargets(code_ptr, code_end, &number_of_branches)) {
490 MaybeRecordStat(MethodCompilationStat::kNotCompiledBranchOutsideMethodCode);
491 return false;
492 }
Nicolas Geoffray43a539f2014-12-02 10:19:51 +0000493
494 // Note that the compiler driver is null when unit testing.
David Brazdil1b498722015-03-31 11:37:18 +0100495 if ((compiler_driver_ != nullptr) && SkipCompilation(code_item, number_of_branches)) {
David Brazdil5e8b1372015-01-23 14:39:08 +0000496 return false;
Nicolas Geoffray43a539f2014-12-02 10:19:51 +0000497 }
Nicolas Geoffray818f2102014-02-18 16:43:35 +0000498
David Brazdilfc6a86a2015-06-26 10:33:45 +0000499 CreateBlocksForTryCatch(code_item);
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +0000500
Nicolas Geoffray52e832b2014-11-06 15:15:31 +0000501 InitializeParameters(code_item.ins_size_);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +0100502
Calin Juravle225ff812014-11-13 16:46:39 +0000503 size_t dex_pc = 0;
Nicolas Geoffray818f2102014-02-18 16:43:35 +0000504 while (code_ptr < code_end) {
Calin Juravle225ff812014-11-13 16:46:39 +0000505 // Update the current block if dex_pc starts a new block.
506 MaybeUpdateCurrentBlock(dex_pc);
Nicolas Geoffray818f2102014-02-18 16:43:35 +0000507 const Instruction& instruction = *Instruction::At(code_ptr);
Calin Juravle48c2b032014-12-09 18:11:36 +0000508 if (!AnalyzeDexInstruction(instruction, dex_pc)) {
David Brazdil5e8b1372015-01-23 14:39:08 +0000509 return false;
Calin Juravle48c2b032014-12-09 18:11:36 +0000510 }
Calin Juravle225ff812014-11-13 16:46:39 +0000511 dex_pc += instruction.SizeInCodeUnits();
Nicolas Geoffray818f2102014-02-18 16:43:35 +0000512 code_ptr += instruction.SizeInCodeUnits();
513 }
514
David Brazdilfc6a86a2015-06-26 10:33:45 +0000515 // Add Exit to the exit block.
David Brazdil3e187382015-06-26 09:59:52 +0000516 exit_block_->AddInstruction(new (arena_) HExit());
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000517 // Add the suspend check to the entry block.
518 entry_block_->AddInstruction(new (arena_) HSuspendCheck(0));
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +0000519 entry_block_->AddInstruction(new (arena_) HGoto());
David Brazdilbff75032015-07-08 17:26:51 +0000520 // Add the exit block at the end.
521 graph_->AddBlock(exit_block_);
David Brazdil5e8b1372015-01-23 14:39:08 +0000522
David Brazdilfc6a86a2015-06-26 10:33:45 +0000523 // Iterate over blocks covered by TryItems and insert TryBoundaries at entry
524 // and exit points. This requires all control-flow instructions and
525 // non-exceptional edges to have been created.
526 InsertTryBoundaryBlocks(code_item);
527
David Brazdil5e8b1372015-01-23 14:39:08 +0000528 return true;
Nicolas Geoffray818f2102014-02-18 16:43:35 +0000529}
530
David Brazdilfc6a86a2015-06-26 10:33:45 +0000531void HGraphBuilder::MaybeUpdateCurrentBlock(size_t dex_pc) {
532 HBasicBlock* block = FindBlockStartingAt(dex_pc);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000533 if (block == nullptr) {
534 return;
535 }
Nicolas Geoffraybe9a92a2014-02-25 14:22:56 +0000536
537 if (current_block_ != nullptr) {
538 // Branching instructions clear current_block, so we know
539 // the last instruction of the current block is not a branching
540 // instruction. We add an unconditional goto to the found block.
Yevgeny Rouban3ecfd652015-09-07 17:57:00 +0600541 current_block_->AddInstruction(new (arena_) HGoto(dex_pc));
Nicolas Geoffraybe9a92a2014-02-25 14:22:56 +0000542 current_block_->AddSuccessor(block);
543 }
544 graph_->AddBlock(block);
545 current_block_ = block;
546}
547
Calin Juravle702d2602015-04-30 19:28:21 +0100548bool HGraphBuilder::ComputeBranchTargets(const uint16_t* code_ptr,
Nicolas Geoffray43a539f2014-12-02 10:19:51 +0000549 const uint16_t* code_end,
Nicolas Geoffray43a539f2014-12-02 10:19:51 +0000550 size_t* number_of_branches) {
Nicolas Geoffraybe9a92a2014-02-25 14:22:56 +0000551 branch_targets_.SetSize(code_end - code_ptr);
552
553 // Create the first block for the dex instructions, single successor of the entry block.
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100554 HBasicBlock* block = new (arena_) HBasicBlock(graph_, 0);
Nicolas Geoffraybe9a92a2014-02-25 14:22:56 +0000555 branch_targets_.Put(0, block);
556 entry_block_->AddSuccessor(block);
557
558 // Iterate over all instructions and find branching instructions. Create blocks for
559 // the locations these instructions branch to.
Andreas Gamped881df52014-11-24 23:28:39 -0800560 uint32_t dex_pc = 0;
Nicolas Geoffraybe9a92a2014-02-25 14:22:56 +0000561 while (code_ptr < code_end) {
562 const Instruction& instruction = *Instruction::At(code_ptr);
563 if (instruction.IsBranch()) {
Nicolas Geoffray43a539f2014-12-02 10:19:51 +0000564 (*number_of_branches)++;
Calin Juravle225ff812014-11-13 16:46:39 +0000565 int32_t target = instruction.GetTargetOffset() + dex_pc;
Nicolas Geoffraybe9a92a2014-02-25 14:22:56 +0000566 // Create a block for the target instruction.
David Brazdilfc6a86a2015-06-26 10:33:45 +0000567 FindOrCreateBlockStartingAt(target);
568
Calin Juravle225ff812014-11-13 16:46:39 +0000569 dex_pc += instruction.SizeInCodeUnits();
Nicolas Geoffraybe9a92a2014-02-25 14:22:56 +0000570 code_ptr += instruction.SizeInCodeUnits();
Calin Juravle702d2602015-04-30 19:28:21 +0100571
David Brazdilfe659462015-06-24 14:23:56 +0100572 if (instruction.CanFlowThrough()) {
573 if (code_ptr >= code_end) {
Calin Juravle702d2602015-04-30 19:28:21 +0100574 // In the normal case we should never hit this but someone can artificially forge a dex
575 // file to fall-through out the method code. In this case we bail out compilation.
576 return false;
David Brazdilfc6a86a2015-06-26 10:33:45 +0000577 } else {
578 FindOrCreateBlockStartingAt(dex_pc);
Calin Juravle702d2602015-04-30 19:28:21 +0100579 }
Nicolas Geoffraybe9a92a2014-02-25 14:22:56 +0000580 }
Andreas Gampee4d4d322014-12-04 09:09:57 -0800581 } else if (instruction.IsSwitch()) {
582 SwitchTable table(instruction, dex_pc, instruction.Opcode() == Instruction::SPARSE_SWITCH);
Andreas Gamped881df52014-11-24 23:28:39 -0800583
584 uint16_t num_entries = table.GetNumEntries();
585
Andreas Gampee4d4d322014-12-04 09:09:57 -0800586 // In a packed-switch, the entry at index 0 is the starting key. In a sparse-switch, the
587 // entry at index 0 is the first key, and values are after *all* keys.
588 size_t offset = table.GetFirstValueIndex();
589
590 // Use a larger loop counter type to avoid overflow issues.
591 for (size_t i = 0; i < num_entries; ++i) {
Andreas Gamped881df52014-11-24 23:28:39 -0800592 // The target of the case.
Andreas Gampee4d4d322014-12-04 09:09:57 -0800593 uint32_t target = dex_pc + table.GetEntryAt(i + offset);
David Brazdilfc6a86a2015-06-26 10:33:45 +0000594 FindOrCreateBlockStartingAt(target);
Andreas Gamped881df52014-11-24 23:28:39 -0800595
David Brazdil281a6322015-07-03 10:34:57 +0100596 // Create a block for the switch-case logic. The block gets the dex_pc
597 // of the SWITCH instruction because it is part of its semantics.
598 block = new (arena_) HBasicBlock(graph_, dex_pc);
599 branch_targets_.Put(table.GetDexPcForIndex(i), block);
Andreas Gamped881df52014-11-24 23:28:39 -0800600 }
601
602 // Fall-through. Add a block if there is more code afterwards.
603 dex_pc += instruction.SizeInCodeUnits();
604 code_ptr += instruction.SizeInCodeUnits();
Calin Juravle702d2602015-04-30 19:28:21 +0100605 if (code_ptr >= code_end) {
606 // In the normal case we should never hit this but someone can artificially forge a dex
607 // file to fall-through out the method code. In this case we bail out compilation.
608 // (A switch can fall-through so we don't need to check CanFlowThrough().)
609 return false;
David Brazdilfc6a86a2015-06-26 10:33:45 +0000610 } else {
611 FindOrCreateBlockStartingAt(dex_pc);
Andreas Gamped881df52014-11-24 23:28:39 -0800612 }
Nicolas Geoffraybe9a92a2014-02-25 14:22:56 +0000613 } else {
614 code_ptr += instruction.SizeInCodeUnits();
Calin Juravle225ff812014-11-13 16:46:39 +0000615 dex_pc += instruction.SizeInCodeUnits();
Nicolas Geoffraybe9a92a2014-02-25 14:22:56 +0000616 }
617 }
Calin Juravle702d2602015-04-30 19:28:21 +0100618 return true;
Nicolas Geoffraybe9a92a2014-02-25 14:22:56 +0000619}
620
David Brazdilfc6a86a2015-06-26 10:33:45 +0000621HBasicBlock* HGraphBuilder::FindBlockStartingAt(int32_t dex_pc) const {
622 DCHECK_GE(dex_pc, 0);
623 DCHECK_LT(static_cast<size_t>(dex_pc), branch_targets_.Size());
624 return branch_targets_.Get(dex_pc);
625}
626
627HBasicBlock* HGraphBuilder::FindOrCreateBlockStartingAt(int32_t dex_pc) {
628 HBasicBlock* block = FindBlockStartingAt(dex_pc);
629 if (block == nullptr) {
630 block = new (arena_) HBasicBlock(graph_, dex_pc);
631 branch_targets_.Put(dex_pc, block);
632 }
633 return block;
Nicolas Geoffraybe9a92a2014-02-25 14:22:56 +0000634}
635
Nicolas Geoffrayf583e592014-04-07 13:20:42 +0100636template<typename T>
Yevgeny Rouban3ecfd652015-09-07 17:57:00 +0600637void HGraphBuilder::Unop_12x(const Instruction& instruction,
638 Primitive::Type type,
639 uint32_t dex_pc) {
640 HInstruction* first = LoadLocal(instruction.VRegB(), type, dex_pc);
641 current_block_->AddInstruction(new (arena_) T(type, first, dex_pc));
642 UpdateLocal(instruction.VRegA(), current_block_->GetLastInstruction(), dex_pc);
Roland Levillain88cb1752014-10-20 16:36:47 +0100643}
644
Roland Levillaindff1f282014-11-05 14:15:05 +0000645void HGraphBuilder::Conversion_12x(const Instruction& instruction,
646 Primitive::Type input_type,
Roland Levillain624279f2014-12-04 11:54:28 +0000647 Primitive::Type result_type,
648 uint32_t dex_pc) {
Yevgeny Rouban3ecfd652015-09-07 17:57:00 +0600649 HInstruction* first = LoadLocal(instruction.VRegB(), input_type, dex_pc);
Roland Levillain624279f2014-12-04 11:54:28 +0000650 current_block_->AddInstruction(new (arena_) HTypeConversion(result_type, first, dex_pc));
Yevgeny Rouban3ecfd652015-09-07 17:57:00 +0600651 UpdateLocal(instruction.VRegA(), current_block_->GetLastInstruction(), dex_pc);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +0100652}
653
654template<typename T>
Calin Juravled6fb6cf2014-11-11 19:07:44 +0000655void HGraphBuilder::Binop_23x(const Instruction& instruction,
656 Primitive::Type type,
657 uint32_t dex_pc) {
Yevgeny Rouban3ecfd652015-09-07 17:57:00 +0600658 HInstruction* first = LoadLocal(instruction.VRegB(), type, dex_pc);
659 HInstruction* second = LoadLocal(instruction.VRegC(), type, dex_pc);
Calin Juravled6fb6cf2014-11-11 19:07:44 +0000660 current_block_->AddInstruction(new (arena_) T(type, first, second, dex_pc));
Yevgeny Rouban3ecfd652015-09-07 17:57:00 +0600661 UpdateLocal(instruction.VRegA(), current_block_->GetLastInstruction(), dex_pc);
Calin Juravled6fb6cf2014-11-11 19:07:44 +0000662}
663
664template<typename T>
Calin Juravle9aec02f2014-11-18 23:06:35 +0000665void HGraphBuilder::Binop_23x_shift(const Instruction& instruction,
Yevgeny Rouban3ecfd652015-09-07 17:57:00 +0600666 Primitive::Type type,
667 uint32_t dex_pc) {
668 HInstruction* first = LoadLocal(instruction.VRegB(), type, dex_pc);
669 HInstruction* second = LoadLocal(instruction.VRegC(), Primitive::kPrimInt, dex_pc);
670 current_block_->AddInstruction(new (arena_) T(type, first, second, dex_pc));
671 UpdateLocal(instruction.VRegA(), current_block_->GetLastInstruction(), dex_pc);
Calin Juravle9aec02f2014-11-18 23:06:35 +0000672}
673
Calin Juravleddb7df22014-11-25 20:56:51 +0000674void HGraphBuilder::Binop_23x_cmp(const Instruction& instruction,
675 Primitive::Type type,
Mark Mendellc4701932015-04-10 13:18:51 -0400676 ComparisonBias bias,
Alexey Frunze4dda3372015-06-01 18:31:49 -0700677 uint32_t dex_pc) {
Yevgeny Rouban3ecfd652015-09-07 17:57:00 +0600678 HInstruction* first = LoadLocal(instruction.VRegB(), type, dex_pc);
679 HInstruction* second = LoadLocal(instruction.VRegC(), type, dex_pc);
Alexey Frunze4dda3372015-06-01 18:31:49 -0700680 current_block_->AddInstruction(new (arena_) HCompare(type, first, second, bias, dex_pc));
Yevgeny Rouban3ecfd652015-09-07 17:57:00 +0600681 UpdateLocal(instruction.VRegA(), current_block_->GetLastInstruction(), dex_pc);
Calin Juravleddb7df22014-11-25 20:56:51 +0000682}
683
Calin Juravle9aec02f2014-11-18 23:06:35 +0000684template<typename T>
Yevgeny Rouban3ecfd652015-09-07 17:57:00 +0600685void HGraphBuilder::Binop_12x_shift(const Instruction& instruction, Primitive::Type type,
686 uint32_t dex_pc) {
687 HInstruction* first = LoadLocal(instruction.VRegA(), type, dex_pc);
688 HInstruction* second = LoadLocal(instruction.VRegB(), Primitive::kPrimInt, dex_pc);
689 current_block_->AddInstruction(new (arena_) T(type, first, second, dex_pc));
690 UpdateLocal(instruction.VRegA(), current_block_->GetLastInstruction(), dex_pc);
Calin Juravle9aec02f2014-11-18 23:06:35 +0000691}
692
693template<typename T>
Calin Juravled6fb6cf2014-11-11 19:07:44 +0000694void HGraphBuilder::Binop_12x(const Instruction& instruction,
695 Primitive::Type type,
696 uint32_t dex_pc) {
Yevgeny Rouban3ecfd652015-09-07 17:57:00 +0600697 HInstruction* first = LoadLocal(instruction.VRegA(), type, dex_pc);
698 HInstruction* second = LoadLocal(instruction.VRegB(), type, dex_pc);
Calin Juravled6fb6cf2014-11-11 19:07:44 +0000699 current_block_->AddInstruction(new (arena_) T(type, first, second, dex_pc));
Yevgeny Rouban3ecfd652015-09-07 17:57:00 +0600700 UpdateLocal(instruction.VRegA(), current_block_->GetLastInstruction(), dex_pc);
Calin Juravled6fb6cf2014-11-11 19:07:44 +0000701}
702
703template<typename T>
Yevgeny Rouban3ecfd652015-09-07 17:57:00 +0600704void HGraphBuilder::Binop_22s(const Instruction& instruction, bool reverse, uint32_t dex_pc) {
705 HInstruction* first = LoadLocal(instruction.VRegB(), Primitive::kPrimInt, dex_pc);
706 HInstruction* second = graph_->GetIntConstant(instruction.VRegC_22s(), dex_pc);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +0100707 if (reverse) {
708 std::swap(first, second);
709 }
Yevgeny Rouban3ecfd652015-09-07 17:57:00 +0600710 current_block_->AddInstruction(new (arena_) T(Primitive::kPrimInt, first, second, dex_pc));
711 UpdateLocal(instruction.VRegA(), current_block_->GetLastInstruction(), dex_pc);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +0100712}
713
714template<typename T>
Yevgeny Rouban3ecfd652015-09-07 17:57:00 +0600715void HGraphBuilder::Binop_22b(const Instruction& instruction, bool reverse, uint32_t dex_pc) {
716 HInstruction* first = LoadLocal(instruction.VRegB(), Primitive::kPrimInt, dex_pc);
717 HInstruction* second = graph_->GetIntConstant(instruction.VRegC_22b(), dex_pc);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +0100718 if (reverse) {
719 std::swap(first, second);
720 }
Yevgeny Rouban3ecfd652015-09-07 17:57:00 +0600721 current_block_->AddInstruction(new (arena_) T(Primitive::kPrimInt, first, second, dex_pc));
722 UpdateLocal(instruction.VRegA(), current_block_->GetLastInstruction(), dex_pc);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +0100723}
724
Calin Juravle0c25d102015-04-20 14:49:09 +0100725static bool RequiresConstructorBarrier(const DexCompilationUnit* cu, const CompilerDriver& driver) {
Calin Juravle27df7582015-04-17 19:12:31 +0100726 Thread* self = Thread::Current();
Calin Juravle0c25d102015-04-20 14:49:09 +0100727 return cu->IsConstructor()
728 && driver.RequiresConstructorBarrier(self, cu->GetDexFile(), cu->GetClassDefIndex());
Calin Juravle27df7582015-04-17 19:12:31 +0100729}
730
Yevgeny Rouban3ecfd652015-09-07 17:57:00 +0600731void HGraphBuilder::BuildReturn(const Instruction& instruction,
732 Primitive::Type type,
733 uint32_t dex_pc) {
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100734 if (type == Primitive::kPrimVoid) {
Calin Juravle3cd4fc82015-05-14 15:15:42 +0100735 if (graph_->ShouldGenerateConstructorBarrier()) {
736 // The compilation unit is null during testing.
737 if (dex_compilation_unit_ != nullptr) {
738 DCHECK(RequiresConstructorBarrier(dex_compilation_unit_, *compiler_driver_))
739 << "Inconsistent use of ShouldGenerateConstructorBarrier. Should not generate a barrier.";
740 }
Yevgeny Rouban3ecfd652015-09-07 17:57:00 +0600741 current_block_->AddInstruction(new (arena_) HMemoryBarrier(kStoreStore, dex_pc));
Calin Juravle27df7582015-04-17 19:12:31 +0100742 }
Yevgeny Rouban3ecfd652015-09-07 17:57:00 +0600743 current_block_->AddInstruction(new (arena_) HReturnVoid(dex_pc));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100744 } else {
Yevgeny Rouban3ecfd652015-09-07 17:57:00 +0600745 HInstruction* value = LoadLocal(instruction.VRegA(), type, dex_pc);
746 current_block_->AddInstruction(new (arena_) HReturn(value, dex_pc));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100747 }
748 current_block_->AddSuccessor(exit_block_);
749 current_block_ = nullptr;
750}
751
Calin Juravle68ad6492015-08-18 17:08:12 +0100752static InvokeType GetInvokeTypeFromOpCode(Instruction::Code opcode) {
753 switch (opcode) {
754 case Instruction::INVOKE_STATIC:
755 case Instruction::INVOKE_STATIC_RANGE:
756 return kStatic;
757 case Instruction::INVOKE_DIRECT:
758 case Instruction::INVOKE_DIRECT_RANGE:
759 return kDirect;
760 case Instruction::INVOKE_VIRTUAL:
761 case Instruction::INVOKE_VIRTUAL_QUICK:
762 case Instruction::INVOKE_VIRTUAL_RANGE:
763 case Instruction::INVOKE_VIRTUAL_RANGE_QUICK:
764 return kVirtual;
765 case Instruction::INVOKE_INTERFACE:
766 case Instruction::INVOKE_INTERFACE_RANGE:
767 return kInterface;
768 case Instruction::INVOKE_SUPER_RANGE:
769 case Instruction::INVOKE_SUPER:
770 return kSuper;
771 default:
772 LOG(FATAL) << "Unexpected invoke opcode: " << opcode;
773 UNREACHABLE();
Nicolas Geoffray2e7cd752015-07-10 11:38:52 +0100774 }
Calin Juravle68ad6492015-08-18 17:08:12 +0100775}
776
777bool HGraphBuilder::BuildInvoke(const Instruction& instruction,
778 uint32_t dex_pc,
779 uint32_t method_idx,
780 uint32_t number_of_vreg_arguments,
781 bool is_range,
782 uint32_t* args,
783 uint32_t register_index) {
784 InvokeType original_invoke_type = GetInvokeTypeFromOpCode(instruction.Opcode());
785 InvokeType optimized_invoke_type = original_invoke_type;
786 const char* descriptor = dex_file_->GetMethodShorty(method_idx);
787 Primitive::Type return_type = Primitive::GetType(descriptor[0]);
788
789 // Remove the return type from the 'proto'.
790 size_t number_of_arguments = strlen(descriptor) - 1;
791 if (original_invoke_type != kStatic) { // instance call
792 // One extra argument for 'this'.
793 number_of_arguments++;
794 }
795
796 MethodReference target_method(dex_file_, method_idx);
Calin Juravle5d01db12015-08-25 15:02:42 +0100797 int32_t table_index = 0;
798 uintptr_t direct_code = 0;
799 uintptr_t direct_method = 0;
Calin Juravle68ad6492015-08-18 17:08:12 +0100800
Calin Juravle5d01db12015-08-25 15:02:42 +0100801 // Special handling for string init.
802 int32_t string_init_offset = 0;
803 bool is_string_init = compiler_driver_->IsStringInit(method_idx,
804 dex_file_,
805 &string_init_offset);
806 // Replace calls to String.<init> with StringFactory.
807 if (is_string_init) {
808 HInvokeStaticOrDirect::DispatchInfo dispatch_info = ComputeDispatchInfo(is_string_init,
809 string_init_offset,
810 target_method,
811 direct_method,
812 direct_code);
813 HInvoke* invoke = new (arena_) HInvokeStaticOrDirect(
814 arena_,
815 number_of_arguments - 1,
816 Primitive::kPrimNot /*return_type */,
817 dex_pc,
818 method_idx,
819 target_method,
820 dispatch_info,
821 original_invoke_type,
822 kStatic /* optimized_invoke_type */,
823 HInvokeStaticOrDirect::ClinitCheckRequirement::kImplicit);
824 return HandleStringInit(invoke,
825 number_of_vreg_arguments,
826 args,
827 register_index,
828 is_range,
829 descriptor);
830 }
831
832 // Handle unresolved methods.
Calin Juravle68ad6492015-08-18 17:08:12 +0100833 if (!compiler_driver_->ComputeInvokeInfo(dex_compilation_unit_,
834 dex_pc,
835 true /* update_stats */,
836 true /* enable_devirtualization */,
837 &optimized_invoke_type,
838 &target_method,
839 &table_index,
840 &direct_code,
841 &direct_method)) {
Calin Juravle175dc732015-08-25 15:42:32 +0100842 MaybeRecordStat(MethodCompilationStat::kUnresolvedMethod);
843 HInvoke* invoke = new (arena_) HInvokeUnresolved(arena_,
844 number_of_arguments,
845 return_type,
846 dex_pc,
847 method_idx,
848 original_invoke_type);
849 return HandleInvoke(invoke,
850 number_of_vreg_arguments,
851 args,
852 register_index,
853 is_range,
854 descriptor,
855 nullptr /* clinit_check */);
Calin Juravle68ad6492015-08-18 17:08:12 +0100856 }
857
Calin Juravle5d01db12015-08-25 15:02:42 +0100858 // Handle resolved methods (non string init).
Calin Juravle68ad6492015-08-18 17:08:12 +0100859
Calin Juravle5d01db12015-08-25 15:02:42 +0100860 DCHECK(optimized_invoke_type != kSuper);
Calin Juravle68ad6492015-08-18 17:08:12 +0100861
862 // Potential class initialization check, in the case of a static method call.
863 HClinitCheck* clinit_check = nullptr;
864 HInvoke* invoke = nullptr;
865
Calin Juravle5d01db12015-08-25 15:02:42 +0100866 if (optimized_invoke_type == kDirect || optimized_invoke_type == kStatic) {
Calin Juravle68ad6492015-08-18 17:08:12 +0100867 // By default, consider that the called method implicitly requires
868 // an initialization check of its declaring method.
869 HInvokeStaticOrDirect::ClinitCheckRequirement clinit_check_requirement
870 = HInvokeStaticOrDirect::ClinitCheckRequirement::kImplicit;
Calin Juravle5d01db12015-08-25 15:02:42 +0100871 if (optimized_invoke_type == kStatic) {
Calin Juravle68ad6492015-08-18 17:08:12 +0100872 clinit_check = ProcessClinitCheckForInvoke(dex_pc, method_idx, &clinit_check_requirement);
Nicolas Geoffray2e7cd752015-07-10 11:38:52 +0100873 }
Calin Juravle68ad6492015-08-18 17:08:12 +0100874
Calin Juravle68ad6492015-08-18 17:08:12 +0100875 HInvokeStaticOrDirect::DispatchInfo dispatch_info = ComputeDispatchInfo(is_string_init,
876 string_init_offset,
877 target_method,
878 direct_method,
879 direct_code);
880 invoke = new (arena_) HInvokeStaticOrDirect(arena_,
881 number_of_arguments,
882 return_type,
883 dex_pc,
884 method_idx,
885 target_method,
886 dispatch_info,
887 original_invoke_type,
888 optimized_invoke_type,
889 clinit_check_requirement);
890 } else if (optimized_invoke_type == kVirtual) {
891 invoke = new (arena_) HInvokeVirtual(arena_,
892 number_of_arguments,
893 return_type,
894 dex_pc,
895 method_idx,
896 table_index);
Nicolas Geoffray2e7cd752015-07-10 11:38:52 +0100897 } else {
Calin Juravle68ad6492015-08-18 17:08:12 +0100898 DCHECK_EQ(optimized_invoke_type, kInterface);
899 invoke = new (arena_) HInvokeInterface(arena_,
900 number_of_arguments,
901 return_type,
902 dex_pc,
903 method_idx,
904 table_index);
Nicolas Geoffray2e7cd752015-07-10 11:38:52 +0100905 }
Calin Juravle68ad6492015-08-18 17:08:12 +0100906
Calin Juravle5d01db12015-08-25 15:02:42 +0100907 return HandleInvoke(invoke,
908 number_of_vreg_arguments,
909 args,
910 register_index,
911 is_range,
912 descriptor,
913 clinit_check);
Calin Juravle68ad6492015-08-18 17:08:12 +0100914}
915
916HClinitCheck* HGraphBuilder::ProcessClinitCheckForInvoke(
917 uint32_t dex_pc,
918 uint32_t method_idx,
919 HInvokeStaticOrDirect::ClinitCheckRequirement* clinit_check_requirement) {
920 ScopedObjectAccess soa(Thread::Current());
921 StackHandleScope<4> hs(soa.Self());
922 Handle<mirror::DexCache> dex_cache(hs.NewHandle(
923 dex_compilation_unit_->GetClassLinker()->FindDexCache(
Mathieu Chartier673ed3d2015-08-28 14:56:43 -0700924 soa.Self(), *dex_compilation_unit_->GetDexFile())));
Calin Juravle68ad6492015-08-18 17:08:12 +0100925 Handle<mirror::ClassLoader> class_loader(hs.NewHandle(
926 soa.Decode<mirror::ClassLoader*>(dex_compilation_unit_->GetClassLoader())));
927 ArtMethod* resolved_method = compiler_driver_->ResolveMethod(
928 soa, dex_cache, class_loader, dex_compilation_unit_, method_idx, InvokeType::kStatic);
929
930 DCHECK(resolved_method != nullptr);
931
932 const DexFile& outer_dex_file = *outer_compilation_unit_->GetDexFile();
933 Handle<mirror::DexCache> outer_dex_cache(hs.NewHandle(
Mathieu Chartier673ed3d2015-08-28 14:56:43 -0700934 outer_compilation_unit_->GetClassLinker()->FindDexCache(soa.Self(), outer_dex_file)));
Calin Juravle68ad6492015-08-18 17:08:12 +0100935 Handle<mirror::Class> outer_class(hs.NewHandle(GetOutermostCompilingClass()));
936
937 // The index at which the method's class is stored in the DexCache's type array.
938 uint32_t storage_index = DexFile::kDexNoIndex;
939 bool is_outer_class = (resolved_method->GetDeclaringClass() == outer_class.Get());
940 if (is_outer_class) {
941 storage_index = outer_class->GetDexTypeIndex();
942 } else if (outer_dex_cache.Get() == dex_cache.Get()) {
943 // Get `storage_index` from IsClassOfStaticMethodAvailableToReferrer.
944 compiler_driver_->IsClassOfStaticMethodAvailableToReferrer(outer_dex_cache.Get(),
945 GetCompilingClass(),
946 resolved_method,
947 method_idx,
948 &storage_index);
949 }
950
951 HClinitCheck* clinit_check = nullptr;
952
953 if (!outer_class->IsInterface()
954 && outer_class->IsSubClass(resolved_method->GetDeclaringClass())) {
955 // If the outer class is the declaring class or a subclass
956 // of the declaring class, no class initialization is needed
957 // before the static method call.
958 // Note that in case of inlining, we do not need to add clinit checks
959 // to calls that satisfy this subclass check with any inlined methods. This
960 // will be detected by the optimization passes.
961 *clinit_check_requirement = HInvokeStaticOrDirect::ClinitCheckRequirement::kNone;
962 } else if (storage_index != DexFile::kDexNoIndex) {
963 // If the method's class type index is available, check
964 // whether we should add an explicit class initialization
965 // check for its declaring class before the static method call.
966
967 // TODO: find out why this check is needed.
968 bool is_in_dex_cache = compiler_driver_->CanAssumeTypeIsPresentInDexCache(
969 *outer_compilation_unit_->GetDexFile(), storage_index);
970 bool is_initialized =
971 resolved_method->GetDeclaringClass()->IsInitialized() && is_in_dex_cache;
972
973 if (is_initialized) {
974 *clinit_check_requirement = HInvokeStaticOrDirect::ClinitCheckRequirement::kNone;
975 } else {
976 *clinit_check_requirement = HInvokeStaticOrDirect::ClinitCheckRequirement::kExplicit;
977 HLoadClass* load_class = new (arena_) HLoadClass(
978 graph_->GetCurrentMethod(),
979 storage_index,
980 *dex_compilation_unit_->GetDexFile(),
981 is_outer_class,
982 dex_pc);
983 current_block_->AddInstruction(load_class);
984 clinit_check = new (arena_) HClinitCheck(load_class, dex_pc);
985 current_block_->AddInstruction(clinit_check);
986 }
987 }
988 return clinit_check;
Nicolas Geoffray2e7cd752015-07-10 11:38:52 +0100989}
990
Vladimir Marko58155012015-08-19 12:49:41 +0000991HInvokeStaticOrDirect::DispatchInfo HGraphBuilder::ComputeDispatchInfo(
992 bool is_string_init,
993 int32_t string_init_offset,
994 MethodReference target_method,
995 uintptr_t direct_method,
996 uintptr_t direct_code) {
997 HInvokeStaticOrDirect::MethodLoadKind method_load_kind;
998 HInvokeStaticOrDirect::CodePtrLocation code_ptr_location;
999 uint64_t method_load_data = 0u;
1000 uint64_t direct_code_ptr = 0u;
1001
1002 if (is_string_init) {
1003 // TODO: Use direct_method and direct_code for the appropriate StringFactory method.
1004 method_load_kind = HInvokeStaticOrDirect::MethodLoadKind::kStringInit;
1005 code_ptr_location = HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod;
1006 method_load_data = string_init_offset;
1007 } else if (target_method.dex_file == outer_compilation_unit_->GetDexFile() &&
1008 target_method.dex_method_index == outer_compilation_unit_->GetDexMethodIndex()) {
1009 method_load_kind = HInvokeStaticOrDirect::MethodLoadKind::kRecursive;
1010 code_ptr_location = HInvokeStaticOrDirect::CodePtrLocation::kCallSelf;
1011 } else {
1012 if (direct_method != 0u) { // Should we use a direct pointer to the method?
1013 if (direct_method != static_cast<uintptr_t>(-1)) { // Is the method pointer known now?
1014 method_load_kind = HInvokeStaticOrDirect::MethodLoadKind::kDirectAddress;
1015 method_load_data = direct_method;
1016 } else { // The direct pointer will be known at link time.
1017 method_load_kind = HInvokeStaticOrDirect::MethodLoadKind::kDirectAddressWithFixup;
1018 }
1019 } else { // Use dex cache.
1020 DCHECK(target_method.dex_file == dex_compilation_unit_->GetDexFile());
1021 DexCacheArraysLayout layout =
1022 compiler_driver_->GetDexCacheArraysLayout(target_method.dex_file);
1023 if (layout.Valid()) { // Can we use PC-relative access to the dex cache arrays?
1024 method_load_kind = HInvokeStaticOrDirect::MethodLoadKind::kDexCachePcRelative;
1025 method_load_data = layout.MethodOffset(target_method.dex_method_index);
1026 } else { // We must go through the ArtMethod's pointer to resolved methods.
1027 method_load_kind = HInvokeStaticOrDirect::MethodLoadKind::kDexCacheViaMethod;
1028 }
1029 }
1030 if (direct_code != 0u) { // Should we use a direct pointer to the code?
1031 if (direct_code != static_cast<uintptr_t>(-1)) { // Is the code pointer known now?
1032 code_ptr_location = HInvokeStaticOrDirect::CodePtrLocation::kCallDirect;
1033 direct_code_ptr = direct_code;
1034 } else if (compiler_driver_->IsImage() ||
1035 target_method.dex_file == dex_compilation_unit_->GetDexFile()) {
1036 // Use PC-relative calls for invokes within a multi-dex oat file.
1037 // TODO: Recognize when the target dex file is within the current oat file for
1038 // app compilation. At the moment we recognize only the boot image as multi-dex.
1039 // NOTE: This will require changing the ARM backend which currently falls
1040 // through from kCallPCRelative to kDirectCodeFixup for different dex files.
1041 code_ptr_location = HInvokeStaticOrDirect::CodePtrLocation::kCallPCRelative;
1042 } else { // The direct pointer will be known at link time.
1043 // NOTE: This is used for app->boot calls when compiling an app against
1044 // a relocatable but not yet relocated image.
1045 code_ptr_location = HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup;
1046 }
1047 } else { // We must use the code pointer from the ArtMethod.
1048 code_ptr_location = HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod;
1049 }
1050 }
1051
1052 if (graph_->IsDebuggable()) {
1053 // For debuggable apps always use the code pointer from ArtMethod
1054 // so that we don't circumvent instrumentation stubs if installed.
1055 code_ptr_location = HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod;
1056 }
1057
1058 return HInvokeStaticOrDirect::DispatchInfo {
1059 method_load_kind, code_ptr_location, method_load_data, direct_code_ptr };
1060}
1061
Calin Juravle5d01db12015-08-25 15:02:42 +01001062bool HGraphBuilder::SetupInvokeArguments(HInvoke* invoke,
1063 uint32_t number_of_vreg_arguments,
1064 uint32_t* args,
1065 uint32_t register_index,
1066 bool is_range,
1067 const char* descriptor,
1068 size_t start_index,
1069 size_t* argument_index) {
Calin Juravle68ad6492015-08-18 17:08:12 +01001070 uint32_t descriptor_index = 1; // Skip the return type.
Yevgeny Rouban3ecfd652015-09-07 17:57:00 +06001071 uint32_t dex_pc = invoke->GetDexPc();
Calin Juravle68ad6492015-08-18 17:08:12 +01001072
Nicolas Geoffray2e335252015-06-18 11:11:27 +01001073 for (size_t i = start_index;
1074 // Make sure we don't go over the expected arguments or over the number of
1075 // dex registers given. If the instruction was seen as dead by the verifier,
1076 // it hasn't been properly checked.
Calin Juravle5d01db12015-08-25 15:02:42 +01001077 (i < number_of_vreg_arguments) && (*argument_index < invoke->GetNumberOfArguments());
1078 i++, (*argument_index)++) {
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001079 Primitive::Type type = Primitive::GetType(descriptor[descriptor_index++]);
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001080 bool is_wide = (type == Primitive::kPrimLong) || (type == Primitive::kPrimDouble);
Nicolas Geoffray2e335252015-06-18 11:11:27 +01001081 if (!is_range
1082 && is_wide
1083 && ((i + 1 == number_of_vreg_arguments) || (args[i] + 1 != args[i + 1]))) {
1084 // Longs and doubles should be in pairs, that is, sequential registers. The verifier should
1085 // reject any class where this is violated. However, the verifier only does these checks
1086 // on non trivially dead instructions, so we just bailout the compilation.
1087 VLOG(compiler) << "Did not compile "
1088 << PrettyMethod(dex_compilation_unit_->GetDexMethodIndex(), *dex_file_)
1089 << " because of non-sequential dex register pair in wide argument";
1090 MaybeRecordStat(MethodCompilationStat::kNotCompiledMalformedOpcode);
1091 return false;
1092 }
Yevgeny Rouban3ecfd652015-09-07 17:57:00 +06001093 HInstruction* arg = LoadLocal(is_range ? register_index + i : args[i], type, dex_pc);
Calin Juravle5d01db12015-08-25 15:02:42 +01001094 invoke->SetArgumentAt(*argument_index, arg);
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001095 if (is_wide) {
Nicolas Geoffrayabed4d02014-07-14 15:24:11 +01001096 i++;
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001097 }
1098 }
Nicolas Geoffray2e335252015-06-18 11:11:27 +01001099
Calin Juravle5d01db12015-08-25 15:02:42 +01001100 if (*argument_index != invoke->GetNumberOfArguments()) {
Nicolas Geoffray2e335252015-06-18 11:11:27 +01001101 VLOG(compiler) << "Did not compile "
1102 << PrettyMethod(dex_compilation_unit_->GetDexMethodIndex(), *dex_file_)
1103 << " because of wrong number of arguments in invoke instruction";
1104 MaybeRecordStat(MethodCompilationStat::kNotCompiledMalformedOpcode);
1105 return false;
1106 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001107
Nicolas Geoffray38207af2015-06-01 15:46:22 +01001108 if (invoke->IsInvokeStaticOrDirect()) {
Calin Juravle5d01db12015-08-25 15:02:42 +01001109 invoke->SetArgumentAt(*argument_index, graph_->GetCurrentMethod());
1110 (*argument_index)++;
1111 }
1112
1113 return true;
1114}
1115
1116bool HGraphBuilder::HandleInvoke(HInvoke* invoke,
1117 uint32_t number_of_vreg_arguments,
1118 uint32_t* args,
1119 uint32_t register_index,
1120 bool is_range,
1121 const char* descriptor,
1122 HClinitCheck* clinit_check) {
1123 DCHECK(!invoke->IsInvokeStaticOrDirect() || !invoke->AsInvokeStaticOrDirect()->IsStringInit());
1124
1125 size_t start_index = 0;
1126 size_t argument_index = 0;
1127 if (invoke->GetOriginalInvokeType() != InvokeType::kStatic) { // Instance call.
1128 Temporaries temps(graph_);
1129 HInstruction* arg = LoadLocal(
1130 is_range ? register_index : args[0], Primitive::kPrimNot, invoke->GetDexPc());
1131 HNullCheck* null_check = new (arena_) HNullCheck(arg, invoke->GetDexPc());
1132 current_block_->AddInstruction(null_check);
1133 temps.Add(null_check);
1134 invoke->SetArgumentAt(0, null_check);
1135 start_index = 1;
1136 argument_index = 1;
1137 }
1138
1139 if (!SetupInvokeArguments(invoke,
1140 number_of_vreg_arguments,
1141 args,
1142 register_index,
1143 is_range,
1144 descriptor,
1145 start_index,
1146 &argument_index)) {
1147 return false;
Nicolas Geoffray38207af2015-06-01 15:46:22 +01001148 }
1149
Calin Juravle68ad6492015-08-18 17:08:12 +01001150 if (clinit_check != nullptr) {
Roland Levillain4c0eb422015-04-24 16:43:49 +01001151 // Add the class initialization check as last input of `invoke`.
Calin Juravle68ad6492015-08-18 17:08:12 +01001152 DCHECK(invoke->IsInvokeStaticOrDirect());
1153 DCHECK(invoke->AsInvokeStaticOrDirect()->GetClinitCheckRequirement()
1154 == HInvokeStaticOrDirect::ClinitCheckRequirement::kExplicit);
Roland Levillain3e3d7332015-04-28 11:00:54 +01001155 invoke->SetArgumentAt(argument_index, clinit_check);
Nicolas Geoffray2e7cd752015-07-10 11:38:52 +01001156 argument_index++;
Roland Levillain4c0eb422015-04-24 16:43:49 +01001157 }
1158
Calin Juravle5d01db12015-08-25 15:02:42 +01001159 current_block_->AddInstruction(invoke);
1160 latest_result_ = invoke;
1161
1162 return true;
1163}
1164
1165bool HGraphBuilder::HandleStringInit(HInvoke* invoke,
1166 uint32_t number_of_vreg_arguments,
1167 uint32_t* args,
1168 uint32_t register_index,
1169 bool is_range,
1170 const char* descriptor) {
1171 DCHECK(invoke->IsInvokeStaticOrDirect());
1172 DCHECK(invoke->AsInvokeStaticOrDirect()->IsStringInit());
1173
1174 size_t start_index = 1;
1175 size_t argument_index = 0;
1176 if (!SetupInvokeArguments(invoke,
1177 number_of_vreg_arguments,
1178 args,
1179 register_index,
1180 is_range,
1181 descriptor,
1182 start_index,
1183 &argument_index)) {
1184 return false;
Jeff Hao848f70a2014-01-15 13:49:50 -08001185 }
Calin Juravle0eedd7e2015-08-20 14:48:00 +01001186
Calin Juravle5d01db12015-08-25 15:02:42 +01001187 // Add move-result for StringFactory method.
1188 uint32_t orig_this_reg = is_range ? register_index : args[0];
1189 HInstruction* fake_string = LoadLocal(orig_this_reg, Primitive::kPrimNot, invoke->GetDexPc());
1190 invoke->SetArgumentAt(argument_index, fake_string);
1191 current_block_->AddInstruction(invoke);
1192 PotentiallySimplifyFakeString(orig_this_reg, invoke->GetDexPc(), invoke);
1193
Calin Juravle0eedd7e2015-08-20 14:48:00 +01001194 latest_result_ = invoke;
1195
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001196 return true;
1197}
1198
Calin Juravle68ad6492015-08-18 17:08:12 +01001199void HGraphBuilder::PotentiallySimplifyFakeString(uint16_t original_dex_register,
1200 uint32_t dex_pc,
1201 HInvoke* actual_string) {
1202 if (!graph_->IsDebuggable()) {
1203 // Notify that we cannot compile with baseline. The dex registers aliasing
1204 // with `original_dex_register` will be handled when we optimize
1205 // (see HInstructionSimplifer::VisitFakeString).
1206 can_use_baseline_for_string_init_ = false;
1207 return;
1208 }
1209 const VerifiedMethod* verified_method =
1210 compiler_driver_->GetVerifiedMethod(dex_file_, dex_compilation_unit_->GetDexMethodIndex());
1211 if (verified_method != nullptr) {
Yevgeny Rouban3ecfd652015-09-07 17:57:00 +06001212 UpdateLocal(original_dex_register, actual_string, dex_pc);
Calin Juravle68ad6492015-08-18 17:08:12 +01001213 const SafeMap<uint32_t, std::set<uint32_t>>& string_init_map =
1214 verified_method->GetStringInitPcRegMap();
1215 auto map_it = string_init_map.find(dex_pc);
1216 if (map_it != string_init_map.end()) {
1217 std::set<uint32_t> reg_set = map_it->second;
1218 for (auto set_it = reg_set.begin(); set_it != reg_set.end(); ++set_it) {
Yevgeny Rouban3ecfd652015-09-07 17:57:00 +06001219 HInstruction* load_local = LoadLocal(original_dex_register, Primitive::kPrimNot, dex_pc);
1220 UpdateLocal(*set_it, load_local, dex_pc);
Calin Juravle68ad6492015-08-18 17:08:12 +01001221 }
1222 }
1223 } else {
1224 can_use_baseline_for_string_init_ = false;
1225 }
1226}
1227
Calin Juravle23a8e352015-09-08 19:56:31 +01001228static Primitive::Type GetFieldAccessType(const DexFile& dex_file, uint16_t field_index) {
1229 const DexFile::FieldId& field_id = dex_file.GetFieldId(field_index);
1230 const char* type = dex_file.GetFieldTypeDescriptor(field_id);
1231 return Primitive::GetType(type[0]);
1232}
1233
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01001234bool HGraphBuilder::BuildInstanceFieldAccess(const Instruction& instruction,
Calin Juravle225ff812014-11-13 16:46:39 +00001235 uint32_t dex_pc,
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01001236 bool is_put) {
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001237 uint32_t source_or_dest_reg = instruction.VRegA_22c();
1238 uint32_t obj_reg = instruction.VRegB_22c();
Nicolas Geoffray9523a3e2015-07-17 11:51:28 +00001239 uint16_t field_index;
1240 if (instruction.IsQuickened()) {
1241 if (!CanDecodeQuickenedInfo()) {
1242 return false;
1243 }
1244 field_index = LookupQuickenedInfo(dex_pc);
1245 } else {
1246 field_index = instruction.VRegC_22c();
1247 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001248
1249 ScopedObjectAccess soa(Thread::Current());
Mathieu Chartierc7853442015-03-27 14:35:38 -07001250 ArtField* resolved_field =
1251 compiler_driver_->ComputeInstanceFieldInfo(field_index, dex_compilation_unit_, is_put, soa);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001252
Nicolas Geoffrayabed4d02014-07-14 15:24:11 +01001253
Yevgeny Rouban3ecfd652015-09-07 17:57:00 +06001254 HInstruction* object = LoadLocal(obj_reg, Primitive::kPrimNot, dex_pc);
Calin Juravle23a8e352015-09-08 19:56:31 +01001255 HInstruction* null_check = new (arena_) HNullCheck(object, dex_pc);
1256 current_block_->AddInstruction(null_check);
1257
1258 Primitive::Type field_type = (resolved_field == nullptr)
1259 ? GetFieldAccessType(*dex_file_, field_index)
1260 : resolved_field->GetTypeAsPrimitiveType();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001261 if (is_put) {
Calin Juravlef97f9fb2014-11-11 15:38:19 +00001262 Temporaries temps(graph_);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001263 // We need one temporary for the null check.
1264 temps.Add(null_check);
Yevgeny Rouban3ecfd652015-09-07 17:57:00 +06001265 HInstruction* value = LoadLocal(source_or_dest_reg, field_type, dex_pc);
Calin Juravle23a8e352015-09-08 19:56:31 +01001266 HInstruction* field_set = nullptr;
1267 if (resolved_field == nullptr) {
1268 MaybeRecordStat(MethodCompilationStat::kUnresolvedField);
1269 field_set = new (arena_) HUnresolvedInstanceFieldSet(null_check,
1270 value,
1271 field_type,
1272 field_index,
1273 dex_pc);
1274 } else {
1275 field_set = new (arena_) HInstanceFieldSet(null_check,
1276 value,
1277 field_type,
1278 resolved_field->GetOffset(),
1279 resolved_field->IsVolatile(),
1280 field_index,
1281 *dex_file_,
1282 dex_compilation_unit_->GetDexCache(),
1283 dex_pc);
1284 }
1285 current_block_->AddInstruction(field_set);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001286 } else {
Calin Juravle23a8e352015-09-08 19:56:31 +01001287 HInstruction* field_get = nullptr;
1288 if (resolved_field == nullptr) {
1289 MaybeRecordStat(MethodCompilationStat::kUnresolvedField);
1290 field_get = new (arena_) HUnresolvedInstanceFieldGet(null_check,
1291 field_type,
1292 field_index,
1293 dex_pc);
1294 } else {
1295 field_get = new (arena_) HInstanceFieldGet(null_check,
1296 field_type,
1297 resolved_field->GetOffset(),
1298 resolved_field->IsVolatile(),
1299 field_index,
1300 *dex_file_,
1301 dex_compilation_unit_->GetDexCache(),
1302 dex_pc);
1303 }
1304 current_block_->AddInstruction(field_get);
1305 UpdateLocal(source_or_dest_reg, field_get, dex_pc);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001306 }
Calin Juravle23a8e352015-09-08 19:56:31 +01001307
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001308 return true;
1309}
1310
Nicolas Geoffray30451742015-06-19 13:32:41 +01001311static mirror::Class* GetClassFrom(CompilerDriver* driver,
1312 const DexCompilationUnit& compilation_unit) {
Nicolas Geoffray9437b782015-03-25 10:08:51 +00001313 ScopedObjectAccess soa(Thread::Current());
1314 StackHandleScope<2> hs(soa.Self());
Nicolas Geoffray30451742015-06-19 13:32:41 +01001315 const DexFile& dex_file = *compilation_unit.GetDexFile();
Nicolas Geoffray9437b782015-03-25 10:08:51 +00001316 Handle<mirror::ClassLoader> class_loader(hs.NewHandle(
Nicolas Geoffray30451742015-06-19 13:32:41 +01001317 soa.Decode<mirror::ClassLoader*>(compilation_unit.GetClassLoader())));
1318 Handle<mirror::DexCache> dex_cache(hs.NewHandle(
Mathieu Chartier673ed3d2015-08-28 14:56:43 -07001319 compilation_unit.GetClassLinker()->FindDexCache(soa.Self(), dex_file)));
Nicolas Geoffray9437b782015-03-25 10:08:51 +00001320
Nicolas Geoffray30451742015-06-19 13:32:41 +01001321 return driver->ResolveCompilingMethodsClass(soa, dex_cache, class_loader, &compilation_unit);
1322}
1323
1324mirror::Class* HGraphBuilder::GetOutermostCompilingClass() const {
1325 return GetClassFrom(compiler_driver_, *outer_compilation_unit_);
1326}
1327
1328mirror::Class* HGraphBuilder::GetCompilingClass() const {
1329 return GetClassFrom(compiler_driver_, *dex_compilation_unit_);
Nicolas Geoffray9437b782015-03-25 10:08:51 +00001330}
1331
1332bool HGraphBuilder::IsOutermostCompilingClass(uint16_t type_index) const {
1333 ScopedObjectAccess soa(Thread::Current());
1334 StackHandleScope<4> hs(soa.Self());
1335 Handle<mirror::DexCache> dex_cache(hs.NewHandle(
Mathieu Chartier673ed3d2015-08-28 14:56:43 -07001336 dex_compilation_unit_->GetClassLinker()->FindDexCache(
1337 soa.Self(), *dex_compilation_unit_->GetDexFile())));
Nicolas Geoffray9437b782015-03-25 10:08:51 +00001338 Handle<mirror::ClassLoader> class_loader(hs.NewHandle(
1339 soa.Decode<mirror::ClassLoader*>(dex_compilation_unit_->GetClassLoader())));
1340 Handle<mirror::Class> cls(hs.NewHandle(compiler_driver_->ResolveClass(
1341 soa, dex_cache, class_loader, type_index, dex_compilation_unit_)));
Nicolas Geoffrayafd06412015-06-20 22:44:47 +01001342 Handle<mirror::Class> outer_class(hs.NewHandle(GetOutermostCompilingClass()));
Nicolas Geoffray9437b782015-03-25 10:08:51 +00001343
Nicolas Geoffrayafd06412015-06-20 22:44:47 +01001344 return outer_class.Get() == cls.Get();
Nicolas Geoffray9437b782015-03-25 10:08:51 +00001345}
1346
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01001347bool HGraphBuilder::BuildStaticFieldAccess(const Instruction& instruction,
Calin Juravle225ff812014-11-13 16:46:39 +00001348 uint32_t dex_pc,
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01001349 bool is_put) {
1350 uint32_t source_or_dest_reg = instruction.VRegA_21c();
1351 uint16_t field_index = instruction.VRegB_21c();
1352
Nicolas Geoffraye53798a2014-12-01 10:31:54 +00001353 ScopedObjectAccess soa(Thread::Current());
Mathieu Chartierc7853442015-03-27 14:35:38 -07001354 StackHandleScope<4> hs(soa.Self());
Nicolas Geoffraye53798a2014-12-01 10:31:54 +00001355 Handle<mirror::DexCache> dex_cache(hs.NewHandle(
Mathieu Chartier673ed3d2015-08-28 14:56:43 -07001356 dex_compilation_unit_->GetClassLinker()->FindDexCache(
1357 soa.Self(), *dex_compilation_unit_->GetDexFile())));
Nicolas Geoffraye53798a2014-12-01 10:31:54 +00001358 Handle<mirror::ClassLoader> class_loader(hs.NewHandle(
1359 soa.Decode<mirror::ClassLoader*>(dex_compilation_unit_->GetClassLoader())));
Mathieu Chartierc7853442015-03-27 14:35:38 -07001360 ArtField* resolved_field = compiler_driver_->ResolveField(
1361 soa, dex_cache, class_loader, dex_compilation_unit_, field_index, true);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01001362
Mathieu Chartierc7853442015-03-27 14:35:38 -07001363 if (resolved_field == nullptr) {
Calin Juravle23a8e352015-09-08 19:56:31 +01001364 MaybeRecordStat(MethodCompilationStat::kUnresolvedField);
1365 Primitive::Type field_type = GetFieldAccessType(*dex_file_, field_index);
1366 if (is_put) {
1367 HInstruction* value = LoadLocal(source_or_dest_reg, field_type, dex_pc);
1368 current_block_->AddInstruction(
1369 new (arena_) HUnresolvedStaticFieldSet(value, field_type, field_index, dex_pc));
1370 } else {
1371 current_block_->AddInstruction(
1372 new (arena_) HUnresolvedStaticFieldGet(field_type, field_index, dex_pc));
1373 UpdateLocal(source_or_dest_reg, current_block_->GetLastInstruction(), dex_pc);
1374 }
1375 return true;
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01001376 }
1377
Nicolas Geoffray9437b782015-03-25 10:08:51 +00001378 const DexFile& outer_dex_file = *outer_compilation_unit_->GetDexFile();
1379 Handle<mirror::DexCache> outer_dex_cache(hs.NewHandle(
Mathieu Chartier673ed3d2015-08-28 14:56:43 -07001380 outer_compilation_unit_->GetClassLinker()->FindDexCache(soa.Self(), outer_dex_file)));
Nicolas Geoffray30451742015-06-19 13:32:41 +01001381 Handle<mirror::Class> outer_class(hs.NewHandle(GetOutermostCompilingClass()));
Nicolas Geoffraye53798a2014-12-01 10:31:54 +00001382
1383 // The index at which the field's class is stored in the DexCache's type array.
1384 uint32_t storage_index;
Nicolas Geoffray30451742015-06-19 13:32:41 +01001385 bool is_outer_class = (outer_class.Get() == resolved_field->GetDeclaringClass());
1386 if (is_outer_class) {
1387 storage_index = outer_class->GetDexTypeIndex();
Nicolas Geoffray9437b782015-03-25 10:08:51 +00001388 } else if (outer_dex_cache.Get() != dex_cache.Get()) {
Roland Levillain4c0eb422015-04-24 16:43:49 +01001389 // The compiler driver cannot currently understand multiple dex caches involved. Just bailout.
Nicolas Geoffraye53798a2014-12-01 10:31:54 +00001390 return false;
Nicolas Geoffray9437b782015-03-25 10:08:51 +00001391 } else {
1392 std::pair<bool, bool> pair = compiler_driver_->IsFastStaticField(
1393 outer_dex_cache.Get(),
Nicolas Geoffray30451742015-06-19 13:32:41 +01001394 GetCompilingClass(),
Mathieu Chartierc7853442015-03-27 14:35:38 -07001395 resolved_field,
Nicolas Geoffray9437b782015-03-25 10:08:51 +00001396 field_index,
1397 &storage_index);
1398 bool can_easily_access = is_put ? pair.second : pair.first;
1399 if (!can_easily_access) {
1400 return false;
1401 }
Nicolas Geoffraye53798a2014-12-01 10:31:54 +00001402 }
1403
1404 // TODO: find out why this check is needed.
1405 bool is_in_dex_cache = compiler_driver_->CanAssumeTypeIsPresentInDexCache(
Nicolas Geoffray6a816cf2015-03-24 16:17:56 +00001406 *outer_compilation_unit_->GetDexFile(), storage_index);
Nicolas Geoffraye53798a2014-12-01 10:31:54 +00001407 bool is_initialized = resolved_field->GetDeclaringClass()->IsInitialized() && is_in_dex_cache;
Nicolas Geoffraye53798a2014-12-01 10:31:54 +00001408
Nicolas Geoffray76b1e172015-05-27 17:18:33 +01001409 HLoadClass* constant = new (arena_) HLoadClass(graph_->GetCurrentMethod(),
1410 storage_index,
1411 *dex_compilation_unit_->GetDexFile(),
Nicolas Geoffray30451742015-06-19 13:32:41 +01001412 is_outer_class,
Nicolas Geoffray76b1e172015-05-27 17:18:33 +01001413 dex_pc);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01001414 current_block_->AddInstruction(constant);
1415
1416 HInstruction* cls = constant;
Nicolas Geoffray30451742015-06-19 13:32:41 +01001417 if (!is_initialized && !is_outer_class) {
Calin Juravle225ff812014-11-13 16:46:39 +00001418 cls = new (arena_) HClinitCheck(constant, dex_pc);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01001419 current_block_->AddInstruction(cls);
1420 }
1421
Nicolas Geoffraye53798a2014-12-01 10:31:54 +00001422 Primitive::Type field_type = resolved_field->GetTypeAsPrimitiveType();
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01001423 if (is_put) {
1424 // We need to keep the class alive before loading the value.
Calin Juravlef97f9fb2014-11-11 15:38:19 +00001425 Temporaries temps(graph_);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01001426 temps.Add(cls);
Yevgeny Rouban3ecfd652015-09-07 17:57:00 +06001427 HInstruction* value = LoadLocal(source_or_dest_reg, field_type, dex_pc);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01001428 DCHECK_EQ(value->GetType(), field_type);
Guillaume "Vermeille" Sanchez104fd8a2015-05-20 17:52:13 +01001429 current_block_->AddInstruction(new (arena_) HStaticFieldSet(cls,
1430 value,
1431 field_type,
1432 resolved_field->GetOffset(),
1433 resolved_field->IsVolatile(),
1434 field_index,
Mathieu Chartier736b5602015-09-02 14:54:11 -07001435 *dex_file_,
Yevgeny Rouban3ecfd652015-09-07 17:57:00 +06001436 dex_cache_,
1437 dex_pc));
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01001438 } else {
Guillaume "Vermeille" Sanchez104fd8a2015-05-20 17:52:13 +01001439 current_block_->AddInstruction(new (arena_) HStaticFieldGet(cls,
1440 field_type,
1441 resolved_field->GetOffset(),
1442 resolved_field->IsVolatile(),
1443 field_index,
Mathieu Chartier736b5602015-09-02 14:54:11 -07001444 *dex_file_,
Yevgeny Rouban3ecfd652015-09-07 17:57:00 +06001445 dex_cache_,
1446 dex_pc));
1447 UpdateLocal(source_or_dest_reg, current_block_->GetLastInstruction(), dex_pc);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01001448 }
1449 return true;
1450}
1451
Calin Juravlebacfec32014-11-14 15:54:36 +00001452void HGraphBuilder::BuildCheckedDivRem(uint16_t out_vreg,
1453 uint16_t first_vreg,
1454 int64_t second_vreg_or_constant,
1455 uint32_t dex_pc,
1456 Primitive::Type type,
1457 bool second_is_constant,
1458 bool isDiv) {
Calin Juravled6fb6cf2014-11-11 19:07:44 +00001459 DCHECK(type == Primitive::kPrimInt || type == Primitive::kPrimLong);
Calin Juravled0d48522014-11-04 16:40:20 +00001460
Yevgeny Rouban3ecfd652015-09-07 17:57:00 +06001461 HInstruction* first = LoadLocal(first_vreg, type, dex_pc);
Calin Juravled6fb6cf2014-11-11 19:07:44 +00001462 HInstruction* second = nullptr;
1463 if (second_is_constant) {
1464 if (type == Primitive::kPrimInt) {
Yevgeny Rouban3ecfd652015-09-07 17:57:00 +06001465 second = graph_->GetIntConstant(second_vreg_or_constant, dex_pc);
Calin Juravled6fb6cf2014-11-11 19:07:44 +00001466 } else {
Yevgeny Rouban3ecfd652015-09-07 17:57:00 +06001467 second = graph_->GetLongConstant(second_vreg_or_constant, dex_pc);
Calin Juravled6fb6cf2014-11-11 19:07:44 +00001468 }
1469 } else {
Yevgeny Rouban3ecfd652015-09-07 17:57:00 +06001470 second = LoadLocal(second_vreg_or_constant, type, dex_pc);
Calin Juravled6fb6cf2014-11-11 19:07:44 +00001471 }
1472
1473 if (!second_is_constant
1474 || (type == Primitive::kPrimInt && second->AsIntConstant()->GetValue() == 0)
1475 || (type == Primitive::kPrimLong && second->AsLongConstant()->GetValue() == 0)) {
1476 second = new (arena_) HDivZeroCheck(second, dex_pc);
Calin Juravlef97f9fb2014-11-11 15:38:19 +00001477 Temporaries temps(graph_);
Calin Juravled0d48522014-11-04 16:40:20 +00001478 current_block_->AddInstruction(second);
1479 temps.Add(current_block_->GetLastInstruction());
1480 }
1481
Calin Juravlebacfec32014-11-14 15:54:36 +00001482 if (isDiv) {
1483 current_block_->AddInstruction(new (arena_) HDiv(type, first, second, dex_pc));
1484 } else {
1485 current_block_->AddInstruction(new (arena_) HRem(type, first, second, dex_pc));
1486 }
Yevgeny Rouban3ecfd652015-09-07 17:57:00 +06001487 UpdateLocal(out_vreg, current_block_->GetLastInstruction(), dex_pc);
Calin Juravled0d48522014-11-04 16:40:20 +00001488}
1489
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001490void HGraphBuilder::BuildArrayAccess(const Instruction& instruction,
Calin Juravle225ff812014-11-13 16:46:39 +00001491 uint32_t dex_pc,
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001492 bool is_put,
1493 Primitive::Type anticipated_type) {
1494 uint8_t source_or_dest_reg = instruction.VRegA_23x();
1495 uint8_t array_reg = instruction.VRegB_23x();
1496 uint8_t index_reg = instruction.VRegC_23x();
1497
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001498 // We need one temporary for the null check, one for the index, and one for the length.
Calin Juravlef97f9fb2014-11-11 15:38:19 +00001499 Temporaries temps(graph_);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001500
Yevgeny Rouban3ecfd652015-09-07 17:57:00 +06001501 HInstruction* object = LoadLocal(array_reg, Primitive::kPrimNot, dex_pc);
Calin Juravle225ff812014-11-13 16:46:39 +00001502 object = new (arena_) HNullCheck(object, dex_pc);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001503 current_block_->AddInstruction(object);
1504 temps.Add(object);
1505
Yevgeny Rouban3ecfd652015-09-07 17:57:00 +06001506 HInstruction* length = new (arena_) HArrayLength(object, dex_pc);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001507 current_block_->AddInstruction(length);
1508 temps.Add(length);
Yevgeny Rouban3ecfd652015-09-07 17:57:00 +06001509 HInstruction* index = LoadLocal(index_reg, Primitive::kPrimInt, dex_pc);
Calin Juravle225ff812014-11-13 16:46:39 +00001510 index = new (arena_) HBoundsCheck(index, length, dex_pc);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001511 current_block_->AddInstruction(index);
1512 temps.Add(index);
1513 if (is_put) {
Yevgeny Rouban3ecfd652015-09-07 17:57:00 +06001514 HInstruction* value = LoadLocal(source_or_dest_reg, anticipated_type, dex_pc);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001515 // TODO: Insert a type check node if the type is Object.
Nicolas Geoffray39468442014-09-02 15:17:15 +01001516 current_block_->AddInstruction(new (arena_) HArraySet(
Calin Juravle225ff812014-11-13 16:46:39 +00001517 object, index, value, anticipated_type, dex_pc));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001518 } else {
Yevgeny Rouban3ecfd652015-09-07 17:57:00 +06001519 current_block_->AddInstruction(new (arena_) HArrayGet(object, index, anticipated_type, dex_pc));
1520 UpdateLocal(source_or_dest_reg, current_block_->GetLastInstruction(), dex_pc);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001521 }
Mark Mendell1152c922015-04-24 17:06:35 -04001522 graph_->SetHasBoundsChecks(true);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001523}
1524
Calin Juravle225ff812014-11-13 16:46:39 +00001525void HGraphBuilder::BuildFilledNewArray(uint32_t dex_pc,
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01001526 uint32_t type_index,
1527 uint32_t number_of_vreg_arguments,
1528 bool is_range,
1529 uint32_t* args,
1530 uint32_t register_index) {
Yevgeny Rouban3ecfd652015-09-07 17:57:00 +06001531 HInstruction* length = graph_->GetIntConstant(number_of_vreg_arguments, dex_pc);
Nicolas Geoffraycb1b00a2015-01-28 14:50:01 +00001532 QuickEntrypointEnum entrypoint = NeedsAccessCheck(type_index)
1533 ? kQuickAllocArrayWithAccessCheck
1534 : kQuickAllocArray;
Guillaume "Vermeille" Sanchez81d804a2015-05-20 12:42:25 +01001535 HInstruction* object = new (arena_) HNewArray(length,
Nicolas Geoffray69aa6012015-06-09 10:34:25 +01001536 graph_->GetCurrentMethod(),
Guillaume "Vermeille" Sanchez81d804a2015-05-20 12:42:25 +01001537 dex_pc,
1538 type_index,
1539 *dex_compilation_unit_->GetDexFile(),
1540 entrypoint);
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01001541 current_block_->AddInstruction(object);
1542
1543 const char* descriptor = dex_file_->StringByTypeIdx(type_index);
1544 DCHECK_EQ(descriptor[0], '[') << descriptor;
1545 char primitive = descriptor[1];
1546 DCHECK(primitive == 'I'
1547 || primitive == 'L'
1548 || primitive == '[') << descriptor;
1549 bool is_reference_array = (primitive == 'L') || (primitive == '[');
1550 Primitive::Type type = is_reference_array ? Primitive::kPrimNot : Primitive::kPrimInt;
1551
Calin Juravlef97f9fb2014-11-11 15:38:19 +00001552 Temporaries temps(graph_);
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01001553 temps.Add(object);
1554 for (size_t i = 0; i < number_of_vreg_arguments; ++i) {
Yevgeny Rouban3ecfd652015-09-07 17:57:00 +06001555 HInstruction* value = LoadLocal(is_range ? register_index + i : args[i], type, dex_pc);
1556 HInstruction* index = graph_->GetIntConstant(i, dex_pc);
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01001557 current_block_->AddInstruction(
Calin Juravle225ff812014-11-13 16:46:39 +00001558 new (arena_) HArraySet(object, index, value, type, dex_pc));
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01001559 }
1560 latest_result_ = object;
1561}
1562
1563template <typename T>
1564void HGraphBuilder::BuildFillArrayData(HInstruction* object,
1565 const T* data,
1566 uint32_t element_count,
1567 Primitive::Type anticipated_type,
Calin Juravle225ff812014-11-13 16:46:39 +00001568 uint32_t dex_pc) {
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01001569 for (uint32_t i = 0; i < element_count; ++i) {
Yevgeny Rouban3ecfd652015-09-07 17:57:00 +06001570 HInstruction* index = graph_->GetIntConstant(i, dex_pc);
1571 HInstruction* value = graph_->GetIntConstant(data[i], dex_pc);
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01001572 current_block_->AddInstruction(new (arena_) HArraySet(
Calin Juravle225ff812014-11-13 16:46:39 +00001573 object, index, value, anticipated_type, dex_pc));
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01001574 }
1575}
1576
Calin Juravle225ff812014-11-13 16:46:39 +00001577void HGraphBuilder::BuildFillArrayData(const Instruction& instruction, uint32_t dex_pc) {
Calin Juravlef97f9fb2014-11-11 15:38:19 +00001578 Temporaries temps(graph_);
Yevgeny Rouban3ecfd652015-09-07 17:57:00 +06001579 HInstruction* array = LoadLocal(instruction.VRegA_31t(), Primitive::kPrimNot, dex_pc);
Calin Juravle225ff812014-11-13 16:46:39 +00001580 HNullCheck* null_check = new (arena_) HNullCheck(array, dex_pc);
Calin Juravled0d48522014-11-04 16:40:20 +00001581 current_block_->AddInstruction(null_check);
1582 temps.Add(null_check);
1583
Yevgeny Rouban3ecfd652015-09-07 17:57:00 +06001584 HInstruction* length = new (arena_) HArrayLength(null_check, dex_pc);
Calin Juravled0d48522014-11-04 16:40:20 +00001585 current_block_->AddInstruction(length);
1586
Calin Juravle225ff812014-11-13 16:46:39 +00001587 int32_t payload_offset = instruction.VRegB_31t() + dex_pc;
Calin Juravled0d48522014-11-04 16:40:20 +00001588 const Instruction::ArrayDataPayload* payload =
1589 reinterpret_cast<const Instruction::ArrayDataPayload*>(code_start_ + payload_offset);
1590 const uint8_t* data = payload->data;
1591 uint32_t element_count = payload->element_count;
1592
1593 // Implementation of this DEX instruction seems to be that the bounds check is
1594 // done before doing any stores.
Yevgeny Rouban3ecfd652015-09-07 17:57:00 +06001595 HInstruction* last_index = graph_->GetIntConstant(payload->element_count - 1, dex_pc);
Calin Juravle225ff812014-11-13 16:46:39 +00001596 current_block_->AddInstruction(new (arena_) HBoundsCheck(last_index, length, dex_pc));
Calin Juravled0d48522014-11-04 16:40:20 +00001597
1598 switch (payload->element_width) {
1599 case 1:
1600 BuildFillArrayData(null_check,
1601 reinterpret_cast<const int8_t*>(data),
1602 element_count,
1603 Primitive::kPrimByte,
Calin Juravle225ff812014-11-13 16:46:39 +00001604 dex_pc);
Calin Juravled0d48522014-11-04 16:40:20 +00001605 break;
1606 case 2:
1607 BuildFillArrayData(null_check,
1608 reinterpret_cast<const int16_t*>(data),
1609 element_count,
1610 Primitive::kPrimShort,
Calin Juravle225ff812014-11-13 16:46:39 +00001611 dex_pc);
Calin Juravled0d48522014-11-04 16:40:20 +00001612 break;
1613 case 4:
1614 BuildFillArrayData(null_check,
1615 reinterpret_cast<const int32_t*>(data),
1616 element_count,
1617 Primitive::kPrimInt,
Calin Juravle225ff812014-11-13 16:46:39 +00001618 dex_pc);
Calin Juravled0d48522014-11-04 16:40:20 +00001619 break;
1620 case 8:
1621 BuildFillWideArrayData(null_check,
1622 reinterpret_cast<const int64_t*>(data),
1623 element_count,
Calin Juravle225ff812014-11-13 16:46:39 +00001624 dex_pc);
Calin Juravled0d48522014-11-04 16:40:20 +00001625 break;
1626 default:
1627 LOG(FATAL) << "Unknown element width for " << payload->element_width;
1628 }
Mark Mendell1152c922015-04-24 17:06:35 -04001629 graph_->SetHasBoundsChecks(true);
Calin Juravled0d48522014-11-04 16:40:20 +00001630}
1631
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01001632void HGraphBuilder::BuildFillWideArrayData(HInstruction* object,
Nicolas Geoffray8d6ae522014-10-23 18:32:13 +01001633 const int64_t* data,
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01001634 uint32_t element_count,
Calin Juravle225ff812014-11-13 16:46:39 +00001635 uint32_t dex_pc) {
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01001636 for (uint32_t i = 0; i < element_count; ++i) {
Yevgeny Rouban3ecfd652015-09-07 17:57:00 +06001637 HInstruction* index = graph_->GetIntConstant(i, dex_pc);
1638 HInstruction* value = graph_->GetLongConstant(data[i], dex_pc);
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01001639 current_block_->AddInstruction(new (arena_) HArraySet(
Calin Juravle225ff812014-11-13 16:46:39 +00001640 object, index, value, Primitive::kPrimLong, dex_pc));
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01001641 }
1642}
1643
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00001644bool HGraphBuilder::BuildTypeCheck(const Instruction& instruction,
1645 uint8_t destination,
1646 uint8_t reference,
1647 uint16_t type_index,
Calin Juravle225ff812014-11-13 16:46:39 +00001648 uint32_t dex_pc) {
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00001649 bool type_known_final;
1650 bool type_known_abstract;
Nicolas Geoffraye53798a2014-12-01 10:31:54 +00001651 // `CanAccessTypeWithoutChecks` will tell whether the method being
1652 // built is trying to access its own class, so that the generated
1653 // code can optimize for this case. However, the optimization does not
Nicolas Geoffray9437b782015-03-25 10:08:51 +00001654 // work for inlining, so we use `IsOutermostCompilingClass` instead.
Nicolas Geoffraye53798a2014-12-01 10:31:54 +00001655 bool dont_use_is_referrers_class;
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00001656 bool can_access = compiler_driver_->CanAccessTypeWithoutChecks(
1657 dex_compilation_unit_->GetDexMethodIndex(), *dex_file_, type_index,
Nicolas Geoffraye53798a2014-12-01 10:31:54 +00001658 &type_known_final, &type_known_abstract, &dont_use_is_referrers_class);
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00001659 if (!can_access) {
Calin Juravle48c2b032014-12-09 18:11:36 +00001660 MaybeRecordStat(MethodCompilationStat::kNotCompiledCantAccesType);
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00001661 return false;
1662 }
Yevgeny Rouban3ecfd652015-09-07 17:57:00 +06001663 HInstruction* object = LoadLocal(reference, Primitive::kPrimNot, dex_pc);
Nicolas Geoffray9437b782015-03-25 10:08:51 +00001664 HLoadClass* cls = new (arena_) HLoadClass(
Nicolas Geoffray76b1e172015-05-27 17:18:33 +01001665 graph_->GetCurrentMethod(),
Nicolas Geoffrayd5111bf2015-05-22 15:37:09 +01001666 type_index,
1667 *dex_compilation_unit_->GetDexFile(),
1668 IsOutermostCompilingClass(type_index),
1669 dex_pc);
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00001670 current_block_->AddInstruction(cls);
1671 // The class needs a temporary before being used by the type check.
Calin Juravlef97f9fb2014-11-11 15:38:19 +00001672 Temporaries temps(graph_);
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00001673 temps.Add(cls);
1674 if (instruction.Opcode() == Instruction::INSTANCE_OF) {
1675 current_block_->AddInstruction(
Calin Juravle225ff812014-11-13 16:46:39 +00001676 new (arena_) HInstanceOf(object, cls, type_known_final, dex_pc));
Yevgeny Rouban3ecfd652015-09-07 17:57:00 +06001677 UpdateLocal(destination, current_block_->GetLastInstruction(), dex_pc);
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00001678 } else {
1679 DCHECK_EQ(instruction.Opcode(), Instruction::CHECK_CAST);
1680 current_block_->AddInstruction(
Calin Juravle225ff812014-11-13 16:46:39 +00001681 new (arena_) HCheckCast(object, cls, type_known_final, dex_pc));
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00001682 }
1683 return true;
1684}
1685
Nicolas Geoffraycb1b00a2015-01-28 14:50:01 +00001686bool HGraphBuilder::NeedsAccessCheck(uint32_t type_index) const {
1687 return !compiler_driver_->CanAccessInstantiableTypeWithoutChecks(
1688 dex_compilation_unit_->GetDexMethodIndex(), *dex_file_, type_index);
1689}
1690
Calin Juravle48c2b032014-12-09 18:11:36 +00001691void HGraphBuilder::BuildPackedSwitch(const Instruction& instruction, uint32_t dex_pc) {
David Brazdil2ef645b2015-06-17 18:20:52 +01001692 // Verifier guarantees that the payload for PackedSwitch contains:
1693 // (a) number of entries (may be zero)
1694 // (b) first and lowest switch case value (entry 0, always present)
1695 // (c) list of target pcs (entries 1 <= i <= N)
Andreas Gamped881df52014-11-24 23:28:39 -08001696 SwitchTable table(instruction, dex_pc, false);
1697
1698 // Value to test against.
Yevgeny Rouban3ecfd652015-09-07 17:57:00 +06001699 HInstruction* value = LoadLocal(instruction.VRegA(), Primitive::kPrimInt, dex_pc);
Andreas Gamped881df52014-11-24 23:28:39 -08001700
David Brazdil2ef645b2015-06-17 18:20:52 +01001701 // Retrieve number of entries.
Andreas Gampee4d4d322014-12-04 09:09:57 -08001702 uint16_t num_entries = table.GetNumEntries();
David Brazdil2ef645b2015-06-17 18:20:52 +01001703 if (num_entries == 0) {
1704 return;
1705 }
Andreas Gampee4d4d322014-12-04 09:09:57 -08001706
Andreas Gamped881df52014-11-24 23:28:39 -08001707 // Chained cmp-and-branch, starting from starting_key.
1708 int32_t starting_key = table.GetEntryAt(0);
1709
Andreas Gamped881df52014-11-24 23:28:39 -08001710 for (size_t i = 1; i <= num_entries; i++) {
Andreas Gampee4d4d322014-12-04 09:09:57 -08001711 BuildSwitchCaseHelper(instruction, i, i == num_entries, table, value, starting_key + i - 1,
1712 table.GetEntryAt(i), dex_pc);
Andreas Gamped881df52014-11-24 23:28:39 -08001713 }
Andreas Gamped881df52014-11-24 23:28:39 -08001714}
1715
Calin Juravle48c2b032014-12-09 18:11:36 +00001716void HGraphBuilder::BuildSparseSwitch(const Instruction& instruction, uint32_t dex_pc) {
David Brazdil2ef645b2015-06-17 18:20:52 +01001717 // Verifier guarantees that the payload for SparseSwitch contains:
1718 // (a) number of entries (may be zero)
1719 // (b) sorted key values (entries 0 <= i < N)
1720 // (c) target pcs corresponding to the switch values (entries N <= i < 2*N)
Andreas Gampee4d4d322014-12-04 09:09:57 -08001721 SwitchTable table(instruction, dex_pc, true);
1722
1723 // Value to test against.
Yevgeny Rouban3ecfd652015-09-07 17:57:00 +06001724 HInstruction* value = LoadLocal(instruction.VRegA(), Primitive::kPrimInt, dex_pc);
Andreas Gampee4d4d322014-12-04 09:09:57 -08001725
1726 uint16_t num_entries = table.GetNumEntries();
Andreas Gampee4d4d322014-12-04 09:09:57 -08001727
1728 for (size_t i = 0; i < num_entries; i++) {
1729 BuildSwitchCaseHelper(instruction, i, i == static_cast<size_t>(num_entries) - 1, table, value,
1730 table.GetEntryAt(i), table.GetEntryAt(i + num_entries), dex_pc);
1731 }
Andreas Gampee4d4d322014-12-04 09:09:57 -08001732}
1733
1734void HGraphBuilder::BuildSwitchCaseHelper(const Instruction& instruction, size_t index,
1735 bool is_last_case, const SwitchTable& table,
1736 HInstruction* value, int32_t case_value_int,
1737 int32_t target_offset, uint32_t dex_pc) {
David Brazdil852eaff2015-02-02 15:23:05 +00001738 HBasicBlock* case_target = FindBlockStartingAt(dex_pc + target_offset);
1739 DCHECK(case_target != nullptr);
1740 PotentiallyAddSuspendCheck(case_target, dex_pc);
Andreas Gampee4d4d322014-12-04 09:09:57 -08001741
1742 // The current case's value.
Yevgeny Rouban3ecfd652015-09-07 17:57:00 +06001743 HInstruction* this_case_value = graph_->GetIntConstant(case_value_int, dex_pc);
Andreas Gampee4d4d322014-12-04 09:09:57 -08001744
1745 // Compare value and this_case_value.
Yevgeny Rouban3ecfd652015-09-07 17:57:00 +06001746 HEqual* comparison = new (arena_) HEqual(value, this_case_value, dex_pc);
Andreas Gampee4d4d322014-12-04 09:09:57 -08001747 current_block_->AddInstruction(comparison);
Yevgeny Rouban3ecfd652015-09-07 17:57:00 +06001748 HInstruction* ifinst = new (arena_) HIf(comparison, dex_pc);
Andreas Gampee4d4d322014-12-04 09:09:57 -08001749 current_block_->AddInstruction(ifinst);
1750
1751 // Case hit: use the target offset to determine where to go.
Andreas Gampee4d4d322014-12-04 09:09:57 -08001752 current_block_->AddSuccessor(case_target);
1753
1754 // Case miss: go to the next case (or default fall-through).
1755 // When there is a next case, we use the block stored with the table offset representing this
1756 // case (that is where we registered them in ComputeBranchTargets).
1757 // When there is no next case, we use the following instruction.
1758 // TODO: Find a good way to peel the last iteration to avoid conditional, but still have re-use.
1759 if (!is_last_case) {
1760 HBasicBlock* next_case_target = FindBlockStartingAt(table.GetDexPcForIndex(index));
1761 DCHECK(next_case_target != nullptr);
1762 current_block_->AddSuccessor(next_case_target);
1763
1764 // Need to manually add the block, as there is no dex-pc transition for the cases.
1765 graph_->AddBlock(next_case_target);
1766
1767 current_block_ = next_case_target;
1768 } else {
1769 HBasicBlock* default_target = FindBlockStartingAt(dex_pc + instruction.SizeInCodeUnits());
1770 DCHECK(default_target != nullptr);
1771 current_block_->AddSuccessor(default_target);
1772 current_block_ = nullptr;
1773 }
1774}
1775
David Brazdil852eaff2015-02-02 15:23:05 +00001776void HGraphBuilder::PotentiallyAddSuspendCheck(HBasicBlock* target, uint32_t dex_pc) {
1777 int32_t target_offset = target->GetDexPc() - dex_pc;
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00001778 if (target_offset <= 0) {
David Brazdil852eaff2015-02-02 15:23:05 +00001779 // DX generates back edges to the first encountered return. We can save
1780 // time of later passes by not adding redundant suspend checks.
David Brazdil2fd6aa52015-02-02 18:58:27 +00001781 HInstruction* last_in_target = target->GetLastInstruction();
1782 if (last_in_target != nullptr &&
1783 (last_in_target->IsReturn() || last_in_target->IsReturnVoid())) {
1784 return;
David Brazdil852eaff2015-02-02 15:23:05 +00001785 }
1786
1787 // Add a suspend check to backward branches which may potentially loop. We
1788 // can remove them after we recognize loops in the graph.
Calin Juravle225ff812014-11-13 16:46:39 +00001789 current_block_->AddInstruction(new (arena_) HSuspendCheck(dex_pc));
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00001790 }
1791}
1792
Nicolas Geoffray9523a3e2015-07-17 11:51:28 +00001793bool HGraphBuilder::CanDecodeQuickenedInfo() const {
1794 return interpreter_metadata_ != nullptr;
1795}
1796
1797uint16_t HGraphBuilder::LookupQuickenedInfo(uint32_t dex_pc) {
1798 DCHECK(interpreter_metadata_ != nullptr);
1799 uint32_t dex_pc_in_map = DecodeUnsignedLeb128(&interpreter_metadata_);
1800 DCHECK_EQ(dex_pc, dex_pc_in_map);
1801 return DecodeUnsignedLeb128(&interpreter_metadata_);
1802}
1803
Calin Juravle225ff812014-11-13 16:46:39 +00001804bool HGraphBuilder::AnalyzeDexInstruction(const Instruction& instruction, uint32_t dex_pc) {
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001805 if (current_block_ == nullptr) {
1806 return true; // Dead code
1807 }
Nicolas Geoffraybe9a92a2014-02-25 14:22:56 +00001808
Nicolas Geoffray818f2102014-02-18 16:43:35 +00001809 switch (instruction.Opcode()) {
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00001810 case Instruction::CONST_4: {
1811 int32_t register_index = instruction.VRegA();
Yevgeny Rouban3ecfd652015-09-07 17:57:00 +06001812 HIntConstant* constant = graph_->GetIntConstant(instruction.VRegB_11n(), dex_pc);
1813 UpdateLocal(register_index, constant, dex_pc);
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00001814 break;
1815 }
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001816
Nicolas Geoffrayb55f8352014-04-07 15:26:35 +01001817 case Instruction::CONST_16: {
1818 int32_t register_index = instruction.VRegA();
Yevgeny Rouban3ecfd652015-09-07 17:57:00 +06001819 HIntConstant* constant = graph_->GetIntConstant(instruction.VRegB_21s(), dex_pc);
1820 UpdateLocal(register_index, constant, dex_pc);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001821 break;
1822 }
1823
Dave Allison20dfc792014-06-16 20:44:29 -07001824 case Instruction::CONST: {
1825 int32_t register_index = instruction.VRegA();
Yevgeny Rouban3ecfd652015-09-07 17:57:00 +06001826 HIntConstant* constant = graph_->GetIntConstant(instruction.VRegB_31i(), dex_pc);
1827 UpdateLocal(register_index, constant, dex_pc);
Dave Allison20dfc792014-06-16 20:44:29 -07001828 break;
1829 }
1830
1831 case Instruction::CONST_HIGH16: {
1832 int32_t register_index = instruction.VRegA();
Yevgeny Rouban3ecfd652015-09-07 17:57:00 +06001833 HIntConstant* constant = graph_->GetIntConstant(instruction.VRegB_21h() << 16, dex_pc);
1834 UpdateLocal(register_index, constant, dex_pc);
Dave Allison20dfc792014-06-16 20:44:29 -07001835 break;
1836 }
1837
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001838 case Instruction::CONST_WIDE_16: {
1839 int32_t register_index = instruction.VRegA();
Dave Allison20dfc792014-06-16 20:44:29 -07001840 // Get 16 bits of constant value, sign extended to 64 bits.
1841 int64_t value = instruction.VRegB_21s();
1842 value <<= 48;
1843 value >>= 48;
Yevgeny Rouban3ecfd652015-09-07 17:57:00 +06001844 HLongConstant* constant = graph_->GetLongConstant(value, dex_pc);
1845 UpdateLocal(register_index, constant, dex_pc);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001846 break;
1847 }
1848
1849 case Instruction::CONST_WIDE_32: {
1850 int32_t register_index = instruction.VRegA();
Dave Allison20dfc792014-06-16 20:44:29 -07001851 // Get 32 bits of constant value, sign extended to 64 bits.
1852 int64_t value = instruction.VRegB_31i();
1853 value <<= 32;
1854 value >>= 32;
Yevgeny Rouban3ecfd652015-09-07 17:57:00 +06001855 HLongConstant* constant = graph_->GetLongConstant(value, dex_pc);
1856 UpdateLocal(register_index, constant, dex_pc);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001857 break;
1858 }
1859
1860 case Instruction::CONST_WIDE: {
1861 int32_t register_index = instruction.VRegA();
Yevgeny Rouban3ecfd652015-09-07 17:57:00 +06001862 HLongConstant* constant = graph_->GetLongConstant(instruction.VRegB_51l(), dex_pc);
1863 UpdateLocal(register_index, constant, dex_pc);
Nicolas Geoffrayb55f8352014-04-07 15:26:35 +01001864 break;
1865 }
1866
Dave Allison20dfc792014-06-16 20:44:29 -07001867 case Instruction::CONST_WIDE_HIGH16: {
1868 int32_t register_index = instruction.VRegA();
1869 int64_t value = static_cast<int64_t>(instruction.VRegB_21h()) << 48;
Yevgeny Rouban3ecfd652015-09-07 17:57:00 +06001870 HLongConstant* constant = graph_->GetLongConstant(value, dex_pc);
1871 UpdateLocal(register_index, constant, dex_pc);
Dave Allison20dfc792014-06-16 20:44:29 -07001872 break;
1873 }
1874
Nicolas Geoffraydadf3172014-11-07 16:36:02 +00001875 // Note that the SSA building will refine the types.
Dave Allison20dfc792014-06-16 20:44:29 -07001876 case Instruction::MOVE:
1877 case Instruction::MOVE_FROM16:
1878 case Instruction::MOVE_16: {
Yevgeny Rouban3ecfd652015-09-07 17:57:00 +06001879 HInstruction* value = LoadLocal(instruction.VRegB(), Primitive::kPrimInt, dex_pc);
1880 UpdateLocal(instruction.VRegA(), value, dex_pc);
Nicolas Geoffrayb55f8352014-04-07 15:26:35 +01001881 break;
1882 }
1883
Nicolas Geoffraydadf3172014-11-07 16:36:02 +00001884 // Note that the SSA building will refine the types.
Dave Allison20dfc792014-06-16 20:44:29 -07001885 case Instruction::MOVE_WIDE:
1886 case Instruction::MOVE_WIDE_FROM16:
1887 case Instruction::MOVE_WIDE_16: {
Yevgeny Rouban3ecfd652015-09-07 17:57:00 +06001888 HInstruction* value = LoadLocal(instruction.VRegB(), Primitive::kPrimLong, dex_pc);
1889 UpdateLocal(instruction.VRegA(), value, dex_pc);
Dave Allison20dfc792014-06-16 20:44:29 -07001890 break;
1891 }
1892
1893 case Instruction::MOVE_OBJECT:
1894 case Instruction::MOVE_OBJECT_16:
1895 case Instruction::MOVE_OBJECT_FROM16: {
Yevgeny Rouban3ecfd652015-09-07 17:57:00 +06001896 HInstruction* value = LoadLocal(instruction.VRegB(), Primitive::kPrimNot, dex_pc);
1897 UpdateLocal(instruction.VRegA(), value, dex_pc);
Dave Allison20dfc792014-06-16 20:44:29 -07001898 break;
1899 }
1900
Nicolas Geoffray9523a3e2015-07-17 11:51:28 +00001901 case Instruction::RETURN_VOID_NO_BARRIER:
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001902 case Instruction::RETURN_VOID: {
Yevgeny Rouban3ecfd652015-09-07 17:57:00 +06001903 BuildReturn(instruction, Primitive::kPrimVoid, dex_pc);
Nicolas Geoffray818f2102014-02-18 16:43:35 +00001904 break;
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001905 }
1906
Dave Allison20dfc792014-06-16 20:44:29 -07001907#define IF_XX(comparison, cond) \
Calin Juravle225ff812014-11-13 16:46:39 +00001908 case Instruction::IF_##cond: If_22t<comparison>(instruction, dex_pc); break; \
1909 case Instruction::IF_##cond##Z: If_21t<comparison>(instruction, dex_pc); break
Nicolas Geoffrayb55f8352014-04-07 15:26:35 +01001910
Dave Allison20dfc792014-06-16 20:44:29 -07001911 IF_XX(HEqual, EQ);
1912 IF_XX(HNotEqual, NE);
1913 IF_XX(HLessThan, LT);
1914 IF_XX(HLessThanOrEqual, LE);
1915 IF_XX(HGreaterThan, GT);
1916 IF_XX(HGreaterThanOrEqual, GE);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001917
Nicolas Geoffraybe9a92a2014-02-25 14:22:56 +00001918 case Instruction::GOTO:
1919 case Instruction::GOTO_16:
1920 case Instruction::GOTO_32: {
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00001921 int32_t offset = instruction.GetTargetOffset();
Calin Juravle225ff812014-11-13 16:46:39 +00001922 HBasicBlock* target = FindBlockStartingAt(offset + dex_pc);
Nicolas Geoffraybe9a92a2014-02-25 14:22:56 +00001923 DCHECK(target != nullptr);
David Brazdil852eaff2015-02-02 15:23:05 +00001924 PotentiallyAddSuspendCheck(target, dex_pc);
Yevgeny Rouban3ecfd652015-09-07 17:57:00 +06001925 current_block_->AddInstruction(new (arena_) HGoto(dex_pc));
Nicolas Geoffraybe9a92a2014-02-25 14:22:56 +00001926 current_block_->AddSuccessor(target);
1927 current_block_ = nullptr;
1928 break;
1929 }
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001930
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001931 case Instruction::RETURN: {
Yevgeny Rouban3ecfd652015-09-07 17:57:00 +06001932 BuildReturn(instruction, return_type_, dex_pc);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001933 break;
1934 }
1935
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001936 case Instruction::RETURN_OBJECT: {
Yevgeny Rouban3ecfd652015-09-07 17:57:00 +06001937 BuildReturn(instruction, return_type_, dex_pc);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001938 break;
1939 }
1940
1941 case Instruction::RETURN_WIDE: {
Yevgeny Rouban3ecfd652015-09-07 17:57:00 +06001942 BuildReturn(instruction, return_type_, dex_pc);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001943 break;
1944 }
1945
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001946 case Instruction::INVOKE_DIRECT:
Nicolas Geoffray0d8db992014-11-11 14:40:10 +00001947 case Instruction::INVOKE_INTERFACE:
1948 case Instruction::INVOKE_STATIC:
1949 case Instruction::INVOKE_SUPER:
Nicolas Geoffray9523a3e2015-07-17 11:51:28 +00001950 case Instruction::INVOKE_VIRTUAL:
1951 case Instruction::INVOKE_VIRTUAL_QUICK: {
1952 uint16_t method_idx;
1953 if (instruction.Opcode() == Instruction::INVOKE_VIRTUAL_QUICK) {
1954 if (!CanDecodeQuickenedInfo()) {
1955 return false;
1956 }
1957 method_idx = LookupQuickenedInfo(dex_pc);
1958 } else {
1959 method_idx = instruction.VRegB_35c();
1960 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001961 uint32_t number_of_vreg_arguments = instruction.VRegA_35c();
Nicolas Geoffray4a34a422014-04-03 10:38:37 +01001962 uint32_t args[5];
Ian Rogers29a26482014-05-02 15:27:29 -07001963 instruction.GetVarArgs(args);
Calin Juravle225ff812014-11-13 16:46:39 +00001964 if (!BuildInvoke(instruction, dex_pc, method_idx,
Nicolas Geoffraydadf3172014-11-07 16:36:02 +00001965 number_of_vreg_arguments, false, args, -1)) {
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001966 return false;
Nicolas Geoffray4a34a422014-04-03 10:38:37 +01001967 }
Nicolas Geoffray4a34a422014-04-03 10:38:37 +01001968 break;
1969 }
1970
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001971 case Instruction::INVOKE_DIRECT_RANGE:
Nicolas Geoffray0d8db992014-11-11 14:40:10 +00001972 case Instruction::INVOKE_INTERFACE_RANGE:
1973 case Instruction::INVOKE_STATIC_RANGE:
1974 case Instruction::INVOKE_SUPER_RANGE:
Nicolas Geoffray9523a3e2015-07-17 11:51:28 +00001975 case Instruction::INVOKE_VIRTUAL_RANGE:
1976 case Instruction::INVOKE_VIRTUAL_RANGE_QUICK: {
1977 uint16_t method_idx;
1978 if (instruction.Opcode() == Instruction::INVOKE_VIRTUAL_RANGE_QUICK) {
1979 if (!CanDecodeQuickenedInfo()) {
1980 return false;
1981 }
1982 method_idx = LookupQuickenedInfo(dex_pc);
1983 } else {
1984 method_idx = instruction.VRegB_3rc();
1985 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001986 uint32_t number_of_vreg_arguments = instruction.VRegA_3rc();
1987 uint32_t register_index = instruction.VRegC();
Calin Juravle225ff812014-11-13 16:46:39 +00001988 if (!BuildInvoke(instruction, dex_pc, method_idx,
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001989 number_of_vreg_arguments, true, nullptr, register_index)) {
Nicolas Geoffray4a34a422014-04-03 10:38:37 +01001990 return false;
1991 }
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001992 break;
1993 }
1994
Roland Levillain88cb1752014-10-20 16:36:47 +01001995 case Instruction::NEG_INT: {
Yevgeny Rouban3ecfd652015-09-07 17:57:00 +06001996 Unop_12x<HNeg>(instruction, Primitive::kPrimInt, dex_pc);
Roland Levillain88cb1752014-10-20 16:36:47 +01001997 break;
1998 }
1999
Roland Levillain2e07b4f2014-10-23 18:12:09 +01002000 case Instruction::NEG_LONG: {
Yevgeny Rouban3ecfd652015-09-07 17:57:00 +06002001 Unop_12x<HNeg>(instruction, Primitive::kPrimLong, dex_pc);
Roland Levillain2e07b4f2014-10-23 18:12:09 +01002002 break;
2003 }
2004
Roland Levillain3dbcb382014-10-28 17:30:07 +00002005 case Instruction::NEG_FLOAT: {
Yevgeny Rouban3ecfd652015-09-07 17:57:00 +06002006 Unop_12x<HNeg>(instruction, Primitive::kPrimFloat, dex_pc);
Roland Levillain3dbcb382014-10-28 17:30:07 +00002007 break;
2008 }
2009
2010 case Instruction::NEG_DOUBLE: {
Yevgeny Rouban3ecfd652015-09-07 17:57:00 +06002011 Unop_12x<HNeg>(instruction, Primitive::kPrimDouble, dex_pc);
Roland Levillain3dbcb382014-10-28 17:30:07 +00002012 break;
2013 }
2014
Roland Levillain1cc5f2512014-10-22 18:06:21 +01002015 case Instruction::NOT_INT: {
Yevgeny Rouban3ecfd652015-09-07 17:57:00 +06002016 Unop_12x<HNot>(instruction, Primitive::kPrimInt, dex_pc);
Roland Levillain1cc5f2512014-10-22 18:06:21 +01002017 break;
2018 }
2019
Roland Levillain70566432014-10-24 16:20:17 +01002020 case Instruction::NOT_LONG: {
Yevgeny Rouban3ecfd652015-09-07 17:57:00 +06002021 Unop_12x<HNot>(instruction, Primitive::kPrimLong, dex_pc);
Roland Levillain70566432014-10-24 16:20:17 +01002022 break;
2023 }
2024
Roland Levillaindff1f282014-11-05 14:15:05 +00002025 case Instruction::INT_TO_LONG: {
Roland Levillain624279f2014-12-04 11:54:28 +00002026 Conversion_12x(instruction, Primitive::kPrimInt, Primitive::kPrimLong, dex_pc);
Roland Levillaindff1f282014-11-05 14:15:05 +00002027 break;
2028 }
2029
Roland Levillaincff13742014-11-17 14:32:17 +00002030 case Instruction::INT_TO_FLOAT: {
Roland Levillain624279f2014-12-04 11:54:28 +00002031 Conversion_12x(instruction, Primitive::kPrimInt, Primitive::kPrimFloat, dex_pc);
Roland Levillaincff13742014-11-17 14:32:17 +00002032 break;
2033 }
2034
2035 case Instruction::INT_TO_DOUBLE: {
Roland Levillain624279f2014-12-04 11:54:28 +00002036 Conversion_12x(instruction, Primitive::kPrimInt, Primitive::kPrimDouble, dex_pc);
Roland Levillaincff13742014-11-17 14:32:17 +00002037 break;
2038 }
2039
Roland Levillain946e1432014-11-11 17:35:19 +00002040 case Instruction::LONG_TO_INT: {
Roland Levillain624279f2014-12-04 11:54:28 +00002041 Conversion_12x(instruction, Primitive::kPrimLong, Primitive::kPrimInt, dex_pc);
Roland Levillain946e1432014-11-11 17:35:19 +00002042 break;
2043 }
2044
Roland Levillain6d0e4832014-11-27 18:31:21 +00002045 case Instruction::LONG_TO_FLOAT: {
Roland Levillain624279f2014-12-04 11:54:28 +00002046 Conversion_12x(instruction, Primitive::kPrimLong, Primitive::kPrimFloat, dex_pc);
Roland Levillain6d0e4832014-11-27 18:31:21 +00002047 break;
2048 }
2049
Roland Levillain647b9ed2014-11-27 12:06:00 +00002050 case Instruction::LONG_TO_DOUBLE: {
Roland Levillain624279f2014-12-04 11:54:28 +00002051 Conversion_12x(instruction, Primitive::kPrimLong, Primitive::kPrimDouble, dex_pc);
Roland Levillain647b9ed2014-11-27 12:06:00 +00002052 break;
2053 }
2054
Roland Levillain3f8f9362014-12-02 17:45:01 +00002055 case Instruction::FLOAT_TO_INT: {
Roland Levillain624279f2014-12-04 11:54:28 +00002056 Conversion_12x(instruction, Primitive::kPrimFloat, Primitive::kPrimInt, dex_pc);
2057 break;
2058 }
2059
2060 case Instruction::FLOAT_TO_LONG: {
2061 Conversion_12x(instruction, Primitive::kPrimFloat, Primitive::kPrimLong, dex_pc);
Roland Levillain3f8f9362014-12-02 17:45:01 +00002062 break;
2063 }
2064
Roland Levillain8964e2b2014-12-04 12:10:50 +00002065 case Instruction::FLOAT_TO_DOUBLE: {
2066 Conversion_12x(instruction, Primitive::kPrimFloat, Primitive::kPrimDouble, dex_pc);
2067 break;
2068 }
2069
Roland Levillain4c0b61f2014-12-05 12:06:01 +00002070 case Instruction::DOUBLE_TO_INT: {
2071 Conversion_12x(instruction, Primitive::kPrimDouble, Primitive::kPrimInt, dex_pc);
2072 break;
2073 }
2074
2075 case Instruction::DOUBLE_TO_LONG: {
2076 Conversion_12x(instruction, Primitive::kPrimDouble, Primitive::kPrimLong, dex_pc);
2077 break;
2078 }
2079
Roland Levillain8964e2b2014-12-04 12:10:50 +00002080 case Instruction::DOUBLE_TO_FLOAT: {
2081 Conversion_12x(instruction, Primitive::kPrimDouble, Primitive::kPrimFloat, dex_pc);
2082 break;
2083 }
2084
Roland Levillain51d3fc42014-11-13 14:11:42 +00002085 case Instruction::INT_TO_BYTE: {
Roland Levillain624279f2014-12-04 11:54:28 +00002086 Conversion_12x(instruction, Primitive::kPrimInt, Primitive::kPrimByte, dex_pc);
Roland Levillain51d3fc42014-11-13 14:11:42 +00002087 break;
2088 }
2089
Roland Levillain01a8d712014-11-14 16:27:39 +00002090 case Instruction::INT_TO_SHORT: {
Roland Levillain624279f2014-12-04 11:54:28 +00002091 Conversion_12x(instruction, Primitive::kPrimInt, Primitive::kPrimShort, dex_pc);
Roland Levillain01a8d712014-11-14 16:27:39 +00002092 break;
2093 }
2094
Roland Levillain981e4542014-11-14 11:47:14 +00002095 case Instruction::INT_TO_CHAR: {
Roland Levillain624279f2014-12-04 11:54:28 +00002096 Conversion_12x(instruction, Primitive::kPrimInt, Primitive::kPrimChar, dex_pc);
Roland Levillain981e4542014-11-14 11:47:14 +00002097 break;
2098 }
2099
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00002100 case Instruction::ADD_INT: {
Yevgeny Rouban3ecfd652015-09-07 17:57:00 +06002101 Binop_23x<HAdd>(instruction, Primitive::kPrimInt, dex_pc);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002102 break;
2103 }
2104
2105 case Instruction::ADD_LONG: {
Yevgeny Rouban3ecfd652015-09-07 17:57:00 +06002106 Binop_23x<HAdd>(instruction, Primitive::kPrimLong, dex_pc);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002107 break;
2108 }
2109
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01002110 case Instruction::ADD_DOUBLE: {
Yevgeny Rouban3ecfd652015-09-07 17:57:00 +06002111 Binop_23x<HAdd>(instruction, Primitive::kPrimDouble, dex_pc);
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01002112 break;
2113 }
2114
2115 case Instruction::ADD_FLOAT: {
Yevgeny Rouban3ecfd652015-09-07 17:57:00 +06002116 Binop_23x<HAdd>(instruction, Primitive::kPrimFloat, dex_pc);
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01002117 break;
2118 }
2119
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002120 case Instruction::SUB_INT: {
Yevgeny Rouban3ecfd652015-09-07 17:57:00 +06002121 Binop_23x<HSub>(instruction, Primitive::kPrimInt, dex_pc);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002122 break;
2123 }
2124
2125 case Instruction::SUB_LONG: {
Yevgeny Rouban3ecfd652015-09-07 17:57:00 +06002126 Binop_23x<HSub>(instruction, Primitive::kPrimLong, dex_pc);
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00002127 break;
2128 }
2129
Calin Juravle096cc022014-10-23 17:01:13 +01002130 case Instruction::SUB_FLOAT: {
Yevgeny Rouban3ecfd652015-09-07 17:57:00 +06002131 Binop_23x<HSub>(instruction, Primitive::kPrimFloat, dex_pc);
Calin Juravle096cc022014-10-23 17:01:13 +01002132 break;
2133 }
2134
2135 case Instruction::SUB_DOUBLE: {
Yevgeny Rouban3ecfd652015-09-07 17:57:00 +06002136 Binop_23x<HSub>(instruction, Primitive::kPrimDouble, dex_pc);
Calin Juravle096cc022014-10-23 17:01:13 +01002137 break;
2138 }
2139
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00002140 case Instruction::ADD_INT_2ADDR: {
Yevgeny Rouban3ecfd652015-09-07 17:57:00 +06002141 Binop_12x<HAdd>(instruction, Primitive::kPrimInt, dex_pc);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002142 break;
2143 }
2144
Calin Juravle34bacdf2014-10-07 20:23:36 +01002145 case Instruction::MUL_INT: {
Yevgeny Rouban3ecfd652015-09-07 17:57:00 +06002146 Binop_23x<HMul>(instruction, Primitive::kPrimInt, dex_pc);
Calin Juravle34bacdf2014-10-07 20:23:36 +01002147 break;
2148 }
2149
2150 case Instruction::MUL_LONG: {
Yevgeny Rouban3ecfd652015-09-07 17:57:00 +06002151 Binop_23x<HMul>(instruction, Primitive::kPrimLong, dex_pc);
Calin Juravle34bacdf2014-10-07 20:23:36 +01002152 break;
2153 }
2154
Calin Juravleb5bfa962014-10-21 18:02:24 +01002155 case Instruction::MUL_FLOAT: {
Yevgeny Rouban3ecfd652015-09-07 17:57:00 +06002156 Binop_23x<HMul>(instruction, Primitive::kPrimFloat, dex_pc);
Calin Juravleb5bfa962014-10-21 18:02:24 +01002157 break;
2158 }
2159
2160 case Instruction::MUL_DOUBLE: {
Yevgeny Rouban3ecfd652015-09-07 17:57:00 +06002161 Binop_23x<HMul>(instruction, Primitive::kPrimDouble, dex_pc);
Calin Juravleb5bfa962014-10-21 18:02:24 +01002162 break;
2163 }
2164
Calin Juravled0d48522014-11-04 16:40:20 +00002165 case Instruction::DIV_INT: {
Calin Juravlebacfec32014-11-14 15:54:36 +00002166 BuildCheckedDivRem(instruction.VRegA(), instruction.VRegB(), instruction.VRegC(),
2167 dex_pc, Primitive::kPrimInt, false, true);
Calin Juravled0d48522014-11-04 16:40:20 +00002168 break;
2169 }
2170
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002171 case Instruction::DIV_LONG: {
Calin Juravlebacfec32014-11-14 15:54:36 +00002172 BuildCheckedDivRem(instruction.VRegA(), instruction.VRegB(), instruction.VRegC(),
2173 dex_pc, Primitive::kPrimLong, false, true);
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002174 break;
2175 }
2176
Calin Juravle7c4954d2014-10-28 16:57:40 +00002177 case Instruction::DIV_FLOAT: {
Calin Juravle225ff812014-11-13 16:46:39 +00002178 Binop_23x<HDiv>(instruction, Primitive::kPrimFloat, dex_pc);
Calin Juravle7c4954d2014-10-28 16:57:40 +00002179 break;
2180 }
2181
2182 case Instruction::DIV_DOUBLE: {
Calin Juravle225ff812014-11-13 16:46:39 +00002183 Binop_23x<HDiv>(instruction, Primitive::kPrimDouble, dex_pc);
Calin Juravle7c4954d2014-10-28 16:57:40 +00002184 break;
2185 }
2186
Calin Juravlebacfec32014-11-14 15:54:36 +00002187 case Instruction::REM_INT: {
2188 BuildCheckedDivRem(instruction.VRegA(), instruction.VRegB(), instruction.VRegC(),
2189 dex_pc, Primitive::kPrimInt, false, false);
2190 break;
2191 }
2192
2193 case Instruction::REM_LONG: {
2194 BuildCheckedDivRem(instruction.VRegA(), instruction.VRegB(), instruction.VRegC(),
2195 dex_pc, Primitive::kPrimLong, false, false);
2196 break;
2197 }
2198
Calin Juravled2ec87d2014-12-08 14:24:46 +00002199 case Instruction::REM_FLOAT: {
2200 Binop_23x<HRem>(instruction, Primitive::kPrimFloat, dex_pc);
2201 break;
2202 }
2203
2204 case Instruction::REM_DOUBLE: {
2205 Binop_23x<HRem>(instruction, Primitive::kPrimDouble, dex_pc);
2206 break;
2207 }
2208
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00002209 case Instruction::AND_INT: {
Yevgeny Rouban3ecfd652015-09-07 17:57:00 +06002210 Binop_23x<HAnd>(instruction, Primitive::kPrimInt, dex_pc);
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00002211 break;
2212 }
2213
2214 case Instruction::AND_LONG: {
Yevgeny Rouban3ecfd652015-09-07 17:57:00 +06002215 Binop_23x<HAnd>(instruction, Primitive::kPrimLong, dex_pc);
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00002216 break;
2217 }
2218
Calin Juravle9aec02f2014-11-18 23:06:35 +00002219 case Instruction::SHL_INT: {
Yevgeny Rouban3ecfd652015-09-07 17:57:00 +06002220 Binop_23x_shift<HShl>(instruction, Primitive::kPrimInt, dex_pc);
Calin Juravle9aec02f2014-11-18 23:06:35 +00002221 break;
2222 }
2223
2224 case Instruction::SHL_LONG: {
Yevgeny Rouban3ecfd652015-09-07 17:57:00 +06002225 Binop_23x_shift<HShl>(instruction, Primitive::kPrimLong, dex_pc);
Calin Juravle9aec02f2014-11-18 23:06:35 +00002226 break;
2227 }
2228
2229 case Instruction::SHR_INT: {
Yevgeny Rouban3ecfd652015-09-07 17:57:00 +06002230 Binop_23x_shift<HShr>(instruction, Primitive::kPrimInt, dex_pc);
Calin Juravle9aec02f2014-11-18 23:06:35 +00002231 break;
2232 }
2233
2234 case Instruction::SHR_LONG: {
Yevgeny Rouban3ecfd652015-09-07 17:57:00 +06002235 Binop_23x_shift<HShr>(instruction, Primitive::kPrimLong, dex_pc);
Calin Juravle9aec02f2014-11-18 23:06:35 +00002236 break;
2237 }
2238
2239 case Instruction::USHR_INT: {
Yevgeny Rouban3ecfd652015-09-07 17:57:00 +06002240 Binop_23x_shift<HUShr>(instruction, Primitive::kPrimInt, dex_pc);
Calin Juravle9aec02f2014-11-18 23:06:35 +00002241 break;
2242 }
2243
2244 case Instruction::USHR_LONG: {
Yevgeny Rouban3ecfd652015-09-07 17:57:00 +06002245 Binop_23x_shift<HUShr>(instruction, Primitive::kPrimLong, dex_pc);
Calin Juravle9aec02f2014-11-18 23:06:35 +00002246 break;
2247 }
2248
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00002249 case Instruction::OR_INT: {
Yevgeny Rouban3ecfd652015-09-07 17:57:00 +06002250 Binop_23x<HOr>(instruction, Primitive::kPrimInt, dex_pc);
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00002251 break;
2252 }
2253
2254 case Instruction::OR_LONG: {
Yevgeny Rouban3ecfd652015-09-07 17:57:00 +06002255 Binop_23x<HOr>(instruction, Primitive::kPrimLong, dex_pc);
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00002256 break;
2257 }
2258
2259 case Instruction::XOR_INT: {
Yevgeny Rouban3ecfd652015-09-07 17:57:00 +06002260 Binop_23x<HXor>(instruction, Primitive::kPrimInt, dex_pc);
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00002261 break;
2262 }
2263
2264 case Instruction::XOR_LONG: {
Yevgeny Rouban3ecfd652015-09-07 17:57:00 +06002265 Binop_23x<HXor>(instruction, Primitive::kPrimLong, dex_pc);
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00002266 break;
2267 }
2268
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002269 case Instruction::ADD_LONG_2ADDR: {
Yevgeny Rouban3ecfd652015-09-07 17:57:00 +06002270 Binop_12x<HAdd>(instruction, Primitive::kPrimLong, dex_pc);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002271 break;
2272 }
2273
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01002274 case Instruction::ADD_DOUBLE_2ADDR: {
Yevgeny Rouban3ecfd652015-09-07 17:57:00 +06002275 Binop_12x<HAdd>(instruction, Primitive::kPrimDouble, dex_pc);
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01002276 break;
2277 }
2278
2279 case Instruction::ADD_FLOAT_2ADDR: {
Yevgeny Rouban3ecfd652015-09-07 17:57:00 +06002280 Binop_12x<HAdd>(instruction, Primitive::kPrimFloat, dex_pc);
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01002281 break;
2282 }
2283
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002284 case Instruction::SUB_INT_2ADDR: {
Yevgeny Rouban3ecfd652015-09-07 17:57:00 +06002285 Binop_12x<HSub>(instruction, Primitive::kPrimInt, dex_pc);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002286 break;
2287 }
2288
2289 case Instruction::SUB_LONG_2ADDR: {
Yevgeny Rouban3ecfd652015-09-07 17:57:00 +06002290 Binop_12x<HSub>(instruction, Primitive::kPrimLong, dex_pc);
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00002291 break;
2292 }
2293
Calin Juravle096cc022014-10-23 17:01:13 +01002294 case Instruction::SUB_FLOAT_2ADDR: {
Yevgeny Rouban3ecfd652015-09-07 17:57:00 +06002295 Binop_12x<HSub>(instruction, Primitive::kPrimFloat, dex_pc);
Calin Juravle096cc022014-10-23 17:01:13 +01002296 break;
2297 }
2298
2299 case Instruction::SUB_DOUBLE_2ADDR: {
Yevgeny Rouban3ecfd652015-09-07 17:57:00 +06002300 Binop_12x<HSub>(instruction, Primitive::kPrimDouble, dex_pc);
Calin Juravle096cc022014-10-23 17:01:13 +01002301 break;
2302 }
2303
Calin Juravle34bacdf2014-10-07 20:23:36 +01002304 case Instruction::MUL_INT_2ADDR: {
Yevgeny Rouban3ecfd652015-09-07 17:57:00 +06002305 Binop_12x<HMul>(instruction, Primitive::kPrimInt, dex_pc);
Calin Juravle34bacdf2014-10-07 20:23:36 +01002306 break;
2307 }
2308
2309 case Instruction::MUL_LONG_2ADDR: {
Yevgeny Rouban3ecfd652015-09-07 17:57:00 +06002310 Binop_12x<HMul>(instruction, Primitive::kPrimLong, dex_pc);
Calin Juravle34bacdf2014-10-07 20:23:36 +01002311 break;
2312 }
2313
Calin Juravleb5bfa962014-10-21 18:02:24 +01002314 case Instruction::MUL_FLOAT_2ADDR: {
Yevgeny Rouban3ecfd652015-09-07 17:57:00 +06002315 Binop_12x<HMul>(instruction, Primitive::kPrimFloat, dex_pc);
Calin Juravleb5bfa962014-10-21 18:02:24 +01002316 break;
2317 }
2318
2319 case Instruction::MUL_DOUBLE_2ADDR: {
Yevgeny Rouban3ecfd652015-09-07 17:57:00 +06002320 Binop_12x<HMul>(instruction, Primitive::kPrimDouble, dex_pc);
Calin Juravleb5bfa962014-10-21 18:02:24 +01002321 break;
2322 }
2323
Calin Juravle865fc882014-11-06 17:09:03 +00002324 case Instruction::DIV_INT_2ADDR: {
Calin Juravlebacfec32014-11-14 15:54:36 +00002325 BuildCheckedDivRem(instruction.VRegA(), instruction.VRegA(), instruction.VRegB(),
2326 dex_pc, Primitive::kPrimInt, false, true);
Calin Juravle865fc882014-11-06 17:09:03 +00002327 break;
2328 }
2329
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002330 case Instruction::DIV_LONG_2ADDR: {
Calin Juravlebacfec32014-11-14 15:54:36 +00002331 BuildCheckedDivRem(instruction.VRegA(), instruction.VRegA(), instruction.VRegB(),
2332 dex_pc, Primitive::kPrimLong, false, true);
2333 break;
2334 }
2335
2336 case Instruction::REM_INT_2ADDR: {
2337 BuildCheckedDivRem(instruction.VRegA(), instruction.VRegA(), instruction.VRegB(),
2338 dex_pc, Primitive::kPrimInt, false, false);
2339 break;
2340 }
2341
2342 case Instruction::REM_LONG_2ADDR: {
2343 BuildCheckedDivRem(instruction.VRegA(), instruction.VRegA(), instruction.VRegB(),
2344 dex_pc, Primitive::kPrimLong, false, false);
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002345 break;
2346 }
2347
Calin Juravled2ec87d2014-12-08 14:24:46 +00002348 case Instruction::REM_FLOAT_2ADDR: {
2349 Binop_12x<HRem>(instruction, Primitive::kPrimFloat, dex_pc);
2350 break;
2351 }
2352
2353 case Instruction::REM_DOUBLE_2ADDR: {
2354 Binop_12x<HRem>(instruction, Primitive::kPrimDouble, dex_pc);
2355 break;
2356 }
2357
Calin Juravle9aec02f2014-11-18 23:06:35 +00002358 case Instruction::SHL_INT_2ADDR: {
Yevgeny Rouban3ecfd652015-09-07 17:57:00 +06002359 Binop_12x_shift<HShl>(instruction, Primitive::kPrimInt, dex_pc);
Calin Juravle9aec02f2014-11-18 23:06:35 +00002360 break;
2361 }
2362
2363 case Instruction::SHL_LONG_2ADDR: {
Yevgeny Rouban3ecfd652015-09-07 17:57:00 +06002364 Binop_12x_shift<HShl>(instruction, Primitive::kPrimLong, dex_pc);
Calin Juravle9aec02f2014-11-18 23:06:35 +00002365 break;
2366 }
2367
2368 case Instruction::SHR_INT_2ADDR: {
Yevgeny Rouban3ecfd652015-09-07 17:57:00 +06002369 Binop_12x_shift<HShr>(instruction, Primitive::kPrimInt, dex_pc);
Calin Juravle9aec02f2014-11-18 23:06:35 +00002370 break;
2371 }
2372
2373 case Instruction::SHR_LONG_2ADDR: {
Yevgeny Rouban3ecfd652015-09-07 17:57:00 +06002374 Binop_12x_shift<HShr>(instruction, Primitive::kPrimLong, dex_pc);
Calin Juravle9aec02f2014-11-18 23:06:35 +00002375 break;
2376 }
2377
2378 case Instruction::USHR_INT_2ADDR: {
Yevgeny Rouban3ecfd652015-09-07 17:57:00 +06002379 Binop_12x_shift<HUShr>(instruction, Primitive::kPrimInt, dex_pc);
Calin Juravle9aec02f2014-11-18 23:06:35 +00002380 break;
2381 }
2382
2383 case Instruction::USHR_LONG_2ADDR: {
Yevgeny Rouban3ecfd652015-09-07 17:57:00 +06002384 Binop_12x_shift<HUShr>(instruction, Primitive::kPrimLong, dex_pc);
Calin Juravle9aec02f2014-11-18 23:06:35 +00002385 break;
2386 }
2387
Calin Juravle7c4954d2014-10-28 16:57:40 +00002388 case Instruction::DIV_FLOAT_2ADDR: {
Calin Juravle225ff812014-11-13 16:46:39 +00002389 Binop_12x<HDiv>(instruction, Primitive::kPrimFloat, dex_pc);
Calin Juravle7c4954d2014-10-28 16:57:40 +00002390 break;
2391 }
2392
2393 case Instruction::DIV_DOUBLE_2ADDR: {
Calin Juravle225ff812014-11-13 16:46:39 +00002394 Binop_12x<HDiv>(instruction, Primitive::kPrimDouble, dex_pc);
Calin Juravle7c4954d2014-10-28 16:57:40 +00002395 break;
2396 }
2397
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00002398 case Instruction::AND_INT_2ADDR: {
Yevgeny Rouban3ecfd652015-09-07 17:57:00 +06002399 Binop_12x<HAnd>(instruction, Primitive::kPrimInt, dex_pc);
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00002400 break;
2401 }
2402
2403 case Instruction::AND_LONG_2ADDR: {
Yevgeny Rouban3ecfd652015-09-07 17:57:00 +06002404 Binop_12x<HAnd>(instruction, Primitive::kPrimLong, dex_pc);
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00002405 break;
2406 }
2407
2408 case Instruction::OR_INT_2ADDR: {
Yevgeny Rouban3ecfd652015-09-07 17:57:00 +06002409 Binop_12x<HOr>(instruction, Primitive::kPrimInt, dex_pc);
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00002410 break;
2411 }
2412
2413 case Instruction::OR_LONG_2ADDR: {
Yevgeny Rouban3ecfd652015-09-07 17:57:00 +06002414 Binop_12x<HOr>(instruction, Primitive::kPrimLong, dex_pc);
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00002415 break;
2416 }
2417
2418 case Instruction::XOR_INT_2ADDR: {
Yevgeny Rouban3ecfd652015-09-07 17:57:00 +06002419 Binop_12x<HXor>(instruction, Primitive::kPrimInt, dex_pc);
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00002420 break;
2421 }
2422
2423 case Instruction::XOR_LONG_2ADDR: {
Yevgeny Rouban3ecfd652015-09-07 17:57:00 +06002424 Binop_12x<HXor>(instruction, Primitive::kPrimLong, dex_pc);
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00002425 break;
2426 }
2427
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00002428 case Instruction::ADD_INT_LIT16: {
Yevgeny Rouban3ecfd652015-09-07 17:57:00 +06002429 Binop_22s<HAdd>(instruction, false, dex_pc);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002430 break;
2431 }
2432
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00002433 case Instruction::AND_INT_LIT16: {
Yevgeny Rouban3ecfd652015-09-07 17:57:00 +06002434 Binop_22s<HAnd>(instruction, false, dex_pc);
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00002435 break;
2436 }
2437
2438 case Instruction::OR_INT_LIT16: {
Yevgeny Rouban3ecfd652015-09-07 17:57:00 +06002439 Binop_22s<HOr>(instruction, false, dex_pc);
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00002440 break;
2441 }
2442
2443 case Instruction::XOR_INT_LIT16: {
Yevgeny Rouban3ecfd652015-09-07 17:57:00 +06002444 Binop_22s<HXor>(instruction, false, dex_pc);
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00002445 break;
2446 }
2447
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002448 case Instruction::RSUB_INT: {
Yevgeny Rouban3ecfd652015-09-07 17:57:00 +06002449 Binop_22s<HSub>(instruction, true, dex_pc);
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00002450 break;
2451 }
2452
Calin Juravle34bacdf2014-10-07 20:23:36 +01002453 case Instruction::MUL_INT_LIT16: {
Yevgeny Rouban3ecfd652015-09-07 17:57:00 +06002454 Binop_22s<HMul>(instruction, false, dex_pc);
Calin Juravle34bacdf2014-10-07 20:23:36 +01002455 break;
2456 }
2457
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00002458 case Instruction::ADD_INT_LIT8: {
Yevgeny Rouban3ecfd652015-09-07 17:57:00 +06002459 Binop_22b<HAdd>(instruction, false, dex_pc);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002460 break;
2461 }
2462
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00002463 case Instruction::AND_INT_LIT8: {
Yevgeny Rouban3ecfd652015-09-07 17:57:00 +06002464 Binop_22b<HAnd>(instruction, false, dex_pc);
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00002465 break;
2466 }
2467
2468 case Instruction::OR_INT_LIT8: {
Yevgeny Rouban3ecfd652015-09-07 17:57:00 +06002469 Binop_22b<HOr>(instruction, false, dex_pc);
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00002470 break;
2471 }
2472
2473 case Instruction::XOR_INT_LIT8: {
Yevgeny Rouban3ecfd652015-09-07 17:57:00 +06002474 Binop_22b<HXor>(instruction, false, dex_pc);
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00002475 break;
2476 }
2477
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002478 case Instruction::RSUB_INT_LIT8: {
Yevgeny Rouban3ecfd652015-09-07 17:57:00 +06002479 Binop_22b<HSub>(instruction, true, dex_pc);
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00002480 break;
2481 }
2482
Calin Juravle34bacdf2014-10-07 20:23:36 +01002483 case Instruction::MUL_INT_LIT8: {
Yevgeny Rouban3ecfd652015-09-07 17:57:00 +06002484 Binop_22b<HMul>(instruction, false, dex_pc);
Calin Juravle34bacdf2014-10-07 20:23:36 +01002485 break;
2486 }
2487
Calin Juravled0d48522014-11-04 16:40:20 +00002488 case Instruction::DIV_INT_LIT16:
2489 case Instruction::DIV_INT_LIT8: {
Calin Juravlebacfec32014-11-14 15:54:36 +00002490 BuildCheckedDivRem(instruction.VRegA(), instruction.VRegB(), instruction.VRegC(),
2491 dex_pc, Primitive::kPrimInt, true, true);
2492 break;
2493 }
2494
2495 case Instruction::REM_INT_LIT16:
2496 case Instruction::REM_INT_LIT8: {
2497 BuildCheckedDivRem(instruction.VRegA(), instruction.VRegB(), instruction.VRegC(),
2498 dex_pc, Primitive::kPrimInt, true, false);
Calin Juravled0d48522014-11-04 16:40:20 +00002499 break;
2500 }
2501
Calin Juravle9aec02f2014-11-18 23:06:35 +00002502 case Instruction::SHL_INT_LIT8: {
Yevgeny Rouban3ecfd652015-09-07 17:57:00 +06002503 Binop_22b<HShl>(instruction, false, dex_pc);
Calin Juravle9aec02f2014-11-18 23:06:35 +00002504 break;
2505 }
2506
2507 case Instruction::SHR_INT_LIT8: {
Yevgeny Rouban3ecfd652015-09-07 17:57:00 +06002508 Binop_22b<HShr>(instruction, false, dex_pc);
Calin Juravle9aec02f2014-11-18 23:06:35 +00002509 break;
2510 }
2511
2512 case Instruction::USHR_INT_LIT8: {
Yevgeny Rouban3ecfd652015-09-07 17:57:00 +06002513 Binop_22b<HUShr>(instruction, false, dex_pc);
Calin Juravle9aec02f2014-11-18 23:06:35 +00002514 break;
2515 }
2516
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01002517 case Instruction::NEW_INSTANCE: {
Nicolas Geoffraycb1b00a2015-01-28 14:50:01 +00002518 uint16_t type_index = instruction.VRegB_21c();
Jeff Hao848f70a2014-01-15 13:49:50 -08002519 if (compiler_driver_->IsStringTypeIndex(type_index, dex_file_)) {
Jeff Hao848f70a2014-01-15 13:49:50 -08002520 int32_t register_index = instruction.VRegA();
Yevgeny Rouban3ecfd652015-09-07 17:57:00 +06002521 HFakeString* fake_string = new (arena_) HFakeString(dex_pc);
Nicolas Geoffray2e7cd752015-07-10 11:38:52 +01002522 current_block_->AddInstruction(fake_string);
Yevgeny Rouban3ecfd652015-09-07 17:57:00 +06002523 UpdateLocal(register_index, fake_string, dex_pc);
Jeff Hao848f70a2014-01-15 13:49:50 -08002524 } else {
2525 QuickEntrypointEnum entrypoint = NeedsAccessCheck(type_index)
2526 ? kQuickAllocObjectWithAccessCheck
2527 : kQuickAllocObject;
Nicolas Geoffraycb1b00a2015-01-28 14:50:01 +00002528
Nicolas Geoffrayd5111bf2015-05-22 15:37:09 +01002529 current_block_->AddInstruction(new (arena_) HNewInstance(
Nicolas Geoffray69aa6012015-06-09 10:34:25 +01002530 graph_->GetCurrentMethod(),
2531 dex_pc,
2532 type_index,
2533 *dex_compilation_unit_->GetDexFile(),
2534 entrypoint));
Yevgeny Rouban3ecfd652015-09-07 17:57:00 +06002535 UpdateLocal(instruction.VRegA(), current_block_->GetLastInstruction(), dex_pc);
Jeff Hao848f70a2014-01-15 13:49:50 -08002536 }
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01002537 break;
2538 }
2539
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01002540 case Instruction::NEW_ARRAY: {
Nicolas Geoffraycb1b00a2015-01-28 14:50:01 +00002541 uint16_t type_index = instruction.VRegC_22c();
Yevgeny Rouban3ecfd652015-09-07 17:57:00 +06002542 HInstruction* length = LoadLocal(instruction.VRegB_22c(), Primitive::kPrimInt, dex_pc);
Nicolas Geoffraycb1b00a2015-01-28 14:50:01 +00002543 QuickEntrypointEnum entrypoint = NeedsAccessCheck(type_index)
2544 ? kQuickAllocArrayWithAccessCheck
2545 : kQuickAllocArray;
Nicolas Geoffray69aa6012015-06-09 10:34:25 +01002546 current_block_->AddInstruction(new (arena_) HNewArray(length,
2547 graph_->GetCurrentMethod(),
2548 dex_pc,
2549 type_index,
2550 *dex_compilation_unit_->GetDexFile(),
2551 entrypoint));
Yevgeny Rouban3ecfd652015-09-07 17:57:00 +06002552 UpdateLocal(instruction.VRegA_22c(), current_block_->GetLastInstruction(), dex_pc);
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01002553 break;
2554 }
2555
2556 case Instruction::FILLED_NEW_ARRAY: {
2557 uint32_t number_of_vreg_arguments = instruction.VRegA_35c();
2558 uint32_t type_index = instruction.VRegB_35c();
2559 uint32_t args[5];
2560 instruction.GetVarArgs(args);
Calin Juravle225ff812014-11-13 16:46:39 +00002561 BuildFilledNewArray(dex_pc, type_index, number_of_vreg_arguments, false, args, 0);
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01002562 break;
2563 }
2564
2565 case Instruction::FILLED_NEW_ARRAY_RANGE: {
2566 uint32_t number_of_vreg_arguments = instruction.VRegA_3rc();
2567 uint32_t type_index = instruction.VRegB_3rc();
2568 uint32_t register_index = instruction.VRegC_3rc();
2569 BuildFilledNewArray(
Calin Juravle225ff812014-11-13 16:46:39 +00002570 dex_pc, type_index, number_of_vreg_arguments, true, nullptr, register_index);
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01002571 break;
2572 }
2573
2574 case Instruction::FILL_ARRAY_DATA: {
Calin Juravle225ff812014-11-13 16:46:39 +00002575 BuildFillArrayData(instruction, dex_pc);
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01002576 break;
2577 }
2578
Nicolas Geoffrayddb311f2014-05-16 09:28:54 +01002579 case Instruction::MOVE_RESULT:
Dave Allison20dfc792014-06-16 20:44:29 -07002580 case Instruction::MOVE_RESULT_WIDE:
David Brazdilfc6a86a2015-06-26 10:33:45 +00002581 case Instruction::MOVE_RESULT_OBJECT: {
Nicolas Geoffray1efcc222015-06-24 12:41:20 +01002582 if (latest_result_ == nullptr) {
2583 // Only dead code can lead to this situation, where the verifier
2584 // does not reject the method.
2585 } else {
David Brazdilfc6a86a2015-06-26 10:33:45 +00002586 // An Invoke/FilledNewArray and its MoveResult could have landed in
2587 // different blocks if there was a try/catch block boundary between
2588 // them. For Invoke, we insert a StoreLocal after the instruction. For
2589 // FilledNewArray, the local needs to be updated after the array was
2590 // filled, otherwise we might overwrite an input vreg.
2591 HStoreLocal* update_local =
Yevgeny Rouban3ecfd652015-09-07 17:57:00 +06002592 new (arena_) HStoreLocal(GetLocalAt(instruction.VRegA()), latest_result_, dex_pc);
David Brazdilfc6a86a2015-06-26 10:33:45 +00002593 HBasicBlock* block = latest_result_->GetBlock();
2594 if (block == current_block_) {
2595 // MoveResult and the previous instruction are in the same block.
2596 current_block_->AddInstruction(update_local);
2597 } else {
2598 // The two instructions are in different blocks. Insert the MoveResult
2599 // before the final control-flow instruction of the previous block.
2600 DCHECK(block->EndsWithControlFlowInstruction());
2601 DCHECK(current_block_->GetInstructions().IsEmpty());
2602 block->InsertInstructionBefore(update_local, block->GetLastInstruction());
2603 }
Nicolas Geoffray1efcc222015-06-24 12:41:20 +01002604 latest_result_ = nullptr;
2605 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002606 break;
David Brazdilfc6a86a2015-06-26 10:33:45 +00002607 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002608
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002609 case Instruction::CMP_LONG: {
Roland Levillain4fa13f62015-07-06 18:11:54 +01002610 Binop_23x_cmp(instruction, Primitive::kPrimLong, ComparisonBias::kNoBias, dex_pc);
Calin Juravleddb7df22014-11-25 20:56:51 +00002611 break;
2612 }
2613
2614 case Instruction::CMPG_FLOAT: {
Roland Levillain4fa13f62015-07-06 18:11:54 +01002615 Binop_23x_cmp(instruction, Primitive::kPrimFloat, ComparisonBias::kGtBias, dex_pc);
Calin Juravleddb7df22014-11-25 20:56:51 +00002616 break;
2617 }
2618
2619 case Instruction::CMPG_DOUBLE: {
Roland Levillain4fa13f62015-07-06 18:11:54 +01002620 Binop_23x_cmp(instruction, Primitive::kPrimDouble, ComparisonBias::kGtBias, dex_pc);
Calin Juravleddb7df22014-11-25 20:56:51 +00002621 break;
2622 }
2623
2624 case Instruction::CMPL_FLOAT: {
Roland Levillain4fa13f62015-07-06 18:11:54 +01002625 Binop_23x_cmp(instruction, Primitive::kPrimFloat, ComparisonBias::kLtBias, dex_pc);
Calin Juravleddb7df22014-11-25 20:56:51 +00002626 break;
2627 }
2628
2629 case Instruction::CMPL_DOUBLE: {
Roland Levillain4fa13f62015-07-06 18:11:54 +01002630 Binop_23x_cmp(instruction, Primitive::kPrimDouble, ComparisonBias::kLtBias, dex_pc);
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002631 break;
2632 }
2633
Nicolas Geoffraybe9a92a2014-02-25 14:22:56 +00002634 case Instruction::NOP:
2635 break;
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00002636
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002637 case Instruction::IGET:
Nicolas Geoffray9523a3e2015-07-17 11:51:28 +00002638 case Instruction::IGET_QUICK:
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002639 case Instruction::IGET_WIDE:
Nicolas Geoffray9523a3e2015-07-17 11:51:28 +00002640 case Instruction::IGET_WIDE_QUICK:
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002641 case Instruction::IGET_OBJECT:
Nicolas Geoffray9523a3e2015-07-17 11:51:28 +00002642 case Instruction::IGET_OBJECT_QUICK:
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002643 case Instruction::IGET_BOOLEAN:
Nicolas Geoffray9523a3e2015-07-17 11:51:28 +00002644 case Instruction::IGET_BOOLEAN_QUICK:
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002645 case Instruction::IGET_BYTE:
Nicolas Geoffray9523a3e2015-07-17 11:51:28 +00002646 case Instruction::IGET_BYTE_QUICK:
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002647 case Instruction::IGET_CHAR:
Nicolas Geoffray9523a3e2015-07-17 11:51:28 +00002648 case Instruction::IGET_CHAR_QUICK:
2649 case Instruction::IGET_SHORT:
2650 case Instruction::IGET_SHORT_QUICK: {
Calin Juravle225ff812014-11-13 16:46:39 +00002651 if (!BuildInstanceFieldAccess(instruction, dex_pc, false)) {
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002652 return false;
2653 }
2654 break;
2655 }
2656
2657 case Instruction::IPUT:
Nicolas Geoffray9523a3e2015-07-17 11:51:28 +00002658 case Instruction::IPUT_QUICK:
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002659 case Instruction::IPUT_WIDE:
Nicolas Geoffray9523a3e2015-07-17 11:51:28 +00002660 case Instruction::IPUT_WIDE_QUICK:
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002661 case Instruction::IPUT_OBJECT:
Nicolas Geoffray9523a3e2015-07-17 11:51:28 +00002662 case Instruction::IPUT_OBJECT_QUICK:
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002663 case Instruction::IPUT_BOOLEAN:
Nicolas Geoffray9523a3e2015-07-17 11:51:28 +00002664 case Instruction::IPUT_BOOLEAN_QUICK:
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002665 case Instruction::IPUT_BYTE:
Nicolas Geoffray9523a3e2015-07-17 11:51:28 +00002666 case Instruction::IPUT_BYTE_QUICK:
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002667 case Instruction::IPUT_CHAR:
Nicolas Geoffray9523a3e2015-07-17 11:51:28 +00002668 case Instruction::IPUT_CHAR_QUICK:
2669 case Instruction::IPUT_SHORT:
2670 case Instruction::IPUT_SHORT_QUICK: {
Calin Juravle225ff812014-11-13 16:46:39 +00002671 if (!BuildInstanceFieldAccess(instruction, dex_pc, true)) {
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01002672 return false;
2673 }
2674 break;
2675 }
2676
2677 case Instruction::SGET:
2678 case Instruction::SGET_WIDE:
2679 case Instruction::SGET_OBJECT:
2680 case Instruction::SGET_BOOLEAN:
2681 case Instruction::SGET_BYTE:
2682 case Instruction::SGET_CHAR:
2683 case Instruction::SGET_SHORT: {
Calin Juravle225ff812014-11-13 16:46:39 +00002684 if (!BuildStaticFieldAccess(instruction, dex_pc, false)) {
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01002685 return false;
2686 }
2687 break;
2688 }
2689
2690 case Instruction::SPUT:
2691 case Instruction::SPUT_WIDE:
2692 case Instruction::SPUT_OBJECT:
2693 case Instruction::SPUT_BOOLEAN:
2694 case Instruction::SPUT_BYTE:
2695 case Instruction::SPUT_CHAR:
2696 case Instruction::SPUT_SHORT: {
Calin Juravle225ff812014-11-13 16:46:39 +00002697 if (!BuildStaticFieldAccess(instruction, dex_pc, true)) {
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002698 return false;
2699 }
2700 break;
2701 }
2702
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002703#define ARRAY_XX(kind, anticipated_type) \
2704 case Instruction::AGET##kind: { \
Calin Juravle225ff812014-11-13 16:46:39 +00002705 BuildArrayAccess(instruction, dex_pc, false, anticipated_type); \
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002706 break; \
2707 } \
2708 case Instruction::APUT##kind: { \
Calin Juravle225ff812014-11-13 16:46:39 +00002709 BuildArrayAccess(instruction, dex_pc, true, anticipated_type); \
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002710 break; \
2711 }
2712
2713 ARRAY_XX(, Primitive::kPrimInt);
2714 ARRAY_XX(_WIDE, Primitive::kPrimLong);
2715 ARRAY_XX(_OBJECT, Primitive::kPrimNot);
2716 ARRAY_XX(_BOOLEAN, Primitive::kPrimBoolean);
2717 ARRAY_XX(_BYTE, Primitive::kPrimByte);
2718 ARRAY_XX(_CHAR, Primitive::kPrimChar);
2719 ARRAY_XX(_SHORT, Primitive::kPrimShort);
2720
Nicolas Geoffray39468442014-09-02 15:17:15 +01002721 case Instruction::ARRAY_LENGTH: {
Yevgeny Rouban3ecfd652015-09-07 17:57:00 +06002722 HInstruction* object = LoadLocal(instruction.VRegB_12x(), Primitive::kPrimNot, dex_pc);
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +00002723 // No need for a temporary for the null check, it is the only input of the following
2724 // instruction.
Calin Juravle225ff812014-11-13 16:46:39 +00002725 object = new (arena_) HNullCheck(object, dex_pc);
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +00002726 current_block_->AddInstruction(object);
Yevgeny Rouban3ecfd652015-09-07 17:57:00 +06002727 current_block_->AddInstruction(new (arena_) HArrayLength(object, dex_pc));
2728 UpdateLocal(instruction.VRegA_12x(), current_block_->GetLastInstruction(), dex_pc);
Nicolas Geoffray39468442014-09-02 15:17:15 +01002729 break;
2730 }
2731
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +00002732 case Instruction::CONST_STRING: {
Nicolas Geoffrayfbdaa302015-05-29 12:06:56 +01002733 current_block_->AddInstruction(
2734 new (arena_) HLoadString(graph_->GetCurrentMethod(), instruction.VRegB_21c(), dex_pc));
Yevgeny Rouban3ecfd652015-09-07 17:57:00 +06002735 UpdateLocal(instruction.VRegA_21c(), current_block_->GetLastInstruction(), dex_pc);
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +00002736 break;
2737 }
2738
2739 case Instruction::CONST_STRING_JUMBO: {
Nicolas Geoffrayfbdaa302015-05-29 12:06:56 +01002740 current_block_->AddInstruction(
2741 new (arena_) HLoadString(graph_->GetCurrentMethod(), instruction.VRegB_31c(), dex_pc));
Yevgeny Rouban3ecfd652015-09-07 17:57:00 +06002742 UpdateLocal(instruction.VRegA_31c(), current_block_->GetLastInstruction(), dex_pc);
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +00002743 break;
2744 }
2745
Nicolas Geoffray424f6762014-11-03 14:51:25 +00002746 case Instruction::CONST_CLASS: {
2747 uint16_t type_index = instruction.VRegB_21c();
2748 bool type_known_final;
2749 bool type_known_abstract;
Nicolas Geoffraye53798a2014-12-01 10:31:54 +00002750 bool dont_use_is_referrers_class;
2751 // `CanAccessTypeWithoutChecks` will tell whether the method being
2752 // built is trying to access its own class, so that the generated
2753 // code can optimize for this case. However, the optimization does not
Nicolas Geoffray9437b782015-03-25 10:08:51 +00002754 // work for inlining, so we use `IsOutermostCompilingClass` instead.
Nicolas Geoffray424f6762014-11-03 14:51:25 +00002755 bool can_access = compiler_driver_->CanAccessTypeWithoutChecks(
2756 dex_compilation_unit_->GetDexMethodIndex(), *dex_file_, type_index,
Nicolas Geoffraye53798a2014-12-01 10:31:54 +00002757 &type_known_final, &type_known_abstract, &dont_use_is_referrers_class);
Nicolas Geoffray424f6762014-11-03 14:51:25 +00002758 if (!can_access) {
Calin Juravle48c2b032014-12-09 18:11:36 +00002759 MaybeRecordStat(MethodCompilationStat::kNotCompiledCantAccesType);
Nicolas Geoffray424f6762014-11-03 14:51:25 +00002760 return false;
2761 }
Nicolas Geoffrayd5111bf2015-05-22 15:37:09 +01002762 current_block_->AddInstruction(new (arena_) HLoadClass(
Nicolas Geoffray76b1e172015-05-27 17:18:33 +01002763 graph_->GetCurrentMethod(),
Nicolas Geoffrayd5111bf2015-05-22 15:37:09 +01002764 type_index,
2765 *dex_compilation_unit_->GetDexFile(),
2766 IsOutermostCompilingClass(type_index),
2767 dex_pc));
Yevgeny Rouban3ecfd652015-09-07 17:57:00 +06002768 UpdateLocal(instruction.VRegA_21c(), current_block_->GetLastInstruction(), dex_pc);
Nicolas Geoffray424f6762014-11-03 14:51:25 +00002769 break;
2770 }
2771
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +00002772 case Instruction::MOVE_EXCEPTION: {
Yevgeny Rouban3ecfd652015-09-07 17:57:00 +06002773 current_block_->AddInstruction(new (arena_) HLoadException(dex_pc));
2774 UpdateLocal(instruction.VRegA_11x(), current_block_->GetLastInstruction(), dex_pc);
2775 current_block_->AddInstruction(new (arena_) HClearException(dex_pc));
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +00002776 break;
2777 }
2778
2779 case Instruction::THROW: {
Yevgeny Rouban3ecfd652015-09-07 17:57:00 +06002780 HInstruction* exception = LoadLocal(instruction.VRegA_11x(), Primitive::kPrimNot, dex_pc);
Calin Juravle225ff812014-11-13 16:46:39 +00002781 current_block_->AddInstruction(new (arena_) HThrow(exception, dex_pc));
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +00002782 // A throw instruction must branch to the exit block.
2783 current_block_->AddSuccessor(exit_block_);
2784 // We finished building this block. Set the current block to null to avoid
2785 // adding dead instructions to it.
2786 current_block_ = nullptr;
2787 break;
2788 }
2789
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00002790 case Instruction::INSTANCE_OF: {
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00002791 uint8_t destination = instruction.VRegA_22c();
2792 uint8_t reference = instruction.VRegB_22c();
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00002793 uint16_t type_index = instruction.VRegC_22c();
Calin Juravle225ff812014-11-13 16:46:39 +00002794 if (!BuildTypeCheck(instruction, destination, reference, type_index, dex_pc)) {
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00002795 return false;
2796 }
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00002797 break;
2798 }
2799
2800 case Instruction::CHECK_CAST: {
2801 uint8_t reference = instruction.VRegA_21c();
2802 uint16_t type_index = instruction.VRegB_21c();
Calin Juravle225ff812014-11-13 16:46:39 +00002803 if (!BuildTypeCheck(instruction, -1, reference, type_index, dex_pc)) {
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00002804 return false;
2805 }
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00002806 break;
2807 }
2808
Nicolas Geoffrayb7baf5c2014-11-11 16:29:44 +00002809 case Instruction::MONITOR_ENTER: {
2810 current_block_->AddInstruction(new (arena_) HMonitorOperation(
Yevgeny Rouban3ecfd652015-09-07 17:57:00 +06002811 LoadLocal(instruction.VRegA_11x(), Primitive::kPrimNot, dex_pc),
Nicolas Geoffrayb7baf5c2014-11-11 16:29:44 +00002812 HMonitorOperation::kEnter,
Calin Juravle225ff812014-11-13 16:46:39 +00002813 dex_pc));
Nicolas Geoffrayb7baf5c2014-11-11 16:29:44 +00002814 break;
2815 }
2816
2817 case Instruction::MONITOR_EXIT: {
2818 current_block_->AddInstruction(new (arena_) HMonitorOperation(
Yevgeny Rouban3ecfd652015-09-07 17:57:00 +06002819 LoadLocal(instruction.VRegA_11x(), Primitive::kPrimNot, dex_pc),
Nicolas Geoffrayb7baf5c2014-11-11 16:29:44 +00002820 HMonitorOperation::kExit,
Calin Juravle225ff812014-11-13 16:46:39 +00002821 dex_pc));
Nicolas Geoffrayb7baf5c2014-11-11 16:29:44 +00002822 break;
2823 }
2824
Andreas Gamped881df52014-11-24 23:28:39 -08002825 case Instruction::PACKED_SWITCH: {
Calin Juravle48c2b032014-12-09 18:11:36 +00002826 BuildPackedSwitch(instruction, dex_pc);
Andreas Gamped881df52014-11-24 23:28:39 -08002827 break;
2828 }
2829
Andreas Gampee4d4d322014-12-04 09:09:57 -08002830 case Instruction::SPARSE_SWITCH: {
Calin Juravle48c2b032014-12-09 18:11:36 +00002831 BuildSparseSwitch(instruction, dex_pc);
Andreas Gampee4d4d322014-12-04 09:09:57 -08002832 break;
2833 }
2834
Nicolas Geoffray818f2102014-02-18 16:43:35 +00002835 default:
Calin Juravle48c2b032014-12-09 18:11:36 +00002836 VLOG(compiler) << "Did not compile "
2837 << PrettyMethod(dex_compilation_unit_->GetDexMethodIndex(), *dex_file_)
2838 << " because of unhandled instruction "
2839 << instruction.Name();
2840 MaybeRecordStat(MethodCompilationStat::kNotCompiledUnhandledInstruction);
Nicolas Geoffray818f2102014-02-18 16:43:35 +00002841 return false;
2842 }
2843 return true;
Nicolas Geoffraydadf3172014-11-07 16:36:02 +00002844} // NOLINT(readability/fn_size)
Nicolas Geoffray818f2102014-02-18 16:43:35 +00002845
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00002846HLocal* HGraphBuilder::GetLocalAt(int register_index) const {
2847 return locals_.Get(register_index);
2848}
2849
Yevgeny Rouban3ecfd652015-09-07 17:57:00 +06002850void HGraphBuilder::UpdateLocal(int register_index,
2851 HInstruction* instruction,
2852 uint32_t dex_pc) const {
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00002853 HLocal* local = GetLocalAt(register_index);
Yevgeny Rouban3ecfd652015-09-07 17:57:00 +06002854 current_block_->AddInstruction(new (arena_) HStoreLocal(local, instruction, dex_pc));
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00002855}
2856
Yevgeny Rouban3ecfd652015-09-07 17:57:00 +06002857HInstruction* HGraphBuilder::LoadLocal(int register_index,
2858 Primitive::Type type,
2859 uint32_t dex_pc) const {
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00002860 HLocal* local = GetLocalAt(register_index);
Yevgeny Rouban3ecfd652015-09-07 17:57:00 +06002861 current_block_->AddInstruction(new (arena_) HLoadLocal(local, type, dex_pc));
Nicolas Geoffray787c3072014-03-17 10:20:19 +00002862 return current_block_->GetLastInstruction();
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00002863}
2864
Nicolas Geoffray818f2102014-02-18 16:43:35 +00002865} // namespace art