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 | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame^] | 154 | x64_codegen->Move( |
| 155 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), index_location_); |
| 156 | x64_codegen->Move( |
| 157 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), length_location_); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 158 | __ gs()->call(Address::Absolute( |
| 159 | QUICK_ENTRYPOINT_OFFSET(kX86_64WordSize, pThrowArrayBounds), true)); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 160 | codegen->RecordPcInfo(instruction_, instruction_->GetDexPc()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 161 | } |
| 162 | |
| 163 | private: |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 164 | HBoundsCheck* const instruction_; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 165 | const Location index_location_; |
| 166 | const Location length_location_; |
| 167 | |
| 168 | DISALLOW_COPY_AND_ASSIGN(BoundsCheckSlowPathX86_64); |
| 169 | }; |
| 170 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame^] | 171 | class ClinitCheckSlowPathX86_64 : public SlowPathCodeX86_64 { |
| 172 | public: |
| 173 | explicit ClinitCheckSlowPathX86_64(HClinitCheck* instruction) : instruction_(instruction) {} |
| 174 | |
| 175 | virtual void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 176 | CodeGeneratorX86_64* x64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
| 177 | __ Bind(GetEntryLabel()); |
| 178 | codegen->SaveLiveRegisters(instruction_->GetLocations()); |
| 179 | |
| 180 | HLoadClass* cls = instruction_->GetLoadClass(); |
| 181 | InvokeRuntimeCallingConvention calling_convention; |
| 182 | __ movl(CpuRegister(calling_convention.GetRegisterAt(0)), Immediate(cls->GetTypeIndex())); |
| 183 | x64_codegen->LoadCurrentMethod(CpuRegister(calling_convention.GetRegisterAt(1))); |
| 184 | __ gs()->call(Address::Absolute( |
| 185 | QUICK_ENTRYPOINT_OFFSET(kX86_64WordSize, pInitializeStaticStorage), true)); |
| 186 | |
| 187 | codegen->RecordPcInfo(instruction_, instruction_->GetDexPc()); |
| 188 | x64_codegen->Move(instruction_->GetLocations()->InAt(0), Location::RegisterLocation(RAX)); |
| 189 | codegen->RestoreLiveRegisters(instruction_->GetLocations()); |
| 190 | __ jmp(GetExitLabel()); |
| 191 | } |
| 192 | |
| 193 | private: |
| 194 | HClinitCheck* const instruction_; |
| 195 | |
| 196 | DISALLOW_COPY_AND_ASSIGN(ClinitCheckSlowPathX86_64); |
| 197 | }; |
| 198 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 199 | #undef __ |
| 200 | #define __ reinterpret_cast<X86_64Assembler*>(GetAssembler())-> |
| 201 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 202 | inline Condition X86_64Condition(IfCondition cond) { |
| 203 | switch (cond) { |
| 204 | case kCondEQ: return kEqual; |
| 205 | case kCondNE: return kNotEqual; |
| 206 | case kCondLT: return kLess; |
| 207 | case kCondLE: return kLessEqual; |
| 208 | case kCondGT: return kGreater; |
| 209 | case kCondGE: return kGreaterEqual; |
| 210 | default: |
| 211 | LOG(FATAL) << "Unknown if condition"; |
| 212 | } |
| 213 | return kEqual; |
| 214 | } |
| 215 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 216 | void CodeGeneratorX86_64::DumpCoreRegister(std::ostream& stream, int reg) const { |
| 217 | stream << X86_64ManagedRegister::FromCpuRegister(Register(reg)); |
| 218 | } |
| 219 | |
| 220 | void CodeGeneratorX86_64::DumpFloatingPointRegister(std::ostream& stream, int reg) const { |
| 221 | stream << X86_64ManagedRegister::FromXmmRegister(FloatRegister(reg)); |
| 222 | } |
| 223 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 224 | size_t CodeGeneratorX86_64::SaveCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 225 | __ movq(Address(CpuRegister(RSP), stack_index), CpuRegister(reg_id)); |
| 226 | return kX86_64WordSize; |
Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 227 | } |
| 228 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 229 | size_t CodeGeneratorX86_64::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 230 | __ movq(CpuRegister(reg_id), Address(CpuRegister(RSP), stack_index)); |
| 231 | return kX86_64WordSize; |
| 232 | } |
| 233 | |
| 234 | size_t CodeGeneratorX86_64::SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| 235 | __ movsd(Address(CpuRegister(RSP), stack_index), XmmRegister(reg_id)); |
| 236 | return kX86_64WordSize; |
| 237 | } |
| 238 | |
| 239 | size_t CodeGeneratorX86_64::RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| 240 | __ movsd(XmmRegister(reg_id), Address(CpuRegister(RSP), stack_index)); |
| 241 | return kX86_64WordSize; |
Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 242 | } |
| 243 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 244 | CodeGeneratorX86_64::CodeGeneratorX86_64(HGraph* graph) |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 245 | : CodeGenerator(graph, kNumberOfCpuRegisters, kNumberOfFloatRegisters, 0), |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 246 | block_labels_(graph->GetArena(), 0), |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 247 | location_builder_(graph, this), |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 248 | instruction_visitor_(graph, this), |
| 249 | move_resolver_(graph->GetArena(), this) {} |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 250 | |
Nicolas Geoffray | ab032bc | 2014-07-15 12:55:21 +0100 | [diff] [blame] | 251 | size_t CodeGeneratorX86_64::FrameEntrySpillSize() const { |
| 252 | return kNumberOfPushedRegistersAtEntry * kX86_64WordSize; |
| 253 | } |
| 254 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 255 | InstructionCodeGeneratorX86_64::InstructionCodeGeneratorX86_64(HGraph* graph, |
| 256 | CodeGeneratorX86_64* codegen) |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 257 | : HGraphVisitor(graph), |
| 258 | assembler_(codegen->GetAssembler()), |
| 259 | codegen_(codegen) {} |
| 260 | |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 261 | Location CodeGeneratorX86_64::AllocateFreeRegister(Primitive::Type type) const { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 262 | switch (type) { |
| 263 | case Primitive::kPrimLong: |
| 264 | case Primitive::kPrimByte: |
| 265 | case Primitive::kPrimBoolean: |
| 266 | case Primitive::kPrimChar: |
| 267 | case Primitive::kPrimShort: |
| 268 | case Primitive::kPrimInt: |
| 269 | case Primitive::kPrimNot: { |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 270 | size_t reg = FindFreeEntry(blocked_core_registers_, kNumberOfCpuRegisters); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 271 | return Location::RegisterLocation(reg); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 272 | } |
| 273 | |
| 274 | case Primitive::kPrimFloat: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 275 | case Primitive::kPrimDouble: { |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 276 | size_t reg = FindFreeEntry(blocked_fpu_registers_, kNumberOfFloatRegisters); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 277 | return Location::FpuRegisterLocation(reg); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 278 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 279 | |
| 280 | case Primitive::kPrimVoid: |
| 281 | LOG(FATAL) << "Unreachable type " << type; |
| 282 | } |
| 283 | |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 284 | return Location(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 285 | } |
| 286 | |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 287 | void CodeGeneratorX86_64::SetupBlockedRegisters() const { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 288 | // Stack register is always reserved. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 289 | blocked_core_registers_[RSP] = true; |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 290 | |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 291 | // Block the register used as TMP. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 292 | blocked_core_registers_[TMP] = true; |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 293 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 294 | // TODO: We currently don't use Quick's callee saved registers. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 295 | blocked_core_registers_[RBX] = true; |
| 296 | blocked_core_registers_[RBP] = true; |
| 297 | blocked_core_registers_[R12] = true; |
| 298 | blocked_core_registers_[R13] = true; |
| 299 | blocked_core_registers_[R14] = true; |
| 300 | blocked_core_registers_[R15] = true; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 301 | |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 302 | blocked_fpu_registers_[XMM12] = true; |
| 303 | blocked_fpu_registers_[XMM13] = true; |
| 304 | blocked_fpu_registers_[XMM14] = true; |
| 305 | blocked_fpu_registers_[XMM15] = true; |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 306 | } |
| 307 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 308 | void CodeGeneratorX86_64::GenerateFrameEntry() { |
| 309 | // Create a fake register to mimic Quick. |
| 310 | static const int kFakeReturnRegister = 16; |
| 311 | core_spill_mask_ |= (1 << kFakeReturnRegister); |
| 312 | |
Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 313 | bool skip_overflow_check = IsLeafMethod() |
Dave Allison | 648d711 | 2014-07-25 16:15:27 -0700 | [diff] [blame] | 314 | && !FrameNeedsStackCheck(GetFrameSize(), InstructionSet::kX86_64); |
Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 315 | |
| 316 | if (!skip_overflow_check && !kExplicitStackOverflowCheck) { |
| 317 | __ testq(CpuRegister(RAX), Address( |
| 318 | CpuRegister(RSP), -static_cast<int32_t>(GetStackOverflowReservedBytes(kX86_64)))); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 319 | RecordPcInfo(nullptr, 0); |
Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 320 | } |
| 321 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 322 | // The return PC has already been pushed on the stack. |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 323 | __ subq(CpuRegister(RSP), |
| 324 | Immediate(GetFrameSize() - kNumberOfPushedRegistersAtEntry * kX86_64WordSize)); |
| 325 | |
Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 326 | if (!skip_overflow_check && kExplicitStackOverflowCheck) { |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 327 | SlowPathCodeX86_64* slow_path = new (GetGraph()->GetArena()) StackOverflowCheckSlowPathX86_64(); |
Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 328 | AddSlowPath(slow_path); |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 329 | |
Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 330 | __ gs()->cmpq(CpuRegister(RSP), |
| 331 | Address::Absolute(Thread::StackEndOffset<kX86_64WordSize>(), true)); |
| 332 | __ j(kLess, slow_path->GetEntryLabel()); |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 333 | } |
| 334 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 335 | __ movl(Address(CpuRegister(RSP), kCurrentMethodStackOffset), CpuRegister(RDI)); |
| 336 | } |
| 337 | |
| 338 | void CodeGeneratorX86_64::GenerateFrameExit() { |
| 339 | __ addq(CpuRegister(RSP), |
| 340 | Immediate(GetFrameSize() - kNumberOfPushedRegistersAtEntry * kX86_64WordSize)); |
| 341 | } |
| 342 | |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 343 | void CodeGeneratorX86_64::Bind(HBasicBlock* block) { |
| 344 | __ Bind(GetLabelOf(block)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 345 | } |
| 346 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame^] | 347 | void CodeGeneratorX86_64::LoadCurrentMethod(CpuRegister reg) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 348 | __ movl(reg, Address(CpuRegister(RSP), kCurrentMethodStackOffset)); |
| 349 | } |
| 350 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 351 | Location CodeGeneratorX86_64::GetStackLocation(HLoadLocal* load) const { |
| 352 | switch (load->GetType()) { |
| 353 | case Primitive::kPrimLong: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 354 | case Primitive::kPrimDouble: |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 355 | return Location::DoubleStackSlot(GetStackSlot(load->GetLocal())); |
| 356 | break; |
| 357 | |
| 358 | case Primitive::kPrimInt: |
| 359 | case Primitive::kPrimNot: |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 360 | case Primitive::kPrimFloat: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 361 | return Location::StackSlot(GetStackSlot(load->GetLocal())); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 362 | |
| 363 | case Primitive::kPrimBoolean: |
| 364 | case Primitive::kPrimByte: |
| 365 | case Primitive::kPrimChar: |
| 366 | case Primitive::kPrimShort: |
| 367 | case Primitive::kPrimVoid: |
| 368 | LOG(FATAL) << "Unexpected type " << load->GetType(); |
| 369 | } |
| 370 | |
| 371 | LOG(FATAL) << "Unreachable"; |
| 372 | return Location(); |
| 373 | } |
| 374 | |
| 375 | void CodeGeneratorX86_64::Move(Location destination, Location source) { |
| 376 | if (source.Equals(destination)) { |
| 377 | return; |
| 378 | } |
| 379 | if (destination.IsRegister()) { |
| 380 | if (source.IsRegister()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 381 | __ movq(destination.As<CpuRegister>(), source.As<CpuRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 382 | } else if (source.IsFpuRegister()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 383 | __ movd(destination.As<CpuRegister>(), source.As<XmmRegister>()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 384 | } else if (source.IsStackSlot()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 385 | __ movl(destination.As<CpuRegister>(), |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 386 | Address(CpuRegister(RSP), source.GetStackIndex())); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 387 | } else { |
| 388 | DCHECK(source.IsDoubleStackSlot()); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 389 | __ movq(destination.As<CpuRegister>(), |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 390 | Address(CpuRegister(RSP), source.GetStackIndex())); |
| 391 | } |
| 392 | } else if (destination.IsFpuRegister()) { |
| 393 | if (source.IsRegister()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 394 | __ movd(destination.As<XmmRegister>(), source.As<CpuRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 395 | } else if (source.IsFpuRegister()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 396 | __ movaps(destination.As<XmmRegister>(), source.As<XmmRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 397 | } else if (source.IsStackSlot()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 398 | __ movss(destination.As<XmmRegister>(), |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 399 | Address(CpuRegister(RSP), source.GetStackIndex())); |
| 400 | } else { |
| 401 | DCHECK(source.IsDoubleStackSlot()); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 402 | __ movsd(destination.As<XmmRegister>(), |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 403 | Address(CpuRegister(RSP), source.GetStackIndex())); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 404 | } |
| 405 | } else if (destination.IsStackSlot()) { |
| 406 | if (source.IsRegister()) { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 407 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 408 | source.As<CpuRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 409 | } else if (source.IsFpuRegister()) { |
| 410 | __ movss(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 411 | source.As<XmmRegister>()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 412 | } else { |
| 413 | DCHECK(source.IsStackSlot()); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 414 | __ movl(CpuRegister(TMP), Address(CpuRegister(RSP), source.GetStackIndex())); |
| 415 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), CpuRegister(TMP)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 416 | } |
| 417 | } else { |
| 418 | DCHECK(destination.IsDoubleStackSlot()); |
| 419 | if (source.IsRegister()) { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 420 | __ movq(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 421 | source.As<CpuRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 422 | } else if (source.IsFpuRegister()) { |
| 423 | __ movsd(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 424 | source.As<XmmRegister>()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 425 | } else { |
| 426 | DCHECK(source.IsDoubleStackSlot()); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 427 | __ movq(CpuRegister(TMP), Address(CpuRegister(RSP), source.GetStackIndex())); |
| 428 | __ movq(Address(CpuRegister(RSP), destination.GetStackIndex()), CpuRegister(TMP)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 429 | } |
| 430 | } |
| 431 | } |
| 432 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 433 | void CodeGeneratorX86_64::Move(HInstruction* instruction, |
| 434 | Location location, |
| 435 | HInstruction* move_for) { |
Roland Levillain | 476df55 | 2014-10-09 17:51:36 +0100 | [diff] [blame] | 436 | if (instruction->IsIntConstant()) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 437 | Immediate imm(instruction->AsIntConstant()->GetValue()); |
| 438 | if (location.IsRegister()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 439 | __ movl(location.As<CpuRegister>(), imm); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 440 | } else if (location.IsStackSlot()) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 441 | __ movl(Address(CpuRegister(RSP), location.GetStackIndex()), imm); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 442 | } else { |
| 443 | DCHECK(location.IsConstant()); |
| 444 | DCHECK_EQ(location.GetConstant(), instruction); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 445 | } |
Roland Levillain | 476df55 | 2014-10-09 17:51:36 +0100 | [diff] [blame] | 446 | } else if (instruction->IsLongConstant()) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 447 | int64_t value = instruction->AsLongConstant()->GetValue(); |
| 448 | if (location.IsRegister()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 449 | __ movq(location.As<CpuRegister>(), Immediate(value)); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 450 | } else if (location.IsDoubleStackSlot()) { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 451 | __ movq(CpuRegister(TMP), Immediate(value)); |
| 452 | __ movq(Address(CpuRegister(RSP), location.GetStackIndex()), CpuRegister(TMP)); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 453 | } else { |
| 454 | DCHECK(location.IsConstant()); |
| 455 | DCHECK_EQ(location.GetConstant(), instruction); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 456 | } |
Roland Levillain | 476df55 | 2014-10-09 17:51:36 +0100 | [diff] [blame] | 457 | } else if (instruction->IsLoadLocal()) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 458 | switch (instruction->GetType()) { |
| 459 | case Primitive::kPrimBoolean: |
| 460 | case Primitive::kPrimByte: |
| 461 | case Primitive::kPrimChar: |
| 462 | case Primitive::kPrimShort: |
| 463 | case Primitive::kPrimInt: |
| 464 | case Primitive::kPrimNot: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 465 | case Primitive::kPrimFloat: |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 466 | Move(location, Location::StackSlot(GetStackSlot(instruction->AsLoadLocal()->GetLocal()))); |
| 467 | break; |
| 468 | |
| 469 | case Primitive::kPrimLong: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 470 | case Primitive::kPrimDouble: |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 471 | Move(location, Location::DoubleStackSlot(GetStackSlot(instruction->AsLoadLocal()->GetLocal()))); |
| 472 | break; |
| 473 | |
| 474 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 475 | LOG(FATAL) << "Unexpected local type " << instruction->GetType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 476 | } |
| 477 | } else { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 478 | DCHECK((instruction->GetNext() == move_for) || instruction->GetNext()->IsTemporary()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 479 | switch (instruction->GetType()) { |
| 480 | case Primitive::kPrimBoolean: |
| 481 | case Primitive::kPrimByte: |
| 482 | case Primitive::kPrimChar: |
| 483 | case Primitive::kPrimShort: |
| 484 | case Primitive::kPrimInt: |
| 485 | case Primitive::kPrimNot: |
| 486 | case Primitive::kPrimLong: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 487 | case Primitive::kPrimFloat: |
| 488 | case Primitive::kPrimDouble: |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 489 | Move(location, instruction->GetLocations()->Out()); |
| 490 | break; |
| 491 | |
| 492 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 493 | LOG(FATAL) << "Unexpected type " << instruction->GetType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 494 | } |
| 495 | } |
| 496 | } |
| 497 | |
| 498 | void LocationsBuilderX86_64::VisitGoto(HGoto* got) { |
| 499 | got->SetLocations(nullptr); |
| 500 | } |
| 501 | |
| 502 | void InstructionCodeGeneratorX86_64::VisitGoto(HGoto* got) { |
| 503 | HBasicBlock* successor = got->GetSuccessor(); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 504 | DCHECK(!successor->IsExitBlock()); |
| 505 | |
| 506 | HBasicBlock* block = got->GetBlock(); |
| 507 | HInstruction* previous = got->GetPrevious(); |
| 508 | |
| 509 | HLoopInformation* info = block->GetLoopInformation(); |
| 510 | if (info != nullptr && info->IsBackEdge(block) && info->HasSuspendCheck()) { |
| 511 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(info->GetSuspendCheck()); |
| 512 | GenerateSuspendCheck(info->GetSuspendCheck(), successor); |
| 513 | return; |
| 514 | } |
| 515 | |
| 516 | if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) { |
| 517 | GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr); |
| 518 | } |
| 519 | if (!codegen_->GoesToNextBlock(got->GetBlock(), successor)) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 520 | __ jmp(codegen_->GetLabelOf(successor)); |
| 521 | } |
| 522 | } |
| 523 | |
| 524 | void LocationsBuilderX86_64::VisitExit(HExit* exit) { |
| 525 | exit->SetLocations(nullptr); |
| 526 | } |
| 527 | |
| 528 | void InstructionCodeGeneratorX86_64::VisitExit(HExit* exit) { |
| 529 | if (kIsDebugBuild) { |
| 530 | __ Comment("Unreachable"); |
| 531 | __ int3(); |
| 532 | } |
| 533 | } |
| 534 | |
| 535 | void LocationsBuilderX86_64::VisitIf(HIf* if_instr) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 536 | LocationSummary* locations = |
| 537 | new (GetGraph()->GetArena()) LocationSummary(if_instr, LocationSummary::kNoCall); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 538 | HInstruction* cond = if_instr->InputAt(0); |
Nicolas Geoffray | 01ef345 | 2014-10-01 11:32:17 +0100 | [diff] [blame] | 539 | if (!cond->IsCondition() || cond->AsCondition()->NeedsMaterialization()) { |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 540 | locations->SetInAt(0, Location::Any()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 541 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 542 | } |
| 543 | |
| 544 | void InstructionCodeGeneratorX86_64::VisitIf(HIf* if_instr) { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 545 | HInstruction* cond = if_instr->InputAt(0); |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 546 | if (cond->IsIntConstant()) { |
| 547 | // Constant condition, statically compared against 1. |
| 548 | int32_t cond_value = cond->AsIntConstant()->GetValue(); |
| 549 | if (cond_value == 1) { |
| 550 | if (!codegen_->GoesToNextBlock(if_instr->GetBlock(), |
| 551 | if_instr->IfTrueSuccessor())) { |
| 552 | __ jmp(codegen_->GetLabelOf(if_instr->IfTrueSuccessor())); |
Nicolas Geoffray | 18efde5 | 2014-09-22 15:51:11 +0100 | [diff] [blame] | 553 | } |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 554 | return; |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 555 | } else { |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 556 | DCHECK_EQ(cond_value, 0); |
| 557 | } |
| 558 | } else { |
| 559 | bool materialized = |
| 560 | !cond->IsCondition() || cond->AsCondition()->NeedsMaterialization(); |
| 561 | // Moves do not affect the eflags register, so if the condition is |
| 562 | // evaluated just before the if, we don't need to evaluate it |
| 563 | // again. |
| 564 | bool eflags_set = cond->IsCondition() |
| 565 | && cond->AsCondition()->IsBeforeWhenDisregardMoves(if_instr); |
| 566 | if (materialized) { |
| 567 | if (!eflags_set) { |
| 568 | // Materialized condition, compare against 0. |
| 569 | Location lhs = if_instr->GetLocations()->InAt(0); |
| 570 | if (lhs.IsRegister()) { |
| 571 | __ cmpl(lhs.As<CpuRegister>(), Immediate(0)); |
| 572 | } else { |
| 573 | __ cmpl(Address(CpuRegister(RSP), lhs.GetStackIndex()), |
| 574 | Immediate(0)); |
| 575 | } |
| 576 | __ j(kNotEqual, codegen_->GetLabelOf(if_instr->IfTrueSuccessor())); |
| 577 | } else { |
| 578 | __ j(X86_64Condition(cond->AsCondition()->GetCondition()), |
| 579 | codegen_->GetLabelOf(if_instr->IfTrueSuccessor())); |
| 580 | } |
| 581 | } else { |
| 582 | Location lhs = cond->GetLocations()->InAt(0); |
| 583 | Location rhs = cond->GetLocations()->InAt(1); |
| 584 | if (rhs.IsRegister()) { |
| 585 | __ cmpl(lhs.As<CpuRegister>(), rhs.As<CpuRegister>()); |
| 586 | } else if (rhs.IsConstant()) { |
| 587 | __ cmpl(lhs.As<CpuRegister>(), |
| 588 | Immediate(rhs.GetConstant()->AsIntConstant()->GetValue())); |
| 589 | } else { |
| 590 | __ cmpl(lhs.As<CpuRegister>(), |
| 591 | Address(CpuRegister(RSP), rhs.GetStackIndex())); |
| 592 | } |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 593 | __ j(X86_64Condition(cond->AsCondition()->GetCondition()), |
| 594 | codegen_->GetLabelOf(if_instr->IfTrueSuccessor())); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 595 | } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 596 | } |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 597 | if (!codegen_->GoesToNextBlock(if_instr->GetBlock(), |
| 598 | if_instr->IfFalseSuccessor())) { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 599 | __ jmp(codegen_->GetLabelOf(if_instr->IfFalseSuccessor())); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 600 | } |
| 601 | } |
| 602 | |
| 603 | void LocationsBuilderX86_64::VisitLocal(HLocal* local) { |
| 604 | local->SetLocations(nullptr); |
| 605 | } |
| 606 | |
| 607 | void InstructionCodeGeneratorX86_64::VisitLocal(HLocal* local) { |
| 608 | DCHECK_EQ(local->GetBlock(), GetGraph()->GetEntryBlock()); |
| 609 | } |
| 610 | |
| 611 | void LocationsBuilderX86_64::VisitLoadLocal(HLoadLocal* local) { |
| 612 | local->SetLocations(nullptr); |
| 613 | } |
| 614 | |
| 615 | void InstructionCodeGeneratorX86_64::VisitLoadLocal(HLoadLocal* load) { |
| 616 | // Nothing to do, this is driven by the code generator. |
| 617 | } |
| 618 | |
| 619 | void LocationsBuilderX86_64::VisitStoreLocal(HStoreLocal* store) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 620 | LocationSummary* locations = |
| 621 | new (GetGraph()->GetArena()) LocationSummary(store, LocationSummary::kNoCall); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 622 | switch (store->InputAt(1)->GetType()) { |
| 623 | case Primitive::kPrimBoolean: |
| 624 | case Primitive::kPrimByte: |
| 625 | case Primitive::kPrimChar: |
| 626 | case Primitive::kPrimShort: |
| 627 | case Primitive::kPrimInt: |
| 628 | case Primitive::kPrimNot: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 629 | case Primitive::kPrimFloat: |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 630 | locations->SetInAt(1, Location::StackSlot(codegen_->GetStackSlot(store->GetLocal()))); |
| 631 | break; |
| 632 | |
| 633 | case Primitive::kPrimLong: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 634 | case Primitive::kPrimDouble: |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 635 | locations->SetInAt(1, Location::DoubleStackSlot(codegen_->GetStackSlot(store->GetLocal()))); |
| 636 | break; |
| 637 | |
| 638 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 639 | LOG(FATAL) << "Unexpected local type " << store->InputAt(1)->GetType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 640 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 641 | } |
| 642 | |
| 643 | void InstructionCodeGeneratorX86_64::VisitStoreLocal(HStoreLocal* store) { |
| 644 | } |
| 645 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 646 | void LocationsBuilderX86_64::VisitCondition(HCondition* comp) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 647 | LocationSummary* locations = |
| 648 | new (GetGraph()->GetArena()) LocationSummary(comp, LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 649 | locations->SetInAt(0, Location::RequiresRegister()); |
| 650 | locations->SetInAt(1, Location::Any()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 651 | if (comp->NeedsMaterialization()) { |
| 652 | locations->SetOut(Location::RequiresRegister()); |
| 653 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 654 | } |
| 655 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 656 | void InstructionCodeGeneratorX86_64::VisitCondition(HCondition* comp) { |
| 657 | if (comp->NeedsMaterialization()) { |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 658 | LocationSummary* locations = comp->GetLocations(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 659 | CpuRegister reg = locations->Out().As<CpuRegister>(); |
Nicolas Geoffray | 18efde5 | 2014-09-22 15:51:11 +0100 | [diff] [blame] | 660 | // Clear register: setcc only sets the low byte. |
| 661 | __ xorq(reg, reg); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 662 | if (locations->InAt(1).IsRegister()) { |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 663 | __ cmpl(locations->InAt(0).As<CpuRegister>(), |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 664 | locations->InAt(1).As<CpuRegister>()); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 665 | } else if (locations->InAt(1).IsConstant()) { |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 666 | __ cmpl(locations->InAt(0).As<CpuRegister>(), |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 667 | Immediate(locations->InAt(1).GetConstant()->AsIntConstant()->GetValue())); |
| 668 | } else { |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 669 | __ cmpl(locations->InAt(0).As<CpuRegister>(), |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 670 | Address(CpuRegister(RSP), locations->InAt(1).GetStackIndex())); |
| 671 | } |
Nicolas Geoffray | 18efde5 | 2014-09-22 15:51:11 +0100 | [diff] [blame] | 672 | __ setcc(X86_64Condition(comp->GetCondition()), reg); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 673 | } |
| 674 | } |
| 675 | |
| 676 | void LocationsBuilderX86_64::VisitEqual(HEqual* comp) { |
| 677 | VisitCondition(comp); |
| 678 | } |
| 679 | |
| 680 | void InstructionCodeGeneratorX86_64::VisitEqual(HEqual* comp) { |
| 681 | VisitCondition(comp); |
| 682 | } |
| 683 | |
| 684 | void LocationsBuilderX86_64::VisitNotEqual(HNotEqual* comp) { |
| 685 | VisitCondition(comp); |
| 686 | } |
| 687 | |
| 688 | void InstructionCodeGeneratorX86_64::VisitNotEqual(HNotEqual* comp) { |
| 689 | VisitCondition(comp); |
| 690 | } |
| 691 | |
| 692 | void LocationsBuilderX86_64::VisitLessThan(HLessThan* comp) { |
| 693 | VisitCondition(comp); |
| 694 | } |
| 695 | |
| 696 | void InstructionCodeGeneratorX86_64::VisitLessThan(HLessThan* comp) { |
| 697 | VisitCondition(comp); |
| 698 | } |
| 699 | |
| 700 | void LocationsBuilderX86_64::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
| 701 | VisitCondition(comp); |
| 702 | } |
| 703 | |
| 704 | void InstructionCodeGeneratorX86_64::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
| 705 | VisitCondition(comp); |
| 706 | } |
| 707 | |
| 708 | void LocationsBuilderX86_64::VisitGreaterThan(HGreaterThan* comp) { |
| 709 | VisitCondition(comp); |
| 710 | } |
| 711 | |
| 712 | void InstructionCodeGeneratorX86_64::VisitGreaterThan(HGreaterThan* comp) { |
| 713 | VisitCondition(comp); |
| 714 | } |
| 715 | |
| 716 | void LocationsBuilderX86_64::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
| 717 | VisitCondition(comp); |
| 718 | } |
| 719 | |
| 720 | void InstructionCodeGeneratorX86_64::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
| 721 | VisitCondition(comp); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 722 | } |
| 723 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 724 | void LocationsBuilderX86_64::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 725 | LocationSummary* locations = |
| 726 | new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 727 | locations->SetInAt(0, Location::RequiresRegister()); |
| 728 | locations->SetInAt(1, Location::RequiresRegister()); |
| 729 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 730 | } |
| 731 | |
| 732 | void InstructionCodeGeneratorX86_64::VisitCompare(HCompare* compare) { |
| 733 | Label greater, done; |
| 734 | LocationSummary* locations = compare->GetLocations(); |
| 735 | switch (compare->InputAt(0)->GetType()) { |
| 736 | case Primitive::kPrimLong: |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 737 | __ cmpq(locations->InAt(0).As<CpuRegister>(), |
| 738 | locations->InAt(1).As<CpuRegister>()); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 739 | break; |
| 740 | default: |
| 741 | LOG(FATAL) << "Unimplemented compare type " << compare->InputAt(0)->GetType(); |
| 742 | } |
| 743 | |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 744 | CpuRegister output = locations->Out().As<CpuRegister>(); |
| 745 | __ movl(output, Immediate(0)); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 746 | __ j(kEqual, &done); |
| 747 | __ j(kGreater, &greater); |
| 748 | |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 749 | __ movl(output, Immediate(-1)); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 750 | __ jmp(&done); |
| 751 | |
| 752 | __ Bind(&greater); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 753 | __ movl(output, Immediate(1)); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 754 | |
| 755 | __ Bind(&done); |
| 756 | } |
| 757 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 758 | void LocationsBuilderX86_64::VisitIntConstant(HIntConstant* constant) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 759 | LocationSummary* locations = |
| 760 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 761 | locations->SetOut(Location::ConstantLocation(constant)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 762 | } |
| 763 | |
| 764 | void InstructionCodeGeneratorX86_64::VisitIntConstant(HIntConstant* constant) { |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 765 | // Will be generated at use site. |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 766 | } |
| 767 | |
| 768 | void LocationsBuilderX86_64::VisitLongConstant(HLongConstant* constant) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 769 | LocationSummary* locations = |
| 770 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 771 | locations->SetOut(Location::ConstantLocation(constant)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 772 | } |
| 773 | |
| 774 | void InstructionCodeGeneratorX86_64::VisitLongConstant(HLongConstant* constant) { |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 775 | // Will be generated at use site. |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 776 | } |
| 777 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 778 | void LocationsBuilderX86_64::VisitFloatConstant(HFloatConstant* constant) { |
| 779 | LocationSummary* locations = |
| 780 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 781 | locations->SetOut(Location::ConstantLocation(constant)); |
| 782 | } |
| 783 | |
| 784 | void InstructionCodeGeneratorX86_64::VisitFloatConstant(HFloatConstant* constant) { |
| 785 | // Will be generated at use site. |
| 786 | } |
| 787 | |
| 788 | void LocationsBuilderX86_64::VisitDoubleConstant(HDoubleConstant* constant) { |
| 789 | LocationSummary* locations = |
| 790 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 791 | locations->SetOut(Location::ConstantLocation(constant)); |
| 792 | } |
| 793 | |
| 794 | void InstructionCodeGeneratorX86_64::VisitDoubleConstant(HDoubleConstant* constant) { |
| 795 | // Will be generated at use site. |
| 796 | } |
| 797 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 798 | void LocationsBuilderX86_64::VisitReturnVoid(HReturnVoid* ret) { |
| 799 | ret->SetLocations(nullptr); |
| 800 | } |
| 801 | |
| 802 | void InstructionCodeGeneratorX86_64::VisitReturnVoid(HReturnVoid* ret) { |
| 803 | codegen_->GenerateFrameExit(); |
| 804 | __ ret(); |
| 805 | } |
| 806 | |
| 807 | void LocationsBuilderX86_64::VisitReturn(HReturn* ret) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 808 | LocationSummary* locations = |
| 809 | new (GetGraph()->GetArena()) LocationSummary(ret, LocationSummary::kNoCall); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 810 | switch (ret->InputAt(0)->GetType()) { |
| 811 | case Primitive::kPrimBoolean: |
| 812 | case Primitive::kPrimByte: |
| 813 | case Primitive::kPrimChar: |
| 814 | case Primitive::kPrimShort: |
| 815 | case Primitive::kPrimInt: |
| 816 | case Primitive::kPrimNot: |
| 817 | case Primitive::kPrimLong: |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 818 | locations->SetInAt(0, Location::RegisterLocation(RAX)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 819 | break; |
| 820 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 821 | case Primitive::kPrimFloat: |
| 822 | case Primitive::kPrimDouble: |
| 823 | locations->SetInAt(0, |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 824 | Location::FpuRegisterLocation(XMM0)); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 825 | break; |
| 826 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 827 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 828 | LOG(FATAL) << "Unexpected return type " << ret->InputAt(0)->GetType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 829 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 830 | } |
| 831 | |
| 832 | void InstructionCodeGeneratorX86_64::VisitReturn(HReturn* ret) { |
| 833 | if (kIsDebugBuild) { |
| 834 | switch (ret->InputAt(0)->GetType()) { |
| 835 | case Primitive::kPrimBoolean: |
| 836 | case Primitive::kPrimByte: |
| 837 | case Primitive::kPrimChar: |
| 838 | case Primitive::kPrimShort: |
| 839 | case Primitive::kPrimInt: |
| 840 | case Primitive::kPrimNot: |
| 841 | case Primitive::kPrimLong: |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 842 | DCHECK_EQ(ret->GetLocations()->InAt(0).As<CpuRegister>().AsRegister(), RAX); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 843 | break; |
| 844 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 845 | case Primitive::kPrimFloat: |
| 846 | case Primitive::kPrimDouble: |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 847 | DCHECK_EQ(ret->GetLocations()->InAt(0).As<XmmRegister>().AsFloatRegister(), |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 848 | XMM0); |
| 849 | break; |
| 850 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 851 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 852 | LOG(FATAL) << "Unexpected return type " << ret->InputAt(0)->GetType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 853 | } |
| 854 | } |
| 855 | codegen_->GenerateFrameExit(); |
| 856 | __ ret(); |
| 857 | } |
| 858 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 859 | Location InvokeDexCallingConventionVisitor::GetNextLocation(Primitive::Type type) { |
| 860 | switch (type) { |
| 861 | case Primitive::kPrimBoolean: |
| 862 | case Primitive::kPrimByte: |
| 863 | case Primitive::kPrimChar: |
| 864 | case Primitive::kPrimShort: |
| 865 | case Primitive::kPrimInt: |
| 866 | case Primitive::kPrimNot: { |
| 867 | uint32_t index = gp_index_++; |
| 868 | stack_index_++; |
| 869 | if (index < calling_convention.GetNumberOfRegisters()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 870 | return Location::RegisterLocation(calling_convention.GetRegisterAt(index)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 871 | } else { |
| 872 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 1)); |
| 873 | } |
| 874 | } |
| 875 | |
| 876 | case Primitive::kPrimLong: { |
| 877 | uint32_t index = gp_index_; |
| 878 | stack_index_ += 2; |
| 879 | if (index < calling_convention.GetNumberOfRegisters()) { |
| 880 | gp_index_ += 1; |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 881 | return Location::RegisterLocation(calling_convention.GetRegisterAt(index)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 882 | } else { |
| 883 | gp_index_ += 2; |
| 884 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 2)); |
| 885 | } |
| 886 | } |
| 887 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 888 | case Primitive::kPrimFloat: { |
| 889 | uint32_t index = fp_index_++; |
| 890 | stack_index_++; |
| 891 | if (index < calling_convention.GetNumberOfFpuRegisters()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 892 | return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(index)); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 893 | } else { |
| 894 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 1)); |
| 895 | } |
| 896 | } |
| 897 | |
| 898 | case Primitive::kPrimDouble: { |
| 899 | uint32_t index = fp_index_++; |
| 900 | stack_index_ += 2; |
| 901 | if (index < calling_convention.GetNumberOfFpuRegisters()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 902 | return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(index)); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 903 | } else { |
| 904 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 2)); |
| 905 | } |
| 906 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 907 | |
| 908 | case Primitive::kPrimVoid: |
| 909 | LOG(FATAL) << "Unexpected parameter type " << type; |
| 910 | break; |
| 911 | } |
| 912 | return Location(); |
| 913 | } |
| 914 | |
| 915 | void LocationsBuilderX86_64::VisitInvokeStatic(HInvokeStatic* invoke) { |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 916 | HandleInvoke(invoke); |
| 917 | } |
| 918 | |
| 919 | void InstructionCodeGeneratorX86_64::VisitInvokeStatic(HInvokeStatic* invoke) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 920 | CpuRegister temp = invoke->GetLocations()->GetTemp(0).As<CpuRegister>(); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 921 | // TODO: Implement all kinds of calls: |
| 922 | // 1) boot -> boot |
| 923 | // 2) app -> boot |
| 924 | // 3) app -> app |
| 925 | // |
| 926 | // Currently we implement the app -> app logic, which looks up in the resolve cache. |
| 927 | |
| 928 | // temp = method; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame^] | 929 | codegen_->LoadCurrentMethod(temp); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 930 | // temp = temp->dex_cache_resolved_methods_; |
| 931 | __ movl(temp, Address(temp, mirror::ArtMethod::DexCacheResolvedMethodsOffset().SizeValue())); |
| 932 | // temp = temp[index_in_cache] |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame^] | 933 | __ movl(temp, Address(temp, CodeGenerator::GetCacheOffset(invoke->GetIndexInDexCache()))); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 934 | // (temp + offset_of_quick_compiled_code)() |
| 935 | __ call(Address(temp, mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset().SizeValue())); |
| 936 | |
| 937 | DCHECK(!codegen_->IsLeafMethod()); |
| 938 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 939 | } |
| 940 | |
| 941 | void LocationsBuilderX86_64::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
| 942 | HandleInvoke(invoke); |
| 943 | } |
| 944 | |
| 945 | void LocationsBuilderX86_64::HandleInvoke(HInvoke* invoke) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 946 | LocationSummary* locations = |
| 947 | new (GetGraph()->GetArena()) LocationSummary(invoke, LocationSummary::kCall); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 948 | locations->AddTemp(Location::RegisterLocation(RDI)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 949 | |
| 950 | InvokeDexCallingConventionVisitor calling_convention_visitor; |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 951 | for (size_t i = 0; i < invoke->InputCount(); i++) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 952 | HInstruction* input = invoke->InputAt(i); |
| 953 | locations->SetInAt(i, calling_convention_visitor.GetNextLocation(input->GetType())); |
| 954 | } |
| 955 | |
| 956 | switch (invoke->GetType()) { |
| 957 | case Primitive::kPrimBoolean: |
| 958 | case Primitive::kPrimByte: |
| 959 | case Primitive::kPrimChar: |
| 960 | case Primitive::kPrimShort: |
| 961 | case Primitive::kPrimInt: |
| 962 | case Primitive::kPrimNot: |
| 963 | case Primitive::kPrimLong: |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 964 | locations->SetOut(Location::RegisterLocation(RAX)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 965 | break; |
| 966 | |
| 967 | case Primitive::kPrimVoid: |
| 968 | break; |
| 969 | |
| 970 | case Primitive::kPrimDouble: |
| 971 | case Primitive::kPrimFloat: |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 972 | locations->SetOut(Location::FpuRegisterLocation(XMM0)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 973 | break; |
| 974 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 975 | } |
| 976 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 977 | void InstructionCodeGeneratorX86_64::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 978 | CpuRegister temp = invoke->GetLocations()->GetTemp(0).As<CpuRegister>(); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 979 | size_t method_offset = mirror::Class::EmbeddedVTableOffset().SizeValue() + |
| 980 | invoke->GetVTableIndex() * sizeof(mirror::Class::VTableEntry); |
| 981 | LocationSummary* locations = invoke->GetLocations(); |
| 982 | Location receiver = locations->InAt(0); |
| 983 | size_t class_offset = mirror::Object::ClassOffset().SizeValue(); |
| 984 | // temp = object->GetClass(); |
| 985 | if (receiver.IsStackSlot()) { |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 986 | __ movl(temp, Address(CpuRegister(RSP), receiver.GetStackIndex())); |
| 987 | __ movl(temp, Address(temp, class_offset)); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 988 | } else { |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 989 | __ movl(temp, Address(receiver.As<CpuRegister>(), class_offset)); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 990 | } |
| 991 | // temp = temp->GetMethodAt(method_offset); |
| 992 | __ movl(temp, Address(temp, method_offset)); |
| 993 | // call temp->GetEntryPoint(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 994 | __ call(Address(temp, mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset().SizeValue())); |
| 995 | |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 996 | DCHECK(!codegen_->IsLeafMethod()); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 997 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 998 | } |
| 999 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1000 | void LocationsBuilderX86_64::VisitNeg(HNeg* neg) { |
| 1001 | LocationSummary* locations = |
| 1002 | new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall); |
| 1003 | switch (neg->GetResultType()) { |
| 1004 | case Primitive::kPrimInt: |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 1005 | case Primitive::kPrimLong: |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1006 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1007 | locations->SetOut(Location::SameAsFirstInput()); |
| 1008 | break; |
| 1009 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1010 | case Primitive::kPrimFloat: |
| 1011 | case Primitive::kPrimDouble: |
| 1012 | LOG(FATAL) << "Not yet implemented neg type " << neg->GetResultType(); |
| 1013 | break; |
| 1014 | |
| 1015 | default: |
| 1016 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 1017 | } |
| 1018 | } |
| 1019 | |
| 1020 | void InstructionCodeGeneratorX86_64::VisitNeg(HNeg* neg) { |
| 1021 | LocationSummary* locations = neg->GetLocations(); |
| 1022 | Location out = locations->Out(); |
| 1023 | Location in = locations->InAt(0); |
| 1024 | switch (neg->GetResultType()) { |
| 1025 | case Primitive::kPrimInt: |
| 1026 | DCHECK(in.IsRegister()); |
| 1027 | __ negl(out.As<CpuRegister>()); |
| 1028 | break; |
| 1029 | |
| 1030 | case Primitive::kPrimLong: |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 1031 | DCHECK(in.IsRegister()); |
| 1032 | __ negq(out.As<CpuRegister>()); |
| 1033 | break; |
| 1034 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1035 | case Primitive::kPrimFloat: |
| 1036 | case Primitive::kPrimDouble: |
| 1037 | LOG(FATAL) << "Not yet implemented neg type " << neg->GetResultType(); |
| 1038 | break; |
| 1039 | |
| 1040 | default: |
| 1041 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 1042 | } |
| 1043 | } |
| 1044 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1045 | void LocationsBuilderX86_64::VisitAdd(HAdd* add) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1046 | LocationSummary* locations = |
| 1047 | new (GetGraph()->GetArena()) LocationSummary(add, LocationSummary::kNoCall); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1048 | switch (add->GetResultType()) { |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1049 | case Primitive::kPrimInt: { |
| 1050 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1051 | locations->SetInAt(1, Location::Any()); |
| 1052 | locations->SetOut(Location::SameAsFirstInput()); |
| 1053 | break; |
| 1054 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1055 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1056 | case Primitive::kPrimLong: { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 1057 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1058 | locations->SetInAt(1, Location::RequiresRegister()); |
| 1059 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1060 | break; |
| 1061 | } |
| 1062 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1063 | case Primitive::kPrimDouble: |
| 1064 | case Primitive::kPrimFloat: { |
| 1065 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1066 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1067 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1068 | break; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1069 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1070 | |
| 1071 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1072 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1073 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1074 | } |
| 1075 | |
| 1076 | void InstructionCodeGeneratorX86_64::VisitAdd(HAdd* add) { |
| 1077 | LocationSummary* locations = add->GetLocations(); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1078 | Location first = locations->InAt(0); |
| 1079 | Location second = locations->InAt(1); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1080 | DCHECK(first.Equals(locations->Out())); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 1081 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1082 | switch (add->GetResultType()) { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 1083 | case Primitive::kPrimInt: { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1084 | if (second.IsRegister()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1085 | __ addl(first.As<CpuRegister>(), second.As<CpuRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1086 | } else if (second.IsConstant()) { |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 1087 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue()); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1088 | __ addl(first.As<CpuRegister>(), imm); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1089 | } else { |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 1090 | __ addl(first.As<CpuRegister>(), Address(CpuRegister(RSP), second.GetStackIndex())); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1091 | } |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 1092 | break; |
| 1093 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1094 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1095 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1096 | __ addq(first.As<CpuRegister>(), second.As<CpuRegister>()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1097 | break; |
| 1098 | } |
| 1099 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1100 | case Primitive::kPrimFloat: { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1101 | __ addss(first.As<XmmRegister>(), second.As<XmmRegister>()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1102 | break; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1103 | } |
| 1104 | |
| 1105 | case Primitive::kPrimDouble: { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1106 | __ addsd(first.As<XmmRegister>(), second.As<XmmRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1107 | break; |
| 1108 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1109 | |
| 1110 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1111 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1112 | } |
| 1113 | } |
| 1114 | |
| 1115 | void LocationsBuilderX86_64::VisitSub(HSub* sub) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1116 | LocationSummary* locations = |
| 1117 | new (GetGraph()->GetArena()) LocationSummary(sub, LocationSummary::kNoCall); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1118 | switch (sub->GetResultType()) { |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1119 | case Primitive::kPrimInt: { |
| 1120 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1121 | locations->SetInAt(1, Location::Any()); |
| 1122 | locations->SetOut(Location::SameAsFirstInput()); |
| 1123 | break; |
| 1124 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1125 | case Primitive::kPrimLong: { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 1126 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1127 | locations->SetInAt(1, Location::RequiresRegister()); |
| 1128 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1129 | break; |
| 1130 | } |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 1131 | case Primitive::kPrimFloat: |
| 1132 | case Primitive::kPrimDouble: { |
| 1133 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1134 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 1135 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1136 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 1137 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1138 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 1139 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1140 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1141 | } |
| 1142 | |
| 1143 | void InstructionCodeGeneratorX86_64::VisitSub(HSub* sub) { |
| 1144 | LocationSummary* locations = sub->GetLocations(); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 1145 | Location first = locations->InAt(0); |
| 1146 | Location second = locations->InAt(1); |
| 1147 | DCHECK(first.Equals(locations->Out())); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1148 | switch (sub->GetResultType()) { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 1149 | case Primitive::kPrimInt: { |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 1150 | if (second.IsRegister()) { |
| 1151 | __ subl(first.As<CpuRegister>(), second.As<CpuRegister>()); |
| 1152 | } else if (second.IsConstant()) { |
| 1153 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue()); |
| 1154 | __ subl(first.As<CpuRegister>(), imm); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1155 | } else { |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 1156 | __ subl(first.As<CpuRegister>(), Address(CpuRegister(RSP), second.GetStackIndex())); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1157 | } |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 1158 | break; |
| 1159 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1160 | case Primitive::kPrimLong: { |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 1161 | __ subq(first.As<CpuRegister>(), second.As<CpuRegister>()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1162 | break; |
| 1163 | } |
| 1164 | |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 1165 | case Primitive::kPrimFloat: { |
| 1166 | __ subss(first.As<XmmRegister>(), second.As<XmmRegister>()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1167 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 1168 | } |
| 1169 | |
| 1170 | case Primitive::kPrimDouble: { |
| 1171 | __ subsd(first.As<XmmRegister>(), second.As<XmmRegister>()); |
| 1172 | break; |
| 1173 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1174 | |
| 1175 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 1176 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1177 | } |
| 1178 | } |
| 1179 | |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 1180 | void LocationsBuilderX86_64::VisitMul(HMul* mul) { |
| 1181 | LocationSummary* locations = |
| 1182 | new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall); |
| 1183 | switch (mul->GetResultType()) { |
| 1184 | case Primitive::kPrimInt: { |
| 1185 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1186 | locations->SetInAt(1, Location::Any()); |
| 1187 | locations->SetOut(Location::SameAsFirstInput()); |
| 1188 | break; |
| 1189 | } |
| 1190 | case Primitive::kPrimLong: { |
| 1191 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1192 | locations->SetInAt(1, Location::RequiresRegister()); |
| 1193 | locations->SetOut(Location::SameAsFirstInput()); |
| 1194 | break; |
| 1195 | } |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 1196 | case Primitive::kPrimFloat: |
| 1197 | case Primitive::kPrimDouble: { |
| 1198 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1199 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 1200 | locations->SetOut(Location::SameAsFirstInput()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 1201 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 1202 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 1203 | |
| 1204 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 1205 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 1206 | } |
| 1207 | } |
| 1208 | |
| 1209 | void InstructionCodeGeneratorX86_64::VisitMul(HMul* mul) { |
| 1210 | LocationSummary* locations = mul->GetLocations(); |
| 1211 | Location first = locations->InAt(0); |
| 1212 | Location second = locations->InAt(1); |
| 1213 | DCHECK(first.Equals(locations->Out())); |
| 1214 | switch (mul->GetResultType()) { |
| 1215 | case Primitive::kPrimInt: { |
| 1216 | if (second.IsRegister()) { |
| 1217 | __ imull(first.As<CpuRegister>(), second.As<CpuRegister>()); |
| 1218 | } else if (second.IsConstant()) { |
| 1219 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue()); |
| 1220 | __ imull(first.As<CpuRegister>(), imm); |
| 1221 | } else { |
| 1222 | DCHECK(second.IsStackSlot()); |
| 1223 | __ imull(first.As<CpuRegister>(), Address(CpuRegister(RSP), second.GetStackIndex())); |
| 1224 | } |
| 1225 | break; |
| 1226 | } |
| 1227 | case Primitive::kPrimLong: { |
| 1228 | __ imulq(first.As<CpuRegister>(), second.As<CpuRegister>()); |
| 1229 | break; |
| 1230 | } |
| 1231 | |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 1232 | case Primitive::kPrimFloat: { |
| 1233 | __ mulss(first.As<XmmRegister>(), second.As<XmmRegister>()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 1234 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 1235 | } |
| 1236 | |
| 1237 | case Primitive::kPrimDouble: { |
| 1238 | __ mulsd(first.As<XmmRegister>(), second.As<XmmRegister>()); |
| 1239 | break; |
| 1240 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 1241 | |
| 1242 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 1243 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 1244 | } |
| 1245 | } |
| 1246 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1247 | void LocationsBuilderX86_64::VisitDiv(HDiv* div) { |
| 1248 | LocationSummary* locations = |
| 1249 | new (GetGraph()->GetArena()) LocationSummary(div, LocationSummary::kNoCall); |
| 1250 | switch (div->GetResultType()) { |
| 1251 | case Primitive::kPrimInt: |
| 1252 | case Primitive::kPrimLong: { |
| 1253 | LOG(FATAL) << "Not implemented div type" << div->GetResultType(); |
| 1254 | break; |
| 1255 | } |
| 1256 | case Primitive::kPrimFloat: |
| 1257 | case Primitive::kPrimDouble: { |
| 1258 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1259 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 1260 | locations->SetOut(Location::SameAsFirstInput()); |
| 1261 | break; |
| 1262 | } |
| 1263 | |
| 1264 | default: |
| 1265 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 1266 | } |
| 1267 | } |
| 1268 | |
| 1269 | void InstructionCodeGeneratorX86_64::VisitDiv(HDiv* div) { |
| 1270 | LocationSummary* locations = div->GetLocations(); |
| 1271 | Location first = locations->InAt(0); |
| 1272 | Location second = locations->InAt(1); |
| 1273 | DCHECK(first.Equals(locations->Out())); |
| 1274 | |
| 1275 | switch (div->GetResultType()) { |
| 1276 | case Primitive::kPrimInt: |
| 1277 | case Primitive::kPrimLong: { |
| 1278 | LOG(FATAL) << "Not implemented div type" << div->GetResultType(); |
| 1279 | break; |
| 1280 | } |
| 1281 | |
| 1282 | case Primitive::kPrimFloat: { |
| 1283 | __ divss(first.As<XmmRegister>(), second.As<XmmRegister>()); |
| 1284 | break; |
| 1285 | } |
| 1286 | |
| 1287 | case Primitive::kPrimDouble: { |
| 1288 | __ divsd(first.As<XmmRegister>(), second.As<XmmRegister>()); |
| 1289 | break; |
| 1290 | } |
| 1291 | |
| 1292 | default: |
| 1293 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 1294 | } |
| 1295 | } |
| 1296 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1297 | void LocationsBuilderX86_64::VisitNewInstance(HNewInstance* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1298 | LocationSummary* locations = |
| 1299 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
Nicolas Geoffray | 9ae0daa | 2014-09-30 22:40:23 +0100 | [diff] [blame] | 1300 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1301 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 1302 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 1303 | locations->SetOut(Location::RegisterLocation(RAX)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1304 | } |
| 1305 | |
| 1306 | void InstructionCodeGeneratorX86_64::VisitNewInstance(HNewInstance* instruction) { |
| 1307 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame^] | 1308 | codegen_->LoadCurrentMethod(CpuRegister(calling_convention.GetRegisterAt(1))); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1309 | __ movq(CpuRegister(calling_convention.GetRegisterAt(0)), Immediate(instruction->GetTypeIndex())); |
| 1310 | |
| 1311 | __ gs()->call(Address::Absolute( |
| 1312 | QUICK_ENTRYPOINT_OFFSET(kX86_64WordSize, pAllocObjectWithAccessCheck), true)); |
| 1313 | |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 1314 | DCHECK(!codegen_->IsLeafMethod()); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1315 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1316 | } |
| 1317 | |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 1318 | void LocationsBuilderX86_64::VisitNewArray(HNewArray* instruction) { |
| 1319 | LocationSummary* locations = |
| 1320 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
| 1321 | InvokeRuntimeCallingConvention calling_convention; |
| 1322 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 1323 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 1324 | locations->SetOut(Location::RegisterLocation(RAX)); |
| 1325 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(2))); |
| 1326 | } |
| 1327 | |
| 1328 | void InstructionCodeGeneratorX86_64::VisitNewArray(HNewArray* instruction) { |
| 1329 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame^] | 1330 | codegen_->LoadCurrentMethod(CpuRegister(calling_convention.GetRegisterAt(1))); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 1331 | __ movq(CpuRegister(calling_convention.GetRegisterAt(0)), Immediate(instruction->GetTypeIndex())); |
| 1332 | |
| 1333 | __ gs()->call(Address::Absolute( |
| 1334 | QUICK_ENTRYPOINT_OFFSET(kX86_64WordSize, pAllocArrayWithAccessCheck), true)); |
| 1335 | |
| 1336 | DCHECK(!codegen_->IsLeafMethod()); |
| 1337 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
| 1338 | } |
| 1339 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1340 | void LocationsBuilderX86_64::VisitParameterValue(HParameterValue* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1341 | LocationSummary* locations = |
| 1342 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1343 | Location location = parameter_visitor_.GetNextLocation(instruction->GetType()); |
| 1344 | if (location.IsStackSlot()) { |
| 1345 | location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 1346 | } else if (location.IsDoubleStackSlot()) { |
| 1347 | location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 1348 | } |
| 1349 | locations->SetOut(location); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1350 | } |
| 1351 | |
| 1352 | void InstructionCodeGeneratorX86_64::VisitParameterValue(HParameterValue* instruction) { |
| 1353 | // Nothing to do, the parameter is already at its location. |
| 1354 | } |
| 1355 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 1356 | void LocationsBuilderX86_64::VisitNot(HNot* not_) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1357 | LocationSummary* locations = |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 1358 | new (GetGraph()->GetArena()) LocationSummary(not_, LocationSummary::kNoCall); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 1359 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1360 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1361 | } |
| 1362 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 1363 | void InstructionCodeGeneratorX86_64::VisitNot(HNot* not_) { |
| 1364 | LocationSummary* locations = not_->GetLocations(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1365 | DCHECK_EQ(locations->InAt(0).As<CpuRegister>().AsRegister(), |
| 1366 | locations->Out().As<CpuRegister>().AsRegister()); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 1367 | Location out = locations->Out(); |
| 1368 | switch (not_->InputAt(0)->GetType()) { |
| 1369 | case Primitive::kPrimBoolean: |
| 1370 | __ xorq(out.As<CpuRegister>(), Immediate(1)); |
| 1371 | break; |
| 1372 | |
| 1373 | case Primitive::kPrimInt: |
| 1374 | __ notl(out.As<CpuRegister>()); |
| 1375 | break; |
| 1376 | |
| 1377 | case Primitive::kPrimLong: |
Roland Levillain | 7056643 | 2014-10-24 16:20:17 +0100 | [diff] [blame] | 1378 | __ notq(out.As<CpuRegister>()); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 1379 | break; |
| 1380 | |
| 1381 | default: |
| 1382 | LOG(FATAL) << "Unimplemented type for not operation " << not_->GetResultType(); |
| 1383 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1384 | } |
| 1385 | |
| 1386 | void LocationsBuilderX86_64::VisitPhi(HPhi* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1387 | LocationSummary* locations = |
| 1388 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1389 | for (size_t i = 0, e = instruction->InputCount(); i < e; ++i) { |
| 1390 | locations->SetInAt(i, Location::Any()); |
| 1391 | } |
| 1392 | locations->SetOut(Location::Any()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1393 | } |
| 1394 | |
| 1395 | void InstructionCodeGeneratorX86_64::VisitPhi(HPhi* instruction) { |
| 1396 | LOG(FATAL) << "Unimplemented"; |
| 1397 | } |
| 1398 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1399 | void LocationsBuilderX86_64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1400 | LocationSummary* locations = |
| 1401 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 9ae0daa | 2014-09-30 22:40:23 +0100 | [diff] [blame] | 1402 | Primitive::Type field_type = instruction->GetFieldType(); |
| 1403 | bool is_object_type = field_type == Primitive::kPrimNot; |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 1404 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1405 | locations->SetInAt(1, Location::RequiresRegister()); |
Nicolas Geoffray | 9ae0daa | 2014-09-30 22:40:23 +0100 | [diff] [blame] | 1406 | if (is_object_type) { |
| 1407 | // Temporary registers for the write barrier. |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 1408 | locations->AddTemp(Location::RequiresRegister()); |
| 1409 | locations->AddTemp(Location::RequiresRegister()); |
| 1410 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1411 | } |
| 1412 | |
| 1413 | void InstructionCodeGeneratorX86_64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
| 1414 | LocationSummary* locations = instruction->GetLocations(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1415 | CpuRegister obj = locations->InAt(0).As<CpuRegister>(); |
| 1416 | CpuRegister value = locations->InAt(1).As<CpuRegister>(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1417 | size_t offset = instruction->GetFieldOffset().SizeValue(); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1418 | Primitive::Type field_type = instruction->GetFieldType(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1419 | |
| 1420 | switch (field_type) { |
| 1421 | case Primitive::kPrimBoolean: |
| 1422 | case Primitive::kPrimByte: { |
| 1423 | __ movb(Address(obj, offset), value); |
| 1424 | break; |
| 1425 | } |
| 1426 | |
| 1427 | case Primitive::kPrimShort: |
| 1428 | case Primitive::kPrimChar: { |
| 1429 | __ movw(Address(obj, offset), value); |
| 1430 | break; |
| 1431 | } |
| 1432 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1433 | case Primitive::kPrimInt: |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1434 | case Primitive::kPrimNot: { |
| 1435 | __ movl(Address(obj, offset), value); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1436 | if (field_type == Primitive::kPrimNot) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1437 | CpuRegister temp = locations->GetTemp(0).As<CpuRegister>(); |
| 1438 | CpuRegister card = locations->GetTemp(1).As<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1439 | codegen_->MarkGCCard(temp, card, obj, value); |
| 1440 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1441 | break; |
| 1442 | } |
| 1443 | |
| 1444 | case Primitive::kPrimLong: { |
| 1445 | __ movq(Address(obj, offset), value); |
| 1446 | break; |
| 1447 | } |
| 1448 | |
| 1449 | case Primitive::kPrimFloat: |
| 1450 | case Primitive::kPrimDouble: |
| 1451 | LOG(FATAL) << "Unimplemented register type " << field_type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 1452 | UNREACHABLE(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1453 | case Primitive::kPrimVoid: |
| 1454 | LOG(FATAL) << "Unreachable type " << field_type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 1455 | UNREACHABLE(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1456 | } |
| 1457 | } |
| 1458 | |
| 1459 | void LocationsBuilderX86_64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1460 | LocationSummary* locations = |
| 1461 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 1462 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1463 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1464 | } |
| 1465 | |
| 1466 | void InstructionCodeGeneratorX86_64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 1467 | LocationSummary* locations = instruction->GetLocations(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1468 | CpuRegister obj = locations->InAt(0).As<CpuRegister>(); |
| 1469 | CpuRegister out = locations->Out().As<CpuRegister>(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1470 | size_t offset = instruction->GetFieldOffset().SizeValue(); |
| 1471 | |
| 1472 | switch (instruction->GetType()) { |
| 1473 | case Primitive::kPrimBoolean: { |
| 1474 | __ movzxb(out, Address(obj, offset)); |
| 1475 | break; |
| 1476 | } |
| 1477 | |
| 1478 | case Primitive::kPrimByte: { |
| 1479 | __ movsxb(out, Address(obj, offset)); |
| 1480 | break; |
| 1481 | } |
| 1482 | |
| 1483 | case Primitive::kPrimShort: { |
| 1484 | __ movsxw(out, Address(obj, offset)); |
| 1485 | break; |
| 1486 | } |
| 1487 | |
| 1488 | case Primitive::kPrimChar: { |
| 1489 | __ movzxw(out, Address(obj, offset)); |
| 1490 | break; |
| 1491 | } |
| 1492 | |
| 1493 | case Primitive::kPrimInt: |
| 1494 | case Primitive::kPrimNot: { |
| 1495 | __ movl(out, Address(obj, offset)); |
| 1496 | break; |
| 1497 | } |
| 1498 | |
| 1499 | case Primitive::kPrimLong: { |
| 1500 | __ movq(out, Address(obj, offset)); |
| 1501 | break; |
| 1502 | } |
| 1503 | |
| 1504 | case Primitive::kPrimFloat: |
| 1505 | case Primitive::kPrimDouble: |
| 1506 | LOG(FATAL) << "Unimplemented register type " << instruction->GetType(); |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 1507 | UNREACHABLE(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1508 | case Primitive::kPrimVoid: |
| 1509 | LOG(FATAL) << "Unreachable type " << instruction->GetType(); |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 1510 | UNREACHABLE(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1511 | } |
| 1512 | } |
| 1513 | |
| 1514 | void LocationsBuilderX86_64::VisitNullCheck(HNullCheck* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1515 | LocationSummary* locations = |
| 1516 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1517 | locations->SetInAt(0, Location::Any()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 1518 | if (instruction->HasUses()) { |
| 1519 | locations->SetOut(Location::SameAsFirstInput()); |
| 1520 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1521 | } |
| 1522 | |
| 1523 | void InstructionCodeGeneratorX86_64::VisitNullCheck(HNullCheck* instruction) { |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 1524 | SlowPathCodeX86_64* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathX86_64(instruction); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1525 | codegen_->AddSlowPath(slow_path); |
| 1526 | |
| 1527 | LocationSummary* locations = instruction->GetLocations(); |
| 1528 | Location obj = locations->InAt(0); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1529 | |
| 1530 | if (obj.IsRegister()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1531 | __ cmpl(obj.As<CpuRegister>(), Immediate(0)); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 1532 | } else if (obj.IsStackSlot()) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1533 | __ cmpl(Address(CpuRegister(RSP), obj.GetStackIndex()), Immediate(0)); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 1534 | } else { |
| 1535 | DCHECK(obj.IsConstant()) << obj; |
| 1536 | DCHECK_EQ(obj.GetConstant()->AsIntConstant()->GetValue(), 0); |
| 1537 | __ jmp(slow_path->GetEntryLabel()); |
| 1538 | return; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1539 | } |
| 1540 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 1541 | } |
| 1542 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1543 | void LocationsBuilderX86_64::VisitArrayGet(HArrayGet* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1544 | LocationSummary* locations = |
| 1545 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 1546 | locations->SetInAt(0, Location::RequiresRegister()); |
Nicolas Geoffray | 9ae0daa | 2014-09-30 22:40:23 +0100 | [diff] [blame] | 1547 | locations->SetInAt( |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 1548 | 1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 1549 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1550 | } |
| 1551 | |
| 1552 | void InstructionCodeGeneratorX86_64::VisitArrayGet(HArrayGet* instruction) { |
| 1553 | LocationSummary* locations = instruction->GetLocations(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1554 | CpuRegister obj = locations->InAt(0).As<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1555 | Location index = locations->InAt(1); |
| 1556 | |
| 1557 | switch (instruction->GetType()) { |
| 1558 | case Primitive::kPrimBoolean: { |
| 1559 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1560 | CpuRegister out = locations->Out().As<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1561 | if (index.IsConstant()) { |
| 1562 | __ movzxb(out, Address(obj, |
| 1563 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset)); |
| 1564 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1565 | __ movzxb(out, Address(obj, index.As<CpuRegister>(), TIMES_1, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1566 | } |
| 1567 | break; |
| 1568 | } |
| 1569 | |
| 1570 | case Primitive::kPrimByte: { |
| 1571 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int8_t)).Uint32Value(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1572 | CpuRegister out = locations->Out().As<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1573 | if (index.IsConstant()) { |
| 1574 | __ movsxb(out, Address(obj, |
| 1575 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset)); |
| 1576 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1577 | __ movsxb(out, Address(obj, index.As<CpuRegister>(), TIMES_1, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1578 | } |
| 1579 | break; |
| 1580 | } |
| 1581 | |
| 1582 | case Primitive::kPrimShort: { |
| 1583 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int16_t)).Uint32Value(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1584 | CpuRegister out = locations->Out().As<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1585 | if (index.IsConstant()) { |
| 1586 | __ movsxw(out, Address(obj, |
| 1587 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset)); |
| 1588 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1589 | __ movsxw(out, Address(obj, index.As<CpuRegister>(), TIMES_2, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1590 | } |
| 1591 | break; |
| 1592 | } |
| 1593 | |
| 1594 | case Primitive::kPrimChar: { |
| 1595 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1596 | CpuRegister out = locations->Out().As<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1597 | if (index.IsConstant()) { |
| 1598 | __ movzxw(out, Address(obj, |
| 1599 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset)); |
| 1600 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1601 | __ movzxw(out, Address(obj, index.As<CpuRegister>(), TIMES_2, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1602 | } |
| 1603 | break; |
| 1604 | } |
| 1605 | |
| 1606 | case Primitive::kPrimInt: |
| 1607 | case Primitive::kPrimNot: { |
| 1608 | DCHECK_EQ(sizeof(mirror::HeapReference<mirror::Object>), sizeof(int32_t)); |
| 1609 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1610 | CpuRegister out = locations->Out().As<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1611 | if (index.IsConstant()) { |
| 1612 | __ movl(out, Address(obj, |
| 1613 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset)); |
| 1614 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1615 | __ movl(out, Address(obj, index.As<CpuRegister>(), TIMES_4, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1616 | } |
| 1617 | break; |
| 1618 | } |
| 1619 | |
| 1620 | case Primitive::kPrimLong: { |
| 1621 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1622 | CpuRegister out = locations->Out().As<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1623 | if (index.IsConstant()) { |
| 1624 | __ movq(out, Address(obj, |
| 1625 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset)); |
| 1626 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1627 | __ movq(out, Address(obj, index.As<CpuRegister>(), TIMES_8, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1628 | } |
| 1629 | break; |
| 1630 | } |
| 1631 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1632 | case Primitive::kPrimFloat: { |
| 1633 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value(); |
| 1634 | XmmRegister out = locations->Out().As<XmmRegister>(); |
| 1635 | if (index.IsConstant()) { |
| 1636 | __ movss(out, Address(obj, |
| 1637 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset)); |
| 1638 | } else { |
| 1639 | __ movss(out, Address(obj, index.As<CpuRegister>(), TIMES_4, data_offset)); |
| 1640 | } |
| 1641 | break; |
| 1642 | } |
| 1643 | |
| 1644 | case Primitive::kPrimDouble: { |
| 1645 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value(); |
| 1646 | XmmRegister out = locations->Out().As<XmmRegister>(); |
| 1647 | if (index.IsConstant()) { |
| 1648 | __ movsd(out, Address(obj, |
| 1649 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset)); |
| 1650 | } else { |
| 1651 | __ movsd(out, Address(obj, index.As<CpuRegister>(), TIMES_8, data_offset)); |
| 1652 | } |
| 1653 | break; |
| 1654 | } |
| 1655 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1656 | case Primitive::kPrimVoid: |
| 1657 | LOG(FATAL) << "Unreachable type " << instruction->GetType(); |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 1658 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1659 | } |
| 1660 | } |
| 1661 | |
| 1662 | void LocationsBuilderX86_64::VisitArraySet(HArraySet* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1663 | Primitive::Type value_type = instruction->GetComponentType(); |
| 1664 | bool is_object = value_type == Primitive::kPrimNot; |
| 1665 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary( |
| 1666 | instruction, is_object ? LocationSummary::kCall : LocationSummary::kNoCall); |
| 1667 | if (is_object) { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1668 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1669 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 1670 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 1671 | locations->SetInAt(2, Location::RegisterLocation(calling_convention.GetRegisterAt(2))); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1672 | } else { |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 1673 | locations->SetInAt(0, Location::RequiresRegister()); |
Nicolas Geoffray | 9ae0daa | 2014-09-30 22:40:23 +0100 | [diff] [blame] | 1674 | locations->SetInAt( |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 1675 | 1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 1676 | locations->SetInAt(2, Location::RequiresRegister()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 1677 | if (value_type == Primitive::kPrimLong) { |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 1678 | locations->SetInAt(2, Location::RequiresRegister()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1679 | } else if (value_type == Primitive::kPrimFloat || value_type == Primitive::kPrimDouble) { |
| 1680 | locations->SetInAt(2, Location::RequiresFpuRegister()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 1681 | } else { |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 1682 | locations->SetInAt(2, Location::RegisterOrConstant(instruction->InputAt(2))); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 1683 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1684 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1685 | } |
| 1686 | |
| 1687 | void InstructionCodeGeneratorX86_64::VisitArraySet(HArraySet* instruction) { |
| 1688 | LocationSummary* locations = instruction->GetLocations(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1689 | CpuRegister obj = locations->InAt(0).As<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1690 | Location index = locations->InAt(1); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 1691 | Location value = locations->InAt(2); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1692 | Primitive::Type value_type = instruction->GetComponentType(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1693 | |
| 1694 | switch (value_type) { |
| 1695 | case Primitive::kPrimBoolean: |
| 1696 | case Primitive::kPrimByte: { |
| 1697 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1698 | if (index.IsConstant()) { |
| 1699 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset; |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 1700 | if (value.IsRegister()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1701 | __ movb(Address(obj, offset), value.As<CpuRegister>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 1702 | } else { |
| 1703 | __ movb(Address(obj, offset), Immediate(value.GetConstant()->AsIntConstant()->GetValue())); |
| 1704 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1705 | } else { |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 1706 | if (value.IsRegister()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1707 | __ movb(Address(obj, index.As<CpuRegister>(), TIMES_1, data_offset), |
| 1708 | value.As<CpuRegister>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 1709 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1710 | __ movb(Address(obj, index.As<CpuRegister>(), TIMES_1, data_offset), |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 1711 | Immediate(value.GetConstant()->AsIntConstant()->GetValue())); |
| 1712 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1713 | } |
| 1714 | break; |
| 1715 | } |
| 1716 | |
| 1717 | case Primitive::kPrimShort: |
| 1718 | case Primitive::kPrimChar: { |
| 1719 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1720 | if (index.IsConstant()) { |
| 1721 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset; |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 1722 | if (value.IsRegister()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1723 | __ movw(Address(obj, offset), value.As<CpuRegister>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 1724 | } else { |
| 1725 | __ movw(Address(obj, offset), Immediate(value.GetConstant()->AsIntConstant()->GetValue())); |
| 1726 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1727 | } else { |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 1728 | if (value.IsRegister()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1729 | __ movw(Address(obj, index.As<CpuRegister>(), TIMES_2, data_offset), |
| 1730 | value.As<CpuRegister>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 1731 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1732 | __ movw(Address(obj, index.As<CpuRegister>(), TIMES_2, data_offset), |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 1733 | Immediate(value.GetConstant()->AsIntConstant()->GetValue())); |
| 1734 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1735 | } |
| 1736 | break; |
| 1737 | } |
| 1738 | |
| 1739 | case Primitive::kPrimInt: { |
| 1740 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1741 | if (index.IsConstant()) { |
| 1742 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 1743 | if (value.IsRegister()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1744 | __ movl(Address(obj, offset), value.As<CpuRegister>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 1745 | } else { |
| 1746 | __ movl(Address(obj, offset), Immediate(value.GetConstant()->AsIntConstant()->GetValue())); |
| 1747 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1748 | } else { |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 1749 | if (value.IsRegister()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1750 | __ movl(Address(obj, index.As<CpuRegister>(), TIMES_4, data_offset), |
| 1751 | value.As<CpuRegister>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 1752 | } else { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1753 | DCHECK(value.IsConstant()) << value; |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1754 | __ movl(Address(obj, index.As<CpuRegister>(), TIMES_4, data_offset), |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 1755 | Immediate(value.GetConstant()->AsIntConstant()->GetValue())); |
| 1756 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1757 | } |
| 1758 | break; |
| 1759 | } |
| 1760 | |
| 1761 | case Primitive::kPrimNot: { |
| 1762 | __ gs()->call(Address::Absolute(QUICK_ENTRYPOINT_OFFSET(kX86_64WordSize, pAputObject), true)); |
| 1763 | DCHECK(!codegen_->IsLeafMethod()); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1764 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1765 | break; |
| 1766 | } |
| 1767 | |
| 1768 | case Primitive::kPrimLong: { |
| 1769 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1770 | if (index.IsConstant()) { |
| 1771 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 1772 | DCHECK(value.IsRegister()); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1773 | __ movq(Address(obj, offset), value.As<CpuRegister>()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1774 | } else { |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 1775 | DCHECK(value.IsRegister()); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1776 | __ movq(Address(obj, index.As<CpuRegister>(), TIMES_8, data_offset), |
| 1777 | value.As<CpuRegister>()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1778 | } |
| 1779 | break; |
| 1780 | } |
| 1781 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1782 | case Primitive::kPrimFloat: { |
| 1783 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value(); |
| 1784 | if (index.IsConstant()) { |
| 1785 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
| 1786 | DCHECK(value.IsFpuRegister()); |
| 1787 | __ movss(Address(obj, offset), value.As<XmmRegister>()); |
| 1788 | } else { |
| 1789 | DCHECK(value.IsFpuRegister()); |
| 1790 | __ movss(Address(obj, index.As<CpuRegister>(), TIMES_4, data_offset), |
| 1791 | value.As<XmmRegister>()); |
| 1792 | } |
| 1793 | break; |
| 1794 | } |
| 1795 | |
| 1796 | case Primitive::kPrimDouble: { |
| 1797 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value(); |
| 1798 | if (index.IsConstant()) { |
| 1799 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
| 1800 | DCHECK(value.IsFpuRegister()); |
| 1801 | __ movsd(Address(obj, offset), value.As<XmmRegister>()); |
| 1802 | } else { |
| 1803 | DCHECK(value.IsFpuRegister()); |
| 1804 | __ movsd(Address(obj, index.As<CpuRegister>(), TIMES_8, data_offset), |
| 1805 | value.As<XmmRegister>()); |
| 1806 | } |
| 1807 | break; |
| 1808 | } |
| 1809 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1810 | case Primitive::kPrimVoid: |
| 1811 | LOG(FATAL) << "Unreachable type " << instruction->GetType(); |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 1812 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1813 | } |
| 1814 | } |
| 1815 | |
| 1816 | void LocationsBuilderX86_64::VisitArrayLength(HArrayLength* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1817 | LocationSummary* locations = |
| 1818 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 1819 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1820 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1821 | } |
| 1822 | |
| 1823 | void InstructionCodeGeneratorX86_64::VisitArrayLength(HArrayLength* instruction) { |
| 1824 | LocationSummary* locations = instruction->GetLocations(); |
| 1825 | uint32_t offset = mirror::Array::LengthOffset().Uint32Value(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1826 | CpuRegister obj = locations->InAt(0).As<CpuRegister>(); |
| 1827 | CpuRegister out = locations->Out().As<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1828 | __ movl(out, Address(obj, offset)); |
| 1829 | } |
| 1830 | |
| 1831 | void LocationsBuilderX86_64::VisitBoundsCheck(HBoundsCheck* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1832 | LocationSummary* locations = |
| 1833 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1834 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1835 | locations->SetInAt(1, Location::RequiresRegister()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 1836 | if (instruction->HasUses()) { |
| 1837 | locations->SetOut(Location::SameAsFirstInput()); |
| 1838 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1839 | } |
| 1840 | |
| 1841 | void InstructionCodeGeneratorX86_64::VisitBoundsCheck(HBoundsCheck* instruction) { |
| 1842 | LocationSummary* locations = instruction->GetLocations(); |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 1843 | SlowPathCodeX86_64* slow_path = new (GetGraph()->GetArena()) BoundsCheckSlowPathX86_64( |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1844 | instruction, locations->InAt(0), locations->InAt(1)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1845 | codegen_->AddSlowPath(slow_path); |
| 1846 | |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1847 | CpuRegister index = locations->InAt(0).As<CpuRegister>(); |
| 1848 | CpuRegister length = locations->InAt(1).As<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1849 | |
| 1850 | __ cmpl(index, length); |
| 1851 | __ j(kAboveEqual, slow_path->GetEntryLabel()); |
| 1852 | } |
| 1853 | |
| 1854 | void CodeGeneratorX86_64::MarkGCCard(CpuRegister temp, |
| 1855 | CpuRegister card, |
| 1856 | CpuRegister object, |
| 1857 | CpuRegister value) { |
| 1858 | Label is_null; |
| 1859 | __ testl(value, value); |
| 1860 | __ j(kEqual, &is_null); |
| 1861 | __ gs()->movq(card, Address::Absolute( |
| 1862 | Thread::CardTableOffset<kX86_64WordSize>().Int32Value(), true)); |
| 1863 | __ movq(temp, object); |
| 1864 | __ shrq(temp, Immediate(gc::accounting::CardTable::kCardShift)); |
| 1865 | __ movb(Address(temp, card, TIMES_1, 0), card); |
| 1866 | __ Bind(&is_null); |
| 1867 | } |
| 1868 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1869 | void LocationsBuilderX86_64::VisitTemporary(HTemporary* temp) { |
| 1870 | temp->SetLocations(nullptr); |
| 1871 | } |
| 1872 | |
| 1873 | void InstructionCodeGeneratorX86_64::VisitTemporary(HTemporary* temp) { |
| 1874 | // Nothing to do, this is driven by the code generator. |
| 1875 | } |
| 1876 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1877 | void LocationsBuilderX86_64::VisitParallelMove(HParallelMove* instruction) { |
| 1878 | LOG(FATAL) << "Unimplemented"; |
| 1879 | } |
| 1880 | |
| 1881 | void InstructionCodeGeneratorX86_64::VisitParallelMove(HParallelMove* instruction) { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 1882 | codegen_->GetMoveResolver()->EmitNativeCode(instruction); |
| 1883 | } |
| 1884 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 1885 | void LocationsBuilderX86_64::VisitSuspendCheck(HSuspendCheck* instruction) { |
| 1886 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath); |
| 1887 | } |
| 1888 | |
| 1889 | void InstructionCodeGeneratorX86_64::VisitSuspendCheck(HSuspendCheck* instruction) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1890 | HBasicBlock* block = instruction->GetBlock(); |
| 1891 | if (block->GetLoopInformation() != nullptr) { |
| 1892 | DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction); |
| 1893 | // The back edge will generate the suspend check. |
| 1894 | return; |
| 1895 | } |
| 1896 | if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) { |
| 1897 | // The goto will generate the suspend check. |
| 1898 | return; |
| 1899 | } |
| 1900 | GenerateSuspendCheck(instruction, nullptr); |
| 1901 | } |
| 1902 | |
| 1903 | void InstructionCodeGeneratorX86_64::GenerateSuspendCheck(HSuspendCheck* instruction, |
| 1904 | HBasicBlock* successor) { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 1905 | SuspendCheckSlowPathX86_64* slow_path = |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1906 | new (GetGraph()->GetArena()) SuspendCheckSlowPathX86_64(instruction, successor); |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 1907 | codegen_->AddSlowPath(slow_path); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1908 | __ gs()->cmpw(Address::Absolute( |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 1909 | Thread::ThreadFlagsOffset<kX86_64WordSize>().Int32Value(), true), Immediate(0)); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1910 | if (successor == nullptr) { |
| 1911 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 1912 | __ Bind(slow_path->GetReturnLabel()); |
| 1913 | } else { |
| 1914 | __ j(kEqual, codegen_->GetLabelOf(successor)); |
| 1915 | __ jmp(slow_path->GetEntryLabel()); |
| 1916 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 1917 | } |
| 1918 | |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 1919 | X86_64Assembler* ParallelMoveResolverX86_64::GetAssembler() const { |
| 1920 | return codegen_->GetAssembler(); |
| 1921 | } |
| 1922 | |
| 1923 | void ParallelMoveResolverX86_64::EmitMove(size_t index) { |
| 1924 | MoveOperands* move = moves_.Get(index); |
| 1925 | Location source = move->GetSource(); |
| 1926 | Location destination = move->GetDestination(); |
| 1927 | |
| 1928 | if (source.IsRegister()) { |
| 1929 | if (destination.IsRegister()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1930 | __ movq(destination.As<CpuRegister>(), source.As<CpuRegister>()); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1931 | } else if (destination.IsStackSlot()) { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 1932 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1933 | source.As<CpuRegister>()); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1934 | } else { |
| 1935 | DCHECK(destination.IsDoubleStackSlot()); |
| 1936 | __ movq(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1937 | source.As<CpuRegister>()); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 1938 | } |
| 1939 | } else if (source.IsStackSlot()) { |
| 1940 | if (destination.IsRegister()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1941 | __ movl(destination.As<CpuRegister>(), |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 1942 | Address(CpuRegister(RSP), source.GetStackIndex())); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1943 | } else if (destination.IsFpuRegister()) { |
| 1944 | __ movss(destination.As<XmmRegister>(), |
| 1945 | Address(CpuRegister(RSP), source.GetStackIndex())); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 1946 | } else { |
| 1947 | DCHECK(destination.IsStackSlot()); |
| 1948 | __ movl(CpuRegister(TMP), Address(CpuRegister(RSP), source.GetStackIndex())); |
| 1949 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), CpuRegister(TMP)); |
| 1950 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1951 | } else if (source.IsDoubleStackSlot()) { |
| 1952 | if (destination.IsRegister()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1953 | __ movq(destination.As<CpuRegister>(), |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1954 | Address(CpuRegister(RSP), source.GetStackIndex())); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1955 | } else if (destination.IsFpuRegister()) { |
| 1956 | __ movsd(destination.As<XmmRegister>(), Address(CpuRegister(RSP), source.GetStackIndex())); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1957 | } else { |
Nicolas Geoffray | c8147a7 | 2014-10-21 16:06:20 +0100 | [diff] [blame] | 1958 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1959 | __ movq(CpuRegister(TMP), Address(CpuRegister(RSP), source.GetStackIndex())); |
| 1960 | __ movq(Address(CpuRegister(RSP), destination.GetStackIndex()), CpuRegister(TMP)); |
| 1961 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1962 | } else if (source.IsConstant()) { |
| 1963 | HConstant* constant = source.GetConstant(); |
| 1964 | if (constant->IsIntConstant()) { |
| 1965 | Immediate imm(constant->AsIntConstant()->GetValue()); |
| 1966 | if (destination.IsRegister()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1967 | __ movl(destination.As<CpuRegister>(), imm); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1968 | } else { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1969 | DCHECK(destination.IsStackSlot()) << destination; |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1970 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), imm); |
| 1971 | } |
| 1972 | } else if (constant->IsLongConstant()) { |
| 1973 | int64_t value = constant->AsLongConstant()->GetValue(); |
| 1974 | if (destination.IsRegister()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1975 | __ movq(destination.As<CpuRegister>(), Immediate(value)); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1976 | } else { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1977 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1978 | __ movq(CpuRegister(TMP), Immediate(value)); |
| 1979 | __ movq(Address(CpuRegister(RSP), destination.GetStackIndex()), CpuRegister(TMP)); |
| 1980 | } |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1981 | } else if (constant->IsFloatConstant()) { |
| 1982 | Immediate imm(bit_cast<float, int32_t>(constant->AsFloatConstant()->GetValue())); |
| 1983 | if (destination.IsFpuRegister()) { |
| 1984 | __ movl(CpuRegister(TMP), imm); |
| 1985 | __ movd(destination.As<XmmRegister>(), CpuRegister(TMP)); |
| 1986 | } else { |
| 1987 | DCHECK(destination.IsStackSlot()) << destination; |
| 1988 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), imm); |
| 1989 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1990 | } else { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1991 | DCHECK(constant->IsDoubleConstant()) << constant->DebugName(); |
| 1992 | Immediate imm(bit_cast<double, int64_t>(constant->AsDoubleConstant()->GetValue())); |
| 1993 | if (destination.IsFpuRegister()) { |
| 1994 | __ movq(CpuRegister(TMP), imm); |
| 1995 | __ movd(destination.As<XmmRegister>(), CpuRegister(TMP)); |
| 1996 | } else { |
| 1997 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 1998 | __ movq(CpuRegister(TMP), imm); |
| 1999 | __ movq(Address(CpuRegister(RSP), destination.GetStackIndex()), CpuRegister(TMP)); |
| 2000 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2001 | } |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2002 | } else if (source.IsFpuRegister()) { |
| 2003 | if (destination.IsFpuRegister()) { |
| 2004 | __ movaps(destination.As<XmmRegister>(), source.As<XmmRegister>()); |
| 2005 | } else if (destination.IsStackSlot()) { |
| 2006 | __ movss(Address(CpuRegister(RSP), destination.GetStackIndex()), |
| 2007 | source.As<XmmRegister>()); |
| 2008 | } else { |
| 2009 | DCHECK(destination.IsDoubleStackSlot()); |
| 2010 | __ movsd(Address(CpuRegister(RSP), destination.GetStackIndex()), |
| 2011 | source.As<XmmRegister>()); |
| 2012 | } |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 2013 | } |
| 2014 | } |
| 2015 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 2016 | void ParallelMoveResolverX86_64::Exchange32(CpuRegister reg, int mem) { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 2017 | __ movl(CpuRegister(TMP), Address(CpuRegister(RSP), mem)); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 2018 | __ movl(Address(CpuRegister(RSP), mem), reg); |
| 2019 | __ movl(reg, CpuRegister(TMP)); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 2020 | } |
| 2021 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 2022 | void ParallelMoveResolverX86_64::Exchange32(int mem1, int mem2) { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 2023 | ScratchRegisterScope ensure_scratch( |
| 2024 | this, TMP, RAX, codegen_->GetNumberOfCoreRegisters()); |
| 2025 | |
| 2026 | int stack_offset = ensure_scratch.IsSpilled() ? kX86_64WordSize : 0; |
| 2027 | __ movl(CpuRegister(TMP), Address(CpuRegister(RSP), mem1 + stack_offset)); |
| 2028 | __ movl(CpuRegister(ensure_scratch.GetRegister()), |
| 2029 | Address(CpuRegister(RSP), mem2 + stack_offset)); |
| 2030 | __ movl(Address(CpuRegister(RSP), mem2 + stack_offset), CpuRegister(TMP)); |
| 2031 | __ movl(Address(CpuRegister(RSP), mem1 + stack_offset), |
| 2032 | CpuRegister(ensure_scratch.GetRegister())); |
| 2033 | } |
| 2034 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 2035 | void ParallelMoveResolverX86_64::Exchange64(CpuRegister reg, int mem) { |
| 2036 | __ movq(CpuRegister(TMP), Address(CpuRegister(RSP), mem)); |
| 2037 | __ movq(Address(CpuRegister(RSP), mem), reg); |
| 2038 | __ movq(reg, CpuRegister(TMP)); |
| 2039 | } |
| 2040 | |
| 2041 | void ParallelMoveResolverX86_64::Exchange64(int mem1, int mem2) { |
| 2042 | ScratchRegisterScope ensure_scratch( |
| 2043 | this, TMP, RAX, codegen_->GetNumberOfCoreRegisters()); |
| 2044 | |
| 2045 | int stack_offset = ensure_scratch.IsSpilled() ? kX86_64WordSize : 0; |
| 2046 | __ movq(CpuRegister(TMP), Address(CpuRegister(RSP), mem1 + stack_offset)); |
| 2047 | __ movq(CpuRegister(ensure_scratch.GetRegister()), |
| 2048 | Address(CpuRegister(RSP), mem2 + stack_offset)); |
| 2049 | __ movq(Address(CpuRegister(RSP), mem2 + stack_offset), CpuRegister(TMP)); |
| 2050 | __ movq(Address(CpuRegister(RSP), mem1 + stack_offset), |
| 2051 | CpuRegister(ensure_scratch.GetRegister())); |
| 2052 | } |
| 2053 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2054 | void ParallelMoveResolverX86_64::Exchange32(XmmRegister reg, int mem) { |
| 2055 | __ movl(CpuRegister(TMP), Address(CpuRegister(RSP), mem)); |
| 2056 | __ movss(Address(CpuRegister(RSP), mem), reg); |
| 2057 | __ movd(reg, CpuRegister(TMP)); |
| 2058 | } |
| 2059 | |
| 2060 | void ParallelMoveResolverX86_64::Exchange64(XmmRegister reg, int mem) { |
| 2061 | __ movq(CpuRegister(TMP), Address(CpuRegister(RSP), mem)); |
| 2062 | __ movsd(Address(CpuRegister(RSP), mem), reg); |
| 2063 | __ movd(reg, CpuRegister(TMP)); |
| 2064 | } |
| 2065 | |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 2066 | void ParallelMoveResolverX86_64::EmitSwap(size_t index) { |
| 2067 | MoveOperands* move = moves_.Get(index); |
| 2068 | Location source = move->GetSource(); |
| 2069 | Location destination = move->GetDestination(); |
| 2070 | |
| 2071 | if (source.IsRegister() && destination.IsRegister()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2072 | __ xchgq(destination.As<CpuRegister>(), source.As<CpuRegister>()); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 2073 | } else if (source.IsRegister() && destination.IsStackSlot()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2074 | Exchange32(source.As<CpuRegister>(), destination.GetStackIndex()); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 2075 | } else if (source.IsStackSlot() && destination.IsRegister()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2076 | Exchange32(destination.As<CpuRegister>(), source.GetStackIndex()); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 2077 | } else if (source.IsStackSlot() && destination.IsStackSlot()) { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 2078 | Exchange32(destination.GetStackIndex(), source.GetStackIndex()); |
| 2079 | } else if (source.IsRegister() && destination.IsDoubleStackSlot()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2080 | Exchange64(source.As<CpuRegister>(), destination.GetStackIndex()); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 2081 | } else if (source.IsDoubleStackSlot() && destination.IsRegister()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2082 | Exchange64(destination.As<CpuRegister>(), source.GetStackIndex()); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 2083 | } else if (source.IsDoubleStackSlot() && destination.IsDoubleStackSlot()) { |
| 2084 | Exchange64(destination.GetStackIndex(), source.GetStackIndex()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2085 | } else if (source.IsFpuRegister() && destination.IsFpuRegister()) { |
| 2086 | __ movd(CpuRegister(TMP), source.As<XmmRegister>()); |
| 2087 | __ movaps(source.As<XmmRegister>(), destination.As<XmmRegister>()); |
| 2088 | __ movd(destination.As<XmmRegister>(), CpuRegister(TMP)); |
| 2089 | } else if (source.IsFpuRegister() && destination.IsStackSlot()) { |
| 2090 | Exchange32(source.As<XmmRegister>(), destination.GetStackIndex()); |
| 2091 | } else if (source.IsStackSlot() && destination.IsFpuRegister()) { |
| 2092 | Exchange32(destination.As<XmmRegister>(), source.GetStackIndex()); |
| 2093 | } else if (source.IsFpuRegister() && destination.IsDoubleStackSlot()) { |
| 2094 | Exchange64(source.As<XmmRegister>(), destination.GetStackIndex()); |
| 2095 | } else if (source.IsDoubleStackSlot() && destination.IsFpuRegister()) { |
| 2096 | Exchange64(destination.As<XmmRegister>(), source.GetStackIndex()); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 2097 | } else { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2098 | LOG(FATAL) << "Unimplemented swap between " << source << " and " << destination; |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 2099 | } |
| 2100 | } |
| 2101 | |
| 2102 | |
| 2103 | void ParallelMoveResolverX86_64::SpillScratch(int reg) { |
| 2104 | __ pushq(CpuRegister(reg)); |
| 2105 | } |
| 2106 | |
| 2107 | |
| 2108 | void ParallelMoveResolverX86_64::RestoreScratch(int reg) { |
| 2109 | __ popq(CpuRegister(reg)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2110 | } |
| 2111 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame^] | 2112 | void LocationsBuilderX86_64::VisitLoadClass(HLoadClass* cls) { |
| 2113 | LocationSummary* locations = |
| 2114 | new (GetGraph()->GetArena()) LocationSummary(cls, LocationSummary::kNoCall); |
| 2115 | locations->SetOut(Location::RequiresRegister()); |
| 2116 | } |
| 2117 | |
| 2118 | void InstructionCodeGeneratorX86_64::VisitLoadClass(HLoadClass* cls) { |
| 2119 | CpuRegister out = cls->GetLocations()->Out().As<CpuRegister>(); |
| 2120 | if (cls->IsReferrersClass()) { |
| 2121 | codegen_->LoadCurrentMethod(out); |
| 2122 | __ movl(out, Address(out, mirror::ArtMethod::DeclaringClassOffset().Int32Value())); |
| 2123 | } else { |
| 2124 | codegen_->LoadCurrentMethod(out); |
| 2125 | __ movl(out, Address(out, mirror::ArtMethod::DexCacheResolvedTypesOffset().Int32Value())); |
| 2126 | __ movl(out, Address(out, CodeGenerator::GetCacheOffset(cls->GetTypeIndex()))); |
| 2127 | } |
| 2128 | } |
| 2129 | |
| 2130 | void LocationsBuilderX86_64::VisitClinitCheck(HClinitCheck* check) { |
| 2131 | LocationSummary* locations = |
| 2132 | new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath); |
| 2133 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2134 | if (check->HasUses()) { |
| 2135 | locations->SetOut(Location::SameAsFirstInput()); |
| 2136 | } |
| 2137 | } |
| 2138 | |
| 2139 | void InstructionCodeGeneratorX86_64::VisitClinitCheck(HClinitCheck* check) { |
| 2140 | SlowPathCodeX86_64* slow_path = new (GetGraph()->GetArena()) ClinitCheckSlowPathX86_64(check); |
| 2141 | codegen_->AddSlowPath(slow_path); |
| 2142 | |
| 2143 | LocationSummary* locations = check->GetLocations(); |
| 2144 | // We remove the class as a live register, we know it's null or unused in the slow path. |
| 2145 | RegisterSet* register_set = locations->GetLiveRegisters(); |
| 2146 | register_set->Remove(locations->InAt(0)); |
| 2147 | |
| 2148 | CpuRegister class_reg = locations->InAt(0).As<CpuRegister>(); |
| 2149 | __ testl(class_reg, class_reg); |
| 2150 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 2151 | __ cmpl(Address(class_reg, mirror::Class::StatusOffset().Int32Value()), |
| 2152 | Immediate(mirror::Class::kStatusInitialized)); |
| 2153 | __ j(kLess, slow_path->GetEntryLabel()); |
| 2154 | __ Bind(slow_path->GetExitLabel()); |
| 2155 | // No need for memory fence, thanks to the X86_64 memory model. |
| 2156 | } |
| 2157 | |
| 2158 | void LocationsBuilderX86_64::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 2159 | LocationSummary* locations = |
| 2160 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 2161 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2162 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2163 | } |
| 2164 | |
| 2165 | void InstructionCodeGeneratorX86_64::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 2166 | LocationSummary* locations = instruction->GetLocations(); |
| 2167 | CpuRegister cls = locations->InAt(0).As<CpuRegister>(); |
| 2168 | CpuRegister out = locations->Out().As<CpuRegister>(); |
| 2169 | size_t offset = instruction->GetFieldOffset().SizeValue(); |
| 2170 | |
| 2171 | switch (instruction->GetType()) { |
| 2172 | case Primitive::kPrimBoolean: { |
| 2173 | __ movzxb(out, Address(cls, offset)); |
| 2174 | break; |
| 2175 | } |
| 2176 | |
| 2177 | case Primitive::kPrimByte: { |
| 2178 | __ movsxb(out, Address(cls, offset)); |
| 2179 | break; |
| 2180 | } |
| 2181 | |
| 2182 | case Primitive::kPrimShort: { |
| 2183 | __ movsxw(out, Address(cls, offset)); |
| 2184 | break; |
| 2185 | } |
| 2186 | |
| 2187 | case Primitive::kPrimChar: { |
| 2188 | __ movzxw(out, Address(cls, offset)); |
| 2189 | break; |
| 2190 | } |
| 2191 | |
| 2192 | case Primitive::kPrimInt: |
| 2193 | case Primitive::kPrimNot: { |
| 2194 | __ movl(out, Address(cls, offset)); |
| 2195 | break; |
| 2196 | } |
| 2197 | |
| 2198 | case Primitive::kPrimLong: { |
| 2199 | __ movq(out, Address(cls, offset)); |
| 2200 | break; |
| 2201 | } |
| 2202 | |
| 2203 | case Primitive::kPrimFloat: |
| 2204 | case Primitive::kPrimDouble: |
| 2205 | LOG(FATAL) << "Unimplemented register type " << instruction->GetType(); |
| 2206 | UNREACHABLE(); |
| 2207 | case Primitive::kPrimVoid: |
| 2208 | LOG(FATAL) << "Unreachable type " << instruction->GetType(); |
| 2209 | UNREACHABLE(); |
| 2210 | } |
| 2211 | } |
| 2212 | |
| 2213 | void LocationsBuilderX86_64::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
| 2214 | LocationSummary* locations = |
| 2215 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 2216 | Primitive::Type field_type = instruction->GetFieldType(); |
| 2217 | bool is_object_type = field_type == Primitive::kPrimNot; |
| 2218 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2219 | locations->SetInAt(1, Location::RequiresRegister()); |
| 2220 | if (is_object_type) { |
| 2221 | // Temporary registers for the write barrier. |
| 2222 | locations->AddTemp(Location::RequiresRegister()); |
| 2223 | locations->AddTemp(Location::RequiresRegister()); |
| 2224 | } |
| 2225 | } |
| 2226 | |
| 2227 | void InstructionCodeGeneratorX86_64::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
| 2228 | LocationSummary* locations = instruction->GetLocations(); |
| 2229 | CpuRegister cls = locations->InAt(0).As<CpuRegister>(); |
| 2230 | CpuRegister value = locations->InAt(1).As<CpuRegister>(); |
| 2231 | size_t offset = instruction->GetFieldOffset().SizeValue(); |
| 2232 | Primitive::Type field_type = instruction->GetFieldType(); |
| 2233 | |
| 2234 | switch (field_type) { |
| 2235 | case Primitive::kPrimBoolean: |
| 2236 | case Primitive::kPrimByte: { |
| 2237 | __ movb(Address(cls, offset), value); |
| 2238 | break; |
| 2239 | } |
| 2240 | |
| 2241 | case Primitive::kPrimShort: |
| 2242 | case Primitive::kPrimChar: { |
| 2243 | __ movw(Address(cls, offset), value); |
| 2244 | break; |
| 2245 | } |
| 2246 | |
| 2247 | case Primitive::kPrimInt: |
| 2248 | case Primitive::kPrimNot: { |
| 2249 | __ movl(Address(cls, offset), value); |
| 2250 | if (field_type == Primitive::kPrimNot) { |
| 2251 | CpuRegister temp = locations->GetTemp(0).As<CpuRegister>(); |
| 2252 | CpuRegister card = locations->GetTemp(1).As<CpuRegister>(); |
| 2253 | codegen_->MarkGCCard(temp, card, cls, value); |
| 2254 | } |
| 2255 | break; |
| 2256 | } |
| 2257 | |
| 2258 | case Primitive::kPrimLong: { |
| 2259 | __ movq(Address(cls, offset), value); |
| 2260 | break; |
| 2261 | } |
| 2262 | |
| 2263 | case Primitive::kPrimFloat: |
| 2264 | case Primitive::kPrimDouble: |
| 2265 | LOG(FATAL) << "Unimplemented register type " << field_type; |
| 2266 | UNREACHABLE(); |
| 2267 | case Primitive::kPrimVoid: |
| 2268 | LOG(FATAL) << "Unreachable type " << field_type; |
| 2269 | UNREACHABLE(); |
| 2270 | } |
| 2271 | } |
| 2272 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2273 | } // namespace x86_64 |
| 2274 | } // namespace art |