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 | 01ef345 | 2014-10-01 11:32:17 +0100 | [diff] [blame] | 485 | if (!cond->IsCondition() || cond->AsCondition()->NeedsMaterialization()) { |
Nicolas Geoffray | 18efde5 | 2014-09-22 15:51:11 +0100 | [diff] [blame] | 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. |
Nicolas Geoffray | 01ef345 | 2014-10-01 11:32:17 +0100 | [diff] [blame] | 488 | if (!cond->IsCondition() || !cond->AsCondition()->IsBeforeWhenDisregardMoves(if_instr)) { |
Nicolas Geoffray | 18efde5 | 2014-09-22 15:51:11 +0100 | [diff] [blame] | 489 | // Materialized condition, compare against 0. |
| 490 | Location lhs = if_instr->GetLocations()->InAt(0); |
| 491 | if (lhs.IsRegister()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 492 | __ cmpl(lhs.As<CpuRegister>(), Immediate(0)); |
Nicolas Geoffray | 18efde5 | 2014-09-22 15:51:11 +0100 | [diff] [blame] | 493 | } else { |
| 494 | __ cmpl(Address(CpuRegister(RSP), lhs.GetStackIndex()), Immediate(0)); |
| 495 | } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 496 | } |
Nicolas Geoffray | 18efde5 | 2014-09-22 15:51:11 +0100 | [diff] [blame] | 497 | __ j(kNotEqual, codegen_->GetLabelOf(if_instr->IfTrueSuccessor())); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 498 | } else { |
Nicolas Geoffray | 01ef345 | 2014-10-01 11:32:17 +0100 | [diff] [blame] | 499 | Location lhs = cond->GetLocations()->InAt(0); |
| 500 | Location rhs = cond->GetLocations()->InAt(1); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 501 | if (rhs.IsRegister()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 502 | __ cmpl(lhs.As<CpuRegister>(), rhs.As<CpuRegister>()); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 503 | } else if (rhs.IsConstant()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 504 | __ cmpl(lhs.As<CpuRegister>(), |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 505 | Immediate(rhs.GetConstant()->AsIntConstant()->GetValue())); |
| 506 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 507 | __ cmpl(lhs.As<CpuRegister>(), Address(CpuRegister(RSP), rhs.GetStackIndex())); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 508 | } |
Nicolas Geoffray | 01ef345 | 2014-10-01 11:32:17 +0100 | [diff] [blame] | 509 | __ j(X86_64Condition(cond->AsCondition()->GetCondition()), |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 510 | codegen_->GetLabelOf(if_instr->IfTrueSuccessor())); |
| 511 | } |
| 512 | if (!codegen_->GoesToNextBlock(if_instr->GetBlock(), if_instr->IfFalseSuccessor())) { |
| 513 | __ jmp(codegen_->GetLabelOf(if_instr->IfFalseSuccessor())); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 514 | } |
| 515 | } |
| 516 | |
| 517 | void LocationsBuilderX86_64::VisitLocal(HLocal* local) { |
| 518 | local->SetLocations(nullptr); |
| 519 | } |
| 520 | |
| 521 | void InstructionCodeGeneratorX86_64::VisitLocal(HLocal* local) { |
| 522 | DCHECK_EQ(local->GetBlock(), GetGraph()->GetEntryBlock()); |
| 523 | } |
| 524 | |
| 525 | void LocationsBuilderX86_64::VisitLoadLocal(HLoadLocal* local) { |
| 526 | local->SetLocations(nullptr); |
| 527 | } |
| 528 | |
| 529 | void InstructionCodeGeneratorX86_64::VisitLoadLocal(HLoadLocal* load) { |
| 530 | // Nothing to do, this is driven by the code generator. |
| 531 | } |
| 532 | |
| 533 | void LocationsBuilderX86_64::VisitStoreLocal(HStoreLocal* store) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 534 | LocationSummary* locations = |
| 535 | new (GetGraph()->GetArena()) LocationSummary(store, LocationSummary::kNoCall); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 536 | switch (store->InputAt(1)->GetType()) { |
| 537 | case Primitive::kPrimBoolean: |
| 538 | case Primitive::kPrimByte: |
| 539 | case Primitive::kPrimChar: |
| 540 | case Primitive::kPrimShort: |
| 541 | case Primitive::kPrimInt: |
| 542 | case Primitive::kPrimNot: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 543 | case Primitive::kPrimFloat: |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 544 | locations->SetInAt(1, Location::StackSlot(codegen_->GetStackSlot(store->GetLocal()))); |
| 545 | break; |
| 546 | |
| 547 | case Primitive::kPrimLong: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 548 | case Primitive::kPrimDouble: |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 549 | locations->SetInAt(1, Location::DoubleStackSlot(codegen_->GetStackSlot(store->GetLocal()))); |
| 550 | break; |
| 551 | |
| 552 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 553 | LOG(FATAL) << "Unexpected local type " << store->InputAt(1)->GetType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 554 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 555 | } |
| 556 | |
| 557 | void InstructionCodeGeneratorX86_64::VisitStoreLocal(HStoreLocal* store) { |
| 558 | } |
| 559 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 560 | void LocationsBuilderX86_64::VisitCondition(HCondition* comp) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 561 | LocationSummary* locations = |
| 562 | new (GetGraph()->GetArena()) LocationSummary(comp, LocationSummary::kNoCall); |
Nicolas Geoffray | 9ae0daa | 2014-09-30 22:40:23 +0100 | [diff] [blame] | 563 | locations->SetInAt(0, Location::RequiresRegister(), Location::kDiesAtEntry); |
| 564 | locations->SetInAt(1, Location::Any(), Location::kDiesAtEntry); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 565 | if (comp->NeedsMaterialization()) { |
| 566 | locations->SetOut(Location::RequiresRegister()); |
| 567 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 568 | } |
| 569 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 570 | void InstructionCodeGeneratorX86_64::VisitCondition(HCondition* comp) { |
| 571 | if (comp->NeedsMaterialization()) { |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 572 | LocationSummary* locations = comp->GetLocations(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 573 | CpuRegister reg = locations->Out().As<CpuRegister>(); |
Nicolas Geoffray | 18efde5 | 2014-09-22 15:51:11 +0100 | [diff] [blame] | 574 | // Clear register: setcc only sets the low byte. |
| 575 | __ xorq(reg, reg); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 576 | if (locations->InAt(1).IsRegister()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 577 | __ cmpq(locations->InAt(0).As<CpuRegister>(), |
| 578 | locations->InAt(1).As<CpuRegister>()); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 579 | } else if (locations->InAt(1).IsConstant()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 580 | __ cmpq(locations->InAt(0).As<CpuRegister>(), |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 581 | Immediate(locations->InAt(1).GetConstant()->AsIntConstant()->GetValue())); |
| 582 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 583 | __ cmpq(locations->InAt(0).As<CpuRegister>(), |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 584 | Address(CpuRegister(RSP), locations->InAt(1).GetStackIndex())); |
| 585 | } |
Nicolas Geoffray | 18efde5 | 2014-09-22 15:51:11 +0100 | [diff] [blame] | 586 | __ setcc(X86_64Condition(comp->GetCondition()), reg); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 587 | } |
| 588 | } |
| 589 | |
| 590 | void LocationsBuilderX86_64::VisitEqual(HEqual* comp) { |
| 591 | VisitCondition(comp); |
| 592 | } |
| 593 | |
| 594 | void InstructionCodeGeneratorX86_64::VisitEqual(HEqual* comp) { |
| 595 | VisitCondition(comp); |
| 596 | } |
| 597 | |
| 598 | void LocationsBuilderX86_64::VisitNotEqual(HNotEqual* comp) { |
| 599 | VisitCondition(comp); |
| 600 | } |
| 601 | |
| 602 | void InstructionCodeGeneratorX86_64::VisitNotEqual(HNotEqual* comp) { |
| 603 | VisitCondition(comp); |
| 604 | } |
| 605 | |
| 606 | void LocationsBuilderX86_64::VisitLessThan(HLessThan* comp) { |
| 607 | VisitCondition(comp); |
| 608 | } |
| 609 | |
| 610 | void InstructionCodeGeneratorX86_64::VisitLessThan(HLessThan* comp) { |
| 611 | VisitCondition(comp); |
| 612 | } |
| 613 | |
| 614 | void LocationsBuilderX86_64::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
| 615 | VisitCondition(comp); |
| 616 | } |
| 617 | |
| 618 | void InstructionCodeGeneratorX86_64::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
| 619 | VisitCondition(comp); |
| 620 | } |
| 621 | |
| 622 | void LocationsBuilderX86_64::VisitGreaterThan(HGreaterThan* comp) { |
| 623 | VisitCondition(comp); |
| 624 | } |
| 625 | |
| 626 | void InstructionCodeGeneratorX86_64::VisitGreaterThan(HGreaterThan* comp) { |
| 627 | VisitCondition(comp); |
| 628 | } |
| 629 | |
| 630 | void LocationsBuilderX86_64::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
| 631 | VisitCondition(comp); |
| 632 | } |
| 633 | |
| 634 | void InstructionCodeGeneratorX86_64::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
| 635 | VisitCondition(comp); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 636 | } |
| 637 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 638 | void LocationsBuilderX86_64::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 639 | LocationSummary* locations = |
| 640 | new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall); |
Nicolas Geoffray | 9ae0daa | 2014-09-30 22:40:23 +0100 | [diff] [blame] | 641 | locations->SetInAt(0, Location::RequiresRegister(), Location::kDiesAtEntry); |
| 642 | locations->SetInAt(1, Location::RequiresRegister(), Location::kDiesAtEntry); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 643 | locations->SetOut(Location::RequiresRegister()); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 644 | } |
| 645 | |
| 646 | void InstructionCodeGeneratorX86_64::VisitCompare(HCompare* compare) { |
| 647 | Label greater, done; |
| 648 | LocationSummary* locations = compare->GetLocations(); |
| 649 | switch (compare->InputAt(0)->GetType()) { |
| 650 | case Primitive::kPrimLong: |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 651 | __ cmpq(locations->InAt(0).As<CpuRegister>(), |
| 652 | locations->InAt(1).As<CpuRegister>()); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 653 | break; |
| 654 | default: |
| 655 | LOG(FATAL) << "Unimplemented compare type " << compare->InputAt(0)->GetType(); |
| 656 | } |
| 657 | |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 658 | CpuRegister output = locations->Out().As<CpuRegister>(); |
| 659 | __ movl(output, Immediate(0)); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 660 | __ j(kEqual, &done); |
| 661 | __ j(kGreater, &greater); |
| 662 | |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 663 | __ movl(output, Immediate(-1)); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 664 | __ jmp(&done); |
| 665 | |
| 666 | __ Bind(&greater); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 667 | __ movl(output, Immediate(1)); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 668 | |
| 669 | __ Bind(&done); |
| 670 | } |
| 671 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 672 | void LocationsBuilderX86_64::VisitIntConstant(HIntConstant* constant) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 673 | LocationSummary* locations = |
| 674 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 675 | locations->SetOut(Location::ConstantLocation(constant)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 676 | } |
| 677 | |
| 678 | void InstructionCodeGeneratorX86_64::VisitIntConstant(HIntConstant* constant) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 679 | } |
| 680 | |
| 681 | void LocationsBuilderX86_64::VisitLongConstant(HLongConstant* constant) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 682 | LocationSummary* locations = |
| 683 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 684 | locations->SetOut(Location::ConstantLocation(constant)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 685 | } |
| 686 | |
| 687 | void InstructionCodeGeneratorX86_64::VisitLongConstant(HLongConstant* constant) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 688 | } |
| 689 | |
| 690 | void LocationsBuilderX86_64::VisitReturnVoid(HReturnVoid* ret) { |
| 691 | ret->SetLocations(nullptr); |
| 692 | } |
| 693 | |
| 694 | void InstructionCodeGeneratorX86_64::VisitReturnVoid(HReturnVoid* ret) { |
| 695 | codegen_->GenerateFrameExit(); |
| 696 | __ ret(); |
| 697 | } |
| 698 | |
| 699 | void LocationsBuilderX86_64::VisitReturn(HReturn* ret) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 700 | LocationSummary* locations = |
| 701 | new (GetGraph()->GetArena()) LocationSummary(ret, LocationSummary::kNoCall); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 702 | switch (ret->InputAt(0)->GetType()) { |
| 703 | case Primitive::kPrimBoolean: |
| 704 | case Primitive::kPrimByte: |
| 705 | case Primitive::kPrimChar: |
| 706 | case Primitive::kPrimShort: |
| 707 | case Primitive::kPrimInt: |
| 708 | case Primitive::kPrimNot: |
| 709 | case Primitive::kPrimLong: |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 710 | locations->SetInAt(0, Location::RegisterLocation(RAX)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 711 | break; |
| 712 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 713 | case Primitive::kPrimFloat: |
| 714 | case Primitive::kPrimDouble: |
| 715 | locations->SetInAt(0, |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 716 | Location::FpuRegisterLocation(XMM0)); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 717 | break; |
| 718 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 719 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 720 | LOG(FATAL) << "Unexpected return type " << ret->InputAt(0)->GetType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 721 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 722 | } |
| 723 | |
| 724 | void InstructionCodeGeneratorX86_64::VisitReturn(HReturn* ret) { |
| 725 | if (kIsDebugBuild) { |
| 726 | switch (ret->InputAt(0)->GetType()) { |
| 727 | case Primitive::kPrimBoolean: |
| 728 | case Primitive::kPrimByte: |
| 729 | case Primitive::kPrimChar: |
| 730 | case Primitive::kPrimShort: |
| 731 | case Primitive::kPrimInt: |
| 732 | case Primitive::kPrimNot: |
| 733 | case Primitive::kPrimLong: |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 734 | DCHECK_EQ(ret->GetLocations()->InAt(0).As<CpuRegister>().AsRegister(), RAX); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 735 | break; |
| 736 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 737 | case Primitive::kPrimFloat: |
| 738 | case Primitive::kPrimDouble: |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 739 | DCHECK_EQ(ret->GetLocations()->InAt(0).As<XmmRegister>().AsFloatRegister(), |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 740 | XMM0); |
| 741 | break; |
| 742 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 743 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 744 | LOG(FATAL) << "Unexpected return type " << ret->InputAt(0)->GetType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 745 | } |
| 746 | } |
| 747 | codegen_->GenerateFrameExit(); |
| 748 | __ ret(); |
| 749 | } |
| 750 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 751 | Location InvokeDexCallingConventionVisitor::GetNextLocation(Primitive::Type type) { |
| 752 | switch (type) { |
| 753 | case Primitive::kPrimBoolean: |
| 754 | case Primitive::kPrimByte: |
| 755 | case Primitive::kPrimChar: |
| 756 | case Primitive::kPrimShort: |
| 757 | case Primitive::kPrimInt: |
| 758 | case Primitive::kPrimNot: { |
| 759 | uint32_t index = gp_index_++; |
| 760 | stack_index_++; |
| 761 | if (index < calling_convention.GetNumberOfRegisters()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 762 | return Location::RegisterLocation(calling_convention.GetRegisterAt(index)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 763 | } else { |
| 764 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 1)); |
| 765 | } |
| 766 | } |
| 767 | |
| 768 | case Primitive::kPrimLong: { |
| 769 | uint32_t index = gp_index_; |
| 770 | stack_index_ += 2; |
| 771 | if (index < calling_convention.GetNumberOfRegisters()) { |
| 772 | gp_index_ += 1; |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 773 | return Location::RegisterLocation(calling_convention.GetRegisterAt(index)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 774 | } else { |
| 775 | gp_index_ += 2; |
| 776 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 2)); |
| 777 | } |
| 778 | } |
| 779 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 780 | case Primitive::kPrimFloat: { |
| 781 | uint32_t index = fp_index_++; |
| 782 | stack_index_++; |
| 783 | if (index < calling_convention.GetNumberOfFpuRegisters()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 784 | return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(index)); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 785 | } else { |
| 786 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 1)); |
| 787 | } |
| 788 | } |
| 789 | |
| 790 | case Primitive::kPrimDouble: { |
| 791 | uint32_t index = fp_index_++; |
| 792 | stack_index_ += 2; |
| 793 | if (index < calling_convention.GetNumberOfFpuRegisters()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 794 | return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(index)); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 795 | } else { |
| 796 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 2)); |
| 797 | } |
| 798 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 799 | |
| 800 | case Primitive::kPrimVoid: |
| 801 | LOG(FATAL) << "Unexpected parameter type " << type; |
| 802 | break; |
| 803 | } |
| 804 | return Location(); |
| 805 | } |
| 806 | |
| 807 | void LocationsBuilderX86_64::VisitInvokeStatic(HInvokeStatic* invoke) { |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 808 | HandleInvoke(invoke); |
| 809 | } |
| 810 | |
| 811 | void InstructionCodeGeneratorX86_64::VisitInvokeStatic(HInvokeStatic* invoke) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 812 | CpuRegister temp = invoke->GetLocations()->GetTemp(0).As<CpuRegister>(); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 813 | uint32_t heap_reference_size = sizeof(mirror::HeapReference<mirror::Object>); |
| 814 | size_t index_in_cache = mirror::Array::DataOffset(heap_reference_size).SizeValue() + |
| 815 | invoke->GetIndexInDexCache() * heap_reference_size; |
| 816 | |
| 817 | // TODO: Implement all kinds of calls: |
| 818 | // 1) boot -> boot |
| 819 | // 2) app -> boot |
| 820 | // 3) app -> app |
| 821 | // |
| 822 | // Currently we implement the app -> app logic, which looks up in the resolve cache. |
| 823 | |
| 824 | // temp = method; |
| 825 | LoadCurrentMethod(temp); |
| 826 | // temp = temp->dex_cache_resolved_methods_; |
| 827 | __ movl(temp, Address(temp, mirror::ArtMethod::DexCacheResolvedMethodsOffset().SizeValue())); |
| 828 | // temp = temp[index_in_cache] |
| 829 | __ movl(temp, Address(temp, index_in_cache)); |
| 830 | // (temp + offset_of_quick_compiled_code)() |
| 831 | __ call(Address(temp, mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset().SizeValue())); |
| 832 | |
| 833 | DCHECK(!codegen_->IsLeafMethod()); |
| 834 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 835 | } |
| 836 | |
| 837 | void LocationsBuilderX86_64::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
| 838 | HandleInvoke(invoke); |
| 839 | } |
| 840 | |
| 841 | void LocationsBuilderX86_64::HandleInvoke(HInvoke* invoke) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 842 | LocationSummary* locations = |
| 843 | new (GetGraph()->GetArena()) LocationSummary(invoke, LocationSummary::kCall); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 844 | locations->AddTemp(Location::RegisterLocation(RDI)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 845 | |
| 846 | InvokeDexCallingConventionVisitor calling_convention_visitor; |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 847 | for (size_t i = 0; i < invoke->InputCount(); i++) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 848 | HInstruction* input = invoke->InputAt(i); |
| 849 | locations->SetInAt(i, calling_convention_visitor.GetNextLocation(input->GetType())); |
| 850 | } |
| 851 | |
| 852 | switch (invoke->GetType()) { |
| 853 | case Primitive::kPrimBoolean: |
| 854 | case Primitive::kPrimByte: |
| 855 | case Primitive::kPrimChar: |
| 856 | case Primitive::kPrimShort: |
| 857 | case Primitive::kPrimInt: |
| 858 | case Primitive::kPrimNot: |
| 859 | case Primitive::kPrimLong: |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 860 | locations->SetOut(Location::RegisterLocation(RAX)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 861 | break; |
| 862 | |
| 863 | case Primitive::kPrimVoid: |
| 864 | break; |
| 865 | |
| 866 | case Primitive::kPrimDouble: |
| 867 | case Primitive::kPrimFloat: |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 868 | locations->SetOut(Location::FpuRegisterLocation(XMM0)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 869 | break; |
| 870 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 871 | } |
| 872 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 873 | void InstructionCodeGeneratorX86_64::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 874 | CpuRegister temp = invoke->GetLocations()->GetTemp(0).As<CpuRegister>(); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 875 | size_t method_offset = mirror::Class::EmbeddedVTableOffset().SizeValue() + |
| 876 | invoke->GetVTableIndex() * sizeof(mirror::Class::VTableEntry); |
| 877 | LocationSummary* locations = invoke->GetLocations(); |
| 878 | Location receiver = locations->InAt(0); |
| 879 | size_t class_offset = mirror::Object::ClassOffset().SizeValue(); |
| 880 | // temp = object->GetClass(); |
| 881 | if (receiver.IsStackSlot()) { |
| 882 | __ movq(temp, Address(CpuRegister(RSP), receiver.GetStackIndex())); |
| 883 | __ movq(temp, Address(temp, class_offset)); |
| 884 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 885 | __ movq(temp, Address(receiver.As<CpuRegister>(), class_offset)); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 886 | } |
| 887 | // temp = temp->GetMethodAt(method_offset); |
| 888 | __ movl(temp, Address(temp, method_offset)); |
| 889 | // call temp->GetEntryPoint(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 890 | __ call(Address(temp, mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset().SizeValue())); |
| 891 | |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 892 | DCHECK(!codegen_->IsLeafMethod()); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 893 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 894 | } |
| 895 | |
| 896 | void LocationsBuilderX86_64::VisitAdd(HAdd* add) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 897 | LocationSummary* locations = |
| 898 | new (GetGraph()->GetArena()) LocationSummary(add, LocationSummary::kNoCall); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 899 | switch (add->GetResultType()) { |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 900 | case Primitive::kPrimInt: { |
| 901 | locations->SetInAt(0, Location::RequiresRegister()); |
| 902 | locations->SetInAt(1, Location::Any()); |
| 903 | locations->SetOut(Location::SameAsFirstInput()); |
| 904 | break; |
| 905 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 906 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 907 | case Primitive::kPrimLong: { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 908 | locations->SetInAt(0, Location::RequiresRegister()); |
| 909 | locations->SetInAt(1, Location::RequiresRegister()); |
| 910 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 911 | break; |
| 912 | } |
| 913 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 914 | case Primitive::kPrimDouble: |
| 915 | case Primitive::kPrimFloat: { |
| 916 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 917 | locations->SetInAt(1, Location::Any()); |
| 918 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 919 | break; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 920 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 921 | |
| 922 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 923 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 924 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 925 | } |
| 926 | |
| 927 | void InstructionCodeGeneratorX86_64::VisitAdd(HAdd* add) { |
| 928 | LocationSummary* locations = add->GetLocations(); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 929 | Location first = locations->InAt(0); |
| 930 | Location second = locations->InAt(1); |
| 931 | |
| 932 | DCHECK(first.Equals(locations->Out())); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 933 | switch (add->GetResultType()) { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 934 | case Primitive::kPrimInt: { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 935 | if (second.IsRegister()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 936 | __ addl(first.As<CpuRegister>(), second.As<CpuRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 937 | } else if (second.IsConstant()) { |
| 938 | HConstant* instruction = second.GetConstant(); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 939 | Immediate imm(instruction->AsIntConstant()->GetValue()); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 940 | __ addl(first.As<CpuRegister>(), imm); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 941 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 942 | __ addl(first.As<CpuRegister>(), |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 943 | Address(CpuRegister(RSP), second.GetStackIndex())); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 944 | } |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 945 | break; |
| 946 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 947 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 948 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 949 | __ addq(first.As<CpuRegister>(), second.As<CpuRegister>()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 950 | break; |
| 951 | } |
| 952 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 953 | case Primitive::kPrimFloat: { |
| 954 | if (second.IsFpuRegister()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 955 | __ addss(first.As<XmmRegister>(), second.As<XmmRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 956 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 957 | __ addss(first.As<XmmRegister>(), |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 958 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 959 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 960 | break; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 961 | } |
| 962 | |
| 963 | case Primitive::kPrimDouble: { |
| 964 | if (second.IsFpuRegister()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 965 | __ addsd(first.As<XmmRegister>(), second.As<XmmRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 966 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 967 | __ addsd(first.As<XmmRegister>(), Address(CpuRegister(RSP), second.GetStackIndex())); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 968 | } |
| 969 | break; |
| 970 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 971 | |
| 972 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 973 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 974 | } |
| 975 | } |
| 976 | |
| 977 | void LocationsBuilderX86_64::VisitSub(HSub* sub) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 978 | LocationSummary* locations = |
| 979 | new (GetGraph()->GetArena()) LocationSummary(sub, LocationSummary::kNoCall); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 980 | switch (sub->GetResultType()) { |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 981 | case Primitive::kPrimInt: { |
| 982 | locations->SetInAt(0, Location::RequiresRegister()); |
| 983 | locations->SetInAt(1, Location::Any()); |
| 984 | locations->SetOut(Location::SameAsFirstInput()); |
| 985 | break; |
| 986 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 987 | case Primitive::kPrimLong: { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 988 | locations->SetInAt(0, Location::RequiresRegister()); |
| 989 | locations->SetInAt(1, Location::RequiresRegister()); |
| 990 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 991 | break; |
| 992 | } |
| 993 | |
| 994 | case Primitive::kPrimBoolean: |
| 995 | case Primitive::kPrimByte: |
| 996 | case Primitive::kPrimChar: |
| 997 | case Primitive::kPrimShort: |
| 998 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
| 999 | break; |
| 1000 | |
| 1001 | default: |
| 1002 | LOG(FATAL) << "Unimplemented sub type " << sub->GetResultType(); |
| 1003 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1004 | } |
| 1005 | |
| 1006 | void InstructionCodeGeneratorX86_64::VisitSub(HSub* sub) { |
| 1007 | LocationSummary* locations = sub->GetLocations(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1008 | DCHECK_EQ(locations->InAt(0).As<CpuRegister>().AsRegister(), |
| 1009 | locations->Out().As<CpuRegister>().AsRegister()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1010 | switch (sub->GetResultType()) { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 1011 | case Primitive::kPrimInt: { |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1012 | if (locations->InAt(1).IsRegister()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1013 | __ subl(locations->InAt(0).As<CpuRegister>(), |
| 1014 | locations->InAt(1).As<CpuRegister>()); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1015 | } else if (locations->InAt(1).IsConstant()) { |
| 1016 | HConstant* instruction = locations->InAt(1).GetConstant(); |
| 1017 | Immediate imm(instruction->AsIntConstant()->GetValue()); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1018 | __ subl(locations->InAt(0).As<CpuRegister>(), imm); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1019 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1020 | __ subl(locations->InAt(0).As<CpuRegister>(), |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1021 | Address(CpuRegister(RSP), locations->InAt(1).GetStackIndex())); |
| 1022 | } |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 1023 | break; |
| 1024 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1025 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1026 | __ subq(locations->InAt(0).As<CpuRegister>(), |
| 1027 | locations->InAt(1).As<CpuRegister>()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1028 | break; |
| 1029 | } |
| 1030 | |
| 1031 | case Primitive::kPrimBoolean: |
| 1032 | case Primitive::kPrimByte: |
| 1033 | case Primitive::kPrimChar: |
| 1034 | case Primitive::kPrimShort: |
| 1035 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
| 1036 | break; |
| 1037 | |
| 1038 | default: |
| 1039 | LOG(FATAL) << "Unimplemented sub type " << sub->GetResultType(); |
| 1040 | } |
| 1041 | } |
| 1042 | |
| 1043 | void LocationsBuilderX86_64::VisitNewInstance(HNewInstance* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1044 | LocationSummary* locations = |
| 1045 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
Nicolas Geoffray | 9ae0daa | 2014-09-30 22:40:23 +0100 | [diff] [blame] | 1046 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1047 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 1048 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 1049 | locations->SetOut(Location::RegisterLocation(RAX)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1050 | } |
| 1051 | |
| 1052 | void InstructionCodeGeneratorX86_64::VisitNewInstance(HNewInstance* instruction) { |
| 1053 | InvokeRuntimeCallingConvention calling_convention; |
| 1054 | LoadCurrentMethod(CpuRegister(calling_convention.GetRegisterAt(1))); |
| 1055 | __ movq(CpuRegister(calling_convention.GetRegisterAt(0)), Immediate(instruction->GetTypeIndex())); |
| 1056 | |
| 1057 | __ gs()->call(Address::Absolute( |
| 1058 | QUICK_ENTRYPOINT_OFFSET(kX86_64WordSize, pAllocObjectWithAccessCheck), true)); |
| 1059 | |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 1060 | DCHECK(!codegen_->IsLeafMethod()); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1061 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1062 | } |
| 1063 | |
| 1064 | void LocationsBuilderX86_64::VisitParameterValue(HParameterValue* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1065 | LocationSummary* locations = |
| 1066 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1067 | Location location = parameter_visitor_.GetNextLocation(instruction->GetType()); |
| 1068 | if (location.IsStackSlot()) { |
| 1069 | location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 1070 | } else if (location.IsDoubleStackSlot()) { |
| 1071 | location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 1072 | } |
| 1073 | locations->SetOut(location); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1074 | } |
| 1075 | |
| 1076 | void InstructionCodeGeneratorX86_64::VisitParameterValue(HParameterValue* instruction) { |
| 1077 | // Nothing to do, the parameter is already at its location. |
| 1078 | } |
| 1079 | |
| 1080 | void LocationsBuilderX86_64::VisitNot(HNot* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1081 | LocationSummary* locations = |
| 1082 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 1083 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1084 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1085 | } |
| 1086 | |
| 1087 | void InstructionCodeGeneratorX86_64::VisitNot(HNot* instruction) { |
| 1088 | LocationSummary* locations = instruction->GetLocations(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1089 | DCHECK_EQ(locations->InAt(0).As<CpuRegister>().AsRegister(), |
| 1090 | locations->Out().As<CpuRegister>().AsRegister()); |
| 1091 | __ xorq(locations->Out().As<CpuRegister>(), Immediate(1)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1092 | } |
| 1093 | |
| 1094 | void LocationsBuilderX86_64::VisitPhi(HPhi* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1095 | LocationSummary* locations = |
| 1096 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1097 | for (size_t i = 0, e = instruction->InputCount(); i < e; ++i) { |
| 1098 | locations->SetInAt(i, Location::Any()); |
| 1099 | } |
| 1100 | locations->SetOut(Location::Any()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1101 | } |
| 1102 | |
| 1103 | void InstructionCodeGeneratorX86_64::VisitPhi(HPhi* instruction) { |
| 1104 | LOG(FATAL) << "Unimplemented"; |
| 1105 | } |
| 1106 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1107 | void LocationsBuilderX86_64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1108 | LocationSummary* locations = |
| 1109 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 9ae0daa | 2014-09-30 22:40:23 +0100 | [diff] [blame] | 1110 | Primitive::Type field_type = instruction->GetFieldType(); |
| 1111 | bool is_object_type = field_type == Primitive::kPrimNot; |
| 1112 | bool dies_at_entry = !is_object_type; |
| 1113 | locations->SetInAt(0, Location::RequiresRegister(), dies_at_entry); |
| 1114 | locations->SetInAt(1, Location::RequiresRegister(), dies_at_entry); |
| 1115 | if (is_object_type) { |
| 1116 | // Temporary registers for the write barrier. |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 1117 | locations->AddTemp(Location::RequiresRegister()); |
| 1118 | locations->AddTemp(Location::RequiresRegister()); |
| 1119 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1120 | } |
| 1121 | |
| 1122 | void InstructionCodeGeneratorX86_64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
| 1123 | LocationSummary* locations = instruction->GetLocations(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1124 | CpuRegister obj = locations->InAt(0).As<CpuRegister>(); |
| 1125 | CpuRegister value = locations->InAt(1).As<CpuRegister>(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1126 | size_t offset = instruction->GetFieldOffset().SizeValue(); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1127 | Primitive::Type field_type = instruction->GetFieldType(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1128 | |
| 1129 | switch (field_type) { |
| 1130 | case Primitive::kPrimBoolean: |
| 1131 | case Primitive::kPrimByte: { |
| 1132 | __ movb(Address(obj, offset), value); |
| 1133 | break; |
| 1134 | } |
| 1135 | |
| 1136 | case Primitive::kPrimShort: |
| 1137 | case Primitive::kPrimChar: { |
| 1138 | __ movw(Address(obj, offset), value); |
| 1139 | break; |
| 1140 | } |
| 1141 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1142 | case Primitive::kPrimInt: |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1143 | case Primitive::kPrimNot: { |
| 1144 | __ movl(Address(obj, offset), value); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1145 | if (field_type == Primitive::kPrimNot) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1146 | CpuRegister temp = locations->GetTemp(0).As<CpuRegister>(); |
| 1147 | CpuRegister card = locations->GetTemp(1).As<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1148 | codegen_->MarkGCCard(temp, card, obj, value); |
| 1149 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1150 | break; |
| 1151 | } |
| 1152 | |
| 1153 | case Primitive::kPrimLong: { |
| 1154 | __ movq(Address(obj, offset), value); |
| 1155 | break; |
| 1156 | } |
| 1157 | |
| 1158 | case Primitive::kPrimFloat: |
| 1159 | case Primitive::kPrimDouble: |
| 1160 | LOG(FATAL) << "Unimplemented register type " << field_type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame^] | 1161 | UNREACHABLE(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1162 | case Primitive::kPrimVoid: |
| 1163 | LOG(FATAL) << "Unreachable type " << field_type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame^] | 1164 | UNREACHABLE(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1165 | } |
| 1166 | } |
| 1167 | |
| 1168 | void LocationsBuilderX86_64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1169 | LocationSummary* locations = |
| 1170 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 9ae0daa | 2014-09-30 22:40:23 +0100 | [diff] [blame] | 1171 | locations->SetInAt(0, Location::RequiresRegister(), Location::kDiesAtEntry); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1172 | locations->SetOut(Location::RequiresRegister()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1173 | } |
| 1174 | |
| 1175 | void InstructionCodeGeneratorX86_64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 1176 | LocationSummary* locations = instruction->GetLocations(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1177 | CpuRegister obj = locations->InAt(0).As<CpuRegister>(); |
| 1178 | CpuRegister out = locations->Out().As<CpuRegister>(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1179 | size_t offset = instruction->GetFieldOffset().SizeValue(); |
| 1180 | |
| 1181 | switch (instruction->GetType()) { |
| 1182 | case Primitive::kPrimBoolean: { |
| 1183 | __ movzxb(out, Address(obj, offset)); |
| 1184 | break; |
| 1185 | } |
| 1186 | |
| 1187 | case Primitive::kPrimByte: { |
| 1188 | __ movsxb(out, Address(obj, offset)); |
| 1189 | break; |
| 1190 | } |
| 1191 | |
| 1192 | case Primitive::kPrimShort: { |
| 1193 | __ movsxw(out, Address(obj, offset)); |
| 1194 | break; |
| 1195 | } |
| 1196 | |
| 1197 | case Primitive::kPrimChar: { |
| 1198 | __ movzxw(out, Address(obj, offset)); |
| 1199 | break; |
| 1200 | } |
| 1201 | |
| 1202 | case Primitive::kPrimInt: |
| 1203 | case Primitive::kPrimNot: { |
| 1204 | __ movl(out, Address(obj, offset)); |
| 1205 | break; |
| 1206 | } |
| 1207 | |
| 1208 | case Primitive::kPrimLong: { |
| 1209 | __ movq(out, Address(obj, offset)); |
| 1210 | break; |
| 1211 | } |
| 1212 | |
| 1213 | case Primitive::kPrimFloat: |
| 1214 | case Primitive::kPrimDouble: |
| 1215 | LOG(FATAL) << "Unimplemented register type " << instruction->GetType(); |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame^] | 1216 | UNREACHABLE(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1217 | case Primitive::kPrimVoid: |
| 1218 | LOG(FATAL) << "Unreachable type " << instruction->GetType(); |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame^] | 1219 | UNREACHABLE(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1220 | } |
| 1221 | } |
| 1222 | |
| 1223 | void LocationsBuilderX86_64::VisitNullCheck(HNullCheck* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1224 | LocationSummary* locations = |
| 1225 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1226 | locations->SetInAt(0, Location::Any()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 1227 | if (instruction->HasUses()) { |
| 1228 | locations->SetOut(Location::SameAsFirstInput()); |
| 1229 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1230 | } |
| 1231 | |
| 1232 | void InstructionCodeGeneratorX86_64::VisitNullCheck(HNullCheck* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1233 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathX86_64(instruction); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1234 | codegen_->AddSlowPath(slow_path); |
| 1235 | |
| 1236 | LocationSummary* locations = instruction->GetLocations(); |
| 1237 | Location obj = locations->InAt(0); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1238 | |
| 1239 | if (obj.IsRegister()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1240 | __ cmpl(obj.As<CpuRegister>(), Immediate(0)); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 1241 | } else if (obj.IsStackSlot()) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1242 | __ cmpl(Address(CpuRegister(RSP), obj.GetStackIndex()), Immediate(0)); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 1243 | } else { |
| 1244 | DCHECK(obj.IsConstant()) << obj; |
| 1245 | DCHECK_EQ(obj.GetConstant()->AsIntConstant()->GetValue(), 0); |
| 1246 | __ jmp(slow_path->GetEntryLabel()); |
| 1247 | return; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1248 | } |
| 1249 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 1250 | } |
| 1251 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1252 | void LocationsBuilderX86_64::VisitArrayGet(HArrayGet* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1253 | LocationSummary* locations = |
| 1254 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 9ae0daa | 2014-09-30 22:40:23 +0100 | [diff] [blame] | 1255 | locations->SetInAt(0, Location::RequiresRegister(), Location::kDiesAtEntry); |
| 1256 | locations->SetInAt( |
| 1257 | 1, Location::RegisterOrConstant(instruction->InputAt(1)), Location::kDiesAtEntry); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1258 | locations->SetOut(Location::RequiresRegister()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1259 | } |
| 1260 | |
| 1261 | void InstructionCodeGeneratorX86_64::VisitArrayGet(HArrayGet* instruction) { |
| 1262 | LocationSummary* locations = instruction->GetLocations(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1263 | CpuRegister obj = locations->InAt(0).As<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1264 | Location index = locations->InAt(1); |
| 1265 | |
| 1266 | switch (instruction->GetType()) { |
| 1267 | case Primitive::kPrimBoolean: { |
| 1268 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1269 | CpuRegister out = locations->Out().As<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1270 | if (index.IsConstant()) { |
| 1271 | __ movzxb(out, Address(obj, |
| 1272 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset)); |
| 1273 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1274 | __ movzxb(out, Address(obj, index.As<CpuRegister>(), TIMES_1, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1275 | } |
| 1276 | break; |
| 1277 | } |
| 1278 | |
| 1279 | case Primitive::kPrimByte: { |
| 1280 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int8_t)).Uint32Value(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1281 | CpuRegister out = locations->Out().As<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1282 | if (index.IsConstant()) { |
| 1283 | __ movsxb(out, Address(obj, |
| 1284 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset)); |
| 1285 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1286 | __ movsxb(out, Address(obj, index.As<CpuRegister>(), TIMES_1, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1287 | } |
| 1288 | break; |
| 1289 | } |
| 1290 | |
| 1291 | case Primitive::kPrimShort: { |
| 1292 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int16_t)).Uint32Value(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1293 | CpuRegister out = locations->Out().As<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1294 | if (index.IsConstant()) { |
| 1295 | __ movsxw(out, Address(obj, |
| 1296 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset)); |
| 1297 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1298 | __ movsxw(out, Address(obj, index.As<CpuRegister>(), TIMES_2, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1299 | } |
| 1300 | break; |
| 1301 | } |
| 1302 | |
| 1303 | case Primitive::kPrimChar: { |
| 1304 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1305 | CpuRegister out = locations->Out().As<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1306 | if (index.IsConstant()) { |
| 1307 | __ movzxw(out, Address(obj, |
| 1308 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset)); |
| 1309 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1310 | __ movzxw(out, Address(obj, index.As<CpuRegister>(), TIMES_2, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1311 | } |
| 1312 | break; |
| 1313 | } |
| 1314 | |
| 1315 | case Primitive::kPrimInt: |
| 1316 | case Primitive::kPrimNot: { |
| 1317 | DCHECK_EQ(sizeof(mirror::HeapReference<mirror::Object>), sizeof(int32_t)); |
| 1318 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1319 | CpuRegister out = locations->Out().As<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1320 | if (index.IsConstant()) { |
| 1321 | __ movl(out, Address(obj, |
| 1322 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset)); |
| 1323 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1324 | __ movl(out, Address(obj, index.As<CpuRegister>(), TIMES_4, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1325 | } |
| 1326 | break; |
| 1327 | } |
| 1328 | |
| 1329 | case Primitive::kPrimLong: { |
| 1330 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1331 | CpuRegister out = locations->Out().As<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1332 | if (index.IsConstant()) { |
| 1333 | __ movq(out, Address(obj, |
| 1334 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset)); |
| 1335 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1336 | __ movq(out, Address(obj, index.As<CpuRegister>(), TIMES_8, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1337 | } |
| 1338 | break; |
| 1339 | } |
| 1340 | |
| 1341 | case Primitive::kPrimFloat: |
| 1342 | case Primitive::kPrimDouble: |
| 1343 | LOG(FATAL) << "Unimplemented register type " << instruction->GetType(); |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame^] | 1344 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1345 | case Primitive::kPrimVoid: |
| 1346 | LOG(FATAL) << "Unreachable type " << instruction->GetType(); |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame^] | 1347 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1348 | } |
| 1349 | } |
| 1350 | |
| 1351 | void LocationsBuilderX86_64::VisitArraySet(HArraySet* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1352 | Primitive::Type value_type = instruction->GetComponentType(); |
| 1353 | bool is_object = value_type == Primitive::kPrimNot; |
| 1354 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary( |
| 1355 | instruction, is_object ? LocationSummary::kCall : LocationSummary::kNoCall); |
| 1356 | if (is_object) { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1357 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1358 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 1359 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 1360 | locations->SetInAt(2, Location::RegisterLocation(calling_convention.GetRegisterAt(2))); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1361 | } else { |
Nicolas Geoffray | 9ae0daa | 2014-09-30 22:40:23 +0100 | [diff] [blame] | 1362 | locations->SetInAt(0, Location::RequiresRegister(), Location::kDiesAtEntry); |
| 1363 | locations->SetInAt( |
| 1364 | 1, Location::RegisterOrConstant(instruction->InputAt(1)), Location::kDiesAtEntry); |
| 1365 | locations->SetInAt(2, Location::RequiresRegister(), Location::kDiesAtEntry); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 1366 | if (value_type == Primitive::kPrimLong) { |
| 1367 | locations->SetInAt(2, Location::RequiresRegister(), Location::kDiesAtEntry); |
| 1368 | } else { |
| 1369 | locations->SetInAt(2, Location::RegisterOrConstant(instruction->InputAt(2)), Location::kDiesAtEntry); |
| 1370 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1371 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1372 | } |
| 1373 | |
| 1374 | void InstructionCodeGeneratorX86_64::VisitArraySet(HArraySet* instruction) { |
| 1375 | LocationSummary* locations = instruction->GetLocations(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1376 | CpuRegister obj = locations->InAt(0).As<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1377 | Location index = locations->InAt(1); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 1378 | Location value = locations->InAt(2); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1379 | Primitive::Type value_type = instruction->GetComponentType(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1380 | |
| 1381 | switch (value_type) { |
| 1382 | case Primitive::kPrimBoolean: |
| 1383 | case Primitive::kPrimByte: { |
| 1384 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1385 | if (index.IsConstant()) { |
| 1386 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset; |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 1387 | if (value.IsRegister()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1388 | __ movb(Address(obj, offset), value.As<CpuRegister>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 1389 | } else { |
| 1390 | __ movb(Address(obj, offset), Immediate(value.GetConstant()->AsIntConstant()->GetValue())); |
| 1391 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1392 | } else { |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 1393 | if (value.IsRegister()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1394 | __ movb(Address(obj, index.As<CpuRegister>(), TIMES_1, data_offset), |
| 1395 | value.As<CpuRegister>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 1396 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1397 | __ movb(Address(obj, index.As<CpuRegister>(), TIMES_1, data_offset), |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 1398 | Immediate(value.GetConstant()->AsIntConstant()->GetValue())); |
| 1399 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1400 | } |
| 1401 | break; |
| 1402 | } |
| 1403 | |
| 1404 | case Primitive::kPrimShort: |
| 1405 | case Primitive::kPrimChar: { |
| 1406 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1407 | if (index.IsConstant()) { |
| 1408 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset; |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 1409 | if (value.IsRegister()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1410 | __ movw(Address(obj, offset), value.As<CpuRegister>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 1411 | } else { |
| 1412 | __ movw(Address(obj, offset), Immediate(value.GetConstant()->AsIntConstant()->GetValue())); |
| 1413 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1414 | } else { |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 1415 | if (value.IsRegister()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1416 | __ movw(Address(obj, index.As<CpuRegister>(), TIMES_2, data_offset), |
| 1417 | value.As<CpuRegister>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 1418 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1419 | __ movw(Address(obj, index.As<CpuRegister>(), TIMES_2, data_offset), |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 1420 | Immediate(value.GetConstant()->AsIntConstant()->GetValue())); |
| 1421 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1422 | } |
| 1423 | break; |
| 1424 | } |
| 1425 | |
| 1426 | case Primitive::kPrimInt: { |
| 1427 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1428 | if (index.IsConstant()) { |
| 1429 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 1430 | if (value.IsRegister()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1431 | __ movl(Address(obj, offset), value.As<CpuRegister>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 1432 | } else { |
| 1433 | __ movl(Address(obj, offset), Immediate(value.GetConstant()->AsIntConstant()->GetValue())); |
| 1434 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1435 | } else { |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 1436 | if (value.IsRegister()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1437 | __ movl(Address(obj, index.As<CpuRegister>(), TIMES_4, data_offset), |
| 1438 | value.As<CpuRegister>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 1439 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1440 | __ movl(Address(obj, index.As<CpuRegister>(), TIMES_4, data_offset), |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 1441 | Immediate(value.GetConstant()->AsIntConstant()->GetValue())); |
| 1442 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1443 | } |
| 1444 | break; |
| 1445 | } |
| 1446 | |
| 1447 | case Primitive::kPrimNot: { |
| 1448 | __ gs()->call(Address::Absolute(QUICK_ENTRYPOINT_OFFSET(kX86_64WordSize, pAputObject), true)); |
| 1449 | DCHECK(!codegen_->IsLeafMethod()); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1450 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1451 | break; |
| 1452 | } |
| 1453 | |
| 1454 | case Primitive::kPrimLong: { |
| 1455 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1456 | if (index.IsConstant()) { |
| 1457 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 1458 | DCHECK(value.IsRegister()); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1459 | __ movq(Address(obj, offset), value.As<CpuRegister>()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1460 | } else { |
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, index.As<CpuRegister>(), TIMES_8, data_offset), |
| 1463 | value.As<CpuRegister>()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1464 | } |
| 1465 | break; |
| 1466 | } |
| 1467 | |
| 1468 | case Primitive::kPrimFloat: |
| 1469 | case Primitive::kPrimDouble: |
| 1470 | LOG(FATAL) << "Unimplemented register type " << instruction->GetType(); |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame^] | 1471 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1472 | case Primitive::kPrimVoid: |
| 1473 | LOG(FATAL) << "Unreachable type " << instruction->GetType(); |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame^] | 1474 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1475 | } |
| 1476 | } |
| 1477 | |
| 1478 | void LocationsBuilderX86_64::VisitArrayLength(HArrayLength* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1479 | LocationSummary* locations = |
| 1480 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 9ae0daa | 2014-09-30 22:40:23 +0100 | [diff] [blame] | 1481 | locations->SetInAt(0, Location::RequiresRegister(), Location::kDiesAtEntry); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1482 | locations->SetOut(Location::RequiresRegister()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1483 | } |
| 1484 | |
| 1485 | void InstructionCodeGeneratorX86_64::VisitArrayLength(HArrayLength* instruction) { |
| 1486 | LocationSummary* locations = instruction->GetLocations(); |
| 1487 | uint32_t offset = mirror::Array::LengthOffset().Uint32Value(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1488 | CpuRegister obj = locations->InAt(0).As<CpuRegister>(); |
| 1489 | CpuRegister out = locations->Out().As<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1490 | __ movl(out, Address(obj, offset)); |
| 1491 | } |
| 1492 | |
| 1493 | void LocationsBuilderX86_64::VisitBoundsCheck(HBoundsCheck* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1494 | LocationSummary* locations = |
| 1495 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1496 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1497 | locations->SetInAt(1, Location::RequiresRegister()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 1498 | if (instruction->HasUses()) { |
| 1499 | locations->SetOut(Location::SameAsFirstInput()); |
| 1500 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1501 | } |
| 1502 | |
| 1503 | void InstructionCodeGeneratorX86_64::VisitBoundsCheck(HBoundsCheck* instruction) { |
| 1504 | LocationSummary* locations = instruction->GetLocations(); |
| 1505 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) BoundsCheckSlowPathX86_64( |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1506 | instruction, locations->InAt(0), locations->InAt(1)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1507 | codegen_->AddSlowPath(slow_path); |
| 1508 | |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1509 | CpuRegister index = locations->InAt(0).As<CpuRegister>(); |
| 1510 | CpuRegister length = locations->InAt(1).As<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1511 | |
| 1512 | __ cmpl(index, length); |
| 1513 | __ j(kAboveEqual, slow_path->GetEntryLabel()); |
| 1514 | } |
| 1515 | |
| 1516 | void CodeGeneratorX86_64::MarkGCCard(CpuRegister temp, |
| 1517 | CpuRegister card, |
| 1518 | CpuRegister object, |
| 1519 | CpuRegister value) { |
| 1520 | Label is_null; |
| 1521 | __ testl(value, value); |
| 1522 | __ j(kEqual, &is_null); |
| 1523 | __ gs()->movq(card, Address::Absolute( |
| 1524 | Thread::CardTableOffset<kX86_64WordSize>().Int32Value(), true)); |
| 1525 | __ movq(temp, object); |
| 1526 | __ shrq(temp, Immediate(gc::accounting::CardTable::kCardShift)); |
| 1527 | __ movb(Address(temp, card, TIMES_1, 0), card); |
| 1528 | __ Bind(&is_null); |
| 1529 | } |
| 1530 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1531 | void LocationsBuilderX86_64::VisitTemporary(HTemporary* temp) { |
| 1532 | temp->SetLocations(nullptr); |
| 1533 | } |
| 1534 | |
| 1535 | void InstructionCodeGeneratorX86_64::VisitTemporary(HTemporary* temp) { |
| 1536 | // Nothing to do, this is driven by the code generator. |
| 1537 | } |
| 1538 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1539 | void LocationsBuilderX86_64::VisitParallelMove(HParallelMove* instruction) { |
| 1540 | LOG(FATAL) << "Unimplemented"; |
| 1541 | } |
| 1542 | |
| 1543 | void InstructionCodeGeneratorX86_64::VisitParallelMove(HParallelMove* instruction) { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 1544 | codegen_->GetMoveResolver()->EmitNativeCode(instruction); |
| 1545 | } |
| 1546 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 1547 | void LocationsBuilderX86_64::VisitSuspendCheck(HSuspendCheck* instruction) { |
| 1548 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath); |
| 1549 | } |
| 1550 | |
| 1551 | void InstructionCodeGeneratorX86_64::VisitSuspendCheck(HSuspendCheck* instruction) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1552 | HBasicBlock* block = instruction->GetBlock(); |
| 1553 | if (block->GetLoopInformation() != nullptr) { |
| 1554 | DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction); |
| 1555 | // The back edge will generate the suspend check. |
| 1556 | return; |
| 1557 | } |
| 1558 | if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) { |
| 1559 | // The goto will generate the suspend check. |
| 1560 | return; |
| 1561 | } |
| 1562 | GenerateSuspendCheck(instruction, nullptr); |
| 1563 | } |
| 1564 | |
| 1565 | void InstructionCodeGeneratorX86_64::GenerateSuspendCheck(HSuspendCheck* instruction, |
| 1566 | HBasicBlock* successor) { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 1567 | SuspendCheckSlowPathX86_64* slow_path = |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1568 | new (GetGraph()->GetArena()) SuspendCheckSlowPathX86_64(instruction, successor); |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 1569 | codegen_->AddSlowPath(slow_path); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1570 | __ gs()->cmpw(Address::Absolute( |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 1571 | Thread::ThreadFlagsOffset<kX86_64WordSize>().Int32Value(), true), Immediate(0)); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1572 | if (successor == nullptr) { |
| 1573 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 1574 | __ Bind(slow_path->GetReturnLabel()); |
| 1575 | } else { |
| 1576 | __ j(kEqual, codegen_->GetLabelOf(successor)); |
| 1577 | __ jmp(slow_path->GetEntryLabel()); |
| 1578 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 1579 | } |
| 1580 | |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 1581 | X86_64Assembler* ParallelMoveResolverX86_64::GetAssembler() const { |
| 1582 | return codegen_->GetAssembler(); |
| 1583 | } |
| 1584 | |
| 1585 | void ParallelMoveResolverX86_64::EmitMove(size_t index) { |
| 1586 | MoveOperands* move = moves_.Get(index); |
| 1587 | Location source = move->GetSource(); |
| 1588 | Location destination = move->GetDestination(); |
| 1589 | |
| 1590 | if (source.IsRegister()) { |
| 1591 | if (destination.IsRegister()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1592 | __ movq(destination.As<CpuRegister>(), source.As<CpuRegister>()); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1593 | } else if (destination.IsStackSlot()) { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 1594 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1595 | source.As<CpuRegister>()); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1596 | } else { |
| 1597 | DCHECK(destination.IsDoubleStackSlot()); |
| 1598 | __ movq(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1599 | source.As<CpuRegister>()); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 1600 | } |
| 1601 | } else if (source.IsStackSlot()) { |
| 1602 | if (destination.IsRegister()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1603 | __ movl(destination.As<CpuRegister>(), |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 1604 | Address(CpuRegister(RSP), source.GetStackIndex())); |
| 1605 | } else { |
| 1606 | DCHECK(destination.IsStackSlot()); |
| 1607 | __ movl(CpuRegister(TMP), Address(CpuRegister(RSP), source.GetStackIndex())); |
| 1608 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), CpuRegister(TMP)); |
| 1609 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1610 | } else if (source.IsDoubleStackSlot()) { |
| 1611 | if (destination.IsRegister()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1612 | __ movq(destination.As<CpuRegister>(), |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1613 | Address(CpuRegister(RSP), source.GetStackIndex())); |
| 1614 | } else { |
| 1615 | DCHECK(destination.IsDoubleStackSlot()); |
| 1616 | __ movq(CpuRegister(TMP), Address(CpuRegister(RSP), source.GetStackIndex())); |
| 1617 | __ movq(Address(CpuRegister(RSP), destination.GetStackIndex()), CpuRegister(TMP)); |
| 1618 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1619 | } else if (source.IsConstant()) { |
| 1620 | HConstant* constant = source.GetConstant(); |
| 1621 | if (constant->IsIntConstant()) { |
| 1622 | Immediate imm(constant->AsIntConstant()->GetValue()); |
| 1623 | if (destination.IsRegister()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1624 | __ movl(destination.As<CpuRegister>(), imm); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1625 | } else { |
| 1626 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), imm); |
| 1627 | } |
| 1628 | } else if (constant->IsLongConstant()) { |
| 1629 | int64_t value = constant->AsLongConstant()->GetValue(); |
| 1630 | if (destination.IsRegister()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1631 | __ movq(destination.As<CpuRegister>(), Immediate(value)); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1632 | } else { |
| 1633 | __ movq(CpuRegister(TMP), Immediate(value)); |
| 1634 | __ movq(Address(CpuRegister(RSP), destination.GetStackIndex()), CpuRegister(TMP)); |
| 1635 | } |
| 1636 | } else { |
| 1637 | LOG(FATAL) << "Unimplemented constant type"; |
| 1638 | } |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 1639 | } else { |
| 1640 | LOG(FATAL) << "Unimplemented"; |
| 1641 | } |
| 1642 | } |
| 1643 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1644 | void ParallelMoveResolverX86_64::Exchange32(CpuRegister reg, int mem) { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 1645 | __ movl(CpuRegister(TMP), Address(CpuRegister(RSP), mem)); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1646 | __ movl(Address(CpuRegister(RSP), mem), reg); |
| 1647 | __ movl(reg, CpuRegister(TMP)); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 1648 | } |
| 1649 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1650 | void ParallelMoveResolverX86_64::Exchange32(int mem1, int mem2) { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 1651 | ScratchRegisterScope ensure_scratch( |
| 1652 | this, TMP, RAX, codegen_->GetNumberOfCoreRegisters()); |
| 1653 | |
| 1654 | int stack_offset = ensure_scratch.IsSpilled() ? kX86_64WordSize : 0; |
| 1655 | __ movl(CpuRegister(TMP), Address(CpuRegister(RSP), mem1 + stack_offset)); |
| 1656 | __ movl(CpuRegister(ensure_scratch.GetRegister()), |
| 1657 | Address(CpuRegister(RSP), mem2 + stack_offset)); |
| 1658 | __ movl(Address(CpuRegister(RSP), mem2 + stack_offset), CpuRegister(TMP)); |
| 1659 | __ movl(Address(CpuRegister(RSP), mem1 + stack_offset), |
| 1660 | CpuRegister(ensure_scratch.GetRegister())); |
| 1661 | } |
| 1662 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1663 | void ParallelMoveResolverX86_64::Exchange64(CpuRegister reg, int mem) { |
| 1664 | __ movq(CpuRegister(TMP), Address(CpuRegister(RSP), mem)); |
| 1665 | __ movq(Address(CpuRegister(RSP), mem), reg); |
| 1666 | __ movq(reg, CpuRegister(TMP)); |
| 1667 | } |
| 1668 | |
| 1669 | void ParallelMoveResolverX86_64::Exchange64(int mem1, int mem2) { |
| 1670 | ScratchRegisterScope ensure_scratch( |
| 1671 | this, TMP, RAX, codegen_->GetNumberOfCoreRegisters()); |
| 1672 | |
| 1673 | int stack_offset = ensure_scratch.IsSpilled() ? kX86_64WordSize : 0; |
| 1674 | __ movq(CpuRegister(TMP), Address(CpuRegister(RSP), mem1 + stack_offset)); |
| 1675 | __ movq(CpuRegister(ensure_scratch.GetRegister()), |
| 1676 | Address(CpuRegister(RSP), mem2 + stack_offset)); |
| 1677 | __ movq(Address(CpuRegister(RSP), mem2 + stack_offset), CpuRegister(TMP)); |
| 1678 | __ movq(Address(CpuRegister(RSP), mem1 + stack_offset), |
| 1679 | CpuRegister(ensure_scratch.GetRegister())); |
| 1680 | } |
| 1681 | |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 1682 | void ParallelMoveResolverX86_64::EmitSwap(size_t index) { |
| 1683 | MoveOperands* move = moves_.Get(index); |
| 1684 | Location source = move->GetSource(); |
| 1685 | Location destination = move->GetDestination(); |
| 1686 | |
| 1687 | if (source.IsRegister() && destination.IsRegister()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1688 | __ xchgq(destination.As<CpuRegister>(), source.As<CpuRegister>()); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 1689 | } else if (source.IsRegister() && destination.IsStackSlot()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1690 | Exchange32(source.As<CpuRegister>(), destination.GetStackIndex()); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 1691 | } else if (source.IsStackSlot() && destination.IsRegister()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1692 | Exchange32(destination.As<CpuRegister>(), source.GetStackIndex()); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 1693 | } else if (source.IsStackSlot() && destination.IsStackSlot()) { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1694 | Exchange32(destination.GetStackIndex(), source.GetStackIndex()); |
| 1695 | } else if (source.IsRegister() && destination.IsDoubleStackSlot()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1696 | Exchange64(source.As<CpuRegister>(), destination.GetStackIndex()); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1697 | } else if (source.IsDoubleStackSlot() && destination.IsRegister()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1698 | Exchange64(destination.As<CpuRegister>(), source.GetStackIndex()); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1699 | } else if (source.IsDoubleStackSlot() && destination.IsDoubleStackSlot()) { |
| 1700 | Exchange64(destination.GetStackIndex(), source.GetStackIndex()); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 1701 | } else { |
| 1702 | LOG(FATAL) << "Unimplemented"; |
| 1703 | } |
| 1704 | } |
| 1705 | |
| 1706 | |
| 1707 | void ParallelMoveResolverX86_64::SpillScratch(int reg) { |
| 1708 | __ pushq(CpuRegister(reg)); |
| 1709 | } |
| 1710 | |
| 1711 | |
| 1712 | void ParallelMoveResolverX86_64::RestoreScratch(int reg) { |
| 1713 | __ popq(CpuRegister(reg)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1714 | } |
| 1715 | |
| 1716 | } // namespace x86_64 |
| 1717 | } // namespace art |