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 | |
Vladimir Marko | 0a51605 | 2019-10-14 13:00:44 +0000 | [diff] [blame] | 27 | namespace art { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 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 | |
Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 82 | class CriticalNativeCallingConventionVisitorX86_64 : public InvokeDexCallingConventionVisitor { |
| 83 | public: |
| 84 | explicit CriticalNativeCallingConventionVisitorX86_64(bool for_register_allocation) |
| 85 | : for_register_allocation_(for_register_allocation) {} |
| 86 | |
| 87 | virtual ~CriticalNativeCallingConventionVisitorX86_64() {} |
| 88 | |
| 89 | Location GetNextLocation(DataType::Type type) override; |
| 90 | Location GetReturnLocation(DataType::Type type) const override; |
| 91 | Location GetMethodLocation() const override; |
| 92 | |
| 93 | size_t GetStackOffset() const { return stack_offset_; } |
| 94 | |
| 95 | private: |
| 96 | // Register allocator does not support adjusting frame size, so we cannot provide final locations |
| 97 | // of stack arguments for register allocation. We ask the register allocator for any location and |
| 98 | // move these arguments to the right place after adjusting the SP when generating the call. |
| 99 | const bool for_register_allocation_; |
| 100 | size_t gpr_index_ = 0u; |
| 101 | size_t fpr_index_ = 0u; |
| 102 | size_t stack_offset_ = 0u; |
| 103 | |
| 104 | DISALLOW_COPY_AND_ASSIGN(CriticalNativeCallingConventionVisitorX86_64); |
| 105 | }; |
| 106 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 107 | class FieldAccessCallingConventionX86_64 : public FieldAccessCallingConvention { |
| 108 | public: |
| 109 | FieldAccessCallingConventionX86_64() {} |
| 110 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 111 | Location GetObjectLocation() const override { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 112 | return Location::RegisterLocation(RSI); |
| 113 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 114 | Location GetFieldIndexLocation() const override { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 115 | return Location::RegisterLocation(RDI); |
| 116 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 117 | Location GetReturnLocation(DataType::Type type ATTRIBUTE_UNUSED) const override { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 118 | return Location::RegisterLocation(RAX); |
| 119 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 120 | Location GetSetValueLocation(DataType::Type type ATTRIBUTE_UNUSED, bool is_instance) |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 121 | const override { |
Nicolas Geoffray | 5b3c6c0 | 2017-01-19 14:22:26 +0000 | [diff] [blame] | 122 | return is_instance |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 123 | ? Location::RegisterLocation(RDX) |
Nicolas Geoffray | 5b3c6c0 | 2017-01-19 14:22:26 +0000 | [diff] [blame] | 124 | : Location::RegisterLocation(RSI); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 125 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 126 | Location GetFpuLocation(DataType::Type type ATTRIBUTE_UNUSED) const override { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 127 | return Location::FpuRegisterLocation(XMM0); |
| 128 | } |
| 129 | |
| 130 | private: |
| 131 | DISALLOW_COPY_AND_ASSIGN(FieldAccessCallingConventionX86_64); |
| 132 | }; |
| 133 | |
| 134 | |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 135 | class InvokeDexCallingConventionVisitorX86_64 : public InvokeDexCallingConventionVisitor { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 136 | public: |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 137 | InvokeDexCallingConventionVisitorX86_64() {} |
| 138 | virtual ~InvokeDexCallingConventionVisitorX86_64() {} |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 139 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 140 | Location GetNextLocation(DataType::Type type) override; |
| 141 | Location GetReturnLocation(DataType::Type type) const override; |
| 142 | Location GetMethodLocation() const override; |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 143 | |
| 144 | private: |
| 145 | InvokeDexCallingConvention calling_convention; |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 146 | |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 147 | DISALLOW_COPY_AND_ASSIGN(InvokeDexCallingConventionVisitorX86_64); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 148 | }; |
| 149 | |
| 150 | class CodeGeneratorX86_64; |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 151 | |
Zheng Xu | ad4450e | 2015-04-17 18:48:56 +0800 | [diff] [blame] | 152 | class ParallelMoveResolverX86_64 : public ParallelMoveResolverWithSwap { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 153 | public: |
| 154 | ParallelMoveResolverX86_64(ArenaAllocator* allocator, CodeGeneratorX86_64* codegen) |
Zheng Xu | ad4450e | 2015-04-17 18:48:56 +0800 | [diff] [blame] | 155 | : ParallelMoveResolverWithSwap(allocator), codegen_(codegen) {} |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 156 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 157 | void EmitMove(size_t index) override; |
| 158 | void EmitSwap(size_t index) override; |
| 159 | void SpillScratch(int reg) override; |
| 160 | void RestoreScratch(int reg) override; |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 161 | |
| 162 | X86_64Assembler* GetAssembler() const; |
| 163 | |
| 164 | private: |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 165 | void Exchange32(CpuRegister reg, int mem); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 166 | void Exchange32(XmmRegister reg, int mem); |
Mark Mendell | 8a1c728 | 2015-06-29 15:41:28 -0400 | [diff] [blame] | 167 | void Exchange64(CpuRegister reg1, CpuRegister reg2); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 168 | void Exchange64(CpuRegister reg, int mem); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 169 | void Exchange64(XmmRegister reg, int mem); |
Aart Bik | cfe50bb | 2017-12-12 14:54:12 -0800 | [diff] [blame] | 170 | void Exchange128(XmmRegister reg, int mem); |
| 171 | void ExchangeMemory32(int mem1, int mem2); |
| 172 | void ExchangeMemory64(int mem1, int mem2, int num_of_qwords); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 173 | |
| 174 | CodeGeneratorX86_64* const codegen_; |
| 175 | |
| 176 | DISALLOW_COPY_AND_ASSIGN(ParallelMoveResolverX86_64); |
| 177 | }; |
| 178 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 179 | class LocationsBuilderX86_64 : public HGraphVisitor { |
| 180 | public: |
| 181 | LocationsBuilderX86_64(HGraph* graph, CodeGeneratorX86_64* codegen) |
| 182 | : HGraphVisitor(graph), codegen_(codegen) {} |
| 183 | |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 184 | #define DECLARE_VISIT_INSTRUCTION(name, super) \ |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 185 | void Visit##name(H##name* instr) override; |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 186 | |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 187 | FOR_EACH_CONCRETE_INSTRUCTION_COMMON(DECLARE_VISIT_INSTRUCTION) |
| 188 | FOR_EACH_CONCRETE_INSTRUCTION_X86_64(DECLARE_VISIT_INSTRUCTION) |
Shalini Salomi Bodapati | dd121f6 | 2018-10-26 15:03:53 +0530 | [diff] [blame] | 189 | FOR_EACH_CONCRETE_INSTRUCTION_X86_COMMON(DECLARE_VISIT_INSTRUCTION) |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 190 | |
| 191 | #undef DECLARE_VISIT_INSTRUCTION |
| 192 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 193 | void VisitInstruction(HInstruction* instruction) override { |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 194 | LOG(FATAL) << "Unreachable instruction " << instruction->DebugName() |
| 195 | << " (id " << instruction->GetId() << ")"; |
| 196 | } |
| 197 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 198 | private: |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 199 | void HandleInvoke(HInvoke* invoke); |
| 200 | void HandleBitwiseOperation(HBinaryOperation* operation); |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 201 | void HandleCondition(HCondition* condition); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 202 | void HandleShift(HBinaryOperation* operation); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 203 | void HandleFieldSet(HInstruction* instruction, const FieldInfo& field_info); |
| 204 | void HandleFieldGet(HInstruction* instruction); |
Shalini Salomi Bodapati | b45a435 | 2019-07-10 16:09:41 +0530 | [diff] [blame] | 205 | bool CpuHasAvxFeatureFlag(); |
| 206 | bool CpuHasAvx2FeatureFlag(); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 207 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 208 | CodeGeneratorX86_64* const codegen_; |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 209 | InvokeDexCallingConventionVisitorX86_64 parameter_visitor_; |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 210 | |
| 211 | DISALLOW_COPY_AND_ASSIGN(LocationsBuilderX86_64); |
| 212 | }; |
| 213 | |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 214 | class InstructionCodeGeneratorX86_64 : public InstructionCodeGenerator { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 215 | public: |
| 216 | InstructionCodeGeneratorX86_64(HGraph* graph, CodeGeneratorX86_64* codegen); |
| 217 | |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 218 | #define DECLARE_VISIT_INSTRUCTION(name, super) \ |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 219 | void Visit##name(H##name* instr) override; |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 220 | |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 221 | FOR_EACH_CONCRETE_INSTRUCTION_COMMON(DECLARE_VISIT_INSTRUCTION) |
| 222 | FOR_EACH_CONCRETE_INSTRUCTION_X86_64(DECLARE_VISIT_INSTRUCTION) |
Shalini Salomi Bodapati | dd121f6 | 2018-10-26 15:03:53 +0530 | [diff] [blame] | 223 | FOR_EACH_CONCRETE_INSTRUCTION_X86_COMMON(DECLARE_VISIT_INSTRUCTION) |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 224 | |
| 225 | #undef DECLARE_VISIT_INSTRUCTION |
| 226 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 227 | void VisitInstruction(HInstruction* instruction) override { |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 228 | LOG(FATAL) << "Unreachable instruction " << instruction->DebugName() |
| 229 | << " (id " << instruction->GetId() << ")"; |
| 230 | } |
| 231 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 232 | X86_64Assembler* GetAssembler() const { return assembler_; } |
| 233 | |
| 234 | private: |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 235 | // Generate code for the given suspend check. If not null, `successor` |
| 236 | // is the block to branch to if the suspend check is not needed, and after |
| 237 | // the suspend call. |
| 238 | void GenerateSuspendCheck(HSuspendCheck* instruction, HBasicBlock* successor); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 239 | void GenerateClassInitializationCheck(SlowPathCode* slow_path, CpuRegister class_reg); |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 240 | void GenerateBitstringTypeCheckCompare(HTypeCheckInstruction* check, CpuRegister temp); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 241 | void HandleBitwiseOperation(HBinaryOperation* operation); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 242 | void GenerateRemFP(HRem* rem); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 243 | void DivRemOneOrMinusOne(HBinaryOperation* instruction); |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 244 | void DivByPowerOfTwo(HDiv* instruction); |
Shalini Salomi Bodapati | a66784b | 2018-11-06 13:05:44 +0530 | [diff] [blame] | 245 | void RemByPowerOfTwo(HRem* instruction); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 246 | void GenerateDivRemWithAnyConstant(HBinaryOperation* instruction); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 247 | void GenerateDivRemIntegral(HBinaryOperation* instruction); |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 248 | void HandleCondition(HCondition* condition); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 249 | void HandleShift(HBinaryOperation* operation); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 250 | |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 251 | void HandleFieldSet(HInstruction* instruction, |
| 252 | const FieldInfo& field_info, |
| 253 | bool value_can_be_null); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 254 | void HandleFieldGet(HInstruction* instruction, const FieldInfo& field_info); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 255 | |
Aart Bik | 351df3e | 2018-03-07 11:54:57 -0800 | [diff] [blame] | 256 | void GenerateMinMaxInt(LocationSummary* locations, bool is_min, DataType::Type type); |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 257 | void GenerateMinMaxFP(LocationSummary* locations, bool is_min, DataType::Type type); |
Aart Bik | 351df3e | 2018-03-07 11:54:57 -0800 | [diff] [blame] | 258 | void GenerateMinMax(HBinaryOperation* minmax, bool is_min); |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 259 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 260 | // Generate a heap reference load using one register `out`: |
| 261 | // |
| 262 | // out <- *(out + offset) |
| 263 | // |
| 264 | // while honoring heap poisoning and/or read barriers (if any). |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 265 | // |
| 266 | // Location `maybe_temp` is used when generating a read barrier and |
| 267 | // shall be a register in that case; it may be an invalid location |
| 268 | // otherwise. |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 269 | void GenerateReferenceLoadOneRegister(HInstruction* instruction, |
| 270 | Location out, |
| 271 | uint32_t offset, |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 272 | Location maybe_temp, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 273 | ReadBarrierOption read_barrier_option); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 274 | // Generate a heap reference load using two different registers |
| 275 | // `out` and `obj`: |
| 276 | // |
| 277 | // out <- *(obj + offset) |
| 278 | // |
| 279 | // while honoring heap poisoning and/or read barriers (if any). |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 280 | // |
| 281 | // Location `maybe_temp` is used when generating a Baker's (fast |
| 282 | // path) read barrier and shall be a register in that case; it may |
| 283 | // be an invalid location otherwise. |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 284 | void GenerateReferenceLoadTwoRegisters(HInstruction* instruction, |
| 285 | Location out, |
| 286 | Location obj, |
Mathieu Chartier | cdba73b | 2016-11-03 19:23:06 -0700 | [diff] [blame] | 287 | uint32_t offset, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 288 | ReadBarrierOption read_barrier_option); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 289 | // Generate a GC root reference load: |
| 290 | // |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 291 | // root <- *address |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 292 | // |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 293 | // while honoring read barriers based on read_barrier_option. |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 294 | void GenerateGcRootFieldLoad(HInstruction* instruction, |
| 295 | Location root, |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 296 | const Address& address, |
Roland Levillain | 00468f3 | 2016-10-27 18:02:48 +0100 | [diff] [blame] | 297 | Label* fixup_label, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 298 | ReadBarrierOption read_barrier_option); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 299 | |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 300 | void PushOntoFPStack(Location source, uint32_t temp_offset, |
| 301 | uint32_t stack_adjustment, bool is_float); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 302 | void GenerateCompareTest(HCondition* condition); |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 303 | template<class LabelType> |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 304 | void GenerateTestAndBranch(HInstruction* instruction, |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 305 | size_t condition_input_index, |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 306 | LabelType* true_target, |
| 307 | LabelType* false_target); |
| 308 | template<class LabelType> |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 309 | void GenerateCompareTestAndBranch(HCondition* condition, |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 310 | LabelType* true_target, |
| 311 | LabelType* false_target); |
| 312 | template<class LabelType> |
| 313 | void GenerateFPJumps(HCondition* cond, LabelType* true_label, LabelType* false_label); |
| 314 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 315 | void HandleGoto(HInstruction* got, HBasicBlock* successor); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 316 | |
Shalini Salomi Bodapati | b45a435 | 2019-07-10 16:09:41 +0530 | [diff] [blame] | 317 | bool CpuHasAvxFeatureFlag(); |
| 318 | bool CpuHasAvx2FeatureFlag(); |
| 319 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 320 | X86_64Assembler* const assembler_; |
| 321 | CodeGeneratorX86_64* const codegen_; |
| 322 | |
| 323 | DISALLOW_COPY_AND_ASSIGN(InstructionCodeGeneratorX86_64); |
| 324 | }; |
| 325 | |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 326 | // Class for fixups to jump tables. |
| 327 | class JumpTableRIPFixup; |
| 328 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 329 | class CodeGeneratorX86_64 : public CodeGenerator { |
| 330 | public: |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 331 | CodeGeneratorX86_64(HGraph* graph, |
Serban Constantinescu | ecc4366 | 2015-08-13 13:33:12 +0100 | [diff] [blame] | 332 | const CompilerOptions& compiler_options, |
| 333 | OptimizingCompilerStats* stats = nullptr); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 334 | virtual ~CodeGeneratorX86_64() {} |
| 335 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 336 | void GenerateFrameEntry() override; |
| 337 | void GenerateFrameExit() override; |
| 338 | void Bind(HBasicBlock* block) override; |
| 339 | void MoveConstant(Location destination, int32_t value) override; |
| 340 | void MoveLocation(Location dst, Location src, DataType::Type dst_type) override; |
| 341 | void AddLocationAsTemp(Location location, LocationSummary* locations) override; |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 342 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 343 | size_t SaveCoreRegister(size_t stack_index, uint32_t reg_id) override; |
| 344 | size_t RestoreCoreRegister(size_t stack_index, uint32_t reg_id) override; |
| 345 | size_t SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) override; |
| 346 | size_t RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) override; |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 347 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 348 | // Generate code to invoke a runtime entry point. |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 349 | void InvokeRuntime(QuickEntrypointEnum entrypoint, |
| 350 | HInstruction* instruction, |
| 351 | uint32_t dex_pc, |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 352 | SlowPathCode* slow_path = nullptr) override; |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 353 | |
Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 354 | // Generate code to invoke a runtime entry point, but do not record |
| 355 | // PC-related information in a stack map. |
| 356 | void InvokeRuntimeWithoutRecordingPcInfo(int32_t entry_point_offset, |
| 357 | HInstruction* instruction, |
| 358 | SlowPathCode* slow_path); |
| 359 | |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 360 | void GenerateInvokeRuntime(int32_t entry_point_offset); |
| 361 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 362 | size_t GetWordSize() const override { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 363 | return kX86_64WordSize; |
| 364 | } |
| 365 | |
Artem Serov | 6a0b657 | 2019-07-26 20:38:37 +0100 | [diff] [blame] | 366 | size_t GetSlowPathFPWidth() const override { |
Aart Bik | b13c65b | 2017-03-21 20:14:07 -0700 | [diff] [blame] | 367 | return GetGraph()->HasSIMD() |
Artem Serov | c8150b5 | 2019-07-31 18:28:00 +0100 | [diff] [blame] | 368 | ? GetSIMDRegisterWidth() |
Aart Bik | b13c65b | 2017-03-21 20:14:07 -0700 | [diff] [blame] | 369 | : 1 * kX86_64WordSize; // 8 bytes == 1 x86_64 words for each spill |
Mark Mendell | f85a9ca | 2015-01-13 09:20:58 -0500 | [diff] [blame] | 370 | } |
| 371 | |
Artem Serov | 6a0b657 | 2019-07-26 20:38:37 +0100 | [diff] [blame] | 372 | size_t GetCalleePreservedFPWidth() const override { |
| 373 | return 1 * kX86_64WordSize; |
| 374 | } |
| 375 | |
Artem Serov | c8150b5 | 2019-07-31 18:28:00 +0100 | [diff] [blame] | 376 | size_t GetSIMDRegisterWidth() const override { |
| 377 | return 2 * kX86_64WordSize; |
| 378 | } |
| 379 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 380 | HGraphVisitor* GetLocationBuilder() override { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 381 | return &location_builder_; |
| 382 | } |
| 383 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 384 | HGraphVisitor* GetInstructionVisitor() override { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 385 | return &instruction_visitor_; |
| 386 | } |
| 387 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 388 | X86_64Assembler* GetAssembler() override { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 389 | return &assembler_; |
| 390 | } |
| 391 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 392 | const X86_64Assembler& GetAssembler() const override { |
Alexandre Rames | eb7b739 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 393 | return assembler_; |
| 394 | } |
| 395 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 396 | ParallelMoveResolverX86_64* GetMoveResolver() override { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 397 | return &move_resolver_; |
| 398 | } |
| 399 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 400 | uintptr_t GetAddressOf(HBasicBlock* block) override { |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 401 | return GetLabelOf(block)->Position(); |
| 402 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 403 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 404 | void SetupBlockedRegisters() const override; |
| 405 | void DumpCoreRegister(std::ostream& stream, int reg) const override; |
| 406 | void DumpFloatingPointRegister(std::ostream& stream, int reg) const override; |
| 407 | void Finalize(CodeAllocator* allocator) override; |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 408 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 409 | InstructionSet GetInstructionSet() const override { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 410 | return InstructionSet::kX86_64; |
| 411 | } |
| 412 | |
Vladimir Marko | a043111 | 2018-06-25 09:32:54 +0100 | [diff] [blame] | 413 | const X86_64InstructionSetFeatures& GetInstructionSetFeatures() const; |
| 414 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 415 | // Emit a write barrier. |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 416 | void MarkGCCard(CpuRegister temp, |
| 417 | CpuRegister card, |
| 418 | CpuRegister object, |
| 419 | CpuRegister value, |
| 420 | bool value_can_be_null); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 421 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 422 | void GenerateMemoryBarrier(MemBarrierKind kind); |
| 423 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 424 | // Helper method to move a value between two locations. |
| 425 | void Move(Location destination, Location source); |
| 426 | |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 427 | Label* GetLabelOf(HBasicBlock* block) const { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 428 | return CommonGetLabelOf<Label>(block_labels_, block); |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 429 | } |
| 430 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 431 | void Initialize() override { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 432 | block_labels_ = CommonInitializeLabels<Label>(); |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 433 | } |
| 434 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 435 | bool NeedsTwoRegisters(DataType::Type type ATTRIBUTE_UNUSED) const override { |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 436 | return false; |
| 437 | } |
| 438 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 439 | // Check if the desired_string_load_kind is supported. If it is, return it, |
| 440 | // otherwise return a fall-back kind that should be used instead. |
| 441 | HLoadString::LoadKind GetSupportedLoadStringKind( |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 442 | HLoadString::LoadKind desired_string_load_kind) override; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 443 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 444 | // Check if the desired_class_load_kind is supported. If it is, return it, |
| 445 | // otherwise return a fall-back kind that should be used instead. |
| 446 | HLoadClass::LoadKind GetSupportedLoadClassKind( |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 447 | HLoadClass::LoadKind desired_class_load_kind) override; |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 448 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 449 | // Check if the desired_dispatch_info is supported. If it is, return it, |
| 450 | // otherwise return a fall-back info that should be used instead. |
| 451 | HInvokeStaticOrDirect::DispatchInfo GetSupportedInvokeStaticOrDirectDispatch( |
| 452 | const HInvokeStaticOrDirect::DispatchInfo& desired_dispatch_info, |
Nicolas Geoffray | bdb2ecc | 2018-09-18 14:33:55 +0100 | [diff] [blame] | 453 | ArtMethod* method) override; |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 454 | |
Nicolas Geoffray | 8d34a18 | 2020-09-16 09:46:58 +0100 | [diff] [blame] | 455 | void LoadMethod(MethodLoadKind load_kind, Location temp, HInvoke* invoke); |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 456 | void GenerateStaticOrDirectCall( |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 457 | HInvokeStaticOrDirect* invoke, Location temp, SlowPathCode* slow_path = nullptr) override; |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 458 | void GenerateVirtualCall( |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 459 | HInvokeVirtual* invoke, Location temp, SlowPathCode* slow_path = nullptr) override; |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 460 | |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 461 | void RecordBootImageIntrinsicPatch(uint32_t intrinsic_data); |
Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 462 | void RecordBootImageRelRoPatch(uint32_t boot_image_offset); |
Nicolas Geoffray | 8d34a18 | 2020-09-16 09:46:58 +0100 | [diff] [blame] | 463 | void RecordBootImageMethodPatch(HInvoke* invoke); |
| 464 | void RecordMethodBssEntryPatch(HInvoke* invoke); |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 465 | void RecordBootImageTypePatch(HLoadClass* load_class); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 466 | Label* NewTypeBssEntryPatch(HLoadClass* load_class); |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 467 | void RecordBootImageStringPatch(HLoadString* load_string); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 468 | Label* NewStringBssEntryPatch(HLoadString* load_string); |
Vladimir Marko | eb9eb00 | 2020-10-02 13:54:19 +0100 | [diff] [blame] | 469 | void RecordBootImageJniEntrypointPatch(HInvokeStaticOrDirect* invoke); |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 470 | Label* NewJitRootStringPatch(const DexFile& dex_file, |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 471 | dex::StringIndex string_index, |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 472 | Handle<mirror::String> handle); |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 473 | Label* NewJitRootClassPatch(const DexFile& dex_file, |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 474 | dex::TypeIndex type_index, |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 475 | Handle<mirror::Class> handle); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 476 | |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 477 | void LoadBootImageAddress(CpuRegister reg, uint32_t boot_image_reference); |
Vladimir Marko | de91ca9 | 2020-10-27 13:41:40 +0000 | [diff] [blame] | 478 | void LoadIntrinsicDeclaringClass(CpuRegister reg, HInvoke* invoke); |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 479 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 480 | void EmitLinkerPatches(ArenaVector<linker::LinkerPatch>* linker_patches) override; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 481 | |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 482 | void PatchJitRootUse(uint8_t* code, |
| 483 | const uint8_t* roots_data, |
| 484 | const PatchInfo<Label>& info, |
| 485 | uint64_t index_in_table) const; |
| 486 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 487 | void EmitJitRootPatches(uint8_t* code, const uint8_t* roots_data) override; |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 488 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 489 | // Fast path implementation of ReadBarrier::Barrier for a heap |
| 490 | // reference field load when Baker's read barriers are used. |
| 491 | void GenerateFieldLoadWithBakerReadBarrier(HInstruction* instruction, |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 492 | Location ref, |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 493 | CpuRegister obj, |
| 494 | uint32_t offset, |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 495 | bool needs_null_check); |
| 496 | // Fast path implementation of ReadBarrier::Barrier for a heap |
| 497 | // reference array load when Baker's read barriers are used. |
| 498 | void GenerateArrayLoadWithBakerReadBarrier(HInstruction* instruction, |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 499 | Location ref, |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 500 | CpuRegister obj, |
| 501 | uint32_t data_offset, |
| 502 | Location index, |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 503 | bool needs_null_check); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 504 | // Factored implementation, used by GenerateFieldLoadWithBakerReadBarrier, |
| 505 | // GenerateArrayLoadWithBakerReadBarrier and some intrinsics. |
| 506 | // |
| 507 | // Load the object reference located at address `src`, held by |
| 508 | // object `obj`, into `ref`, and mark it if needed. The base of |
| 509 | // address `src` must be `obj`. |
| 510 | // |
| 511 | // If `always_update_field` is true, the value of the reference is |
| 512 | // atomically updated in the holder (`obj`). This operation |
| 513 | // requires two temporary registers, which must be provided as |
| 514 | // non-null pointers (`temp1` and `temp2`). |
Sang, Chunlei | 0fcd2b8 | 2016-04-05 17:12:59 +0800 | [diff] [blame] | 515 | void GenerateReferenceLoadWithBakerReadBarrier(HInstruction* instruction, |
| 516 | Location ref, |
| 517 | CpuRegister obj, |
| 518 | const Address& src, |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 519 | bool needs_null_check, |
| 520 | bool always_update_field = false, |
| 521 | CpuRegister* temp1 = nullptr, |
| 522 | CpuRegister* temp2 = nullptr); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 523 | |
| 524 | // Generate a read barrier for a heap reference within `instruction` |
| 525 | // using a slow path. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 526 | // |
| 527 | // A read barrier for an object reference read from the heap is |
| 528 | // implemented as a call to the artReadBarrierSlow runtime entry |
| 529 | // point, which is passed the values in locations `ref`, `obj`, and |
| 530 | // `offset`: |
| 531 | // |
| 532 | // mirror::Object* artReadBarrierSlow(mirror::Object* ref, |
| 533 | // mirror::Object* obj, |
| 534 | // uint32_t offset); |
| 535 | // |
| 536 | // The `out` location contains the value returned by |
| 537 | // artReadBarrierSlow. |
| 538 | // |
| 539 | // When `index` provided (i.e., when it is different from |
| 540 | // Location::NoLocation()), the offset value passed to |
| 541 | // artReadBarrierSlow is adjusted to take `index` into account. |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 542 | void GenerateReadBarrierSlow(HInstruction* instruction, |
| 543 | Location out, |
| 544 | Location ref, |
| 545 | Location obj, |
| 546 | uint32_t offset, |
| 547 | Location index = Location::NoLocation()); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 548 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 549 | // If read barriers are enabled, generate a read barrier for a heap |
| 550 | // reference using a slow path. If heap poisoning is enabled, also |
| 551 | // unpoison the reference in `out`. |
| 552 | void MaybeGenerateReadBarrierSlow(HInstruction* instruction, |
| 553 | Location out, |
| 554 | Location ref, |
| 555 | Location obj, |
| 556 | uint32_t offset, |
| 557 | Location index = Location::NoLocation()); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 558 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 559 | // Generate a read barrier for a GC root within `instruction` using |
| 560 | // a slow path. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 561 | // |
| 562 | // A read barrier for an object reference GC root is implemented as |
| 563 | // a call to the artReadBarrierForRootSlow runtime entry point, |
| 564 | // which is passed the value in location `root`: |
| 565 | // |
| 566 | // mirror::Object* artReadBarrierForRootSlow(GcRoot<mirror::Object>* root); |
| 567 | // |
| 568 | // The `out` location contains the value returned by |
| 569 | // artReadBarrierForRootSlow. |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 570 | void GenerateReadBarrierForRootSlow(HInstruction* instruction, Location out, Location root); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 571 | |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 572 | int ConstantAreaStart() const { |
| 573 | return constant_area_start_; |
| 574 | } |
| 575 | |
| 576 | Address LiteralDoubleAddress(double v); |
| 577 | Address LiteralFloatAddress(float v); |
| 578 | Address LiteralInt32Address(int32_t v); |
| 579 | Address LiteralInt64Address(int64_t v); |
| 580 | |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 581 | // 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] | 582 | void Load32BitValue(CpuRegister dest, int32_t value); |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 583 | void Load64BitValue(CpuRegister dest, int64_t value); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 584 | void Load32BitValue(XmmRegister dest, int32_t value); |
| 585 | void Load64BitValue(XmmRegister dest, int64_t value); |
| 586 | void Load32BitValue(XmmRegister dest, float value); |
| 587 | void Load64BitValue(XmmRegister dest, double value); |
Aart Bik | c5d4754 | 2016-01-27 17:00:35 -0800 | [diff] [blame] | 588 | |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 589 | // Compare a register with a 32/64-bit value in the most efficient manner. |
| 590 | void Compare32BitValue(CpuRegister dest, int32_t value); |
| 591 | void Compare64BitValue(CpuRegister dest, int64_t value); |
| 592 | |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 593 | // Compare int values. Supports register locations for `lhs`. |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 594 | void GenerateIntCompare(Location lhs, Location rhs); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 595 | void GenerateIntCompare(CpuRegister lhs, Location rhs); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 596 | |
| 597 | // Compare long values. Supports only register locations for `lhs`. |
| 598 | void GenerateLongCompare(Location lhs, Location rhs); |
| 599 | |
| 600 | // Construct address for array access. |
| 601 | static Address ArrayAddress(CpuRegister obj, |
| 602 | Location index, |
| 603 | ScaleFactor scale, |
| 604 | uint32_t data_offset); |
| 605 | |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 606 | Address LiteralCaseTable(HPackedSwitch* switch_instr); |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 607 | |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 608 | // Store a 64 bit value into a DoubleStackSlot in the most efficient manner. |
| 609 | void Store64BitValueToStack(Location dest, int64_t value); |
| 610 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 611 | void MoveFromReturnRegister(Location trg, DataType::Type type) override; |
Vladimir Marko | eebb821 | 2018-06-05 14:57:24 +0100 | [diff] [blame] | 612 | |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 613 | // Assign a 64 bit constant to an address. |
| 614 | void MoveInt64ToAddress(const Address& addr_low, |
| 615 | const Address& addr_high, |
| 616 | int64_t v, |
| 617 | HInstruction* instruction); |
| 618 | |
Mark P Mendell | 17077d8 | 2015-12-16 19:15:59 +0000 | [diff] [blame] | 619 | // Ensure that prior stores complete to memory before subsequent loads. |
| 620 | // The locked add implementation will avoid serializing device memory, but will |
Mark Mendell | 7aa04a1 | 2016-01-27 22:39:07 -0500 | [diff] [blame] | 621 | // touch (but not change) the top of the stack. |
| 622 | // 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] | 623 | void MemoryFence(bool force_mfence = false) { |
Mark Mendell | 7aa04a1 | 2016-01-27 22:39:07 -0500 | [diff] [blame] | 624 | if (!force_mfence) { |
Mark P Mendell | 17077d8 | 2015-12-16 19:15:59 +0000 | [diff] [blame] | 625 | assembler_.lock()->addl(Address(CpuRegister(RSP), 0), Immediate(0)); |
| 626 | } else { |
| 627 | assembler_.mfence(); |
| 628 | } |
| 629 | } |
| 630 | |
Vladimir Marko | dec7817 | 2020-06-19 15:31:23 +0100 | [diff] [blame] | 631 | void IncreaseFrame(size_t adjustment) override; |
| 632 | void DecreaseFrame(size_t adjustment) override; |
| 633 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 634 | void GenerateNop() override; |
| 635 | void GenerateImplicitNullCheck(HNullCheck* instruction) override; |
| 636 | void GenerateExplicitNullCheck(HNullCheck* instruction) override; |
Nicolas Geoffray | 20036d8 | 2019-11-28 16:15:00 +0000 | [diff] [blame] | 637 | void MaybeGenerateInlineCacheCheck(HInstruction* instruction, CpuRegister cls); |
Nicolas Geoffray | e2a3aa9 | 2019-11-25 17:52:58 +0000 | [diff] [blame] | 638 | |
David Srbecky | c7098ff | 2016-02-09 14:30:11 +0000 | [diff] [blame] | 639 | |
Nicolas Geoffray | a59af8a | 2019-11-27 17:42:32 +0000 | [diff] [blame] | 640 | void MaybeIncrementHotness(bool is_frame_entry); |
| 641 | |
Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 642 | static void BlockNonVolatileXmmRegisters(LocationSummary* locations); |
| 643 | |
Vladimir Marko | 4ef451a | 2020-07-23 09:54:27 +0000 | [diff] [blame] | 644 | // When we don't know the proper offset for the value, we use kPlaceholder32BitOffset. |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 645 | // We will fix this up in the linker later to have the right value. |
Vladimir Marko | 4ef451a | 2020-07-23 09:54:27 +0000 | [diff] [blame] | 646 | static constexpr int32_t kPlaceholder32BitOffset = 256; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 647 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 648 | private: |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 649 | template <linker::LinkerPatch (*Factory)(size_t, const DexFile*, uint32_t, uint32_t)> |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 650 | static void EmitPcRelativeLinkerPatches(const ArenaDeque<PatchInfo<Label>>& infos, |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 651 | ArenaVector<linker::LinkerPatch>* linker_patches); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 652 | |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 653 | // Labels for each block that will be compiled. |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 654 | Label* block_labels_; // Indexed by block id. |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 655 | Label frame_entry_label_; |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 656 | LocationsBuilderX86_64 location_builder_; |
| 657 | InstructionCodeGeneratorX86_64 instruction_visitor_; |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 658 | ParallelMoveResolverX86_64 move_resolver_; |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 659 | X86_64Assembler assembler_; |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 660 | |
Mark Mendell | 39dcf55 | 2015-04-09 20:42:42 -0400 | [diff] [blame] | 661 | // Offset to the start of the constant area in the assembled code. |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 662 | // Used for fixups to the constant area. |
| 663 | int constant_area_start_; |
| 664 | |
Vladimir Marko | 2d06e02 | 2019-07-08 15:45:19 +0100 | [diff] [blame] | 665 | // PC-relative method patch info for kBootImageLinkTimePcRelative. |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 666 | ArenaDeque<PatchInfo<Label>> boot_image_method_patches_; |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 667 | // PC-relative method patch info for kBssEntry. |
| 668 | ArenaDeque<PatchInfo<Label>> method_bss_entry_patches_; |
Vladimir Marko | 764d454 | 2017-05-16 10:31:41 +0100 | [diff] [blame] | 669 | // PC-relative type patch info for kBootImageLinkTimePcRelative. |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 670 | ArenaDeque<PatchInfo<Label>> boot_image_type_patches_; |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 671 | // PC-relative type patch info for kBssEntry. |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 672 | ArenaDeque<PatchInfo<Label>> type_bss_entry_patches_; |
Vladimir Marko | 8f63f10 | 2020-09-28 12:10:28 +0100 | [diff] [blame] | 673 | // PC-relative public type patch info for kBssEntryPublic. |
| 674 | ArenaDeque<PatchInfo<Label>> public_type_bss_entry_patches_; |
| 675 | // PC-relative package type patch info for kBssEntryPackage. |
| 676 | ArenaDeque<PatchInfo<Label>> package_type_bss_entry_patches_; |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 677 | // PC-relative String patch info for kBootImageLinkTimePcRelative. |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 678 | ArenaDeque<PatchInfo<Label>> boot_image_string_patches_; |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 679 | // PC-relative String patch info for kBssEntry. |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 680 | ArenaDeque<PatchInfo<Label>> string_bss_entry_patches_; |
Vladimir Marko | eb9eb00 | 2020-10-02 13:54:19 +0100 | [diff] [blame] | 681 | // PC-relative method patch info for kBootImageLinkTimePcRelative+kCallCriticalNative. |
| 682 | ArenaDeque<PatchInfo<Label>> boot_image_jni_entrypoint_patches_; |
Vladimir Marko | 2d06e02 | 2019-07-08 15:45:19 +0100 | [diff] [blame] | 683 | // PC-relative patch info for IntrinsicObjects for the boot image, |
| 684 | // and for method/type/string patches for kBootImageRelRo otherwise. |
| 685 | ArenaDeque<PatchInfo<Label>> boot_image_other_patches_; |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 686 | |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 687 | // Patches for string literals in JIT compiled code. |
| 688 | ArenaDeque<PatchInfo<Label>> jit_string_patches_; |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 689 | // Patches for class literals in JIT compiled code. |
| 690 | ArenaDeque<PatchInfo<Label>> jit_class_patches_; |
| 691 | |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 692 | // Fixups for jump tables need to be handled specially. |
| 693 | ArenaVector<JumpTableRIPFixup*> fixups_to_jump_tables_; |
| 694 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 695 | DISALLOW_COPY_AND_ASSIGN(CodeGeneratorX86_64); |
| 696 | }; |
| 697 | |
| 698 | } // namespace x86_64 |
| 699 | } // namespace art |
| 700 | |
| 701 | #endif // ART_COMPILER_OPTIMIZING_CODE_GENERATOR_X86_64_H_ |