blob: 1130b4c6927644a9581e72b5ff73f7b384fde4d1 [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
Calin Juravled0d48522014-11-04 16:40:20 +000093class DivZeroCheckSlowPathX86_64 : public SlowPathCodeX86_64 {
94 public:
95 explicit DivZeroCheckSlowPathX86_64(HDivZeroCheck* instruction) : instruction_(instruction) {}
96
97 virtual void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
98 __ Bind(GetEntryLabel());
99 __ gs()->call(
100 Address::Absolute(QUICK_ENTRYPOINT_OFFSET(kX86_64WordSize, pThrowDivZero), true));
101 codegen->RecordPcInfo(instruction_, instruction_->GetDexPc());
102 }
103
104 private:
105 HDivZeroCheck* const instruction_;
106 DISALLOW_COPY_AND_ASSIGN(DivZeroCheckSlowPathX86_64);
107};
108
109class DivMinusOneSlowPathX86_64 : public SlowPathCodeX86_64 {
110 public:
111 explicit DivMinusOneSlowPathX86_64(Register reg) : reg_(reg) {}
112
113 virtual void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
114 __ Bind(GetEntryLabel());
115 __ negl(CpuRegister(reg_));
116 __ jmp(GetExitLabel());
117 }
118
119 private:
120 Register reg_;
121 DISALLOW_COPY_AND_ASSIGN(DivMinusOneSlowPathX86_64);
122};
123
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100124class StackOverflowCheckSlowPathX86_64 : public SlowPathCodeX86_64 {
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +0100125 public:
126 StackOverflowCheckSlowPathX86_64() {}
127
128 virtual void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
129 __ Bind(GetEntryLabel());
130 __ addq(CpuRegister(RSP),
131 Immediate(codegen->GetFrameSize() - kNumberOfPushedRegistersAtEntry * kX86_64WordSize));
132 __ gs()->jmp(
133 Address::Absolute(QUICK_ENTRYPOINT_OFFSET(kX86_64WordSize, pThrowStackOverflow), true));
134 }
135
136 private:
137 DISALLOW_COPY_AND_ASSIGN(StackOverflowCheckSlowPathX86_64);
138};
139
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100140class SuspendCheckSlowPathX86_64 : public SlowPathCodeX86_64 {
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000141 public:
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100142 explicit SuspendCheckSlowPathX86_64(HSuspendCheck* instruction, HBasicBlock* successor)
143 : instruction_(instruction), successor_(successor) {}
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000144
145 virtual void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100146 CodeGeneratorX86_64* x64_codegen = down_cast<CodeGeneratorX86_64*>(codegen);
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000147 __ Bind(GetEntryLabel());
Nicolas Geoffray3bca0df2014-09-19 11:01:00 +0100148 codegen->SaveLiveRegisters(instruction_->GetLocations());
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000149 __ gs()->call(Address::Absolute(QUICK_ENTRYPOINT_OFFSET(kX86_64WordSize, pTestSuspend), true));
150 codegen->RecordPcInfo(instruction_, instruction_->GetDexPc());
Nicolas Geoffray3bca0df2014-09-19 11:01:00 +0100151 codegen->RestoreLiveRegisters(instruction_->GetLocations());
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100152 if (successor_ == nullptr) {
153 __ jmp(GetReturnLabel());
154 } else {
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100155 __ jmp(x64_codegen->GetLabelOf(successor_));
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100156 }
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000157 }
158
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100159 Label* GetReturnLabel() {
160 DCHECK(successor_ == nullptr);
161 return &return_label_;
162 }
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000163
164 private:
165 HSuspendCheck* const instruction_;
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100166 HBasicBlock* const successor_;
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000167 Label return_label_;
168
169 DISALLOW_COPY_AND_ASSIGN(SuspendCheckSlowPathX86_64);
170};
171
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100172class BoundsCheckSlowPathX86_64 : public SlowPathCodeX86_64 {
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100173 public:
Roland Levillain5799fc02014-09-25 12:15:20 +0100174 BoundsCheckSlowPathX86_64(HBoundsCheck* instruction,
175 Location index_location,
176 Location length_location)
Nicolas Geoffray39468442014-09-02 15:17:15 +0100177 : instruction_(instruction),
178 index_location_(index_location),
179 length_location_(length_location) {}
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100180
181 virtual void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100182 CodeGeneratorX86_64* x64_codegen = down_cast<CodeGeneratorX86_64*>(codegen);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100183 __ Bind(GetEntryLabel());
184 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100185 x64_codegen->Move(
186 Location::RegisterLocation(calling_convention.GetRegisterAt(0)), index_location_);
187 x64_codegen->Move(
188 Location::RegisterLocation(calling_convention.GetRegisterAt(1)), length_location_);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100189 __ gs()->call(Address::Absolute(
190 QUICK_ENTRYPOINT_OFFSET(kX86_64WordSize, pThrowArrayBounds), true));
Nicolas Geoffray39468442014-09-02 15:17:15 +0100191 codegen->RecordPcInfo(instruction_, instruction_->GetDexPc());
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100192 }
193
194 private:
Nicolas Geoffray39468442014-09-02 15:17:15 +0100195 HBoundsCheck* const instruction_;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100196 const Location index_location_;
197 const Location length_location_;
198
199 DISALLOW_COPY_AND_ASSIGN(BoundsCheckSlowPathX86_64);
200};
201
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000202class LoadClassSlowPathX86_64 : public SlowPathCodeX86_64 {
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100203 public:
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000204 LoadClassSlowPathX86_64(HLoadClass* cls,
205 HInstruction* at,
206 uint32_t dex_pc,
207 bool do_clinit)
208 : cls_(cls), at_(at), dex_pc_(dex_pc), do_clinit_(do_clinit) {
209 DCHECK(at->IsLoadClass() || at->IsClinitCheck());
210 }
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100211
212 virtual void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000213 LocationSummary* locations = at_->GetLocations();
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100214 CodeGeneratorX86_64* x64_codegen = down_cast<CodeGeneratorX86_64*>(codegen);
215 __ Bind(GetEntryLabel());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100216
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000217 codegen->SaveLiveRegisters(locations);
218
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100219 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000220 __ movl(CpuRegister(calling_convention.GetRegisterAt(0)), Immediate(cls_->GetTypeIndex()));
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100221 x64_codegen->LoadCurrentMethod(CpuRegister(calling_convention.GetRegisterAt(1)));
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000222 __ gs()->call(Address::Absolute((do_clinit_
223 ? QUICK_ENTRYPOINT_OFFSET(kX86_64WordSize, pInitializeStaticStorage)
224 : QUICK_ENTRYPOINT_OFFSET(kX86_64WordSize, pInitializeType)) , true));
225 codegen->RecordPcInfo(at_, dex_pc_);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100226
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000227 // Move the class to the desired location.
228 if (locations->Out().IsValid()) {
229 DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg()));
230 x64_codegen->Move(locations->Out(), Location::RegisterLocation(RAX));
231 }
232
233 codegen->RestoreLiveRegisters(locations);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100234 __ jmp(GetExitLabel());
235 }
236
237 private:
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000238 // The class this slow path will load.
239 HLoadClass* const cls_;
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100240
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000241 // The instruction where this slow path is happening.
242 // (Might be the load class or an initialization check).
243 HInstruction* const at_;
244
245 // The dex PC of `at_`.
246 const uint32_t dex_pc_;
247
248 // Whether to initialize the class.
249 const bool do_clinit_;
250
251 DISALLOW_COPY_AND_ASSIGN(LoadClassSlowPathX86_64);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100252};
253
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +0000254class LoadStringSlowPathX86_64 : public SlowPathCodeX86_64 {
255 public:
256 explicit LoadStringSlowPathX86_64(HLoadString* instruction) : instruction_(instruction) {}
257
258 virtual void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
259 LocationSummary* locations = instruction_->GetLocations();
260 DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg()));
261
262 CodeGeneratorX86_64* x64_codegen = down_cast<CodeGeneratorX86_64*>(codegen);
263 __ Bind(GetEntryLabel());
264 codegen->SaveLiveRegisters(locations);
265
266 InvokeRuntimeCallingConvention calling_convention;
267 x64_codegen->LoadCurrentMethod(CpuRegister(calling_convention.GetRegisterAt(0)));
268 __ movl(CpuRegister(calling_convention.GetRegisterAt(1)),
269 Immediate(instruction_->GetStringIndex()));
270 __ gs()->call(Address::Absolute(
271 QUICK_ENTRYPOINT_OFFSET(kX86_64WordSize, pResolveString), true));
272 codegen->RecordPcInfo(instruction_, instruction_->GetDexPc());
273 x64_codegen->Move(locations->Out(), Location::RegisterLocation(RAX));
274 codegen->RestoreLiveRegisters(locations);
275 __ jmp(GetExitLabel());
276 }
277
278 private:
279 HLoadString* const instruction_;
280
281 DISALLOW_COPY_AND_ASSIGN(LoadStringSlowPathX86_64);
282};
283
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100284#undef __
285#define __ reinterpret_cast<X86_64Assembler*>(GetAssembler())->
286
Dave Allison20dfc792014-06-16 20:44:29 -0700287inline Condition X86_64Condition(IfCondition cond) {
288 switch (cond) {
289 case kCondEQ: return kEqual;
290 case kCondNE: return kNotEqual;
291 case kCondLT: return kLess;
292 case kCondLE: return kLessEqual;
293 case kCondGT: return kGreater;
294 case kCondGE: return kGreaterEqual;
295 default:
296 LOG(FATAL) << "Unknown if condition";
297 }
298 return kEqual;
299}
300
Nicolas Geoffray9cf35522014-06-09 18:40:10 +0100301void CodeGeneratorX86_64::DumpCoreRegister(std::ostream& stream, int reg) const {
302 stream << X86_64ManagedRegister::FromCpuRegister(Register(reg));
303}
304
305void CodeGeneratorX86_64::DumpFloatingPointRegister(std::ostream& stream, int reg) const {
306 stream << X86_64ManagedRegister::FromXmmRegister(FloatRegister(reg));
307}
308
Nicolas Geoffray102cbed2014-10-15 18:31:05 +0100309size_t CodeGeneratorX86_64::SaveCoreRegister(size_t stack_index, uint32_t reg_id) {
310 __ movq(Address(CpuRegister(RSP), stack_index), CpuRegister(reg_id));
311 return kX86_64WordSize;
Nicolas Geoffray3bca0df2014-09-19 11:01:00 +0100312}
313
Nicolas Geoffray102cbed2014-10-15 18:31:05 +0100314size_t CodeGeneratorX86_64::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) {
315 __ movq(CpuRegister(reg_id), Address(CpuRegister(RSP), stack_index));
316 return kX86_64WordSize;
317}
318
319size_t CodeGeneratorX86_64::SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) {
320 __ movsd(Address(CpuRegister(RSP), stack_index), XmmRegister(reg_id));
321 return kX86_64WordSize;
322}
323
324size_t CodeGeneratorX86_64::RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) {
325 __ movsd(XmmRegister(reg_id), Address(CpuRegister(RSP), stack_index));
326 return kX86_64WordSize;
Nicolas Geoffray3bca0df2014-09-19 11:01:00 +0100327}
328
Nicolas Geoffray9cf35522014-06-09 18:40:10 +0100329CodeGeneratorX86_64::CodeGeneratorX86_64(HGraph* graph)
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100330 : CodeGenerator(graph, kNumberOfCpuRegisters, kNumberOfFloatRegisters, 0),
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100331 block_labels_(graph->GetArena(), 0),
Nicolas Geoffray9cf35522014-06-09 18:40:10 +0100332 location_builder_(graph, this),
Nicolas Geoffrayecb2f9b2014-06-13 08:59:59 +0000333 instruction_visitor_(graph, this),
334 move_resolver_(graph->GetArena(), this) {}
Nicolas Geoffray9cf35522014-06-09 18:40:10 +0100335
Nicolas Geoffrayab032bc2014-07-15 12:55:21 +0100336size_t CodeGeneratorX86_64::FrameEntrySpillSize() const {
337 return kNumberOfPushedRegistersAtEntry * kX86_64WordSize;
338}
339
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100340InstructionCodeGeneratorX86_64::InstructionCodeGeneratorX86_64(HGraph* graph,
341 CodeGeneratorX86_64* codegen)
Nicolas Geoffray9cf35522014-06-09 18:40:10 +0100342 : HGraphVisitor(graph),
343 assembler_(codegen->GetAssembler()),
344 codegen_(codegen) {}
345
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100346Location CodeGeneratorX86_64::AllocateFreeRegister(Primitive::Type type) const {
Nicolas Geoffray9cf35522014-06-09 18:40:10 +0100347 switch (type) {
348 case Primitive::kPrimLong:
349 case Primitive::kPrimByte:
350 case Primitive::kPrimBoolean:
351 case Primitive::kPrimChar:
352 case Primitive::kPrimShort:
353 case Primitive::kPrimInt:
354 case Primitive::kPrimNot: {
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100355 size_t reg = FindFreeEntry(blocked_core_registers_, kNumberOfCpuRegisters);
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100356 return Location::RegisterLocation(reg);
Nicolas Geoffray9cf35522014-06-09 18:40:10 +0100357 }
358
359 case Primitive::kPrimFloat:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100360 case Primitive::kPrimDouble: {
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100361 size_t reg = FindFreeEntry(blocked_fpu_registers_, kNumberOfFloatRegisters);
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100362 return Location::FpuRegisterLocation(reg);
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100363 }
Nicolas Geoffray9cf35522014-06-09 18:40:10 +0100364
365 case Primitive::kPrimVoid:
366 LOG(FATAL) << "Unreachable type " << type;
367 }
368
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100369 return Location();
Nicolas Geoffray9cf35522014-06-09 18:40:10 +0100370}
371
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100372void CodeGeneratorX86_64::SetupBlockedRegisters() const {
Nicolas Geoffray9cf35522014-06-09 18:40:10 +0100373 // Stack register is always reserved.
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100374 blocked_core_registers_[RSP] = true;
Nicolas Geoffray9cf35522014-06-09 18:40:10 +0100375
Nicolas Geoffrayecb2f9b2014-06-13 08:59:59 +0000376 // Block the register used as TMP.
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100377 blocked_core_registers_[TMP] = true;
Nicolas Geoffrayecb2f9b2014-06-13 08:59:59 +0000378
Nicolas Geoffray9cf35522014-06-09 18:40:10 +0100379 // TODO: We currently don't use Quick's callee saved registers.
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100380 blocked_core_registers_[RBX] = true;
381 blocked_core_registers_[RBP] = true;
382 blocked_core_registers_[R12] = true;
383 blocked_core_registers_[R13] = true;
384 blocked_core_registers_[R14] = true;
385 blocked_core_registers_[R15] = true;
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100386
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100387 blocked_fpu_registers_[XMM12] = true;
388 blocked_fpu_registers_[XMM13] = true;
389 blocked_fpu_registers_[XMM14] = true;
390 blocked_fpu_registers_[XMM15] = true;
Nicolas Geoffray9cf35522014-06-09 18:40:10 +0100391}
392
Nicolas Geoffray9cf35522014-06-09 18:40:10 +0100393void CodeGeneratorX86_64::GenerateFrameEntry() {
394 // Create a fake register to mimic Quick.
395 static const int kFakeReturnRegister = 16;
396 core_spill_mask_ |= (1 << kFakeReturnRegister);
397
Nicolas Geoffrayf6e206c2014-08-07 20:25:41 +0100398 bool skip_overflow_check = IsLeafMethod()
Dave Allison648d7112014-07-25 16:15:27 -0700399 && !FrameNeedsStackCheck(GetFrameSize(), InstructionSet::kX86_64);
Nicolas Geoffrayf6e206c2014-08-07 20:25:41 +0100400
401 if (!skip_overflow_check && !kExplicitStackOverflowCheck) {
402 __ testq(CpuRegister(RAX), Address(
403 CpuRegister(RSP), -static_cast<int32_t>(GetStackOverflowReservedBytes(kX86_64))));
Nicolas Geoffray39468442014-09-02 15:17:15 +0100404 RecordPcInfo(nullptr, 0);
Nicolas Geoffrayf6e206c2014-08-07 20:25:41 +0100405 }
406
Nicolas Geoffray9cf35522014-06-09 18:40:10 +0100407 // The return PC has already been pushed on the stack.
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +0100408 __ subq(CpuRegister(RSP),
409 Immediate(GetFrameSize() - kNumberOfPushedRegistersAtEntry * kX86_64WordSize));
410
Nicolas Geoffrayf6e206c2014-08-07 20:25:41 +0100411 if (!skip_overflow_check && kExplicitStackOverflowCheck) {
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100412 SlowPathCodeX86_64* slow_path = new (GetGraph()->GetArena()) StackOverflowCheckSlowPathX86_64();
Nicolas Geoffrayf6e206c2014-08-07 20:25:41 +0100413 AddSlowPath(slow_path);
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +0100414
Nicolas Geoffrayf6e206c2014-08-07 20:25:41 +0100415 __ gs()->cmpq(CpuRegister(RSP),
416 Address::Absolute(Thread::StackEndOffset<kX86_64WordSize>(), true));
417 __ j(kLess, slow_path->GetEntryLabel());
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +0100418 }
419
Nicolas Geoffray9cf35522014-06-09 18:40:10 +0100420 __ movl(Address(CpuRegister(RSP), kCurrentMethodStackOffset), CpuRegister(RDI));
421}
422
423void CodeGeneratorX86_64::GenerateFrameExit() {
424 __ addq(CpuRegister(RSP),
425 Immediate(GetFrameSize() - kNumberOfPushedRegistersAtEntry * kX86_64WordSize));
426}
427
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100428void CodeGeneratorX86_64::Bind(HBasicBlock* block) {
429 __ Bind(GetLabelOf(block));
Nicolas Geoffray9cf35522014-06-09 18:40:10 +0100430}
431
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100432void CodeGeneratorX86_64::LoadCurrentMethod(CpuRegister reg) {
Nicolas Geoffray9cf35522014-06-09 18:40:10 +0100433 __ movl(reg, Address(CpuRegister(RSP), kCurrentMethodStackOffset));
434}
435
Nicolas Geoffray9cf35522014-06-09 18:40:10 +0100436Location CodeGeneratorX86_64::GetStackLocation(HLoadLocal* load) const {
437 switch (load->GetType()) {
438 case Primitive::kPrimLong:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100439 case Primitive::kPrimDouble:
Nicolas Geoffray9cf35522014-06-09 18:40:10 +0100440 return Location::DoubleStackSlot(GetStackSlot(load->GetLocal()));
441 break;
442
443 case Primitive::kPrimInt:
444 case Primitive::kPrimNot:
Nicolas Geoffray9cf35522014-06-09 18:40:10 +0100445 case Primitive::kPrimFloat:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100446 return Location::StackSlot(GetStackSlot(load->GetLocal()));
Nicolas Geoffray9cf35522014-06-09 18:40:10 +0100447
448 case Primitive::kPrimBoolean:
449 case Primitive::kPrimByte:
450 case Primitive::kPrimChar:
451 case Primitive::kPrimShort:
452 case Primitive::kPrimVoid:
453 LOG(FATAL) << "Unexpected type " << load->GetType();
454 }
455
456 LOG(FATAL) << "Unreachable";
457 return Location();
458}
459
460void CodeGeneratorX86_64::Move(Location destination, Location source) {
461 if (source.Equals(destination)) {
462 return;
463 }
464 if (destination.IsRegister()) {
465 if (source.IsRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100466 __ movq(destination.As<CpuRegister>(), source.As<CpuRegister>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100467 } else if (source.IsFpuRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100468 __ movd(destination.As<CpuRegister>(), source.As<XmmRegister>());
Nicolas Geoffray9cf35522014-06-09 18:40:10 +0100469 } else if (source.IsStackSlot()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100470 __ movl(destination.As<CpuRegister>(),
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100471 Address(CpuRegister(RSP), source.GetStackIndex()));
Nicolas Geoffray9cf35522014-06-09 18:40:10 +0100472 } else {
473 DCHECK(source.IsDoubleStackSlot());
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100474 __ movq(destination.As<CpuRegister>(),
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100475 Address(CpuRegister(RSP), source.GetStackIndex()));
476 }
477 } else if (destination.IsFpuRegister()) {
478 if (source.IsRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100479 __ movd(destination.As<XmmRegister>(), source.As<CpuRegister>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100480 } else if (source.IsFpuRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100481 __ movaps(destination.As<XmmRegister>(), source.As<XmmRegister>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100482 } else if (source.IsStackSlot()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100483 __ movss(destination.As<XmmRegister>(),
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100484 Address(CpuRegister(RSP), source.GetStackIndex()));
485 } else {
486 DCHECK(source.IsDoubleStackSlot());
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100487 __ movsd(destination.As<XmmRegister>(),
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100488 Address(CpuRegister(RSP), source.GetStackIndex()));
Nicolas Geoffray9cf35522014-06-09 18:40:10 +0100489 }
490 } else if (destination.IsStackSlot()) {
491 if (source.IsRegister()) {
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100492 __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()),
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100493 source.As<CpuRegister>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100494 } else if (source.IsFpuRegister()) {
495 __ movss(Address(CpuRegister(RSP), destination.GetStackIndex()),
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100496 source.As<XmmRegister>());
Nicolas Geoffray9cf35522014-06-09 18:40:10 +0100497 } else {
498 DCHECK(source.IsStackSlot());
Nicolas Geoffrayecb2f9b2014-06-13 08:59:59 +0000499 __ movl(CpuRegister(TMP), Address(CpuRegister(RSP), source.GetStackIndex()));
500 __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), CpuRegister(TMP));
Nicolas Geoffray9cf35522014-06-09 18:40:10 +0100501 }
502 } else {
503 DCHECK(destination.IsDoubleStackSlot());
504 if (source.IsRegister()) {
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100505 __ movq(Address(CpuRegister(RSP), destination.GetStackIndex()),
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100506 source.As<CpuRegister>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100507 } else if (source.IsFpuRegister()) {
508 __ movsd(Address(CpuRegister(RSP), destination.GetStackIndex()),
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100509 source.As<XmmRegister>());
Nicolas Geoffray9cf35522014-06-09 18:40:10 +0100510 } else {
511 DCHECK(source.IsDoubleStackSlot());
Nicolas Geoffrayecb2f9b2014-06-13 08:59:59 +0000512 __ movq(CpuRegister(TMP), Address(CpuRegister(RSP), source.GetStackIndex()));
513 __ movq(Address(CpuRegister(RSP), destination.GetStackIndex()), CpuRegister(TMP));
Nicolas Geoffray9cf35522014-06-09 18:40:10 +0100514 }
515 }
516}
517
Nicolas Geoffray412f10c2014-06-19 10:00:34 +0100518void CodeGeneratorX86_64::Move(HInstruction* instruction,
519 Location location,
520 HInstruction* move_for) {
Roland Levillain476df552014-10-09 17:51:36 +0100521 if (instruction->IsIntConstant()) {
Nicolas Geoffray9cf35522014-06-09 18:40:10 +0100522 Immediate imm(instruction->AsIntConstant()->GetValue());
523 if (location.IsRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100524 __ movl(location.As<CpuRegister>(), imm);
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +0100525 } else if (location.IsStackSlot()) {
Nicolas Geoffray9cf35522014-06-09 18:40:10 +0100526 __ movl(Address(CpuRegister(RSP), location.GetStackIndex()), imm);
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +0100527 } else {
528 DCHECK(location.IsConstant());
529 DCHECK_EQ(location.GetConstant(), instruction);
Nicolas Geoffray9cf35522014-06-09 18:40:10 +0100530 }
Roland Levillain476df552014-10-09 17:51:36 +0100531 } else if (instruction->IsLongConstant()) {
Nicolas Geoffray9cf35522014-06-09 18:40:10 +0100532 int64_t value = instruction->AsLongConstant()->GetValue();
533 if (location.IsRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100534 __ movq(location.As<CpuRegister>(), Immediate(value));
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +0100535 } else if (location.IsDoubleStackSlot()) {
Nicolas Geoffrayecb2f9b2014-06-13 08:59:59 +0000536 __ movq(CpuRegister(TMP), Immediate(value));
537 __ movq(Address(CpuRegister(RSP), location.GetStackIndex()), CpuRegister(TMP));
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +0100538 } else {
539 DCHECK(location.IsConstant());
540 DCHECK_EQ(location.GetConstant(), instruction);
Nicolas Geoffray9cf35522014-06-09 18:40:10 +0100541 }
Roland Levillain476df552014-10-09 17:51:36 +0100542 } else if (instruction->IsLoadLocal()) {
Nicolas Geoffray9cf35522014-06-09 18:40:10 +0100543 switch (instruction->GetType()) {
544 case Primitive::kPrimBoolean:
545 case Primitive::kPrimByte:
546 case Primitive::kPrimChar:
547 case Primitive::kPrimShort:
548 case Primitive::kPrimInt:
549 case Primitive::kPrimNot:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100550 case Primitive::kPrimFloat:
Nicolas Geoffray9cf35522014-06-09 18:40:10 +0100551 Move(location, Location::StackSlot(GetStackSlot(instruction->AsLoadLocal()->GetLocal())));
552 break;
553
554 case Primitive::kPrimLong:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100555 case Primitive::kPrimDouble:
Nicolas Geoffray9cf35522014-06-09 18:40:10 +0100556 Move(location, Location::DoubleStackSlot(GetStackSlot(instruction->AsLoadLocal()->GetLocal())));
557 break;
558
559 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100560 LOG(FATAL) << "Unexpected local type " << instruction->GetType();
Nicolas Geoffray9cf35522014-06-09 18:40:10 +0100561 }
562 } else {
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100563 DCHECK((instruction->GetNext() == move_for) || instruction->GetNext()->IsTemporary());
Nicolas Geoffray9cf35522014-06-09 18:40:10 +0100564 switch (instruction->GetType()) {
565 case Primitive::kPrimBoolean:
566 case Primitive::kPrimByte:
567 case Primitive::kPrimChar:
568 case Primitive::kPrimShort:
569 case Primitive::kPrimInt:
570 case Primitive::kPrimNot:
571 case Primitive::kPrimLong:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100572 case Primitive::kPrimFloat:
573 case Primitive::kPrimDouble:
Nicolas Geoffray9cf35522014-06-09 18:40:10 +0100574 Move(location, instruction->GetLocations()->Out());
575 break;
576
577 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100578 LOG(FATAL) << "Unexpected type " << instruction->GetType();
Nicolas Geoffray9cf35522014-06-09 18:40:10 +0100579 }
580 }
581}
582
583void LocationsBuilderX86_64::VisitGoto(HGoto* got) {
584 got->SetLocations(nullptr);
585}
586
587void InstructionCodeGeneratorX86_64::VisitGoto(HGoto* got) {
588 HBasicBlock* successor = got->GetSuccessor();
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100589 DCHECK(!successor->IsExitBlock());
590
591 HBasicBlock* block = got->GetBlock();
592 HInstruction* previous = got->GetPrevious();
593
594 HLoopInformation* info = block->GetLoopInformation();
595 if (info != nullptr && info->IsBackEdge(block) && info->HasSuspendCheck()) {
596 codegen_->ClearSpillSlotsFromLoopPhisInStackMap(info->GetSuspendCheck());
597 GenerateSuspendCheck(info->GetSuspendCheck(), successor);
598 return;
599 }
600
601 if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) {
602 GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr);
603 }
604 if (!codegen_->GoesToNextBlock(got->GetBlock(), successor)) {
Nicolas Geoffray9cf35522014-06-09 18:40:10 +0100605 __ jmp(codegen_->GetLabelOf(successor));
606 }
607}
608
609void LocationsBuilderX86_64::VisitExit(HExit* exit) {
610 exit->SetLocations(nullptr);
611}
612
613void InstructionCodeGeneratorX86_64::VisitExit(HExit* exit) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -0700614 UNUSED(exit);
Nicolas Geoffray9cf35522014-06-09 18:40:10 +0100615 if (kIsDebugBuild) {
616 __ Comment("Unreachable");
617 __ int3();
618 }
619}
620
621void LocationsBuilderX86_64::VisitIf(HIf* if_instr) {
Nicolas Geoffray39468442014-09-02 15:17:15 +0100622 LocationSummary* locations =
623 new (GetGraph()->GetArena()) LocationSummary(if_instr, LocationSummary::kNoCall);
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100624 HInstruction* cond = if_instr->InputAt(0);
Nicolas Geoffray01ef3452014-10-01 11:32:17 +0100625 if (!cond->IsCondition() || cond->AsCondition()->NeedsMaterialization()) {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +0100626 locations->SetInAt(0, Location::Any());
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100627 }
Nicolas Geoffray9cf35522014-06-09 18:40:10 +0100628}
629
630void InstructionCodeGeneratorX86_64::VisitIf(HIf* if_instr) {
Dave Allison20dfc792014-06-16 20:44:29 -0700631 HInstruction* cond = if_instr->InputAt(0);
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100632 if (cond->IsIntConstant()) {
633 // Constant condition, statically compared against 1.
634 int32_t cond_value = cond->AsIntConstant()->GetValue();
635 if (cond_value == 1) {
636 if (!codegen_->GoesToNextBlock(if_instr->GetBlock(),
637 if_instr->IfTrueSuccessor())) {
638 __ jmp(codegen_->GetLabelOf(if_instr->IfTrueSuccessor()));
Nicolas Geoffray18efde52014-09-22 15:51:11 +0100639 }
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100640 return;
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100641 } else {
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100642 DCHECK_EQ(cond_value, 0);
643 }
644 } else {
645 bool materialized =
646 !cond->IsCondition() || cond->AsCondition()->NeedsMaterialization();
647 // Moves do not affect the eflags register, so if the condition is
648 // evaluated just before the if, we don't need to evaluate it
649 // again.
650 bool eflags_set = cond->IsCondition()
651 && cond->AsCondition()->IsBeforeWhenDisregardMoves(if_instr);
652 if (materialized) {
653 if (!eflags_set) {
654 // Materialized condition, compare against 0.
655 Location lhs = if_instr->GetLocations()->InAt(0);
656 if (lhs.IsRegister()) {
657 __ cmpl(lhs.As<CpuRegister>(), Immediate(0));
658 } else {
659 __ cmpl(Address(CpuRegister(RSP), lhs.GetStackIndex()),
660 Immediate(0));
661 }
662 __ j(kNotEqual, codegen_->GetLabelOf(if_instr->IfTrueSuccessor()));
663 } else {
664 __ j(X86_64Condition(cond->AsCondition()->GetCondition()),
665 codegen_->GetLabelOf(if_instr->IfTrueSuccessor()));
666 }
667 } else {
668 Location lhs = cond->GetLocations()->InAt(0);
669 Location rhs = cond->GetLocations()->InAt(1);
670 if (rhs.IsRegister()) {
671 __ cmpl(lhs.As<CpuRegister>(), rhs.As<CpuRegister>());
672 } else if (rhs.IsConstant()) {
673 __ cmpl(lhs.As<CpuRegister>(),
674 Immediate(rhs.GetConstant()->AsIntConstant()->GetValue()));
675 } else {
676 __ cmpl(lhs.As<CpuRegister>(),
677 Address(CpuRegister(RSP), rhs.GetStackIndex()));
678 }
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100679 __ j(X86_64Condition(cond->AsCondition()->GetCondition()),
680 codegen_->GetLabelOf(if_instr->IfTrueSuccessor()));
Dave Allison20dfc792014-06-16 20:44:29 -0700681 }
Dave Allison20dfc792014-06-16 20:44:29 -0700682 }
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100683 if (!codegen_->GoesToNextBlock(if_instr->GetBlock(),
684 if_instr->IfFalseSuccessor())) {
Dave Allison20dfc792014-06-16 20:44:29 -0700685 __ jmp(codegen_->GetLabelOf(if_instr->IfFalseSuccessor()));
Nicolas Geoffray9cf35522014-06-09 18:40:10 +0100686 }
687}
688
689void LocationsBuilderX86_64::VisitLocal(HLocal* local) {
690 local->SetLocations(nullptr);
691}
692
693void InstructionCodeGeneratorX86_64::VisitLocal(HLocal* local) {
694 DCHECK_EQ(local->GetBlock(), GetGraph()->GetEntryBlock());
695}
696
697void LocationsBuilderX86_64::VisitLoadLocal(HLoadLocal* local) {
698 local->SetLocations(nullptr);
699}
700
701void InstructionCodeGeneratorX86_64::VisitLoadLocal(HLoadLocal* load) {
702 // Nothing to do, this is driven by the code generator.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -0700703 UNUSED(load);
Nicolas Geoffray9cf35522014-06-09 18:40:10 +0100704}
705
706void LocationsBuilderX86_64::VisitStoreLocal(HStoreLocal* store) {
Nicolas Geoffray39468442014-09-02 15:17:15 +0100707 LocationSummary* locations =
708 new (GetGraph()->GetArena()) LocationSummary(store, LocationSummary::kNoCall);
Nicolas Geoffray9cf35522014-06-09 18:40:10 +0100709 switch (store->InputAt(1)->GetType()) {
710 case Primitive::kPrimBoolean:
711 case Primitive::kPrimByte:
712 case Primitive::kPrimChar:
713 case Primitive::kPrimShort:
714 case Primitive::kPrimInt:
715 case Primitive::kPrimNot:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100716 case Primitive::kPrimFloat:
Nicolas Geoffray9cf35522014-06-09 18:40:10 +0100717 locations->SetInAt(1, Location::StackSlot(codegen_->GetStackSlot(store->GetLocal())));
718 break;
719
720 case Primitive::kPrimLong:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100721 case Primitive::kPrimDouble:
Nicolas Geoffray9cf35522014-06-09 18:40:10 +0100722 locations->SetInAt(1, Location::DoubleStackSlot(codegen_->GetStackSlot(store->GetLocal())));
723 break;
724
725 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100726 LOG(FATAL) << "Unexpected local type " << store->InputAt(1)->GetType();
Nicolas Geoffray9cf35522014-06-09 18:40:10 +0100727 }
Nicolas Geoffray9cf35522014-06-09 18:40:10 +0100728}
729
730void InstructionCodeGeneratorX86_64::VisitStoreLocal(HStoreLocal* store) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -0700731 UNUSED(store);
Nicolas Geoffray9cf35522014-06-09 18:40:10 +0100732}
733
Dave Allison20dfc792014-06-16 20:44:29 -0700734void LocationsBuilderX86_64::VisitCondition(HCondition* comp) {
Nicolas Geoffray39468442014-09-02 15:17:15 +0100735 LocationSummary* locations =
736 new (GetGraph()->GetArena()) LocationSummary(comp, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +0100737 locations->SetInAt(0, Location::RequiresRegister());
738 locations->SetInAt(1, Location::Any());
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100739 if (comp->NeedsMaterialization()) {
740 locations->SetOut(Location::RequiresRegister());
741 }
Nicolas Geoffray9cf35522014-06-09 18:40:10 +0100742}
743
Dave Allison20dfc792014-06-16 20:44:29 -0700744void InstructionCodeGeneratorX86_64::VisitCondition(HCondition* comp) {
745 if (comp->NeedsMaterialization()) {
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100746 LocationSummary* locations = comp->GetLocations();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100747 CpuRegister reg = locations->Out().As<CpuRegister>();
Nicolas Geoffray18efde52014-09-22 15:51:11 +0100748 // Clear register: setcc only sets the low byte.
749 __ xorq(reg, reg);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100750 if (locations->InAt(1).IsRegister()) {
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100751 __ cmpl(locations->InAt(0).As<CpuRegister>(),
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100752 locations->InAt(1).As<CpuRegister>());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100753 } else if (locations->InAt(1).IsConstant()) {
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100754 __ cmpl(locations->InAt(0).As<CpuRegister>(),
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100755 Immediate(locations->InAt(1).GetConstant()->AsIntConstant()->GetValue()));
756 } else {
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100757 __ cmpl(locations->InAt(0).As<CpuRegister>(),
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100758 Address(CpuRegister(RSP), locations->InAt(1).GetStackIndex()));
759 }
Nicolas Geoffray18efde52014-09-22 15:51:11 +0100760 __ setcc(X86_64Condition(comp->GetCondition()), reg);
Dave Allison20dfc792014-06-16 20:44:29 -0700761 }
762}
763
764void LocationsBuilderX86_64::VisitEqual(HEqual* comp) {
765 VisitCondition(comp);
766}
767
768void InstructionCodeGeneratorX86_64::VisitEqual(HEqual* comp) {
769 VisitCondition(comp);
770}
771
772void LocationsBuilderX86_64::VisitNotEqual(HNotEqual* comp) {
773 VisitCondition(comp);
774}
775
776void InstructionCodeGeneratorX86_64::VisitNotEqual(HNotEqual* comp) {
777 VisitCondition(comp);
778}
779
780void LocationsBuilderX86_64::VisitLessThan(HLessThan* comp) {
781 VisitCondition(comp);
782}
783
784void InstructionCodeGeneratorX86_64::VisitLessThan(HLessThan* comp) {
785 VisitCondition(comp);
786}
787
788void LocationsBuilderX86_64::VisitLessThanOrEqual(HLessThanOrEqual* comp) {
789 VisitCondition(comp);
790}
791
792void InstructionCodeGeneratorX86_64::VisitLessThanOrEqual(HLessThanOrEqual* comp) {
793 VisitCondition(comp);
794}
795
796void LocationsBuilderX86_64::VisitGreaterThan(HGreaterThan* comp) {
797 VisitCondition(comp);
798}
799
800void InstructionCodeGeneratorX86_64::VisitGreaterThan(HGreaterThan* comp) {
801 VisitCondition(comp);
802}
803
804void LocationsBuilderX86_64::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) {
805 VisitCondition(comp);
806}
807
808void InstructionCodeGeneratorX86_64::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) {
809 VisitCondition(comp);
Nicolas Geoffray9cf35522014-06-09 18:40:10 +0100810}
811
Nicolas Geoffray412f10c2014-06-19 10:00:34 +0100812void LocationsBuilderX86_64::VisitCompare(HCompare* compare) {
Nicolas Geoffray39468442014-09-02 15:17:15 +0100813 LocationSummary* locations =
814 new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +0100815 locations->SetInAt(0, Location::RequiresRegister());
816 locations->SetInAt(1, Location::RequiresRegister());
817 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray412f10c2014-06-19 10:00:34 +0100818}
819
820void InstructionCodeGeneratorX86_64::VisitCompare(HCompare* compare) {
821 Label greater, done;
822 LocationSummary* locations = compare->GetLocations();
823 switch (compare->InputAt(0)->GetType()) {
824 case Primitive::kPrimLong:
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100825 __ cmpq(locations->InAt(0).As<CpuRegister>(),
826 locations->InAt(1).As<CpuRegister>());
Nicolas Geoffray412f10c2014-06-19 10:00:34 +0100827 break;
828 default:
829 LOG(FATAL) << "Unimplemented compare type " << compare->InputAt(0)->GetType();
830 }
831
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100832 CpuRegister output = locations->Out().As<CpuRegister>();
833 __ movl(output, Immediate(0));
Nicolas Geoffray412f10c2014-06-19 10:00:34 +0100834 __ j(kEqual, &done);
835 __ j(kGreater, &greater);
836
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100837 __ movl(output, Immediate(-1));
Nicolas Geoffray412f10c2014-06-19 10:00:34 +0100838 __ jmp(&done);
839
840 __ Bind(&greater);
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100841 __ movl(output, Immediate(1));
Nicolas Geoffray412f10c2014-06-19 10:00:34 +0100842
843 __ Bind(&done);
844}
845
Nicolas Geoffray9cf35522014-06-09 18:40:10 +0100846void LocationsBuilderX86_64::VisitIntConstant(HIntConstant* constant) {
Nicolas Geoffray39468442014-09-02 15:17:15 +0100847 LocationSummary* locations =
848 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100849 locations->SetOut(Location::ConstantLocation(constant));
Nicolas Geoffray9cf35522014-06-09 18:40:10 +0100850}
851
852void InstructionCodeGeneratorX86_64::VisitIntConstant(HIntConstant* constant) {
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100853 // Will be generated at use site.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -0700854 UNUSED(constant);
Nicolas Geoffray9cf35522014-06-09 18:40:10 +0100855}
856
857void LocationsBuilderX86_64::VisitLongConstant(HLongConstant* constant) {
Nicolas Geoffray39468442014-09-02 15:17:15 +0100858 LocationSummary* locations =
859 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100860 locations->SetOut(Location::ConstantLocation(constant));
Nicolas Geoffray9cf35522014-06-09 18:40:10 +0100861}
862
863void InstructionCodeGeneratorX86_64::VisitLongConstant(HLongConstant* constant) {
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100864 // Will be generated at use site.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -0700865 UNUSED(constant);
Nicolas Geoffray9cf35522014-06-09 18:40:10 +0100866}
867
Nicolas Geoffray102cbed2014-10-15 18:31:05 +0100868void LocationsBuilderX86_64::VisitFloatConstant(HFloatConstant* constant) {
869 LocationSummary* locations =
870 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
871 locations->SetOut(Location::ConstantLocation(constant));
872}
873
874void InstructionCodeGeneratorX86_64::VisitFloatConstant(HFloatConstant* constant) {
875 // Will be generated at use site.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -0700876 UNUSED(constant);
Nicolas Geoffray102cbed2014-10-15 18:31:05 +0100877}
878
879void LocationsBuilderX86_64::VisitDoubleConstant(HDoubleConstant* constant) {
880 LocationSummary* locations =
881 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
882 locations->SetOut(Location::ConstantLocation(constant));
883}
884
885void InstructionCodeGeneratorX86_64::VisitDoubleConstant(HDoubleConstant* constant) {
886 // Will be generated at use site.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -0700887 UNUSED(constant);
Nicolas Geoffray102cbed2014-10-15 18:31:05 +0100888}
889
Nicolas Geoffray9cf35522014-06-09 18:40:10 +0100890void LocationsBuilderX86_64::VisitReturnVoid(HReturnVoid* ret) {
891 ret->SetLocations(nullptr);
892}
893
894void InstructionCodeGeneratorX86_64::VisitReturnVoid(HReturnVoid* ret) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -0700895 UNUSED(ret);
Nicolas Geoffray9cf35522014-06-09 18:40:10 +0100896 codegen_->GenerateFrameExit();
897 __ ret();
898}
899
900void LocationsBuilderX86_64::VisitReturn(HReturn* ret) {
Nicolas Geoffray39468442014-09-02 15:17:15 +0100901 LocationSummary* locations =
902 new (GetGraph()->GetArena()) LocationSummary(ret, LocationSummary::kNoCall);
Nicolas Geoffray9cf35522014-06-09 18:40:10 +0100903 switch (ret->InputAt(0)->GetType()) {
904 case Primitive::kPrimBoolean:
905 case Primitive::kPrimByte:
906 case Primitive::kPrimChar:
907 case Primitive::kPrimShort:
908 case Primitive::kPrimInt:
909 case Primitive::kPrimNot:
910 case Primitive::kPrimLong:
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100911 locations->SetInAt(0, Location::RegisterLocation(RAX));
Nicolas Geoffray9cf35522014-06-09 18:40:10 +0100912 break;
913
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100914 case Primitive::kPrimFloat:
915 case Primitive::kPrimDouble:
916 locations->SetInAt(0,
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100917 Location::FpuRegisterLocation(XMM0));
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100918 break;
919
Nicolas Geoffray9cf35522014-06-09 18:40:10 +0100920 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100921 LOG(FATAL) << "Unexpected return type " << ret->InputAt(0)->GetType();
Nicolas Geoffray9cf35522014-06-09 18:40:10 +0100922 }
Nicolas Geoffray9cf35522014-06-09 18:40:10 +0100923}
924
925void InstructionCodeGeneratorX86_64::VisitReturn(HReturn* ret) {
926 if (kIsDebugBuild) {
927 switch (ret->InputAt(0)->GetType()) {
928 case Primitive::kPrimBoolean:
929 case Primitive::kPrimByte:
930 case Primitive::kPrimChar:
931 case Primitive::kPrimShort:
932 case Primitive::kPrimInt:
933 case Primitive::kPrimNot:
934 case Primitive::kPrimLong:
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100935 DCHECK_EQ(ret->GetLocations()->InAt(0).As<CpuRegister>().AsRegister(), RAX);
Nicolas Geoffray9cf35522014-06-09 18:40:10 +0100936 break;
937
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100938 case Primitive::kPrimFloat:
939 case Primitive::kPrimDouble:
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100940 DCHECK_EQ(ret->GetLocations()->InAt(0).As<XmmRegister>().AsFloatRegister(),
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100941 XMM0);
942 break;
943
Nicolas Geoffray9cf35522014-06-09 18:40:10 +0100944 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100945 LOG(FATAL) << "Unexpected return type " << ret->InputAt(0)->GetType();
Nicolas Geoffray9cf35522014-06-09 18:40:10 +0100946 }
947 }
948 codegen_->GenerateFrameExit();
949 __ ret();
950}
951
Nicolas Geoffray9cf35522014-06-09 18:40:10 +0100952Location InvokeDexCallingConventionVisitor::GetNextLocation(Primitive::Type type) {
953 switch (type) {
954 case Primitive::kPrimBoolean:
955 case Primitive::kPrimByte:
956 case Primitive::kPrimChar:
957 case Primitive::kPrimShort:
958 case Primitive::kPrimInt:
959 case Primitive::kPrimNot: {
960 uint32_t index = gp_index_++;
961 stack_index_++;
962 if (index < calling_convention.GetNumberOfRegisters()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100963 return Location::RegisterLocation(calling_convention.GetRegisterAt(index));
Nicolas Geoffray9cf35522014-06-09 18:40:10 +0100964 } else {
965 return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 1));
966 }
967 }
968
969 case Primitive::kPrimLong: {
970 uint32_t index = gp_index_;
971 stack_index_ += 2;
972 if (index < calling_convention.GetNumberOfRegisters()) {
973 gp_index_ += 1;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100974 return Location::RegisterLocation(calling_convention.GetRegisterAt(index));
Nicolas Geoffray9cf35522014-06-09 18:40:10 +0100975 } else {
976 gp_index_ += 2;
977 return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 2));
978 }
979 }
980
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100981 case Primitive::kPrimFloat: {
982 uint32_t index = fp_index_++;
983 stack_index_++;
984 if (index < calling_convention.GetNumberOfFpuRegisters()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100985 return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(index));
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100986 } else {
987 return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 1));
988 }
989 }
990
991 case Primitive::kPrimDouble: {
992 uint32_t index = fp_index_++;
993 stack_index_ += 2;
994 if (index < calling_convention.GetNumberOfFpuRegisters()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100995 return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(index));
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100996 } else {
997 return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 2));
998 }
999 }
Nicolas Geoffray9cf35522014-06-09 18:40:10 +01001000
1001 case Primitive::kPrimVoid:
1002 LOG(FATAL) << "Unexpected parameter type " << type;
1003 break;
1004 }
1005 return Location();
1006}
1007
1008void LocationsBuilderX86_64::VisitInvokeStatic(HInvokeStatic* invoke) {
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001009 HandleInvoke(invoke);
1010}
1011
1012void InstructionCodeGeneratorX86_64::VisitInvokeStatic(HInvokeStatic* invoke) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001013 CpuRegister temp = invoke->GetLocations()->GetTemp(0).As<CpuRegister>();
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001014 // TODO: Implement all kinds of calls:
1015 // 1) boot -> boot
1016 // 2) app -> boot
1017 // 3) app -> app
1018 //
1019 // Currently we implement the app -> app logic, which looks up in the resolve cache.
1020
1021 // temp = method;
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01001022 codegen_->LoadCurrentMethod(temp);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001023 // temp = temp->dex_cache_resolved_methods_;
1024 __ movl(temp, Address(temp, mirror::ArtMethod::DexCacheResolvedMethodsOffset().SizeValue()));
1025 // temp = temp[index_in_cache]
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01001026 __ movl(temp, Address(temp, CodeGenerator::GetCacheOffset(invoke->GetIndexInDexCache())));
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001027 // (temp + offset_of_quick_compiled_code)()
1028 __ call(Address(temp, mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset().SizeValue()));
1029
1030 DCHECK(!codegen_->IsLeafMethod());
1031 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
1032}
1033
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001034void LocationsBuilderX86_64::HandleInvoke(HInvoke* invoke) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001035 LocationSummary* locations =
1036 new (GetGraph()->GetArena()) LocationSummary(invoke, LocationSummary::kCall);
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001037 locations->AddTemp(Location::RegisterLocation(RDI));
Nicolas Geoffray9cf35522014-06-09 18:40:10 +01001038
1039 InvokeDexCallingConventionVisitor calling_convention_visitor;
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001040 for (size_t i = 0; i < invoke->InputCount(); i++) {
Nicolas Geoffray9cf35522014-06-09 18:40:10 +01001041 HInstruction* input = invoke->InputAt(i);
1042 locations->SetInAt(i, calling_convention_visitor.GetNextLocation(input->GetType()));
1043 }
1044
1045 switch (invoke->GetType()) {
1046 case Primitive::kPrimBoolean:
1047 case Primitive::kPrimByte:
1048 case Primitive::kPrimChar:
1049 case Primitive::kPrimShort:
1050 case Primitive::kPrimInt:
1051 case Primitive::kPrimNot:
1052 case Primitive::kPrimLong:
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001053 locations->SetOut(Location::RegisterLocation(RAX));
Nicolas Geoffray9cf35522014-06-09 18:40:10 +01001054 break;
1055
1056 case Primitive::kPrimVoid:
1057 break;
1058
1059 case Primitive::kPrimDouble:
1060 case Primitive::kPrimFloat:
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001061 locations->SetOut(Location::FpuRegisterLocation(XMM0));
Nicolas Geoffray9cf35522014-06-09 18:40:10 +01001062 break;
1063 }
Nicolas Geoffray9cf35522014-06-09 18:40:10 +01001064}
1065
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001066void LocationsBuilderX86_64::VisitInvokeVirtual(HInvokeVirtual* invoke) {
1067 HandleInvoke(invoke);
1068}
1069
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001070void InstructionCodeGeneratorX86_64::VisitInvokeVirtual(HInvokeVirtual* invoke) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001071 CpuRegister temp = invoke->GetLocations()->GetTemp(0).As<CpuRegister>();
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001072 size_t method_offset = mirror::Class::EmbeddedVTableOffset().SizeValue() +
1073 invoke->GetVTableIndex() * sizeof(mirror::Class::VTableEntry);
1074 LocationSummary* locations = invoke->GetLocations();
1075 Location receiver = locations->InAt(0);
1076 size_t class_offset = mirror::Object::ClassOffset().SizeValue();
1077 // temp = object->GetClass();
1078 if (receiver.IsStackSlot()) {
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001079 __ movl(temp, Address(CpuRegister(RSP), receiver.GetStackIndex()));
1080 __ movl(temp, Address(temp, class_offset));
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001081 } else {
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001082 __ movl(temp, Address(receiver.As<CpuRegister>(), class_offset));
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001083 }
1084 // temp = temp->GetMethodAt(method_offset);
1085 __ movl(temp, Address(temp, method_offset));
1086 // call temp->GetEntryPoint();
Nicolas Geoffray9cf35522014-06-09 18:40:10 +01001087 __ call(Address(temp, mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset().SizeValue()));
1088
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +01001089 DCHECK(!codegen_->IsLeafMethod());
Nicolas Geoffray39468442014-09-02 15:17:15 +01001090 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
Nicolas Geoffray9cf35522014-06-09 18:40:10 +01001091}
1092
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001093void LocationsBuilderX86_64::VisitInvokeInterface(HInvokeInterface* invoke) {
1094 HandleInvoke(invoke);
1095 // Add the hidden argument.
1096 invoke->GetLocations()->AddTemp(Location::RegisterLocation(RAX));
1097}
1098
1099void InstructionCodeGeneratorX86_64::VisitInvokeInterface(HInvokeInterface* invoke) {
1100 // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError.
1101 CpuRegister temp = invoke->GetLocations()->GetTemp(0).As<CpuRegister>();
1102 uint32_t method_offset = mirror::Class::EmbeddedImTableOffset().Uint32Value() +
1103 (invoke->GetImtIndex() % mirror::Class::kImtSize) * sizeof(mirror::Class::ImTableEntry);
1104 LocationSummary* locations = invoke->GetLocations();
1105 Location receiver = locations->InAt(0);
1106 size_t class_offset = mirror::Object::ClassOffset().SizeValue();
1107
1108 // Set the hidden argument.
1109 __ movq(invoke->GetLocations()->GetTemp(1).As<CpuRegister>(),
1110 Immediate(invoke->GetDexMethodIndex()));
1111
1112 // temp = object->GetClass();
1113 if (receiver.IsStackSlot()) {
1114 __ movl(temp, Address(CpuRegister(RSP), receiver.GetStackIndex()));
1115 __ movl(temp, Address(temp, class_offset));
1116 } else {
1117 __ movl(temp, Address(receiver.As<CpuRegister>(), class_offset));
1118 }
1119 // temp = temp->GetImtEntryAt(method_offset);
1120 __ movl(temp, Address(temp, method_offset));
1121 // call temp->GetEntryPoint();
1122 __ call(Address(temp, mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset().SizeValue()));
1123
1124 DCHECK(!codegen_->IsLeafMethod());
1125 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
1126}
1127
Roland Levillain88cb1752014-10-20 16:36:47 +01001128void LocationsBuilderX86_64::VisitNeg(HNeg* neg) {
1129 LocationSummary* locations =
1130 new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall);
1131 switch (neg->GetResultType()) {
1132 case Primitive::kPrimInt:
Roland Levillain2e07b4f2014-10-23 18:12:09 +01001133 case Primitive::kPrimLong:
Roland Levillain88cb1752014-10-20 16:36:47 +01001134 locations->SetInAt(0, Location::RequiresRegister());
1135 locations->SetOut(Location::SameAsFirstInput());
1136 break;
1137
Roland Levillain88cb1752014-10-20 16:36:47 +01001138 case Primitive::kPrimFloat:
1139 case Primitive::kPrimDouble:
Roland Levillain3dbcb382014-10-28 17:30:07 +00001140 locations->SetInAt(0, Location::RequiresFpuRegister());
1141 // Output overlaps as we need a fresh (zero-initialized)
1142 // register to perform subtraction from zero.
1143 locations->SetOut(Location::RequiresFpuRegister());
Roland Levillain88cb1752014-10-20 16:36:47 +01001144 break;
1145
1146 default:
1147 LOG(FATAL) << "Unexpected neg type " << neg->GetResultType();
1148 }
1149}
1150
1151void InstructionCodeGeneratorX86_64::VisitNeg(HNeg* neg) {
1152 LocationSummary* locations = neg->GetLocations();
1153 Location out = locations->Out();
1154 Location in = locations->InAt(0);
1155 switch (neg->GetResultType()) {
1156 case Primitive::kPrimInt:
1157 DCHECK(in.IsRegister());
Roland Levillain3dbcb382014-10-28 17:30:07 +00001158 DCHECK(in.Equals(out));
Roland Levillain88cb1752014-10-20 16:36:47 +01001159 __ negl(out.As<CpuRegister>());
1160 break;
1161
1162 case Primitive::kPrimLong:
Roland Levillain2e07b4f2014-10-23 18:12:09 +01001163 DCHECK(in.IsRegister());
Roland Levillain3dbcb382014-10-28 17:30:07 +00001164 DCHECK(in.Equals(out));
Roland Levillain2e07b4f2014-10-23 18:12:09 +01001165 __ negq(out.As<CpuRegister>());
1166 break;
1167
Roland Levillain88cb1752014-10-20 16:36:47 +01001168 case Primitive::kPrimFloat:
Roland Levillain3dbcb382014-10-28 17:30:07 +00001169 DCHECK(in.IsFpuRegister());
1170 DCHECK(out.IsFpuRegister());
1171 DCHECK(!in.Equals(out));
1172 // TODO: Instead of computing negation as a subtraction from
1173 // zero, implement it with an exclusive or with value 0x80000000
1174 // (mask for bit 31, representing the sign of a single-precision
1175 // floating-point number), fetched from a constant pool:
1176 //
1177 // xorps out, [RIP:...] // value at RIP is 0x80 00 00 00
1178
1179 // out = 0
1180 __ xorps(out.As<XmmRegister>(), out.As<XmmRegister>());
1181 // out = out - in
1182 __ subss(out.As<XmmRegister>(), in.As<XmmRegister>());
1183 break;
1184
Roland Levillain88cb1752014-10-20 16:36:47 +01001185 case Primitive::kPrimDouble:
Roland Levillain3dbcb382014-10-28 17:30:07 +00001186 DCHECK(in.IsFpuRegister());
1187 DCHECK(out.IsFpuRegister());
1188 DCHECK(!in.Equals(out));
1189 // TODO: Instead of computing negation as a subtraction from
1190 // zero, implement it with an exclusive or with value
1191 // 0x8000000000000000 (mask for bit 63, representing the sign of
1192 // a double-precision floating-point number), fetched from a
1193 // constant pool:
1194 //
1195 // xorpd out, [RIP:...] // value at RIP is 0x80 00 00 00 00 00 00 00
1196
1197 // out = 0
1198 __ xorpd(out.As<XmmRegister>(), out.As<XmmRegister>());
1199 // out = out - in
1200 __ subsd(out.As<XmmRegister>(), in.As<XmmRegister>());
Roland Levillain88cb1752014-10-20 16:36:47 +01001201 break;
1202
1203 default:
1204 LOG(FATAL) << "Unexpected neg type " << neg->GetResultType();
1205 }
1206}
1207
Roland Levillaindff1f282014-11-05 14:15:05 +00001208void LocationsBuilderX86_64::VisitTypeConversion(HTypeConversion* conversion) {
1209 LocationSummary* locations =
1210 new (GetGraph()->GetArena()) LocationSummary(conversion, LocationSummary::kNoCall);
1211 Primitive::Type result_type = conversion->GetResultType();
1212 Primitive::Type input_type = conversion->GetInputType();
1213 switch (result_type) {
1214 case Primitive::kPrimLong:
1215 switch (input_type) {
1216 case Primitive::kPrimByte:
1217 case Primitive::kPrimShort:
1218 case Primitive::kPrimInt:
1219 // int-to-long conversion.
1220 // TODO: We would benefit from a (to-be-implemented)
1221 // Location::RegisterOrStackSlot requirement for this input.
1222 locations->SetInAt(0, Location::RequiresRegister());
1223 locations->SetOut(Location::RequiresRegister());
1224 break;
1225
1226 case Primitive::kPrimFloat:
1227 case Primitive::kPrimDouble:
1228 LOG(FATAL) << "Type conversion from " << input_type << " to "
1229 << result_type << " not yet implemented";
1230 break;
1231
1232 default:
1233 LOG(FATAL) << "Unexpected type conversion from " << input_type
1234 << " to " << result_type;
1235 }
1236 break;
1237
1238 case Primitive::kPrimInt:
1239 case Primitive::kPrimFloat:
1240 case Primitive::kPrimDouble:
1241 LOG(FATAL) << "Type conversion from " << input_type
1242 << " to " << result_type << " not yet implemented";
1243 break;
1244
1245 default:
1246 LOG(FATAL) << "Unexpected type conversion from " << input_type
1247 << " to " << result_type;
1248 }
1249}
1250
1251void InstructionCodeGeneratorX86_64::VisitTypeConversion(HTypeConversion* conversion) {
1252 LocationSummary* locations = conversion->GetLocations();
1253 Location out = locations->Out();
1254 Location in = locations->InAt(0);
1255 Primitive::Type result_type = conversion->GetResultType();
1256 Primitive::Type input_type = conversion->GetInputType();
1257 switch (result_type) {
1258 case Primitive::kPrimLong:
1259 switch (input_type) {
1260 DCHECK(out.IsRegister());
1261 case Primitive::kPrimByte:
1262 case Primitive::kPrimShort:
1263 case Primitive::kPrimInt:
1264 // int-to-long conversion.
1265 DCHECK(in.IsRegister());
1266 __ movsxd(out.As<CpuRegister>(), in.As<CpuRegister>());
1267 break;
1268
1269 case Primitive::kPrimFloat:
1270 case Primitive::kPrimDouble:
1271 LOG(FATAL) << "Type conversion from " << input_type << " to "
1272 << result_type << " not yet implemented";
1273 break;
1274
1275 default:
1276 LOG(FATAL) << "Unexpected type conversion from " << input_type
1277 << " to " << result_type;
1278 }
1279 break;
1280
1281 case Primitive::kPrimInt:
1282 case Primitive::kPrimFloat:
1283 case Primitive::kPrimDouble:
1284 LOG(FATAL) << "Type conversion from " << input_type
1285 << " to " << result_type << " not yet implemented";
1286 break;
1287
1288 default:
1289 LOG(FATAL) << "Unexpected type conversion from " << input_type
1290 << " to " << result_type;
1291 }
1292}
1293
Nicolas Geoffray9cf35522014-06-09 18:40:10 +01001294void LocationsBuilderX86_64::VisitAdd(HAdd* add) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001295 LocationSummary* locations =
1296 new (GetGraph()->GetArena()) LocationSummary(add, LocationSummary::kNoCall);
Nicolas Geoffray9cf35522014-06-09 18:40:10 +01001297 switch (add->GetResultType()) {
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001298 case Primitive::kPrimInt: {
1299 locations->SetInAt(0, Location::RequiresRegister());
1300 locations->SetInAt(1, Location::Any());
1301 locations->SetOut(Location::SameAsFirstInput());
1302 break;
1303 }
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001304
Nicolas Geoffray9cf35522014-06-09 18:40:10 +01001305 case Primitive::kPrimLong: {
Nicolas Geoffrayecb2f9b2014-06-13 08:59:59 +00001306 locations->SetInAt(0, Location::RequiresRegister());
1307 locations->SetInAt(1, Location::RequiresRegister());
1308 locations->SetOut(Location::SameAsFirstInput());
Nicolas Geoffray9cf35522014-06-09 18:40:10 +01001309 break;
1310 }
1311
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001312 case Primitive::kPrimDouble:
1313 case Primitive::kPrimFloat: {
1314 locations->SetInAt(0, Location::RequiresFpuRegister());
Nicolas Geoffray102cbed2014-10-15 18:31:05 +01001315 locations->SetInAt(1, Location::RequiresFpuRegister());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001316 locations->SetOut(Location::SameAsFirstInput());
Nicolas Geoffray9cf35522014-06-09 18:40:10 +01001317 break;
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001318 }
Nicolas Geoffray9cf35522014-06-09 18:40:10 +01001319
1320 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001321 LOG(FATAL) << "Unexpected add type " << add->GetResultType();
Nicolas Geoffray9cf35522014-06-09 18:40:10 +01001322 }
Nicolas Geoffray9cf35522014-06-09 18:40:10 +01001323}
1324
1325void InstructionCodeGeneratorX86_64::VisitAdd(HAdd* add) {
1326 LocationSummary* locations = add->GetLocations();
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001327 Location first = locations->InAt(0);
1328 Location second = locations->InAt(1);
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001329 DCHECK(first.Equals(locations->Out()));
Calin Juravle11351682014-10-23 15:38:15 +01001330
Nicolas Geoffray9cf35522014-06-09 18:40:10 +01001331 switch (add->GetResultType()) {
Nicolas Geoffrayecb2f9b2014-06-13 08:59:59 +00001332 case Primitive::kPrimInt: {
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001333 if (second.IsRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001334 __ addl(first.As<CpuRegister>(), second.As<CpuRegister>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001335 } else if (second.IsConstant()) {
Calin Juravle11351682014-10-23 15:38:15 +01001336 Immediate imm(second.GetConstant()->AsIntConstant()->GetValue());
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001337 __ addl(first.As<CpuRegister>(), imm);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001338 } else {
Calin Juravle11351682014-10-23 15:38:15 +01001339 __ addl(first.As<CpuRegister>(), Address(CpuRegister(RSP), second.GetStackIndex()));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001340 }
Nicolas Geoffrayecb2f9b2014-06-13 08:59:59 +00001341 break;
1342 }
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001343
Nicolas Geoffray9cf35522014-06-09 18:40:10 +01001344 case Primitive::kPrimLong: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001345 __ addq(first.As<CpuRegister>(), second.As<CpuRegister>());
Nicolas Geoffray9cf35522014-06-09 18:40:10 +01001346 break;
1347 }
1348
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001349 case Primitive::kPrimFloat: {
Nicolas Geoffray102cbed2014-10-15 18:31:05 +01001350 __ addss(first.As<XmmRegister>(), second.As<XmmRegister>());
Nicolas Geoffray9cf35522014-06-09 18:40:10 +01001351 break;
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001352 }
1353
1354 case Primitive::kPrimDouble: {
Nicolas Geoffray102cbed2014-10-15 18:31:05 +01001355 __ addsd(first.As<XmmRegister>(), second.As<XmmRegister>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001356 break;
1357 }
Nicolas Geoffray9cf35522014-06-09 18:40:10 +01001358
1359 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001360 LOG(FATAL) << "Unexpected add type " << add->GetResultType();
Nicolas Geoffray9cf35522014-06-09 18:40:10 +01001361 }
1362}
1363
1364void LocationsBuilderX86_64::VisitSub(HSub* sub) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001365 LocationSummary* locations =
1366 new (GetGraph()->GetArena()) LocationSummary(sub, LocationSummary::kNoCall);
Nicolas Geoffray9cf35522014-06-09 18:40:10 +01001367 switch (sub->GetResultType()) {
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001368 case Primitive::kPrimInt: {
1369 locations->SetInAt(0, Location::RequiresRegister());
1370 locations->SetInAt(1, Location::Any());
1371 locations->SetOut(Location::SameAsFirstInput());
1372 break;
1373 }
Nicolas Geoffray9cf35522014-06-09 18:40:10 +01001374 case Primitive::kPrimLong: {
Nicolas Geoffrayecb2f9b2014-06-13 08:59:59 +00001375 locations->SetInAt(0, Location::RequiresRegister());
1376 locations->SetInAt(1, Location::RequiresRegister());
1377 locations->SetOut(Location::SameAsFirstInput());
Nicolas Geoffray9cf35522014-06-09 18:40:10 +01001378 break;
1379 }
Calin Juravle11351682014-10-23 15:38:15 +01001380 case Primitive::kPrimFloat:
1381 case Primitive::kPrimDouble: {
1382 locations->SetInAt(0, Location::RequiresFpuRegister());
1383 locations->SetInAt(1, Location::RequiresFpuRegister());
1384 locations->SetOut(Location::SameAsFirstInput());
Nicolas Geoffray9cf35522014-06-09 18:40:10 +01001385 break;
Calin Juravle11351682014-10-23 15:38:15 +01001386 }
Nicolas Geoffray9cf35522014-06-09 18:40:10 +01001387 default:
Calin Juravle11351682014-10-23 15:38:15 +01001388 LOG(FATAL) << "Unexpected sub type " << sub->GetResultType();
Nicolas Geoffray9cf35522014-06-09 18:40:10 +01001389 }
Nicolas Geoffray9cf35522014-06-09 18:40:10 +01001390}
1391
1392void InstructionCodeGeneratorX86_64::VisitSub(HSub* sub) {
1393 LocationSummary* locations = sub->GetLocations();
Calin Juravle11351682014-10-23 15:38:15 +01001394 Location first = locations->InAt(0);
1395 Location second = locations->InAt(1);
1396 DCHECK(first.Equals(locations->Out()));
Nicolas Geoffray9cf35522014-06-09 18:40:10 +01001397 switch (sub->GetResultType()) {
Nicolas Geoffrayecb2f9b2014-06-13 08:59:59 +00001398 case Primitive::kPrimInt: {
Calin Juravle11351682014-10-23 15:38:15 +01001399 if (second.IsRegister()) {
1400 __ subl(first.As<CpuRegister>(), second.As<CpuRegister>());
1401 } else if (second.IsConstant()) {
1402 Immediate imm(second.GetConstant()->AsIntConstant()->GetValue());
1403 __ subl(first.As<CpuRegister>(), imm);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001404 } else {
Calin Juravle11351682014-10-23 15:38:15 +01001405 __ subl(first.As<CpuRegister>(), Address(CpuRegister(RSP), second.GetStackIndex()));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001406 }
Nicolas Geoffrayecb2f9b2014-06-13 08:59:59 +00001407 break;
1408 }
Nicolas Geoffray9cf35522014-06-09 18:40:10 +01001409 case Primitive::kPrimLong: {
Calin Juravle11351682014-10-23 15:38:15 +01001410 __ subq(first.As<CpuRegister>(), second.As<CpuRegister>());
Nicolas Geoffray9cf35522014-06-09 18:40:10 +01001411 break;
1412 }
1413
Calin Juravle11351682014-10-23 15:38:15 +01001414 case Primitive::kPrimFloat: {
1415 __ subss(first.As<XmmRegister>(), second.As<XmmRegister>());
Nicolas Geoffray9cf35522014-06-09 18:40:10 +01001416 break;
Calin Juravle11351682014-10-23 15:38:15 +01001417 }
1418
1419 case Primitive::kPrimDouble: {
1420 __ subsd(first.As<XmmRegister>(), second.As<XmmRegister>());
1421 break;
1422 }
Nicolas Geoffray9cf35522014-06-09 18:40:10 +01001423
1424 default:
Calin Juravle11351682014-10-23 15:38:15 +01001425 LOG(FATAL) << "Unexpected sub type " << sub->GetResultType();
Nicolas Geoffray9cf35522014-06-09 18:40:10 +01001426 }
1427}
1428
Calin Juravle34bacdf2014-10-07 20:23:36 +01001429void LocationsBuilderX86_64::VisitMul(HMul* mul) {
1430 LocationSummary* locations =
1431 new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall);
1432 switch (mul->GetResultType()) {
1433 case Primitive::kPrimInt: {
1434 locations->SetInAt(0, Location::RequiresRegister());
1435 locations->SetInAt(1, Location::Any());
1436 locations->SetOut(Location::SameAsFirstInput());
1437 break;
1438 }
1439 case Primitive::kPrimLong: {
1440 locations->SetInAt(0, Location::RequiresRegister());
1441 locations->SetInAt(1, Location::RequiresRegister());
1442 locations->SetOut(Location::SameAsFirstInput());
1443 break;
1444 }
Calin Juravleb5bfa962014-10-21 18:02:24 +01001445 case Primitive::kPrimFloat:
1446 case Primitive::kPrimDouble: {
1447 locations->SetInAt(0, Location::RequiresFpuRegister());
1448 locations->SetInAt(1, Location::RequiresFpuRegister());
1449 locations->SetOut(Location::SameAsFirstInput());
Calin Juravle34bacdf2014-10-07 20:23:36 +01001450 break;
Calin Juravleb5bfa962014-10-21 18:02:24 +01001451 }
Calin Juravle34bacdf2014-10-07 20:23:36 +01001452
1453 default:
Calin Juravleb5bfa962014-10-21 18:02:24 +01001454 LOG(FATAL) << "Unexpected mul type " << mul->GetResultType();
Calin Juravle34bacdf2014-10-07 20:23:36 +01001455 }
1456}
1457
1458void InstructionCodeGeneratorX86_64::VisitMul(HMul* mul) {
1459 LocationSummary* locations = mul->GetLocations();
1460 Location first = locations->InAt(0);
1461 Location second = locations->InAt(1);
1462 DCHECK(first.Equals(locations->Out()));
1463 switch (mul->GetResultType()) {
1464 case Primitive::kPrimInt: {
1465 if (second.IsRegister()) {
1466 __ imull(first.As<CpuRegister>(), second.As<CpuRegister>());
1467 } else if (second.IsConstant()) {
1468 Immediate imm(second.GetConstant()->AsIntConstant()->GetValue());
1469 __ imull(first.As<CpuRegister>(), imm);
1470 } else {
1471 DCHECK(second.IsStackSlot());
1472 __ imull(first.As<CpuRegister>(), Address(CpuRegister(RSP), second.GetStackIndex()));
1473 }
1474 break;
1475 }
1476 case Primitive::kPrimLong: {
1477 __ imulq(first.As<CpuRegister>(), second.As<CpuRegister>());
1478 break;
1479 }
1480
Calin Juravleb5bfa962014-10-21 18:02:24 +01001481 case Primitive::kPrimFloat: {
1482 __ mulss(first.As<XmmRegister>(), second.As<XmmRegister>());
Calin Juravle34bacdf2014-10-07 20:23:36 +01001483 break;
Calin Juravleb5bfa962014-10-21 18:02:24 +01001484 }
1485
1486 case Primitive::kPrimDouble: {
1487 __ mulsd(first.As<XmmRegister>(), second.As<XmmRegister>());
1488 break;
1489 }
Calin Juravle34bacdf2014-10-07 20:23:36 +01001490
1491 default:
Calin Juravleb5bfa962014-10-21 18:02:24 +01001492 LOG(FATAL) << "Unexpected mul type " << mul->GetResultType();
Calin Juravle34bacdf2014-10-07 20:23:36 +01001493 }
1494}
1495
Calin Juravle7c4954d2014-10-28 16:57:40 +00001496void LocationsBuilderX86_64::VisitDiv(HDiv* div) {
1497 LocationSummary* locations =
1498 new (GetGraph()->GetArena()) LocationSummary(div, LocationSummary::kNoCall);
1499 switch (div->GetResultType()) {
Calin Juravled0d48522014-11-04 16:40:20 +00001500 case Primitive::kPrimInt: {
1501 locations->SetInAt(0, Location::RegisterLocation(RAX));
1502 locations->SetInAt(1, Location::RequiresRegister());
1503 locations->SetOut(Location::SameAsFirstInput());
1504 // Intel uses edx:eax as the dividend.
1505 locations->AddTemp(Location::RegisterLocation(RDX));
1506 break;
1507 }
Calin Juravle7c4954d2014-10-28 16:57:40 +00001508 case Primitive::kPrimLong: {
1509 LOG(FATAL) << "Not implemented div type" << div->GetResultType();
1510 break;
1511 }
1512 case Primitive::kPrimFloat:
1513 case Primitive::kPrimDouble: {
1514 locations->SetInAt(0, Location::RequiresFpuRegister());
1515 locations->SetInAt(1, Location::RequiresFpuRegister());
1516 locations->SetOut(Location::SameAsFirstInput());
1517 break;
1518 }
1519
1520 default:
1521 LOG(FATAL) << "Unexpected div type " << div->GetResultType();
1522 }
1523}
1524
1525void InstructionCodeGeneratorX86_64::VisitDiv(HDiv* div) {
1526 LocationSummary* locations = div->GetLocations();
1527 Location first = locations->InAt(0);
1528 Location second = locations->InAt(1);
1529 DCHECK(first.Equals(locations->Out()));
1530
1531 switch (div->GetResultType()) {
Calin Juravled0d48522014-11-04 16:40:20 +00001532 case Primitive::kPrimInt: {
1533 CpuRegister first_reg = first.As<CpuRegister>();
1534 CpuRegister second_reg = second.As<CpuRegister>();
1535 DCHECK_EQ(RAX, first_reg.AsRegister());
1536 DCHECK_EQ(RDX, locations->GetTemp(0).As<CpuRegister>().AsRegister());
1537
1538 SlowPathCodeX86_64* slow_path =
1539 new (GetGraph()->GetArena()) DivMinusOneSlowPathX86_64(first_reg.AsRegister());
1540 codegen_->AddSlowPath(slow_path);
1541
1542 // 0x80000000/-1 triggers an arithmetic exception!
1543 // Dividing by -1 is actually negation and -0x800000000 = 0x80000000 so
1544 // it's safe to just use negl instead of more complex comparisons.
1545
1546 __ cmpl(second_reg, Immediate(-1));
1547 __ j(kEqual, slow_path->GetEntryLabel());
1548
1549 // edx:eax <- sign-extended of eax
1550 __ cdq();
1551 // eax = quotient, edx = remainder
1552 __ idivl(second_reg);
1553
1554 __ Bind(slow_path->GetExitLabel());
1555 break;
1556 }
1557
Calin Juravle7c4954d2014-10-28 16:57:40 +00001558 case Primitive::kPrimLong: {
1559 LOG(FATAL) << "Not implemented div type" << div->GetResultType();
1560 break;
1561 }
1562
1563 case Primitive::kPrimFloat: {
1564 __ divss(first.As<XmmRegister>(), second.As<XmmRegister>());
1565 break;
1566 }
1567
1568 case Primitive::kPrimDouble: {
1569 __ divsd(first.As<XmmRegister>(), second.As<XmmRegister>());
1570 break;
1571 }
1572
1573 default:
1574 LOG(FATAL) << "Unexpected div type " << div->GetResultType();
1575 }
1576}
1577
Calin Juravled0d48522014-11-04 16:40:20 +00001578void LocationsBuilderX86_64::VisitDivZeroCheck(HDivZeroCheck* instruction) {
1579 LocationSummary* locations =
1580 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
1581 locations->SetInAt(0, Location::Any());
1582 if (instruction->HasUses()) {
1583 locations->SetOut(Location::SameAsFirstInput());
1584 }
1585}
1586
1587void InstructionCodeGeneratorX86_64::VisitDivZeroCheck(HDivZeroCheck* instruction) {
1588 SlowPathCodeX86_64* slow_path =
1589 new (GetGraph()->GetArena()) DivZeroCheckSlowPathX86_64(instruction);
1590 codegen_->AddSlowPath(slow_path);
1591
1592 LocationSummary* locations = instruction->GetLocations();
1593 Location value = locations->InAt(0);
1594
1595 if (value.IsRegister()) {
1596 __ testl(value.As<CpuRegister>(), value.As<CpuRegister>());
1597 } else if (value.IsStackSlot()) {
1598 __ cmpl(Address(CpuRegister(RSP), value.GetStackIndex()), Immediate(0));
1599 } else {
1600 DCHECK(value.IsConstant()) << value;
1601 if (value.GetConstant()->AsIntConstant()->GetValue() == 0) {
1602 __ jmp(slow_path->GetEntryLabel());
1603 }
1604 return;
1605 }
1606 __ j(kEqual, slow_path->GetEntryLabel());
1607}
1608
Nicolas Geoffray9cf35522014-06-09 18:40:10 +01001609void LocationsBuilderX86_64::VisitNewInstance(HNewInstance* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001610 LocationSummary* locations =
1611 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
Nicolas Geoffray9ae0daa2014-09-30 22:40:23 +01001612 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001613 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
1614 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
1615 locations->SetOut(Location::RegisterLocation(RAX));
Nicolas Geoffray9cf35522014-06-09 18:40:10 +01001616}
1617
1618void InstructionCodeGeneratorX86_64::VisitNewInstance(HNewInstance* instruction) {
1619 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01001620 codegen_->LoadCurrentMethod(CpuRegister(calling_convention.GetRegisterAt(1)));
Nicolas Geoffray9cf35522014-06-09 18:40:10 +01001621 __ movq(CpuRegister(calling_convention.GetRegisterAt(0)), Immediate(instruction->GetTypeIndex()));
1622
1623 __ gs()->call(Address::Absolute(
1624 QUICK_ENTRYPOINT_OFFSET(kX86_64WordSize, pAllocObjectWithAccessCheck), true));
1625
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +01001626 DCHECK(!codegen_->IsLeafMethod());
Nicolas Geoffray39468442014-09-02 15:17:15 +01001627 codegen_->RecordPcInfo(instruction, instruction->GetDexPc());
Nicolas Geoffray9cf35522014-06-09 18:40:10 +01001628}
1629
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01001630void LocationsBuilderX86_64::VisitNewArray(HNewArray* instruction) {
1631 LocationSummary* locations =
1632 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
1633 InvokeRuntimeCallingConvention calling_convention;
1634 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
1635 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
1636 locations->SetOut(Location::RegisterLocation(RAX));
1637 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(2)));
1638}
1639
1640void InstructionCodeGeneratorX86_64::VisitNewArray(HNewArray* instruction) {
1641 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01001642 codegen_->LoadCurrentMethod(CpuRegister(calling_convention.GetRegisterAt(1)));
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01001643 __ movq(CpuRegister(calling_convention.GetRegisterAt(0)), Immediate(instruction->GetTypeIndex()));
1644
1645 __ gs()->call(Address::Absolute(
1646 QUICK_ENTRYPOINT_OFFSET(kX86_64WordSize, pAllocArrayWithAccessCheck), true));
1647
1648 DCHECK(!codegen_->IsLeafMethod());
1649 codegen_->RecordPcInfo(instruction, instruction->GetDexPc());
1650}
1651
Nicolas Geoffray9cf35522014-06-09 18:40:10 +01001652void LocationsBuilderX86_64::VisitParameterValue(HParameterValue* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001653 LocationSummary* locations =
1654 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray9cf35522014-06-09 18:40:10 +01001655 Location location = parameter_visitor_.GetNextLocation(instruction->GetType());
1656 if (location.IsStackSlot()) {
1657 location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize());
1658 } else if (location.IsDoubleStackSlot()) {
1659 location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize());
1660 }
1661 locations->SetOut(location);
Nicolas Geoffray9cf35522014-06-09 18:40:10 +01001662}
1663
1664void InstructionCodeGeneratorX86_64::VisitParameterValue(HParameterValue* instruction) {
1665 // Nothing to do, the parameter is already at its location.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001666 UNUSED(instruction);
Nicolas Geoffray9cf35522014-06-09 18:40:10 +01001667}
1668
Roland Levillain1cc5f2512014-10-22 18:06:21 +01001669void LocationsBuilderX86_64::VisitNot(HNot* not_) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001670 LocationSummary* locations =
Roland Levillain1cc5f2512014-10-22 18:06:21 +01001671 new (GetGraph()->GetArena()) LocationSummary(not_, LocationSummary::kNoCall);
Nicolas Geoffrayecb2f9b2014-06-13 08:59:59 +00001672 locations->SetInAt(0, Location::RequiresRegister());
1673 locations->SetOut(Location::SameAsFirstInput());
Nicolas Geoffray9cf35522014-06-09 18:40:10 +01001674}
1675
Roland Levillain1cc5f2512014-10-22 18:06:21 +01001676void InstructionCodeGeneratorX86_64::VisitNot(HNot* not_) {
1677 LocationSummary* locations = not_->GetLocations();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001678 DCHECK_EQ(locations->InAt(0).As<CpuRegister>().AsRegister(),
1679 locations->Out().As<CpuRegister>().AsRegister());
Roland Levillain1cc5f2512014-10-22 18:06:21 +01001680 Location out = locations->Out();
1681 switch (not_->InputAt(0)->GetType()) {
1682 case Primitive::kPrimBoolean:
1683 __ xorq(out.As<CpuRegister>(), Immediate(1));
1684 break;
1685
1686 case Primitive::kPrimInt:
1687 __ notl(out.As<CpuRegister>());
1688 break;
1689
1690 case Primitive::kPrimLong:
Roland Levillain70566432014-10-24 16:20:17 +01001691 __ notq(out.As<CpuRegister>());
Roland Levillain1cc5f2512014-10-22 18:06:21 +01001692 break;
1693
1694 default:
1695 LOG(FATAL) << "Unimplemented type for not operation " << not_->GetResultType();
1696 }
Nicolas Geoffray9cf35522014-06-09 18:40:10 +01001697}
1698
1699void LocationsBuilderX86_64::VisitPhi(HPhi* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001700 LocationSummary* locations =
1701 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray9cf35522014-06-09 18:40:10 +01001702 for (size_t i = 0, e = instruction->InputCount(); i < e; ++i) {
1703 locations->SetInAt(i, Location::Any());
1704 }
1705 locations->SetOut(Location::Any());
Nicolas Geoffray9cf35522014-06-09 18:40:10 +01001706}
1707
1708void InstructionCodeGeneratorX86_64::VisitPhi(HPhi* instruction) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001709 UNUSED(instruction);
Nicolas Geoffray9cf35522014-06-09 18:40:10 +01001710 LOG(FATAL) << "Unimplemented";
1711}
1712
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001713void LocationsBuilderX86_64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001714 LocationSummary* locations =
1715 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray9ae0daa2014-09-30 22:40:23 +01001716 Primitive::Type field_type = instruction->GetFieldType();
1717 bool is_object_type = field_type == Primitive::kPrimNot;
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001718 locations->SetInAt(0, Location::RequiresRegister());
1719 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray9ae0daa2014-09-30 22:40:23 +01001720 if (is_object_type) {
1721 // Temporary registers for the write barrier.
Nicolas Geoffray1a43dd72014-07-17 15:15:34 +01001722 locations->AddTemp(Location::RequiresRegister());
1723 locations->AddTemp(Location::RequiresRegister());
1724 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001725}
1726
1727void InstructionCodeGeneratorX86_64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) {
1728 LocationSummary* locations = instruction->GetLocations();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001729 CpuRegister obj = locations->InAt(0).As<CpuRegister>();
1730 CpuRegister value = locations->InAt(1).As<CpuRegister>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001731 size_t offset = instruction->GetFieldOffset().SizeValue();
Nicolas Geoffray39468442014-09-02 15:17:15 +01001732 Primitive::Type field_type = instruction->GetFieldType();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001733
1734 switch (field_type) {
1735 case Primitive::kPrimBoolean:
1736 case Primitive::kPrimByte: {
1737 __ movb(Address(obj, offset), value);
1738 break;
1739 }
1740
1741 case Primitive::kPrimShort:
1742 case Primitive::kPrimChar: {
1743 __ movw(Address(obj, offset), value);
1744 break;
1745 }
1746
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001747 case Primitive::kPrimInt:
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001748 case Primitive::kPrimNot: {
1749 __ movl(Address(obj, offset), value);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001750 if (field_type == Primitive::kPrimNot) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001751 CpuRegister temp = locations->GetTemp(0).As<CpuRegister>();
1752 CpuRegister card = locations->GetTemp(1).As<CpuRegister>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001753 codegen_->MarkGCCard(temp, card, obj, value);
1754 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001755 break;
1756 }
1757
1758 case Primitive::kPrimLong: {
1759 __ movq(Address(obj, offset), value);
1760 break;
1761 }
1762
1763 case Primitive::kPrimFloat:
1764 case Primitive::kPrimDouble:
1765 LOG(FATAL) << "Unimplemented register type " << field_type;
Ian Rogersfc787ec2014-10-09 21:56:44 -07001766 UNREACHABLE();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001767 case Primitive::kPrimVoid:
1768 LOG(FATAL) << "Unreachable type " << field_type;
Ian Rogersfc787ec2014-10-09 21:56:44 -07001769 UNREACHABLE();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001770 }
1771}
1772
1773void LocationsBuilderX86_64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001774 LocationSummary* locations =
1775 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001776 locations->SetInAt(0, Location::RequiresRegister());
1777 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001778}
1779
1780void InstructionCodeGeneratorX86_64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) {
1781 LocationSummary* locations = instruction->GetLocations();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001782 CpuRegister obj = locations->InAt(0).As<CpuRegister>();
1783 CpuRegister out = locations->Out().As<CpuRegister>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001784 size_t offset = instruction->GetFieldOffset().SizeValue();
1785
1786 switch (instruction->GetType()) {
1787 case Primitive::kPrimBoolean: {
1788 __ movzxb(out, Address(obj, offset));
1789 break;
1790 }
1791
1792 case Primitive::kPrimByte: {
1793 __ movsxb(out, Address(obj, offset));
1794 break;
1795 }
1796
1797 case Primitive::kPrimShort: {
1798 __ movsxw(out, Address(obj, offset));
1799 break;
1800 }
1801
1802 case Primitive::kPrimChar: {
1803 __ movzxw(out, Address(obj, offset));
1804 break;
1805 }
1806
1807 case Primitive::kPrimInt:
1808 case Primitive::kPrimNot: {
1809 __ movl(out, Address(obj, offset));
1810 break;
1811 }
1812
1813 case Primitive::kPrimLong: {
1814 __ movq(out, Address(obj, offset));
1815 break;
1816 }
1817
1818 case Primitive::kPrimFloat:
1819 case Primitive::kPrimDouble:
1820 LOG(FATAL) << "Unimplemented register type " << instruction->GetType();
Ian Rogersfc787ec2014-10-09 21:56:44 -07001821 UNREACHABLE();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001822 case Primitive::kPrimVoid:
1823 LOG(FATAL) << "Unreachable type " << instruction->GetType();
Ian Rogersfc787ec2014-10-09 21:56:44 -07001824 UNREACHABLE();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001825 }
1826}
1827
1828void LocationsBuilderX86_64::VisitNullCheck(HNullCheck* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001829 LocationSummary* locations =
1830 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001831 locations->SetInAt(0, Location::Any());
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01001832 if (instruction->HasUses()) {
1833 locations->SetOut(Location::SameAsFirstInput());
1834 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001835}
1836
1837void InstructionCodeGeneratorX86_64::VisitNullCheck(HNullCheck* instruction) {
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +01001838 SlowPathCodeX86_64* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathX86_64(instruction);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001839 codegen_->AddSlowPath(slow_path);
1840
1841 LocationSummary* locations = instruction->GetLocations();
1842 Location obj = locations->InAt(0);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001843
1844 if (obj.IsRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001845 __ cmpl(obj.As<CpuRegister>(), Immediate(0));
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01001846 } else if (obj.IsStackSlot()) {
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001847 __ cmpl(Address(CpuRegister(RSP), obj.GetStackIndex()), Immediate(0));
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01001848 } else {
1849 DCHECK(obj.IsConstant()) << obj;
1850 DCHECK_EQ(obj.GetConstant()->AsIntConstant()->GetValue(), 0);
1851 __ jmp(slow_path->GetEntryLabel());
1852 return;
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001853 }
1854 __ j(kEqual, slow_path->GetEntryLabel());
1855}
1856
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001857void LocationsBuilderX86_64::VisitArrayGet(HArrayGet* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001858 LocationSummary* locations =
1859 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001860 locations->SetInAt(0, Location::RequiresRegister());
Nicolas Geoffray9ae0daa2014-09-30 22:40:23 +01001861 locations->SetInAt(
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001862 1, Location::RegisterOrConstant(instruction->InputAt(1)));
1863 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001864}
1865
1866void InstructionCodeGeneratorX86_64::VisitArrayGet(HArrayGet* instruction) {
1867 LocationSummary* locations = instruction->GetLocations();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001868 CpuRegister obj = locations->InAt(0).As<CpuRegister>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001869 Location index = locations->InAt(1);
1870
1871 switch (instruction->GetType()) {
1872 case Primitive::kPrimBoolean: {
1873 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001874 CpuRegister out = locations->Out().As<CpuRegister>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001875 if (index.IsConstant()) {
1876 __ movzxb(out, Address(obj,
1877 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset));
1878 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001879 __ movzxb(out, Address(obj, index.As<CpuRegister>(), TIMES_1, data_offset));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001880 }
1881 break;
1882 }
1883
1884 case Primitive::kPrimByte: {
1885 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int8_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001886 CpuRegister out = locations->Out().As<CpuRegister>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001887 if (index.IsConstant()) {
1888 __ movsxb(out, Address(obj,
1889 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset));
1890 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001891 __ movsxb(out, Address(obj, index.As<CpuRegister>(), TIMES_1, data_offset));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001892 }
1893 break;
1894 }
1895
1896 case Primitive::kPrimShort: {
1897 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int16_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001898 CpuRegister out = locations->Out().As<CpuRegister>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001899 if (index.IsConstant()) {
1900 __ movsxw(out, Address(obj,
1901 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset));
1902 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001903 __ movsxw(out, Address(obj, index.As<CpuRegister>(), TIMES_2, data_offset));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001904 }
1905 break;
1906 }
1907
1908 case Primitive::kPrimChar: {
1909 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001910 CpuRegister out = locations->Out().As<CpuRegister>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001911 if (index.IsConstant()) {
1912 __ movzxw(out, Address(obj,
1913 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset));
1914 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001915 __ movzxw(out, Address(obj, index.As<CpuRegister>(), TIMES_2, data_offset));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001916 }
1917 break;
1918 }
1919
1920 case Primitive::kPrimInt:
1921 case Primitive::kPrimNot: {
1922 DCHECK_EQ(sizeof(mirror::HeapReference<mirror::Object>), sizeof(int32_t));
1923 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001924 CpuRegister out = locations->Out().As<CpuRegister>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001925 if (index.IsConstant()) {
1926 __ movl(out, Address(obj,
1927 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset));
1928 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001929 __ movl(out, Address(obj, index.As<CpuRegister>(), TIMES_4, data_offset));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001930 }
1931 break;
1932 }
1933
1934 case Primitive::kPrimLong: {
1935 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001936 CpuRegister out = locations->Out().As<CpuRegister>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001937 if (index.IsConstant()) {
1938 __ movq(out, Address(obj,
1939 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset));
1940 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001941 __ movq(out, Address(obj, index.As<CpuRegister>(), TIMES_8, data_offset));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001942 }
1943 break;
1944 }
1945
Nicolas Geoffray102cbed2014-10-15 18:31:05 +01001946 case Primitive::kPrimFloat: {
1947 uint32_t data_offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value();
1948 XmmRegister out = locations->Out().As<XmmRegister>();
1949 if (index.IsConstant()) {
1950 __ movss(out, Address(obj,
1951 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset));
1952 } else {
1953 __ movss(out, Address(obj, index.As<CpuRegister>(), TIMES_4, data_offset));
1954 }
1955 break;
1956 }
1957
1958 case Primitive::kPrimDouble: {
1959 uint32_t data_offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value();
1960 XmmRegister out = locations->Out().As<XmmRegister>();
1961 if (index.IsConstant()) {
1962 __ movsd(out, Address(obj,
1963 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset));
1964 } else {
1965 __ movsd(out, Address(obj, index.As<CpuRegister>(), TIMES_8, data_offset));
1966 }
1967 break;
1968 }
1969
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001970 case Primitive::kPrimVoid:
1971 LOG(FATAL) << "Unreachable type " << instruction->GetType();
Ian Rogersfc787ec2014-10-09 21:56:44 -07001972 UNREACHABLE();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001973 }
1974}
1975
1976void LocationsBuilderX86_64::VisitArraySet(HArraySet* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001977 Primitive::Type value_type = instruction->GetComponentType();
1978 bool is_object = value_type == Primitive::kPrimNot;
1979 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(
1980 instruction, is_object ? LocationSummary::kCall : LocationSummary::kNoCall);
1981 if (is_object) {
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001982 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001983 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
1984 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
1985 locations->SetInAt(2, Location::RegisterLocation(calling_convention.GetRegisterAt(2)));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001986 } else {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001987 locations->SetInAt(0, Location::RequiresRegister());
Nicolas Geoffray9ae0daa2014-09-30 22:40:23 +01001988 locations->SetInAt(
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001989 1, Location::RegisterOrConstant(instruction->InputAt(1)));
1990 locations->SetInAt(2, Location::RequiresRegister());
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01001991 if (value_type == Primitive::kPrimLong) {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001992 locations->SetInAt(2, Location::RequiresRegister());
Nicolas Geoffray102cbed2014-10-15 18:31:05 +01001993 } else if (value_type == Primitive::kPrimFloat || value_type == Primitive::kPrimDouble) {
1994 locations->SetInAt(2, Location::RequiresFpuRegister());
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01001995 } else {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001996 locations->SetInAt(2, Location::RegisterOrConstant(instruction->InputAt(2)));
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01001997 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001998 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001999}
2000
2001void InstructionCodeGeneratorX86_64::VisitArraySet(HArraySet* instruction) {
2002 LocationSummary* locations = instruction->GetLocations();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002003 CpuRegister obj = locations->InAt(0).As<CpuRegister>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002004 Location index = locations->InAt(1);
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01002005 Location value = locations->InAt(2);
Nicolas Geoffray39468442014-09-02 15:17:15 +01002006 Primitive::Type value_type = instruction->GetComponentType();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002007
2008 switch (value_type) {
2009 case Primitive::kPrimBoolean:
2010 case Primitive::kPrimByte: {
2011 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002012 if (index.IsConstant()) {
2013 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01002014 if (value.IsRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002015 __ movb(Address(obj, offset), value.As<CpuRegister>());
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01002016 } else {
2017 __ movb(Address(obj, offset), Immediate(value.GetConstant()->AsIntConstant()->GetValue()));
2018 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002019 } else {
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01002020 if (value.IsRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002021 __ movb(Address(obj, index.As<CpuRegister>(), TIMES_1, data_offset),
2022 value.As<CpuRegister>());
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01002023 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002024 __ movb(Address(obj, index.As<CpuRegister>(), TIMES_1, data_offset),
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01002025 Immediate(value.GetConstant()->AsIntConstant()->GetValue()));
2026 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002027 }
2028 break;
2029 }
2030
2031 case Primitive::kPrimShort:
2032 case Primitive::kPrimChar: {
2033 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002034 if (index.IsConstant()) {
2035 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset;
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01002036 if (value.IsRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002037 __ movw(Address(obj, offset), value.As<CpuRegister>());
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01002038 } else {
2039 __ movw(Address(obj, offset), Immediate(value.GetConstant()->AsIntConstant()->GetValue()));
2040 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002041 } else {
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01002042 if (value.IsRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002043 __ movw(Address(obj, index.As<CpuRegister>(), TIMES_2, data_offset),
2044 value.As<CpuRegister>());
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01002045 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002046 __ movw(Address(obj, index.As<CpuRegister>(), TIMES_2, data_offset),
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01002047 Immediate(value.GetConstant()->AsIntConstant()->GetValue()));
2048 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002049 }
2050 break;
2051 }
2052
2053 case Primitive::kPrimInt: {
2054 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002055 if (index.IsConstant()) {
2056 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01002057 if (value.IsRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002058 __ movl(Address(obj, offset), value.As<CpuRegister>());
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01002059 } else {
2060 __ movl(Address(obj, offset), Immediate(value.GetConstant()->AsIntConstant()->GetValue()));
2061 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002062 } else {
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01002063 if (value.IsRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002064 __ movl(Address(obj, index.As<CpuRegister>(), TIMES_4, data_offset),
2065 value.As<CpuRegister>());
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01002066 } else {
Nicolas Geoffray102cbed2014-10-15 18:31:05 +01002067 DCHECK(value.IsConstant()) << value;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002068 __ movl(Address(obj, index.As<CpuRegister>(), TIMES_4, data_offset),
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01002069 Immediate(value.GetConstant()->AsIntConstant()->GetValue()));
2070 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002071 }
2072 break;
2073 }
2074
2075 case Primitive::kPrimNot: {
2076 __ gs()->call(Address::Absolute(QUICK_ENTRYPOINT_OFFSET(kX86_64WordSize, pAputObject), true));
2077 DCHECK(!codegen_->IsLeafMethod());
Nicolas Geoffray39468442014-09-02 15:17:15 +01002078 codegen_->RecordPcInfo(instruction, instruction->GetDexPc());
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002079 break;
2080 }
2081
2082 case Primitive::kPrimLong: {
2083 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002084 if (index.IsConstant()) {
2085 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01002086 DCHECK(value.IsRegister());
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002087 __ movq(Address(obj, offset), value.As<CpuRegister>());
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002088 } else {
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01002089 DCHECK(value.IsRegister());
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002090 __ movq(Address(obj, index.As<CpuRegister>(), TIMES_8, data_offset),
2091 value.As<CpuRegister>());
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002092 }
2093 break;
2094 }
2095
Nicolas Geoffray102cbed2014-10-15 18:31:05 +01002096 case Primitive::kPrimFloat: {
2097 uint32_t data_offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value();
2098 if (index.IsConstant()) {
2099 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
2100 DCHECK(value.IsFpuRegister());
2101 __ movss(Address(obj, offset), value.As<XmmRegister>());
2102 } else {
2103 DCHECK(value.IsFpuRegister());
2104 __ movss(Address(obj, index.As<CpuRegister>(), TIMES_4, data_offset),
2105 value.As<XmmRegister>());
2106 }
2107 break;
2108 }
2109
2110 case Primitive::kPrimDouble: {
2111 uint32_t data_offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value();
2112 if (index.IsConstant()) {
2113 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
2114 DCHECK(value.IsFpuRegister());
2115 __ movsd(Address(obj, offset), value.As<XmmRegister>());
2116 } else {
2117 DCHECK(value.IsFpuRegister());
2118 __ movsd(Address(obj, index.As<CpuRegister>(), TIMES_8, data_offset),
2119 value.As<XmmRegister>());
2120 }
2121 break;
2122 }
2123
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002124 case Primitive::kPrimVoid:
2125 LOG(FATAL) << "Unreachable type " << instruction->GetType();
Ian Rogersfc787ec2014-10-09 21:56:44 -07002126 UNREACHABLE();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002127 }
2128}
2129
2130void LocationsBuilderX86_64::VisitArrayLength(HArrayLength* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002131 LocationSummary* locations =
2132 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01002133 locations->SetInAt(0, Location::RequiresRegister());
2134 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002135}
2136
2137void InstructionCodeGeneratorX86_64::VisitArrayLength(HArrayLength* instruction) {
2138 LocationSummary* locations = instruction->GetLocations();
2139 uint32_t offset = mirror::Array::LengthOffset().Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002140 CpuRegister obj = locations->InAt(0).As<CpuRegister>();
2141 CpuRegister out = locations->Out().As<CpuRegister>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002142 __ movl(out, Address(obj, offset));
2143}
2144
2145void LocationsBuilderX86_64::VisitBoundsCheck(HBoundsCheck* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002146 LocationSummary* locations =
2147 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002148 locations->SetInAt(0, Location::RequiresRegister());
2149 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01002150 if (instruction->HasUses()) {
2151 locations->SetOut(Location::SameAsFirstInput());
2152 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002153}
2154
2155void InstructionCodeGeneratorX86_64::VisitBoundsCheck(HBoundsCheck* instruction) {
2156 LocationSummary* locations = instruction->GetLocations();
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +01002157 SlowPathCodeX86_64* slow_path = new (GetGraph()->GetArena()) BoundsCheckSlowPathX86_64(
Nicolas Geoffray39468442014-09-02 15:17:15 +01002158 instruction, locations->InAt(0), locations->InAt(1));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002159 codegen_->AddSlowPath(slow_path);
2160
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002161 CpuRegister index = locations->InAt(0).As<CpuRegister>();
2162 CpuRegister length = locations->InAt(1).As<CpuRegister>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002163
2164 __ cmpl(index, length);
2165 __ j(kAboveEqual, slow_path->GetEntryLabel());
2166}
2167
2168void CodeGeneratorX86_64::MarkGCCard(CpuRegister temp,
2169 CpuRegister card,
2170 CpuRegister object,
2171 CpuRegister value) {
2172 Label is_null;
2173 __ testl(value, value);
2174 __ j(kEqual, &is_null);
2175 __ gs()->movq(card, Address::Absolute(
2176 Thread::CardTableOffset<kX86_64WordSize>().Int32Value(), true));
2177 __ movq(temp, object);
2178 __ shrq(temp, Immediate(gc::accounting::CardTable::kCardShift));
2179 __ movb(Address(temp, card, TIMES_1, 0), card);
2180 __ Bind(&is_null);
2181}
2182
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002183void LocationsBuilderX86_64::VisitTemporary(HTemporary* temp) {
2184 temp->SetLocations(nullptr);
2185}
2186
2187void InstructionCodeGeneratorX86_64::VisitTemporary(HTemporary* temp) {
2188 // Nothing to do, this is driven by the code generator.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07002189 UNUSED(temp);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002190}
2191
Nicolas Geoffray9cf35522014-06-09 18:40:10 +01002192void LocationsBuilderX86_64::VisitParallelMove(HParallelMove* instruction) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07002193 UNUSED(instruction);
Nicolas Geoffray9cf35522014-06-09 18:40:10 +01002194 LOG(FATAL) << "Unimplemented";
2195}
2196
2197void InstructionCodeGeneratorX86_64::VisitParallelMove(HParallelMove* instruction) {
Nicolas Geoffrayecb2f9b2014-06-13 08:59:59 +00002198 codegen_->GetMoveResolver()->EmitNativeCode(instruction);
2199}
2200
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00002201void LocationsBuilderX86_64::VisitSuspendCheck(HSuspendCheck* instruction) {
2202 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath);
2203}
2204
2205void InstructionCodeGeneratorX86_64::VisitSuspendCheck(HSuspendCheck* instruction) {
Nicolas Geoffray3c049742014-09-24 18:10:46 +01002206 HBasicBlock* block = instruction->GetBlock();
2207 if (block->GetLoopInformation() != nullptr) {
2208 DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction);
2209 // The back edge will generate the suspend check.
2210 return;
2211 }
2212 if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) {
2213 // The goto will generate the suspend check.
2214 return;
2215 }
2216 GenerateSuspendCheck(instruction, nullptr);
2217}
2218
2219void InstructionCodeGeneratorX86_64::GenerateSuspendCheck(HSuspendCheck* instruction,
2220 HBasicBlock* successor) {
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00002221 SuspendCheckSlowPathX86_64* slow_path =
Nicolas Geoffray3c049742014-09-24 18:10:46 +01002222 new (GetGraph()->GetArena()) SuspendCheckSlowPathX86_64(instruction, successor);
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00002223 codegen_->AddSlowPath(slow_path);
Nicolas Geoffray3c049742014-09-24 18:10:46 +01002224 __ gs()->cmpw(Address::Absolute(
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00002225 Thread::ThreadFlagsOffset<kX86_64WordSize>().Int32Value(), true), Immediate(0));
Nicolas Geoffray3c049742014-09-24 18:10:46 +01002226 if (successor == nullptr) {
2227 __ j(kNotEqual, slow_path->GetEntryLabel());
2228 __ Bind(slow_path->GetReturnLabel());
2229 } else {
2230 __ j(kEqual, codegen_->GetLabelOf(successor));
2231 __ jmp(slow_path->GetEntryLabel());
2232 }
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00002233}
2234
Nicolas Geoffrayecb2f9b2014-06-13 08:59:59 +00002235X86_64Assembler* ParallelMoveResolverX86_64::GetAssembler() const {
2236 return codegen_->GetAssembler();
2237}
2238
2239void ParallelMoveResolverX86_64::EmitMove(size_t index) {
2240 MoveOperands* move = moves_.Get(index);
2241 Location source = move->GetSource();
2242 Location destination = move->GetDestination();
2243
2244 if (source.IsRegister()) {
2245 if (destination.IsRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002246 __ movq(destination.As<CpuRegister>(), source.As<CpuRegister>());
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002247 } else if (destination.IsStackSlot()) {
Nicolas Geoffrayecb2f9b2014-06-13 08:59:59 +00002248 __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()),
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002249 source.As<CpuRegister>());
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002250 } else {
2251 DCHECK(destination.IsDoubleStackSlot());
2252 __ movq(Address(CpuRegister(RSP), destination.GetStackIndex()),
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002253 source.As<CpuRegister>());
Nicolas Geoffrayecb2f9b2014-06-13 08:59:59 +00002254 }
2255 } else if (source.IsStackSlot()) {
2256 if (destination.IsRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002257 __ movl(destination.As<CpuRegister>(),
Nicolas Geoffrayecb2f9b2014-06-13 08:59:59 +00002258 Address(CpuRegister(RSP), source.GetStackIndex()));
Nicolas Geoffray102cbed2014-10-15 18:31:05 +01002259 } else if (destination.IsFpuRegister()) {
2260 __ movss(destination.As<XmmRegister>(),
2261 Address(CpuRegister(RSP), source.GetStackIndex()));
Nicolas Geoffrayecb2f9b2014-06-13 08:59:59 +00002262 } else {
2263 DCHECK(destination.IsStackSlot());
2264 __ movl(CpuRegister(TMP), Address(CpuRegister(RSP), source.GetStackIndex()));
2265 __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), CpuRegister(TMP));
2266 }
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002267 } else if (source.IsDoubleStackSlot()) {
2268 if (destination.IsRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002269 __ movq(destination.As<CpuRegister>(),
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002270 Address(CpuRegister(RSP), source.GetStackIndex()));
Nicolas Geoffray102cbed2014-10-15 18:31:05 +01002271 } else if (destination.IsFpuRegister()) {
2272 __ movsd(destination.As<XmmRegister>(), Address(CpuRegister(RSP), source.GetStackIndex()));
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002273 } else {
Nicolas Geoffrayc8147a72014-10-21 16:06:20 +01002274 DCHECK(destination.IsDoubleStackSlot()) << destination;
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002275 __ movq(CpuRegister(TMP), Address(CpuRegister(RSP), source.GetStackIndex()));
2276 __ movq(Address(CpuRegister(RSP), destination.GetStackIndex()), CpuRegister(TMP));
2277 }
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01002278 } else if (source.IsConstant()) {
2279 HConstant* constant = source.GetConstant();
2280 if (constant->IsIntConstant()) {
2281 Immediate imm(constant->AsIntConstant()->GetValue());
2282 if (destination.IsRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002283 __ movl(destination.As<CpuRegister>(), imm);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01002284 } else {
Nicolas Geoffray102cbed2014-10-15 18:31:05 +01002285 DCHECK(destination.IsStackSlot()) << destination;
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01002286 __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), imm);
2287 }
2288 } else if (constant->IsLongConstant()) {
2289 int64_t value = constant->AsLongConstant()->GetValue();
2290 if (destination.IsRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002291 __ movq(destination.As<CpuRegister>(), Immediate(value));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01002292 } else {
Nicolas Geoffray102cbed2014-10-15 18:31:05 +01002293 DCHECK(destination.IsDoubleStackSlot()) << destination;
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01002294 __ movq(CpuRegister(TMP), Immediate(value));
2295 __ movq(Address(CpuRegister(RSP), destination.GetStackIndex()), CpuRegister(TMP));
2296 }
Nicolas Geoffray102cbed2014-10-15 18:31:05 +01002297 } else if (constant->IsFloatConstant()) {
2298 Immediate imm(bit_cast<float, int32_t>(constant->AsFloatConstant()->GetValue()));
2299 if (destination.IsFpuRegister()) {
2300 __ movl(CpuRegister(TMP), imm);
2301 __ movd(destination.As<XmmRegister>(), CpuRegister(TMP));
2302 } else {
2303 DCHECK(destination.IsStackSlot()) << destination;
2304 __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), imm);
2305 }
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01002306 } else {
Nicolas Geoffray102cbed2014-10-15 18:31:05 +01002307 DCHECK(constant->IsDoubleConstant()) << constant->DebugName();
2308 Immediate imm(bit_cast<double, int64_t>(constant->AsDoubleConstant()->GetValue()));
2309 if (destination.IsFpuRegister()) {
2310 __ movq(CpuRegister(TMP), imm);
2311 __ movd(destination.As<XmmRegister>(), CpuRegister(TMP));
2312 } else {
2313 DCHECK(destination.IsDoubleStackSlot()) << destination;
2314 __ movq(CpuRegister(TMP), imm);
2315 __ movq(Address(CpuRegister(RSP), destination.GetStackIndex()), CpuRegister(TMP));
2316 }
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01002317 }
Nicolas Geoffray102cbed2014-10-15 18:31:05 +01002318 } else if (source.IsFpuRegister()) {
2319 if (destination.IsFpuRegister()) {
2320 __ movaps(destination.As<XmmRegister>(), source.As<XmmRegister>());
2321 } else if (destination.IsStackSlot()) {
2322 __ movss(Address(CpuRegister(RSP), destination.GetStackIndex()),
2323 source.As<XmmRegister>());
2324 } else {
2325 DCHECK(destination.IsDoubleStackSlot());
2326 __ movsd(Address(CpuRegister(RSP), destination.GetStackIndex()),
2327 source.As<XmmRegister>());
2328 }
Nicolas Geoffrayecb2f9b2014-06-13 08:59:59 +00002329 }
2330}
2331
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002332void ParallelMoveResolverX86_64::Exchange32(CpuRegister reg, int mem) {
Nicolas Geoffrayecb2f9b2014-06-13 08:59:59 +00002333 __ movl(CpuRegister(TMP), Address(CpuRegister(RSP), mem));
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002334 __ movl(Address(CpuRegister(RSP), mem), reg);
2335 __ movl(reg, CpuRegister(TMP));
Nicolas Geoffrayecb2f9b2014-06-13 08:59:59 +00002336}
2337
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002338void ParallelMoveResolverX86_64::Exchange32(int mem1, int mem2) {
Nicolas Geoffrayecb2f9b2014-06-13 08:59:59 +00002339 ScratchRegisterScope ensure_scratch(
2340 this, TMP, RAX, codegen_->GetNumberOfCoreRegisters());
2341
2342 int stack_offset = ensure_scratch.IsSpilled() ? kX86_64WordSize : 0;
2343 __ movl(CpuRegister(TMP), Address(CpuRegister(RSP), mem1 + stack_offset));
2344 __ movl(CpuRegister(ensure_scratch.GetRegister()),
2345 Address(CpuRegister(RSP), mem2 + stack_offset));
2346 __ movl(Address(CpuRegister(RSP), mem2 + stack_offset), CpuRegister(TMP));
2347 __ movl(Address(CpuRegister(RSP), mem1 + stack_offset),
2348 CpuRegister(ensure_scratch.GetRegister()));
2349}
2350
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002351void ParallelMoveResolverX86_64::Exchange64(CpuRegister reg, int mem) {
2352 __ movq(CpuRegister(TMP), Address(CpuRegister(RSP), mem));
2353 __ movq(Address(CpuRegister(RSP), mem), reg);
2354 __ movq(reg, CpuRegister(TMP));
2355}
2356
2357void ParallelMoveResolverX86_64::Exchange64(int mem1, int mem2) {
2358 ScratchRegisterScope ensure_scratch(
2359 this, TMP, RAX, codegen_->GetNumberOfCoreRegisters());
2360
2361 int stack_offset = ensure_scratch.IsSpilled() ? kX86_64WordSize : 0;
2362 __ movq(CpuRegister(TMP), Address(CpuRegister(RSP), mem1 + stack_offset));
2363 __ movq(CpuRegister(ensure_scratch.GetRegister()),
2364 Address(CpuRegister(RSP), mem2 + stack_offset));
2365 __ movq(Address(CpuRegister(RSP), mem2 + stack_offset), CpuRegister(TMP));
2366 __ movq(Address(CpuRegister(RSP), mem1 + stack_offset),
2367 CpuRegister(ensure_scratch.GetRegister()));
2368}
2369
Nicolas Geoffray102cbed2014-10-15 18:31:05 +01002370void ParallelMoveResolverX86_64::Exchange32(XmmRegister reg, int mem) {
2371 __ movl(CpuRegister(TMP), Address(CpuRegister(RSP), mem));
2372 __ movss(Address(CpuRegister(RSP), mem), reg);
2373 __ movd(reg, CpuRegister(TMP));
2374}
2375
2376void ParallelMoveResolverX86_64::Exchange64(XmmRegister reg, int mem) {
2377 __ movq(CpuRegister(TMP), Address(CpuRegister(RSP), mem));
2378 __ movsd(Address(CpuRegister(RSP), mem), reg);
2379 __ movd(reg, CpuRegister(TMP));
2380}
2381
Nicolas Geoffrayecb2f9b2014-06-13 08:59:59 +00002382void ParallelMoveResolverX86_64::EmitSwap(size_t index) {
2383 MoveOperands* move = moves_.Get(index);
2384 Location source = move->GetSource();
2385 Location destination = move->GetDestination();
2386
2387 if (source.IsRegister() && destination.IsRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002388 __ xchgq(destination.As<CpuRegister>(), source.As<CpuRegister>());
Nicolas Geoffrayecb2f9b2014-06-13 08:59:59 +00002389 } else if (source.IsRegister() && destination.IsStackSlot()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002390 Exchange32(source.As<CpuRegister>(), destination.GetStackIndex());
Nicolas Geoffrayecb2f9b2014-06-13 08:59:59 +00002391 } else if (source.IsStackSlot() && destination.IsRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002392 Exchange32(destination.As<CpuRegister>(), source.GetStackIndex());
Nicolas Geoffrayecb2f9b2014-06-13 08:59:59 +00002393 } else if (source.IsStackSlot() && destination.IsStackSlot()) {
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002394 Exchange32(destination.GetStackIndex(), source.GetStackIndex());
2395 } else if (source.IsRegister() && destination.IsDoubleStackSlot()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002396 Exchange64(source.As<CpuRegister>(), destination.GetStackIndex());
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002397 } else if (source.IsDoubleStackSlot() && destination.IsRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002398 Exchange64(destination.As<CpuRegister>(), source.GetStackIndex());
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002399 } else if (source.IsDoubleStackSlot() && destination.IsDoubleStackSlot()) {
2400 Exchange64(destination.GetStackIndex(), source.GetStackIndex());
Nicolas Geoffray102cbed2014-10-15 18:31:05 +01002401 } else if (source.IsFpuRegister() && destination.IsFpuRegister()) {
2402 __ movd(CpuRegister(TMP), source.As<XmmRegister>());
2403 __ movaps(source.As<XmmRegister>(), destination.As<XmmRegister>());
2404 __ movd(destination.As<XmmRegister>(), CpuRegister(TMP));
2405 } else if (source.IsFpuRegister() && destination.IsStackSlot()) {
2406 Exchange32(source.As<XmmRegister>(), destination.GetStackIndex());
2407 } else if (source.IsStackSlot() && destination.IsFpuRegister()) {
2408 Exchange32(destination.As<XmmRegister>(), source.GetStackIndex());
2409 } else if (source.IsFpuRegister() && destination.IsDoubleStackSlot()) {
2410 Exchange64(source.As<XmmRegister>(), destination.GetStackIndex());
2411 } else if (source.IsDoubleStackSlot() && destination.IsFpuRegister()) {
2412 Exchange64(destination.As<XmmRegister>(), source.GetStackIndex());
Nicolas Geoffrayecb2f9b2014-06-13 08:59:59 +00002413 } else {
Nicolas Geoffray102cbed2014-10-15 18:31:05 +01002414 LOG(FATAL) << "Unimplemented swap between " << source << " and " << destination;
Nicolas Geoffrayecb2f9b2014-06-13 08:59:59 +00002415 }
2416}
2417
2418
2419void ParallelMoveResolverX86_64::SpillScratch(int reg) {
2420 __ pushq(CpuRegister(reg));
2421}
2422
2423
2424void ParallelMoveResolverX86_64::RestoreScratch(int reg) {
2425 __ popq(CpuRegister(reg));
Nicolas Geoffray9cf35522014-06-09 18:40:10 +01002426}
2427
Nicolas Geoffray424f6762014-11-03 14:51:25 +00002428void InstructionCodeGeneratorX86_64::GenerateClassInitializationCheck(
2429 SlowPathCodeX86_64* slow_path, CpuRegister class_reg) {
2430 __ cmpl(Address(class_reg, mirror::Class::StatusOffset().Int32Value()),
2431 Immediate(mirror::Class::kStatusInitialized));
2432 __ j(kLess, slow_path->GetEntryLabel());
2433 __ Bind(slow_path->GetExitLabel());
2434 // No need for memory fence, thanks to the X86_64 memory model.
2435}
2436
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01002437void LocationsBuilderX86_64::VisitLoadClass(HLoadClass* cls) {
Nicolas Geoffray424f6762014-11-03 14:51:25 +00002438 LocationSummary::CallKind call_kind = cls->CanCallRuntime()
2439 ? LocationSummary::kCallOnSlowPath
2440 : LocationSummary::kNoCall;
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01002441 LocationSummary* locations =
Nicolas Geoffray424f6762014-11-03 14:51:25 +00002442 new (GetGraph()->GetArena()) LocationSummary(cls, call_kind);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01002443 locations->SetOut(Location::RequiresRegister());
2444}
2445
2446void InstructionCodeGeneratorX86_64::VisitLoadClass(HLoadClass* cls) {
2447 CpuRegister out = cls->GetLocations()->Out().As<CpuRegister>();
2448 if (cls->IsReferrersClass()) {
Nicolas Geoffray424f6762014-11-03 14:51:25 +00002449 DCHECK(!cls->CanCallRuntime());
2450 DCHECK(!cls->MustGenerateClinitCheck());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01002451 codegen_->LoadCurrentMethod(out);
2452 __ movl(out, Address(out, mirror::ArtMethod::DeclaringClassOffset().Int32Value()));
2453 } else {
Nicolas Geoffray424f6762014-11-03 14:51:25 +00002454 DCHECK(cls->CanCallRuntime());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01002455 codegen_->LoadCurrentMethod(out);
2456 __ movl(out, Address(out, mirror::ArtMethod::DexCacheResolvedTypesOffset().Int32Value()));
2457 __ movl(out, Address(out, CodeGenerator::GetCacheOffset(cls->GetTypeIndex())));
Nicolas Geoffray424f6762014-11-03 14:51:25 +00002458 SlowPathCodeX86_64* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathX86_64(
2459 cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck());
2460 codegen_->AddSlowPath(slow_path);
2461 __ testl(out, out);
2462 __ j(kEqual, slow_path->GetEntryLabel());
2463 if (cls->MustGenerateClinitCheck()) {
2464 GenerateClassInitializationCheck(slow_path, out);
2465 } else {
2466 __ Bind(slow_path->GetExitLabel());
2467 }
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01002468 }
2469}
2470
2471void LocationsBuilderX86_64::VisitClinitCheck(HClinitCheck* check) {
2472 LocationSummary* locations =
2473 new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath);
2474 locations->SetInAt(0, Location::RequiresRegister());
2475 if (check->HasUses()) {
2476 locations->SetOut(Location::SameAsFirstInput());
2477 }
2478}
2479
2480void InstructionCodeGeneratorX86_64::VisitClinitCheck(HClinitCheck* check) {
Nicolas Geoffray424f6762014-11-03 14:51:25 +00002481 // We assume the class to not be null.
2482 SlowPathCodeX86_64* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathX86_64(
2483 check->GetLoadClass(), check, check->GetDexPc(), true);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01002484 codegen_->AddSlowPath(slow_path);
Nicolas Geoffray424f6762014-11-03 14:51:25 +00002485 GenerateClassInitializationCheck(slow_path, check->GetLocations()->InAt(0).As<CpuRegister>());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01002486}
2487
2488void LocationsBuilderX86_64::VisitStaticFieldGet(HStaticFieldGet* instruction) {
2489 LocationSummary* locations =
2490 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
2491 locations->SetInAt(0, Location::RequiresRegister());
2492 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2493}
2494
2495void InstructionCodeGeneratorX86_64::VisitStaticFieldGet(HStaticFieldGet* instruction) {
2496 LocationSummary* locations = instruction->GetLocations();
2497 CpuRegister cls = locations->InAt(0).As<CpuRegister>();
2498 CpuRegister out = locations->Out().As<CpuRegister>();
2499 size_t offset = instruction->GetFieldOffset().SizeValue();
2500
2501 switch (instruction->GetType()) {
2502 case Primitive::kPrimBoolean: {
2503 __ movzxb(out, Address(cls, offset));
2504 break;
2505 }
2506
2507 case Primitive::kPrimByte: {
2508 __ movsxb(out, Address(cls, offset));
2509 break;
2510 }
2511
2512 case Primitive::kPrimShort: {
2513 __ movsxw(out, Address(cls, offset));
2514 break;
2515 }
2516
2517 case Primitive::kPrimChar: {
2518 __ movzxw(out, Address(cls, offset));
2519 break;
2520 }
2521
2522 case Primitive::kPrimInt:
2523 case Primitive::kPrimNot: {
2524 __ movl(out, Address(cls, offset));
2525 break;
2526 }
2527
2528 case Primitive::kPrimLong: {
2529 __ movq(out, Address(cls, offset));
2530 break;
2531 }
2532
2533 case Primitive::kPrimFloat:
2534 case Primitive::kPrimDouble:
2535 LOG(FATAL) << "Unimplemented register type " << instruction->GetType();
2536 UNREACHABLE();
2537 case Primitive::kPrimVoid:
2538 LOG(FATAL) << "Unreachable type " << instruction->GetType();
2539 UNREACHABLE();
2540 }
2541}
2542
2543void LocationsBuilderX86_64::VisitStaticFieldSet(HStaticFieldSet* instruction) {
2544 LocationSummary* locations =
2545 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
2546 Primitive::Type field_type = instruction->GetFieldType();
2547 bool is_object_type = field_type == Primitive::kPrimNot;
2548 locations->SetInAt(0, Location::RequiresRegister());
2549 locations->SetInAt(1, Location::RequiresRegister());
2550 if (is_object_type) {
2551 // Temporary registers for the write barrier.
2552 locations->AddTemp(Location::RequiresRegister());
2553 locations->AddTemp(Location::RequiresRegister());
2554 }
2555}
2556
2557void InstructionCodeGeneratorX86_64::VisitStaticFieldSet(HStaticFieldSet* instruction) {
2558 LocationSummary* locations = instruction->GetLocations();
2559 CpuRegister cls = locations->InAt(0).As<CpuRegister>();
2560 CpuRegister value = locations->InAt(1).As<CpuRegister>();
2561 size_t offset = instruction->GetFieldOffset().SizeValue();
2562 Primitive::Type field_type = instruction->GetFieldType();
2563
2564 switch (field_type) {
2565 case Primitive::kPrimBoolean:
2566 case Primitive::kPrimByte: {
2567 __ movb(Address(cls, offset), value);
2568 break;
2569 }
2570
2571 case Primitive::kPrimShort:
2572 case Primitive::kPrimChar: {
2573 __ movw(Address(cls, offset), value);
2574 break;
2575 }
2576
2577 case Primitive::kPrimInt:
2578 case Primitive::kPrimNot: {
2579 __ movl(Address(cls, offset), value);
2580 if (field_type == Primitive::kPrimNot) {
2581 CpuRegister temp = locations->GetTemp(0).As<CpuRegister>();
2582 CpuRegister card = locations->GetTemp(1).As<CpuRegister>();
2583 codegen_->MarkGCCard(temp, card, cls, value);
2584 }
2585 break;
2586 }
2587
2588 case Primitive::kPrimLong: {
2589 __ movq(Address(cls, offset), value);
2590 break;
2591 }
2592
2593 case Primitive::kPrimFloat:
2594 case Primitive::kPrimDouble:
2595 LOG(FATAL) << "Unimplemented register type " << field_type;
2596 UNREACHABLE();
2597 case Primitive::kPrimVoid:
2598 LOG(FATAL) << "Unreachable type " << field_type;
2599 UNREACHABLE();
2600 }
2601}
2602
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +00002603void LocationsBuilderX86_64::VisitLoadString(HLoadString* load) {
2604 LocationSummary* locations =
2605 new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kCallOnSlowPath);
2606 locations->SetOut(Location::RequiresRegister());
2607}
2608
2609void InstructionCodeGeneratorX86_64::VisitLoadString(HLoadString* load) {
2610 SlowPathCodeX86_64* slow_path = new (GetGraph()->GetArena()) LoadStringSlowPathX86_64(load);
2611 codegen_->AddSlowPath(slow_path);
2612
2613 CpuRegister out = load->GetLocations()->Out().As<CpuRegister>();
2614 codegen_->LoadCurrentMethod(CpuRegister(out));
2615 __ movl(out, Address(out, mirror::ArtMethod::DexCacheStringsOffset().Int32Value()));
2616 __ movl(out, Address(out, CodeGenerator::GetCacheOffset(load->GetStringIndex())));
2617 __ testl(out, out);
2618 __ j(kEqual, slow_path->GetEntryLabel());
2619 __ Bind(slow_path->GetExitLabel());
2620}
2621
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +00002622void LocationsBuilderX86_64::VisitLoadException(HLoadException* load) {
2623 LocationSummary* locations =
2624 new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall);
2625 locations->SetOut(Location::RequiresRegister());
2626}
2627
2628void InstructionCodeGeneratorX86_64::VisitLoadException(HLoadException* load) {
2629 Address address = Address::Absolute(
2630 Thread::ExceptionOffset<kX86_64WordSize>().Int32Value(), true);
2631 __ gs()->movl(load->GetLocations()->Out().As<CpuRegister>(), address);
2632 __ gs()->movl(address, Immediate(0));
2633}
2634
2635void LocationsBuilderX86_64::VisitThrow(HThrow* instruction) {
2636 LocationSummary* locations =
2637 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
2638 InvokeRuntimeCallingConvention calling_convention;
2639 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
2640}
2641
2642void InstructionCodeGeneratorX86_64::VisitThrow(HThrow* instruction) {
2643 __ gs()->call(
2644 Address::Absolute(QUICK_ENTRYPOINT_OFFSET(kX86_64WordSize, pDeliverException), true));
2645 codegen_->RecordPcInfo(instruction, instruction->GetDexPc());
2646}
2647
Nicolas Geoffray9cf35522014-06-09 18:40:10 +01002648} // namespace x86_64
2649} // namespace art