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 2017077d888a6752a2e5f8161eee1b2c3285783d12Mark P Mendell#include "arch/x86_64/instruction_set_features_x86_64.h" 219cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray#include "code_generator.h" 2252c489645b6e9ae33623f1ec24143cde5444906eCalin Juravle#include "dex/compiler_enums.h" 23cd6dffedf1bd8e6dfb3fb0c933551f9a90f7de3fCalin Juravle#include "driver/compiler_options.h" 249cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray#include "nodes.h" 25ecb2f9ba57b08ceac4204ddd6a0a88a0524f8741Nicolas Geoffray#include "parallel_move_resolver.h" 269cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray#include "utils/x86_64/assembler_x86_64.h" 279cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray 289cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffraynamespace art { 299cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffraynamespace x86_64 { 309cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray 3186a8d7afc7f00ff0f5ea7b8aaf4d50514250a4e6Nicolas Geoffray// Use a local definition to prevent copying mistakes. 3286a8d7afc7f00ff0f5ea7b8aaf4d50514250a4e6Nicolas Geoffraystatic constexpr size_t kX86_64WordSize = kX86_64PointerSize; 339cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray 34ee3cf0731d0ef0787bc2947c8e3ca432b513956bNicolas Geoffray// Some x86_64 instructions require a register to be available as temp. 35ee3cf0731d0ef0787bc2947c8e3ca432b513956bNicolas Geoffraystatic constexpr Register TMP = R11; 36ee3cf0731d0ef0787bc2947c8e3ca432b513956bNicolas Geoffray 379cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffraystatic constexpr Register kParameterCoreRegisters[] = { RSI, RDX, RCX, R8, R9 }; 387fb49da8ec62e8a10ed9419ade9f32c6b1174687Nicolas Geoffraystatic constexpr FloatRegister kParameterFloatRegisters[] = 397fb49da8ec62e8a10ed9419ade9f32c6b1174687Nicolas Geoffray { XMM0, XMM1, XMM2, XMM3, XMM4, XMM5, XMM6, XMM7 }; 409cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray 419cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffraystatic constexpr size_t kParameterCoreRegistersLength = arraysize(kParameterCoreRegisters); 427fb49da8ec62e8a10ed9419ade9f32c6b1174687Nicolas Geoffraystatic constexpr size_t kParameterFloatRegistersLength = arraysize(kParameterFloatRegisters); 439cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray 44848f70a3d73833fc1bf3032a9ff6812e429661d9Jeff Haostatic constexpr Register kRuntimeParameterCoreRegisters[] = { RDI, RSI, RDX, RCX }; 45d75948ac93a4a317feaf136cae78823071234ba5Nicolas Geoffraystatic constexpr size_t kRuntimeParameterCoreRegistersLength = 46d75948ac93a4a317feaf136cae78823071234ba5Nicolas Geoffray arraysize(kRuntimeParameterCoreRegisters); 47d75948ac93a4a317feaf136cae78823071234ba5Nicolas Geoffraystatic constexpr FloatRegister kRuntimeParameterFpuRegisters[] = { XMM0, XMM1 }; 48d75948ac93a4a317feaf136cae78823071234ba5Nicolas Geoffraystatic constexpr size_t kRuntimeParameterFpuRegistersLength = 49d75948ac93a4a317feaf136cae78823071234ba5Nicolas Geoffray arraysize(kRuntimeParameterFpuRegisters); 50d75948ac93a4a317feaf136cae78823071234ba5Nicolas Geoffray 51a4f1220c1518074db18ca1044e9201492975750bMark Mendell// These XMM registers are non-volatile in ART ABI, but volatile in native ABI. 52a4f1220c1518074db18ca1044e9201492975750bMark Mendell// If the ART ABI changes, this list must be updated. It is used to ensure that 53a4f1220c1518074db18ca1044e9201492975750bMark Mendell// these are not clobbered by any direct call to native code (such as math intrinsics). 54a4f1220c1518074db18ca1044e9201492975750bMark Mendellstatic constexpr FloatRegister non_volatile_xmm_regs[] = { XMM12, XMM13, XMM14, XMM15 }; 55a4f1220c1518074db18ca1044e9201492975750bMark Mendell 56a4f1220c1518074db18ca1044e9201492975750bMark Mendell 57d75948ac93a4a317feaf136cae78823071234ba5Nicolas Geoffrayclass InvokeRuntimeCallingConvention : public CallingConvention<Register, FloatRegister> { 58d75948ac93a4a317feaf136cae78823071234ba5Nicolas Geoffray public: 59d75948ac93a4a317feaf136cae78823071234ba5Nicolas Geoffray InvokeRuntimeCallingConvention() 60d75948ac93a4a317feaf136cae78823071234ba5Nicolas Geoffray : CallingConvention(kRuntimeParameterCoreRegisters, 61d75948ac93a4a317feaf136cae78823071234ba5Nicolas Geoffray kRuntimeParameterCoreRegistersLength, 62d75948ac93a4a317feaf136cae78823071234ba5Nicolas Geoffray kRuntimeParameterFpuRegisters, 63e401d146407d61eeb99f8d6176b2ac13c4df1e33Mathieu Chartier kRuntimeParameterFpuRegistersLength, 64e401d146407d61eeb99f8d6176b2ac13c4df1e33Mathieu Chartier kX86_64PointerSize) {} 65d75948ac93a4a317feaf136cae78823071234ba5Nicolas Geoffray 66d75948ac93a4a317feaf136cae78823071234ba5Nicolas Geoffray private: 67d75948ac93a4a317feaf136cae78823071234ba5Nicolas Geoffray DISALLOW_COPY_AND_ASSIGN(InvokeRuntimeCallingConvention); 68d75948ac93a4a317feaf136cae78823071234ba5Nicolas Geoffray}; 69d75948ac93a4a317feaf136cae78823071234ba5Nicolas Geoffray 707fb49da8ec62e8a10ed9419ade9f32c6b1174687Nicolas Geoffrayclass InvokeDexCallingConvention : public CallingConvention<Register, FloatRegister> { 719cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray public: 727fb49da8ec62e8a10ed9419ade9f32c6b1174687Nicolas Geoffray InvokeDexCallingConvention() : CallingConvention( 737fb49da8ec62e8a10ed9419ade9f32c6b1174687Nicolas Geoffray kParameterCoreRegisters, 747fb49da8ec62e8a10ed9419ade9f32c6b1174687Nicolas Geoffray kParameterCoreRegistersLength, 757fb49da8ec62e8a10ed9419ade9f32c6b1174687Nicolas Geoffray kParameterFloatRegisters, 76e401d146407d61eeb99f8d6176b2ac13c4df1e33Mathieu Chartier kParameterFloatRegistersLength, 77e401d146407d61eeb99f8d6176b2ac13c4df1e33Mathieu Chartier kX86_64PointerSize) {} 789cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray 799cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray private: 809cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray DISALLOW_COPY_AND_ASSIGN(InvokeDexCallingConvention); 819cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray}; 829cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray 83e460d1df1f789c7c8bb97024a8efbd713ac175e9Calin Juravleclass FieldAccessCallingConventionX86_64 : public FieldAccessCallingConvention { 84e460d1df1f789c7c8bb97024a8efbd713ac175e9Calin Juravle public: 85e460d1df1f789c7c8bb97024a8efbd713ac175e9Calin Juravle FieldAccessCallingConventionX86_64() {} 86e460d1df1f789c7c8bb97024a8efbd713ac175e9Calin Juravle 87e460d1df1f789c7c8bb97024a8efbd713ac175e9Calin Juravle Location GetObjectLocation() const OVERRIDE { 88e460d1df1f789c7c8bb97024a8efbd713ac175e9Calin Juravle return Location::RegisterLocation(RSI); 89e460d1df1f789c7c8bb97024a8efbd713ac175e9Calin Juravle } 90e460d1df1f789c7c8bb97024a8efbd713ac175e9Calin Juravle Location GetFieldIndexLocation() const OVERRIDE { 91e460d1df1f789c7c8bb97024a8efbd713ac175e9Calin Juravle return Location::RegisterLocation(RDI); 92e460d1df1f789c7c8bb97024a8efbd713ac175e9Calin Juravle } 93e460d1df1f789c7c8bb97024a8efbd713ac175e9Calin Juravle Location GetReturnLocation(Primitive::Type type ATTRIBUTE_UNUSED) const OVERRIDE { 94e460d1df1f789c7c8bb97024a8efbd713ac175e9Calin Juravle return Location::RegisterLocation(RAX); 95e460d1df1f789c7c8bb97024a8efbd713ac175e9Calin Juravle } 96e460d1df1f789c7c8bb97024a8efbd713ac175e9Calin Juravle Location GetSetValueLocation(Primitive::Type type, bool is_instance) const OVERRIDE { 97e460d1df1f789c7c8bb97024a8efbd713ac175e9Calin Juravle return Primitive::Is64BitType(type) 98e460d1df1f789c7c8bb97024a8efbd713ac175e9Calin Juravle ? Location::RegisterLocation(RDX) 99e460d1df1f789c7c8bb97024a8efbd713ac175e9Calin Juravle : (is_instance 100e460d1df1f789c7c8bb97024a8efbd713ac175e9Calin Juravle ? Location::RegisterLocation(RDX) 101e460d1df1f789c7c8bb97024a8efbd713ac175e9Calin Juravle : Location::RegisterLocation(RSI)); 102e460d1df1f789c7c8bb97024a8efbd713ac175e9Calin Juravle } 103e460d1df1f789c7c8bb97024a8efbd713ac175e9Calin Juravle Location GetFpuLocation(Primitive::Type type ATTRIBUTE_UNUSED) const OVERRIDE { 104e460d1df1f789c7c8bb97024a8efbd713ac175e9Calin Juravle return Location::FpuRegisterLocation(XMM0); 105e460d1df1f789c7c8bb97024a8efbd713ac175e9Calin Juravle } 106e460d1df1f789c7c8bb97024a8efbd713ac175e9Calin Juravle 107e460d1df1f789c7c8bb97024a8efbd713ac175e9Calin Juravle private: 108e460d1df1f789c7c8bb97024a8efbd713ac175e9Calin Juravle DISALLOW_COPY_AND_ASSIGN(FieldAccessCallingConventionX86_64); 109e460d1df1f789c7c8bb97024a8efbd713ac175e9Calin Juravle}; 110e460d1df1f789c7c8bb97024a8efbd713ac175e9Calin Juravle 111e460d1df1f789c7c8bb97024a8efbd713ac175e9Calin Juravle 1122d27c8e338af7262dbd4aaa66127bb8fa1758b86Roland Levillainclass InvokeDexCallingConventionVisitorX86_64 : public InvokeDexCallingConventionVisitor { 1139cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray public: 1142d27c8e338af7262dbd4aaa66127bb8fa1758b86Roland Levillain InvokeDexCallingConventionVisitorX86_64() {} 1152d27c8e338af7262dbd4aaa66127bb8fa1758b86Roland Levillain virtual ~InvokeDexCallingConventionVisitorX86_64() {} 1169cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray 1172d27c8e338af7262dbd4aaa66127bb8fa1758b86Roland Levillain Location GetNextLocation(Primitive::Type type) OVERRIDE; 118fd88f16100cceafbfde1b4f095f17e89444d6fa8Nicolas Geoffray Location GetReturnLocation(Primitive::Type type) const OVERRIDE; 119fd88f16100cceafbfde1b4f095f17e89444d6fa8Nicolas Geoffray Location GetMethodLocation() const OVERRIDE; 1209cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray 1219cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray private: 1229cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray InvokeDexCallingConvention calling_convention; 1232d27c8e338af7262dbd4aaa66127bb8fa1758b86Roland Levillain 1242d27c8e338af7262dbd4aaa66127bb8fa1758b86Roland Levillain DISALLOW_COPY_AND_ASSIGN(InvokeDexCallingConventionVisitorX86_64); 1259cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray}; 1269cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray 1279cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffrayclass CodeGeneratorX86_64; 12871fb52fee246b7d511f520febbd73dc7a9bbca79Andreas Gampe 129ad4450e5c3ffaa9566216cc6fafbf5c11186c467Zheng Xuclass ParallelMoveResolverX86_64 : public ParallelMoveResolverWithSwap { 130ecb2f9ba57b08ceac4204ddd6a0a88a0524f8741Nicolas Geoffray public: 131ecb2f9ba57b08ceac4204ddd6a0a88a0524f8741Nicolas Geoffray ParallelMoveResolverX86_64(ArenaAllocator* allocator, CodeGeneratorX86_64* codegen) 132ad4450e5c3ffaa9566216cc6fafbf5c11186c467Zheng Xu : ParallelMoveResolverWithSwap(allocator), codegen_(codegen) {} 133ecb2f9ba57b08ceac4204ddd6a0a88a0524f8741Nicolas Geoffray 134de58ab2c03ff8112b07ab827c8fa38f670dfc656Nicolas Geoffray void EmitMove(size_t index) OVERRIDE; 135de58ab2c03ff8112b07ab827c8fa38f670dfc656Nicolas Geoffray void EmitSwap(size_t index) OVERRIDE; 136de58ab2c03ff8112b07ab827c8fa38f670dfc656Nicolas Geoffray void SpillScratch(int reg) OVERRIDE; 137de58ab2c03ff8112b07ab827c8fa38f670dfc656Nicolas Geoffray void RestoreScratch(int reg) OVERRIDE; 138ecb2f9ba57b08ceac4204ddd6a0a88a0524f8741Nicolas Geoffray 139ecb2f9ba57b08ceac4204ddd6a0a88a0524f8741Nicolas Geoffray X86_64Assembler* GetAssembler() const; 140ecb2f9ba57b08ceac4204ddd6a0a88a0524f8741Nicolas Geoffray 141ecb2f9ba57b08ceac4204ddd6a0a88a0524f8741Nicolas Geoffray private: 142412f10cfed002ab617c78f2621d68446ca4dd8bdNicolas Geoffray void Exchange32(CpuRegister reg, int mem); 143102cbed1e52b7c5f09458b44903fe97bb3e14d5fNicolas Geoffray void Exchange32(XmmRegister reg, int mem); 144412f10cfed002ab617c78f2621d68446ca4dd8bdNicolas Geoffray void Exchange32(int mem1, int mem2); 1458a1c728e40813d30a85a1f27afaf16a3f105d32aMark Mendell void Exchange64(CpuRegister reg1, CpuRegister reg2); 146412f10cfed002ab617c78f2621d68446ca4dd8bdNicolas Geoffray void Exchange64(CpuRegister reg, int mem); 147102cbed1e52b7c5f09458b44903fe97bb3e14d5fNicolas Geoffray void Exchange64(XmmRegister reg, int mem); 148412f10cfed002ab617c78f2621d68446ca4dd8bdNicolas Geoffray void Exchange64(int mem1, int mem2); 149ecb2f9ba57b08ceac4204ddd6a0a88a0524f8741Nicolas Geoffray 150ecb2f9ba57b08ceac4204ddd6a0a88a0524f8741Nicolas Geoffray CodeGeneratorX86_64* const codegen_; 151ecb2f9ba57b08ceac4204ddd6a0a88a0524f8741Nicolas Geoffray 152ecb2f9ba57b08ceac4204ddd6a0a88a0524f8741Nicolas Geoffray DISALLOW_COPY_AND_ASSIGN(ParallelMoveResolverX86_64); 153ecb2f9ba57b08ceac4204ddd6a0a88a0524f8741Nicolas Geoffray}; 154ecb2f9ba57b08ceac4204ddd6a0a88a0524f8741Nicolas Geoffray 1559cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffrayclass LocationsBuilderX86_64 : public HGraphVisitor { 1569cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray public: 1579cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray LocationsBuilderX86_64(HGraph* graph, CodeGeneratorX86_64* codegen) 1589cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray : HGraphVisitor(graph), codegen_(codegen) {} 1599cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray 160360231a056e796c36ffe62348507e904dc9efb9bNicolas Geoffray#define DECLARE_VISIT_INSTRUCTION(name, super) \ 161de58ab2c03ff8112b07ab827c8fa38f670dfc656Nicolas Geoffray void Visit##name(H##name* instr) OVERRIDE; 1629cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray 163ef20f71e16f035a39a329c8524d7e59ca6a11f04Alexandre Rames FOR_EACH_CONCRETE_INSTRUCTION_COMMON(DECLARE_VISIT_INSTRUCTION) 164ef20f71e16f035a39a329c8524d7e59ca6a11f04Alexandre Rames FOR_EACH_CONCRETE_INSTRUCTION_X86_64(DECLARE_VISIT_INSTRUCTION) 1659cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray 1669cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray#undef DECLARE_VISIT_INSTRUCTION 1679cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray 168ef20f71e16f035a39a329c8524d7e59ca6a11f04Alexandre Rames void VisitInstruction(HInstruction* instruction) OVERRIDE { 169ef20f71e16f035a39a329c8524d7e59ca6a11f04Alexandre Rames LOG(FATAL) << "Unreachable instruction " << instruction->DebugName() 170ef20f71e16f035a39a329c8524d7e59ca6a11f04Alexandre Rames << " (id " << instruction->GetId() << ")"; 171ef20f71e16f035a39a329c8524d7e59ca6a11f04Alexandre Rames } 172ef20f71e16f035a39a329c8524d7e59ca6a11f04Alexandre Rames 1739574c4b5f5ef039d694ac12c97e25ca02eca83c0Nicolas Geoffray private: 174e982f0b8e809cece6f460fa2d8df25873aa69de4Nicolas Geoffray void HandleInvoke(HInvoke* invoke); 1759574c4b5f5ef039d694ac12c97e25ca02eca83c0Nicolas Geoffray void HandleBitwiseOperation(HBinaryOperation* operation); 1765f7b58ea1adfc0639dd605b65f59198d3763f801Vladimir Marko void HandleCondition(HCondition* condition); 1779aec02fc5df5518c16f1e5a9b6cb198a192db973Calin Juravle void HandleShift(HBinaryOperation* operation); 17852c489645b6e9ae33623f1ec24143cde5444906eCalin Juravle void HandleFieldSet(HInstruction* instruction, const FieldInfo& field_info); 17952c489645b6e9ae33623f1ec24143cde5444906eCalin Juravle void HandleFieldGet(HInstruction* instruction); 180e982f0b8e809cece6f460fa2d8df25873aa69de4Nicolas Geoffray 1819cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray CodeGeneratorX86_64* const codegen_; 1822d27c8e338af7262dbd4aaa66127bb8fa1758b86Roland Levillain InvokeDexCallingConventionVisitorX86_64 parameter_visitor_; 1839cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray 1849cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray DISALLOW_COPY_AND_ASSIGN(LocationsBuilderX86_64); 1859cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray}; 1869cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray 18742249c3602c3d0243396ee3627ffb5906aa77c1eAart Bikclass InstructionCodeGeneratorX86_64 : public InstructionCodeGenerator { 1889cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray public: 1899cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray InstructionCodeGeneratorX86_64(HGraph* graph, CodeGeneratorX86_64* codegen); 1909cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray 191360231a056e796c36ffe62348507e904dc9efb9bNicolas Geoffray#define DECLARE_VISIT_INSTRUCTION(name, super) \ 192de58ab2c03ff8112b07ab827c8fa38f670dfc656Nicolas Geoffray void Visit##name(H##name* instr) OVERRIDE; 1939cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray 194ef20f71e16f035a39a329c8524d7e59ca6a11f04Alexandre Rames FOR_EACH_CONCRETE_INSTRUCTION_COMMON(DECLARE_VISIT_INSTRUCTION) 195ef20f71e16f035a39a329c8524d7e59ca6a11f04Alexandre Rames FOR_EACH_CONCRETE_INSTRUCTION_X86_64(DECLARE_VISIT_INSTRUCTION) 1969cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray 1979cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray#undef DECLARE_VISIT_INSTRUCTION 1989cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray 199ef20f71e16f035a39a329c8524d7e59ca6a11f04Alexandre Rames void VisitInstruction(HInstruction* instruction) OVERRIDE { 200ef20f71e16f035a39a329c8524d7e59ca6a11f04Alexandre Rames LOG(FATAL) << "Unreachable instruction " << instruction->DebugName() 201ef20f71e16f035a39a329c8524d7e59ca6a11f04Alexandre Rames << " (id " << instruction->GetId() << ")"; 202ef20f71e16f035a39a329c8524d7e59ca6a11f04Alexandre Rames } 203ef20f71e16f035a39a329c8524d7e59ca6a11f04Alexandre Rames 2049cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray X86_64Assembler* GetAssembler() const { return assembler_; } 2059cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray 2069cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray private: 2073c04974a90b0e03f4b509010bff49f0b2a3da57fNicolas Geoffray // Generate code for the given suspend check. If not null, `successor` 2083c04974a90b0e03f4b509010bff49f0b2a3da57fNicolas Geoffray // is the block to branch to if the suspend check is not needed, and after 2093c04974a90b0e03f4b509010bff49f0b2a3da57fNicolas Geoffray // the suspend call. 2103c04974a90b0e03f4b509010bff49f0b2a3da57fNicolas Geoffray void GenerateSuspendCheck(HSuspendCheck* instruction, HBasicBlock* successor); 21185b62f23fc6dfffe2ddd3ddfa74611666c9ff41dAndreas Gampe void GenerateClassInitializationCheck(SlowPathCode* slow_path, CpuRegister class_reg); 2129574c4b5f5ef039d694ac12c97e25ca02eca83c0Nicolas Geoffray void HandleBitwiseOperation(HBinaryOperation* operation); 213c470193cfc522fc818eb2eaab896aef9caf0c75aMark Mendell void GenerateRemFP(HRem* rem); 2140f88e87085b7cf6544dadff3f555773966a6853eGuillaume Sanchez void DivRemOneOrMinusOne(HBinaryOperation* instruction); 215b19930c5cba3cf662dce5ee057fcc9829b4cbb9cGuillaume Sanchez void DivByPowerOfTwo(HDiv* instruction); 2160f88e87085b7cf6544dadff3f555773966a6853eGuillaume Sanchez void GenerateDivRemWithAnyConstant(HBinaryOperation* instruction); 217bacfec30ee9f2f6fdfd190f11b105b609938efcaCalin Juravle void GenerateDivRemIntegral(HBinaryOperation* instruction); 2185f7b58ea1adfc0639dd605b65f59198d3763f801Vladimir Marko void HandleCondition(HCondition* condition); 2199aec02fc5df5518c16f1e5a9b6cb198a192db973Calin Juravle void HandleShift(HBinaryOperation* operation); 2201e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain 22107276db28d654594e0e86e9e467cad393f752e6eNicolas Geoffray void HandleFieldSet(HInstruction* instruction, 22207276db28d654594e0e86e9e467cad393f752e6eNicolas Geoffray const FieldInfo& field_info, 22307276db28d654594e0e86e9e467cad393f752e6eNicolas Geoffray bool value_can_be_null); 22452c489645b6e9ae33623f1ec24143cde5444906eCalin Juravle void HandleFieldGet(HInstruction* instruction, const FieldInfo& field_info); 2251e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain 2261e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain // Generate a heap reference load using one register `out`: 2271e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain // 2281e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain // out <- *(out + offset) 2291e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain // 2301e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain // while honoring heap poisoning and/or read barriers (if any). 23195e7ffc28ea4d6deba356e636b16120ae49b62e2Roland Levillain // 23295e7ffc28ea4d6deba356e636b16120ae49b62e2Roland Levillain // Location `maybe_temp` is used when generating a read barrier and 23395e7ffc28ea4d6deba356e636b16120ae49b62e2Roland Levillain // shall be a register in that case; it may be an invalid location 23495e7ffc28ea4d6deba356e636b16120ae49b62e2Roland Levillain // otherwise. 2351e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain void GenerateReferenceLoadOneRegister(HInstruction* instruction, 2361e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain Location out, 2371e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain uint32_t offset, 23895e7ffc28ea4d6deba356e636b16120ae49b62e2Roland Levillain Location maybe_temp); 2391e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain // Generate a heap reference load using two different registers 2401e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain // `out` and `obj`: 2411e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain // 2421e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain // out <- *(obj + offset) 2431e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain // 2441e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain // while honoring heap poisoning and/or read barriers (if any). 24595e7ffc28ea4d6deba356e636b16120ae49b62e2Roland Levillain // 24695e7ffc28ea4d6deba356e636b16120ae49b62e2Roland Levillain // Location `maybe_temp` is used when generating a Baker's (fast 24795e7ffc28ea4d6deba356e636b16120ae49b62e2Roland Levillain // path) read barrier and shall be a register in that case; it may 24895e7ffc28ea4d6deba356e636b16120ae49b62e2Roland Levillain // be an invalid location otherwise. 2491e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain void GenerateReferenceLoadTwoRegisters(HInstruction* instruction, 2501e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain Location out, 2511e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain Location obj, 2521e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain uint32_t offset, 25395e7ffc28ea4d6deba356e636b16120ae49b62e2Roland Levillain Location maybe_temp); 2541e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain // Generate a GC root reference load: 2551e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain // 256cac5a7e871f1f346b317894359ad06fa7bd67fbaVladimir Marko // root <- *address 2571e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain // 2581e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain // while honoring read barriers (if any). 2591e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain void GenerateGcRootFieldLoad(HInstruction* instruction, 2601e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain Location root, 261cac5a7e871f1f346b317894359ad06fa7bd67fbaVladimir Marko const Address& address, 262cac5a7e871f1f346b317894359ad06fa7bd67fbaVladimir Marko Label* fixup_label = nullptr); 2631e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain 26424f2dfae084b2382c053f5d688fd6bb26cb8a328Mark Mendell void PushOntoFPStack(Location source, uint32_t temp_offset, 26524f2dfae084b2382c053f5d688fd6bb26cb8a328Mark Mendell uint32_t stack_adjustment, bool is_float); 2667c0b44f180f1b8cf82c568091d250071d1130954Mark Mendell void GenerateCompareTest(HCondition* condition); 267152408f8c2188a7ed950cad04883b2f67dc74e84Mark Mendell template<class LabelType> 268d43b3ac88cd46b8815890188c9c2b9a3f1564648Mingyao Yang void GenerateTestAndBranch(HInstruction* instruction, 2690debae7bc89eb05f7a2bf7dccd223318fad7c88dDavid Brazdil size_t condition_input_index, 270152408f8c2188a7ed950cad04883b2f67dc74e84Mark Mendell LabelType* true_target, 271152408f8c2188a7ed950cad04883b2f67dc74e84Mark Mendell LabelType* false_target); 272152408f8c2188a7ed950cad04883b2f67dc74e84Mark Mendell template<class LabelType> 2730debae7bc89eb05f7a2bf7dccd223318fad7c88dDavid Brazdil void GenerateCompareTestAndBranch(HCondition* condition, 274152408f8c2188a7ed950cad04883b2f67dc74e84Mark Mendell LabelType* true_target, 275152408f8c2188a7ed950cad04883b2f67dc74e84Mark Mendell LabelType* false_target); 276152408f8c2188a7ed950cad04883b2f67dc74e84Mark Mendell template<class LabelType> 277152408f8c2188a7ed950cad04883b2f67dc74e84Mark Mendell void GenerateFPJumps(HCondition* cond, LabelType* true_label, LabelType* false_label); 278152408f8c2188a7ed950cad04883b2f67dc74e84Mark Mendell 279fc6a86ab2b70781e72b807c1798b83829ca7f931David Brazdil void HandleGoto(HInstruction* got, HBasicBlock* successor); 2803c04974a90b0e03f4b509010bff49f0b2a3da57fNicolas Geoffray 2819cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray X86_64Assembler* const assembler_; 2829cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray CodeGeneratorX86_64* const codegen_; 2839cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray 2849cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray DISALLOW_COPY_AND_ASSIGN(InstructionCodeGeneratorX86_64); 2859cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray}; 2869cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray 2879c86b485bc6169eadf846dd5f7cdf0958fe1eb23Mark Mendell// Class for fixups to jump tables. 2889c86b485bc6169eadf846dd5f7cdf0958fe1eb23Mark Mendellclass JumpTableRIPFixup; 2899c86b485bc6169eadf846dd5f7cdf0958fe1eb23Mark Mendell 2909cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffrayclass CodeGeneratorX86_64 : public CodeGenerator { 2919cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray public: 292fb8d279bc011b31d0765dc7ca59afea324fd0d0cMark Mendell CodeGeneratorX86_64(HGraph* graph, 293fb8d279bc011b31d0765dc7ca59afea324fd0d0cMark Mendell const X86_64InstructionSetFeatures& isa_features, 294ecc4366670e12b4812ef1653f7c8d52234ca1b1fSerban Constantinescu const CompilerOptions& compiler_options, 295ecc4366670e12b4812ef1653f7c8d52234ca1b1fSerban Constantinescu OptimizingCompilerStats* stats = nullptr); 2969cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray virtual ~CodeGeneratorX86_64() {} 2979cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray 298de58ab2c03ff8112b07ab827c8fa38f670dfc656Nicolas Geoffray void GenerateFrameEntry() OVERRIDE; 299de58ab2c03ff8112b07ab827c8fa38f670dfc656Nicolas Geoffray void GenerateFrameExit() OVERRIDE; 300de58ab2c03ff8112b07ab827c8fa38f670dfc656Nicolas Geoffray void Bind(HBasicBlock* block) OVERRIDE; 301175dc732c80e6f2afd83209348124df349290ba8Calin Juravle void MoveConstant(Location destination, int32_t value) OVERRIDE; 302e460d1df1f789c7c8bb97024a8efbd713ac175e9Calin Juravle void MoveLocation(Location dst, Location src, Primitive::Type dst_type) OVERRIDE; 303e460d1df1f789c7c8bb97024a8efbd713ac175e9Calin Juravle void AddLocationAsTemp(Location location, LocationSummary* locations) OVERRIDE; 304e460d1df1f789c7c8bb97024a8efbd713ac175e9Calin Juravle 305de58ab2c03ff8112b07ab827c8fa38f670dfc656Nicolas Geoffray size_t SaveCoreRegister(size_t stack_index, uint32_t reg_id) OVERRIDE; 306de58ab2c03ff8112b07ab827c8fa38f670dfc656Nicolas Geoffray size_t RestoreCoreRegister(size_t stack_index, uint32_t reg_id) OVERRIDE; 307de58ab2c03ff8112b07ab827c8fa38f670dfc656Nicolas Geoffray size_t SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) OVERRIDE; 308de58ab2c03ff8112b07ab827c8fa38f670dfc656Nicolas Geoffray size_t RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) OVERRIDE; 3099cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray 3108158f28b6689314213eb4dbbe14166073be71f7eAlexandre Rames // Generate code to invoke a runtime entry point. 311175dc732c80e6f2afd83209348124df349290ba8Calin Juravle void InvokeRuntime(QuickEntrypointEnum entrypoint, 312175dc732c80e6f2afd83209348124df349290ba8Calin Juravle HInstruction* instruction, 313175dc732c80e6f2afd83209348124df349290ba8Calin Juravle uint32_t dex_pc, 314175dc732c80e6f2afd83209348124df349290ba8Calin Juravle SlowPathCode* slow_path) OVERRIDE; 315175dc732c80e6f2afd83209348124df349290ba8Calin Juravle 316175dc732c80e6f2afd83209348124df349290ba8Calin Juravle void InvokeRuntime(int32_t entry_point_offset, 3178158f28b6689314213eb4dbbe14166073be71f7eAlexandre Rames HInstruction* instruction, 3188158f28b6689314213eb4dbbe14166073be71f7eAlexandre Rames uint32_t dex_pc, 3198158f28b6689314213eb4dbbe14166073be71f7eAlexandre Rames SlowPathCode* slow_path); 3208158f28b6689314213eb4dbbe14166073be71f7eAlexandre Rames 321de58ab2c03ff8112b07ab827c8fa38f670dfc656Nicolas Geoffray size_t GetWordSize() const OVERRIDE { 3229cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray return kX86_64WordSize; 3239cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray } 3249cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray 325f85a9ca9859ad843dc03d3a2b600afbaf2e9bbddMark Mendell size_t GetFloatingPointSpillSlotSize() const OVERRIDE { 326f85a9ca9859ad843dc03d3a2b600afbaf2e9bbddMark Mendell return kX86_64WordSize; 327f85a9ca9859ad843dc03d3a2b600afbaf2e9bbddMark Mendell } 328f85a9ca9859ad843dc03d3a2b600afbaf2e9bbddMark Mendell 329de58ab2c03ff8112b07ab827c8fa38f670dfc656Nicolas Geoffray HGraphVisitor* GetLocationBuilder() OVERRIDE { 3309cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray return &location_builder_; 3319cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray } 3329cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray 333de58ab2c03ff8112b07ab827c8fa38f670dfc656Nicolas Geoffray HGraphVisitor* GetInstructionVisitor() OVERRIDE { 3349cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray return &instruction_visitor_; 3359cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray } 3369cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray 337de58ab2c03ff8112b07ab827c8fa38f670dfc656Nicolas Geoffray X86_64Assembler* GetAssembler() OVERRIDE { 3389cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray return &assembler_; 3399cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray } 3409cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray 341eb7b7399dbdb5e471b8ae00a567bf4f19edd3907Alexandre Rames const X86_64Assembler& GetAssembler() const OVERRIDE { 342eb7b7399dbdb5e471b8ae00a567bf4f19edd3907Alexandre Rames return assembler_; 343eb7b7399dbdb5e471b8ae00a567bf4f19edd3907Alexandre Rames } 344eb7b7399dbdb5e471b8ae00a567bf4f19edd3907Alexandre Rames 345f0e3937b87453234d0d7970b8712082062709b8dNicolas Geoffray ParallelMoveResolverX86_64* GetMoveResolver() OVERRIDE { 346ecb2f9ba57b08ceac4204ddd6a0a88a0524f8741Nicolas Geoffray return &move_resolver_; 347ecb2f9ba57b08ceac4204ddd6a0a88a0524f8741Nicolas Geoffray } 348ecb2f9ba57b08ceac4204ddd6a0a88a0524f8741Nicolas Geoffray 349c393d63aa2b8f6984672fdd4de631bbeff14b6a2Alexandre Rames uintptr_t GetAddressOf(HBasicBlock* block) OVERRIDE { 350de58ab2c03ff8112b07ab827c8fa38f670dfc656Nicolas Geoffray return GetLabelOf(block)->Position(); 351de58ab2c03ff8112b07ab827c8fa38f670dfc656Nicolas Geoffray } 352de58ab2c03ff8112b07ab827c8fa38f670dfc656Nicolas Geoffray 35358282f4510961317b8d5a364a6f740a78926716fDavid Brazdil void SetupBlockedRegisters() const OVERRIDE; 354de58ab2c03ff8112b07ab827c8fa38f670dfc656Nicolas Geoffray void DumpCoreRegister(std::ostream& stream, int reg) const OVERRIDE; 355de58ab2c03ff8112b07ab827c8fa38f670dfc656Nicolas Geoffray void DumpFloatingPointRegister(std::ostream& stream, int reg) const OVERRIDE; 356f55c3e0825cdfc4c5a27730031177d1a0198ec5aMark Mendell void Finalize(CodeAllocator* allocator) OVERRIDE; 3579cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray 358de58ab2c03ff8112b07ab827c8fa38f670dfc656Nicolas Geoffray InstructionSet GetInstructionSet() const OVERRIDE { 359412f10cfed002ab617c78f2621d68446ca4dd8bdNicolas Geoffray return InstructionSet::kX86_64; 360412f10cfed002ab617c78f2621d68446ca4dd8bdNicolas Geoffray } 361412f10cfed002ab617c78f2621d68446ca4dd8bdNicolas Geoffray 3623c7bb98698f77af10372cf31824d3bb115d9bf0fNicolas Geoffray // Emit a write barrier. 36307276db28d654594e0e86e9e467cad393f752e6eNicolas Geoffray void MarkGCCard(CpuRegister temp, 36407276db28d654594e0e86e9e467cad393f752e6eNicolas Geoffray CpuRegister card, 36507276db28d654594e0e86e9e467cad393f752e6eNicolas Geoffray CpuRegister object, 36607276db28d654594e0e86e9e467cad393f752e6eNicolas Geoffray CpuRegister value, 36707276db28d654594e0e86e9e467cad393f752e6eNicolas Geoffray bool value_can_be_null); 3683c7bb98698f77af10372cf31824d3bb115d9bf0fNicolas Geoffray 3691e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain void GenerateMemoryBarrier(MemBarrierKind kind); 3701e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain 3719cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray // Helper method to move a value between two locations. 3729cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray void Move(Location destination, Location source); 3739cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray 37492a73aef279be78e3c2b04db1713076183933436Nicolas Geoffray Label* GetLabelOf(HBasicBlock* block) const { 375225b6464a58ebe11c156144653f11a1c6607f4ebVladimir Marko return CommonGetLabelOf<Label>(block_labels_, block); 37692a73aef279be78e3c2b04db1713076183933436Nicolas Geoffray } 37792a73aef279be78e3c2b04db1713076183933436Nicolas Geoffray 378de58ab2c03ff8112b07ab827c8fa38f670dfc656Nicolas Geoffray void Initialize() OVERRIDE { 379225b6464a58ebe11c156144653f11a1c6607f4ebVladimir Marko block_labels_ = CommonInitializeLabels<Label>(); 38092a73aef279be78e3c2b04db1713076183933436Nicolas Geoffray } 38192a73aef279be78e3c2b04db1713076183933436Nicolas Geoffray 382840e5461a85f8908f51e7f6cd562a9129ff0e7ceNicolas Geoffray bool NeedsTwoRegisters(Primitive::Type type ATTRIBUTE_UNUSED) const OVERRIDE { 383840e5461a85f8908f51e7f6cd562a9129ff0e7ceNicolas Geoffray return false; 384840e5461a85f8908f51e7f6cd562a9129ff0e7ceNicolas Geoffray } 385840e5461a85f8908f51e7f6cd562a9129ff0e7ceNicolas Geoffray 386cac5a7e871f1f346b317894359ad06fa7bd67fbaVladimir Marko // Check if the desired_string_load_kind is supported. If it is, return it, 387cac5a7e871f1f346b317894359ad06fa7bd67fbaVladimir Marko // otherwise return a fall-back kind that should be used instead. 388cac5a7e871f1f346b317894359ad06fa7bd67fbaVladimir Marko HLoadString::LoadKind GetSupportedLoadStringKind( 389cac5a7e871f1f346b317894359ad06fa7bd67fbaVladimir Marko HLoadString::LoadKind desired_string_load_kind) OVERRIDE; 390cac5a7e871f1f346b317894359ad06fa7bd67fbaVladimir Marko 391dc151b2346bb8a4fdeed0c06e54c2fca21d59b5dVladimir Marko // Check if the desired_dispatch_info is supported. If it is, return it, 392dc151b2346bb8a4fdeed0c06e54c2fca21d59b5dVladimir Marko // otherwise return a fall-back info that should be used instead. 393dc151b2346bb8a4fdeed0c06e54c2fca21d59b5dVladimir Marko HInvokeStaticOrDirect::DispatchInfo GetSupportedInvokeStaticOrDirectDispatch( 394dc151b2346bb8a4fdeed0c06e54c2fca21d59b5dVladimir Marko const HInvokeStaticOrDirect::DispatchInfo& desired_dispatch_info, 395dc151b2346bb8a4fdeed0c06e54c2fca21d59b5dVladimir Marko MethodReference target_method) OVERRIDE; 396dc151b2346bb8a4fdeed0c06e54c2fca21d59b5dVladimir Marko 39785b62f23fc6dfffe2ddd3ddfa74611666c9ff41dAndreas Gampe void GenerateStaticOrDirectCall(HInvokeStaticOrDirect* invoke, Location temp) OVERRIDE; 39885b62f23fc6dfffe2ddd3ddfa74611666c9ff41dAndreas Gampe void GenerateVirtualCall(HInvokeVirtual* invoke, Location temp) OVERRIDE; 39985b62f23fc6dfffe2ddd3ddfa74611666c9ff41dAndreas Gampe 400cac5a7e871f1f346b317894359ad06fa7bd67fbaVladimir Marko void RecordSimplePatch(); 401cac5a7e871f1f346b317894359ad06fa7bd67fbaVladimir Marko void RecordStringPatch(HLoadString* load_string); 402cac5a7e871f1f346b317894359ad06fa7bd67fbaVladimir Marko Label* NewPcRelativeDexCacheArrayPatch(const DexFile& dex_file, uint32_t element_offset); 403cac5a7e871f1f346b317894359ad06fa7bd67fbaVladimir Marko 40485b62f23fc6dfffe2ddd3ddfa74611666c9ff41dAndreas Gampe void MoveFromReturnRegister(Location trg, Primitive::Type type) OVERRIDE; 40571fb52fee246b7d511f520febbd73dc7a9bbca79Andreas Gampe 406581550137ee3a068a14224870e71aeee924a0646Vladimir Marko void EmitLinkerPatches(ArenaVector<LinkerPatch>* linker_patches) OVERRIDE; 407581550137ee3a068a14224870e71aeee924a0646Vladimir Marko 408fb8d279bc011b31d0765dc7ca59afea324fd0d0cMark Mendell const X86_64InstructionSetFeatures& GetInstructionSetFeatures() const { 409fb8d279bc011b31d0765dc7ca59afea324fd0d0cMark Mendell return isa_features_; 410fb8d279bc011b31d0765dc7ca59afea324fd0d0cMark Mendell } 411fb8d279bc011b31d0765dc7ca59afea324fd0d0cMark Mendell 4121e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain // Fast path implementation of ReadBarrier::Barrier for a heap 4131e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain // reference field load when Baker's read barriers are used. 4141e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain void GenerateFieldLoadWithBakerReadBarrier(HInstruction* instruction, 415e3f43ac79e50a4693ea4d46acf5cffca64910ceeRoland Levillain Location ref, 4161e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain CpuRegister obj, 4171e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain uint32_t offset, 4181e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain Location temp, 4191e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain bool needs_null_check); 4201e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain // Fast path implementation of ReadBarrier::Barrier for a heap 4211e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain // reference array load when Baker's read barriers are used. 4221e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain void GenerateArrayLoadWithBakerReadBarrier(HInstruction* instruction, 423e3f43ac79e50a4693ea4d46acf5cffca64910ceeRoland Levillain Location ref, 4241e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain CpuRegister obj, 4251e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain uint32_t data_offset, 4261e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain Location index, 4271e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain Location temp, 4281e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain bool needs_null_check); 4291e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain 4301e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain // Generate a read barrier for a heap reference within `instruction` 4311e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain // using a slow path. 4320d5a281c671444bfa75d63caf1427a8c0e6e1177Roland Levillain // 4330d5a281c671444bfa75d63caf1427a8c0e6e1177Roland Levillain // A read barrier for an object reference read from the heap is 4340d5a281c671444bfa75d63caf1427a8c0e6e1177Roland Levillain // implemented as a call to the artReadBarrierSlow runtime entry 4350d5a281c671444bfa75d63caf1427a8c0e6e1177Roland Levillain // point, which is passed the values in locations `ref`, `obj`, and 4360d5a281c671444bfa75d63caf1427a8c0e6e1177Roland Levillain // `offset`: 4370d5a281c671444bfa75d63caf1427a8c0e6e1177Roland Levillain // 4380d5a281c671444bfa75d63caf1427a8c0e6e1177Roland Levillain // mirror::Object* artReadBarrierSlow(mirror::Object* ref, 4390d5a281c671444bfa75d63caf1427a8c0e6e1177Roland Levillain // mirror::Object* obj, 4400d5a281c671444bfa75d63caf1427a8c0e6e1177Roland Levillain // uint32_t offset); 4410d5a281c671444bfa75d63caf1427a8c0e6e1177Roland Levillain // 4420d5a281c671444bfa75d63caf1427a8c0e6e1177Roland Levillain // The `out` location contains the value returned by 4430d5a281c671444bfa75d63caf1427a8c0e6e1177Roland Levillain // artReadBarrierSlow. 4440d5a281c671444bfa75d63caf1427a8c0e6e1177Roland Levillain // 4450d5a281c671444bfa75d63caf1427a8c0e6e1177Roland Levillain // When `index` provided (i.e., when it is different from 4460d5a281c671444bfa75d63caf1427a8c0e6e1177Roland Levillain // Location::NoLocation()), the offset value passed to 4470d5a281c671444bfa75d63caf1427a8c0e6e1177Roland Levillain // artReadBarrierSlow is adjusted to take `index` into account. 4481e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain void GenerateReadBarrierSlow(HInstruction* instruction, 4491e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain Location out, 4501e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain Location ref, 4511e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain Location obj, 4521e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain uint32_t offset, 4531e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain Location index = Location::NoLocation()); 4541e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain 4551e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain // If read barriers are enabled, generate a read barrier for a heap 4561e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain // reference using a slow path. If heap poisoning is enabled, also 4571e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain // unpoison the reference in `out`. 4581e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain void MaybeGenerateReadBarrierSlow(HInstruction* instruction, 4591e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain Location out, 4601e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain Location ref, 4611e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain Location obj, 4621e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain uint32_t offset, 4631e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain Location index = Location::NoLocation()); 4641e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain 4651e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain // Generate a read barrier for a GC root within `instruction` using 4661e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain // a slow path. 4670d5a281c671444bfa75d63caf1427a8c0e6e1177Roland Levillain // 4680d5a281c671444bfa75d63caf1427a8c0e6e1177Roland Levillain // A read barrier for an object reference GC root is implemented as 4690d5a281c671444bfa75d63caf1427a8c0e6e1177Roland Levillain // a call to the artReadBarrierForRootSlow runtime entry point, 4700d5a281c671444bfa75d63caf1427a8c0e6e1177Roland Levillain // which is passed the value in location `root`: 4710d5a281c671444bfa75d63caf1427a8c0e6e1177Roland Levillain // 4720d5a281c671444bfa75d63caf1427a8c0e6e1177Roland Levillain // mirror::Object* artReadBarrierForRootSlow(GcRoot<mirror::Object>* root); 4730d5a281c671444bfa75d63caf1427a8c0e6e1177Roland Levillain // 4740d5a281c671444bfa75d63caf1427a8c0e6e1177Roland Levillain // The `out` location contains the value returned by 4750d5a281c671444bfa75d63caf1427a8c0e6e1177Roland Levillain // artReadBarrierForRootSlow. 4761e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain void GenerateReadBarrierForRootSlow(HInstruction* instruction, Location out, Location root); 4770d5a281c671444bfa75d63caf1427a8c0e6e1177Roland Levillain 478f55c3e0825cdfc4c5a27730031177d1a0198ec5aMark Mendell int ConstantAreaStart() const { 479f55c3e0825cdfc4c5a27730031177d1a0198ec5aMark Mendell return constant_area_start_; 480f55c3e0825cdfc4c5a27730031177d1a0198ec5aMark Mendell } 481f55c3e0825cdfc4c5a27730031177d1a0198ec5aMark Mendell 482f55c3e0825cdfc4c5a27730031177d1a0198ec5aMark Mendell Address LiteralDoubleAddress(double v); 483f55c3e0825cdfc4c5a27730031177d1a0198ec5aMark Mendell Address LiteralFloatAddress(float v); 484f55c3e0825cdfc4c5a27730031177d1a0198ec5aMark Mendell Address LiteralInt32Address(int32_t v); 485f55c3e0825cdfc4c5a27730031177d1a0198ec5aMark Mendell Address LiteralInt64Address(int64_t v); 486f55c3e0825cdfc4c5a27730031177d1a0198ec5aMark Mendell 487a19616e3363276e7f2c471eb2839fb16f1d43f27Aart Bik // Load a 32/64-bit value into a register in the most efficient manner. 488c5d4754198aadb2ada2d3f5daacd10d79bc13f38Aart Bik void Load32BitValue(CpuRegister dest, int32_t value); 48992e83bf8c0b2df8c977ffbc527989631d94b1819Mark Mendell void Load64BitValue(CpuRegister dest, int64_t value); 4907c0b44f180f1b8cf82c568091d250071d1130954Mark Mendell void Load32BitValue(XmmRegister dest, int32_t value); 4917c0b44f180f1b8cf82c568091d250071d1130954Mark Mendell void Load64BitValue(XmmRegister dest, int64_t value); 4927c0b44f180f1b8cf82c568091d250071d1130954Mark Mendell void Load32BitValue(XmmRegister dest, float value); 4937c0b44f180f1b8cf82c568091d250071d1130954Mark Mendell void Load64BitValue(XmmRegister dest, double value); 494c5d4754198aadb2ada2d3f5daacd10d79bc13f38Aart Bik 495a19616e3363276e7f2c471eb2839fb16f1d43f27Aart Bik // Compare a register with a 32/64-bit value in the most efficient manner. 496a19616e3363276e7f2c471eb2839fb16f1d43f27Aart Bik void Compare32BitValue(CpuRegister dest, int32_t value); 497a19616e3363276e7f2c471eb2839fb16f1d43f27Aart Bik void Compare64BitValue(CpuRegister dest, int64_t value); 498a19616e3363276e7f2c471eb2839fb16f1d43f27Aart Bik 4999c86b485bc6169eadf846dd5f7cdf0958fe1eb23Mark Mendell Address LiteralCaseTable(HPackedSwitch* switch_instr); 50092e83bf8c0b2df8c977ffbc527989631d94b1819Mark Mendell 501cfa410b0ea561318f74a76c5323f0f6cd8eaaa50Mark Mendell // Store a 64 bit value into a DoubleStackSlot in the most efficient manner. 502cfa410b0ea561318f74a76c5323f0f6cd8eaaa50Mark Mendell void Store64BitValueToStack(Location dest, int64_t value); 503cfa410b0ea561318f74a76c5323f0f6cd8eaaa50Mark Mendell 504ea5af68d6dda832bdfb5978a0c5d6f86a3f67e80Mark Mendell // Assign a 64 bit constant to an address. 505ea5af68d6dda832bdfb5978a0c5d6f86a3f67e80Mark Mendell void MoveInt64ToAddress(const Address& addr_low, 506ea5af68d6dda832bdfb5978a0c5d6f86a3f67e80Mark Mendell const Address& addr_high, 507ea5af68d6dda832bdfb5978a0c5d6f86a3f67e80Mark Mendell int64_t v, 508ea5af68d6dda832bdfb5978a0c5d6f86a3f67e80Mark Mendell HInstruction* instruction); 509ea5af68d6dda832bdfb5978a0c5d6f86a3f67e80Mark Mendell 51017077d888a6752a2e5f8161eee1b2c3285783d12Mark P Mendell // Ensure that prior stores complete to memory before subsequent loads. 51117077d888a6752a2e5f8161eee1b2c3285783d12Mark P Mendell // The locked add implementation will avoid serializing device memory, but will 51217077d888a6752a2e5f8161eee1b2c3285783d12Mark P Mendell // touch (but not change) the top of the stack. The locked add should not be used for 51317077d888a6752a2e5f8161eee1b2c3285783d12Mark P Mendell // ordering non-temporal stores. 51417077d888a6752a2e5f8161eee1b2c3285783d12Mark P Mendell void MemoryFence(bool force_mfence = false) { 51517077d888a6752a2e5f8161eee1b2c3285783d12Mark P Mendell if (!force_mfence && isa_features_.PrefersLockedAddSynchronization()) { 51617077d888a6752a2e5f8161eee1b2c3285783d12Mark P Mendell assembler_.lock()->addl(Address(CpuRegister(RSP), 0), Immediate(0)); 51717077d888a6752a2e5f8161eee1b2c3285783d12Mark P Mendell } else { 51817077d888a6752a2e5f8161eee1b2c3285783d12Mark P Mendell assembler_.mfence(); 51917077d888a6752a2e5f8161eee1b2c3285783d12Mark P Mendell } 52017077d888a6752a2e5f8161eee1b2c3285783d12Mark P Mendell } 52117077d888a6752a2e5f8161eee1b2c3285783d12Mark P Mendell 522c7098ff991bb4e00a800d315d1c36f52a9cb0149David Srbecky void GenerateNop(); 5232ae48182573da7087bffc2873730bc758ec29696Calin Juravle void GenerateImplicitNullCheck(HNullCheck* instruction); 5242ae48182573da7087bffc2873730bc758ec29696Calin Juravle void GenerateExplicitNullCheck(HNullCheck* instruction); 525c7098ff991bb4e00a800d315d1c36f52a9cb0149David Srbecky 526cac5a7e871f1f346b317894359ad06fa7bd67fbaVladimir Marko // When we don't know the proper offset for the value, we use kDummy32BitOffset. 527cac5a7e871f1f346b317894359ad06fa7bd67fbaVladimir Marko // We will fix this up in the linker later to have the right value. 528cac5a7e871f1f346b317894359ad06fa7bd67fbaVladimir Marko static constexpr int32_t kDummy32BitOffset = 256; 529cac5a7e871f1f346b317894359ad06fa7bd67fbaVladimir Marko 5303c7bb98698f77af10372cf31824d3bb115d9bf0fNicolas Geoffray private: 5311e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain // Factored implementation of GenerateFieldLoadWithBakerReadBarrier 5321e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain // and GenerateArrayLoadWithBakerReadBarrier. 5331e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain void GenerateReferenceLoadWithBakerReadBarrier(HInstruction* instruction, 5341e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain Location ref, 5351e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain CpuRegister obj, 5361e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain const Address& src, 5371e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain Location temp, 5381e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain bool needs_null_check); 5391e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain 540581550137ee3a068a14224870e71aeee924a0646Vladimir Marko struct PcRelativeDexCacheAccessInfo { 541581550137ee3a068a14224870e71aeee924a0646Vladimir Marko PcRelativeDexCacheAccessInfo(const DexFile& dex_file, uint32_t element_off) 542581550137ee3a068a14224870e71aeee924a0646Vladimir Marko : target_dex_file(dex_file), element_offset(element_off), label() { } 543581550137ee3a068a14224870e71aeee924a0646Vladimir Marko 544581550137ee3a068a14224870e71aeee924a0646Vladimir Marko const DexFile& target_dex_file; 545581550137ee3a068a14224870e71aeee924a0646Vladimir Marko uint32_t element_offset; 546581550137ee3a068a14224870e71aeee924a0646Vladimir Marko Label label; 547581550137ee3a068a14224870e71aeee924a0646Vladimir Marko }; 548581550137ee3a068a14224870e71aeee924a0646Vladimir Marko 54992a73aef279be78e3c2b04db1713076183933436Nicolas Geoffray // Labels for each block that will be compiled. 550225b6464a58ebe11c156144653f11a1c6607f4ebVladimir Marko Label* block_labels_; // Indexed by block id. 5511cf95287364948689f6a1a320567acd7728e94a3Nicolas Geoffray Label frame_entry_label_; 5529cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray LocationsBuilderX86_64 location_builder_; 5539cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray InstructionCodeGeneratorX86_64 instruction_visitor_; 554ecb2f9ba57b08ceac4204ddd6a0a88a0524f8741Nicolas Geoffray ParallelMoveResolverX86_64 move_resolver_; 5559cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray X86_64Assembler assembler_; 556fb8d279bc011b31d0765dc7ca59afea324fd0d0cMark Mendell const X86_64InstructionSetFeatures& isa_features_; 5579cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray 55839dcf55a56da746e04f477f89e7b00ba1de03880Mark Mendell // Offset to the start of the constant area in the assembled code. 559f55c3e0825cdfc4c5a27730031177d1a0198ec5aMark Mendell // Used for fixups to the constant area. 560f55c3e0825cdfc4c5a27730031177d1a0198ec5aMark Mendell int constant_area_start_; 561f55c3e0825cdfc4c5a27730031177d1a0198ec5aMark Mendell 562581550137ee3a068a14224870e71aeee924a0646Vladimir Marko // Method patch info. Using ArenaDeque<> which retains element addresses on push/emplace_back(). 563581550137ee3a068a14224870e71aeee924a0646Vladimir Marko ArenaDeque<MethodPatchInfo<Label>> method_patches_; 564581550137ee3a068a14224870e71aeee924a0646Vladimir Marko ArenaDeque<MethodPatchInfo<Label>> relative_call_patches_; 565581550137ee3a068a14224870e71aeee924a0646Vladimir Marko // PC-relative DexCache access info. 5660f7dca4ca0be8d2f8776794d35edf8b51b5bc997Vladimir Marko ArenaDeque<PcRelativeDexCacheAccessInfo> pc_relative_dex_cache_patches_; 567cac5a7e871f1f346b317894359ad06fa7bd67fbaVladimir Marko // Patch locations for patchoat where the linker doesn't do any other work. 568cac5a7e871f1f346b317894359ad06fa7bd67fbaVladimir Marko ArenaDeque<Label> simple_patches_; 569cac5a7e871f1f346b317894359ad06fa7bd67fbaVladimir Marko // String patch locations. 570cac5a7e871f1f346b317894359ad06fa7bd67fbaVladimir Marko ArenaDeque<StringPatchInfo<Label>> string_patches_; 571581550137ee3a068a14224870e71aeee924a0646Vladimir Marko 5729c86b485bc6169eadf846dd5f7cdf0958fe1eb23Mark Mendell // Fixups for jump tables need to be handled specially. 5739c86b485bc6169eadf846dd5f7cdf0958fe1eb23Mark Mendell ArenaVector<JumpTableRIPFixup*> fixups_to_jump_tables_; 5749c86b485bc6169eadf846dd5f7cdf0958fe1eb23Mark Mendell 5759cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray DISALLOW_COPY_AND_ASSIGN(CodeGeneratorX86_64); 5769cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray}; 5779cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray 5789cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray} // namespace x86_64 5799cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray} // namespace art 5809cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray 5819cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray#endif // ART_COMPILER_OPTIMIZING_CODE_GENERATOR_X86_64_H_ 582