blob: 24993c3a4b2faaf2a40e29e33026148cf40d998b [file] [log] [blame]
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +00001/*
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_H_
18#define ART_COMPILER_OPTIMIZING_CODE_GENERATOR_X86_H_
19
Mark P Mendell17077d82015-12-16 19:15:59 +000020#include "arch/x86/instruction_set_features_x86.h"
Andreas Gampe542451c2016-07-26 09:02:02 -070021#include "base/enums.h"
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +000022#include "code_generator.h"
David Sehr9e734c72018-01-04 17:56:19 -080023#include "dex/dex_file_types.h"
Calin Juravlecd6dffe2015-01-08 17:35:35 +000024#include "driver/compiler_options.h"
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +000025#include "nodes.h"
Nicolas Geoffray86dbb9a2014-06-04 11:12:39 +010026#include "parallel_move_resolver.h"
Nicolas Geoffray787c3072014-03-17 10:20:19 +000027#include "utils/x86/assembler_x86.h"
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +000028
Vladimir Marko0a516052019-10-14 13:00:44 +000029namespace art {
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +000030namespace x86 {
31
Nicolas Geoffray86a8d7a2014-11-19 08:47:18 +000032// Use a local definition to prevent copying mistakes.
Andreas Gampe542451c2016-07-26 09:02:02 -070033static constexpr size_t kX86WordSize = static_cast<size_t>(kX86PointerSize);
Nicolas Geoffray707c8092014-04-04 10:50:14 +010034
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +010035class CodeGeneratorX86;
36
Nicolas Geoffraya747a392014-04-17 14:56:23 +010037static constexpr Register kParameterCoreRegisters[] = { ECX, EDX, EBX };
38static constexpr RegisterPair kParameterCorePairRegisters[] = { ECX_EDX, EDX_EBX };
39static constexpr size_t kParameterCoreRegistersLength = arraysize(kParameterCoreRegisters);
Mark P Mendell966c3ae2015-01-27 15:45:27 +000040static constexpr XmmRegister kParameterFpuRegisters[] = { XMM0, XMM1, XMM2, XMM3 };
41static constexpr size_t kParameterFpuRegistersLength = arraysize(kParameterFpuRegisters);
Nicolas Geoffraya747a392014-04-17 14:56:23 +010042
Nicolas Geoffrayd75948a2015-03-27 09:53:16 +000043static constexpr Register kRuntimeParameterCoreRegisters[] = { EAX, ECX, EDX, EBX };
44static constexpr size_t kRuntimeParameterCoreRegistersLength =
45 arraysize(kRuntimeParameterCoreRegisters);
46static constexpr XmmRegister kRuntimeParameterFpuRegisters[] = { XMM0, XMM1, XMM2, XMM3 };
47static constexpr size_t kRuntimeParameterFpuRegistersLength =
48 arraysize(kRuntimeParameterFpuRegisters);
49
50class InvokeRuntimeCallingConvention : public CallingConvention<Register, XmmRegister> {
51 public:
52 InvokeRuntimeCallingConvention()
53 : CallingConvention(kRuntimeParameterCoreRegisters,
54 kRuntimeParameterCoreRegistersLength,
55 kRuntimeParameterFpuRegisters,
Mathieu Chartiere401d142015-04-22 13:56:20 -070056 kRuntimeParameterFpuRegistersLength,
57 kX86PointerSize) {}
Nicolas Geoffrayd75948a2015-03-27 09:53:16 +000058
59 private:
60 DISALLOW_COPY_AND_ASSIGN(InvokeRuntimeCallingConvention);
61};
62
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +010063class InvokeDexCallingConvention : public CallingConvention<Register, XmmRegister> {
Nicolas Geoffraya747a392014-04-17 14:56:23 +010064 public:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +010065 InvokeDexCallingConvention() : CallingConvention(
66 kParameterCoreRegisters,
67 kParameterCoreRegistersLength,
68 kParameterFpuRegisters,
Mathieu Chartiere401d142015-04-22 13:56:20 -070069 kParameterFpuRegistersLength,
70 kX86PointerSize) {}
Nicolas Geoffraya747a392014-04-17 14:56:23 +010071
72 RegisterPair GetRegisterPairAt(size_t argument_index) {
73 DCHECK_LT(argument_index + 1, GetNumberOfRegisters());
74 return kParameterCorePairRegisters[argument_index];
75 }
76
77 private:
78 DISALLOW_COPY_AND_ASSIGN(InvokeDexCallingConvention);
79};
80
Roland Levillain2d27c8e2015-04-28 15:48:45 +010081class InvokeDexCallingConventionVisitorX86 : public InvokeDexCallingConventionVisitor {
Nicolas Geoffraya747a392014-04-17 14:56:23 +010082 public:
Roland Levillain2d27c8e2015-04-28 15:48:45 +010083 InvokeDexCallingConventionVisitorX86() {}
84 virtual ~InvokeDexCallingConventionVisitorX86() {}
Nicolas Geoffraya747a392014-04-17 14:56:23 +010085
Roland Levillainbbc6e7e2018-08-24 16:58:47 +010086 Location GetNextLocation(DataType::Type type) override;
87 Location GetReturnLocation(DataType::Type type) const override;
88 Location GetMethodLocation() const override;
Nicolas Geoffraya747a392014-04-17 14:56:23 +010089
90 private:
91 InvokeDexCallingConvention calling_convention;
Nicolas Geoffraya747a392014-04-17 14:56:23 +010092
Roland Levillain2d27c8e2015-04-28 15:48:45 +010093 DISALLOW_COPY_AND_ASSIGN(InvokeDexCallingConventionVisitorX86);
Nicolas Geoffraya747a392014-04-17 14:56:23 +010094};
95
Vladimir Marko86c87522020-05-11 16:55:55 +010096class CriticalNativeCallingConventionVisitorX86 : public InvokeDexCallingConventionVisitor {
97 public:
98 explicit CriticalNativeCallingConventionVisitorX86(bool for_register_allocation)
99 : for_register_allocation_(for_register_allocation) {}
100
101 virtual ~CriticalNativeCallingConventionVisitorX86() {}
102
103 Location GetNextLocation(DataType::Type type) override;
104 Location GetReturnLocation(DataType::Type type) const override;
105 Location GetMethodLocation() const override;
106
107 size_t GetStackOffset() const { return stack_offset_; }
108
109 private:
110 // Register allocator does not support adjusting frame size, so we cannot provide final locations
111 // of stack arguments for register allocation. We ask the register allocator for any location and
112 // move these arguments to the right place after adjusting the SP when generating the call.
113 const bool for_register_allocation_;
114 size_t stack_offset_ = 0u;
115
116 DISALLOW_COPY_AND_ASSIGN(CriticalNativeCallingConventionVisitorX86);
117};
118
Calin Juravlee460d1d2015-09-29 04:52:17 +0100119class FieldAccessCallingConventionX86 : public FieldAccessCallingConvention {
120 public:
121 FieldAccessCallingConventionX86() {}
122
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100123 Location GetObjectLocation() const override {
Calin Juravlee460d1d2015-09-29 04:52:17 +0100124 return Location::RegisterLocation(ECX);
125 }
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100126 Location GetFieldIndexLocation() const override {
Calin Juravlee460d1d2015-09-29 04:52:17 +0100127 return Location::RegisterLocation(EAX);
128 }
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100129 Location GetReturnLocation(DataType::Type type) const override {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100130 return DataType::Is64BitType(type)
Calin Juravlee460d1d2015-09-29 04:52:17 +0100131 ? Location::RegisterPairLocation(EAX, EDX)
132 : Location::RegisterLocation(EAX);
133 }
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100134 Location GetSetValueLocation(DataType::Type type, bool is_instance) const override {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100135 return DataType::Is64BitType(type)
Nicolas Geoffray5b3c6c02017-01-19 14:22:26 +0000136 ? (is_instance
137 ? Location::RegisterPairLocation(EDX, EBX)
138 : Location::RegisterPairLocation(ECX, EDX))
Calin Juravlee460d1d2015-09-29 04:52:17 +0100139 : (is_instance
140 ? Location::RegisterLocation(EDX)
141 : Location::RegisterLocation(ECX));
142 }
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100143 Location GetFpuLocation(DataType::Type type ATTRIBUTE_UNUSED) const override {
Calin Juravlee460d1d2015-09-29 04:52:17 +0100144 return Location::FpuRegisterLocation(XMM0);
145 }
146
147 private:
148 DISALLOW_COPY_AND_ASSIGN(FieldAccessCallingConventionX86);
149};
150
Zheng Xuad4450e2015-04-17 18:48:56 +0800151class ParallelMoveResolverX86 : public ParallelMoveResolverWithSwap {
Nicolas Geoffray86dbb9a2014-06-04 11:12:39 +0100152 public:
153 ParallelMoveResolverX86(ArenaAllocator* allocator, CodeGeneratorX86* codegen)
Zheng Xuad4450e2015-04-17 18:48:56 +0800154 : ParallelMoveResolverWithSwap(allocator), codegen_(codegen) {}
Nicolas Geoffray86dbb9a2014-06-04 11:12:39 +0100155
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100156 void EmitMove(size_t index) override;
157 void EmitSwap(size_t index) override;
158 void SpillScratch(int reg) override;
159 void RestoreScratch(int reg) override;
Nicolas Geoffray86dbb9a2014-06-04 11:12:39 +0100160
161 X86Assembler* GetAssembler() const;
162
163 private:
164 void Exchange(Register reg, int mem);
Mark Mendell7c8d0092015-01-26 11:21:33 -0500165 void Exchange32(XmmRegister reg, int mem);
Aart Bikcfe50bb2017-12-12 14:54:12 -0800166 void Exchange128(XmmRegister reg, int mem);
167 void ExchangeMemory(int mem1, int mem2, int number_of_words);
168 void MoveMemoryToMemory(int dst, int src, int number_of_words);
Nicolas Geoffray86dbb9a2014-06-04 11:12:39 +0100169
170 CodeGeneratorX86* const codegen_;
171
172 DISALLOW_COPY_AND_ASSIGN(ParallelMoveResolverX86);
173};
174
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000175class LocationsBuilderX86 : public HGraphVisitor {
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000176 public:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100177 LocationsBuilderX86(HGraph* graph, CodeGeneratorX86* codegen)
178 : HGraphVisitor(graph), codegen_(codegen) {}
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000179
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100180#define DECLARE_VISIT_INSTRUCTION(name, super) \
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100181 void Visit##name(H##name* instr) override;
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000182
Alexandre Ramesef20f712015-06-09 10:29:30 +0100183 FOR_EACH_CONCRETE_INSTRUCTION_COMMON(DECLARE_VISIT_INSTRUCTION)
184 FOR_EACH_CONCRETE_INSTRUCTION_X86(DECLARE_VISIT_INSTRUCTION)
Shalini Salomi Bodapatidd121f62018-10-26 15:03:53 +0530185 FOR_EACH_CONCRETE_INSTRUCTION_X86_COMMON(DECLARE_VISIT_INSTRUCTION)
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000186
187#undef DECLARE_VISIT_INSTRUCTION
188
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100189 void VisitInstruction(HInstruction* instruction) override {
Alexandre Ramesef20f712015-06-09 10:29:30 +0100190 LOG(FATAL) << "Unreachable instruction " << instruction->DebugName()
191 << " (id " << instruction->GetId() << ")";
192 }
193
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +0000194 private:
195 void HandleBitwiseOperation(HBinaryOperation* instruction);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +0100196 void HandleInvoke(HInvoke* invoke);
Vladimir Marko5f7b58e2015-11-23 19:49:34 +0000197 void HandleCondition(HCondition* condition);
Calin Juravle9aec02f2014-11-18 23:06:35 +0000198 void HandleShift(HBinaryOperation* instruction);
Calin Juravle52c48962014-12-16 17:02:57 +0000199 void HandleFieldSet(HInstruction* instruction, const FieldInfo& field_info);
200 void HandleFieldGet(HInstruction* instruction, const FieldInfo& field_info);
Shalini Salomi Bodapatib45a4352019-07-10 16:09:41 +0530201 bool CpuHasAvxFeatureFlag();
202 bool CpuHasAvx2FeatureFlag();
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +0100203
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100204 CodeGeneratorX86* const codegen_;
Roland Levillain2d27c8e2015-04-28 15:48:45 +0100205 InvokeDexCallingConventionVisitorX86 parameter_visitor_;
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100206
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000207 DISALLOW_COPY_AND_ASSIGN(LocationsBuilderX86);
208};
209
Aart Bik42249c32016-01-07 15:33:50 -0800210class InstructionCodeGeneratorX86 : public InstructionCodeGenerator {
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000211 public:
Nicolas Geoffray4a34a422014-04-03 10:38:37 +0100212 InstructionCodeGeneratorX86(HGraph* graph, CodeGeneratorX86* codegen);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000213
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100214#define DECLARE_VISIT_INSTRUCTION(name, super) \
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100215 void Visit##name(H##name* instr) override;
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000216
Alexandre Ramesef20f712015-06-09 10:29:30 +0100217 FOR_EACH_CONCRETE_INSTRUCTION_COMMON(DECLARE_VISIT_INSTRUCTION)
218 FOR_EACH_CONCRETE_INSTRUCTION_X86(DECLARE_VISIT_INSTRUCTION)
Shalini Salomi Bodapatidd121f62018-10-26 15:03:53 +0530219 FOR_EACH_CONCRETE_INSTRUCTION_X86_COMMON(DECLARE_VISIT_INSTRUCTION)
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000220
221#undef DECLARE_VISIT_INSTRUCTION
222
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100223 void VisitInstruction(HInstruction* instruction) override {
Alexandre Ramesef20f712015-06-09 10:29:30 +0100224 LOG(FATAL) << "Unreachable instruction " << instruction->DebugName()
225 << " (id " << instruction->GetId() << ")";
226 }
227
Nicolas Geoffray4a34a422014-04-03 10:38:37 +0100228 X86Assembler* GetAssembler() const { return assembler_; }
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000229
Vladimir Markof3e0ee22015-12-17 15:23:13 +0000230 // The compare/jump sequence will generate about (1.5 * num_entries) instructions. A jump
231 // table version generates 7 instructions and num_entries literals. Compare/jump sequence will
232 // generates less code/data with a small num_entries.
233 static constexpr uint32_t kPackedSwitchJumpTableThreshold = 5;
234
Andra Danciu1ca6f322020-08-12 08:58:07 +0000235 // Generate a GC root reference load:
236 //
237 // root <- *address
238 //
239 // while honoring read barriers based on read_barrier_option.
240 void GenerateGcRootFieldLoad(HInstruction* instruction,
241 Location root,
242 const Address& address,
243 Label* fixup_label,
244 ReadBarrierOption read_barrier_option);
245
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000246 private:
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100247 // Generate code for the given suspend check. If not null, `successor`
248 // is the block to branch to if the suspend check is not needed, and after
249 // the suspend call.
250 void GenerateSuspendCheck(HSuspendCheck* check, HBasicBlock* successor);
Andreas Gampe85b62f22015-09-09 13:15:38 -0700251 void GenerateClassInitializationCheck(SlowPathCode* slow_path, Register class_reg);
Vladimir Marko175e7862018-03-27 09:03:13 +0000252 void GenerateBitstringTypeCheckCompare(HTypeCheckInstruction* check, Register temp);
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +0000253 void HandleBitwiseOperation(HBinaryOperation* instruction);
Calin Juravlebacfec32014-11-14 15:54:36 +0000254 void GenerateDivRemIntegral(HBinaryOperation* instruction);
Guillaume Sanchez0f88e872015-03-30 17:55:45 +0100255 void DivRemOneOrMinusOne(HBinaryOperation* instruction);
Guillaume Sanchezb19930c2015-04-09 21:12:15 +0100256 void DivByPowerOfTwo(HDiv* instruction);
Shalini Salomi Bodapatia66784b2018-11-06 13:05:44 +0530257 void RemByPowerOfTwo(HRem* instruction);
Guillaume Sanchez0f88e872015-03-30 17:55:45 +0100258 void GenerateDivRemWithAnyConstant(HBinaryOperation* instruction);
Mark Mendellc4701932015-04-10 13:18:51 -0400259 void GenerateRemFP(HRem* rem);
Vladimir Marko5f7b58e2015-11-23 19:49:34 +0000260 void HandleCondition(HCondition* condition);
Calin Juravle9aec02f2014-11-18 23:06:35 +0000261 void HandleShift(HBinaryOperation* instruction);
262 void GenerateShlLong(const Location& loc, Register shifter);
263 void GenerateShrLong(const Location& loc, Register shifter);
264 void GenerateUShrLong(const Location& loc, Register shifter);
Mark P Mendell73945692015-04-29 14:56:17 +0000265 void GenerateShlLong(const Location& loc, int shift);
266 void GenerateShrLong(const Location& loc, int shift);
267 void GenerateUShrLong(const Location& loc, int shift);
Aart Bik351df3e2018-03-07 11:54:57 -0800268 void GenerateMinMaxInt(LocationSummary* locations, bool is_min, DataType::Type type);
Aart Bik1f8d51b2018-02-15 10:42:37 -0800269 void GenerateMinMaxFP(LocationSummary* locations, bool is_min, DataType::Type type);
Aart Bik351df3e2018-03-07 11:54:57 -0800270 void GenerateMinMax(HBinaryOperation* minmax, bool is_min);
Roland Levillain7c1559a2015-12-15 10:55:36 +0000271
Nicolas Geoffray07276db2015-05-18 14:22:09 +0100272 void HandleFieldSet(HInstruction* instruction,
273 const FieldInfo& field_info,
274 bool value_can_be_null);
Calin Juravle52c48962014-12-16 17:02:57 +0000275 void HandleFieldGet(HInstruction* instruction, const FieldInfo& field_info);
Roland Levillain7c1559a2015-12-15 10:55:36 +0000276
277 // Generate a heap reference load using one register `out`:
278 //
279 // out <- *(out + offset)
280 //
281 // while honoring heap poisoning and/or read barriers (if any).
Roland Levillain95e7ffc2016-01-22 11:57:25 +0000282 //
283 // Location `maybe_temp` is used when generating a read barrier and
284 // shall be a register in that case; it may be an invalid location
285 // otherwise.
Roland Levillain7c1559a2015-12-15 10:55:36 +0000286 void GenerateReferenceLoadOneRegister(HInstruction* instruction,
287 Location out,
288 uint32_t offset,
Mathieu Chartieraa474eb2016-11-09 15:18:27 -0800289 Location maybe_temp,
Mathieu Chartier3af00dc2016-11-10 11:25:57 -0800290 ReadBarrierOption read_barrier_option);
Roland Levillain7c1559a2015-12-15 10:55:36 +0000291 // Generate a heap reference load using two different registers
292 // `out` and `obj`:
293 //
294 // out <- *(obj + offset)
295 //
296 // while honoring heap poisoning and/or read barriers (if any).
Roland Levillain95e7ffc2016-01-22 11:57:25 +0000297 //
298 // Location `maybe_temp` is used when generating a Baker's (fast
299 // path) read barrier and shall be a register in that case; it may
300 // be an invalid location otherwise.
Roland Levillain7c1559a2015-12-15 10:55:36 +0000301 void GenerateReferenceLoadTwoRegisters(HInstruction* instruction,
302 Location out,
303 Location obj,
Mathieu Chartier5c44c1b2016-11-04 18:13:04 -0700304 uint32_t offset,
Mathieu Chartier3af00dc2016-11-10 11:25:57 -0800305 ReadBarrierOption read_barrier_option);
Roland Levillain7c1559a2015-12-15 10:55:36 +0000306
Roland Levillain232ade02015-04-20 15:14:36 +0100307 // Push value to FPU stack. `is_fp` specifies whether the value is floating point or not.
308 // `is_wide` specifies whether it is long/double or not.
Mark Mendell24f2dfa2015-01-14 19:51:45 -0500309 void PushOntoFPStack(Location source, uint32_t temp_offset,
Roland Levillain232ade02015-04-20 15:14:36 +0100310 uint32_t stack_adjustment, bool is_fp, bool is_wide);
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100311
Mark Mendell152408f2015-12-31 12:28:50 -0500312 template<class LabelType>
Mingyao Yangd43b3ac2015-04-01 14:03:04 -0700313 void GenerateTestAndBranch(HInstruction* instruction,
David Brazdil0debae72015-11-12 18:37:00 +0000314 size_t condition_input_index,
Mark Mendell152408f2015-12-31 12:28:50 -0500315 LabelType* true_target,
316 LabelType* false_target);
317 template<class LabelType>
David Brazdil0debae72015-11-12 18:37:00 +0000318 void GenerateCompareTestAndBranch(HCondition* condition,
Mark Mendell152408f2015-12-31 12:28:50 -0500319 LabelType* true_target,
320 LabelType* false_target);
321 template<class LabelType>
322 void GenerateFPJumps(HCondition* cond, LabelType* true_label, LabelType* false_label);
323 template<class LabelType>
324 void GenerateLongComparesAndJumps(HCondition* cond,
325 LabelType* true_label,
326 LabelType* false_label);
327
David Brazdilfc6a86a2015-06-26 10:33:45 +0000328 void HandleGoto(HInstruction* got, HBasicBlock* successor);
Vladimir Markof3e0ee22015-12-17 15:23:13 +0000329 void GenPackedSwitchWithCompares(Register value_reg,
330 int32_t lower_bound,
331 uint32_t num_entries,
332 HBasicBlock* switch_block,
333 HBasicBlock* default_block);
Calin Juravlecd6dffe2015-01-08 17:35:35 +0000334
Mark P Mendell2f10a5f2016-01-25 14:47:50 +0000335 void GenerateFPCompare(Location lhs, Location rhs, HInstruction* insn, bool is_double);
Shalini Salomi Bodapatib45a4352019-07-10 16:09:41 +0530336 bool CpuHasAvxFeatureFlag();
337 bool CpuHasAvx2FeatureFlag();
Mark P Mendell2f10a5f2016-01-25 14:47:50 +0000338
Nicolas Geoffray4a34a422014-04-03 10:38:37 +0100339 X86Assembler* const assembler_;
340 CodeGeneratorX86* const codegen_;
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000341
342 DISALLOW_COPY_AND_ASSIGN(InstructionCodeGeneratorX86);
343};
344
Mark Mendell805b3b52015-09-18 14:10:29 -0400345class JumpTableRIPFixup;
346
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000347class CodeGeneratorX86 : public CodeGenerator {
348 public:
Mark Mendellfb8d2792015-03-31 22:16:59 -0400349 CodeGeneratorX86(HGraph* graph,
Serban Constantinescuecc43662015-08-13 13:33:12 +0100350 const CompilerOptions& compiler_options,
351 OptimizingCompilerStats* stats = nullptr);
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +0100352 virtual ~CodeGeneratorX86() {}
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000353
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100354 void GenerateFrameEntry() override;
355 void GenerateFrameExit() override;
356 void Bind(HBasicBlock* block) override;
357 void MoveConstant(Location destination, int32_t value) override;
358 void MoveLocation(Location dst, Location src, DataType::Type dst_type) override;
359 void AddLocationAsTemp(Location location, LocationSummary* locations) override;
Calin Juravlee460d1d2015-09-29 04:52:17 +0100360
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100361 size_t SaveCoreRegister(size_t stack_index, uint32_t reg_id) override;
362 size_t RestoreCoreRegister(size_t stack_index, uint32_t reg_id) override;
363 size_t SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) override;
364 size_t RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) override;
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000365
Alexandre Rames8158f282015-08-07 10:26:17 +0100366 // Generate code to invoke a runtime entry point.
Calin Juravle175dc732015-08-25 15:42:32 +0100367 void InvokeRuntime(QuickEntrypointEnum entrypoint,
368 HInstruction* instruction,
369 uint32_t dex_pc,
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100370 SlowPathCode* slow_path = nullptr) override;
Alexandre Rames8158f282015-08-07 10:26:17 +0100371
Roland Levillaindec8f632016-07-22 17:10:06 +0100372 // Generate code to invoke a runtime entry point, but do not record
373 // PC-related information in a stack map.
374 void InvokeRuntimeWithoutRecordingPcInfo(int32_t entry_point_offset,
375 HInstruction* instruction,
376 SlowPathCode* slow_path);
377
Serban Constantinescuba45db02016-07-12 22:53:02 +0100378 void GenerateInvokeRuntime(int32_t entry_point_offset);
379
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100380 size_t GetWordSize() const override {
Nicolas Geoffray707c8092014-04-04 10:50:14 +0100381 return kX86WordSize;
382 }
383
Artem Serov6a0b6572019-07-26 20:38:37 +0100384 size_t GetSlowPathFPWidth() const override {
Aart Bikb13c65b2017-03-21 20:14:07 -0700385 return GetGraph()->HasSIMD()
Artem Serovc8150b52019-07-31 18:28:00 +0100386 ? GetSIMDRegisterWidth()
Aart Bikb13c65b2017-03-21 20:14:07 -0700387 : 2 * kX86WordSize; // 8 bytes == 2 words for each spill
Mark Mendellf85a9ca2015-01-13 09:20:58 -0500388 }
389
Artem Serov6a0b6572019-07-26 20:38:37 +0100390 size_t GetCalleePreservedFPWidth() const override {
391 return 2 * kX86WordSize;
392 }
393
Artem Serovc8150b52019-07-31 18:28:00 +0100394 size_t GetSIMDRegisterWidth() const override {
395 return 4 * kX86WordSize;
396 }
397
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100398 HGraphVisitor* GetLocationBuilder() override {
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000399 return &location_builder_;
400 }
401
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100402 HGraphVisitor* GetInstructionVisitor() override {
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000403 return &instruction_visitor_;
404 }
405
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100406 X86Assembler* GetAssembler() override {
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000407 return &assembler_;
408 }
409
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100410 const X86Assembler& GetAssembler() const override {
Alexandre Rameseb7b7392015-06-19 14:47:01 +0100411 return assembler_;
412 }
413
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100414 uintptr_t GetAddressOf(HBasicBlock* block) override {
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +0000415 return GetLabelOf(block)->Position();
416 }
Calin Juravle34bacdf2014-10-07 20:23:36 +0100417
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100418 void SetupBlockedRegisters() const override;
Nicolas Geoffray4a34a422014-04-03 10:38:37 +0100419
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100420 void DumpCoreRegister(std::ostream& stream, int reg) const override;
421 void DumpFloatingPointRegister(std::ostream& stream, int reg) const override;
Nicolas Geoffraya7062e02014-05-22 12:50:17 +0100422
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100423 ParallelMoveResolverX86* GetMoveResolver() override {
Nicolas Geoffray86dbb9a2014-06-04 11:12:39 +0100424 return &move_resolver_;
425 }
426
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100427 InstructionSet GetInstructionSet() const override {
Nicolas Geoffray412f10c2014-06-19 10:00:34 +0100428 return InstructionSet::kX86;
429 }
430
Vladimir Markoa0431112018-06-25 09:32:54 +0100431 const X86InstructionSetFeatures& GetInstructionSetFeatures() const;
432
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100433 // Helper method to move a 32bits value between two locations.
434 void Move32(Location destination, Location source);
435 // Helper method to move a 64bits value between two locations.
436 void Move64(Location destination, Location source);
Andra Danciu73c31802020-09-01 13:17:05 +0000437 // Helper method to move a primitive value from an address to a register.
Andra Danciu1ca6f322020-08-12 08:58:07 +0000438 void MoveFromMemory(DataType::Type dst_type,
439 Location dst,
440 Register src_base,
441 Register src_index = Register::kNoRegister,
442 ScaleFactor src_scale = TIMES_1,
443 int32_t src_disp = 0);
Andra Danciu73c31802020-09-01 13:17:05 +0000444 // Helper method to move a primitive value from a location to an address.
445 void MoveToMemory(DataType::Type src_type,
446 Location src,
447 Register dst_base,
448 Register dst_index = Register::kNoRegister,
449 ScaleFactor dst_scale = TIMES_1,
450 int32_t dst_disp = 0);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100451
Vladimir Markocac5a7e2016-02-22 10:39:50 +0000452 // Check if the desired_string_load_kind is supported. If it is, return it,
453 // otherwise return a fall-back kind that should be used instead.
454 HLoadString::LoadKind GetSupportedLoadStringKind(
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100455 HLoadString::LoadKind desired_string_load_kind) override;
Vladimir Markocac5a7e2016-02-22 10:39:50 +0000456
Vladimir Markodbb7f5b2016-03-30 13:23:58 +0100457 // Check if the desired_class_load_kind is supported. If it is, return it,
458 // otherwise return a fall-back kind that should be used instead.
459 HLoadClass::LoadKind GetSupportedLoadClassKind(
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100460 HLoadClass::LoadKind desired_class_load_kind) override;
Vladimir Markodbb7f5b2016-03-30 13:23:58 +0100461
Vladimir Markodc151b22015-10-15 18:02:30 +0100462 // Check if the desired_dispatch_info is supported. If it is, return it,
463 // otherwise return a fall-back info that should be used instead.
464 HInvokeStaticOrDirect::DispatchInfo GetSupportedInvokeStaticOrDirectDispatch(
465 const HInvokeStaticOrDirect::DispatchInfo& desired_dispatch_info,
Nicolas Geoffraybdb2ecc2018-09-18 14:33:55 +0100466 ArtMethod* method) override;
Vladimir Markodc151b22015-10-15 18:02:30 +0100467
Mark Mendell09ed1a32015-03-25 08:30:06 -0400468 // Generate a call to a static or direct method.
Vladimir Markoe7197bf2017-06-02 17:00:23 +0100469 void GenerateStaticOrDirectCall(
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100470 HInvokeStaticOrDirect* invoke, Location temp, SlowPathCode* slow_path = nullptr) override;
Andreas Gampebfb5ba92015-09-01 15:45:02 +0000471 // Generate a call to a virtual method.
Vladimir Markoe7197bf2017-06-02 17:00:23 +0100472 void GenerateVirtualCall(
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100473 HInvokeVirtual* invoke, Location temp, SlowPathCode* slow_path = nullptr) override;
Andreas Gampe85b62f22015-09-09 13:15:38 -0700474
Vladimir Marko6fd16062018-06-26 11:02:04 +0100475 void RecordBootImageIntrinsicPatch(HX86ComputeBaseMethodAddress* method_address,
476 uint32_t intrinsic_data);
Vladimir Markob066d432018-01-03 13:14:37 +0000477 void RecordBootImageRelRoPatch(HX86ComputeBaseMethodAddress* method_address,
478 uint32_t boot_image_offset);
Vladimir Marko59eb30f2018-02-20 11:52:34 +0000479 void RecordBootImageMethodPatch(HInvokeStaticOrDirect* invoke);
480 void RecordMethodBssEntryPatch(HInvokeStaticOrDirect* invoke);
481 void RecordBootImageTypePatch(HLoadClass* load_class);
Vladimir Marko6bec91c2017-01-09 15:03:12 +0000482 Label* NewTypeBssEntryPatch(HLoadClass* load_class);
Vladimir Marko59eb30f2018-02-20 11:52:34 +0000483 void RecordBootImageStringPatch(HLoadString* load_string);
Vladimir Markoaad75c62016-10-03 08:46:48 +0000484 Label* NewStringBssEntryPatch(HLoadString* load_string);
Vladimir Markoeebb8212018-06-05 14:57:24 +0100485
486 void LoadBootImageAddress(Register reg,
Vladimir Marko6fd16062018-06-26 11:02:04 +0100487 uint32_t boot_image_reference,
Vladimir Markoeebb8212018-06-05 14:57:24 +0100488 HInvokeStaticOrDirect* invoke);
Vladimir Marko6fd16062018-06-26 11:02:04 +0100489 void AllocateInstanceForIntrinsic(HInvokeStaticOrDirect* invoke, uint32_t boot_image_offset);
Vladimir Markoeebb8212018-06-05 14:57:24 +0100490
Nicolas Geoffrayf0acfe72017-01-09 20:54:52 +0000491 Label* NewJitRootStringPatch(const DexFile& dex_file,
Vladimir Marko174b2e22017-10-12 13:34:49 +0100492 dex::StringIndex string_index,
Nicolas Geoffrayf0acfe72017-01-09 20:54:52 +0000493 Handle<mirror::String> handle);
Nicolas Geoffray5247c082017-01-13 14:17:29 +0000494 Label* NewJitRootClassPatch(const DexFile& dex_file,
Vladimir Marko174b2e22017-10-12 13:34:49 +0100495 dex::TypeIndex type_index,
Nicolas Geoffray5247c082017-01-13 14:17:29 +0000496 Handle<mirror::Class> handle);
Vladimir Markocac5a7e2016-02-22 10:39:50 +0000497
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100498 void MoveFromReturnRegister(Location trg, DataType::Type type) override;
Mark Mendell09ed1a32015-03-25 08:30:06 -0400499
Vladimir Marko58155012015-08-19 12:49:41 +0000500 // Emit linker patches.
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100501 void EmitLinkerPatches(ArenaVector<linker::LinkerPatch>* linker_patches) override;
Vladimir Marko58155012015-08-19 12:49:41 +0000502
Nicolas Geoffray22384ae2016-12-12 22:33:36 +0000503 void PatchJitRootUse(uint8_t* code,
504 const uint8_t* roots_data,
505 const PatchInfo<Label>& info,
506 uint64_t index_in_table) const;
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100507 void EmitJitRootPatches(uint8_t* code, const uint8_t* roots_data) override;
Nicolas Geoffray132d8362016-11-16 09:19:42 +0000508
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100509 // Emit a write barrier.
Nicolas Geoffray07276db2015-05-18 14:22:09 +0100510 void MarkGCCard(Register temp,
511 Register card,
512 Register object,
513 Register value,
514 bool value_can_be_null);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100515
Roland Levillain7c1559a2015-12-15 10:55:36 +0000516 void GenerateMemoryBarrier(MemBarrierKind kind);
517
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100518 Label* GetLabelOf(HBasicBlock* block) const {
Vladimir Marko225b6462015-09-28 12:17:40 +0100519 return CommonGetLabelOf<Label>(block_labels_, block);
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100520 }
521
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100522 void Initialize() override {
Vladimir Marko225b6462015-09-28 12:17:40 +0100523 block_labels_ = CommonInitializeLabels<Label>();
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100524 }
525
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100526 bool NeedsTwoRegisters(DataType::Type type) const override {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100527 return type == DataType::Type::kInt64;
Nicolas Geoffray840e5462015-01-07 16:01:24 +0000528 }
529
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100530 bool ShouldSplitLongMoves() const override { return true; }
Nicolas Geoffray234d69d2015-03-09 10:28:50 +0000531
Nicolas Geoffray1cf95282014-12-12 19:22:03 +0000532 Label* GetFrameEntryLabel() { return &frame_entry_label_; }
533
Nicolas Geoffray133719e2017-01-22 15:44:39 +0000534 void AddMethodAddressOffset(HX86ComputeBaseMethodAddress* method_base, int32_t offset) {
535 method_address_offset_.Put(method_base->GetId(), offset);
Mark Mendell0616ae02015-04-17 12:49:27 -0400536 }
537
Nicolas Geoffray133719e2017-01-22 15:44:39 +0000538 int32_t GetMethodAddressOffset(HX86ComputeBaseMethodAddress* method_base) const {
539 return method_address_offset_.Get(method_base->GetId());
Mark Mendell0616ae02015-04-17 12:49:27 -0400540 }
541
542 int32_t ConstantAreaStart() const {
543 return constant_area_start_;
544 }
545
Nicolas Geoffray133719e2017-01-22 15:44:39 +0000546 Address LiteralDoubleAddress(double v, HX86ComputeBaseMethodAddress* method_base, Register reg);
547 Address LiteralFloatAddress(float v, HX86ComputeBaseMethodAddress* method_base, Register reg);
548 Address LiteralInt32Address(int32_t v, HX86ComputeBaseMethodAddress* method_base, Register reg);
549 Address LiteralInt64Address(int64_t v, HX86ComputeBaseMethodAddress* method_base, Register reg);
Mark Mendell0616ae02015-04-17 12:49:27 -0400550
Aart Bika19616e2016-02-01 18:57:58 -0800551 // Load a 32-bit value into a register in the most efficient manner.
552 void Load32BitValue(Register dest, int32_t value);
553
554 // Compare a register with a 32-bit value in the most efficient manner.
555 void Compare32BitValue(Register dest, int32_t value);
556
Vladimir Marko56f4bdd2016-09-16 11:32:36 +0100557 // Compare int values. Supports only register locations for `lhs`.
558 void GenerateIntCompare(Location lhs, Location rhs);
jessicahandojo4877b792016-09-08 19:49:13 -0700559 void GenerateIntCompare(Register lhs, Location rhs);
Vladimir Marko56f4bdd2016-09-16 11:32:36 +0100560
561 // Construct address for array access.
562 static Address ArrayAddress(Register obj,
563 Location index,
564 ScaleFactor scale,
565 uint32_t data_offset);
566
Mark Mendell805b3b52015-09-18 14:10:29 -0400567 Address LiteralCaseTable(HX86PackedSwitch* switch_instr, Register reg, Register value);
568
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100569 void Finalize(CodeAllocator* allocator) override;
Mark Mendell0616ae02015-04-17 12:49:27 -0400570
Roland Levillain7c1559a2015-12-15 10:55:36 +0000571 // Fast path implementation of ReadBarrier::Barrier for a heap
572 // reference field load when Baker's read barriers are used.
573 void GenerateFieldLoadWithBakerReadBarrier(HInstruction* instruction,
Roland Levillaine3f43ac2016-01-19 15:07:47 +0000574 Location ref,
Roland Levillain7c1559a2015-12-15 10:55:36 +0000575 Register obj,
576 uint32_t offset,
Roland Levillain7c1559a2015-12-15 10:55:36 +0000577 bool needs_null_check);
578 // Fast path implementation of ReadBarrier::Barrier for a heap
579 // reference array load when Baker's read barriers are used.
580 void GenerateArrayLoadWithBakerReadBarrier(HInstruction* instruction,
Roland Levillaine3f43ac2016-01-19 15:07:47 +0000581 Location ref,
Roland Levillain7c1559a2015-12-15 10:55:36 +0000582 Register obj,
583 uint32_t data_offset,
584 Location index,
Roland Levillain7c1559a2015-12-15 10:55:36 +0000585 bool needs_null_check);
Roland Levillaina1aa3b12016-10-26 13:03:38 +0100586 // Factored implementation, used by GenerateFieldLoadWithBakerReadBarrier,
587 // GenerateArrayLoadWithBakerReadBarrier and some intrinsics.
588 //
589 // Load the object reference located at address `src`, held by
590 // object `obj`, into `ref`, and mark it if needed. The base of
591 // address `src` must be `obj`.
592 //
593 // If `always_update_field` is true, the value of the reference is
594 // atomically updated in the holder (`obj`). This operation
595 // requires a temporary register, which must be provided as a
596 // non-null pointer (`temp`).
Sang, Chunlei0fcd2b82016-04-05 17:12:59 +0800597 void GenerateReferenceLoadWithBakerReadBarrier(HInstruction* instruction,
598 Location ref,
599 Register obj,
600 const Address& src,
Roland Levillaina1aa3b12016-10-26 13:03:38 +0100601 bool needs_null_check,
602 bool always_update_field = false,
603 Register* temp = nullptr);
Roland Levillain7c1559a2015-12-15 10:55:36 +0000604
605 // Generate a read barrier for a heap reference within `instruction`
606 // using a slow path.
Roland Levillain0d5a2812015-11-13 10:07:31 +0000607 //
608 // A read barrier for an object reference read from the heap is
609 // implemented as a call to the artReadBarrierSlow runtime entry
610 // point, which is passed the values in locations `ref`, `obj`, and
611 // `offset`:
612 //
613 // mirror::Object* artReadBarrierSlow(mirror::Object* ref,
614 // mirror::Object* obj,
615 // uint32_t offset);
616 //
617 // The `out` location contains the value returned by
618 // artReadBarrierSlow.
619 //
620 // When `index` is provided (i.e. for array accesses), the offset
621 // value passed to artReadBarrierSlow is adjusted to take `index`
622 // into account.
Roland Levillain7c1559a2015-12-15 10:55:36 +0000623 void GenerateReadBarrierSlow(HInstruction* instruction,
624 Location out,
625 Location ref,
626 Location obj,
627 uint32_t offset,
628 Location index = Location::NoLocation());
Roland Levillain0d5a2812015-11-13 10:07:31 +0000629
Roland Levillain7c1559a2015-12-15 10:55:36 +0000630 // If read barriers are enabled, generate a read barrier for a heap
631 // reference using a slow path. If heap poisoning is enabled, also
632 // unpoison the reference in `out`.
633 void MaybeGenerateReadBarrierSlow(HInstruction* instruction,
634 Location out,
635 Location ref,
636 Location obj,
637 uint32_t offset,
638 Location index = Location::NoLocation());
Roland Levillain0d5a2812015-11-13 10:07:31 +0000639
Roland Levillain7c1559a2015-12-15 10:55:36 +0000640 // Generate a read barrier for a GC root within `instruction` using
641 // a slow path.
Roland Levillain0d5a2812015-11-13 10:07:31 +0000642 //
643 // A read barrier for an object reference GC root is implemented as
644 // a call to the artReadBarrierForRootSlow runtime entry point,
645 // which is passed the value in location `root`:
646 //
647 // mirror::Object* artReadBarrierForRootSlow(GcRoot<mirror::Object>* root);
648 //
649 // The `out` location contains the value returned by
650 // artReadBarrierForRootSlow.
Roland Levillain7c1559a2015-12-15 10:55:36 +0000651 void GenerateReadBarrierForRootSlow(HInstruction* instruction, Location out, Location root);
Roland Levillain0d5a2812015-11-13 10:07:31 +0000652
Mark P Mendell17077d82015-12-16 19:15:59 +0000653 // Ensure that prior stores complete to memory before subsequent loads.
654 // The locked add implementation will avoid serializing device memory, but will
655 // touch (but not change) the top of the stack.
656 // The 'non_temporal' parameter should be used to ensure ordering of non-temporal stores.
657 void MemoryFence(bool non_temporal = false) {
Mark Mendell7aa04a12016-01-27 22:39:07 -0500658 if (!non_temporal) {
Mark P Mendell17077d82015-12-16 19:15:59 +0000659 assembler_.lock()->addl(Address(ESP, 0), Immediate(0));
660 } else {
661 assembler_.mfence();
662 }
663 }
664
Vladimir Markodec78172020-06-19 15:31:23 +0100665 void IncreaseFrame(size_t adjustment) override;
666 void DecreaseFrame(size_t adjustment) override;
667
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100668 void GenerateNop() override;
669 void GenerateImplicitNullCheck(HNullCheck* instruction) override;
670 void GenerateExplicitNullCheck(HNullCheck* instruction) override;
Mark P Mendell17077d82015-12-16 19:15:59 +0000671
Nicolas Geoffraye2a3aa92019-11-25 17:52:58 +0000672 void MaybeGenerateInlineCacheCheck(HInstruction* instruction, Register klass);
Nicolas Geoffraya59af8a2019-11-27 17:42:32 +0000673 void MaybeIncrementHotness(bool is_frame_entry);
Nicolas Geoffraye2a3aa92019-11-25 17:52:58 +0000674
Vladimir Marko4ef451a2020-07-23 09:54:27 +0000675 // When we don't know the proper offset for the value, we use kPlaceholder32BitOffset.
Vladimir Markocac5a7e2016-02-22 10:39:50 +0000676 // The correct value will be inserted when processing Assembler fixups.
Vladimir Marko4ef451a2020-07-23 09:54:27 +0000677 static constexpr int32_t kPlaceholder32BitOffset = 256;
Vladimir Markocac5a7e2016-02-22 10:39:50 +0000678
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100679 private:
Nicolas Geoffray133719e2017-01-22 15:44:39 +0000680 struct X86PcRelativePatchInfo : PatchInfo<Label> {
681 X86PcRelativePatchInfo(HX86ComputeBaseMethodAddress* address,
Vladimir Marko59eb30f2018-02-20 11:52:34 +0000682 const DexFile* target_dex_file,
Nicolas Geoffray133719e2017-01-22 15:44:39 +0000683 uint32_t target_index)
684 : PatchInfo(target_dex_file, target_index),
685 method_address(address) {}
686 HX86ComputeBaseMethodAddress* method_address;
687 };
Vladimir Marko0f7dca42015-11-02 14:36:43 +0000688
Vladimir Markod8dbc8d2017-09-20 13:37:47 +0100689 template <linker::LinkerPatch (*Factory)(size_t, const DexFile*, uint32_t, uint32_t)>
Nicolas Geoffray133719e2017-01-22 15:44:39 +0000690 void EmitPcRelativeLinkerPatches(const ArenaDeque<X86PcRelativePatchInfo>& infos,
Vladimir Markod8dbc8d2017-09-20 13:37:47 +0100691 ArenaVector<linker::LinkerPatch>* linker_patches);
Vladimir Marko0f7dca42015-11-02 14:36:43 +0000692
Nicolas Geoffray133719e2017-01-22 15:44:39 +0000693 Register GetInvokeStaticOrDirectExtraParameter(HInvokeStaticOrDirect* invoke, Register temp);
694
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100695 // Labels for each block that will be compiled.
Vladimir Marko225b6462015-09-28 12:17:40 +0100696 Label* block_labels_; // Indexed by block id.
Nicolas Geoffray1cf95282014-12-12 19:22:03 +0000697 Label frame_entry_label_;
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000698 LocationsBuilderX86 location_builder_;
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000699 InstructionCodeGeneratorX86 instruction_visitor_;
Nicolas Geoffray86dbb9a2014-06-04 11:12:39 +0100700 ParallelMoveResolverX86 move_resolver_;
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000701 X86Assembler assembler_;
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000702
Vladimir Marko2d06e022019-07-08 15:45:19 +0100703 // PC-relative method patch info for kBootImageLinkTimePcRelative.
Vladimir Marko65979462017-05-19 17:25:12 +0100704 ArenaDeque<X86PcRelativePatchInfo> boot_image_method_patches_;
Vladimir Marko0eb882b2017-05-15 13:39:18 +0100705 // PC-relative method patch info for kBssEntry.
706 ArenaDeque<X86PcRelativePatchInfo> method_bss_entry_patches_;
Vladimir Marko764d4542017-05-16 10:31:41 +0100707 // PC-relative type patch info for kBootImageLinkTimePcRelative.
Nicolas Geoffray133719e2017-01-22 15:44:39 +0000708 ArenaDeque<X86PcRelativePatchInfo> boot_image_type_patches_;
Vladimir Markoe47f60c2018-02-21 13:43:28 +0000709 // PC-relative type patch info for kBssEntry.
Nicolas Geoffray133719e2017-01-22 15:44:39 +0000710 ArenaDeque<X86PcRelativePatchInfo> type_bss_entry_patches_;
Vladimir Markoe47f60c2018-02-21 13:43:28 +0000711 // PC-relative String patch info for kBootImageLinkTimePcRelative.
Vladimir Marko59eb30f2018-02-20 11:52:34 +0000712 ArenaDeque<X86PcRelativePatchInfo> boot_image_string_patches_;
Vladimir Markoe47f60c2018-02-21 13:43:28 +0000713 // PC-relative String patch info for kBssEntry.
Vladimir Marko6cfbdbc2017-07-25 13:26:39 +0100714 ArenaDeque<X86PcRelativePatchInfo> string_bss_entry_patches_;
Vladimir Marko2d06e022019-07-08 15:45:19 +0100715 // PC-relative patch info for IntrinsicObjects for the boot image,
716 // and for method/type/string patches for kBootImageRelRo otherwise.
717 ArenaDeque<X86PcRelativePatchInfo> boot_image_other_patches_;
Vladimir Marko58155012015-08-19 12:49:41 +0000718
Nicolas Geoffray132d8362016-11-16 09:19:42 +0000719 // Patches for string root accesses in JIT compiled code.
720 ArenaDeque<PatchInfo<Label>> jit_string_patches_;
Nicolas Geoffray22384ae2016-12-12 22:33:36 +0000721 // Patches for class root accesses in JIT compiled code.
722 ArenaDeque<PatchInfo<Label>> jit_class_patches_;
723
Mark Mendell0616ae02015-04-17 12:49:27 -0400724 // Offset to the start of the constant area in the assembled code.
725 // Used for fixups to the constant area.
726 int32_t constant_area_start_;
727
Mark Mendell805b3b52015-09-18 14:10:29 -0400728 // Fixups for jump tables that need to be patched after the constant table is generated.
729 ArenaVector<JumpTableRIPFixup*> fixups_to_jump_tables_;
730
Nicolas Geoffray133719e2017-01-22 15:44:39 +0000731 // Maps a HX86ComputeBaseMethodAddress instruction id, to its offset in the
732 // compiled code.
733 ArenaSafeMap<uint32_t, int32_t> method_address_offset_;
Mark Mendell0616ae02015-04-17 12:49:27 -0400734
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000735 DISALLOW_COPY_AND_ASSIGN(CodeGeneratorX86);
736};
737
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000738} // namespace x86
739} // namespace art
740
741#endif // ART_COMPILER_OPTIMIZING_CODE_GENERATOR_X86_H_