Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [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 | #include "code_generator_x86_64.h" |
| 18 | |
| 19 | #include "entrypoints/quick/quick_entrypoints.h" |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 20 | #include "gc/accounting/card_table.h" |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 21 | #include "mirror/array.h" |
| 22 | #include "mirror/art_method.h" |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 23 | #include "mirror/class.h" |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 24 | #include "mirror/object_reference.h" |
| 25 | #include "thread.h" |
| 26 | #include "utils/assembler.h" |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 27 | #include "utils/stack_checks.h" |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 28 | #include "utils/x86_64/assembler_x86_64.h" |
| 29 | #include "utils/x86_64/managed_register_x86_64.h" |
| 30 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 31 | namespace art { |
| 32 | |
| 33 | x86_64::X86_64ManagedRegister Location::AsX86_64() const { |
| 34 | return reg().AsX86_64(); |
| 35 | } |
| 36 | |
| 37 | namespace x86_64 { |
| 38 | |
Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 39 | static constexpr bool kExplicitStackOverflowCheck = false; |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 40 | |
| 41 | // Some x86_64 instructions require a register to be available as temp. |
| 42 | static constexpr Register TMP = R11; |
| 43 | |
| 44 | static constexpr int kNumberOfPushedRegistersAtEntry = 1; |
| 45 | static constexpr int kCurrentMethodStackOffset = 0; |
| 46 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 47 | static Location X86_64CpuLocation(Register reg) { |
| 48 | return Location::RegisterLocation(X86_64ManagedRegister::FromCpuRegister(reg)); |
| 49 | } |
| 50 | |
| 51 | static constexpr Register kRuntimeParameterCoreRegisters[] = { RDI, RSI, RDX }; |
| 52 | static constexpr size_t kRuntimeParameterCoreRegistersLength = |
| 53 | arraysize(kRuntimeParameterCoreRegisters); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame^] | 54 | static constexpr FloatRegister kRuntimeParameterFpuRegisters[] = { }; |
| 55 | static constexpr size_t kRuntimeParameterFpuRegistersLength = 0; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 56 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame^] | 57 | class InvokeRuntimeCallingConvention : public CallingConvention<Register, FloatRegister> { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 58 | public: |
| 59 | InvokeRuntimeCallingConvention() |
| 60 | : CallingConvention(kRuntimeParameterCoreRegisters, |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame^] | 61 | kRuntimeParameterCoreRegistersLength, |
| 62 | kRuntimeParameterFpuRegisters, |
| 63 | kRuntimeParameterFpuRegistersLength) {} |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 64 | |
| 65 | private: |
| 66 | DISALLOW_COPY_AND_ASSIGN(InvokeRuntimeCallingConvention); |
| 67 | }; |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 68 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 69 | #define __ reinterpret_cast<X86_64Assembler*>(codegen->GetAssembler())-> |
| 70 | |
| 71 | class NullCheckSlowPathX86_64 : public SlowPathCode { |
| 72 | public: |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 73 | explicit NullCheckSlowPathX86_64(HNullCheck* instruction) : instruction_(instruction) {} |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 74 | |
| 75 | virtual void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 76 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 77 | __ gs()->call( |
| 78 | Address::Absolute(QUICK_ENTRYPOINT_OFFSET(kX86_64WordSize, pThrowNullPointer), true)); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 79 | codegen->RecordPcInfo(instruction_, instruction_->GetDexPc()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 80 | } |
| 81 | |
| 82 | private: |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 83 | HNullCheck* const instruction_; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 84 | DISALLOW_COPY_AND_ASSIGN(NullCheckSlowPathX86_64); |
| 85 | }; |
| 86 | |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 87 | class StackOverflowCheckSlowPathX86_64 : public SlowPathCode { |
| 88 | public: |
| 89 | StackOverflowCheckSlowPathX86_64() {} |
| 90 | |
| 91 | virtual void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 92 | __ Bind(GetEntryLabel()); |
| 93 | __ addq(CpuRegister(RSP), |
| 94 | Immediate(codegen->GetFrameSize() - kNumberOfPushedRegistersAtEntry * kX86_64WordSize)); |
| 95 | __ gs()->jmp( |
| 96 | Address::Absolute(QUICK_ENTRYPOINT_OFFSET(kX86_64WordSize, pThrowStackOverflow), true)); |
| 97 | } |
| 98 | |
| 99 | private: |
| 100 | DISALLOW_COPY_AND_ASSIGN(StackOverflowCheckSlowPathX86_64); |
| 101 | }; |
| 102 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 103 | class SuspendCheckSlowPathX86_64 : public SlowPathCode { |
| 104 | public: |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 105 | explicit SuspendCheckSlowPathX86_64(HSuspendCheck* instruction, HBasicBlock* successor) |
| 106 | : instruction_(instruction), successor_(successor) {} |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 107 | |
| 108 | virtual void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 109 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 110 | codegen->SaveLiveRegisters(instruction_->GetLocations()); |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 111 | __ gs()->call(Address::Absolute(QUICK_ENTRYPOINT_OFFSET(kX86_64WordSize, pTestSuspend), true)); |
| 112 | codegen->RecordPcInfo(instruction_, instruction_->GetDexPc()); |
Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 113 | codegen->RestoreLiveRegisters(instruction_->GetLocations()); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 114 | if (successor_ == nullptr) { |
| 115 | __ jmp(GetReturnLabel()); |
| 116 | } else { |
| 117 | __ jmp(codegen->GetLabelOf(successor_)); |
| 118 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 119 | } |
| 120 | |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 121 | Label* GetReturnLabel() { |
| 122 | DCHECK(successor_ == nullptr); |
| 123 | return &return_label_; |
| 124 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 125 | |
| 126 | private: |
| 127 | HSuspendCheck* const instruction_; |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 128 | HBasicBlock* const successor_; |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 129 | Label return_label_; |
| 130 | |
| 131 | DISALLOW_COPY_AND_ASSIGN(SuspendCheckSlowPathX86_64); |
| 132 | }; |
| 133 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 134 | class BoundsCheckSlowPathX86_64 : public SlowPathCode { |
| 135 | public: |
Roland Levillain | 5799fc0 | 2014-09-25 12:15:20 +0100 | [diff] [blame] | 136 | BoundsCheckSlowPathX86_64(HBoundsCheck* instruction, |
| 137 | Location index_location, |
| 138 | Location length_location) |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 139 | : instruction_(instruction), |
| 140 | index_location_(index_location), |
| 141 | length_location_(length_location) {} |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 142 | |
| 143 | virtual void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 144 | CodeGeneratorX86_64* x64_codegen = reinterpret_cast<CodeGeneratorX86_64*>(codegen); |
| 145 | __ Bind(GetEntryLabel()); |
| 146 | InvokeRuntimeCallingConvention calling_convention; |
| 147 | x64_codegen->Move(X86_64CpuLocation(calling_convention.GetRegisterAt(0)), index_location_); |
| 148 | x64_codegen->Move(X86_64CpuLocation(calling_convention.GetRegisterAt(1)), length_location_); |
| 149 | __ gs()->call(Address::Absolute( |
| 150 | QUICK_ENTRYPOINT_OFFSET(kX86_64WordSize, pThrowArrayBounds), true)); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 151 | codegen->RecordPcInfo(instruction_, instruction_->GetDexPc()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 152 | } |
| 153 | |
| 154 | private: |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 155 | HBoundsCheck* const instruction_; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 156 | const Location index_location_; |
| 157 | const Location length_location_; |
| 158 | |
| 159 | DISALLOW_COPY_AND_ASSIGN(BoundsCheckSlowPathX86_64); |
| 160 | }; |
| 161 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 162 | #undef __ |
| 163 | #define __ reinterpret_cast<X86_64Assembler*>(GetAssembler())-> |
| 164 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 165 | inline Condition X86_64Condition(IfCondition cond) { |
| 166 | switch (cond) { |
| 167 | case kCondEQ: return kEqual; |
| 168 | case kCondNE: return kNotEqual; |
| 169 | case kCondLT: return kLess; |
| 170 | case kCondLE: return kLessEqual; |
| 171 | case kCondGT: return kGreater; |
| 172 | case kCondGE: return kGreaterEqual; |
| 173 | default: |
| 174 | LOG(FATAL) << "Unknown if condition"; |
| 175 | } |
| 176 | return kEqual; |
| 177 | } |
| 178 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 179 | void CodeGeneratorX86_64::DumpCoreRegister(std::ostream& stream, int reg) const { |
| 180 | stream << X86_64ManagedRegister::FromCpuRegister(Register(reg)); |
| 181 | } |
| 182 | |
| 183 | void CodeGeneratorX86_64::DumpFloatingPointRegister(std::ostream& stream, int reg) const { |
| 184 | stream << X86_64ManagedRegister::FromXmmRegister(FloatRegister(reg)); |
| 185 | } |
| 186 | |
Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 187 | void CodeGeneratorX86_64::SaveCoreRegister(Location stack_location, uint32_t reg_id) { |
| 188 | __ movq(Address(CpuRegister(RSP), stack_location.GetStackIndex()), CpuRegister(reg_id)); |
| 189 | } |
| 190 | |
| 191 | void CodeGeneratorX86_64::RestoreCoreRegister(Location stack_location, uint32_t reg_id) { |
| 192 | __ movq(CpuRegister(reg_id), Address(CpuRegister(RSP), stack_location.GetStackIndex())); |
| 193 | } |
| 194 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 195 | CodeGeneratorX86_64::CodeGeneratorX86_64(HGraph* graph) |
| 196 | : CodeGenerator(graph, kNumberOfRegIds), |
| 197 | location_builder_(graph, this), |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 198 | instruction_visitor_(graph, this), |
| 199 | move_resolver_(graph->GetArena(), this) {} |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 200 | |
Nicolas Geoffray | ab032bc | 2014-07-15 12:55:21 +0100 | [diff] [blame] | 201 | size_t CodeGeneratorX86_64::FrameEntrySpillSize() const { |
| 202 | return kNumberOfPushedRegistersAtEntry * kX86_64WordSize; |
| 203 | } |
| 204 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 205 | InstructionCodeGeneratorX86_64::InstructionCodeGeneratorX86_64(HGraph* graph, |
| 206 | CodeGeneratorX86_64* codegen) |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 207 | : HGraphVisitor(graph), |
| 208 | assembler_(codegen->GetAssembler()), |
| 209 | codegen_(codegen) {} |
| 210 | |
| 211 | ManagedRegister CodeGeneratorX86_64::AllocateFreeRegister(Primitive::Type type, |
| 212 | bool* blocked_registers) const { |
| 213 | switch (type) { |
| 214 | case Primitive::kPrimLong: |
| 215 | case Primitive::kPrimByte: |
| 216 | case Primitive::kPrimBoolean: |
| 217 | case Primitive::kPrimChar: |
| 218 | case Primitive::kPrimShort: |
| 219 | case Primitive::kPrimInt: |
| 220 | case Primitive::kPrimNot: { |
| 221 | size_t reg = AllocateFreeRegisterInternal(blocked_registers, kNumberOfCpuRegisters); |
| 222 | return X86_64ManagedRegister::FromCpuRegister(static_cast<Register>(reg)); |
| 223 | } |
| 224 | |
| 225 | case Primitive::kPrimFloat: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame^] | 226 | case Primitive::kPrimDouble: { |
| 227 | size_t reg = AllocateFreeRegisterInternal( |
| 228 | blocked_registers + kNumberOfCpuRegisters, kNumberOfFloatRegisters); |
| 229 | return X86_64ManagedRegister::FromXmmRegister(static_cast<FloatRegister>(reg)); |
| 230 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 231 | |
| 232 | case Primitive::kPrimVoid: |
| 233 | LOG(FATAL) << "Unreachable type " << type; |
| 234 | } |
| 235 | |
| 236 | return ManagedRegister::NoRegister(); |
| 237 | } |
| 238 | |
| 239 | void CodeGeneratorX86_64::SetupBlockedRegisters(bool* blocked_registers) const { |
| 240 | // Stack register is always reserved. |
| 241 | blocked_registers[RSP] = true; |
| 242 | |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 243 | // Block the register used as TMP. |
| 244 | blocked_registers[TMP] = true; |
| 245 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 246 | // TODO: We currently don't use Quick's callee saved registers. |
| 247 | blocked_registers[RBX] = true; |
| 248 | blocked_registers[RBP] = true; |
| 249 | blocked_registers[R12] = true; |
| 250 | blocked_registers[R13] = true; |
| 251 | blocked_registers[R14] = true; |
| 252 | blocked_registers[R15] = true; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame^] | 253 | |
| 254 | bool* blocked_xmm_registers = blocked_registers + kNumberOfCpuRegisters; |
| 255 | blocked_xmm_registers[XMM12] = true; |
| 256 | blocked_xmm_registers[XMM13] = true; |
| 257 | blocked_xmm_registers[XMM14] = true; |
| 258 | blocked_xmm_registers[XMM15] = true; |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 259 | } |
| 260 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 261 | void CodeGeneratorX86_64::GenerateFrameEntry() { |
| 262 | // Create a fake register to mimic Quick. |
| 263 | static const int kFakeReturnRegister = 16; |
| 264 | core_spill_mask_ |= (1 << kFakeReturnRegister); |
| 265 | |
Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 266 | bool skip_overflow_check = IsLeafMethod() |
Dave Allison | 648d711 | 2014-07-25 16:15:27 -0700 | [diff] [blame] | 267 | && !FrameNeedsStackCheck(GetFrameSize(), InstructionSet::kX86_64); |
Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 268 | |
| 269 | if (!skip_overflow_check && !kExplicitStackOverflowCheck) { |
| 270 | __ testq(CpuRegister(RAX), Address( |
| 271 | CpuRegister(RSP), -static_cast<int32_t>(GetStackOverflowReservedBytes(kX86_64)))); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 272 | RecordPcInfo(nullptr, 0); |
Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 273 | } |
| 274 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 275 | // The return PC has already been pushed on the stack. |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 276 | __ subq(CpuRegister(RSP), |
| 277 | Immediate(GetFrameSize() - kNumberOfPushedRegistersAtEntry * kX86_64WordSize)); |
| 278 | |
Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 279 | if (!skip_overflow_check && kExplicitStackOverflowCheck) { |
| 280 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) StackOverflowCheckSlowPathX86_64(); |
| 281 | AddSlowPath(slow_path); |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 282 | |
Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 283 | __ gs()->cmpq(CpuRegister(RSP), |
| 284 | Address::Absolute(Thread::StackEndOffset<kX86_64WordSize>(), true)); |
| 285 | __ j(kLess, slow_path->GetEntryLabel()); |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 286 | } |
| 287 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 288 | __ movl(Address(CpuRegister(RSP), kCurrentMethodStackOffset), CpuRegister(RDI)); |
| 289 | } |
| 290 | |
| 291 | void CodeGeneratorX86_64::GenerateFrameExit() { |
| 292 | __ addq(CpuRegister(RSP), |
| 293 | Immediate(GetFrameSize() - kNumberOfPushedRegistersAtEntry * kX86_64WordSize)); |
| 294 | } |
| 295 | |
| 296 | void CodeGeneratorX86_64::Bind(Label* label) { |
| 297 | __ Bind(label); |
| 298 | } |
| 299 | |
| 300 | void InstructionCodeGeneratorX86_64::LoadCurrentMethod(CpuRegister reg) { |
| 301 | __ movl(reg, Address(CpuRegister(RSP), kCurrentMethodStackOffset)); |
| 302 | } |
| 303 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 304 | Location CodeGeneratorX86_64::GetStackLocation(HLoadLocal* load) const { |
| 305 | switch (load->GetType()) { |
| 306 | case Primitive::kPrimLong: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame^] | 307 | case Primitive::kPrimDouble: |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 308 | return Location::DoubleStackSlot(GetStackSlot(load->GetLocal())); |
| 309 | break; |
| 310 | |
| 311 | case Primitive::kPrimInt: |
| 312 | case Primitive::kPrimNot: |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 313 | case Primitive::kPrimFloat: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame^] | 314 | return Location::StackSlot(GetStackSlot(load->GetLocal())); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 315 | |
| 316 | case Primitive::kPrimBoolean: |
| 317 | case Primitive::kPrimByte: |
| 318 | case Primitive::kPrimChar: |
| 319 | case Primitive::kPrimShort: |
| 320 | case Primitive::kPrimVoid: |
| 321 | LOG(FATAL) << "Unexpected type " << load->GetType(); |
| 322 | } |
| 323 | |
| 324 | LOG(FATAL) << "Unreachable"; |
| 325 | return Location(); |
| 326 | } |
| 327 | |
| 328 | void CodeGeneratorX86_64::Move(Location destination, Location source) { |
| 329 | if (source.Equals(destination)) { |
| 330 | return; |
| 331 | } |
| 332 | if (destination.IsRegister()) { |
| 333 | if (source.IsRegister()) { |
| 334 | __ movq(destination.AsX86_64().AsCpuRegister(), source.AsX86_64().AsCpuRegister()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame^] | 335 | } else if (source.IsFpuRegister()) { |
| 336 | __ movd(destination.AsX86_64().AsCpuRegister(), source.AsX86_64().AsXmmRegister()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 337 | } else if (source.IsStackSlot()) { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame^] | 338 | __ movl(destination.AsX86_64().AsCpuRegister(), |
| 339 | Address(CpuRegister(RSP), source.GetStackIndex())); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 340 | } else { |
| 341 | DCHECK(source.IsDoubleStackSlot()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame^] | 342 | __ movq(destination.AsX86_64().AsCpuRegister(), |
| 343 | Address(CpuRegister(RSP), source.GetStackIndex())); |
| 344 | } |
| 345 | } else if (destination.IsFpuRegister()) { |
| 346 | if (source.IsRegister()) { |
| 347 | __ movd(destination.AsX86_64().AsXmmRegister(), source.AsX86_64().AsCpuRegister()); |
| 348 | } else if (source.IsFpuRegister()) { |
| 349 | __ movaps(destination.AsX86_64().AsXmmRegister(), source.AsX86_64().AsXmmRegister()); |
| 350 | } else if (source.IsStackSlot()) { |
| 351 | __ movss(destination.AsX86_64().AsXmmRegister(), |
| 352 | Address(CpuRegister(RSP), source.GetStackIndex())); |
| 353 | } else { |
| 354 | DCHECK(source.IsDoubleStackSlot()); |
| 355 | __ movsd(destination.AsX86_64().AsXmmRegister(), |
| 356 | Address(CpuRegister(RSP), source.GetStackIndex())); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 357 | } |
| 358 | } else if (destination.IsStackSlot()) { |
| 359 | if (source.IsRegister()) { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame^] | 360 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), |
| 361 | source.AsX86_64().AsCpuRegister()); |
| 362 | } else if (source.IsFpuRegister()) { |
| 363 | __ movss(Address(CpuRegister(RSP), destination.GetStackIndex()), |
| 364 | source.AsX86_64().AsXmmRegister()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 365 | } else { |
| 366 | DCHECK(source.IsStackSlot()); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 367 | __ movl(CpuRegister(TMP), Address(CpuRegister(RSP), source.GetStackIndex())); |
| 368 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), CpuRegister(TMP)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 369 | } |
| 370 | } else { |
| 371 | DCHECK(destination.IsDoubleStackSlot()); |
| 372 | if (source.IsRegister()) { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame^] | 373 | __ movq(Address(CpuRegister(RSP), destination.GetStackIndex()), |
| 374 | source.AsX86_64().AsCpuRegister()); |
| 375 | } else if (source.IsFpuRegister()) { |
| 376 | __ movsd(Address(CpuRegister(RSP), destination.GetStackIndex()), |
| 377 | source.AsX86_64().AsXmmRegister()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 378 | } else { |
| 379 | DCHECK(source.IsDoubleStackSlot()); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 380 | __ movq(CpuRegister(TMP), Address(CpuRegister(RSP), source.GetStackIndex())); |
| 381 | __ movq(Address(CpuRegister(RSP), destination.GetStackIndex()), CpuRegister(TMP)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 382 | } |
| 383 | } |
| 384 | } |
| 385 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 386 | void CodeGeneratorX86_64::Move(HInstruction* instruction, |
| 387 | Location location, |
| 388 | HInstruction* move_for) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 389 | if (instruction->AsIntConstant() != nullptr) { |
| 390 | Immediate imm(instruction->AsIntConstant()->GetValue()); |
| 391 | if (location.IsRegister()) { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 392 | __ movl(location.AsX86_64().AsCpuRegister(), imm); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 393 | } else { |
| 394 | __ movl(Address(CpuRegister(RSP), location.GetStackIndex()), imm); |
| 395 | } |
| 396 | } else if (instruction->AsLongConstant() != nullptr) { |
| 397 | int64_t value = instruction->AsLongConstant()->GetValue(); |
| 398 | if (location.IsRegister()) { |
| 399 | __ movq(location.AsX86_64().AsCpuRegister(), Immediate(value)); |
| 400 | } else { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 401 | __ movq(CpuRegister(TMP), Immediate(value)); |
| 402 | __ movq(Address(CpuRegister(RSP), location.GetStackIndex()), CpuRegister(TMP)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 403 | } |
| 404 | } else if (instruction->AsLoadLocal() != nullptr) { |
| 405 | switch (instruction->GetType()) { |
| 406 | case Primitive::kPrimBoolean: |
| 407 | case Primitive::kPrimByte: |
| 408 | case Primitive::kPrimChar: |
| 409 | case Primitive::kPrimShort: |
| 410 | case Primitive::kPrimInt: |
| 411 | case Primitive::kPrimNot: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame^] | 412 | case Primitive::kPrimFloat: |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 413 | Move(location, Location::StackSlot(GetStackSlot(instruction->AsLoadLocal()->GetLocal()))); |
| 414 | break; |
| 415 | |
| 416 | case Primitive::kPrimLong: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame^] | 417 | case Primitive::kPrimDouble: |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 418 | Move(location, Location::DoubleStackSlot(GetStackSlot(instruction->AsLoadLocal()->GetLocal()))); |
| 419 | break; |
| 420 | |
| 421 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame^] | 422 | LOG(FATAL) << "Unexpected local type " << instruction->GetType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 423 | } |
| 424 | } else { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 425 | DCHECK((instruction->GetNext() == move_for) || instruction->GetNext()->IsTemporary()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 426 | switch (instruction->GetType()) { |
| 427 | case Primitive::kPrimBoolean: |
| 428 | case Primitive::kPrimByte: |
| 429 | case Primitive::kPrimChar: |
| 430 | case Primitive::kPrimShort: |
| 431 | case Primitive::kPrimInt: |
| 432 | case Primitive::kPrimNot: |
| 433 | case Primitive::kPrimLong: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame^] | 434 | case Primitive::kPrimFloat: |
| 435 | case Primitive::kPrimDouble: |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 436 | Move(location, instruction->GetLocations()->Out()); |
| 437 | break; |
| 438 | |
| 439 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame^] | 440 | LOG(FATAL) << "Unexpected type " << instruction->GetType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 441 | } |
| 442 | } |
| 443 | } |
| 444 | |
| 445 | void LocationsBuilderX86_64::VisitGoto(HGoto* got) { |
| 446 | got->SetLocations(nullptr); |
| 447 | } |
| 448 | |
| 449 | void InstructionCodeGeneratorX86_64::VisitGoto(HGoto* got) { |
| 450 | HBasicBlock* successor = got->GetSuccessor(); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 451 | DCHECK(!successor->IsExitBlock()); |
| 452 | |
| 453 | HBasicBlock* block = got->GetBlock(); |
| 454 | HInstruction* previous = got->GetPrevious(); |
| 455 | |
| 456 | HLoopInformation* info = block->GetLoopInformation(); |
| 457 | if (info != nullptr && info->IsBackEdge(block) && info->HasSuspendCheck()) { |
| 458 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(info->GetSuspendCheck()); |
| 459 | GenerateSuspendCheck(info->GetSuspendCheck(), successor); |
| 460 | return; |
| 461 | } |
| 462 | |
| 463 | if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) { |
| 464 | GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr); |
| 465 | } |
| 466 | if (!codegen_->GoesToNextBlock(got->GetBlock(), successor)) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 467 | __ jmp(codegen_->GetLabelOf(successor)); |
| 468 | } |
| 469 | } |
| 470 | |
| 471 | void LocationsBuilderX86_64::VisitExit(HExit* exit) { |
| 472 | exit->SetLocations(nullptr); |
| 473 | } |
| 474 | |
| 475 | void InstructionCodeGeneratorX86_64::VisitExit(HExit* exit) { |
| 476 | if (kIsDebugBuild) { |
| 477 | __ Comment("Unreachable"); |
| 478 | __ int3(); |
| 479 | } |
| 480 | } |
| 481 | |
| 482 | void LocationsBuilderX86_64::VisitIf(HIf* if_instr) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 483 | LocationSummary* locations = |
| 484 | new (GetGraph()->GetArena()) LocationSummary(if_instr, LocationSummary::kNoCall); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 485 | HInstruction* cond = if_instr->InputAt(0); |
| 486 | DCHECK(cond->IsCondition()); |
| 487 | HCondition* condition = cond->AsCondition(); |
| 488 | if (condition->NeedsMaterialization()) { |
Nicolas Geoffray | 9ae0daa | 2014-09-30 22:40:23 +0100 | [diff] [blame] | 489 | locations->SetInAt(0, Location::Any(), Location::kDiesAtEntry); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 490 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 491 | } |
| 492 | |
| 493 | void InstructionCodeGeneratorX86_64::VisitIf(HIf* if_instr) { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 494 | HInstruction* cond = if_instr->InputAt(0); |
| 495 | DCHECK(cond->IsCondition()); |
| 496 | HCondition* condition = cond->AsCondition(); |
| 497 | if (condition->NeedsMaterialization()) { |
Nicolas Geoffray | 18efde5 | 2014-09-22 15:51:11 +0100 | [diff] [blame] | 498 | // Moves do not affect the eflags register, so if the condition is evaluated |
| 499 | // just before the if, we don't need to evaluate it again. |
| 500 | if (!condition->IsBeforeWhenDisregardMoves(if_instr)) { |
| 501 | // Materialized condition, compare against 0. |
| 502 | Location lhs = if_instr->GetLocations()->InAt(0); |
| 503 | if (lhs.IsRegister()) { |
| 504 | __ cmpl(lhs.AsX86_64().AsCpuRegister(), Immediate(0)); |
| 505 | } else { |
| 506 | __ cmpl(Address(CpuRegister(RSP), lhs.GetStackIndex()), Immediate(0)); |
| 507 | } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 508 | } |
Nicolas Geoffray | 18efde5 | 2014-09-22 15:51:11 +0100 | [diff] [blame] | 509 | __ j(kNotEqual, codegen_->GetLabelOf(if_instr->IfTrueSuccessor())); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 510 | } else { |
| 511 | Location lhs = condition->GetLocations()->InAt(0); |
| 512 | Location rhs = condition->GetLocations()->InAt(1); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 513 | if (rhs.IsRegister()) { |
| 514 | __ cmpl(lhs.AsX86_64().AsCpuRegister(), rhs.AsX86_64().AsCpuRegister()); |
| 515 | } else if (rhs.IsConstant()) { |
| 516 | __ cmpl(lhs.AsX86_64().AsCpuRegister(), |
| 517 | Immediate(rhs.GetConstant()->AsIntConstant()->GetValue())); |
| 518 | } else { |
| 519 | __ cmpl(lhs.AsX86_64().AsCpuRegister(), Address(CpuRegister(RSP), rhs.GetStackIndex())); |
| 520 | } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 521 | __ j(X86_64Condition(condition->GetCondition()), |
| 522 | codegen_->GetLabelOf(if_instr->IfTrueSuccessor())); |
| 523 | } |
| 524 | if (!codegen_->GoesToNextBlock(if_instr->GetBlock(), if_instr->IfFalseSuccessor())) { |
| 525 | __ jmp(codegen_->GetLabelOf(if_instr->IfFalseSuccessor())); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 526 | } |
| 527 | } |
| 528 | |
| 529 | void LocationsBuilderX86_64::VisitLocal(HLocal* local) { |
| 530 | local->SetLocations(nullptr); |
| 531 | } |
| 532 | |
| 533 | void InstructionCodeGeneratorX86_64::VisitLocal(HLocal* local) { |
| 534 | DCHECK_EQ(local->GetBlock(), GetGraph()->GetEntryBlock()); |
| 535 | } |
| 536 | |
| 537 | void LocationsBuilderX86_64::VisitLoadLocal(HLoadLocal* local) { |
| 538 | local->SetLocations(nullptr); |
| 539 | } |
| 540 | |
| 541 | void InstructionCodeGeneratorX86_64::VisitLoadLocal(HLoadLocal* load) { |
| 542 | // Nothing to do, this is driven by the code generator. |
| 543 | } |
| 544 | |
| 545 | void LocationsBuilderX86_64::VisitStoreLocal(HStoreLocal* store) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 546 | LocationSummary* locations = |
| 547 | new (GetGraph()->GetArena()) LocationSummary(store, LocationSummary::kNoCall); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 548 | switch (store->InputAt(1)->GetType()) { |
| 549 | case Primitive::kPrimBoolean: |
| 550 | case Primitive::kPrimByte: |
| 551 | case Primitive::kPrimChar: |
| 552 | case Primitive::kPrimShort: |
| 553 | case Primitive::kPrimInt: |
| 554 | case Primitive::kPrimNot: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame^] | 555 | case Primitive::kPrimFloat: |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 556 | locations->SetInAt(1, Location::StackSlot(codegen_->GetStackSlot(store->GetLocal()))); |
| 557 | break; |
| 558 | |
| 559 | case Primitive::kPrimLong: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame^] | 560 | case Primitive::kPrimDouble: |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 561 | locations->SetInAt(1, Location::DoubleStackSlot(codegen_->GetStackSlot(store->GetLocal()))); |
| 562 | break; |
| 563 | |
| 564 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame^] | 565 | LOG(FATAL) << "Unexpected local type " << store->InputAt(1)->GetType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 566 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 567 | } |
| 568 | |
| 569 | void InstructionCodeGeneratorX86_64::VisitStoreLocal(HStoreLocal* store) { |
| 570 | } |
| 571 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 572 | void LocationsBuilderX86_64::VisitCondition(HCondition* comp) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 573 | LocationSummary* locations = |
| 574 | new (GetGraph()->GetArena()) LocationSummary(comp, LocationSummary::kNoCall); |
Nicolas Geoffray | 9ae0daa | 2014-09-30 22:40:23 +0100 | [diff] [blame] | 575 | locations->SetInAt(0, Location::RequiresRegister(), Location::kDiesAtEntry); |
| 576 | locations->SetInAt(1, Location::Any(), Location::kDiesAtEntry); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 577 | if (comp->NeedsMaterialization()) { |
| 578 | locations->SetOut(Location::RequiresRegister()); |
| 579 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 580 | } |
| 581 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 582 | void InstructionCodeGeneratorX86_64::VisitCondition(HCondition* comp) { |
| 583 | if (comp->NeedsMaterialization()) { |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 584 | LocationSummary* locations = comp->GetLocations(); |
Nicolas Geoffray | 18efde5 | 2014-09-22 15:51:11 +0100 | [diff] [blame] | 585 | CpuRegister reg = locations->Out().AsX86_64().AsCpuRegister(); |
| 586 | // Clear register: setcc only sets the low byte. |
| 587 | __ xorq(reg, reg); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 588 | if (locations->InAt(1).IsRegister()) { |
| 589 | __ cmpq(locations->InAt(0).AsX86_64().AsCpuRegister(), |
| 590 | locations->InAt(1).AsX86_64().AsCpuRegister()); |
| 591 | } else if (locations->InAt(1).IsConstant()) { |
| 592 | __ cmpq(locations->InAt(0).AsX86_64().AsCpuRegister(), |
| 593 | Immediate(locations->InAt(1).GetConstant()->AsIntConstant()->GetValue())); |
| 594 | } else { |
| 595 | __ cmpq(locations->InAt(0).AsX86_64().AsCpuRegister(), |
| 596 | Address(CpuRegister(RSP), locations->InAt(1).GetStackIndex())); |
| 597 | } |
Nicolas Geoffray | 18efde5 | 2014-09-22 15:51:11 +0100 | [diff] [blame] | 598 | __ setcc(X86_64Condition(comp->GetCondition()), reg); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 599 | } |
| 600 | } |
| 601 | |
| 602 | void LocationsBuilderX86_64::VisitEqual(HEqual* comp) { |
| 603 | VisitCondition(comp); |
| 604 | } |
| 605 | |
| 606 | void InstructionCodeGeneratorX86_64::VisitEqual(HEqual* comp) { |
| 607 | VisitCondition(comp); |
| 608 | } |
| 609 | |
| 610 | void LocationsBuilderX86_64::VisitNotEqual(HNotEqual* comp) { |
| 611 | VisitCondition(comp); |
| 612 | } |
| 613 | |
| 614 | void InstructionCodeGeneratorX86_64::VisitNotEqual(HNotEqual* comp) { |
| 615 | VisitCondition(comp); |
| 616 | } |
| 617 | |
| 618 | void LocationsBuilderX86_64::VisitLessThan(HLessThan* comp) { |
| 619 | VisitCondition(comp); |
| 620 | } |
| 621 | |
| 622 | void InstructionCodeGeneratorX86_64::VisitLessThan(HLessThan* comp) { |
| 623 | VisitCondition(comp); |
| 624 | } |
| 625 | |
| 626 | void LocationsBuilderX86_64::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
| 627 | VisitCondition(comp); |
| 628 | } |
| 629 | |
| 630 | void InstructionCodeGeneratorX86_64::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
| 631 | VisitCondition(comp); |
| 632 | } |
| 633 | |
| 634 | void LocationsBuilderX86_64::VisitGreaterThan(HGreaterThan* comp) { |
| 635 | VisitCondition(comp); |
| 636 | } |
| 637 | |
| 638 | void InstructionCodeGeneratorX86_64::VisitGreaterThan(HGreaterThan* comp) { |
| 639 | VisitCondition(comp); |
| 640 | } |
| 641 | |
| 642 | void LocationsBuilderX86_64::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
| 643 | VisitCondition(comp); |
| 644 | } |
| 645 | |
| 646 | void InstructionCodeGeneratorX86_64::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
| 647 | VisitCondition(comp); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 648 | } |
| 649 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 650 | void LocationsBuilderX86_64::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 651 | LocationSummary* locations = |
| 652 | new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall); |
Nicolas Geoffray | 9ae0daa | 2014-09-30 22:40:23 +0100 | [diff] [blame] | 653 | locations->SetInAt(0, Location::RequiresRegister(), Location::kDiesAtEntry); |
| 654 | locations->SetInAt(1, Location::RequiresRegister(), Location::kDiesAtEntry); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 655 | locations->SetOut(Location::RequiresRegister()); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 656 | } |
| 657 | |
| 658 | void InstructionCodeGeneratorX86_64::VisitCompare(HCompare* compare) { |
| 659 | Label greater, done; |
| 660 | LocationSummary* locations = compare->GetLocations(); |
| 661 | switch (compare->InputAt(0)->GetType()) { |
| 662 | case Primitive::kPrimLong: |
| 663 | __ cmpq(locations->InAt(0).AsX86_64().AsCpuRegister(), |
| 664 | locations->InAt(1).AsX86_64().AsCpuRegister()); |
| 665 | break; |
| 666 | default: |
| 667 | LOG(FATAL) << "Unimplemented compare type " << compare->InputAt(0)->GetType(); |
| 668 | } |
| 669 | |
| 670 | __ movl(locations->Out().AsX86_64().AsCpuRegister(), Immediate(0)); |
| 671 | __ j(kEqual, &done); |
| 672 | __ j(kGreater, &greater); |
| 673 | |
| 674 | __ movl(locations->Out().AsX86_64().AsCpuRegister(), Immediate(-1)); |
| 675 | __ jmp(&done); |
| 676 | |
| 677 | __ Bind(&greater); |
| 678 | __ movl(locations->Out().AsX86_64().AsCpuRegister(), Immediate(1)); |
| 679 | |
| 680 | __ Bind(&done); |
| 681 | } |
| 682 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 683 | void LocationsBuilderX86_64::VisitIntConstant(HIntConstant* constant) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 684 | LocationSummary* locations = |
| 685 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 686 | locations->SetOut(Location::ConstantLocation(constant)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 687 | } |
| 688 | |
| 689 | void InstructionCodeGeneratorX86_64::VisitIntConstant(HIntConstant* constant) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 690 | } |
| 691 | |
| 692 | void LocationsBuilderX86_64::VisitLongConstant(HLongConstant* constant) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 693 | LocationSummary* locations = |
| 694 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 695 | locations->SetOut(Location::ConstantLocation(constant)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 696 | } |
| 697 | |
| 698 | void InstructionCodeGeneratorX86_64::VisitLongConstant(HLongConstant* constant) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 699 | } |
| 700 | |
| 701 | void LocationsBuilderX86_64::VisitReturnVoid(HReturnVoid* ret) { |
| 702 | ret->SetLocations(nullptr); |
| 703 | } |
| 704 | |
| 705 | void InstructionCodeGeneratorX86_64::VisitReturnVoid(HReturnVoid* ret) { |
| 706 | codegen_->GenerateFrameExit(); |
| 707 | __ ret(); |
| 708 | } |
| 709 | |
| 710 | void LocationsBuilderX86_64::VisitReturn(HReturn* ret) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 711 | LocationSummary* locations = |
| 712 | new (GetGraph()->GetArena()) LocationSummary(ret, LocationSummary::kNoCall); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 713 | switch (ret->InputAt(0)->GetType()) { |
| 714 | case Primitive::kPrimBoolean: |
| 715 | case Primitive::kPrimByte: |
| 716 | case Primitive::kPrimChar: |
| 717 | case Primitive::kPrimShort: |
| 718 | case Primitive::kPrimInt: |
| 719 | case Primitive::kPrimNot: |
| 720 | case Primitive::kPrimLong: |
| 721 | locations->SetInAt(0, X86_64CpuLocation(RAX)); |
| 722 | break; |
| 723 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame^] | 724 | case Primitive::kPrimFloat: |
| 725 | case Primitive::kPrimDouble: |
| 726 | locations->SetInAt(0, |
| 727 | Location::FpuRegisterLocation(X86_64ManagedRegister::FromXmmRegister(XMM0))); |
| 728 | break; |
| 729 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 730 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame^] | 731 | LOG(FATAL) << "Unexpected return type " << ret->InputAt(0)->GetType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 732 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 733 | } |
| 734 | |
| 735 | void InstructionCodeGeneratorX86_64::VisitReturn(HReturn* ret) { |
| 736 | if (kIsDebugBuild) { |
| 737 | switch (ret->InputAt(0)->GetType()) { |
| 738 | case Primitive::kPrimBoolean: |
| 739 | case Primitive::kPrimByte: |
| 740 | case Primitive::kPrimChar: |
| 741 | case Primitive::kPrimShort: |
| 742 | case Primitive::kPrimInt: |
| 743 | case Primitive::kPrimNot: |
| 744 | case Primitive::kPrimLong: |
| 745 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsX86_64().AsCpuRegister().AsRegister(), RAX); |
| 746 | break; |
| 747 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame^] | 748 | case Primitive::kPrimFloat: |
| 749 | case Primitive::kPrimDouble: |
| 750 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsX86_64().AsXmmRegister().AsFloatRegister(), |
| 751 | XMM0); |
| 752 | break; |
| 753 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 754 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame^] | 755 | LOG(FATAL) << "Unexpected return type " << ret->InputAt(0)->GetType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 756 | } |
| 757 | } |
| 758 | codegen_->GenerateFrameExit(); |
| 759 | __ ret(); |
| 760 | } |
| 761 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 762 | Location InvokeDexCallingConventionVisitor::GetNextLocation(Primitive::Type type) { |
| 763 | switch (type) { |
| 764 | case Primitive::kPrimBoolean: |
| 765 | case Primitive::kPrimByte: |
| 766 | case Primitive::kPrimChar: |
| 767 | case Primitive::kPrimShort: |
| 768 | case Primitive::kPrimInt: |
| 769 | case Primitive::kPrimNot: { |
| 770 | uint32_t index = gp_index_++; |
| 771 | stack_index_++; |
| 772 | if (index < calling_convention.GetNumberOfRegisters()) { |
| 773 | return X86_64CpuLocation(calling_convention.GetRegisterAt(index)); |
| 774 | } else { |
| 775 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 1)); |
| 776 | } |
| 777 | } |
| 778 | |
| 779 | case Primitive::kPrimLong: { |
| 780 | uint32_t index = gp_index_; |
| 781 | stack_index_ += 2; |
| 782 | if (index < calling_convention.GetNumberOfRegisters()) { |
| 783 | gp_index_ += 1; |
| 784 | return X86_64CpuLocation(calling_convention.GetRegisterAt(index)); |
| 785 | } else { |
| 786 | gp_index_ += 2; |
| 787 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 2)); |
| 788 | } |
| 789 | } |
| 790 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame^] | 791 | case Primitive::kPrimFloat: { |
| 792 | uint32_t index = fp_index_++; |
| 793 | stack_index_++; |
| 794 | if (index < calling_convention.GetNumberOfFpuRegisters()) { |
| 795 | return Location::FpuRegisterLocation(X86_64ManagedRegister::FromXmmRegister( |
| 796 | calling_convention.GetFpuRegisterAt(index))); |
| 797 | } else { |
| 798 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 1)); |
| 799 | } |
| 800 | } |
| 801 | |
| 802 | case Primitive::kPrimDouble: { |
| 803 | uint32_t index = fp_index_++; |
| 804 | stack_index_ += 2; |
| 805 | if (index < calling_convention.GetNumberOfFpuRegisters()) { |
| 806 | return Location::FpuRegisterLocation(X86_64ManagedRegister::FromXmmRegister( |
| 807 | calling_convention.GetFpuRegisterAt(index))); |
| 808 | } else { |
| 809 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 2)); |
| 810 | } |
| 811 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 812 | |
| 813 | case Primitive::kPrimVoid: |
| 814 | LOG(FATAL) << "Unexpected parameter type " << type; |
| 815 | break; |
| 816 | } |
| 817 | return Location(); |
| 818 | } |
| 819 | |
| 820 | void LocationsBuilderX86_64::VisitInvokeStatic(HInvokeStatic* invoke) { |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 821 | HandleInvoke(invoke); |
| 822 | } |
| 823 | |
| 824 | void InstructionCodeGeneratorX86_64::VisitInvokeStatic(HInvokeStatic* invoke) { |
| 825 | CpuRegister temp = invoke->GetLocations()->GetTemp(0).AsX86_64().AsCpuRegister(); |
| 826 | uint32_t heap_reference_size = sizeof(mirror::HeapReference<mirror::Object>); |
| 827 | size_t index_in_cache = mirror::Array::DataOffset(heap_reference_size).SizeValue() + |
| 828 | invoke->GetIndexInDexCache() * heap_reference_size; |
| 829 | |
| 830 | // TODO: Implement all kinds of calls: |
| 831 | // 1) boot -> boot |
| 832 | // 2) app -> boot |
| 833 | // 3) app -> app |
| 834 | // |
| 835 | // Currently we implement the app -> app logic, which looks up in the resolve cache. |
| 836 | |
| 837 | // temp = method; |
| 838 | LoadCurrentMethod(temp); |
| 839 | // temp = temp->dex_cache_resolved_methods_; |
| 840 | __ movl(temp, Address(temp, mirror::ArtMethod::DexCacheResolvedMethodsOffset().SizeValue())); |
| 841 | // temp = temp[index_in_cache] |
| 842 | __ movl(temp, Address(temp, index_in_cache)); |
| 843 | // (temp + offset_of_quick_compiled_code)() |
| 844 | __ call(Address(temp, mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset().SizeValue())); |
| 845 | |
| 846 | DCHECK(!codegen_->IsLeafMethod()); |
| 847 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 848 | } |
| 849 | |
| 850 | void LocationsBuilderX86_64::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
| 851 | HandleInvoke(invoke); |
| 852 | } |
| 853 | |
| 854 | void LocationsBuilderX86_64::HandleInvoke(HInvoke* invoke) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 855 | LocationSummary* locations = |
| 856 | new (GetGraph()->GetArena()) LocationSummary(invoke, LocationSummary::kCall); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 857 | locations->AddTemp(X86_64CpuLocation(RDI)); |
| 858 | |
| 859 | InvokeDexCallingConventionVisitor calling_convention_visitor; |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 860 | for (size_t i = 0; i < invoke->InputCount(); i++) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 861 | HInstruction* input = invoke->InputAt(i); |
| 862 | locations->SetInAt(i, calling_convention_visitor.GetNextLocation(input->GetType())); |
| 863 | } |
| 864 | |
| 865 | switch (invoke->GetType()) { |
| 866 | case Primitive::kPrimBoolean: |
| 867 | case Primitive::kPrimByte: |
| 868 | case Primitive::kPrimChar: |
| 869 | case Primitive::kPrimShort: |
| 870 | case Primitive::kPrimInt: |
| 871 | case Primitive::kPrimNot: |
| 872 | case Primitive::kPrimLong: |
| 873 | locations->SetOut(X86_64CpuLocation(RAX)); |
| 874 | break; |
| 875 | |
| 876 | case Primitive::kPrimVoid: |
| 877 | break; |
| 878 | |
| 879 | case Primitive::kPrimDouble: |
| 880 | case Primitive::kPrimFloat: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame^] | 881 | locations->SetOut( |
| 882 | Location::FpuRegisterLocation(X86_64ManagedRegister::FromXmmRegister(XMM0))); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 883 | break; |
| 884 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 885 | } |
| 886 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 887 | void InstructionCodeGeneratorX86_64::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 888 | CpuRegister temp = invoke->GetLocations()->GetTemp(0).AsX86_64().AsCpuRegister(); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 889 | size_t method_offset = mirror::Class::EmbeddedVTableOffset().SizeValue() + |
| 890 | invoke->GetVTableIndex() * sizeof(mirror::Class::VTableEntry); |
| 891 | LocationSummary* locations = invoke->GetLocations(); |
| 892 | Location receiver = locations->InAt(0); |
| 893 | size_t class_offset = mirror::Object::ClassOffset().SizeValue(); |
| 894 | // temp = object->GetClass(); |
| 895 | if (receiver.IsStackSlot()) { |
| 896 | __ movq(temp, Address(CpuRegister(RSP), receiver.GetStackIndex())); |
| 897 | __ movq(temp, Address(temp, class_offset)); |
| 898 | } else { |
| 899 | __ movq(temp, Address(receiver.AsX86_64().AsCpuRegister(), class_offset)); |
| 900 | } |
| 901 | // temp = temp->GetMethodAt(method_offset); |
| 902 | __ movl(temp, Address(temp, method_offset)); |
| 903 | // call temp->GetEntryPoint(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 904 | __ call(Address(temp, mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset().SizeValue())); |
| 905 | |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 906 | DCHECK(!codegen_->IsLeafMethod()); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 907 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 908 | } |
| 909 | |
| 910 | void LocationsBuilderX86_64::VisitAdd(HAdd* add) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 911 | LocationSummary* locations = |
| 912 | new (GetGraph()->GetArena()) LocationSummary(add, LocationSummary::kNoCall); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 913 | switch (add->GetResultType()) { |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 914 | case Primitive::kPrimInt: { |
| 915 | locations->SetInAt(0, Location::RequiresRegister()); |
| 916 | locations->SetInAt(1, Location::Any()); |
| 917 | locations->SetOut(Location::SameAsFirstInput()); |
| 918 | break; |
| 919 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame^] | 920 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 921 | case Primitive::kPrimLong: { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 922 | locations->SetInAt(0, Location::RequiresRegister()); |
| 923 | locations->SetInAt(1, Location::RequiresRegister()); |
| 924 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 925 | break; |
| 926 | } |
| 927 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame^] | 928 | case Primitive::kPrimDouble: |
| 929 | case Primitive::kPrimFloat: { |
| 930 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 931 | locations->SetInAt(1, Location::Any()); |
| 932 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 933 | break; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame^] | 934 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 935 | |
| 936 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame^] | 937 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 938 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 939 | } |
| 940 | |
| 941 | void InstructionCodeGeneratorX86_64::VisitAdd(HAdd* add) { |
| 942 | LocationSummary* locations = add->GetLocations(); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame^] | 943 | Location first = locations->InAt(0); |
| 944 | Location second = locations->InAt(1); |
| 945 | |
| 946 | DCHECK(first.Equals(locations->Out())); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 947 | switch (add->GetResultType()) { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 948 | case Primitive::kPrimInt: { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame^] | 949 | if (second.IsRegister()) { |
| 950 | __ addl(first.AsX86_64().AsCpuRegister(), second.AsX86_64().AsCpuRegister()); |
| 951 | } else if (second.IsConstant()) { |
| 952 | HConstant* instruction = second.GetConstant(); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 953 | Immediate imm(instruction->AsIntConstant()->GetValue()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame^] | 954 | __ addl(first.AsX86_64().AsCpuRegister(), imm); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 955 | } else { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame^] | 956 | __ addl(first.AsX86_64().AsCpuRegister(), |
| 957 | Address(CpuRegister(RSP), second.GetStackIndex())); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 958 | } |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 959 | break; |
| 960 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame^] | 961 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 962 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame^] | 963 | __ addq(first.AsX86_64().AsCpuRegister(), second.AsX86_64().AsCpuRegister()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 964 | break; |
| 965 | } |
| 966 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame^] | 967 | case Primitive::kPrimFloat: { |
| 968 | if (second.IsFpuRegister()) { |
| 969 | __ addss(first.AsX86_64().AsXmmRegister(), second.AsX86_64().AsXmmRegister()); |
| 970 | } else { |
| 971 | __ addss(first.AsX86_64().AsXmmRegister(), |
| 972 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 973 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 974 | break; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame^] | 975 | } |
| 976 | |
| 977 | case Primitive::kPrimDouble: { |
| 978 | if (second.IsFpuRegister()) { |
| 979 | __ addsd(first.AsX86_64().AsXmmRegister(), second.AsX86_64().AsXmmRegister()); |
| 980 | } else { |
| 981 | __ addsd(first.AsX86_64().AsXmmRegister(), |
| 982 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 983 | } |
| 984 | break; |
| 985 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 986 | |
| 987 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame^] | 988 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 989 | } |
| 990 | } |
| 991 | |
| 992 | void LocationsBuilderX86_64::VisitSub(HSub* sub) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 993 | LocationSummary* locations = |
| 994 | new (GetGraph()->GetArena()) LocationSummary(sub, LocationSummary::kNoCall); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 995 | switch (sub->GetResultType()) { |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 996 | case Primitive::kPrimInt: { |
| 997 | locations->SetInAt(0, Location::RequiresRegister()); |
| 998 | locations->SetInAt(1, Location::Any()); |
| 999 | locations->SetOut(Location::SameAsFirstInput()); |
| 1000 | break; |
| 1001 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1002 | case Primitive::kPrimLong: { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 1003 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1004 | locations->SetInAt(1, Location::RequiresRegister()); |
| 1005 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1006 | break; |
| 1007 | } |
| 1008 | |
| 1009 | case Primitive::kPrimBoolean: |
| 1010 | case Primitive::kPrimByte: |
| 1011 | case Primitive::kPrimChar: |
| 1012 | case Primitive::kPrimShort: |
| 1013 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
| 1014 | break; |
| 1015 | |
| 1016 | default: |
| 1017 | LOG(FATAL) << "Unimplemented sub type " << sub->GetResultType(); |
| 1018 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1019 | } |
| 1020 | |
| 1021 | void InstructionCodeGeneratorX86_64::VisitSub(HSub* sub) { |
| 1022 | LocationSummary* locations = sub->GetLocations(); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 1023 | DCHECK_EQ(locations->InAt(0).AsX86_64().AsCpuRegister().AsRegister(), |
| 1024 | locations->Out().AsX86_64().AsCpuRegister().AsRegister()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1025 | switch (sub->GetResultType()) { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 1026 | case Primitive::kPrimInt: { |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1027 | if (locations->InAt(1).IsRegister()) { |
| 1028 | __ subl(locations->InAt(0).AsX86_64().AsCpuRegister(), |
| 1029 | locations->InAt(1).AsX86_64().AsCpuRegister()); |
| 1030 | } else if (locations->InAt(1).IsConstant()) { |
| 1031 | HConstant* instruction = locations->InAt(1).GetConstant(); |
| 1032 | Immediate imm(instruction->AsIntConstant()->GetValue()); |
| 1033 | __ subl(locations->InAt(0).AsX86_64().AsCpuRegister(), imm); |
| 1034 | } else { |
| 1035 | __ subl(locations->InAt(0).AsX86_64().AsCpuRegister(), |
| 1036 | Address(CpuRegister(RSP), locations->InAt(1).GetStackIndex())); |
| 1037 | } |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 1038 | break; |
| 1039 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1040 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1041 | __ subq(locations->InAt(0).AsX86_64().AsCpuRegister(), |
| 1042 | locations->InAt(1).AsX86_64().AsCpuRegister()); |
| 1043 | break; |
| 1044 | } |
| 1045 | |
| 1046 | case Primitive::kPrimBoolean: |
| 1047 | case Primitive::kPrimByte: |
| 1048 | case Primitive::kPrimChar: |
| 1049 | case Primitive::kPrimShort: |
| 1050 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
| 1051 | break; |
| 1052 | |
| 1053 | default: |
| 1054 | LOG(FATAL) << "Unimplemented sub type " << sub->GetResultType(); |
| 1055 | } |
| 1056 | } |
| 1057 | |
| 1058 | void LocationsBuilderX86_64::VisitNewInstance(HNewInstance* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1059 | LocationSummary* locations = |
| 1060 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
Nicolas Geoffray | 9ae0daa | 2014-09-30 22:40:23 +0100 | [diff] [blame] | 1061 | InvokeRuntimeCallingConvention calling_convention; |
| 1062 | locations->AddTemp(X86_64CpuLocation(calling_convention.GetRegisterAt(0))); |
| 1063 | locations->AddTemp(X86_64CpuLocation(calling_convention.GetRegisterAt(1))); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1064 | locations->SetOut(X86_64CpuLocation(RAX)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1065 | } |
| 1066 | |
| 1067 | void InstructionCodeGeneratorX86_64::VisitNewInstance(HNewInstance* instruction) { |
| 1068 | InvokeRuntimeCallingConvention calling_convention; |
| 1069 | LoadCurrentMethod(CpuRegister(calling_convention.GetRegisterAt(1))); |
| 1070 | __ movq(CpuRegister(calling_convention.GetRegisterAt(0)), Immediate(instruction->GetTypeIndex())); |
| 1071 | |
| 1072 | __ gs()->call(Address::Absolute( |
| 1073 | QUICK_ENTRYPOINT_OFFSET(kX86_64WordSize, pAllocObjectWithAccessCheck), true)); |
| 1074 | |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 1075 | DCHECK(!codegen_->IsLeafMethod()); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1076 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1077 | } |
| 1078 | |
| 1079 | void LocationsBuilderX86_64::VisitParameterValue(HParameterValue* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1080 | LocationSummary* locations = |
| 1081 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1082 | Location location = parameter_visitor_.GetNextLocation(instruction->GetType()); |
| 1083 | if (location.IsStackSlot()) { |
| 1084 | location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 1085 | } else if (location.IsDoubleStackSlot()) { |
| 1086 | location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 1087 | } |
| 1088 | locations->SetOut(location); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1089 | } |
| 1090 | |
| 1091 | void InstructionCodeGeneratorX86_64::VisitParameterValue(HParameterValue* instruction) { |
| 1092 | // Nothing to do, the parameter is already at its location. |
| 1093 | } |
| 1094 | |
| 1095 | void LocationsBuilderX86_64::VisitNot(HNot* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1096 | LocationSummary* locations = |
| 1097 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 1098 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1099 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1100 | } |
| 1101 | |
| 1102 | void InstructionCodeGeneratorX86_64::VisitNot(HNot* instruction) { |
| 1103 | LocationSummary* locations = instruction->GetLocations(); |
| 1104 | DCHECK_EQ(locations->InAt(0).AsX86_64().AsCpuRegister().AsRegister(), |
| 1105 | locations->Out().AsX86_64().AsCpuRegister().AsRegister()); |
| 1106 | __ xorq(locations->Out().AsX86_64().AsCpuRegister(), Immediate(1)); |
| 1107 | } |
| 1108 | |
| 1109 | void LocationsBuilderX86_64::VisitPhi(HPhi* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1110 | LocationSummary* locations = |
| 1111 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1112 | for (size_t i = 0, e = instruction->InputCount(); i < e; ++i) { |
| 1113 | locations->SetInAt(i, Location::Any()); |
| 1114 | } |
| 1115 | locations->SetOut(Location::Any()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1116 | } |
| 1117 | |
| 1118 | void InstructionCodeGeneratorX86_64::VisitPhi(HPhi* instruction) { |
| 1119 | LOG(FATAL) << "Unimplemented"; |
| 1120 | } |
| 1121 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1122 | void LocationsBuilderX86_64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1123 | LocationSummary* locations = |
| 1124 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 9ae0daa | 2014-09-30 22:40:23 +0100 | [diff] [blame] | 1125 | Primitive::Type field_type = instruction->GetFieldType(); |
| 1126 | bool is_object_type = field_type == Primitive::kPrimNot; |
| 1127 | bool dies_at_entry = !is_object_type; |
| 1128 | locations->SetInAt(0, Location::RequiresRegister(), dies_at_entry); |
| 1129 | locations->SetInAt(1, Location::RequiresRegister(), dies_at_entry); |
| 1130 | if (is_object_type) { |
| 1131 | // Temporary registers for the write barrier. |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 1132 | locations->AddTemp(Location::RequiresRegister()); |
| 1133 | locations->AddTemp(Location::RequiresRegister()); |
| 1134 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1135 | } |
| 1136 | |
| 1137 | void InstructionCodeGeneratorX86_64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
| 1138 | LocationSummary* locations = instruction->GetLocations(); |
| 1139 | CpuRegister obj = locations->InAt(0).AsX86_64().AsCpuRegister(); |
| 1140 | CpuRegister value = locations->InAt(1).AsX86_64().AsCpuRegister(); |
| 1141 | size_t offset = instruction->GetFieldOffset().SizeValue(); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1142 | Primitive::Type field_type = instruction->GetFieldType(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1143 | |
| 1144 | switch (field_type) { |
| 1145 | case Primitive::kPrimBoolean: |
| 1146 | case Primitive::kPrimByte: { |
| 1147 | __ movb(Address(obj, offset), value); |
| 1148 | break; |
| 1149 | } |
| 1150 | |
| 1151 | case Primitive::kPrimShort: |
| 1152 | case Primitive::kPrimChar: { |
| 1153 | __ movw(Address(obj, offset), value); |
| 1154 | break; |
| 1155 | } |
| 1156 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1157 | case Primitive::kPrimInt: |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1158 | case Primitive::kPrimNot: { |
| 1159 | __ movl(Address(obj, offset), value); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1160 | if (field_type == Primitive::kPrimNot) { |
| 1161 | CpuRegister temp = locations->GetTemp(0).AsX86_64().AsCpuRegister(); |
| 1162 | CpuRegister card = locations->GetTemp(1).AsX86_64().AsCpuRegister(); |
| 1163 | codegen_->MarkGCCard(temp, card, obj, value); |
| 1164 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1165 | break; |
| 1166 | } |
| 1167 | |
| 1168 | case Primitive::kPrimLong: { |
| 1169 | __ movq(Address(obj, offset), value); |
| 1170 | break; |
| 1171 | } |
| 1172 | |
| 1173 | case Primitive::kPrimFloat: |
| 1174 | case Primitive::kPrimDouble: |
| 1175 | LOG(FATAL) << "Unimplemented register type " << field_type; |
| 1176 | |
| 1177 | case Primitive::kPrimVoid: |
| 1178 | LOG(FATAL) << "Unreachable type " << field_type; |
| 1179 | } |
| 1180 | } |
| 1181 | |
| 1182 | void LocationsBuilderX86_64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1183 | LocationSummary* locations = |
| 1184 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 9ae0daa | 2014-09-30 22:40:23 +0100 | [diff] [blame] | 1185 | locations->SetInAt(0, Location::RequiresRegister(), Location::kDiesAtEntry); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1186 | locations->SetOut(Location::RequiresRegister()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1187 | } |
| 1188 | |
| 1189 | void InstructionCodeGeneratorX86_64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 1190 | LocationSummary* locations = instruction->GetLocations(); |
| 1191 | CpuRegister obj = locations->InAt(0).AsX86_64().AsCpuRegister(); |
| 1192 | CpuRegister out = locations->Out().AsX86_64().AsCpuRegister(); |
| 1193 | size_t offset = instruction->GetFieldOffset().SizeValue(); |
| 1194 | |
| 1195 | switch (instruction->GetType()) { |
| 1196 | case Primitive::kPrimBoolean: { |
| 1197 | __ movzxb(out, Address(obj, offset)); |
| 1198 | break; |
| 1199 | } |
| 1200 | |
| 1201 | case Primitive::kPrimByte: { |
| 1202 | __ movsxb(out, Address(obj, offset)); |
| 1203 | break; |
| 1204 | } |
| 1205 | |
| 1206 | case Primitive::kPrimShort: { |
| 1207 | __ movsxw(out, Address(obj, offset)); |
| 1208 | break; |
| 1209 | } |
| 1210 | |
| 1211 | case Primitive::kPrimChar: { |
| 1212 | __ movzxw(out, Address(obj, offset)); |
| 1213 | break; |
| 1214 | } |
| 1215 | |
| 1216 | case Primitive::kPrimInt: |
| 1217 | case Primitive::kPrimNot: { |
| 1218 | __ movl(out, Address(obj, offset)); |
| 1219 | break; |
| 1220 | } |
| 1221 | |
| 1222 | case Primitive::kPrimLong: { |
| 1223 | __ movq(out, Address(obj, offset)); |
| 1224 | break; |
| 1225 | } |
| 1226 | |
| 1227 | case Primitive::kPrimFloat: |
| 1228 | case Primitive::kPrimDouble: |
| 1229 | LOG(FATAL) << "Unimplemented register type " << instruction->GetType(); |
| 1230 | |
| 1231 | case Primitive::kPrimVoid: |
| 1232 | LOG(FATAL) << "Unreachable type " << instruction->GetType(); |
| 1233 | } |
| 1234 | } |
| 1235 | |
| 1236 | void LocationsBuilderX86_64::VisitNullCheck(HNullCheck* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1237 | LocationSummary* locations = |
| 1238 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1239 | locations->SetInAt(0, Location::Any()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 1240 | if (instruction->HasUses()) { |
| 1241 | locations->SetOut(Location::SameAsFirstInput()); |
| 1242 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1243 | } |
| 1244 | |
| 1245 | void InstructionCodeGeneratorX86_64::VisitNullCheck(HNullCheck* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1246 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathX86_64(instruction); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1247 | codegen_->AddSlowPath(slow_path); |
| 1248 | |
| 1249 | LocationSummary* locations = instruction->GetLocations(); |
| 1250 | Location obj = locations->InAt(0); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1251 | |
| 1252 | if (obj.IsRegister()) { |
| 1253 | __ cmpl(obj.AsX86_64().AsCpuRegister(), Immediate(0)); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 1254 | } else if (obj.IsStackSlot()) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1255 | __ cmpl(Address(CpuRegister(RSP), obj.GetStackIndex()), Immediate(0)); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 1256 | } else { |
| 1257 | DCHECK(obj.IsConstant()) << obj; |
| 1258 | DCHECK_EQ(obj.GetConstant()->AsIntConstant()->GetValue(), 0); |
| 1259 | __ jmp(slow_path->GetEntryLabel()); |
| 1260 | return; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1261 | } |
| 1262 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 1263 | } |
| 1264 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1265 | void LocationsBuilderX86_64::VisitArrayGet(HArrayGet* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1266 | LocationSummary* locations = |
| 1267 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 9ae0daa | 2014-09-30 22:40:23 +0100 | [diff] [blame] | 1268 | locations->SetInAt(0, Location::RequiresRegister(), Location::kDiesAtEntry); |
| 1269 | locations->SetInAt( |
| 1270 | 1, Location::RegisterOrConstant(instruction->InputAt(1)), Location::kDiesAtEntry); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1271 | locations->SetOut(Location::RequiresRegister()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1272 | } |
| 1273 | |
| 1274 | void InstructionCodeGeneratorX86_64::VisitArrayGet(HArrayGet* instruction) { |
| 1275 | LocationSummary* locations = instruction->GetLocations(); |
| 1276 | CpuRegister obj = locations->InAt(0).AsX86_64().AsCpuRegister(); |
| 1277 | Location index = locations->InAt(1); |
| 1278 | |
| 1279 | switch (instruction->GetType()) { |
| 1280 | case Primitive::kPrimBoolean: { |
| 1281 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value(); |
| 1282 | CpuRegister out = locations->Out().AsX86_64().AsCpuRegister(); |
| 1283 | if (index.IsConstant()) { |
| 1284 | __ movzxb(out, Address(obj, |
| 1285 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset)); |
| 1286 | } else { |
| 1287 | __ movzxb(out, Address(obj, index.AsX86_64().AsCpuRegister(), TIMES_1, data_offset)); |
| 1288 | } |
| 1289 | break; |
| 1290 | } |
| 1291 | |
| 1292 | case Primitive::kPrimByte: { |
| 1293 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int8_t)).Uint32Value(); |
| 1294 | CpuRegister out = locations->Out().AsX86_64().AsCpuRegister(); |
| 1295 | if (index.IsConstant()) { |
| 1296 | __ movsxb(out, Address(obj, |
| 1297 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset)); |
| 1298 | } else { |
| 1299 | __ movsxb(out, Address(obj, index.AsX86_64().AsCpuRegister(), TIMES_1, data_offset)); |
| 1300 | } |
| 1301 | break; |
| 1302 | } |
| 1303 | |
| 1304 | case Primitive::kPrimShort: { |
| 1305 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int16_t)).Uint32Value(); |
| 1306 | CpuRegister out = locations->Out().AsX86_64().AsCpuRegister(); |
| 1307 | if (index.IsConstant()) { |
| 1308 | __ movsxw(out, Address(obj, |
| 1309 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset)); |
| 1310 | } else { |
| 1311 | __ movsxw(out, Address(obj, index.AsX86_64().AsCpuRegister(), TIMES_2, data_offset)); |
| 1312 | } |
| 1313 | break; |
| 1314 | } |
| 1315 | |
| 1316 | case Primitive::kPrimChar: { |
| 1317 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value(); |
| 1318 | CpuRegister out = locations->Out().AsX86_64().AsCpuRegister(); |
| 1319 | if (index.IsConstant()) { |
| 1320 | __ movzxw(out, Address(obj, |
| 1321 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset)); |
| 1322 | } else { |
| 1323 | __ movzxw(out, Address(obj, index.AsX86_64().AsCpuRegister(), TIMES_2, data_offset)); |
| 1324 | } |
| 1325 | break; |
| 1326 | } |
| 1327 | |
| 1328 | case Primitive::kPrimInt: |
| 1329 | case Primitive::kPrimNot: { |
| 1330 | DCHECK_EQ(sizeof(mirror::HeapReference<mirror::Object>), sizeof(int32_t)); |
| 1331 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
| 1332 | CpuRegister out = locations->Out().AsX86_64().AsCpuRegister(); |
| 1333 | if (index.IsConstant()) { |
| 1334 | __ movl(out, Address(obj, |
| 1335 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset)); |
| 1336 | } else { |
| 1337 | __ movl(out, Address(obj, index.AsX86_64().AsCpuRegister(), TIMES_4, data_offset)); |
| 1338 | } |
| 1339 | break; |
| 1340 | } |
| 1341 | |
| 1342 | case Primitive::kPrimLong: { |
| 1343 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value(); |
| 1344 | CpuRegister out = locations->Out().AsX86_64().AsCpuRegister(); |
| 1345 | if (index.IsConstant()) { |
| 1346 | __ movq(out, Address(obj, |
| 1347 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset)); |
| 1348 | } else { |
| 1349 | __ movq(out, Address(obj, index.AsX86_64().AsCpuRegister(), TIMES_8, data_offset)); |
| 1350 | } |
| 1351 | break; |
| 1352 | } |
| 1353 | |
| 1354 | case Primitive::kPrimFloat: |
| 1355 | case Primitive::kPrimDouble: |
| 1356 | LOG(FATAL) << "Unimplemented register type " << instruction->GetType(); |
| 1357 | |
| 1358 | case Primitive::kPrimVoid: |
| 1359 | LOG(FATAL) << "Unreachable type " << instruction->GetType(); |
| 1360 | } |
| 1361 | } |
| 1362 | |
| 1363 | void LocationsBuilderX86_64::VisitArraySet(HArraySet* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1364 | Primitive::Type value_type = instruction->GetComponentType(); |
| 1365 | bool is_object = value_type == Primitive::kPrimNot; |
| 1366 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary( |
| 1367 | instruction, is_object ? LocationSummary::kCall : LocationSummary::kNoCall); |
| 1368 | if (is_object) { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1369 | InvokeRuntimeCallingConvention calling_convention; |
| 1370 | locations->SetInAt(0, X86_64CpuLocation(calling_convention.GetRegisterAt(0))); |
| 1371 | locations->SetInAt(1, X86_64CpuLocation(calling_convention.GetRegisterAt(1))); |
| 1372 | locations->SetInAt(2, X86_64CpuLocation(calling_convention.GetRegisterAt(2))); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1373 | } else { |
Nicolas Geoffray | 9ae0daa | 2014-09-30 22:40:23 +0100 | [diff] [blame] | 1374 | locations->SetInAt(0, Location::RequiresRegister(), Location::kDiesAtEntry); |
| 1375 | locations->SetInAt( |
| 1376 | 1, Location::RegisterOrConstant(instruction->InputAt(1)), Location::kDiesAtEntry); |
| 1377 | locations->SetInAt(2, Location::RequiresRegister(), Location::kDiesAtEntry); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 1378 | if (value_type == Primitive::kPrimLong) { |
| 1379 | locations->SetInAt(2, Location::RequiresRegister(), Location::kDiesAtEntry); |
| 1380 | } else { |
| 1381 | locations->SetInAt(2, Location::RegisterOrConstant(instruction->InputAt(2)), Location::kDiesAtEntry); |
| 1382 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1383 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1384 | } |
| 1385 | |
| 1386 | void InstructionCodeGeneratorX86_64::VisitArraySet(HArraySet* instruction) { |
| 1387 | LocationSummary* locations = instruction->GetLocations(); |
| 1388 | CpuRegister obj = locations->InAt(0).AsX86_64().AsCpuRegister(); |
| 1389 | Location index = locations->InAt(1); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 1390 | Location value = locations->InAt(2); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1391 | Primitive::Type value_type = instruction->GetComponentType(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1392 | |
| 1393 | switch (value_type) { |
| 1394 | case Primitive::kPrimBoolean: |
| 1395 | case Primitive::kPrimByte: { |
| 1396 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1397 | if (index.IsConstant()) { |
| 1398 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset; |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 1399 | if (value.IsRegister()) { |
| 1400 | __ movb(Address(obj, offset), value.AsX86_64().AsCpuRegister()); |
| 1401 | } else { |
| 1402 | __ movb(Address(obj, offset), Immediate(value.GetConstant()->AsIntConstant()->GetValue())); |
| 1403 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1404 | } else { |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 1405 | if (value.IsRegister()) { |
| 1406 | __ movb(Address(obj, index.AsX86_64().AsCpuRegister(), TIMES_1, data_offset), |
| 1407 | value.AsX86_64().AsCpuRegister()); |
| 1408 | } else { |
| 1409 | __ movb(Address(obj, index.AsX86_64().AsCpuRegister(), TIMES_1, data_offset), |
| 1410 | Immediate(value.GetConstant()->AsIntConstant()->GetValue())); |
| 1411 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1412 | } |
| 1413 | break; |
| 1414 | } |
| 1415 | |
| 1416 | case Primitive::kPrimShort: |
| 1417 | case Primitive::kPrimChar: { |
| 1418 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1419 | if (index.IsConstant()) { |
| 1420 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset; |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 1421 | if (value.IsRegister()) { |
| 1422 | __ movw(Address(obj, offset), value.AsX86_64().AsCpuRegister()); |
| 1423 | } else { |
| 1424 | __ movw(Address(obj, offset), Immediate(value.GetConstant()->AsIntConstant()->GetValue())); |
| 1425 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1426 | } else { |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 1427 | if (value.IsRegister()) { |
| 1428 | __ movw(Address(obj, index.AsX86_64().AsCpuRegister(), TIMES_2, data_offset), |
| 1429 | value.AsX86_64().AsCpuRegister()); |
| 1430 | } else { |
| 1431 | __ movw(Address(obj, index.AsX86_64().AsCpuRegister(), TIMES_2, data_offset), |
| 1432 | Immediate(value.GetConstant()->AsIntConstant()->GetValue())); |
| 1433 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1434 | } |
| 1435 | break; |
| 1436 | } |
| 1437 | |
| 1438 | case Primitive::kPrimInt: { |
| 1439 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1440 | if (index.IsConstant()) { |
| 1441 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 1442 | if (value.IsRegister()) { |
| 1443 | __ movl(Address(obj, offset), value.AsX86_64().AsCpuRegister()); |
| 1444 | } else { |
| 1445 | __ movl(Address(obj, offset), Immediate(value.GetConstant()->AsIntConstant()->GetValue())); |
| 1446 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1447 | } else { |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 1448 | if (value.IsRegister()) { |
| 1449 | __ movl(Address(obj, index.AsX86_64().AsCpuRegister(), TIMES_4, data_offset), |
| 1450 | value.AsX86_64().AsCpuRegister()); |
| 1451 | } else { |
| 1452 | __ movl(Address(obj, index.AsX86_64().AsCpuRegister(), TIMES_4, data_offset), |
| 1453 | Immediate(value.GetConstant()->AsIntConstant()->GetValue())); |
| 1454 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1455 | } |
| 1456 | break; |
| 1457 | } |
| 1458 | |
| 1459 | case Primitive::kPrimNot: { |
| 1460 | __ gs()->call(Address::Absolute(QUICK_ENTRYPOINT_OFFSET(kX86_64WordSize, pAputObject), true)); |
| 1461 | DCHECK(!codegen_->IsLeafMethod()); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1462 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1463 | break; |
| 1464 | } |
| 1465 | |
| 1466 | case Primitive::kPrimLong: { |
| 1467 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1468 | if (index.IsConstant()) { |
| 1469 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 1470 | DCHECK(value.IsRegister()); |
| 1471 | __ movq(Address(obj, offset), value.AsX86_64().AsCpuRegister()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1472 | } else { |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 1473 | DCHECK(value.IsRegister()); |
| 1474 | __ movq(Address(obj, index.AsX86_64().AsCpuRegister(), TIMES_8, data_offset), |
| 1475 | value.AsX86_64().AsCpuRegister()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1476 | } |
| 1477 | break; |
| 1478 | } |
| 1479 | |
| 1480 | case Primitive::kPrimFloat: |
| 1481 | case Primitive::kPrimDouble: |
| 1482 | LOG(FATAL) << "Unimplemented register type " << instruction->GetType(); |
| 1483 | |
| 1484 | case Primitive::kPrimVoid: |
| 1485 | LOG(FATAL) << "Unreachable type " << instruction->GetType(); |
| 1486 | } |
| 1487 | } |
| 1488 | |
| 1489 | void LocationsBuilderX86_64::VisitArrayLength(HArrayLength* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1490 | LocationSummary* locations = |
| 1491 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 9ae0daa | 2014-09-30 22:40:23 +0100 | [diff] [blame] | 1492 | locations->SetInAt(0, Location::RequiresRegister(), Location::kDiesAtEntry); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1493 | locations->SetOut(Location::RequiresRegister()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1494 | } |
| 1495 | |
| 1496 | void InstructionCodeGeneratorX86_64::VisitArrayLength(HArrayLength* instruction) { |
| 1497 | LocationSummary* locations = instruction->GetLocations(); |
| 1498 | uint32_t offset = mirror::Array::LengthOffset().Uint32Value(); |
| 1499 | CpuRegister obj = locations->InAt(0).AsX86_64().AsCpuRegister(); |
| 1500 | CpuRegister out = locations->Out().AsX86_64().AsCpuRegister(); |
| 1501 | __ movl(out, Address(obj, offset)); |
| 1502 | } |
| 1503 | |
| 1504 | void LocationsBuilderX86_64::VisitBoundsCheck(HBoundsCheck* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1505 | LocationSummary* locations = |
| 1506 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1507 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1508 | locations->SetInAt(1, Location::RequiresRegister()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 1509 | if (instruction->HasUses()) { |
| 1510 | locations->SetOut(Location::SameAsFirstInput()); |
| 1511 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1512 | } |
| 1513 | |
| 1514 | void InstructionCodeGeneratorX86_64::VisitBoundsCheck(HBoundsCheck* instruction) { |
| 1515 | LocationSummary* locations = instruction->GetLocations(); |
| 1516 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) BoundsCheckSlowPathX86_64( |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1517 | instruction, locations->InAt(0), locations->InAt(1)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1518 | codegen_->AddSlowPath(slow_path); |
| 1519 | |
| 1520 | CpuRegister index = locations->InAt(0).AsX86_64().AsCpuRegister(); |
| 1521 | CpuRegister length = locations->InAt(1).AsX86_64().AsCpuRegister(); |
| 1522 | |
| 1523 | __ cmpl(index, length); |
| 1524 | __ j(kAboveEqual, slow_path->GetEntryLabel()); |
| 1525 | } |
| 1526 | |
| 1527 | void CodeGeneratorX86_64::MarkGCCard(CpuRegister temp, |
| 1528 | CpuRegister card, |
| 1529 | CpuRegister object, |
| 1530 | CpuRegister value) { |
| 1531 | Label is_null; |
| 1532 | __ testl(value, value); |
| 1533 | __ j(kEqual, &is_null); |
| 1534 | __ gs()->movq(card, Address::Absolute( |
| 1535 | Thread::CardTableOffset<kX86_64WordSize>().Int32Value(), true)); |
| 1536 | __ movq(temp, object); |
| 1537 | __ shrq(temp, Immediate(gc::accounting::CardTable::kCardShift)); |
| 1538 | __ movb(Address(temp, card, TIMES_1, 0), card); |
| 1539 | __ Bind(&is_null); |
| 1540 | } |
| 1541 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1542 | void LocationsBuilderX86_64::VisitTemporary(HTemporary* temp) { |
| 1543 | temp->SetLocations(nullptr); |
| 1544 | } |
| 1545 | |
| 1546 | void InstructionCodeGeneratorX86_64::VisitTemporary(HTemporary* temp) { |
| 1547 | // Nothing to do, this is driven by the code generator. |
| 1548 | } |
| 1549 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1550 | void LocationsBuilderX86_64::VisitParallelMove(HParallelMove* instruction) { |
| 1551 | LOG(FATAL) << "Unimplemented"; |
| 1552 | } |
| 1553 | |
| 1554 | void InstructionCodeGeneratorX86_64::VisitParallelMove(HParallelMove* instruction) { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 1555 | codegen_->GetMoveResolver()->EmitNativeCode(instruction); |
| 1556 | } |
| 1557 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 1558 | void LocationsBuilderX86_64::VisitSuspendCheck(HSuspendCheck* instruction) { |
| 1559 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath); |
| 1560 | } |
| 1561 | |
| 1562 | void InstructionCodeGeneratorX86_64::VisitSuspendCheck(HSuspendCheck* instruction) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1563 | HBasicBlock* block = instruction->GetBlock(); |
| 1564 | if (block->GetLoopInformation() != nullptr) { |
| 1565 | DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction); |
| 1566 | // The back edge will generate the suspend check. |
| 1567 | return; |
| 1568 | } |
| 1569 | if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) { |
| 1570 | // The goto will generate the suspend check. |
| 1571 | return; |
| 1572 | } |
| 1573 | GenerateSuspendCheck(instruction, nullptr); |
| 1574 | } |
| 1575 | |
| 1576 | void InstructionCodeGeneratorX86_64::GenerateSuspendCheck(HSuspendCheck* instruction, |
| 1577 | HBasicBlock* successor) { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 1578 | SuspendCheckSlowPathX86_64* slow_path = |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1579 | new (GetGraph()->GetArena()) SuspendCheckSlowPathX86_64(instruction, successor); |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 1580 | codegen_->AddSlowPath(slow_path); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1581 | __ gs()->cmpw(Address::Absolute( |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 1582 | Thread::ThreadFlagsOffset<kX86_64WordSize>().Int32Value(), true), Immediate(0)); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1583 | if (successor == nullptr) { |
| 1584 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 1585 | __ Bind(slow_path->GetReturnLabel()); |
| 1586 | } else { |
| 1587 | __ j(kEqual, codegen_->GetLabelOf(successor)); |
| 1588 | __ jmp(slow_path->GetEntryLabel()); |
| 1589 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 1590 | } |
| 1591 | |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 1592 | X86_64Assembler* ParallelMoveResolverX86_64::GetAssembler() const { |
| 1593 | return codegen_->GetAssembler(); |
| 1594 | } |
| 1595 | |
| 1596 | void ParallelMoveResolverX86_64::EmitMove(size_t index) { |
| 1597 | MoveOperands* move = moves_.Get(index); |
| 1598 | Location source = move->GetSource(); |
| 1599 | Location destination = move->GetDestination(); |
| 1600 | |
| 1601 | if (source.IsRegister()) { |
| 1602 | if (destination.IsRegister()) { |
| 1603 | __ movq(destination.AsX86_64().AsCpuRegister(), source.AsX86_64().AsCpuRegister()); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1604 | } else if (destination.IsStackSlot()) { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 1605 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), |
| 1606 | source.AsX86_64().AsCpuRegister()); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1607 | } else { |
| 1608 | DCHECK(destination.IsDoubleStackSlot()); |
| 1609 | __ movq(Address(CpuRegister(RSP), destination.GetStackIndex()), |
| 1610 | source.AsX86_64().AsCpuRegister()); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 1611 | } |
| 1612 | } else if (source.IsStackSlot()) { |
| 1613 | if (destination.IsRegister()) { |
| 1614 | __ movl(destination.AsX86_64().AsX86_64().AsCpuRegister(), |
| 1615 | Address(CpuRegister(RSP), source.GetStackIndex())); |
| 1616 | } else { |
| 1617 | DCHECK(destination.IsStackSlot()); |
| 1618 | __ movl(CpuRegister(TMP), Address(CpuRegister(RSP), source.GetStackIndex())); |
| 1619 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), CpuRegister(TMP)); |
| 1620 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1621 | } else if (source.IsDoubleStackSlot()) { |
| 1622 | if (destination.IsRegister()) { |
| 1623 | __ movq(destination.AsX86_64().AsX86_64().AsCpuRegister(), |
| 1624 | Address(CpuRegister(RSP), source.GetStackIndex())); |
| 1625 | } else { |
| 1626 | DCHECK(destination.IsDoubleStackSlot()); |
| 1627 | __ movq(CpuRegister(TMP), Address(CpuRegister(RSP), source.GetStackIndex())); |
| 1628 | __ movq(Address(CpuRegister(RSP), destination.GetStackIndex()), CpuRegister(TMP)); |
| 1629 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1630 | } else if (source.IsConstant()) { |
| 1631 | HConstant* constant = source.GetConstant(); |
| 1632 | if (constant->IsIntConstant()) { |
| 1633 | Immediate imm(constant->AsIntConstant()->GetValue()); |
| 1634 | if (destination.IsRegister()) { |
| 1635 | __ movl(destination.AsX86_64().AsCpuRegister(), imm); |
| 1636 | } else { |
| 1637 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), imm); |
| 1638 | } |
| 1639 | } else if (constant->IsLongConstant()) { |
| 1640 | int64_t value = constant->AsLongConstant()->GetValue(); |
| 1641 | if (destination.IsRegister()) { |
| 1642 | __ movq(destination.AsX86_64().AsCpuRegister(), Immediate(value)); |
| 1643 | } else { |
| 1644 | __ movq(CpuRegister(TMP), Immediate(value)); |
| 1645 | __ movq(Address(CpuRegister(RSP), destination.GetStackIndex()), CpuRegister(TMP)); |
| 1646 | } |
| 1647 | } else { |
| 1648 | LOG(FATAL) << "Unimplemented constant type"; |
| 1649 | } |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 1650 | } else { |
| 1651 | LOG(FATAL) << "Unimplemented"; |
| 1652 | } |
| 1653 | } |
| 1654 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1655 | void ParallelMoveResolverX86_64::Exchange32(CpuRegister reg, int mem) { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 1656 | __ movl(CpuRegister(TMP), Address(CpuRegister(RSP), mem)); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1657 | __ movl(Address(CpuRegister(RSP), mem), reg); |
| 1658 | __ movl(reg, CpuRegister(TMP)); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 1659 | } |
| 1660 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1661 | void ParallelMoveResolverX86_64::Exchange32(int mem1, int mem2) { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 1662 | ScratchRegisterScope ensure_scratch( |
| 1663 | this, TMP, RAX, codegen_->GetNumberOfCoreRegisters()); |
| 1664 | |
| 1665 | int stack_offset = ensure_scratch.IsSpilled() ? kX86_64WordSize : 0; |
| 1666 | __ movl(CpuRegister(TMP), Address(CpuRegister(RSP), mem1 + stack_offset)); |
| 1667 | __ movl(CpuRegister(ensure_scratch.GetRegister()), |
| 1668 | Address(CpuRegister(RSP), mem2 + stack_offset)); |
| 1669 | __ movl(Address(CpuRegister(RSP), mem2 + stack_offset), CpuRegister(TMP)); |
| 1670 | __ movl(Address(CpuRegister(RSP), mem1 + stack_offset), |
| 1671 | CpuRegister(ensure_scratch.GetRegister())); |
| 1672 | } |
| 1673 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1674 | void ParallelMoveResolverX86_64::Exchange64(CpuRegister reg, int mem) { |
| 1675 | __ movq(CpuRegister(TMP), Address(CpuRegister(RSP), mem)); |
| 1676 | __ movq(Address(CpuRegister(RSP), mem), reg); |
| 1677 | __ movq(reg, CpuRegister(TMP)); |
| 1678 | } |
| 1679 | |
| 1680 | void ParallelMoveResolverX86_64::Exchange64(int mem1, int mem2) { |
| 1681 | ScratchRegisterScope ensure_scratch( |
| 1682 | this, TMP, RAX, codegen_->GetNumberOfCoreRegisters()); |
| 1683 | |
| 1684 | int stack_offset = ensure_scratch.IsSpilled() ? kX86_64WordSize : 0; |
| 1685 | __ movq(CpuRegister(TMP), Address(CpuRegister(RSP), mem1 + stack_offset)); |
| 1686 | __ movq(CpuRegister(ensure_scratch.GetRegister()), |
| 1687 | Address(CpuRegister(RSP), mem2 + stack_offset)); |
| 1688 | __ movq(Address(CpuRegister(RSP), mem2 + stack_offset), CpuRegister(TMP)); |
| 1689 | __ movq(Address(CpuRegister(RSP), mem1 + stack_offset), |
| 1690 | CpuRegister(ensure_scratch.GetRegister())); |
| 1691 | } |
| 1692 | |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 1693 | void ParallelMoveResolverX86_64::EmitSwap(size_t index) { |
| 1694 | MoveOperands* move = moves_.Get(index); |
| 1695 | Location source = move->GetSource(); |
| 1696 | Location destination = move->GetDestination(); |
| 1697 | |
| 1698 | if (source.IsRegister() && destination.IsRegister()) { |
| 1699 | __ xchgq(destination.AsX86_64().AsCpuRegister(), source.AsX86_64().AsCpuRegister()); |
| 1700 | } else if (source.IsRegister() && destination.IsStackSlot()) { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1701 | Exchange32(source.AsX86_64().AsCpuRegister(), destination.GetStackIndex()); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 1702 | } else if (source.IsStackSlot() && destination.IsRegister()) { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1703 | Exchange32(destination.AsX86_64().AsCpuRegister(), source.GetStackIndex()); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 1704 | } else if (source.IsStackSlot() && destination.IsStackSlot()) { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1705 | Exchange32(destination.GetStackIndex(), source.GetStackIndex()); |
| 1706 | } else if (source.IsRegister() && destination.IsDoubleStackSlot()) { |
| 1707 | Exchange64(source.AsX86_64().AsCpuRegister(), destination.GetStackIndex()); |
| 1708 | } else if (source.IsDoubleStackSlot() && destination.IsRegister()) { |
| 1709 | Exchange64(destination.AsX86_64().AsCpuRegister(), source.GetStackIndex()); |
| 1710 | } else if (source.IsDoubleStackSlot() && destination.IsDoubleStackSlot()) { |
| 1711 | Exchange64(destination.GetStackIndex(), source.GetStackIndex()); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 1712 | } else { |
| 1713 | LOG(FATAL) << "Unimplemented"; |
| 1714 | } |
| 1715 | } |
| 1716 | |
| 1717 | |
| 1718 | void ParallelMoveResolverX86_64::SpillScratch(int reg) { |
| 1719 | __ pushq(CpuRegister(reg)); |
| 1720 | } |
| 1721 | |
| 1722 | |
| 1723 | void ParallelMoveResolverX86_64::RestoreScratch(int reg) { |
| 1724 | __ popq(CpuRegister(reg)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1725 | } |
| 1726 | |
| 1727 | } // namespace x86_64 |
| 1728 | } // namespace art |