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