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 | |
| 20 | #include "code_generator.h" |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 21 | #include "dex/compiler_enums.h" |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 22 | #include "driver/compiler_options.h" |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 23 | #include "nodes.h" |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 24 | #include "parallel_move_resolver.h" |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 25 | #include "utils/x86/assembler_x86.h" |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 26 | |
| 27 | namespace art { |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 28 | namespace x86 { |
| 29 | |
Nicolas Geoffray | 86a8d7a | 2014-11-19 08:47:18 +0000 | [diff] [blame] | 30 | // Use a local definition to prevent copying mistakes. |
| 31 | static constexpr size_t kX86WordSize = kX86PointerSize; |
Nicolas Geoffray | 707c809 | 2014-04-04 10:50:14 +0100 | [diff] [blame] | 32 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 33 | class CodeGeneratorX86; |
| 34 | |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 35 | static constexpr Register kParameterCoreRegisters[] = { ECX, EDX, EBX }; |
| 36 | static constexpr RegisterPair kParameterCorePairRegisters[] = { ECX_EDX, EDX_EBX }; |
| 37 | static constexpr size_t kParameterCoreRegistersLength = arraysize(kParameterCoreRegisters); |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 38 | static constexpr XmmRegister kParameterFpuRegisters[] = { XMM0, XMM1, XMM2, XMM3 }; |
| 39 | static constexpr size_t kParameterFpuRegistersLength = arraysize(kParameterFpuRegisters); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 40 | |
Nicolas Geoffray | d75948a | 2015-03-27 09:53:16 +0000 | [diff] [blame] | 41 | static constexpr Register kRuntimeParameterCoreRegisters[] = { EAX, ECX, EDX, EBX }; |
| 42 | static constexpr size_t kRuntimeParameterCoreRegistersLength = |
| 43 | arraysize(kRuntimeParameterCoreRegisters); |
| 44 | static constexpr XmmRegister kRuntimeParameterFpuRegisters[] = { XMM0, XMM1, XMM2, XMM3 }; |
| 45 | static constexpr size_t kRuntimeParameterFpuRegistersLength = |
| 46 | arraysize(kRuntimeParameterFpuRegisters); |
| 47 | |
| 48 | class InvokeRuntimeCallingConvention : public CallingConvention<Register, XmmRegister> { |
| 49 | public: |
| 50 | InvokeRuntimeCallingConvention() |
| 51 | : CallingConvention(kRuntimeParameterCoreRegisters, |
| 52 | kRuntimeParameterCoreRegistersLength, |
| 53 | kRuntimeParameterFpuRegisters, |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 54 | kRuntimeParameterFpuRegistersLength, |
| 55 | kX86PointerSize) {} |
Nicolas Geoffray | d75948a | 2015-03-27 09:53:16 +0000 | [diff] [blame] | 56 | |
| 57 | private: |
| 58 | DISALLOW_COPY_AND_ASSIGN(InvokeRuntimeCallingConvention); |
| 59 | }; |
| 60 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 61 | class InvokeDexCallingConvention : public CallingConvention<Register, XmmRegister> { |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 62 | public: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 63 | InvokeDexCallingConvention() : CallingConvention( |
| 64 | kParameterCoreRegisters, |
| 65 | kParameterCoreRegistersLength, |
| 66 | kParameterFpuRegisters, |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 67 | kParameterFpuRegistersLength, |
| 68 | kX86PointerSize) {} |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 69 | |
| 70 | RegisterPair GetRegisterPairAt(size_t argument_index) { |
| 71 | DCHECK_LT(argument_index + 1, GetNumberOfRegisters()); |
| 72 | return kParameterCorePairRegisters[argument_index]; |
| 73 | } |
| 74 | |
| 75 | private: |
| 76 | DISALLOW_COPY_AND_ASSIGN(InvokeDexCallingConvention); |
| 77 | }; |
| 78 | |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 79 | class InvokeDexCallingConventionVisitorX86 : public InvokeDexCallingConventionVisitor { |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 80 | public: |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 81 | InvokeDexCallingConventionVisitorX86() {} |
| 82 | virtual ~InvokeDexCallingConventionVisitorX86() {} |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 83 | |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 84 | Location GetNextLocation(Primitive::Type type) OVERRIDE; |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 85 | Location GetReturnLocation(Primitive::Type type) const OVERRIDE; |
| 86 | Location GetMethodLocation() const OVERRIDE; |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 87 | |
| 88 | private: |
| 89 | InvokeDexCallingConvention calling_convention; |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 90 | |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 91 | DISALLOW_COPY_AND_ASSIGN(InvokeDexCallingConventionVisitorX86); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 92 | }; |
| 93 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 94 | class FieldAccessCallingConventionX86 : public FieldAccessCallingConvention { |
| 95 | public: |
| 96 | FieldAccessCallingConventionX86() {} |
| 97 | |
| 98 | Location GetObjectLocation() const OVERRIDE { |
| 99 | return Location::RegisterLocation(ECX); |
| 100 | } |
| 101 | Location GetFieldIndexLocation() const OVERRIDE { |
| 102 | return Location::RegisterLocation(EAX); |
| 103 | } |
| 104 | Location GetReturnLocation(Primitive::Type type) const OVERRIDE { |
| 105 | return Primitive::Is64BitType(type) |
| 106 | ? Location::RegisterPairLocation(EAX, EDX) |
| 107 | : Location::RegisterLocation(EAX); |
| 108 | } |
| 109 | Location GetSetValueLocation(Primitive::Type type, bool is_instance) const OVERRIDE { |
| 110 | return Primitive::Is64BitType(type) |
| 111 | ? Location::RegisterPairLocation(EDX, EBX) |
| 112 | : (is_instance |
| 113 | ? Location::RegisterLocation(EDX) |
| 114 | : Location::RegisterLocation(ECX)); |
| 115 | } |
| 116 | Location GetFpuLocation(Primitive::Type type ATTRIBUTE_UNUSED) const OVERRIDE { |
| 117 | return Location::FpuRegisterLocation(XMM0); |
| 118 | } |
| 119 | |
| 120 | private: |
| 121 | DISALLOW_COPY_AND_ASSIGN(FieldAccessCallingConventionX86); |
| 122 | }; |
| 123 | |
Zheng Xu | ad4450e | 2015-04-17 18:48:56 +0800 | [diff] [blame] | 124 | class ParallelMoveResolverX86 : public ParallelMoveResolverWithSwap { |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 125 | public: |
| 126 | ParallelMoveResolverX86(ArenaAllocator* allocator, CodeGeneratorX86* codegen) |
Zheng Xu | ad4450e | 2015-04-17 18:48:56 +0800 | [diff] [blame] | 127 | : ParallelMoveResolverWithSwap(allocator), codegen_(codegen) {} |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 128 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 129 | void EmitMove(size_t index) OVERRIDE; |
| 130 | void EmitSwap(size_t index) OVERRIDE; |
| 131 | void SpillScratch(int reg) OVERRIDE; |
| 132 | void RestoreScratch(int reg) OVERRIDE; |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 133 | |
| 134 | X86Assembler* GetAssembler() const; |
| 135 | |
| 136 | private: |
| 137 | void Exchange(Register reg, int mem); |
| 138 | void Exchange(int mem1, int mem2); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 139 | void Exchange32(XmmRegister reg, int mem); |
| 140 | void MoveMemoryToMemory32(int dst, int src); |
| 141 | void MoveMemoryToMemory64(int dst, int src); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 142 | |
| 143 | CodeGeneratorX86* const codegen_; |
| 144 | |
| 145 | DISALLOW_COPY_AND_ASSIGN(ParallelMoveResolverX86); |
| 146 | }; |
| 147 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 148 | class LocationsBuilderX86 : public HGraphVisitor { |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 149 | public: |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 150 | LocationsBuilderX86(HGraph* graph, CodeGeneratorX86* codegen) |
| 151 | : HGraphVisitor(graph), codegen_(codegen) {} |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 152 | |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 153 | #define DECLARE_VISIT_INSTRUCTION(name, super) \ |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 154 | void Visit##name(H##name* instr) OVERRIDE; |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 155 | |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 156 | FOR_EACH_CONCRETE_INSTRUCTION_COMMON(DECLARE_VISIT_INSTRUCTION) |
| 157 | FOR_EACH_CONCRETE_INSTRUCTION_X86(DECLARE_VISIT_INSTRUCTION) |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 158 | |
| 159 | #undef DECLARE_VISIT_INSTRUCTION |
| 160 | |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 161 | void VisitInstruction(HInstruction* instruction) OVERRIDE { |
| 162 | LOG(FATAL) << "Unreachable instruction " << instruction->DebugName() |
| 163 | << " (id " << instruction->GetId() << ")"; |
| 164 | } |
| 165 | |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 166 | private: |
| 167 | void HandleBitwiseOperation(HBinaryOperation* instruction); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 168 | void HandleInvoke(HInvoke* invoke); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 169 | void HandleShift(HBinaryOperation* instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 170 | void HandleFieldSet(HInstruction* instruction, const FieldInfo& field_info); |
| 171 | void HandleFieldGet(HInstruction* instruction, const FieldInfo& field_info); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 172 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 173 | CodeGeneratorX86* const codegen_; |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 174 | InvokeDexCallingConventionVisitorX86 parameter_visitor_; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 175 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 176 | DISALLOW_COPY_AND_ASSIGN(LocationsBuilderX86); |
| 177 | }; |
| 178 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 179 | class InstructionCodeGeneratorX86 : public HGraphVisitor { |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 180 | public: |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 181 | InstructionCodeGeneratorX86(HGraph* graph, CodeGeneratorX86* codegen); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 182 | |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 183 | #define DECLARE_VISIT_INSTRUCTION(name, super) \ |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 184 | void Visit##name(H##name* instr) OVERRIDE; |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 185 | |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 186 | FOR_EACH_CONCRETE_INSTRUCTION_COMMON(DECLARE_VISIT_INSTRUCTION) |
| 187 | FOR_EACH_CONCRETE_INSTRUCTION_X86(DECLARE_VISIT_INSTRUCTION) |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 188 | |
| 189 | #undef DECLARE_VISIT_INSTRUCTION |
| 190 | |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 191 | void VisitInstruction(HInstruction* instruction) OVERRIDE { |
| 192 | LOG(FATAL) << "Unreachable instruction " << instruction->DebugName() |
| 193 | << " (id " << instruction->GetId() << ")"; |
| 194 | } |
| 195 | |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 196 | X86Assembler* GetAssembler() const { return assembler_; } |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 197 | |
| 198 | private: |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 199 | // Generate code for the given suspend check. If not null, `successor` |
| 200 | // is the block to branch to if the suspend check is not needed, and after |
| 201 | // the suspend call. |
| 202 | void GenerateSuspendCheck(HSuspendCheck* check, HBasicBlock* successor); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 203 | void GenerateClassInitializationCheck(SlowPathCode* slow_path, Register class_reg); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 204 | void HandleBitwiseOperation(HBinaryOperation* instruction); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 205 | void GenerateDivRemIntegral(HBinaryOperation* instruction); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 206 | void DivRemOneOrMinusOne(HBinaryOperation* instruction); |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 207 | void DivByPowerOfTwo(HDiv* instruction); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 208 | void GenerateDivRemWithAnyConstant(HBinaryOperation* instruction); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 209 | void GenerateRemFP(HRem* rem); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 210 | void HandleShift(HBinaryOperation* instruction); |
| 211 | void GenerateShlLong(const Location& loc, Register shifter); |
| 212 | void GenerateShrLong(const Location& loc, Register shifter); |
| 213 | void GenerateUShrLong(const Location& loc, Register shifter); |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 214 | void GenerateShlLong(const Location& loc, int shift); |
| 215 | void GenerateShrLong(const Location& loc, int shift); |
| 216 | void GenerateUShrLong(const Location& loc, int shift); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 217 | void GenerateMemoryBarrier(MemBarrierKind kind); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 218 | void HandleFieldSet(HInstruction* instruction, |
| 219 | const FieldInfo& field_info, |
| 220 | bool value_can_be_null); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 221 | void HandleFieldGet(HInstruction* instruction, const FieldInfo& field_info); |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 222 | // Push value to FPU stack. `is_fp` specifies whether the value is floating point or not. |
| 223 | // `is_wide` specifies whether it is long/double or not. |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 224 | void PushOntoFPStack(Location source, uint32_t temp_offset, |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 225 | uint32_t stack_adjustment, bool is_fp, bool is_wide); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 226 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 227 | void GenerateImplicitNullCheck(HNullCheck* instruction); |
| 228 | void GenerateExplicitNullCheck(HNullCheck* instruction); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 229 | void GenerateTestAndBranch(HInstruction* instruction, |
| 230 | Label* true_target, |
| 231 | Label* false_target, |
| 232 | Label* always_true_target); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 233 | void GenerateCompareTestAndBranch(HIf* if_inst, |
| 234 | HCondition* condition, |
| 235 | Label* true_target, |
| 236 | Label* false_target, |
| 237 | Label* always_true_target); |
| 238 | void GenerateFPJumps(HCondition* cond, Label* true_label, Label* false_label); |
| 239 | void GenerateLongComparesAndJumps(HCondition* cond, Label* true_label, Label* false_label); |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 240 | void HandleGoto(HInstruction* got, HBasicBlock* successor); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 241 | |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 242 | X86Assembler* const assembler_; |
| 243 | CodeGeneratorX86* const codegen_; |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 244 | |
| 245 | DISALLOW_COPY_AND_ASSIGN(InstructionCodeGeneratorX86); |
| 246 | }; |
| 247 | |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 248 | class JumpTableRIPFixup; |
| 249 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 250 | class CodeGeneratorX86 : public CodeGenerator { |
| 251 | public: |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 252 | CodeGeneratorX86(HGraph* graph, |
| 253 | const X86InstructionSetFeatures& isa_features, |
Serban Constantinescu | ecc4366 | 2015-08-13 13:33:12 +0100 | [diff] [blame] | 254 | const CompilerOptions& compiler_options, |
| 255 | OptimizingCompilerStats* stats = nullptr); |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 256 | virtual ~CodeGeneratorX86() {} |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 257 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 258 | void GenerateFrameEntry() OVERRIDE; |
| 259 | void GenerateFrameExit() OVERRIDE; |
| 260 | void Bind(HBasicBlock* block) OVERRIDE; |
| 261 | void Move(HInstruction* instruction, Location location, HInstruction* move_for) OVERRIDE; |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 262 | void MoveConstant(Location destination, int32_t value) OVERRIDE; |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 263 | void MoveLocation(Location dst, Location src, Primitive::Type dst_type) OVERRIDE; |
| 264 | void AddLocationAsTemp(Location location, LocationSummary* locations) OVERRIDE; |
| 265 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 266 | size_t SaveCoreRegister(size_t stack_index, uint32_t reg_id) OVERRIDE; |
| 267 | size_t RestoreCoreRegister(size_t stack_index, uint32_t reg_id) OVERRIDE; |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 268 | size_t SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) OVERRIDE; |
| 269 | size_t RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) OVERRIDE; |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 270 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 271 | // Generate code to invoke a runtime entry point. |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 272 | void InvokeRuntime(QuickEntrypointEnum entrypoint, |
| 273 | HInstruction* instruction, |
| 274 | uint32_t dex_pc, |
| 275 | SlowPathCode* slow_path) OVERRIDE; |
| 276 | |
| 277 | void InvokeRuntime(int32_t entry_point_offset, |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 278 | HInstruction* instruction, |
| 279 | uint32_t dex_pc, |
| 280 | SlowPathCode* slow_path); |
| 281 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 282 | size_t GetWordSize() const OVERRIDE { |
Nicolas Geoffray | 707c809 | 2014-04-04 10:50:14 +0100 | [diff] [blame] | 283 | return kX86WordSize; |
| 284 | } |
| 285 | |
Mark Mendell | f85a9ca | 2015-01-13 09:20:58 -0500 | [diff] [blame] | 286 | size_t GetFloatingPointSpillSlotSize() const OVERRIDE { |
| 287 | // 8 bytes == 2 words for each spill. |
| 288 | return 2 * kX86WordSize; |
| 289 | } |
| 290 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 291 | HGraphVisitor* GetLocationBuilder() OVERRIDE { |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 292 | return &location_builder_; |
| 293 | } |
| 294 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 295 | HGraphVisitor* GetInstructionVisitor() OVERRIDE { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 296 | return &instruction_visitor_; |
| 297 | } |
| 298 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 299 | X86Assembler* GetAssembler() OVERRIDE { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 300 | return &assembler_; |
| 301 | } |
| 302 | |
Alexandre Rames | eb7b739 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 303 | const X86Assembler& GetAssembler() const OVERRIDE { |
| 304 | return assembler_; |
| 305 | } |
| 306 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 307 | uintptr_t GetAddressOf(HBasicBlock* block) const OVERRIDE { |
| 308 | return GetLabelOf(block)->Position(); |
| 309 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 310 | |
Nicolas Geoffray | 9889396 | 2015-01-21 12:32:32 +0000 | [diff] [blame] | 311 | void SetupBlockedRegisters(bool is_baseline) const OVERRIDE; |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 312 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 313 | Location AllocateFreeRegister(Primitive::Type type) const OVERRIDE; |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 314 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 315 | Location GetStackLocation(HLoadLocal* load) const OVERRIDE; |
| 316 | |
| 317 | void DumpCoreRegister(std::ostream& stream, int reg) const OVERRIDE; |
| 318 | void DumpFloatingPointRegister(std::ostream& stream, int reg) const OVERRIDE; |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 319 | |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 320 | // Blocks all register pairs made out of blocked core registers. |
| 321 | void UpdateBlockedPairRegisters() const; |
| 322 | |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 323 | ParallelMoveResolverX86* GetMoveResolver() OVERRIDE { |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 324 | return &move_resolver_; |
| 325 | } |
| 326 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 327 | InstructionSet GetInstructionSet() const OVERRIDE { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 328 | return InstructionSet::kX86; |
| 329 | } |
| 330 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 331 | // Helper method to move a 32bits value between two locations. |
| 332 | void Move32(Location destination, Location source); |
| 333 | // Helper method to move a 64bits value between two locations. |
| 334 | void Move64(Location destination, Location source); |
| 335 | |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 336 | // Generate a call to a static or direct method. |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 337 | void GenerateStaticOrDirectCall(HInvokeStaticOrDirect* invoke, Location temp) OVERRIDE; |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 338 | // Generate a call to a virtual method. |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 339 | void GenerateVirtualCall(HInvokeVirtual* invoke, Location temp) OVERRIDE; |
| 340 | |
| 341 | void MoveFromReturnRegister(Location trg, Primitive::Type type) OVERRIDE; |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 342 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 343 | // Emit linker patches. |
| 344 | void EmitLinkerPatches(ArenaVector<LinkerPatch>* linker_patches) OVERRIDE; |
| 345 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 346 | // Emit a write barrier. |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 347 | void MarkGCCard(Register temp, |
| 348 | Register card, |
| 349 | Register object, |
| 350 | Register value, |
| 351 | bool value_can_be_null); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 352 | |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 353 | Label* GetLabelOf(HBasicBlock* block) const { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 354 | return CommonGetLabelOf<Label>(block_labels_, block); |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 355 | } |
| 356 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 357 | void Initialize() OVERRIDE { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 358 | block_labels_ = CommonInitializeLabels<Label>(); |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 359 | } |
| 360 | |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 361 | bool NeedsTwoRegisters(Primitive::Type type) const OVERRIDE { |
| 362 | return type == Primitive::kPrimLong; |
| 363 | } |
| 364 | |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 365 | bool ShouldSplitLongMoves() const OVERRIDE { return true; } |
| 366 | |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 367 | Label* GetFrameEntryLabel() { return &frame_entry_label_; } |
| 368 | |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 369 | const X86InstructionSetFeatures& GetInstructionSetFeatures() const { |
| 370 | return isa_features_; |
| 371 | } |
| 372 | |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 373 | void SetMethodAddressOffset(int32_t offset) { |
| 374 | method_address_offset_ = offset; |
| 375 | } |
| 376 | |
| 377 | int32_t GetMethodAddressOffset() const { |
| 378 | return method_address_offset_; |
| 379 | } |
| 380 | |
| 381 | int32_t ConstantAreaStart() const { |
| 382 | return constant_area_start_; |
| 383 | } |
| 384 | |
| 385 | Address LiteralDoubleAddress(double v, Register reg); |
| 386 | Address LiteralFloatAddress(float v, Register reg); |
| 387 | Address LiteralInt32Address(int32_t v, Register reg); |
| 388 | Address LiteralInt64Address(int64_t v, Register reg); |
| 389 | |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 390 | Address LiteralCaseTable(HX86PackedSwitch* switch_instr, Register reg, Register value); |
| 391 | |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 392 | void Finalize(CodeAllocator* allocator) OVERRIDE; |
| 393 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 394 | private: |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 395 | // Labels for each block that will be compiled. |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 396 | Label* block_labels_; // Indexed by block id. |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 397 | Label frame_entry_label_; |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 398 | LocationsBuilderX86 location_builder_; |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 399 | InstructionCodeGeneratorX86 instruction_visitor_; |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 400 | ParallelMoveResolverX86 move_resolver_; |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 401 | X86Assembler assembler_; |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 402 | const X86InstructionSetFeatures& isa_features_; |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 403 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 404 | // Method patch info. Using ArenaDeque<> which retains element addresses on push/emplace_back(). |
| 405 | ArenaDeque<MethodPatchInfo<Label>> method_patches_; |
| 406 | ArenaDeque<MethodPatchInfo<Label>> relative_call_patches_; |
| 407 | |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 408 | // Offset to the start of the constant area in the assembled code. |
| 409 | // Used for fixups to the constant area. |
| 410 | int32_t constant_area_start_; |
| 411 | |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 412 | // Fixups for jump tables that need to be patched after the constant table is generated. |
| 413 | ArenaVector<JumpTableRIPFixup*> fixups_to_jump_tables_; |
| 414 | |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 415 | // If there is a HX86ComputeBaseMethodAddress instruction in the graph |
| 416 | // (which shall be the sole instruction of this kind), subtracting this offset |
| 417 | // from the value contained in the out register of this HX86ComputeBaseMethodAddress |
| 418 | // instruction gives the address of the start of this method. |
| 419 | int32_t method_address_offset_; |
| 420 | |
| 421 | // When we don't know the proper offset for the value, we use kDummy32BitOffset. |
| 422 | // The correct value will be inserted when processing Assembler fixups. |
| 423 | static constexpr int32_t kDummy32BitOffset = 256; |
| 424 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 425 | DISALLOW_COPY_AND_ASSIGN(CodeGeneratorX86); |
| 426 | }; |
| 427 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 428 | } // namespace x86 |
| 429 | } // namespace art |
| 430 | |
| 431 | #endif // ART_COMPILER_OPTIMIZING_CODE_GENERATOR_X86_H_ |