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