code_generator_x86_64.h revision 0debae7bc89eb05f7a2bf7dccd223318fad7c88d
19cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray/*
29cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray * Copyright (C) 2014 The Android Open Source Project
39cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray *
49cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray * Licensed under the Apache License, Version 2.0 (the "License");
59cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray * you may not use this file except in compliance with the License.
69cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray * You may obtain a copy of the License at
79cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray *
89cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray *      http://www.apache.org/licenses/LICENSE-2.0
99cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray *
109cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray * Unless required by applicable law or agreed to in writing, software
119cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray * distributed under the License is distributed on an "AS IS" BASIS,
129cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
139cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray * See the License for the specific language governing permissions and
149cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray * limitations under the License.
159cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray */
169cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray
179cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray#ifndef ART_COMPILER_OPTIMIZING_CODE_GENERATOR_X86_64_H_
189cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray#define ART_COMPILER_OPTIMIZING_CODE_GENERATOR_X86_64_H_
199cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray
209cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray#include "code_generator.h"
2152c489645b6e9ae33623f1ec24143cde5444906eCalin Juravle#include "dex/compiler_enums.h"
22cd6dffedf1bd8e6dfb3fb0c933551f9a90f7de3fCalin Juravle#include "driver/compiler_options.h"
239cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray#include "nodes.h"
24ecb2f9ba57b08ceac4204ddd6a0a88a0524f8741Nicolas Geoffray#include "parallel_move_resolver.h"
259cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray#include "utils/x86_64/assembler_x86_64.h"
269cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray
279cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffraynamespace art {
289cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffraynamespace x86_64 {
299cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray
3086a8d7afc7f00ff0f5ea7b8aaf4d50514250a4e6Nicolas Geoffray// Use a local definition to prevent copying mistakes.
3186a8d7afc7f00ff0f5ea7b8aaf4d50514250a4e6Nicolas Geoffraystatic constexpr size_t kX86_64WordSize = kX86_64PointerSize;
329cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray
33ee3cf0731d0ef0787bc2947c8e3ca432b513956bNicolas Geoffray// Some x86_64 instructions require a register to be available as temp.
34ee3cf0731d0ef0787bc2947c8e3ca432b513956bNicolas Geoffraystatic constexpr Register TMP = R11;
35ee3cf0731d0ef0787bc2947c8e3ca432b513956bNicolas Geoffray
369cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffraystatic constexpr Register kParameterCoreRegisters[] = { RSI, RDX, RCX, R8, R9 };
377fb49da8ec62e8a10ed9419ade9f32c6b1174687Nicolas Geoffraystatic constexpr FloatRegister kParameterFloatRegisters[] =
387fb49da8ec62e8a10ed9419ade9f32c6b1174687Nicolas Geoffray    { XMM0, XMM1, XMM2, XMM3, XMM4, XMM5, XMM6, XMM7 };
399cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray
409cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffraystatic constexpr size_t kParameterCoreRegistersLength = arraysize(kParameterCoreRegisters);
417fb49da8ec62e8a10ed9419ade9f32c6b1174687Nicolas Geoffraystatic constexpr size_t kParameterFloatRegistersLength = arraysize(kParameterFloatRegisters);
429cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray
43848f70a3d73833fc1bf3032a9ff6812e429661d9Jeff Haostatic constexpr Register kRuntimeParameterCoreRegisters[] = { RDI, RSI, RDX, RCX };
44d75948ac93a4a317feaf136cae78823071234ba5Nicolas Geoffraystatic constexpr size_t kRuntimeParameterCoreRegistersLength =
45d75948ac93a4a317feaf136cae78823071234ba5Nicolas Geoffray    arraysize(kRuntimeParameterCoreRegisters);
46d75948ac93a4a317feaf136cae78823071234ba5Nicolas Geoffraystatic constexpr FloatRegister kRuntimeParameterFpuRegisters[] = { XMM0, XMM1 };
47d75948ac93a4a317feaf136cae78823071234ba5Nicolas Geoffraystatic constexpr size_t kRuntimeParameterFpuRegistersLength =
48d75948ac93a4a317feaf136cae78823071234ba5Nicolas Geoffray    arraysize(kRuntimeParameterFpuRegisters);
49d75948ac93a4a317feaf136cae78823071234ba5Nicolas Geoffray
50d75948ac93a4a317feaf136cae78823071234ba5Nicolas Geoffrayclass InvokeRuntimeCallingConvention : public CallingConvention<Register, FloatRegister> {
51d75948ac93a4a317feaf136cae78823071234ba5Nicolas Geoffray public:
52d75948ac93a4a317feaf136cae78823071234ba5Nicolas Geoffray  InvokeRuntimeCallingConvention()
53d75948ac93a4a317feaf136cae78823071234ba5Nicolas Geoffray      : CallingConvention(kRuntimeParameterCoreRegisters,
54d75948ac93a4a317feaf136cae78823071234ba5Nicolas Geoffray                          kRuntimeParameterCoreRegistersLength,
55d75948ac93a4a317feaf136cae78823071234ba5Nicolas Geoffray                          kRuntimeParameterFpuRegisters,
56e401d146407d61eeb99f8d6176b2ac13c4df1e33Mathieu Chartier                          kRuntimeParameterFpuRegistersLength,
57e401d146407d61eeb99f8d6176b2ac13c4df1e33Mathieu Chartier                          kX86_64PointerSize) {}
58d75948ac93a4a317feaf136cae78823071234ba5Nicolas Geoffray
59d75948ac93a4a317feaf136cae78823071234ba5Nicolas Geoffray private:
60d75948ac93a4a317feaf136cae78823071234ba5Nicolas Geoffray  DISALLOW_COPY_AND_ASSIGN(InvokeRuntimeCallingConvention);
61d75948ac93a4a317feaf136cae78823071234ba5Nicolas Geoffray};
62d75948ac93a4a317feaf136cae78823071234ba5Nicolas Geoffray
637fb49da8ec62e8a10ed9419ade9f32c6b1174687Nicolas Geoffrayclass InvokeDexCallingConvention : public CallingConvention<Register, FloatRegister> {
649cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray public:
657fb49da8ec62e8a10ed9419ade9f32c6b1174687Nicolas Geoffray  InvokeDexCallingConvention() : CallingConvention(
667fb49da8ec62e8a10ed9419ade9f32c6b1174687Nicolas Geoffray      kParameterCoreRegisters,
677fb49da8ec62e8a10ed9419ade9f32c6b1174687Nicolas Geoffray      kParameterCoreRegistersLength,
687fb49da8ec62e8a10ed9419ade9f32c6b1174687Nicolas Geoffray      kParameterFloatRegisters,
69e401d146407d61eeb99f8d6176b2ac13c4df1e33Mathieu Chartier      kParameterFloatRegistersLength,
70e401d146407d61eeb99f8d6176b2ac13c4df1e33Mathieu Chartier      kX86_64PointerSize) {}
719cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray
729cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray private:
739cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray  DISALLOW_COPY_AND_ASSIGN(InvokeDexCallingConvention);
749cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray};
759cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray
76e460d1df1f789c7c8bb97024a8efbd713ac175e9Calin Juravleclass FieldAccessCallingConventionX86_64 : public FieldAccessCallingConvention {
77e460d1df1f789c7c8bb97024a8efbd713ac175e9Calin Juravle public:
78e460d1df1f789c7c8bb97024a8efbd713ac175e9Calin Juravle  FieldAccessCallingConventionX86_64() {}
79e460d1df1f789c7c8bb97024a8efbd713ac175e9Calin Juravle
80e460d1df1f789c7c8bb97024a8efbd713ac175e9Calin Juravle  Location GetObjectLocation() const OVERRIDE {
81e460d1df1f789c7c8bb97024a8efbd713ac175e9Calin Juravle    return Location::RegisterLocation(RSI);
82e460d1df1f789c7c8bb97024a8efbd713ac175e9Calin Juravle  }
83e460d1df1f789c7c8bb97024a8efbd713ac175e9Calin Juravle  Location GetFieldIndexLocation() const OVERRIDE {
84e460d1df1f789c7c8bb97024a8efbd713ac175e9Calin Juravle    return Location::RegisterLocation(RDI);
85e460d1df1f789c7c8bb97024a8efbd713ac175e9Calin Juravle  }
86e460d1df1f789c7c8bb97024a8efbd713ac175e9Calin Juravle  Location GetReturnLocation(Primitive::Type type ATTRIBUTE_UNUSED) const OVERRIDE {
87e460d1df1f789c7c8bb97024a8efbd713ac175e9Calin Juravle    return Location::RegisterLocation(RAX);
88e460d1df1f789c7c8bb97024a8efbd713ac175e9Calin Juravle  }
89e460d1df1f789c7c8bb97024a8efbd713ac175e9Calin Juravle  Location GetSetValueLocation(Primitive::Type type, bool is_instance) const OVERRIDE {
90e460d1df1f789c7c8bb97024a8efbd713ac175e9Calin Juravle    return Primitive::Is64BitType(type)
91e460d1df1f789c7c8bb97024a8efbd713ac175e9Calin Juravle        ? Location::RegisterLocation(RDX)
92e460d1df1f789c7c8bb97024a8efbd713ac175e9Calin Juravle        : (is_instance
93e460d1df1f789c7c8bb97024a8efbd713ac175e9Calin Juravle            ? Location::RegisterLocation(RDX)
94e460d1df1f789c7c8bb97024a8efbd713ac175e9Calin Juravle            : Location::RegisterLocation(RSI));
95e460d1df1f789c7c8bb97024a8efbd713ac175e9Calin Juravle  }
96e460d1df1f789c7c8bb97024a8efbd713ac175e9Calin Juravle  Location GetFpuLocation(Primitive::Type type ATTRIBUTE_UNUSED) const OVERRIDE {
97e460d1df1f789c7c8bb97024a8efbd713ac175e9Calin Juravle    return Location::FpuRegisterLocation(XMM0);
98e460d1df1f789c7c8bb97024a8efbd713ac175e9Calin Juravle  }
99e460d1df1f789c7c8bb97024a8efbd713ac175e9Calin Juravle
100e460d1df1f789c7c8bb97024a8efbd713ac175e9Calin Juravle private:
101e460d1df1f789c7c8bb97024a8efbd713ac175e9Calin Juravle  DISALLOW_COPY_AND_ASSIGN(FieldAccessCallingConventionX86_64);
102e460d1df1f789c7c8bb97024a8efbd713ac175e9Calin Juravle};
103e460d1df1f789c7c8bb97024a8efbd713ac175e9Calin Juravle
104e460d1df1f789c7c8bb97024a8efbd713ac175e9Calin Juravle
1052d27c8e338af7262dbd4aaa66127bb8fa1758b86Roland Levillainclass InvokeDexCallingConventionVisitorX86_64 : public InvokeDexCallingConventionVisitor {
1069cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray public:
1072d27c8e338af7262dbd4aaa66127bb8fa1758b86Roland Levillain  InvokeDexCallingConventionVisitorX86_64() {}
1082d27c8e338af7262dbd4aaa66127bb8fa1758b86Roland Levillain  virtual ~InvokeDexCallingConventionVisitorX86_64() {}
1099cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray
1102d27c8e338af7262dbd4aaa66127bb8fa1758b86Roland Levillain  Location GetNextLocation(Primitive::Type type) OVERRIDE;
111fd88f16100cceafbfde1b4f095f17e89444d6fa8Nicolas Geoffray  Location GetReturnLocation(Primitive::Type type) const OVERRIDE;
112fd88f16100cceafbfde1b4f095f17e89444d6fa8Nicolas Geoffray  Location GetMethodLocation() const OVERRIDE;
1139cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray
1149cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray private:
1159cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray  InvokeDexCallingConvention calling_convention;
1162d27c8e338af7262dbd4aaa66127bb8fa1758b86Roland Levillain
1172d27c8e338af7262dbd4aaa66127bb8fa1758b86Roland Levillain  DISALLOW_COPY_AND_ASSIGN(InvokeDexCallingConventionVisitorX86_64);
1189cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray};
1199cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray
1209cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffrayclass CodeGeneratorX86_64;
12171fb52fee246b7d511f520febbd73dc7a9bbca79Andreas Gampe
122ad4450e5c3ffaa9566216cc6fafbf5c11186c467Zheng Xuclass ParallelMoveResolverX86_64 : public ParallelMoveResolverWithSwap {
123ecb2f9ba57b08ceac4204ddd6a0a88a0524f8741Nicolas Geoffray public:
124ecb2f9ba57b08ceac4204ddd6a0a88a0524f8741Nicolas Geoffray  ParallelMoveResolverX86_64(ArenaAllocator* allocator, CodeGeneratorX86_64* codegen)
125ad4450e5c3ffaa9566216cc6fafbf5c11186c467Zheng Xu      : ParallelMoveResolverWithSwap(allocator), codegen_(codegen) {}
126ecb2f9ba57b08ceac4204ddd6a0a88a0524f8741Nicolas Geoffray
127de58ab2c03ff8112b07ab827c8fa38f670dfc656Nicolas Geoffray  void EmitMove(size_t index) OVERRIDE;
128de58ab2c03ff8112b07ab827c8fa38f670dfc656Nicolas Geoffray  void EmitSwap(size_t index) OVERRIDE;
129de58ab2c03ff8112b07ab827c8fa38f670dfc656Nicolas Geoffray  void SpillScratch(int reg) OVERRIDE;
130de58ab2c03ff8112b07ab827c8fa38f670dfc656Nicolas Geoffray  void RestoreScratch(int reg) OVERRIDE;
131ecb2f9ba57b08ceac4204ddd6a0a88a0524f8741Nicolas Geoffray
132ecb2f9ba57b08ceac4204ddd6a0a88a0524f8741Nicolas Geoffray  X86_64Assembler* GetAssembler() const;
133ecb2f9ba57b08ceac4204ddd6a0a88a0524f8741Nicolas Geoffray
134ecb2f9ba57b08ceac4204ddd6a0a88a0524f8741Nicolas Geoffray private:
135412f10cfed002ab617c78f2621d68446ca4dd8bdNicolas Geoffray  void Exchange32(CpuRegister reg, int mem);
136102cbed1e52b7c5f09458b44903fe97bb3e14d5fNicolas Geoffray  void Exchange32(XmmRegister reg, int mem);
137412f10cfed002ab617c78f2621d68446ca4dd8bdNicolas Geoffray  void Exchange32(int mem1, int mem2);
138412f10cfed002ab617c78f2621d68446ca4dd8bdNicolas Geoffray  void Exchange64(CpuRegister reg, int mem);
139102cbed1e52b7c5f09458b44903fe97bb3e14d5fNicolas Geoffray  void Exchange64(XmmRegister reg, int mem);
140412f10cfed002ab617c78f2621d68446ca4dd8bdNicolas Geoffray  void Exchange64(int mem1, int mem2);
141ecb2f9ba57b08ceac4204ddd6a0a88a0524f8741Nicolas Geoffray
142ecb2f9ba57b08ceac4204ddd6a0a88a0524f8741Nicolas Geoffray  CodeGeneratorX86_64* const codegen_;
143ecb2f9ba57b08ceac4204ddd6a0a88a0524f8741Nicolas Geoffray
144ecb2f9ba57b08ceac4204ddd6a0a88a0524f8741Nicolas Geoffray  DISALLOW_COPY_AND_ASSIGN(ParallelMoveResolverX86_64);
145ecb2f9ba57b08ceac4204ddd6a0a88a0524f8741Nicolas Geoffray};
146ecb2f9ba57b08ceac4204ddd6a0a88a0524f8741Nicolas Geoffray
1479cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffrayclass LocationsBuilderX86_64 : public HGraphVisitor {
1489cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray public:
1499cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray  LocationsBuilderX86_64(HGraph* graph, CodeGeneratorX86_64* codegen)
1509cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray      : HGraphVisitor(graph), codegen_(codegen) {}
1519cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray
152360231a056e796c36ffe62348507e904dc9efb9bNicolas Geoffray#define DECLARE_VISIT_INSTRUCTION(name, super)     \
153de58ab2c03ff8112b07ab827c8fa38f670dfc656Nicolas Geoffray  void Visit##name(H##name* instr) OVERRIDE;
1549cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray
155ef20f71e16f035a39a329c8524d7e59ca6a11f04Alexandre Rames  FOR_EACH_CONCRETE_INSTRUCTION_COMMON(DECLARE_VISIT_INSTRUCTION)
156ef20f71e16f035a39a329c8524d7e59ca6a11f04Alexandre Rames  FOR_EACH_CONCRETE_INSTRUCTION_X86_64(DECLARE_VISIT_INSTRUCTION)
1579cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray
1589cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray#undef DECLARE_VISIT_INSTRUCTION
1599cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray
160ef20f71e16f035a39a329c8524d7e59ca6a11f04Alexandre Rames  void VisitInstruction(HInstruction* instruction) OVERRIDE {
161ef20f71e16f035a39a329c8524d7e59ca6a11f04Alexandre Rames    LOG(FATAL) << "Unreachable instruction " << instruction->DebugName()
162ef20f71e16f035a39a329c8524d7e59ca6a11f04Alexandre Rames               << " (id " << instruction->GetId() << ")";
163ef20f71e16f035a39a329c8524d7e59ca6a11f04Alexandre Rames  }
164ef20f71e16f035a39a329c8524d7e59ca6a11f04Alexandre Rames
1659574c4b5f5ef039d694ac12c97e25ca02eca83c0Nicolas Geoffray private:
166e982f0b8e809cece6f460fa2d8df25873aa69de4Nicolas Geoffray  void HandleInvoke(HInvoke* invoke);
1679574c4b5f5ef039d694ac12c97e25ca02eca83c0Nicolas Geoffray  void HandleBitwiseOperation(HBinaryOperation* operation);
1689aec02fc5df5518c16f1e5a9b6cb198a192db973Calin Juravle  void HandleShift(HBinaryOperation* operation);
16952c489645b6e9ae33623f1ec24143cde5444906eCalin Juravle  void HandleFieldSet(HInstruction* instruction, const FieldInfo& field_info);
17052c489645b6e9ae33623f1ec24143cde5444906eCalin Juravle  void HandleFieldGet(HInstruction* instruction);
171e982f0b8e809cece6f460fa2d8df25873aa69de4Nicolas Geoffray
1729cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray  CodeGeneratorX86_64* const codegen_;
1732d27c8e338af7262dbd4aaa66127bb8fa1758b86Roland Levillain  InvokeDexCallingConventionVisitorX86_64 parameter_visitor_;
1749cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray
1759cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray  DISALLOW_COPY_AND_ASSIGN(LocationsBuilderX86_64);
1769cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray};
1779cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray
1789cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffrayclass InstructionCodeGeneratorX86_64 : public HGraphVisitor {
1799cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray public:
1809cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray  InstructionCodeGeneratorX86_64(HGraph* graph, CodeGeneratorX86_64* codegen);
1819cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray
182360231a056e796c36ffe62348507e904dc9efb9bNicolas Geoffray#define DECLARE_VISIT_INSTRUCTION(name, super)     \
183de58ab2c03ff8112b07ab827c8fa38f670dfc656Nicolas Geoffray  void Visit##name(H##name* instr) OVERRIDE;
1849cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray
185ef20f71e16f035a39a329c8524d7e59ca6a11f04Alexandre Rames  FOR_EACH_CONCRETE_INSTRUCTION_COMMON(DECLARE_VISIT_INSTRUCTION)
186ef20f71e16f035a39a329c8524d7e59ca6a11f04Alexandre Rames  FOR_EACH_CONCRETE_INSTRUCTION_X86_64(DECLARE_VISIT_INSTRUCTION)
1879cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray
1889cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray#undef DECLARE_VISIT_INSTRUCTION
1899cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray
190ef20f71e16f035a39a329c8524d7e59ca6a11f04Alexandre Rames  void VisitInstruction(HInstruction* instruction) OVERRIDE {
191ef20f71e16f035a39a329c8524d7e59ca6a11f04Alexandre Rames    LOG(FATAL) << "Unreachable instruction " << instruction->DebugName()
192ef20f71e16f035a39a329c8524d7e59ca6a11f04Alexandre Rames               << " (id " << instruction->GetId() << ")";
193ef20f71e16f035a39a329c8524d7e59ca6a11f04Alexandre Rames  }
194ef20f71e16f035a39a329c8524d7e59ca6a11f04Alexandre Rames
1959cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray  X86_64Assembler* GetAssembler() const { return assembler_; }
1969cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray
1979cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray private:
1983c04974a90b0e03f4b509010bff49f0b2a3da57fNicolas Geoffray  // Generate code for the given suspend check. If not null, `successor`
1993c04974a90b0e03f4b509010bff49f0b2a3da57fNicolas Geoffray  // is the block to branch to if the suspend check is not needed, and after
2003c04974a90b0e03f4b509010bff49f0b2a3da57fNicolas Geoffray  // the suspend call.
2013c04974a90b0e03f4b509010bff49f0b2a3da57fNicolas Geoffray  void GenerateSuspendCheck(HSuspendCheck* instruction, HBasicBlock* successor);
20285b62f23fc6dfffe2ddd3ddfa74611666c9ff41dAndreas Gampe  void GenerateClassInitializationCheck(SlowPathCode* slow_path, CpuRegister class_reg);
2039574c4b5f5ef039d694ac12c97e25ca02eca83c0Nicolas Geoffray  void HandleBitwiseOperation(HBinaryOperation* operation);
204c470193cfc522fc818eb2eaab896aef9caf0c75aMark Mendell  void GenerateRemFP(HRem* rem);
2050f88e87085b7cf6544dadff3f555773966a6853eGuillaume Sanchez  void DivRemOneOrMinusOne(HBinaryOperation* instruction);
206b19930c5cba3cf662dce5ee057fcc9829b4cbb9cGuillaume Sanchez  void DivByPowerOfTwo(HDiv* instruction);
2070f88e87085b7cf6544dadff3f555773966a6853eGuillaume Sanchez  void GenerateDivRemWithAnyConstant(HBinaryOperation* instruction);
208bacfec30ee9f2f6fdfd190f11b105b609938efcaCalin Juravle  void GenerateDivRemIntegral(HBinaryOperation* instruction);
2099aec02fc5df5518c16f1e5a9b6cb198a192db973Calin Juravle  void HandleShift(HBinaryOperation* operation);
21052c489645b6e9ae33623f1ec24143cde5444906eCalin Juravle  void GenerateMemoryBarrier(MemBarrierKind kind);
21107276db28d654594e0e86e9e467cad393f752e6eNicolas Geoffray  void HandleFieldSet(HInstruction* instruction,
21207276db28d654594e0e86e9e467cad393f752e6eNicolas Geoffray                      const FieldInfo& field_info,
21307276db28d654594e0e86e9e467cad393f752e6eNicolas Geoffray                      bool value_can_be_null);
21452c489645b6e9ae33623f1ec24143cde5444906eCalin Juravle  void HandleFieldGet(HInstruction* instruction, const FieldInfo& field_info);
215cd6dffedf1bd8e6dfb3fb0c933551f9a90f7de3fCalin Juravle  void GenerateImplicitNullCheck(HNullCheck* instruction);
216cd6dffedf1bd8e6dfb3fb0c933551f9a90f7de3fCalin Juravle  void GenerateExplicitNullCheck(HNullCheck* instruction);
21724f2dfae084b2382c053f5d688fd6bb26cb8a328Mark Mendell  void PushOntoFPStack(Location source, uint32_t temp_offset,
21824f2dfae084b2382c053f5d688fd6bb26cb8a328Mark Mendell                       uint32_t stack_adjustment, bool is_float);
219d43b3ac88cd46b8815890188c9c2b9a3f1564648Mingyao Yang  void GenerateTestAndBranch(HInstruction* instruction,
2200debae7bc89eb05f7a2bf7dccd223318fad7c88dDavid Brazdil                             size_t condition_input_index,
221d43b3ac88cd46b8815890188c9c2b9a3f1564648Mingyao Yang                             Label* true_target,
2220debae7bc89eb05f7a2bf7dccd223318fad7c88dDavid Brazdil                             Label* false_target);
2230debae7bc89eb05f7a2bf7dccd223318fad7c88dDavid Brazdil  void GenerateCompareTestAndBranch(HCondition* condition,
224c470193cfc522fc818eb2eaab896aef9caf0c75aMark Mendell                                    Label* true_target,
2250debae7bc89eb05f7a2bf7dccd223318fad7c88dDavid Brazdil                                    Label* false_target);
226c470193cfc522fc818eb2eaab896aef9caf0c75aMark Mendell  void GenerateFPJumps(HCondition* cond, Label* true_label, Label* false_label);
227fc6a86ab2b70781e72b807c1798b83829ca7f931David Brazdil  void HandleGoto(HInstruction* got, HBasicBlock* successor);
2283c04974a90b0e03f4b509010bff49f0b2a3da57fNicolas Geoffray
2299cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray  X86_64Assembler* const assembler_;
2309cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray  CodeGeneratorX86_64* const codegen_;
2319cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray
2329cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray  DISALLOW_COPY_AND_ASSIGN(InstructionCodeGeneratorX86_64);
2339cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray};
2349cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray
2359c86b485bc6169eadf846dd5f7cdf0958fe1eb23Mark Mendell// Class for fixups to jump tables.
2369c86b485bc6169eadf846dd5f7cdf0958fe1eb23Mark Mendellclass JumpTableRIPFixup;
2379c86b485bc6169eadf846dd5f7cdf0958fe1eb23Mark Mendell
2389cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffrayclass CodeGeneratorX86_64 : public CodeGenerator {
2399cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray public:
240fb8d279bc011b31d0765dc7ca59afea324fd0d0cMark Mendell  CodeGeneratorX86_64(HGraph* graph,
241fb8d279bc011b31d0765dc7ca59afea324fd0d0cMark Mendell                  const X86_64InstructionSetFeatures& isa_features,
242ecc4366670e12b4812ef1653f7c8d52234ca1b1fSerban Constantinescu                  const CompilerOptions& compiler_options,
243ecc4366670e12b4812ef1653f7c8d52234ca1b1fSerban Constantinescu                  OptimizingCompilerStats* stats = nullptr);
2449cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray  virtual ~CodeGeneratorX86_64() {}
2459cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray
246de58ab2c03ff8112b07ab827c8fa38f670dfc656Nicolas Geoffray  void GenerateFrameEntry() OVERRIDE;
247de58ab2c03ff8112b07ab827c8fa38f670dfc656Nicolas Geoffray  void GenerateFrameExit() OVERRIDE;
248de58ab2c03ff8112b07ab827c8fa38f670dfc656Nicolas Geoffray  void Bind(HBasicBlock* block) OVERRIDE;
249de58ab2c03ff8112b07ab827c8fa38f670dfc656Nicolas Geoffray  void Move(HInstruction* instruction, Location location, HInstruction* move_for) OVERRIDE;
250175dc732c80e6f2afd83209348124df349290ba8Calin Juravle  void MoveConstant(Location destination, int32_t value) OVERRIDE;
251e460d1df1f789c7c8bb97024a8efbd713ac175e9Calin Juravle  void MoveLocation(Location dst, Location src, Primitive::Type dst_type) OVERRIDE;
252e460d1df1f789c7c8bb97024a8efbd713ac175e9Calin Juravle  void AddLocationAsTemp(Location location, LocationSummary* locations) OVERRIDE;
253e460d1df1f789c7c8bb97024a8efbd713ac175e9Calin Juravle
254de58ab2c03ff8112b07ab827c8fa38f670dfc656Nicolas Geoffray  size_t SaveCoreRegister(size_t stack_index, uint32_t reg_id) OVERRIDE;
255de58ab2c03ff8112b07ab827c8fa38f670dfc656Nicolas Geoffray  size_t RestoreCoreRegister(size_t stack_index, uint32_t reg_id) OVERRIDE;
256de58ab2c03ff8112b07ab827c8fa38f670dfc656Nicolas Geoffray  size_t SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) OVERRIDE;
257de58ab2c03ff8112b07ab827c8fa38f670dfc656Nicolas Geoffray  size_t RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) OVERRIDE;
2589cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray
2598158f28b6689314213eb4dbbe14166073be71f7eAlexandre Rames  // Generate code to invoke a runtime entry point.
260175dc732c80e6f2afd83209348124df349290ba8Calin Juravle  void InvokeRuntime(QuickEntrypointEnum entrypoint,
261175dc732c80e6f2afd83209348124df349290ba8Calin Juravle                     HInstruction* instruction,
262175dc732c80e6f2afd83209348124df349290ba8Calin Juravle                     uint32_t dex_pc,
263175dc732c80e6f2afd83209348124df349290ba8Calin Juravle                     SlowPathCode* slow_path) OVERRIDE;
264175dc732c80e6f2afd83209348124df349290ba8Calin Juravle
265175dc732c80e6f2afd83209348124df349290ba8Calin Juravle  void InvokeRuntime(int32_t entry_point_offset,
2668158f28b6689314213eb4dbbe14166073be71f7eAlexandre Rames                     HInstruction* instruction,
2678158f28b6689314213eb4dbbe14166073be71f7eAlexandre Rames                     uint32_t dex_pc,
2688158f28b6689314213eb4dbbe14166073be71f7eAlexandre Rames                     SlowPathCode* slow_path);
2698158f28b6689314213eb4dbbe14166073be71f7eAlexandre Rames
270de58ab2c03ff8112b07ab827c8fa38f670dfc656Nicolas Geoffray  size_t GetWordSize() const OVERRIDE {
2719cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray    return kX86_64WordSize;
2729cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray  }
2739cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray
274f85a9ca9859ad843dc03d3a2b600afbaf2e9bbddMark Mendell  size_t GetFloatingPointSpillSlotSize() const OVERRIDE {
275f85a9ca9859ad843dc03d3a2b600afbaf2e9bbddMark Mendell    return kX86_64WordSize;
276f85a9ca9859ad843dc03d3a2b600afbaf2e9bbddMark Mendell  }
277f85a9ca9859ad843dc03d3a2b600afbaf2e9bbddMark Mendell
278de58ab2c03ff8112b07ab827c8fa38f670dfc656Nicolas Geoffray  HGraphVisitor* GetLocationBuilder() OVERRIDE {
2799cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray    return &location_builder_;
2809cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray  }
2819cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray
282de58ab2c03ff8112b07ab827c8fa38f670dfc656Nicolas Geoffray  HGraphVisitor* GetInstructionVisitor() OVERRIDE {
2839cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray    return &instruction_visitor_;
2849cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray  }
2859cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray
286de58ab2c03ff8112b07ab827c8fa38f670dfc656Nicolas Geoffray  X86_64Assembler* GetAssembler() OVERRIDE {
2879cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray    return &assembler_;
2889cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray  }
2899cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray
290eb7b7399dbdb5e471b8ae00a567bf4f19edd3907Alexandre Rames  const X86_64Assembler& GetAssembler() const OVERRIDE {
291eb7b7399dbdb5e471b8ae00a567bf4f19edd3907Alexandre Rames    return assembler_;
292eb7b7399dbdb5e471b8ae00a567bf4f19edd3907Alexandre Rames  }
293eb7b7399dbdb5e471b8ae00a567bf4f19edd3907Alexandre Rames
294f0e3937b87453234d0d7970b8712082062709b8dNicolas Geoffray  ParallelMoveResolverX86_64* GetMoveResolver() OVERRIDE {
295ecb2f9ba57b08ceac4204ddd6a0a88a0524f8741Nicolas Geoffray    return &move_resolver_;
296ecb2f9ba57b08ceac4204ddd6a0a88a0524f8741Nicolas Geoffray  }
297ecb2f9ba57b08ceac4204ddd6a0a88a0524f8741Nicolas Geoffray
298de58ab2c03ff8112b07ab827c8fa38f670dfc656Nicolas Geoffray  uintptr_t GetAddressOf(HBasicBlock* block) const OVERRIDE {
299de58ab2c03ff8112b07ab827c8fa38f670dfc656Nicolas Geoffray    return GetLabelOf(block)->Position();
300de58ab2c03ff8112b07ab827c8fa38f670dfc656Nicolas Geoffray  }
301de58ab2c03ff8112b07ab827c8fa38f670dfc656Nicolas Geoffray
302de58ab2c03ff8112b07ab827c8fa38f670dfc656Nicolas Geoffray  Location GetStackLocation(HLoadLocal* load) const OVERRIDE;
3039cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray
304988939683c26c0b1c8808fc206add6337319509aNicolas Geoffray  void SetupBlockedRegisters(bool is_baseline) const OVERRIDE;
305de58ab2c03ff8112b07ab827c8fa38f670dfc656Nicolas Geoffray  Location AllocateFreeRegister(Primitive::Type type) const OVERRIDE;
306de58ab2c03ff8112b07ab827c8fa38f670dfc656Nicolas Geoffray  void DumpCoreRegister(std::ostream& stream, int reg) const OVERRIDE;
307de58ab2c03ff8112b07ab827c8fa38f670dfc656Nicolas Geoffray  void DumpFloatingPointRegister(std::ostream& stream, int reg) const OVERRIDE;
308f55c3e0825cdfc4c5a27730031177d1a0198ec5aMark Mendell  void Finalize(CodeAllocator* allocator) OVERRIDE;
3099cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray
310de58ab2c03ff8112b07ab827c8fa38f670dfc656Nicolas Geoffray  InstructionSet GetInstructionSet() const OVERRIDE {
311412f10cfed002ab617c78f2621d68446ca4dd8bdNicolas Geoffray    return InstructionSet::kX86_64;
312412f10cfed002ab617c78f2621d68446ca4dd8bdNicolas Geoffray  }
313412f10cfed002ab617c78f2621d68446ca4dd8bdNicolas Geoffray
3143c7bb98698f77af10372cf31824d3bb115d9bf0fNicolas Geoffray  // Emit a write barrier.
31507276db28d654594e0e86e9e467cad393f752e6eNicolas Geoffray  void MarkGCCard(CpuRegister temp,
31607276db28d654594e0e86e9e467cad393f752e6eNicolas Geoffray                  CpuRegister card,
31707276db28d654594e0e86e9e467cad393f752e6eNicolas Geoffray                  CpuRegister object,
31807276db28d654594e0e86e9e467cad393f752e6eNicolas Geoffray                  CpuRegister value,
31907276db28d654594e0e86e9e467cad393f752e6eNicolas Geoffray                  bool value_can_be_null);
3203c7bb98698f77af10372cf31824d3bb115d9bf0fNicolas Geoffray
3219cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray  // Helper method to move a value between two locations.
3229cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray  void Move(Location destination, Location source);
3239cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray
32492a73aef279be78e3c2b04db1713076183933436Nicolas Geoffray  Label* GetLabelOf(HBasicBlock* block) const {
325225b6464a58ebe11c156144653f11a1c6607f4ebVladimir Marko    return CommonGetLabelOf<Label>(block_labels_, block);
32692a73aef279be78e3c2b04db1713076183933436Nicolas Geoffray  }
32792a73aef279be78e3c2b04db1713076183933436Nicolas Geoffray
328de58ab2c03ff8112b07ab827c8fa38f670dfc656Nicolas Geoffray  void Initialize() OVERRIDE {
329225b6464a58ebe11c156144653f11a1c6607f4ebVladimir Marko    block_labels_ = CommonInitializeLabels<Label>();
33092a73aef279be78e3c2b04db1713076183933436Nicolas Geoffray  }
33192a73aef279be78e3c2b04db1713076183933436Nicolas Geoffray
332840e5461a85f8908f51e7f6cd562a9129ff0e7ceNicolas Geoffray  bool NeedsTwoRegisters(Primitive::Type type ATTRIBUTE_UNUSED) const OVERRIDE {
333840e5461a85f8908f51e7f6cd562a9129ff0e7ceNicolas Geoffray    return false;
334840e5461a85f8908f51e7f6cd562a9129ff0e7ceNicolas Geoffray  }
335840e5461a85f8908f51e7f6cd562a9129ff0e7ceNicolas Geoffray
336dc151b2346bb8a4fdeed0c06e54c2fca21d59b5dVladimir Marko  // Check if the desired_dispatch_info is supported. If it is, return it,
337dc151b2346bb8a4fdeed0c06e54c2fca21d59b5dVladimir Marko  // otherwise return a fall-back info that should be used instead.
338dc151b2346bb8a4fdeed0c06e54c2fca21d59b5dVladimir Marko  HInvokeStaticOrDirect::DispatchInfo GetSupportedInvokeStaticOrDirectDispatch(
339dc151b2346bb8a4fdeed0c06e54c2fca21d59b5dVladimir Marko      const HInvokeStaticOrDirect::DispatchInfo& desired_dispatch_info,
340dc151b2346bb8a4fdeed0c06e54c2fca21d59b5dVladimir Marko      MethodReference target_method) OVERRIDE;
341dc151b2346bb8a4fdeed0c06e54c2fca21d59b5dVladimir Marko
34285b62f23fc6dfffe2ddd3ddfa74611666c9ff41dAndreas Gampe  void GenerateStaticOrDirectCall(HInvokeStaticOrDirect* invoke, Location temp) OVERRIDE;
34385b62f23fc6dfffe2ddd3ddfa74611666c9ff41dAndreas Gampe  void GenerateVirtualCall(HInvokeVirtual* invoke, Location temp) OVERRIDE;
34485b62f23fc6dfffe2ddd3ddfa74611666c9ff41dAndreas Gampe
34585b62f23fc6dfffe2ddd3ddfa74611666c9ff41dAndreas Gampe  void MoveFromReturnRegister(Location trg, Primitive::Type type) OVERRIDE;
34671fb52fee246b7d511f520febbd73dc7a9bbca79Andreas Gampe
347581550137ee3a068a14224870e71aeee924a0646Vladimir Marko  void EmitLinkerPatches(ArenaVector<LinkerPatch>* linker_patches) OVERRIDE;
348581550137ee3a068a14224870e71aeee924a0646Vladimir Marko
349fb8d279bc011b31d0765dc7ca59afea324fd0d0cMark Mendell  const X86_64InstructionSetFeatures& GetInstructionSetFeatures() const {
350fb8d279bc011b31d0765dc7ca59afea324fd0d0cMark Mendell    return isa_features_;
351fb8d279bc011b31d0765dc7ca59afea324fd0d0cMark Mendell  }
352fb8d279bc011b31d0765dc7ca59afea324fd0d0cMark Mendell
3530d5a281c671444bfa75d63caf1427a8c0e6e1177Roland Levillain  // Generate a read barrier for a heap reference within `instruction`.
3540d5a281c671444bfa75d63caf1427a8c0e6e1177Roland Levillain  //
3550d5a281c671444bfa75d63caf1427a8c0e6e1177Roland Levillain  // A read barrier for an object reference read from the heap is
3560d5a281c671444bfa75d63caf1427a8c0e6e1177Roland Levillain  // implemented as a call to the artReadBarrierSlow runtime entry
3570d5a281c671444bfa75d63caf1427a8c0e6e1177Roland Levillain  // point, which is passed the values in locations `ref`, `obj`, and
3580d5a281c671444bfa75d63caf1427a8c0e6e1177Roland Levillain  // `offset`:
3590d5a281c671444bfa75d63caf1427a8c0e6e1177Roland Levillain  //
3600d5a281c671444bfa75d63caf1427a8c0e6e1177Roland Levillain  //   mirror::Object* artReadBarrierSlow(mirror::Object* ref,
3610d5a281c671444bfa75d63caf1427a8c0e6e1177Roland Levillain  //                                      mirror::Object* obj,
3620d5a281c671444bfa75d63caf1427a8c0e6e1177Roland Levillain  //                                      uint32_t offset);
3630d5a281c671444bfa75d63caf1427a8c0e6e1177Roland Levillain  //
3640d5a281c671444bfa75d63caf1427a8c0e6e1177Roland Levillain  // The `out` location contains the value returned by
3650d5a281c671444bfa75d63caf1427a8c0e6e1177Roland Levillain  // artReadBarrierSlow.
3660d5a281c671444bfa75d63caf1427a8c0e6e1177Roland Levillain  //
3670d5a281c671444bfa75d63caf1427a8c0e6e1177Roland Levillain  // When `index` provided (i.e., when it is different from
3680d5a281c671444bfa75d63caf1427a8c0e6e1177Roland Levillain  // Location::NoLocation()), the offset value passed to
3690d5a281c671444bfa75d63caf1427a8c0e6e1177Roland Levillain  // artReadBarrierSlow is adjusted to take `index` into account.
3700d5a281c671444bfa75d63caf1427a8c0e6e1177Roland Levillain  void GenerateReadBarrier(HInstruction* instruction,
3710d5a281c671444bfa75d63caf1427a8c0e6e1177Roland Levillain                           Location out,
3720d5a281c671444bfa75d63caf1427a8c0e6e1177Roland Levillain                           Location ref,
3730d5a281c671444bfa75d63caf1427a8c0e6e1177Roland Levillain                           Location obj,
3740d5a281c671444bfa75d63caf1427a8c0e6e1177Roland Levillain                           uint32_t offset,
3750d5a281c671444bfa75d63caf1427a8c0e6e1177Roland Levillain                           Location index = Location::NoLocation());
3760d5a281c671444bfa75d63caf1427a8c0e6e1177Roland Levillain
3770d5a281c671444bfa75d63caf1427a8c0e6e1177Roland Levillain  // If read barriers are enabled, generate a read barrier for a heap reference.
3780d5a281c671444bfa75d63caf1427a8c0e6e1177Roland Levillain  // If heap poisoning is enabled, also unpoison the reference in `out`.
3790d5a281c671444bfa75d63caf1427a8c0e6e1177Roland Levillain  void MaybeGenerateReadBarrier(HInstruction* instruction,
3800d5a281c671444bfa75d63caf1427a8c0e6e1177Roland Levillain                                Location out,
3810d5a281c671444bfa75d63caf1427a8c0e6e1177Roland Levillain                                Location ref,
3820d5a281c671444bfa75d63caf1427a8c0e6e1177Roland Levillain                                Location obj,
3830d5a281c671444bfa75d63caf1427a8c0e6e1177Roland Levillain                                uint32_t offset,
3840d5a281c671444bfa75d63caf1427a8c0e6e1177Roland Levillain                                Location index = Location::NoLocation());
3850d5a281c671444bfa75d63caf1427a8c0e6e1177Roland Levillain
3860d5a281c671444bfa75d63caf1427a8c0e6e1177Roland Levillain  // Generate a read barrier for a GC root within `instruction`.
3870d5a281c671444bfa75d63caf1427a8c0e6e1177Roland Levillain  //
3880d5a281c671444bfa75d63caf1427a8c0e6e1177Roland Levillain  // A read barrier for an object reference GC root is implemented as
3890d5a281c671444bfa75d63caf1427a8c0e6e1177Roland Levillain  // a call to the artReadBarrierForRootSlow runtime entry point,
3900d5a281c671444bfa75d63caf1427a8c0e6e1177Roland Levillain  // which is passed the value in location `root`:
3910d5a281c671444bfa75d63caf1427a8c0e6e1177Roland Levillain  //
3920d5a281c671444bfa75d63caf1427a8c0e6e1177Roland Levillain  //   mirror::Object* artReadBarrierForRootSlow(GcRoot<mirror::Object>* root);
3930d5a281c671444bfa75d63caf1427a8c0e6e1177Roland Levillain  //
3940d5a281c671444bfa75d63caf1427a8c0e6e1177Roland Levillain  // The `out` location contains the value returned by
3950d5a281c671444bfa75d63caf1427a8c0e6e1177Roland Levillain  // artReadBarrierForRootSlow.
3960d5a281c671444bfa75d63caf1427a8c0e6e1177Roland Levillain  void GenerateReadBarrierForRoot(HInstruction* instruction, Location out, Location root);
3970d5a281c671444bfa75d63caf1427a8c0e6e1177Roland Levillain
398f55c3e0825cdfc4c5a27730031177d1a0198ec5aMark Mendell  int ConstantAreaStart() const {
399f55c3e0825cdfc4c5a27730031177d1a0198ec5aMark Mendell    return constant_area_start_;
400f55c3e0825cdfc4c5a27730031177d1a0198ec5aMark Mendell  }
401f55c3e0825cdfc4c5a27730031177d1a0198ec5aMark Mendell
402f55c3e0825cdfc4c5a27730031177d1a0198ec5aMark Mendell  Address LiteralDoubleAddress(double v);
403f55c3e0825cdfc4c5a27730031177d1a0198ec5aMark Mendell  Address LiteralFloatAddress(float v);
404f55c3e0825cdfc4c5a27730031177d1a0198ec5aMark Mendell  Address LiteralInt32Address(int32_t v);
405f55c3e0825cdfc4c5a27730031177d1a0198ec5aMark Mendell  Address LiteralInt64Address(int64_t v);
406f55c3e0825cdfc4c5a27730031177d1a0198ec5aMark Mendell
40792e83bf8c0b2df8c977ffbc527989631d94b1819Mark Mendell  // Load a 64 bit value into a register in the most efficient manner.
40892e83bf8c0b2df8c977ffbc527989631d94b1819Mark Mendell  void Load64BitValue(CpuRegister dest, int64_t value);
4099c86b485bc6169eadf846dd5f7cdf0958fe1eb23Mark Mendell  Address LiteralCaseTable(HPackedSwitch* switch_instr);
41092e83bf8c0b2df8c977ffbc527989631d94b1819Mark Mendell
411cfa410b0ea561318f74a76c5323f0f6cd8eaaa50Mark Mendell  // Store a 64 bit value into a DoubleStackSlot in the most efficient manner.
412cfa410b0ea561318f74a76c5323f0f6cd8eaaa50Mark Mendell  void Store64BitValueToStack(Location dest, int64_t value);
413cfa410b0ea561318f74a76c5323f0f6cd8eaaa50Mark Mendell
414ea5af68d6dda832bdfb5978a0c5d6f86a3f67e80Mark Mendell  // Assign a 64 bit constant to an address.
415ea5af68d6dda832bdfb5978a0c5d6f86a3f67e80Mark Mendell  void MoveInt64ToAddress(const Address& addr_low,
416ea5af68d6dda832bdfb5978a0c5d6f86a3f67e80Mark Mendell                          const Address& addr_high,
417ea5af68d6dda832bdfb5978a0c5d6f86a3f67e80Mark Mendell                          int64_t v,
418ea5af68d6dda832bdfb5978a0c5d6f86a3f67e80Mark Mendell                          HInstruction* instruction);
419ea5af68d6dda832bdfb5978a0c5d6f86a3f67e80Mark Mendell
4203c7bb98698f77af10372cf31824d3bb115d9bf0fNicolas Geoffray private:
421581550137ee3a068a14224870e71aeee924a0646Vladimir Marko  struct PcRelativeDexCacheAccessInfo {
422581550137ee3a068a14224870e71aeee924a0646Vladimir Marko    PcRelativeDexCacheAccessInfo(const DexFile& dex_file, uint32_t element_off)
423581550137ee3a068a14224870e71aeee924a0646Vladimir Marko        : target_dex_file(dex_file), element_offset(element_off), label() { }
424581550137ee3a068a14224870e71aeee924a0646Vladimir Marko
425581550137ee3a068a14224870e71aeee924a0646Vladimir Marko    const DexFile& target_dex_file;
426581550137ee3a068a14224870e71aeee924a0646Vladimir Marko    uint32_t element_offset;
427581550137ee3a068a14224870e71aeee924a0646Vladimir Marko    Label label;
428581550137ee3a068a14224870e71aeee924a0646Vladimir Marko  };
429581550137ee3a068a14224870e71aeee924a0646Vladimir Marko
43092a73aef279be78e3c2b04db1713076183933436Nicolas Geoffray  // Labels for each block that will be compiled.
431225b6464a58ebe11c156144653f11a1c6607f4ebVladimir Marko  Label* block_labels_;  // Indexed by block id.
4321cf95287364948689f6a1a320567acd7728e94a3Nicolas Geoffray  Label frame_entry_label_;
4339cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray  LocationsBuilderX86_64 location_builder_;
4349cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray  InstructionCodeGeneratorX86_64 instruction_visitor_;
435ecb2f9ba57b08ceac4204ddd6a0a88a0524f8741Nicolas Geoffray  ParallelMoveResolverX86_64 move_resolver_;
4369cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray  X86_64Assembler assembler_;
437fb8d279bc011b31d0765dc7ca59afea324fd0d0cMark Mendell  const X86_64InstructionSetFeatures& isa_features_;
4389cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray
43939dcf55a56da746e04f477f89e7b00ba1de03880Mark Mendell  // Offset to the start of the constant area in the assembled code.
440f55c3e0825cdfc4c5a27730031177d1a0198ec5aMark Mendell  // Used for fixups to the constant area.
441f55c3e0825cdfc4c5a27730031177d1a0198ec5aMark Mendell  int constant_area_start_;
442f55c3e0825cdfc4c5a27730031177d1a0198ec5aMark Mendell
443581550137ee3a068a14224870e71aeee924a0646Vladimir Marko  // Method patch info. Using ArenaDeque<> which retains element addresses on push/emplace_back().
444581550137ee3a068a14224870e71aeee924a0646Vladimir Marko  ArenaDeque<MethodPatchInfo<Label>> method_patches_;
445581550137ee3a068a14224870e71aeee924a0646Vladimir Marko  ArenaDeque<MethodPatchInfo<Label>> relative_call_patches_;
446581550137ee3a068a14224870e71aeee924a0646Vladimir Marko  // PC-relative DexCache access info.
4470f7dca4ca0be8d2f8776794d35edf8b51b5bc997Vladimir Marko  ArenaDeque<PcRelativeDexCacheAccessInfo> pc_relative_dex_cache_patches_;
448581550137ee3a068a14224870e71aeee924a0646Vladimir Marko
449581550137ee3a068a14224870e71aeee924a0646Vladimir Marko  // When we don't know the proper offset for the value, we use kDummy32BitOffset.
450581550137ee3a068a14224870e71aeee924a0646Vladimir Marko  // We will fix this up in the linker later to have the right value.
451581550137ee3a068a14224870e71aeee924a0646Vladimir Marko  static constexpr int32_t kDummy32BitOffset = 256;
452581550137ee3a068a14224870e71aeee924a0646Vladimir Marko
4539c86b485bc6169eadf846dd5f7cdf0958fe1eb23Mark Mendell  // Fixups for jump tables need to be handled specially.
4549c86b485bc6169eadf846dd5f7cdf0958fe1eb23Mark Mendell  ArenaVector<JumpTableRIPFixup*> fixups_to_jump_tables_;
4559c86b485bc6169eadf846dd5f7cdf0958fe1eb23Mark Mendell
4569cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray  DISALLOW_COPY_AND_ASSIGN(CodeGeneratorX86_64);
4579cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray};
4589cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray
4599cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray}  // namespace x86_64
4609cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray}  // namespace art
4619cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray
4629cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray#endif  // ART_COMPILER_OPTIMIZING_CODE_GENERATOR_X86_64_H_
463