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