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