code_generator_x86.h revision 0f88e87085b7cf6544dadff3f555773966a6853e
1d4dd255db1d110ceb5551f6d95ff31fb57420994Nicolas Geoffray/* 2d4dd255db1d110ceb5551f6d95ff31fb57420994Nicolas Geoffray * Copyright (C) 2014 The Android Open Source Project 3d4dd255db1d110ceb5551f6d95ff31fb57420994Nicolas Geoffray * 4d4dd255db1d110ceb5551f6d95ff31fb57420994Nicolas Geoffray * Licensed under the Apache License, Version 2.0 (the "License"); 5d4dd255db1d110ceb5551f6d95ff31fb57420994Nicolas Geoffray * you may not use this file except in compliance with the License. 6d4dd255db1d110ceb5551f6d95ff31fb57420994Nicolas Geoffray * You may obtain a copy of the License at 7d4dd255db1d110ceb5551f6d95ff31fb57420994Nicolas Geoffray * 8d4dd255db1d110ceb5551f6d95ff31fb57420994Nicolas Geoffray * http://www.apache.org/licenses/LICENSE-2.0 9d4dd255db1d110ceb5551f6d95ff31fb57420994Nicolas Geoffray * 10d4dd255db1d110ceb5551f6d95ff31fb57420994Nicolas Geoffray * Unless required by applicable law or agreed to in writing, software 11d4dd255db1d110ceb5551f6d95ff31fb57420994Nicolas Geoffray * distributed under the License is distributed on an "AS IS" BASIS, 12d4dd255db1d110ceb5551f6d95ff31fb57420994Nicolas Geoffray * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13d4dd255db1d110ceb5551f6d95ff31fb57420994Nicolas Geoffray * See the License for the specific language governing permissions and 14d4dd255db1d110ceb5551f6d95ff31fb57420994Nicolas Geoffray * limitations under the License. 15d4dd255db1d110ceb5551f6d95ff31fb57420994Nicolas Geoffray */ 16d4dd255db1d110ceb5551f6d95ff31fb57420994Nicolas Geoffray 17d4dd255db1d110ceb5551f6d95ff31fb57420994Nicolas Geoffray#ifndef ART_COMPILER_OPTIMIZING_CODE_GENERATOR_X86_H_ 18d4dd255db1d110ceb5551f6d95ff31fb57420994Nicolas Geoffray#define ART_COMPILER_OPTIMIZING_CODE_GENERATOR_X86_H_ 19d4dd255db1d110ceb5551f6d95ff31fb57420994Nicolas Geoffray 20d4dd255db1d110ceb5551f6d95ff31fb57420994Nicolas Geoffray#include "code_generator.h" 2152c489645b6e9ae33623f1ec24143cde5444906eCalin Juravle#include "dex/compiler_enums.h" 22cd6dffedf1bd8e6dfb3fb0c933551f9a90f7de3fCalin Juravle#include "driver/compiler_options.h" 23d4dd255db1d110ceb5551f6d95ff31fb57420994Nicolas Geoffray#include "nodes.h" 2486dbb9a12119273039ce272b41c809fa548b37b6Nicolas Geoffray#include "parallel_move_resolver.h" 25787c3076635cf117eb646c5a89a9014b2072fb44Nicolas Geoffray#include "utils/x86/assembler_x86.h" 26d4dd255db1d110ceb5551f6d95ff31fb57420994Nicolas Geoffray 27d4dd255db1d110ceb5551f6d95ff31fb57420994Nicolas Geoffraynamespace art { 28d4dd255db1d110ceb5551f6d95ff31fb57420994Nicolas Geoffraynamespace x86 { 29d4dd255db1d110ceb5551f6d95ff31fb57420994Nicolas Geoffray 3086a8d7afc7f00ff0f5ea7b8aaf4d50514250a4e6Nicolas Geoffray// Use a local definition to prevent copying mistakes. 3186a8d7afc7f00ff0f5ea7b8aaf4d50514250a4e6Nicolas Geoffraystatic constexpr size_t kX86WordSize = kX86PointerSize; 32707c809f661554713edfacf338365adca8dfd3a3Nicolas Geoffray 3301bc96d007b67fdb7fe349232a83e4b354ce3d08Nicolas Geoffrayclass CodeGeneratorX86; 34424f676379f2f872acd1478672022f19f3240fc1Nicolas Geoffrayclass SlowPathCodeX86; 3501bc96d007b67fdb7fe349232a83e4b354ce3d08Nicolas Geoffray 36a747a392fb5f88d2ecc4c6021edf9f1f6615ba16Nicolas Geoffraystatic constexpr Register kParameterCoreRegisters[] = { ECX, EDX, EBX }; 37a747a392fb5f88d2ecc4c6021edf9f1f6615ba16Nicolas Geoffraystatic constexpr RegisterPair kParameterCorePairRegisters[] = { ECX_EDX, EDX_EBX }; 38a747a392fb5f88d2ecc4c6021edf9f1f6615ba16Nicolas Geoffraystatic constexpr size_t kParameterCoreRegistersLength = arraysize(kParameterCoreRegisters); 39966c3ae95d3c699ee9fbdbccc1acdaaf02325fafMark P Mendellstatic constexpr XmmRegister kParameterFpuRegisters[] = { XMM0, XMM1, XMM2, XMM3 }; 40966c3ae95d3c699ee9fbdbccc1acdaaf02325fafMark P Mendellstatic constexpr size_t kParameterFpuRegistersLength = arraysize(kParameterFpuRegisters); 41a747a392fb5f88d2ecc4c6021edf9f1f6615ba16Nicolas Geoffray 42d75948ac93a4a317feaf136cae78823071234ba5Nicolas Geoffraystatic constexpr Register kRuntimeParameterCoreRegisters[] = { EAX, ECX, EDX, EBX }; 43d75948ac93a4a317feaf136cae78823071234ba5Nicolas Geoffraystatic constexpr size_t kRuntimeParameterCoreRegistersLength = 44d75948ac93a4a317feaf136cae78823071234ba5Nicolas Geoffray arraysize(kRuntimeParameterCoreRegisters); 45d75948ac93a4a317feaf136cae78823071234ba5Nicolas Geoffraystatic constexpr XmmRegister kRuntimeParameterFpuRegisters[] = { XMM0, XMM1, XMM2, XMM3 }; 46d75948ac93a4a317feaf136cae78823071234ba5Nicolas Geoffraystatic constexpr size_t kRuntimeParameterFpuRegistersLength = 47d75948ac93a4a317feaf136cae78823071234ba5Nicolas Geoffray arraysize(kRuntimeParameterFpuRegisters); 48d75948ac93a4a317feaf136cae78823071234ba5Nicolas Geoffray 49d75948ac93a4a317feaf136cae78823071234ba5Nicolas Geoffrayclass InvokeRuntimeCallingConvention : public CallingConvention<Register, XmmRegister> { 50d75948ac93a4a317feaf136cae78823071234ba5Nicolas Geoffray public: 51d75948ac93a4a317feaf136cae78823071234ba5Nicolas Geoffray InvokeRuntimeCallingConvention() 52d75948ac93a4a317feaf136cae78823071234ba5Nicolas Geoffray : CallingConvention(kRuntimeParameterCoreRegisters, 53d75948ac93a4a317feaf136cae78823071234ba5Nicolas Geoffray kRuntimeParameterCoreRegistersLength, 54d75948ac93a4a317feaf136cae78823071234ba5Nicolas Geoffray kRuntimeParameterFpuRegisters, 55d75948ac93a4a317feaf136cae78823071234ba5Nicolas Geoffray kRuntimeParameterFpuRegistersLength) {} 56d75948ac93a4a317feaf136cae78823071234ba5Nicolas Geoffray 57d75948ac93a4a317feaf136cae78823071234ba5Nicolas Geoffray private: 58d75948ac93a4a317feaf136cae78823071234ba5Nicolas Geoffray DISALLOW_COPY_AND_ASSIGN(InvokeRuntimeCallingConvention); 59d75948ac93a4a317feaf136cae78823071234ba5Nicolas Geoffray}; 60d75948ac93a4a317feaf136cae78823071234ba5Nicolas Geoffray 617fb49da8ec62e8a10ed9419ade9f32c6b1174687Nicolas Geoffrayclass InvokeDexCallingConvention : public CallingConvention<Register, XmmRegister> { 62a747a392fb5f88d2ecc4c6021edf9f1f6615ba16Nicolas Geoffray public: 637fb49da8ec62e8a10ed9419ade9f32c6b1174687Nicolas Geoffray InvokeDexCallingConvention() : CallingConvention( 647fb49da8ec62e8a10ed9419ade9f32c6b1174687Nicolas Geoffray kParameterCoreRegisters, 657fb49da8ec62e8a10ed9419ade9f32c6b1174687Nicolas Geoffray kParameterCoreRegistersLength, 667fb49da8ec62e8a10ed9419ade9f32c6b1174687Nicolas Geoffray kParameterFpuRegisters, 677fb49da8ec62e8a10ed9419ade9f32c6b1174687Nicolas Geoffray kParameterFpuRegistersLength) {} 68a747a392fb5f88d2ecc4c6021edf9f1f6615ba16Nicolas Geoffray 69a747a392fb5f88d2ecc4c6021edf9f1f6615ba16Nicolas Geoffray RegisterPair GetRegisterPairAt(size_t argument_index) { 70a747a392fb5f88d2ecc4c6021edf9f1f6615ba16Nicolas Geoffray DCHECK_LT(argument_index + 1, GetNumberOfRegisters()); 71a747a392fb5f88d2ecc4c6021edf9f1f6615ba16Nicolas Geoffray return kParameterCorePairRegisters[argument_index]; 72a747a392fb5f88d2ecc4c6021edf9f1f6615ba16Nicolas Geoffray } 73a747a392fb5f88d2ecc4c6021edf9f1f6615ba16Nicolas Geoffray 74a747a392fb5f88d2ecc4c6021edf9f1f6615ba16Nicolas Geoffray private: 75a747a392fb5f88d2ecc4c6021edf9f1f6615ba16Nicolas Geoffray DISALLOW_COPY_AND_ASSIGN(InvokeDexCallingConvention); 76a747a392fb5f88d2ecc4c6021edf9f1f6615ba16Nicolas Geoffray}; 77a747a392fb5f88d2ecc4c6021edf9f1f6615ba16Nicolas Geoffray 78a747a392fb5f88d2ecc4c6021edf9f1f6615ba16Nicolas Geoffrayclass InvokeDexCallingConventionVisitor { 79a747a392fb5f88d2ecc4c6021edf9f1f6615ba16Nicolas Geoffray public: 80966c3ae95d3c699ee9fbdbccc1acdaaf02325fafMark P Mendell InvokeDexCallingConventionVisitor() : gp_index_(0), fp_index_(0), stack_index_(0) {} 81a747a392fb5f88d2ecc4c6021edf9f1f6615ba16Nicolas Geoffray 82a747a392fb5f88d2ecc4c6021edf9f1f6615ba16Nicolas Geoffray Location GetNextLocation(Primitive::Type type); 83a747a392fb5f88d2ecc4c6021edf9f1f6615ba16Nicolas Geoffray 84a747a392fb5f88d2ecc4c6021edf9f1f6615ba16Nicolas Geoffray private: 85a747a392fb5f88d2ecc4c6021edf9f1f6615ba16Nicolas Geoffray InvokeDexCallingConvention calling_convention; 86966c3ae95d3c699ee9fbdbccc1acdaaf02325fafMark P Mendell // The current index for cpu registers. 87a747a392fb5f88d2ecc4c6021edf9f1f6615ba16Nicolas Geoffray uint32_t gp_index_; 88966c3ae95d3c699ee9fbdbccc1acdaaf02325fafMark P Mendell // The current index for fpu registers. 89966c3ae95d3c699ee9fbdbccc1acdaaf02325fafMark P Mendell uint32_t fp_index_; 90966c3ae95d3c699ee9fbdbccc1acdaaf02325fafMark P Mendell // The current stack index. 91966c3ae95d3c699ee9fbdbccc1acdaaf02325fafMark P Mendell uint32_t stack_index_; 92a747a392fb5f88d2ecc4c6021edf9f1f6615ba16Nicolas Geoffray 93a747a392fb5f88d2ecc4c6021edf9f1f6615ba16Nicolas Geoffray DISALLOW_COPY_AND_ASSIGN(InvokeDexCallingConventionVisitor); 94a747a392fb5f88d2ecc4c6021edf9f1f6615ba16Nicolas Geoffray}; 95a747a392fb5f88d2ecc4c6021edf9f1f6615ba16Nicolas Geoffray 9686dbb9a12119273039ce272b41c809fa548b37b6Nicolas Geoffrayclass ParallelMoveResolverX86 : public ParallelMoveResolver { 9786dbb9a12119273039ce272b41c809fa548b37b6Nicolas Geoffray public: 9886dbb9a12119273039ce272b41c809fa548b37b6Nicolas Geoffray ParallelMoveResolverX86(ArenaAllocator* allocator, CodeGeneratorX86* codegen) 9986dbb9a12119273039ce272b41c809fa548b37b6Nicolas Geoffray : ParallelMoveResolver(allocator), codegen_(codegen) {} 10086dbb9a12119273039ce272b41c809fa548b37b6Nicolas Geoffray 101de58ab2c03ff8112b07ab827c8fa38f670dfc656Nicolas Geoffray void EmitMove(size_t index) OVERRIDE; 102de58ab2c03ff8112b07ab827c8fa38f670dfc656Nicolas Geoffray void EmitSwap(size_t index) OVERRIDE; 103de58ab2c03ff8112b07ab827c8fa38f670dfc656Nicolas Geoffray void SpillScratch(int reg) OVERRIDE; 104de58ab2c03ff8112b07ab827c8fa38f670dfc656Nicolas Geoffray void RestoreScratch(int reg) OVERRIDE; 10586dbb9a12119273039ce272b41c809fa548b37b6Nicolas Geoffray 10686dbb9a12119273039ce272b41c809fa548b37b6Nicolas Geoffray X86Assembler* GetAssembler() const; 10786dbb9a12119273039ce272b41c809fa548b37b6Nicolas Geoffray 10886dbb9a12119273039ce272b41c809fa548b37b6Nicolas Geoffray private: 10986dbb9a12119273039ce272b41c809fa548b37b6Nicolas Geoffray void Exchange(Register reg, int mem); 11086dbb9a12119273039ce272b41c809fa548b37b6Nicolas Geoffray void Exchange(int mem1, int mem2); 1117c8d009552545e6f1fd6036721e4e42e3fd14697Mark Mendell void Exchange32(XmmRegister reg, int mem); 1127c8d009552545e6f1fd6036721e4e42e3fd14697Mark Mendell void MoveMemoryToMemory32(int dst, int src); 1137c8d009552545e6f1fd6036721e4e42e3fd14697Mark Mendell void MoveMemoryToMemory64(int dst, int src); 11486dbb9a12119273039ce272b41c809fa548b37b6Nicolas Geoffray 11586dbb9a12119273039ce272b41c809fa548b37b6Nicolas Geoffray CodeGeneratorX86* const codegen_; 11686dbb9a12119273039ce272b41c809fa548b37b6Nicolas Geoffray 11786dbb9a12119273039ce272b41c809fa548b37b6Nicolas Geoffray DISALLOW_COPY_AND_ASSIGN(ParallelMoveResolverX86); 11886dbb9a12119273039ce272b41c809fa548b37b6Nicolas Geoffray}; 11986dbb9a12119273039ce272b41c809fa548b37b6Nicolas Geoffray 120bab4ed7057799a4fadc6283108ab56f389d117d4Nicolas Geoffrayclass LocationsBuilderX86 : public HGraphVisitor { 121bab4ed7057799a4fadc6283108ab56f389d117d4Nicolas Geoffray public: 12201bc96d007b67fdb7fe349232a83e4b354ce3d08Nicolas Geoffray LocationsBuilderX86(HGraph* graph, CodeGeneratorX86* codegen) 12301bc96d007b67fdb7fe349232a83e4b354ce3d08Nicolas Geoffray : HGraphVisitor(graph), codegen_(codegen) {} 124bab4ed7057799a4fadc6283108ab56f389d117d4Nicolas Geoffray 125360231a056e796c36ffe62348507e904dc9efb9bNicolas Geoffray#define DECLARE_VISIT_INSTRUCTION(name, super) \ 126de58ab2c03ff8112b07ab827c8fa38f670dfc656Nicolas Geoffray void Visit##name(H##name* instr) OVERRIDE; 127bab4ed7057799a4fadc6283108ab56f389d117d4Nicolas Geoffray 12896f89a290eb67d7bf4b1636798fa28df14309cc7Nicolas Geoffray FOR_EACH_CONCRETE_INSTRUCTION(DECLARE_VISIT_INSTRUCTION) 129bab4ed7057799a4fadc6283108ab56f389d117d4Nicolas Geoffray 130bab4ed7057799a4fadc6283108ab56f389d117d4Nicolas Geoffray#undef DECLARE_VISIT_INSTRUCTION 131bab4ed7057799a4fadc6283108ab56f389d117d4Nicolas Geoffray 1329574c4b5f5ef039d694ac12c97e25ca02eca83c0Nicolas Geoffray private: 1339574c4b5f5ef039d694ac12c97e25ca02eca83c0Nicolas Geoffray void HandleBitwiseOperation(HBinaryOperation* instruction); 134e982f0b8e809cece6f460fa2d8df25873aa69de4Nicolas Geoffray void HandleInvoke(HInvoke* invoke); 1359aec02fc5df5518c16f1e5a9b6cb198a192db973Calin Juravle void HandleShift(HBinaryOperation* instruction); 13652c489645b6e9ae33623f1ec24143cde5444906eCalin Juravle void HandleFieldSet(HInstruction* instruction, const FieldInfo& field_info); 13752c489645b6e9ae33623f1ec24143cde5444906eCalin Juravle void HandleFieldGet(HInstruction* instruction, const FieldInfo& field_info); 138e982f0b8e809cece6f460fa2d8df25873aa69de4Nicolas Geoffray 13901bc96d007b67fdb7fe349232a83e4b354ce3d08Nicolas Geoffray CodeGeneratorX86* const codegen_; 140a747a392fb5f88d2ecc4c6021edf9f1f6615ba16Nicolas Geoffray InvokeDexCallingConventionVisitor parameter_visitor_; 14101bc96d007b67fdb7fe349232a83e4b354ce3d08Nicolas Geoffray 142bab4ed7057799a4fadc6283108ab56f389d117d4Nicolas Geoffray DISALLOW_COPY_AND_ASSIGN(LocationsBuilderX86); 143bab4ed7057799a4fadc6283108ab56f389d117d4Nicolas Geoffray}; 144bab4ed7057799a4fadc6283108ab56f389d117d4Nicolas Geoffray 145787c3076635cf117eb646c5a89a9014b2072fb44Nicolas Geoffrayclass InstructionCodeGeneratorX86 : public HGraphVisitor { 146d4dd255db1d110ceb5551f6d95ff31fb57420994Nicolas Geoffray public: 1474a34a428c6a2588e0857ef6baf88f1b73ce65958Nicolas Geoffray InstructionCodeGeneratorX86(HGraph* graph, CodeGeneratorX86* codegen); 148d4dd255db1d110ceb5551f6d95ff31fb57420994Nicolas Geoffray 149360231a056e796c36ffe62348507e904dc9efb9bNicolas Geoffray#define DECLARE_VISIT_INSTRUCTION(name, super) \ 150de58ab2c03ff8112b07ab827c8fa38f670dfc656Nicolas Geoffray void Visit##name(H##name* instr) OVERRIDE; 151d4dd255db1d110ceb5551f6d95ff31fb57420994Nicolas Geoffray 15296f89a290eb67d7bf4b1636798fa28df14309cc7Nicolas Geoffray FOR_EACH_CONCRETE_INSTRUCTION(DECLARE_VISIT_INSTRUCTION) 153d4dd255db1d110ceb5551f6d95ff31fb57420994Nicolas Geoffray 154d4dd255db1d110ceb5551f6d95ff31fb57420994Nicolas Geoffray#undef DECLARE_VISIT_INSTRUCTION 155d4dd255db1d110ceb5551f6d95ff31fb57420994Nicolas Geoffray 1564a34a428c6a2588e0857ef6baf88f1b73ce65958Nicolas Geoffray X86Assembler* GetAssembler() const { return assembler_; } 157787c3076635cf117eb646c5a89a9014b2072fb44Nicolas Geoffray 158787c3076635cf117eb646c5a89a9014b2072fb44Nicolas Geoffray private: 1593c04974a90b0e03f4b509010bff49f0b2a3da57fNicolas Geoffray // Generate code for the given suspend check. If not null, `successor` 1603c04974a90b0e03f4b509010bff49f0b2a3da57fNicolas Geoffray // is the block to branch to if the suspend check is not needed, and after 1613c04974a90b0e03f4b509010bff49f0b2a3da57fNicolas Geoffray // the suspend call. 1623c04974a90b0e03f4b509010bff49f0b2a3da57fNicolas Geoffray void GenerateSuspendCheck(HSuspendCheck* check, HBasicBlock* successor); 163424f676379f2f872acd1478672022f19f3240fc1Nicolas Geoffray void GenerateClassInitializationCheck(SlowPathCodeX86* slow_path, Register class_reg); 1649574c4b5f5ef039d694ac12c97e25ca02eca83c0Nicolas Geoffray void HandleBitwiseOperation(HBinaryOperation* instruction); 165bacfec30ee9f2f6fdfd190f11b105b609938efcaCalin Juravle void GenerateDivRemIntegral(HBinaryOperation* instruction); 1660f88e87085b7cf6544dadff3f555773966a6853eGuillaume Sanchez void DivRemOneOrMinusOne(HBinaryOperation* instruction); 1670f88e87085b7cf6544dadff3f555773966a6853eGuillaume Sanchez void DivByPowerOfTwo(HBinaryOperation* instruction); 1680f88e87085b7cf6544dadff3f555773966a6853eGuillaume Sanchez void GenerateDivRemWithAnyConstant(HBinaryOperation* instruction); 16924f2dfae084b2382c053f5d688fd6bb26cb8a328Mark Mendell void GenerateRemFP(HRem *rem); 1709aec02fc5df5518c16f1e5a9b6cb198a192db973Calin Juravle void HandleShift(HBinaryOperation* instruction); 1719aec02fc5df5518c16f1e5a9b6cb198a192db973Calin Juravle void GenerateShlLong(const Location& loc, Register shifter); 1729aec02fc5df5518c16f1e5a9b6cb198a192db973Calin Juravle void GenerateShrLong(const Location& loc, Register shifter); 1739aec02fc5df5518c16f1e5a9b6cb198a192db973Calin Juravle void GenerateUShrLong(const Location& loc, Register shifter); 17452c489645b6e9ae33623f1ec24143cde5444906eCalin Juravle void GenerateMemoryBarrier(MemBarrierKind kind); 17552c489645b6e9ae33623f1ec24143cde5444906eCalin Juravle void HandleFieldSet(HInstruction* instruction, const FieldInfo& field_info); 17652c489645b6e9ae33623f1ec24143cde5444906eCalin Juravle void HandleFieldGet(HInstruction* instruction, const FieldInfo& field_info); 17724f2dfae084b2382c053f5d688fd6bb26cb8a328Mark Mendell void PushOntoFPStack(Location source, uint32_t temp_offset, 17824f2dfae084b2382c053f5d688fd6bb26cb8a328Mark Mendell uint32_t stack_adjustment, bool is_float); 1793c04974a90b0e03f4b509010bff49f0b2a3da57fNicolas Geoffray 180cd6dffedf1bd8e6dfb3fb0c933551f9a90f7de3fCalin Juravle void GenerateImplicitNullCheck(HNullCheck* instruction); 181cd6dffedf1bd8e6dfb3fb0c933551f9a90f7de3fCalin Juravle void GenerateExplicitNullCheck(HNullCheck* instruction); 182cd6dffedf1bd8e6dfb3fb0c933551f9a90f7de3fCalin Juravle 1834a34a428c6a2588e0857ef6baf88f1b73ce65958Nicolas Geoffray X86Assembler* const assembler_; 1844a34a428c6a2588e0857ef6baf88f1b73ce65958Nicolas Geoffray CodeGeneratorX86* const codegen_; 185787c3076635cf117eb646c5a89a9014b2072fb44Nicolas Geoffray 186787c3076635cf117eb646c5a89a9014b2072fb44Nicolas Geoffray DISALLOW_COPY_AND_ASSIGN(InstructionCodeGeneratorX86); 187787c3076635cf117eb646c5a89a9014b2072fb44Nicolas Geoffray}; 188787c3076635cf117eb646c5a89a9014b2072fb44Nicolas Geoffray 189787c3076635cf117eb646c5a89a9014b2072fb44Nicolas Geoffrayclass CodeGeneratorX86 : public CodeGenerator { 190787c3076635cf117eb646c5a89a9014b2072fb44Nicolas Geoffray public: 191cd6dffedf1bd8e6dfb3fb0c933551f9a90f7de3fCalin Juravle CodeGeneratorX86(HGraph* graph, const CompilerOptions& compiler_options); 192f12feb8e0e857f2832545b3f28d31bad5a9d3903Nicolas Geoffray virtual ~CodeGeneratorX86() {} 193787c3076635cf117eb646c5a89a9014b2072fb44Nicolas Geoffray 194de58ab2c03ff8112b07ab827c8fa38f670dfc656Nicolas Geoffray void GenerateFrameEntry() OVERRIDE; 195de58ab2c03ff8112b07ab827c8fa38f670dfc656Nicolas Geoffray void GenerateFrameExit() OVERRIDE; 196de58ab2c03ff8112b07ab827c8fa38f670dfc656Nicolas Geoffray void Bind(HBasicBlock* block) OVERRIDE; 197de58ab2c03ff8112b07ab827c8fa38f670dfc656Nicolas Geoffray void Move(HInstruction* instruction, Location location, HInstruction* move_for) OVERRIDE; 198de58ab2c03ff8112b07ab827c8fa38f670dfc656Nicolas Geoffray size_t SaveCoreRegister(size_t stack_index, uint32_t reg_id) OVERRIDE; 199de58ab2c03ff8112b07ab827c8fa38f670dfc656Nicolas Geoffray size_t RestoreCoreRegister(size_t stack_index, uint32_t reg_id) OVERRIDE; 2007c8d009552545e6f1fd6036721e4e42e3fd14697Mark Mendell size_t SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) OVERRIDE; 2017c8d009552545e6f1fd6036721e4e42e3fd14697Mark Mendell size_t RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) OVERRIDE; 202bab4ed7057799a4fadc6283108ab56f389d117d4Nicolas Geoffray 203de58ab2c03ff8112b07ab827c8fa38f670dfc656Nicolas Geoffray size_t GetWordSize() const OVERRIDE { 204707c809f661554713edfacf338365adca8dfd3a3Nicolas Geoffray return kX86WordSize; 205707c809f661554713edfacf338365adca8dfd3a3Nicolas Geoffray } 206707c809f661554713edfacf338365adca8dfd3a3Nicolas Geoffray 207f85a9ca9859ad843dc03d3a2b600afbaf2e9bbddMark Mendell size_t GetFloatingPointSpillSlotSize() const OVERRIDE { 208f85a9ca9859ad843dc03d3a2b600afbaf2e9bbddMark Mendell // 8 bytes == 2 words for each spill. 209f85a9ca9859ad843dc03d3a2b600afbaf2e9bbddMark Mendell return 2 * kX86WordSize; 210f85a9ca9859ad843dc03d3a2b600afbaf2e9bbddMark Mendell } 211f85a9ca9859ad843dc03d3a2b600afbaf2e9bbddMark Mendell 212de58ab2c03ff8112b07ab827c8fa38f670dfc656Nicolas Geoffray HGraphVisitor* GetLocationBuilder() OVERRIDE { 213bab4ed7057799a4fadc6283108ab56f389d117d4Nicolas Geoffray return &location_builder_; 214bab4ed7057799a4fadc6283108ab56f389d117d4Nicolas Geoffray } 215bab4ed7057799a4fadc6283108ab56f389d117d4Nicolas Geoffray 216de58ab2c03ff8112b07ab827c8fa38f670dfc656Nicolas Geoffray HGraphVisitor* GetInstructionVisitor() OVERRIDE { 217787c3076635cf117eb646c5a89a9014b2072fb44Nicolas Geoffray return &instruction_visitor_; 218787c3076635cf117eb646c5a89a9014b2072fb44Nicolas Geoffray } 219787c3076635cf117eb646c5a89a9014b2072fb44Nicolas Geoffray 220de58ab2c03ff8112b07ab827c8fa38f670dfc656Nicolas Geoffray X86Assembler* GetAssembler() OVERRIDE { 221787c3076635cf117eb646c5a89a9014b2072fb44Nicolas Geoffray return &assembler_; 222787c3076635cf117eb646c5a89a9014b2072fb44Nicolas Geoffray } 223787c3076635cf117eb646c5a89a9014b2072fb44Nicolas Geoffray 224de58ab2c03ff8112b07ab827c8fa38f670dfc656Nicolas Geoffray uintptr_t GetAddressOf(HBasicBlock* block) const OVERRIDE { 225de58ab2c03ff8112b07ab827c8fa38f670dfc656Nicolas Geoffray return GetLabelOf(block)->Position(); 226de58ab2c03ff8112b07ab827c8fa38f670dfc656Nicolas Geoffray } 227de58ab2c03ff8112b07ab827c8fa38f670dfc656Nicolas Geoffray 228988939683c26c0b1c8808fc206add6337319509aNicolas Geoffray void SetupBlockedRegisters(bool is_baseline) const OVERRIDE; 22934bacdf7eb46c0ffbf24ba7aa14a904bc9176fb2Calin Juravle 230de58ab2c03ff8112b07ab827c8fa38f670dfc656Nicolas Geoffray Location AllocateFreeRegister(Primitive::Type type) const OVERRIDE; 231a7aca370a7d62ca04a1e24423d90e8020d6f1a58Nicolas Geoffray 232de58ab2c03ff8112b07ab827c8fa38f670dfc656Nicolas Geoffray Location GetStackLocation(HLoadLocal* load) const OVERRIDE; 2334a34a428c6a2588e0857ef6baf88f1b73ce65958Nicolas Geoffray 234de58ab2c03ff8112b07ab827c8fa38f670dfc656Nicolas Geoffray void DumpCoreRegister(std::ostream& stream, int reg) const OVERRIDE; 235de58ab2c03ff8112b07ab827c8fa38f670dfc656Nicolas Geoffray void DumpFloatingPointRegister(std::ostream& stream, int reg) const OVERRIDE; 236a7062e05e6048c7f817d784a5b94e3122e25b1ecNicolas Geoffray 23734bacdf7eb46c0ffbf24ba7aa14a904bc9176fb2Calin Juravle // Blocks all register pairs made out of blocked core registers. 23834bacdf7eb46c0ffbf24ba7aa14a904bc9176fb2Calin Juravle void UpdateBlockedPairRegisters() const; 23934bacdf7eb46c0ffbf24ba7aa14a904bc9176fb2Calin Juravle 240f0e3937b87453234d0d7970b8712082062709b8dNicolas Geoffray ParallelMoveResolverX86* GetMoveResolver() OVERRIDE { 24186dbb9a12119273039ce272b41c809fa548b37b6Nicolas Geoffray return &move_resolver_; 24286dbb9a12119273039ce272b41c809fa548b37b6Nicolas Geoffray } 24386dbb9a12119273039ce272b41c809fa548b37b6Nicolas Geoffray 244de58ab2c03ff8112b07ab827c8fa38f670dfc656Nicolas Geoffray InstructionSet GetInstructionSet() const OVERRIDE { 245412f10cfed002ab617c78f2621d68446ca4dd8bdNicolas Geoffray return InstructionSet::kX86; 246412f10cfed002ab617c78f2621d68446ca4dd8bdNicolas Geoffray } 247412f10cfed002ab617c78f2621d68446ca4dd8bdNicolas Geoffray 24801bc96d007b67fdb7fe349232a83e4b354ce3d08Nicolas Geoffray // Helper method to move a 32bits value between two locations. 24901bc96d007b67fdb7fe349232a83e4b354ce3d08Nicolas Geoffray void Move32(Location destination, Location source); 25001bc96d007b67fdb7fe349232a83e4b354ce3d08Nicolas Geoffray // Helper method to move a 64bits value between two locations. 25101bc96d007b67fdb7fe349232a83e4b354ce3d08Nicolas Geoffray void Move64(Location destination, Location source); 25201bc96d007b67fdb7fe349232a83e4b354ce3d08Nicolas Geoffray 25309ed1a3125849ec6ac07cb886e3c502e1dcfada2Mark Mendell // Generate a call to a static or direct method. 25409ed1a3125849ec6ac07cb886e3c502e1dcfada2Mark Mendell void GenerateStaticOrDirectCall(HInvokeStaticOrDirect* invoke, Register temp); 25509ed1a3125849ec6ac07cb886e3c502e1dcfada2Mark Mendell 2563c7bb98698f77af10372cf31824d3bb115d9bf0fNicolas Geoffray // Emit a write barrier. 2573c7bb98698f77af10372cf31824d3bb115d9bf0fNicolas Geoffray void MarkGCCard(Register temp, Register card, Register object, Register value); 2583c7bb98698f77af10372cf31824d3bb115d9bf0fNicolas Geoffray 25919a19cffd197a28ae4c9c3e59eff6352fd392241Nicolas Geoffray void LoadCurrentMethod(Register reg); 26019a19cffd197a28ae4c9c3e59eff6352fd392241Nicolas Geoffray 26192a73aef279be78e3c2b04db1713076183933436Nicolas Geoffray Label* GetLabelOf(HBasicBlock* block) const { 262dc23d8318db08cb42e20f1d16dbc416798951a8bNicolas Geoffray return CommonGetLabelOf<Label>(block_labels_.GetRawStorage(), block); 26392a73aef279be78e3c2b04db1713076183933436Nicolas Geoffray } 26492a73aef279be78e3c2b04db1713076183933436Nicolas Geoffray 265de58ab2c03ff8112b07ab827c8fa38f670dfc656Nicolas Geoffray void Initialize() OVERRIDE { 26692a73aef279be78e3c2b04db1713076183933436Nicolas Geoffray block_labels_.SetSize(GetGraph()->GetBlocks().Size()); 26792a73aef279be78e3c2b04db1713076183933436Nicolas Geoffray } 26892a73aef279be78e3c2b04db1713076183933436Nicolas Geoffray 269840e5461a85f8908f51e7f6cd562a9129ff0e7ceNicolas Geoffray bool NeedsTwoRegisters(Primitive::Type type) const OVERRIDE { 270840e5461a85f8908f51e7f6cd562a9129ff0e7ceNicolas Geoffray return type == Primitive::kPrimLong; 271840e5461a85f8908f51e7f6cd562a9129ff0e7ceNicolas Geoffray } 272840e5461a85f8908f51e7f6cd562a9129ff0e7ceNicolas Geoffray 273234d69d075d1608f80adb647f7935077b62b6376Nicolas Geoffray bool ShouldSplitLongMoves() const OVERRIDE { return true; } 274234d69d075d1608f80adb647f7935077b62b6376Nicolas Geoffray 2751cf95287364948689f6a1a320567acd7728e94a3Nicolas Geoffray Label* GetFrameEntryLabel() { return &frame_entry_label_; } 2761cf95287364948689f6a1a320567acd7728e94a3Nicolas Geoffray 2773c7bb98698f77af10372cf31824d3bb115d9bf0fNicolas Geoffray private: 27892a73aef279be78e3c2b04db1713076183933436Nicolas Geoffray // Labels for each block that will be compiled. 27992a73aef279be78e3c2b04db1713076183933436Nicolas Geoffray GrowableArray<Label> block_labels_; 2801cf95287364948689f6a1a320567acd7728e94a3Nicolas Geoffray Label frame_entry_label_; 281bab4ed7057799a4fadc6283108ab56f389d117d4Nicolas Geoffray LocationsBuilderX86 location_builder_; 282787c3076635cf117eb646c5a89a9014b2072fb44Nicolas Geoffray InstructionCodeGeneratorX86 instruction_visitor_; 28386dbb9a12119273039ce272b41c809fa548b37b6Nicolas Geoffray ParallelMoveResolverX86 move_resolver_; 284787c3076635cf117eb646c5a89a9014b2072fb44Nicolas Geoffray X86Assembler assembler_; 285d4dd255db1d110ceb5551f6d95ff31fb57420994Nicolas Geoffray 286d4dd255db1d110ceb5551f6d95ff31fb57420994Nicolas Geoffray DISALLOW_COPY_AND_ASSIGN(CodeGeneratorX86); 287d4dd255db1d110ceb5551f6d95ff31fb57420994Nicolas Geoffray}; 288d4dd255db1d110ceb5551f6d95ff31fb57420994Nicolas Geoffray 28909ed1a3125849ec6ac07cb886e3c502e1dcfada2Mark Mendellclass SlowPathCodeX86 : public SlowPathCode { 29009ed1a3125849ec6ac07cb886e3c502e1dcfada2Mark Mendell public: 29109ed1a3125849ec6ac07cb886e3c502e1dcfada2Mark Mendell SlowPathCodeX86() : entry_label_(), exit_label_() {} 29209ed1a3125849ec6ac07cb886e3c502e1dcfada2Mark Mendell 29309ed1a3125849ec6ac07cb886e3c502e1dcfada2Mark Mendell Label* GetEntryLabel() { return &entry_label_; } 29409ed1a3125849ec6ac07cb886e3c502e1dcfada2Mark Mendell Label* GetExitLabel() { return &exit_label_; } 29509ed1a3125849ec6ac07cb886e3c502e1dcfada2Mark Mendell 29609ed1a3125849ec6ac07cb886e3c502e1dcfada2Mark Mendell private: 29709ed1a3125849ec6ac07cb886e3c502e1dcfada2Mark Mendell Label entry_label_; 29809ed1a3125849ec6ac07cb886e3c502e1dcfada2Mark Mendell Label exit_label_; 29909ed1a3125849ec6ac07cb886e3c502e1dcfada2Mark Mendell 30009ed1a3125849ec6ac07cb886e3c502e1dcfada2Mark Mendell DISALLOW_COPY_AND_ASSIGN(SlowPathCodeX86); 30109ed1a3125849ec6ac07cb886e3c502e1dcfada2Mark Mendell}; 30209ed1a3125849ec6ac07cb886e3c502e1dcfada2Mark Mendell 303d4dd255db1d110ceb5551f6d95ff31fb57420994Nicolas Geoffray} // namespace x86 304d4dd255db1d110ceb5551f6d95ff31fb57420994Nicolas Geoffray} // namespace art 305d4dd255db1d110ceb5551f6d95ff31fb57420994Nicolas Geoffray 306d4dd255db1d110ceb5551f6d95ff31fb57420994Nicolas Geoffray#endif // ART_COMPILER_OPTIMIZING_CODE_GENERATOR_X86_H_ 307