blob: a3bbfdbd27fa13de34d27aa18b6396c325df5d2d [file] [log] [blame]
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +00001/*
2 * 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
17#include "code_generator.h"
18
Alex Light50fa9932015-08-10 15:30:07 -070019#ifdef ART_ENABLE_CODEGEN_arm
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +000020#include "code_generator_arm.h"
Alex Light50fa9932015-08-10 15:30:07 -070021#endif
22
23#ifdef ART_ENABLE_CODEGEN_arm64
Alexandre Rames5319def2014-10-23 10:03:10 +010024#include "code_generator_arm64.h"
Alex Light50fa9932015-08-10 15:30:07 -070025#endif
26
27#ifdef ART_ENABLE_CODEGEN_x86
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +000028#include "code_generator_x86.h"
Alex Light50fa9932015-08-10 15:30:07 -070029#endif
30
31#ifdef ART_ENABLE_CODEGEN_x86_64
Nicolas Geoffray9cf35522014-06-09 18:40:10 +010032#include "code_generator_x86_64.h"
Alex Light50fa9932015-08-10 15:30:07 -070033#endif
34
Goran Jakovljevicf652cec2015-08-25 16:11:42 +020035#ifdef ART_ENABLE_CODEGEN_mips
36#include "code_generator_mips.h"
37#endif
38
Alex Light50fa9932015-08-10 15:30:07 -070039#ifdef ART_ENABLE_CODEGEN_mips64
Alexey Frunze4dda3372015-06-01 18:31:49 -070040#include "code_generator_mips64.h"
Alex Light50fa9932015-08-10 15:30:07 -070041#endif
42
Yevgeny Roubane3ea8382014-08-08 16:29:38 +070043#include "compiled_method.h"
Nicolas Geoffray92cf83e2014-03-18 17:59:20 +000044#include "dex/verified_method.h"
Nicolas Geoffrayd28b9692015-11-04 14:36:55 +000045#include "driver/compiler_driver.h"
Nicolas Geoffray92cf83e2014-03-18 17:59:20 +000046#include "gc_map_builder.h"
Alexandre Rameseb7b7392015-06-19 14:47:01 +010047#include "graph_visualizer.h"
Nicolas Geoffray5bd05a52015-10-13 09:48:30 +010048#include "intrinsics.h"
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +000049#include "leb128.h"
50#include "mapping_table.h"
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +010051#include "mirror/array-inl.h"
52#include "mirror/object_array-inl.h"
53#include "mirror/object_reference.h"
Alex Light50fa9932015-08-10 15:30:07 -070054#include "parallel_move_resolver.h"
Nicolas Geoffray3c049742014-09-24 18:10:46 +010055#include "ssa_liveness_analysis.h"
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +000056#include "utils/assembler.h"
Nicolas Geoffray92cf83e2014-03-18 17:59:20 +000057#include "verifier/dex_gc_map.h"
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +000058#include "vmap_table.h"
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +000059
60namespace art {
61
Alexandre Rames88c13cd2015-04-14 17:35:39 +010062// Return whether a location is consistent with a type.
63static bool CheckType(Primitive::Type type, Location location) {
64 if (location.IsFpuRegister()
65 || (location.IsUnallocated() && (location.GetPolicy() == Location::kRequiresFpuRegister))) {
66 return (type == Primitive::kPrimFloat) || (type == Primitive::kPrimDouble);
67 } else if (location.IsRegister() ||
68 (location.IsUnallocated() && (location.GetPolicy() == Location::kRequiresRegister))) {
69 return Primitive::IsIntegralType(type) || (type == Primitive::kPrimNot);
70 } else if (location.IsRegisterPair()) {
71 return type == Primitive::kPrimLong;
72 } else if (location.IsFpuRegisterPair()) {
73 return type == Primitive::kPrimDouble;
74 } else if (location.IsStackSlot()) {
75 return (Primitive::IsIntegralType(type) && type != Primitive::kPrimLong)
76 || (type == Primitive::kPrimFloat)
77 || (type == Primitive::kPrimNot);
78 } else if (location.IsDoubleStackSlot()) {
79 return (type == Primitive::kPrimLong) || (type == Primitive::kPrimDouble);
80 } else if (location.IsConstant()) {
81 if (location.GetConstant()->IsIntConstant()) {
82 return Primitive::IsIntegralType(type) && (type != Primitive::kPrimLong);
83 } else if (location.GetConstant()->IsNullConstant()) {
84 return type == Primitive::kPrimNot;
85 } else if (location.GetConstant()->IsLongConstant()) {
86 return type == Primitive::kPrimLong;
87 } else if (location.GetConstant()->IsFloatConstant()) {
88 return type == Primitive::kPrimFloat;
89 } else {
90 return location.GetConstant()->IsDoubleConstant()
91 && (type == Primitive::kPrimDouble);
92 }
93 } else {
94 return location.IsInvalid() || (location.GetPolicy() == Location::kAny);
95 }
96}
97
98// Check that a location summary is consistent with an instruction.
99static bool CheckTypeConsistency(HInstruction* instruction) {
100 LocationSummary* locations = instruction->GetLocations();
101 if (locations == nullptr) {
102 return true;
103 }
104
105 if (locations->Out().IsUnallocated()
106 && (locations->Out().GetPolicy() == Location::kSameAsFirstInput)) {
107 DCHECK(CheckType(instruction->GetType(), locations->InAt(0)))
108 << instruction->GetType()
109 << " " << locations->InAt(0);
110 } else {
111 DCHECK(CheckType(instruction->GetType(), locations->Out()))
112 << instruction->GetType()
113 << " " << locations->Out();
114 }
115
116 for (size_t i = 0, e = instruction->InputCount(); i < e; ++i) {
117 DCHECK(CheckType(instruction->InputAt(i)->GetType(), locations->InAt(i)))
118 << instruction->InputAt(i)->GetType()
119 << " " << locations->InAt(i);
120 }
121
122 HEnvironment* environment = instruction->GetEnvironment();
123 for (size_t i = 0; i < instruction->EnvironmentSize(); ++i) {
124 if (environment->GetInstructionAt(i) != nullptr) {
125 Primitive::Type type = environment->GetInstructionAt(i)->GetType();
Nicolas Geoffray0a23d742015-05-07 11:57:35 +0100126 DCHECK(CheckType(type, environment->GetLocationAt(i)))
127 << type << " " << environment->GetLocationAt(i);
Alexandre Rames88c13cd2015-04-14 17:35:39 +0100128 } else {
Nicolas Geoffray0a23d742015-05-07 11:57:35 +0100129 DCHECK(environment->GetLocationAt(i).IsInvalid())
130 << environment->GetLocationAt(i);
Alexandre Rames88c13cd2015-04-14 17:35:39 +0100131 }
132 }
133 return true;
134}
135
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100136size_t CodeGenerator::GetCacheOffset(uint32_t index) {
Vladimir Marko05792b92015-08-03 11:56:49 +0100137 return sizeof(GcRoot<mirror::Object>) * index;
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100138}
139
Mathieu Chartiere401d142015-04-22 13:56:20 -0700140size_t CodeGenerator::GetCachePointerOffset(uint32_t index) {
141 auto pointer_size = InstructionSetPointerSize(GetInstructionSet());
Vladimir Marko05792b92015-08-03 11:56:49 +0100142 return pointer_size * index;
Mathieu Chartiere401d142015-04-22 13:56:20 -0700143}
144
Nicolas Geoffraydc23d832015-02-16 11:15:43 +0000145bool CodeGenerator::GoesToNextBlock(HBasicBlock* current, HBasicBlock* next) const {
Vladimir Markofa6b93c2015-09-15 10:15:55 +0100146 DCHECK_EQ((*block_order_)[current_block_index_], current);
Nicolas Geoffraydc23d832015-02-16 11:15:43 +0000147 return GetNextBlockToEmit() == FirstNonEmptyBlock(next);
148}
149
150HBasicBlock* CodeGenerator::GetNextBlockToEmit() const {
Vladimir Markofa6b93c2015-09-15 10:15:55 +0100151 for (size_t i = current_block_index_ + 1; i < block_order_->size(); ++i) {
152 HBasicBlock* block = (*block_order_)[i];
David Brazdilfc6a86a2015-06-26 10:33:45 +0000153 if (!block->IsSingleJump()) {
Nicolas Geoffraydc23d832015-02-16 11:15:43 +0000154 return block;
155 }
156 }
157 return nullptr;
158}
159
160HBasicBlock* CodeGenerator::FirstNonEmptyBlock(HBasicBlock* block) const {
David Brazdilfc6a86a2015-06-26 10:33:45 +0000161 while (block->IsSingleJump()) {
Vladimir Markoec7802a2015-10-01 20:57:57 +0100162 block = block->GetSuccessors()[0];
Nicolas Geoffraydc23d832015-02-16 11:15:43 +0000163 }
164 return block;
165}
166
Alexandre Rameseb7b7392015-06-19 14:47:01 +0100167class DisassemblyScope {
168 public:
169 DisassemblyScope(HInstruction* instruction, const CodeGenerator& codegen)
170 : codegen_(codegen), instruction_(instruction), start_offset_(static_cast<size_t>(-1)) {
171 if (codegen_.GetDisassemblyInformation() != nullptr) {
172 start_offset_ = codegen_.GetAssembler().CodeSize();
173 }
174 }
175
176 ~DisassemblyScope() {
177 // We avoid building this data when we know it will not be used.
178 if (codegen_.GetDisassemblyInformation() != nullptr) {
179 codegen_.GetDisassemblyInformation()->AddInstructionInterval(
180 instruction_, start_offset_, codegen_.GetAssembler().CodeSize());
181 }
182 }
183
184 private:
185 const CodeGenerator& codegen_;
186 HInstruction* instruction_;
187 size_t start_offset_;
188};
189
190
191void CodeGenerator::GenerateSlowPaths() {
192 size_t code_start = 0;
Vladimir Marko225b6462015-09-28 12:17:40 +0100193 for (SlowPathCode* slow_path : slow_paths_) {
Vladimir Marko0f7dca42015-11-02 14:36:43 +0000194 current_slow_path_ = slow_path;
Alexandre Rameseb7b7392015-06-19 14:47:01 +0100195 if (disasm_info_ != nullptr) {
196 code_start = GetAssembler()->CodeSize();
197 }
Vladimir Marko225b6462015-09-28 12:17:40 +0100198 slow_path->EmitNativeCode(this);
Alexandre Rameseb7b7392015-06-19 14:47:01 +0100199 if (disasm_info_ != nullptr) {
Vladimir Marko225b6462015-09-28 12:17:40 +0100200 disasm_info_->AddSlowPathInterval(slow_path, code_start, GetAssembler()->CodeSize());
Alexandre Rameseb7b7392015-06-19 14:47:01 +0100201 }
202 }
Vladimir Marko0f7dca42015-11-02 14:36:43 +0000203 current_slow_path_ = nullptr;
Alexandre Rameseb7b7392015-06-19 14:47:01 +0100204}
205
David Brazdil58282f42016-01-14 12:45:10 +0000206void CodeGenerator::Compile(CodeAllocator* allocator) {
207 // The register allocator already called `InitializeCodeGeneration`,
208 // where the frame size has been computed.
209 DCHECK(block_order_ != nullptr);
210 Initialize();
211
Nicolas Geoffray8a16d972014-09-11 10:30:02 +0100212 HGraphVisitor* instruction_visitor = GetInstructionVisitor();
Nicolas Geoffray4c204ba2015-02-03 15:12:35 +0000213 DCHECK_EQ(current_block_index_, 0u);
Alexandre Rameseb7b7392015-06-19 14:47:01 +0100214
215 size_t frame_start = GetAssembler()->CodeSize();
Nicolas Geoffray4c204ba2015-02-03 15:12:35 +0000216 GenerateFrameEntry();
David Srbeckyc6b4dd82015-04-07 20:32:43 +0100217 DCHECK_EQ(GetAssembler()->cfi().GetCurrentCFAOffset(), static_cast<int>(frame_size_));
Alexandre Rameseb7b7392015-06-19 14:47:01 +0100218 if (disasm_info_ != nullptr) {
219 disasm_info_->SetFrameEntryInterval(frame_start, GetAssembler()->CodeSize());
220 }
221
Vladimir Markofa6b93c2015-09-15 10:15:55 +0100222 for (size_t e = block_order_->size(); current_block_index_ < e; ++current_block_index_) {
223 HBasicBlock* block = (*block_order_)[current_block_index_];
Nicolas Geoffraydc23d832015-02-16 11:15:43 +0000224 // Don't generate code for an empty block. Its predecessors will branch to its successor
225 // directly. Also, the label of that block will not be emitted, so this helps catch
226 // errors where we reference that label.
David Brazdilfc6a86a2015-06-26 10:33:45 +0000227 if (block->IsSingleJump()) continue;
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100228 Bind(block);
Nicolas Geoffray86dbb9a2014-06-04 11:12:39 +0100229 for (HInstructionIterator it(block->GetInstructions()); !it.Done(); it.Advance()) {
230 HInstruction* current = it.Current();
Alexandre Rameseb7b7392015-06-19 14:47:01 +0100231 DisassemblyScope disassembly_scope(current, *this);
Alexandre Rames88c13cd2015-04-14 17:35:39 +0100232 DCHECK(CheckTypeConsistency(current));
Nicolas Geoffray86dbb9a2014-06-04 11:12:39 +0100233 current->Accept(instruction_visitor);
234 }
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000235 }
Nicolas Geoffray4c204ba2015-02-03 15:12:35 +0000236
Alexandre Rameseb7b7392015-06-19 14:47:01 +0100237 GenerateSlowPaths();
Nicolas Geoffray4c204ba2015-02-03 15:12:35 +0000238
David Brazdil77a48ae2015-09-15 12:34:04 +0000239 // Emit catch stack maps at the end of the stack map stream as expected by the
240 // runtime exception handler.
David Brazdil58282f42016-01-14 12:45:10 +0000241 if (graph_->HasTryCatch()) {
David Brazdil77a48ae2015-09-15 12:34:04 +0000242 RecordCatchBlockInfo();
243 }
244
Nicolas Geoffray4c204ba2015-02-03 15:12:35 +0000245 // Finalize instructions in assember;
Serban Constantinescu32f5b4d2014-11-25 20:05:46 +0000246 Finalize(allocator);
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000247}
248
Serban Constantinescu32f5b4d2014-11-25 20:05:46 +0000249void CodeGenerator::Finalize(CodeAllocator* allocator) {
Nicolas Geoffray86dbb9a2014-06-04 11:12:39 +0100250 size_t code_size = GetAssembler()->CodeSize();
251 uint8_t* buffer = allocator->Allocate(code_size);
Serban Constantinescu32f5b4d2014-11-25 20:05:46 +0000252
Nicolas Geoffray86dbb9a2014-06-04 11:12:39 +0100253 MemoryRegion code(buffer, code_size);
254 GetAssembler()->FinalizeInstructions(code);
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000255}
256
Vladimir Marko58155012015-08-19 12:49:41 +0000257void CodeGenerator::EmitLinkerPatches(ArenaVector<LinkerPatch>* linker_patches ATTRIBUTE_UNUSED) {
258 // No linker patches by default.
259}
260
Nicolas Geoffray4c204ba2015-02-03 15:12:35 +0000261void CodeGenerator::InitializeCodeGeneration(size_t number_of_spill_slots,
262 size_t maximum_number_of_live_core_registers,
Roland Levillain0d5a2812015-11-13 10:07:31 +0000263 size_t maximum_number_of_live_fpu_registers,
Nicolas Geoffray4c204ba2015-02-03 15:12:35 +0000264 size_t number_of_out_slots,
Vladimir Markofa6b93c2015-09-15 10:15:55 +0100265 const ArenaVector<HBasicBlock*>& block_order) {
Nicolas Geoffray4c204ba2015-02-03 15:12:35 +0000266 block_order_ = &block_order;
Vladimir Markofa6b93c2015-09-15 10:15:55 +0100267 DCHECK(!block_order.empty());
268 DCHECK(block_order[0] == GetGraph()->GetEntryBlock());
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000269 ComputeSpillMask();
Nicolas Geoffray3bca0df2014-09-19 11:01:00 +0100270 first_register_slot_in_slow_path_ = (number_of_out_slots + number_of_spill_slots) * kVRegSize;
271
Nicolas Geoffrayc0572a42015-02-06 14:35:25 +0000272 if (number_of_spill_slots == 0
273 && !HasAllocatedCalleeSaveRegisters()
274 && IsLeafMethod()
275 && !RequiresCurrentMethod()) {
276 DCHECK_EQ(maximum_number_of_live_core_registers, 0u);
Roland Levillain0d5a2812015-11-13 10:07:31 +0000277 DCHECK_EQ(maximum_number_of_live_fpu_registers, 0u);
Nicolas Geoffrayc0572a42015-02-06 14:35:25 +0000278 SetFrameSize(CallPushesPC() ? GetWordSize() : 0);
279 } else {
280 SetFrameSize(RoundUp(
281 number_of_spill_slots * kVRegSize
282 + number_of_out_slots * kVRegSize
283 + maximum_number_of_live_core_registers * GetWordSize()
Roland Levillain0d5a2812015-11-13 10:07:31 +0000284 + maximum_number_of_live_fpu_registers * GetFloatingPointSpillSlotSize()
Nicolas Geoffrayc0572a42015-02-06 14:35:25 +0000285 + FrameEntrySpillSize(),
286 kStackAlignment));
287 }
Nicolas Geoffrayab032bc2014-07-15 12:55:21 +0100288}
289
290Location CodeGenerator::GetTemporaryLocation(HTemporary* temp) const {
291 uint16_t number_of_locals = GetGraph()->GetNumberOfLocalVRegs();
Calin Juravlef97f9fb2014-11-11 15:38:19 +0000292 // The type of the previous instruction tells us if we need a single or double stack slot.
293 Primitive::Type type = temp->GetType();
294 int32_t temp_size = (type == Primitive::kPrimLong) || (type == Primitive::kPrimDouble) ? 2 : 1;
Nicolas Geoffrayab032bc2014-07-15 12:55:21 +0100295 // Use the temporary region (right below the dex registers).
296 int32_t slot = GetFrameSize() - FrameEntrySpillSize()
297 - kVRegSize // filler
298 - (number_of_locals * kVRegSize)
Calin Juravlef97f9fb2014-11-11 15:38:19 +0000299 - ((temp_size + temp->GetIndex()) * kVRegSize);
300 return temp_size == 2 ? Location::DoubleStackSlot(slot) : Location::StackSlot(slot);
Nicolas Geoffrayab032bc2014-07-15 12:55:21 +0100301}
302
303int32_t CodeGenerator::GetStackSlot(HLocal* local) const {
304 uint16_t reg_number = local->GetRegNumber();
305 uint16_t number_of_locals = GetGraph()->GetNumberOfLocalVRegs();
306 if (reg_number >= number_of_locals) {
307 // Local is a parameter of the method. It is stored in the caller's frame.
Mathieu Chartiere401d142015-04-22 13:56:20 -0700308 // TODO: Share this logic with StackVisitor::GetVRegOffsetFromQuickCode.
309 return GetFrameSize() + InstructionSetPointerSize(GetInstructionSet()) // ART method
Nicolas Geoffrayab032bc2014-07-15 12:55:21 +0100310 + (reg_number - number_of_locals) * kVRegSize;
311 } else {
312 // Local is a temporary in this method. It is stored in this method's frame.
313 return GetFrameSize() - FrameEntrySpillSize()
314 - kVRegSize // filler.
315 - (number_of_locals * kVRegSize)
316 + (reg_number * kVRegSize);
317 }
318}
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100319
Nicolas Geoffrayfd88f162015-06-03 11:23:52 +0100320void CodeGenerator::CreateCommonInvokeLocationSummary(
Nicolas Geoffray4e40c262015-06-03 12:02:38 +0100321 HInvoke* invoke, InvokeDexCallingConventionVisitor* visitor) {
Nicolas Geoffrayfd88f162015-06-03 11:23:52 +0100322 ArenaAllocator* allocator = invoke->GetBlock()->GetGraph()->GetArena();
323 LocationSummary* locations = new (allocator) LocationSummary(invoke, LocationSummary::kCall);
Nicolas Geoffrayfd88f162015-06-03 11:23:52 +0100324
325 for (size_t i = 0; i < invoke->GetNumberOfArguments(); i++) {
326 HInstruction* input = invoke->InputAt(i);
327 locations->SetInAt(i, visitor->GetNextLocation(input->GetType()));
328 }
329
330 locations->SetOut(visitor->GetReturnLocation(invoke->GetType()));
Nicolas Geoffray94015b92015-06-04 18:21:04 +0100331
332 if (invoke->IsInvokeStaticOrDirect()) {
333 HInvokeStaticOrDirect* call = invoke->AsInvokeStaticOrDirect();
Vladimir Markodc151b22015-10-15 18:02:30 +0100334 switch (call->GetMethodLoadKind()) {
335 case HInvokeStaticOrDirect::MethodLoadKind::kRecursive:
Vladimir Markoc53c0792015-11-19 15:48:33 +0000336 locations->SetInAt(call->GetSpecialInputIndex(), visitor->GetMethodLocation());
Vladimir Markodc151b22015-10-15 18:02:30 +0100337 break;
338 case HInvokeStaticOrDirect::MethodLoadKind::kDexCacheViaMethod:
339 locations->AddTemp(visitor->GetMethodLocation());
Vladimir Markoc53c0792015-11-19 15:48:33 +0000340 locations->SetInAt(call->GetSpecialInputIndex(), Location::RequiresRegister());
Vladimir Markodc151b22015-10-15 18:02:30 +0100341 break;
342 default:
343 locations->AddTemp(visitor->GetMethodLocation());
344 break;
Nicolas Geoffray94015b92015-06-04 18:21:04 +0100345 }
346 } else {
347 locations->AddTemp(visitor->GetMethodLocation());
348 }
Nicolas Geoffrayfd88f162015-06-03 11:23:52 +0100349}
350
Calin Juravle175dc732015-08-25 15:42:32 +0100351void CodeGenerator::GenerateInvokeUnresolvedRuntimeCall(HInvokeUnresolved* invoke) {
352 MoveConstant(invoke->GetLocations()->GetTemp(0), invoke->GetDexMethodIndex());
353
354 // Initialize to anything to silent compiler warnings.
355 QuickEntrypointEnum entrypoint = kQuickInvokeStaticTrampolineWithAccessCheck;
356 switch (invoke->GetOriginalInvokeType()) {
357 case kStatic:
358 entrypoint = kQuickInvokeStaticTrampolineWithAccessCheck;
359 break;
360 case kDirect:
361 entrypoint = kQuickInvokeDirectTrampolineWithAccessCheck;
362 break;
363 case kVirtual:
364 entrypoint = kQuickInvokeVirtualTrampolineWithAccessCheck;
365 break;
366 case kSuper:
367 entrypoint = kQuickInvokeSuperTrampolineWithAccessCheck;
368 break;
369 case kInterface:
370 entrypoint = kQuickInvokeInterfaceTrampolineWithAccessCheck;
371 break;
372 }
373 InvokeRuntime(entrypoint, invoke, invoke->GetDexPc(), nullptr);
374}
375
Calin Juravlee460d1d2015-09-29 04:52:17 +0100376void CodeGenerator::CreateUnresolvedFieldLocationSummary(
377 HInstruction* field_access,
378 Primitive::Type field_type,
379 const FieldAccessCallingConvention& calling_convention) {
380 bool is_instance = field_access->IsUnresolvedInstanceFieldGet()
381 || field_access->IsUnresolvedInstanceFieldSet();
382 bool is_get = field_access->IsUnresolvedInstanceFieldGet()
383 || field_access->IsUnresolvedStaticFieldGet();
384
385 ArenaAllocator* allocator = field_access->GetBlock()->GetGraph()->GetArena();
386 LocationSummary* locations =
387 new (allocator) LocationSummary(field_access, LocationSummary::kCall);
388
389 locations->AddTemp(calling_convention.GetFieldIndexLocation());
390
391 if (is_instance) {
392 // Add the `this` object for instance field accesses.
393 locations->SetInAt(0, calling_convention.GetObjectLocation());
394 }
395
396 // Note that pSetXXStatic/pGetXXStatic always takes/returns an int or int64
397 // regardless of the the type. Because of that we forced to special case
398 // the access to floating point values.
399 if (is_get) {
400 if (Primitive::IsFloatingPointType(field_type)) {
401 // The return value will be stored in regular registers while register
402 // allocator expects it in a floating point register.
403 // Note We don't need to request additional temps because the return
404 // register(s) are already blocked due the call and they may overlap with
405 // the input or field index.
406 // The transfer between the two will be done at codegen level.
407 locations->SetOut(calling_convention.GetFpuLocation(field_type));
408 } else {
409 locations->SetOut(calling_convention.GetReturnLocation(field_type));
410 }
411 } else {
412 size_t set_index = is_instance ? 1 : 0;
413 if (Primitive::IsFloatingPointType(field_type)) {
414 // The set value comes from a float location while the calling convention
415 // expects it in a regular register location. Allocate a temp for it and
416 // make the transfer at codegen.
417 AddLocationAsTemp(calling_convention.GetSetValueLocation(field_type, is_instance), locations);
418 locations->SetInAt(set_index, calling_convention.GetFpuLocation(field_type));
419 } else {
420 locations->SetInAt(set_index,
421 calling_convention.GetSetValueLocation(field_type, is_instance));
422 }
423 }
424}
425
426void CodeGenerator::GenerateUnresolvedFieldAccess(
427 HInstruction* field_access,
428 Primitive::Type field_type,
429 uint32_t field_index,
430 uint32_t dex_pc,
431 const FieldAccessCallingConvention& calling_convention) {
432 LocationSummary* locations = field_access->GetLocations();
433
434 MoveConstant(locations->GetTemp(0), field_index);
435
436 bool is_instance = field_access->IsUnresolvedInstanceFieldGet()
437 || field_access->IsUnresolvedInstanceFieldSet();
438 bool is_get = field_access->IsUnresolvedInstanceFieldGet()
439 || field_access->IsUnresolvedStaticFieldGet();
440
441 if (!is_get && Primitive::IsFloatingPointType(field_type)) {
442 // Copy the float value to be set into the calling convention register.
443 // Note that using directly the temp location is problematic as we don't
444 // support temp register pairs. To avoid boilerplate conversion code, use
445 // the location from the calling convention.
446 MoveLocation(calling_convention.GetSetValueLocation(field_type, is_instance),
447 locations->InAt(is_instance ? 1 : 0),
448 (Primitive::Is64BitType(field_type) ? Primitive::kPrimLong : Primitive::kPrimInt));
449 }
450
451 QuickEntrypointEnum entrypoint = kQuickSet8Static; // Initialize to anything to avoid warnings.
452 switch (field_type) {
453 case Primitive::kPrimBoolean:
454 entrypoint = is_instance
455 ? (is_get ? kQuickGetBooleanInstance : kQuickSet8Instance)
456 : (is_get ? kQuickGetBooleanStatic : kQuickSet8Static);
457 break;
458 case Primitive::kPrimByte:
459 entrypoint = is_instance
460 ? (is_get ? kQuickGetByteInstance : kQuickSet8Instance)
461 : (is_get ? kQuickGetByteStatic : kQuickSet8Static);
462 break;
463 case Primitive::kPrimShort:
464 entrypoint = is_instance
465 ? (is_get ? kQuickGetShortInstance : kQuickSet16Instance)
466 : (is_get ? kQuickGetShortStatic : kQuickSet16Static);
467 break;
468 case Primitive::kPrimChar:
469 entrypoint = is_instance
470 ? (is_get ? kQuickGetCharInstance : kQuickSet16Instance)
471 : (is_get ? kQuickGetCharStatic : kQuickSet16Static);
472 break;
473 case Primitive::kPrimInt:
474 case Primitive::kPrimFloat:
475 entrypoint = is_instance
476 ? (is_get ? kQuickGet32Instance : kQuickSet32Instance)
477 : (is_get ? kQuickGet32Static : kQuickSet32Static);
478 break;
479 case Primitive::kPrimNot:
480 entrypoint = is_instance
481 ? (is_get ? kQuickGetObjInstance : kQuickSetObjInstance)
482 : (is_get ? kQuickGetObjStatic : kQuickSetObjStatic);
483 break;
484 case Primitive::kPrimLong:
485 case Primitive::kPrimDouble:
486 entrypoint = is_instance
487 ? (is_get ? kQuickGet64Instance : kQuickSet64Instance)
488 : (is_get ? kQuickGet64Static : kQuickSet64Static);
489 break;
490 default:
491 LOG(FATAL) << "Invalid type " << field_type;
492 }
493 InvokeRuntime(entrypoint, field_access, dex_pc, nullptr);
494
495 if (is_get && Primitive::IsFloatingPointType(field_type)) {
496 MoveLocation(locations->Out(), calling_convention.GetReturnLocation(field_type), field_type);
497 }
498}
499
Roland Levillain0d5a2812015-11-13 10:07:31 +0000500// TODO: Remove argument `code_generator_supports_read_barrier` when
501// all code generators have read barrier support.
Calin Juravle98893e12015-10-02 21:05:03 +0100502void CodeGenerator::CreateLoadClassLocationSummary(HLoadClass* cls,
503 Location runtime_type_index_location,
Roland Levillain0d5a2812015-11-13 10:07:31 +0000504 Location runtime_return_location,
505 bool code_generator_supports_read_barrier) {
Calin Juravle98893e12015-10-02 21:05:03 +0100506 ArenaAllocator* allocator = cls->GetBlock()->GetGraph()->GetArena();
507 LocationSummary::CallKind call_kind = cls->NeedsAccessCheck()
508 ? LocationSummary::kCall
Roland Levillain0d5a2812015-11-13 10:07:31 +0000509 : (((code_generator_supports_read_barrier && kEmitCompilerReadBarrier) ||
510 cls->CanCallRuntime())
511 ? LocationSummary::kCallOnSlowPath
512 : LocationSummary::kNoCall);
Calin Juravle98893e12015-10-02 21:05:03 +0100513 LocationSummary* locations = new (allocator) LocationSummary(cls, call_kind);
Calin Juravle98893e12015-10-02 21:05:03 +0100514 if (cls->NeedsAccessCheck()) {
Calin Juravle580b6092015-10-06 17:35:58 +0100515 locations->SetInAt(0, Location::NoLocation());
Calin Juravle98893e12015-10-02 21:05:03 +0100516 locations->AddTemp(runtime_type_index_location);
517 locations->SetOut(runtime_return_location);
518 } else {
Calin Juravle580b6092015-10-06 17:35:58 +0100519 locations->SetInAt(0, Location::RequiresRegister());
Calin Juravle98893e12015-10-02 21:05:03 +0100520 locations->SetOut(Location::RequiresRegister());
521 }
522}
523
524
Mark Mendell5f874182015-03-04 15:42:45 -0500525void CodeGenerator::BlockIfInRegister(Location location, bool is_out) const {
526 // The DCHECKS below check that a register is not specified twice in
527 // the summary. The out location can overlap with an input, so we need
528 // to special case it.
529 if (location.IsRegister()) {
530 DCHECK(is_out || !blocked_core_registers_[location.reg()]);
531 blocked_core_registers_[location.reg()] = true;
532 } else if (location.IsFpuRegister()) {
533 DCHECK(is_out || !blocked_fpu_registers_[location.reg()]);
534 blocked_fpu_registers_[location.reg()] = true;
535 } else if (location.IsFpuRegisterPair()) {
536 DCHECK(is_out || !blocked_fpu_registers_[location.AsFpuRegisterPairLow<int>()]);
537 blocked_fpu_registers_[location.AsFpuRegisterPairLow<int>()] = true;
538 DCHECK(is_out || !blocked_fpu_registers_[location.AsFpuRegisterPairHigh<int>()]);
539 blocked_fpu_registers_[location.AsFpuRegisterPairHigh<int>()] = true;
540 } else if (location.IsRegisterPair()) {
541 DCHECK(is_out || !blocked_core_registers_[location.AsRegisterPairLow<int>()]);
542 blocked_core_registers_[location.AsRegisterPairLow<int>()] = true;
543 DCHECK(is_out || !blocked_core_registers_[location.AsRegisterPairHigh<int>()]);
544 blocked_core_registers_[location.AsRegisterPairHigh<int>()] = true;
545 }
546}
547
Nicolas Geoffrayc0572a42015-02-06 14:35:25 +0000548void CodeGenerator::AllocateLocations(HInstruction* instruction) {
549 instruction->Accept(GetLocationBuilder());
Alexandre Rames88c13cd2015-04-14 17:35:39 +0100550 DCHECK(CheckTypeConsistency(instruction));
Nicolas Geoffrayc0572a42015-02-06 14:35:25 +0000551 LocationSummary* locations = instruction->GetLocations();
552 if (!instruction->IsSuspendCheckEntry()) {
553 if (locations != nullptr && locations->CanCall()) {
554 MarkNotLeaf();
555 }
556 if (instruction->NeedsCurrentMethod()) {
557 SetRequiresCurrentMethod();
558 }
559 }
560}
561
Serban Constantinescuecc43662015-08-13 13:33:12 +0100562void CodeGenerator::MaybeRecordStat(MethodCompilationStat compilation_stat, size_t count) const {
563 if (stats_ != nullptr) {
564 stats_->RecordStat(compilation_stat, count);
565 }
566}
567
Nicolas Geoffray12df9eb2015-01-09 14:53:50 +0000568CodeGenerator* CodeGenerator::Create(HGraph* graph,
Calin Juravle34166012014-12-19 17:22:29 +0000569 InstructionSet instruction_set,
Calin Juravlecd6dffe2015-01-08 17:35:35 +0000570 const InstructionSetFeatures& isa_features,
Serban Constantinescuecc43662015-08-13 13:33:12 +0100571 const CompilerOptions& compiler_options,
572 OptimizingCompilerStats* stats) {
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000573 switch (instruction_set) {
Alex Light50fa9932015-08-10 15:30:07 -0700574#ifdef ART_ENABLE_CODEGEN_arm
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000575 case kArm:
576 case kThumb2: {
Nicolas Geoffray12df9eb2015-01-09 14:53:50 +0000577 return new arm::CodeGeneratorARM(graph,
Serban Constantinescuecc43662015-08-13 13:33:12 +0100578 *isa_features.AsArmInstructionSetFeatures(),
579 compiler_options,
580 stats);
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000581 }
Alex Light50fa9932015-08-10 15:30:07 -0700582#endif
583#ifdef ART_ENABLE_CODEGEN_arm64
Alexandre Rames5319def2014-10-23 10:03:10 +0100584 case kArm64: {
Serban Constantinescu579885a2015-02-22 20:51:33 +0000585 return new arm64::CodeGeneratorARM64(graph,
Serban Constantinescuecc43662015-08-13 13:33:12 +0100586 *isa_features.AsArm64InstructionSetFeatures(),
587 compiler_options,
588 stats);
Alexandre Rames5319def2014-10-23 10:03:10 +0100589 }
Alex Light50fa9932015-08-10 15:30:07 -0700590#endif
591#ifdef ART_ENABLE_CODEGEN_mips
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200592 case kMips: {
593 return new mips::CodeGeneratorMIPS(graph,
594 *isa_features.AsMipsInstructionSetFeatures(),
595 compiler_options,
596 stats);
597 }
Alex Light50fa9932015-08-10 15:30:07 -0700598#endif
599#ifdef ART_ENABLE_CODEGEN_mips64
Alexey Frunze4dda3372015-06-01 18:31:49 -0700600 case kMips64: {
601 return new mips64::CodeGeneratorMIPS64(graph,
Serban Constantinescuecc43662015-08-13 13:33:12 +0100602 *isa_features.AsMips64InstructionSetFeatures(),
603 compiler_options,
604 stats);
Alexey Frunze4dda3372015-06-01 18:31:49 -0700605 }
Alex Light50fa9932015-08-10 15:30:07 -0700606#endif
607#ifdef ART_ENABLE_CODEGEN_x86
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000608 case kX86: {
Mark Mendellfb8d2792015-03-31 22:16:59 -0400609 return new x86::CodeGeneratorX86(graph,
Serban Constantinescuecc43662015-08-13 13:33:12 +0100610 *isa_features.AsX86InstructionSetFeatures(),
611 compiler_options,
612 stats);
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000613 }
Alex Light50fa9932015-08-10 15:30:07 -0700614#endif
615#ifdef ART_ENABLE_CODEGEN_x86_64
Dmitry Petrochenko6a58cb12014-04-02 17:27:59 +0700616 case kX86_64: {
Mark Mendellfb8d2792015-03-31 22:16:59 -0400617 return new x86_64::CodeGeneratorX86_64(graph,
Serban Constantinescuecc43662015-08-13 13:33:12 +0100618 *isa_features.AsX86_64InstructionSetFeatures(),
619 compiler_options,
620 stats);
Dmitry Petrochenko6a58cb12014-04-02 17:27:59 +0700621 }
Alex Light50fa9932015-08-10 15:30:07 -0700622#endif
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000623 default:
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000624 return nullptr;
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000625 }
626}
627
Nicolas Geoffrayd28b9692015-11-04 14:36:55 +0000628size_t CodeGenerator::ComputeStackMapsSize() {
629 return stack_map_stream_.PrepareForFillIn();
630}
631
632void CodeGenerator::BuildStackMaps(MemoryRegion region) {
Nicolas Geoffray39468442014-09-02 15:17:15 +0100633 stack_map_stream_.FillIn(region);
634}
635
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000636void CodeGenerator::RecordPcInfo(HInstruction* instruction,
637 uint32_t dex_pc,
638 SlowPathCode* slow_path) {
Calin Juravled2ec87d2014-12-08 14:24:46 +0000639 if (instruction != nullptr) {
Alexey Frunze4dda3372015-06-01 18:31:49 -0700640 // The code generated for some type conversions and comparisons
641 // may call the runtime, thus normally requiring a subsequent
642 // call to this method. However, the method verifier does not
643 // produce PC information for certain instructions, which are
644 // considered "atomic" (they cannot join a GC).
Roland Levillain624279f2014-12-04 11:54:28 +0000645 // Therefore we do not currently record PC information for such
646 // instructions. As this may change later, we added this special
647 // case so that code generators may nevertheless call
648 // CodeGenerator::RecordPcInfo without triggering an error in
649 // CodeGenerator::BuildNativeGCMap ("Missing ref for dex pc 0x")
650 // thereafter.
Alexey Frunze4dda3372015-06-01 18:31:49 -0700651 if (instruction->IsTypeConversion() || instruction->IsCompare()) {
Calin Juravled2ec87d2014-12-08 14:24:46 +0000652 return;
653 }
654 if (instruction->IsRem()) {
655 Primitive::Type type = instruction->AsRem()->GetResultType();
656 if ((type == Primitive::kPrimFloat) || (type == Primitive::kPrimDouble)) {
657 return;
658 }
659 }
Roland Levillain624279f2014-12-04 11:54:28 +0000660 }
661
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100662 uint32_t outer_dex_pc = dex_pc;
663 uint32_t outer_environment_size = 0;
664 uint32_t inlining_depth = 0;
665 if (instruction != nullptr) {
666 for (HEnvironment* environment = instruction->GetEnvironment();
667 environment != nullptr;
668 environment = environment->GetParent()) {
669 outer_dex_pc = environment->GetDexPc();
670 outer_environment_size = environment->Size();
671 if (environment != instruction->GetEnvironment()) {
672 inlining_depth++;
673 }
674 }
675 }
676
Nicolas Geoffray39468442014-09-02 15:17:15 +0100677 // Collect PC infos for the mapping table.
Vladimir Markobd8c7252015-06-12 10:06:32 +0100678 uint32_t native_pc = GetAssembler()->CodeSize();
Nicolas Geoffray39468442014-09-02 15:17:15 +0100679
Nicolas Geoffray39468442014-09-02 15:17:15 +0100680 if (instruction == nullptr) {
681 // For stack overflow checks.
Vladimir Markobd8c7252015-06-12 10:06:32 +0100682 stack_map_stream_.BeginStackMapEntry(outer_dex_pc, native_pc, 0, 0, 0, 0);
Calin Juravle4f46ac52015-04-23 18:47:21 +0100683 stack_map_stream_.EndStackMapEntry();
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000684 return;
685 }
686 LocationSummary* locations = instruction->GetLocations();
Nicolas Geoffray39468442014-09-02 15:17:15 +0100687
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000688 uint32_t register_mask = locations->GetRegisterMask();
689 if (locations->OnlyCallsOnSlowPath()) {
690 // In case of slow path, we currently set the location of caller-save registers
691 // to register (instead of their stack location when pushed before the slow-path
692 // call). Therefore register_mask contains both callee-save and caller-save
693 // registers that hold objects. We must remove the caller-save from the mask, since
694 // they will be overwritten by the callee.
695 register_mask &= core_callee_save_mask_;
696 }
697 // The register mask must be a subset of callee-save registers.
698 DCHECK_EQ(register_mask & core_callee_save_mask_, register_mask);
Vladimir Markobd8c7252015-06-12 10:06:32 +0100699 stack_map_stream_.BeginStackMapEntry(outer_dex_pc,
700 native_pc,
Calin Juravle4f46ac52015-04-23 18:47:21 +0100701 register_mask,
702 locations->GetStackMask(),
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100703 outer_environment_size,
Calin Juravle4f46ac52015-04-23 18:47:21 +0100704 inlining_depth);
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100705
706 EmitEnvironment(instruction->GetEnvironment(), slow_path);
707 stack_map_stream_.EndStackMapEntry();
708}
709
David Srbeckyb7070a22016-01-08 18:13:53 +0000710bool CodeGenerator::HasStackMapAtCurrentPc() {
711 uint32_t pc = GetAssembler()->CodeSize();
712 size_t count = stack_map_stream_.GetNumberOfStackMaps();
713 return count > 0 && stack_map_stream_.GetStackMap(count - 1).native_pc_offset == pc;
714}
715
David Brazdil77a48ae2015-09-15 12:34:04 +0000716void CodeGenerator::RecordCatchBlockInfo() {
717 ArenaAllocator* arena = graph_->GetArena();
718
Vladimir Markofa6b93c2015-09-15 10:15:55 +0100719 for (HBasicBlock* block : *block_order_) {
David Brazdil77a48ae2015-09-15 12:34:04 +0000720 if (!block->IsCatchBlock()) {
721 continue;
722 }
723
724 uint32_t dex_pc = block->GetDexPc();
725 uint32_t num_vregs = graph_->GetNumberOfVRegs();
726 uint32_t inlining_depth = 0; // Inlining of catch blocks is not supported at the moment.
727 uint32_t native_pc = GetAddressOf(block);
728 uint32_t register_mask = 0; // Not used.
729
730 // The stack mask is not used, so we leave it empty.
731 ArenaBitVector* stack_mask = new (arena) ArenaBitVector(arena, 0, /* expandable */ true);
732
733 stack_map_stream_.BeginStackMapEntry(dex_pc,
734 native_pc,
735 register_mask,
736 stack_mask,
737 num_vregs,
738 inlining_depth);
739
740 HInstruction* current_phi = block->GetFirstPhi();
741 for (size_t vreg = 0; vreg < num_vregs; ++vreg) {
742 while (current_phi != nullptr && current_phi->AsPhi()->GetRegNumber() < vreg) {
743 HInstruction* next_phi = current_phi->GetNext();
744 DCHECK(next_phi == nullptr ||
745 current_phi->AsPhi()->GetRegNumber() <= next_phi->AsPhi()->GetRegNumber())
746 << "Phis need to be sorted by vreg number to keep this a linear-time loop.";
747 current_phi = next_phi;
748 }
749
750 if (current_phi == nullptr || current_phi->AsPhi()->GetRegNumber() != vreg) {
751 stack_map_stream_.AddDexRegisterEntry(DexRegisterLocation::Kind::kNone, 0);
752 } else {
753 Location location = current_phi->GetLiveInterval()->ToLocation();
754 switch (location.GetKind()) {
755 case Location::kStackSlot: {
756 stack_map_stream_.AddDexRegisterEntry(
757 DexRegisterLocation::Kind::kInStack, location.GetStackIndex());
758 break;
759 }
760 case Location::kDoubleStackSlot: {
761 stack_map_stream_.AddDexRegisterEntry(
762 DexRegisterLocation::Kind::kInStack, location.GetStackIndex());
763 stack_map_stream_.AddDexRegisterEntry(
764 DexRegisterLocation::Kind::kInStack, location.GetHighStackIndex(kVRegSize));
765 ++vreg;
766 DCHECK_LT(vreg, num_vregs);
767 break;
768 }
769 default: {
770 // All catch phis must be allocated to a stack slot.
771 LOG(FATAL) << "Unexpected kind " << location.GetKind();
772 UNREACHABLE();
773 }
774 }
775 }
776 }
777
778 stack_map_stream_.EndStackMapEntry();
779 }
780}
781
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100782void CodeGenerator::EmitEnvironment(HEnvironment* environment, SlowPathCode* slow_path) {
783 if (environment == nullptr) return;
784
785 if (environment->GetParent() != nullptr) {
786 // We emit the parent environment first.
787 EmitEnvironment(environment->GetParent(), slow_path);
Nicolas Geoffrayb176d7c2015-05-20 18:48:31 +0100788 stack_map_stream_.BeginInlineInfoEntry(environment->GetMethodIdx(),
789 environment->GetDexPc(),
790 environment->GetInvokeType(),
791 environment->Size());
Nicolas Geoffray0a23d742015-05-07 11:57:35 +0100792 }
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000793
794 // Walk over the environment, and record the location of dex registers.
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100795 for (size_t i = 0, environment_size = environment->Size(); i < environment_size; ++i) {
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000796 HInstruction* current = environment->GetInstructionAt(i);
797 if (current == nullptr) {
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100798 stack_map_stream_.AddDexRegisterEntry(DexRegisterLocation::Kind::kNone, 0);
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000799 continue;
Nicolas Geoffray39468442014-09-02 15:17:15 +0100800 }
801
Nicolas Geoffray0a23d742015-05-07 11:57:35 +0100802 Location location = environment->GetLocationAt(i);
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000803 switch (location.GetKind()) {
804 case Location::kConstant: {
805 DCHECK_EQ(current, location.GetConstant());
806 if (current->IsLongConstant()) {
807 int64_t value = current->AsLongConstant()->GetValue();
808 stack_map_stream_.AddDexRegisterEntry(
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100809 DexRegisterLocation::Kind::kConstant, Low32Bits(value));
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000810 stack_map_stream_.AddDexRegisterEntry(
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100811 DexRegisterLocation::Kind::kConstant, High32Bits(value));
812 ++i;
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000813 DCHECK_LT(i, environment_size);
814 } else if (current->IsDoubleConstant()) {
Roland Levillainda4d79b2015-03-24 14:36:11 +0000815 int64_t value = bit_cast<int64_t, double>(current->AsDoubleConstant()->GetValue());
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000816 stack_map_stream_.AddDexRegisterEntry(
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100817 DexRegisterLocation::Kind::kConstant, Low32Bits(value));
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000818 stack_map_stream_.AddDexRegisterEntry(
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100819 DexRegisterLocation::Kind::kConstant, High32Bits(value));
820 ++i;
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000821 DCHECK_LT(i, environment_size);
822 } else if (current->IsIntConstant()) {
823 int32_t value = current->AsIntConstant()->GetValue();
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100824 stack_map_stream_.AddDexRegisterEntry(DexRegisterLocation::Kind::kConstant, value);
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000825 } else if (current->IsNullConstant()) {
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100826 stack_map_stream_.AddDexRegisterEntry(DexRegisterLocation::Kind::kConstant, 0);
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000827 } else {
828 DCHECK(current->IsFloatConstant()) << current->DebugName();
Roland Levillainda4d79b2015-03-24 14:36:11 +0000829 int32_t value = bit_cast<int32_t, float>(current->AsFloatConstant()->GetValue());
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100830 stack_map_stream_.AddDexRegisterEntry(DexRegisterLocation::Kind::kConstant, value);
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000831 }
832 break;
833 }
834
835 case Location::kStackSlot: {
836 stack_map_stream_.AddDexRegisterEntry(
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100837 DexRegisterLocation::Kind::kInStack, location.GetStackIndex());
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000838 break;
839 }
840
841 case Location::kDoubleStackSlot: {
842 stack_map_stream_.AddDexRegisterEntry(
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100843 DexRegisterLocation::Kind::kInStack, location.GetStackIndex());
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000844 stack_map_stream_.AddDexRegisterEntry(
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100845 DexRegisterLocation::Kind::kInStack, location.GetHighStackIndex(kVRegSize));
846 ++i;
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000847 DCHECK_LT(i, environment_size);
848 break;
849 }
850
851 case Location::kRegister : {
852 int id = location.reg();
853 if (slow_path != nullptr && slow_path->IsCoreRegisterSaved(id)) {
854 uint32_t offset = slow_path->GetStackOffsetOfCoreRegister(id);
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100855 stack_map_stream_.AddDexRegisterEntry(DexRegisterLocation::Kind::kInStack, offset);
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000856 if (current->GetType() == Primitive::kPrimLong) {
857 stack_map_stream_.AddDexRegisterEntry(
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100858 DexRegisterLocation::Kind::kInStack, offset + kVRegSize);
859 ++i;
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000860 DCHECK_LT(i, environment_size);
861 }
862 } else {
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100863 stack_map_stream_.AddDexRegisterEntry(DexRegisterLocation::Kind::kInRegister, id);
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000864 if (current->GetType() == Primitive::kPrimLong) {
David Brazdild9cb68e2015-08-25 13:52:43 +0100865 stack_map_stream_.AddDexRegisterEntry(DexRegisterLocation::Kind::kInRegisterHigh, id);
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100866 ++i;
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000867 DCHECK_LT(i, environment_size);
868 }
869 }
870 break;
871 }
872
873 case Location::kFpuRegister : {
874 int id = location.reg();
875 if (slow_path != nullptr && slow_path->IsFpuRegisterSaved(id)) {
876 uint32_t offset = slow_path->GetStackOffsetOfFpuRegister(id);
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100877 stack_map_stream_.AddDexRegisterEntry(DexRegisterLocation::Kind::kInStack, offset);
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000878 if (current->GetType() == Primitive::kPrimDouble) {
879 stack_map_stream_.AddDexRegisterEntry(
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100880 DexRegisterLocation::Kind::kInStack, offset + kVRegSize);
881 ++i;
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000882 DCHECK_LT(i, environment_size);
883 }
884 } else {
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100885 stack_map_stream_.AddDexRegisterEntry(DexRegisterLocation::Kind::kInFpuRegister, id);
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000886 if (current->GetType() == Primitive::kPrimDouble) {
David Brazdild9cb68e2015-08-25 13:52:43 +0100887 stack_map_stream_.AddDexRegisterEntry(
888 DexRegisterLocation::Kind::kInFpuRegisterHigh, id);
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100889 ++i;
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000890 DCHECK_LT(i, environment_size);
891 }
892 }
893 break;
894 }
895
896 case Location::kFpuRegisterPair : {
897 int low = location.low();
898 int high = location.high();
899 if (slow_path != nullptr && slow_path->IsFpuRegisterSaved(low)) {
900 uint32_t offset = slow_path->GetStackOffsetOfFpuRegister(low);
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100901 stack_map_stream_.AddDexRegisterEntry(DexRegisterLocation::Kind::kInStack, offset);
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000902 } else {
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100903 stack_map_stream_.AddDexRegisterEntry(DexRegisterLocation::Kind::kInFpuRegister, low);
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000904 }
905 if (slow_path != nullptr && slow_path->IsFpuRegisterSaved(high)) {
906 uint32_t offset = slow_path->GetStackOffsetOfFpuRegister(high);
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100907 stack_map_stream_.AddDexRegisterEntry(DexRegisterLocation::Kind::kInStack, offset);
908 ++i;
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000909 } else {
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100910 stack_map_stream_.AddDexRegisterEntry(DexRegisterLocation::Kind::kInFpuRegister, high);
911 ++i;
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000912 }
913 DCHECK_LT(i, environment_size);
914 break;
915 }
916
917 case Location::kRegisterPair : {
918 int low = location.low();
919 int high = location.high();
920 if (slow_path != nullptr && slow_path->IsCoreRegisterSaved(low)) {
921 uint32_t offset = slow_path->GetStackOffsetOfCoreRegister(low);
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100922 stack_map_stream_.AddDexRegisterEntry(DexRegisterLocation::Kind::kInStack, offset);
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000923 } else {
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100924 stack_map_stream_.AddDexRegisterEntry(DexRegisterLocation::Kind::kInRegister, low);
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000925 }
926 if (slow_path != nullptr && slow_path->IsCoreRegisterSaved(high)) {
927 uint32_t offset = slow_path->GetStackOffsetOfCoreRegister(high);
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100928 stack_map_stream_.AddDexRegisterEntry(DexRegisterLocation::Kind::kInStack, offset);
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000929 } else {
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100930 stack_map_stream_.AddDexRegisterEntry(DexRegisterLocation::Kind::kInRegister, high);
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000931 }
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100932 ++i;
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000933 DCHECK_LT(i, environment_size);
934 break;
935 }
936
937 case Location::kInvalid: {
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100938 stack_map_stream_.AddDexRegisterEntry(DexRegisterLocation::Kind::kNone, 0);
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000939 break;
940 }
941
942 default:
943 LOG(FATAL) << "Unexpected kind " << location.GetKind();
944 }
Nicolas Geoffray39468442014-09-02 15:17:15 +0100945 }
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100946
947 if (environment->GetParent() != nullptr) {
948 stack_map_stream_.EndInlineInfoEntry();
949 }
Nicolas Geoffray39468442014-09-02 15:17:15 +0100950}
951
David Brazdil77a48ae2015-09-15 12:34:04 +0000952bool CodeGenerator::IsImplicitNullCheckAllowed(HNullCheck* null_check) const {
953 return compiler_options_.GetImplicitNullChecks() &&
954 // Null checks which might throw into a catch block need to save live
955 // registers and therefore cannot be done implicitly.
956 !null_check->CanThrowIntoCatchBlock();
957}
958
Calin Juravle77520bc2015-01-12 18:45:46 +0000959bool CodeGenerator::CanMoveNullCheckToUser(HNullCheck* null_check) {
960 HInstruction* first_next_not_move = null_check->GetNextDisregardingMoves();
Calin Juravle641547a2015-04-21 22:08:51 +0100961
962 return (first_next_not_move != nullptr)
963 && first_next_not_move->CanDoImplicitNullCheckOn(null_check->InputAt(0));
Calin Juravle77520bc2015-01-12 18:45:46 +0000964}
965
966void CodeGenerator::MaybeRecordImplicitNullCheck(HInstruction* instr) {
967 // If we are from a static path don't record the pc as we can't throw NPE.
968 // NB: having the checks here makes the code much less verbose in the arch
969 // specific code generators.
970 if (instr->IsStaticFieldSet() || instr->IsStaticFieldGet()) {
971 return;
972 }
973
Calin Juravle641547a2015-04-21 22:08:51 +0100974 if (!instr->CanDoImplicitNullCheckOn(instr->InputAt(0))) {
Calin Juravle77520bc2015-01-12 18:45:46 +0000975 return;
976 }
977
978 // Find the first previous instruction which is not a move.
979 HInstruction* first_prev_not_move = instr->GetPreviousDisregardingMoves();
980
981 // If the instruction is a null check it means that `instr` is the first user
982 // and needs to record the pc.
983 if (first_prev_not_move != nullptr && first_prev_not_move->IsNullCheck()) {
984 HNullCheck* null_check = first_prev_not_move->AsNullCheck();
David Brazdil77a48ae2015-09-15 12:34:04 +0000985 if (IsImplicitNullCheckAllowed(null_check)) {
986 // TODO: The parallel moves modify the environment. Their changes need to be
987 // reverted otherwise the stack maps at the throw point will not be correct.
988 RecordPcInfo(null_check, null_check->GetDexPc());
989 }
Calin Juravle77520bc2015-01-12 18:45:46 +0000990 }
991}
992
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100993void CodeGenerator::ClearSpillSlotsFromLoopPhisInStackMap(HSuspendCheck* suspend_check) const {
994 LocationSummary* locations = suspend_check->GetLocations();
995 HBasicBlock* block = suspend_check->GetBlock();
996 DCHECK(block->GetLoopInformation()->GetSuspendCheck() == suspend_check);
997 DCHECK(block->IsLoopHeader());
998
999 for (HInstructionIterator it(block->GetPhis()); !it.Done(); it.Advance()) {
1000 HInstruction* current = it.Current();
1001 LiveInterval* interval = current->GetLiveInterval();
1002 // We only need to clear bits of loop phis containing objects and allocated in register.
1003 // Loop phis allocated on stack already have the object in the stack.
1004 if (current->GetType() == Primitive::kPrimNot
1005 && interval->HasRegister()
1006 && interval->HasSpillSlot()) {
1007 locations->ClearStackBit(interval->GetSpillSlot() / kVRegSize);
1008 }
1009 }
1010}
1011
Nicolas Geoffray90218252015-04-15 11:56:51 +01001012void CodeGenerator::EmitParallelMoves(Location from1,
1013 Location to1,
1014 Primitive::Type type1,
1015 Location from2,
1016 Location to2,
1017 Primitive::Type type2) {
Nicolas Geoffrayf0e39372014-11-12 17:50:07 +00001018 HParallelMove parallel_move(GetGraph()->GetArena());
Nicolas Geoffray90218252015-04-15 11:56:51 +01001019 parallel_move.AddMove(from1, to1, type1, nullptr);
1020 parallel_move.AddMove(from2, to2, type2, nullptr);
Nicolas Geoffrayf0e39372014-11-12 17:50:07 +00001021 GetMoveResolver()->EmitNativeCode(&parallel_move);
1022}
1023
Alexandre Rames78e3ef62015-08-12 13:43:29 +01001024void CodeGenerator::ValidateInvokeRuntime(HInstruction* instruction, SlowPathCode* slow_path) {
1025 // Ensure that the call kind indication given to the register allocator is
1026 // coherent with the runtime call generated, and that the GC side effect is
1027 // set when required.
1028 if (slow_path == nullptr) {
Roland Levillain0d5a2812015-11-13 10:07:31 +00001029 DCHECK(instruction->GetLocations()->WillCall())
1030 << "instruction->DebugName()=" << instruction->DebugName();
Roland Levillaindf3f8222015-08-13 12:31:44 +01001031 DCHECK(instruction->GetSideEffects().Includes(SideEffects::CanTriggerGC()))
Roland Levillain0d5a2812015-11-13 10:07:31 +00001032 << "instruction->DebugName()=" << instruction->DebugName()
1033 << " instruction->GetSideEffects().ToString()=" << instruction->GetSideEffects().ToString();
Alexandre Rames78e3ef62015-08-12 13:43:29 +01001034 } else {
Roland Levillaindf3f8222015-08-13 12:31:44 +01001035 DCHECK(instruction->GetLocations()->OnlyCallsOnSlowPath() || slow_path->IsFatal())
Roland Levillain0d5a2812015-11-13 10:07:31 +00001036 << "instruction->DebugName()=" << instruction->DebugName()
1037 << " slow_path->GetDescription()=" << slow_path->GetDescription();
Alexandre Rames78e3ef62015-08-12 13:43:29 +01001038 DCHECK(instruction->GetSideEffects().Includes(SideEffects::CanTriggerGC()) ||
Roland Levillain0d5a2812015-11-13 10:07:31 +00001039 // When read barriers are enabled, some instructions use a
1040 // slow path to emit a read barrier, which does not trigger
1041 // GC, is not fatal, nor is emitted by HDeoptimize
1042 // instructions.
1043 (kEmitCompilerReadBarrier &&
1044 (instruction->IsInstanceFieldGet() ||
1045 instruction->IsStaticFieldGet() ||
1046 instruction->IsArraySet() ||
1047 instruction->IsArrayGet() ||
1048 instruction->IsLoadClass() ||
1049 instruction->IsLoadString() ||
1050 instruction->IsInstanceOf() ||
1051 instruction->IsCheckCast())))
1052 << "instruction->DebugName()=" << instruction->DebugName()
1053 << " instruction->GetSideEffects().ToString()=" << instruction->GetSideEffects().ToString()
1054 << " slow_path->GetDescription()=" << slow_path->GetDescription();
Alexandre Rames78e3ef62015-08-12 13:43:29 +01001055 }
1056
1057 // Check the coherency of leaf information.
1058 DCHECK(instruction->IsSuspendCheck()
1059 || ((slow_path != nullptr) && slow_path->IsFatal())
1060 || instruction->GetLocations()->CanCall()
Roland Levillaindf3f8222015-08-13 12:31:44 +01001061 || !IsLeafMethod())
1062 << instruction->DebugName() << ((slow_path != nullptr) ? slow_path->GetDescription() : "");
Alexandre Rames78e3ef62015-08-12 13:43:29 +01001063}
1064
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +00001065void SlowPathCode::SaveLiveRegisters(CodeGenerator* codegen, LocationSummary* locations) {
Roland Levillain0d5a2812015-11-13 10:07:31 +00001066 RegisterSet* live_registers = locations->GetLiveRegisters();
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +00001067 size_t stack_offset = codegen->GetFirstRegisterSlotInSlowPath();
Roland Levillain0d5a2812015-11-13 10:07:31 +00001068
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +00001069 for (size_t i = 0, e = codegen->GetNumberOfCoreRegisters(); i < e; ++i) {
1070 if (!codegen->IsCoreCalleeSaveRegister(i)) {
Roland Levillain0d5a2812015-11-13 10:07:31 +00001071 if (live_registers->ContainsCoreRegister(i)) {
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +00001072 // If the register holds an object, update the stack mask.
1073 if (locations->RegisterContainsObject(i)) {
1074 locations->SetStackBit(stack_offset / kVRegSize);
1075 }
1076 DCHECK_LT(stack_offset, codegen->GetFrameSize() - codegen->FrameEntrySpillSize());
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00001077 DCHECK_LT(i, kMaximumNumberOfExpectedRegisters);
1078 saved_core_stack_offsets_[i] = stack_offset;
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +00001079 stack_offset += codegen->SaveCoreRegister(stack_offset, i);
1080 }
1081 }
1082 }
1083
1084 for (size_t i = 0, e = codegen->GetNumberOfFloatingPointRegisters(); i < e; ++i) {
1085 if (!codegen->IsFloatingPointCalleeSaveRegister(i)) {
Roland Levillain0d5a2812015-11-13 10:07:31 +00001086 if (live_registers->ContainsFloatingPointRegister(i)) {
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +00001087 DCHECK_LT(stack_offset, codegen->GetFrameSize() - codegen->FrameEntrySpillSize());
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00001088 DCHECK_LT(i, kMaximumNumberOfExpectedRegisters);
1089 saved_fpu_stack_offsets_[i] = stack_offset;
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +00001090 stack_offset += codegen->SaveFloatingPointRegister(stack_offset, i);
1091 }
1092 }
1093 }
1094}
1095
1096void SlowPathCode::RestoreLiveRegisters(CodeGenerator* codegen, LocationSummary* locations) {
Roland Levillain0d5a2812015-11-13 10:07:31 +00001097 RegisterSet* live_registers = locations->GetLiveRegisters();
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +00001098 size_t stack_offset = codegen->GetFirstRegisterSlotInSlowPath();
Roland Levillain0d5a2812015-11-13 10:07:31 +00001099
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +00001100 for (size_t i = 0, e = codegen->GetNumberOfCoreRegisters(); i < e; ++i) {
1101 if (!codegen->IsCoreCalleeSaveRegister(i)) {
Roland Levillain0d5a2812015-11-13 10:07:31 +00001102 if (live_registers->ContainsCoreRegister(i)) {
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +00001103 DCHECK_LT(stack_offset, codegen->GetFrameSize() - codegen->FrameEntrySpillSize());
Roland Levillain0d5a2812015-11-13 10:07:31 +00001104 DCHECK_LT(i, kMaximumNumberOfExpectedRegisters);
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +00001105 stack_offset += codegen->RestoreCoreRegister(stack_offset, i);
1106 }
1107 }
1108 }
1109
1110 for (size_t i = 0, e = codegen->GetNumberOfFloatingPointRegisters(); i < e; ++i) {
1111 if (!codegen->IsFloatingPointCalleeSaveRegister(i)) {
Roland Levillain0d5a2812015-11-13 10:07:31 +00001112 if (live_registers->ContainsFloatingPointRegister(i)) {
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +00001113 DCHECK_LT(stack_offset, codegen->GetFrameSize() - codegen->FrameEntrySpillSize());
Roland Levillain0d5a2812015-11-13 10:07:31 +00001114 DCHECK_LT(i, kMaximumNumberOfExpectedRegisters);
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +00001115 stack_offset += codegen->RestoreFloatingPointRegister(stack_offset, i);
1116 }
1117 }
1118 }
1119}
1120
Nicolas Geoffray5bd05a52015-10-13 09:48:30 +01001121void CodeGenerator::CreateSystemArrayCopyLocationSummary(HInvoke* invoke) {
1122 // Check to see if we have known failures that will cause us to have to bail out
1123 // to the runtime, and just generate the runtime call directly.
1124 HIntConstant* src_pos = invoke->InputAt(1)->AsIntConstant();
1125 HIntConstant* dest_pos = invoke->InputAt(3)->AsIntConstant();
1126
1127 // The positions must be non-negative.
1128 if ((src_pos != nullptr && src_pos->GetValue() < 0) ||
1129 (dest_pos != nullptr && dest_pos->GetValue() < 0)) {
1130 // We will have to fail anyways.
1131 return;
1132 }
1133
1134 // The length must be >= 0.
1135 HIntConstant* length = invoke->InputAt(4)->AsIntConstant();
1136 if (length != nullptr) {
1137 int32_t len = length->GetValue();
1138 if (len < 0) {
1139 // Just call as normal.
1140 return;
1141 }
1142 }
1143
1144 SystemArrayCopyOptimizations optimizations(invoke);
1145
1146 if (optimizations.GetDestinationIsSource()) {
1147 if (src_pos != nullptr && dest_pos != nullptr && src_pos->GetValue() < dest_pos->GetValue()) {
1148 // We only support backward copying if source and destination are the same.
1149 return;
1150 }
1151 }
1152
1153 if (optimizations.GetDestinationIsPrimitiveArray() || optimizations.GetSourceIsPrimitiveArray()) {
1154 // We currently don't intrinsify primitive copying.
1155 return;
1156 }
1157
1158 ArenaAllocator* allocator = invoke->GetBlock()->GetGraph()->GetArena();
1159 LocationSummary* locations = new (allocator) LocationSummary(invoke,
1160 LocationSummary::kCallOnSlowPath,
1161 kIntrinsified);
1162 // arraycopy(Object src, int src_pos, Object dest, int dest_pos, int length).
1163 locations->SetInAt(0, Location::RequiresRegister());
1164 locations->SetInAt(1, Location::RegisterOrConstant(invoke->InputAt(1)));
1165 locations->SetInAt(2, Location::RequiresRegister());
1166 locations->SetInAt(3, Location::RegisterOrConstant(invoke->InputAt(3)));
1167 locations->SetInAt(4, Location::RegisterOrConstant(invoke->InputAt(4)));
1168
1169 locations->AddTemp(Location::RequiresRegister());
1170 locations->AddTemp(Location::RequiresRegister());
1171 locations->AddTemp(Location::RequiresRegister());
1172}
1173
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +00001174} // namespace art