code_generator_x86_64.h revision cac5a7e871f1f346b317894359ad06fa7bd67fba
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); 1755f7b58ea1adfc0639dd605b65f59198d3763f801Vladimir Marko void HandleCondition(HCondition* condition); 1769aec02fc5df5518c16f1e5a9b6cb198a192db973Calin Juravle void HandleShift(HBinaryOperation* operation); 17752c489645b6e9ae33623f1ec24143cde5444906eCalin Juravle void HandleFieldSet(HInstruction* instruction, const FieldInfo& field_info); 17852c489645b6e9ae33623f1ec24143cde5444906eCalin Juravle void HandleFieldGet(HInstruction* instruction); 179e982f0b8e809cece6f460fa2d8df25873aa69de4Nicolas Geoffray 1809cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray CodeGeneratorX86_64* const codegen_; 1812d27c8e338af7262dbd4aaa66127bb8fa1758b86Roland Levillain InvokeDexCallingConventionVisitorX86_64 parameter_visitor_; 1829cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray 1839cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray DISALLOW_COPY_AND_ASSIGN(LocationsBuilderX86_64); 1849cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray}; 1859cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray 18642249c3602c3d0243396ee3627ffb5906aa77c1eAart Bikclass InstructionCodeGeneratorX86_64 : public InstructionCodeGenerator { 1879cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray public: 1889cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray InstructionCodeGeneratorX86_64(HGraph* graph, CodeGeneratorX86_64* codegen); 1899cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray 190360231a056e796c36ffe62348507e904dc9efb9bNicolas Geoffray#define DECLARE_VISIT_INSTRUCTION(name, super) \ 191de58ab2c03ff8112b07ab827c8fa38f670dfc656Nicolas Geoffray void Visit##name(H##name* instr) OVERRIDE; 1929cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray 193ef20f71e16f035a39a329c8524d7e59ca6a11f04Alexandre Rames FOR_EACH_CONCRETE_INSTRUCTION_COMMON(DECLARE_VISIT_INSTRUCTION) 194ef20f71e16f035a39a329c8524d7e59ca6a11f04Alexandre Rames FOR_EACH_CONCRETE_INSTRUCTION_X86_64(DECLARE_VISIT_INSTRUCTION) 1959cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray 1969cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray#undef DECLARE_VISIT_INSTRUCTION 1979cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray 198ef20f71e16f035a39a329c8524d7e59ca6a11f04Alexandre Rames void VisitInstruction(HInstruction* instruction) OVERRIDE { 199ef20f71e16f035a39a329c8524d7e59ca6a11f04Alexandre Rames LOG(FATAL) << "Unreachable instruction " << instruction->DebugName() 200ef20f71e16f035a39a329c8524d7e59ca6a11f04Alexandre Rames << " (id " << instruction->GetId() << ")"; 201ef20f71e16f035a39a329c8524d7e59ca6a11f04Alexandre Rames } 202ef20f71e16f035a39a329c8524d7e59ca6a11f04Alexandre Rames 2039cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray X86_64Assembler* GetAssembler() const { return assembler_; } 2049cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray 2059cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray private: 2063c04974a90b0e03f4b509010bff49f0b2a3da57fNicolas Geoffray // Generate code for the given suspend check. If not null, `successor` 2073c04974a90b0e03f4b509010bff49f0b2a3da57fNicolas Geoffray // is the block to branch to if the suspend check is not needed, and after 2083c04974a90b0e03f4b509010bff49f0b2a3da57fNicolas Geoffray // the suspend call. 2093c04974a90b0e03f4b509010bff49f0b2a3da57fNicolas Geoffray void GenerateSuspendCheck(HSuspendCheck* instruction, HBasicBlock* successor); 21085b62f23fc6dfffe2ddd3ddfa74611666c9ff41dAndreas Gampe void GenerateClassInitializationCheck(SlowPathCode* slow_path, CpuRegister class_reg); 2119574c4b5f5ef039d694ac12c97e25ca02eca83c0Nicolas Geoffray void HandleBitwiseOperation(HBinaryOperation* operation); 212c470193cfc522fc818eb2eaab896aef9caf0c75aMark Mendell void GenerateRemFP(HRem* rem); 2130f88e87085b7cf6544dadff3f555773966a6853eGuillaume Sanchez void DivRemOneOrMinusOne(HBinaryOperation* instruction); 214b19930c5cba3cf662dce5ee057fcc9829b4cbb9cGuillaume Sanchez void DivByPowerOfTwo(HDiv* instruction); 2150f88e87085b7cf6544dadff3f555773966a6853eGuillaume Sanchez void GenerateDivRemWithAnyConstant(HBinaryOperation* instruction); 216bacfec30ee9f2f6fdfd190f11b105b609938efcaCalin Juravle void GenerateDivRemIntegral(HBinaryOperation* instruction); 2175f7b58ea1adfc0639dd605b65f59198d3763f801Vladimir Marko void HandleCondition(HCondition* condition); 2189aec02fc5df5518c16f1e5a9b6cb198a192db973Calin Juravle void HandleShift(HBinaryOperation* operation); 2191e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain 22007276db28d654594e0e86e9e467cad393f752e6eNicolas Geoffray void HandleFieldSet(HInstruction* instruction, 22107276db28d654594e0e86e9e467cad393f752e6eNicolas Geoffray const FieldInfo& field_info, 22207276db28d654594e0e86e9e467cad393f752e6eNicolas Geoffray bool value_can_be_null); 22352c489645b6e9ae33623f1ec24143cde5444906eCalin Juravle void HandleFieldGet(HInstruction* instruction, const FieldInfo& field_info); 2241e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain 2251e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain // Generate a heap reference load using one register `out`: 2261e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain // 2271e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain // out <- *(out + offset) 2281e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain // 2291e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain // while honoring heap poisoning and/or read barriers (if any). 23095e7ffc28ea4d6deba356e636b16120ae49b62e2Roland Levillain // 23195e7ffc28ea4d6deba356e636b16120ae49b62e2Roland Levillain // Location `maybe_temp` is used when generating a read barrier and 23295e7ffc28ea4d6deba356e636b16120ae49b62e2Roland Levillain // shall be a register in that case; it may be an invalid location 23395e7ffc28ea4d6deba356e636b16120ae49b62e2Roland Levillain // otherwise. 2341e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain void GenerateReferenceLoadOneRegister(HInstruction* instruction, 2351e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain Location out, 2361e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain uint32_t offset, 23795e7ffc28ea4d6deba356e636b16120ae49b62e2Roland Levillain Location maybe_temp); 2381e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain // Generate a heap reference load using two different registers 2391e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain // `out` and `obj`: 2401e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain // 2411e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain // out <- *(obj + offset) 2421e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain // 2431e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain // while honoring heap poisoning and/or read barriers (if any). 24495e7ffc28ea4d6deba356e636b16120ae49b62e2Roland Levillain // 24595e7ffc28ea4d6deba356e636b16120ae49b62e2Roland Levillain // Location `maybe_temp` is used when generating a Baker's (fast 24695e7ffc28ea4d6deba356e636b16120ae49b62e2Roland Levillain // path) read barrier and shall be a register in that case; it may 24795e7ffc28ea4d6deba356e636b16120ae49b62e2Roland Levillain // be an invalid location otherwise. 2481e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain void GenerateReferenceLoadTwoRegisters(HInstruction* instruction, 2491e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain Location out, 2501e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain Location obj, 2511e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain uint32_t offset, 25295e7ffc28ea4d6deba356e636b16120ae49b62e2Roland Levillain Location maybe_temp); 2531e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain // Generate a GC root reference load: 2541e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain // 255cac5a7e871f1f346b317894359ad06fa7bd67fbaVladimir Marko // root <- *address 2561e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain // 2571e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain // while honoring read barriers (if any). 2581e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain void GenerateGcRootFieldLoad(HInstruction* instruction, 2591e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain Location root, 260cac5a7e871f1f346b317894359ad06fa7bd67fbaVladimir Marko const Address& address, 261cac5a7e871f1f346b317894359ad06fa7bd67fbaVladimir Marko Label* fixup_label = nullptr); 2621e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain 26324f2dfae084b2382c053f5d688fd6bb26cb8a328Mark Mendell void PushOntoFPStack(Location source, uint32_t temp_offset, 26424f2dfae084b2382c053f5d688fd6bb26cb8a328Mark Mendell uint32_t stack_adjustment, bool is_float); 2657c0b44f180f1b8cf82c568091d250071d1130954Mark Mendell void GenerateCompareTest(HCondition* condition); 266152408f8c2188a7ed950cad04883b2f67dc74e84Mark Mendell template<class LabelType> 267d43b3ac88cd46b8815890188c9c2b9a3f1564648Mingyao Yang void GenerateTestAndBranch(HInstruction* instruction, 2680debae7bc89eb05f7a2bf7dccd223318fad7c88dDavid Brazdil size_t condition_input_index, 269152408f8c2188a7ed950cad04883b2f67dc74e84Mark Mendell LabelType* true_target, 270152408f8c2188a7ed950cad04883b2f67dc74e84Mark Mendell LabelType* false_target); 271152408f8c2188a7ed950cad04883b2f67dc74e84Mark Mendell template<class LabelType> 2720debae7bc89eb05f7a2bf7dccd223318fad7c88dDavid Brazdil void GenerateCompareTestAndBranch(HCondition* condition, 273152408f8c2188a7ed950cad04883b2f67dc74e84Mark Mendell LabelType* true_target, 274152408f8c2188a7ed950cad04883b2f67dc74e84Mark Mendell LabelType* false_target); 275152408f8c2188a7ed950cad04883b2f67dc74e84Mark Mendell template<class LabelType> 276152408f8c2188a7ed950cad04883b2f67dc74e84Mark Mendell void GenerateFPJumps(HCondition* cond, LabelType* true_label, LabelType* false_label); 277152408f8c2188a7ed950cad04883b2f67dc74e84Mark Mendell 278fc6a86ab2b70781e72b807c1798b83829ca7f931David Brazdil void HandleGoto(HInstruction* got, HBasicBlock* successor); 2793c04974a90b0e03f4b509010bff49f0b2a3da57fNicolas Geoffray 2809cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray X86_64Assembler* const assembler_; 2819cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray CodeGeneratorX86_64* const codegen_; 2829cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray 2839cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray DISALLOW_COPY_AND_ASSIGN(InstructionCodeGeneratorX86_64); 2849cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray}; 2859cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray 2869c86b485bc6169eadf846dd5f7cdf0958fe1eb23Mark Mendell// Class for fixups to jump tables. 2879c86b485bc6169eadf846dd5f7cdf0958fe1eb23Mark Mendellclass JumpTableRIPFixup; 2889c86b485bc6169eadf846dd5f7cdf0958fe1eb23Mark Mendell 2899cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffrayclass CodeGeneratorX86_64 : public CodeGenerator { 2909cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray public: 291fb8d279bc011b31d0765dc7ca59afea324fd0d0cMark Mendell CodeGeneratorX86_64(HGraph* graph, 292fb8d279bc011b31d0765dc7ca59afea324fd0d0cMark Mendell const X86_64InstructionSetFeatures& isa_features, 293ecc4366670e12b4812ef1653f7c8d52234ca1b1fSerban Constantinescu const CompilerOptions& compiler_options, 294ecc4366670e12b4812ef1653f7c8d52234ca1b1fSerban Constantinescu OptimizingCompilerStats* stats = nullptr); 2959cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray virtual ~CodeGeneratorX86_64() {} 2969cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray 297de58ab2c03ff8112b07ab827c8fa38f670dfc656Nicolas Geoffray void GenerateFrameEntry() OVERRIDE; 298de58ab2c03ff8112b07ab827c8fa38f670dfc656Nicolas Geoffray void GenerateFrameExit() OVERRIDE; 299de58ab2c03ff8112b07ab827c8fa38f670dfc656Nicolas Geoffray void Bind(HBasicBlock* block) OVERRIDE; 300175dc732c80e6f2afd83209348124df349290ba8Calin Juravle void MoveConstant(Location destination, int32_t value) OVERRIDE; 301e460d1df1f789c7c8bb97024a8efbd713ac175e9Calin Juravle void MoveLocation(Location dst, Location src, Primitive::Type dst_type) OVERRIDE; 302e460d1df1f789c7c8bb97024a8efbd713ac175e9Calin Juravle void AddLocationAsTemp(Location location, LocationSummary* locations) OVERRIDE; 303e460d1df1f789c7c8bb97024a8efbd713ac175e9Calin Juravle 304de58ab2c03ff8112b07ab827c8fa38f670dfc656Nicolas Geoffray size_t SaveCoreRegister(size_t stack_index, uint32_t reg_id) OVERRIDE; 305de58ab2c03ff8112b07ab827c8fa38f670dfc656Nicolas Geoffray size_t RestoreCoreRegister(size_t stack_index, uint32_t reg_id) OVERRIDE; 306de58ab2c03ff8112b07ab827c8fa38f670dfc656Nicolas Geoffray size_t SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) OVERRIDE; 307de58ab2c03ff8112b07ab827c8fa38f670dfc656Nicolas Geoffray size_t RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) OVERRIDE; 3089cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray 3098158f28b6689314213eb4dbbe14166073be71f7eAlexandre Rames // Generate code to invoke a runtime entry point. 310175dc732c80e6f2afd83209348124df349290ba8Calin Juravle void InvokeRuntime(QuickEntrypointEnum entrypoint, 311175dc732c80e6f2afd83209348124df349290ba8Calin Juravle HInstruction* instruction, 312175dc732c80e6f2afd83209348124df349290ba8Calin Juravle uint32_t dex_pc, 313175dc732c80e6f2afd83209348124df349290ba8Calin Juravle SlowPathCode* slow_path) OVERRIDE; 314175dc732c80e6f2afd83209348124df349290ba8Calin Juravle 315175dc732c80e6f2afd83209348124df349290ba8Calin Juravle void InvokeRuntime(int32_t entry_point_offset, 3168158f28b6689314213eb4dbbe14166073be71f7eAlexandre Rames HInstruction* instruction, 3178158f28b6689314213eb4dbbe14166073be71f7eAlexandre Rames uint32_t dex_pc, 3188158f28b6689314213eb4dbbe14166073be71f7eAlexandre Rames SlowPathCode* slow_path); 3198158f28b6689314213eb4dbbe14166073be71f7eAlexandre Rames 320de58ab2c03ff8112b07ab827c8fa38f670dfc656Nicolas Geoffray size_t GetWordSize() const OVERRIDE { 3219cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray return kX86_64WordSize; 3229cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray } 3239cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray 324f85a9ca9859ad843dc03d3a2b600afbaf2e9bbddMark Mendell size_t GetFloatingPointSpillSlotSize() const OVERRIDE { 325f85a9ca9859ad843dc03d3a2b600afbaf2e9bbddMark Mendell return kX86_64WordSize; 326f85a9ca9859ad843dc03d3a2b600afbaf2e9bbddMark Mendell } 327f85a9ca9859ad843dc03d3a2b600afbaf2e9bbddMark Mendell 328de58ab2c03ff8112b07ab827c8fa38f670dfc656Nicolas Geoffray HGraphVisitor* GetLocationBuilder() OVERRIDE { 3299cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray return &location_builder_; 3309cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray } 3319cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray 332de58ab2c03ff8112b07ab827c8fa38f670dfc656Nicolas Geoffray HGraphVisitor* GetInstructionVisitor() OVERRIDE { 3339cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray return &instruction_visitor_; 3349cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray } 3359cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray 336de58ab2c03ff8112b07ab827c8fa38f670dfc656Nicolas Geoffray X86_64Assembler* GetAssembler() OVERRIDE { 3379cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray return &assembler_; 3389cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray } 3399cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray 340eb7b7399dbdb5e471b8ae00a567bf4f19edd3907Alexandre Rames const X86_64Assembler& GetAssembler() const OVERRIDE { 341eb7b7399dbdb5e471b8ae00a567bf4f19edd3907Alexandre Rames return assembler_; 342eb7b7399dbdb5e471b8ae00a567bf4f19edd3907Alexandre Rames } 343eb7b7399dbdb5e471b8ae00a567bf4f19edd3907Alexandre Rames 344f0e3937b87453234d0d7970b8712082062709b8dNicolas Geoffray ParallelMoveResolverX86_64* GetMoveResolver() OVERRIDE { 345ecb2f9ba57b08ceac4204ddd6a0a88a0524f8741Nicolas Geoffray return &move_resolver_; 346ecb2f9ba57b08ceac4204ddd6a0a88a0524f8741Nicolas Geoffray } 347ecb2f9ba57b08ceac4204ddd6a0a88a0524f8741Nicolas Geoffray 348de58ab2c03ff8112b07ab827c8fa38f670dfc656Nicolas Geoffray uintptr_t GetAddressOf(HBasicBlock* block) const OVERRIDE { 349de58ab2c03ff8112b07ab827c8fa38f670dfc656Nicolas Geoffray return GetLabelOf(block)->Position(); 350de58ab2c03ff8112b07ab827c8fa38f670dfc656Nicolas Geoffray } 351de58ab2c03ff8112b07ab827c8fa38f670dfc656Nicolas Geoffray 352de58ab2c03ff8112b07ab827c8fa38f670dfc656Nicolas Geoffray Location GetStackLocation(HLoadLocal* load) const OVERRIDE; 3539cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray 35458282f4510961317b8d5a364a6f740a78926716fDavid Brazdil void SetupBlockedRegisters() const OVERRIDE; 355de58ab2c03ff8112b07ab827c8fa38f670dfc656Nicolas Geoffray void DumpCoreRegister(std::ostream& stream, int reg) const OVERRIDE; 356de58ab2c03ff8112b07ab827c8fa38f670dfc656Nicolas Geoffray void DumpFloatingPointRegister(std::ostream& stream, int reg) const OVERRIDE; 357f55c3e0825cdfc4c5a27730031177d1a0198ec5aMark Mendell void Finalize(CodeAllocator* allocator) OVERRIDE; 3589cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray 359de58ab2c03ff8112b07ab827c8fa38f670dfc656Nicolas Geoffray InstructionSet GetInstructionSet() const OVERRIDE { 360412f10cfed002ab617c78f2621d68446ca4dd8bdNicolas Geoffray return InstructionSet::kX86_64; 361412f10cfed002ab617c78f2621d68446ca4dd8bdNicolas Geoffray } 362412f10cfed002ab617c78f2621d68446ca4dd8bdNicolas Geoffray 3633c7bb98698f77af10372cf31824d3bb115d9bf0fNicolas Geoffray // Emit a write barrier. 36407276db28d654594e0e86e9e467cad393f752e6eNicolas Geoffray void MarkGCCard(CpuRegister temp, 36507276db28d654594e0e86e9e467cad393f752e6eNicolas Geoffray CpuRegister card, 36607276db28d654594e0e86e9e467cad393f752e6eNicolas Geoffray CpuRegister object, 36707276db28d654594e0e86e9e467cad393f752e6eNicolas Geoffray CpuRegister value, 36807276db28d654594e0e86e9e467cad393f752e6eNicolas Geoffray bool value_can_be_null); 3693c7bb98698f77af10372cf31824d3bb115d9bf0fNicolas Geoffray 3701e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain void GenerateMemoryBarrier(MemBarrierKind kind); 3711e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain 3729cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray // Helper method to move a value between two locations. 3739cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray void Move(Location destination, Location source); 3749cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray 37592a73aef279be78e3c2b04db1713076183933436Nicolas Geoffray Label* GetLabelOf(HBasicBlock* block) const { 376225b6464a58ebe11c156144653f11a1c6607f4ebVladimir Marko return CommonGetLabelOf<Label>(block_labels_, block); 37792a73aef279be78e3c2b04db1713076183933436Nicolas Geoffray } 37892a73aef279be78e3c2b04db1713076183933436Nicolas Geoffray 379de58ab2c03ff8112b07ab827c8fa38f670dfc656Nicolas Geoffray void Initialize() OVERRIDE { 380225b6464a58ebe11c156144653f11a1c6607f4ebVladimir Marko block_labels_ = CommonInitializeLabels<Label>(); 38192a73aef279be78e3c2b04db1713076183933436Nicolas Geoffray } 38292a73aef279be78e3c2b04db1713076183933436Nicolas Geoffray 383840e5461a85f8908f51e7f6cd562a9129ff0e7ceNicolas Geoffray bool NeedsTwoRegisters(Primitive::Type type ATTRIBUTE_UNUSED) const OVERRIDE { 384840e5461a85f8908f51e7f6cd562a9129ff0e7ceNicolas Geoffray return false; 385840e5461a85f8908f51e7f6cd562a9129ff0e7ceNicolas Geoffray } 386840e5461a85f8908f51e7f6cd562a9129ff0e7ceNicolas Geoffray 387cac5a7e871f1f346b317894359ad06fa7bd67fbaVladimir Marko // Check if the desired_string_load_kind is supported. If it is, return it, 388cac5a7e871f1f346b317894359ad06fa7bd67fbaVladimir Marko // otherwise return a fall-back kind that should be used instead. 389cac5a7e871f1f346b317894359ad06fa7bd67fbaVladimir Marko HLoadString::LoadKind GetSupportedLoadStringKind( 390cac5a7e871f1f346b317894359ad06fa7bd67fbaVladimir Marko HLoadString::LoadKind desired_string_load_kind) OVERRIDE; 391cac5a7e871f1f346b317894359ad06fa7bd67fbaVladimir Marko 392dc151b2346bb8a4fdeed0c06e54c2fca21d59b5dVladimir Marko // Check if the desired_dispatch_info is supported. If it is, return it, 393dc151b2346bb8a4fdeed0c06e54c2fca21d59b5dVladimir Marko // otherwise return a fall-back info that should be used instead. 394dc151b2346bb8a4fdeed0c06e54c2fca21d59b5dVladimir Marko HInvokeStaticOrDirect::DispatchInfo GetSupportedInvokeStaticOrDirectDispatch( 395dc151b2346bb8a4fdeed0c06e54c2fca21d59b5dVladimir Marko const HInvokeStaticOrDirect::DispatchInfo& desired_dispatch_info, 396dc151b2346bb8a4fdeed0c06e54c2fca21d59b5dVladimir Marko MethodReference target_method) OVERRIDE; 397dc151b2346bb8a4fdeed0c06e54c2fca21d59b5dVladimir Marko 39885b62f23fc6dfffe2ddd3ddfa74611666c9ff41dAndreas Gampe void GenerateStaticOrDirectCall(HInvokeStaticOrDirect* invoke, Location temp) OVERRIDE; 39985b62f23fc6dfffe2ddd3ddfa74611666c9ff41dAndreas Gampe void GenerateVirtualCall(HInvokeVirtual* invoke, Location temp) OVERRIDE; 40085b62f23fc6dfffe2ddd3ddfa74611666c9ff41dAndreas Gampe 401cac5a7e871f1f346b317894359ad06fa7bd67fbaVladimir Marko void RecordSimplePatch(); 402cac5a7e871f1f346b317894359ad06fa7bd67fbaVladimir Marko void RecordStringPatch(HLoadString* load_string); 403cac5a7e871f1f346b317894359ad06fa7bd67fbaVladimir Marko Label* NewPcRelativeDexCacheArrayPatch(const DexFile& dex_file, uint32_t element_offset); 404cac5a7e871f1f346b317894359ad06fa7bd67fbaVladimir Marko 40585b62f23fc6dfffe2ddd3ddfa74611666c9ff41dAndreas Gampe void MoveFromReturnRegister(Location trg, Primitive::Type type) OVERRIDE; 40671fb52fee246b7d511f520febbd73dc7a9bbca79Andreas Gampe 407581550137ee3a068a14224870e71aeee924a0646Vladimir Marko void EmitLinkerPatches(ArenaVector<LinkerPatch>* linker_patches) OVERRIDE; 408581550137ee3a068a14224870e71aeee924a0646Vladimir Marko 409fb8d279bc011b31d0765dc7ca59afea324fd0d0cMark Mendell const X86_64InstructionSetFeatures& GetInstructionSetFeatures() const { 410fb8d279bc011b31d0765dc7ca59afea324fd0d0cMark Mendell return isa_features_; 411fb8d279bc011b31d0765dc7ca59afea324fd0d0cMark Mendell } 412fb8d279bc011b31d0765dc7ca59afea324fd0d0cMark Mendell 4131e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain // Fast path implementation of ReadBarrier::Barrier for a heap 4141e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain // reference field load when Baker's read barriers are used. 4151e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain void GenerateFieldLoadWithBakerReadBarrier(HInstruction* instruction, 416e3f43ac79e50a4693ea4d46acf5cffca64910ceeRoland Levillain Location ref, 4171e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain CpuRegister obj, 4181e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain uint32_t offset, 4191e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain Location temp, 4201e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain bool needs_null_check); 4211e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain // Fast path implementation of ReadBarrier::Barrier for a heap 4221e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain // reference array load when Baker's read barriers are used. 4231e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain void GenerateArrayLoadWithBakerReadBarrier(HInstruction* instruction, 424e3f43ac79e50a4693ea4d46acf5cffca64910ceeRoland Levillain Location ref, 4251e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain CpuRegister obj, 4261e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain uint32_t data_offset, 4271e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain Location index, 4281e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain Location temp, 4291e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain bool needs_null_check); 4301e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain 4311e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain // Generate a read barrier for a heap reference within `instruction` 4321e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain // using a slow path. 4330d5a281c671444bfa75d63caf1427a8c0e6e1177Roland Levillain // 4340d5a281c671444bfa75d63caf1427a8c0e6e1177Roland Levillain // A read barrier for an object reference read from the heap is 4350d5a281c671444bfa75d63caf1427a8c0e6e1177Roland Levillain // implemented as a call to the artReadBarrierSlow runtime entry 4360d5a281c671444bfa75d63caf1427a8c0e6e1177Roland Levillain // point, which is passed the values in locations `ref`, `obj`, and 4370d5a281c671444bfa75d63caf1427a8c0e6e1177Roland Levillain // `offset`: 4380d5a281c671444bfa75d63caf1427a8c0e6e1177Roland Levillain // 4390d5a281c671444bfa75d63caf1427a8c0e6e1177Roland Levillain // mirror::Object* artReadBarrierSlow(mirror::Object* ref, 4400d5a281c671444bfa75d63caf1427a8c0e6e1177Roland Levillain // mirror::Object* obj, 4410d5a281c671444bfa75d63caf1427a8c0e6e1177Roland Levillain // uint32_t offset); 4420d5a281c671444bfa75d63caf1427a8c0e6e1177Roland Levillain // 4430d5a281c671444bfa75d63caf1427a8c0e6e1177Roland Levillain // The `out` location contains the value returned by 4440d5a281c671444bfa75d63caf1427a8c0e6e1177Roland Levillain // artReadBarrierSlow. 4450d5a281c671444bfa75d63caf1427a8c0e6e1177Roland Levillain // 4460d5a281c671444bfa75d63caf1427a8c0e6e1177Roland Levillain // When `index` provided (i.e., when it is different from 4470d5a281c671444bfa75d63caf1427a8c0e6e1177Roland Levillain // Location::NoLocation()), the offset value passed to 4480d5a281c671444bfa75d63caf1427a8c0e6e1177Roland Levillain // artReadBarrierSlow is adjusted to take `index` into account. 4491e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain void GenerateReadBarrierSlow(HInstruction* instruction, 4501e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain Location out, 4511e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain Location ref, 4521e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain Location obj, 4531e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain uint32_t offset, 4541e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain Location index = Location::NoLocation()); 4551e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain 4561e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain // If read barriers are enabled, generate a read barrier for a heap 4571e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain // reference using a slow path. If heap poisoning is enabled, also 4581e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain // unpoison the reference in `out`. 4591e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain void MaybeGenerateReadBarrierSlow(HInstruction* instruction, 4601e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain Location out, 4611e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain Location ref, 4621e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain Location obj, 4631e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain uint32_t offset, 4641e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain Location index = Location::NoLocation()); 4651e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain 4661e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain // Generate a read barrier for a GC root within `instruction` using 4671e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain // a slow path. 4680d5a281c671444bfa75d63caf1427a8c0e6e1177Roland Levillain // 4690d5a281c671444bfa75d63caf1427a8c0e6e1177Roland Levillain // A read barrier for an object reference GC root is implemented as 4700d5a281c671444bfa75d63caf1427a8c0e6e1177Roland Levillain // a call to the artReadBarrierForRootSlow runtime entry point, 4710d5a281c671444bfa75d63caf1427a8c0e6e1177Roland Levillain // which is passed the value in location `root`: 4720d5a281c671444bfa75d63caf1427a8c0e6e1177Roland Levillain // 4730d5a281c671444bfa75d63caf1427a8c0e6e1177Roland Levillain // mirror::Object* artReadBarrierForRootSlow(GcRoot<mirror::Object>* root); 4740d5a281c671444bfa75d63caf1427a8c0e6e1177Roland Levillain // 4750d5a281c671444bfa75d63caf1427a8c0e6e1177Roland Levillain // The `out` location contains the value returned by 4760d5a281c671444bfa75d63caf1427a8c0e6e1177Roland Levillain // artReadBarrierForRootSlow. 4771e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain void GenerateReadBarrierForRootSlow(HInstruction* instruction, Location out, Location root); 4780d5a281c671444bfa75d63caf1427a8c0e6e1177Roland Levillain 479f55c3e0825cdfc4c5a27730031177d1a0198ec5aMark Mendell int ConstantAreaStart() const { 480f55c3e0825cdfc4c5a27730031177d1a0198ec5aMark Mendell return constant_area_start_; 481f55c3e0825cdfc4c5a27730031177d1a0198ec5aMark Mendell } 482f55c3e0825cdfc4c5a27730031177d1a0198ec5aMark Mendell 483f55c3e0825cdfc4c5a27730031177d1a0198ec5aMark Mendell Address LiteralDoubleAddress(double v); 484f55c3e0825cdfc4c5a27730031177d1a0198ec5aMark Mendell Address LiteralFloatAddress(float v); 485f55c3e0825cdfc4c5a27730031177d1a0198ec5aMark Mendell Address LiteralInt32Address(int32_t v); 486f55c3e0825cdfc4c5a27730031177d1a0198ec5aMark Mendell Address LiteralInt64Address(int64_t v); 487f55c3e0825cdfc4c5a27730031177d1a0198ec5aMark Mendell 488a19616e3363276e7f2c471eb2839fb16f1d43f27Aart Bik // Load a 32/64-bit value into a register in the most efficient manner. 489c5d4754198aadb2ada2d3f5daacd10d79bc13f38Aart Bik void Load32BitValue(CpuRegister dest, int32_t value); 49092e83bf8c0b2df8c977ffbc527989631d94b1819Mark Mendell void Load64BitValue(CpuRegister dest, int64_t value); 4917c0b44f180f1b8cf82c568091d250071d1130954Mark Mendell void Load32BitValue(XmmRegister dest, int32_t value); 4927c0b44f180f1b8cf82c568091d250071d1130954Mark Mendell void Load64BitValue(XmmRegister dest, int64_t value); 4937c0b44f180f1b8cf82c568091d250071d1130954Mark Mendell void Load32BitValue(XmmRegister dest, float value); 4947c0b44f180f1b8cf82c568091d250071d1130954Mark Mendell void Load64BitValue(XmmRegister dest, double value); 495c5d4754198aadb2ada2d3f5daacd10d79bc13f38Aart Bik 496a19616e3363276e7f2c471eb2839fb16f1d43f27Aart Bik // Compare a register with a 32/64-bit value in the most efficient manner. 497a19616e3363276e7f2c471eb2839fb16f1d43f27Aart Bik void Compare32BitValue(CpuRegister dest, int32_t value); 498a19616e3363276e7f2c471eb2839fb16f1d43f27Aart Bik void Compare64BitValue(CpuRegister dest, int64_t value); 499a19616e3363276e7f2c471eb2839fb16f1d43f27Aart Bik 5009c86b485bc6169eadf846dd5f7cdf0958fe1eb23Mark Mendell Address LiteralCaseTable(HPackedSwitch* switch_instr); 50192e83bf8c0b2df8c977ffbc527989631d94b1819Mark Mendell 502cfa410b0ea561318f74a76c5323f0f6cd8eaaa50Mark Mendell // Store a 64 bit value into a DoubleStackSlot in the most efficient manner. 503cfa410b0ea561318f74a76c5323f0f6cd8eaaa50Mark Mendell void Store64BitValueToStack(Location dest, int64_t value); 504cfa410b0ea561318f74a76c5323f0f6cd8eaaa50Mark Mendell 505ea5af68d6dda832bdfb5978a0c5d6f86a3f67e80Mark Mendell // Assign a 64 bit constant to an address. 506ea5af68d6dda832bdfb5978a0c5d6f86a3f67e80Mark Mendell void MoveInt64ToAddress(const Address& addr_low, 507ea5af68d6dda832bdfb5978a0c5d6f86a3f67e80Mark Mendell const Address& addr_high, 508ea5af68d6dda832bdfb5978a0c5d6f86a3f67e80Mark Mendell int64_t v, 509ea5af68d6dda832bdfb5978a0c5d6f86a3f67e80Mark Mendell HInstruction* instruction); 510ea5af68d6dda832bdfb5978a0c5d6f86a3f67e80Mark Mendell 51117077d888a6752a2e5f8161eee1b2c3285783d12Mark P Mendell // Ensure that prior stores complete to memory before subsequent loads. 51217077d888a6752a2e5f8161eee1b2c3285783d12Mark P Mendell // The locked add implementation will avoid serializing device memory, but will 51317077d888a6752a2e5f8161eee1b2c3285783d12Mark P Mendell // touch (but not change) the top of the stack. The locked add should not be used for 51417077d888a6752a2e5f8161eee1b2c3285783d12Mark P Mendell // ordering non-temporal stores. 51517077d888a6752a2e5f8161eee1b2c3285783d12Mark P Mendell void MemoryFence(bool force_mfence = false) { 51617077d888a6752a2e5f8161eee1b2c3285783d12Mark P Mendell if (!force_mfence && isa_features_.PrefersLockedAddSynchronization()) { 51717077d888a6752a2e5f8161eee1b2c3285783d12Mark P Mendell assembler_.lock()->addl(Address(CpuRegister(RSP), 0), Immediate(0)); 51817077d888a6752a2e5f8161eee1b2c3285783d12Mark P Mendell } else { 51917077d888a6752a2e5f8161eee1b2c3285783d12Mark P Mendell assembler_.mfence(); 52017077d888a6752a2e5f8161eee1b2c3285783d12Mark P Mendell } 52117077d888a6752a2e5f8161eee1b2c3285783d12Mark P Mendell } 52217077d888a6752a2e5f8161eee1b2c3285783d12Mark P Mendell 523c7098ff991bb4e00a800d315d1c36f52a9cb0149David Srbecky void GenerateNop(); 5242ae48182573da7087bffc2873730bc758ec29696Calin Juravle void GenerateImplicitNullCheck(HNullCheck* instruction); 5252ae48182573da7087bffc2873730bc758ec29696Calin Juravle void GenerateExplicitNullCheck(HNullCheck* instruction); 526c7098ff991bb4e00a800d315d1c36f52a9cb0149David Srbecky 527cac5a7e871f1f346b317894359ad06fa7bd67fbaVladimir Marko // When we don't know the proper offset for the value, we use kDummy32BitOffset. 528cac5a7e871f1f346b317894359ad06fa7bd67fbaVladimir Marko // We will fix this up in the linker later to have the right value. 529cac5a7e871f1f346b317894359ad06fa7bd67fbaVladimir Marko static constexpr int32_t kDummy32BitOffset = 256; 530cac5a7e871f1f346b317894359ad06fa7bd67fbaVladimir Marko 5313c7bb98698f77af10372cf31824d3bb115d9bf0fNicolas Geoffray private: 5321e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain // Factored implementation of GenerateFieldLoadWithBakerReadBarrier 5331e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain // and GenerateArrayLoadWithBakerReadBarrier. 5341e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain void GenerateReferenceLoadWithBakerReadBarrier(HInstruction* instruction, 5351e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain Location ref, 5361e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain CpuRegister obj, 5371e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain const Address& src, 5381e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain Location temp, 5391e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain bool needs_null_check); 5401e7f8db01a929ac816ca122868edc067c3c6cd17Roland Levillain 541581550137ee3a068a14224870e71aeee924a0646Vladimir Marko struct PcRelativeDexCacheAccessInfo { 542581550137ee3a068a14224870e71aeee924a0646Vladimir Marko PcRelativeDexCacheAccessInfo(const DexFile& dex_file, uint32_t element_off) 543581550137ee3a068a14224870e71aeee924a0646Vladimir Marko : target_dex_file(dex_file), element_offset(element_off), label() { } 544581550137ee3a068a14224870e71aeee924a0646Vladimir Marko 545581550137ee3a068a14224870e71aeee924a0646Vladimir Marko const DexFile& target_dex_file; 546581550137ee3a068a14224870e71aeee924a0646Vladimir Marko uint32_t element_offset; 547581550137ee3a068a14224870e71aeee924a0646Vladimir Marko Label label; 548581550137ee3a068a14224870e71aeee924a0646Vladimir Marko }; 549581550137ee3a068a14224870e71aeee924a0646Vladimir Marko 55092a73aef279be78e3c2b04db1713076183933436Nicolas Geoffray // Labels for each block that will be compiled. 551225b6464a58ebe11c156144653f11a1c6607f4ebVladimir Marko Label* block_labels_; // Indexed by block id. 5521cf95287364948689f6a1a320567acd7728e94a3Nicolas Geoffray Label frame_entry_label_; 5539cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray LocationsBuilderX86_64 location_builder_; 5549cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray InstructionCodeGeneratorX86_64 instruction_visitor_; 555ecb2f9ba57b08ceac4204ddd6a0a88a0524f8741Nicolas Geoffray ParallelMoveResolverX86_64 move_resolver_; 5569cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray X86_64Assembler assembler_; 557fb8d279bc011b31d0765dc7ca59afea324fd0d0cMark Mendell const X86_64InstructionSetFeatures& isa_features_; 5589cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray 55939dcf55a56da746e04f477f89e7b00ba1de03880Mark Mendell // Offset to the start of the constant area in the assembled code. 560f55c3e0825cdfc4c5a27730031177d1a0198ec5aMark Mendell // Used for fixups to the constant area. 561f55c3e0825cdfc4c5a27730031177d1a0198ec5aMark Mendell int constant_area_start_; 562f55c3e0825cdfc4c5a27730031177d1a0198ec5aMark Mendell 563581550137ee3a068a14224870e71aeee924a0646Vladimir Marko // Method patch info. Using ArenaDeque<> which retains element addresses on push/emplace_back(). 564581550137ee3a068a14224870e71aeee924a0646Vladimir Marko ArenaDeque<MethodPatchInfo<Label>> method_patches_; 565581550137ee3a068a14224870e71aeee924a0646Vladimir Marko ArenaDeque<MethodPatchInfo<Label>> relative_call_patches_; 566581550137ee3a068a14224870e71aeee924a0646Vladimir Marko // PC-relative DexCache access info. 5670f7dca4ca0be8d2f8776794d35edf8b51b5bc997Vladimir Marko ArenaDeque<PcRelativeDexCacheAccessInfo> pc_relative_dex_cache_patches_; 568cac5a7e871f1f346b317894359ad06fa7bd67fbaVladimir Marko // Patch locations for patchoat where the linker doesn't do any other work. 569cac5a7e871f1f346b317894359ad06fa7bd67fbaVladimir Marko ArenaDeque<Label> simple_patches_; 570cac5a7e871f1f346b317894359ad06fa7bd67fbaVladimir Marko // String patch locations. 571cac5a7e871f1f346b317894359ad06fa7bd67fbaVladimir Marko ArenaDeque<StringPatchInfo<Label>> string_patches_; 572581550137ee3a068a14224870e71aeee924a0646Vladimir Marko 5739c86b485bc6169eadf846dd5f7cdf0958fe1eb23Mark Mendell // Fixups for jump tables need to be handled specially. 5749c86b485bc6169eadf846dd5f7cdf0958fe1eb23Mark Mendell ArenaVector<JumpTableRIPFixup*> fixups_to_jump_tables_; 5759c86b485bc6169eadf846dd5f7cdf0958fe1eb23Mark Mendell 5769cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray DISALLOW_COPY_AND_ASSIGN(CodeGeneratorX86_64); 5779cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray}; 5789cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray 5799cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray} // namespace x86_64 5809cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray} // namespace art 5819cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray 5829cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray#endif // ART_COMPILER_OPTIMIZING_CODE_GENERATOR_X86_64_H_ 583