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 | |
Mark P Mendell | 17077d8 | 2015-12-16 19:15:59 +0000 | [diff] [blame] | 20 | #include "arch/x86_64/instruction_set_features_x86_64.h" |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 21 | #include "code_generator.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. |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 31 | static constexpr size_t kX86_64WordSize = static_cast<size_t>(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 | |
Mark Mendell | a4f1220 | 2015-08-06 15:23:34 -0400 | [diff] [blame] | 50 | // These XMM registers are non-volatile in ART ABI, but volatile in native ABI. |
| 51 | // If the ART ABI changes, this list must be updated. It is used to ensure that |
| 52 | // these are not clobbered by any direct call to native code (such as math intrinsics). |
| 53 | static constexpr FloatRegister non_volatile_xmm_regs[] = { XMM12, XMM13, XMM14, XMM15 }; |
| 54 | |
| 55 | |
Nicolas Geoffray | d75948a | 2015-03-27 09:53:16 +0000 | [diff] [blame] | 56 | class InvokeRuntimeCallingConvention : public CallingConvention<Register, FloatRegister> { |
| 57 | public: |
| 58 | InvokeRuntimeCallingConvention() |
| 59 | : CallingConvention(kRuntimeParameterCoreRegisters, |
| 60 | kRuntimeParameterCoreRegistersLength, |
| 61 | kRuntimeParameterFpuRegisters, |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 62 | kRuntimeParameterFpuRegistersLength, |
| 63 | kX86_64PointerSize) {} |
Nicolas Geoffray | d75948a | 2015-03-27 09:53:16 +0000 | [diff] [blame] | 64 | |
| 65 | private: |
| 66 | DISALLOW_COPY_AND_ASSIGN(InvokeRuntimeCallingConvention); |
| 67 | }; |
| 68 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 69 | class InvokeDexCallingConvention : public CallingConvention<Register, FloatRegister> { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 70 | public: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 71 | InvokeDexCallingConvention() : CallingConvention( |
| 72 | kParameterCoreRegisters, |
| 73 | kParameterCoreRegistersLength, |
| 74 | kParameterFloatRegisters, |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 75 | kParameterFloatRegistersLength, |
| 76 | kX86_64PointerSize) {} |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 77 | |
| 78 | private: |
| 79 | DISALLOW_COPY_AND_ASSIGN(InvokeDexCallingConvention); |
| 80 | }; |
| 81 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 82 | class FieldAccessCallingConventionX86_64 : public FieldAccessCallingConvention { |
| 83 | public: |
| 84 | FieldAccessCallingConventionX86_64() {} |
| 85 | |
| 86 | Location GetObjectLocation() const OVERRIDE { |
| 87 | return Location::RegisterLocation(RSI); |
| 88 | } |
| 89 | Location GetFieldIndexLocation() const OVERRIDE { |
| 90 | return Location::RegisterLocation(RDI); |
| 91 | } |
| 92 | Location GetReturnLocation(Primitive::Type type ATTRIBUTE_UNUSED) const OVERRIDE { |
| 93 | return Location::RegisterLocation(RAX); |
| 94 | } |
| 95 | Location GetSetValueLocation(Primitive::Type type, bool is_instance) const OVERRIDE { |
| 96 | return Primitive::Is64BitType(type) |
| 97 | ? Location::RegisterLocation(RDX) |
| 98 | : (is_instance |
| 99 | ? Location::RegisterLocation(RDX) |
| 100 | : Location::RegisterLocation(RSI)); |
| 101 | } |
| 102 | Location GetFpuLocation(Primitive::Type type ATTRIBUTE_UNUSED) const OVERRIDE { |
| 103 | return Location::FpuRegisterLocation(XMM0); |
| 104 | } |
| 105 | |
| 106 | private: |
| 107 | DISALLOW_COPY_AND_ASSIGN(FieldAccessCallingConventionX86_64); |
| 108 | }; |
| 109 | |
| 110 | |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 111 | class InvokeDexCallingConventionVisitorX86_64 : public InvokeDexCallingConventionVisitor { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 112 | public: |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 113 | InvokeDexCallingConventionVisitorX86_64() {} |
| 114 | virtual ~InvokeDexCallingConventionVisitorX86_64() {} |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 115 | |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 116 | Location GetNextLocation(Primitive::Type type) OVERRIDE; |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 117 | Location GetReturnLocation(Primitive::Type type) const OVERRIDE; |
| 118 | Location GetMethodLocation() const OVERRIDE; |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 119 | |
| 120 | private: |
| 121 | InvokeDexCallingConvention calling_convention; |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 122 | |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 123 | DISALLOW_COPY_AND_ASSIGN(InvokeDexCallingConventionVisitorX86_64); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 124 | }; |
| 125 | |
| 126 | class CodeGeneratorX86_64; |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 127 | |
Zheng Xu | ad4450e | 2015-04-17 18:48:56 +0800 | [diff] [blame] | 128 | class ParallelMoveResolverX86_64 : public ParallelMoveResolverWithSwap { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 129 | public: |
| 130 | ParallelMoveResolverX86_64(ArenaAllocator* allocator, CodeGeneratorX86_64* codegen) |
Zheng Xu | ad4450e | 2015-04-17 18:48:56 +0800 | [diff] [blame] | 131 | : ParallelMoveResolverWithSwap(allocator), codegen_(codegen) {} |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 132 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 133 | void EmitMove(size_t index) OVERRIDE; |
| 134 | void EmitSwap(size_t index) OVERRIDE; |
| 135 | void SpillScratch(int reg) OVERRIDE; |
| 136 | void RestoreScratch(int reg) OVERRIDE; |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 137 | |
| 138 | X86_64Assembler* GetAssembler() const; |
| 139 | |
| 140 | private: |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 141 | void Exchange32(CpuRegister reg, int mem); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 142 | void Exchange32(XmmRegister reg, int mem); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 143 | void Exchange32(int mem1, int mem2); |
Mark Mendell | 8a1c728 | 2015-06-29 15:41:28 -0400 | [diff] [blame] | 144 | void Exchange64(CpuRegister reg1, CpuRegister reg2); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 145 | void Exchange64(CpuRegister reg, int mem); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 146 | void Exchange64(XmmRegister reg, int mem); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 147 | void Exchange64(int mem1, int mem2); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 148 | |
| 149 | CodeGeneratorX86_64* const codegen_; |
| 150 | |
| 151 | DISALLOW_COPY_AND_ASSIGN(ParallelMoveResolverX86_64); |
| 152 | }; |
| 153 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 154 | class LocationsBuilderX86_64 : public HGraphVisitor { |
| 155 | public: |
| 156 | LocationsBuilderX86_64(HGraph* graph, CodeGeneratorX86_64* codegen) |
| 157 | : HGraphVisitor(graph), codegen_(codegen) {} |
| 158 | |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 159 | #define DECLARE_VISIT_INSTRUCTION(name, super) \ |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 160 | void Visit##name(H##name* instr) OVERRIDE; |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 161 | |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 162 | FOR_EACH_CONCRETE_INSTRUCTION_COMMON(DECLARE_VISIT_INSTRUCTION) |
| 163 | FOR_EACH_CONCRETE_INSTRUCTION_X86_64(DECLARE_VISIT_INSTRUCTION) |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 164 | |
| 165 | #undef DECLARE_VISIT_INSTRUCTION |
| 166 | |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 167 | void VisitInstruction(HInstruction* instruction) OVERRIDE { |
| 168 | LOG(FATAL) << "Unreachable instruction " << instruction->DebugName() |
| 169 | << " (id " << instruction->GetId() << ")"; |
| 170 | } |
| 171 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 172 | private: |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 173 | void HandleInvoke(HInvoke* invoke); |
| 174 | void HandleBitwiseOperation(HBinaryOperation* operation); |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 175 | void HandleCondition(HCondition* condition); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 176 | void HandleShift(HBinaryOperation* operation); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 177 | void HandleFieldSet(HInstruction* instruction, const FieldInfo& field_info); |
| 178 | void HandleFieldGet(HInstruction* instruction); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 179 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 180 | CodeGeneratorX86_64* const codegen_; |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 181 | InvokeDexCallingConventionVisitorX86_64 parameter_visitor_; |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 182 | |
| 183 | DISALLOW_COPY_AND_ASSIGN(LocationsBuilderX86_64); |
| 184 | }; |
| 185 | |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 186 | class InstructionCodeGeneratorX86_64 : public InstructionCodeGenerator { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 187 | public: |
| 188 | InstructionCodeGeneratorX86_64(HGraph* graph, CodeGeneratorX86_64* codegen); |
| 189 | |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 190 | #define DECLARE_VISIT_INSTRUCTION(name, super) \ |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 191 | void Visit##name(H##name* instr) OVERRIDE; |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 192 | |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 193 | FOR_EACH_CONCRETE_INSTRUCTION_COMMON(DECLARE_VISIT_INSTRUCTION) |
| 194 | FOR_EACH_CONCRETE_INSTRUCTION_X86_64(DECLARE_VISIT_INSTRUCTION) |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 195 | |
| 196 | #undef DECLARE_VISIT_INSTRUCTION |
| 197 | |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 198 | void VisitInstruction(HInstruction* instruction) OVERRIDE { |
| 199 | LOG(FATAL) << "Unreachable instruction " << instruction->DebugName() |
| 200 | << " (id " << instruction->GetId() << ")"; |
| 201 | } |
| 202 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 203 | X86_64Assembler* GetAssembler() const { return assembler_; } |
| 204 | |
| 205 | private: |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 206 | // Generate code for the given suspend check. If not null, `successor` |
| 207 | // is the block to branch to if the suspend check is not needed, and after |
| 208 | // the suspend call. |
| 209 | void GenerateSuspendCheck(HSuspendCheck* instruction, HBasicBlock* successor); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 210 | void GenerateClassInitializationCheck(SlowPathCode* slow_path, CpuRegister class_reg); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 211 | void HandleBitwiseOperation(HBinaryOperation* operation); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 212 | void GenerateRemFP(HRem* rem); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 213 | void DivRemOneOrMinusOne(HBinaryOperation* instruction); |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 214 | void DivByPowerOfTwo(HDiv* instruction); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 215 | void GenerateDivRemWithAnyConstant(HBinaryOperation* instruction); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 216 | void GenerateDivRemIntegral(HBinaryOperation* instruction); |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 217 | void HandleCondition(HCondition* condition); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 218 | void HandleShift(HBinaryOperation* operation); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 219 | |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 220 | void HandleFieldSet(HInstruction* instruction, |
| 221 | const FieldInfo& field_info, |
| 222 | bool value_can_be_null); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 223 | void HandleFieldGet(HInstruction* instruction, const FieldInfo& field_info); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 224 | |
| 225 | // Generate a heap reference load using one register `out`: |
| 226 | // |
| 227 | // out <- *(out + offset) |
| 228 | // |
| 229 | // while honoring heap poisoning and/or read barriers (if any). |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 230 | // |
| 231 | // Location `maybe_temp` is used when generating a read barrier and |
| 232 | // shall be a register in that case; it may be an invalid location |
| 233 | // otherwise. |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 234 | void GenerateReferenceLoadOneRegister(HInstruction* instruction, |
| 235 | Location out, |
| 236 | uint32_t offset, |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 237 | Location maybe_temp); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 238 | // Generate a heap reference load using two different registers |
| 239 | // `out` and `obj`: |
| 240 | // |
| 241 | // out <- *(obj + offset) |
| 242 | // |
| 243 | // while honoring heap poisoning and/or read barriers (if any). |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 244 | // |
| 245 | // Location `maybe_temp` is used when generating a Baker's (fast |
| 246 | // path) read barrier and shall be a register in that case; it may |
| 247 | // be an invalid location otherwise. |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 248 | void GenerateReferenceLoadTwoRegisters(HInstruction* instruction, |
| 249 | Location out, |
| 250 | Location obj, |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 251 | uint32_t offset); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 252 | // Generate a GC root reference load: |
| 253 | // |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 254 | // root <- *address |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 255 | // |
| 256 | // while honoring read barriers (if any). |
| 257 | void GenerateGcRootFieldLoad(HInstruction* instruction, |
| 258 | Location root, |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 259 | const Address& address, |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 260 | Label* fixup_label = nullptr, |
| 261 | bool requires_read_barrier = kEmitCompilerReadBarrier); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 262 | |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 263 | void PushOntoFPStack(Location source, uint32_t temp_offset, |
| 264 | uint32_t stack_adjustment, bool is_float); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 265 | void GenerateCompareTest(HCondition* condition); |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 266 | template<class LabelType> |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 267 | void GenerateTestAndBranch(HInstruction* instruction, |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 268 | size_t condition_input_index, |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 269 | LabelType* true_target, |
| 270 | LabelType* false_target); |
| 271 | template<class LabelType> |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 272 | void GenerateCompareTestAndBranch(HCondition* condition, |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 273 | LabelType* true_target, |
| 274 | LabelType* false_target); |
| 275 | template<class LabelType> |
| 276 | void GenerateFPJumps(HCondition* cond, LabelType* true_label, LabelType* false_label); |
| 277 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 278 | void HandleGoto(HInstruction* got, HBasicBlock* successor); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 279 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 280 | X86_64Assembler* const assembler_; |
| 281 | CodeGeneratorX86_64* const codegen_; |
| 282 | |
| 283 | DISALLOW_COPY_AND_ASSIGN(InstructionCodeGeneratorX86_64); |
| 284 | }; |
| 285 | |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 286 | // Class for fixups to jump tables. |
| 287 | class JumpTableRIPFixup; |
| 288 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 289 | class CodeGeneratorX86_64 : public CodeGenerator { |
| 290 | public: |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 291 | CodeGeneratorX86_64(HGraph* graph, |
| 292 | const X86_64InstructionSetFeatures& isa_features, |
Serban Constantinescu | ecc4366 | 2015-08-13 13:33:12 +0100 | [diff] [blame] | 293 | const CompilerOptions& compiler_options, |
| 294 | OptimizingCompilerStats* stats = nullptr); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 295 | virtual ~CodeGeneratorX86_64() {} |
| 296 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 297 | void GenerateFrameEntry() OVERRIDE; |
| 298 | void GenerateFrameExit() OVERRIDE; |
| 299 | void Bind(HBasicBlock* block) OVERRIDE; |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 300 | void MoveConstant(Location destination, int32_t value) OVERRIDE; |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 301 | void MoveLocation(Location dst, Location src, Primitive::Type dst_type) OVERRIDE; |
| 302 | void AddLocationAsTemp(Location location, LocationSummary* locations) OVERRIDE; |
| 303 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 304 | size_t SaveCoreRegister(size_t stack_index, uint32_t reg_id) OVERRIDE; |
| 305 | size_t RestoreCoreRegister(size_t stack_index, uint32_t reg_id) OVERRIDE; |
| 306 | size_t SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) OVERRIDE; |
| 307 | size_t RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) OVERRIDE; |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 308 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 309 | // Generate code to invoke a runtime entry point. |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 310 | void InvokeRuntime(QuickEntrypointEnum entrypoint, |
| 311 | HInstruction* instruction, |
| 312 | uint32_t dex_pc, |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 313 | SlowPathCode* slow_path = nullptr) OVERRIDE; |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 314 | |
Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 315 | // Generate code to invoke a runtime entry point, but do not record |
| 316 | // PC-related information in a stack map. |
| 317 | void InvokeRuntimeWithoutRecordingPcInfo(int32_t entry_point_offset, |
| 318 | HInstruction* instruction, |
| 319 | SlowPathCode* slow_path); |
| 320 | |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 321 | void GenerateInvokeRuntime(int32_t entry_point_offset); |
| 322 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 323 | size_t GetWordSize() const OVERRIDE { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 324 | return kX86_64WordSize; |
| 325 | } |
| 326 | |
Mark Mendell | f85a9ca | 2015-01-13 09:20:58 -0500 | [diff] [blame] | 327 | size_t GetFloatingPointSpillSlotSize() const OVERRIDE { |
| 328 | return kX86_64WordSize; |
| 329 | } |
| 330 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 331 | HGraphVisitor* GetLocationBuilder() OVERRIDE { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 332 | return &location_builder_; |
| 333 | } |
| 334 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 335 | HGraphVisitor* GetInstructionVisitor() OVERRIDE { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 336 | return &instruction_visitor_; |
| 337 | } |
| 338 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 339 | X86_64Assembler* GetAssembler() OVERRIDE { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 340 | return &assembler_; |
| 341 | } |
| 342 | |
Alexandre Rames | eb7b739 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 343 | const X86_64Assembler& GetAssembler() const OVERRIDE { |
| 344 | return assembler_; |
| 345 | } |
| 346 | |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 347 | ParallelMoveResolverX86_64* GetMoveResolver() OVERRIDE { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 348 | return &move_resolver_; |
| 349 | } |
| 350 | |
Alexandre Rames | c01a664 | 2016-04-15 11:54:06 +0100 | [diff] [blame] | 351 | uintptr_t GetAddressOf(HBasicBlock* block) OVERRIDE { |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 352 | return GetLabelOf(block)->Position(); |
| 353 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 354 | |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 355 | void SetupBlockedRegisters() const OVERRIDE; |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 356 | void DumpCoreRegister(std::ostream& stream, int reg) const OVERRIDE; |
| 357 | void DumpFloatingPointRegister(std::ostream& stream, int reg) const OVERRIDE; |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 358 | void Finalize(CodeAllocator* allocator) OVERRIDE; |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 359 | |
| 360 | InstructionSet GetInstructionSet() const OVERRIDE { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 361 | return InstructionSet::kX86_64; |
| 362 | } |
| 363 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 364 | // Emit a write barrier. |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 365 | void MarkGCCard(CpuRegister temp, |
| 366 | CpuRegister card, |
| 367 | CpuRegister object, |
| 368 | CpuRegister value, |
| 369 | bool value_can_be_null); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 370 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 371 | void GenerateMemoryBarrier(MemBarrierKind kind); |
| 372 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 373 | // Helper method to move a value between two locations. |
| 374 | void Move(Location destination, Location source); |
| 375 | |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 376 | Label* GetLabelOf(HBasicBlock* block) const { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 377 | return CommonGetLabelOf<Label>(block_labels_, block); |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 378 | } |
| 379 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 380 | void Initialize() OVERRIDE { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 381 | block_labels_ = CommonInitializeLabels<Label>(); |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 382 | } |
| 383 | |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 384 | bool NeedsTwoRegisters(Primitive::Type type ATTRIBUTE_UNUSED) const OVERRIDE { |
| 385 | return false; |
| 386 | } |
| 387 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 388 | // Check if the desired_string_load_kind is supported. If it is, return it, |
| 389 | // otherwise return a fall-back kind that should be used instead. |
| 390 | HLoadString::LoadKind GetSupportedLoadStringKind( |
| 391 | HLoadString::LoadKind desired_string_load_kind) OVERRIDE; |
| 392 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 393 | // Check if the desired_class_load_kind is supported. If it is, return it, |
| 394 | // otherwise return a fall-back kind that should be used instead. |
| 395 | HLoadClass::LoadKind GetSupportedLoadClassKind( |
| 396 | HLoadClass::LoadKind desired_class_load_kind) OVERRIDE; |
| 397 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 398 | // Check if the desired_dispatch_info is supported. If it is, return it, |
| 399 | // otherwise return a fall-back info that should be used instead. |
| 400 | HInvokeStaticOrDirect::DispatchInfo GetSupportedInvokeStaticOrDirectDispatch( |
| 401 | const HInvokeStaticOrDirect::DispatchInfo& desired_dispatch_info, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 402 | HInvokeStaticOrDirect* invoke) OVERRIDE; |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 403 | |
Serguei Katkov | 288c7a8 | 2016-05-16 11:53:15 +0600 | [diff] [blame] | 404 | Location GenerateCalleeMethodStaticOrDirectCall(HInvokeStaticOrDirect* invoke, Location temp); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 405 | void GenerateStaticOrDirectCall(HInvokeStaticOrDirect* invoke, Location temp) OVERRIDE; |
| 406 | void GenerateVirtualCall(HInvokeVirtual* invoke, Location temp) OVERRIDE; |
| 407 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 408 | void RecordSimplePatch(); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 409 | void RecordBootStringPatch(HLoadString* load_string); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 410 | void RecordTypePatch(HLoadClass* load_class); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 411 | Label* NewStringBssEntryPatch(HLoadString* load_string); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 412 | Label* NewPcRelativeDexCacheArrayPatch(const DexFile& dex_file, uint32_t element_offset); |
| 413 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 414 | void MoveFromReturnRegister(Location trg, Primitive::Type type) OVERRIDE; |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 415 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 416 | void EmitLinkerPatches(ArenaVector<LinkerPatch>* linker_patches) OVERRIDE; |
| 417 | |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 418 | const X86_64InstructionSetFeatures& GetInstructionSetFeatures() const { |
| 419 | return isa_features_; |
| 420 | } |
| 421 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 422 | // Fast path implementation of ReadBarrier::Barrier for a heap |
| 423 | // reference field load when Baker's read barriers are used. |
| 424 | void GenerateFieldLoadWithBakerReadBarrier(HInstruction* instruction, |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 425 | Location ref, |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 426 | CpuRegister obj, |
| 427 | uint32_t offset, |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 428 | bool needs_null_check); |
| 429 | // Fast path implementation of ReadBarrier::Barrier for a heap |
| 430 | // reference array load when Baker's read barriers are used. |
| 431 | void GenerateArrayLoadWithBakerReadBarrier(HInstruction* instruction, |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 432 | Location ref, |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 433 | CpuRegister obj, |
| 434 | uint32_t data_offset, |
| 435 | Location index, |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 436 | bool needs_null_check); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame^] | 437 | // Factored implementation, used by GenerateFieldLoadWithBakerReadBarrier, |
| 438 | // GenerateArrayLoadWithBakerReadBarrier and some intrinsics. |
| 439 | // |
| 440 | // Load the object reference located at address `src`, held by |
| 441 | // object `obj`, into `ref`, and mark it if needed. The base of |
| 442 | // address `src` must be `obj`. |
| 443 | // |
| 444 | // If `always_update_field` is true, the value of the reference is |
| 445 | // atomically updated in the holder (`obj`). This operation |
| 446 | // requires two temporary registers, which must be provided as |
| 447 | // non-null pointers (`temp1` and `temp2`). |
Sang, Chunlei | 0fcd2b8 | 2016-04-05 17:12:59 +0800 | [diff] [blame] | 448 | void GenerateReferenceLoadWithBakerReadBarrier(HInstruction* instruction, |
| 449 | Location ref, |
| 450 | CpuRegister obj, |
| 451 | const Address& src, |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame^] | 452 | bool needs_null_check, |
| 453 | bool always_update_field = false, |
| 454 | CpuRegister* temp1 = nullptr, |
| 455 | CpuRegister* temp2 = nullptr); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 456 | |
| 457 | // Generate a read barrier for a heap reference within `instruction` |
| 458 | // using a slow path. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 459 | // |
| 460 | // A read barrier for an object reference read from the heap is |
| 461 | // implemented as a call to the artReadBarrierSlow runtime entry |
| 462 | // point, which is passed the values in locations `ref`, `obj`, and |
| 463 | // `offset`: |
| 464 | // |
| 465 | // mirror::Object* artReadBarrierSlow(mirror::Object* ref, |
| 466 | // mirror::Object* obj, |
| 467 | // uint32_t offset); |
| 468 | // |
| 469 | // The `out` location contains the value returned by |
| 470 | // artReadBarrierSlow. |
| 471 | // |
| 472 | // When `index` provided (i.e., when it is different from |
| 473 | // Location::NoLocation()), the offset value passed to |
| 474 | // artReadBarrierSlow is adjusted to take `index` into account. |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 475 | void GenerateReadBarrierSlow(HInstruction* instruction, |
| 476 | Location out, |
| 477 | Location ref, |
| 478 | Location obj, |
| 479 | uint32_t offset, |
| 480 | Location index = Location::NoLocation()); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 481 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 482 | // If read barriers are enabled, generate a read barrier for a heap |
| 483 | // reference using a slow path. If heap poisoning is enabled, also |
| 484 | // unpoison the reference in `out`. |
| 485 | void MaybeGenerateReadBarrierSlow(HInstruction* instruction, |
| 486 | Location out, |
| 487 | Location ref, |
| 488 | Location obj, |
| 489 | uint32_t offset, |
| 490 | Location index = Location::NoLocation()); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 491 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 492 | // Generate a read barrier for a GC root within `instruction` using |
| 493 | // a slow path. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 494 | // |
| 495 | // A read barrier for an object reference GC root is implemented as |
| 496 | // a call to the artReadBarrierForRootSlow runtime entry point, |
| 497 | // which is passed the value in location `root`: |
| 498 | // |
| 499 | // mirror::Object* artReadBarrierForRootSlow(GcRoot<mirror::Object>* root); |
| 500 | // |
| 501 | // The `out` location contains the value returned by |
| 502 | // artReadBarrierForRootSlow. |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 503 | void GenerateReadBarrierForRootSlow(HInstruction* instruction, Location out, Location root); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 504 | |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 505 | int ConstantAreaStart() const { |
| 506 | return constant_area_start_; |
| 507 | } |
| 508 | |
| 509 | Address LiteralDoubleAddress(double v); |
| 510 | Address LiteralFloatAddress(float v); |
| 511 | Address LiteralInt32Address(int32_t v); |
| 512 | Address LiteralInt64Address(int64_t v); |
| 513 | |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 514 | // Load a 32/64-bit value into a register in the most efficient manner. |
Aart Bik | c5d4754 | 2016-01-27 17:00:35 -0800 | [diff] [blame] | 515 | void Load32BitValue(CpuRegister dest, int32_t value); |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 516 | void Load64BitValue(CpuRegister dest, int64_t value); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 517 | void Load32BitValue(XmmRegister dest, int32_t value); |
| 518 | void Load64BitValue(XmmRegister dest, int64_t value); |
| 519 | void Load32BitValue(XmmRegister dest, float value); |
| 520 | void Load64BitValue(XmmRegister dest, double value); |
Aart Bik | c5d4754 | 2016-01-27 17:00:35 -0800 | [diff] [blame] | 521 | |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 522 | // Compare a register with a 32/64-bit value in the most efficient manner. |
| 523 | void Compare32BitValue(CpuRegister dest, int32_t value); |
| 524 | void Compare64BitValue(CpuRegister dest, int64_t value); |
| 525 | |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 526 | // Compare int values. Supports register locations for `lhs`. |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 527 | void GenerateIntCompare(Location lhs, Location rhs); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 528 | void GenerateIntCompare(CpuRegister lhs, Location rhs); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 529 | |
| 530 | // Compare long values. Supports only register locations for `lhs`. |
| 531 | void GenerateLongCompare(Location lhs, Location rhs); |
| 532 | |
| 533 | // Construct address for array access. |
| 534 | static Address ArrayAddress(CpuRegister obj, |
| 535 | Location index, |
| 536 | ScaleFactor scale, |
| 537 | uint32_t data_offset); |
| 538 | |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 539 | Address LiteralCaseTable(HPackedSwitch* switch_instr); |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 540 | |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 541 | // Store a 64 bit value into a DoubleStackSlot in the most efficient manner. |
| 542 | void Store64BitValueToStack(Location dest, int64_t value); |
| 543 | |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 544 | // Assign a 64 bit constant to an address. |
| 545 | void MoveInt64ToAddress(const Address& addr_low, |
| 546 | const Address& addr_high, |
| 547 | int64_t v, |
| 548 | HInstruction* instruction); |
| 549 | |
Mark P Mendell | 17077d8 | 2015-12-16 19:15:59 +0000 | [diff] [blame] | 550 | // Ensure that prior stores complete to memory before subsequent loads. |
| 551 | // The locked add implementation will avoid serializing device memory, but will |
Mark Mendell | 7aa04a1 | 2016-01-27 22:39:07 -0500 | [diff] [blame] | 552 | // touch (but not change) the top of the stack. |
| 553 | // The 'non_temporal' parameter should be used to ensure ordering of non-temporal stores. |
Mark P Mendell | 17077d8 | 2015-12-16 19:15:59 +0000 | [diff] [blame] | 554 | void MemoryFence(bool force_mfence = false) { |
Mark Mendell | 7aa04a1 | 2016-01-27 22:39:07 -0500 | [diff] [blame] | 555 | if (!force_mfence) { |
Mark P Mendell | 17077d8 | 2015-12-16 19:15:59 +0000 | [diff] [blame] | 556 | assembler_.lock()->addl(Address(CpuRegister(RSP), 0), Immediate(0)); |
| 557 | } else { |
| 558 | assembler_.mfence(); |
| 559 | } |
| 560 | } |
| 561 | |
Roland Levillain | f41f956 | 2016-09-14 19:26:48 +0100 | [diff] [blame] | 562 | void GenerateNop() OVERRIDE; |
| 563 | void GenerateImplicitNullCheck(HNullCheck* instruction) OVERRIDE; |
| 564 | void GenerateExplicitNullCheck(HNullCheck* instruction) OVERRIDE; |
David Srbecky | c7098ff | 2016-02-09 14:30:11 +0000 | [diff] [blame] | 565 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 566 | // When we don't know the proper offset for the value, we use kDummy32BitOffset. |
| 567 | // We will fix this up in the linker later to have the right value. |
| 568 | static constexpr int32_t kDummy32BitOffset = 256; |
| 569 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 570 | private: |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 571 | template <LinkerPatch (*Factory)(size_t, const DexFile*, uint32_t, uint32_t)> |
| 572 | static void EmitPcRelativeLinkerPatches(const ArenaDeque<PatchInfo<Label>>& infos, |
| 573 | ArenaVector<LinkerPatch>* linker_patches); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 574 | |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 575 | // Labels for each block that will be compiled. |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 576 | Label* block_labels_; // Indexed by block id. |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 577 | Label frame_entry_label_; |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 578 | LocationsBuilderX86_64 location_builder_; |
| 579 | InstructionCodeGeneratorX86_64 instruction_visitor_; |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 580 | ParallelMoveResolverX86_64 move_resolver_; |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 581 | X86_64Assembler assembler_; |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 582 | const X86_64InstructionSetFeatures& isa_features_; |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 583 | |
Mark Mendell | 39dcf55 | 2015-04-09 20:42:42 -0400 | [diff] [blame] | 584 | // Offset to the start of the constant area in the assembled code. |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 585 | // Used for fixups to the constant area. |
| 586 | int constant_area_start_; |
| 587 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 588 | // Method patch info. Using ArenaDeque<> which retains element addresses on push/emplace_back(). |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 589 | ArenaDeque<PatchInfo<Label>> method_patches_; |
| 590 | ArenaDeque<PatchInfo<Label>> relative_call_patches_; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 591 | // PC-relative DexCache access info. |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 592 | ArenaDeque<PatchInfo<Label>> pc_relative_dex_cache_patches_; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 593 | // Patch locations for patchoat where the linker doesn't do any other work. |
| 594 | ArenaDeque<Label> simple_patches_; |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 595 | // String patch locations; type depends on configuration (app .bss or boot image PIC). |
| 596 | ArenaDeque<PatchInfo<Label>> string_patches_; |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 597 | // Type patch locations. |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 598 | ArenaDeque<PatchInfo<Label>> type_patches_; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 599 | |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 600 | // Fixups for jump tables need to be handled specially. |
| 601 | ArenaVector<JumpTableRIPFixup*> fixups_to_jump_tables_; |
| 602 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 603 | DISALLOW_COPY_AND_ASSIGN(CodeGeneratorX86_64); |
| 604 | }; |
| 605 | |
| 606 | } // namespace x86_64 |
| 607 | } // namespace art |
| 608 | |
| 609 | #endif // ART_COMPILER_OPTIMIZING_CODE_GENERATOR_X86_64_H_ |