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