code_generator_x86_64.h revision fc6a86ab2b70781e72b807c1798b83829ca7f931
19cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray/* 29cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray * Copyright (C) 2014 The Android Open Source Project 39cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray * 49cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray * Licensed under the Apache License, Version 2.0 (the "License"); 59cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray * you may not use this file except in compliance with the License. 69cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray * You may obtain a copy of the License at 79cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray * 89cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray * http://www.apache.org/licenses/LICENSE-2.0 99cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray * 109cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray * Unless required by applicable law or agreed to in writing, software 119cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray * distributed under the License is distributed on an "AS IS" BASIS, 129cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 139cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray * See the License for the specific language governing permissions and 149cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray * limitations under the License. 159cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray */ 169cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray 179cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray#ifndef ART_COMPILER_OPTIMIZING_CODE_GENERATOR_X86_64_H_ 189cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray#define ART_COMPILER_OPTIMIZING_CODE_GENERATOR_X86_64_H_ 199cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray 209cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray#include "code_generator.h" 2152c489645b6e9ae33623f1ec24143cde5444906eCalin Juravle#include "dex/compiler_enums.h" 22cd6dffedf1bd8e6dfb3fb0c933551f9a90f7de3fCalin Juravle#include "driver/compiler_options.h" 239cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray#include "nodes.h" 24ecb2f9ba57b08ceac4204ddd6a0a88a0524f8741Nicolas Geoffray#include "parallel_move_resolver.h" 259cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray#include "utils/x86_64/assembler_x86_64.h" 269cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray 279cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffraynamespace art { 289cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffraynamespace x86_64 { 299cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray 3086a8d7afc7f00ff0f5ea7b8aaf4d50514250a4e6Nicolas Geoffray// Use a local definition to prevent copying mistakes. 3186a8d7afc7f00ff0f5ea7b8aaf4d50514250a4e6Nicolas Geoffraystatic constexpr size_t kX86_64WordSize = kX86_64PointerSize; 329cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray 339cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffraystatic constexpr Register kParameterCoreRegisters[] = { RSI, RDX, RCX, R8, R9 }; 347fb49da8ec62e8a10ed9419ade9f32c6b1174687Nicolas Geoffraystatic constexpr FloatRegister kParameterFloatRegisters[] = 357fb49da8ec62e8a10ed9419ade9f32c6b1174687Nicolas Geoffray { XMM0, XMM1, XMM2, XMM3, XMM4, XMM5, XMM6, XMM7 }; 369cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray 379cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffraystatic constexpr size_t kParameterCoreRegistersLength = arraysize(kParameterCoreRegisters); 387fb49da8ec62e8a10ed9419ade9f32c6b1174687Nicolas Geoffraystatic constexpr size_t kParameterFloatRegistersLength = arraysize(kParameterFloatRegisters); 399cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray 40848f70a3d73833fc1bf3032a9ff6812e429661d9Jeff Haostatic constexpr Register kRuntimeParameterCoreRegisters[] = { RDI, RSI, RDX, RCX }; 41d75948ac93a4a317feaf136cae78823071234ba5Nicolas Geoffraystatic constexpr size_t kRuntimeParameterCoreRegistersLength = 42d75948ac93a4a317feaf136cae78823071234ba5Nicolas Geoffray arraysize(kRuntimeParameterCoreRegisters); 43d75948ac93a4a317feaf136cae78823071234ba5Nicolas Geoffraystatic constexpr FloatRegister kRuntimeParameterFpuRegisters[] = { XMM0, XMM1 }; 44d75948ac93a4a317feaf136cae78823071234ba5Nicolas Geoffraystatic constexpr size_t kRuntimeParameterFpuRegistersLength = 45d75948ac93a4a317feaf136cae78823071234ba5Nicolas Geoffray arraysize(kRuntimeParameterFpuRegisters); 46d75948ac93a4a317feaf136cae78823071234ba5Nicolas Geoffray 47d75948ac93a4a317feaf136cae78823071234ba5Nicolas Geoffrayclass InvokeRuntimeCallingConvention : public CallingConvention<Register, FloatRegister> { 48d75948ac93a4a317feaf136cae78823071234ba5Nicolas Geoffray public: 49d75948ac93a4a317feaf136cae78823071234ba5Nicolas Geoffray InvokeRuntimeCallingConvention() 50d75948ac93a4a317feaf136cae78823071234ba5Nicolas Geoffray : CallingConvention(kRuntimeParameterCoreRegisters, 51d75948ac93a4a317feaf136cae78823071234ba5Nicolas Geoffray kRuntimeParameterCoreRegistersLength, 52d75948ac93a4a317feaf136cae78823071234ba5Nicolas Geoffray kRuntimeParameterFpuRegisters, 53e401d146407d61eeb99f8d6176b2ac13c4df1e33Mathieu Chartier kRuntimeParameterFpuRegistersLength, 54e401d146407d61eeb99f8d6176b2ac13c4df1e33Mathieu Chartier kX86_64PointerSize) {} 55d75948ac93a4a317feaf136cae78823071234ba5Nicolas Geoffray 56d75948ac93a4a317feaf136cae78823071234ba5Nicolas Geoffray private: 57d75948ac93a4a317feaf136cae78823071234ba5Nicolas Geoffray DISALLOW_COPY_AND_ASSIGN(InvokeRuntimeCallingConvention); 58d75948ac93a4a317feaf136cae78823071234ba5Nicolas Geoffray}; 59d75948ac93a4a317feaf136cae78823071234ba5Nicolas Geoffray 607fb49da8ec62e8a10ed9419ade9f32c6b1174687Nicolas Geoffrayclass InvokeDexCallingConvention : public CallingConvention<Register, FloatRegister> { 619cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray public: 627fb49da8ec62e8a10ed9419ade9f32c6b1174687Nicolas Geoffray InvokeDexCallingConvention() : CallingConvention( 637fb49da8ec62e8a10ed9419ade9f32c6b1174687Nicolas Geoffray kParameterCoreRegisters, 647fb49da8ec62e8a10ed9419ade9f32c6b1174687Nicolas Geoffray kParameterCoreRegistersLength, 657fb49da8ec62e8a10ed9419ade9f32c6b1174687Nicolas Geoffray kParameterFloatRegisters, 66e401d146407d61eeb99f8d6176b2ac13c4df1e33Mathieu Chartier kParameterFloatRegistersLength, 67e401d146407d61eeb99f8d6176b2ac13c4df1e33Mathieu Chartier kX86_64PointerSize) {} 689cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray 699cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray private: 709cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray DISALLOW_COPY_AND_ASSIGN(InvokeDexCallingConvention); 719cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray}; 729cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray 732d27c8e338af7262dbd4aaa66127bb8fa1758b86Roland Levillainclass InvokeDexCallingConventionVisitorX86_64 : public InvokeDexCallingConventionVisitor { 749cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray public: 752d27c8e338af7262dbd4aaa66127bb8fa1758b86Roland Levillain InvokeDexCallingConventionVisitorX86_64() {} 762d27c8e338af7262dbd4aaa66127bb8fa1758b86Roland Levillain virtual ~InvokeDexCallingConventionVisitorX86_64() {} 779cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray 782d27c8e338af7262dbd4aaa66127bb8fa1758b86Roland Levillain Location GetNextLocation(Primitive::Type type) OVERRIDE; 79fd88f16100cceafbfde1b4f095f17e89444d6fa8Nicolas Geoffray Location GetReturnLocation(Primitive::Type type) const OVERRIDE; 80fd88f16100cceafbfde1b4f095f17e89444d6fa8Nicolas Geoffray Location GetMethodLocation() const OVERRIDE; 819cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray 829cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray private: 839cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray InvokeDexCallingConvention calling_convention; 842d27c8e338af7262dbd4aaa66127bb8fa1758b86Roland Levillain 852d27c8e338af7262dbd4aaa66127bb8fa1758b86Roland Levillain DISALLOW_COPY_AND_ASSIGN(InvokeDexCallingConventionVisitorX86_64); 869cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray}; 879cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray 889cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffrayclass CodeGeneratorX86_64; 8971fb52fee246b7d511f520febbd73dc7a9bbca79Andreas Gampe 9071fb52fee246b7d511f520febbd73dc7a9bbca79Andreas Gampeclass SlowPathCodeX86_64 : public SlowPathCode { 9171fb52fee246b7d511f520febbd73dc7a9bbca79Andreas Gampe public: 9271fb52fee246b7d511f520febbd73dc7a9bbca79Andreas Gampe SlowPathCodeX86_64() : entry_label_(), exit_label_() {} 9371fb52fee246b7d511f520febbd73dc7a9bbca79Andreas Gampe 9471fb52fee246b7d511f520febbd73dc7a9bbca79Andreas Gampe Label* GetEntryLabel() { return &entry_label_; } 9571fb52fee246b7d511f520febbd73dc7a9bbca79Andreas Gampe Label* GetExitLabel() { return &exit_label_; } 9671fb52fee246b7d511f520febbd73dc7a9bbca79Andreas Gampe 9771fb52fee246b7d511f520febbd73dc7a9bbca79Andreas Gampe private: 9871fb52fee246b7d511f520febbd73dc7a9bbca79Andreas Gampe Label entry_label_; 9971fb52fee246b7d511f520febbd73dc7a9bbca79Andreas Gampe Label exit_label_; 10071fb52fee246b7d511f520febbd73dc7a9bbca79Andreas Gampe 10171fb52fee246b7d511f520febbd73dc7a9bbca79Andreas Gampe DISALLOW_COPY_AND_ASSIGN(SlowPathCodeX86_64); 10271fb52fee246b7d511f520febbd73dc7a9bbca79Andreas Gampe}; 1039cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray 104ad4450e5c3ffaa9566216cc6fafbf5c11186c467Zheng Xuclass ParallelMoveResolverX86_64 : public ParallelMoveResolverWithSwap { 105ecb2f9ba57b08ceac4204ddd6a0a88a0524f8741Nicolas Geoffray public: 106ecb2f9ba57b08ceac4204ddd6a0a88a0524f8741Nicolas Geoffray ParallelMoveResolverX86_64(ArenaAllocator* allocator, CodeGeneratorX86_64* codegen) 107ad4450e5c3ffaa9566216cc6fafbf5c11186c467Zheng Xu : ParallelMoveResolverWithSwap(allocator), codegen_(codegen) {} 108ecb2f9ba57b08ceac4204ddd6a0a88a0524f8741Nicolas Geoffray 109de58ab2c03ff8112b07ab827c8fa38f670dfc656Nicolas Geoffray void EmitMove(size_t index) OVERRIDE; 110de58ab2c03ff8112b07ab827c8fa38f670dfc656Nicolas Geoffray void EmitSwap(size_t index) OVERRIDE; 111de58ab2c03ff8112b07ab827c8fa38f670dfc656Nicolas Geoffray void SpillScratch(int reg) OVERRIDE; 112de58ab2c03ff8112b07ab827c8fa38f670dfc656Nicolas Geoffray void RestoreScratch(int reg) OVERRIDE; 113ecb2f9ba57b08ceac4204ddd6a0a88a0524f8741Nicolas Geoffray 114ecb2f9ba57b08ceac4204ddd6a0a88a0524f8741Nicolas Geoffray X86_64Assembler* GetAssembler() const; 115ecb2f9ba57b08ceac4204ddd6a0a88a0524f8741Nicolas Geoffray 116ecb2f9ba57b08ceac4204ddd6a0a88a0524f8741Nicolas Geoffray private: 117412f10cfed002ab617c78f2621d68446ca4dd8bdNicolas Geoffray void Exchange32(CpuRegister reg, int mem); 118102cbed1e52b7c5f09458b44903fe97bb3e14d5fNicolas Geoffray void Exchange32(XmmRegister reg, int mem); 119412f10cfed002ab617c78f2621d68446ca4dd8bdNicolas Geoffray void Exchange32(int mem1, int mem2); 120412f10cfed002ab617c78f2621d68446ca4dd8bdNicolas Geoffray void Exchange64(CpuRegister reg, int mem); 121102cbed1e52b7c5f09458b44903fe97bb3e14d5fNicolas Geoffray void Exchange64(XmmRegister reg, int mem); 122412f10cfed002ab617c78f2621d68446ca4dd8bdNicolas Geoffray void Exchange64(int mem1, int mem2); 123ecb2f9ba57b08ceac4204ddd6a0a88a0524f8741Nicolas Geoffray 124ecb2f9ba57b08ceac4204ddd6a0a88a0524f8741Nicolas Geoffray CodeGeneratorX86_64* const codegen_; 125ecb2f9ba57b08ceac4204ddd6a0a88a0524f8741Nicolas Geoffray 126ecb2f9ba57b08ceac4204ddd6a0a88a0524f8741Nicolas Geoffray DISALLOW_COPY_AND_ASSIGN(ParallelMoveResolverX86_64); 127ecb2f9ba57b08ceac4204ddd6a0a88a0524f8741Nicolas Geoffray}; 128ecb2f9ba57b08ceac4204ddd6a0a88a0524f8741Nicolas Geoffray 1299cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffrayclass LocationsBuilderX86_64 : public HGraphVisitor { 1309cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray public: 1319cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray LocationsBuilderX86_64(HGraph* graph, CodeGeneratorX86_64* codegen) 1329cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray : HGraphVisitor(graph), codegen_(codegen) {} 1339cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray 134360231a056e796c36ffe62348507e904dc9efb9bNicolas Geoffray#define DECLARE_VISIT_INSTRUCTION(name, super) \ 135de58ab2c03ff8112b07ab827c8fa38f670dfc656Nicolas Geoffray void Visit##name(H##name* instr) OVERRIDE; 1369cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray 137ef20f71e16f035a39a329c8524d7e59ca6a11f04Alexandre Rames FOR_EACH_CONCRETE_INSTRUCTION_COMMON(DECLARE_VISIT_INSTRUCTION) 138ef20f71e16f035a39a329c8524d7e59ca6a11f04Alexandre Rames FOR_EACH_CONCRETE_INSTRUCTION_X86_64(DECLARE_VISIT_INSTRUCTION) 1399cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray 1409cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray#undef DECLARE_VISIT_INSTRUCTION 1419cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray 142ef20f71e16f035a39a329c8524d7e59ca6a11f04Alexandre Rames void VisitInstruction(HInstruction* instruction) OVERRIDE { 143ef20f71e16f035a39a329c8524d7e59ca6a11f04Alexandre Rames LOG(FATAL) << "Unreachable instruction " << instruction->DebugName() 144ef20f71e16f035a39a329c8524d7e59ca6a11f04Alexandre Rames << " (id " << instruction->GetId() << ")"; 145ef20f71e16f035a39a329c8524d7e59ca6a11f04Alexandre Rames } 146ef20f71e16f035a39a329c8524d7e59ca6a11f04Alexandre Rames 1479574c4b5f5ef039d694ac12c97e25ca02eca83c0Nicolas Geoffray private: 148e982f0b8e809cece6f460fa2d8df25873aa69de4Nicolas Geoffray void HandleInvoke(HInvoke* invoke); 1499574c4b5f5ef039d694ac12c97e25ca02eca83c0Nicolas Geoffray void HandleBitwiseOperation(HBinaryOperation* operation); 1509aec02fc5df5518c16f1e5a9b6cb198a192db973Calin Juravle void HandleShift(HBinaryOperation* operation); 15152c489645b6e9ae33623f1ec24143cde5444906eCalin Juravle void HandleFieldSet(HInstruction* instruction, const FieldInfo& field_info); 15252c489645b6e9ae33623f1ec24143cde5444906eCalin Juravle void HandleFieldGet(HInstruction* instruction); 153e982f0b8e809cece6f460fa2d8df25873aa69de4Nicolas Geoffray 1549cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray CodeGeneratorX86_64* const codegen_; 1552d27c8e338af7262dbd4aaa66127bb8fa1758b86Roland Levillain InvokeDexCallingConventionVisitorX86_64 parameter_visitor_; 1569cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray 1579cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray DISALLOW_COPY_AND_ASSIGN(LocationsBuilderX86_64); 1589cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray}; 1599cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray 1609cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffrayclass InstructionCodeGeneratorX86_64 : public HGraphVisitor { 1619cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray public: 1629cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray InstructionCodeGeneratorX86_64(HGraph* graph, CodeGeneratorX86_64* codegen); 1639cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray 164360231a056e796c36ffe62348507e904dc9efb9bNicolas Geoffray#define DECLARE_VISIT_INSTRUCTION(name, super) \ 165de58ab2c03ff8112b07ab827c8fa38f670dfc656Nicolas Geoffray void Visit##name(H##name* instr) OVERRIDE; 1669cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray 167ef20f71e16f035a39a329c8524d7e59ca6a11f04Alexandre Rames FOR_EACH_CONCRETE_INSTRUCTION_COMMON(DECLARE_VISIT_INSTRUCTION) 168ef20f71e16f035a39a329c8524d7e59ca6a11f04Alexandre Rames FOR_EACH_CONCRETE_INSTRUCTION_X86_64(DECLARE_VISIT_INSTRUCTION) 1699cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray 1709cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray#undef DECLARE_VISIT_INSTRUCTION 1719cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray 172ef20f71e16f035a39a329c8524d7e59ca6a11f04Alexandre Rames void VisitInstruction(HInstruction* instruction) OVERRIDE { 173ef20f71e16f035a39a329c8524d7e59ca6a11f04Alexandre Rames LOG(FATAL) << "Unreachable instruction " << instruction->DebugName() 174ef20f71e16f035a39a329c8524d7e59ca6a11f04Alexandre Rames << " (id " << instruction->GetId() << ")"; 175ef20f71e16f035a39a329c8524d7e59ca6a11f04Alexandre Rames } 176ef20f71e16f035a39a329c8524d7e59ca6a11f04Alexandre Rames 1779cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray X86_64Assembler* GetAssembler() const { return assembler_; } 1789cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray 1799cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray private: 1803c04974a90b0e03f4b509010bff49f0b2a3da57fNicolas Geoffray // Generate code for the given suspend check. If not null, `successor` 1813c04974a90b0e03f4b509010bff49f0b2a3da57fNicolas Geoffray // is the block to branch to if the suspend check is not needed, and after 1823c04974a90b0e03f4b509010bff49f0b2a3da57fNicolas Geoffray // the suspend call. 1833c04974a90b0e03f4b509010bff49f0b2a3da57fNicolas Geoffray void GenerateSuspendCheck(HSuspendCheck* instruction, HBasicBlock* successor); 184424f676379f2f872acd1478672022f19f3240fc1Nicolas Geoffray void GenerateClassInitializationCheck(SlowPathCodeX86_64* slow_path, CpuRegister class_reg); 1859574c4b5f5ef039d694ac12c97e25ca02eca83c0Nicolas Geoffray void HandleBitwiseOperation(HBinaryOperation* operation); 18624f2dfae084b2382c053f5d688fd6bb26cb8a328Mark Mendell void GenerateRemFP(HRem *rem); 1870f88e87085b7cf6544dadff3f555773966a6853eGuillaume Sanchez void DivRemOneOrMinusOne(HBinaryOperation* instruction); 188b19930c5cba3cf662dce5ee057fcc9829b4cbb9cGuillaume Sanchez void DivByPowerOfTwo(HDiv* instruction); 1890f88e87085b7cf6544dadff3f555773966a6853eGuillaume Sanchez void GenerateDivRemWithAnyConstant(HBinaryOperation* instruction); 190bacfec30ee9f2f6fdfd190f11b105b609938efcaCalin Juravle void GenerateDivRemIntegral(HBinaryOperation* instruction); 1919aec02fc5df5518c16f1e5a9b6cb198a192db973Calin Juravle void HandleShift(HBinaryOperation* operation); 19252c489645b6e9ae33623f1ec24143cde5444906eCalin Juravle void GenerateMemoryBarrier(MemBarrierKind kind); 19307276db28d654594e0e86e9e467cad393f752e6eNicolas Geoffray void HandleFieldSet(HInstruction* instruction, 19407276db28d654594e0e86e9e467cad393f752e6eNicolas Geoffray const FieldInfo& field_info, 19507276db28d654594e0e86e9e467cad393f752e6eNicolas Geoffray bool value_can_be_null); 19652c489645b6e9ae33623f1ec24143cde5444906eCalin Juravle void HandleFieldGet(HInstruction* instruction, const FieldInfo& field_info); 197cd6dffedf1bd8e6dfb3fb0c933551f9a90f7de3fCalin Juravle void GenerateImplicitNullCheck(HNullCheck* instruction); 198cd6dffedf1bd8e6dfb3fb0c933551f9a90f7de3fCalin Juravle void GenerateExplicitNullCheck(HNullCheck* instruction); 19924f2dfae084b2382c053f5d688fd6bb26cb8a328Mark Mendell void PushOntoFPStack(Location source, uint32_t temp_offset, 20024f2dfae084b2382c053f5d688fd6bb26cb8a328Mark Mendell uint32_t stack_adjustment, bool is_float); 201d43b3ac88cd46b8815890188c9c2b9a3f1564648Mingyao Yang void GenerateTestAndBranch(HInstruction* instruction, 202d43b3ac88cd46b8815890188c9c2b9a3f1564648Mingyao Yang Label* true_target, 203d43b3ac88cd46b8815890188c9c2b9a3f1564648Mingyao Yang Label* false_target, 204d43b3ac88cd46b8815890188c9c2b9a3f1564648Mingyao Yang Label* always_true_target); 205fc6a86ab2b70781e72b807c1798b83829ca7f931David Brazdil void HandleGoto(HInstruction* got, HBasicBlock* successor); 2063c04974a90b0e03f4b509010bff49f0b2a3da57fNicolas Geoffray 2079cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray X86_64Assembler* const assembler_; 2089cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray CodeGeneratorX86_64* const codegen_; 2099cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray 2109cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray DISALLOW_COPY_AND_ASSIGN(InstructionCodeGeneratorX86_64); 2119cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray}; 2129cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray 2139cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffrayclass CodeGeneratorX86_64 : public CodeGenerator { 2149cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray public: 215fb8d279bc011b31d0765dc7ca59afea324fd0d0cMark Mendell CodeGeneratorX86_64(HGraph* graph, 216fb8d279bc011b31d0765dc7ca59afea324fd0d0cMark Mendell const X86_64InstructionSetFeatures& isa_features, 217fb8d279bc011b31d0765dc7ca59afea324fd0d0cMark Mendell const CompilerOptions& compiler_options); 2189cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray virtual ~CodeGeneratorX86_64() {} 2199cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray 220de58ab2c03ff8112b07ab827c8fa38f670dfc656Nicolas Geoffray void GenerateFrameEntry() OVERRIDE; 221de58ab2c03ff8112b07ab827c8fa38f670dfc656Nicolas Geoffray void GenerateFrameExit() OVERRIDE; 222de58ab2c03ff8112b07ab827c8fa38f670dfc656Nicolas Geoffray void Bind(HBasicBlock* block) OVERRIDE; 223de58ab2c03ff8112b07ab827c8fa38f670dfc656Nicolas Geoffray void Move(HInstruction* instruction, Location location, HInstruction* move_for) OVERRIDE; 224de58ab2c03ff8112b07ab827c8fa38f670dfc656Nicolas Geoffray size_t SaveCoreRegister(size_t stack_index, uint32_t reg_id) OVERRIDE; 225de58ab2c03ff8112b07ab827c8fa38f670dfc656Nicolas Geoffray size_t RestoreCoreRegister(size_t stack_index, uint32_t reg_id) OVERRIDE; 226de58ab2c03ff8112b07ab827c8fa38f670dfc656Nicolas Geoffray size_t SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) OVERRIDE; 227de58ab2c03ff8112b07ab827c8fa38f670dfc656Nicolas Geoffray size_t RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) OVERRIDE; 2289cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray 229de58ab2c03ff8112b07ab827c8fa38f670dfc656Nicolas Geoffray size_t GetWordSize() const OVERRIDE { 2309cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray return kX86_64WordSize; 2319cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray } 2329cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray 233f85a9ca9859ad843dc03d3a2b600afbaf2e9bbddMark Mendell size_t GetFloatingPointSpillSlotSize() const OVERRIDE { 234f85a9ca9859ad843dc03d3a2b600afbaf2e9bbddMark Mendell return kX86_64WordSize; 235f85a9ca9859ad843dc03d3a2b600afbaf2e9bbddMark Mendell } 236f85a9ca9859ad843dc03d3a2b600afbaf2e9bbddMark Mendell 237de58ab2c03ff8112b07ab827c8fa38f670dfc656Nicolas Geoffray HGraphVisitor* GetLocationBuilder() OVERRIDE { 2389cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray return &location_builder_; 2399cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray } 2409cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray 241de58ab2c03ff8112b07ab827c8fa38f670dfc656Nicolas Geoffray HGraphVisitor* GetInstructionVisitor() OVERRIDE { 2429cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray return &instruction_visitor_; 2439cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray } 2449cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray 245de58ab2c03ff8112b07ab827c8fa38f670dfc656Nicolas Geoffray X86_64Assembler* GetAssembler() OVERRIDE { 2469cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray return &assembler_; 2479cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray } 2489cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray 249eb7b7399dbdb5e471b8ae00a567bf4f19edd3907Alexandre Rames const X86_64Assembler& GetAssembler() const OVERRIDE { 250eb7b7399dbdb5e471b8ae00a567bf4f19edd3907Alexandre Rames return assembler_; 251eb7b7399dbdb5e471b8ae00a567bf4f19edd3907Alexandre Rames } 252eb7b7399dbdb5e471b8ae00a567bf4f19edd3907Alexandre Rames 253f0e3937b87453234d0d7970b8712082062709b8dNicolas Geoffray ParallelMoveResolverX86_64* GetMoveResolver() OVERRIDE { 254ecb2f9ba57b08ceac4204ddd6a0a88a0524f8741Nicolas Geoffray return &move_resolver_; 255ecb2f9ba57b08ceac4204ddd6a0a88a0524f8741Nicolas Geoffray } 256ecb2f9ba57b08ceac4204ddd6a0a88a0524f8741Nicolas Geoffray 257de58ab2c03ff8112b07ab827c8fa38f670dfc656Nicolas Geoffray uintptr_t GetAddressOf(HBasicBlock* block) const OVERRIDE { 258de58ab2c03ff8112b07ab827c8fa38f670dfc656Nicolas Geoffray return GetLabelOf(block)->Position(); 259de58ab2c03ff8112b07ab827c8fa38f670dfc656Nicolas Geoffray } 260de58ab2c03ff8112b07ab827c8fa38f670dfc656Nicolas Geoffray 261de58ab2c03ff8112b07ab827c8fa38f670dfc656Nicolas Geoffray Location GetStackLocation(HLoadLocal* load) const OVERRIDE; 2629cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray 263988939683c26c0b1c8808fc206add6337319509aNicolas Geoffray void SetupBlockedRegisters(bool is_baseline) const OVERRIDE; 264de58ab2c03ff8112b07ab827c8fa38f670dfc656Nicolas Geoffray Location AllocateFreeRegister(Primitive::Type type) const OVERRIDE; 265de58ab2c03ff8112b07ab827c8fa38f670dfc656Nicolas Geoffray void DumpCoreRegister(std::ostream& stream, int reg) const OVERRIDE; 266de58ab2c03ff8112b07ab827c8fa38f670dfc656Nicolas Geoffray void DumpFloatingPointRegister(std::ostream& stream, int reg) const OVERRIDE; 267f55c3e0825cdfc4c5a27730031177d1a0198ec5aMark Mendell void Finalize(CodeAllocator* allocator) OVERRIDE; 2689cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray 269de58ab2c03ff8112b07ab827c8fa38f670dfc656Nicolas Geoffray InstructionSet GetInstructionSet() const OVERRIDE { 270412f10cfed002ab617c78f2621d68446ca4dd8bdNicolas Geoffray return InstructionSet::kX86_64; 271412f10cfed002ab617c78f2621d68446ca4dd8bdNicolas Geoffray } 272412f10cfed002ab617c78f2621d68446ca4dd8bdNicolas Geoffray 2733c7bb98698f77af10372cf31824d3bb115d9bf0fNicolas Geoffray // Emit a write barrier. 27407276db28d654594e0e86e9e467cad393f752e6eNicolas Geoffray void MarkGCCard(CpuRegister temp, 27507276db28d654594e0e86e9e467cad393f752e6eNicolas Geoffray CpuRegister card, 27607276db28d654594e0e86e9e467cad393f752e6eNicolas Geoffray CpuRegister object, 27707276db28d654594e0e86e9e467cad393f752e6eNicolas Geoffray CpuRegister value, 27807276db28d654594e0e86e9e467cad393f752e6eNicolas Geoffray bool value_can_be_null); 2793c7bb98698f77af10372cf31824d3bb115d9bf0fNicolas Geoffray 2809cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray // Helper method to move a value between two locations. 2819cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray void Move(Location destination, Location source); 2829cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray 28392a73aef279be78e3c2b04db1713076183933436Nicolas Geoffray Label* GetLabelOf(HBasicBlock* block) const { 284dc23d8318db08cb42e20f1d16dbc416798951a8bNicolas Geoffray return CommonGetLabelOf<Label>(block_labels_.GetRawStorage(), block); 28592a73aef279be78e3c2b04db1713076183933436Nicolas Geoffray } 28692a73aef279be78e3c2b04db1713076183933436Nicolas Geoffray 287de58ab2c03ff8112b07ab827c8fa38f670dfc656Nicolas Geoffray void Initialize() OVERRIDE { 28892a73aef279be78e3c2b04db1713076183933436Nicolas Geoffray block_labels_.SetSize(GetGraph()->GetBlocks().Size()); 28992a73aef279be78e3c2b04db1713076183933436Nicolas Geoffray } 29092a73aef279be78e3c2b04db1713076183933436Nicolas Geoffray 291840e5461a85f8908f51e7f6cd562a9129ff0e7ceNicolas Geoffray bool NeedsTwoRegisters(Primitive::Type type ATTRIBUTE_UNUSED) const OVERRIDE { 292840e5461a85f8908f51e7f6cd562a9129ff0e7ceNicolas Geoffray return false; 293840e5461a85f8908f51e7f6cd562a9129ff0e7ceNicolas Geoffray } 294840e5461a85f8908f51e7f6cd562a9129ff0e7ceNicolas Geoffray 29538207af82afb6f99c687f64b15601ed20d82220aNicolas Geoffray void GenerateStaticOrDirectCall(HInvokeStaticOrDirect* invoke, Location temp); 29671fb52fee246b7d511f520febbd73dc7a9bbca79Andreas Gampe 297fb8d279bc011b31d0765dc7ca59afea324fd0d0cMark Mendell const X86_64InstructionSetFeatures& GetInstructionSetFeatures() const { 298fb8d279bc011b31d0765dc7ca59afea324fd0d0cMark Mendell return isa_features_; 299fb8d279bc011b31d0765dc7ca59afea324fd0d0cMark Mendell } 300fb8d279bc011b31d0765dc7ca59afea324fd0d0cMark Mendell 301f55c3e0825cdfc4c5a27730031177d1a0198ec5aMark Mendell int ConstantAreaStart() const { 302f55c3e0825cdfc4c5a27730031177d1a0198ec5aMark Mendell return constant_area_start_; 303f55c3e0825cdfc4c5a27730031177d1a0198ec5aMark Mendell } 304f55c3e0825cdfc4c5a27730031177d1a0198ec5aMark Mendell 305f55c3e0825cdfc4c5a27730031177d1a0198ec5aMark Mendell Address LiteralDoubleAddress(double v); 306f55c3e0825cdfc4c5a27730031177d1a0198ec5aMark Mendell Address LiteralFloatAddress(float v); 307f55c3e0825cdfc4c5a27730031177d1a0198ec5aMark Mendell Address LiteralInt32Address(int32_t v); 308f55c3e0825cdfc4c5a27730031177d1a0198ec5aMark Mendell Address LiteralInt64Address(int64_t v); 309f55c3e0825cdfc4c5a27730031177d1a0198ec5aMark Mendell 31092e83bf8c0b2df8c977ffbc527989631d94b1819Mark Mendell // Load a 64 bit value into a register in the most efficient manner. 31192e83bf8c0b2df8c977ffbc527989631d94b1819Mark Mendell void Load64BitValue(CpuRegister dest, int64_t value); 31292e83bf8c0b2df8c977ffbc527989631d94b1819Mark Mendell 3133c7bb98698f77af10372cf31824d3bb115d9bf0fNicolas Geoffray private: 31492a73aef279be78e3c2b04db1713076183933436Nicolas Geoffray // Labels for each block that will be compiled. 31592a73aef279be78e3c2b04db1713076183933436Nicolas Geoffray GrowableArray<Label> block_labels_; 3161cf95287364948689f6a1a320567acd7728e94a3Nicolas Geoffray Label frame_entry_label_; 3179cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray LocationsBuilderX86_64 location_builder_; 3189cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray InstructionCodeGeneratorX86_64 instruction_visitor_; 319ecb2f9ba57b08ceac4204ddd6a0a88a0524f8741Nicolas Geoffray ParallelMoveResolverX86_64 move_resolver_; 3209cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray X86_64Assembler assembler_; 321fb8d279bc011b31d0765dc7ca59afea324fd0d0cMark Mendell const X86_64InstructionSetFeatures& isa_features_; 3229cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray 32339dcf55a56da746e04f477f89e7b00ba1de03880Mark Mendell // Offset to the start of the constant area in the assembled code. 324f55c3e0825cdfc4c5a27730031177d1a0198ec5aMark Mendell // Used for fixups to the constant area. 325f55c3e0825cdfc4c5a27730031177d1a0198ec5aMark Mendell int constant_area_start_; 326f55c3e0825cdfc4c5a27730031177d1a0198ec5aMark Mendell 3279cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray DISALLOW_COPY_AND_ASSIGN(CodeGeneratorX86_64); 3289cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray}; 3299cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray 3309cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray} // namespace x86_64 3319cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray} // namespace art 3329cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray 3339cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray#endif // ART_COMPILER_OPTIMIZING_CODE_GENERATOR_X86_64_H_ 334