blob: 43f5acdd65eca908f70a21fb8d3334e3983ec3f6 [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
Calin Juravlee460d1d2015-09-29 04:52:17 +010096class FieldAccessCallingConventionX86 : public FieldAccessCallingConvention {
97 public:
98 FieldAccessCallingConventionX86() {}
99
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100100 Location GetObjectLocation() const override {
Calin Juravlee460d1d2015-09-29 04:52:17 +0100101 return Location::RegisterLocation(ECX);
102 }
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100103 Location GetFieldIndexLocation() const override {
Calin Juravlee460d1d2015-09-29 04:52:17 +0100104 return Location::RegisterLocation(EAX);
105 }
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100106 Location GetReturnLocation(DataType::Type type) const override {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100107 return DataType::Is64BitType(type)
Calin Juravlee460d1d2015-09-29 04:52:17 +0100108 ? Location::RegisterPairLocation(EAX, EDX)
109 : Location::RegisterLocation(EAX);
110 }
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100111 Location GetSetValueLocation(DataType::Type type, bool is_instance) const override {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100112 return DataType::Is64BitType(type)
Nicolas Geoffray5b3c6c02017-01-19 14:22:26 +0000113 ? (is_instance
114 ? Location::RegisterPairLocation(EDX, EBX)
115 : Location::RegisterPairLocation(ECX, EDX))
Calin Juravlee460d1d2015-09-29 04:52:17 +0100116 : (is_instance
117 ? Location::RegisterLocation(EDX)
118 : Location::RegisterLocation(ECX));
119 }
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100120 Location GetFpuLocation(DataType::Type type ATTRIBUTE_UNUSED) const override {
Calin Juravlee460d1d2015-09-29 04:52:17 +0100121 return Location::FpuRegisterLocation(XMM0);
122 }
123
124 private:
125 DISALLOW_COPY_AND_ASSIGN(FieldAccessCallingConventionX86);
126};
127
Zheng Xuad4450e2015-04-17 18:48:56 +0800128class ParallelMoveResolverX86 : public ParallelMoveResolverWithSwap {
Nicolas Geoffray86dbb9a2014-06-04 11:12:39 +0100129 public:
130 ParallelMoveResolverX86(ArenaAllocator* allocator, CodeGeneratorX86* codegen)
Zheng Xuad4450e2015-04-17 18:48:56 +0800131 : ParallelMoveResolverWithSwap(allocator), codegen_(codegen) {}
Nicolas Geoffray86dbb9a2014-06-04 11:12:39 +0100132
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100133 void EmitMove(size_t index) override;
134 void EmitSwap(size_t index) override;
135 void SpillScratch(int reg) override;
136 void RestoreScratch(int reg) override;
Nicolas Geoffray86dbb9a2014-06-04 11:12:39 +0100137
138 X86Assembler* GetAssembler() const;
139
140 private:
141 void Exchange(Register reg, int mem);
Mark Mendell7c8d0092015-01-26 11:21:33 -0500142 void Exchange32(XmmRegister reg, int mem);
Aart Bikcfe50bb2017-12-12 14:54:12 -0800143 void Exchange128(XmmRegister reg, int mem);
144 void ExchangeMemory(int mem1, int mem2, int number_of_words);
145 void MoveMemoryToMemory(int dst, int src, int number_of_words);
Nicolas Geoffray86dbb9a2014-06-04 11:12:39 +0100146
147 CodeGeneratorX86* const codegen_;
148
149 DISALLOW_COPY_AND_ASSIGN(ParallelMoveResolverX86);
150};
151
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000152class LocationsBuilderX86 : public HGraphVisitor {
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000153 public:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100154 LocationsBuilderX86(HGraph* graph, CodeGeneratorX86* codegen)
155 : HGraphVisitor(graph), codegen_(codegen) {}
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000156
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100157#define DECLARE_VISIT_INSTRUCTION(name, super) \
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100158 void Visit##name(H##name* instr) override;
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000159
Alexandre Ramesef20f712015-06-09 10:29:30 +0100160 FOR_EACH_CONCRETE_INSTRUCTION_COMMON(DECLARE_VISIT_INSTRUCTION)
161 FOR_EACH_CONCRETE_INSTRUCTION_X86(DECLARE_VISIT_INSTRUCTION)
Shalini Salomi Bodapatidd121f62018-10-26 15:03:53 +0530162 FOR_EACH_CONCRETE_INSTRUCTION_X86_COMMON(DECLARE_VISIT_INSTRUCTION)
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000163
164#undef DECLARE_VISIT_INSTRUCTION
165
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100166 void VisitInstruction(HInstruction* instruction) override {
Alexandre Ramesef20f712015-06-09 10:29:30 +0100167 LOG(FATAL) << "Unreachable instruction " << instruction->DebugName()
168 << " (id " << instruction->GetId() << ")";
169 }
170
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +0000171 private:
172 void HandleBitwiseOperation(HBinaryOperation* instruction);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +0100173 void HandleInvoke(HInvoke* invoke);
Vladimir Marko5f7b58e2015-11-23 19:49:34 +0000174 void HandleCondition(HCondition* condition);
Calin Juravle9aec02f2014-11-18 23:06:35 +0000175 void HandleShift(HBinaryOperation* instruction);
Calin Juravle52c48962014-12-16 17:02:57 +0000176 void HandleFieldSet(HInstruction* instruction, const FieldInfo& field_info);
177 void HandleFieldGet(HInstruction* instruction, const FieldInfo& field_info);
Shalini Salomi Bodapatib45a4352019-07-10 16:09:41 +0530178 bool CpuHasAvxFeatureFlag();
179 bool CpuHasAvx2FeatureFlag();
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +0100180
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100181 CodeGeneratorX86* const codegen_;
Roland Levillain2d27c8e2015-04-28 15:48:45 +0100182 InvokeDexCallingConventionVisitorX86 parameter_visitor_;
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100183
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000184 DISALLOW_COPY_AND_ASSIGN(LocationsBuilderX86);
185};
186
Aart Bik42249c32016-01-07 15:33:50 -0800187class InstructionCodeGeneratorX86 : public InstructionCodeGenerator {
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000188 public:
Nicolas Geoffray4a34a422014-04-03 10:38:37 +0100189 InstructionCodeGeneratorX86(HGraph* graph, CodeGeneratorX86* codegen);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000190
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100191#define DECLARE_VISIT_INSTRUCTION(name, super) \
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100192 void Visit##name(H##name* instr) override;
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000193
Alexandre Ramesef20f712015-06-09 10:29:30 +0100194 FOR_EACH_CONCRETE_INSTRUCTION_COMMON(DECLARE_VISIT_INSTRUCTION)
195 FOR_EACH_CONCRETE_INSTRUCTION_X86(DECLARE_VISIT_INSTRUCTION)
Shalini Salomi Bodapatidd121f62018-10-26 15:03:53 +0530196 FOR_EACH_CONCRETE_INSTRUCTION_X86_COMMON(DECLARE_VISIT_INSTRUCTION)
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000197
198#undef DECLARE_VISIT_INSTRUCTION
199
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100200 void VisitInstruction(HInstruction* instruction) override {
Alexandre Ramesef20f712015-06-09 10:29:30 +0100201 LOG(FATAL) << "Unreachable instruction " << instruction->DebugName()
202 << " (id " << instruction->GetId() << ")";
203 }
204
Nicolas Geoffray4a34a422014-04-03 10:38:37 +0100205 X86Assembler* GetAssembler() const { return assembler_; }
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000206
Vladimir Markof3e0ee22015-12-17 15:23:13 +0000207 // The compare/jump sequence will generate about (1.5 * num_entries) instructions. A jump
208 // table version generates 7 instructions and num_entries literals. Compare/jump sequence will
209 // generates less code/data with a small num_entries.
210 static constexpr uint32_t kPackedSwitchJumpTableThreshold = 5;
211
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000212 private:
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100213 // Generate code for the given suspend check. If not null, `successor`
214 // is the block to branch to if the suspend check is not needed, and after
215 // the suspend call.
216 void GenerateSuspendCheck(HSuspendCheck* check, HBasicBlock* successor);
Andreas Gampe85b62f22015-09-09 13:15:38 -0700217 void GenerateClassInitializationCheck(SlowPathCode* slow_path, Register class_reg);
Vladimir Marko175e7862018-03-27 09:03:13 +0000218 void GenerateBitstringTypeCheckCompare(HTypeCheckInstruction* check, Register temp);
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +0000219 void HandleBitwiseOperation(HBinaryOperation* instruction);
Calin Juravlebacfec32014-11-14 15:54:36 +0000220 void GenerateDivRemIntegral(HBinaryOperation* instruction);
Guillaume Sanchez0f88e872015-03-30 17:55:45 +0100221 void DivRemOneOrMinusOne(HBinaryOperation* instruction);
Guillaume Sanchezb19930c2015-04-09 21:12:15 +0100222 void DivByPowerOfTwo(HDiv* instruction);
Shalini Salomi Bodapatia66784b2018-11-06 13:05:44 +0530223 void RemByPowerOfTwo(HRem* instruction);
Guillaume Sanchez0f88e872015-03-30 17:55:45 +0100224 void GenerateDivRemWithAnyConstant(HBinaryOperation* instruction);
Mark Mendellc4701932015-04-10 13:18:51 -0400225 void GenerateRemFP(HRem* rem);
Vladimir Marko5f7b58e2015-11-23 19:49:34 +0000226 void HandleCondition(HCondition* condition);
Calin Juravle9aec02f2014-11-18 23:06:35 +0000227 void HandleShift(HBinaryOperation* instruction);
228 void GenerateShlLong(const Location& loc, Register shifter);
229 void GenerateShrLong(const Location& loc, Register shifter);
230 void GenerateUShrLong(const Location& loc, Register shifter);
Mark P Mendell73945692015-04-29 14:56:17 +0000231 void GenerateShlLong(const Location& loc, int shift);
232 void GenerateShrLong(const Location& loc, int shift);
233 void GenerateUShrLong(const Location& loc, int shift);
Aart Bik351df3e2018-03-07 11:54:57 -0800234 void GenerateMinMaxInt(LocationSummary* locations, bool is_min, DataType::Type type);
Aart Bik1f8d51b2018-02-15 10:42:37 -0800235 void GenerateMinMaxFP(LocationSummary* locations, bool is_min, DataType::Type type);
Aart Bik351df3e2018-03-07 11:54:57 -0800236 void GenerateMinMax(HBinaryOperation* minmax, bool is_min);
Roland Levillain7c1559a2015-12-15 10:55:36 +0000237
Nicolas Geoffray07276db2015-05-18 14:22:09 +0100238 void HandleFieldSet(HInstruction* instruction,
239 const FieldInfo& field_info,
240 bool value_can_be_null);
Calin Juravle52c48962014-12-16 17:02:57 +0000241 void HandleFieldGet(HInstruction* instruction, const FieldInfo& field_info);
Roland Levillain7c1559a2015-12-15 10:55:36 +0000242
243 // Generate a heap reference load using one register `out`:
244 //
245 // out <- *(out + offset)
246 //
247 // while honoring heap poisoning and/or read barriers (if any).
Roland Levillain95e7ffc2016-01-22 11:57:25 +0000248 //
249 // Location `maybe_temp` is used when generating a read barrier and
250 // shall be a register in that case; it may be an invalid location
251 // otherwise.
Roland Levillain7c1559a2015-12-15 10:55:36 +0000252 void GenerateReferenceLoadOneRegister(HInstruction* instruction,
253 Location out,
254 uint32_t offset,
Mathieu Chartieraa474eb2016-11-09 15:18:27 -0800255 Location maybe_temp,
Mathieu Chartier3af00dc2016-11-10 11:25:57 -0800256 ReadBarrierOption read_barrier_option);
Roland Levillain7c1559a2015-12-15 10:55:36 +0000257 // Generate a heap reference load using two different registers
258 // `out` and `obj`:
259 //
260 // out <- *(obj + offset)
261 //
262 // while honoring heap poisoning and/or read barriers (if any).
Roland Levillain95e7ffc2016-01-22 11:57:25 +0000263 //
264 // Location `maybe_temp` is used when generating a Baker's (fast
265 // path) read barrier and shall be a register in that case; it may
266 // be an invalid location otherwise.
Roland Levillain7c1559a2015-12-15 10:55:36 +0000267 void GenerateReferenceLoadTwoRegisters(HInstruction* instruction,
268 Location out,
269 Location obj,
Mathieu Chartier5c44c1b2016-11-04 18:13:04 -0700270 uint32_t offset,
Mathieu Chartier3af00dc2016-11-10 11:25:57 -0800271 ReadBarrierOption read_barrier_option);
Roland Levillain7c1559a2015-12-15 10:55:36 +0000272 // Generate a GC root reference load:
273 //
Vladimir Markocac5a7e2016-02-22 10:39:50 +0000274 // root <- *address
Roland Levillain7c1559a2015-12-15 10:55:36 +0000275 //
Mathieu Chartier3af00dc2016-11-10 11:25:57 -0800276 // while honoring read barriers based on read_barrier_option.
Roland Levillain7c1559a2015-12-15 10:55:36 +0000277 void GenerateGcRootFieldLoad(HInstruction* instruction,
278 Location root,
Vladimir Markocac5a7e2016-02-22 10:39:50 +0000279 const Address& address,
Roland Levillain00468f32016-10-27 18:02:48 +0100280 Label* fixup_label,
Mathieu Chartier3af00dc2016-11-10 11:25:57 -0800281 ReadBarrierOption read_barrier_option);
Roland Levillain7c1559a2015-12-15 10:55:36 +0000282
Roland Levillain232ade02015-04-20 15:14:36 +0100283 // Push value to FPU stack. `is_fp` specifies whether the value is floating point or not.
284 // `is_wide` specifies whether it is long/double or not.
Mark Mendell24f2dfa2015-01-14 19:51:45 -0500285 void PushOntoFPStack(Location source, uint32_t temp_offset,
Roland Levillain232ade02015-04-20 15:14:36 +0100286 uint32_t stack_adjustment, bool is_fp, bool is_wide);
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100287
Mark Mendell152408f2015-12-31 12:28:50 -0500288 template<class LabelType>
Mingyao Yangd43b3ac2015-04-01 14:03:04 -0700289 void GenerateTestAndBranch(HInstruction* instruction,
David Brazdil0debae72015-11-12 18:37:00 +0000290 size_t condition_input_index,
Mark Mendell152408f2015-12-31 12:28:50 -0500291 LabelType* true_target,
292 LabelType* false_target);
293 template<class LabelType>
David Brazdil0debae72015-11-12 18:37:00 +0000294 void GenerateCompareTestAndBranch(HCondition* condition,
Mark Mendell152408f2015-12-31 12:28:50 -0500295 LabelType* true_target,
296 LabelType* false_target);
297 template<class LabelType>
298 void GenerateFPJumps(HCondition* cond, LabelType* true_label, LabelType* false_label);
299 template<class LabelType>
300 void GenerateLongComparesAndJumps(HCondition* cond,
301 LabelType* true_label,
302 LabelType* false_label);
303
David Brazdilfc6a86a2015-06-26 10:33:45 +0000304 void HandleGoto(HInstruction* got, HBasicBlock* successor);
Vladimir Markof3e0ee22015-12-17 15:23:13 +0000305 void GenPackedSwitchWithCompares(Register value_reg,
306 int32_t lower_bound,
307 uint32_t num_entries,
308 HBasicBlock* switch_block,
309 HBasicBlock* default_block);
Calin Juravlecd6dffe2015-01-08 17:35:35 +0000310
Mark P Mendell2f10a5f2016-01-25 14:47:50 +0000311 void GenerateFPCompare(Location lhs, Location rhs, HInstruction* insn, bool is_double);
Shalini Salomi Bodapatib45a4352019-07-10 16:09:41 +0530312 bool CpuHasAvxFeatureFlag();
313 bool CpuHasAvx2FeatureFlag();
Mark P Mendell2f10a5f2016-01-25 14:47:50 +0000314
Nicolas Geoffray4a34a422014-04-03 10:38:37 +0100315 X86Assembler* const assembler_;
316 CodeGeneratorX86* const codegen_;
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000317
318 DISALLOW_COPY_AND_ASSIGN(InstructionCodeGeneratorX86);
319};
320
Mark Mendell805b3b52015-09-18 14:10:29 -0400321class JumpTableRIPFixup;
322
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000323class CodeGeneratorX86 : public CodeGenerator {
324 public:
Mark Mendellfb8d2792015-03-31 22:16:59 -0400325 CodeGeneratorX86(HGraph* graph,
Serban Constantinescuecc43662015-08-13 13:33:12 +0100326 const CompilerOptions& compiler_options,
327 OptimizingCompilerStats* stats = nullptr);
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +0100328 virtual ~CodeGeneratorX86() {}
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000329
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100330 void GenerateFrameEntry() override;
331 void GenerateFrameExit() override;
332 void Bind(HBasicBlock* block) override;
333 void MoveConstant(Location destination, int32_t value) override;
334 void MoveLocation(Location dst, Location src, DataType::Type dst_type) override;
335 void AddLocationAsTemp(Location location, LocationSummary* locations) override;
Calin Juravlee460d1d2015-09-29 04:52:17 +0100336
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100337 size_t SaveCoreRegister(size_t stack_index, uint32_t reg_id) override;
338 size_t RestoreCoreRegister(size_t stack_index, uint32_t reg_id) override;
339 size_t SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) override;
340 size_t RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) override;
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000341
Alexandre Rames8158f282015-08-07 10:26:17 +0100342 // Generate code to invoke a runtime entry point.
Calin Juravle175dc732015-08-25 15:42:32 +0100343 void InvokeRuntime(QuickEntrypointEnum entrypoint,
344 HInstruction* instruction,
345 uint32_t dex_pc,
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100346 SlowPathCode* slow_path = nullptr) override;
Alexandre Rames8158f282015-08-07 10:26:17 +0100347
Roland Levillaindec8f632016-07-22 17:10:06 +0100348 // Generate code to invoke a runtime entry point, but do not record
349 // PC-related information in a stack map.
350 void InvokeRuntimeWithoutRecordingPcInfo(int32_t entry_point_offset,
351 HInstruction* instruction,
352 SlowPathCode* slow_path);
353
Serban Constantinescuba45db02016-07-12 22:53:02 +0100354 void GenerateInvokeRuntime(int32_t entry_point_offset);
355
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100356 size_t GetWordSize() const override {
Nicolas Geoffray707c8092014-04-04 10:50:14 +0100357 return kX86WordSize;
358 }
359
Artem Serov6a0b6572019-07-26 20:38:37 +0100360 size_t GetSlowPathFPWidth() const override {
Aart Bikb13c65b2017-03-21 20:14:07 -0700361 return GetGraph()->HasSIMD()
Artem Serovc8150b52019-07-31 18:28:00 +0100362 ? GetSIMDRegisterWidth()
Aart Bikb13c65b2017-03-21 20:14:07 -0700363 : 2 * kX86WordSize; // 8 bytes == 2 words for each spill
Mark Mendellf85a9ca2015-01-13 09:20:58 -0500364 }
365
Artem Serov6a0b6572019-07-26 20:38:37 +0100366 size_t GetCalleePreservedFPWidth() const override {
367 return 2 * kX86WordSize;
368 }
369
Artem Serovc8150b52019-07-31 18:28:00 +0100370 size_t GetSIMDRegisterWidth() const override {
371 return 4 * kX86WordSize;
372 }
373
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100374 HGraphVisitor* GetLocationBuilder() override {
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000375 return &location_builder_;
376 }
377
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100378 HGraphVisitor* GetInstructionVisitor() override {
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000379 return &instruction_visitor_;
380 }
381
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100382 X86Assembler* GetAssembler() override {
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000383 return &assembler_;
384 }
385
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100386 const X86Assembler& GetAssembler() const override {
Alexandre Rameseb7b7392015-06-19 14:47:01 +0100387 return assembler_;
388 }
389
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100390 uintptr_t GetAddressOf(HBasicBlock* block) override {
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +0000391 return GetLabelOf(block)->Position();
392 }
Calin Juravle34bacdf2014-10-07 20:23:36 +0100393
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100394 void SetupBlockedRegisters() const override;
Nicolas Geoffray4a34a422014-04-03 10:38:37 +0100395
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100396 void DumpCoreRegister(std::ostream& stream, int reg) const override;
397 void DumpFloatingPointRegister(std::ostream& stream, int reg) const override;
Nicolas Geoffraya7062e02014-05-22 12:50:17 +0100398
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100399 ParallelMoveResolverX86* GetMoveResolver() override {
Nicolas Geoffray86dbb9a2014-06-04 11:12:39 +0100400 return &move_resolver_;
401 }
402
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100403 InstructionSet GetInstructionSet() const override {
Nicolas Geoffray412f10c2014-06-19 10:00:34 +0100404 return InstructionSet::kX86;
405 }
406
Vladimir Markoa0431112018-06-25 09:32:54 +0100407 const X86InstructionSetFeatures& GetInstructionSetFeatures() const;
408
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100409 // Helper method to move a 32bits value between two locations.
410 void Move32(Location destination, Location source);
411 // Helper method to move a 64bits value between two locations.
412 void Move64(Location destination, Location source);
413
Vladimir Markocac5a7e2016-02-22 10:39:50 +0000414 // Check if the desired_string_load_kind is supported. If it is, return it,
415 // otherwise return a fall-back kind that should be used instead.
416 HLoadString::LoadKind GetSupportedLoadStringKind(
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100417 HLoadString::LoadKind desired_string_load_kind) override;
Vladimir Markocac5a7e2016-02-22 10:39:50 +0000418
Vladimir Markodbb7f5b2016-03-30 13:23:58 +0100419 // Check if the desired_class_load_kind is supported. If it is, return it,
420 // otherwise return a fall-back kind that should be used instead.
421 HLoadClass::LoadKind GetSupportedLoadClassKind(
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100422 HLoadClass::LoadKind desired_class_load_kind) override;
Vladimir Markodbb7f5b2016-03-30 13:23:58 +0100423
Vladimir Markodc151b22015-10-15 18:02:30 +0100424 // Check if the desired_dispatch_info is supported. If it is, return it,
425 // otherwise return a fall-back info that should be used instead.
426 HInvokeStaticOrDirect::DispatchInfo GetSupportedInvokeStaticOrDirectDispatch(
427 const HInvokeStaticOrDirect::DispatchInfo& desired_dispatch_info,
Nicolas Geoffraybdb2ecc2018-09-18 14:33:55 +0100428 ArtMethod* method) override;
Vladimir Markodc151b22015-10-15 18:02:30 +0100429
Mark Mendell09ed1a32015-03-25 08:30:06 -0400430 // Generate a call to a static or direct method.
Vladimir Markoe7197bf2017-06-02 17:00:23 +0100431 void GenerateStaticOrDirectCall(
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100432 HInvokeStaticOrDirect* invoke, Location temp, SlowPathCode* slow_path = nullptr) override;
Andreas Gampebfb5ba92015-09-01 15:45:02 +0000433 // Generate a call to a virtual method.
Vladimir Markoe7197bf2017-06-02 17:00:23 +0100434 void GenerateVirtualCall(
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100435 HInvokeVirtual* invoke, Location temp, SlowPathCode* slow_path = nullptr) override;
Andreas Gampe85b62f22015-09-09 13:15:38 -0700436
Vladimir Marko6fd16062018-06-26 11:02:04 +0100437 void RecordBootImageIntrinsicPatch(HX86ComputeBaseMethodAddress* method_address,
438 uint32_t intrinsic_data);
Vladimir Markob066d432018-01-03 13:14:37 +0000439 void RecordBootImageRelRoPatch(HX86ComputeBaseMethodAddress* method_address,
440 uint32_t boot_image_offset);
Vladimir Marko59eb30f2018-02-20 11:52:34 +0000441 void RecordBootImageMethodPatch(HInvokeStaticOrDirect* invoke);
442 void RecordMethodBssEntryPatch(HInvokeStaticOrDirect* invoke);
443 void RecordBootImageTypePatch(HLoadClass* load_class);
Vladimir Marko6bec91c2017-01-09 15:03:12 +0000444 Label* NewTypeBssEntryPatch(HLoadClass* load_class);
Vladimir Marko59eb30f2018-02-20 11:52:34 +0000445 void RecordBootImageStringPatch(HLoadString* load_string);
Vladimir Markoaad75c62016-10-03 08:46:48 +0000446 Label* NewStringBssEntryPatch(HLoadString* load_string);
Vladimir Markoeebb8212018-06-05 14:57:24 +0100447
448 void LoadBootImageAddress(Register reg,
Vladimir Marko6fd16062018-06-26 11:02:04 +0100449 uint32_t boot_image_reference,
Vladimir Markoeebb8212018-06-05 14:57:24 +0100450 HInvokeStaticOrDirect* invoke);
Vladimir Marko6fd16062018-06-26 11:02:04 +0100451 void AllocateInstanceForIntrinsic(HInvokeStaticOrDirect* invoke, uint32_t boot_image_offset);
Vladimir Markoeebb8212018-06-05 14:57:24 +0100452
Nicolas Geoffrayf0acfe72017-01-09 20:54:52 +0000453 Label* NewJitRootStringPatch(const DexFile& dex_file,
Vladimir Marko174b2e22017-10-12 13:34:49 +0100454 dex::StringIndex string_index,
Nicolas Geoffrayf0acfe72017-01-09 20:54:52 +0000455 Handle<mirror::String> handle);
Nicolas Geoffray5247c082017-01-13 14:17:29 +0000456 Label* NewJitRootClassPatch(const DexFile& dex_file,
Vladimir Marko174b2e22017-10-12 13:34:49 +0100457 dex::TypeIndex type_index,
Nicolas Geoffray5247c082017-01-13 14:17:29 +0000458 Handle<mirror::Class> handle);
Vladimir Markocac5a7e2016-02-22 10:39:50 +0000459
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100460 void MoveFromReturnRegister(Location trg, DataType::Type type) override;
Mark Mendell09ed1a32015-03-25 08:30:06 -0400461
Vladimir Marko58155012015-08-19 12:49:41 +0000462 // Emit linker patches.
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100463 void EmitLinkerPatches(ArenaVector<linker::LinkerPatch>* linker_patches) override;
Vladimir Marko58155012015-08-19 12:49:41 +0000464
Nicolas Geoffray22384ae2016-12-12 22:33:36 +0000465 void PatchJitRootUse(uint8_t* code,
466 const uint8_t* roots_data,
467 const PatchInfo<Label>& info,
468 uint64_t index_in_table) const;
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100469 void EmitJitRootPatches(uint8_t* code, const uint8_t* roots_data) override;
Nicolas Geoffray132d8362016-11-16 09:19:42 +0000470
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100471 // Emit a write barrier.
Nicolas Geoffray07276db2015-05-18 14:22:09 +0100472 void MarkGCCard(Register temp,
473 Register card,
474 Register object,
475 Register value,
476 bool value_can_be_null);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100477
Roland Levillain7c1559a2015-12-15 10:55:36 +0000478 void GenerateMemoryBarrier(MemBarrierKind kind);
479
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100480 Label* GetLabelOf(HBasicBlock* block) const {
Vladimir Marko225b6462015-09-28 12:17:40 +0100481 return CommonGetLabelOf<Label>(block_labels_, block);
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100482 }
483
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100484 void Initialize() override {
Vladimir Marko225b6462015-09-28 12:17:40 +0100485 block_labels_ = CommonInitializeLabels<Label>();
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100486 }
487
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100488 bool NeedsTwoRegisters(DataType::Type type) const override {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100489 return type == DataType::Type::kInt64;
Nicolas Geoffray840e5462015-01-07 16:01:24 +0000490 }
491
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100492 bool ShouldSplitLongMoves() const override { return true; }
Nicolas Geoffray234d69d2015-03-09 10:28:50 +0000493
Nicolas Geoffray1cf95282014-12-12 19:22:03 +0000494 Label* GetFrameEntryLabel() { return &frame_entry_label_; }
495
Nicolas Geoffray133719e2017-01-22 15:44:39 +0000496 void AddMethodAddressOffset(HX86ComputeBaseMethodAddress* method_base, int32_t offset) {
497 method_address_offset_.Put(method_base->GetId(), offset);
Mark Mendell0616ae02015-04-17 12:49:27 -0400498 }
499
Nicolas Geoffray133719e2017-01-22 15:44:39 +0000500 int32_t GetMethodAddressOffset(HX86ComputeBaseMethodAddress* method_base) const {
501 return method_address_offset_.Get(method_base->GetId());
Mark Mendell0616ae02015-04-17 12:49:27 -0400502 }
503
504 int32_t ConstantAreaStart() const {
505 return constant_area_start_;
506 }
507
Nicolas Geoffray133719e2017-01-22 15:44:39 +0000508 Address LiteralDoubleAddress(double v, HX86ComputeBaseMethodAddress* method_base, Register reg);
509 Address LiteralFloatAddress(float v, HX86ComputeBaseMethodAddress* method_base, Register reg);
510 Address LiteralInt32Address(int32_t v, HX86ComputeBaseMethodAddress* method_base, Register reg);
511 Address LiteralInt64Address(int64_t v, HX86ComputeBaseMethodAddress* method_base, Register reg);
Mark Mendell0616ae02015-04-17 12:49:27 -0400512
Aart Bika19616e2016-02-01 18:57:58 -0800513 // Load a 32-bit value into a register in the most efficient manner.
514 void Load32BitValue(Register dest, int32_t value);
515
516 // Compare a register with a 32-bit value in the most efficient manner.
517 void Compare32BitValue(Register dest, int32_t value);
518
Vladimir Marko56f4bdd2016-09-16 11:32:36 +0100519 // Compare int values. Supports only register locations for `lhs`.
520 void GenerateIntCompare(Location lhs, Location rhs);
jessicahandojo4877b792016-09-08 19:49:13 -0700521 void GenerateIntCompare(Register lhs, Location rhs);
Vladimir Marko56f4bdd2016-09-16 11:32:36 +0100522
523 // Construct address for array access.
524 static Address ArrayAddress(Register obj,
525 Location index,
526 ScaleFactor scale,
527 uint32_t data_offset);
528
Mark Mendell805b3b52015-09-18 14:10:29 -0400529 Address LiteralCaseTable(HX86PackedSwitch* switch_instr, Register reg, Register value);
530
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100531 void Finalize(CodeAllocator* allocator) override;
Mark Mendell0616ae02015-04-17 12:49:27 -0400532
Roland Levillain7c1559a2015-12-15 10:55:36 +0000533 // Fast path implementation of ReadBarrier::Barrier for a heap
534 // reference field load when Baker's read barriers are used.
535 void GenerateFieldLoadWithBakerReadBarrier(HInstruction* instruction,
Roland Levillaine3f43ac2016-01-19 15:07:47 +0000536 Location ref,
Roland Levillain7c1559a2015-12-15 10:55:36 +0000537 Register obj,
538 uint32_t offset,
Roland Levillain7c1559a2015-12-15 10:55:36 +0000539 bool needs_null_check);
540 // Fast path implementation of ReadBarrier::Barrier for a heap
541 // reference array load when Baker's read barriers are used.
542 void GenerateArrayLoadWithBakerReadBarrier(HInstruction* instruction,
Roland Levillaine3f43ac2016-01-19 15:07:47 +0000543 Location ref,
Roland Levillain7c1559a2015-12-15 10:55:36 +0000544 Register obj,
545 uint32_t data_offset,
546 Location index,
Roland Levillain7c1559a2015-12-15 10:55:36 +0000547 bool needs_null_check);
Roland Levillaina1aa3b12016-10-26 13:03:38 +0100548 // Factored implementation, used by GenerateFieldLoadWithBakerReadBarrier,
549 // GenerateArrayLoadWithBakerReadBarrier and some intrinsics.
550 //
551 // Load the object reference located at address `src`, held by
552 // object `obj`, into `ref`, and mark it if needed. The base of
553 // address `src` must be `obj`.
554 //
555 // If `always_update_field` is true, the value of the reference is
556 // atomically updated in the holder (`obj`). This operation
557 // requires a temporary register, which must be provided as a
558 // non-null pointer (`temp`).
Sang, Chunlei0fcd2b82016-04-05 17:12:59 +0800559 void GenerateReferenceLoadWithBakerReadBarrier(HInstruction* instruction,
560 Location ref,
561 Register obj,
562 const Address& src,
Roland Levillaina1aa3b12016-10-26 13:03:38 +0100563 bool needs_null_check,
564 bool always_update_field = false,
565 Register* temp = nullptr);
Roland Levillain7c1559a2015-12-15 10:55:36 +0000566
567 // Generate a read barrier for a heap reference within `instruction`
568 // using a slow path.
Roland Levillain0d5a2812015-11-13 10:07:31 +0000569 //
570 // A read barrier for an object reference read from the heap is
571 // implemented as a call to the artReadBarrierSlow runtime entry
572 // point, which is passed the values in locations `ref`, `obj`, and
573 // `offset`:
574 //
575 // mirror::Object* artReadBarrierSlow(mirror::Object* ref,
576 // mirror::Object* obj,
577 // uint32_t offset);
578 //
579 // The `out` location contains the value returned by
580 // artReadBarrierSlow.
581 //
582 // When `index` is provided (i.e. for array accesses), the offset
583 // value passed to artReadBarrierSlow is adjusted to take `index`
584 // into account.
Roland Levillain7c1559a2015-12-15 10:55:36 +0000585 void GenerateReadBarrierSlow(HInstruction* instruction,
586 Location out,
587 Location ref,
588 Location obj,
589 uint32_t offset,
590 Location index = Location::NoLocation());
Roland Levillain0d5a2812015-11-13 10:07:31 +0000591
Roland Levillain7c1559a2015-12-15 10:55:36 +0000592 // If read barriers are enabled, generate a read barrier for a heap
593 // reference using a slow path. If heap poisoning is enabled, also
594 // unpoison the reference in `out`.
595 void MaybeGenerateReadBarrierSlow(HInstruction* instruction,
596 Location out,
597 Location ref,
598 Location obj,
599 uint32_t offset,
600 Location index = Location::NoLocation());
Roland Levillain0d5a2812015-11-13 10:07:31 +0000601
Roland Levillain7c1559a2015-12-15 10:55:36 +0000602 // Generate a read barrier for a GC root within `instruction` using
603 // a slow path.
Roland Levillain0d5a2812015-11-13 10:07:31 +0000604 //
605 // A read barrier for an object reference GC root is implemented as
606 // a call to the artReadBarrierForRootSlow runtime entry point,
607 // which is passed the value in location `root`:
608 //
609 // mirror::Object* artReadBarrierForRootSlow(GcRoot<mirror::Object>* root);
610 //
611 // The `out` location contains the value returned by
612 // artReadBarrierForRootSlow.
Roland Levillain7c1559a2015-12-15 10:55:36 +0000613 void GenerateReadBarrierForRootSlow(HInstruction* instruction, Location out, Location root);
Roland Levillain0d5a2812015-11-13 10:07:31 +0000614
Mark P Mendell17077d82015-12-16 19:15:59 +0000615 // Ensure that prior stores complete to memory before subsequent loads.
616 // The locked add implementation will avoid serializing device memory, but will
617 // touch (but not change) the top of the stack.
618 // The 'non_temporal' parameter should be used to ensure ordering of non-temporal stores.
619 void MemoryFence(bool non_temporal = false) {
Mark Mendell7aa04a12016-01-27 22:39:07 -0500620 if (!non_temporal) {
Mark P Mendell17077d82015-12-16 19:15:59 +0000621 assembler_.lock()->addl(Address(ESP, 0), Immediate(0));
622 } else {
623 assembler_.mfence();
624 }
625 }
626
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100627 void GenerateNop() override;
628 void GenerateImplicitNullCheck(HNullCheck* instruction) override;
629 void GenerateExplicitNullCheck(HNullCheck* instruction) override;
Mark P Mendell17077d82015-12-16 19:15:59 +0000630
Nicolas Geoffraye2a3aa92019-11-25 17:52:58 +0000631 void MaybeGenerateInlineCacheCheck(HInstruction* instruction, Register klass);
Nicolas Geoffraya59af8a2019-11-27 17:42:32 +0000632 void MaybeIncrementHotness(bool is_frame_entry);
Nicolas Geoffraye2a3aa92019-11-25 17:52:58 +0000633
Vladimir Markocac5a7e2016-02-22 10:39:50 +0000634 // When we don't know the proper offset for the value, we use kDummy32BitOffset.
635 // The correct value will be inserted when processing Assembler fixups.
636 static constexpr int32_t kDummy32BitOffset = 256;
637
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100638 private:
Nicolas Geoffray133719e2017-01-22 15:44:39 +0000639 struct X86PcRelativePatchInfo : PatchInfo<Label> {
640 X86PcRelativePatchInfo(HX86ComputeBaseMethodAddress* address,
Vladimir Marko59eb30f2018-02-20 11:52:34 +0000641 const DexFile* target_dex_file,
Nicolas Geoffray133719e2017-01-22 15:44:39 +0000642 uint32_t target_index)
643 : PatchInfo(target_dex_file, target_index),
644 method_address(address) {}
645 HX86ComputeBaseMethodAddress* method_address;
646 };
Vladimir Marko0f7dca42015-11-02 14:36:43 +0000647
Vladimir Markod8dbc8d2017-09-20 13:37:47 +0100648 template <linker::LinkerPatch (*Factory)(size_t, const DexFile*, uint32_t, uint32_t)>
Nicolas Geoffray133719e2017-01-22 15:44:39 +0000649 void EmitPcRelativeLinkerPatches(const ArenaDeque<X86PcRelativePatchInfo>& infos,
Vladimir Markod8dbc8d2017-09-20 13:37:47 +0100650 ArenaVector<linker::LinkerPatch>* linker_patches);
Vladimir Marko0f7dca42015-11-02 14:36:43 +0000651
Nicolas Geoffray133719e2017-01-22 15:44:39 +0000652 Register GetInvokeStaticOrDirectExtraParameter(HInvokeStaticOrDirect* invoke, Register temp);
653
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100654 // Labels for each block that will be compiled.
Vladimir Marko225b6462015-09-28 12:17:40 +0100655 Label* block_labels_; // Indexed by block id.
Nicolas Geoffray1cf95282014-12-12 19:22:03 +0000656 Label frame_entry_label_;
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000657 LocationsBuilderX86 location_builder_;
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000658 InstructionCodeGeneratorX86 instruction_visitor_;
Nicolas Geoffray86dbb9a2014-06-04 11:12:39 +0100659 ParallelMoveResolverX86 move_resolver_;
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000660 X86Assembler assembler_;
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000661
Vladimir Marko2d06e022019-07-08 15:45:19 +0100662 // PC-relative method patch info for kBootImageLinkTimePcRelative.
Vladimir Marko65979462017-05-19 17:25:12 +0100663 ArenaDeque<X86PcRelativePatchInfo> boot_image_method_patches_;
Vladimir Marko0eb882b2017-05-15 13:39:18 +0100664 // PC-relative method patch info for kBssEntry.
665 ArenaDeque<X86PcRelativePatchInfo> method_bss_entry_patches_;
Vladimir Marko764d4542017-05-16 10:31:41 +0100666 // PC-relative type patch info for kBootImageLinkTimePcRelative.
Nicolas Geoffray133719e2017-01-22 15:44:39 +0000667 ArenaDeque<X86PcRelativePatchInfo> boot_image_type_patches_;
Vladimir Markoe47f60c2018-02-21 13:43:28 +0000668 // PC-relative type patch info for kBssEntry.
Nicolas Geoffray133719e2017-01-22 15:44:39 +0000669 ArenaDeque<X86PcRelativePatchInfo> type_bss_entry_patches_;
Vladimir Markoe47f60c2018-02-21 13:43:28 +0000670 // PC-relative String patch info for kBootImageLinkTimePcRelative.
Vladimir Marko59eb30f2018-02-20 11:52:34 +0000671 ArenaDeque<X86PcRelativePatchInfo> boot_image_string_patches_;
Vladimir Markoe47f60c2018-02-21 13:43:28 +0000672 // PC-relative String patch info for kBssEntry.
Vladimir Marko6cfbdbc2017-07-25 13:26:39 +0100673 ArenaDeque<X86PcRelativePatchInfo> string_bss_entry_patches_;
Vladimir Marko2d06e022019-07-08 15:45:19 +0100674 // PC-relative patch info for IntrinsicObjects for the boot image,
675 // and for method/type/string patches for kBootImageRelRo otherwise.
676 ArenaDeque<X86PcRelativePatchInfo> boot_image_other_patches_;
Vladimir Marko58155012015-08-19 12:49:41 +0000677
Nicolas Geoffray132d8362016-11-16 09:19:42 +0000678 // Patches for string root accesses in JIT compiled code.
679 ArenaDeque<PatchInfo<Label>> jit_string_patches_;
Nicolas Geoffray22384ae2016-12-12 22:33:36 +0000680 // Patches for class root accesses in JIT compiled code.
681 ArenaDeque<PatchInfo<Label>> jit_class_patches_;
682
Mark Mendell0616ae02015-04-17 12:49:27 -0400683 // Offset to the start of the constant area in the assembled code.
684 // Used for fixups to the constant area.
685 int32_t constant_area_start_;
686
Mark Mendell805b3b52015-09-18 14:10:29 -0400687 // Fixups for jump tables that need to be patched after the constant table is generated.
688 ArenaVector<JumpTableRIPFixup*> fixups_to_jump_tables_;
689
Nicolas Geoffray133719e2017-01-22 15:44:39 +0000690 // Maps a HX86ComputeBaseMethodAddress instruction id, to its offset in the
691 // compiled code.
692 ArenaSafeMap<uint32_t, int32_t> method_address_offset_;
Mark Mendell0616ae02015-04-17 12:49:27 -0400693
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000694 DISALLOW_COPY_AND_ASSIGN(CodeGeneratorX86);
695};
696
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000697} // namespace x86
698} // namespace art
699
700#endif // ART_COMPILER_OPTIMIZING_CODE_GENERATOR_X86_H_