code_generator_x86_64.h revision 17077d888a6752a2e5f8161eee1b2c3285783d12
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); 145412f10cfed002ab617c78f2621d68446ca4dd8bdNicolas Geoffray void Exchange64(CpuRegister reg, int mem); 146102cbed1e52b7c5f09458b44903fe97bb3e14d5fNicolas Geoffray void Exchange64(XmmRegister reg, int mem); 147412f10cfed002ab617c78f2621d68446ca4dd8bdNicolas Geoffray void Exchange64(int mem1, int mem2); 148ecb2f9ba57b08ceac4204ddd6a0a88a0524f8741Nicolas Geoffray 149ecb2f9ba57b08ceac4204ddd6a0a88a0524f8741Nicolas Geoffray CodeGeneratorX86_64* const codegen_; 150ecb2f9ba57b08ceac4204ddd6a0a88a0524f8741Nicolas Geoffray 151ecb2f9ba57b08ceac4204ddd6a0a88a0524f8741Nicolas Geoffray DISALLOW_COPY_AND_ASSIGN(ParallelMoveResolverX86_64); 152ecb2f9ba57b08ceac4204ddd6a0a88a0524f8741Nicolas Geoffray}; 153ecb2f9ba57b08ceac4204ddd6a0a88a0524f8741Nicolas Geoffray 1549cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffrayclass LocationsBuilderX86_64 : public HGraphVisitor { 1559cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray public: 1569cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray LocationsBuilderX86_64(HGraph* graph, CodeGeneratorX86_64* codegen) 1579cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray : HGraphVisitor(graph), codegen_(codegen) {} 1589cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray 159360231a056e796c36ffe62348507e904dc9efb9bNicolas Geoffray#define DECLARE_VISIT_INSTRUCTION(name, super) \ 160de58ab2c03ff8112b07ab827c8fa38f670dfc656Nicolas Geoffray void Visit##name(H##name* instr) OVERRIDE; 1619cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray 162ef20f71e16f035a39a329c8524d7e59ca6a11f04Alexandre Rames FOR_EACH_CONCRETE_INSTRUCTION_COMMON(DECLARE_VISIT_INSTRUCTION) 163ef20f71e16f035a39a329c8524d7e59ca6a11f04Alexandre Rames FOR_EACH_CONCRETE_INSTRUCTION_X86_64(DECLARE_VISIT_INSTRUCTION) 1649cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray 1659cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray#undef DECLARE_VISIT_INSTRUCTION 1669cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray 167ef20f71e16f035a39a329c8524d7e59ca6a11f04Alexandre Rames void VisitInstruction(HInstruction* instruction) OVERRIDE { 168ef20f71e16f035a39a329c8524d7e59ca6a11f04Alexandre Rames LOG(FATAL) << "Unreachable instruction " << instruction->DebugName() 169ef20f71e16f035a39a329c8524d7e59ca6a11f04Alexandre Rames << " (id " << instruction->GetId() << ")"; 170ef20f71e16f035a39a329c8524d7e59ca6a11f04Alexandre Rames } 171ef20f71e16f035a39a329c8524d7e59ca6a11f04Alexandre Rames 1729574c4b5f5ef039d694ac12c97e25ca02eca83c0Nicolas Geoffray private: 173e982f0b8e809cece6f460fa2d8df25873aa69de4Nicolas Geoffray void HandleInvoke(HInvoke* invoke); 1749574c4b5f5ef039d694ac12c97e25ca02eca83c0Nicolas Geoffray void HandleBitwiseOperation(HBinaryOperation* operation); 1759aec02fc5df5518c16f1e5a9b6cb198a192db973Calin Juravle void HandleShift(HBinaryOperation* operation); 17652c489645b6e9ae33623f1ec24143cde5444906eCalin Juravle void HandleFieldSet(HInstruction* instruction, const FieldInfo& field_info); 17752c489645b6e9ae33623f1ec24143cde5444906eCalin Juravle void HandleFieldGet(HInstruction* instruction); 178e982f0b8e809cece6f460fa2d8df25873aa69de4Nicolas Geoffray 1799cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray CodeGeneratorX86_64* const codegen_; 1802d27c8e338af7262dbd4aaa66127bb8fa1758b86Roland Levillain InvokeDexCallingConventionVisitorX86_64 parameter_visitor_; 1819cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray 1829cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray DISALLOW_COPY_AND_ASSIGN(LocationsBuilderX86_64); 1839cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray}; 1849cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray 1859cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffrayclass InstructionCodeGeneratorX86_64 : public HGraphVisitor { 1869cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray public: 1879cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray InstructionCodeGeneratorX86_64(HGraph* graph, CodeGeneratorX86_64* codegen); 1889cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray 189360231a056e796c36ffe62348507e904dc9efb9bNicolas Geoffray#define DECLARE_VISIT_INSTRUCTION(name, super) \ 190de58ab2c03ff8112b07ab827c8fa38f670dfc656Nicolas Geoffray void Visit##name(H##name* instr) OVERRIDE; 1919cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray 192ef20f71e16f035a39a329c8524d7e59ca6a11f04Alexandre Rames FOR_EACH_CONCRETE_INSTRUCTION_COMMON(DECLARE_VISIT_INSTRUCTION) 193ef20f71e16f035a39a329c8524d7e59ca6a11f04Alexandre Rames FOR_EACH_CONCRETE_INSTRUCTION_X86_64(DECLARE_VISIT_INSTRUCTION) 1949cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray 1959cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray#undef DECLARE_VISIT_INSTRUCTION 1969cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray 197ef20f71e16f035a39a329c8524d7e59ca6a11f04Alexandre Rames void VisitInstruction(HInstruction* instruction) OVERRIDE { 198ef20f71e16f035a39a329c8524d7e59ca6a11f04Alexandre Rames LOG(FATAL) << "Unreachable instruction " << instruction->DebugName() 199ef20f71e16f035a39a329c8524d7e59ca6a11f04Alexandre Rames << " (id " << instruction->GetId() << ")"; 200ef20f71e16f035a39a329c8524d7e59ca6a11f04Alexandre Rames } 201ef20f71e16f035a39a329c8524d7e59ca6a11f04Alexandre Rames 2029cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray X86_64Assembler* GetAssembler() const { return assembler_; } 2039cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray 2049cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray private: 2053c04974a90b0e03f4b509010bff49f0b2a3da57fNicolas Geoffray // Generate code for the given suspend check. If not null, `successor` 2063c04974a90b0e03f4b509010bff49f0b2a3da57fNicolas Geoffray // is the block to branch to if the suspend check is not needed, and after 2073c04974a90b0e03f4b509010bff49f0b2a3da57fNicolas Geoffray // the suspend call. 2083c04974a90b0e03f4b509010bff49f0b2a3da57fNicolas Geoffray void GenerateSuspendCheck(HSuspendCheck* instruction, HBasicBlock* successor); 20985b62f23fc6dfffe2ddd3ddfa74611666c9ff41dAndreas Gampe void GenerateClassInitializationCheck(SlowPathCode* slow_path, CpuRegister class_reg); 2109574c4b5f5ef039d694ac12c97e25ca02eca83c0Nicolas Geoffray void HandleBitwiseOperation(HBinaryOperation* operation); 211c470193cfc522fc818eb2eaab896aef9caf0c75aMark Mendell void GenerateRemFP(HRem* rem); 2120f88e87085b7cf6544dadff3f555773966a6853eGuillaume Sanchez void DivRemOneOrMinusOne(HBinaryOperation* instruction); 213b19930c5cba3cf662dce5ee057fcc9829b4cbb9cGuillaume Sanchez void DivByPowerOfTwo(HDiv* instruction); 2140f88e87085b7cf6544dadff3f555773966a6853eGuillaume Sanchez void GenerateDivRemWithAnyConstant(HBinaryOperation* instruction); 215bacfec30ee9f2f6fdfd190f11b105b609938efcaCalin Juravle void GenerateDivRemIntegral(HBinaryOperation* instruction); 2169aec02fc5df5518c16f1e5a9b6cb198a192db973Calin Juravle void HandleShift(HBinaryOperation* operation); 2171e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain 21807276db28d654594e0e86e9e467cad393f752e6eNicolas Geoffray void HandleFieldSet(HInstruction* instruction, 21907276db28d654594e0e86e9e467cad393f752e6eNicolas Geoffray const FieldInfo& field_info, 22007276db28d654594e0e86e9e467cad393f752e6eNicolas Geoffray bool value_can_be_null); 22152c489645b6e9ae33623f1ec24143cde5444906eCalin Juravle void HandleFieldGet(HInstruction* instruction, const FieldInfo& field_info); 2221e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain 2231e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain // Generate a heap reference load using one register `out`: 2241e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain // 2251e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain // out <- *(out + offset) 2261e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain // 2271e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain // while honoring heap poisoning and/or read barriers (if any). 2281e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain // Register `temp` is used when generating a read barrier. 2291e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain void GenerateReferenceLoadOneRegister(HInstruction* instruction, 2301e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain Location out, 2311e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain uint32_t offset, 2321e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain Location temp); 2331e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain // Generate a heap reference load using two different registers 2341e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain // `out` and `obj`: 2351e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain // 2361e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain // out <- *(obj + offset) 2371e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain // 2381e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain // while honoring heap poisoning and/or read barriers (if any). 2391e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain // Register `temp` is used when generating a Baker's read barrier. 2401e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain void GenerateReferenceLoadTwoRegisters(HInstruction* instruction, 2411e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain Location out, 2421e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain Location obj, 2431e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain uint32_t offset, 2441e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain Location temp); 2451e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain // Generate a GC root reference load: 2461e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain // 2471e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain // root <- *(obj + offset) 2481e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain // 2491e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain // while honoring read barriers (if any). 2501e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain void GenerateGcRootFieldLoad(HInstruction* instruction, 2511e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain Location root, 2521e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain CpuRegister obj, 2531e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain uint32_t offset); 2541e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain 255cd6dffedf1bd8e6dfb3fb0c933551f9a90f7de3fCalin Juravle void GenerateImplicitNullCheck(HNullCheck* instruction); 256cd6dffedf1bd8e6dfb3fb0c933551f9a90f7de3fCalin Juravle void GenerateExplicitNullCheck(HNullCheck* instruction); 25724f2dfae084b2382c053f5d688fd6bb26cb8a328Mark Mendell void PushOntoFPStack(Location source, uint32_t temp_offset, 25824f2dfae084b2382c053f5d688fd6bb26cb8a328Mark Mendell uint32_t stack_adjustment, bool is_float); 259d43b3ac88cd46b8815890188c9c2b9a3f1564648Mingyao Yang void GenerateTestAndBranch(HInstruction* instruction, 2600debae7bc89eb05f7a2bf7dccd223318fad7c88dDavid Brazdil size_t condition_input_index, 261d43b3ac88cd46b8815890188c9c2b9a3f1564648Mingyao Yang Label* true_target, 2620debae7bc89eb05f7a2bf7dccd223318fad7c88dDavid Brazdil Label* false_target); 2630debae7bc89eb05f7a2bf7dccd223318fad7c88dDavid Brazdil void GenerateCompareTestAndBranch(HCondition* condition, 264c470193cfc522fc818eb2eaab896aef9caf0c75aMark Mendell Label* true_target, 2650debae7bc89eb05f7a2bf7dccd223318fad7c88dDavid Brazdil Label* false_target); 266c470193cfc522fc818eb2eaab896aef9caf0c75aMark Mendell void GenerateFPJumps(HCondition* cond, Label* true_label, Label* false_label); 267fc6a86ab2b70781e72b807c1798b83829ca7f931David Brazdil void HandleGoto(HInstruction* got, HBasicBlock* successor); 2683c04974a90b0e03f4b509010bff49f0b2a3da57fNicolas Geoffray 2699cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray X86_64Assembler* const assembler_; 2709cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray CodeGeneratorX86_64* const codegen_; 2719cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray 2729cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray DISALLOW_COPY_AND_ASSIGN(InstructionCodeGeneratorX86_64); 2739cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray}; 2749cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray 2759c86b485bc6169eadf846dd5f7cdf0958fe1eb23Mark Mendell// Class for fixups to jump tables. 2769c86b485bc6169eadf846dd5f7cdf0958fe1eb23Mark Mendellclass JumpTableRIPFixup; 2779c86b485bc6169eadf846dd5f7cdf0958fe1eb23Mark Mendell 2789cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffrayclass CodeGeneratorX86_64 : public CodeGenerator { 2799cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray public: 280fb8d279bc011b31d0765dc7ca59afea324fd0d0cMark Mendell CodeGeneratorX86_64(HGraph* graph, 281fb8d279bc011b31d0765dc7ca59afea324fd0d0cMark Mendell const X86_64InstructionSetFeatures& isa_features, 282ecc4366670e12b4812ef1653f7c8d52234ca1b1fSerban Constantinescu const CompilerOptions& compiler_options, 283ecc4366670e12b4812ef1653f7c8d52234ca1b1fSerban Constantinescu OptimizingCompilerStats* stats = nullptr); 2849cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray virtual ~CodeGeneratorX86_64() {} 2859cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray 286de58ab2c03ff8112b07ab827c8fa38f670dfc656Nicolas Geoffray void GenerateFrameEntry() OVERRIDE; 287de58ab2c03ff8112b07ab827c8fa38f670dfc656Nicolas Geoffray void GenerateFrameExit() OVERRIDE; 288de58ab2c03ff8112b07ab827c8fa38f670dfc656Nicolas Geoffray void Bind(HBasicBlock* block) OVERRIDE; 289de58ab2c03ff8112b07ab827c8fa38f670dfc656Nicolas Geoffray void Move(HInstruction* instruction, Location location, HInstruction* move_for) OVERRIDE; 290175dc732c80e6f2afd83209348124df349290ba8Calin Juravle void MoveConstant(Location destination, int32_t value) OVERRIDE; 291e460d1df1f789c7c8bb97024a8efbd713ac175e9Calin Juravle void MoveLocation(Location dst, Location src, Primitive::Type dst_type) OVERRIDE; 292e460d1df1f789c7c8bb97024a8efbd713ac175e9Calin Juravle void AddLocationAsTemp(Location location, LocationSummary* locations) OVERRIDE; 293e460d1df1f789c7c8bb97024a8efbd713ac175e9Calin Juravle 294de58ab2c03ff8112b07ab827c8fa38f670dfc656Nicolas Geoffray size_t SaveCoreRegister(size_t stack_index, uint32_t reg_id) OVERRIDE; 295de58ab2c03ff8112b07ab827c8fa38f670dfc656Nicolas Geoffray size_t RestoreCoreRegister(size_t stack_index, uint32_t reg_id) OVERRIDE; 296de58ab2c03ff8112b07ab827c8fa38f670dfc656Nicolas Geoffray size_t SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) OVERRIDE; 297de58ab2c03ff8112b07ab827c8fa38f670dfc656Nicolas Geoffray size_t RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) OVERRIDE; 2989cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray 2998158f28b6689314213eb4dbbe14166073be71f7eAlexandre Rames // Generate code to invoke a runtime entry point. 300175dc732c80e6f2afd83209348124df349290ba8Calin Juravle void InvokeRuntime(QuickEntrypointEnum entrypoint, 301175dc732c80e6f2afd83209348124df349290ba8Calin Juravle HInstruction* instruction, 302175dc732c80e6f2afd83209348124df349290ba8Calin Juravle uint32_t dex_pc, 303175dc732c80e6f2afd83209348124df349290ba8Calin Juravle SlowPathCode* slow_path) OVERRIDE; 304175dc732c80e6f2afd83209348124df349290ba8Calin Juravle 305175dc732c80e6f2afd83209348124df349290ba8Calin Juravle void InvokeRuntime(int32_t entry_point_offset, 3068158f28b6689314213eb4dbbe14166073be71f7eAlexandre Rames HInstruction* instruction, 3078158f28b6689314213eb4dbbe14166073be71f7eAlexandre Rames uint32_t dex_pc, 3088158f28b6689314213eb4dbbe14166073be71f7eAlexandre Rames SlowPathCode* slow_path); 3098158f28b6689314213eb4dbbe14166073be71f7eAlexandre Rames 310de58ab2c03ff8112b07ab827c8fa38f670dfc656Nicolas Geoffray size_t GetWordSize() const OVERRIDE { 3119cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray return kX86_64WordSize; 3129cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray } 3139cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray 314f85a9ca9859ad843dc03d3a2b600afbaf2e9bbddMark Mendell size_t GetFloatingPointSpillSlotSize() const OVERRIDE { 315f85a9ca9859ad843dc03d3a2b600afbaf2e9bbddMark Mendell return kX86_64WordSize; 316f85a9ca9859ad843dc03d3a2b600afbaf2e9bbddMark Mendell } 317f85a9ca9859ad843dc03d3a2b600afbaf2e9bbddMark Mendell 318de58ab2c03ff8112b07ab827c8fa38f670dfc656Nicolas Geoffray HGraphVisitor* GetLocationBuilder() OVERRIDE { 3199cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray return &location_builder_; 3209cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray } 3219cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray 322de58ab2c03ff8112b07ab827c8fa38f670dfc656Nicolas Geoffray HGraphVisitor* GetInstructionVisitor() OVERRIDE { 3239cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray return &instruction_visitor_; 3249cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray } 3259cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray 326de58ab2c03ff8112b07ab827c8fa38f670dfc656Nicolas Geoffray X86_64Assembler* GetAssembler() OVERRIDE { 3279cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray return &assembler_; 3289cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray } 3299cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray 330eb7b7399dbdb5e471b8ae00a567bf4f19edd3907Alexandre Rames const X86_64Assembler& GetAssembler() const OVERRIDE { 331eb7b7399dbdb5e471b8ae00a567bf4f19edd3907Alexandre Rames return assembler_; 332eb7b7399dbdb5e471b8ae00a567bf4f19edd3907Alexandre Rames } 333eb7b7399dbdb5e471b8ae00a567bf4f19edd3907Alexandre Rames 334f0e3937b87453234d0d7970b8712082062709b8dNicolas Geoffray ParallelMoveResolverX86_64* GetMoveResolver() OVERRIDE { 335ecb2f9ba57b08ceac4204ddd6a0a88a0524f8741Nicolas Geoffray return &move_resolver_; 336ecb2f9ba57b08ceac4204ddd6a0a88a0524f8741Nicolas Geoffray } 337ecb2f9ba57b08ceac4204ddd6a0a88a0524f8741Nicolas Geoffray 338de58ab2c03ff8112b07ab827c8fa38f670dfc656Nicolas Geoffray uintptr_t GetAddressOf(HBasicBlock* block) const OVERRIDE { 339de58ab2c03ff8112b07ab827c8fa38f670dfc656Nicolas Geoffray return GetLabelOf(block)->Position(); 340de58ab2c03ff8112b07ab827c8fa38f670dfc656Nicolas Geoffray } 341de58ab2c03ff8112b07ab827c8fa38f670dfc656Nicolas Geoffray 342de58ab2c03ff8112b07ab827c8fa38f670dfc656Nicolas Geoffray Location GetStackLocation(HLoadLocal* load) const OVERRIDE; 3439cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray 344988939683c26c0b1c8808fc206add6337319509aNicolas Geoffray void SetupBlockedRegisters(bool is_baseline) const OVERRIDE; 345de58ab2c03ff8112b07ab827c8fa38f670dfc656Nicolas Geoffray Location AllocateFreeRegister(Primitive::Type type) const OVERRIDE; 346de58ab2c03ff8112b07ab827c8fa38f670dfc656Nicolas Geoffray void DumpCoreRegister(std::ostream& stream, int reg) const OVERRIDE; 347de58ab2c03ff8112b07ab827c8fa38f670dfc656Nicolas Geoffray void DumpFloatingPointRegister(std::ostream& stream, int reg) const OVERRIDE; 348f55c3e0825cdfc4c5a27730031177d1a0198ec5aMark Mendell void Finalize(CodeAllocator* allocator) OVERRIDE; 3499cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray 350de58ab2c03ff8112b07ab827c8fa38f670dfc656Nicolas Geoffray InstructionSet GetInstructionSet() const OVERRIDE { 351412f10cfed002ab617c78f2621d68446ca4dd8bdNicolas Geoffray return InstructionSet::kX86_64; 352412f10cfed002ab617c78f2621d68446ca4dd8bdNicolas Geoffray } 353412f10cfed002ab617c78f2621d68446ca4dd8bdNicolas Geoffray 3543c7bb98698f77af10372cf31824d3bb115d9bf0fNicolas Geoffray // Emit a write barrier. 35507276db28d654594e0e86e9e467cad393f752e6eNicolas Geoffray void MarkGCCard(CpuRegister temp, 35607276db28d654594e0e86e9e467cad393f752e6eNicolas Geoffray CpuRegister card, 35707276db28d654594e0e86e9e467cad393f752e6eNicolas Geoffray CpuRegister object, 35807276db28d654594e0e86e9e467cad393f752e6eNicolas Geoffray CpuRegister value, 35907276db28d654594e0e86e9e467cad393f752e6eNicolas Geoffray bool value_can_be_null); 3603c7bb98698f77af10372cf31824d3bb115d9bf0fNicolas Geoffray 3611e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain void GenerateMemoryBarrier(MemBarrierKind kind); 3621e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain 3639cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray // Helper method to move a value between two locations. 3649cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray void Move(Location destination, Location source); 3659cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray 36692a73aef279be78e3c2b04db1713076183933436Nicolas Geoffray Label* GetLabelOf(HBasicBlock* block) const { 367225b6464a58ebe11c156144653f11a1c6607f4ebVladimir Marko return CommonGetLabelOf<Label>(block_labels_, block); 36892a73aef279be78e3c2b04db1713076183933436Nicolas Geoffray } 36992a73aef279be78e3c2b04db1713076183933436Nicolas Geoffray 370de58ab2c03ff8112b07ab827c8fa38f670dfc656Nicolas Geoffray void Initialize() OVERRIDE { 371225b6464a58ebe11c156144653f11a1c6607f4ebVladimir Marko block_labels_ = CommonInitializeLabels<Label>(); 37292a73aef279be78e3c2b04db1713076183933436Nicolas Geoffray } 37392a73aef279be78e3c2b04db1713076183933436Nicolas Geoffray 374840e5461a85f8908f51e7f6cd562a9129ff0e7ceNicolas Geoffray bool NeedsTwoRegisters(Primitive::Type type ATTRIBUTE_UNUSED) const OVERRIDE { 375840e5461a85f8908f51e7f6cd562a9129ff0e7ceNicolas Geoffray return false; 376840e5461a85f8908f51e7f6cd562a9129ff0e7ceNicolas Geoffray } 377840e5461a85f8908f51e7f6cd562a9129ff0e7ceNicolas Geoffray 378dc151b2346bb8a4fdeed0c06e54c2fca21d59b5dVladimir Marko // Check if the desired_dispatch_info is supported. If it is, return it, 379dc151b2346bb8a4fdeed0c06e54c2fca21d59b5dVladimir Marko // otherwise return a fall-back info that should be used instead. 380dc151b2346bb8a4fdeed0c06e54c2fca21d59b5dVladimir Marko HInvokeStaticOrDirect::DispatchInfo GetSupportedInvokeStaticOrDirectDispatch( 381dc151b2346bb8a4fdeed0c06e54c2fca21d59b5dVladimir Marko const HInvokeStaticOrDirect::DispatchInfo& desired_dispatch_info, 382dc151b2346bb8a4fdeed0c06e54c2fca21d59b5dVladimir Marko MethodReference target_method) OVERRIDE; 383dc151b2346bb8a4fdeed0c06e54c2fca21d59b5dVladimir Marko 38485b62f23fc6dfffe2ddd3ddfa74611666c9ff41dAndreas Gampe void GenerateStaticOrDirectCall(HInvokeStaticOrDirect* invoke, Location temp) OVERRIDE; 38585b62f23fc6dfffe2ddd3ddfa74611666c9ff41dAndreas Gampe void GenerateVirtualCall(HInvokeVirtual* invoke, Location temp) OVERRIDE; 38685b62f23fc6dfffe2ddd3ddfa74611666c9ff41dAndreas Gampe 38785b62f23fc6dfffe2ddd3ddfa74611666c9ff41dAndreas Gampe void MoveFromReturnRegister(Location trg, Primitive::Type type) OVERRIDE; 38871fb52fee246b7d511f520febbd73dc7a9bbca79Andreas Gampe 389581550137ee3a068a14224870e71aeee924a0646Vladimir Marko void EmitLinkerPatches(ArenaVector<LinkerPatch>* linker_patches) OVERRIDE; 390581550137ee3a068a14224870e71aeee924a0646Vladimir Marko 391fb8d279bc011b31d0765dc7ca59afea324fd0d0cMark Mendell const X86_64InstructionSetFeatures& GetInstructionSetFeatures() const { 392fb8d279bc011b31d0765dc7ca59afea324fd0d0cMark Mendell return isa_features_; 393fb8d279bc011b31d0765dc7ca59afea324fd0d0cMark Mendell } 394fb8d279bc011b31d0765dc7ca59afea324fd0d0cMark Mendell 3951e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain // Fast path implementation of ReadBarrier::Barrier for a heap 3961e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain // reference field load when Baker's read barriers are used. 3971e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain void GenerateFieldLoadWithBakerReadBarrier(HInstruction* instruction, 3981e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain Location out, 3991e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain CpuRegister obj, 4001e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain uint32_t offset, 4011e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain Location temp, 4021e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain bool needs_null_check); 4031e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain // Fast path implementation of ReadBarrier::Barrier for a heap 4041e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain // reference array load when Baker's read barriers are used. 4051e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain void GenerateArrayLoadWithBakerReadBarrier(HInstruction* instruction, 4061e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain Location out, 4071e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain CpuRegister obj, 4081e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain uint32_t data_offset, 4091e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain Location index, 4101e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain Location temp, 4111e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain bool needs_null_check); 4121e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain 4131e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain // Generate a read barrier for a heap reference within `instruction` 4141e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain // using a slow path. 4150d5a281c671444bfa75d63caf1427a8c0e6e1177Roland Levillain // 4160d5a281c671444bfa75d63caf1427a8c0e6e1177Roland Levillain // A read barrier for an object reference read from the heap is 4170d5a281c671444bfa75d63caf1427a8c0e6e1177Roland Levillain // implemented as a call to the artReadBarrierSlow runtime entry 4180d5a281c671444bfa75d63caf1427a8c0e6e1177Roland Levillain // point, which is passed the values in locations `ref`, `obj`, and 4190d5a281c671444bfa75d63caf1427a8c0e6e1177Roland Levillain // `offset`: 4200d5a281c671444bfa75d63caf1427a8c0e6e1177Roland Levillain // 4210d5a281c671444bfa75d63caf1427a8c0e6e1177Roland Levillain // mirror::Object* artReadBarrierSlow(mirror::Object* ref, 4220d5a281c671444bfa75d63caf1427a8c0e6e1177Roland Levillain // mirror::Object* obj, 4230d5a281c671444bfa75d63caf1427a8c0e6e1177Roland Levillain // uint32_t offset); 4240d5a281c671444bfa75d63caf1427a8c0e6e1177Roland Levillain // 4250d5a281c671444bfa75d63caf1427a8c0e6e1177Roland Levillain // The `out` location contains the value returned by 4260d5a281c671444bfa75d63caf1427a8c0e6e1177Roland Levillain // artReadBarrierSlow. 4270d5a281c671444bfa75d63caf1427a8c0e6e1177Roland Levillain // 4280d5a281c671444bfa75d63caf1427a8c0e6e1177Roland Levillain // When `index` provided (i.e., when it is different from 4290d5a281c671444bfa75d63caf1427a8c0e6e1177Roland Levillain // Location::NoLocation()), the offset value passed to 4300d5a281c671444bfa75d63caf1427a8c0e6e1177Roland Levillain // artReadBarrierSlow is adjusted to take `index` into account. 4311e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain void GenerateReadBarrierSlow(HInstruction* instruction, 4321e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain Location out, 4331e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain Location ref, 4341e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain Location obj, 4351e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain uint32_t offset, 4361e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain Location index = Location::NoLocation()); 4371e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain 4381e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain // If read barriers are enabled, generate a read barrier for a heap 4391e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain // reference using a slow path. If heap poisoning is enabled, also 4401e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain // unpoison the reference in `out`. 4411e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain void MaybeGenerateReadBarrierSlow(HInstruction* instruction, 4421e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain Location out, 4431e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain Location ref, 4441e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain Location obj, 4451e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain uint32_t offset, 4461e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain Location index = Location::NoLocation()); 4471e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain 4481e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain // Generate a read barrier for a GC root within `instruction` using 4491e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain // a slow path. 4500d5a281c671444bfa75d63caf1427a8c0e6e1177Roland Levillain // 4510d5a281c671444bfa75d63caf1427a8c0e6e1177Roland Levillain // A read barrier for an object reference GC root is implemented as 4520d5a281c671444bfa75d63caf1427a8c0e6e1177Roland Levillain // a call to the artReadBarrierForRootSlow runtime entry point, 4530d5a281c671444bfa75d63caf1427a8c0e6e1177Roland Levillain // which is passed the value in location `root`: 4540d5a281c671444bfa75d63caf1427a8c0e6e1177Roland Levillain // 4550d5a281c671444bfa75d63caf1427a8c0e6e1177Roland Levillain // mirror::Object* artReadBarrierForRootSlow(GcRoot<mirror::Object>* root); 4560d5a281c671444bfa75d63caf1427a8c0e6e1177Roland Levillain // 4570d5a281c671444bfa75d63caf1427a8c0e6e1177Roland Levillain // The `out` location contains the value returned by 4580d5a281c671444bfa75d63caf1427a8c0e6e1177Roland Levillain // artReadBarrierForRootSlow. 4591e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain void GenerateReadBarrierForRootSlow(HInstruction* instruction, Location out, Location root); 4600d5a281c671444bfa75d63caf1427a8c0e6e1177Roland Levillain 461f55c3e0825cdfc4c5a27730031177d1a0198ec5aMark Mendell int ConstantAreaStart() const { 462f55c3e0825cdfc4c5a27730031177d1a0198ec5aMark Mendell return constant_area_start_; 463f55c3e0825cdfc4c5a27730031177d1a0198ec5aMark Mendell } 464f55c3e0825cdfc4c5a27730031177d1a0198ec5aMark Mendell 465f55c3e0825cdfc4c5a27730031177d1a0198ec5aMark Mendell Address LiteralDoubleAddress(double v); 466f55c3e0825cdfc4c5a27730031177d1a0198ec5aMark Mendell Address LiteralFloatAddress(float v); 467f55c3e0825cdfc4c5a27730031177d1a0198ec5aMark Mendell Address LiteralInt32Address(int32_t v); 468f55c3e0825cdfc4c5a27730031177d1a0198ec5aMark Mendell Address LiteralInt64Address(int64_t v); 469f55c3e0825cdfc4c5a27730031177d1a0198ec5aMark Mendell 47092e83bf8c0b2df8c977ffbc527989631d94b1819Mark Mendell // Load a 64 bit value into a register in the most efficient manner. 47192e83bf8c0b2df8c977ffbc527989631d94b1819Mark Mendell void Load64BitValue(CpuRegister dest, int64_t value); 4729c86b485bc6169eadf846dd5f7cdf0958fe1eb23Mark Mendell Address LiteralCaseTable(HPackedSwitch* switch_instr); 47392e83bf8c0b2df8c977ffbc527989631d94b1819Mark Mendell 474cfa410b0ea561318f74a76c5323f0f6cd8eaaa50Mark Mendell // Store a 64 bit value into a DoubleStackSlot in the most efficient manner. 475cfa410b0ea561318f74a76c5323f0f6cd8eaaa50Mark Mendell void Store64BitValueToStack(Location dest, int64_t value); 476cfa410b0ea561318f74a76c5323f0f6cd8eaaa50Mark Mendell 477ea5af68d6dda832bdfb5978a0c5d6f86a3f67e80Mark Mendell // Assign a 64 bit constant to an address. 478ea5af68d6dda832bdfb5978a0c5d6f86a3f67e80Mark Mendell void MoveInt64ToAddress(const Address& addr_low, 479ea5af68d6dda832bdfb5978a0c5d6f86a3f67e80Mark Mendell const Address& addr_high, 480ea5af68d6dda832bdfb5978a0c5d6f86a3f67e80Mark Mendell int64_t v, 481ea5af68d6dda832bdfb5978a0c5d6f86a3f67e80Mark Mendell HInstruction* instruction); 482ea5af68d6dda832bdfb5978a0c5d6f86a3f67e80Mark Mendell 48317077d888a6752a2e5f8161eee1b2c3285783d12Mark P Mendell // Ensure that prior stores complete to memory before subsequent loads. 48417077d888a6752a2e5f8161eee1b2c3285783d12Mark P Mendell // The locked add implementation will avoid serializing device memory, but will 48517077d888a6752a2e5f8161eee1b2c3285783d12Mark P Mendell // touch (but not change) the top of the stack. The locked add should not be used for 48617077d888a6752a2e5f8161eee1b2c3285783d12Mark P Mendell // ordering non-temporal stores. 48717077d888a6752a2e5f8161eee1b2c3285783d12Mark P Mendell void MemoryFence(bool force_mfence = false) { 48817077d888a6752a2e5f8161eee1b2c3285783d12Mark P Mendell if (!force_mfence && isa_features_.PrefersLockedAddSynchronization()) { 48917077d888a6752a2e5f8161eee1b2c3285783d12Mark P Mendell assembler_.lock()->addl(Address(CpuRegister(RSP), 0), Immediate(0)); 49017077d888a6752a2e5f8161eee1b2c3285783d12Mark P Mendell } else { 49117077d888a6752a2e5f8161eee1b2c3285783d12Mark P Mendell assembler_.mfence(); 49217077d888a6752a2e5f8161eee1b2c3285783d12Mark P Mendell } 49317077d888a6752a2e5f8161eee1b2c3285783d12Mark P Mendell } 49417077d888a6752a2e5f8161eee1b2c3285783d12Mark P Mendell 4953c7bb98698f77af10372cf31824d3bb115d9bf0fNicolas Geoffray private: 4961e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain // Factored implementation of GenerateFieldLoadWithBakerReadBarrier 4971e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain // and GenerateArrayLoadWithBakerReadBarrier. 4981e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain void GenerateReferenceLoadWithBakerReadBarrier(HInstruction* instruction, 4991e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain Location ref, 5001e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain CpuRegister obj, 5011e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain const Address& src, 5021e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain Location temp, 5031e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain bool needs_null_check); 5041e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain 505581550137ee3a068a14224870e71aeee924a0646Vladimir Marko struct PcRelativeDexCacheAccessInfo { 506581550137ee3a068a14224870e71aeee924a0646Vladimir Marko PcRelativeDexCacheAccessInfo(const DexFile& dex_file, uint32_t element_off) 507581550137ee3a068a14224870e71aeee924a0646Vladimir Marko : target_dex_file(dex_file), element_offset(element_off), label() { } 508581550137ee3a068a14224870e71aeee924a0646Vladimir Marko 509581550137ee3a068a14224870e71aeee924a0646Vladimir Marko const DexFile& target_dex_file; 510581550137ee3a068a14224870e71aeee924a0646Vladimir Marko uint32_t element_offset; 511581550137ee3a068a14224870e71aeee924a0646Vladimir Marko Label label; 512581550137ee3a068a14224870e71aeee924a0646Vladimir Marko }; 513581550137ee3a068a14224870e71aeee924a0646Vladimir Marko 51492a73aef279be78e3c2b04db1713076183933436Nicolas Geoffray // Labels for each block that will be compiled. 515225b6464a58ebe11c156144653f11a1c6607f4ebVladimir Marko Label* block_labels_; // Indexed by block id. 5161cf95287364948689f6a1a320567acd7728e94a3Nicolas Geoffray Label frame_entry_label_; 5179cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray LocationsBuilderX86_64 location_builder_; 5189cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray InstructionCodeGeneratorX86_64 instruction_visitor_; 519ecb2f9ba57b08ceac4204ddd6a0a88a0524f8741Nicolas Geoffray ParallelMoveResolverX86_64 move_resolver_; 5209cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray X86_64Assembler assembler_; 521fb8d279bc011b31d0765dc7ca59afea324fd0d0cMark Mendell const X86_64InstructionSetFeatures& isa_features_; 5229cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray 52339dcf55a56da746e04f477f89e7b00ba1de03880Mark Mendell // Offset to the start of the constant area in the assembled code. 524f55c3e0825cdfc4c5a27730031177d1a0198ec5aMark Mendell // Used for fixups to the constant area. 525f55c3e0825cdfc4c5a27730031177d1a0198ec5aMark Mendell int constant_area_start_; 526f55c3e0825cdfc4c5a27730031177d1a0198ec5aMark Mendell 527581550137ee3a068a14224870e71aeee924a0646Vladimir Marko // Method patch info. Using ArenaDeque<> which retains element addresses on push/emplace_back(). 528581550137ee3a068a14224870e71aeee924a0646Vladimir Marko ArenaDeque<MethodPatchInfo<Label>> method_patches_; 529581550137ee3a068a14224870e71aeee924a0646Vladimir Marko ArenaDeque<MethodPatchInfo<Label>> relative_call_patches_; 530581550137ee3a068a14224870e71aeee924a0646Vladimir Marko // PC-relative DexCache access info. 5310f7dca4ca0be8d2f8776794d35edf8b51b5bc997Vladimir Marko ArenaDeque<PcRelativeDexCacheAccessInfo> pc_relative_dex_cache_patches_; 532581550137ee3a068a14224870e71aeee924a0646Vladimir Marko 533581550137ee3a068a14224870e71aeee924a0646Vladimir Marko // When we don't know the proper offset for the value, we use kDummy32BitOffset. 534581550137ee3a068a14224870e71aeee924a0646Vladimir Marko // We will fix this up in the linker later to have the right value. 535581550137ee3a068a14224870e71aeee924a0646Vladimir Marko static constexpr int32_t kDummy32BitOffset = 256; 536581550137ee3a068a14224870e71aeee924a0646Vladimir Marko 5379c86b485bc6169eadf846dd5f7cdf0958fe1eb23Mark Mendell // Fixups for jump tables need to be handled specially. 5389c86b485bc6169eadf846dd5f7cdf0958fe1eb23Mark Mendell ArenaVector<JumpTableRIPFixup*> fixups_to_jump_tables_; 5399c86b485bc6169eadf846dd5f7cdf0958fe1eb23Mark Mendell 5409cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray DISALLOW_COPY_AND_ASSIGN(CodeGeneratorX86_64); 5419cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray}; 5429cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray 5439cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray} // namespace x86_64 5449cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray} // namespace art 5459cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray 5469cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray#endif // ART_COMPILER_OPTIMIZING_CODE_GENERATOR_X86_64_H_ 547