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