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