code_generator_x86_64.h revision 39dcf55a56da746e04f477f89e7b00ba1de03880
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
40d75948ac93a4a317feaf136cae78823071234ba5Nicolas Geoffraystatic constexpr Register kRuntimeParameterCoreRegisters[] = { RDI, RSI, RDX };
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,
53d75948ac93a4a317feaf136cae78823071234ba5Nicolas Geoffray                          kRuntimeParameterFpuRegistersLength) {}
54d75948ac93a4a317feaf136cae78823071234ba5Nicolas Geoffray
55d75948ac93a4a317feaf136cae78823071234ba5Nicolas Geoffray private:
56d75948ac93a4a317feaf136cae78823071234ba5Nicolas Geoffray  DISALLOW_COPY_AND_ASSIGN(InvokeRuntimeCallingConvention);
57d75948ac93a4a317feaf136cae78823071234ba5Nicolas Geoffray};
58d75948ac93a4a317feaf136cae78823071234ba5Nicolas Geoffray
597fb49da8ec62e8a10ed9419ade9f32c6b1174687Nicolas Geoffrayclass InvokeDexCallingConvention : public CallingConvention<Register, FloatRegister> {
609cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray public:
617fb49da8ec62e8a10ed9419ade9f32c6b1174687Nicolas Geoffray  InvokeDexCallingConvention() : CallingConvention(
627fb49da8ec62e8a10ed9419ade9f32c6b1174687Nicolas Geoffray      kParameterCoreRegisters,
637fb49da8ec62e8a10ed9419ade9f32c6b1174687Nicolas Geoffray      kParameterCoreRegistersLength,
647fb49da8ec62e8a10ed9419ade9f32c6b1174687Nicolas Geoffray      kParameterFloatRegisters,
657fb49da8ec62e8a10ed9419ade9f32c6b1174687Nicolas Geoffray      kParameterFloatRegistersLength) {}
669cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray
679cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray private:
689cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray  DISALLOW_COPY_AND_ASSIGN(InvokeDexCallingConvention);
699cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray};
709cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray
719cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffrayclass InvokeDexCallingConventionVisitor {
729cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray public:
737fb49da8ec62e8a10ed9419ade9f32c6b1174687Nicolas Geoffray  InvokeDexCallingConventionVisitor() : gp_index_(0), fp_index_(0), stack_index_(0) {}
749cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray
759cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray  Location GetNextLocation(Primitive::Type type);
769cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray
779cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray private:
789cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray  InvokeDexCallingConvention calling_convention;
797fb49da8ec62e8a10ed9419ade9f32c6b1174687Nicolas Geoffray  // The current index for cpu registers.
809cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray  uint32_t gp_index_;
817fb49da8ec62e8a10ed9419ade9f32c6b1174687Nicolas Geoffray  // The current index for fpu registers.
827fb49da8ec62e8a10ed9419ade9f32c6b1174687Nicolas Geoffray  uint32_t fp_index_;
837fb49da8ec62e8a10ed9419ade9f32c6b1174687Nicolas Geoffray  // The current stack index.
849cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray  uint32_t stack_index_;
859cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray
869cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray  DISALLOW_COPY_AND_ASSIGN(InvokeDexCallingConventionVisitor);
879cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray};
889cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray
899cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffrayclass CodeGeneratorX86_64;
9071fb52fee246b7d511f520febbd73dc7a9bbca79Andreas Gampe
9171fb52fee246b7d511f520febbd73dc7a9bbca79Andreas Gampeclass SlowPathCodeX86_64 : public SlowPathCode {
9271fb52fee246b7d511f520febbd73dc7a9bbca79Andreas Gampe public:
9371fb52fee246b7d511f520febbd73dc7a9bbca79Andreas Gampe  SlowPathCodeX86_64() : entry_label_(), exit_label_() {}
9471fb52fee246b7d511f520febbd73dc7a9bbca79Andreas Gampe
9571fb52fee246b7d511f520febbd73dc7a9bbca79Andreas Gampe  Label* GetEntryLabel() { return &entry_label_; }
9671fb52fee246b7d511f520febbd73dc7a9bbca79Andreas Gampe  Label* GetExitLabel() { return &exit_label_; }
9771fb52fee246b7d511f520febbd73dc7a9bbca79Andreas Gampe
9871fb52fee246b7d511f520febbd73dc7a9bbca79Andreas Gampe private:
9971fb52fee246b7d511f520febbd73dc7a9bbca79Andreas Gampe  Label entry_label_;
10071fb52fee246b7d511f520febbd73dc7a9bbca79Andreas Gampe  Label exit_label_;
10171fb52fee246b7d511f520febbd73dc7a9bbca79Andreas Gampe
10271fb52fee246b7d511f520febbd73dc7a9bbca79Andreas Gampe  DISALLOW_COPY_AND_ASSIGN(SlowPathCodeX86_64);
10371fb52fee246b7d511f520febbd73dc7a9bbca79Andreas Gampe};
1049cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray
105ecb2f9ba57b08ceac4204ddd6a0a88a0524f8741Nicolas Geoffrayclass ParallelMoveResolverX86_64 : public ParallelMoveResolver {
106ecb2f9ba57b08ceac4204ddd6a0a88a0524f8741Nicolas Geoffray public:
107ecb2f9ba57b08ceac4204ddd6a0a88a0524f8741Nicolas Geoffray  ParallelMoveResolverX86_64(ArenaAllocator* allocator, CodeGeneratorX86_64* codegen)
108ecb2f9ba57b08ceac4204ddd6a0a88a0524f8741Nicolas Geoffray      : ParallelMoveResolver(allocator), codegen_(codegen) {}
109ecb2f9ba57b08ceac4204ddd6a0a88a0524f8741Nicolas Geoffray
110de58ab2c03ff8112b07ab827c8fa38f670dfc656Nicolas Geoffray  void EmitMove(size_t index) OVERRIDE;
111de58ab2c03ff8112b07ab827c8fa38f670dfc656Nicolas Geoffray  void EmitSwap(size_t index) OVERRIDE;
112de58ab2c03ff8112b07ab827c8fa38f670dfc656Nicolas Geoffray  void SpillScratch(int reg) OVERRIDE;
113de58ab2c03ff8112b07ab827c8fa38f670dfc656Nicolas Geoffray  void RestoreScratch(int reg) OVERRIDE;
114ecb2f9ba57b08ceac4204ddd6a0a88a0524f8741Nicolas Geoffray
115ecb2f9ba57b08ceac4204ddd6a0a88a0524f8741Nicolas Geoffray  X86_64Assembler* GetAssembler() const;
116ecb2f9ba57b08ceac4204ddd6a0a88a0524f8741Nicolas Geoffray
117ecb2f9ba57b08ceac4204ddd6a0a88a0524f8741Nicolas Geoffray private:
118412f10cfed002ab617c78f2621d68446ca4dd8bdNicolas Geoffray  void Exchange32(CpuRegister reg, int mem);
119102cbed1e52b7c5f09458b44903fe97bb3e14d5fNicolas Geoffray  void Exchange32(XmmRegister reg, int mem);
120412f10cfed002ab617c78f2621d68446ca4dd8bdNicolas Geoffray  void Exchange32(int mem1, int mem2);
121412f10cfed002ab617c78f2621d68446ca4dd8bdNicolas Geoffray  void Exchange64(CpuRegister reg, int mem);
122102cbed1e52b7c5f09458b44903fe97bb3e14d5fNicolas Geoffray  void Exchange64(XmmRegister reg, int mem);
123412f10cfed002ab617c78f2621d68446ca4dd8bdNicolas Geoffray  void Exchange64(int mem1, int mem2);
124ecb2f9ba57b08ceac4204ddd6a0a88a0524f8741Nicolas Geoffray
125ecb2f9ba57b08ceac4204ddd6a0a88a0524f8741Nicolas Geoffray  CodeGeneratorX86_64* const codegen_;
126ecb2f9ba57b08ceac4204ddd6a0a88a0524f8741Nicolas Geoffray
127ecb2f9ba57b08ceac4204ddd6a0a88a0524f8741Nicolas Geoffray  DISALLOW_COPY_AND_ASSIGN(ParallelMoveResolverX86_64);
128ecb2f9ba57b08ceac4204ddd6a0a88a0524f8741Nicolas Geoffray};
129ecb2f9ba57b08ceac4204ddd6a0a88a0524f8741Nicolas Geoffray
1309cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffrayclass LocationsBuilderX86_64 : public HGraphVisitor {
1319cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray public:
1329cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray  LocationsBuilderX86_64(HGraph* graph, CodeGeneratorX86_64* codegen)
1339cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray      : HGraphVisitor(graph), codegen_(codegen) {}
1349cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray
135360231a056e796c36ffe62348507e904dc9efb9bNicolas Geoffray#define DECLARE_VISIT_INSTRUCTION(name, super)     \
136de58ab2c03ff8112b07ab827c8fa38f670dfc656Nicolas Geoffray  void Visit##name(H##name* instr) OVERRIDE;
1379cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray
13896f89a290eb67d7bf4b1636798fa28df14309cc7Nicolas Geoffray  FOR_EACH_CONCRETE_INSTRUCTION(DECLARE_VISIT_INSTRUCTION)
1399cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray
1409cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray#undef DECLARE_VISIT_INSTRUCTION
1419cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray
1429574c4b5f5ef039d694ac12c97e25ca02eca83c0Nicolas Geoffray private:
143e982f0b8e809cece6f460fa2d8df25873aa69de4Nicolas Geoffray  void HandleInvoke(HInvoke* invoke);
1449574c4b5f5ef039d694ac12c97e25ca02eca83c0Nicolas Geoffray  void HandleBitwiseOperation(HBinaryOperation* operation);
1459aec02fc5df5518c16f1e5a9b6cb198a192db973Calin Juravle  void HandleShift(HBinaryOperation* operation);
14652c489645b6e9ae33623f1ec24143cde5444906eCalin Juravle  void HandleFieldSet(HInstruction* instruction, const FieldInfo& field_info);
14752c489645b6e9ae33623f1ec24143cde5444906eCalin Juravle  void HandleFieldGet(HInstruction* instruction);
148e982f0b8e809cece6f460fa2d8df25873aa69de4Nicolas Geoffray
1499cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray  CodeGeneratorX86_64* const codegen_;
1509cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray  InvokeDexCallingConventionVisitor parameter_visitor_;
1519cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray
1529cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray  DISALLOW_COPY_AND_ASSIGN(LocationsBuilderX86_64);
1539cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray};
1549cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray
1559cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffrayclass InstructionCodeGeneratorX86_64 : public HGraphVisitor {
1569cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray public:
1579cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray  InstructionCodeGeneratorX86_64(HGraph* graph, CodeGeneratorX86_64* codegen);
1589cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray
159360231a056e796c36ffe62348507e904dc9efb9bNicolas Geoffray#define DECLARE_VISIT_INSTRUCTION(name, super)     \
160de58ab2c03ff8112b07ab827c8fa38f670dfc656Nicolas Geoffray  void Visit##name(H##name* instr) OVERRIDE;
1619cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray
16296f89a290eb67d7bf4b1636798fa28df14309cc7Nicolas Geoffray  FOR_EACH_CONCRETE_INSTRUCTION(DECLARE_VISIT_INSTRUCTION)
1639cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray
1649cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray#undef DECLARE_VISIT_INSTRUCTION
1659cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray
1669cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray  X86_64Assembler* GetAssembler() const { return assembler_; }
1679cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray
1689cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray private:
1693c04974a90b0e03f4b509010bff49f0b2a3da57fNicolas Geoffray  // Generate code for the given suspend check. If not null, `successor`
1703c04974a90b0e03f4b509010bff49f0b2a3da57fNicolas Geoffray  // is the block to branch to if the suspend check is not needed, and after
1713c04974a90b0e03f4b509010bff49f0b2a3da57fNicolas Geoffray  // the suspend call.
1723c04974a90b0e03f4b509010bff49f0b2a3da57fNicolas Geoffray  void GenerateSuspendCheck(HSuspendCheck* instruction, HBasicBlock* successor);
173424f676379f2f872acd1478672022f19f3240fc1Nicolas Geoffray  void GenerateClassInitializationCheck(SlowPathCodeX86_64* slow_path, CpuRegister class_reg);
1749574c4b5f5ef039d694ac12c97e25ca02eca83c0Nicolas Geoffray  void HandleBitwiseOperation(HBinaryOperation* operation);
17524f2dfae084b2382c053f5d688fd6bb26cb8a328Mark Mendell  void GenerateRemFP(HRem *rem);
1760f88e87085b7cf6544dadff3f555773966a6853eGuillaume Sanchez  void DivRemOneOrMinusOne(HBinaryOperation* instruction);
1770f88e87085b7cf6544dadff3f555773966a6853eGuillaume Sanchez  void DivByPowerOfTwo(HBinaryOperation* instruction);
1780f88e87085b7cf6544dadff3f555773966a6853eGuillaume Sanchez  void GenerateDivRemWithAnyConstant(HBinaryOperation* instruction);
179bacfec30ee9f2f6fdfd190f11b105b609938efcaCalin Juravle  void GenerateDivRemIntegral(HBinaryOperation* instruction);
1809aec02fc5df5518c16f1e5a9b6cb198a192db973Calin Juravle  void HandleShift(HBinaryOperation* operation);
18152c489645b6e9ae33623f1ec24143cde5444906eCalin Juravle  void GenerateMemoryBarrier(MemBarrierKind kind);
18252c489645b6e9ae33623f1ec24143cde5444906eCalin Juravle  void HandleFieldSet(HInstruction* instruction, const FieldInfo& field_info);
18352c489645b6e9ae33623f1ec24143cde5444906eCalin Juravle  void HandleFieldGet(HInstruction* instruction, const FieldInfo& field_info);
184cd6dffedf1bd8e6dfb3fb0c933551f9a90f7de3fCalin Juravle  void GenerateImplicitNullCheck(HNullCheck* instruction);
185cd6dffedf1bd8e6dfb3fb0c933551f9a90f7de3fCalin Juravle  void GenerateExplicitNullCheck(HNullCheck* instruction);
18624f2dfae084b2382c053f5d688fd6bb26cb8a328Mark Mendell  void PushOntoFPStack(Location source, uint32_t temp_offset,
18724f2dfae084b2382c053f5d688fd6bb26cb8a328Mark Mendell                       uint32_t stack_adjustment, bool is_float);
188d43b3ac88cd46b8815890188c9c2b9a3f1564648Mingyao Yang  void GenerateTestAndBranch(HInstruction* instruction,
189d43b3ac88cd46b8815890188c9c2b9a3f1564648Mingyao Yang                             Label* true_target,
190d43b3ac88cd46b8815890188c9c2b9a3f1564648Mingyao Yang                             Label* false_target,
191d43b3ac88cd46b8815890188c9c2b9a3f1564648Mingyao Yang                             Label* always_true_target);
1923c04974a90b0e03f4b509010bff49f0b2a3da57fNicolas Geoffray
1939cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray  X86_64Assembler* const assembler_;
1949cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray  CodeGeneratorX86_64* const codegen_;
1959cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray
1969cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray  DISALLOW_COPY_AND_ASSIGN(InstructionCodeGeneratorX86_64);
1979cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray};
1989cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray
1999cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffrayclass CodeGeneratorX86_64 : public CodeGenerator {
2009cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray public:
201fb8d279bc011b31d0765dc7ca59afea324fd0d0cMark Mendell  CodeGeneratorX86_64(HGraph* graph,
202fb8d279bc011b31d0765dc7ca59afea324fd0d0cMark Mendell                  const X86_64InstructionSetFeatures& isa_features,
203fb8d279bc011b31d0765dc7ca59afea324fd0d0cMark Mendell                  const CompilerOptions& compiler_options);
2049cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray  virtual ~CodeGeneratorX86_64() {}
2059cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray
206de58ab2c03ff8112b07ab827c8fa38f670dfc656Nicolas Geoffray  void GenerateFrameEntry() OVERRIDE;
207de58ab2c03ff8112b07ab827c8fa38f670dfc656Nicolas Geoffray  void GenerateFrameExit() OVERRIDE;
208de58ab2c03ff8112b07ab827c8fa38f670dfc656Nicolas Geoffray  void Bind(HBasicBlock* block) OVERRIDE;
209de58ab2c03ff8112b07ab827c8fa38f670dfc656Nicolas Geoffray  void Move(HInstruction* instruction, Location location, HInstruction* move_for) OVERRIDE;
210de58ab2c03ff8112b07ab827c8fa38f670dfc656Nicolas Geoffray  size_t SaveCoreRegister(size_t stack_index, uint32_t reg_id) OVERRIDE;
211de58ab2c03ff8112b07ab827c8fa38f670dfc656Nicolas Geoffray  size_t RestoreCoreRegister(size_t stack_index, uint32_t reg_id) OVERRIDE;
212de58ab2c03ff8112b07ab827c8fa38f670dfc656Nicolas Geoffray  size_t SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) OVERRIDE;
213de58ab2c03ff8112b07ab827c8fa38f670dfc656Nicolas Geoffray  size_t RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) OVERRIDE;
2149cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray
215de58ab2c03ff8112b07ab827c8fa38f670dfc656Nicolas Geoffray  size_t GetWordSize() const OVERRIDE {
2169cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray    return kX86_64WordSize;
2179cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray  }
2189cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray
219f85a9ca9859ad843dc03d3a2b600afbaf2e9bbddMark Mendell  size_t GetFloatingPointSpillSlotSize() const OVERRIDE {
220f85a9ca9859ad843dc03d3a2b600afbaf2e9bbddMark Mendell    return kX86_64WordSize;
221f85a9ca9859ad843dc03d3a2b600afbaf2e9bbddMark Mendell  }
222f85a9ca9859ad843dc03d3a2b600afbaf2e9bbddMark Mendell
223de58ab2c03ff8112b07ab827c8fa38f670dfc656Nicolas Geoffray  HGraphVisitor* GetLocationBuilder() OVERRIDE {
2249cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray    return &location_builder_;
2259cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray  }
2269cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray
227de58ab2c03ff8112b07ab827c8fa38f670dfc656Nicolas Geoffray  HGraphVisitor* GetInstructionVisitor() OVERRIDE {
2289cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray    return &instruction_visitor_;
2299cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray  }
2309cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray
231de58ab2c03ff8112b07ab827c8fa38f670dfc656Nicolas Geoffray  X86_64Assembler* GetAssembler() OVERRIDE {
2329cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray    return &assembler_;
2339cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray  }
2349cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray
235f0e3937b87453234d0d7970b8712082062709b8dNicolas Geoffray  ParallelMoveResolverX86_64* GetMoveResolver() OVERRIDE {
236ecb2f9ba57b08ceac4204ddd6a0a88a0524f8741Nicolas Geoffray    return &move_resolver_;
237ecb2f9ba57b08ceac4204ddd6a0a88a0524f8741Nicolas Geoffray  }
238ecb2f9ba57b08ceac4204ddd6a0a88a0524f8741Nicolas Geoffray
239de58ab2c03ff8112b07ab827c8fa38f670dfc656Nicolas Geoffray  uintptr_t GetAddressOf(HBasicBlock* block) const OVERRIDE {
240de58ab2c03ff8112b07ab827c8fa38f670dfc656Nicolas Geoffray    return GetLabelOf(block)->Position();
241de58ab2c03ff8112b07ab827c8fa38f670dfc656Nicolas Geoffray  }
242de58ab2c03ff8112b07ab827c8fa38f670dfc656Nicolas Geoffray
243de58ab2c03ff8112b07ab827c8fa38f670dfc656Nicolas Geoffray  Location GetStackLocation(HLoadLocal* load) const OVERRIDE;
2449cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray
245988939683c26c0b1c8808fc206add6337319509aNicolas Geoffray  void SetupBlockedRegisters(bool is_baseline) const OVERRIDE;
246de58ab2c03ff8112b07ab827c8fa38f670dfc656Nicolas Geoffray  Location AllocateFreeRegister(Primitive::Type type) const OVERRIDE;
247de58ab2c03ff8112b07ab827c8fa38f670dfc656Nicolas Geoffray  void DumpCoreRegister(std::ostream& stream, int reg) const OVERRIDE;
248de58ab2c03ff8112b07ab827c8fa38f670dfc656Nicolas Geoffray  void DumpFloatingPointRegister(std::ostream& stream, int reg) const OVERRIDE;
249f55c3e0825cdfc4c5a27730031177d1a0198ec5aMark Mendell  void Finalize(CodeAllocator* allocator) OVERRIDE;
2509cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray
251de58ab2c03ff8112b07ab827c8fa38f670dfc656Nicolas Geoffray  InstructionSet GetInstructionSet() const OVERRIDE {
252412f10cfed002ab617c78f2621d68446ca4dd8bdNicolas Geoffray    return InstructionSet::kX86_64;
253412f10cfed002ab617c78f2621d68446ca4dd8bdNicolas Geoffray  }
254412f10cfed002ab617c78f2621d68446ca4dd8bdNicolas Geoffray
2553c7bb98698f77af10372cf31824d3bb115d9bf0fNicolas Geoffray  // Emit a write barrier.
2563c7bb98698f77af10372cf31824d3bb115d9bf0fNicolas Geoffray  void MarkGCCard(CpuRegister temp, CpuRegister card, CpuRegister object, CpuRegister value);
2573c7bb98698f77af10372cf31824d3bb115d9bf0fNicolas Geoffray
2589cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray  // Helper method to move a value between two locations.
2599cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray  void Move(Location destination, Location source);
2609cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray
26119a19cffd197a28ae4c9c3e59eff6352fd392241Nicolas Geoffray  void LoadCurrentMethod(CpuRegister reg);
26219a19cffd197a28ae4c9c3e59eff6352fd392241Nicolas Geoffray
26392a73aef279be78e3c2b04db1713076183933436Nicolas Geoffray  Label* GetLabelOf(HBasicBlock* block) const {
264dc23d8318db08cb42e20f1d16dbc416798951a8bNicolas Geoffray    return CommonGetLabelOf<Label>(block_labels_.GetRawStorage(), block);
26592a73aef279be78e3c2b04db1713076183933436Nicolas Geoffray  }
26692a73aef279be78e3c2b04db1713076183933436Nicolas Geoffray
267de58ab2c03ff8112b07ab827c8fa38f670dfc656Nicolas Geoffray  void Initialize() OVERRIDE {
26892a73aef279be78e3c2b04db1713076183933436Nicolas Geoffray    block_labels_.SetSize(GetGraph()->GetBlocks().Size());
26992a73aef279be78e3c2b04db1713076183933436Nicolas Geoffray  }
27092a73aef279be78e3c2b04db1713076183933436Nicolas Geoffray
271840e5461a85f8908f51e7f6cd562a9129ff0e7ceNicolas Geoffray  bool NeedsTwoRegisters(Primitive::Type type ATTRIBUTE_UNUSED) const OVERRIDE {
272840e5461a85f8908f51e7f6cd562a9129ff0e7ceNicolas Geoffray    return false;
273840e5461a85f8908f51e7f6cd562a9129ff0e7ceNicolas Geoffray  }
274840e5461a85f8908f51e7f6cd562a9129ff0e7ceNicolas Geoffray
27571fb52fee246b7d511f520febbd73dc7a9bbca79Andreas Gampe  void GenerateStaticOrDirectCall(HInvokeStaticOrDirect* invoke, CpuRegister temp);
27671fb52fee246b7d511f520febbd73dc7a9bbca79Andreas Gampe
277fb8d279bc011b31d0765dc7ca59afea324fd0d0cMark Mendell  const X86_64InstructionSetFeatures& GetInstructionSetFeatures() const {
278fb8d279bc011b31d0765dc7ca59afea324fd0d0cMark Mendell    return isa_features_;
279fb8d279bc011b31d0765dc7ca59afea324fd0d0cMark Mendell  }
280fb8d279bc011b31d0765dc7ca59afea324fd0d0cMark Mendell
281f55c3e0825cdfc4c5a27730031177d1a0198ec5aMark Mendell  int ConstantAreaStart() const {
282f55c3e0825cdfc4c5a27730031177d1a0198ec5aMark Mendell    return constant_area_start_;
283f55c3e0825cdfc4c5a27730031177d1a0198ec5aMark Mendell  }
284f55c3e0825cdfc4c5a27730031177d1a0198ec5aMark Mendell
285f55c3e0825cdfc4c5a27730031177d1a0198ec5aMark Mendell  Address LiteralDoubleAddress(double v);
286f55c3e0825cdfc4c5a27730031177d1a0198ec5aMark Mendell  Address LiteralFloatAddress(float v);
287f55c3e0825cdfc4c5a27730031177d1a0198ec5aMark Mendell  Address LiteralInt32Address(int32_t v);
288f55c3e0825cdfc4c5a27730031177d1a0198ec5aMark Mendell  Address LiteralInt64Address(int64_t v);
289f55c3e0825cdfc4c5a27730031177d1a0198ec5aMark Mendell
2903c7bb98698f77af10372cf31824d3bb115d9bf0fNicolas Geoffray private:
29192a73aef279be78e3c2b04db1713076183933436Nicolas Geoffray  // Labels for each block that will be compiled.
29292a73aef279be78e3c2b04db1713076183933436Nicolas Geoffray  GrowableArray<Label> block_labels_;
2931cf95287364948689f6a1a320567acd7728e94a3Nicolas Geoffray  Label frame_entry_label_;
2949cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray  LocationsBuilderX86_64 location_builder_;
2959cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray  InstructionCodeGeneratorX86_64 instruction_visitor_;
296ecb2f9ba57b08ceac4204ddd6a0a88a0524f8741Nicolas Geoffray  ParallelMoveResolverX86_64 move_resolver_;
2979cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray  X86_64Assembler assembler_;
298fb8d279bc011b31d0765dc7ca59afea324fd0d0cMark Mendell  const X86_64InstructionSetFeatures& isa_features_;
2999cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray
30039dcf55a56da746e04f477f89e7b00ba1de03880Mark Mendell  // Offset to the start of the constant area in the assembled code.
301f55c3e0825cdfc4c5a27730031177d1a0198ec5aMark Mendell  // Used for fixups to the constant area.
302f55c3e0825cdfc4c5a27730031177d1a0198ec5aMark Mendell  int constant_area_start_;
303f55c3e0825cdfc4c5a27730031177d1a0198ec5aMark Mendell
3049cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray  DISALLOW_COPY_AND_ASSIGN(CodeGeneratorX86_64);
3059cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray};
3069cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray
3079cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray}  // namespace x86_64
3089cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray}  // namespace art
3099cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray
3109cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray#endif  // ART_COMPILER_OPTIMIZING_CODE_GENERATOR_X86_64_H_
311