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