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