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); |
Calin Juravle | 91debbc | 2014-11-26 19:01:09 +0000 | [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) { |
Calin Juravle | 91debbc | 2014-11-26 19:01:09 +0000 | [diff] [blame^] | 908 | Label greater, done; |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 909 | LocationSummary* locations = compare->GetLocations(); |
Calin Juravle | 91debbc | 2014-11-26 19:01:09 +0000 | [diff] [blame^] | 910 | switch (compare->InputAt(0)->GetType()) { |
| 911 | case Primitive::kPrimLong: |
| 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: |
Calin Juravle | 91debbc | 2014-11-26 19:01:09 +0000 | [diff] [blame^] | 916 | LOG(FATAL) << "Unimplemented compare type " << compare->InputAt(0)->GetType(); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 917 | } |
Calin Juravle | cea28ec | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 918 | |
Calin Juravle | 91debbc | 2014-11-26 19:01:09 +0000 | [diff] [blame^] | 919 | CpuRegister output = locations->Out().As<CpuRegister>(); |
| 920 | __ movl(output, Immediate(0)); |
| 921 | __ j(kEqual, &done); |
| 922 | __ j(kGreater, &greater); |
| 923 | |
| 924 | __ movl(output, Immediate(-1)); |
Calin Juravle | fd86124 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 925 | __ jmp(&done); |
| 926 | |
Calin Juravle | 91debbc | 2014-11-26 19:01:09 +0000 | [diff] [blame^] | 927 | __ Bind(&greater); |
| 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)() |
Mathieu Chartier | 2d72101 | 2014-11-10 11:08:06 -0800 | [diff] [blame] | 1115 | __ call(Address(temp, mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
Nicolas Geoffray | 86a8d7a | 2014-11-19 08:47:18 +0000 | [diff] [blame] | 1116 | kX86_64WordSize).SizeValue())); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1117 | |
| 1118 | DCHECK(!codegen_->IsLeafMethod()); |
| 1119 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 1120 | } |
| 1121 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1122 | void LocationsBuilderX86_64::HandleInvoke(HInvoke* invoke) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1123 | LocationSummary* locations = |
| 1124 | new (GetGraph()->GetArena()) LocationSummary(invoke, LocationSummary::kCall); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1125 | locations->AddTemp(Location::RegisterLocation(RDI)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1126 | |
| 1127 | InvokeDexCallingConventionVisitor calling_convention_visitor; |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1128 | for (size_t i = 0; i < invoke->InputCount(); i++) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1129 | HInstruction* input = invoke->InputAt(i); |
| 1130 | locations->SetInAt(i, calling_convention_visitor.GetNextLocation(input->GetType())); |
| 1131 | } |
| 1132 | |
| 1133 | switch (invoke->GetType()) { |
| 1134 | case Primitive::kPrimBoolean: |
| 1135 | case Primitive::kPrimByte: |
| 1136 | case Primitive::kPrimChar: |
| 1137 | case Primitive::kPrimShort: |
| 1138 | case Primitive::kPrimInt: |
| 1139 | case Primitive::kPrimNot: |
| 1140 | case Primitive::kPrimLong: |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1141 | locations->SetOut(Location::RegisterLocation(RAX)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1142 | break; |
| 1143 | |
| 1144 | case Primitive::kPrimVoid: |
| 1145 | break; |
| 1146 | |
| 1147 | case Primitive::kPrimDouble: |
| 1148 | case Primitive::kPrimFloat: |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1149 | locations->SetOut(Location::FpuRegisterLocation(XMM0)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1150 | break; |
| 1151 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1152 | } |
| 1153 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1154 | void LocationsBuilderX86_64::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
| 1155 | HandleInvoke(invoke); |
| 1156 | } |
| 1157 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1158 | void InstructionCodeGeneratorX86_64::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1159 | CpuRegister temp = invoke->GetLocations()->GetTemp(0).As<CpuRegister>(); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1160 | size_t method_offset = mirror::Class::EmbeddedVTableOffset().SizeValue() + |
| 1161 | invoke->GetVTableIndex() * sizeof(mirror::Class::VTableEntry); |
| 1162 | LocationSummary* locations = invoke->GetLocations(); |
| 1163 | Location receiver = locations->InAt(0); |
| 1164 | size_t class_offset = mirror::Object::ClassOffset().SizeValue(); |
| 1165 | // temp = object->GetClass(); |
| 1166 | if (receiver.IsStackSlot()) { |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1167 | __ movl(temp, Address(CpuRegister(RSP), receiver.GetStackIndex())); |
| 1168 | __ movl(temp, Address(temp, class_offset)); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1169 | } else { |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1170 | __ movl(temp, Address(receiver.As<CpuRegister>(), class_offset)); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1171 | } |
| 1172 | // temp = temp->GetMethodAt(method_offset); |
| 1173 | __ movl(temp, Address(temp, method_offset)); |
| 1174 | // call temp->GetEntryPoint(); |
Mathieu Chartier | 2d72101 | 2014-11-10 11:08:06 -0800 | [diff] [blame] | 1175 | __ call(Address(temp, mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
Nicolas Geoffray | 86a8d7a | 2014-11-19 08:47:18 +0000 | [diff] [blame] | 1176 | kX86_64WordSize).SizeValue())); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1177 | |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 1178 | DCHECK(!codegen_->IsLeafMethod()); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1179 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1180 | } |
| 1181 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1182 | void LocationsBuilderX86_64::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 1183 | HandleInvoke(invoke); |
| 1184 | // Add the hidden argument. |
| 1185 | invoke->GetLocations()->AddTemp(Location::RegisterLocation(RAX)); |
| 1186 | } |
| 1187 | |
| 1188 | void InstructionCodeGeneratorX86_64::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 1189 | // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError. |
| 1190 | CpuRegister temp = invoke->GetLocations()->GetTemp(0).As<CpuRegister>(); |
| 1191 | uint32_t method_offset = mirror::Class::EmbeddedImTableOffset().Uint32Value() + |
| 1192 | (invoke->GetImtIndex() % mirror::Class::kImtSize) * sizeof(mirror::Class::ImTableEntry); |
| 1193 | LocationSummary* locations = invoke->GetLocations(); |
| 1194 | Location receiver = locations->InAt(0); |
| 1195 | size_t class_offset = mirror::Object::ClassOffset().SizeValue(); |
| 1196 | |
| 1197 | // Set the hidden argument. |
| 1198 | __ movq(invoke->GetLocations()->GetTemp(1).As<CpuRegister>(), |
| 1199 | Immediate(invoke->GetDexMethodIndex())); |
| 1200 | |
| 1201 | // temp = object->GetClass(); |
| 1202 | if (receiver.IsStackSlot()) { |
| 1203 | __ movl(temp, Address(CpuRegister(RSP), receiver.GetStackIndex())); |
| 1204 | __ movl(temp, Address(temp, class_offset)); |
| 1205 | } else { |
| 1206 | __ movl(temp, Address(receiver.As<CpuRegister>(), class_offset)); |
| 1207 | } |
| 1208 | // temp = temp->GetImtEntryAt(method_offset); |
| 1209 | __ movl(temp, Address(temp, method_offset)); |
| 1210 | // call temp->GetEntryPoint(); |
Mathieu Chartier | 2d72101 | 2014-11-10 11:08:06 -0800 | [diff] [blame] | 1211 | __ call(Address(temp, mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
Nicolas Geoffray | 86a8d7a | 2014-11-19 08:47:18 +0000 | [diff] [blame] | 1212 | kX86_64WordSize).SizeValue())); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1213 | |
| 1214 | DCHECK(!codegen_->IsLeafMethod()); |
| 1215 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 1216 | } |
| 1217 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1218 | void LocationsBuilderX86_64::VisitNeg(HNeg* neg) { |
| 1219 | LocationSummary* locations = |
| 1220 | new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall); |
| 1221 | switch (neg->GetResultType()) { |
| 1222 | case Primitive::kPrimInt: |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 1223 | case Primitive::kPrimLong: |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1224 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1225 | locations->SetOut(Location::SameAsFirstInput()); |
| 1226 | break; |
| 1227 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1228 | case Primitive::kPrimFloat: |
| 1229 | case Primitive::kPrimDouble: |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 1230 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1231 | // Output overlaps as we need a fresh (zero-initialized) |
| 1232 | // register to perform subtraction from zero. |
| 1233 | locations->SetOut(Location::RequiresFpuRegister()); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1234 | break; |
| 1235 | |
| 1236 | default: |
| 1237 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 1238 | } |
| 1239 | } |
| 1240 | |
| 1241 | void InstructionCodeGeneratorX86_64::VisitNeg(HNeg* neg) { |
| 1242 | LocationSummary* locations = neg->GetLocations(); |
| 1243 | Location out = locations->Out(); |
| 1244 | Location in = locations->InAt(0); |
| 1245 | switch (neg->GetResultType()) { |
| 1246 | case Primitive::kPrimInt: |
| 1247 | DCHECK(in.IsRegister()); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 1248 | DCHECK(in.Equals(out)); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1249 | __ negl(out.As<CpuRegister>()); |
| 1250 | break; |
| 1251 | |
| 1252 | case Primitive::kPrimLong: |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 1253 | DCHECK(in.IsRegister()); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 1254 | DCHECK(in.Equals(out)); |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 1255 | __ negq(out.As<CpuRegister>()); |
| 1256 | break; |
| 1257 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1258 | case Primitive::kPrimFloat: |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 1259 | DCHECK(in.IsFpuRegister()); |
| 1260 | DCHECK(out.IsFpuRegister()); |
| 1261 | DCHECK(!in.Equals(out)); |
| 1262 | // TODO: Instead of computing negation as a subtraction from |
| 1263 | // zero, implement it with an exclusive or with value 0x80000000 |
| 1264 | // (mask for bit 31, representing the sign of a single-precision |
| 1265 | // floating-point number), fetched from a constant pool: |
| 1266 | // |
| 1267 | // xorps out, [RIP:...] // value at RIP is 0x80 00 00 00 |
| 1268 | |
| 1269 | // out = 0 |
| 1270 | __ xorps(out.As<XmmRegister>(), out.As<XmmRegister>()); |
| 1271 | // out = out - in |
| 1272 | __ subss(out.As<XmmRegister>(), in.As<XmmRegister>()); |
| 1273 | break; |
| 1274 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1275 | case Primitive::kPrimDouble: |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 1276 | DCHECK(in.IsFpuRegister()); |
| 1277 | DCHECK(out.IsFpuRegister()); |
| 1278 | DCHECK(!in.Equals(out)); |
| 1279 | // TODO: Instead of computing negation as a subtraction from |
| 1280 | // zero, implement it with an exclusive or with value |
| 1281 | // 0x8000000000000000 (mask for bit 63, representing the sign of |
| 1282 | // a double-precision floating-point number), fetched from a |
| 1283 | // constant pool: |
| 1284 | // |
| 1285 | // xorpd out, [RIP:...] // value at RIP is 0x80 00 00 00 00 00 00 00 |
| 1286 | |
| 1287 | // out = 0 |
| 1288 | __ xorpd(out.As<XmmRegister>(), out.As<XmmRegister>()); |
| 1289 | // out = out - in |
| 1290 | __ subsd(out.As<XmmRegister>(), in.As<XmmRegister>()); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1291 | break; |
| 1292 | |
| 1293 | default: |
| 1294 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 1295 | } |
| 1296 | } |
| 1297 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1298 | void LocationsBuilderX86_64::VisitTypeConversion(HTypeConversion* conversion) { |
| 1299 | LocationSummary* locations = |
| 1300 | new (GetGraph()->GetArena()) LocationSummary(conversion, LocationSummary::kNoCall); |
| 1301 | Primitive::Type result_type = conversion->GetResultType(); |
| 1302 | Primitive::Type input_type = conversion->GetInputType(); |
| 1303 | switch (result_type) { |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 1304 | case Primitive::kPrimByte: |
| 1305 | switch (input_type) { |
| 1306 | case Primitive::kPrimShort: |
| 1307 | case Primitive::kPrimInt: |
| 1308 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 1309 | // Processing a Dex `int-to-byte' instruction. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 1310 | locations->SetInAt(0, Location::Any()); |
| 1311 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1312 | break; |
| 1313 | |
| 1314 | default: |
| 1315 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1316 | << " to " << result_type; |
| 1317 | } |
| 1318 | break; |
| 1319 | |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 1320 | case Primitive::kPrimShort: |
| 1321 | switch (input_type) { |
| 1322 | case Primitive::kPrimByte: |
| 1323 | case Primitive::kPrimInt: |
| 1324 | case Primitive::kPrimChar: |
| 1325 | // Processing a Dex `int-to-short' instruction. |
| 1326 | locations->SetInAt(0, Location::Any()); |
| 1327 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1328 | break; |
| 1329 | |
| 1330 | default: |
| 1331 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1332 | << " to " << result_type; |
| 1333 | } |
| 1334 | break; |
| 1335 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 1336 | case Primitive::kPrimInt: |
| 1337 | switch (input_type) { |
| 1338 | case Primitive::kPrimLong: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 1339 | // Processing a Dex `long-to-int' instruction. |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 1340 | locations->SetInAt(0, Location::Any()); |
| 1341 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1342 | break; |
| 1343 | |
| 1344 | case Primitive::kPrimFloat: |
| 1345 | case Primitive::kPrimDouble: |
| 1346 | LOG(FATAL) << "Type conversion from " << input_type |
| 1347 | << " to " << result_type << " not yet implemented"; |
| 1348 | break; |
| 1349 | |
| 1350 | default: |
| 1351 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1352 | << " to " << result_type; |
| 1353 | } |
| 1354 | break; |
| 1355 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1356 | case Primitive::kPrimLong: |
| 1357 | switch (input_type) { |
| 1358 | case Primitive::kPrimByte: |
| 1359 | case Primitive::kPrimShort: |
| 1360 | case Primitive::kPrimInt: |
Roland Levillain | 666c732 | 2014-11-10 13:39:43 +0000 | [diff] [blame] | 1361 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 1362 | // Processing a Dex `int-to-long' instruction. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1363 | // TODO: We would benefit from a (to-be-implemented) |
| 1364 | // Location::RegisterOrStackSlot requirement for this input. |
| 1365 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1366 | locations->SetOut(Location::RequiresRegister()); |
| 1367 | break; |
| 1368 | |
| 1369 | case Primitive::kPrimFloat: |
| 1370 | case Primitive::kPrimDouble: |
| 1371 | LOG(FATAL) << "Type conversion from " << input_type << " to " |
| 1372 | << result_type << " not yet implemented"; |
| 1373 | break; |
| 1374 | |
| 1375 | default: |
| 1376 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1377 | << " to " << result_type; |
| 1378 | } |
| 1379 | break; |
| 1380 | |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 1381 | case Primitive::kPrimChar: |
| 1382 | switch (input_type) { |
| 1383 | case Primitive::kPrimByte: |
| 1384 | case Primitive::kPrimShort: |
| 1385 | case Primitive::kPrimInt: |
| 1386 | case Primitive::kPrimChar: |
| 1387 | // Processing a Dex `int-to-char' instruction. |
| 1388 | locations->SetInAt(0, Location::Any()); |
| 1389 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1390 | break; |
| 1391 | |
| 1392 | default: |
| 1393 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1394 | << " to " << result_type; |
| 1395 | } |
| 1396 | break; |
| 1397 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1398 | case Primitive::kPrimFloat: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 1399 | switch (input_type) { |
| 1400 | case Primitive::kPrimByte: |
| 1401 | case Primitive::kPrimShort: |
| 1402 | case Primitive::kPrimInt: |
| 1403 | case Primitive::kPrimChar: |
| 1404 | // Processing a Dex `int-to-float' instruction. |
| 1405 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1406 | locations->SetOut(Location::RequiresFpuRegister()); |
| 1407 | break; |
| 1408 | |
| 1409 | case Primitive::kPrimLong: |
| 1410 | case Primitive::kPrimDouble: |
| 1411 | LOG(FATAL) << "Type conversion from " << input_type |
| 1412 | << " to " << result_type << " not yet implemented"; |
| 1413 | break; |
| 1414 | |
| 1415 | default: |
| 1416 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1417 | << " to " << result_type; |
| 1418 | }; |
| 1419 | break; |
| 1420 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1421 | case Primitive::kPrimDouble: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 1422 | switch (input_type) { |
| 1423 | case Primitive::kPrimByte: |
| 1424 | case Primitive::kPrimShort: |
| 1425 | case Primitive::kPrimInt: |
| 1426 | case Primitive::kPrimChar: |
| 1427 | // Processing a Dex `int-to-double' instruction. |
| 1428 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1429 | locations->SetOut(Location::RequiresFpuRegister()); |
| 1430 | break; |
| 1431 | |
| 1432 | case Primitive::kPrimLong: |
| 1433 | case Primitive::kPrimFloat: |
| 1434 | LOG(FATAL) << "Type conversion from " << input_type |
| 1435 | << " to " << result_type << " not yet implemented"; |
| 1436 | break; |
| 1437 | |
| 1438 | default: |
| 1439 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1440 | << " to " << result_type; |
| 1441 | } |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1442 | break; |
| 1443 | |
| 1444 | default: |
| 1445 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1446 | << " to " << result_type; |
| 1447 | } |
| 1448 | } |
| 1449 | |
| 1450 | void InstructionCodeGeneratorX86_64::VisitTypeConversion(HTypeConversion* conversion) { |
| 1451 | LocationSummary* locations = conversion->GetLocations(); |
| 1452 | Location out = locations->Out(); |
| 1453 | Location in = locations->InAt(0); |
| 1454 | Primitive::Type result_type = conversion->GetResultType(); |
| 1455 | Primitive::Type input_type = conversion->GetInputType(); |
| 1456 | switch (result_type) { |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 1457 | case Primitive::kPrimByte: |
| 1458 | switch (input_type) { |
| 1459 | case Primitive::kPrimShort: |
| 1460 | case Primitive::kPrimInt: |
| 1461 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 1462 | // Processing a Dex `int-to-byte' instruction. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 1463 | if (in.IsRegister()) { |
| 1464 | __ movsxb(out.As<CpuRegister>(), in.As<CpuRegister>()); |
| 1465 | } else if (in.IsStackSlot()) { |
| 1466 | __ movsxb(out.As<CpuRegister>(), |
| 1467 | Address(CpuRegister(RSP), in.GetStackIndex())); |
| 1468 | } else { |
| 1469 | DCHECK(in.GetConstant()->IsIntConstant()); |
| 1470 | __ movl(out.As<CpuRegister>(), |
| 1471 | Immediate(static_cast<int8_t>(in.GetConstant()->AsIntConstant()->GetValue()))); |
| 1472 | } |
| 1473 | break; |
| 1474 | |
| 1475 | default: |
| 1476 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1477 | << " to " << result_type; |
| 1478 | } |
| 1479 | break; |
| 1480 | |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 1481 | case Primitive::kPrimShort: |
| 1482 | switch (input_type) { |
| 1483 | case Primitive::kPrimByte: |
| 1484 | case Primitive::kPrimInt: |
| 1485 | case Primitive::kPrimChar: |
| 1486 | // Processing a Dex `int-to-short' instruction. |
| 1487 | if (in.IsRegister()) { |
| 1488 | __ movsxw(out.As<CpuRegister>(), in.As<CpuRegister>()); |
| 1489 | } else if (in.IsStackSlot()) { |
| 1490 | __ movsxw(out.As<CpuRegister>(), |
| 1491 | Address(CpuRegister(RSP), in.GetStackIndex())); |
| 1492 | } else { |
| 1493 | DCHECK(in.GetConstant()->IsIntConstant()); |
| 1494 | __ movl(out.As<CpuRegister>(), |
| 1495 | Immediate(static_cast<int16_t>(in.GetConstant()->AsIntConstant()->GetValue()))); |
| 1496 | } |
| 1497 | break; |
| 1498 | |
| 1499 | default: |
| 1500 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1501 | << " to " << result_type; |
| 1502 | } |
| 1503 | break; |
| 1504 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 1505 | case Primitive::kPrimInt: |
| 1506 | switch (input_type) { |
| 1507 | case Primitive::kPrimLong: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 1508 | // Processing a Dex `long-to-int' instruction. |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 1509 | if (in.IsRegister()) { |
| 1510 | __ movl(out.As<CpuRegister>(), in.As<CpuRegister>()); |
| 1511 | } else if (in.IsDoubleStackSlot()) { |
| 1512 | __ movl(out.As<CpuRegister>(), |
| 1513 | Address(CpuRegister(RSP), in.GetStackIndex())); |
| 1514 | } else { |
| 1515 | DCHECK(in.IsConstant()); |
| 1516 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 1517 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
| 1518 | __ movl(out.As<CpuRegister>(), Immediate(static_cast<int32_t>(value))); |
| 1519 | } |
| 1520 | break; |
| 1521 | |
| 1522 | case Primitive::kPrimFloat: |
| 1523 | case Primitive::kPrimDouble: |
| 1524 | LOG(FATAL) << "Type conversion from " << input_type |
| 1525 | << " to " << result_type << " not yet implemented"; |
| 1526 | break; |
| 1527 | |
| 1528 | default: |
| 1529 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1530 | << " to " << result_type; |
| 1531 | } |
| 1532 | break; |
| 1533 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1534 | case Primitive::kPrimLong: |
| 1535 | switch (input_type) { |
| 1536 | DCHECK(out.IsRegister()); |
| 1537 | case Primitive::kPrimByte: |
| 1538 | case Primitive::kPrimShort: |
| 1539 | case Primitive::kPrimInt: |
Roland Levillain | 666c732 | 2014-11-10 13:39:43 +0000 | [diff] [blame] | 1540 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 1541 | // Processing a Dex `int-to-long' instruction. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1542 | DCHECK(in.IsRegister()); |
| 1543 | __ movsxd(out.As<CpuRegister>(), in.As<CpuRegister>()); |
| 1544 | break; |
| 1545 | |
| 1546 | case Primitive::kPrimFloat: |
| 1547 | case Primitive::kPrimDouble: |
| 1548 | LOG(FATAL) << "Type conversion from " << input_type << " to " |
| 1549 | << result_type << " not yet implemented"; |
| 1550 | break; |
| 1551 | |
| 1552 | default: |
| 1553 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1554 | << " to " << result_type; |
| 1555 | } |
| 1556 | break; |
| 1557 | |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 1558 | case Primitive::kPrimChar: |
| 1559 | switch (input_type) { |
| 1560 | case Primitive::kPrimByte: |
| 1561 | case Primitive::kPrimShort: |
| 1562 | case Primitive::kPrimInt: |
| 1563 | case Primitive::kPrimChar: |
| 1564 | // Processing a Dex `int-to-char' instruction. |
| 1565 | if (in.IsRegister()) { |
| 1566 | __ movzxw(out.As<CpuRegister>(), in.As<CpuRegister>()); |
| 1567 | } else if (in.IsStackSlot()) { |
| 1568 | __ movzxw(out.As<CpuRegister>(), |
| 1569 | Address(CpuRegister(RSP), in.GetStackIndex())); |
| 1570 | } else { |
| 1571 | DCHECK(in.GetConstant()->IsIntConstant()); |
| 1572 | __ movl(out.As<CpuRegister>(), |
| 1573 | Immediate(static_cast<uint16_t>(in.GetConstant()->AsIntConstant()->GetValue()))); |
| 1574 | } |
| 1575 | break; |
| 1576 | |
| 1577 | default: |
| 1578 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1579 | << " to " << result_type; |
| 1580 | } |
| 1581 | break; |
| 1582 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1583 | case Primitive::kPrimFloat: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 1584 | switch (input_type) { |
| 1585 | // Processing a Dex `int-to-float' instruction. |
| 1586 | case Primitive::kPrimByte: |
| 1587 | case Primitive::kPrimShort: |
| 1588 | case Primitive::kPrimInt: |
| 1589 | case Primitive::kPrimChar: |
| 1590 | __ cvtsi2ss(out.As<XmmRegister>(), in.As<CpuRegister>()); |
| 1591 | break; |
| 1592 | |
| 1593 | case Primitive::kPrimLong: |
| 1594 | case Primitive::kPrimDouble: |
| 1595 | LOG(FATAL) << "Type conversion from " << input_type |
| 1596 | << " to " << result_type << " not yet implemented"; |
| 1597 | break; |
| 1598 | |
| 1599 | default: |
| 1600 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1601 | << " to " << result_type; |
| 1602 | }; |
| 1603 | break; |
| 1604 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1605 | case Primitive::kPrimDouble: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 1606 | switch (input_type) { |
| 1607 | // Processing a Dex `int-to-double' instruction. |
| 1608 | case Primitive::kPrimByte: |
| 1609 | case Primitive::kPrimShort: |
| 1610 | case Primitive::kPrimInt: |
| 1611 | case Primitive::kPrimChar: |
| 1612 | __ cvtsi2sd(out.As<XmmRegister>(), in.As<CpuRegister>()); |
| 1613 | break; |
| 1614 | |
| 1615 | case Primitive::kPrimLong: |
| 1616 | case Primitive::kPrimFloat: |
| 1617 | LOG(FATAL) << "Type conversion from " << input_type |
| 1618 | << " to " << result_type << " not yet implemented"; |
| 1619 | break; |
| 1620 | |
| 1621 | default: |
| 1622 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1623 | << " to " << result_type; |
| 1624 | }; |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1625 | break; |
| 1626 | |
| 1627 | default: |
| 1628 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1629 | << " to " << result_type; |
| 1630 | } |
| 1631 | } |
| 1632 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1633 | void LocationsBuilderX86_64::VisitAdd(HAdd* add) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1634 | LocationSummary* locations = |
| 1635 | new (GetGraph()->GetArena()) LocationSummary(add, LocationSummary::kNoCall); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1636 | switch (add->GetResultType()) { |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1637 | case Primitive::kPrimInt: { |
| 1638 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1639 | locations->SetInAt(1, Location::Any()); |
| 1640 | locations->SetOut(Location::SameAsFirstInput()); |
| 1641 | break; |
| 1642 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1643 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1644 | case Primitive::kPrimLong: { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 1645 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1646 | locations->SetInAt(1, Location::RequiresRegister()); |
| 1647 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1648 | break; |
| 1649 | } |
| 1650 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1651 | case Primitive::kPrimDouble: |
| 1652 | case Primitive::kPrimFloat: { |
| 1653 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1654 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1655 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1656 | break; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1657 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1658 | |
| 1659 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1660 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1661 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1662 | } |
| 1663 | |
| 1664 | void InstructionCodeGeneratorX86_64::VisitAdd(HAdd* add) { |
| 1665 | LocationSummary* locations = add->GetLocations(); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1666 | Location first = locations->InAt(0); |
| 1667 | Location second = locations->InAt(1); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1668 | DCHECK(first.Equals(locations->Out())); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 1669 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1670 | switch (add->GetResultType()) { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 1671 | case Primitive::kPrimInt: { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1672 | if (second.IsRegister()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1673 | __ addl(first.As<CpuRegister>(), second.As<CpuRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1674 | } else if (second.IsConstant()) { |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 1675 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue()); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1676 | __ addl(first.As<CpuRegister>(), imm); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1677 | } else { |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 1678 | __ addl(first.As<CpuRegister>(), Address(CpuRegister(RSP), second.GetStackIndex())); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1679 | } |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 1680 | break; |
| 1681 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1682 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1683 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1684 | __ addq(first.As<CpuRegister>(), second.As<CpuRegister>()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1685 | break; |
| 1686 | } |
| 1687 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1688 | case Primitive::kPrimFloat: { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1689 | __ addss(first.As<XmmRegister>(), second.As<XmmRegister>()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1690 | break; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1691 | } |
| 1692 | |
| 1693 | case Primitive::kPrimDouble: { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1694 | __ addsd(first.As<XmmRegister>(), second.As<XmmRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1695 | break; |
| 1696 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1697 | |
| 1698 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1699 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1700 | } |
| 1701 | } |
| 1702 | |
| 1703 | void LocationsBuilderX86_64::VisitSub(HSub* sub) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1704 | LocationSummary* locations = |
| 1705 | new (GetGraph()->GetArena()) LocationSummary(sub, LocationSummary::kNoCall); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1706 | switch (sub->GetResultType()) { |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1707 | case Primitive::kPrimInt: { |
| 1708 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1709 | locations->SetInAt(1, Location::Any()); |
| 1710 | locations->SetOut(Location::SameAsFirstInput()); |
| 1711 | break; |
| 1712 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1713 | case Primitive::kPrimLong: { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 1714 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1715 | locations->SetInAt(1, Location::RequiresRegister()); |
| 1716 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1717 | break; |
| 1718 | } |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 1719 | case Primitive::kPrimFloat: |
| 1720 | case Primitive::kPrimDouble: { |
| 1721 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1722 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 1723 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1724 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 1725 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1726 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 1727 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1728 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1729 | } |
| 1730 | |
| 1731 | void InstructionCodeGeneratorX86_64::VisitSub(HSub* sub) { |
| 1732 | LocationSummary* locations = sub->GetLocations(); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 1733 | Location first = locations->InAt(0); |
| 1734 | Location second = locations->InAt(1); |
| 1735 | DCHECK(first.Equals(locations->Out())); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1736 | switch (sub->GetResultType()) { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 1737 | case Primitive::kPrimInt: { |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 1738 | if (second.IsRegister()) { |
| 1739 | __ subl(first.As<CpuRegister>(), second.As<CpuRegister>()); |
| 1740 | } else if (second.IsConstant()) { |
| 1741 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue()); |
| 1742 | __ subl(first.As<CpuRegister>(), imm); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1743 | } else { |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 1744 | __ subl(first.As<CpuRegister>(), Address(CpuRegister(RSP), second.GetStackIndex())); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1745 | } |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 1746 | break; |
| 1747 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1748 | case Primitive::kPrimLong: { |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 1749 | __ subq(first.As<CpuRegister>(), second.As<CpuRegister>()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1750 | break; |
| 1751 | } |
| 1752 | |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 1753 | case Primitive::kPrimFloat: { |
| 1754 | __ subss(first.As<XmmRegister>(), second.As<XmmRegister>()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1755 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 1756 | } |
| 1757 | |
| 1758 | case Primitive::kPrimDouble: { |
| 1759 | __ subsd(first.As<XmmRegister>(), second.As<XmmRegister>()); |
| 1760 | break; |
| 1761 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1762 | |
| 1763 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 1764 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1765 | } |
| 1766 | } |
| 1767 | |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 1768 | void LocationsBuilderX86_64::VisitMul(HMul* mul) { |
| 1769 | LocationSummary* locations = |
| 1770 | new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall); |
| 1771 | switch (mul->GetResultType()) { |
| 1772 | case Primitive::kPrimInt: { |
| 1773 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1774 | locations->SetInAt(1, Location::Any()); |
| 1775 | locations->SetOut(Location::SameAsFirstInput()); |
| 1776 | break; |
| 1777 | } |
| 1778 | case Primitive::kPrimLong: { |
| 1779 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1780 | locations->SetInAt(1, Location::RequiresRegister()); |
| 1781 | locations->SetOut(Location::SameAsFirstInput()); |
| 1782 | break; |
| 1783 | } |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 1784 | case Primitive::kPrimFloat: |
| 1785 | case Primitive::kPrimDouble: { |
| 1786 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1787 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 1788 | locations->SetOut(Location::SameAsFirstInput()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 1789 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 1790 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 1791 | |
| 1792 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 1793 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 1794 | } |
| 1795 | } |
| 1796 | |
| 1797 | void InstructionCodeGeneratorX86_64::VisitMul(HMul* mul) { |
| 1798 | LocationSummary* locations = mul->GetLocations(); |
| 1799 | Location first = locations->InAt(0); |
| 1800 | Location second = locations->InAt(1); |
| 1801 | DCHECK(first.Equals(locations->Out())); |
| 1802 | switch (mul->GetResultType()) { |
| 1803 | case Primitive::kPrimInt: { |
| 1804 | if (second.IsRegister()) { |
| 1805 | __ imull(first.As<CpuRegister>(), second.As<CpuRegister>()); |
| 1806 | } else if (second.IsConstant()) { |
| 1807 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue()); |
| 1808 | __ imull(first.As<CpuRegister>(), imm); |
| 1809 | } else { |
| 1810 | DCHECK(second.IsStackSlot()); |
| 1811 | __ imull(first.As<CpuRegister>(), Address(CpuRegister(RSP), second.GetStackIndex())); |
| 1812 | } |
| 1813 | break; |
| 1814 | } |
| 1815 | case Primitive::kPrimLong: { |
| 1816 | __ imulq(first.As<CpuRegister>(), second.As<CpuRegister>()); |
| 1817 | break; |
| 1818 | } |
| 1819 | |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 1820 | case Primitive::kPrimFloat: { |
| 1821 | __ mulss(first.As<XmmRegister>(), second.As<XmmRegister>()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 1822 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 1823 | } |
| 1824 | |
| 1825 | case Primitive::kPrimDouble: { |
| 1826 | __ mulsd(first.As<XmmRegister>(), second.As<XmmRegister>()); |
| 1827 | break; |
| 1828 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 1829 | |
| 1830 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 1831 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 1832 | } |
| 1833 | } |
| 1834 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 1835 | void InstructionCodeGeneratorX86_64::GenerateDivRemIntegral(HBinaryOperation* instruction) { |
| 1836 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 1837 | Primitive::Type type = instruction->GetResultType(); |
| 1838 | DCHECK(type == Primitive::kPrimInt || Primitive::kPrimLong); |
| 1839 | |
| 1840 | bool is_div = instruction->IsDiv(); |
| 1841 | LocationSummary* locations = instruction->GetLocations(); |
| 1842 | |
| 1843 | CpuRegister out_reg = locations->Out().As<CpuRegister>(); |
| 1844 | CpuRegister second_reg = locations->InAt(1).As<CpuRegister>(); |
| 1845 | |
| 1846 | DCHECK_EQ(RAX, locations->InAt(0).As<CpuRegister>().AsRegister()); |
| 1847 | DCHECK_EQ(is_div ? RAX : RDX, out_reg.AsRegister()); |
| 1848 | |
| 1849 | SlowPathCodeX86_64* slow_path = |
| 1850 | new (GetGraph()->GetArena()) DivRemMinusOneSlowPathX86_64( |
| 1851 | out_reg.AsRegister(), type, is_div); |
| 1852 | codegen_->AddSlowPath(slow_path); |
| 1853 | |
| 1854 | // 0x80000000(00000000)/-1 triggers an arithmetic exception! |
| 1855 | // Dividing by -1 is actually negation and -0x800000000(00000000) = 0x80000000(00000000) |
| 1856 | // so it's safe to just use negl instead of more complex comparisons. |
| 1857 | |
| 1858 | __ cmpl(second_reg, Immediate(-1)); |
| 1859 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 1860 | |
| 1861 | if (type == Primitive::kPrimInt) { |
| 1862 | // edx:eax <- sign-extended of eax |
| 1863 | __ cdq(); |
| 1864 | // eax = quotient, edx = remainder |
| 1865 | __ idivl(second_reg); |
| 1866 | } else { |
| 1867 | // rdx:rax <- sign-extended of rax |
| 1868 | __ cqo(); |
| 1869 | // rax = quotient, rdx = remainder |
| 1870 | __ idivq(second_reg); |
| 1871 | } |
| 1872 | |
| 1873 | __ Bind(slow_path->GetExitLabel()); |
| 1874 | } |
| 1875 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1876 | void LocationsBuilderX86_64::VisitDiv(HDiv* div) { |
| 1877 | LocationSummary* locations = |
| 1878 | new (GetGraph()->GetArena()) LocationSummary(div, LocationSummary::kNoCall); |
| 1879 | switch (div->GetResultType()) { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 1880 | case Primitive::kPrimInt: |
| 1881 | case Primitive::kPrimLong: { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 1882 | locations->SetInAt(0, Location::RegisterLocation(RAX)); |
| 1883 | locations->SetInAt(1, Location::RequiresRegister()); |
| 1884 | locations->SetOut(Location::SameAsFirstInput()); |
| 1885 | // Intel uses edx:eax as the dividend. |
| 1886 | locations->AddTemp(Location::RegisterLocation(RDX)); |
| 1887 | break; |
| 1888 | } |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 1889 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1890 | case Primitive::kPrimFloat: |
| 1891 | case Primitive::kPrimDouble: { |
| 1892 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1893 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 1894 | locations->SetOut(Location::SameAsFirstInput()); |
| 1895 | break; |
| 1896 | } |
| 1897 | |
| 1898 | default: |
| 1899 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 1900 | } |
| 1901 | } |
| 1902 | |
| 1903 | void InstructionCodeGeneratorX86_64::VisitDiv(HDiv* div) { |
| 1904 | LocationSummary* locations = div->GetLocations(); |
| 1905 | Location first = locations->InAt(0); |
| 1906 | Location second = locations->InAt(1); |
| 1907 | DCHECK(first.Equals(locations->Out())); |
| 1908 | |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 1909 | Primitive::Type type = div->GetResultType(); |
| 1910 | switch (type) { |
| 1911 | case Primitive::kPrimInt: |
| 1912 | case Primitive::kPrimLong: { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 1913 | GenerateDivRemIntegral(div); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 1914 | break; |
| 1915 | } |
| 1916 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1917 | case Primitive::kPrimFloat: { |
| 1918 | __ divss(first.As<XmmRegister>(), second.As<XmmRegister>()); |
| 1919 | break; |
| 1920 | } |
| 1921 | |
| 1922 | case Primitive::kPrimDouble: { |
| 1923 | __ divsd(first.As<XmmRegister>(), second.As<XmmRegister>()); |
| 1924 | break; |
| 1925 | } |
| 1926 | |
| 1927 | default: |
| 1928 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 1929 | } |
| 1930 | } |
| 1931 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 1932 | void LocationsBuilderX86_64::VisitRem(HRem* rem) { |
| 1933 | LocationSummary* locations = |
| 1934 | new (GetGraph()->GetArena()) LocationSummary(rem, LocationSummary::kNoCall); |
| 1935 | switch (rem->GetResultType()) { |
| 1936 | case Primitive::kPrimInt: |
| 1937 | case Primitive::kPrimLong: { |
| 1938 | locations->SetInAt(0, Location::RegisterLocation(RAX)); |
| 1939 | locations->SetInAt(1, Location::RequiresRegister()); |
| 1940 | // Intel uses rdx:rax as the dividend and puts the remainder in rdx |
| 1941 | locations->SetOut(Location::RegisterLocation(RDX)); |
| 1942 | break; |
| 1943 | } |
| 1944 | |
| 1945 | case Primitive::kPrimFloat: |
| 1946 | case Primitive::kPrimDouble: { |
| 1947 | LOG(FATAL) << "Unimplemented rem type " << rem->GetResultType(); |
| 1948 | break; |
| 1949 | } |
| 1950 | |
| 1951 | default: |
| 1952 | LOG(FATAL) << "Unexpected rem type " << rem->GetResultType(); |
| 1953 | } |
| 1954 | } |
| 1955 | |
| 1956 | void InstructionCodeGeneratorX86_64::VisitRem(HRem* rem) { |
| 1957 | Primitive::Type type = rem->GetResultType(); |
| 1958 | switch (type) { |
| 1959 | case Primitive::kPrimInt: |
| 1960 | case Primitive::kPrimLong: { |
| 1961 | GenerateDivRemIntegral(rem); |
| 1962 | break; |
| 1963 | } |
| 1964 | |
| 1965 | case Primitive::kPrimFloat: |
| 1966 | case Primitive::kPrimDouble: { |
| 1967 | LOG(FATAL) << "Unimplemented rem type " << rem->GetResultType(); |
| 1968 | break; |
| 1969 | } |
| 1970 | |
| 1971 | default: |
| 1972 | LOG(FATAL) << "Unexpected rem type " << rem->GetResultType(); |
| 1973 | } |
| 1974 | } |
| 1975 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 1976 | void LocationsBuilderX86_64::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
| 1977 | LocationSummary* locations = |
| 1978 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 1979 | locations->SetInAt(0, Location::Any()); |
| 1980 | if (instruction->HasUses()) { |
| 1981 | locations->SetOut(Location::SameAsFirstInput()); |
| 1982 | } |
| 1983 | } |
| 1984 | |
| 1985 | void InstructionCodeGeneratorX86_64::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
| 1986 | SlowPathCodeX86_64* slow_path = |
| 1987 | new (GetGraph()->GetArena()) DivZeroCheckSlowPathX86_64(instruction); |
| 1988 | codegen_->AddSlowPath(slow_path); |
| 1989 | |
| 1990 | LocationSummary* locations = instruction->GetLocations(); |
| 1991 | Location value = locations->InAt(0); |
| 1992 | |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 1993 | switch (instruction->GetType()) { |
| 1994 | case Primitive::kPrimInt: { |
| 1995 | if (value.IsRegister()) { |
| 1996 | __ testl(value.As<CpuRegister>(), value.As<CpuRegister>()); |
| 1997 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 1998 | } else if (value.IsStackSlot()) { |
| 1999 | __ cmpl(Address(CpuRegister(RSP), value.GetStackIndex()), Immediate(0)); |
| 2000 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 2001 | } else { |
| 2002 | DCHECK(value.IsConstant()) << value; |
| 2003 | if (value.GetConstant()->AsIntConstant()->GetValue() == 0) { |
| 2004 | __ jmp(slow_path->GetEntryLabel()); |
| 2005 | } |
| 2006 | } |
| 2007 | break; |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 2008 | } |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 2009 | case Primitive::kPrimLong: { |
| 2010 | if (value.IsRegister()) { |
| 2011 | __ testq(value.As<CpuRegister>(), value.As<CpuRegister>()); |
| 2012 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 2013 | } else if (value.IsDoubleStackSlot()) { |
| 2014 | __ cmpq(Address(CpuRegister(RSP), value.GetStackIndex()), Immediate(0)); |
| 2015 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 2016 | } else { |
| 2017 | DCHECK(value.IsConstant()) << value; |
| 2018 | if (value.GetConstant()->AsLongConstant()->GetValue() == 0) { |
| 2019 | __ jmp(slow_path->GetEntryLabel()); |
| 2020 | } |
| 2021 | } |
| 2022 | break; |
| 2023 | } |
| 2024 | default: |
| 2025 | LOG(FATAL) << "Unexpected type for HDivZeroCheck " << instruction->GetType(); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 2026 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 2027 | } |
| 2028 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 2029 | void LocationsBuilderX86_64::HandleShift(HBinaryOperation* op) { |
| 2030 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 2031 | |
| 2032 | LocationSummary* locations = |
| 2033 | new (GetGraph()->GetArena()) LocationSummary(op, LocationSummary::kNoCall); |
| 2034 | |
| 2035 | switch (op->GetResultType()) { |
| 2036 | case Primitive::kPrimInt: |
| 2037 | case Primitive::kPrimLong: { |
| 2038 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2039 | // The shift count needs to be in CL. |
| 2040 | locations->SetInAt(1, Location::ByteRegisterOrConstant(RCX, op->InputAt(1))); |
| 2041 | locations->SetOut(Location::SameAsFirstInput()); |
| 2042 | break; |
| 2043 | } |
| 2044 | default: |
| 2045 | LOG(FATAL) << "Unexpected operation type " << op->GetResultType(); |
| 2046 | } |
| 2047 | } |
| 2048 | |
| 2049 | void InstructionCodeGeneratorX86_64::HandleShift(HBinaryOperation* op) { |
| 2050 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 2051 | |
| 2052 | LocationSummary* locations = op->GetLocations(); |
| 2053 | CpuRegister first_reg = locations->InAt(0).As<CpuRegister>(); |
| 2054 | Location second = locations->InAt(1); |
| 2055 | |
| 2056 | switch (op->GetResultType()) { |
| 2057 | case Primitive::kPrimInt: { |
| 2058 | if (second.IsRegister()) { |
| 2059 | CpuRegister second_reg = second.As<CpuRegister>(); |
| 2060 | if (op->IsShl()) { |
| 2061 | __ shll(first_reg, second_reg); |
| 2062 | } else if (op->IsShr()) { |
| 2063 | __ sarl(first_reg, second_reg); |
| 2064 | } else { |
| 2065 | __ shrl(first_reg, second_reg); |
| 2066 | } |
| 2067 | } else { |
| 2068 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue()); |
| 2069 | if (op->IsShl()) { |
| 2070 | __ shll(first_reg, imm); |
| 2071 | } else if (op->IsShr()) { |
| 2072 | __ sarl(first_reg, imm); |
| 2073 | } else { |
| 2074 | __ shrl(first_reg, imm); |
| 2075 | } |
| 2076 | } |
| 2077 | break; |
| 2078 | } |
| 2079 | case Primitive::kPrimLong: { |
| 2080 | if (second.IsRegister()) { |
| 2081 | CpuRegister second_reg = second.As<CpuRegister>(); |
| 2082 | if (op->IsShl()) { |
| 2083 | __ shlq(first_reg, second_reg); |
| 2084 | } else if (op->IsShr()) { |
| 2085 | __ sarq(first_reg, second_reg); |
| 2086 | } else { |
| 2087 | __ shrq(first_reg, second_reg); |
| 2088 | } |
| 2089 | } else { |
| 2090 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue()); |
| 2091 | if (op->IsShl()) { |
| 2092 | __ shlq(first_reg, imm); |
| 2093 | } else if (op->IsShr()) { |
| 2094 | __ sarq(first_reg, imm); |
| 2095 | } else { |
| 2096 | __ shrq(first_reg, imm); |
| 2097 | } |
| 2098 | } |
| 2099 | break; |
| 2100 | } |
| 2101 | default: |
| 2102 | LOG(FATAL) << "Unexpected operation type " << op->GetResultType(); |
| 2103 | } |
| 2104 | } |
| 2105 | |
| 2106 | void LocationsBuilderX86_64::VisitShl(HShl* shl) { |
| 2107 | HandleShift(shl); |
| 2108 | } |
| 2109 | |
| 2110 | void InstructionCodeGeneratorX86_64::VisitShl(HShl* shl) { |
| 2111 | HandleShift(shl); |
| 2112 | } |
| 2113 | |
| 2114 | void LocationsBuilderX86_64::VisitShr(HShr* shr) { |
| 2115 | HandleShift(shr); |
| 2116 | } |
| 2117 | |
| 2118 | void InstructionCodeGeneratorX86_64::VisitShr(HShr* shr) { |
| 2119 | HandleShift(shr); |
| 2120 | } |
| 2121 | |
| 2122 | void LocationsBuilderX86_64::VisitUShr(HUShr* ushr) { |
| 2123 | HandleShift(ushr); |
| 2124 | } |
| 2125 | |
| 2126 | void InstructionCodeGeneratorX86_64::VisitUShr(HUShr* ushr) { |
| 2127 | HandleShift(ushr); |
| 2128 | } |
| 2129 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2130 | void LocationsBuilderX86_64::VisitNewInstance(HNewInstance* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2131 | LocationSummary* locations = |
| 2132 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
Nicolas Geoffray | 9ae0daa | 2014-09-30 22:40:23 +0100 | [diff] [blame] | 2133 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2134 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 2135 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 2136 | locations->SetOut(Location::RegisterLocation(RAX)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2137 | } |
| 2138 | |
| 2139 | void InstructionCodeGeneratorX86_64::VisitNewInstance(HNewInstance* instruction) { |
| 2140 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 2141 | codegen_->LoadCurrentMethod(CpuRegister(calling_convention.GetRegisterAt(1))); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2142 | __ movq(CpuRegister(calling_convention.GetRegisterAt(0)), Immediate(instruction->GetTypeIndex())); |
| 2143 | |
| 2144 | __ gs()->call(Address::Absolute( |
| 2145 | QUICK_ENTRYPOINT_OFFSET(kX86_64WordSize, pAllocObjectWithAccessCheck), true)); |
| 2146 | |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 2147 | DCHECK(!codegen_->IsLeafMethod()); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2148 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2149 | } |
| 2150 | |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 2151 | void LocationsBuilderX86_64::VisitNewArray(HNewArray* instruction) { |
| 2152 | LocationSummary* locations = |
| 2153 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
| 2154 | InvokeRuntimeCallingConvention calling_convention; |
| 2155 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 2156 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 2157 | locations->SetOut(Location::RegisterLocation(RAX)); |
| 2158 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(2))); |
| 2159 | } |
| 2160 | |
| 2161 | void InstructionCodeGeneratorX86_64::VisitNewArray(HNewArray* instruction) { |
| 2162 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 2163 | codegen_->LoadCurrentMethod(CpuRegister(calling_convention.GetRegisterAt(1))); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 2164 | __ movq(CpuRegister(calling_convention.GetRegisterAt(0)), Immediate(instruction->GetTypeIndex())); |
| 2165 | |
| 2166 | __ gs()->call(Address::Absolute( |
| 2167 | QUICK_ENTRYPOINT_OFFSET(kX86_64WordSize, pAllocArrayWithAccessCheck), true)); |
| 2168 | |
| 2169 | DCHECK(!codegen_->IsLeafMethod()); |
| 2170 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
| 2171 | } |
| 2172 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2173 | void LocationsBuilderX86_64::VisitParameterValue(HParameterValue* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2174 | LocationSummary* locations = |
| 2175 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2176 | Location location = parameter_visitor_.GetNextLocation(instruction->GetType()); |
| 2177 | if (location.IsStackSlot()) { |
| 2178 | location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 2179 | } else if (location.IsDoubleStackSlot()) { |
| 2180 | location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 2181 | } |
| 2182 | locations->SetOut(location); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2183 | } |
| 2184 | |
| 2185 | void InstructionCodeGeneratorX86_64::VisitParameterValue(HParameterValue* instruction) { |
| 2186 | // Nothing to do, the parameter is already at its location. |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 2187 | UNUSED(instruction); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2188 | } |
| 2189 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 2190 | void LocationsBuilderX86_64::VisitNot(HNot* not_) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2191 | LocationSummary* locations = |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 2192 | new (GetGraph()->GetArena()) LocationSummary(not_, LocationSummary::kNoCall); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 2193 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2194 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2195 | } |
| 2196 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 2197 | void InstructionCodeGeneratorX86_64::VisitNot(HNot* not_) { |
| 2198 | LocationSummary* locations = not_->GetLocations(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2199 | DCHECK_EQ(locations->InAt(0).As<CpuRegister>().AsRegister(), |
| 2200 | locations->Out().As<CpuRegister>().AsRegister()); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 2201 | Location out = locations->Out(); |
| 2202 | switch (not_->InputAt(0)->GetType()) { |
| 2203 | case Primitive::kPrimBoolean: |
| 2204 | __ xorq(out.As<CpuRegister>(), Immediate(1)); |
| 2205 | break; |
| 2206 | |
| 2207 | case Primitive::kPrimInt: |
| 2208 | __ notl(out.As<CpuRegister>()); |
| 2209 | break; |
| 2210 | |
| 2211 | case Primitive::kPrimLong: |
Roland Levillain | 7056643 | 2014-10-24 16:20:17 +0100 | [diff] [blame] | 2212 | __ notq(out.As<CpuRegister>()); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 2213 | break; |
| 2214 | |
| 2215 | default: |
| 2216 | LOG(FATAL) << "Unimplemented type for not operation " << not_->GetResultType(); |
| 2217 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2218 | } |
| 2219 | |
| 2220 | void LocationsBuilderX86_64::VisitPhi(HPhi* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2221 | LocationSummary* locations = |
| 2222 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2223 | for (size_t i = 0, e = instruction->InputCount(); i < e; ++i) { |
| 2224 | locations->SetInAt(i, Location::Any()); |
| 2225 | } |
| 2226 | locations->SetOut(Location::Any()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2227 | } |
| 2228 | |
| 2229 | void InstructionCodeGeneratorX86_64::VisitPhi(HPhi* instruction) { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 2230 | UNUSED(instruction); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2231 | LOG(FATAL) << "Unimplemented"; |
| 2232 | } |
| 2233 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2234 | void LocationsBuilderX86_64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2235 | LocationSummary* locations = |
| 2236 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 9ae0daa | 2014-09-30 22:40:23 +0100 | [diff] [blame] | 2237 | Primitive::Type field_type = instruction->GetFieldType(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 2238 | bool needs_write_barrier = |
| 2239 | CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->GetValue()); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 2240 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2241 | locations->SetInAt(1, Location::RequiresRegister()); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 2242 | if (needs_write_barrier) { |
Nicolas Geoffray | 9ae0daa | 2014-09-30 22:40:23 +0100 | [diff] [blame] | 2243 | // Temporary registers for the write barrier. |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 2244 | locations->AddTemp(Location::RequiresRegister()); |
| 2245 | locations->AddTemp(Location::RequiresRegister()); |
| 2246 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2247 | } |
| 2248 | |
| 2249 | void InstructionCodeGeneratorX86_64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
| 2250 | LocationSummary* locations = instruction->GetLocations(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2251 | CpuRegister obj = locations->InAt(0).As<CpuRegister>(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2252 | size_t offset = instruction->GetFieldOffset().SizeValue(); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2253 | Primitive::Type field_type = instruction->GetFieldType(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2254 | |
| 2255 | switch (field_type) { |
| 2256 | case Primitive::kPrimBoolean: |
| 2257 | case Primitive::kPrimByte: { |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 2258 | CpuRegister value = locations->InAt(1).As<CpuRegister>(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2259 | __ movb(Address(obj, offset), value); |
| 2260 | break; |
| 2261 | } |
| 2262 | |
| 2263 | case Primitive::kPrimShort: |
| 2264 | case Primitive::kPrimChar: { |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 2265 | CpuRegister value = locations->InAt(1).As<CpuRegister>(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2266 | __ movw(Address(obj, offset), value); |
| 2267 | break; |
| 2268 | } |
| 2269 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2270 | case Primitive::kPrimInt: |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2271 | case Primitive::kPrimNot: { |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 2272 | CpuRegister value = locations->InAt(1).As<CpuRegister>(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2273 | __ movl(Address(obj, offset), value); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 2274 | if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->GetValue())) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2275 | CpuRegister temp = locations->GetTemp(0).As<CpuRegister>(); |
| 2276 | CpuRegister card = locations->GetTemp(1).As<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2277 | codegen_->MarkGCCard(temp, card, obj, value); |
| 2278 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2279 | break; |
| 2280 | } |
| 2281 | |
| 2282 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 2283 | CpuRegister value = locations->InAt(1).As<CpuRegister>(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2284 | __ movq(Address(obj, offset), value); |
| 2285 | break; |
| 2286 | } |
| 2287 | |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 2288 | case Primitive::kPrimFloat: { |
| 2289 | XmmRegister value = locations->InAt(1).As<XmmRegister>(); |
| 2290 | __ movss(Address(obj, offset), value); |
| 2291 | break; |
| 2292 | } |
| 2293 | |
| 2294 | case Primitive::kPrimDouble: { |
| 2295 | XmmRegister value = locations->InAt(1).As<XmmRegister>(); |
| 2296 | __ movsd(Address(obj, offset), value); |
| 2297 | break; |
| 2298 | } |
| 2299 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2300 | case Primitive::kPrimVoid: |
| 2301 | LOG(FATAL) << "Unreachable type " << field_type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 2302 | UNREACHABLE(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2303 | } |
| 2304 | } |
| 2305 | |
| 2306 | void LocationsBuilderX86_64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2307 | LocationSummary* locations = |
| 2308 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 2309 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2310 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2311 | } |
| 2312 | |
| 2313 | void InstructionCodeGeneratorX86_64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 2314 | LocationSummary* locations = instruction->GetLocations(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2315 | CpuRegister obj = locations->InAt(0).As<CpuRegister>(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2316 | size_t offset = instruction->GetFieldOffset().SizeValue(); |
| 2317 | |
| 2318 | switch (instruction->GetType()) { |
| 2319 | case Primitive::kPrimBoolean: { |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 2320 | CpuRegister out = locations->Out().As<CpuRegister>(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2321 | __ movzxb(out, Address(obj, offset)); |
| 2322 | break; |
| 2323 | } |
| 2324 | |
| 2325 | case Primitive::kPrimByte: { |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 2326 | CpuRegister out = locations->Out().As<CpuRegister>(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2327 | __ movsxb(out, Address(obj, offset)); |
| 2328 | break; |
| 2329 | } |
| 2330 | |
| 2331 | case Primitive::kPrimShort: { |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 2332 | CpuRegister out = locations->Out().As<CpuRegister>(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2333 | __ movsxw(out, Address(obj, offset)); |
| 2334 | break; |
| 2335 | } |
| 2336 | |
| 2337 | case Primitive::kPrimChar: { |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 2338 | CpuRegister out = locations->Out().As<CpuRegister>(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2339 | __ movzxw(out, Address(obj, offset)); |
| 2340 | break; |
| 2341 | } |
| 2342 | |
| 2343 | case Primitive::kPrimInt: |
| 2344 | case Primitive::kPrimNot: { |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 2345 | CpuRegister out = locations->Out().As<CpuRegister>(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2346 | __ movl(out, Address(obj, offset)); |
| 2347 | break; |
| 2348 | } |
| 2349 | |
| 2350 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 2351 | CpuRegister out = locations->Out().As<CpuRegister>(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2352 | __ movq(out, Address(obj, offset)); |
| 2353 | break; |
| 2354 | } |
| 2355 | |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 2356 | case Primitive::kPrimFloat: { |
| 2357 | XmmRegister out = locations->Out().As<XmmRegister>(); |
| 2358 | __ movss(out, Address(obj, offset)); |
| 2359 | break; |
| 2360 | } |
| 2361 | |
| 2362 | case Primitive::kPrimDouble: { |
| 2363 | XmmRegister out = locations->Out().As<XmmRegister>(); |
| 2364 | __ movsd(out, Address(obj, offset)); |
| 2365 | break; |
| 2366 | } |
| 2367 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2368 | case Primitive::kPrimVoid: |
| 2369 | LOG(FATAL) << "Unreachable type " << instruction->GetType(); |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 2370 | UNREACHABLE(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2371 | } |
| 2372 | } |
| 2373 | |
| 2374 | void LocationsBuilderX86_64::VisitNullCheck(HNullCheck* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2375 | LocationSummary* locations = |
| 2376 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2377 | locations->SetInAt(0, Location::Any()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 2378 | if (instruction->HasUses()) { |
| 2379 | locations->SetOut(Location::SameAsFirstInput()); |
| 2380 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2381 | } |
| 2382 | |
| 2383 | void InstructionCodeGeneratorX86_64::VisitNullCheck(HNullCheck* instruction) { |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 2384 | SlowPathCodeX86_64* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathX86_64(instruction); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2385 | codegen_->AddSlowPath(slow_path); |
| 2386 | |
| 2387 | LocationSummary* locations = instruction->GetLocations(); |
| 2388 | Location obj = locations->InAt(0); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2389 | |
| 2390 | if (obj.IsRegister()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2391 | __ cmpl(obj.As<CpuRegister>(), Immediate(0)); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 2392 | } else if (obj.IsStackSlot()) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2393 | __ cmpl(Address(CpuRegister(RSP), obj.GetStackIndex()), Immediate(0)); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 2394 | } else { |
| 2395 | DCHECK(obj.IsConstant()) << obj; |
| 2396 | DCHECK_EQ(obj.GetConstant()->AsIntConstant()->GetValue(), 0); |
| 2397 | __ jmp(slow_path->GetEntryLabel()); |
| 2398 | return; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2399 | } |
| 2400 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 2401 | } |
| 2402 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2403 | void LocationsBuilderX86_64::VisitArrayGet(HArrayGet* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2404 | LocationSummary* locations = |
| 2405 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 2406 | locations->SetInAt(0, Location::RequiresRegister()); |
Nicolas Geoffray | 9ae0daa | 2014-09-30 22:40:23 +0100 | [diff] [blame] | 2407 | locations->SetInAt( |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 2408 | 1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 2409 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2410 | } |
| 2411 | |
| 2412 | void InstructionCodeGeneratorX86_64::VisitArrayGet(HArrayGet* instruction) { |
| 2413 | LocationSummary* locations = instruction->GetLocations(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2414 | CpuRegister obj = locations->InAt(0).As<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2415 | Location index = locations->InAt(1); |
| 2416 | |
| 2417 | switch (instruction->GetType()) { |
| 2418 | case Primitive::kPrimBoolean: { |
| 2419 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2420 | CpuRegister out = locations->Out().As<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2421 | if (index.IsConstant()) { |
| 2422 | __ movzxb(out, Address(obj, |
| 2423 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset)); |
| 2424 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2425 | __ movzxb(out, Address(obj, index.As<CpuRegister>(), TIMES_1, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2426 | } |
| 2427 | break; |
| 2428 | } |
| 2429 | |
| 2430 | case Primitive::kPrimByte: { |
| 2431 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int8_t)).Uint32Value(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2432 | CpuRegister out = locations->Out().As<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2433 | if (index.IsConstant()) { |
| 2434 | __ movsxb(out, Address(obj, |
| 2435 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset)); |
| 2436 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2437 | __ movsxb(out, Address(obj, index.As<CpuRegister>(), TIMES_1, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2438 | } |
| 2439 | break; |
| 2440 | } |
| 2441 | |
| 2442 | case Primitive::kPrimShort: { |
| 2443 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int16_t)).Uint32Value(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2444 | CpuRegister out = locations->Out().As<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2445 | if (index.IsConstant()) { |
| 2446 | __ movsxw(out, Address(obj, |
| 2447 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset)); |
| 2448 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2449 | __ movsxw(out, Address(obj, index.As<CpuRegister>(), TIMES_2, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2450 | } |
| 2451 | break; |
| 2452 | } |
| 2453 | |
| 2454 | case Primitive::kPrimChar: { |
| 2455 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2456 | CpuRegister out = locations->Out().As<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2457 | if (index.IsConstant()) { |
| 2458 | __ movzxw(out, Address(obj, |
| 2459 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset)); |
| 2460 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2461 | __ movzxw(out, Address(obj, index.As<CpuRegister>(), TIMES_2, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2462 | } |
| 2463 | break; |
| 2464 | } |
| 2465 | |
| 2466 | case Primitive::kPrimInt: |
| 2467 | case Primitive::kPrimNot: { |
| 2468 | DCHECK_EQ(sizeof(mirror::HeapReference<mirror::Object>), sizeof(int32_t)); |
| 2469 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2470 | CpuRegister out = locations->Out().As<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2471 | if (index.IsConstant()) { |
| 2472 | __ movl(out, Address(obj, |
| 2473 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset)); |
| 2474 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2475 | __ movl(out, Address(obj, index.As<CpuRegister>(), TIMES_4, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2476 | } |
| 2477 | break; |
| 2478 | } |
| 2479 | |
| 2480 | case Primitive::kPrimLong: { |
| 2481 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2482 | CpuRegister out = locations->Out().As<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2483 | if (index.IsConstant()) { |
| 2484 | __ movq(out, Address(obj, |
| 2485 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset)); |
| 2486 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2487 | __ movq(out, Address(obj, index.As<CpuRegister>(), TIMES_8, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2488 | } |
| 2489 | break; |
| 2490 | } |
| 2491 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2492 | case Primitive::kPrimFloat: { |
| 2493 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value(); |
| 2494 | XmmRegister out = locations->Out().As<XmmRegister>(); |
| 2495 | if (index.IsConstant()) { |
| 2496 | __ movss(out, Address(obj, |
| 2497 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset)); |
| 2498 | } else { |
| 2499 | __ movss(out, Address(obj, index.As<CpuRegister>(), TIMES_4, data_offset)); |
| 2500 | } |
| 2501 | break; |
| 2502 | } |
| 2503 | |
| 2504 | case Primitive::kPrimDouble: { |
| 2505 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value(); |
| 2506 | XmmRegister out = locations->Out().As<XmmRegister>(); |
| 2507 | if (index.IsConstant()) { |
| 2508 | __ movsd(out, Address(obj, |
| 2509 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset)); |
| 2510 | } else { |
| 2511 | __ movsd(out, Address(obj, index.As<CpuRegister>(), TIMES_8, data_offset)); |
| 2512 | } |
| 2513 | break; |
| 2514 | } |
| 2515 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2516 | case Primitive::kPrimVoid: |
| 2517 | LOG(FATAL) << "Unreachable type " << instruction->GetType(); |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 2518 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2519 | } |
| 2520 | } |
| 2521 | |
| 2522 | void LocationsBuilderX86_64::VisitArraySet(HArraySet* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2523 | Primitive::Type value_type = instruction->GetComponentType(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 2524 | |
| 2525 | bool needs_write_barrier = |
| 2526 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
| 2527 | bool needs_runtime_call = instruction->NeedsTypeCheck(); |
| 2528 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2529 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary( |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 2530 | instruction, needs_runtime_call ? LocationSummary::kCall : LocationSummary::kNoCall); |
| 2531 | if (needs_runtime_call) { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2532 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2533 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 2534 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 2535 | locations->SetInAt(2, Location::RegisterLocation(calling_convention.GetRegisterAt(2))); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2536 | } else { |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 2537 | locations->SetInAt(0, Location::RequiresRegister()); |
Nicolas Geoffray | 9ae0daa | 2014-09-30 22:40:23 +0100 | [diff] [blame] | 2538 | locations->SetInAt( |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 2539 | 1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 2540 | locations->SetInAt(2, Location::RequiresRegister()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 2541 | if (value_type == Primitive::kPrimLong) { |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 2542 | locations->SetInAt(2, Location::RequiresRegister()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2543 | } else if (value_type == Primitive::kPrimFloat || value_type == Primitive::kPrimDouble) { |
| 2544 | locations->SetInAt(2, Location::RequiresFpuRegister()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 2545 | } else { |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 2546 | locations->SetInAt(2, Location::RegisterOrConstant(instruction->InputAt(2))); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 2547 | } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 2548 | |
| 2549 | if (needs_write_barrier) { |
| 2550 | // Temporary registers for the write barrier. |
| 2551 | locations->AddTemp(Location::RequiresRegister()); |
| 2552 | locations->AddTemp(Location::RequiresRegister()); |
| 2553 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2554 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2555 | } |
| 2556 | |
| 2557 | void InstructionCodeGeneratorX86_64::VisitArraySet(HArraySet* instruction) { |
| 2558 | LocationSummary* locations = instruction->GetLocations(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2559 | CpuRegister obj = locations->InAt(0).As<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2560 | Location index = locations->InAt(1); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 2561 | Location value = locations->InAt(2); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2562 | Primitive::Type value_type = instruction->GetComponentType(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 2563 | bool needs_runtime_call = locations->WillCall(); |
| 2564 | bool needs_write_barrier = |
| 2565 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2566 | |
| 2567 | switch (value_type) { |
| 2568 | case Primitive::kPrimBoolean: |
| 2569 | case Primitive::kPrimByte: { |
| 2570 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2571 | if (index.IsConstant()) { |
| 2572 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset; |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 2573 | if (value.IsRegister()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2574 | __ movb(Address(obj, offset), value.As<CpuRegister>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 2575 | } else { |
| 2576 | __ movb(Address(obj, offset), Immediate(value.GetConstant()->AsIntConstant()->GetValue())); |
| 2577 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2578 | } else { |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 2579 | if (value.IsRegister()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2580 | __ movb(Address(obj, index.As<CpuRegister>(), TIMES_1, data_offset), |
| 2581 | value.As<CpuRegister>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 2582 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2583 | __ movb(Address(obj, index.As<CpuRegister>(), TIMES_1, data_offset), |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 2584 | Immediate(value.GetConstant()->AsIntConstant()->GetValue())); |
| 2585 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2586 | } |
| 2587 | break; |
| 2588 | } |
| 2589 | |
| 2590 | case Primitive::kPrimShort: |
| 2591 | case Primitive::kPrimChar: { |
| 2592 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2593 | if (index.IsConstant()) { |
| 2594 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset; |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 2595 | if (value.IsRegister()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2596 | __ movw(Address(obj, offset), value.As<CpuRegister>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 2597 | } else { |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 2598 | DCHECK(value.IsConstant()) << value; |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 2599 | __ movw(Address(obj, offset), Immediate(value.GetConstant()->AsIntConstant()->GetValue())); |
| 2600 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2601 | } else { |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 2602 | DCHECK(index.IsRegister()) << index; |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 2603 | if (value.IsRegister()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2604 | __ movw(Address(obj, index.As<CpuRegister>(), TIMES_2, data_offset), |
| 2605 | value.As<CpuRegister>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 2606 | } else { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2607 | DCHECK(value.IsConstant()) << value; |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 2608 | __ movw(Address(obj, index.As<CpuRegister>(), TIMES_2, data_offset), |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 2609 | Immediate(value.GetConstant()->AsIntConstant()->GetValue())); |
| 2610 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2611 | } |
| 2612 | break; |
| 2613 | } |
| 2614 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 2615 | case Primitive::kPrimInt: |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2616 | case Primitive::kPrimNot: { |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 2617 | if (!needs_runtime_call) { |
| 2618 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
| 2619 | if (index.IsConstant()) { |
| 2620 | size_t offset = |
| 2621 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
| 2622 | if (value.IsRegister()) { |
| 2623 | __ movl(Address(obj, offset), value.As<CpuRegister>()); |
| 2624 | } else { |
| 2625 | DCHECK(value.IsConstant()) << value; |
| 2626 | __ movl(Address(obj, offset), |
| 2627 | Immediate(value.GetConstant()->AsIntConstant()->GetValue())); |
| 2628 | } |
| 2629 | } else { |
| 2630 | DCHECK(index.IsRegister()) << index; |
| 2631 | if (value.IsRegister()) { |
| 2632 | __ movl(Address(obj, index.As<CpuRegister>(), TIMES_4, data_offset), |
| 2633 | value.As<CpuRegister>()); |
| 2634 | } else { |
| 2635 | DCHECK(value.IsConstant()) << value; |
| 2636 | __ movl(Address(obj, index.As<CpuRegister>(), TIMES_4, data_offset), |
| 2637 | Immediate(value.GetConstant()->AsIntConstant()->GetValue())); |
| 2638 | } |
| 2639 | } |
| 2640 | |
| 2641 | if (needs_write_barrier) { |
| 2642 | DCHECK_EQ(value_type, Primitive::kPrimNot); |
| 2643 | CpuRegister temp = locations->GetTemp(0).As<CpuRegister>(); |
| 2644 | CpuRegister card = locations->GetTemp(1).As<CpuRegister>(); |
| 2645 | codegen_->MarkGCCard(temp, card, obj, value.As<CpuRegister>()); |
| 2646 | } |
| 2647 | } else { |
| 2648 | DCHECK_EQ(value_type, Primitive::kPrimNot); |
| 2649 | __ gs()->call(Address::Absolute(QUICK_ENTRYPOINT_OFFSET(kX86_64WordSize, pAputObject), true)); |
| 2650 | DCHECK(!codegen_->IsLeafMethod()); |
| 2651 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
| 2652 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2653 | break; |
| 2654 | } |
| 2655 | |
| 2656 | case Primitive::kPrimLong: { |
| 2657 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2658 | if (index.IsConstant()) { |
| 2659 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 2660 | DCHECK(value.IsRegister()); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2661 | __ movq(Address(obj, offset), value.As<CpuRegister>()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2662 | } else { |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 2663 | DCHECK(value.IsRegister()); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2664 | __ movq(Address(obj, index.As<CpuRegister>(), TIMES_8, data_offset), |
| 2665 | value.As<CpuRegister>()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2666 | } |
| 2667 | break; |
| 2668 | } |
| 2669 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2670 | case Primitive::kPrimFloat: { |
| 2671 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value(); |
| 2672 | if (index.IsConstant()) { |
| 2673 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
| 2674 | DCHECK(value.IsFpuRegister()); |
| 2675 | __ movss(Address(obj, offset), value.As<XmmRegister>()); |
| 2676 | } else { |
| 2677 | DCHECK(value.IsFpuRegister()); |
| 2678 | __ movss(Address(obj, index.As<CpuRegister>(), TIMES_4, data_offset), |
| 2679 | value.As<XmmRegister>()); |
| 2680 | } |
| 2681 | break; |
| 2682 | } |
| 2683 | |
| 2684 | case Primitive::kPrimDouble: { |
| 2685 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value(); |
| 2686 | if (index.IsConstant()) { |
| 2687 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
| 2688 | DCHECK(value.IsFpuRegister()); |
| 2689 | __ movsd(Address(obj, offset), value.As<XmmRegister>()); |
| 2690 | } else { |
| 2691 | DCHECK(value.IsFpuRegister()); |
| 2692 | __ movsd(Address(obj, index.As<CpuRegister>(), TIMES_8, data_offset), |
| 2693 | value.As<XmmRegister>()); |
| 2694 | } |
| 2695 | break; |
| 2696 | } |
| 2697 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2698 | case Primitive::kPrimVoid: |
| 2699 | LOG(FATAL) << "Unreachable type " << instruction->GetType(); |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 2700 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2701 | } |
| 2702 | } |
| 2703 | |
| 2704 | void LocationsBuilderX86_64::VisitArrayLength(HArrayLength* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2705 | LocationSummary* locations = |
| 2706 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 2707 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2708 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2709 | } |
| 2710 | |
| 2711 | void InstructionCodeGeneratorX86_64::VisitArrayLength(HArrayLength* instruction) { |
| 2712 | LocationSummary* locations = instruction->GetLocations(); |
| 2713 | uint32_t offset = mirror::Array::LengthOffset().Uint32Value(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2714 | CpuRegister obj = locations->InAt(0).As<CpuRegister>(); |
| 2715 | CpuRegister out = locations->Out().As<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2716 | __ movl(out, Address(obj, offset)); |
| 2717 | } |
| 2718 | |
| 2719 | void LocationsBuilderX86_64::VisitBoundsCheck(HBoundsCheck* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2720 | LocationSummary* locations = |
| 2721 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2722 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2723 | locations->SetInAt(1, Location::RequiresRegister()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 2724 | if (instruction->HasUses()) { |
| 2725 | locations->SetOut(Location::SameAsFirstInput()); |
| 2726 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2727 | } |
| 2728 | |
| 2729 | void InstructionCodeGeneratorX86_64::VisitBoundsCheck(HBoundsCheck* instruction) { |
| 2730 | LocationSummary* locations = instruction->GetLocations(); |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 2731 | SlowPathCodeX86_64* slow_path = new (GetGraph()->GetArena()) BoundsCheckSlowPathX86_64( |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2732 | instruction, locations->InAt(0), locations->InAt(1)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2733 | codegen_->AddSlowPath(slow_path); |
| 2734 | |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2735 | CpuRegister index = locations->InAt(0).As<CpuRegister>(); |
| 2736 | CpuRegister length = locations->InAt(1).As<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2737 | |
| 2738 | __ cmpl(index, length); |
| 2739 | __ j(kAboveEqual, slow_path->GetEntryLabel()); |
| 2740 | } |
| 2741 | |
| 2742 | void CodeGeneratorX86_64::MarkGCCard(CpuRegister temp, |
| 2743 | CpuRegister card, |
| 2744 | CpuRegister object, |
| 2745 | CpuRegister value) { |
| 2746 | Label is_null; |
| 2747 | __ testl(value, value); |
| 2748 | __ j(kEqual, &is_null); |
| 2749 | __ gs()->movq(card, Address::Absolute( |
| 2750 | Thread::CardTableOffset<kX86_64WordSize>().Int32Value(), true)); |
| 2751 | __ movq(temp, object); |
| 2752 | __ shrq(temp, Immediate(gc::accounting::CardTable::kCardShift)); |
| 2753 | __ movb(Address(temp, card, TIMES_1, 0), card); |
| 2754 | __ Bind(&is_null); |
| 2755 | } |
| 2756 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2757 | void LocationsBuilderX86_64::VisitTemporary(HTemporary* temp) { |
| 2758 | temp->SetLocations(nullptr); |
| 2759 | } |
| 2760 | |
| 2761 | void InstructionCodeGeneratorX86_64::VisitTemporary(HTemporary* temp) { |
| 2762 | // Nothing to do, this is driven by the code generator. |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 2763 | UNUSED(temp); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2764 | } |
| 2765 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2766 | void LocationsBuilderX86_64::VisitParallelMove(HParallelMove* instruction) { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 2767 | UNUSED(instruction); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2768 | LOG(FATAL) << "Unimplemented"; |
| 2769 | } |
| 2770 | |
| 2771 | void InstructionCodeGeneratorX86_64::VisitParallelMove(HParallelMove* instruction) { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 2772 | codegen_->GetMoveResolver()->EmitNativeCode(instruction); |
| 2773 | } |
| 2774 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 2775 | void LocationsBuilderX86_64::VisitSuspendCheck(HSuspendCheck* instruction) { |
| 2776 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath); |
| 2777 | } |
| 2778 | |
| 2779 | void InstructionCodeGeneratorX86_64::VisitSuspendCheck(HSuspendCheck* instruction) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 2780 | HBasicBlock* block = instruction->GetBlock(); |
| 2781 | if (block->GetLoopInformation() != nullptr) { |
| 2782 | DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction); |
| 2783 | // The back edge will generate the suspend check. |
| 2784 | return; |
| 2785 | } |
| 2786 | if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) { |
| 2787 | // The goto will generate the suspend check. |
| 2788 | return; |
| 2789 | } |
| 2790 | GenerateSuspendCheck(instruction, nullptr); |
| 2791 | } |
| 2792 | |
| 2793 | void InstructionCodeGeneratorX86_64::GenerateSuspendCheck(HSuspendCheck* instruction, |
| 2794 | HBasicBlock* successor) { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 2795 | SuspendCheckSlowPathX86_64* slow_path = |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 2796 | new (GetGraph()->GetArena()) SuspendCheckSlowPathX86_64(instruction, successor); |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 2797 | codegen_->AddSlowPath(slow_path); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 2798 | __ gs()->cmpw(Address::Absolute( |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 2799 | Thread::ThreadFlagsOffset<kX86_64WordSize>().Int32Value(), true), Immediate(0)); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 2800 | if (successor == nullptr) { |
| 2801 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 2802 | __ Bind(slow_path->GetReturnLabel()); |
| 2803 | } else { |
| 2804 | __ j(kEqual, codegen_->GetLabelOf(successor)); |
| 2805 | __ jmp(slow_path->GetEntryLabel()); |
| 2806 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 2807 | } |
| 2808 | |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 2809 | X86_64Assembler* ParallelMoveResolverX86_64::GetAssembler() const { |
| 2810 | return codegen_->GetAssembler(); |
| 2811 | } |
| 2812 | |
| 2813 | void ParallelMoveResolverX86_64::EmitMove(size_t index) { |
| 2814 | MoveOperands* move = moves_.Get(index); |
| 2815 | Location source = move->GetSource(); |
| 2816 | Location destination = move->GetDestination(); |
| 2817 | |
| 2818 | if (source.IsRegister()) { |
| 2819 | if (destination.IsRegister()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2820 | __ movq(destination.As<CpuRegister>(), source.As<CpuRegister>()); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 2821 | } else if (destination.IsStackSlot()) { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 2822 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2823 | source.As<CpuRegister>()); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 2824 | } else { |
| 2825 | DCHECK(destination.IsDoubleStackSlot()); |
| 2826 | __ movq(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2827 | source.As<CpuRegister>()); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 2828 | } |
| 2829 | } else if (source.IsStackSlot()) { |
| 2830 | if (destination.IsRegister()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2831 | __ movl(destination.As<CpuRegister>(), |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 2832 | Address(CpuRegister(RSP), source.GetStackIndex())); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2833 | } else if (destination.IsFpuRegister()) { |
| 2834 | __ movss(destination.As<XmmRegister>(), |
| 2835 | Address(CpuRegister(RSP), source.GetStackIndex())); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 2836 | } else { |
| 2837 | DCHECK(destination.IsStackSlot()); |
| 2838 | __ movl(CpuRegister(TMP), Address(CpuRegister(RSP), source.GetStackIndex())); |
| 2839 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), CpuRegister(TMP)); |
| 2840 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 2841 | } else if (source.IsDoubleStackSlot()) { |
| 2842 | if (destination.IsRegister()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2843 | __ movq(destination.As<CpuRegister>(), |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 2844 | Address(CpuRegister(RSP), source.GetStackIndex())); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2845 | } else if (destination.IsFpuRegister()) { |
| 2846 | __ movsd(destination.As<XmmRegister>(), Address(CpuRegister(RSP), source.GetStackIndex())); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 2847 | } else { |
Nicolas Geoffray | c8147a7 | 2014-10-21 16:06:20 +0100 | [diff] [blame] | 2848 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 2849 | __ movq(CpuRegister(TMP), Address(CpuRegister(RSP), source.GetStackIndex())); |
| 2850 | __ movq(Address(CpuRegister(RSP), destination.GetStackIndex()), CpuRegister(TMP)); |
| 2851 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2852 | } else if (source.IsConstant()) { |
| 2853 | HConstant* constant = source.GetConstant(); |
| 2854 | if (constant->IsIntConstant()) { |
| 2855 | Immediate imm(constant->AsIntConstant()->GetValue()); |
| 2856 | if (destination.IsRegister()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2857 | __ movl(destination.As<CpuRegister>(), imm); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2858 | } else { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2859 | DCHECK(destination.IsStackSlot()) << destination; |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2860 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), imm); |
| 2861 | } |
| 2862 | } else if (constant->IsLongConstant()) { |
| 2863 | int64_t value = constant->AsLongConstant()->GetValue(); |
| 2864 | if (destination.IsRegister()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2865 | __ movq(destination.As<CpuRegister>(), Immediate(value)); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2866 | } else { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2867 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2868 | __ movq(CpuRegister(TMP), Immediate(value)); |
| 2869 | __ movq(Address(CpuRegister(RSP), destination.GetStackIndex()), CpuRegister(TMP)); |
| 2870 | } |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2871 | } else if (constant->IsFloatConstant()) { |
| 2872 | Immediate imm(bit_cast<float, int32_t>(constant->AsFloatConstant()->GetValue())); |
| 2873 | if (destination.IsFpuRegister()) { |
| 2874 | __ movl(CpuRegister(TMP), imm); |
| 2875 | __ movd(destination.As<XmmRegister>(), CpuRegister(TMP)); |
| 2876 | } else { |
| 2877 | DCHECK(destination.IsStackSlot()) << destination; |
| 2878 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), imm); |
| 2879 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2880 | } else { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2881 | DCHECK(constant->IsDoubleConstant()) << constant->DebugName(); |
| 2882 | Immediate imm(bit_cast<double, int64_t>(constant->AsDoubleConstant()->GetValue())); |
| 2883 | if (destination.IsFpuRegister()) { |
| 2884 | __ movq(CpuRegister(TMP), imm); |
| 2885 | __ movd(destination.As<XmmRegister>(), CpuRegister(TMP)); |
| 2886 | } else { |
| 2887 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 2888 | __ movq(CpuRegister(TMP), imm); |
| 2889 | __ movq(Address(CpuRegister(RSP), destination.GetStackIndex()), CpuRegister(TMP)); |
| 2890 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2891 | } |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2892 | } else if (source.IsFpuRegister()) { |
| 2893 | if (destination.IsFpuRegister()) { |
| 2894 | __ movaps(destination.As<XmmRegister>(), source.As<XmmRegister>()); |
| 2895 | } else if (destination.IsStackSlot()) { |
| 2896 | __ movss(Address(CpuRegister(RSP), destination.GetStackIndex()), |
| 2897 | source.As<XmmRegister>()); |
| 2898 | } else { |
Nicolas Geoffray | 3159674 | 2014-11-24 15:28:45 +0000 | [diff] [blame] | 2899 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2900 | __ movsd(Address(CpuRegister(RSP), destination.GetStackIndex()), |
| 2901 | source.As<XmmRegister>()); |
| 2902 | } |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 2903 | } |
| 2904 | } |
| 2905 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 2906 | void ParallelMoveResolverX86_64::Exchange32(CpuRegister reg, int mem) { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 2907 | __ movl(CpuRegister(TMP), Address(CpuRegister(RSP), mem)); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 2908 | __ movl(Address(CpuRegister(RSP), mem), reg); |
| 2909 | __ movl(reg, CpuRegister(TMP)); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 2910 | } |
| 2911 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 2912 | void ParallelMoveResolverX86_64::Exchange32(int mem1, int mem2) { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 2913 | ScratchRegisterScope ensure_scratch( |
| 2914 | this, TMP, RAX, codegen_->GetNumberOfCoreRegisters()); |
| 2915 | |
| 2916 | int stack_offset = ensure_scratch.IsSpilled() ? kX86_64WordSize : 0; |
| 2917 | __ movl(CpuRegister(TMP), Address(CpuRegister(RSP), mem1 + stack_offset)); |
| 2918 | __ movl(CpuRegister(ensure_scratch.GetRegister()), |
| 2919 | Address(CpuRegister(RSP), mem2 + stack_offset)); |
| 2920 | __ movl(Address(CpuRegister(RSP), mem2 + stack_offset), CpuRegister(TMP)); |
| 2921 | __ movl(Address(CpuRegister(RSP), mem1 + stack_offset), |
| 2922 | CpuRegister(ensure_scratch.GetRegister())); |
| 2923 | } |
| 2924 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 2925 | void ParallelMoveResolverX86_64::Exchange64(CpuRegister reg, int mem) { |
| 2926 | __ movq(CpuRegister(TMP), Address(CpuRegister(RSP), mem)); |
| 2927 | __ movq(Address(CpuRegister(RSP), mem), reg); |
| 2928 | __ movq(reg, CpuRegister(TMP)); |
| 2929 | } |
| 2930 | |
| 2931 | void ParallelMoveResolverX86_64::Exchange64(int mem1, int mem2) { |
| 2932 | ScratchRegisterScope ensure_scratch( |
| 2933 | this, TMP, RAX, codegen_->GetNumberOfCoreRegisters()); |
| 2934 | |
| 2935 | int stack_offset = ensure_scratch.IsSpilled() ? kX86_64WordSize : 0; |
| 2936 | __ movq(CpuRegister(TMP), Address(CpuRegister(RSP), mem1 + stack_offset)); |
| 2937 | __ movq(CpuRegister(ensure_scratch.GetRegister()), |
| 2938 | Address(CpuRegister(RSP), mem2 + stack_offset)); |
| 2939 | __ movq(Address(CpuRegister(RSP), mem2 + stack_offset), CpuRegister(TMP)); |
| 2940 | __ movq(Address(CpuRegister(RSP), mem1 + stack_offset), |
| 2941 | CpuRegister(ensure_scratch.GetRegister())); |
| 2942 | } |
| 2943 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2944 | void ParallelMoveResolverX86_64::Exchange32(XmmRegister reg, int mem) { |
| 2945 | __ movl(CpuRegister(TMP), Address(CpuRegister(RSP), mem)); |
| 2946 | __ movss(Address(CpuRegister(RSP), mem), reg); |
| 2947 | __ movd(reg, CpuRegister(TMP)); |
| 2948 | } |
| 2949 | |
| 2950 | void ParallelMoveResolverX86_64::Exchange64(XmmRegister reg, int mem) { |
| 2951 | __ movq(CpuRegister(TMP), Address(CpuRegister(RSP), mem)); |
| 2952 | __ movsd(Address(CpuRegister(RSP), mem), reg); |
| 2953 | __ movd(reg, CpuRegister(TMP)); |
| 2954 | } |
| 2955 | |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 2956 | void ParallelMoveResolverX86_64::EmitSwap(size_t index) { |
| 2957 | MoveOperands* move = moves_.Get(index); |
| 2958 | Location source = move->GetSource(); |
| 2959 | Location destination = move->GetDestination(); |
| 2960 | |
| 2961 | if (source.IsRegister() && destination.IsRegister()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2962 | __ xchgq(destination.As<CpuRegister>(), source.As<CpuRegister>()); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 2963 | } else if (source.IsRegister() && destination.IsStackSlot()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2964 | Exchange32(source.As<CpuRegister>(), destination.GetStackIndex()); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 2965 | } else if (source.IsStackSlot() && destination.IsRegister()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2966 | Exchange32(destination.As<CpuRegister>(), source.GetStackIndex()); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 2967 | } else if (source.IsStackSlot() && destination.IsStackSlot()) { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 2968 | Exchange32(destination.GetStackIndex(), source.GetStackIndex()); |
| 2969 | } else if (source.IsRegister() && destination.IsDoubleStackSlot()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2970 | Exchange64(source.As<CpuRegister>(), destination.GetStackIndex()); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 2971 | } else if (source.IsDoubleStackSlot() && destination.IsRegister()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2972 | Exchange64(destination.As<CpuRegister>(), source.GetStackIndex()); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 2973 | } else if (source.IsDoubleStackSlot() && destination.IsDoubleStackSlot()) { |
| 2974 | Exchange64(destination.GetStackIndex(), source.GetStackIndex()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2975 | } else if (source.IsFpuRegister() && destination.IsFpuRegister()) { |
| 2976 | __ movd(CpuRegister(TMP), source.As<XmmRegister>()); |
| 2977 | __ movaps(source.As<XmmRegister>(), destination.As<XmmRegister>()); |
| 2978 | __ movd(destination.As<XmmRegister>(), CpuRegister(TMP)); |
| 2979 | } else if (source.IsFpuRegister() && destination.IsStackSlot()) { |
| 2980 | Exchange32(source.As<XmmRegister>(), destination.GetStackIndex()); |
| 2981 | } else if (source.IsStackSlot() && destination.IsFpuRegister()) { |
| 2982 | Exchange32(destination.As<XmmRegister>(), source.GetStackIndex()); |
| 2983 | } else if (source.IsFpuRegister() && destination.IsDoubleStackSlot()) { |
| 2984 | Exchange64(source.As<XmmRegister>(), destination.GetStackIndex()); |
| 2985 | } else if (source.IsDoubleStackSlot() && destination.IsFpuRegister()) { |
| 2986 | Exchange64(destination.As<XmmRegister>(), source.GetStackIndex()); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 2987 | } else { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2988 | LOG(FATAL) << "Unimplemented swap between " << source << " and " << destination; |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 2989 | } |
| 2990 | } |
| 2991 | |
| 2992 | |
| 2993 | void ParallelMoveResolverX86_64::SpillScratch(int reg) { |
| 2994 | __ pushq(CpuRegister(reg)); |
| 2995 | } |
| 2996 | |
| 2997 | |
| 2998 | void ParallelMoveResolverX86_64::RestoreScratch(int reg) { |
| 2999 | __ popq(CpuRegister(reg)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3000 | } |
| 3001 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 3002 | void InstructionCodeGeneratorX86_64::GenerateClassInitializationCheck( |
| 3003 | SlowPathCodeX86_64* slow_path, CpuRegister class_reg) { |
| 3004 | __ cmpl(Address(class_reg, mirror::Class::StatusOffset().Int32Value()), |
| 3005 | Immediate(mirror::Class::kStatusInitialized)); |
| 3006 | __ j(kLess, slow_path->GetEntryLabel()); |
| 3007 | __ Bind(slow_path->GetExitLabel()); |
| 3008 | // No need for memory fence, thanks to the X86_64 memory model. |
| 3009 | } |
| 3010 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 3011 | void LocationsBuilderX86_64::VisitLoadClass(HLoadClass* cls) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 3012 | LocationSummary::CallKind call_kind = cls->CanCallRuntime() |
| 3013 | ? LocationSummary::kCallOnSlowPath |
| 3014 | : LocationSummary::kNoCall; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 3015 | LocationSummary* locations = |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 3016 | new (GetGraph()->GetArena()) LocationSummary(cls, call_kind); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 3017 | locations->SetOut(Location::RequiresRegister()); |
| 3018 | } |
| 3019 | |
| 3020 | void InstructionCodeGeneratorX86_64::VisitLoadClass(HLoadClass* cls) { |
| 3021 | CpuRegister out = cls->GetLocations()->Out().As<CpuRegister>(); |
| 3022 | if (cls->IsReferrersClass()) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 3023 | DCHECK(!cls->CanCallRuntime()); |
| 3024 | DCHECK(!cls->MustGenerateClinitCheck()); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 3025 | codegen_->LoadCurrentMethod(out); |
| 3026 | __ movl(out, Address(out, mirror::ArtMethod::DeclaringClassOffset().Int32Value())); |
| 3027 | } else { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 3028 | DCHECK(cls->CanCallRuntime()); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 3029 | codegen_->LoadCurrentMethod(out); |
| 3030 | __ movl(out, Address(out, mirror::ArtMethod::DexCacheResolvedTypesOffset().Int32Value())); |
| 3031 | __ movl(out, Address(out, CodeGenerator::GetCacheOffset(cls->GetTypeIndex()))); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 3032 | SlowPathCodeX86_64* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathX86_64( |
| 3033 | cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck()); |
| 3034 | codegen_->AddSlowPath(slow_path); |
| 3035 | __ testl(out, out); |
| 3036 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3037 | if (cls->MustGenerateClinitCheck()) { |
| 3038 | GenerateClassInitializationCheck(slow_path, out); |
| 3039 | } else { |
| 3040 | __ Bind(slow_path->GetExitLabel()); |
| 3041 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 3042 | } |
| 3043 | } |
| 3044 | |
| 3045 | void LocationsBuilderX86_64::VisitClinitCheck(HClinitCheck* check) { |
| 3046 | LocationSummary* locations = |
| 3047 | new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath); |
| 3048 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3049 | if (check->HasUses()) { |
| 3050 | locations->SetOut(Location::SameAsFirstInput()); |
| 3051 | } |
| 3052 | } |
| 3053 | |
| 3054 | void InstructionCodeGeneratorX86_64::VisitClinitCheck(HClinitCheck* check) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 3055 | // We assume the class to not be null. |
| 3056 | SlowPathCodeX86_64* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathX86_64( |
| 3057 | check->GetLoadClass(), check, check->GetDexPc(), true); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 3058 | codegen_->AddSlowPath(slow_path); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 3059 | GenerateClassInitializationCheck(slow_path, check->GetLocations()->InAt(0).As<CpuRegister>()); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 3060 | } |
| 3061 | |
| 3062 | void LocationsBuilderX86_64::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 3063 | LocationSummary* locations = |
| 3064 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 3065 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3066 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3067 | } |
| 3068 | |
| 3069 | void InstructionCodeGeneratorX86_64::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 3070 | LocationSummary* locations = instruction->GetLocations(); |
| 3071 | CpuRegister cls = locations->InAt(0).As<CpuRegister>(); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 3072 | size_t offset = instruction->GetFieldOffset().SizeValue(); |
| 3073 | |
| 3074 | switch (instruction->GetType()) { |
| 3075 | case Primitive::kPrimBoolean: { |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 3076 | CpuRegister out = locations->Out().As<CpuRegister>(); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 3077 | __ movzxb(out, Address(cls, offset)); |
| 3078 | break; |
| 3079 | } |
| 3080 | |
| 3081 | case Primitive::kPrimByte: { |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 3082 | CpuRegister out = locations->Out().As<CpuRegister>(); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 3083 | __ movsxb(out, Address(cls, offset)); |
| 3084 | break; |
| 3085 | } |
| 3086 | |
| 3087 | case Primitive::kPrimShort: { |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 3088 | CpuRegister out = locations->Out().As<CpuRegister>(); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 3089 | __ movsxw(out, Address(cls, offset)); |
| 3090 | break; |
| 3091 | } |
| 3092 | |
| 3093 | case Primitive::kPrimChar: { |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 3094 | CpuRegister out = locations->Out().As<CpuRegister>(); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 3095 | __ movzxw(out, Address(cls, offset)); |
| 3096 | break; |
| 3097 | } |
| 3098 | |
| 3099 | case Primitive::kPrimInt: |
| 3100 | case Primitive::kPrimNot: { |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 3101 | CpuRegister out = locations->Out().As<CpuRegister>(); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 3102 | __ movl(out, Address(cls, offset)); |
| 3103 | break; |
| 3104 | } |
| 3105 | |
| 3106 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 3107 | CpuRegister out = locations->Out().As<CpuRegister>(); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 3108 | __ movq(out, Address(cls, offset)); |
| 3109 | break; |
| 3110 | } |
| 3111 | |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 3112 | case Primitive::kPrimFloat: { |
| 3113 | XmmRegister out = locations->Out().As<XmmRegister>(); |
| 3114 | __ movss(out, Address(cls, offset)); |
| 3115 | break; |
| 3116 | } |
| 3117 | |
| 3118 | case Primitive::kPrimDouble: { |
| 3119 | XmmRegister out = locations->Out().As<XmmRegister>(); |
| 3120 | __ movsd(out, Address(cls, offset)); |
| 3121 | break; |
| 3122 | } |
| 3123 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 3124 | case Primitive::kPrimVoid: |
| 3125 | LOG(FATAL) << "Unreachable type " << instruction->GetType(); |
| 3126 | UNREACHABLE(); |
| 3127 | } |
| 3128 | } |
| 3129 | |
| 3130 | void LocationsBuilderX86_64::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
| 3131 | LocationSummary* locations = |
| 3132 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 3133 | Primitive::Type field_type = instruction->GetFieldType(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 3134 | bool needs_write_barrier = |
| 3135 | CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->GetValue()); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 3136 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3137 | locations->SetInAt(1, Location::RequiresRegister()); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 3138 | if (needs_write_barrier) { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 3139 | // Temporary registers for the write barrier. |
| 3140 | locations->AddTemp(Location::RequiresRegister()); |
| 3141 | locations->AddTemp(Location::RequiresRegister()); |
| 3142 | } |
| 3143 | } |
| 3144 | |
| 3145 | void InstructionCodeGeneratorX86_64::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
| 3146 | LocationSummary* locations = instruction->GetLocations(); |
| 3147 | CpuRegister cls = locations->InAt(0).As<CpuRegister>(); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 3148 | size_t offset = instruction->GetFieldOffset().SizeValue(); |
| 3149 | Primitive::Type field_type = instruction->GetFieldType(); |
| 3150 | |
| 3151 | switch (field_type) { |
| 3152 | case Primitive::kPrimBoolean: |
| 3153 | case Primitive::kPrimByte: { |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 3154 | CpuRegister value = locations->InAt(1).As<CpuRegister>(); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 3155 | __ movb(Address(cls, offset), value); |
| 3156 | break; |
| 3157 | } |
| 3158 | |
| 3159 | case Primitive::kPrimShort: |
| 3160 | case Primitive::kPrimChar: { |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 3161 | CpuRegister value = locations->InAt(1).As<CpuRegister>(); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 3162 | __ movw(Address(cls, offset), value); |
| 3163 | break; |
| 3164 | } |
| 3165 | |
| 3166 | case Primitive::kPrimInt: |
| 3167 | case Primitive::kPrimNot: { |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 3168 | CpuRegister value = locations->InAt(1).As<CpuRegister>(); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 3169 | __ movl(Address(cls, offset), value); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 3170 | if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->GetValue())) { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 3171 | CpuRegister temp = locations->GetTemp(0).As<CpuRegister>(); |
| 3172 | CpuRegister card = locations->GetTemp(1).As<CpuRegister>(); |
| 3173 | codegen_->MarkGCCard(temp, card, cls, value); |
| 3174 | } |
| 3175 | break; |
| 3176 | } |
| 3177 | |
| 3178 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 3179 | CpuRegister value = locations->InAt(1).As<CpuRegister>(); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 3180 | __ movq(Address(cls, offset), value); |
| 3181 | break; |
| 3182 | } |
| 3183 | |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 3184 | case Primitive::kPrimFloat: { |
| 3185 | XmmRegister value = locations->InAt(1).As<XmmRegister>(); |
| 3186 | __ movss(Address(cls, offset), value); |
| 3187 | break; |
| 3188 | } |
| 3189 | |
| 3190 | case Primitive::kPrimDouble: { |
| 3191 | XmmRegister value = locations->InAt(1).As<XmmRegister>(); |
| 3192 | __ movsd(Address(cls, offset), value); |
| 3193 | break; |
| 3194 | } |
| 3195 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 3196 | case Primitive::kPrimVoid: |
| 3197 | LOG(FATAL) << "Unreachable type " << field_type; |
| 3198 | UNREACHABLE(); |
| 3199 | } |
| 3200 | } |
| 3201 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 3202 | void LocationsBuilderX86_64::VisitLoadString(HLoadString* load) { |
| 3203 | LocationSummary* locations = |
| 3204 | new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kCallOnSlowPath); |
| 3205 | locations->SetOut(Location::RequiresRegister()); |
| 3206 | } |
| 3207 | |
| 3208 | void InstructionCodeGeneratorX86_64::VisitLoadString(HLoadString* load) { |
| 3209 | SlowPathCodeX86_64* slow_path = new (GetGraph()->GetArena()) LoadStringSlowPathX86_64(load); |
| 3210 | codegen_->AddSlowPath(slow_path); |
| 3211 | |
| 3212 | CpuRegister out = load->GetLocations()->Out().As<CpuRegister>(); |
| 3213 | codegen_->LoadCurrentMethod(CpuRegister(out)); |
Mathieu Chartier | eace458 | 2014-11-24 18:29:54 -0800 | [diff] [blame] | 3214 | __ movl(out, Address(out, mirror::ArtMethod::DeclaringClassOffset().Int32Value())); |
| 3215 | __ movl(out, Address(out, mirror::Class::DexCacheStringsOffset().Int32Value())); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 3216 | __ movl(out, Address(out, CodeGenerator::GetCacheOffset(load->GetStringIndex()))); |
| 3217 | __ testl(out, out); |
| 3218 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3219 | __ Bind(slow_path->GetExitLabel()); |
| 3220 | } |
| 3221 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 3222 | void LocationsBuilderX86_64::VisitLoadException(HLoadException* load) { |
| 3223 | LocationSummary* locations = |
| 3224 | new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall); |
| 3225 | locations->SetOut(Location::RequiresRegister()); |
| 3226 | } |
| 3227 | |
| 3228 | void InstructionCodeGeneratorX86_64::VisitLoadException(HLoadException* load) { |
| 3229 | Address address = Address::Absolute( |
| 3230 | Thread::ExceptionOffset<kX86_64WordSize>().Int32Value(), true); |
| 3231 | __ gs()->movl(load->GetLocations()->Out().As<CpuRegister>(), address); |
| 3232 | __ gs()->movl(address, Immediate(0)); |
| 3233 | } |
| 3234 | |
| 3235 | void LocationsBuilderX86_64::VisitThrow(HThrow* instruction) { |
| 3236 | LocationSummary* locations = |
| 3237 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
| 3238 | InvokeRuntimeCallingConvention calling_convention; |
| 3239 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 3240 | } |
| 3241 | |
| 3242 | void InstructionCodeGeneratorX86_64::VisitThrow(HThrow* instruction) { |
| 3243 | __ gs()->call( |
| 3244 | Address::Absolute(QUICK_ENTRYPOINT_OFFSET(kX86_64WordSize, pDeliverException), true)); |
| 3245 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
| 3246 | } |
| 3247 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 3248 | void LocationsBuilderX86_64::VisitInstanceOf(HInstanceOf* instruction) { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 3249 | LocationSummary::CallKind call_kind = instruction->IsClassFinal() |
| 3250 | ? LocationSummary::kNoCall |
| 3251 | : LocationSummary::kCallOnSlowPath; |
| 3252 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
| 3253 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3254 | locations->SetInAt(1, Location::Any()); |
| 3255 | locations->SetOut(Location::RequiresRegister()); |
| 3256 | } |
| 3257 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 3258 | void InstructionCodeGeneratorX86_64::VisitInstanceOf(HInstanceOf* instruction) { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 3259 | LocationSummary* locations = instruction->GetLocations(); |
| 3260 | CpuRegister obj = locations->InAt(0).As<CpuRegister>(); |
| 3261 | Location cls = locations->InAt(1); |
| 3262 | CpuRegister out = locations->Out().As<CpuRegister>(); |
| 3263 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 3264 | Label done, zero; |
| 3265 | SlowPathCodeX86_64* slow_path = nullptr; |
| 3266 | |
| 3267 | // Return 0 if `obj` is null. |
| 3268 | // TODO: avoid this check if we know obj is not null. |
| 3269 | __ testl(obj, obj); |
| 3270 | __ j(kEqual, &zero); |
| 3271 | // Compare the class of `obj` with `cls`. |
| 3272 | __ movl(out, Address(obj, class_offset)); |
| 3273 | if (cls.IsRegister()) { |
| 3274 | __ cmpl(out, cls.As<CpuRegister>()); |
| 3275 | } else { |
| 3276 | DCHECK(cls.IsStackSlot()) << cls; |
| 3277 | __ cmpl(out, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 3278 | } |
| 3279 | if (instruction->IsClassFinal()) { |
| 3280 | // Classes must be equal for the instanceof to succeed. |
| 3281 | __ j(kNotEqual, &zero); |
| 3282 | __ movl(out, Immediate(1)); |
| 3283 | __ jmp(&done); |
| 3284 | } else { |
| 3285 | // If the classes are not equal, we go into a slow path. |
| 3286 | DCHECK(locations->OnlyCallsOnSlowPath()); |
| 3287 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathX86_64( |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 3288 | instruction, locations->InAt(1), locations->Out(), instruction->GetDexPc()); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 3289 | codegen_->AddSlowPath(slow_path); |
| 3290 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 3291 | __ movl(out, Immediate(1)); |
| 3292 | __ jmp(&done); |
| 3293 | } |
| 3294 | __ Bind(&zero); |
| 3295 | __ movl(out, Immediate(0)); |
| 3296 | if (slow_path != nullptr) { |
| 3297 | __ Bind(slow_path->GetExitLabel()); |
| 3298 | } |
| 3299 | __ Bind(&done); |
| 3300 | } |
| 3301 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 3302 | void LocationsBuilderX86_64::VisitCheckCast(HCheckCast* instruction) { |
| 3303 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary( |
| 3304 | instruction, LocationSummary::kCallOnSlowPath); |
| 3305 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3306 | locations->SetInAt(1, Location::Any()); |
| 3307 | locations->AddTemp(Location::RequiresRegister()); |
| 3308 | } |
| 3309 | |
| 3310 | void InstructionCodeGeneratorX86_64::VisitCheckCast(HCheckCast* instruction) { |
| 3311 | LocationSummary* locations = instruction->GetLocations(); |
| 3312 | CpuRegister obj = locations->InAt(0).As<CpuRegister>(); |
| 3313 | Location cls = locations->InAt(1); |
| 3314 | CpuRegister temp = locations->GetTemp(0).As<CpuRegister>(); |
| 3315 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 3316 | SlowPathCodeX86_64* slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathX86_64( |
| 3317 | instruction, locations->InAt(1), locations->GetTemp(0), instruction->GetDexPc()); |
| 3318 | codegen_->AddSlowPath(slow_path); |
| 3319 | |
| 3320 | // TODO: avoid this check if we know obj is not null. |
| 3321 | __ testl(obj, obj); |
| 3322 | __ j(kEqual, slow_path->GetExitLabel()); |
| 3323 | // Compare the class of `obj` with `cls`. |
| 3324 | __ movl(temp, Address(obj, class_offset)); |
| 3325 | if (cls.IsRegister()) { |
| 3326 | __ cmpl(temp, cls.As<CpuRegister>()); |
| 3327 | } else { |
| 3328 | DCHECK(cls.IsStackSlot()) << cls; |
| 3329 | __ cmpl(temp, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 3330 | } |
| 3331 | // Classes must be equal for the checkcast to succeed. |
| 3332 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 3333 | __ Bind(slow_path->GetExitLabel()); |
| 3334 | } |
| 3335 | |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 3336 | void LocationsBuilderX86_64::VisitMonitorOperation(HMonitorOperation* instruction) { |
| 3337 | LocationSummary* locations = |
| 3338 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
| 3339 | InvokeRuntimeCallingConvention calling_convention; |
| 3340 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 3341 | } |
| 3342 | |
| 3343 | void InstructionCodeGeneratorX86_64::VisitMonitorOperation(HMonitorOperation* instruction) { |
| 3344 | __ gs()->call(Address::Absolute(instruction->IsEnter() |
| 3345 | ? QUICK_ENTRYPOINT_OFFSET(kX86_64WordSize, pLockObject) |
| 3346 | : QUICK_ENTRYPOINT_OFFSET(kX86_64WordSize, pUnlockObject), |
| 3347 | true)); |
| 3348 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
| 3349 | } |
| 3350 | |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 3351 | void LocationsBuilderX86_64::VisitAnd(HAnd* instruction) { HandleBitwiseOperation(instruction); } |
| 3352 | void LocationsBuilderX86_64::VisitOr(HOr* instruction) { HandleBitwiseOperation(instruction); } |
| 3353 | void LocationsBuilderX86_64::VisitXor(HXor* instruction) { HandleBitwiseOperation(instruction); } |
| 3354 | |
| 3355 | void LocationsBuilderX86_64::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 3356 | LocationSummary* locations = |
| 3357 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 3358 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt |
| 3359 | || instruction->GetResultType() == Primitive::kPrimLong); |
| 3360 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3361 | if (instruction->GetType() == Primitive::kPrimInt) { |
| 3362 | locations->SetInAt(1, Location::Any()); |
| 3363 | } else { |
| 3364 | // Request a register to avoid loading a 64bits constant. |
| 3365 | locations->SetInAt(1, Location::RequiresRegister()); |
| 3366 | } |
| 3367 | locations->SetOut(Location::SameAsFirstInput()); |
| 3368 | } |
| 3369 | |
| 3370 | void InstructionCodeGeneratorX86_64::VisitAnd(HAnd* instruction) { |
| 3371 | HandleBitwiseOperation(instruction); |
| 3372 | } |
| 3373 | |
| 3374 | void InstructionCodeGeneratorX86_64::VisitOr(HOr* instruction) { |
| 3375 | HandleBitwiseOperation(instruction); |
| 3376 | } |
| 3377 | |
| 3378 | void InstructionCodeGeneratorX86_64::VisitXor(HXor* instruction) { |
| 3379 | HandleBitwiseOperation(instruction); |
| 3380 | } |
| 3381 | |
| 3382 | void InstructionCodeGeneratorX86_64::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 3383 | LocationSummary* locations = instruction->GetLocations(); |
| 3384 | Location first = locations->InAt(0); |
| 3385 | Location second = locations->InAt(1); |
| 3386 | DCHECK(first.Equals(locations->Out())); |
| 3387 | |
| 3388 | if (instruction->GetResultType() == Primitive::kPrimInt) { |
| 3389 | if (second.IsRegister()) { |
| 3390 | if (instruction->IsAnd()) { |
| 3391 | __ andl(first.As<CpuRegister>(), second.As<CpuRegister>()); |
| 3392 | } else if (instruction->IsOr()) { |
| 3393 | __ orl(first.As<CpuRegister>(), second.As<CpuRegister>()); |
| 3394 | } else { |
| 3395 | DCHECK(instruction->IsXor()); |
| 3396 | __ xorl(first.As<CpuRegister>(), second.As<CpuRegister>()); |
| 3397 | } |
| 3398 | } else if (second.IsConstant()) { |
| 3399 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue()); |
| 3400 | if (instruction->IsAnd()) { |
| 3401 | __ andl(first.As<CpuRegister>(), imm); |
| 3402 | } else if (instruction->IsOr()) { |
| 3403 | __ orl(first.As<CpuRegister>(), imm); |
| 3404 | } else { |
| 3405 | DCHECK(instruction->IsXor()); |
| 3406 | __ xorl(first.As<CpuRegister>(), imm); |
| 3407 | } |
| 3408 | } else { |
| 3409 | Address address(CpuRegister(RSP), second.GetStackIndex()); |
| 3410 | if (instruction->IsAnd()) { |
| 3411 | __ andl(first.As<CpuRegister>(), address); |
| 3412 | } else if (instruction->IsOr()) { |
| 3413 | __ orl(first.As<CpuRegister>(), address); |
| 3414 | } else { |
| 3415 | DCHECK(instruction->IsXor()); |
| 3416 | __ xorl(first.As<CpuRegister>(), address); |
| 3417 | } |
| 3418 | } |
| 3419 | } else { |
| 3420 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong); |
| 3421 | if (instruction->IsAnd()) { |
| 3422 | __ andq(first.As<CpuRegister>(), second.As<CpuRegister>()); |
| 3423 | } else if (instruction->IsOr()) { |
| 3424 | __ orq(first.As<CpuRegister>(), second.As<CpuRegister>()); |
| 3425 | } else { |
| 3426 | DCHECK(instruction->IsXor()); |
| 3427 | __ xorq(first.As<CpuRegister>(), second.As<CpuRegister>()); |
| 3428 | } |
| 3429 | } |
| 3430 | } |
| 3431 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3432 | } // namespace x86_64 |
| 3433 | } // namespace art |