blob: 4a379c124daa2609fc000f098798a0c9561f01ae [file] [log] [blame]
Nicolas Geoffray9cf35522014-06-09 18:40:10 +01001/*
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_x86_64.h"
18
19#include "entrypoints/quick/quick_entrypoints.h"
Nicolas Geoffray1a43dd72014-07-17 15:15:34 +010020#include "gc/accounting/card_table.h"
Ian Rogers7e70b002014-10-08 11:47:24 -070021#include "mirror/array-inl.h"
Nicolas Geoffray9cf35522014-06-09 18:40:10 +010022#include "mirror/art_method.h"
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +010023#include "mirror/class.h"
Nicolas Geoffray9cf35522014-06-09 18:40:10 +010024#include "mirror/object_reference.h"
25#include "thread.h"
26#include "utils/assembler.h"
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +010027#include "utils/stack_checks.h"
Nicolas Geoffray9cf35522014-06-09 18:40:10 +010028#include "utils/x86_64/assembler_x86_64.h"
29#include "utils/x86_64/managed_register_x86_64.h"
30
Nicolas Geoffray9cf35522014-06-09 18:40:10 +010031namespace art {
32
Nicolas Geoffray9cf35522014-06-09 18:40:10 +010033namespace x86_64 {
34
Nicolas Geoffrayf6e206c2014-08-07 20:25:41 +010035static constexpr bool kExplicitStackOverflowCheck = false;
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +010036
37// Some x86_64 instructions require a register to be available as temp.
38static constexpr Register TMP = R11;
39
40static constexpr int kNumberOfPushedRegistersAtEntry = 1;
41static constexpr int kCurrentMethodStackOffset = 0;
42
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +010043static constexpr Register kRuntimeParameterCoreRegisters[] = { RDI, RSI, RDX };
44static constexpr size_t kRuntimeParameterCoreRegistersLength =
45 arraysize(kRuntimeParameterCoreRegisters);
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +010046static constexpr FloatRegister kRuntimeParameterFpuRegisters[] = { };
47static constexpr size_t kRuntimeParameterFpuRegistersLength = 0;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +010048
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +010049class InvokeRuntimeCallingConvention : public CallingConvention<Register, FloatRegister> {
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +010050 public:
51 InvokeRuntimeCallingConvention()
52 : CallingConvention(kRuntimeParameterCoreRegisters,
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +010053 kRuntimeParameterCoreRegistersLength,
54 kRuntimeParameterFpuRegisters,
55 kRuntimeParameterFpuRegistersLength) {}
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +010056
57 private:
58 DISALLOW_COPY_AND_ASSIGN(InvokeRuntimeCallingConvention);
59};
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +010060
Nicolas Geoffraye5038322014-07-04 09:41:32 +010061#define __ reinterpret_cast<X86_64Assembler*>(codegen->GetAssembler())->
62
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +010063class SlowPathCodeX86_64 : public SlowPathCode {
64 public:
65 SlowPathCodeX86_64() : entry_label_(), exit_label_() {}
66
67 Label* GetEntryLabel() { return &entry_label_; }
68 Label* GetExitLabel() { return &exit_label_; }
69
70 private:
71 Label entry_label_;
72 Label exit_label_;
73
74 DISALLOW_COPY_AND_ASSIGN(SlowPathCodeX86_64);
75};
76
77class NullCheckSlowPathX86_64 : public SlowPathCodeX86_64 {
Nicolas Geoffraye5038322014-07-04 09:41:32 +010078 public:
Nicolas Geoffray39468442014-09-02 15:17:15 +010079 explicit NullCheckSlowPathX86_64(HNullCheck* instruction) : instruction_(instruction) {}
Nicolas Geoffraye5038322014-07-04 09:41:32 +010080
81 virtual void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
82 __ Bind(GetEntryLabel());
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +010083 __ gs()->call(
84 Address::Absolute(QUICK_ENTRYPOINT_OFFSET(kX86_64WordSize, pThrowNullPointer), true));
Nicolas Geoffray39468442014-09-02 15:17:15 +010085 codegen->RecordPcInfo(instruction_, instruction_->GetDexPc());
Nicolas Geoffraye5038322014-07-04 09:41:32 +010086 }
87
88 private:
Nicolas Geoffray39468442014-09-02 15:17:15 +010089 HNullCheck* const instruction_;
Nicolas Geoffraye5038322014-07-04 09:41:32 +010090 DISALLOW_COPY_AND_ASSIGN(NullCheckSlowPathX86_64);
91};
92
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +010093class StackOverflowCheckSlowPathX86_64 : public SlowPathCodeX86_64 {
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +010094 public:
95 StackOverflowCheckSlowPathX86_64() {}
96
97 virtual void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
98 __ Bind(GetEntryLabel());
99 __ addq(CpuRegister(RSP),
100 Immediate(codegen->GetFrameSize() - kNumberOfPushedRegistersAtEntry * kX86_64WordSize));
101 __ gs()->jmp(
102 Address::Absolute(QUICK_ENTRYPOINT_OFFSET(kX86_64WordSize, pThrowStackOverflow), true));
103 }
104
105 private:
106 DISALLOW_COPY_AND_ASSIGN(StackOverflowCheckSlowPathX86_64);
107};
108
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100109class SuspendCheckSlowPathX86_64 : public SlowPathCodeX86_64 {
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000110 public:
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100111 explicit SuspendCheckSlowPathX86_64(HSuspendCheck* instruction, HBasicBlock* successor)
112 : instruction_(instruction), successor_(successor) {}
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000113
114 virtual void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100115 CodeGeneratorX86_64* x64_codegen = down_cast<CodeGeneratorX86_64*>(codegen);
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000116 __ Bind(GetEntryLabel());
Nicolas Geoffray3bca0df2014-09-19 11:01:00 +0100117 codegen->SaveLiveRegisters(instruction_->GetLocations());
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000118 __ gs()->call(Address::Absolute(QUICK_ENTRYPOINT_OFFSET(kX86_64WordSize, pTestSuspend), true));
119 codegen->RecordPcInfo(instruction_, instruction_->GetDexPc());
Nicolas Geoffray3bca0df2014-09-19 11:01:00 +0100120 codegen->RestoreLiveRegisters(instruction_->GetLocations());
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100121 if (successor_ == nullptr) {
122 __ jmp(GetReturnLabel());
123 } else {
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100124 __ jmp(x64_codegen->GetLabelOf(successor_));
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100125 }
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000126 }
127
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100128 Label* GetReturnLabel() {
129 DCHECK(successor_ == nullptr);
130 return &return_label_;
131 }
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000132
133 private:
134 HSuspendCheck* const instruction_;
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100135 HBasicBlock* const successor_;
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000136 Label return_label_;
137
138 DISALLOW_COPY_AND_ASSIGN(SuspendCheckSlowPathX86_64);
139};
140
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100141class BoundsCheckSlowPathX86_64 : public SlowPathCodeX86_64 {
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100142 public:
Roland Levillain5799fc02014-09-25 12:15:20 +0100143 BoundsCheckSlowPathX86_64(HBoundsCheck* instruction,
144 Location index_location,
145 Location length_location)
Nicolas Geoffray39468442014-09-02 15:17:15 +0100146 : instruction_(instruction),
147 index_location_(index_location),
148 length_location_(length_location) {}
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100149
150 virtual void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100151 CodeGeneratorX86_64* x64_codegen = down_cast<CodeGeneratorX86_64*>(codegen);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100152 __ Bind(GetEntryLabel());
153 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100154 x64_codegen->Move(Location::RegisterLocation(calling_convention.GetRegisterAt(0)), index_location_);
155 x64_codegen->Move(Location::RegisterLocation(calling_convention.GetRegisterAt(1)), length_location_);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100156 __ gs()->call(Address::Absolute(
157 QUICK_ENTRYPOINT_OFFSET(kX86_64WordSize, pThrowArrayBounds), true));
Nicolas Geoffray39468442014-09-02 15:17:15 +0100158 codegen->RecordPcInfo(instruction_, instruction_->GetDexPc());
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100159 }
160
161 private:
Nicolas Geoffray39468442014-09-02 15:17:15 +0100162 HBoundsCheck* const instruction_;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100163 const Location index_location_;
164 const Location length_location_;
165
166 DISALLOW_COPY_AND_ASSIGN(BoundsCheckSlowPathX86_64);
167};
168
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100169#undef __
170#define __ reinterpret_cast<X86_64Assembler*>(GetAssembler())->
171
Dave Allison20dfc792014-06-16 20:44:29 -0700172inline Condition X86_64Condition(IfCondition cond) {
173 switch (cond) {
174 case kCondEQ: return kEqual;
175 case kCondNE: return kNotEqual;
176 case kCondLT: return kLess;
177 case kCondLE: return kLessEqual;
178 case kCondGT: return kGreater;
179 case kCondGE: return kGreaterEqual;
180 default:
181 LOG(FATAL) << "Unknown if condition";
182 }
183 return kEqual;
184}
185
Nicolas Geoffray9cf35522014-06-09 18:40:10 +0100186void CodeGeneratorX86_64::DumpCoreRegister(std::ostream& stream, int reg) const {
187 stream << X86_64ManagedRegister::FromCpuRegister(Register(reg));
188}
189
190void CodeGeneratorX86_64::DumpFloatingPointRegister(std::ostream& stream, int reg) const {
191 stream << X86_64ManagedRegister::FromXmmRegister(FloatRegister(reg));
192}
193
Nicolas Geoffray3bca0df2014-09-19 11:01:00 +0100194void CodeGeneratorX86_64::SaveCoreRegister(Location stack_location, uint32_t reg_id) {
195 __ movq(Address(CpuRegister(RSP), stack_location.GetStackIndex()), CpuRegister(reg_id));
196}
197
198void CodeGeneratorX86_64::RestoreCoreRegister(Location stack_location, uint32_t reg_id) {
199 __ movq(CpuRegister(reg_id), Address(CpuRegister(RSP), stack_location.GetStackIndex()));
200}
201
Nicolas Geoffray9cf35522014-06-09 18:40:10 +0100202CodeGeneratorX86_64::CodeGeneratorX86_64(HGraph* graph)
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100203 : CodeGenerator(graph, kNumberOfCpuRegisters, kNumberOfFloatRegisters, 0),
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100204 block_labels_(graph->GetArena(), 0),
Nicolas Geoffray9cf35522014-06-09 18:40:10 +0100205 location_builder_(graph, this),
Nicolas Geoffrayecb2f9b2014-06-13 08:59:59 +0000206 instruction_visitor_(graph, this),
207 move_resolver_(graph->GetArena(), this) {}
Nicolas Geoffray9cf35522014-06-09 18:40:10 +0100208
Nicolas Geoffrayab032bc2014-07-15 12:55:21 +0100209size_t CodeGeneratorX86_64::FrameEntrySpillSize() const {
210 return kNumberOfPushedRegistersAtEntry * kX86_64WordSize;
211}
212
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100213InstructionCodeGeneratorX86_64::InstructionCodeGeneratorX86_64(HGraph* graph,
214 CodeGeneratorX86_64* codegen)
Nicolas Geoffray9cf35522014-06-09 18:40:10 +0100215 : HGraphVisitor(graph),
216 assembler_(codegen->GetAssembler()),
217 codegen_(codegen) {}
218
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100219Location CodeGeneratorX86_64::AllocateFreeRegister(Primitive::Type type) const {
Nicolas Geoffray9cf35522014-06-09 18:40:10 +0100220 switch (type) {
221 case Primitive::kPrimLong:
222 case Primitive::kPrimByte:
223 case Primitive::kPrimBoolean:
224 case Primitive::kPrimChar:
225 case Primitive::kPrimShort:
226 case Primitive::kPrimInt:
227 case Primitive::kPrimNot: {
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100228 size_t reg = FindFreeEntry(blocked_core_registers_, kNumberOfCpuRegisters);
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100229 return Location::RegisterLocation(reg);
Nicolas Geoffray9cf35522014-06-09 18:40:10 +0100230 }
231
232 case Primitive::kPrimFloat:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100233 case Primitive::kPrimDouble: {
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100234 size_t reg = FindFreeEntry(blocked_fpu_registers_, kNumberOfFloatRegisters);
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100235 return Location::FpuRegisterLocation(reg);
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100236 }
Nicolas Geoffray9cf35522014-06-09 18:40:10 +0100237
238 case Primitive::kPrimVoid:
239 LOG(FATAL) << "Unreachable type " << type;
240 }
241
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100242 return Location();
Nicolas Geoffray9cf35522014-06-09 18:40:10 +0100243}
244
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100245void CodeGeneratorX86_64::SetupBlockedRegisters() const {
Nicolas Geoffray9cf35522014-06-09 18:40:10 +0100246 // Stack register is always reserved.
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100247 blocked_core_registers_[RSP] = true;
Nicolas Geoffray9cf35522014-06-09 18:40:10 +0100248
Nicolas Geoffrayecb2f9b2014-06-13 08:59:59 +0000249 // Block the register used as TMP.
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100250 blocked_core_registers_[TMP] = true;
Nicolas Geoffrayecb2f9b2014-06-13 08:59:59 +0000251
Nicolas Geoffray9cf35522014-06-09 18:40:10 +0100252 // TODO: We currently don't use Quick's callee saved registers.
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100253 blocked_core_registers_[RBX] = true;
254 blocked_core_registers_[RBP] = true;
255 blocked_core_registers_[R12] = true;
256 blocked_core_registers_[R13] = true;
257 blocked_core_registers_[R14] = true;
258 blocked_core_registers_[R15] = true;
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100259
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100260 blocked_fpu_registers_[XMM12] = true;
261 blocked_fpu_registers_[XMM13] = true;
262 blocked_fpu_registers_[XMM14] = true;
263 blocked_fpu_registers_[XMM15] = true;
Nicolas Geoffray9cf35522014-06-09 18:40:10 +0100264}
265
Nicolas Geoffray9cf35522014-06-09 18:40:10 +0100266void CodeGeneratorX86_64::GenerateFrameEntry() {
267 // Create a fake register to mimic Quick.
268 static const int kFakeReturnRegister = 16;
269 core_spill_mask_ |= (1 << kFakeReturnRegister);
270
Nicolas Geoffrayf6e206c2014-08-07 20:25:41 +0100271 bool skip_overflow_check = IsLeafMethod()
Dave Allison648d7112014-07-25 16:15:27 -0700272 && !FrameNeedsStackCheck(GetFrameSize(), InstructionSet::kX86_64);
Nicolas Geoffrayf6e206c2014-08-07 20:25:41 +0100273
274 if (!skip_overflow_check && !kExplicitStackOverflowCheck) {
275 __ testq(CpuRegister(RAX), Address(
276 CpuRegister(RSP), -static_cast<int32_t>(GetStackOverflowReservedBytes(kX86_64))));
Nicolas Geoffray39468442014-09-02 15:17:15 +0100277 RecordPcInfo(nullptr, 0);
Nicolas Geoffrayf6e206c2014-08-07 20:25:41 +0100278 }
279
Nicolas Geoffray9cf35522014-06-09 18:40:10 +0100280 // The return PC has already been pushed on the stack.
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +0100281 __ subq(CpuRegister(RSP),
282 Immediate(GetFrameSize() - kNumberOfPushedRegistersAtEntry * kX86_64WordSize));
283
Nicolas Geoffrayf6e206c2014-08-07 20:25:41 +0100284 if (!skip_overflow_check && kExplicitStackOverflowCheck) {
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100285 SlowPathCodeX86_64* slow_path = new (GetGraph()->GetArena()) StackOverflowCheckSlowPathX86_64();
Nicolas Geoffrayf6e206c2014-08-07 20:25:41 +0100286 AddSlowPath(slow_path);
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +0100287
Nicolas Geoffrayf6e206c2014-08-07 20:25:41 +0100288 __ gs()->cmpq(CpuRegister(RSP),
289 Address::Absolute(Thread::StackEndOffset<kX86_64WordSize>(), true));
290 __ j(kLess, slow_path->GetEntryLabel());
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +0100291 }
292
Nicolas Geoffray9cf35522014-06-09 18:40:10 +0100293 __ movl(Address(CpuRegister(RSP), kCurrentMethodStackOffset), CpuRegister(RDI));
294}
295
296void CodeGeneratorX86_64::GenerateFrameExit() {
297 __ addq(CpuRegister(RSP),
298 Immediate(GetFrameSize() - kNumberOfPushedRegistersAtEntry * kX86_64WordSize));
299}
300
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100301void CodeGeneratorX86_64::Bind(HBasicBlock* block) {
302 __ Bind(GetLabelOf(block));
Nicolas Geoffray9cf35522014-06-09 18:40:10 +0100303}
304
305void InstructionCodeGeneratorX86_64::LoadCurrentMethod(CpuRegister reg) {
306 __ movl(reg, Address(CpuRegister(RSP), kCurrentMethodStackOffset));
307}
308
Nicolas Geoffray9cf35522014-06-09 18:40:10 +0100309Location CodeGeneratorX86_64::GetStackLocation(HLoadLocal* load) const {
310 switch (load->GetType()) {
311 case Primitive::kPrimLong:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100312 case Primitive::kPrimDouble:
Nicolas Geoffray9cf35522014-06-09 18:40:10 +0100313 return Location::DoubleStackSlot(GetStackSlot(load->GetLocal()));
314 break;
315
316 case Primitive::kPrimInt:
317 case Primitive::kPrimNot:
Nicolas Geoffray9cf35522014-06-09 18:40:10 +0100318 case Primitive::kPrimFloat:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100319 return Location::StackSlot(GetStackSlot(load->GetLocal()));
Nicolas Geoffray9cf35522014-06-09 18:40:10 +0100320
321 case Primitive::kPrimBoolean:
322 case Primitive::kPrimByte:
323 case Primitive::kPrimChar:
324 case Primitive::kPrimShort:
325 case Primitive::kPrimVoid:
326 LOG(FATAL) << "Unexpected type " << load->GetType();
327 }
328
329 LOG(FATAL) << "Unreachable";
330 return Location();
331}
332
333void CodeGeneratorX86_64::Move(Location destination, Location source) {
334 if (source.Equals(destination)) {
335 return;
336 }
337 if (destination.IsRegister()) {
338 if (source.IsRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100339 __ movq(destination.As<CpuRegister>(), source.As<CpuRegister>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100340 } else if (source.IsFpuRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100341 __ movd(destination.As<CpuRegister>(), source.As<XmmRegister>());
Nicolas Geoffray9cf35522014-06-09 18:40:10 +0100342 } else if (source.IsStackSlot()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100343 __ movl(destination.As<CpuRegister>(),
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100344 Address(CpuRegister(RSP), source.GetStackIndex()));
Nicolas Geoffray9cf35522014-06-09 18:40:10 +0100345 } else {
346 DCHECK(source.IsDoubleStackSlot());
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100347 __ movq(destination.As<CpuRegister>(),
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100348 Address(CpuRegister(RSP), source.GetStackIndex()));
349 }
350 } else if (destination.IsFpuRegister()) {
351 if (source.IsRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100352 __ movd(destination.As<XmmRegister>(), source.As<CpuRegister>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100353 } else if (source.IsFpuRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100354 __ movaps(destination.As<XmmRegister>(), source.As<XmmRegister>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100355 } else if (source.IsStackSlot()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100356 __ movss(destination.As<XmmRegister>(),
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100357 Address(CpuRegister(RSP), source.GetStackIndex()));
358 } else {
359 DCHECK(source.IsDoubleStackSlot());
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100360 __ movsd(destination.As<XmmRegister>(),
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100361 Address(CpuRegister(RSP), source.GetStackIndex()));
Nicolas Geoffray9cf35522014-06-09 18:40:10 +0100362 }
363 } else if (destination.IsStackSlot()) {
364 if (source.IsRegister()) {
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100365 __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()),
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100366 source.As<CpuRegister>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100367 } else if (source.IsFpuRegister()) {
368 __ movss(Address(CpuRegister(RSP), destination.GetStackIndex()),
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100369 source.As<XmmRegister>());
Nicolas Geoffray9cf35522014-06-09 18:40:10 +0100370 } else {
371 DCHECK(source.IsStackSlot());
Nicolas Geoffrayecb2f9b2014-06-13 08:59:59 +0000372 __ movl(CpuRegister(TMP), Address(CpuRegister(RSP), source.GetStackIndex()));
373 __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), CpuRegister(TMP));
Nicolas Geoffray9cf35522014-06-09 18:40:10 +0100374 }
375 } else {
376 DCHECK(destination.IsDoubleStackSlot());
377 if (source.IsRegister()) {
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100378 __ movq(Address(CpuRegister(RSP), destination.GetStackIndex()),
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100379 source.As<CpuRegister>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100380 } else if (source.IsFpuRegister()) {
381 __ movsd(Address(CpuRegister(RSP), destination.GetStackIndex()),
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100382 source.As<XmmRegister>());
Nicolas Geoffray9cf35522014-06-09 18:40:10 +0100383 } else {
384 DCHECK(source.IsDoubleStackSlot());
Nicolas Geoffrayecb2f9b2014-06-13 08:59:59 +0000385 __ movq(CpuRegister(TMP), Address(CpuRegister(RSP), source.GetStackIndex()));
386 __ movq(Address(CpuRegister(RSP), destination.GetStackIndex()), CpuRegister(TMP));
Nicolas Geoffray9cf35522014-06-09 18:40:10 +0100387 }
388 }
389}
390
Nicolas Geoffray412f10c2014-06-19 10:00:34 +0100391void CodeGeneratorX86_64::Move(HInstruction* instruction,
392 Location location,
393 HInstruction* move_for) {
Roland Levillain476df552014-10-09 17:51:36 +0100394 if (instruction->IsIntConstant()) {
Nicolas Geoffray9cf35522014-06-09 18:40:10 +0100395 Immediate imm(instruction->AsIntConstant()->GetValue());
396 if (location.IsRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100397 __ movl(location.As<CpuRegister>(), imm);
Nicolas Geoffray9cf35522014-06-09 18:40:10 +0100398 } else {
399 __ movl(Address(CpuRegister(RSP), location.GetStackIndex()), imm);
400 }
Roland Levillain476df552014-10-09 17:51:36 +0100401 } else if (instruction->IsLongConstant()) {
Nicolas Geoffray9cf35522014-06-09 18:40:10 +0100402 int64_t value = instruction->AsLongConstant()->GetValue();
403 if (location.IsRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100404 __ movq(location.As<CpuRegister>(), Immediate(value));
Nicolas Geoffray9cf35522014-06-09 18:40:10 +0100405 } else {
Nicolas Geoffrayecb2f9b2014-06-13 08:59:59 +0000406 __ movq(CpuRegister(TMP), Immediate(value));
407 __ movq(Address(CpuRegister(RSP), location.GetStackIndex()), CpuRegister(TMP));
Nicolas Geoffray9cf35522014-06-09 18:40:10 +0100408 }
Roland Levillain476df552014-10-09 17:51:36 +0100409 } else if (instruction->IsLoadLocal()) {
Nicolas Geoffray9cf35522014-06-09 18:40:10 +0100410 switch (instruction->GetType()) {
411 case Primitive::kPrimBoolean:
412 case Primitive::kPrimByte:
413 case Primitive::kPrimChar:
414 case Primitive::kPrimShort:
415 case Primitive::kPrimInt:
416 case Primitive::kPrimNot:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100417 case Primitive::kPrimFloat:
Nicolas Geoffray9cf35522014-06-09 18:40:10 +0100418 Move(location, Location::StackSlot(GetStackSlot(instruction->AsLoadLocal()->GetLocal())));
419 break;
420
421 case Primitive::kPrimLong:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100422 case Primitive::kPrimDouble:
Nicolas Geoffray9cf35522014-06-09 18:40:10 +0100423 Move(location, Location::DoubleStackSlot(GetStackSlot(instruction->AsLoadLocal()->GetLocal())));
424 break;
425
426 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100427 LOG(FATAL) << "Unexpected local type " << instruction->GetType();
Nicolas Geoffray9cf35522014-06-09 18:40:10 +0100428 }
429 } else {
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100430 DCHECK((instruction->GetNext() == move_for) || instruction->GetNext()->IsTemporary());
Nicolas Geoffray9cf35522014-06-09 18:40:10 +0100431 switch (instruction->GetType()) {
432 case Primitive::kPrimBoolean:
433 case Primitive::kPrimByte:
434 case Primitive::kPrimChar:
435 case Primitive::kPrimShort:
436 case Primitive::kPrimInt:
437 case Primitive::kPrimNot:
438 case Primitive::kPrimLong:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100439 case Primitive::kPrimFloat:
440 case Primitive::kPrimDouble:
Nicolas Geoffray9cf35522014-06-09 18:40:10 +0100441 Move(location, instruction->GetLocations()->Out());
442 break;
443
444 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100445 LOG(FATAL) << "Unexpected type " << instruction->GetType();
Nicolas Geoffray9cf35522014-06-09 18:40:10 +0100446 }
447 }
448}
449
450void LocationsBuilderX86_64::VisitGoto(HGoto* got) {
451 got->SetLocations(nullptr);
452}
453
454void InstructionCodeGeneratorX86_64::VisitGoto(HGoto* got) {
455 HBasicBlock* successor = got->GetSuccessor();
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100456 DCHECK(!successor->IsExitBlock());
457
458 HBasicBlock* block = got->GetBlock();
459 HInstruction* previous = got->GetPrevious();
460
461 HLoopInformation* info = block->GetLoopInformation();
462 if (info != nullptr && info->IsBackEdge(block) && info->HasSuspendCheck()) {
463 codegen_->ClearSpillSlotsFromLoopPhisInStackMap(info->GetSuspendCheck());
464 GenerateSuspendCheck(info->GetSuspendCheck(), successor);
465 return;
466 }
467
468 if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) {
469 GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr);
470 }
471 if (!codegen_->GoesToNextBlock(got->GetBlock(), successor)) {
Nicolas Geoffray9cf35522014-06-09 18:40:10 +0100472 __ jmp(codegen_->GetLabelOf(successor));
473 }
474}
475
476void LocationsBuilderX86_64::VisitExit(HExit* exit) {
477 exit->SetLocations(nullptr);
478}
479
480void InstructionCodeGeneratorX86_64::VisitExit(HExit* exit) {
481 if (kIsDebugBuild) {
482 __ Comment("Unreachable");
483 __ int3();
484 }
485}
486
487void LocationsBuilderX86_64::VisitIf(HIf* if_instr) {
Nicolas Geoffray39468442014-09-02 15:17:15 +0100488 LocationSummary* locations =
489 new (GetGraph()->GetArena()) LocationSummary(if_instr, LocationSummary::kNoCall);
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100490 HInstruction* cond = if_instr->InputAt(0);
Nicolas Geoffray01ef3452014-10-01 11:32:17 +0100491 if (!cond->IsCondition() || cond->AsCondition()->NeedsMaterialization()) {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +0100492 locations->SetInAt(0, Location::Any());
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100493 }
Nicolas Geoffray9cf35522014-06-09 18:40:10 +0100494}
495
496void InstructionCodeGeneratorX86_64::VisitIf(HIf* if_instr) {
Dave Allison20dfc792014-06-16 20:44:29 -0700497 HInstruction* cond = if_instr->InputAt(0);
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100498 if (cond->IsIntConstant()) {
499 // Constant condition, statically compared against 1.
500 int32_t cond_value = cond->AsIntConstant()->GetValue();
501 if (cond_value == 1) {
502 if (!codegen_->GoesToNextBlock(if_instr->GetBlock(),
503 if_instr->IfTrueSuccessor())) {
504 __ jmp(codegen_->GetLabelOf(if_instr->IfTrueSuccessor()));
Nicolas Geoffray18efde52014-09-22 15:51:11 +0100505 }
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100506 return;
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100507 } else {
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100508 DCHECK_EQ(cond_value, 0);
509 }
510 } else {
511 bool materialized =
512 !cond->IsCondition() || cond->AsCondition()->NeedsMaterialization();
513 // Moves do not affect the eflags register, so if the condition is
514 // evaluated just before the if, we don't need to evaluate it
515 // again.
516 bool eflags_set = cond->IsCondition()
517 && cond->AsCondition()->IsBeforeWhenDisregardMoves(if_instr);
518 if (materialized) {
519 if (!eflags_set) {
520 // Materialized condition, compare against 0.
521 Location lhs = if_instr->GetLocations()->InAt(0);
522 if (lhs.IsRegister()) {
523 __ cmpl(lhs.As<CpuRegister>(), Immediate(0));
524 } else {
525 __ cmpl(Address(CpuRegister(RSP), lhs.GetStackIndex()),
526 Immediate(0));
527 }
528 __ j(kNotEqual, codegen_->GetLabelOf(if_instr->IfTrueSuccessor()));
529 } else {
530 __ j(X86_64Condition(cond->AsCondition()->GetCondition()),
531 codegen_->GetLabelOf(if_instr->IfTrueSuccessor()));
532 }
533 } else {
534 Location lhs = cond->GetLocations()->InAt(0);
535 Location rhs = cond->GetLocations()->InAt(1);
536 if (rhs.IsRegister()) {
537 __ cmpl(lhs.As<CpuRegister>(), rhs.As<CpuRegister>());
538 } else if (rhs.IsConstant()) {
539 __ cmpl(lhs.As<CpuRegister>(),
540 Immediate(rhs.GetConstant()->AsIntConstant()->GetValue()));
541 } else {
542 __ cmpl(lhs.As<CpuRegister>(),
543 Address(CpuRegister(RSP), rhs.GetStackIndex()));
544 }
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100545 __ j(X86_64Condition(cond->AsCondition()->GetCondition()),
546 codegen_->GetLabelOf(if_instr->IfTrueSuccessor()));
Dave Allison20dfc792014-06-16 20:44:29 -0700547 }
Dave Allison20dfc792014-06-16 20:44:29 -0700548 }
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100549 if (!codegen_->GoesToNextBlock(if_instr->GetBlock(),
550 if_instr->IfFalseSuccessor())) {
Dave Allison20dfc792014-06-16 20:44:29 -0700551 __ jmp(codegen_->GetLabelOf(if_instr->IfFalseSuccessor()));
Nicolas Geoffray9cf35522014-06-09 18:40:10 +0100552 }
553}
554
555void LocationsBuilderX86_64::VisitLocal(HLocal* local) {
556 local->SetLocations(nullptr);
557}
558
559void InstructionCodeGeneratorX86_64::VisitLocal(HLocal* local) {
560 DCHECK_EQ(local->GetBlock(), GetGraph()->GetEntryBlock());
561}
562
563void LocationsBuilderX86_64::VisitLoadLocal(HLoadLocal* local) {
564 local->SetLocations(nullptr);
565}
566
567void InstructionCodeGeneratorX86_64::VisitLoadLocal(HLoadLocal* load) {
568 // Nothing to do, this is driven by the code generator.
569}
570
571void LocationsBuilderX86_64::VisitStoreLocal(HStoreLocal* store) {
Nicolas Geoffray39468442014-09-02 15:17:15 +0100572 LocationSummary* locations =
573 new (GetGraph()->GetArena()) LocationSummary(store, LocationSummary::kNoCall);
Nicolas Geoffray9cf35522014-06-09 18:40:10 +0100574 switch (store->InputAt(1)->GetType()) {
575 case Primitive::kPrimBoolean:
576 case Primitive::kPrimByte:
577 case Primitive::kPrimChar:
578 case Primitive::kPrimShort:
579 case Primitive::kPrimInt:
580 case Primitive::kPrimNot:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100581 case Primitive::kPrimFloat:
Nicolas Geoffray9cf35522014-06-09 18:40:10 +0100582 locations->SetInAt(1, Location::StackSlot(codegen_->GetStackSlot(store->GetLocal())));
583 break;
584
585 case Primitive::kPrimLong:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100586 case Primitive::kPrimDouble:
Nicolas Geoffray9cf35522014-06-09 18:40:10 +0100587 locations->SetInAt(1, Location::DoubleStackSlot(codegen_->GetStackSlot(store->GetLocal())));
588 break;
589
590 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100591 LOG(FATAL) << "Unexpected local type " << store->InputAt(1)->GetType();
Nicolas Geoffray9cf35522014-06-09 18:40:10 +0100592 }
Nicolas Geoffray9cf35522014-06-09 18:40:10 +0100593}
594
595void InstructionCodeGeneratorX86_64::VisitStoreLocal(HStoreLocal* store) {
596}
597
Dave Allison20dfc792014-06-16 20:44:29 -0700598void LocationsBuilderX86_64::VisitCondition(HCondition* comp) {
Nicolas Geoffray39468442014-09-02 15:17:15 +0100599 LocationSummary* locations =
600 new (GetGraph()->GetArena()) LocationSummary(comp, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +0100601 locations->SetInAt(0, Location::RequiresRegister());
602 locations->SetInAt(1, Location::Any());
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100603 if (comp->NeedsMaterialization()) {
604 locations->SetOut(Location::RequiresRegister());
605 }
Nicolas Geoffray9cf35522014-06-09 18:40:10 +0100606}
607
Dave Allison20dfc792014-06-16 20:44:29 -0700608void InstructionCodeGeneratorX86_64::VisitCondition(HCondition* comp) {
609 if (comp->NeedsMaterialization()) {
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100610 LocationSummary* locations = comp->GetLocations();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100611 CpuRegister reg = locations->Out().As<CpuRegister>();
Nicolas Geoffray18efde52014-09-22 15:51:11 +0100612 // Clear register: setcc only sets the low byte.
613 __ xorq(reg, reg);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100614 if (locations->InAt(1).IsRegister()) {
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100615 __ cmpl(locations->InAt(0).As<CpuRegister>(),
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100616 locations->InAt(1).As<CpuRegister>());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100617 } else if (locations->InAt(1).IsConstant()) {
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100618 __ cmpl(locations->InAt(0).As<CpuRegister>(),
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100619 Immediate(locations->InAt(1).GetConstant()->AsIntConstant()->GetValue()));
620 } else {
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100621 __ cmpl(locations->InAt(0).As<CpuRegister>(),
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100622 Address(CpuRegister(RSP), locations->InAt(1).GetStackIndex()));
623 }
Nicolas Geoffray18efde52014-09-22 15:51:11 +0100624 __ setcc(X86_64Condition(comp->GetCondition()), reg);
Dave Allison20dfc792014-06-16 20:44:29 -0700625 }
626}
627
628void LocationsBuilderX86_64::VisitEqual(HEqual* comp) {
629 VisitCondition(comp);
630}
631
632void InstructionCodeGeneratorX86_64::VisitEqual(HEqual* comp) {
633 VisitCondition(comp);
634}
635
636void LocationsBuilderX86_64::VisitNotEqual(HNotEqual* comp) {
637 VisitCondition(comp);
638}
639
640void InstructionCodeGeneratorX86_64::VisitNotEqual(HNotEqual* comp) {
641 VisitCondition(comp);
642}
643
644void LocationsBuilderX86_64::VisitLessThan(HLessThan* comp) {
645 VisitCondition(comp);
646}
647
648void InstructionCodeGeneratorX86_64::VisitLessThan(HLessThan* comp) {
649 VisitCondition(comp);
650}
651
652void LocationsBuilderX86_64::VisitLessThanOrEqual(HLessThanOrEqual* comp) {
653 VisitCondition(comp);
654}
655
656void InstructionCodeGeneratorX86_64::VisitLessThanOrEqual(HLessThanOrEqual* comp) {
657 VisitCondition(comp);
658}
659
660void LocationsBuilderX86_64::VisitGreaterThan(HGreaterThan* comp) {
661 VisitCondition(comp);
662}
663
664void InstructionCodeGeneratorX86_64::VisitGreaterThan(HGreaterThan* comp) {
665 VisitCondition(comp);
666}
667
668void LocationsBuilderX86_64::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) {
669 VisitCondition(comp);
670}
671
672void InstructionCodeGeneratorX86_64::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) {
673 VisitCondition(comp);
Nicolas Geoffray9cf35522014-06-09 18:40:10 +0100674}
675
Nicolas Geoffray412f10c2014-06-19 10:00:34 +0100676void LocationsBuilderX86_64::VisitCompare(HCompare* compare) {
Nicolas Geoffray39468442014-09-02 15:17:15 +0100677 LocationSummary* locations =
678 new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +0100679 locations->SetInAt(0, Location::RequiresRegister());
680 locations->SetInAt(1, Location::RequiresRegister());
681 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray412f10c2014-06-19 10:00:34 +0100682}
683
684void InstructionCodeGeneratorX86_64::VisitCompare(HCompare* compare) {
685 Label greater, done;
686 LocationSummary* locations = compare->GetLocations();
687 switch (compare->InputAt(0)->GetType()) {
688 case Primitive::kPrimLong:
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100689 __ cmpq(locations->InAt(0).As<CpuRegister>(),
690 locations->InAt(1).As<CpuRegister>());
Nicolas Geoffray412f10c2014-06-19 10:00:34 +0100691 break;
692 default:
693 LOG(FATAL) << "Unimplemented compare type " << compare->InputAt(0)->GetType();
694 }
695
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100696 CpuRegister output = locations->Out().As<CpuRegister>();
697 __ movl(output, Immediate(0));
Nicolas Geoffray412f10c2014-06-19 10:00:34 +0100698 __ j(kEqual, &done);
699 __ j(kGreater, &greater);
700
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100701 __ movl(output, Immediate(-1));
Nicolas Geoffray412f10c2014-06-19 10:00:34 +0100702 __ jmp(&done);
703
704 __ Bind(&greater);
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100705 __ movl(output, Immediate(1));
Nicolas Geoffray412f10c2014-06-19 10:00:34 +0100706
707 __ Bind(&done);
708}
709
Nicolas Geoffray9cf35522014-06-09 18:40:10 +0100710void LocationsBuilderX86_64::VisitIntConstant(HIntConstant* constant) {
Nicolas Geoffray39468442014-09-02 15:17:15 +0100711 LocationSummary* locations =
712 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100713 locations->SetOut(Location::ConstantLocation(constant));
Nicolas Geoffray9cf35522014-06-09 18:40:10 +0100714}
715
716void InstructionCodeGeneratorX86_64::VisitIntConstant(HIntConstant* constant) {
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100717 // Will be generated at use site.
Nicolas Geoffray9cf35522014-06-09 18:40:10 +0100718}
719
720void LocationsBuilderX86_64::VisitLongConstant(HLongConstant* constant) {
Nicolas Geoffray39468442014-09-02 15:17:15 +0100721 LocationSummary* locations =
722 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100723 locations->SetOut(Location::ConstantLocation(constant));
Nicolas Geoffray9cf35522014-06-09 18:40:10 +0100724}
725
726void InstructionCodeGeneratorX86_64::VisitLongConstant(HLongConstant* constant) {
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100727 // Will be generated at use site.
Nicolas Geoffray9cf35522014-06-09 18:40:10 +0100728}
729
730void LocationsBuilderX86_64::VisitReturnVoid(HReturnVoid* ret) {
731 ret->SetLocations(nullptr);
732}
733
734void InstructionCodeGeneratorX86_64::VisitReturnVoid(HReturnVoid* ret) {
735 codegen_->GenerateFrameExit();
736 __ ret();
737}
738
739void LocationsBuilderX86_64::VisitReturn(HReturn* ret) {
Nicolas Geoffray39468442014-09-02 15:17:15 +0100740 LocationSummary* locations =
741 new (GetGraph()->GetArena()) LocationSummary(ret, LocationSummary::kNoCall);
Nicolas Geoffray9cf35522014-06-09 18:40:10 +0100742 switch (ret->InputAt(0)->GetType()) {
743 case Primitive::kPrimBoolean:
744 case Primitive::kPrimByte:
745 case Primitive::kPrimChar:
746 case Primitive::kPrimShort:
747 case Primitive::kPrimInt:
748 case Primitive::kPrimNot:
749 case Primitive::kPrimLong:
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100750 locations->SetInAt(0, Location::RegisterLocation(RAX));
Nicolas Geoffray9cf35522014-06-09 18:40:10 +0100751 break;
752
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100753 case Primitive::kPrimFloat:
754 case Primitive::kPrimDouble:
755 locations->SetInAt(0,
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100756 Location::FpuRegisterLocation(XMM0));
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100757 break;
758
Nicolas Geoffray9cf35522014-06-09 18:40:10 +0100759 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100760 LOG(FATAL) << "Unexpected return type " << ret->InputAt(0)->GetType();
Nicolas Geoffray9cf35522014-06-09 18:40:10 +0100761 }
Nicolas Geoffray9cf35522014-06-09 18:40:10 +0100762}
763
764void InstructionCodeGeneratorX86_64::VisitReturn(HReturn* ret) {
765 if (kIsDebugBuild) {
766 switch (ret->InputAt(0)->GetType()) {
767 case Primitive::kPrimBoolean:
768 case Primitive::kPrimByte:
769 case Primitive::kPrimChar:
770 case Primitive::kPrimShort:
771 case Primitive::kPrimInt:
772 case Primitive::kPrimNot:
773 case Primitive::kPrimLong:
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100774 DCHECK_EQ(ret->GetLocations()->InAt(0).As<CpuRegister>().AsRegister(), RAX);
Nicolas Geoffray9cf35522014-06-09 18:40:10 +0100775 break;
776
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100777 case Primitive::kPrimFloat:
778 case Primitive::kPrimDouble:
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100779 DCHECK_EQ(ret->GetLocations()->InAt(0).As<XmmRegister>().AsFloatRegister(),
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100780 XMM0);
781 break;
782
Nicolas Geoffray9cf35522014-06-09 18:40:10 +0100783 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100784 LOG(FATAL) << "Unexpected return type " << ret->InputAt(0)->GetType();
Nicolas Geoffray9cf35522014-06-09 18:40:10 +0100785 }
786 }
787 codegen_->GenerateFrameExit();
788 __ ret();
789}
790
Nicolas Geoffray9cf35522014-06-09 18:40:10 +0100791Location InvokeDexCallingConventionVisitor::GetNextLocation(Primitive::Type type) {
792 switch (type) {
793 case Primitive::kPrimBoolean:
794 case Primitive::kPrimByte:
795 case Primitive::kPrimChar:
796 case Primitive::kPrimShort:
797 case Primitive::kPrimInt:
798 case Primitive::kPrimNot: {
799 uint32_t index = gp_index_++;
800 stack_index_++;
801 if (index < calling_convention.GetNumberOfRegisters()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100802 return Location::RegisterLocation(calling_convention.GetRegisterAt(index));
Nicolas Geoffray9cf35522014-06-09 18:40:10 +0100803 } else {
804 return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 1));
805 }
806 }
807
808 case Primitive::kPrimLong: {
809 uint32_t index = gp_index_;
810 stack_index_ += 2;
811 if (index < calling_convention.GetNumberOfRegisters()) {
812 gp_index_ += 1;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100813 return Location::RegisterLocation(calling_convention.GetRegisterAt(index));
Nicolas Geoffray9cf35522014-06-09 18:40:10 +0100814 } else {
815 gp_index_ += 2;
816 return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 2));
817 }
818 }
819
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100820 case Primitive::kPrimFloat: {
821 uint32_t index = fp_index_++;
822 stack_index_++;
823 if (index < calling_convention.GetNumberOfFpuRegisters()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100824 return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(index));
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100825 } else {
826 return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 1));
827 }
828 }
829
830 case Primitive::kPrimDouble: {
831 uint32_t index = fp_index_++;
832 stack_index_ += 2;
833 if (index < calling_convention.GetNumberOfFpuRegisters()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100834 return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(index));
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100835 } else {
836 return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 2));
837 }
838 }
Nicolas Geoffray9cf35522014-06-09 18:40:10 +0100839
840 case Primitive::kPrimVoid:
841 LOG(FATAL) << "Unexpected parameter type " << type;
842 break;
843 }
844 return Location();
845}
846
847void LocationsBuilderX86_64::VisitInvokeStatic(HInvokeStatic* invoke) {
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +0100848 HandleInvoke(invoke);
849}
850
851void InstructionCodeGeneratorX86_64::VisitInvokeStatic(HInvokeStatic* invoke) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100852 CpuRegister temp = invoke->GetLocations()->GetTemp(0).As<CpuRegister>();
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +0100853 uint32_t heap_reference_size = sizeof(mirror::HeapReference<mirror::Object>);
854 size_t index_in_cache = mirror::Array::DataOffset(heap_reference_size).SizeValue() +
855 invoke->GetIndexInDexCache() * heap_reference_size;
856
857 // TODO: Implement all kinds of calls:
858 // 1) boot -> boot
859 // 2) app -> boot
860 // 3) app -> app
861 //
862 // Currently we implement the app -> app logic, which looks up in the resolve cache.
863
864 // temp = method;
865 LoadCurrentMethod(temp);
866 // temp = temp->dex_cache_resolved_methods_;
867 __ movl(temp, Address(temp, mirror::ArtMethod::DexCacheResolvedMethodsOffset().SizeValue()));
868 // temp = temp[index_in_cache]
869 __ movl(temp, Address(temp, index_in_cache));
870 // (temp + offset_of_quick_compiled_code)()
871 __ call(Address(temp, mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset().SizeValue()));
872
873 DCHECK(!codegen_->IsLeafMethod());
874 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
875}
876
877void LocationsBuilderX86_64::VisitInvokeVirtual(HInvokeVirtual* invoke) {
878 HandleInvoke(invoke);
879}
880
881void LocationsBuilderX86_64::HandleInvoke(HInvoke* invoke) {
Nicolas Geoffray39468442014-09-02 15:17:15 +0100882 LocationSummary* locations =
883 new (GetGraph()->GetArena()) LocationSummary(invoke, LocationSummary::kCall);
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100884 locations->AddTemp(Location::RegisterLocation(RDI));
Nicolas Geoffray9cf35522014-06-09 18:40:10 +0100885
886 InvokeDexCallingConventionVisitor calling_convention_visitor;
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +0100887 for (size_t i = 0; i < invoke->InputCount(); i++) {
Nicolas Geoffray9cf35522014-06-09 18:40:10 +0100888 HInstruction* input = invoke->InputAt(i);
889 locations->SetInAt(i, calling_convention_visitor.GetNextLocation(input->GetType()));
890 }
891
892 switch (invoke->GetType()) {
893 case Primitive::kPrimBoolean:
894 case Primitive::kPrimByte:
895 case Primitive::kPrimChar:
896 case Primitive::kPrimShort:
897 case Primitive::kPrimInt:
898 case Primitive::kPrimNot:
899 case Primitive::kPrimLong:
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100900 locations->SetOut(Location::RegisterLocation(RAX));
Nicolas Geoffray9cf35522014-06-09 18:40:10 +0100901 break;
902
903 case Primitive::kPrimVoid:
904 break;
905
906 case Primitive::kPrimDouble:
907 case Primitive::kPrimFloat:
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100908 locations->SetOut(Location::FpuRegisterLocation(XMM0));
Nicolas Geoffray9cf35522014-06-09 18:40:10 +0100909 break;
910 }
Nicolas Geoffray9cf35522014-06-09 18:40:10 +0100911}
912
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +0100913void InstructionCodeGeneratorX86_64::VisitInvokeVirtual(HInvokeVirtual* invoke) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100914 CpuRegister temp = invoke->GetLocations()->GetTemp(0).As<CpuRegister>();
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +0100915 size_t method_offset = mirror::Class::EmbeddedVTableOffset().SizeValue() +
916 invoke->GetVTableIndex() * sizeof(mirror::Class::VTableEntry);
917 LocationSummary* locations = invoke->GetLocations();
918 Location receiver = locations->InAt(0);
919 size_t class_offset = mirror::Object::ClassOffset().SizeValue();
920 // temp = object->GetClass();
921 if (receiver.IsStackSlot()) {
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100922 __ movl(temp, Address(CpuRegister(RSP), receiver.GetStackIndex()));
923 __ movl(temp, Address(temp, class_offset));
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +0100924 } else {
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100925 __ movl(temp, Address(receiver.As<CpuRegister>(), class_offset));
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +0100926 }
927 // temp = temp->GetMethodAt(method_offset);
928 __ movl(temp, Address(temp, method_offset));
929 // call temp->GetEntryPoint();
Nicolas Geoffray9cf35522014-06-09 18:40:10 +0100930 __ call(Address(temp, mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset().SizeValue()));
931
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +0100932 DCHECK(!codegen_->IsLeafMethod());
Nicolas Geoffray39468442014-09-02 15:17:15 +0100933 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
Nicolas Geoffray9cf35522014-06-09 18:40:10 +0100934}
935
936void LocationsBuilderX86_64::VisitAdd(HAdd* add) {
Nicolas Geoffray39468442014-09-02 15:17:15 +0100937 LocationSummary* locations =
938 new (GetGraph()->GetArena()) LocationSummary(add, LocationSummary::kNoCall);
Nicolas Geoffray9cf35522014-06-09 18:40:10 +0100939 switch (add->GetResultType()) {
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100940 case Primitive::kPrimInt: {
941 locations->SetInAt(0, Location::RequiresRegister());
942 locations->SetInAt(1, Location::Any());
943 locations->SetOut(Location::SameAsFirstInput());
944 break;
945 }
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100946
Nicolas Geoffray9cf35522014-06-09 18:40:10 +0100947 case Primitive::kPrimLong: {
Nicolas Geoffrayecb2f9b2014-06-13 08:59:59 +0000948 locations->SetInAt(0, Location::RequiresRegister());
949 locations->SetInAt(1, Location::RequiresRegister());
950 locations->SetOut(Location::SameAsFirstInput());
Nicolas Geoffray9cf35522014-06-09 18:40:10 +0100951 break;
952 }
953
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100954 case Primitive::kPrimDouble:
955 case Primitive::kPrimFloat: {
956 locations->SetInAt(0, Location::RequiresFpuRegister());
957 locations->SetInAt(1, Location::Any());
958 locations->SetOut(Location::SameAsFirstInput());
Nicolas Geoffray9cf35522014-06-09 18:40:10 +0100959 break;
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100960 }
Nicolas Geoffray9cf35522014-06-09 18:40:10 +0100961
962 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100963 LOG(FATAL) << "Unexpected add type " << add->GetResultType();
Nicolas Geoffray9cf35522014-06-09 18:40:10 +0100964 }
Nicolas Geoffray9cf35522014-06-09 18:40:10 +0100965}
966
967void InstructionCodeGeneratorX86_64::VisitAdd(HAdd* add) {
968 LocationSummary* locations = add->GetLocations();
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100969 Location first = locations->InAt(0);
970 Location second = locations->InAt(1);
971
972 DCHECK(first.Equals(locations->Out()));
Nicolas Geoffray9cf35522014-06-09 18:40:10 +0100973 switch (add->GetResultType()) {
Nicolas Geoffrayecb2f9b2014-06-13 08:59:59 +0000974 case Primitive::kPrimInt: {
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100975 if (second.IsRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100976 __ addl(first.As<CpuRegister>(), second.As<CpuRegister>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100977 } else if (second.IsConstant()) {
978 HConstant* instruction = second.GetConstant();
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100979 Immediate imm(instruction->AsIntConstant()->GetValue());
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100980 __ addl(first.As<CpuRegister>(), imm);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100981 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100982 __ addl(first.As<CpuRegister>(),
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100983 Address(CpuRegister(RSP), second.GetStackIndex()));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100984 }
Nicolas Geoffrayecb2f9b2014-06-13 08:59:59 +0000985 break;
986 }
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100987
Nicolas Geoffray9cf35522014-06-09 18:40:10 +0100988 case Primitive::kPrimLong: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100989 __ addq(first.As<CpuRegister>(), second.As<CpuRegister>());
Nicolas Geoffray9cf35522014-06-09 18:40:10 +0100990 break;
991 }
992
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100993 case Primitive::kPrimFloat: {
994 if (second.IsFpuRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100995 __ addss(first.As<XmmRegister>(), second.As<XmmRegister>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100996 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100997 __ addss(first.As<XmmRegister>(),
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100998 Address(CpuRegister(RSP), second.GetStackIndex()));
999 }
Nicolas Geoffray9cf35522014-06-09 18:40:10 +01001000 break;
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001001 }
1002
1003 case Primitive::kPrimDouble: {
1004 if (second.IsFpuRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001005 __ addsd(first.As<XmmRegister>(), second.As<XmmRegister>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001006 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001007 __ addsd(first.As<XmmRegister>(), Address(CpuRegister(RSP), second.GetStackIndex()));
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001008 }
1009 break;
1010 }
Nicolas Geoffray9cf35522014-06-09 18:40:10 +01001011
1012 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001013 LOG(FATAL) << "Unexpected add type " << add->GetResultType();
Nicolas Geoffray9cf35522014-06-09 18:40:10 +01001014 }
1015}
1016
1017void LocationsBuilderX86_64::VisitSub(HSub* sub) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001018 LocationSummary* locations =
1019 new (GetGraph()->GetArena()) LocationSummary(sub, LocationSummary::kNoCall);
Nicolas Geoffray9cf35522014-06-09 18:40:10 +01001020 switch (sub->GetResultType()) {
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001021 case Primitive::kPrimInt: {
1022 locations->SetInAt(0, Location::RequiresRegister());
1023 locations->SetInAt(1, Location::Any());
1024 locations->SetOut(Location::SameAsFirstInput());
1025 break;
1026 }
Nicolas Geoffray9cf35522014-06-09 18:40:10 +01001027 case Primitive::kPrimLong: {
Nicolas Geoffrayecb2f9b2014-06-13 08:59:59 +00001028 locations->SetInAt(0, Location::RequiresRegister());
1029 locations->SetInAt(1, Location::RequiresRegister());
1030 locations->SetOut(Location::SameAsFirstInput());
Nicolas Geoffray9cf35522014-06-09 18:40:10 +01001031 break;
1032 }
1033
1034 case Primitive::kPrimBoolean:
1035 case Primitive::kPrimByte:
1036 case Primitive::kPrimChar:
1037 case Primitive::kPrimShort:
1038 LOG(FATAL) << "Unexpected sub type " << sub->GetResultType();
1039 break;
1040
1041 default:
1042 LOG(FATAL) << "Unimplemented sub type " << sub->GetResultType();
1043 }
Nicolas Geoffray9cf35522014-06-09 18:40:10 +01001044}
1045
1046void InstructionCodeGeneratorX86_64::VisitSub(HSub* sub) {
1047 LocationSummary* locations = sub->GetLocations();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001048 DCHECK_EQ(locations->InAt(0).As<CpuRegister>().AsRegister(),
1049 locations->Out().As<CpuRegister>().AsRegister());
Nicolas Geoffray9cf35522014-06-09 18:40:10 +01001050 switch (sub->GetResultType()) {
Nicolas Geoffrayecb2f9b2014-06-13 08:59:59 +00001051 case Primitive::kPrimInt: {
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001052 if (locations->InAt(1).IsRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001053 __ subl(locations->InAt(0).As<CpuRegister>(),
1054 locations->InAt(1).As<CpuRegister>());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001055 } else if (locations->InAt(1).IsConstant()) {
1056 HConstant* instruction = locations->InAt(1).GetConstant();
1057 Immediate imm(instruction->AsIntConstant()->GetValue());
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001058 __ subl(locations->InAt(0).As<CpuRegister>(), imm);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001059 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001060 __ subl(locations->InAt(0).As<CpuRegister>(),
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001061 Address(CpuRegister(RSP), locations->InAt(1).GetStackIndex()));
1062 }
Nicolas Geoffrayecb2f9b2014-06-13 08:59:59 +00001063 break;
1064 }
Nicolas Geoffray9cf35522014-06-09 18:40:10 +01001065 case Primitive::kPrimLong: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001066 __ subq(locations->InAt(0).As<CpuRegister>(),
1067 locations->InAt(1).As<CpuRegister>());
Nicolas Geoffray9cf35522014-06-09 18:40:10 +01001068 break;
1069 }
1070
1071 case Primitive::kPrimBoolean:
1072 case Primitive::kPrimByte:
1073 case Primitive::kPrimChar:
1074 case Primitive::kPrimShort:
1075 LOG(FATAL) << "Unexpected sub type " << sub->GetResultType();
1076 break;
1077
1078 default:
1079 LOG(FATAL) << "Unimplemented sub type " << sub->GetResultType();
1080 }
1081}
1082
Calin Juravle34bacdf2014-10-07 20:23:36 +01001083void LocationsBuilderX86_64::VisitMul(HMul* mul) {
1084 LocationSummary* locations =
1085 new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall);
1086 switch (mul->GetResultType()) {
1087 case Primitive::kPrimInt: {
1088 locations->SetInAt(0, Location::RequiresRegister());
1089 locations->SetInAt(1, Location::Any());
1090 locations->SetOut(Location::SameAsFirstInput());
1091 break;
1092 }
1093 case Primitive::kPrimLong: {
1094 locations->SetInAt(0, Location::RequiresRegister());
1095 locations->SetInAt(1, Location::RequiresRegister());
1096 locations->SetOut(Location::SameAsFirstInput());
1097 break;
1098 }
1099
1100 case Primitive::kPrimBoolean:
1101 case Primitive::kPrimByte:
1102 case Primitive::kPrimChar:
1103 case Primitive::kPrimShort:
1104 LOG(FATAL) << "Unexpected mul type " << mul->GetResultType();
1105 break;
1106
1107 default:
1108 LOG(FATAL) << "Unimplemented mul type " << mul->GetResultType();
1109 }
1110}
1111
1112void InstructionCodeGeneratorX86_64::VisitMul(HMul* mul) {
1113 LocationSummary* locations = mul->GetLocations();
1114 Location first = locations->InAt(0);
1115 Location second = locations->InAt(1);
1116 DCHECK(first.Equals(locations->Out()));
1117 switch (mul->GetResultType()) {
1118 case Primitive::kPrimInt: {
1119 if (second.IsRegister()) {
1120 __ imull(first.As<CpuRegister>(), second.As<CpuRegister>());
1121 } else if (second.IsConstant()) {
1122 Immediate imm(second.GetConstant()->AsIntConstant()->GetValue());
1123 __ imull(first.As<CpuRegister>(), imm);
1124 } else {
1125 DCHECK(second.IsStackSlot());
1126 __ imull(first.As<CpuRegister>(), Address(CpuRegister(RSP), second.GetStackIndex()));
1127 }
1128 break;
1129 }
1130 case Primitive::kPrimLong: {
1131 __ imulq(first.As<CpuRegister>(), second.As<CpuRegister>());
1132 break;
1133 }
1134
1135 case Primitive::kPrimBoolean:
1136 case Primitive::kPrimByte:
1137 case Primitive::kPrimChar:
1138 case Primitive::kPrimShort:
1139 LOG(FATAL) << "Unexpected mul type " << mul->GetResultType();
1140 break;
1141
1142 default:
1143 LOG(FATAL) << "Unimplemented mul type " << mul->GetResultType();
1144 }
1145}
1146
Nicolas Geoffray9cf35522014-06-09 18:40:10 +01001147void LocationsBuilderX86_64::VisitNewInstance(HNewInstance* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001148 LocationSummary* locations =
1149 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
Nicolas Geoffray9ae0daa2014-09-30 22:40:23 +01001150 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001151 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
1152 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
1153 locations->SetOut(Location::RegisterLocation(RAX));
Nicolas Geoffray9cf35522014-06-09 18:40:10 +01001154}
1155
1156void InstructionCodeGeneratorX86_64::VisitNewInstance(HNewInstance* instruction) {
1157 InvokeRuntimeCallingConvention calling_convention;
1158 LoadCurrentMethod(CpuRegister(calling_convention.GetRegisterAt(1)));
1159 __ movq(CpuRegister(calling_convention.GetRegisterAt(0)), Immediate(instruction->GetTypeIndex()));
1160
1161 __ gs()->call(Address::Absolute(
1162 QUICK_ENTRYPOINT_OFFSET(kX86_64WordSize, pAllocObjectWithAccessCheck), true));
1163
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +01001164 DCHECK(!codegen_->IsLeafMethod());
Nicolas Geoffray39468442014-09-02 15:17:15 +01001165 codegen_->RecordPcInfo(instruction, instruction->GetDexPc());
Nicolas Geoffray9cf35522014-06-09 18:40:10 +01001166}
1167
1168void LocationsBuilderX86_64::VisitParameterValue(HParameterValue* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001169 LocationSummary* locations =
1170 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray9cf35522014-06-09 18:40:10 +01001171 Location location = parameter_visitor_.GetNextLocation(instruction->GetType());
1172 if (location.IsStackSlot()) {
1173 location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize());
1174 } else if (location.IsDoubleStackSlot()) {
1175 location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize());
1176 }
1177 locations->SetOut(location);
Nicolas Geoffray9cf35522014-06-09 18:40:10 +01001178}
1179
1180void InstructionCodeGeneratorX86_64::VisitParameterValue(HParameterValue* instruction) {
1181 // Nothing to do, the parameter is already at its location.
1182}
1183
1184void LocationsBuilderX86_64::VisitNot(HNot* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001185 LocationSummary* locations =
1186 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffrayecb2f9b2014-06-13 08:59:59 +00001187 locations->SetInAt(0, Location::RequiresRegister());
1188 locations->SetOut(Location::SameAsFirstInput());
Nicolas Geoffray9cf35522014-06-09 18:40:10 +01001189}
1190
1191void InstructionCodeGeneratorX86_64::VisitNot(HNot* instruction) {
1192 LocationSummary* locations = instruction->GetLocations();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001193 DCHECK_EQ(locations->InAt(0).As<CpuRegister>().AsRegister(),
1194 locations->Out().As<CpuRegister>().AsRegister());
1195 __ xorq(locations->Out().As<CpuRegister>(), Immediate(1));
Nicolas Geoffray9cf35522014-06-09 18:40:10 +01001196}
1197
1198void LocationsBuilderX86_64::VisitPhi(HPhi* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001199 LocationSummary* locations =
1200 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray9cf35522014-06-09 18:40:10 +01001201 for (size_t i = 0, e = instruction->InputCount(); i < e; ++i) {
1202 locations->SetInAt(i, Location::Any());
1203 }
1204 locations->SetOut(Location::Any());
Nicolas Geoffray9cf35522014-06-09 18:40:10 +01001205}
1206
1207void InstructionCodeGeneratorX86_64::VisitPhi(HPhi* instruction) {
1208 LOG(FATAL) << "Unimplemented";
1209}
1210
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001211void LocationsBuilderX86_64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001212 LocationSummary* locations =
1213 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray9ae0daa2014-09-30 22:40:23 +01001214 Primitive::Type field_type = instruction->GetFieldType();
1215 bool is_object_type = field_type == Primitive::kPrimNot;
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001216 locations->SetInAt(0, Location::RequiresRegister());
1217 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray9ae0daa2014-09-30 22:40:23 +01001218 if (is_object_type) {
1219 // Temporary registers for the write barrier.
Nicolas Geoffray1a43dd72014-07-17 15:15:34 +01001220 locations->AddTemp(Location::RequiresRegister());
1221 locations->AddTemp(Location::RequiresRegister());
1222 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001223}
1224
1225void InstructionCodeGeneratorX86_64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) {
1226 LocationSummary* locations = instruction->GetLocations();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001227 CpuRegister obj = locations->InAt(0).As<CpuRegister>();
1228 CpuRegister value = locations->InAt(1).As<CpuRegister>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001229 size_t offset = instruction->GetFieldOffset().SizeValue();
Nicolas Geoffray39468442014-09-02 15:17:15 +01001230 Primitive::Type field_type = instruction->GetFieldType();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001231
1232 switch (field_type) {
1233 case Primitive::kPrimBoolean:
1234 case Primitive::kPrimByte: {
1235 __ movb(Address(obj, offset), value);
1236 break;
1237 }
1238
1239 case Primitive::kPrimShort:
1240 case Primitive::kPrimChar: {
1241 __ movw(Address(obj, offset), value);
1242 break;
1243 }
1244
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001245 case Primitive::kPrimInt:
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001246 case Primitive::kPrimNot: {
1247 __ movl(Address(obj, offset), value);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001248 if (field_type == Primitive::kPrimNot) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001249 CpuRegister temp = locations->GetTemp(0).As<CpuRegister>();
1250 CpuRegister card = locations->GetTemp(1).As<CpuRegister>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001251 codegen_->MarkGCCard(temp, card, obj, value);
1252 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001253 break;
1254 }
1255
1256 case Primitive::kPrimLong: {
1257 __ movq(Address(obj, offset), value);
1258 break;
1259 }
1260
1261 case Primitive::kPrimFloat:
1262 case Primitive::kPrimDouble:
1263 LOG(FATAL) << "Unimplemented register type " << field_type;
Ian Rogersfc787ec2014-10-09 21:56:44 -07001264 UNREACHABLE();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001265 case Primitive::kPrimVoid:
1266 LOG(FATAL) << "Unreachable type " << field_type;
Ian Rogersfc787ec2014-10-09 21:56:44 -07001267 UNREACHABLE();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001268 }
1269}
1270
1271void LocationsBuilderX86_64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001272 LocationSummary* locations =
1273 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001274 locations->SetInAt(0, Location::RequiresRegister());
1275 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001276}
1277
1278void InstructionCodeGeneratorX86_64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) {
1279 LocationSummary* locations = instruction->GetLocations();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001280 CpuRegister obj = locations->InAt(0).As<CpuRegister>();
1281 CpuRegister out = locations->Out().As<CpuRegister>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001282 size_t offset = instruction->GetFieldOffset().SizeValue();
1283
1284 switch (instruction->GetType()) {
1285 case Primitive::kPrimBoolean: {
1286 __ movzxb(out, Address(obj, offset));
1287 break;
1288 }
1289
1290 case Primitive::kPrimByte: {
1291 __ movsxb(out, Address(obj, offset));
1292 break;
1293 }
1294
1295 case Primitive::kPrimShort: {
1296 __ movsxw(out, Address(obj, offset));
1297 break;
1298 }
1299
1300 case Primitive::kPrimChar: {
1301 __ movzxw(out, Address(obj, offset));
1302 break;
1303 }
1304
1305 case Primitive::kPrimInt:
1306 case Primitive::kPrimNot: {
1307 __ movl(out, Address(obj, offset));
1308 break;
1309 }
1310
1311 case Primitive::kPrimLong: {
1312 __ movq(out, Address(obj, offset));
1313 break;
1314 }
1315
1316 case Primitive::kPrimFloat:
1317 case Primitive::kPrimDouble:
1318 LOG(FATAL) << "Unimplemented register type " << instruction->GetType();
Ian Rogersfc787ec2014-10-09 21:56:44 -07001319 UNREACHABLE();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001320 case Primitive::kPrimVoid:
1321 LOG(FATAL) << "Unreachable type " << instruction->GetType();
Ian Rogersfc787ec2014-10-09 21:56:44 -07001322 UNREACHABLE();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001323 }
1324}
1325
1326void LocationsBuilderX86_64::VisitNullCheck(HNullCheck* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001327 LocationSummary* locations =
1328 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001329 locations->SetInAt(0, Location::Any());
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01001330 if (instruction->HasUses()) {
1331 locations->SetOut(Location::SameAsFirstInput());
1332 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001333}
1334
1335void InstructionCodeGeneratorX86_64::VisitNullCheck(HNullCheck* instruction) {
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +01001336 SlowPathCodeX86_64* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathX86_64(instruction);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001337 codegen_->AddSlowPath(slow_path);
1338
1339 LocationSummary* locations = instruction->GetLocations();
1340 Location obj = locations->InAt(0);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001341
1342 if (obj.IsRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001343 __ cmpl(obj.As<CpuRegister>(), Immediate(0));
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01001344 } else if (obj.IsStackSlot()) {
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001345 __ cmpl(Address(CpuRegister(RSP), obj.GetStackIndex()), Immediate(0));
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01001346 } else {
1347 DCHECK(obj.IsConstant()) << obj;
1348 DCHECK_EQ(obj.GetConstant()->AsIntConstant()->GetValue(), 0);
1349 __ jmp(slow_path->GetEntryLabel());
1350 return;
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001351 }
1352 __ j(kEqual, slow_path->GetEntryLabel());
1353}
1354
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001355void LocationsBuilderX86_64::VisitArrayGet(HArrayGet* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001356 LocationSummary* locations =
1357 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001358 locations->SetInAt(0, Location::RequiresRegister());
Nicolas Geoffray9ae0daa2014-09-30 22:40:23 +01001359 locations->SetInAt(
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001360 1, Location::RegisterOrConstant(instruction->InputAt(1)));
1361 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001362}
1363
1364void InstructionCodeGeneratorX86_64::VisitArrayGet(HArrayGet* instruction) {
1365 LocationSummary* locations = instruction->GetLocations();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001366 CpuRegister obj = locations->InAt(0).As<CpuRegister>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001367 Location index = locations->InAt(1);
1368
1369 switch (instruction->GetType()) {
1370 case Primitive::kPrimBoolean: {
1371 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001372 CpuRegister out = locations->Out().As<CpuRegister>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001373 if (index.IsConstant()) {
1374 __ movzxb(out, Address(obj,
1375 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset));
1376 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001377 __ movzxb(out, Address(obj, index.As<CpuRegister>(), TIMES_1, data_offset));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001378 }
1379 break;
1380 }
1381
1382 case Primitive::kPrimByte: {
1383 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int8_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001384 CpuRegister out = locations->Out().As<CpuRegister>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001385 if (index.IsConstant()) {
1386 __ movsxb(out, Address(obj,
1387 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset));
1388 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001389 __ movsxb(out, Address(obj, index.As<CpuRegister>(), TIMES_1, data_offset));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001390 }
1391 break;
1392 }
1393
1394 case Primitive::kPrimShort: {
1395 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int16_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001396 CpuRegister out = locations->Out().As<CpuRegister>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001397 if (index.IsConstant()) {
1398 __ movsxw(out, Address(obj,
1399 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset));
1400 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001401 __ movsxw(out, Address(obj, index.As<CpuRegister>(), TIMES_2, data_offset));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001402 }
1403 break;
1404 }
1405
1406 case Primitive::kPrimChar: {
1407 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001408 CpuRegister out = locations->Out().As<CpuRegister>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001409 if (index.IsConstant()) {
1410 __ movzxw(out, Address(obj,
1411 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset));
1412 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001413 __ movzxw(out, Address(obj, index.As<CpuRegister>(), TIMES_2, data_offset));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001414 }
1415 break;
1416 }
1417
1418 case Primitive::kPrimInt:
1419 case Primitive::kPrimNot: {
1420 DCHECK_EQ(sizeof(mirror::HeapReference<mirror::Object>), sizeof(int32_t));
1421 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001422 CpuRegister out = locations->Out().As<CpuRegister>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001423 if (index.IsConstant()) {
1424 __ movl(out, Address(obj,
1425 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset));
1426 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001427 __ movl(out, Address(obj, index.As<CpuRegister>(), TIMES_4, data_offset));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001428 }
1429 break;
1430 }
1431
1432 case Primitive::kPrimLong: {
1433 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001434 CpuRegister out = locations->Out().As<CpuRegister>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001435 if (index.IsConstant()) {
1436 __ movq(out, Address(obj,
1437 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset));
1438 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001439 __ movq(out, Address(obj, index.As<CpuRegister>(), TIMES_8, data_offset));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001440 }
1441 break;
1442 }
1443
1444 case Primitive::kPrimFloat:
1445 case Primitive::kPrimDouble:
1446 LOG(FATAL) << "Unimplemented register type " << instruction->GetType();
Ian Rogersfc787ec2014-10-09 21:56:44 -07001447 UNREACHABLE();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001448 case Primitive::kPrimVoid:
1449 LOG(FATAL) << "Unreachable type " << instruction->GetType();
Ian Rogersfc787ec2014-10-09 21:56:44 -07001450 UNREACHABLE();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001451 }
1452}
1453
1454void LocationsBuilderX86_64::VisitArraySet(HArraySet* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001455 Primitive::Type value_type = instruction->GetComponentType();
1456 bool is_object = value_type == Primitive::kPrimNot;
1457 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(
1458 instruction, is_object ? LocationSummary::kCall : LocationSummary::kNoCall);
1459 if (is_object) {
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001460 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001461 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
1462 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
1463 locations->SetInAt(2, Location::RegisterLocation(calling_convention.GetRegisterAt(2)));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001464 } else {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001465 locations->SetInAt(0, Location::RequiresRegister());
Nicolas Geoffray9ae0daa2014-09-30 22:40:23 +01001466 locations->SetInAt(
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001467 1, Location::RegisterOrConstant(instruction->InputAt(1)));
1468 locations->SetInAt(2, Location::RequiresRegister());
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01001469 if (value_type == Primitive::kPrimLong) {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001470 locations->SetInAt(2, Location::RequiresRegister());
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01001471 } else {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001472 locations->SetInAt(2, Location::RegisterOrConstant(instruction->InputAt(2)));
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01001473 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001474 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001475}
1476
1477void InstructionCodeGeneratorX86_64::VisitArraySet(HArraySet* instruction) {
1478 LocationSummary* locations = instruction->GetLocations();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001479 CpuRegister obj = locations->InAt(0).As<CpuRegister>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001480 Location index = locations->InAt(1);
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01001481 Location value = locations->InAt(2);
Nicolas Geoffray39468442014-09-02 15:17:15 +01001482 Primitive::Type value_type = instruction->GetComponentType();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001483
1484 switch (value_type) {
1485 case Primitive::kPrimBoolean:
1486 case Primitive::kPrimByte: {
1487 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001488 if (index.IsConstant()) {
1489 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01001490 if (value.IsRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001491 __ movb(Address(obj, offset), value.As<CpuRegister>());
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01001492 } else {
1493 __ movb(Address(obj, offset), Immediate(value.GetConstant()->AsIntConstant()->GetValue()));
1494 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001495 } else {
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01001496 if (value.IsRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001497 __ movb(Address(obj, index.As<CpuRegister>(), TIMES_1, data_offset),
1498 value.As<CpuRegister>());
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01001499 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001500 __ movb(Address(obj, index.As<CpuRegister>(), TIMES_1, data_offset),
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01001501 Immediate(value.GetConstant()->AsIntConstant()->GetValue()));
1502 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001503 }
1504 break;
1505 }
1506
1507 case Primitive::kPrimShort:
1508 case Primitive::kPrimChar: {
1509 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001510 if (index.IsConstant()) {
1511 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset;
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01001512 if (value.IsRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001513 __ movw(Address(obj, offset), value.As<CpuRegister>());
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01001514 } else {
1515 __ movw(Address(obj, offset), Immediate(value.GetConstant()->AsIntConstant()->GetValue()));
1516 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001517 } else {
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01001518 if (value.IsRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001519 __ movw(Address(obj, index.As<CpuRegister>(), TIMES_2, data_offset),
1520 value.As<CpuRegister>());
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01001521 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001522 __ movw(Address(obj, index.As<CpuRegister>(), TIMES_2, data_offset),
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01001523 Immediate(value.GetConstant()->AsIntConstant()->GetValue()));
1524 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001525 }
1526 break;
1527 }
1528
1529 case Primitive::kPrimInt: {
1530 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001531 if (index.IsConstant()) {
1532 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01001533 if (value.IsRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001534 __ movl(Address(obj, offset), value.As<CpuRegister>());
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01001535 } else {
1536 __ movl(Address(obj, offset), Immediate(value.GetConstant()->AsIntConstant()->GetValue()));
1537 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001538 } else {
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01001539 if (value.IsRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001540 __ movl(Address(obj, index.As<CpuRegister>(), TIMES_4, data_offset),
1541 value.As<CpuRegister>());
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01001542 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001543 __ movl(Address(obj, index.As<CpuRegister>(), TIMES_4, data_offset),
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01001544 Immediate(value.GetConstant()->AsIntConstant()->GetValue()));
1545 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001546 }
1547 break;
1548 }
1549
1550 case Primitive::kPrimNot: {
1551 __ gs()->call(Address::Absolute(QUICK_ENTRYPOINT_OFFSET(kX86_64WordSize, pAputObject), true));
1552 DCHECK(!codegen_->IsLeafMethod());
Nicolas Geoffray39468442014-09-02 15:17:15 +01001553 codegen_->RecordPcInfo(instruction, instruction->GetDexPc());
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001554 break;
1555 }
1556
1557 case Primitive::kPrimLong: {
1558 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001559 if (index.IsConstant()) {
1560 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01001561 DCHECK(value.IsRegister());
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001562 __ movq(Address(obj, offset), value.As<CpuRegister>());
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001563 } else {
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01001564 DCHECK(value.IsRegister());
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001565 __ movq(Address(obj, index.As<CpuRegister>(), TIMES_8, data_offset),
1566 value.As<CpuRegister>());
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001567 }
1568 break;
1569 }
1570
1571 case Primitive::kPrimFloat:
1572 case Primitive::kPrimDouble:
1573 LOG(FATAL) << "Unimplemented register type " << instruction->GetType();
Ian Rogersfc787ec2014-10-09 21:56:44 -07001574 UNREACHABLE();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001575 case Primitive::kPrimVoid:
1576 LOG(FATAL) << "Unreachable type " << instruction->GetType();
Ian Rogersfc787ec2014-10-09 21:56:44 -07001577 UNREACHABLE();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001578 }
1579}
1580
1581void LocationsBuilderX86_64::VisitArrayLength(HArrayLength* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001582 LocationSummary* locations =
1583 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001584 locations->SetInAt(0, Location::RequiresRegister());
1585 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001586}
1587
1588void InstructionCodeGeneratorX86_64::VisitArrayLength(HArrayLength* instruction) {
1589 LocationSummary* locations = instruction->GetLocations();
1590 uint32_t offset = mirror::Array::LengthOffset().Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001591 CpuRegister obj = locations->InAt(0).As<CpuRegister>();
1592 CpuRegister out = locations->Out().As<CpuRegister>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001593 __ movl(out, Address(obj, offset));
1594}
1595
1596void LocationsBuilderX86_64::VisitBoundsCheck(HBoundsCheck* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001597 LocationSummary* locations =
1598 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001599 locations->SetInAt(0, Location::RequiresRegister());
1600 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01001601 if (instruction->HasUses()) {
1602 locations->SetOut(Location::SameAsFirstInput());
1603 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001604}
1605
1606void InstructionCodeGeneratorX86_64::VisitBoundsCheck(HBoundsCheck* instruction) {
1607 LocationSummary* locations = instruction->GetLocations();
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +01001608 SlowPathCodeX86_64* slow_path = new (GetGraph()->GetArena()) BoundsCheckSlowPathX86_64(
Nicolas Geoffray39468442014-09-02 15:17:15 +01001609 instruction, locations->InAt(0), locations->InAt(1));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001610 codegen_->AddSlowPath(slow_path);
1611
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001612 CpuRegister index = locations->InAt(0).As<CpuRegister>();
1613 CpuRegister length = locations->InAt(1).As<CpuRegister>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001614
1615 __ cmpl(index, length);
1616 __ j(kAboveEqual, slow_path->GetEntryLabel());
1617}
1618
1619void CodeGeneratorX86_64::MarkGCCard(CpuRegister temp,
1620 CpuRegister card,
1621 CpuRegister object,
1622 CpuRegister value) {
1623 Label is_null;
1624 __ testl(value, value);
1625 __ j(kEqual, &is_null);
1626 __ gs()->movq(card, Address::Absolute(
1627 Thread::CardTableOffset<kX86_64WordSize>().Int32Value(), true));
1628 __ movq(temp, object);
1629 __ shrq(temp, Immediate(gc::accounting::CardTable::kCardShift));
1630 __ movb(Address(temp, card, TIMES_1, 0), card);
1631 __ Bind(&is_null);
1632}
1633
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001634void LocationsBuilderX86_64::VisitTemporary(HTemporary* temp) {
1635 temp->SetLocations(nullptr);
1636}
1637
1638void InstructionCodeGeneratorX86_64::VisitTemporary(HTemporary* temp) {
1639 // Nothing to do, this is driven by the code generator.
1640}
1641
Nicolas Geoffray9cf35522014-06-09 18:40:10 +01001642void LocationsBuilderX86_64::VisitParallelMove(HParallelMove* instruction) {
1643 LOG(FATAL) << "Unimplemented";
1644}
1645
1646void InstructionCodeGeneratorX86_64::VisitParallelMove(HParallelMove* instruction) {
Nicolas Geoffrayecb2f9b2014-06-13 08:59:59 +00001647 codegen_->GetMoveResolver()->EmitNativeCode(instruction);
1648}
1649
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00001650void LocationsBuilderX86_64::VisitSuspendCheck(HSuspendCheck* instruction) {
1651 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath);
1652}
1653
1654void InstructionCodeGeneratorX86_64::VisitSuspendCheck(HSuspendCheck* instruction) {
Nicolas Geoffray3c049742014-09-24 18:10:46 +01001655 HBasicBlock* block = instruction->GetBlock();
1656 if (block->GetLoopInformation() != nullptr) {
1657 DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction);
1658 // The back edge will generate the suspend check.
1659 return;
1660 }
1661 if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) {
1662 // The goto will generate the suspend check.
1663 return;
1664 }
1665 GenerateSuspendCheck(instruction, nullptr);
1666}
1667
1668void InstructionCodeGeneratorX86_64::GenerateSuspendCheck(HSuspendCheck* instruction,
1669 HBasicBlock* successor) {
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00001670 SuspendCheckSlowPathX86_64* slow_path =
Nicolas Geoffray3c049742014-09-24 18:10:46 +01001671 new (GetGraph()->GetArena()) SuspendCheckSlowPathX86_64(instruction, successor);
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00001672 codegen_->AddSlowPath(slow_path);
Nicolas Geoffray3c049742014-09-24 18:10:46 +01001673 __ gs()->cmpw(Address::Absolute(
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00001674 Thread::ThreadFlagsOffset<kX86_64WordSize>().Int32Value(), true), Immediate(0));
Nicolas Geoffray3c049742014-09-24 18:10:46 +01001675 if (successor == nullptr) {
1676 __ j(kNotEqual, slow_path->GetEntryLabel());
1677 __ Bind(slow_path->GetReturnLabel());
1678 } else {
1679 __ j(kEqual, codegen_->GetLabelOf(successor));
1680 __ jmp(slow_path->GetEntryLabel());
1681 }
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00001682}
1683
Nicolas Geoffrayecb2f9b2014-06-13 08:59:59 +00001684X86_64Assembler* ParallelMoveResolverX86_64::GetAssembler() const {
1685 return codegen_->GetAssembler();
1686}
1687
1688void ParallelMoveResolverX86_64::EmitMove(size_t index) {
1689 MoveOperands* move = moves_.Get(index);
1690 Location source = move->GetSource();
1691 Location destination = move->GetDestination();
1692
1693 if (source.IsRegister()) {
1694 if (destination.IsRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001695 __ movq(destination.As<CpuRegister>(), source.As<CpuRegister>());
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01001696 } else if (destination.IsStackSlot()) {
Nicolas Geoffrayecb2f9b2014-06-13 08:59:59 +00001697 __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()),
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001698 source.As<CpuRegister>());
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01001699 } else {
1700 DCHECK(destination.IsDoubleStackSlot());
1701 __ movq(Address(CpuRegister(RSP), destination.GetStackIndex()),
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001702 source.As<CpuRegister>());
Nicolas Geoffrayecb2f9b2014-06-13 08:59:59 +00001703 }
1704 } else if (source.IsStackSlot()) {
1705 if (destination.IsRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001706 __ movl(destination.As<CpuRegister>(),
Nicolas Geoffrayecb2f9b2014-06-13 08:59:59 +00001707 Address(CpuRegister(RSP), source.GetStackIndex()));
1708 } else {
1709 DCHECK(destination.IsStackSlot());
1710 __ movl(CpuRegister(TMP), Address(CpuRegister(RSP), source.GetStackIndex()));
1711 __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), CpuRegister(TMP));
1712 }
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01001713 } else if (source.IsDoubleStackSlot()) {
1714 if (destination.IsRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001715 __ movq(destination.As<CpuRegister>(),
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01001716 Address(CpuRegister(RSP), source.GetStackIndex()));
1717 } else {
1718 DCHECK(destination.IsDoubleStackSlot());
1719 __ movq(CpuRegister(TMP), Address(CpuRegister(RSP), source.GetStackIndex()));
1720 __ movq(Address(CpuRegister(RSP), destination.GetStackIndex()), CpuRegister(TMP));
1721 }
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001722 } else if (source.IsConstant()) {
1723 HConstant* constant = source.GetConstant();
1724 if (constant->IsIntConstant()) {
1725 Immediate imm(constant->AsIntConstant()->GetValue());
1726 if (destination.IsRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001727 __ movl(destination.As<CpuRegister>(), imm);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001728 } else {
1729 __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), imm);
1730 }
1731 } else if (constant->IsLongConstant()) {
1732 int64_t value = constant->AsLongConstant()->GetValue();
1733 if (destination.IsRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001734 __ movq(destination.As<CpuRegister>(), Immediate(value));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001735 } else {
1736 __ movq(CpuRegister(TMP), Immediate(value));
1737 __ movq(Address(CpuRegister(RSP), destination.GetStackIndex()), CpuRegister(TMP));
1738 }
1739 } else {
1740 LOG(FATAL) << "Unimplemented constant type";
1741 }
Nicolas Geoffrayecb2f9b2014-06-13 08:59:59 +00001742 } else {
1743 LOG(FATAL) << "Unimplemented";
1744 }
1745}
1746
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01001747void ParallelMoveResolverX86_64::Exchange32(CpuRegister reg, int mem) {
Nicolas Geoffrayecb2f9b2014-06-13 08:59:59 +00001748 __ movl(CpuRegister(TMP), Address(CpuRegister(RSP), mem));
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01001749 __ movl(Address(CpuRegister(RSP), mem), reg);
1750 __ movl(reg, CpuRegister(TMP));
Nicolas Geoffrayecb2f9b2014-06-13 08:59:59 +00001751}
1752
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01001753void ParallelMoveResolverX86_64::Exchange32(int mem1, int mem2) {
Nicolas Geoffrayecb2f9b2014-06-13 08:59:59 +00001754 ScratchRegisterScope ensure_scratch(
1755 this, TMP, RAX, codegen_->GetNumberOfCoreRegisters());
1756
1757 int stack_offset = ensure_scratch.IsSpilled() ? kX86_64WordSize : 0;
1758 __ movl(CpuRegister(TMP), Address(CpuRegister(RSP), mem1 + stack_offset));
1759 __ movl(CpuRegister(ensure_scratch.GetRegister()),
1760 Address(CpuRegister(RSP), mem2 + stack_offset));
1761 __ movl(Address(CpuRegister(RSP), mem2 + stack_offset), CpuRegister(TMP));
1762 __ movl(Address(CpuRegister(RSP), mem1 + stack_offset),
1763 CpuRegister(ensure_scratch.GetRegister()));
1764}
1765
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01001766void ParallelMoveResolverX86_64::Exchange64(CpuRegister reg, int mem) {
1767 __ movq(CpuRegister(TMP), Address(CpuRegister(RSP), mem));
1768 __ movq(Address(CpuRegister(RSP), mem), reg);
1769 __ movq(reg, CpuRegister(TMP));
1770}
1771
1772void ParallelMoveResolverX86_64::Exchange64(int mem1, int mem2) {
1773 ScratchRegisterScope ensure_scratch(
1774 this, TMP, RAX, codegen_->GetNumberOfCoreRegisters());
1775
1776 int stack_offset = ensure_scratch.IsSpilled() ? kX86_64WordSize : 0;
1777 __ movq(CpuRegister(TMP), Address(CpuRegister(RSP), mem1 + stack_offset));
1778 __ movq(CpuRegister(ensure_scratch.GetRegister()),
1779 Address(CpuRegister(RSP), mem2 + stack_offset));
1780 __ movq(Address(CpuRegister(RSP), mem2 + stack_offset), CpuRegister(TMP));
1781 __ movq(Address(CpuRegister(RSP), mem1 + stack_offset),
1782 CpuRegister(ensure_scratch.GetRegister()));
1783}
1784
Nicolas Geoffrayecb2f9b2014-06-13 08:59:59 +00001785void ParallelMoveResolverX86_64::EmitSwap(size_t index) {
1786 MoveOperands* move = moves_.Get(index);
1787 Location source = move->GetSource();
1788 Location destination = move->GetDestination();
1789
1790 if (source.IsRegister() && destination.IsRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001791 __ xchgq(destination.As<CpuRegister>(), source.As<CpuRegister>());
Nicolas Geoffrayecb2f9b2014-06-13 08:59:59 +00001792 } else if (source.IsRegister() && destination.IsStackSlot()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001793 Exchange32(source.As<CpuRegister>(), destination.GetStackIndex());
Nicolas Geoffrayecb2f9b2014-06-13 08:59:59 +00001794 } else if (source.IsStackSlot() && destination.IsRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001795 Exchange32(destination.As<CpuRegister>(), source.GetStackIndex());
Nicolas Geoffrayecb2f9b2014-06-13 08:59:59 +00001796 } else if (source.IsStackSlot() && destination.IsStackSlot()) {
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01001797 Exchange32(destination.GetStackIndex(), source.GetStackIndex());
1798 } else if (source.IsRegister() && destination.IsDoubleStackSlot()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001799 Exchange64(source.As<CpuRegister>(), destination.GetStackIndex());
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01001800 } else if (source.IsDoubleStackSlot() && destination.IsRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001801 Exchange64(destination.As<CpuRegister>(), source.GetStackIndex());
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01001802 } else if (source.IsDoubleStackSlot() && destination.IsDoubleStackSlot()) {
1803 Exchange64(destination.GetStackIndex(), source.GetStackIndex());
Nicolas Geoffrayecb2f9b2014-06-13 08:59:59 +00001804 } else {
1805 LOG(FATAL) << "Unimplemented";
1806 }
1807}
1808
1809
1810void ParallelMoveResolverX86_64::SpillScratch(int reg) {
1811 __ pushq(CpuRegister(reg));
1812}
1813
1814
1815void ParallelMoveResolverX86_64::RestoreScratch(int reg) {
1816 __ popq(CpuRegister(reg));
Nicolas Geoffray9cf35522014-06-09 18:40:10 +01001817}
1818
1819} // namespace x86_64
1820} // namespace art