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