blob: 7d82f185a64544693ccb03f3cf27292da1933c54 [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
35#ifdef ART_ENABLE_CODEGEN_mips64
Alexey Frunze4dda3372015-06-01 18:31:49 -070036#include "code_generator_mips64.h"
Alex Light50fa9932015-08-10 15:30:07 -070037#endif
38
Yevgeny Roubane3ea8382014-08-08 16:29:38 +070039#include "compiled_method.h"
Nicolas Geoffray92cf83e2014-03-18 17:59:20 +000040#include "dex/verified_method.h"
41#include "driver/dex_compilation_unit.h"
42#include "gc_map_builder.h"
Alexandre Rameseb7b7392015-06-19 14:47:01 +010043#include "graph_visualizer.h"
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +000044#include "leb128.h"
45#include "mapping_table.h"
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +010046#include "mirror/array-inl.h"
47#include "mirror/object_array-inl.h"
48#include "mirror/object_reference.h"
Alex Light50fa9932015-08-10 15:30:07 -070049#include "parallel_move_resolver.h"
Nicolas Geoffray3c049742014-09-24 18:10:46 +010050#include "ssa_liveness_analysis.h"
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +000051#include "utils/assembler.h"
Nicolas Geoffray92cf83e2014-03-18 17:59:20 +000052#include "verifier/dex_gc_map.h"
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +000053#include "vmap_table.h"
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +000054
55namespace art {
56
Alexandre Rames88c13cd2015-04-14 17:35:39 +010057// Return whether a location is consistent with a type.
58static bool CheckType(Primitive::Type type, Location location) {
59 if (location.IsFpuRegister()
60 || (location.IsUnallocated() && (location.GetPolicy() == Location::kRequiresFpuRegister))) {
61 return (type == Primitive::kPrimFloat) || (type == Primitive::kPrimDouble);
62 } else if (location.IsRegister() ||
63 (location.IsUnallocated() && (location.GetPolicy() == Location::kRequiresRegister))) {
64 return Primitive::IsIntegralType(type) || (type == Primitive::kPrimNot);
65 } else if (location.IsRegisterPair()) {
66 return type == Primitive::kPrimLong;
67 } else if (location.IsFpuRegisterPair()) {
68 return type == Primitive::kPrimDouble;
69 } else if (location.IsStackSlot()) {
70 return (Primitive::IsIntegralType(type) && type != Primitive::kPrimLong)
71 || (type == Primitive::kPrimFloat)
72 || (type == Primitive::kPrimNot);
73 } else if (location.IsDoubleStackSlot()) {
74 return (type == Primitive::kPrimLong) || (type == Primitive::kPrimDouble);
75 } else if (location.IsConstant()) {
76 if (location.GetConstant()->IsIntConstant()) {
77 return Primitive::IsIntegralType(type) && (type != Primitive::kPrimLong);
78 } else if (location.GetConstant()->IsNullConstant()) {
79 return type == Primitive::kPrimNot;
80 } else if (location.GetConstant()->IsLongConstant()) {
81 return type == Primitive::kPrimLong;
82 } else if (location.GetConstant()->IsFloatConstant()) {
83 return type == Primitive::kPrimFloat;
84 } else {
85 return location.GetConstant()->IsDoubleConstant()
86 && (type == Primitive::kPrimDouble);
87 }
88 } else {
89 return location.IsInvalid() || (location.GetPolicy() == Location::kAny);
90 }
91}
92
93// Check that a location summary is consistent with an instruction.
94static bool CheckTypeConsistency(HInstruction* instruction) {
95 LocationSummary* locations = instruction->GetLocations();
96 if (locations == nullptr) {
97 return true;
98 }
99
100 if (locations->Out().IsUnallocated()
101 && (locations->Out().GetPolicy() == Location::kSameAsFirstInput)) {
102 DCHECK(CheckType(instruction->GetType(), locations->InAt(0)))
103 << instruction->GetType()
104 << " " << locations->InAt(0);
105 } else {
106 DCHECK(CheckType(instruction->GetType(), locations->Out()))
107 << instruction->GetType()
108 << " " << locations->Out();
109 }
110
111 for (size_t i = 0, e = instruction->InputCount(); i < e; ++i) {
112 DCHECK(CheckType(instruction->InputAt(i)->GetType(), locations->InAt(i)))
113 << instruction->InputAt(i)->GetType()
114 << " " << locations->InAt(i);
115 }
116
117 HEnvironment* environment = instruction->GetEnvironment();
118 for (size_t i = 0; i < instruction->EnvironmentSize(); ++i) {
119 if (environment->GetInstructionAt(i) != nullptr) {
120 Primitive::Type type = environment->GetInstructionAt(i)->GetType();
Nicolas Geoffray0a23d742015-05-07 11:57:35 +0100121 DCHECK(CheckType(type, environment->GetLocationAt(i)))
122 << type << " " << environment->GetLocationAt(i);
Alexandre Rames88c13cd2015-04-14 17:35:39 +0100123 } else {
Nicolas Geoffray0a23d742015-05-07 11:57:35 +0100124 DCHECK(environment->GetLocationAt(i).IsInvalid())
125 << environment->GetLocationAt(i);
Alexandre Rames88c13cd2015-04-14 17:35:39 +0100126 }
127 }
128 return true;
129}
130
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100131size_t CodeGenerator::GetCacheOffset(uint32_t index) {
132 return mirror::ObjectArray<mirror::Object>::OffsetOfElement(index).SizeValue();
133}
134
Mathieu Chartiere401d142015-04-22 13:56:20 -0700135size_t CodeGenerator::GetCachePointerOffset(uint32_t index) {
136 auto pointer_size = InstructionSetPointerSize(GetInstructionSet());
137 return mirror::Array::DataOffset(pointer_size).Uint32Value() + pointer_size * index;
138}
139
Nicolas Geoffray73e80c32014-07-22 17:47:56 +0100140void CodeGenerator::CompileBaseline(CodeAllocator* allocator, bool is_leaf) {
Nicolas Geoffray4c204ba2015-02-03 15:12:35 +0000141 Initialize();
Nicolas Geoffray73e80c32014-07-22 17:47:56 +0100142 if (!is_leaf) {
143 MarkNotLeaf();
144 }
Mathieu Chartiere3b034a2015-05-31 14:29:23 -0700145 const bool is_64_bit = Is64BitInstructionSet(GetInstructionSet());
Nicolas Geoffray4c204ba2015-02-03 15:12:35 +0000146 InitializeCodeGeneration(GetGraph()->GetNumberOfLocalVRegs()
147 + GetGraph()->GetTemporariesVRegSlots()
148 + 1 /* filler */,
149 0, /* the baseline compiler does not have live registers at slow path */
150 0, /* the baseline compiler does not have live registers at slow path */
151 GetGraph()->GetMaximumNumberOfOutVRegs()
Mathieu Chartiere3b034a2015-05-31 14:29:23 -0700152 + (is_64_bit ? 2 : 1) /* current method */,
Nicolas Geoffray4c204ba2015-02-03 15:12:35 +0000153 GetGraph()->GetBlocks());
154 CompileInternal(allocator, /* is_baseline */ true);
155}
Nicolas Geoffray86dbb9a2014-06-04 11:12:39 +0100156
Nicolas Geoffraydc23d832015-02-16 11:15:43 +0000157bool CodeGenerator::GoesToNextBlock(HBasicBlock* current, HBasicBlock* next) const {
158 DCHECK_EQ(block_order_->Get(current_block_index_), current);
159 return GetNextBlockToEmit() == FirstNonEmptyBlock(next);
160}
161
162HBasicBlock* CodeGenerator::GetNextBlockToEmit() const {
163 for (size_t i = current_block_index_ + 1; i < block_order_->Size(); ++i) {
164 HBasicBlock* block = block_order_->Get(i);
David Brazdilfc6a86a2015-06-26 10:33:45 +0000165 if (!block->IsSingleJump()) {
Nicolas Geoffraydc23d832015-02-16 11:15:43 +0000166 return block;
167 }
168 }
169 return nullptr;
170}
171
172HBasicBlock* CodeGenerator::FirstNonEmptyBlock(HBasicBlock* block) const {
David Brazdilfc6a86a2015-06-26 10:33:45 +0000173 while (block->IsSingleJump()) {
Nicolas Geoffraydc23d832015-02-16 11:15:43 +0000174 block = block->GetSuccessors().Get(0);
175 }
176 return block;
177}
178
Alexandre Rameseb7b7392015-06-19 14:47:01 +0100179class DisassemblyScope {
180 public:
181 DisassemblyScope(HInstruction* instruction, const CodeGenerator& codegen)
182 : codegen_(codegen), instruction_(instruction), start_offset_(static_cast<size_t>(-1)) {
183 if (codegen_.GetDisassemblyInformation() != nullptr) {
184 start_offset_ = codegen_.GetAssembler().CodeSize();
185 }
186 }
187
188 ~DisassemblyScope() {
189 // We avoid building this data when we know it will not be used.
190 if (codegen_.GetDisassemblyInformation() != nullptr) {
191 codegen_.GetDisassemblyInformation()->AddInstructionInterval(
192 instruction_, start_offset_, codegen_.GetAssembler().CodeSize());
193 }
194 }
195
196 private:
197 const CodeGenerator& codegen_;
198 HInstruction* instruction_;
199 size_t start_offset_;
200};
201
202
203void CodeGenerator::GenerateSlowPaths() {
204 size_t code_start = 0;
205 for (size_t i = 0, e = slow_paths_.Size(); i < e; ++i) {
206 if (disasm_info_ != nullptr) {
207 code_start = GetAssembler()->CodeSize();
208 }
209 slow_paths_.Get(i)->EmitNativeCode(this);
210 if (disasm_info_ != nullptr) {
211 disasm_info_->AddSlowPathInterval(slow_paths_.Get(i), code_start, GetAssembler()->CodeSize());
212 }
213 }
214}
215
Nicolas Geoffray4c204ba2015-02-03 15:12:35 +0000216void CodeGenerator::CompileInternal(CodeAllocator* allocator, bool is_baseline) {
Roland Levillain3e3d7332015-04-28 11:00:54 +0100217 is_baseline_ = is_baseline;
Nicolas Geoffray8a16d972014-09-11 10:30:02 +0100218 HGraphVisitor* instruction_visitor = GetInstructionVisitor();
Nicolas Geoffray4c204ba2015-02-03 15:12:35 +0000219 DCHECK_EQ(current_block_index_, 0u);
Alexandre Rameseb7b7392015-06-19 14:47:01 +0100220
221 size_t frame_start = GetAssembler()->CodeSize();
Nicolas Geoffray4c204ba2015-02-03 15:12:35 +0000222 GenerateFrameEntry();
David Srbeckyc6b4dd82015-04-07 20:32:43 +0100223 DCHECK_EQ(GetAssembler()->cfi().GetCurrentCFAOffset(), static_cast<int>(frame_size_));
Alexandre Rameseb7b7392015-06-19 14:47:01 +0100224 if (disasm_info_ != nullptr) {
225 disasm_info_->SetFrameEntryInterval(frame_start, GetAssembler()->CodeSize());
226 }
227
Nicolas Geoffray4c204ba2015-02-03 15:12:35 +0000228 for (size_t e = block_order_->Size(); current_block_index_ < e; ++current_block_index_) {
229 HBasicBlock* block = block_order_->Get(current_block_index_);
Nicolas Geoffraydc23d832015-02-16 11:15:43 +0000230 // Don't generate code for an empty block. Its predecessors will branch to its successor
231 // directly. Also, the label of that block will not be emitted, so this helps catch
232 // errors where we reference that label.
David Brazdilfc6a86a2015-06-26 10:33:45 +0000233 if (block->IsSingleJump()) continue;
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100234 Bind(block);
Nicolas Geoffray86dbb9a2014-06-04 11:12:39 +0100235 for (HInstructionIterator it(block->GetInstructions()); !it.Done(); it.Advance()) {
236 HInstruction* current = it.Current();
Alexandre Rameseb7b7392015-06-19 14:47:01 +0100237 DisassemblyScope disassembly_scope(current, *this);
Nicolas Geoffray4c204ba2015-02-03 15:12:35 +0000238 if (is_baseline) {
Nicolas Geoffrayc0572a42015-02-06 14:35:25 +0000239 InitLocationsBaseline(current);
Nicolas Geoffray4c204ba2015-02-03 15:12:35 +0000240 }
Alexandre Rames88c13cd2015-04-14 17:35:39 +0100241 DCHECK(CheckTypeConsistency(current));
Nicolas Geoffray86dbb9a2014-06-04 11:12:39 +0100242 current->Accept(instruction_visitor);
243 }
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000244 }
Nicolas Geoffray4c204ba2015-02-03 15:12:35 +0000245
Alexandre Rameseb7b7392015-06-19 14:47:01 +0100246 GenerateSlowPaths();
Nicolas Geoffray4c204ba2015-02-03 15:12:35 +0000247
248 // Finalize instructions in assember;
Serban Constantinescu32f5b4d2014-11-25 20:05:46 +0000249 Finalize(allocator);
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000250}
251
Nicolas Geoffray86dbb9a2014-06-04 11:12:39 +0100252void CodeGenerator::CompileOptimized(CodeAllocator* allocator) {
Nicolas Geoffray4c204ba2015-02-03 15:12:35 +0000253 // The register allocator already called `InitializeCodeGeneration`,
254 // where the frame size has been computed.
Nicolas Geoffray4c204ba2015-02-03 15:12:35 +0000255 DCHECK(block_order_ != nullptr);
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100256 Initialize();
Nicolas Geoffray4c204ba2015-02-03 15:12:35 +0000257 CompileInternal(allocator, /* is_baseline */ false);
Serban Constantinescu32f5b4d2014-11-25 20:05:46 +0000258}
Nicolas Geoffray86dbb9a2014-06-04 11:12:39 +0100259
Serban Constantinescu32f5b4d2014-11-25 20:05:46 +0000260void CodeGenerator::Finalize(CodeAllocator* allocator) {
Nicolas Geoffray86dbb9a2014-06-04 11:12:39 +0100261 size_t code_size = GetAssembler()->CodeSize();
262 uint8_t* buffer = allocator->Allocate(code_size);
Serban Constantinescu32f5b4d2014-11-25 20:05:46 +0000263
Nicolas Geoffray86dbb9a2014-06-04 11:12:39 +0100264 MemoryRegion code(buffer, code_size);
265 GetAssembler()->FinalizeInstructions(code);
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000266}
267
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100268size_t CodeGenerator::FindFreeEntry(bool* array, size_t length) {
269 for (size_t i = 0; i < length; ++i) {
270 if (!array[i]) {
271 array[i] = true;
272 return i;
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100273 }
274 }
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100275 LOG(FATAL) << "Could not find a register in baseline register allocator";
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000276 UNREACHABLE();
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000277}
278
Nicolas Geoffray3c035032014-10-28 10:46:40 +0000279size_t CodeGenerator::FindTwoFreeConsecutiveAlignedEntries(bool* array, size_t length) {
280 for (size_t i = 0; i < length - 1; i += 2) {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000281 if (!array[i] && !array[i + 1]) {
282 array[i] = true;
283 array[i + 1] = true;
284 return i;
285 }
286 }
287 LOG(FATAL) << "Could not find a register in baseline register allocator";
288 UNREACHABLE();
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100289}
290
Nicolas Geoffray4c204ba2015-02-03 15:12:35 +0000291void CodeGenerator::InitializeCodeGeneration(size_t number_of_spill_slots,
292 size_t maximum_number_of_live_core_registers,
293 size_t maximum_number_of_live_fp_registers,
294 size_t number_of_out_slots,
295 const GrowableArray<HBasicBlock*>& block_order) {
296 block_order_ = &block_order;
297 DCHECK(block_order_->Get(0) == GetGraph()->GetEntryBlock());
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000298 ComputeSpillMask();
Nicolas Geoffray3bca0df2014-09-19 11:01:00 +0100299 first_register_slot_in_slow_path_ = (number_of_out_slots + number_of_spill_slots) * kVRegSize;
300
Nicolas Geoffrayc0572a42015-02-06 14:35:25 +0000301 if (number_of_spill_slots == 0
302 && !HasAllocatedCalleeSaveRegisters()
303 && IsLeafMethod()
304 && !RequiresCurrentMethod()) {
305 DCHECK_EQ(maximum_number_of_live_core_registers, 0u);
306 DCHECK_EQ(maximum_number_of_live_fp_registers, 0u);
307 SetFrameSize(CallPushesPC() ? GetWordSize() : 0);
308 } else {
309 SetFrameSize(RoundUp(
310 number_of_spill_slots * kVRegSize
311 + number_of_out_slots * kVRegSize
312 + maximum_number_of_live_core_registers * GetWordSize()
313 + maximum_number_of_live_fp_registers * GetFloatingPointSpillSlotSize()
314 + FrameEntrySpillSize(),
315 kStackAlignment));
316 }
Nicolas Geoffrayab032bc2014-07-15 12:55:21 +0100317}
318
319Location CodeGenerator::GetTemporaryLocation(HTemporary* temp) const {
320 uint16_t number_of_locals = GetGraph()->GetNumberOfLocalVRegs();
Calin Juravlef97f9fb2014-11-11 15:38:19 +0000321 // The type of the previous instruction tells us if we need a single or double stack slot.
322 Primitive::Type type = temp->GetType();
323 int32_t temp_size = (type == Primitive::kPrimLong) || (type == Primitive::kPrimDouble) ? 2 : 1;
Nicolas Geoffrayab032bc2014-07-15 12:55:21 +0100324 // Use the temporary region (right below the dex registers).
325 int32_t slot = GetFrameSize() - FrameEntrySpillSize()
326 - kVRegSize // filler
327 - (number_of_locals * kVRegSize)
Calin Juravlef97f9fb2014-11-11 15:38:19 +0000328 - ((temp_size + temp->GetIndex()) * kVRegSize);
329 return temp_size == 2 ? Location::DoubleStackSlot(slot) : Location::StackSlot(slot);
Nicolas Geoffrayab032bc2014-07-15 12:55:21 +0100330}
331
332int32_t CodeGenerator::GetStackSlot(HLocal* local) const {
333 uint16_t reg_number = local->GetRegNumber();
334 uint16_t number_of_locals = GetGraph()->GetNumberOfLocalVRegs();
335 if (reg_number >= number_of_locals) {
336 // Local is a parameter of the method. It is stored in the caller's frame.
Mathieu Chartiere401d142015-04-22 13:56:20 -0700337 // TODO: Share this logic with StackVisitor::GetVRegOffsetFromQuickCode.
338 return GetFrameSize() + InstructionSetPointerSize(GetInstructionSet()) // ART method
Nicolas Geoffrayab032bc2014-07-15 12:55:21 +0100339 + (reg_number - number_of_locals) * kVRegSize;
340 } else {
341 // Local is a temporary in this method. It is stored in this method's frame.
342 return GetFrameSize() - FrameEntrySpillSize()
343 - kVRegSize // filler.
344 - (number_of_locals * kVRegSize)
345 + (reg_number * kVRegSize);
346 }
347}
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100348
Nicolas Geoffrayfd88f162015-06-03 11:23:52 +0100349void CodeGenerator::CreateCommonInvokeLocationSummary(
Nicolas Geoffray4e40c262015-06-03 12:02:38 +0100350 HInvoke* invoke, InvokeDexCallingConventionVisitor* visitor) {
Nicolas Geoffrayfd88f162015-06-03 11:23:52 +0100351 ArenaAllocator* allocator = invoke->GetBlock()->GetGraph()->GetArena();
352 LocationSummary* locations = new (allocator) LocationSummary(invoke, LocationSummary::kCall);
Nicolas Geoffrayfd88f162015-06-03 11:23:52 +0100353
354 for (size_t i = 0; i < invoke->GetNumberOfArguments(); i++) {
355 HInstruction* input = invoke->InputAt(i);
356 locations->SetInAt(i, visitor->GetNextLocation(input->GetType()));
357 }
358
359 locations->SetOut(visitor->GetReturnLocation(invoke->GetType()));
Nicolas Geoffray94015b92015-06-04 18:21:04 +0100360
361 if (invoke->IsInvokeStaticOrDirect()) {
362 HInvokeStaticOrDirect* call = invoke->AsInvokeStaticOrDirect();
363 if (call->IsStringInit()) {
364 locations->AddTemp(visitor->GetMethodLocation());
365 } else if (call->IsRecursive()) {
366 locations->SetInAt(call->GetCurrentMethodInputIndex(), visitor->GetMethodLocation());
367 } else {
368 locations->AddTemp(visitor->GetMethodLocation());
369 locations->SetInAt(call->GetCurrentMethodInputIndex(), Location::RequiresRegister());
370 }
371 } else {
372 locations->AddTemp(visitor->GetMethodLocation());
373 }
Nicolas Geoffrayfd88f162015-06-03 11:23:52 +0100374}
375
Mark Mendell5f874182015-03-04 15:42:45 -0500376void CodeGenerator::BlockIfInRegister(Location location, bool is_out) const {
377 // The DCHECKS below check that a register is not specified twice in
378 // the summary. The out location can overlap with an input, so we need
379 // to special case it.
380 if (location.IsRegister()) {
381 DCHECK(is_out || !blocked_core_registers_[location.reg()]);
382 blocked_core_registers_[location.reg()] = true;
383 } else if (location.IsFpuRegister()) {
384 DCHECK(is_out || !blocked_fpu_registers_[location.reg()]);
385 blocked_fpu_registers_[location.reg()] = true;
386 } else if (location.IsFpuRegisterPair()) {
387 DCHECK(is_out || !blocked_fpu_registers_[location.AsFpuRegisterPairLow<int>()]);
388 blocked_fpu_registers_[location.AsFpuRegisterPairLow<int>()] = true;
389 DCHECK(is_out || !blocked_fpu_registers_[location.AsFpuRegisterPairHigh<int>()]);
390 blocked_fpu_registers_[location.AsFpuRegisterPairHigh<int>()] = true;
391 } else if (location.IsRegisterPair()) {
392 DCHECK(is_out || !blocked_core_registers_[location.AsRegisterPairLow<int>()]);
393 blocked_core_registers_[location.AsRegisterPairLow<int>()] = true;
394 DCHECK(is_out || !blocked_core_registers_[location.AsRegisterPairHigh<int>()]);
395 blocked_core_registers_[location.AsRegisterPairHigh<int>()] = true;
396 }
397}
398
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100399void CodeGenerator::AllocateRegistersLocally(HInstruction* instruction) const {
400 LocationSummary* locations = instruction->GetLocations();
401 if (locations == nullptr) return;
402
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100403 for (size_t i = 0, e = GetNumberOfCoreRegisters(); i < e; ++i) {
404 blocked_core_registers_[i] = false;
405 }
406
407 for (size_t i = 0, e = GetNumberOfFloatingPointRegisters(); i < e; ++i) {
408 blocked_fpu_registers_[i] = false;
409 }
410
411 for (size_t i = 0, e = number_of_register_pairs_; i < e; ++i) {
412 blocked_register_pairs_[i] = false;
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100413 }
414
415 // Mark all fixed input, temp and output registers as used.
416 for (size_t i = 0, e = locations->GetInputCount(); i < e; ++i) {
Mark Mendell5f874182015-03-04 15:42:45 -0500417 BlockIfInRegister(locations->InAt(i));
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100418 }
419
420 for (size_t i = 0, e = locations->GetTempCount(); i < e; ++i) {
421 Location loc = locations->GetTemp(i);
Mark Mendell5f874182015-03-04 15:42:45 -0500422 BlockIfInRegister(loc);
423 }
424 Location result_location = locations->Out();
425 if (locations->OutputCanOverlapWithInputs()) {
426 BlockIfInRegister(result_location, /* is_out */ true);
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100427 }
428
Mark Mendell5f874182015-03-04 15:42:45 -0500429 SetupBlockedRegisters(/* is_baseline */ true);
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100430
431 // Allocate all unallocated input locations.
432 for (size_t i = 0, e = locations->GetInputCount(); i < e; ++i) {
433 Location loc = locations->InAt(i);
434 HInstruction* input = instruction->InputAt(i);
435 if (loc.IsUnallocated()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100436 if ((loc.GetPolicy() == Location::kRequiresRegister)
437 || (loc.GetPolicy() == Location::kRequiresFpuRegister)) {
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100438 loc = AllocateFreeRegister(input->GetType());
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100439 } else {
440 DCHECK_EQ(loc.GetPolicy(), Location::kAny);
441 HLoadLocal* load = input->AsLoadLocal();
442 if (load != nullptr) {
443 loc = GetStackLocation(load);
444 } else {
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100445 loc = AllocateFreeRegister(input->GetType());
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100446 }
447 }
448 locations->SetInAt(i, loc);
449 }
450 }
451
452 // Allocate all unallocated temp locations.
453 for (size_t i = 0, e = locations->GetTempCount(); i < e; ++i) {
454 Location loc = locations->GetTemp(i);
455 if (loc.IsUnallocated()) {
Roland Levillain647b9ed2014-11-27 12:06:00 +0000456 switch (loc.GetPolicy()) {
457 case Location::kRequiresRegister:
458 // Allocate a core register (large enough to fit a 32-bit integer).
459 loc = AllocateFreeRegister(Primitive::kPrimInt);
460 break;
461
462 case Location::kRequiresFpuRegister:
463 // Allocate a core register (large enough to fit a 64-bit double).
464 loc = AllocateFreeRegister(Primitive::kPrimDouble);
465 break;
466
467 default:
468 LOG(FATAL) << "Unexpected policy for temporary location "
469 << loc.GetPolicy();
470 }
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100471 locations->SetTempAt(i, loc);
472 }
473 }
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100474 if (result_location.IsUnallocated()) {
475 switch (result_location.GetPolicy()) {
476 case Location::kAny:
477 case Location::kRequiresRegister:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100478 case Location::kRequiresFpuRegister:
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100479 result_location = AllocateFreeRegister(instruction->GetType());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100480 break;
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100481 case Location::kSameAsFirstInput:
482 result_location = locations->InAt(0);
483 break;
484 }
Nicolas Geoffray829280c2015-01-28 10:20:37 +0000485 locations->UpdateOut(result_location);
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100486 }
487}
488
Nicolas Geoffrayc0572a42015-02-06 14:35:25 +0000489void CodeGenerator::InitLocationsBaseline(HInstruction* instruction) {
490 AllocateLocations(instruction);
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100491 if (instruction->GetLocations() == nullptr) {
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100492 if (instruction->IsTemporary()) {
493 HInstruction* previous = instruction->GetPrevious();
494 Location temp_location = GetTemporaryLocation(instruction->AsTemporary());
495 Move(previous, temp_location, instruction);
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100496 }
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100497 return;
498 }
499 AllocateRegistersLocally(instruction);
500 for (size_t i = 0, e = instruction->InputCount(); i < e; ++i) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000501 Location location = instruction->GetLocations()->InAt(i);
Nicolas Geoffrayf43083d2014-11-07 10:48:10 +0000502 HInstruction* input = instruction->InputAt(i);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000503 if (location.IsValid()) {
504 // Move the input to the desired location.
Nicolas Geoffrayf43083d2014-11-07 10:48:10 +0000505 if (input->GetNext()->IsTemporary()) {
506 // If the input was stored in a temporary, use that temporary to
507 // perform the move.
508 Move(input->GetNext(), location, instruction);
509 } else {
510 Move(input, location, instruction);
511 }
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000512 }
513 }
514}
515
Nicolas Geoffrayc0572a42015-02-06 14:35:25 +0000516void CodeGenerator::AllocateLocations(HInstruction* instruction) {
517 instruction->Accept(GetLocationBuilder());
Alexandre Rames88c13cd2015-04-14 17:35:39 +0100518 DCHECK(CheckTypeConsistency(instruction));
Nicolas Geoffrayc0572a42015-02-06 14:35:25 +0000519 LocationSummary* locations = instruction->GetLocations();
520 if (!instruction->IsSuspendCheckEntry()) {
521 if (locations != nullptr && locations->CanCall()) {
522 MarkNotLeaf();
523 }
524 if (instruction->NeedsCurrentMethod()) {
525 SetRequiresCurrentMethod();
526 }
527 }
528}
529
Nicolas Geoffray12df9eb2015-01-09 14:53:50 +0000530CodeGenerator* CodeGenerator::Create(HGraph* graph,
Calin Juravle34166012014-12-19 17:22:29 +0000531 InstructionSet instruction_set,
Calin Juravlecd6dffe2015-01-08 17:35:35 +0000532 const InstructionSetFeatures& isa_features,
533 const CompilerOptions& compiler_options) {
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000534 switch (instruction_set) {
Alex Light50fa9932015-08-10 15:30:07 -0700535#ifdef ART_ENABLE_CODEGEN_arm
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000536 case kArm:
537 case kThumb2: {
Nicolas Geoffray12df9eb2015-01-09 14:53:50 +0000538 return new arm::CodeGeneratorARM(graph,
Calin Juravlecd6dffe2015-01-08 17:35:35 +0000539 *isa_features.AsArmInstructionSetFeatures(),
540 compiler_options);
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000541 }
Alex Light50fa9932015-08-10 15:30:07 -0700542#endif
543#ifdef ART_ENABLE_CODEGEN_arm64
Alexandre Rames5319def2014-10-23 10:03:10 +0100544 case kArm64: {
Serban Constantinescu579885a2015-02-22 20:51:33 +0000545 return new arm64::CodeGeneratorARM64(graph,
546 *isa_features.AsArm64InstructionSetFeatures(),
547 compiler_options);
Alexandre Rames5319def2014-10-23 10:03:10 +0100548 }
Alex Light50fa9932015-08-10 15:30:07 -0700549#endif
550#ifdef ART_ENABLE_CODEGEN_mips
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000551 case kMips:
Alex Light50fa9932015-08-10 15:30:07 -0700552 UNUSED(compiler_options);
553 UNUSED(graph);
554 UNUSED(isa_features);
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000555 return nullptr;
Alex Light50fa9932015-08-10 15:30:07 -0700556#endif
557#ifdef ART_ENABLE_CODEGEN_mips64
Alexey Frunze4dda3372015-06-01 18:31:49 -0700558 case kMips64: {
559 return new mips64::CodeGeneratorMIPS64(graph,
560 *isa_features.AsMips64InstructionSetFeatures(),
561 compiler_options);
562 }
Alex Light50fa9932015-08-10 15:30:07 -0700563#endif
564#ifdef ART_ENABLE_CODEGEN_x86
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000565 case kX86: {
Mark Mendellfb8d2792015-03-31 22:16:59 -0400566 return new x86::CodeGeneratorX86(graph,
567 *isa_features.AsX86InstructionSetFeatures(),
568 compiler_options);
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000569 }
Alex Light50fa9932015-08-10 15:30:07 -0700570#endif
571#ifdef ART_ENABLE_CODEGEN_x86_64
Dmitry Petrochenko6a58cb12014-04-02 17:27:59 +0700572 case kX86_64: {
Mark Mendellfb8d2792015-03-31 22:16:59 -0400573 return new x86_64::CodeGeneratorX86_64(graph,
574 *isa_features.AsX86_64InstructionSetFeatures(),
575 compiler_options);
Dmitry Petrochenko6a58cb12014-04-02 17:27:59 +0700576 }
Alex Light50fa9932015-08-10 15:30:07 -0700577#endif
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000578 default:
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000579 return nullptr;
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000580 }
581}
582
Nicolas Geoffray92cf83e2014-03-18 17:59:20 +0000583void CodeGenerator::BuildNativeGCMap(
584 std::vector<uint8_t>* data, const DexCompilationUnit& dex_compilation_unit) const {
585 const std::vector<uint8_t>& gc_map_raw =
586 dex_compilation_unit.GetVerifiedMethod()->GetDexGcMap();
587 verifier::DexPcToReferenceMap dex_gc_map(&(gc_map_raw)[0]);
588
Vladimir Markobd8c7252015-06-12 10:06:32 +0100589 uint32_t max_native_offset = stack_map_stream_.ComputeMaxNativePcOffset();
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +0000590
Vladimir Markobd8c7252015-06-12 10:06:32 +0100591 size_t num_stack_maps = stack_map_stream_.GetNumberOfStackMaps();
592 GcMapBuilder builder(data, num_stack_maps, max_native_offset, dex_gc_map.RegWidth());
593 for (size_t i = 0; i != num_stack_maps; ++i) {
594 const StackMapStream::StackMapEntry& stack_map_entry = stack_map_stream_.GetStackMap(i);
595 uint32_t native_offset = stack_map_entry.native_pc_offset;
596 uint32_t dex_pc = stack_map_entry.dex_pc;
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +0000597 const uint8_t* references = dex_gc_map.FindBitMap(dex_pc, false);
Jean Christophe Beyler0ada95d2014-12-04 11:20:20 -0800598 CHECK(references != nullptr) << "Missing ref for dex pc 0x" << std::hex << dex_pc;
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +0000599 builder.AddEntry(native_offset, references);
600 }
Nicolas Geoffray92cf83e2014-03-18 17:59:20 +0000601}
602
David Srbeckyc6b4dd82015-04-07 20:32:43 +0100603void CodeGenerator::BuildSourceMap(DefaultSrcMap* src_map) const {
Vladimir Markobd8c7252015-06-12 10:06:32 +0100604 for (size_t i = 0, num = stack_map_stream_.GetNumberOfStackMaps(); i != num; ++i) {
605 const StackMapStream::StackMapEntry& stack_map_entry = stack_map_stream_.GetStackMap(i);
606 uint32_t pc2dex_offset = stack_map_entry.native_pc_offset;
607 int32_t pc2dex_dalvik_offset = stack_map_entry.dex_pc;
David Srbeckyc6b4dd82015-04-07 20:32:43 +0100608 src_map->push_back(SrcMapElem({pc2dex_offset, pc2dex_dalvik_offset}));
609 }
610}
611
612void CodeGenerator::BuildMappingTable(std::vector<uint8_t>* data) const {
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +0000613 uint32_t pc2dex_data_size = 0u;
Vladimir Markobd8c7252015-06-12 10:06:32 +0100614 uint32_t pc2dex_entries = stack_map_stream_.GetNumberOfStackMaps();
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +0000615 uint32_t pc2dex_offset = 0u;
616 int32_t pc2dex_dalvik_offset = 0;
617 uint32_t dex2pc_data_size = 0u;
618 uint32_t dex2pc_entries = 0u;
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +0000619 uint32_t dex2pc_offset = 0u;
620 int32_t dex2pc_dalvik_offset = 0;
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +0000621
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +0000622 for (size_t i = 0; i < pc2dex_entries; i++) {
Vladimir Markobd8c7252015-06-12 10:06:32 +0100623 const StackMapStream::StackMapEntry& stack_map_entry = stack_map_stream_.GetStackMap(i);
624 pc2dex_data_size += UnsignedLeb128Size(stack_map_entry.native_pc_offset - pc2dex_offset);
625 pc2dex_data_size += SignedLeb128Size(stack_map_entry.dex_pc - pc2dex_dalvik_offset);
626 pc2dex_offset = stack_map_entry.native_pc_offset;
627 pc2dex_dalvik_offset = stack_map_entry.dex_pc;
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +0000628 }
629
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +0000630 // Walk over the blocks and find which ones correspond to catch block entries.
631 for (size_t i = 0; i < graph_->GetBlocks().Size(); ++i) {
632 HBasicBlock* block = graph_->GetBlocks().Get(i);
633 if (block->IsCatchBlock()) {
634 intptr_t native_pc = GetAddressOf(block);
635 ++dex2pc_entries;
636 dex2pc_data_size += UnsignedLeb128Size(native_pc - dex2pc_offset);
637 dex2pc_data_size += SignedLeb128Size(block->GetDexPc() - dex2pc_dalvik_offset);
638 dex2pc_offset = native_pc;
639 dex2pc_dalvik_offset = block->GetDexPc();
640 }
641 }
642
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +0000643 uint32_t total_entries = pc2dex_entries + dex2pc_entries;
644 uint32_t hdr_data_size = UnsignedLeb128Size(total_entries) + UnsignedLeb128Size(pc2dex_entries);
645 uint32_t data_size = hdr_data_size + pc2dex_data_size + dex2pc_data_size;
646 data->resize(data_size);
647
648 uint8_t* data_ptr = &(*data)[0];
649 uint8_t* write_pos = data_ptr;
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +0000650
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +0000651 write_pos = EncodeUnsignedLeb128(write_pos, total_entries);
652 write_pos = EncodeUnsignedLeb128(write_pos, pc2dex_entries);
653 DCHECK_EQ(static_cast<size_t>(write_pos - data_ptr), hdr_data_size);
654 uint8_t* write_pos2 = write_pos + pc2dex_data_size;
655
656 pc2dex_offset = 0u;
657 pc2dex_dalvik_offset = 0u;
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +0000658 dex2pc_offset = 0u;
659 dex2pc_dalvik_offset = 0u;
660
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +0000661 for (size_t i = 0; i < pc2dex_entries; i++) {
Vladimir Markobd8c7252015-06-12 10:06:32 +0100662 const StackMapStream::StackMapEntry& stack_map_entry = stack_map_stream_.GetStackMap(i);
663 DCHECK(pc2dex_offset <= stack_map_entry.native_pc_offset);
664 write_pos = EncodeUnsignedLeb128(write_pos, stack_map_entry.native_pc_offset - pc2dex_offset);
665 write_pos = EncodeSignedLeb128(write_pos, stack_map_entry.dex_pc - pc2dex_dalvik_offset);
666 pc2dex_offset = stack_map_entry.native_pc_offset;
667 pc2dex_dalvik_offset = stack_map_entry.dex_pc;
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +0000668 }
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +0000669
670 for (size_t i = 0; i < graph_->GetBlocks().Size(); ++i) {
671 HBasicBlock* block = graph_->GetBlocks().Get(i);
672 if (block->IsCatchBlock()) {
673 intptr_t native_pc = GetAddressOf(block);
674 write_pos2 = EncodeUnsignedLeb128(write_pos2, native_pc - dex2pc_offset);
675 write_pos2 = EncodeSignedLeb128(write_pos2, block->GetDexPc() - dex2pc_dalvik_offset);
676 dex2pc_offset = native_pc;
677 dex2pc_dalvik_offset = block->GetDexPc();
678 }
679 }
680
681
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +0000682 DCHECK_EQ(static_cast<size_t>(write_pos - data_ptr), hdr_data_size + pc2dex_data_size);
683 DCHECK_EQ(static_cast<size_t>(write_pos2 - data_ptr), data_size);
684
685 if (kIsDebugBuild) {
686 // Verify the encoded table holds the expected data.
687 MappingTable table(data_ptr);
688 CHECK_EQ(table.TotalSize(), total_entries);
689 CHECK_EQ(table.PcToDexSize(), pc2dex_entries);
690 auto it = table.PcToDexBegin();
691 auto it2 = table.DexToPcBegin();
692 for (size_t i = 0; i < pc2dex_entries; i++) {
Vladimir Markobd8c7252015-06-12 10:06:32 +0100693 const StackMapStream::StackMapEntry& stack_map_entry = stack_map_stream_.GetStackMap(i);
694 CHECK_EQ(stack_map_entry.native_pc_offset, it.NativePcOffset());
695 CHECK_EQ(stack_map_entry.dex_pc, it.DexPc());
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +0000696 ++it;
697 }
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +0000698 for (size_t i = 0; i < graph_->GetBlocks().Size(); ++i) {
699 HBasicBlock* block = graph_->GetBlocks().Get(i);
700 if (block->IsCatchBlock()) {
701 CHECK_EQ(GetAddressOf(block), it2.NativePcOffset());
702 CHECK_EQ(block->GetDexPc(), it2.DexPc());
703 ++it2;
704 }
705 }
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +0000706 CHECK(it == table.PcToDexEnd());
707 CHECK(it2 == table.DexToPcEnd());
708 }
709}
710
711void CodeGenerator::BuildVMapTable(std::vector<uint8_t>* data) const {
712 Leb128EncodingVector vmap_encoder;
Nicolas Geoffray4a34a422014-04-03 10:38:37 +0100713 // We currently don't use callee-saved registers.
714 size_t size = 0 + 1 /* marker */ + 0;
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +0000715 vmap_encoder.Reserve(size + 1u); // All values are likely to be one byte in ULEB128 (<128).
716 vmap_encoder.PushBackUnsigned(size);
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +0000717 vmap_encoder.PushBackUnsigned(VmapTable::kAdjustedFpMarker);
718
719 *data = vmap_encoder.GetData();
720}
Nicolas Geoffray92cf83e2014-03-18 17:59:20 +0000721
Nicolas Geoffray39468442014-09-02 15:17:15 +0100722void CodeGenerator::BuildStackMaps(std::vector<uint8_t>* data) {
Calin Juravle4f46ac52015-04-23 18:47:21 +0100723 uint32_t size = stack_map_stream_.PrepareForFillIn();
Nicolas Geoffray39468442014-09-02 15:17:15 +0100724 data->resize(size);
725 MemoryRegion region(data->data(), size);
726 stack_map_stream_.FillIn(region);
727}
728
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000729void CodeGenerator::RecordPcInfo(HInstruction* instruction,
730 uint32_t dex_pc,
731 SlowPathCode* slow_path) {
Calin Juravled2ec87d2014-12-08 14:24:46 +0000732 if (instruction != nullptr) {
Alexey Frunze4dda3372015-06-01 18:31:49 -0700733 // The code generated for some type conversions and comparisons
734 // may call the runtime, thus normally requiring a subsequent
735 // call to this method. However, the method verifier does not
736 // produce PC information for certain instructions, which are
737 // considered "atomic" (they cannot join a GC).
Roland Levillain624279f2014-12-04 11:54:28 +0000738 // Therefore we do not currently record PC information for such
739 // instructions. As this may change later, we added this special
740 // case so that code generators may nevertheless call
741 // CodeGenerator::RecordPcInfo without triggering an error in
742 // CodeGenerator::BuildNativeGCMap ("Missing ref for dex pc 0x")
743 // thereafter.
Alexey Frunze4dda3372015-06-01 18:31:49 -0700744 if (instruction->IsTypeConversion() || instruction->IsCompare()) {
Calin Juravled2ec87d2014-12-08 14:24:46 +0000745 return;
746 }
747 if (instruction->IsRem()) {
748 Primitive::Type type = instruction->AsRem()->GetResultType();
749 if ((type == Primitive::kPrimFloat) || (type == Primitive::kPrimDouble)) {
750 return;
751 }
752 }
Roland Levillain624279f2014-12-04 11:54:28 +0000753 }
754
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100755 uint32_t outer_dex_pc = dex_pc;
756 uint32_t outer_environment_size = 0;
757 uint32_t inlining_depth = 0;
758 if (instruction != nullptr) {
759 for (HEnvironment* environment = instruction->GetEnvironment();
760 environment != nullptr;
761 environment = environment->GetParent()) {
762 outer_dex_pc = environment->GetDexPc();
763 outer_environment_size = environment->Size();
764 if (environment != instruction->GetEnvironment()) {
765 inlining_depth++;
766 }
767 }
768 }
769
Nicolas Geoffray39468442014-09-02 15:17:15 +0100770 // Collect PC infos for the mapping table.
Vladimir Markobd8c7252015-06-12 10:06:32 +0100771 uint32_t native_pc = GetAssembler()->CodeSize();
Nicolas Geoffray39468442014-09-02 15:17:15 +0100772
Nicolas Geoffray39468442014-09-02 15:17:15 +0100773 if (instruction == nullptr) {
774 // For stack overflow checks.
Vladimir Markobd8c7252015-06-12 10:06:32 +0100775 stack_map_stream_.BeginStackMapEntry(outer_dex_pc, native_pc, 0, 0, 0, 0);
Calin Juravle4f46ac52015-04-23 18:47:21 +0100776 stack_map_stream_.EndStackMapEntry();
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000777 return;
778 }
779 LocationSummary* locations = instruction->GetLocations();
Nicolas Geoffray39468442014-09-02 15:17:15 +0100780
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000781 uint32_t register_mask = locations->GetRegisterMask();
782 if (locations->OnlyCallsOnSlowPath()) {
783 // In case of slow path, we currently set the location of caller-save registers
784 // to register (instead of their stack location when pushed before the slow-path
785 // call). Therefore register_mask contains both callee-save and caller-save
786 // registers that hold objects. We must remove the caller-save from the mask, since
787 // they will be overwritten by the callee.
788 register_mask &= core_callee_save_mask_;
789 }
790 // The register mask must be a subset of callee-save registers.
791 DCHECK_EQ(register_mask & core_callee_save_mask_, register_mask);
Vladimir Markobd8c7252015-06-12 10:06:32 +0100792 stack_map_stream_.BeginStackMapEntry(outer_dex_pc,
793 native_pc,
Calin Juravle4f46ac52015-04-23 18:47:21 +0100794 register_mask,
795 locations->GetStackMask(),
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100796 outer_environment_size,
Calin Juravle4f46ac52015-04-23 18:47:21 +0100797 inlining_depth);
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100798
799 EmitEnvironment(instruction->GetEnvironment(), slow_path);
800 stack_map_stream_.EndStackMapEntry();
801}
802
803void CodeGenerator::EmitEnvironment(HEnvironment* environment, SlowPathCode* slow_path) {
804 if (environment == nullptr) return;
805
806 if (environment->GetParent() != nullptr) {
807 // We emit the parent environment first.
808 EmitEnvironment(environment->GetParent(), slow_path);
Nicolas Geoffrayb176d7c2015-05-20 18:48:31 +0100809 stack_map_stream_.BeginInlineInfoEntry(environment->GetMethodIdx(),
810 environment->GetDexPc(),
811 environment->GetInvokeType(),
812 environment->Size());
Nicolas Geoffray0a23d742015-05-07 11:57:35 +0100813 }
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000814
815 // Walk over the environment, and record the location of dex registers.
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100816 for (size_t i = 0, environment_size = environment->Size(); i < environment_size; ++i) {
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000817 HInstruction* current = environment->GetInstructionAt(i);
818 if (current == nullptr) {
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100819 stack_map_stream_.AddDexRegisterEntry(DexRegisterLocation::Kind::kNone, 0);
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000820 continue;
Nicolas Geoffray39468442014-09-02 15:17:15 +0100821 }
822
Nicolas Geoffray0a23d742015-05-07 11:57:35 +0100823 Location location = environment->GetLocationAt(i);
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000824 switch (location.GetKind()) {
825 case Location::kConstant: {
826 DCHECK_EQ(current, location.GetConstant());
827 if (current->IsLongConstant()) {
828 int64_t value = current->AsLongConstant()->GetValue();
829 stack_map_stream_.AddDexRegisterEntry(
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100830 DexRegisterLocation::Kind::kConstant, Low32Bits(value));
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000831 stack_map_stream_.AddDexRegisterEntry(
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100832 DexRegisterLocation::Kind::kConstant, High32Bits(value));
833 ++i;
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000834 DCHECK_LT(i, environment_size);
835 } else if (current->IsDoubleConstant()) {
Roland Levillainda4d79b2015-03-24 14:36:11 +0000836 int64_t value = bit_cast<int64_t, double>(current->AsDoubleConstant()->GetValue());
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000837 stack_map_stream_.AddDexRegisterEntry(
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100838 DexRegisterLocation::Kind::kConstant, Low32Bits(value));
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000839 stack_map_stream_.AddDexRegisterEntry(
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100840 DexRegisterLocation::Kind::kConstant, High32Bits(value));
841 ++i;
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000842 DCHECK_LT(i, environment_size);
843 } else if (current->IsIntConstant()) {
844 int32_t value = current->AsIntConstant()->GetValue();
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100845 stack_map_stream_.AddDexRegisterEntry(DexRegisterLocation::Kind::kConstant, value);
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000846 } else if (current->IsNullConstant()) {
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100847 stack_map_stream_.AddDexRegisterEntry(DexRegisterLocation::Kind::kConstant, 0);
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000848 } else {
849 DCHECK(current->IsFloatConstant()) << current->DebugName();
Roland Levillainda4d79b2015-03-24 14:36:11 +0000850 int32_t value = bit_cast<int32_t, float>(current->AsFloatConstant()->GetValue());
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100851 stack_map_stream_.AddDexRegisterEntry(DexRegisterLocation::Kind::kConstant, value);
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000852 }
853 break;
854 }
855
856 case Location::kStackSlot: {
857 stack_map_stream_.AddDexRegisterEntry(
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100858 DexRegisterLocation::Kind::kInStack, location.GetStackIndex());
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000859 break;
860 }
861
862 case Location::kDoubleStackSlot: {
863 stack_map_stream_.AddDexRegisterEntry(
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100864 DexRegisterLocation::Kind::kInStack, location.GetStackIndex());
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000865 stack_map_stream_.AddDexRegisterEntry(
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100866 DexRegisterLocation::Kind::kInStack, location.GetHighStackIndex(kVRegSize));
867 ++i;
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000868 DCHECK_LT(i, environment_size);
869 break;
870 }
871
872 case Location::kRegister : {
873 int id = location.reg();
874 if (slow_path != nullptr && slow_path->IsCoreRegisterSaved(id)) {
875 uint32_t offset = slow_path->GetStackOffsetOfCoreRegister(id);
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100876 stack_map_stream_.AddDexRegisterEntry(DexRegisterLocation::Kind::kInStack, offset);
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000877 if (current->GetType() == Primitive::kPrimLong) {
878 stack_map_stream_.AddDexRegisterEntry(
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100879 DexRegisterLocation::Kind::kInStack, offset + kVRegSize);
880 ++i;
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000881 DCHECK_LT(i, environment_size);
882 }
883 } else {
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100884 stack_map_stream_.AddDexRegisterEntry(DexRegisterLocation::Kind::kInRegister, id);
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000885 if (current->GetType() == Primitive::kPrimLong) {
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100886 stack_map_stream_.AddDexRegisterEntry(DexRegisterLocation::Kind::kInRegister, id);
887 ++i;
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000888 DCHECK_LT(i, environment_size);
889 }
890 }
891 break;
892 }
893
894 case Location::kFpuRegister : {
895 int id = location.reg();
896 if (slow_path != nullptr && slow_path->IsFpuRegisterSaved(id)) {
897 uint32_t offset = slow_path->GetStackOffsetOfFpuRegister(id);
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100898 stack_map_stream_.AddDexRegisterEntry(DexRegisterLocation::Kind::kInStack, offset);
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000899 if (current->GetType() == Primitive::kPrimDouble) {
900 stack_map_stream_.AddDexRegisterEntry(
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100901 DexRegisterLocation::Kind::kInStack, offset + kVRegSize);
902 ++i;
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000903 DCHECK_LT(i, environment_size);
904 }
905 } else {
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100906 stack_map_stream_.AddDexRegisterEntry(DexRegisterLocation::Kind::kInFpuRegister, id);
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000907 if (current->GetType() == Primitive::kPrimDouble) {
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100908 stack_map_stream_.AddDexRegisterEntry(DexRegisterLocation::Kind::kInFpuRegister, id);
909 ++i;
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000910 DCHECK_LT(i, environment_size);
911 }
912 }
913 break;
914 }
915
916 case Location::kFpuRegisterPair : {
917 int low = location.low();
918 int high = location.high();
919 if (slow_path != nullptr && slow_path->IsFpuRegisterSaved(low)) {
920 uint32_t offset = slow_path->GetStackOffsetOfFpuRegister(low);
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100921 stack_map_stream_.AddDexRegisterEntry(DexRegisterLocation::Kind::kInStack, offset);
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000922 } else {
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100923 stack_map_stream_.AddDexRegisterEntry(DexRegisterLocation::Kind::kInFpuRegister, low);
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000924 }
925 if (slow_path != nullptr && slow_path->IsFpuRegisterSaved(high)) {
926 uint32_t offset = slow_path->GetStackOffsetOfFpuRegister(high);
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100927 stack_map_stream_.AddDexRegisterEntry(DexRegisterLocation::Kind::kInStack, offset);
928 ++i;
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000929 } else {
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100930 stack_map_stream_.AddDexRegisterEntry(DexRegisterLocation::Kind::kInFpuRegister, high);
931 ++i;
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000932 }
933 DCHECK_LT(i, environment_size);
934 break;
935 }
936
937 case Location::kRegisterPair : {
938 int low = location.low();
939 int high = location.high();
940 if (slow_path != nullptr && slow_path->IsCoreRegisterSaved(low)) {
941 uint32_t offset = slow_path->GetStackOffsetOfCoreRegister(low);
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100942 stack_map_stream_.AddDexRegisterEntry(DexRegisterLocation::Kind::kInStack, offset);
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000943 } else {
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100944 stack_map_stream_.AddDexRegisterEntry(DexRegisterLocation::Kind::kInRegister, low);
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000945 }
946 if (slow_path != nullptr && slow_path->IsCoreRegisterSaved(high)) {
947 uint32_t offset = slow_path->GetStackOffsetOfCoreRegister(high);
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100948 stack_map_stream_.AddDexRegisterEntry(DexRegisterLocation::Kind::kInStack, offset);
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000949 } else {
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100950 stack_map_stream_.AddDexRegisterEntry(DexRegisterLocation::Kind::kInRegister, high);
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000951 }
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100952 ++i;
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000953 DCHECK_LT(i, environment_size);
954 break;
955 }
956
957 case Location::kInvalid: {
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100958 stack_map_stream_.AddDexRegisterEntry(DexRegisterLocation::Kind::kNone, 0);
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000959 break;
960 }
961
962 default:
963 LOG(FATAL) << "Unexpected kind " << location.GetKind();
964 }
Nicolas Geoffray39468442014-09-02 15:17:15 +0100965 }
Nicolas Geoffrayb1d0f3f2015-05-14 12:41:51 +0100966
967 if (environment->GetParent() != nullptr) {
968 stack_map_stream_.EndInlineInfoEntry();
969 }
Nicolas Geoffray39468442014-09-02 15:17:15 +0100970}
971
Calin Juravle77520bc2015-01-12 18:45:46 +0000972bool CodeGenerator::CanMoveNullCheckToUser(HNullCheck* null_check) {
973 HInstruction* first_next_not_move = null_check->GetNextDisregardingMoves();
Calin Juravle641547a2015-04-21 22:08:51 +0100974
975 return (first_next_not_move != nullptr)
976 && first_next_not_move->CanDoImplicitNullCheckOn(null_check->InputAt(0));
Calin Juravle77520bc2015-01-12 18:45:46 +0000977}
978
979void CodeGenerator::MaybeRecordImplicitNullCheck(HInstruction* instr) {
980 // If we are from a static path don't record the pc as we can't throw NPE.
981 // NB: having the checks here makes the code much less verbose in the arch
982 // specific code generators.
983 if (instr->IsStaticFieldSet() || instr->IsStaticFieldGet()) {
984 return;
985 }
986
987 if (!compiler_options_.GetImplicitNullChecks()) {
988 return;
989 }
990
Calin Juravle641547a2015-04-21 22:08:51 +0100991 if (!instr->CanDoImplicitNullCheckOn(instr->InputAt(0))) {
Calin Juravle77520bc2015-01-12 18:45:46 +0000992 return;
993 }
994
995 // Find the first previous instruction which is not a move.
996 HInstruction* first_prev_not_move = instr->GetPreviousDisregardingMoves();
997
998 // If the instruction is a null check it means that `instr` is the first user
999 // and needs to record the pc.
1000 if (first_prev_not_move != nullptr && first_prev_not_move->IsNullCheck()) {
1001 HNullCheck* null_check = first_prev_not_move->AsNullCheck();
1002 // TODO: The parallel moves modify the environment. Their changes need to be reverted
1003 // otherwise the stack maps at the throw point will not be correct.
1004 RecordPcInfo(null_check, null_check->GetDexPc());
1005 }
1006}
1007
Nicolas Geoffray3c049742014-09-24 18:10:46 +01001008void CodeGenerator::ClearSpillSlotsFromLoopPhisInStackMap(HSuspendCheck* suspend_check) const {
1009 LocationSummary* locations = suspend_check->GetLocations();
1010 HBasicBlock* block = suspend_check->GetBlock();
1011 DCHECK(block->GetLoopInformation()->GetSuspendCheck() == suspend_check);
1012 DCHECK(block->IsLoopHeader());
1013
1014 for (HInstructionIterator it(block->GetPhis()); !it.Done(); it.Advance()) {
1015 HInstruction* current = it.Current();
1016 LiveInterval* interval = current->GetLiveInterval();
1017 // We only need to clear bits of loop phis containing objects and allocated in register.
1018 // Loop phis allocated on stack already have the object in the stack.
1019 if (current->GetType() == Primitive::kPrimNot
1020 && interval->HasRegister()
1021 && interval->HasSpillSlot()) {
1022 locations->ClearStackBit(interval->GetSpillSlot() / kVRegSize);
1023 }
1024 }
1025}
1026
Nicolas Geoffray90218252015-04-15 11:56:51 +01001027void CodeGenerator::EmitParallelMoves(Location from1,
1028 Location to1,
1029 Primitive::Type type1,
1030 Location from2,
1031 Location to2,
1032 Primitive::Type type2) {
Nicolas Geoffrayf0e39372014-11-12 17:50:07 +00001033 HParallelMove parallel_move(GetGraph()->GetArena());
Nicolas Geoffray90218252015-04-15 11:56:51 +01001034 parallel_move.AddMove(from1, to1, type1, nullptr);
1035 parallel_move.AddMove(from2, to2, type2, nullptr);
Nicolas Geoffrayf0e39372014-11-12 17:50:07 +00001036 GetMoveResolver()->EmitNativeCode(&parallel_move);
1037}
1038
Alexandre Rames78e3ef62015-08-12 13:43:29 +01001039void CodeGenerator::ValidateInvokeRuntime(HInstruction* instruction, SlowPathCode* slow_path) {
1040 // Ensure that the call kind indication given to the register allocator is
1041 // coherent with the runtime call generated, and that the GC side effect is
1042 // set when required.
1043 if (slow_path == nullptr) {
Roland Levillaindf3f8222015-08-13 12:31:44 +01001044 DCHECK(instruction->GetLocations()->WillCall()) << instruction->DebugName();
1045 DCHECK(instruction->GetSideEffects().Includes(SideEffects::CanTriggerGC()))
1046 << instruction->DebugName() << instruction->GetSideEffects().ToString();
Alexandre Rames78e3ef62015-08-12 13:43:29 +01001047 } else {
Roland Levillaindf3f8222015-08-13 12:31:44 +01001048 DCHECK(instruction->GetLocations()->OnlyCallsOnSlowPath() || slow_path->IsFatal())
1049 << instruction->DebugName() << slow_path->GetDescription();
Alexandre Rames78e3ef62015-08-12 13:43:29 +01001050 DCHECK(instruction->GetSideEffects().Includes(SideEffects::CanTriggerGC()) ||
1051 // Control flow would not come back into the code if a fatal slow
1052 // path is taken, so we do not care if it triggers GC.
1053 slow_path->IsFatal() ||
1054 // HDeoptimize is a special case: we know we are not coming back from
1055 // it into the code.
Roland Levillaindf3f8222015-08-13 12:31:44 +01001056 instruction->IsDeoptimize())
1057 << instruction->DebugName() << instruction->GetSideEffects().ToString()
1058 << slow_path->GetDescription();
Alexandre Rames78e3ef62015-08-12 13:43:29 +01001059 }
1060
1061 // Check the coherency of leaf information.
1062 DCHECK(instruction->IsSuspendCheck()
1063 || ((slow_path != nullptr) && slow_path->IsFatal())
1064 || instruction->GetLocations()->CanCall()
Roland Levillaindf3f8222015-08-13 12:31:44 +01001065 || !IsLeafMethod())
1066 << instruction->DebugName() << ((slow_path != nullptr) ? slow_path->GetDescription() : "");
Alexandre Rames78e3ef62015-08-12 13:43:29 +01001067}
1068
Roland Levillaindf3f8222015-08-13 12:31:44 +01001069void SlowPathCode::RecordPcInfo(CodeGenerator* codegen,
1070 HInstruction* instruction,
1071 uint32_t dex_pc) {
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00001072 codegen->RecordPcInfo(instruction, dex_pc, this);
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +00001073}
1074
1075void SlowPathCode::SaveLiveRegisters(CodeGenerator* codegen, LocationSummary* locations) {
1076 RegisterSet* register_set = locations->GetLiveRegisters();
1077 size_t stack_offset = codegen->GetFirstRegisterSlotInSlowPath();
1078 for (size_t i = 0, e = codegen->GetNumberOfCoreRegisters(); i < e; ++i) {
1079 if (!codegen->IsCoreCalleeSaveRegister(i)) {
1080 if (register_set->ContainsCoreRegister(i)) {
1081 // If the register holds an object, update the stack mask.
1082 if (locations->RegisterContainsObject(i)) {
1083 locations->SetStackBit(stack_offset / kVRegSize);
1084 }
1085 DCHECK_LT(stack_offset, codegen->GetFrameSize() - codegen->FrameEntrySpillSize());
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00001086 DCHECK_LT(i, kMaximumNumberOfExpectedRegisters);
1087 saved_core_stack_offsets_[i] = stack_offset;
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +00001088 stack_offset += codegen->SaveCoreRegister(stack_offset, i);
1089 }
1090 }
1091 }
1092
1093 for (size_t i = 0, e = codegen->GetNumberOfFloatingPointRegisters(); i < e; ++i) {
1094 if (!codegen->IsFloatingPointCalleeSaveRegister(i)) {
1095 if (register_set->ContainsFloatingPointRegister(i)) {
1096 DCHECK_LT(stack_offset, codegen->GetFrameSize() - codegen->FrameEntrySpillSize());
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00001097 DCHECK_LT(i, kMaximumNumberOfExpectedRegisters);
1098 saved_fpu_stack_offsets_[i] = stack_offset;
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +00001099 stack_offset += codegen->SaveFloatingPointRegister(stack_offset, i);
1100 }
1101 }
1102 }
1103}
1104
1105void SlowPathCode::RestoreLiveRegisters(CodeGenerator* codegen, LocationSummary* locations) {
1106 RegisterSet* register_set = locations->GetLiveRegisters();
1107 size_t stack_offset = codegen->GetFirstRegisterSlotInSlowPath();
1108 for (size_t i = 0, e = codegen->GetNumberOfCoreRegisters(); i < e; ++i) {
1109 if (!codegen->IsCoreCalleeSaveRegister(i)) {
1110 if (register_set->ContainsCoreRegister(i)) {
1111 DCHECK_LT(stack_offset, codegen->GetFrameSize() - codegen->FrameEntrySpillSize());
1112 stack_offset += codegen->RestoreCoreRegister(stack_offset, i);
1113 }
1114 }
1115 }
1116
1117 for (size_t i = 0, e = codegen->GetNumberOfFloatingPointRegisters(); i < e; ++i) {
1118 if (!codegen->IsFloatingPointCalleeSaveRegister(i)) {
1119 if (register_set->ContainsFloatingPointRegister(i)) {
1120 DCHECK_LT(stack_offset, codegen->GetFrameSize() - codegen->FrameEntrySpillSize());
1121 stack_offset += codegen->RestoreFloatingPointRegister(stack_offset, i);
1122 }
1123 }
1124 }
1125}
1126
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +00001127} // namespace art