blob: 873637430691fc174130e4f782375b5a4ff8fdba [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
19#include "code_generator_arm.h"
Alexandre Rames5319def2014-10-23 10:03:10 +010020#include "code_generator_arm64.h"
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +000021#include "code_generator_x86.h"
Nicolas Geoffray9cf35522014-06-09 18:40:10 +010022#include "code_generator_x86_64.h"
Yevgeny Roubane3ea8382014-08-08 16:29:38 +070023#include "compiled_method.h"
Nicolas Geoffray92cf83e2014-03-18 17:59:20 +000024#include "dex/verified_method.h"
25#include "driver/dex_compilation_unit.h"
26#include "gc_map_builder.h"
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +000027#include "leb128.h"
28#include "mapping_table.h"
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +010029#include "mirror/array-inl.h"
30#include "mirror/object_array-inl.h"
31#include "mirror/object_reference.h"
Nicolas Geoffray3c049742014-09-24 18:10:46 +010032#include "ssa_liveness_analysis.h"
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +000033#include "utils/assembler.h"
Nicolas Geoffray92cf83e2014-03-18 17:59:20 +000034#include "verifier/dex_gc_map.h"
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +000035#include "vmap_table.h"
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +000036
37namespace art {
38
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +010039size_t CodeGenerator::GetCacheOffset(uint32_t index) {
40 return mirror::ObjectArray<mirror::Object>::OffsetOfElement(index).SizeValue();
41}
42
Nicolas Geoffray73e80c32014-07-22 17:47:56 +010043void CodeGenerator::CompileBaseline(CodeAllocator* allocator, bool is_leaf) {
Nicolas Geoffray4c204ba2015-02-03 15:12:35 +000044 Initialize();
Nicolas Geoffray73e80c32014-07-22 17:47:56 +010045 if (!is_leaf) {
46 MarkNotLeaf();
47 }
Nicolas Geoffray4c204ba2015-02-03 15:12:35 +000048 InitializeCodeGeneration(GetGraph()->GetNumberOfLocalVRegs()
49 + GetGraph()->GetTemporariesVRegSlots()
50 + 1 /* filler */,
51 0, /* the baseline compiler does not have live registers at slow path */
52 0, /* the baseline compiler does not have live registers at slow path */
53 GetGraph()->GetMaximumNumberOfOutVRegs()
54 + 1 /* current method */,
55 GetGraph()->GetBlocks());
56 CompileInternal(allocator, /* is_baseline */ true);
57}
Nicolas Geoffray86dbb9a2014-06-04 11:12:39 +010058
Nicolas Geoffraydc23d832015-02-16 11:15:43 +000059bool CodeGenerator::GoesToNextBlock(HBasicBlock* current, HBasicBlock* next) const {
60 DCHECK_EQ(block_order_->Get(current_block_index_), current);
61 return GetNextBlockToEmit() == FirstNonEmptyBlock(next);
62}
63
64HBasicBlock* CodeGenerator::GetNextBlockToEmit() const {
65 for (size_t i = current_block_index_ + 1; i < block_order_->Size(); ++i) {
66 HBasicBlock* block = block_order_->Get(i);
David Brazdil46e2a392015-03-16 17:31:52 +000067 if (!block->IsSingleGoto()) {
Nicolas Geoffraydc23d832015-02-16 11:15:43 +000068 return block;
69 }
70 }
71 return nullptr;
72}
73
74HBasicBlock* CodeGenerator::FirstNonEmptyBlock(HBasicBlock* block) const {
David Brazdil46e2a392015-03-16 17:31:52 +000075 while (block->IsSingleGoto()) {
Nicolas Geoffraydc23d832015-02-16 11:15:43 +000076 block = block->GetSuccessors().Get(0);
77 }
78 return block;
79}
80
Nicolas Geoffray4c204ba2015-02-03 15:12:35 +000081void CodeGenerator::CompileInternal(CodeAllocator* allocator, bool is_baseline) {
Nicolas Geoffray8a16d972014-09-11 10:30:02 +010082 HGraphVisitor* instruction_visitor = GetInstructionVisitor();
Nicolas Geoffray4c204ba2015-02-03 15:12:35 +000083 DCHECK_EQ(current_block_index_, 0u);
84 GenerateFrameEntry();
David Srbeckyc6b4dd82015-04-07 20:32:43 +010085 DCHECK_EQ(GetAssembler()->cfi().GetCurrentCFAOffset(), static_cast<int>(frame_size_));
Nicolas Geoffray4c204ba2015-02-03 15:12:35 +000086 for (size_t e = block_order_->Size(); current_block_index_ < e; ++current_block_index_) {
87 HBasicBlock* block = block_order_->Get(current_block_index_);
Nicolas Geoffraydc23d832015-02-16 11:15:43 +000088 // Don't generate code for an empty block. Its predecessors will branch to its successor
89 // directly. Also, the label of that block will not be emitted, so this helps catch
90 // errors where we reference that label.
David Brazdil46e2a392015-03-16 17:31:52 +000091 if (block->IsSingleGoto()) continue;
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +010092 Bind(block);
Nicolas Geoffray86dbb9a2014-06-04 11:12:39 +010093 for (HInstructionIterator it(block->GetInstructions()); !it.Done(); it.Advance()) {
94 HInstruction* current = it.Current();
Nicolas Geoffray4c204ba2015-02-03 15:12:35 +000095 if (is_baseline) {
Nicolas Geoffrayc0572a42015-02-06 14:35:25 +000096 InitLocationsBaseline(current);
Nicolas Geoffray4c204ba2015-02-03 15:12:35 +000097 }
Nicolas Geoffray86dbb9a2014-06-04 11:12:39 +010098 current->Accept(instruction_visitor);
99 }
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000100 }
Nicolas Geoffray4c204ba2015-02-03 15:12:35 +0000101
102 // Generate the slow paths.
103 for (size_t i = 0, e = slow_paths_.Size(); i < e; ++i) {
104 slow_paths_.Get(i)->EmitNativeCode(this);
105 }
106
107 // Finalize instructions in assember;
Serban Constantinescu32f5b4d2014-11-25 20:05:46 +0000108 Finalize(allocator);
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000109}
110
Nicolas Geoffray86dbb9a2014-06-04 11:12:39 +0100111void CodeGenerator::CompileOptimized(CodeAllocator* allocator) {
Nicolas Geoffray4c204ba2015-02-03 15:12:35 +0000112 // The register allocator already called `InitializeCodeGeneration`,
113 // where the frame size has been computed.
Nicolas Geoffray4c204ba2015-02-03 15:12:35 +0000114 DCHECK(block_order_ != nullptr);
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100115 Initialize();
Nicolas Geoffray4c204ba2015-02-03 15:12:35 +0000116 CompileInternal(allocator, /* is_baseline */ false);
Serban Constantinescu32f5b4d2014-11-25 20:05:46 +0000117}
Nicolas Geoffray86dbb9a2014-06-04 11:12:39 +0100118
Serban Constantinescu32f5b4d2014-11-25 20:05:46 +0000119void CodeGenerator::Finalize(CodeAllocator* allocator) {
Nicolas Geoffray86dbb9a2014-06-04 11:12:39 +0100120 size_t code_size = GetAssembler()->CodeSize();
121 uint8_t* buffer = allocator->Allocate(code_size);
Serban Constantinescu32f5b4d2014-11-25 20:05:46 +0000122
Nicolas Geoffray86dbb9a2014-06-04 11:12:39 +0100123 MemoryRegion code(buffer, code_size);
124 GetAssembler()->FinalizeInstructions(code);
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000125}
126
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100127size_t CodeGenerator::FindFreeEntry(bool* array, size_t length) {
128 for (size_t i = 0; i < length; ++i) {
129 if (!array[i]) {
130 array[i] = true;
131 return i;
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100132 }
133 }
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100134 LOG(FATAL) << "Could not find a register in baseline register allocator";
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000135 UNREACHABLE();
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000136}
137
Nicolas Geoffray3c035032014-10-28 10:46:40 +0000138size_t CodeGenerator::FindTwoFreeConsecutiveAlignedEntries(bool* array, size_t length) {
139 for (size_t i = 0; i < length - 1; i += 2) {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000140 if (!array[i] && !array[i + 1]) {
141 array[i] = true;
142 array[i + 1] = true;
143 return i;
144 }
145 }
146 LOG(FATAL) << "Could not find a register in baseline register allocator";
147 UNREACHABLE();
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100148}
149
Nicolas Geoffray4c204ba2015-02-03 15:12:35 +0000150void CodeGenerator::InitializeCodeGeneration(size_t number_of_spill_slots,
151 size_t maximum_number_of_live_core_registers,
152 size_t maximum_number_of_live_fp_registers,
153 size_t number_of_out_slots,
154 const GrowableArray<HBasicBlock*>& block_order) {
155 block_order_ = &block_order;
156 DCHECK(block_order_->Get(0) == GetGraph()->GetEntryBlock());
157 DCHECK(GoesToNextBlock(GetGraph()->GetEntryBlock(), block_order_->Get(1)));
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000158 ComputeSpillMask();
Nicolas Geoffray3bca0df2014-09-19 11:01:00 +0100159 first_register_slot_in_slow_path_ = (number_of_out_slots + number_of_spill_slots) * kVRegSize;
160
Nicolas Geoffrayc0572a42015-02-06 14:35:25 +0000161 if (number_of_spill_slots == 0
162 && !HasAllocatedCalleeSaveRegisters()
163 && IsLeafMethod()
164 && !RequiresCurrentMethod()) {
165 DCHECK_EQ(maximum_number_of_live_core_registers, 0u);
166 DCHECK_EQ(maximum_number_of_live_fp_registers, 0u);
167 SetFrameSize(CallPushesPC() ? GetWordSize() : 0);
168 } else {
169 SetFrameSize(RoundUp(
170 number_of_spill_slots * kVRegSize
171 + number_of_out_slots * kVRegSize
172 + maximum_number_of_live_core_registers * GetWordSize()
173 + maximum_number_of_live_fp_registers * GetFloatingPointSpillSlotSize()
174 + FrameEntrySpillSize(),
175 kStackAlignment));
176 }
Nicolas Geoffrayab032bc2014-07-15 12:55:21 +0100177}
178
179Location CodeGenerator::GetTemporaryLocation(HTemporary* temp) const {
180 uint16_t number_of_locals = GetGraph()->GetNumberOfLocalVRegs();
Calin Juravlef97f9fb2014-11-11 15:38:19 +0000181 // The type of the previous instruction tells us if we need a single or double stack slot.
182 Primitive::Type type = temp->GetType();
183 int32_t temp_size = (type == Primitive::kPrimLong) || (type == Primitive::kPrimDouble) ? 2 : 1;
Nicolas Geoffrayab032bc2014-07-15 12:55:21 +0100184 // Use the temporary region (right below the dex registers).
185 int32_t slot = GetFrameSize() - FrameEntrySpillSize()
186 - kVRegSize // filler
187 - (number_of_locals * kVRegSize)
Calin Juravlef97f9fb2014-11-11 15:38:19 +0000188 - ((temp_size + temp->GetIndex()) * kVRegSize);
189 return temp_size == 2 ? Location::DoubleStackSlot(slot) : Location::StackSlot(slot);
Nicolas Geoffrayab032bc2014-07-15 12:55:21 +0100190}
191
192int32_t CodeGenerator::GetStackSlot(HLocal* local) const {
193 uint16_t reg_number = local->GetRegNumber();
194 uint16_t number_of_locals = GetGraph()->GetNumberOfLocalVRegs();
195 if (reg_number >= number_of_locals) {
196 // Local is a parameter of the method. It is stored in the caller's frame.
197 return GetFrameSize() + kVRegSize // ART method
198 + (reg_number - number_of_locals) * kVRegSize;
199 } else {
200 // Local is a temporary in this method. It is stored in this method's frame.
201 return GetFrameSize() - FrameEntrySpillSize()
202 - kVRegSize // filler.
203 - (number_of_locals * kVRegSize)
204 + (reg_number * kVRegSize);
205 }
206}
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100207
Mark Mendell5f874182015-03-04 15:42:45 -0500208void CodeGenerator::BlockIfInRegister(Location location, bool is_out) const {
209 // The DCHECKS below check that a register is not specified twice in
210 // the summary. The out location can overlap with an input, so we need
211 // to special case it.
212 if (location.IsRegister()) {
213 DCHECK(is_out || !blocked_core_registers_[location.reg()]);
214 blocked_core_registers_[location.reg()] = true;
215 } else if (location.IsFpuRegister()) {
216 DCHECK(is_out || !blocked_fpu_registers_[location.reg()]);
217 blocked_fpu_registers_[location.reg()] = true;
218 } else if (location.IsFpuRegisterPair()) {
219 DCHECK(is_out || !blocked_fpu_registers_[location.AsFpuRegisterPairLow<int>()]);
220 blocked_fpu_registers_[location.AsFpuRegisterPairLow<int>()] = true;
221 DCHECK(is_out || !blocked_fpu_registers_[location.AsFpuRegisterPairHigh<int>()]);
222 blocked_fpu_registers_[location.AsFpuRegisterPairHigh<int>()] = true;
223 } else if (location.IsRegisterPair()) {
224 DCHECK(is_out || !blocked_core_registers_[location.AsRegisterPairLow<int>()]);
225 blocked_core_registers_[location.AsRegisterPairLow<int>()] = true;
226 DCHECK(is_out || !blocked_core_registers_[location.AsRegisterPairHigh<int>()]);
227 blocked_core_registers_[location.AsRegisterPairHigh<int>()] = true;
228 }
229}
230
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100231void CodeGenerator::AllocateRegistersLocally(HInstruction* instruction) const {
232 LocationSummary* locations = instruction->GetLocations();
233 if (locations == nullptr) return;
234
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100235 for (size_t i = 0, e = GetNumberOfCoreRegisters(); i < e; ++i) {
236 blocked_core_registers_[i] = false;
237 }
238
239 for (size_t i = 0, e = GetNumberOfFloatingPointRegisters(); i < e; ++i) {
240 blocked_fpu_registers_[i] = false;
241 }
242
243 for (size_t i = 0, e = number_of_register_pairs_; i < e; ++i) {
244 blocked_register_pairs_[i] = false;
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100245 }
246
247 // Mark all fixed input, temp and output registers as used.
248 for (size_t i = 0, e = locations->GetInputCount(); i < e; ++i) {
Mark Mendell5f874182015-03-04 15:42:45 -0500249 BlockIfInRegister(locations->InAt(i));
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100250 }
251
252 for (size_t i = 0, e = locations->GetTempCount(); i < e; ++i) {
253 Location loc = locations->GetTemp(i);
Mark Mendell5f874182015-03-04 15:42:45 -0500254 BlockIfInRegister(loc);
255 }
256 Location result_location = locations->Out();
257 if (locations->OutputCanOverlapWithInputs()) {
258 BlockIfInRegister(result_location, /* is_out */ true);
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100259 }
260
Mark Mendell5f874182015-03-04 15:42:45 -0500261 SetupBlockedRegisters(/* is_baseline */ true);
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100262
263 // Allocate all unallocated input locations.
264 for (size_t i = 0, e = locations->GetInputCount(); i < e; ++i) {
265 Location loc = locations->InAt(i);
266 HInstruction* input = instruction->InputAt(i);
267 if (loc.IsUnallocated()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100268 if ((loc.GetPolicy() == Location::kRequiresRegister)
269 || (loc.GetPolicy() == Location::kRequiresFpuRegister)) {
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100270 loc = AllocateFreeRegister(input->GetType());
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100271 } else {
272 DCHECK_EQ(loc.GetPolicy(), Location::kAny);
273 HLoadLocal* load = input->AsLoadLocal();
274 if (load != nullptr) {
275 loc = GetStackLocation(load);
276 } else {
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100277 loc = AllocateFreeRegister(input->GetType());
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100278 }
279 }
280 locations->SetInAt(i, loc);
281 }
282 }
283
284 // Allocate all unallocated temp locations.
285 for (size_t i = 0, e = locations->GetTempCount(); i < e; ++i) {
286 Location loc = locations->GetTemp(i);
287 if (loc.IsUnallocated()) {
Roland Levillain647b9ed2014-11-27 12:06:00 +0000288 switch (loc.GetPolicy()) {
289 case Location::kRequiresRegister:
290 // Allocate a core register (large enough to fit a 32-bit integer).
291 loc = AllocateFreeRegister(Primitive::kPrimInt);
292 break;
293
294 case Location::kRequiresFpuRegister:
295 // Allocate a core register (large enough to fit a 64-bit double).
296 loc = AllocateFreeRegister(Primitive::kPrimDouble);
297 break;
298
299 default:
300 LOG(FATAL) << "Unexpected policy for temporary location "
301 << loc.GetPolicy();
302 }
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100303 locations->SetTempAt(i, loc);
304 }
305 }
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100306 if (result_location.IsUnallocated()) {
307 switch (result_location.GetPolicy()) {
308 case Location::kAny:
309 case Location::kRequiresRegister:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100310 case Location::kRequiresFpuRegister:
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100311 result_location = AllocateFreeRegister(instruction->GetType());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100312 break;
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100313 case Location::kSameAsFirstInput:
314 result_location = locations->InAt(0);
315 break;
316 }
Nicolas Geoffray829280c2015-01-28 10:20:37 +0000317 locations->UpdateOut(result_location);
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100318 }
319}
320
Nicolas Geoffrayc0572a42015-02-06 14:35:25 +0000321void CodeGenerator::InitLocationsBaseline(HInstruction* instruction) {
322 AllocateLocations(instruction);
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100323 if (instruction->GetLocations() == nullptr) {
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100324 if (instruction->IsTemporary()) {
325 HInstruction* previous = instruction->GetPrevious();
326 Location temp_location = GetTemporaryLocation(instruction->AsTemporary());
327 Move(previous, temp_location, instruction);
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100328 }
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100329 return;
330 }
331 AllocateRegistersLocally(instruction);
332 for (size_t i = 0, e = instruction->InputCount(); i < e; ++i) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000333 Location location = instruction->GetLocations()->InAt(i);
Nicolas Geoffrayf43083d2014-11-07 10:48:10 +0000334 HInstruction* input = instruction->InputAt(i);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000335 if (location.IsValid()) {
336 // Move the input to the desired location.
Nicolas Geoffrayf43083d2014-11-07 10:48:10 +0000337 if (input->GetNext()->IsTemporary()) {
338 // If the input was stored in a temporary, use that temporary to
339 // perform the move.
340 Move(input->GetNext(), location, instruction);
341 } else {
342 Move(input, location, instruction);
343 }
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000344 }
345 }
346}
347
Nicolas Geoffrayc0572a42015-02-06 14:35:25 +0000348void CodeGenerator::AllocateLocations(HInstruction* instruction) {
349 instruction->Accept(GetLocationBuilder());
350 LocationSummary* locations = instruction->GetLocations();
351 if (!instruction->IsSuspendCheckEntry()) {
352 if (locations != nullptr && locations->CanCall()) {
353 MarkNotLeaf();
354 }
355 if (instruction->NeedsCurrentMethod()) {
356 SetRequiresCurrentMethod();
357 }
358 }
359}
360
Nicolas Geoffray12df9eb2015-01-09 14:53:50 +0000361CodeGenerator* CodeGenerator::Create(HGraph* graph,
Calin Juravle34166012014-12-19 17:22:29 +0000362 InstructionSet instruction_set,
Calin Juravlecd6dffe2015-01-08 17:35:35 +0000363 const InstructionSetFeatures& isa_features,
364 const CompilerOptions& compiler_options) {
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000365 switch (instruction_set) {
366 case kArm:
367 case kThumb2: {
Nicolas Geoffray12df9eb2015-01-09 14:53:50 +0000368 return new arm::CodeGeneratorARM(graph,
Calin Juravlecd6dffe2015-01-08 17:35:35 +0000369 *isa_features.AsArmInstructionSetFeatures(),
370 compiler_options);
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000371 }
Alexandre Rames5319def2014-10-23 10:03:10 +0100372 case kArm64: {
Serban Constantinescu579885a2015-02-22 20:51:33 +0000373 return new arm64::CodeGeneratorARM64(graph,
374 *isa_features.AsArm64InstructionSetFeatures(),
375 compiler_options);
Alexandre Rames5319def2014-10-23 10:03:10 +0100376 }
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000377 case kMips:
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000378 return nullptr;
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000379 case kX86: {
Mark Mendellfb8d2792015-03-31 22:16:59 -0400380 return new x86::CodeGeneratorX86(graph,
381 *isa_features.AsX86InstructionSetFeatures(),
382 compiler_options);
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000383 }
Dmitry Petrochenko6a58cb12014-04-02 17:27:59 +0700384 case kX86_64: {
Mark Mendellfb8d2792015-03-31 22:16:59 -0400385 return new x86_64::CodeGeneratorX86_64(graph,
386 *isa_features.AsX86_64InstructionSetFeatures(),
387 compiler_options);
Dmitry Petrochenko6a58cb12014-04-02 17:27:59 +0700388 }
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000389 default:
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000390 return nullptr;
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000391 }
392}
393
Nicolas Geoffray92cf83e2014-03-18 17:59:20 +0000394void CodeGenerator::BuildNativeGCMap(
395 std::vector<uint8_t>* data, const DexCompilationUnit& dex_compilation_unit) const {
396 const std::vector<uint8_t>& gc_map_raw =
397 dex_compilation_unit.GetVerifiedMethod()->GetDexGcMap();
398 verifier::DexPcToReferenceMap dex_gc_map(&(gc_map_raw)[0]);
399
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +0000400 uint32_t max_native_offset = 0;
401 for (size_t i = 0; i < pc_infos_.Size(); i++) {
402 uint32_t native_offset = pc_infos_.Get(i).native_pc;
403 if (native_offset > max_native_offset) {
404 max_native_offset = native_offset;
405 }
406 }
407
408 GcMapBuilder builder(data, pc_infos_.Size(), max_native_offset, dex_gc_map.RegWidth());
409 for (size_t i = 0; i < pc_infos_.Size(); i++) {
410 struct PcInfo pc_info = pc_infos_.Get(i);
411 uint32_t native_offset = pc_info.native_pc;
412 uint32_t dex_pc = pc_info.dex_pc;
413 const uint8_t* references = dex_gc_map.FindBitMap(dex_pc, false);
Jean Christophe Beyler0ada95d2014-12-04 11:20:20 -0800414 CHECK(references != nullptr) << "Missing ref for dex pc 0x" << std::hex << dex_pc;
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +0000415 builder.AddEntry(native_offset, references);
416 }
Nicolas Geoffray92cf83e2014-03-18 17:59:20 +0000417}
418
David Srbeckyc6b4dd82015-04-07 20:32:43 +0100419void CodeGenerator::BuildSourceMap(DefaultSrcMap* src_map) const {
420 for (size_t i = 0; i < pc_infos_.Size(); i++) {
421 struct PcInfo pc_info = pc_infos_.Get(i);
422 uint32_t pc2dex_offset = pc_info.native_pc;
423 int32_t pc2dex_dalvik_offset = pc_info.dex_pc;
424 src_map->push_back(SrcMapElem({pc2dex_offset, pc2dex_dalvik_offset}));
425 }
426}
427
428void CodeGenerator::BuildMappingTable(std::vector<uint8_t>* data) const {
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +0000429 uint32_t pc2dex_data_size = 0u;
430 uint32_t pc2dex_entries = pc_infos_.Size();
431 uint32_t pc2dex_offset = 0u;
432 int32_t pc2dex_dalvik_offset = 0;
433 uint32_t dex2pc_data_size = 0u;
434 uint32_t dex2pc_entries = 0u;
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +0000435 uint32_t dex2pc_offset = 0u;
436 int32_t dex2pc_dalvik_offset = 0;
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +0000437
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +0000438 for (size_t i = 0; i < pc2dex_entries; i++) {
439 struct PcInfo pc_info = pc_infos_.Get(i);
440 pc2dex_data_size += UnsignedLeb128Size(pc_info.native_pc - pc2dex_offset);
441 pc2dex_data_size += SignedLeb128Size(pc_info.dex_pc - pc2dex_dalvik_offset);
442 pc2dex_offset = pc_info.native_pc;
443 pc2dex_dalvik_offset = pc_info.dex_pc;
444 }
445
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +0000446 // Walk over the blocks and find which ones correspond to catch block entries.
447 for (size_t i = 0; i < graph_->GetBlocks().Size(); ++i) {
448 HBasicBlock* block = graph_->GetBlocks().Get(i);
449 if (block->IsCatchBlock()) {
450 intptr_t native_pc = GetAddressOf(block);
451 ++dex2pc_entries;
452 dex2pc_data_size += UnsignedLeb128Size(native_pc - dex2pc_offset);
453 dex2pc_data_size += SignedLeb128Size(block->GetDexPc() - dex2pc_dalvik_offset);
454 dex2pc_offset = native_pc;
455 dex2pc_dalvik_offset = block->GetDexPc();
456 }
457 }
458
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +0000459 uint32_t total_entries = pc2dex_entries + dex2pc_entries;
460 uint32_t hdr_data_size = UnsignedLeb128Size(total_entries) + UnsignedLeb128Size(pc2dex_entries);
461 uint32_t data_size = hdr_data_size + pc2dex_data_size + dex2pc_data_size;
462 data->resize(data_size);
463
464 uint8_t* data_ptr = &(*data)[0];
465 uint8_t* write_pos = data_ptr;
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +0000466
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +0000467 write_pos = EncodeUnsignedLeb128(write_pos, total_entries);
468 write_pos = EncodeUnsignedLeb128(write_pos, pc2dex_entries);
469 DCHECK_EQ(static_cast<size_t>(write_pos - data_ptr), hdr_data_size);
470 uint8_t* write_pos2 = write_pos + pc2dex_data_size;
471
472 pc2dex_offset = 0u;
473 pc2dex_dalvik_offset = 0u;
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +0000474 dex2pc_offset = 0u;
475 dex2pc_dalvik_offset = 0u;
476
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +0000477 for (size_t i = 0; i < pc2dex_entries; i++) {
478 struct PcInfo pc_info = pc_infos_.Get(i);
479 DCHECK(pc2dex_offset <= pc_info.native_pc);
480 write_pos = EncodeUnsignedLeb128(write_pos, pc_info.native_pc - pc2dex_offset);
481 write_pos = EncodeSignedLeb128(write_pos, pc_info.dex_pc - pc2dex_dalvik_offset);
482 pc2dex_offset = pc_info.native_pc;
483 pc2dex_dalvik_offset = pc_info.dex_pc;
484 }
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +0000485
486 for (size_t i = 0; i < graph_->GetBlocks().Size(); ++i) {
487 HBasicBlock* block = graph_->GetBlocks().Get(i);
488 if (block->IsCatchBlock()) {
489 intptr_t native_pc = GetAddressOf(block);
490 write_pos2 = EncodeUnsignedLeb128(write_pos2, native_pc - dex2pc_offset);
491 write_pos2 = EncodeSignedLeb128(write_pos2, block->GetDexPc() - dex2pc_dalvik_offset);
492 dex2pc_offset = native_pc;
493 dex2pc_dalvik_offset = block->GetDexPc();
494 }
495 }
496
497
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +0000498 DCHECK_EQ(static_cast<size_t>(write_pos - data_ptr), hdr_data_size + pc2dex_data_size);
499 DCHECK_EQ(static_cast<size_t>(write_pos2 - data_ptr), data_size);
500
501 if (kIsDebugBuild) {
502 // Verify the encoded table holds the expected data.
503 MappingTable table(data_ptr);
504 CHECK_EQ(table.TotalSize(), total_entries);
505 CHECK_EQ(table.PcToDexSize(), pc2dex_entries);
506 auto it = table.PcToDexBegin();
507 auto it2 = table.DexToPcBegin();
508 for (size_t i = 0; i < pc2dex_entries; i++) {
509 struct PcInfo pc_info = pc_infos_.Get(i);
510 CHECK_EQ(pc_info.native_pc, it.NativePcOffset());
511 CHECK_EQ(pc_info.dex_pc, it.DexPc());
512 ++it;
513 }
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +0000514 for (size_t i = 0; i < graph_->GetBlocks().Size(); ++i) {
515 HBasicBlock* block = graph_->GetBlocks().Get(i);
516 if (block->IsCatchBlock()) {
517 CHECK_EQ(GetAddressOf(block), it2.NativePcOffset());
518 CHECK_EQ(block->GetDexPc(), it2.DexPc());
519 ++it2;
520 }
521 }
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +0000522 CHECK(it == table.PcToDexEnd());
523 CHECK(it2 == table.DexToPcEnd());
524 }
525}
526
527void CodeGenerator::BuildVMapTable(std::vector<uint8_t>* data) const {
528 Leb128EncodingVector vmap_encoder;
Nicolas Geoffray4a34a422014-04-03 10:38:37 +0100529 // We currently don't use callee-saved registers.
530 size_t size = 0 + 1 /* marker */ + 0;
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +0000531 vmap_encoder.Reserve(size + 1u); // All values are likely to be one byte in ULEB128 (<128).
532 vmap_encoder.PushBackUnsigned(size);
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +0000533 vmap_encoder.PushBackUnsigned(VmapTable::kAdjustedFpMarker);
534
535 *data = vmap_encoder.GetData();
536}
Nicolas Geoffray92cf83e2014-03-18 17:59:20 +0000537
Nicolas Geoffray39468442014-09-02 15:17:15 +0100538void CodeGenerator::BuildStackMaps(std::vector<uint8_t>* data) {
539 uint32_t size = stack_map_stream_.ComputeNeededSize();
540 data->resize(size);
541 MemoryRegion region(data->data(), size);
542 stack_map_stream_.FillIn(region);
543}
544
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000545void CodeGenerator::RecordPcInfo(HInstruction* instruction,
546 uint32_t dex_pc,
547 SlowPathCode* slow_path) {
Calin Juravled2ec87d2014-12-08 14:24:46 +0000548 if (instruction != nullptr) {
Roland Levillain624279f2014-12-04 11:54:28 +0000549 // The code generated for some type conversions may call the
550 // runtime, thus normally requiring a subsequent call to this
551 // method. However, the method verifier does not produce PC
Calin Juravled2ec87d2014-12-08 14:24:46 +0000552 // information for certain instructions, which are considered "atomic"
553 // (they cannot join a GC).
Roland Levillain624279f2014-12-04 11:54:28 +0000554 // Therefore we do not currently record PC information for such
555 // instructions. As this may change later, we added this special
556 // case so that code generators may nevertheless call
557 // CodeGenerator::RecordPcInfo without triggering an error in
558 // CodeGenerator::BuildNativeGCMap ("Missing ref for dex pc 0x")
559 // thereafter.
Calin Juravled2ec87d2014-12-08 14:24:46 +0000560 if (instruction->IsTypeConversion()) {
561 return;
562 }
563 if (instruction->IsRem()) {
564 Primitive::Type type = instruction->AsRem()->GetResultType();
565 if ((type == Primitive::kPrimFloat) || (type == Primitive::kPrimDouble)) {
566 return;
567 }
568 }
Roland Levillain624279f2014-12-04 11:54:28 +0000569 }
570
Nicolas Geoffray39468442014-09-02 15:17:15 +0100571 // Collect PC infos for the mapping table.
572 struct PcInfo pc_info;
573 pc_info.dex_pc = dex_pc;
574 pc_info.native_pc = GetAssembler()->CodeSize();
575 pc_infos_.Add(pc_info);
576
Nicolas Geoffrayfead4e42015-03-13 14:39:40 +0000577 uint32_t inlining_depth = 0;
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000578
Nicolas Geoffray39468442014-09-02 15:17:15 +0100579 if (instruction == nullptr) {
580 // For stack overflow checks.
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000581 stack_map_stream_.AddStackMapEntry(dex_pc, pc_info.native_pc, 0, 0, 0, inlining_depth);
582 return;
583 }
584 LocationSummary* locations = instruction->GetLocations();
585 HEnvironment* environment = instruction->GetEnvironment();
586 size_t environment_size = instruction->EnvironmentSize();
Nicolas Geoffray39468442014-09-02 15:17:15 +0100587
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000588 uint32_t register_mask = locations->GetRegisterMask();
589 if (locations->OnlyCallsOnSlowPath()) {
590 // In case of slow path, we currently set the location of caller-save registers
591 // to register (instead of their stack location when pushed before the slow-path
592 // call). Therefore register_mask contains both callee-save and caller-save
593 // registers that hold objects. We must remove the caller-save from the mask, since
594 // they will be overwritten by the callee.
595 register_mask &= core_callee_save_mask_;
596 }
597 // The register mask must be a subset of callee-save registers.
598 DCHECK_EQ(register_mask & core_callee_save_mask_, register_mask);
599 stack_map_stream_.AddStackMapEntry(dex_pc,
600 pc_info.native_pc,
601 register_mask,
602 locations->GetStackMask(),
603 environment_size,
604 inlining_depth);
605
606 // Walk over the environment, and record the location of dex registers.
607 for (size_t i = 0; i < environment_size; ++i) {
608 HInstruction* current = environment->GetInstructionAt(i);
609 if (current == nullptr) {
610 stack_map_stream_.AddDexRegisterEntry(i, DexRegisterLocation::Kind::kNone, 0);
611 continue;
Nicolas Geoffray39468442014-09-02 15:17:15 +0100612 }
613
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000614 Location location = locations->GetEnvironmentAt(i);
615 switch (location.GetKind()) {
616 case Location::kConstant: {
617 DCHECK_EQ(current, location.GetConstant());
618 if (current->IsLongConstant()) {
619 int64_t value = current->AsLongConstant()->GetValue();
620 stack_map_stream_.AddDexRegisterEntry(
621 i, DexRegisterLocation::Kind::kConstant, Low32Bits(value));
622 stack_map_stream_.AddDexRegisterEntry(
623 ++i, DexRegisterLocation::Kind::kConstant, High32Bits(value));
624 DCHECK_LT(i, environment_size);
625 } else if (current->IsDoubleConstant()) {
Roland Levillainda4d79b2015-03-24 14:36:11 +0000626 int64_t value = bit_cast<int64_t, double>(current->AsDoubleConstant()->GetValue());
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000627 stack_map_stream_.AddDexRegisterEntry(
628 i, DexRegisterLocation::Kind::kConstant, Low32Bits(value));
629 stack_map_stream_.AddDexRegisterEntry(
630 ++i, DexRegisterLocation::Kind::kConstant, High32Bits(value));
631 DCHECK_LT(i, environment_size);
632 } else if (current->IsIntConstant()) {
633 int32_t value = current->AsIntConstant()->GetValue();
634 stack_map_stream_.AddDexRegisterEntry(i, DexRegisterLocation::Kind::kConstant, value);
635 } else if (current->IsNullConstant()) {
636 stack_map_stream_.AddDexRegisterEntry(i, DexRegisterLocation::Kind::kConstant, 0);
637 } else {
638 DCHECK(current->IsFloatConstant()) << current->DebugName();
Roland Levillainda4d79b2015-03-24 14:36:11 +0000639 int32_t value = bit_cast<int32_t, float>(current->AsFloatConstant()->GetValue());
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000640 stack_map_stream_.AddDexRegisterEntry(i, DexRegisterLocation::Kind::kConstant, value);
641 }
642 break;
643 }
644
645 case Location::kStackSlot: {
646 stack_map_stream_.AddDexRegisterEntry(
647 i, DexRegisterLocation::Kind::kInStack, location.GetStackIndex());
648 break;
649 }
650
651 case Location::kDoubleStackSlot: {
652 stack_map_stream_.AddDexRegisterEntry(
653 i, DexRegisterLocation::Kind::kInStack, location.GetStackIndex());
654 stack_map_stream_.AddDexRegisterEntry(
655 ++i, DexRegisterLocation::Kind::kInStack, location.GetHighStackIndex(kVRegSize));
656 DCHECK_LT(i, environment_size);
657 break;
658 }
659
660 case Location::kRegister : {
661 int id = location.reg();
662 if (slow_path != nullptr && slow_path->IsCoreRegisterSaved(id)) {
663 uint32_t offset = slow_path->GetStackOffsetOfCoreRegister(id);
664 stack_map_stream_.AddDexRegisterEntry(i, DexRegisterLocation::Kind::kInStack, offset);
665 if (current->GetType() == Primitive::kPrimLong) {
666 stack_map_stream_.AddDexRegisterEntry(
667 ++i, DexRegisterLocation::Kind::kInStack, offset + kVRegSize);
668 DCHECK_LT(i, environment_size);
669 }
670 } else {
671 stack_map_stream_.AddDexRegisterEntry(i, DexRegisterLocation::Kind::kInRegister, id);
672 if (current->GetType() == Primitive::kPrimLong) {
673 stack_map_stream_.AddDexRegisterEntry(++i, DexRegisterLocation::Kind::kInRegister, id);
674 DCHECK_LT(i, environment_size);
675 }
676 }
677 break;
678 }
679
680 case Location::kFpuRegister : {
681 int id = location.reg();
682 if (slow_path != nullptr && slow_path->IsFpuRegisterSaved(id)) {
683 uint32_t offset = slow_path->GetStackOffsetOfFpuRegister(id);
684 stack_map_stream_.AddDexRegisterEntry(i, DexRegisterLocation::Kind::kInStack, offset);
685 if (current->GetType() == Primitive::kPrimDouble) {
686 stack_map_stream_.AddDexRegisterEntry(
687 ++i, DexRegisterLocation::Kind::kInStack, offset + kVRegSize);
688 DCHECK_LT(i, environment_size);
689 }
690 } else {
691 stack_map_stream_.AddDexRegisterEntry(i, DexRegisterLocation::Kind::kInFpuRegister, id);
692 if (current->GetType() == Primitive::kPrimDouble) {
693 stack_map_stream_.AddDexRegisterEntry(
694 ++i, DexRegisterLocation::Kind::kInFpuRegister, id);
695 DCHECK_LT(i, environment_size);
696 }
697 }
698 break;
699 }
700
701 case Location::kFpuRegisterPair : {
702 int low = location.low();
703 int high = location.high();
704 if (slow_path != nullptr && slow_path->IsFpuRegisterSaved(low)) {
705 uint32_t offset = slow_path->GetStackOffsetOfFpuRegister(low);
706 stack_map_stream_.AddDexRegisterEntry(i, DexRegisterLocation::Kind::kInStack, offset);
707 } else {
708 stack_map_stream_.AddDexRegisterEntry(i, DexRegisterLocation::Kind::kInFpuRegister, low);
709 }
710 if (slow_path != nullptr && slow_path->IsFpuRegisterSaved(high)) {
711 uint32_t offset = slow_path->GetStackOffsetOfFpuRegister(high);
712 stack_map_stream_.AddDexRegisterEntry(++i, DexRegisterLocation::Kind::kInStack, offset);
713 } else {
714 stack_map_stream_.AddDexRegisterEntry(
715 ++i, DexRegisterLocation::Kind::kInFpuRegister, high);
716 }
717 DCHECK_LT(i, environment_size);
718 break;
719 }
720
721 case Location::kRegisterPair : {
722 int low = location.low();
723 int high = location.high();
724 if (slow_path != nullptr && slow_path->IsCoreRegisterSaved(low)) {
725 uint32_t offset = slow_path->GetStackOffsetOfCoreRegister(low);
726 stack_map_stream_.AddDexRegisterEntry(i, DexRegisterLocation::Kind::kInStack, offset);
727 } else {
728 stack_map_stream_.AddDexRegisterEntry(i, DexRegisterLocation::Kind::kInRegister, low);
729 }
730 if (slow_path != nullptr && slow_path->IsCoreRegisterSaved(high)) {
731 uint32_t offset = slow_path->GetStackOffsetOfCoreRegister(high);
732 stack_map_stream_.AddDexRegisterEntry(++i, DexRegisterLocation::Kind::kInStack, offset);
733 } else {
734 stack_map_stream_.AddDexRegisterEntry(
735 ++i, DexRegisterLocation::Kind::kInRegister, high);
736 }
737 DCHECK_LT(i, environment_size);
738 break;
739 }
740
741 case Location::kInvalid: {
742 stack_map_stream_.AddDexRegisterEntry(i, DexRegisterLocation::Kind::kNone, 0);
743 break;
744 }
745
746 default:
747 LOG(FATAL) << "Unexpected kind " << location.GetKind();
748 }
Nicolas Geoffray39468442014-09-02 15:17:15 +0100749 }
750}
751
Calin Juravle77520bc2015-01-12 18:45:46 +0000752bool CodeGenerator::CanMoveNullCheckToUser(HNullCheck* null_check) {
753 HInstruction* first_next_not_move = null_check->GetNextDisregardingMoves();
754 return (first_next_not_move != nullptr) && first_next_not_move->CanDoImplicitNullCheck();
755}
756
757void CodeGenerator::MaybeRecordImplicitNullCheck(HInstruction* instr) {
758 // If we are from a static path don't record the pc as we can't throw NPE.
759 // NB: having the checks here makes the code much less verbose in the arch
760 // specific code generators.
761 if (instr->IsStaticFieldSet() || instr->IsStaticFieldGet()) {
762 return;
763 }
764
765 if (!compiler_options_.GetImplicitNullChecks()) {
766 return;
767 }
768
769 if (!instr->CanDoImplicitNullCheck()) {
770 return;
771 }
772
773 // Find the first previous instruction which is not a move.
774 HInstruction* first_prev_not_move = instr->GetPreviousDisregardingMoves();
775
776 // If the instruction is a null check it means that `instr` is the first user
777 // and needs to record the pc.
778 if (first_prev_not_move != nullptr && first_prev_not_move->IsNullCheck()) {
779 HNullCheck* null_check = first_prev_not_move->AsNullCheck();
780 // TODO: The parallel moves modify the environment. Their changes need to be reverted
781 // otherwise the stack maps at the throw point will not be correct.
782 RecordPcInfo(null_check, null_check->GetDexPc());
783 }
784}
785
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100786void CodeGenerator::ClearSpillSlotsFromLoopPhisInStackMap(HSuspendCheck* suspend_check) const {
787 LocationSummary* locations = suspend_check->GetLocations();
788 HBasicBlock* block = suspend_check->GetBlock();
789 DCHECK(block->GetLoopInformation()->GetSuspendCheck() == suspend_check);
790 DCHECK(block->IsLoopHeader());
791
792 for (HInstructionIterator it(block->GetPhis()); !it.Done(); it.Advance()) {
793 HInstruction* current = it.Current();
794 LiveInterval* interval = current->GetLiveInterval();
795 // We only need to clear bits of loop phis containing objects and allocated in register.
796 // Loop phis allocated on stack already have the object in the stack.
797 if (current->GetType() == Primitive::kPrimNot
798 && interval->HasRegister()
799 && interval->HasSpillSlot()) {
800 locations->ClearStackBit(interval->GetSpillSlot() / kVRegSize);
801 }
802 }
803}
804
Nicolas Geoffrayf0e39372014-11-12 17:50:07 +0000805void CodeGenerator::EmitParallelMoves(Location from1, Location to1, Location from2, Location to2) {
Nicolas Geoffrayf0e39372014-11-12 17:50:07 +0000806 HParallelMove parallel_move(GetGraph()->GetArena());
Nicolas Geoffray42d1f5f2015-01-16 09:14:18 +0000807 parallel_move.AddMove(from1, to1, nullptr);
808 parallel_move.AddMove(from2, to2, nullptr);
Nicolas Geoffrayf0e39372014-11-12 17:50:07 +0000809 GetMoveResolver()->EmitNativeCode(&parallel_move);
810}
811
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +0000812void SlowPathCode::RecordPcInfo(CodeGenerator* codegen, HInstruction* instruction, uint32_t dex_pc) {
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000813 codegen->RecordPcInfo(instruction, dex_pc, this);
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +0000814}
815
816void SlowPathCode::SaveLiveRegisters(CodeGenerator* codegen, LocationSummary* locations) {
817 RegisterSet* register_set = locations->GetLiveRegisters();
818 size_t stack_offset = codegen->GetFirstRegisterSlotInSlowPath();
819 for (size_t i = 0, e = codegen->GetNumberOfCoreRegisters(); i < e; ++i) {
820 if (!codegen->IsCoreCalleeSaveRegister(i)) {
821 if (register_set->ContainsCoreRegister(i)) {
822 // If the register holds an object, update the stack mask.
823 if (locations->RegisterContainsObject(i)) {
824 locations->SetStackBit(stack_offset / kVRegSize);
825 }
826 DCHECK_LT(stack_offset, codegen->GetFrameSize() - codegen->FrameEntrySpillSize());
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000827 DCHECK_LT(i, kMaximumNumberOfExpectedRegisters);
828 saved_core_stack_offsets_[i] = stack_offset;
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +0000829 stack_offset += codegen->SaveCoreRegister(stack_offset, i);
830 }
831 }
832 }
833
834 for (size_t i = 0, e = codegen->GetNumberOfFloatingPointRegisters(); i < e; ++i) {
835 if (!codegen->IsFloatingPointCalleeSaveRegister(i)) {
836 if (register_set->ContainsFloatingPointRegister(i)) {
837 DCHECK_LT(stack_offset, codegen->GetFrameSize() - codegen->FrameEntrySpillSize());
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000838 DCHECK_LT(i, kMaximumNumberOfExpectedRegisters);
839 saved_fpu_stack_offsets_[i] = stack_offset;
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +0000840 stack_offset += codegen->SaveFloatingPointRegister(stack_offset, i);
841 }
842 }
843 }
844}
845
846void SlowPathCode::RestoreLiveRegisters(CodeGenerator* codegen, LocationSummary* locations) {
847 RegisterSet* register_set = locations->GetLiveRegisters();
848 size_t stack_offset = codegen->GetFirstRegisterSlotInSlowPath();
849 for (size_t i = 0, e = codegen->GetNumberOfCoreRegisters(); i < e; ++i) {
850 if (!codegen->IsCoreCalleeSaveRegister(i)) {
851 if (register_set->ContainsCoreRegister(i)) {
852 DCHECK_LT(stack_offset, codegen->GetFrameSize() - codegen->FrameEntrySpillSize());
853 stack_offset += codegen->RestoreCoreRegister(stack_offset, i);
854 }
855 }
856 }
857
858 for (size_t i = 0, e = codegen->GetNumberOfFloatingPointRegisters(); i < e; ++i) {
859 if (!codegen->IsFloatingPointCalleeSaveRegister(i)) {
860 if (register_set->ContainsFloatingPointRegister(i)) {
861 DCHECK_LT(stack_offset, codegen->GetFrameSize() - codegen->FrameEntrySpillSize());
862 stack_offset += codegen->RestoreFloatingPointRegister(stack_offset, i);
863 }
864 }
865 }
866}
867
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000868} // namespace art