| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2014 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #ifndef ART_COMPILER_OPTIMIZING_CODE_GENERATOR_X86_64_H_ |
| 18 | #define ART_COMPILER_OPTIMIZING_CODE_GENERATOR_X86_64_H_ |
| 19 | |
| 20 | #include "code_generator.h" |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 21 | #include "dex/compiler_enums.h" |
| Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 22 | #include "driver/compiler_options.h" |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 23 | #include "nodes.h" |
| Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 24 | #include "parallel_move_resolver.h" |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 25 | #include "utils/x86_64/assembler_x86_64.h" |
| 26 | |
| 27 | namespace art { |
| 28 | namespace x86_64 { |
| 29 | |
| Nicolas Geoffray | 86a8d7a | 2014-11-19 08:47:18 +0000 | [diff] [blame] | 30 | // Use a local definition to prevent copying mistakes. |
| 31 | static constexpr size_t kX86_64WordSize = kX86_64PointerSize; |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 32 | |
| Nicolas Geoffray | ee3cf07 | 2015-10-06 11:45:02 +0100 | [diff] [blame] | 33 | // Some x86_64 instructions require a register to be available as temp. |
| 34 | static constexpr Register TMP = R11; |
| 35 | |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 36 | static constexpr Register kParameterCoreRegisters[] = { RSI, RDX, RCX, R8, R9 }; |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 37 | static constexpr FloatRegister kParameterFloatRegisters[] = |
| 38 | { XMM0, XMM1, XMM2, XMM3, XMM4, XMM5, XMM6, XMM7 }; |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 39 | |
| 40 | static constexpr size_t kParameterCoreRegistersLength = arraysize(kParameterCoreRegisters); |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 41 | static constexpr size_t kParameterFloatRegistersLength = arraysize(kParameterFloatRegisters); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 42 | |
| Jeff Hao | 848f70a | 2014-01-15 13:49:50 -0800 | [diff] [blame] | 43 | static constexpr Register kRuntimeParameterCoreRegisters[] = { RDI, RSI, RDX, RCX }; |
| Nicolas Geoffray | d75948a | 2015-03-27 09:53:16 +0000 | [diff] [blame] | 44 | static constexpr size_t kRuntimeParameterCoreRegistersLength = |
| 45 | arraysize(kRuntimeParameterCoreRegisters); |
| 46 | static constexpr FloatRegister kRuntimeParameterFpuRegisters[] = { XMM0, XMM1 }; |
| 47 | static constexpr size_t kRuntimeParameterFpuRegistersLength = |
| 48 | arraysize(kRuntimeParameterFpuRegisters); |
| 49 | |
| 50 | class InvokeRuntimeCallingConvention : public CallingConvention<Register, FloatRegister> { |
| 51 | public: |
| 52 | InvokeRuntimeCallingConvention() |
| 53 | : CallingConvention(kRuntimeParameterCoreRegisters, |
| 54 | kRuntimeParameterCoreRegistersLength, |
| 55 | kRuntimeParameterFpuRegisters, |
| Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 56 | kRuntimeParameterFpuRegistersLength, |
| 57 | kX86_64PointerSize) {} |
| Nicolas Geoffray | d75948a | 2015-03-27 09:53:16 +0000 | [diff] [blame] | 58 | |
| 59 | private: |
| 60 | DISALLOW_COPY_AND_ASSIGN(InvokeRuntimeCallingConvention); |
| 61 | }; |
| 62 | |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 63 | class InvokeDexCallingConvention : public CallingConvention<Register, FloatRegister> { |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 64 | public: |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 65 | InvokeDexCallingConvention() : CallingConvention( |
| 66 | kParameterCoreRegisters, |
| 67 | kParameterCoreRegistersLength, |
| 68 | kParameterFloatRegisters, |
| Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 69 | kParameterFloatRegistersLength, |
| 70 | kX86_64PointerSize) {} |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 71 | |
| 72 | private: |
| 73 | DISALLOW_COPY_AND_ASSIGN(InvokeDexCallingConvention); |
| 74 | }; |
| 75 | |
| Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 76 | class FieldAccessCallingConventionX86_64 : public FieldAccessCallingConvention { |
| 77 | public: |
| 78 | FieldAccessCallingConventionX86_64() {} |
| 79 | |
| 80 | Location GetObjectLocation() const OVERRIDE { |
| 81 | return Location::RegisterLocation(RSI); |
| 82 | } |
| 83 | Location GetFieldIndexLocation() const OVERRIDE { |
| 84 | return Location::RegisterLocation(RDI); |
| 85 | } |
| 86 | Location GetReturnLocation(Primitive::Type type ATTRIBUTE_UNUSED) const OVERRIDE { |
| 87 | return Location::RegisterLocation(RAX); |
| 88 | } |
| 89 | Location GetSetValueLocation(Primitive::Type type, bool is_instance) const OVERRIDE { |
| 90 | return Primitive::Is64BitType(type) |
| 91 | ? Location::RegisterLocation(RDX) |
| 92 | : (is_instance |
| 93 | ? Location::RegisterLocation(RDX) |
| 94 | : Location::RegisterLocation(RSI)); |
| 95 | } |
| 96 | Location GetFpuLocation(Primitive::Type type ATTRIBUTE_UNUSED) const OVERRIDE { |
| 97 | return Location::FpuRegisterLocation(XMM0); |
| 98 | } |
| 99 | |
| 100 | private: |
| 101 | DISALLOW_COPY_AND_ASSIGN(FieldAccessCallingConventionX86_64); |
| 102 | }; |
| 103 | |
| 104 | |
| Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 105 | class InvokeDexCallingConventionVisitorX86_64 : public InvokeDexCallingConventionVisitor { |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 106 | public: |
| Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 107 | InvokeDexCallingConventionVisitorX86_64() {} |
| 108 | virtual ~InvokeDexCallingConventionVisitorX86_64() {} |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 109 | |
| Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 110 | Location GetNextLocation(Primitive::Type type) OVERRIDE; |
| Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 111 | Location GetReturnLocation(Primitive::Type type) const OVERRIDE; |
| 112 | Location GetMethodLocation() const OVERRIDE; |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 113 | |
| 114 | private: |
| 115 | InvokeDexCallingConvention calling_convention; |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 116 | |
| Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 117 | DISALLOW_COPY_AND_ASSIGN(InvokeDexCallingConventionVisitorX86_64); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 118 | }; |
| 119 | |
| 120 | class CodeGeneratorX86_64; |
| Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 121 | |
| Zheng Xu | ad4450e | 2015-04-17 18:48:56 +0800 | [diff] [blame] | 122 | class ParallelMoveResolverX86_64 : public ParallelMoveResolverWithSwap { |
| Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 123 | public: |
| 124 | ParallelMoveResolverX86_64(ArenaAllocator* allocator, CodeGeneratorX86_64* codegen) |
| Zheng Xu | ad4450e | 2015-04-17 18:48:56 +0800 | [diff] [blame] | 125 | : ParallelMoveResolverWithSwap(allocator), codegen_(codegen) {} |
| Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 126 | |
| Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 127 | void EmitMove(size_t index) OVERRIDE; |
| 128 | void EmitSwap(size_t index) OVERRIDE; |
| 129 | void SpillScratch(int reg) OVERRIDE; |
| 130 | void RestoreScratch(int reg) OVERRIDE; |
| Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 131 | |
| 132 | X86_64Assembler* GetAssembler() const; |
| 133 | |
| 134 | private: |
| Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 135 | void Exchange32(CpuRegister reg, int mem); |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 136 | void Exchange32(XmmRegister reg, int mem); |
| Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 137 | void Exchange32(int mem1, int mem2); |
| 138 | void Exchange64(CpuRegister reg, int mem); |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 139 | void Exchange64(XmmRegister reg, int mem); |
| Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 140 | void Exchange64(int mem1, int mem2); |
| Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 141 | |
| 142 | CodeGeneratorX86_64* const codegen_; |
| 143 | |
| 144 | DISALLOW_COPY_AND_ASSIGN(ParallelMoveResolverX86_64); |
| 145 | }; |
| 146 | |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 147 | class LocationsBuilderX86_64 : public HGraphVisitor { |
| 148 | public: |
| 149 | LocationsBuilderX86_64(HGraph* graph, CodeGeneratorX86_64* codegen) |
| 150 | : HGraphVisitor(graph), codegen_(codegen) {} |
| 151 | |
| Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 152 | #define DECLARE_VISIT_INSTRUCTION(name, super) \ |
| Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 153 | void Visit##name(H##name* instr) OVERRIDE; |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 154 | |
| Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 155 | FOR_EACH_CONCRETE_INSTRUCTION_COMMON(DECLARE_VISIT_INSTRUCTION) |
| 156 | FOR_EACH_CONCRETE_INSTRUCTION_X86_64(DECLARE_VISIT_INSTRUCTION) |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 157 | |
| 158 | #undef DECLARE_VISIT_INSTRUCTION |
| 159 | |
| Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 160 | void VisitInstruction(HInstruction* instruction) OVERRIDE { |
| 161 | LOG(FATAL) << "Unreachable instruction " << instruction->DebugName() |
| 162 | << " (id " << instruction->GetId() << ")"; |
| 163 | } |
| 164 | |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 165 | private: |
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 166 | void HandleInvoke(HInvoke* invoke); |
| 167 | void HandleBitwiseOperation(HBinaryOperation* operation); |
| Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 168 | void HandleShift(HBinaryOperation* operation); |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 169 | void HandleFieldSet(HInstruction* instruction, const FieldInfo& field_info); |
| 170 | void HandleFieldGet(HInstruction* instruction); |
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 171 | |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 172 | CodeGeneratorX86_64* const codegen_; |
| Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 173 | InvokeDexCallingConventionVisitorX86_64 parameter_visitor_; |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 174 | |
| 175 | DISALLOW_COPY_AND_ASSIGN(LocationsBuilderX86_64); |
| 176 | }; |
| 177 | |
| 178 | class InstructionCodeGeneratorX86_64 : public HGraphVisitor { |
| 179 | public: |
| 180 | InstructionCodeGeneratorX86_64(HGraph* graph, CodeGeneratorX86_64* codegen); |
| 181 | |
| Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 182 | #define DECLARE_VISIT_INSTRUCTION(name, super) \ |
| Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 183 | void Visit##name(H##name* instr) OVERRIDE; |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 184 | |
| Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 185 | FOR_EACH_CONCRETE_INSTRUCTION_COMMON(DECLARE_VISIT_INSTRUCTION) |
| 186 | FOR_EACH_CONCRETE_INSTRUCTION_X86_64(DECLARE_VISIT_INSTRUCTION) |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 187 | |
| 188 | #undef DECLARE_VISIT_INSTRUCTION |
| 189 | |
| Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 190 | void VisitInstruction(HInstruction* instruction) OVERRIDE { |
| 191 | LOG(FATAL) << "Unreachable instruction " << instruction->DebugName() |
| 192 | << " (id " << instruction->GetId() << ")"; |
| 193 | } |
| 194 | |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 195 | X86_64Assembler* GetAssembler() const { return assembler_; } |
| 196 | |
| 197 | private: |
| Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 198 | // Generate code for the given suspend check. If not null, `successor` |
| 199 | // is the block to branch to if the suspend check is not needed, and after |
| 200 | // the suspend call. |
| 201 | void GenerateSuspendCheck(HSuspendCheck* instruction, HBasicBlock* successor); |
| Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 202 | void GenerateClassInitializationCheck(SlowPathCode* slow_path, CpuRegister class_reg); |
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 203 | void HandleBitwiseOperation(HBinaryOperation* operation); |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 204 | void GenerateRemFP(HRem* rem); |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 205 | void DivRemOneOrMinusOne(HBinaryOperation* instruction); |
| Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 206 | void DivByPowerOfTwo(HDiv* instruction); |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 207 | void GenerateDivRemWithAnyConstant(HBinaryOperation* instruction); |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 208 | void GenerateDivRemIntegral(HBinaryOperation* instruction); |
| Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 209 | void HandleShift(HBinaryOperation* operation); |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 210 | void GenerateMemoryBarrier(MemBarrierKind kind); |
| Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 211 | void HandleFieldSet(HInstruction* instruction, |
| 212 | const FieldInfo& field_info, |
| 213 | bool value_can_be_null); |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 214 | void HandleFieldGet(HInstruction* instruction, const FieldInfo& field_info); |
| Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 215 | void GenerateImplicitNullCheck(HNullCheck* instruction); |
| 216 | void GenerateExplicitNullCheck(HNullCheck* instruction); |
| Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 217 | void PushOntoFPStack(Location source, uint32_t temp_offset, |
| 218 | uint32_t stack_adjustment, bool is_float); |
| Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 219 | void GenerateTestAndBranch(HInstruction* instruction, |
| 220 | Label* true_target, |
| 221 | Label* false_target, |
| 222 | Label* always_true_target); |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 223 | void GenerateCompareTestAndBranch(HIf* if_inst, |
| 224 | HCondition* condition, |
| 225 | Label* true_target, |
| 226 | Label* false_target, |
| 227 | Label* always_true_target); |
| 228 | void GenerateFPJumps(HCondition* cond, Label* true_label, Label* false_label); |
| David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 229 | void HandleGoto(HInstruction* got, HBasicBlock* successor); |
| Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 230 | |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 231 | X86_64Assembler* const assembler_; |
| 232 | CodeGeneratorX86_64* const codegen_; |
| 233 | |
| 234 | DISALLOW_COPY_AND_ASSIGN(InstructionCodeGeneratorX86_64); |
| 235 | }; |
| 236 | |
| Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 237 | // Class for fixups to jump tables. |
| 238 | class JumpTableRIPFixup; |
| 239 | |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 240 | class CodeGeneratorX86_64 : public CodeGenerator { |
| 241 | public: |
| Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 242 | CodeGeneratorX86_64(HGraph* graph, |
| 243 | const X86_64InstructionSetFeatures& isa_features, |
| Serban Constantinescu | ecc4366 | 2015-08-13 13:33:12 +0100 | [diff] [blame] | 244 | const CompilerOptions& compiler_options, |
| 245 | OptimizingCompilerStats* stats = nullptr); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 246 | virtual ~CodeGeneratorX86_64() {} |
| 247 | |
| Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 248 | void GenerateFrameEntry() OVERRIDE; |
| 249 | void GenerateFrameExit() OVERRIDE; |
| 250 | void Bind(HBasicBlock* block) OVERRIDE; |
| 251 | void Move(HInstruction* instruction, Location location, HInstruction* move_for) OVERRIDE; |
| Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 252 | void MoveConstant(Location destination, int32_t value) OVERRIDE; |
| Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 253 | void MoveLocation(Location dst, Location src, Primitive::Type dst_type) OVERRIDE; |
| 254 | void AddLocationAsTemp(Location location, LocationSummary* locations) OVERRIDE; |
| 255 | |
| Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 256 | size_t SaveCoreRegister(size_t stack_index, uint32_t reg_id) OVERRIDE; |
| 257 | size_t RestoreCoreRegister(size_t stack_index, uint32_t reg_id) OVERRIDE; |
| 258 | size_t SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) OVERRIDE; |
| 259 | size_t RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) OVERRIDE; |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 260 | |
| Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 261 | // Generate code to invoke a runtime entry point. |
| Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 262 | void InvokeRuntime(QuickEntrypointEnum entrypoint, |
| 263 | HInstruction* instruction, |
| 264 | uint32_t dex_pc, |
| 265 | SlowPathCode* slow_path) OVERRIDE; |
| 266 | |
| 267 | void InvokeRuntime(int32_t entry_point_offset, |
| Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 268 | HInstruction* instruction, |
| 269 | uint32_t dex_pc, |
| 270 | SlowPathCode* slow_path); |
| 271 | |
| Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 272 | size_t GetWordSize() const OVERRIDE { |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 273 | return kX86_64WordSize; |
| 274 | } |
| 275 | |
| Mark Mendell | f85a9ca | 2015-01-13 09:20:58 -0500 | [diff] [blame] | 276 | size_t GetFloatingPointSpillSlotSize() const OVERRIDE { |
| 277 | return kX86_64WordSize; |
| 278 | } |
| 279 | |
| Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 280 | HGraphVisitor* GetLocationBuilder() OVERRIDE { |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 281 | return &location_builder_; |
| 282 | } |
| 283 | |
| Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 284 | HGraphVisitor* GetInstructionVisitor() OVERRIDE { |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 285 | return &instruction_visitor_; |
| 286 | } |
| 287 | |
| Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 288 | X86_64Assembler* GetAssembler() OVERRIDE { |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 289 | return &assembler_; |
| 290 | } |
| 291 | |
| Alexandre Rames | eb7b739 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 292 | const X86_64Assembler& GetAssembler() const OVERRIDE { |
| 293 | return assembler_; |
| 294 | } |
| 295 | |
| Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 296 | ParallelMoveResolverX86_64* GetMoveResolver() OVERRIDE { |
| Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 297 | return &move_resolver_; |
| 298 | } |
| 299 | |
| Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 300 | uintptr_t GetAddressOf(HBasicBlock* block) const OVERRIDE { |
| 301 | return GetLabelOf(block)->Position(); |
| 302 | } |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 303 | |
| Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 304 | Location GetStackLocation(HLoadLocal* load) const OVERRIDE; |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 305 | |
| Nicolas Geoffray | 9889396 | 2015-01-21 12:32:32 +0000 | [diff] [blame] | 306 | void SetupBlockedRegisters(bool is_baseline) const OVERRIDE; |
| Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 307 | Location AllocateFreeRegister(Primitive::Type type) const OVERRIDE; |
| 308 | void DumpCoreRegister(std::ostream& stream, int reg) const OVERRIDE; |
| 309 | void DumpFloatingPointRegister(std::ostream& stream, int reg) const OVERRIDE; |
| Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 310 | void Finalize(CodeAllocator* allocator) OVERRIDE; |
| Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 311 | |
| 312 | InstructionSet GetInstructionSet() const OVERRIDE { |
| Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 313 | return InstructionSet::kX86_64; |
| 314 | } |
| 315 | |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 316 | // Emit a write barrier. |
| Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 317 | void MarkGCCard(CpuRegister temp, |
| 318 | CpuRegister card, |
| 319 | CpuRegister object, |
| 320 | CpuRegister value, |
| 321 | bool value_can_be_null); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 322 | |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 323 | // Helper method to move a value between two locations. |
| 324 | void Move(Location destination, Location source); |
| 325 | |
| Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 326 | Label* GetLabelOf(HBasicBlock* block) const { |
| Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 327 | return CommonGetLabelOf<Label>(block_labels_, block); |
| Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 328 | } |
| 329 | |
| Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 330 | void Initialize() OVERRIDE { |
| Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 331 | block_labels_ = CommonInitializeLabels<Label>(); |
| Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 332 | } |
| 333 | |
| Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 334 | bool NeedsTwoRegisters(Primitive::Type type ATTRIBUTE_UNUSED) const OVERRIDE { |
| 335 | return false; |
| 336 | } |
| 337 | |
| Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 338 | void GenerateStaticOrDirectCall(HInvokeStaticOrDirect* invoke, Location temp) OVERRIDE; |
| 339 | void GenerateVirtualCall(HInvokeVirtual* invoke, Location temp) OVERRIDE; |
| 340 | |
| 341 | void MoveFromReturnRegister(Location trg, Primitive::Type type) OVERRIDE; |
| Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 342 | |
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 343 | void EmitLinkerPatches(ArenaVector<LinkerPatch>* linker_patches) OVERRIDE; |
| 344 | |
| Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 345 | const X86_64InstructionSetFeatures& GetInstructionSetFeatures() const { |
| 346 | return isa_features_; |
| 347 | } |
| 348 | |
| Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 349 | int ConstantAreaStart() const { |
| 350 | return constant_area_start_; |
| 351 | } |
| 352 | |
| 353 | Address LiteralDoubleAddress(double v); |
| 354 | Address LiteralFloatAddress(float v); |
| 355 | Address LiteralInt32Address(int32_t v); |
| 356 | Address LiteralInt64Address(int64_t v); |
| 357 | |
| Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 358 | // Load a 64 bit value into a register in the most efficient manner. |
| 359 | void Load64BitValue(CpuRegister dest, int64_t value); |
| Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 360 | Address LiteralCaseTable(HPackedSwitch* switch_instr); |
| Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 361 | |
| Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 362 | // Store a 64 bit value into a DoubleStackSlot in the most efficient manner. |
| 363 | void Store64BitValueToStack(Location dest, int64_t value); |
| 364 | |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 365 | private: |
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 366 | struct PcRelativeDexCacheAccessInfo { |
| 367 | PcRelativeDexCacheAccessInfo(const DexFile& dex_file, uint32_t element_off) |
| 368 | : target_dex_file(dex_file), element_offset(element_off), label() { } |
| 369 | |
| 370 | const DexFile& target_dex_file; |
| 371 | uint32_t element_offset; |
| 372 | Label label; |
| 373 | }; |
| 374 | |
| Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 375 | // Labels for each block that will be compiled. |
| Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 376 | Label* block_labels_; // Indexed by block id. |
| Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 377 | Label frame_entry_label_; |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 378 | LocationsBuilderX86_64 location_builder_; |
| 379 | InstructionCodeGeneratorX86_64 instruction_visitor_; |
| Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 380 | ParallelMoveResolverX86_64 move_resolver_; |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 381 | X86_64Assembler assembler_; |
| Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 382 | const X86_64InstructionSetFeatures& isa_features_; |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 383 | |
| Mark Mendell | 39dcf55 | 2015-04-09 20:42:42 -0400 | [diff] [blame] | 384 | // Offset to the start of the constant area in the assembled code. |
| Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 385 | // Used for fixups to the constant area. |
| 386 | int constant_area_start_; |
| 387 | |
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 388 | // Method patch info. Using ArenaDeque<> which retains element addresses on push/emplace_back(). |
| 389 | ArenaDeque<MethodPatchInfo<Label>> method_patches_; |
| 390 | ArenaDeque<MethodPatchInfo<Label>> relative_call_patches_; |
| 391 | // PC-relative DexCache access info. |
| 392 | ArenaDeque<PcRelativeDexCacheAccessInfo> pc_rel_dex_cache_patches_; |
| 393 | |
| 394 | // When we don't know the proper offset for the value, we use kDummy32BitOffset. |
| 395 | // We will fix this up in the linker later to have the right value. |
| 396 | static constexpr int32_t kDummy32BitOffset = 256; |
| 397 | |
| Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 398 | // Fixups for jump tables need to be handled specially. |
| 399 | ArenaVector<JumpTableRIPFixup*> fixups_to_jump_tables_; |
| 400 | |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 401 | DISALLOW_COPY_AND_ASSIGN(CodeGeneratorX86_64); |
| 402 | }; |
| 403 | |
| 404 | } // namespace x86_64 |
| 405 | } // namespace art |
| 406 | |
| 407 | #endif // ART_COMPILER_OPTIMIZING_CODE_GENERATOR_X86_64_H_ |