Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2014 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #ifndef ART_COMPILER_OPTIMIZING_CODE_GENERATOR_X86_H_ |
| 18 | #define ART_COMPILER_OPTIMIZING_CODE_GENERATOR_X86_H_ |
| 19 | |
Mark P Mendell | 17077d8 | 2015-12-16 19:15:59 +0000 | [diff] [blame] | 20 | #include "arch/x86/instruction_set_features_x86.h" |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 21 | #include "base/enums.h" |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 22 | #include "code_generator.h" |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 23 | #include "dex_file_types.h" |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 24 | #include "driver/compiler_options.h" |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 25 | #include "nodes.h" |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 26 | #include "parallel_move_resolver.h" |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 27 | #include "utils/x86/assembler_x86.h" |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 28 | |
| 29 | namespace art { |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 30 | namespace x86 { |
| 31 | |
Nicolas Geoffray | 86a8d7a | 2014-11-19 08:47:18 +0000 | [diff] [blame] | 32 | // Use a local definition to prevent copying mistakes. |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 33 | static constexpr size_t kX86WordSize = static_cast<size_t>(kX86PointerSize); |
Nicolas Geoffray | 707c809 | 2014-04-04 10:50:14 +0100 | [diff] [blame] | 34 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 35 | class CodeGeneratorX86; |
| 36 | |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 37 | static constexpr Register kParameterCoreRegisters[] = { ECX, EDX, EBX }; |
| 38 | static constexpr RegisterPair kParameterCorePairRegisters[] = { ECX_EDX, EDX_EBX }; |
| 39 | static constexpr size_t kParameterCoreRegistersLength = arraysize(kParameterCoreRegisters); |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 40 | static constexpr XmmRegister kParameterFpuRegisters[] = { XMM0, XMM1, XMM2, XMM3 }; |
| 41 | static constexpr size_t kParameterFpuRegistersLength = arraysize(kParameterFpuRegisters); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 42 | |
Nicolas Geoffray | d75948a | 2015-03-27 09:53:16 +0000 | [diff] [blame] | 43 | static constexpr Register kRuntimeParameterCoreRegisters[] = { EAX, ECX, EDX, EBX }; |
| 44 | static constexpr size_t kRuntimeParameterCoreRegistersLength = |
| 45 | arraysize(kRuntimeParameterCoreRegisters); |
| 46 | static constexpr XmmRegister kRuntimeParameterFpuRegisters[] = { XMM0, XMM1, XMM2, XMM3 }; |
| 47 | static constexpr size_t kRuntimeParameterFpuRegistersLength = |
| 48 | arraysize(kRuntimeParameterFpuRegisters); |
| 49 | |
| 50 | class InvokeRuntimeCallingConvention : public CallingConvention<Register, XmmRegister> { |
| 51 | public: |
| 52 | InvokeRuntimeCallingConvention() |
| 53 | : CallingConvention(kRuntimeParameterCoreRegisters, |
| 54 | kRuntimeParameterCoreRegistersLength, |
| 55 | kRuntimeParameterFpuRegisters, |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 56 | kRuntimeParameterFpuRegistersLength, |
| 57 | kX86PointerSize) {} |
Nicolas Geoffray | d75948a | 2015-03-27 09:53:16 +0000 | [diff] [blame] | 58 | |
| 59 | private: |
| 60 | DISALLOW_COPY_AND_ASSIGN(InvokeRuntimeCallingConvention); |
| 61 | }; |
| 62 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 63 | class InvokeDexCallingConvention : public CallingConvention<Register, XmmRegister> { |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 64 | public: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 65 | InvokeDexCallingConvention() : CallingConvention( |
| 66 | kParameterCoreRegisters, |
| 67 | kParameterCoreRegistersLength, |
| 68 | kParameterFpuRegisters, |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 69 | kParameterFpuRegistersLength, |
| 70 | kX86PointerSize) {} |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 71 | |
| 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 Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 81 | class InvokeDexCallingConventionVisitorX86 : public InvokeDexCallingConventionVisitor { |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 82 | public: |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 83 | InvokeDexCallingConventionVisitorX86() {} |
| 84 | virtual ~InvokeDexCallingConventionVisitorX86() {} |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 85 | |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 86 | Location GetNextLocation(Primitive::Type type) OVERRIDE; |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 87 | Location GetReturnLocation(Primitive::Type type) const OVERRIDE; |
| 88 | Location GetMethodLocation() const OVERRIDE; |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 89 | |
| 90 | private: |
| 91 | InvokeDexCallingConvention calling_convention; |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 92 | |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 93 | DISALLOW_COPY_AND_ASSIGN(InvokeDexCallingConventionVisitorX86); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 94 | }; |
| 95 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 96 | class FieldAccessCallingConventionX86 : public FieldAccessCallingConvention { |
| 97 | public: |
| 98 | FieldAccessCallingConventionX86() {} |
| 99 | |
| 100 | Location GetObjectLocation() const OVERRIDE { |
| 101 | return Location::RegisterLocation(ECX); |
| 102 | } |
| 103 | Location GetFieldIndexLocation() const OVERRIDE { |
| 104 | return Location::RegisterLocation(EAX); |
| 105 | } |
| 106 | Location GetReturnLocation(Primitive::Type type) const OVERRIDE { |
| 107 | return Primitive::Is64BitType(type) |
| 108 | ? Location::RegisterPairLocation(EAX, EDX) |
| 109 | : Location::RegisterLocation(EAX); |
| 110 | } |
| 111 | Location GetSetValueLocation(Primitive::Type type, bool is_instance) const OVERRIDE { |
| 112 | return Primitive::Is64BitType(type) |
| 113 | ? Location::RegisterPairLocation(EDX, EBX) |
| 114 | : (is_instance |
| 115 | ? Location::RegisterLocation(EDX) |
| 116 | : Location::RegisterLocation(ECX)); |
| 117 | } |
| 118 | Location GetFpuLocation(Primitive::Type type ATTRIBUTE_UNUSED) const OVERRIDE { |
| 119 | return Location::FpuRegisterLocation(XMM0); |
| 120 | } |
| 121 | |
| 122 | private: |
| 123 | DISALLOW_COPY_AND_ASSIGN(FieldAccessCallingConventionX86); |
| 124 | }; |
| 125 | |
Zheng Xu | ad4450e | 2015-04-17 18:48:56 +0800 | [diff] [blame] | 126 | class ParallelMoveResolverX86 : public ParallelMoveResolverWithSwap { |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 127 | public: |
| 128 | ParallelMoveResolverX86(ArenaAllocator* allocator, CodeGeneratorX86* codegen) |
Zheng Xu | ad4450e | 2015-04-17 18:48:56 +0800 | [diff] [blame] | 129 | : ParallelMoveResolverWithSwap(allocator), codegen_(codegen) {} |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 130 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 131 | void EmitMove(size_t index) OVERRIDE; |
| 132 | void EmitSwap(size_t index) OVERRIDE; |
| 133 | void SpillScratch(int reg) OVERRIDE; |
| 134 | void RestoreScratch(int reg) OVERRIDE; |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 135 | |
| 136 | X86Assembler* GetAssembler() const; |
| 137 | |
| 138 | private: |
| 139 | void Exchange(Register reg, int mem); |
| 140 | void Exchange(int mem1, int mem2); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 141 | void Exchange32(XmmRegister reg, int mem); |
| 142 | void MoveMemoryToMemory32(int dst, int src); |
| 143 | void MoveMemoryToMemory64(int dst, int src); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 144 | |
| 145 | CodeGeneratorX86* const codegen_; |
| 146 | |
| 147 | DISALLOW_COPY_AND_ASSIGN(ParallelMoveResolverX86); |
| 148 | }; |
| 149 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 150 | class LocationsBuilderX86 : public HGraphVisitor { |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 151 | public: |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 152 | LocationsBuilderX86(HGraph* graph, CodeGeneratorX86* codegen) |
| 153 | : HGraphVisitor(graph), codegen_(codegen) {} |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 154 | |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 155 | #define DECLARE_VISIT_INSTRUCTION(name, super) \ |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 156 | void Visit##name(H##name* instr) OVERRIDE; |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 157 | |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 158 | FOR_EACH_CONCRETE_INSTRUCTION_COMMON(DECLARE_VISIT_INSTRUCTION) |
| 159 | FOR_EACH_CONCRETE_INSTRUCTION_X86(DECLARE_VISIT_INSTRUCTION) |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 160 | |
| 161 | #undef DECLARE_VISIT_INSTRUCTION |
| 162 | |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 163 | void VisitInstruction(HInstruction* instruction) OVERRIDE { |
| 164 | LOG(FATAL) << "Unreachable instruction " << instruction->DebugName() |
| 165 | << " (id " << instruction->GetId() << ")"; |
| 166 | } |
| 167 | |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 168 | private: |
| 169 | void HandleBitwiseOperation(HBinaryOperation* instruction); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 170 | void HandleInvoke(HInvoke* invoke); |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 171 | void HandleCondition(HCondition* condition); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 172 | void HandleShift(HBinaryOperation* instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 173 | void HandleFieldSet(HInstruction* instruction, const FieldInfo& field_info); |
| 174 | void HandleFieldGet(HInstruction* instruction, const FieldInfo& field_info); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 175 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 176 | CodeGeneratorX86* const codegen_; |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 177 | InvokeDexCallingConventionVisitorX86 parameter_visitor_; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 178 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 179 | DISALLOW_COPY_AND_ASSIGN(LocationsBuilderX86); |
| 180 | }; |
| 181 | |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 182 | class InstructionCodeGeneratorX86 : public InstructionCodeGenerator { |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 183 | public: |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 184 | InstructionCodeGeneratorX86(HGraph* graph, CodeGeneratorX86* codegen); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 185 | |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 186 | #define DECLARE_VISIT_INSTRUCTION(name, super) \ |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 187 | void Visit##name(H##name* instr) OVERRIDE; |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 188 | |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 189 | FOR_EACH_CONCRETE_INSTRUCTION_COMMON(DECLARE_VISIT_INSTRUCTION) |
| 190 | FOR_EACH_CONCRETE_INSTRUCTION_X86(DECLARE_VISIT_INSTRUCTION) |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 191 | |
| 192 | #undef DECLARE_VISIT_INSTRUCTION |
| 193 | |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 194 | void VisitInstruction(HInstruction* instruction) OVERRIDE { |
| 195 | LOG(FATAL) << "Unreachable instruction " << instruction->DebugName() |
| 196 | << " (id " << instruction->GetId() << ")"; |
| 197 | } |
| 198 | |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 199 | X86Assembler* GetAssembler() const { return assembler_; } |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 200 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 201 | // The compare/jump sequence will generate about (1.5 * num_entries) instructions. A jump |
| 202 | // table version generates 7 instructions and num_entries literals. Compare/jump sequence will |
| 203 | // generates less code/data with a small num_entries. |
| 204 | static constexpr uint32_t kPackedSwitchJumpTableThreshold = 5; |
| 205 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 206 | private: |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 207 | // Generate code for the given suspend check. If not null, `successor` |
| 208 | // is the block to branch to if the suspend check is not needed, and after |
| 209 | // the suspend call. |
| 210 | void GenerateSuspendCheck(HSuspendCheck* check, HBasicBlock* successor); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 211 | void GenerateClassInitializationCheck(SlowPathCode* slow_path, Register class_reg); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 212 | void HandleBitwiseOperation(HBinaryOperation* instruction); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 213 | void GenerateDivRemIntegral(HBinaryOperation* instruction); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 214 | void DivRemOneOrMinusOne(HBinaryOperation* instruction); |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 215 | void DivByPowerOfTwo(HDiv* instruction); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 216 | void GenerateDivRemWithAnyConstant(HBinaryOperation* instruction); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 217 | void GenerateRemFP(HRem* rem); |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 218 | void HandleCondition(HCondition* condition); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 219 | void HandleShift(HBinaryOperation* instruction); |
| 220 | void GenerateShlLong(const Location& loc, Register shifter); |
| 221 | void GenerateShrLong(const Location& loc, Register shifter); |
| 222 | void GenerateUShrLong(const Location& loc, Register shifter); |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 223 | void GenerateShlLong(const Location& loc, int shift); |
| 224 | void GenerateShrLong(const Location& loc, int shift); |
| 225 | void GenerateUShrLong(const Location& loc, int shift); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 226 | |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 227 | void HandleFieldSet(HInstruction* instruction, |
| 228 | const FieldInfo& field_info, |
| 229 | bool value_can_be_null); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 230 | void HandleFieldGet(HInstruction* instruction, const FieldInfo& field_info); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 231 | |
| 232 | // Generate a heap reference load using one register `out`: |
| 233 | // |
| 234 | // out <- *(out + offset) |
| 235 | // |
| 236 | // while honoring heap poisoning and/or read barriers (if any). |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 237 | // |
| 238 | // Location `maybe_temp` is used when generating a read barrier and |
| 239 | // shall be a register in that case; it may be an invalid location |
| 240 | // otherwise. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 241 | void GenerateReferenceLoadOneRegister(HInstruction* instruction, |
| 242 | Location out, |
| 243 | uint32_t offset, |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 244 | Location maybe_temp, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 245 | ReadBarrierOption read_barrier_option); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 246 | // Generate a heap reference load using two different registers |
| 247 | // `out` and `obj`: |
| 248 | // |
| 249 | // out <- *(obj + offset) |
| 250 | // |
| 251 | // while honoring heap poisoning and/or read barriers (if any). |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 252 | // |
| 253 | // Location `maybe_temp` is used when generating a Baker's (fast |
| 254 | // path) read barrier and shall be a register in that case; it may |
| 255 | // be an invalid location otherwise. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 256 | void GenerateReferenceLoadTwoRegisters(HInstruction* instruction, |
| 257 | Location out, |
| 258 | Location obj, |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 259 | uint32_t offset, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 260 | ReadBarrierOption read_barrier_option); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 261 | // Generate a GC root reference load: |
| 262 | // |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 263 | // root <- *address |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 264 | // |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 265 | // while honoring read barriers based on read_barrier_option. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 266 | void GenerateGcRootFieldLoad(HInstruction* instruction, |
| 267 | Location root, |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 268 | const Address& address, |
Roland Levillain | 00468f3 | 2016-10-27 18:02:48 +0100 | [diff] [blame] | 269 | Label* fixup_label, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 270 | ReadBarrierOption read_barrier_option); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 271 | |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 272 | // Push value to FPU stack. `is_fp` specifies whether the value is floating point or not. |
| 273 | // `is_wide` specifies whether it is long/double or not. |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 274 | void PushOntoFPStack(Location source, uint32_t temp_offset, |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 275 | uint32_t stack_adjustment, bool is_fp, bool is_wide); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 276 | |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 277 | template<class LabelType> |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 278 | void GenerateTestAndBranch(HInstruction* instruction, |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 279 | size_t condition_input_index, |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 280 | LabelType* true_target, |
| 281 | LabelType* false_target); |
| 282 | template<class LabelType> |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 283 | void GenerateCompareTestAndBranch(HCondition* condition, |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 284 | LabelType* true_target, |
| 285 | LabelType* false_target); |
| 286 | template<class LabelType> |
| 287 | void GenerateFPJumps(HCondition* cond, LabelType* true_label, LabelType* false_label); |
| 288 | template<class LabelType> |
| 289 | void GenerateLongComparesAndJumps(HCondition* cond, |
| 290 | LabelType* true_label, |
| 291 | LabelType* false_label); |
| 292 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 293 | void HandleGoto(HInstruction* got, HBasicBlock* successor); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 294 | void GenPackedSwitchWithCompares(Register value_reg, |
| 295 | int32_t lower_bound, |
| 296 | uint32_t num_entries, |
| 297 | HBasicBlock* switch_block, |
| 298 | HBasicBlock* default_block); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 299 | |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 300 | void GenerateFPCompare(Location lhs, Location rhs, HInstruction* insn, bool is_double); |
| 301 | |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 302 | X86Assembler* const assembler_; |
| 303 | CodeGeneratorX86* const codegen_; |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 304 | |
| 305 | DISALLOW_COPY_AND_ASSIGN(InstructionCodeGeneratorX86); |
| 306 | }; |
| 307 | |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 308 | class JumpTableRIPFixup; |
| 309 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 310 | class CodeGeneratorX86 : public CodeGenerator { |
| 311 | public: |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 312 | CodeGeneratorX86(HGraph* graph, |
| 313 | const X86InstructionSetFeatures& isa_features, |
Serban Constantinescu | ecc4366 | 2015-08-13 13:33:12 +0100 | [diff] [blame] | 314 | const CompilerOptions& compiler_options, |
| 315 | OptimizingCompilerStats* stats = nullptr); |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 316 | virtual ~CodeGeneratorX86() {} |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 317 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 318 | void GenerateFrameEntry() OVERRIDE; |
| 319 | void GenerateFrameExit() OVERRIDE; |
| 320 | void Bind(HBasicBlock* block) OVERRIDE; |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 321 | void MoveConstant(Location destination, int32_t value) OVERRIDE; |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 322 | void MoveLocation(Location dst, Location src, Primitive::Type dst_type) OVERRIDE; |
| 323 | void AddLocationAsTemp(Location location, LocationSummary* locations) OVERRIDE; |
| 324 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 325 | size_t SaveCoreRegister(size_t stack_index, uint32_t reg_id) OVERRIDE; |
| 326 | size_t RestoreCoreRegister(size_t stack_index, uint32_t reg_id) OVERRIDE; |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 327 | size_t SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) OVERRIDE; |
| 328 | size_t RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) OVERRIDE; |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 329 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 330 | // Generate code to invoke a runtime entry point. |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 331 | void InvokeRuntime(QuickEntrypointEnum entrypoint, |
| 332 | HInstruction* instruction, |
| 333 | uint32_t dex_pc, |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 334 | SlowPathCode* slow_path = nullptr) OVERRIDE; |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 335 | |
Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 336 | // Generate code to invoke a runtime entry point, but do not record |
| 337 | // PC-related information in a stack map. |
| 338 | void InvokeRuntimeWithoutRecordingPcInfo(int32_t entry_point_offset, |
| 339 | HInstruction* instruction, |
| 340 | SlowPathCode* slow_path); |
| 341 | |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 342 | void GenerateInvokeRuntime(int32_t entry_point_offset); |
| 343 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 344 | size_t GetWordSize() const OVERRIDE { |
Nicolas Geoffray | 707c809 | 2014-04-04 10:50:14 +0100 | [diff] [blame] | 345 | return kX86WordSize; |
| 346 | } |
| 347 | |
Mark Mendell | f85a9ca | 2015-01-13 09:20:58 -0500 | [diff] [blame] | 348 | size_t GetFloatingPointSpillSlotSize() const OVERRIDE { |
| 349 | // 8 bytes == 2 words for each spill. |
| 350 | return 2 * kX86WordSize; |
| 351 | } |
| 352 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 353 | HGraphVisitor* GetLocationBuilder() OVERRIDE { |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 354 | return &location_builder_; |
| 355 | } |
| 356 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 357 | HGraphVisitor* GetInstructionVisitor() OVERRIDE { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 358 | return &instruction_visitor_; |
| 359 | } |
| 360 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 361 | X86Assembler* GetAssembler() OVERRIDE { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 362 | return &assembler_; |
| 363 | } |
| 364 | |
Alexandre Rames | eb7b739 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 365 | const X86Assembler& GetAssembler() const OVERRIDE { |
| 366 | return assembler_; |
| 367 | } |
| 368 | |
Alexandre Rames | c01a664 | 2016-04-15 11:54:06 +0100 | [diff] [blame] | 369 | uintptr_t GetAddressOf(HBasicBlock* block) OVERRIDE { |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 370 | return GetLabelOf(block)->Position(); |
| 371 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 372 | |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 373 | void SetupBlockedRegisters() const OVERRIDE; |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 374 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 375 | void DumpCoreRegister(std::ostream& stream, int reg) const OVERRIDE; |
| 376 | void DumpFloatingPointRegister(std::ostream& stream, int reg) const OVERRIDE; |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 377 | |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 378 | ParallelMoveResolverX86* GetMoveResolver() OVERRIDE { |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 379 | return &move_resolver_; |
| 380 | } |
| 381 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 382 | InstructionSet GetInstructionSet() const OVERRIDE { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 383 | return InstructionSet::kX86; |
| 384 | } |
| 385 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 386 | // Helper method to move a 32bits value between two locations. |
| 387 | void Move32(Location destination, Location source); |
| 388 | // Helper method to move a 64bits value between two locations. |
| 389 | void Move64(Location destination, Location source); |
| 390 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 391 | // Check if the desired_string_load_kind is supported. If it is, return it, |
| 392 | // otherwise return a fall-back kind that should be used instead. |
| 393 | HLoadString::LoadKind GetSupportedLoadStringKind( |
| 394 | HLoadString::LoadKind desired_string_load_kind) OVERRIDE; |
| 395 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 396 | // Check if the desired_class_load_kind is supported. If it is, return it, |
| 397 | // otherwise return a fall-back kind that should be used instead. |
| 398 | HLoadClass::LoadKind GetSupportedLoadClassKind( |
| 399 | HLoadClass::LoadKind desired_class_load_kind) OVERRIDE; |
| 400 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 401 | // Check if the desired_dispatch_info is supported. If it is, return it, |
| 402 | // otherwise return a fall-back info that should be used instead. |
| 403 | HInvokeStaticOrDirect::DispatchInfo GetSupportedInvokeStaticOrDirectDispatch( |
| 404 | const HInvokeStaticOrDirect::DispatchInfo& desired_dispatch_info, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 405 | HInvokeStaticOrDirect* invoke) OVERRIDE; |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 406 | |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 407 | // Generate a call to a static or direct method. |
Serguei Katkov | 288c7a8 | 2016-05-16 11:53:15 +0600 | [diff] [blame] | 408 | Location GenerateCalleeMethodStaticOrDirectCall(HInvokeStaticOrDirect* invoke, Location temp); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 409 | void GenerateStaticOrDirectCall(HInvokeStaticOrDirect* invoke, Location temp) OVERRIDE; |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 410 | // Generate a call to a virtual method. |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 411 | void GenerateVirtualCall(HInvokeVirtual* invoke, Location temp) OVERRIDE; |
| 412 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 413 | void RecordSimplePatch(); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 414 | void RecordBootStringPatch(HLoadString* load_string); |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 415 | void RecordBootTypePatch(HLoadClass* load_class); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 416 | Label* NewTypeBssEntryPatch(HLoadClass* load_class); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 417 | Label* NewStringBssEntryPatch(HLoadString* load_string); |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame^] | 418 | Label* NewPcRelativeDexCacheArrayPatch(HX86ComputeBaseMethodAddress* method_address, |
| 419 | const DexFile& dex_file, |
| 420 | uint32_t element_offset); |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 421 | Label* NewJitRootStringPatch(const DexFile& dex_file, |
| 422 | dex::StringIndex dex_index, |
| 423 | Handle<mirror::String> handle); |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 424 | Label* NewJitRootClassPatch(const DexFile& dex_file, |
| 425 | dex::TypeIndex dex_index, |
| 426 | Handle<mirror::Class> handle); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 427 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 428 | void MoveFromReturnRegister(Location trg, Primitive::Type type) OVERRIDE; |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 429 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 430 | // Emit linker patches. |
| 431 | void EmitLinkerPatches(ArenaVector<LinkerPatch>* linker_patches) OVERRIDE; |
| 432 | |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 433 | void PatchJitRootUse(uint8_t* code, |
| 434 | const uint8_t* roots_data, |
| 435 | const PatchInfo<Label>& info, |
| 436 | uint64_t index_in_table) const; |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 437 | void EmitJitRootPatches(uint8_t* code, const uint8_t* roots_data) OVERRIDE; |
| 438 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 439 | // Emit a write barrier. |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 440 | void MarkGCCard(Register temp, |
| 441 | Register card, |
| 442 | Register object, |
| 443 | Register value, |
| 444 | bool value_can_be_null); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 445 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 446 | void GenerateMemoryBarrier(MemBarrierKind kind); |
| 447 | |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 448 | Label* GetLabelOf(HBasicBlock* block) const { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 449 | return CommonGetLabelOf<Label>(block_labels_, block); |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 450 | } |
| 451 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 452 | void Initialize() OVERRIDE { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 453 | block_labels_ = CommonInitializeLabels<Label>(); |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 454 | } |
| 455 | |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 456 | bool NeedsTwoRegisters(Primitive::Type type) const OVERRIDE { |
| 457 | return type == Primitive::kPrimLong; |
| 458 | } |
| 459 | |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 460 | bool ShouldSplitLongMoves() const OVERRIDE { return true; } |
| 461 | |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 462 | Label* GetFrameEntryLabel() { return &frame_entry_label_; } |
| 463 | |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 464 | const X86InstructionSetFeatures& GetInstructionSetFeatures() const { |
| 465 | return isa_features_; |
| 466 | } |
| 467 | |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame^] | 468 | void AddMethodAddressOffset(HX86ComputeBaseMethodAddress* method_base, int32_t offset) { |
| 469 | method_address_offset_.Put(method_base->GetId(), offset); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 470 | } |
| 471 | |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame^] | 472 | int32_t GetMethodAddressOffset(HX86ComputeBaseMethodAddress* method_base) const { |
| 473 | return method_address_offset_.Get(method_base->GetId()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 474 | } |
| 475 | |
| 476 | int32_t ConstantAreaStart() const { |
| 477 | return constant_area_start_; |
| 478 | } |
| 479 | |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame^] | 480 | Address LiteralDoubleAddress(double v, HX86ComputeBaseMethodAddress* method_base, Register reg); |
| 481 | Address LiteralFloatAddress(float v, HX86ComputeBaseMethodAddress* method_base, Register reg); |
| 482 | Address LiteralInt32Address(int32_t v, HX86ComputeBaseMethodAddress* method_base, Register reg); |
| 483 | Address LiteralInt64Address(int64_t v, HX86ComputeBaseMethodAddress* method_base, Register reg); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 484 | |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 485 | // Load a 32-bit value into a register in the most efficient manner. |
| 486 | void Load32BitValue(Register dest, int32_t value); |
| 487 | |
| 488 | // Compare a register with a 32-bit value in the most efficient manner. |
| 489 | void Compare32BitValue(Register dest, int32_t value); |
| 490 | |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 491 | // Compare int values. Supports only register locations for `lhs`. |
| 492 | void GenerateIntCompare(Location lhs, Location rhs); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 493 | void GenerateIntCompare(Register lhs, Location rhs); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 494 | |
| 495 | // Construct address for array access. |
| 496 | static Address ArrayAddress(Register obj, |
| 497 | Location index, |
| 498 | ScaleFactor scale, |
| 499 | uint32_t data_offset); |
| 500 | |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 501 | Address LiteralCaseTable(HX86PackedSwitch* switch_instr, Register reg, Register value); |
| 502 | |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 503 | void Finalize(CodeAllocator* allocator) OVERRIDE; |
| 504 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 505 | // Fast path implementation of ReadBarrier::Barrier for a heap |
| 506 | // reference field load when Baker's read barriers are used. |
| 507 | void GenerateFieldLoadWithBakerReadBarrier(HInstruction* instruction, |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 508 | Location ref, |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 509 | Register obj, |
| 510 | uint32_t offset, |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 511 | bool needs_null_check); |
| 512 | // Fast path implementation of ReadBarrier::Barrier for a heap |
| 513 | // reference array load when Baker's read barriers are used. |
| 514 | void GenerateArrayLoadWithBakerReadBarrier(HInstruction* instruction, |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 515 | Location ref, |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 516 | Register obj, |
| 517 | uint32_t data_offset, |
| 518 | Location index, |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 519 | bool needs_null_check); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 520 | // Factored implementation, used by GenerateFieldLoadWithBakerReadBarrier, |
| 521 | // GenerateArrayLoadWithBakerReadBarrier and some intrinsics. |
| 522 | // |
| 523 | // Load the object reference located at address `src`, held by |
| 524 | // object `obj`, into `ref`, and mark it if needed. The base of |
| 525 | // address `src` must be `obj`. |
| 526 | // |
| 527 | // If `always_update_field` is true, the value of the reference is |
| 528 | // atomically updated in the holder (`obj`). This operation |
| 529 | // requires a temporary register, which must be provided as a |
| 530 | // non-null pointer (`temp`). |
Sang, Chunlei | 0fcd2b8 | 2016-04-05 17:12:59 +0800 | [diff] [blame] | 531 | void GenerateReferenceLoadWithBakerReadBarrier(HInstruction* instruction, |
| 532 | Location ref, |
| 533 | Register obj, |
| 534 | const Address& src, |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 535 | bool needs_null_check, |
| 536 | bool always_update_field = false, |
| 537 | Register* temp = nullptr); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 538 | |
| 539 | // Generate a read barrier for a heap reference within `instruction` |
| 540 | // using a slow path. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 541 | // |
| 542 | // A read barrier for an object reference read from the heap is |
| 543 | // implemented as a call to the artReadBarrierSlow runtime entry |
| 544 | // point, which is passed the values in locations `ref`, `obj`, and |
| 545 | // `offset`: |
| 546 | // |
| 547 | // mirror::Object* artReadBarrierSlow(mirror::Object* ref, |
| 548 | // mirror::Object* obj, |
| 549 | // uint32_t offset); |
| 550 | // |
| 551 | // The `out` location contains the value returned by |
| 552 | // artReadBarrierSlow. |
| 553 | // |
| 554 | // When `index` is provided (i.e. for array accesses), the offset |
| 555 | // value passed to artReadBarrierSlow is adjusted to take `index` |
| 556 | // into account. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 557 | void GenerateReadBarrierSlow(HInstruction* instruction, |
| 558 | Location out, |
| 559 | Location ref, |
| 560 | Location obj, |
| 561 | uint32_t offset, |
| 562 | Location index = Location::NoLocation()); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 563 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 564 | // If read barriers are enabled, generate a read barrier for a heap |
| 565 | // reference using a slow path. If heap poisoning is enabled, also |
| 566 | // unpoison the reference in `out`. |
| 567 | void MaybeGenerateReadBarrierSlow(HInstruction* instruction, |
| 568 | Location out, |
| 569 | Location ref, |
| 570 | Location obj, |
| 571 | uint32_t offset, |
| 572 | Location index = Location::NoLocation()); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 573 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 574 | // Generate a read barrier for a GC root within `instruction` using |
| 575 | // a slow path. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 576 | // |
| 577 | // A read barrier for an object reference GC root is implemented as |
| 578 | // a call to the artReadBarrierForRootSlow runtime entry point, |
| 579 | // which is passed the value in location `root`: |
| 580 | // |
| 581 | // mirror::Object* artReadBarrierForRootSlow(GcRoot<mirror::Object>* root); |
| 582 | // |
| 583 | // The `out` location contains the value returned by |
| 584 | // artReadBarrierForRootSlow. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 585 | void GenerateReadBarrierForRootSlow(HInstruction* instruction, Location out, Location root); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 586 | |
Mark P Mendell | 17077d8 | 2015-12-16 19:15:59 +0000 | [diff] [blame] | 587 | // Ensure that prior stores complete to memory before subsequent loads. |
| 588 | // The locked add implementation will avoid serializing device memory, but will |
| 589 | // touch (but not change) the top of the stack. |
| 590 | // The 'non_temporal' parameter should be used to ensure ordering of non-temporal stores. |
| 591 | void MemoryFence(bool non_temporal = false) { |
Mark Mendell | 7aa04a1 | 2016-01-27 22:39:07 -0500 | [diff] [blame] | 592 | if (!non_temporal) { |
Mark P Mendell | 17077d8 | 2015-12-16 19:15:59 +0000 | [diff] [blame] | 593 | assembler_.lock()->addl(Address(ESP, 0), Immediate(0)); |
| 594 | } else { |
| 595 | assembler_.mfence(); |
| 596 | } |
| 597 | } |
| 598 | |
Roland Levillain | f41f956 | 2016-09-14 19:26:48 +0100 | [diff] [blame] | 599 | void GenerateNop() OVERRIDE; |
| 600 | void GenerateImplicitNullCheck(HNullCheck* instruction) OVERRIDE; |
| 601 | void GenerateExplicitNullCheck(HNullCheck* instruction) OVERRIDE; |
Mark P Mendell | 17077d8 | 2015-12-16 19:15:59 +0000 | [diff] [blame] | 602 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 603 | // When we don't know the proper offset for the value, we use kDummy32BitOffset. |
| 604 | // The correct value will be inserted when processing Assembler fixups. |
| 605 | static constexpr int32_t kDummy32BitOffset = 256; |
| 606 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 607 | private: |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame^] | 608 | struct X86PcRelativePatchInfo : PatchInfo<Label> { |
| 609 | X86PcRelativePatchInfo(HX86ComputeBaseMethodAddress* address, |
| 610 | const DexFile& target_dex_file, |
| 611 | uint32_t target_index) |
| 612 | : PatchInfo(target_dex_file, target_index), |
| 613 | method_address(address) {} |
| 614 | HX86ComputeBaseMethodAddress* method_address; |
| 615 | }; |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 616 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 617 | template <LinkerPatch (*Factory)(size_t, const DexFile*, uint32_t, uint32_t)> |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame^] | 618 | void EmitPcRelativeLinkerPatches(const ArenaDeque<X86PcRelativePatchInfo>& infos, |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 619 | ArenaVector<LinkerPatch>* linker_patches); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 620 | |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame^] | 621 | Register GetInvokeStaticOrDirectExtraParameter(HInvokeStaticOrDirect* invoke, Register temp); |
| 622 | |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 623 | // Labels for each block that will be compiled. |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 624 | Label* block_labels_; // Indexed by block id. |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 625 | Label frame_entry_label_; |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 626 | LocationsBuilderX86 location_builder_; |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 627 | InstructionCodeGeneratorX86 instruction_visitor_; |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 628 | ParallelMoveResolverX86 move_resolver_; |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 629 | X86Assembler assembler_; |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 630 | const X86InstructionSetFeatures& isa_features_; |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 631 | |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 632 | // PC-relative DexCache access info. |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame^] | 633 | ArenaDeque<X86PcRelativePatchInfo> pc_relative_dex_cache_patches_; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 634 | // Patch locations for patchoat where the linker doesn't do any other work. |
| 635 | ArenaDeque<Label> simple_patches_; |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 636 | // String patch locations; type depends on configuration (app .bss or boot image PIC/non-PIC). |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame^] | 637 | ArenaDeque<X86PcRelativePatchInfo> string_patches_; |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 638 | // Type patch locations for boot image; type depends on configuration (boot image PIC/non-PIC). |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame^] | 639 | ArenaDeque<X86PcRelativePatchInfo> boot_image_type_patches_; |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 640 | // Type patch locations for kBssEntry. |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame^] | 641 | ArenaDeque<X86PcRelativePatchInfo> type_bss_entry_patches_; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 642 | |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 643 | // Patches for string root accesses in JIT compiled code. |
| 644 | ArenaDeque<PatchInfo<Label>> jit_string_patches_; |
| 645 | |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 646 | // Patches for class root accesses in JIT compiled code. |
| 647 | ArenaDeque<PatchInfo<Label>> jit_class_patches_; |
| 648 | |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 649 | // Offset to the start of the constant area in the assembled code. |
| 650 | // Used for fixups to the constant area. |
| 651 | int32_t constant_area_start_; |
| 652 | |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 653 | // Fixups for jump tables that need to be patched after the constant table is generated. |
| 654 | ArenaVector<JumpTableRIPFixup*> fixups_to_jump_tables_; |
| 655 | |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame^] | 656 | // Maps a HX86ComputeBaseMethodAddress instruction id, to its offset in the |
| 657 | // compiled code. |
| 658 | ArenaSafeMap<uint32_t, int32_t> method_address_offset_; |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 659 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 660 | DISALLOW_COPY_AND_ASSIGN(CodeGeneratorX86); |
| 661 | }; |
| 662 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 663 | } // namespace x86 |
| 664 | } // namespace art |
| 665 | |
| 666 | #endif // ART_COMPILER_OPTIMIZING_CODE_GENERATOR_X86_H_ |