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