blob: 283489069662b73126d6375537e392d1680041df [file] [log] [blame]
Nicolas Geoffray9cf35522014-06-09 18:40:10 +01001/*
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 Mendell17077d82015-12-16 19:15:59 +000020#include "arch/x86_64/instruction_set_features_x86_64.h"
Vladimír Marko434d9682022-11-04 14:04:17 +000021#include "base/macros.h"
Nicolas Geoffray9cf35522014-06-09 18:40:10 +010022#include "code_generator.h"
Calin Juravlecd6dffe2015-01-08 17:35:35 +000023#include "driver/compiler_options.h"
Nicolas Geoffray9cf35522014-06-09 18:40:10 +010024#include "nodes.h"
Nicolas Geoffrayecb2f9b2014-06-13 08:59:59 +000025#include "parallel_move_resolver.h"
Nicolas Geoffray9cf35522014-06-09 18:40:10 +010026#include "utils/x86_64/assembler_x86_64.h"
27
Vladimír Marko434d9682022-11-04 14:04:17 +000028namespace art HIDDEN {
Nicolas Geoffray9cf35522014-06-09 18:40:10 +010029namespace x86_64 {
30
Nicolas Geoffray86a8d7a2014-11-19 08:47:18 +000031// Use a local definition to prevent copying mistakes.
Andreas Gampe542451c2016-07-26 09:02:02 -070032static constexpr size_t kX86_64WordSize = static_cast<size_t>(kX86_64PointerSize);
Nicolas Geoffray9cf35522014-06-09 18:40:10 +010033
Nicolas Geoffrayee3cf072015-10-06 11:45:02 +010034// Some x86_64 instructions require a register to be available as temp.
35static constexpr Register TMP = R11;
36
Nicolas Geoffray9cf35522014-06-09 18:40:10 +010037static constexpr Register kParameterCoreRegisters[] = { RSI, RDX, RCX, R8, R9 };
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +010038static constexpr FloatRegister kParameterFloatRegisters[] =
39 { XMM0, XMM1, XMM2, XMM3, XMM4, XMM5, XMM6, XMM7 };
Nicolas Geoffray9cf35522014-06-09 18:40:10 +010040
41static constexpr size_t kParameterCoreRegistersLength = arraysize(kParameterCoreRegisters);
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +010042static constexpr size_t kParameterFloatRegistersLength = arraysize(kParameterFloatRegisters);
Nicolas Geoffray9cf35522014-06-09 18:40:10 +010043
Jeff Hao848f70a2014-01-15 13:49:50 -080044static constexpr Register kRuntimeParameterCoreRegisters[] = { RDI, RSI, RDX, RCX };
Nicolas Geoffrayd75948a2015-03-27 09:53:16 +000045static constexpr size_t kRuntimeParameterCoreRegistersLength =
46 arraysize(kRuntimeParameterCoreRegisters);
47static constexpr FloatRegister kRuntimeParameterFpuRegisters[] = { XMM0, XMM1 };
48static constexpr size_t kRuntimeParameterFpuRegistersLength =
49 arraysize(kRuntimeParameterFpuRegisters);
50
Mark Mendella4f12202015-08-06 15:23:34 -040051// These XMM registers are non-volatile in ART ABI, but volatile in native ABI.
52// If the ART ABI changes, this list must be updated. It is used to ensure that
53// these are not clobbered by any direct call to native code (such as math intrinsics).
54static constexpr FloatRegister non_volatile_xmm_regs[] = { XMM12, XMM13, XMM14, XMM15 };
55
Santiago Aboy Solanes76d519b2023-04-03 12:34:45 +010056#define UNIMPLEMENTED_INTRINSIC_LIST_X86_64(V) \
57 V(CRC32Update) \
58 V(CRC32UpdateBytes) \
59 V(CRC32UpdateByteBuffer) \
60 V(FP16ToFloat) \
61 V(FP16ToHalf) \
62 V(FP16Floor) \
63 V(FP16Ceil) \
64 V(FP16Rint) \
65 V(FP16Greater) \
66 V(FP16GreaterEquals) \
67 V(FP16Less) \
68 V(FP16LessEquals) \
69 V(FP16Compare) \
70 V(FP16Min) \
71 V(FP16Max) \
72 V(StringStringIndexOf) \
73 V(StringStringIndexOfAfter) \
74 V(StringBufferAppend) \
75 V(StringBufferLength) \
76 V(StringBufferToString) \
77 V(StringBuilderAppendObject) \
78 V(StringBuilderAppendString) \
79 V(StringBuilderAppendCharSequence) \
80 V(StringBuilderAppendCharArray) \
81 V(StringBuilderAppendBoolean) \
82 V(StringBuilderAppendChar) \
83 V(StringBuilderAppendInt) \
84 V(StringBuilderAppendLong) \
85 V(StringBuilderAppendFloat) \
86 V(StringBuilderAppendDouble) \
87 V(StringBuilderLength) \
88 V(StringBuilderToString) \
89 /* 1.8 */ \
90 V(UnsafeGetAndAddInt) \
91 V(UnsafeGetAndAddLong) \
92 V(UnsafeGetAndSetInt) \
93 V(UnsafeGetAndSetLong) \
94 V(UnsafeGetAndSetObject) \
95 V(MethodHandleInvokeExact) \
96 V(MethodHandleInvoke) \
97 /* OpenJDK 11 */ \
98 V(JdkUnsafeGetAndAddInt) \
99 V(JdkUnsafeGetAndAddLong) \
100 V(JdkUnsafeGetAndSetInt) \
101 V(JdkUnsafeGetAndSetLong) \
Vladimir Marko0ac7d572023-11-22 16:46:30 +0100102 V(JdkUnsafeGetAndSetReference)
Mark Mendella4f12202015-08-06 15:23:34 -0400103
Nicolas Geoffrayd75948a2015-03-27 09:53:16 +0000104class InvokeRuntimeCallingConvention : public CallingConvention<Register, FloatRegister> {
105 public:
106 InvokeRuntimeCallingConvention()
107 : CallingConvention(kRuntimeParameterCoreRegisters,
108 kRuntimeParameterCoreRegistersLength,
109 kRuntimeParameterFpuRegisters,
Mathieu Chartiere401d142015-04-22 13:56:20 -0700110 kRuntimeParameterFpuRegistersLength,
111 kX86_64PointerSize) {}
Nicolas Geoffrayd75948a2015-03-27 09:53:16 +0000112
113 private:
114 DISALLOW_COPY_AND_ASSIGN(InvokeRuntimeCallingConvention);
115};
116
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100117class InvokeDexCallingConvention : public CallingConvention<Register, FloatRegister> {
Nicolas Geoffray9cf35522014-06-09 18:40:10 +0100118 public:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100119 InvokeDexCallingConvention() : CallingConvention(
120 kParameterCoreRegisters,
121 kParameterCoreRegistersLength,
122 kParameterFloatRegisters,
Mathieu Chartiere401d142015-04-22 13:56:20 -0700123 kParameterFloatRegistersLength,
124 kX86_64PointerSize) {}
Nicolas Geoffray9cf35522014-06-09 18:40:10 +0100125
126 private:
127 DISALLOW_COPY_AND_ASSIGN(InvokeDexCallingConvention);
128};
129
Vladimir Marko86c87522020-05-11 16:55:55 +0100130class CriticalNativeCallingConventionVisitorX86_64 : public InvokeDexCallingConventionVisitor {
131 public:
132 explicit CriticalNativeCallingConventionVisitorX86_64(bool for_register_allocation)
133 : for_register_allocation_(for_register_allocation) {}
134
135 virtual ~CriticalNativeCallingConventionVisitorX86_64() {}
136
137 Location GetNextLocation(DataType::Type type) override;
138 Location GetReturnLocation(DataType::Type type) const override;
139 Location GetMethodLocation() const override;
140
141 size_t GetStackOffset() const { return stack_offset_; }
142
143 private:
144 // Register allocator does not support adjusting frame size, so we cannot provide final locations
145 // of stack arguments for register allocation. We ask the register allocator for any location and
146 // move these arguments to the right place after adjusting the SP when generating the call.
147 const bool for_register_allocation_;
148 size_t gpr_index_ = 0u;
149 size_t fpr_index_ = 0u;
150 size_t stack_offset_ = 0u;
151
152 DISALLOW_COPY_AND_ASSIGN(CriticalNativeCallingConventionVisitorX86_64);
153};
154
Calin Juravlee460d1d2015-09-29 04:52:17 +0100155class FieldAccessCallingConventionX86_64 : public FieldAccessCallingConvention {
156 public:
157 FieldAccessCallingConventionX86_64() {}
158
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100159 Location GetObjectLocation() const override {
Calin Juravlee460d1d2015-09-29 04:52:17 +0100160 return Location::RegisterLocation(RSI);
161 }
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100162 Location GetFieldIndexLocation() const override {
Calin Juravlee460d1d2015-09-29 04:52:17 +0100163 return Location::RegisterLocation(RDI);
164 }
Stefano Cianciulli78f3c722023-05-16 10:32:54 +0000165 Location GetReturnLocation([[maybe_unused]] DataType::Type type) const override {
Calin Juravlee460d1d2015-09-29 04:52:17 +0100166 return Location::RegisterLocation(RAX);
167 }
Stefano Cianciulli78f3c722023-05-16 10:32:54 +0000168 Location GetSetValueLocation([[maybe_unused]] DataType::Type type,
169 bool is_instance) const override {
Nicolas Geoffray5b3c6c02017-01-19 14:22:26 +0000170 return is_instance
Calin Juravlee460d1d2015-09-29 04:52:17 +0100171 ? Location::RegisterLocation(RDX)
Nicolas Geoffray5b3c6c02017-01-19 14:22:26 +0000172 : Location::RegisterLocation(RSI);
Calin Juravlee460d1d2015-09-29 04:52:17 +0100173 }
Stefano Cianciulli78f3c722023-05-16 10:32:54 +0000174 Location GetFpuLocation([[maybe_unused]] DataType::Type type) const override {
Calin Juravlee460d1d2015-09-29 04:52:17 +0100175 return Location::FpuRegisterLocation(XMM0);
176 }
177
178 private:
179 DISALLOW_COPY_AND_ASSIGN(FieldAccessCallingConventionX86_64);
180};
181
182
Roland Levillain2d27c8e2015-04-28 15:48:45 +0100183class InvokeDexCallingConventionVisitorX86_64 : public InvokeDexCallingConventionVisitor {
Nicolas Geoffray9cf35522014-06-09 18:40:10 +0100184 public:
Roland Levillain2d27c8e2015-04-28 15:48:45 +0100185 InvokeDexCallingConventionVisitorX86_64() {}
186 virtual ~InvokeDexCallingConventionVisitorX86_64() {}
Nicolas Geoffray9cf35522014-06-09 18:40:10 +0100187
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100188 Location GetNextLocation(DataType::Type type) override;
189 Location GetReturnLocation(DataType::Type type) const override;
190 Location GetMethodLocation() const override;
Nicolas Geoffray9cf35522014-06-09 18:40:10 +0100191
192 private:
193 InvokeDexCallingConvention calling_convention;
Nicolas Geoffray9cf35522014-06-09 18:40:10 +0100194
Roland Levillain2d27c8e2015-04-28 15:48:45 +0100195 DISALLOW_COPY_AND_ASSIGN(InvokeDexCallingConventionVisitorX86_64);
Nicolas Geoffray9cf35522014-06-09 18:40:10 +0100196};
197
198class CodeGeneratorX86_64;
Andreas Gampe71fb52f2014-12-29 17:43:08 -0800199
Zheng Xuad4450e2015-04-17 18:48:56 +0800200class ParallelMoveResolverX86_64 : public ParallelMoveResolverWithSwap {
Nicolas Geoffrayecb2f9b2014-06-13 08:59:59 +0000201 public:
202 ParallelMoveResolverX86_64(ArenaAllocator* allocator, CodeGeneratorX86_64* codegen)
Zheng Xuad4450e2015-04-17 18:48:56 +0800203 : ParallelMoveResolverWithSwap(allocator), codegen_(codegen) {}
Nicolas Geoffrayecb2f9b2014-06-13 08:59:59 +0000204
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100205 void EmitMove(size_t index) override;
206 void EmitSwap(size_t index) override;
207 void SpillScratch(int reg) override;
208 void RestoreScratch(int reg) override;
Nicolas Geoffrayecb2f9b2014-06-13 08:59:59 +0000209
210 X86_64Assembler* GetAssembler() const;
211
212 private:
Nicolas Geoffray412f10c2014-06-19 10:00:34 +0100213 void Exchange32(CpuRegister reg, int mem);
Nicolas Geoffray102cbed2014-10-15 18:31:05 +0100214 void Exchange32(XmmRegister reg, int mem);
Mark Mendell8a1c7282015-06-29 15:41:28 -0400215 void Exchange64(CpuRegister reg1, CpuRegister reg2);
Nicolas Geoffray412f10c2014-06-19 10:00:34 +0100216 void Exchange64(CpuRegister reg, int mem);
Nicolas Geoffray102cbed2014-10-15 18:31:05 +0100217 void Exchange64(XmmRegister reg, int mem);
Aart Bikcfe50bb2017-12-12 14:54:12 -0800218 void Exchange128(XmmRegister reg, int mem);
219 void ExchangeMemory32(int mem1, int mem2);
220 void ExchangeMemory64(int mem1, int mem2, int num_of_qwords);
Nicolas Geoffrayecb2f9b2014-06-13 08:59:59 +0000221
222 CodeGeneratorX86_64* const codegen_;
223
224 DISALLOW_COPY_AND_ASSIGN(ParallelMoveResolverX86_64);
225};
226
Nicolas Geoffray9cf35522014-06-09 18:40:10 +0100227class LocationsBuilderX86_64 : public HGraphVisitor {
228 public:
229 LocationsBuilderX86_64(HGraph* graph, CodeGeneratorX86_64* codegen)
230 : HGraphVisitor(graph), codegen_(codegen) {}
231
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100232#define DECLARE_VISIT_INSTRUCTION(name, super) \
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100233 void Visit##name(H##name* instr) override;
Nicolas Geoffray9cf35522014-06-09 18:40:10 +0100234
Alexandre Ramesef20f712015-06-09 10:29:30 +0100235 FOR_EACH_CONCRETE_INSTRUCTION_COMMON(DECLARE_VISIT_INSTRUCTION)
236 FOR_EACH_CONCRETE_INSTRUCTION_X86_64(DECLARE_VISIT_INSTRUCTION)
Shalini Salomi Bodapatidd121f62018-10-26 15:03:53 +0530237 FOR_EACH_CONCRETE_INSTRUCTION_X86_COMMON(DECLARE_VISIT_INSTRUCTION)
Nicolas Geoffray9cf35522014-06-09 18:40:10 +0100238
239#undef DECLARE_VISIT_INSTRUCTION
240
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100241 void VisitInstruction(HInstruction* instruction) override {
Alexandre Ramesef20f712015-06-09 10:29:30 +0100242 LOG(FATAL) << "Unreachable instruction " << instruction->DebugName()
243 << " (id " << instruction->GetId() << ")";
244 }
245
Nicolas Geoffray9cf35522014-06-09 18:40:10 +0100246 private:
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +0000247 void HandleInvoke(HInvoke* invoke);
248 void HandleBitwiseOperation(HBinaryOperation* operation);
Vladimir Marko5f7b58e2015-11-23 19:49:34 +0000249 void HandleCondition(HCondition* condition);
Calin Juravle9aec02f2014-11-18 23:06:35 +0000250 void HandleShift(HBinaryOperation* operation);
Calin Juravle52c48962014-12-16 17:02:57 +0000251 void HandleFieldSet(HInstruction* instruction, const FieldInfo& field_info);
252 void HandleFieldGet(HInstruction* instruction);
Shalini Salomi Bodapatib45a4352019-07-10 16:09:41 +0530253 bool CpuHasAvxFeatureFlag();
254 bool CpuHasAvx2FeatureFlag();
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +0000255
Nicolas Geoffray9cf35522014-06-09 18:40:10 +0100256 CodeGeneratorX86_64* const codegen_;
Roland Levillain2d27c8e2015-04-28 15:48:45 +0100257 InvokeDexCallingConventionVisitorX86_64 parameter_visitor_;
Nicolas Geoffray9cf35522014-06-09 18:40:10 +0100258
259 DISALLOW_COPY_AND_ASSIGN(LocationsBuilderX86_64);
260};
261
Aart Bik42249c32016-01-07 15:33:50 -0800262class InstructionCodeGeneratorX86_64 : public InstructionCodeGenerator {
Nicolas Geoffray9cf35522014-06-09 18:40:10 +0100263 public:
264 InstructionCodeGeneratorX86_64(HGraph* graph, CodeGeneratorX86_64* codegen);
265
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100266#define DECLARE_VISIT_INSTRUCTION(name, super) \
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100267 void Visit##name(H##name* instr) override;
Nicolas Geoffray9cf35522014-06-09 18:40:10 +0100268
Alexandre Ramesef20f712015-06-09 10:29:30 +0100269 FOR_EACH_CONCRETE_INSTRUCTION_COMMON(DECLARE_VISIT_INSTRUCTION)
270 FOR_EACH_CONCRETE_INSTRUCTION_X86_64(DECLARE_VISIT_INSTRUCTION)
Shalini Salomi Bodapatidd121f62018-10-26 15:03:53 +0530271 FOR_EACH_CONCRETE_INSTRUCTION_X86_COMMON(DECLARE_VISIT_INSTRUCTION)
Nicolas Geoffray9cf35522014-06-09 18:40:10 +0100272
273#undef DECLARE_VISIT_INSTRUCTION
274
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100275 void VisitInstruction(HInstruction* instruction) override {
Alexandre Ramesef20f712015-06-09 10:29:30 +0100276 LOG(FATAL) << "Unreachable instruction " << instruction->DebugName()
277 << " (id " << instruction->GetId() << ")";
278 }
279
Nicolas Geoffray9cf35522014-06-09 18:40:10 +0100280 X86_64Assembler* GetAssembler() const { return assembler_; }
281
Ulya Trafimovich2ee69692021-05-19 14:15:14 +0100282 // Generate a GC root reference load:
283 //
284 // root <- *address
285 //
286 // while honoring read barriers based on read_barrier_option.
287 void GenerateGcRootFieldLoad(HInstruction* instruction,
288 Location root,
289 const Address& address,
290 Label* fixup_label,
291 ReadBarrierOption read_barrier_option);
Ulya Trafimovich6a4b2992021-06-11 12:02:17 +0100292 void HandleFieldSet(HInstruction* instruction,
293 uint32_t value_index,
294 uint32_t extra_temp_index,
295 DataType::Type field_type,
296 Address field_addr,
297 CpuRegister base,
298 bool is_volatile,
Ulya Trafimovich30bb6af2021-06-15 17:34:51 +0100299 bool is_atomic,
Ulya Trafimovich44a1dc72021-11-02 15:38:03 +0000300 bool value_can_be_null,
Santiago Aboy Solanesd4229602023-01-03 16:20:50 +0000301 bool byte_swap,
302 WriteBarrierKind write_barrier_kind);
Ulya Trafimovich44a1dc72021-11-02 15:38:03 +0000303
304 void Bswap(Location value, DataType::Type type, CpuRegister* temp = nullptr);
Ulya Trafimovich2ee69692021-05-19 14:15:14 +0100305
Nicolas Geoffray9cf35522014-06-09 18:40:10 +0100306 private:
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100307 // Generate code for the given suspend check. If not null, `successor`
308 // is the block to branch to if the suspend check is not needed, and after
309 // the suspend call.
310 void GenerateSuspendCheck(HSuspendCheck* instruction, HBasicBlock* successor);
Andreas Gampe85b62f22015-09-09 13:15:38 -0700311 void GenerateClassInitializationCheck(SlowPathCode* slow_path, CpuRegister class_reg);
Vladimir Marko175e7862018-03-27 09:03:13 +0000312 void GenerateBitstringTypeCheckCompare(HTypeCheckInstruction* check, CpuRegister temp);
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +0000313 void HandleBitwiseOperation(HBinaryOperation* operation);
Mark Mendellc4701932015-04-10 13:18:51 -0400314 void GenerateRemFP(HRem* rem);
Guillaume Sanchez0f88e872015-03-30 17:55:45 +0100315 void DivRemOneOrMinusOne(HBinaryOperation* instruction);
Guillaume Sanchezb19930c2015-04-09 21:12:15 +0100316 void DivByPowerOfTwo(HDiv* instruction);
Shalini Salomi Bodapatia66784b2018-11-06 13:05:44 +0530317 void RemByPowerOfTwo(HRem* instruction);
Guillaume Sanchez0f88e872015-03-30 17:55:45 +0100318 void GenerateDivRemWithAnyConstant(HBinaryOperation* instruction);
Calin Juravlebacfec32014-11-14 15:54:36 +0000319 void GenerateDivRemIntegral(HBinaryOperation* instruction);
Vladimir Marko5f7b58e2015-11-23 19:49:34 +0000320 void HandleCondition(HCondition* condition);
Calin Juravle9aec02f2014-11-18 23:06:35 +0000321 void HandleShift(HBinaryOperation* operation);
Roland Levillain1e7f8db2015-12-15 10:54:19 +0000322
Nicolas Geoffray07276db2015-05-18 14:22:09 +0100323 void HandleFieldSet(HInstruction* instruction,
324 const FieldInfo& field_info,
Santiago Aboy Solanesd4229602023-01-03 16:20:50 +0000325 bool value_can_be_null,
326 WriteBarrierKind write_barrier_kind);
Calin Juravle52c48962014-12-16 17:02:57 +0000327 void HandleFieldGet(HInstruction* instruction, const FieldInfo& field_info);
Roland Levillain1e7f8db2015-12-15 10:54:19 +0000328
Aart Bik351df3e2018-03-07 11:54:57 -0800329 void GenerateMinMaxInt(LocationSummary* locations, bool is_min, DataType::Type type);
Aart Bik1f8d51b2018-02-15 10:42:37 -0800330 void GenerateMinMaxFP(LocationSummary* locations, bool is_min, DataType::Type type);
Aart Bik351df3e2018-03-07 11:54:57 -0800331 void GenerateMinMax(HBinaryOperation* minmax, bool is_min);
Mythri Alle5097f832021-11-02 14:52:30 +0000332 void GenerateMethodEntryExitHook(HInstruction* instruction);
Aart Bik1f8d51b2018-02-15 10:42:37 -0800333
Roland Levillain1e7f8db2015-12-15 10:54:19 +0000334 // Generate a heap reference load using one register `out`:
335 //
336 // out <- *(out + offset)
337 //
338 // while honoring heap poisoning and/or read barriers (if any).
Roland Levillain95e7ffc2016-01-22 11:57:25 +0000339 //
340 // Location `maybe_temp` is used when generating a read barrier and
341 // shall be a register in that case; it may be an invalid location
342 // otherwise.
Roland Levillain1e7f8db2015-12-15 10:54:19 +0000343 void GenerateReferenceLoadOneRegister(HInstruction* instruction,
344 Location out,
345 uint32_t offset,
Mathieu Chartieraa474eb2016-11-09 15:18:27 -0800346 Location maybe_temp,
Mathieu Chartier3af00dc2016-11-10 11:25:57 -0800347 ReadBarrierOption read_barrier_option);
Roland Levillain1e7f8db2015-12-15 10:54:19 +0000348 // Generate a heap reference load using two different registers
349 // `out` and `obj`:
350 //
351 // out <- *(obj + offset)
352 //
353 // while honoring heap poisoning and/or read barriers (if any).
Roland Levillain95e7ffc2016-01-22 11:57:25 +0000354 //
355 // Location `maybe_temp` is used when generating a Baker's (fast
356 // path) read barrier and shall be a register in that case; it may
357 // be an invalid location otherwise.
Roland Levillain1e7f8db2015-12-15 10:54:19 +0000358 void GenerateReferenceLoadTwoRegisters(HInstruction* instruction,
359 Location out,
360 Location obj,
Mathieu Chartiercdba73b2016-11-03 19:23:06 -0700361 uint32_t offset,
Mathieu Chartier3af00dc2016-11-10 11:25:57 -0800362 ReadBarrierOption read_barrier_option);
Roland Levillain1e7f8db2015-12-15 10:54:19 +0000363
Mark Mendell24f2dfa2015-01-14 19:51:45 -0500364 void PushOntoFPStack(Location source, uint32_t temp_offset,
365 uint32_t stack_adjustment, bool is_float);
Mark Mendell7c0b44f2016-02-01 10:08:35 -0500366 void GenerateCompareTest(HCondition* condition);
Mark Mendell152408f2015-12-31 12:28:50 -0500367 template<class LabelType>
Mingyao Yangd43b3ac2015-04-01 14:03:04 -0700368 void GenerateTestAndBranch(HInstruction* instruction,
David Brazdil0debae72015-11-12 18:37:00 +0000369 size_t condition_input_index,
Mark Mendell152408f2015-12-31 12:28:50 -0500370 LabelType* true_target,
371 LabelType* false_target);
372 template<class LabelType>
David Brazdil0debae72015-11-12 18:37:00 +0000373 void GenerateCompareTestAndBranch(HCondition* condition,
Mark Mendell152408f2015-12-31 12:28:50 -0500374 LabelType* true_target,
375 LabelType* false_target);
376 template<class LabelType>
377 void GenerateFPJumps(HCondition* cond, LabelType* true_label, LabelType* false_label);
378
David Brazdilfc6a86a2015-06-26 10:33:45 +0000379 void HandleGoto(HInstruction* got, HBasicBlock* successor);
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100380
Shalini Salomi Bodapatib45a4352019-07-10 16:09:41 +0530381 bool CpuHasAvxFeatureFlag();
382 bool CpuHasAvx2FeatureFlag();
383
Nicolas Geoffray9cf35522014-06-09 18:40:10 +0100384 X86_64Assembler* const assembler_;
385 CodeGeneratorX86_64* const codegen_;
386
387 DISALLOW_COPY_AND_ASSIGN(InstructionCodeGeneratorX86_64);
388};
389
Mark Mendell9c86b482015-09-18 13:36:07 -0400390// Class for fixups to jump tables.
391class JumpTableRIPFixup;
392
Nicolas Geoffray9cf35522014-06-09 18:40:10 +0100393class CodeGeneratorX86_64 : public CodeGenerator {
394 public:
Mark Mendellfb8d2792015-03-31 22:16:59 -0400395 CodeGeneratorX86_64(HGraph* graph,
Serban Constantinescuecc43662015-08-13 13:33:12 +0100396 const CompilerOptions& compiler_options,
397 OptimizingCompilerStats* stats = nullptr);
Nicolas Geoffray9cf35522014-06-09 18:40:10 +0100398 virtual ~CodeGeneratorX86_64() {}
399
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100400 void GenerateFrameEntry() override;
401 void GenerateFrameExit() override;
402 void Bind(HBasicBlock* block) override;
403 void MoveConstant(Location destination, int32_t value) override;
404 void MoveLocation(Location dst, Location src, DataType::Type dst_type) override;
405 void AddLocationAsTemp(Location location, LocationSummary* locations) override;
Calin Juravlee460d1d2015-09-29 04:52:17 +0100406
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100407 size_t SaveCoreRegister(size_t stack_index, uint32_t reg_id) override;
408 size_t RestoreCoreRegister(size_t stack_index, uint32_t reg_id) override;
409 size_t SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) override;
410 size_t RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) override;
Nicolas Geoffray9cf35522014-06-09 18:40:10 +0100411
Alexandre Rames8158f282015-08-07 10:26:17 +0100412 // Generate code to invoke a runtime entry point.
Calin Juravle175dc732015-08-25 15:42:32 +0100413 void InvokeRuntime(QuickEntrypointEnum entrypoint,
414 HInstruction* instruction,
415 uint32_t dex_pc,
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100416 SlowPathCode* slow_path = nullptr) override;
Alexandre Rames8158f282015-08-07 10:26:17 +0100417
Roland Levillaindec8f632016-07-22 17:10:06 +0100418 // Generate code to invoke a runtime entry point, but do not record
419 // PC-related information in a stack map.
420 void InvokeRuntimeWithoutRecordingPcInfo(int32_t entry_point_offset,
421 HInstruction* instruction,
422 SlowPathCode* slow_path);
423
Serban Constantinescuba45db02016-07-12 22:53:02 +0100424 void GenerateInvokeRuntime(int32_t entry_point_offset);
425
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100426 size_t GetWordSize() const override {
Nicolas Geoffray9cf35522014-06-09 18:40:10 +0100427 return kX86_64WordSize;
428 }
429
Artem Serov6a0b6572019-07-26 20:38:37 +0100430 size_t GetSlowPathFPWidth() const override {
Aart Bikb13c65b2017-03-21 20:14:07 -0700431 return GetGraph()->HasSIMD()
Artem Serovc8150b52019-07-31 18:28:00 +0100432 ? GetSIMDRegisterWidth()
Aart Bikb13c65b2017-03-21 20:14:07 -0700433 : 1 * kX86_64WordSize; // 8 bytes == 1 x86_64 words for each spill
Mark Mendellf85a9ca2015-01-13 09:20:58 -0500434 }
435
Artem Serov6a0b6572019-07-26 20:38:37 +0100436 size_t GetCalleePreservedFPWidth() const override {
437 return 1 * kX86_64WordSize;
438 }
439
Artem Serovc8150b52019-07-31 18:28:00 +0100440 size_t GetSIMDRegisterWidth() const override {
441 return 2 * kX86_64WordSize;
442 }
443
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100444 HGraphVisitor* GetLocationBuilder() override {
Nicolas Geoffray9cf35522014-06-09 18:40:10 +0100445 return &location_builder_;
446 }
447
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100448 HGraphVisitor* GetInstructionVisitor() override {
Nicolas Geoffray9cf35522014-06-09 18:40:10 +0100449 return &instruction_visitor_;
450 }
451
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100452 X86_64Assembler* GetAssembler() override {
Nicolas Geoffray9cf35522014-06-09 18:40:10 +0100453 return &assembler_;
454 }
455
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100456 const X86_64Assembler& GetAssembler() const override {
Alexandre Rameseb7b7392015-06-19 14:47:01 +0100457 return assembler_;
458 }
459
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100460 ParallelMoveResolverX86_64* GetMoveResolver() override {
Nicolas Geoffrayecb2f9b2014-06-13 08:59:59 +0000461 return &move_resolver_;
462 }
463
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100464 uintptr_t GetAddressOf(HBasicBlock* block) override {
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +0000465 return GetLabelOf(block)->Position();
466 }
Nicolas Geoffray9cf35522014-06-09 18:40:10 +0100467
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100468 void SetupBlockedRegisters() const override;
469 void DumpCoreRegister(std::ostream& stream, int reg) const override;
470 void DumpFloatingPointRegister(std::ostream& stream, int reg) const override;
Nicolas Geoffray70bba9c2023-06-16 12:18:27 +0100471 void Finalize() override;
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +0000472
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100473 InstructionSet GetInstructionSet() const override {
Nicolas Geoffray412f10c2014-06-19 10:00:34 +0100474 return InstructionSet::kX86_64;
475 }
476
Ulya Trafimovich44a1dc72021-11-02 15:38:03 +0000477 InstructionCodeGeneratorX86_64* GetInstructionCodegen() {
478 return down_cast<InstructionCodeGeneratorX86_64*>(GetInstructionVisitor());
479 }
480
Vladimir Markoa0431112018-06-25 09:32:54 +0100481 const X86_64InstructionSetFeatures& GetInstructionSetFeatures() const;
482
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100483 // Emit a write barrier.
Nicolas Geoffray07276db2015-05-18 14:22:09 +0100484 void MarkGCCard(CpuRegister temp,
485 CpuRegister card,
486 CpuRegister object,
487 CpuRegister value,
Santiago Aboy Solanesd4229602023-01-03 16:20:50 +0000488 bool emit_null_check);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100489
Roland Levillain1e7f8db2015-12-15 10:54:19 +0000490 void GenerateMemoryBarrier(MemBarrierKind kind);
491
Nicolas Geoffray9cf35522014-06-09 18:40:10 +0100492 // Helper method to move a value between two locations.
493 void Move(Location destination, Location source);
Ulya Trafimovich161911c2021-06-01 15:47:28 +0100494 // Helper method to load a value of non-reference type from memory.
495 void LoadFromMemoryNoReference(DataType::Type type, Location dst, Address src);
Nicolas Geoffray9cf35522014-06-09 18:40:10 +0100496
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100497 Label* GetLabelOf(HBasicBlock* block) const {
Vladimir Marko225b6462015-09-28 12:17:40 +0100498 return CommonGetLabelOf<Label>(block_labels_, block);
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100499 }
500
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100501 void Initialize() override {
Vladimir Marko225b6462015-09-28 12:17:40 +0100502 block_labels_ = CommonInitializeLabels<Label>();
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100503 }
504
Stefano Cianciulli78f3c722023-05-16 10:32:54 +0000505 bool NeedsTwoRegisters([[maybe_unused]] DataType::Type type) const override { return false; }
Nicolas Geoffray840e5462015-01-07 16:01:24 +0000506
Vladimir Markocac5a7e2016-02-22 10:39:50 +0000507 // Check if the desired_string_load_kind is supported. If it is, return it,
508 // otherwise return a fall-back kind that should be used instead.
509 HLoadString::LoadKind GetSupportedLoadStringKind(
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100510 HLoadString::LoadKind desired_string_load_kind) override;
Vladimir Markocac5a7e2016-02-22 10:39:50 +0000511
Vladimir Markodbb7f5b2016-03-30 13:23:58 +0100512 // Check if the desired_class_load_kind is supported. If it is, return it,
513 // otherwise return a fall-back kind that should be used instead.
514 HLoadClass::LoadKind GetSupportedLoadClassKind(
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100515 HLoadClass::LoadKind desired_class_load_kind) override;
Vladimir Markodbb7f5b2016-03-30 13:23:58 +0100516
Vladimir Markodc151b22015-10-15 18:02:30 +0100517 // Check if the desired_dispatch_info is supported. If it is, return it,
518 // otherwise return a fall-back info that should be used instead.
519 HInvokeStaticOrDirect::DispatchInfo GetSupportedInvokeStaticOrDirectDispatch(
520 const HInvokeStaticOrDirect::DispatchInfo& desired_dispatch_info,
Nicolas Geoffraybdb2ecc2018-09-18 14:33:55 +0100521 ArtMethod* method) override;
Vladimir Markodc151b22015-10-15 18:02:30 +0100522
Nicolas Geoffray8d34a182020-09-16 09:46:58 +0100523 void LoadMethod(MethodLoadKind load_kind, Location temp, HInvoke* invoke);
Vladimir Markoe7197bf2017-06-02 17:00:23 +0100524 void GenerateStaticOrDirectCall(
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100525 HInvokeStaticOrDirect* invoke, Location temp, SlowPathCode* slow_path = nullptr) override;
Vladimir Markoe7197bf2017-06-02 17:00:23 +0100526 void GenerateVirtualCall(
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100527 HInvokeVirtual* invoke, Location temp, SlowPathCode* slow_path = nullptr) override;
Andreas Gampe85b62f22015-09-09 13:15:38 -0700528
Vladimir Marko6fd16062018-06-26 11:02:04 +0100529 void RecordBootImageIntrinsicPatch(uint32_t intrinsic_data);
Vladimir Markob066d432018-01-03 13:14:37 +0000530 void RecordBootImageRelRoPatch(uint32_t boot_image_offset);
Nicolas Geoffray8d34a182020-09-16 09:46:58 +0100531 void RecordBootImageMethodPatch(HInvoke* invoke);
532 void RecordMethodBssEntryPatch(HInvoke* invoke);
Vladimir Marko9d31daa2022-04-14 10:48:44 +0100533 void RecordBootImageTypePatch(const DexFile& dex_file, dex::TypeIndex type_index);
Vladimir Marko6bec91c2017-01-09 15:03:12 +0000534 Label* NewTypeBssEntryPatch(HLoadClass* load_class);
Vladimir Marko59eb30f2018-02-20 11:52:34 +0000535 void RecordBootImageStringPatch(HLoadString* load_string);
Vladimir Markoaad75c62016-10-03 08:46:48 +0000536 Label* NewStringBssEntryPatch(HLoadString* load_string);
Vladimir Markoeb9eb002020-10-02 13:54:19 +0100537 void RecordBootImageJniEntrypointPatch(HInvokeStaticOrDirect* invoke);
Nicolas Geoffrayf0acfe72017-01-09 20:54:52 +0000538 Label* NewJitRootStringPatch(const DexFile& dex_file,
Vladimir Marko174b2e22017-10-12 13:34:49 +0100539 dex::StringIndex string_index,
Nicolas Geoffrayf0acfe72017-01-09 20:54:52 +0000540 Handle<mirror::String> handle);
Nicolas Geoffray5247c082017-01-13 14:17:29 +0000541 Label* NewJitRootClassPatch(const DexFile& dex_file,
Vladimir Marko174b2e22017-10-12 13:34:49 +0100542 dex::TypeIndex type_index,
Nicolas Geoffray5247c082017-01-13 14:17:29 +0000543 Handle<mirror::Class> handle);
Vladimir Markocac5a7e2016-02-22 10:39:50 +0000544
Vladimir Marko6fd16062018-06-26 11:02:04 +0100545 void LoadBootImageAddress(CpuRegister reg, uint32_t boot_image_reference);
Vladimir Markode91ca92020-10-27 13:41:40 +0000546 void LoadIntrinsicDeclaringClass(CpuRegister reg, HInvoke* invoke);
Ulyana Trafimovich3693b2a2021-10-29 10:43:18 +0000547 void LoadClassRootForIntrinsic(CpuRegister reg, ClassRoot class_root);
Andreas Gampe71fb52f2014-12-29 17:43:08 -0800548
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100549 void EmitLinkerPatches(ArenaVector<linker::LinkerPatch>* linker_patches) override;
Vladimir Marko58155012015-08-19 12:49:41 +0000550
Nicolas Geoffray22384ae2016-12-12 22:33:36 +0000551 void PatchJitRootUse(uint8_t* code,
552 const uint8_t* roots_data,
553 const PatchInfo<Label>& info,
554 uint64_t index_in_table) const;
555
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100556 void EmitJitRootPatches(uint8_t* code, const uint8_t* roots_data) override;
Nicolas Geoffray132d8362016-11-16 09:19:42 +0000557
Roland Levillain1e7f8db2015-12-15 10:54:19 +0000558 // Fast path implementation of ReadBarrier::Barrier for a heap
559 // reference field load when Baker's read barriers are used.
560 void GenerateFieldLoadWithBakerReadBarrier(HInstruction* instruction,
Roland Levillaine3f43ac2016-01-19 15:07:47 +0000561 Location ref,
Roland Levillain1e7f8db2015-12-15 10:54:19 +0000562 CpuRegister obj,
563 uint32_t offset,
Roland Levillain1e7f8db2015-12-15 10:54:19 +0000564 bool needs_null_check);
565 // Fast path implementation of ReadBarrier::Barrier for a heap
566 // reference array load when Baker's read barriers are used.
567 void GenerateArrayLoadWithBakerReadBarrier(HInstruction* instruction,
Roland Levillaine3f43ac2016-01-19 15:07:47 +0000568 Location ref,
Roland Levillain1e7f8db2015-12-15 10:54:19 +0000569 CpuRegister obj,
570 uint32_t data_offset,
571 Location index,
Roland Levillain1e7f8db2015-12-15 10:54:19 +0000572 bool needs_null_check);
Roland Levillaina1aa3b12016-10-26 13:03:38 +0100573 // Factored implementation, used by GenerateFieldLoadWithBakerReadBarrier,
574 // GenerateArrayLoadWithBakerReadBarrier and some intrinsics.
575 //
576 // Load the object reference located at address `src`, held by
577 // object `obj`, into `ref`, and mark it if needed. The base of
578 // address `src` must be `obj`.
579 //
580 // If `always_update_field` is true, the value of the reference is
581 // atomically updated in the holder (`obj`). This operation
582 // requires two temporary registers, which must be provided as
583 // non-null pointers (`temp1` and `temp2`).
Sang, Chunlei0fcd2b82016-04-05 17:12:59 +0800584 void GenerateReferenceLoadWithBakerReadBarrier(HInstruction* instruction,
585 Location ref,
586 CpuRegister obj,
587 const Address& src,
Roland Levillaina1aa3b12016-10-26 13:03:38 +0100588 bool needs_null_check,
589 bool always_update_field = false,
590 CpuRegister* temp1 = nullptr,
591 CpuRegister* temp2 = nullptr);
Roland Levillain1e7f8db2015-12-15 10:54:19 +0000592
593 // Generate a read barrier for a heap reference within `instruction`
594 // using a slow path.
Roland Levillain0d5a2812015-11-13 10:07:31 +0000595 //
596 // A read barrier for an object reference read from the heap is
597 // implemented as a call to the artReadBarrierSlow runtime entry
598 // point, which is passed the values in locations `ref`, `obj`, and
599 // `offset`:
600 //
601 // mirror::Object* artReadBarrierSlow(mirror::Object* ref,
602 // mirror::Object* obj,
603 // uint32_t offset);
604 //
605 // The `out` location contains the value returned by
606 // artReadBarrierSlow.
607 //
608 // When `index` provided (i.e., when it is different from
609 // Location::NoLocation()), the offset value passed to
610 // artReadBarrierSlow is adjusted to take `index` into account.
Roland Levillain1e7f8db2015-12-15 10:54:19 +0000611 void GenerateReadBarrierSlow(HInstruction* instruction,
612 Location out,
613 Location ref,
614 Location obj,
615 uint32_t offset,
616 Location index = Location::NoLocation());
Roland Levillain0d5a2812015-11-13 10:07:31 +0000617
Roland Levillain1e7f8db2015-12-15 10:54:19 +0000618 // If read barriers are enabled, generate a read barrier for a heap
619 // reference using a slow path. If heap poisoning is enabled, also
620 // unpoison the reference in `out`.
621 void MaybeGenerateReadBarrierSlow(HInstruction* instruction,
622 Location out,
623 Location ref,
624 Location obj,
625 uint32_t offset,
626 Location index = Location::NoLocation());
Roland Levillain0d5a2812015-11-13 10:07:31 +0000627
Roland Levillain1e7f8db2015-12-15 10:54:19 +0000628 // Generate a read barrier for a GC root within `instruction` using
629 // a slow path.
Roland Levillain0d5a2812015-11-13 10:07:31 +0000630 //
631 // A read barrier for an object reference GC root is implemented as
632 // a call to the artReadBarrierForRootSlow runtime entry point,
633 // which is passed the value in location `root`:
634 //
635 // mirror::Object* artReadBarrierForRootSlow(GcRoot<mirror::Object>* root);
636 //
637 // The `out` location contains the value returned by
638 // artReadBarrierForRootSlow.
Roland Levillain1e7f8db2015-12-15 10:54:19 +0000639 void GenerateReadBarrierForRootSlow(HInstruction* instruction, Location out, Location root);
Roland Levillain0d5a2812015-11-13 10:07:31 +0000640
Mark Mendellf55c3e02015-03-26 21:07:46 -0400641 int ConstantAreaStart() const {
642 return constant_area_start_;
643 }
644
645 Address LiteralDoubleAddress(double v);
646 Address LiteralFloatAddress(float v);
647 Address LiteralInt32Address(int32_t v);
648 Address LiteralInt64Address(int64_t v);
649
Aart Bika19616e2016-02-01 18:57:58 -0800650 // Load a 32/64-bit value into a register in the most efficient manner.
Aart Bikc5d47542016-01-27 17:00:35 -0800651 void Load32BitValue(CpuRegister dest, int32_t value);
Mark Mendell92e83bf2015-05-07 11:25:03 -0400652 void Load64BitValue(CpuRegister dest, int64_t value);
Mark Mendell7c0b44f2016-02-01 10:08:35 -0500653 void Load32BitValue(XmmRegister dest, int32_t value);
654 void Load64BitValue(XmmRegister dest, int64_t value);
655 void Load32BitValue(XmmRegister dest, float value);
656 void Load64BitValue(XmmRegister dest, double value);
Aart Bikc5d47542016-01-27 17:00:35 -0800657
Aart Bika19616e2016-02-01 18:57:58 -0800658 // Compare a register with a 32/64-bit value in the most efficient manner.
659 void Compare32BitValue(CpuRegister dest, int32_t value);
660 void Compare64BitValue(CpuRegister dest, int64_t value);
661
jessicahandojo4877b792016-09-08 19:49:13 -0700662 // Compare int values. Supports register locations for `lhs`.
Vladimir Marko56f4bdd2016-09-16 11:32:36 +0100663 void GenerateIntCompare(Location lhs, Location rhs);
jessicahandojo4877b792016-09-08 19:49:13 -0700664 void GenerateIntCompare(CpuRegister lhs, Location rhs);
Vladimir Marko56f4bdd2016-09-16 11:32:36 +0100665
666 // Compare long values. Supports only register locations for `lhs`.
667 void GenerateLongCompare(Location lhs, Location rhs);
668
669 // Construct address for array access.
670 static Address ArrayAddress(CpuRegister obj,
671 Location index,
672 ScaleFactor scale,
673 uint32_t data_offset);
674
Mark Mendell9c86b482015-09-18 13:36:07 -0400675 Address LiteralCaseTable(HPackedSwitch* switch_instr);
Mark Mendell92e83bf2015-05-07 11:25:03 -0400676
Mark Mendellcfa410b2015-05-25 16:02:44 -0400677 // Store a 64 bit value into a DoubleStackSlot in the most efficient manner.
678 void Store64BitValueToStack(Location dest, int64_t value);
679
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100680 void MoveFromReturnRegister(Location trg, DataType::Type type) override;
Vladimir Markoeebb8212018-06-05 14:57:24 +0100681
Mark Mendellea5af682015-10-22 17:35:49 -0400682 // Assign a 64 bit constant to an address.
683 void MoveInt64ToAddress(const Address& addr_low,
684 const Address& addr_high,
685 int64_t v,
686 HInstruction* instruction);
687
Mark P Mendell17077d82015-12-16 19:15:59 +0000688 // Ensure that prior stores complete to memory before subsequent loads.
689 // The locked add implementation will avoid serializing device memory, but will
Mark Mendell7aa04a12016-01-27 22:39:07 -0500690 // touch (but not change) the top of the stack.
691 // The 'non_temporal' parameter should be used to ensure ordering of non-temporal stores.
Mark P Mendell17077d82015-12-16 19:15:59 +0000692 void MemoryFence(bool force_mfence = false) {
Mark Mendell7aa04a12016-01-27 22:39:07 -0500693 if (!force_mfence) {
Mark P Mendell17077d82015-12-16 19:15:59 +0000694 assembler_.lock()->addl(Address(CpuRegister(RSP), 0), Immediate(0));
695 } else {
696 assembler_.mfence();
697 }
698 }
699
Vladimir Markodec78172020-06-19 15:31:23 +0100700 void IncreaseFrame(size_t adjustment) override;
701 void DecreaseFrame(size_t adjustment) override;
702
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100703 void GenerateNop() override;
704 void GenerateImplicitNullCheck(HNullCheck* instruction) override;
705 void GenerateExplicitNullCheck(HNullCheck* instruction) override;
Nicolas Geoffray20036d82019-11-28 16:15:00 +0000706 void MaybeGenerateInlineCacheCheck(HInstruction* instruction, CpuRegister cls);
Nicolas Geoffraye2a3aa92019-11-25 17:52:58 +0000707
Nicolas Geoffraya59af8a2019-11-27 17:42:32 +0000708 void MaybeIncrementHotness(bool is_frame_entry);
709
Vladimir Marko86c87522020-05-11 16:55:55 +0100710 static void BlockNonVolatileXmmRegisters(LocationSummary* locations);
711
Vladimir Marko4ef451a2020-07-23 09:54:27 +0000712 // When we don't know the proper offset for the value, we use kPlaceholder32BitOffset.
Vladimir Markocac5a7e2016-02-22 10:39:50 +0000713 // We will fix this up in the linker later to have the right value.
Vladimir Marko4ef451a2020-07-23 09:54:27 +0000714 static constexpr int32_t kPlaceholder32BitOffset = 256;
Vladimir Markocac5a7e2016-02-22 10:39:50 +0000715
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100716 private:
Vladimir Markod8dbc8d2017-09-20 13:37:47 +0100717 template <linker::LinkerPatch (*Factory)(size_t, const DexFile*, uint32_t, uint32_t)>
Vladimir Markoaad75c62016-10-03 08:46:48 +0000718 static void EmitPcRelativeLinkerPatches(const ArenaDeque<PatchInfo<Label>>& infos,
Vladimir Markod8dbc8d2017-09-20 13:37:47 +0100719 ArenaVector<linker::LinkerPatch>* linker_patches);
Vladimir Marko58155012015-08-19 12:49:41 +0000720
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100721 // Labels for each block that will be compiled.
Vladimir Marko225b6462015-09-28 12:17:40 +0100722 Label* block_labels_; // Indexed by block id.
Nicolas Geoffray1cf95282014-12-12 19:22:03 +0000723 Label frame_entry_label_;
Nicolas Geoffray9cf35522014-06-09 18:40:10 +0100724 LocationsBuilderX86_64 location_builder_;
725 InstructionCodeGeneratorX86_64 instruction_visitor_;
Nicolas Geoffrayecb2f9b2014-06-13 08:59:59 +0000726 ParallelMoveResolverX86_64 move_resolver_;
Nicolas Geoffray9cf35522014-06-09 18:40:10 +0100727 X86_64Assembler assembler_;
Nicolas Geoffray9cf35522014-06-09 18:40:10 +0100728
Mark Mendell39dcf552015-04-09 20:42:42 -0400729 // Offset to the start of the constant area in the assembled code.
Mark Mendellf55c3e02015-03-26 21:07:46 -0400730 // Used for fixups to the constant area.
731 int constant_area_start_;
732
Vladimir Marko2d06e022019-07-08 15:45:19 +0100733 // PC-relative method patch info for kBootImageLinkTimePcRelative.
Vladimir Marko65979462017-05-19 17:25:12 +0100734 ArenaDeque<PatchInfo<Label>> boot_image_method_patches_;
Vladimir Marko0eb882b2017-05-15 13:39:18 +0100735 // PC-relative method patch info for kBssEntry.
736 ArenaDeque<PatchInfo<Label>> method_bss_entry_patches_;
Vladimir Marko764d4542017-05-16 10:31:41 +0100737 // PC-relative type patch info for kBootImageLinkTimePcRelative.
Vladimir Marko1998cd02017-01-13 13:02:58 +0000738 ArenaDeque<PatchInfo<Label>> boot_image_type_patches_;
Vladimir Markoe47f60c2018-02-21 13:43:28 +0000739 // PC-relative type patch info for kBssEntry.
Vladimir Marko1998cd02017-01-13 13:02:58 +0000740 ArenaDeque<PatchInfo<Label>> type_bss_entry_patches_;
Vladimir Marko8f63f102020-09-28 12:10:28 +0100741 // PC-relative public type patch info for kBssEntryPublic.
742 ArenaDeque<PatchInfo<Label>> public_type_bss_entry_patches_;
743 // PC-relative package type patch info for kBssEntryPackage.
744 ArenaDeque<PatchInfo<Label>> package_type_bss_entry_patches_;
Vladimir Markoe47f60c2018-02-21 13:43:28 +0000745 // PC-relative String patch info for kBootImageLinkTimePcRelative.
Vladimir Marko59eb30f2018-02-20 11:52:34 +0000746 ArenaDeque<PatchInfo<Label>> boot_image_string_patches_;
Vladimir Markoe47f60c2018-02-21 13:43:28 +0000747 // PC-relative String patch info for kBssEntry.
Vladimir Marko6cfbdbc2017-07-25 13:26:39 +0100748 ArenaDeque<PatchInfo<Label>> string_bss_entry_patches_;
Vladimir Markoeb9eb002020-10-02 13:54:19 +0100749 // PC-relative method patch info for kBootImageLinkTimePcRelative+kCallCriticalNative.
750 ArenaDeque<PatchInfo<Label>> boot_image_jni_entrypoint_patches_;
Vladimir Marko2d06e022019-07-08 15:45:19 +0100751 // PC-relative patch info for IntrinsicObjects for the boot image,
752 // and for method/type/string patches for kBootImageRelRo otherwise.
753 ArenaDeque<PatchInfo<Label>> boot_image_other_patches_;
Mark Mendell9c86b482015-09-18 13:36:07 -0400754
Nicolas Geoffray132d8362016-11-16 09:19:42 +0000755 // Patches for string literals in JIT compiled code.
756 ArenaDeque<PatchInfo<Label>> jit_string_patches_;
Nicolas Geoffray22384ae2016-12-12 22:33:36 +0000757 // Patches for class literals in JIT compiled code.
758 ArenaDeque<PatchInfo<Label>> jit_class_patches_;
759
Vladimir Marko65979462017-05-19 17:25:12 +0100760 // Fixups for jump tables need to be handled specially.
761 ArenaVector<JumpTableRIPFixup*> fixups_to_jump_tables_;
762
Nicolas Geoffray9cf35522014-06-09 18:40:10 +0100763 DISALLOW_COPY_AND_ASSIGN(CodeGeneratorX86_64);
764};
765
766} // namespace x86_64
767} // namespace art
768
769#endif // ART_COMPILER_OPTIMIZING_CODE_GENERATOR_X86_64_H_