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 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1155 | void LocationsBuilderX86::VisitNeg(HNeg* neg) { |
| 1156 | LocationSummary* locations = |
| 1157 | new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall); |
| 1158 | switch (neg->GetResultType()) { |
| 1159 | case Primitive::kPrimInt: |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 1160 | case Primitive::kPrimLong: |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1161 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1162 | locations->SetOut(Location::SameAsFirstInput()); |
| 1163 | break; |
| 1164 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1165 | case Primitive::kPrimFloat: |
| 1166 | case Primitive::kPrimDouble: |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 1167 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1168 | // Output overlaps as we need a fresh (zero-initialized) |
| 1169 | // register to perform subtraction from zero. |
| 1170 | locations->SetOut(Location::RequiresFpuRegister()); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1171 | break; |
| 1172 | |
| 1173 | default: |
| 1174 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 1175 | } |
| 1176 | } |
| 1177 | |
| 1178 | void InstructionCodeGeneratorX86::VisitNeg(HNeg* neg) { |
| 1179 | LocationSummary* locations = neg->GetLocations(); |
| 1180 | Location out = locations->Out(); |
| 1181 | Location in = locations->InAt(0); |
| 1182 | switch (neg->GetResultType()) { |
| 1183 | case Primitive::kPrimInt: |
| 1184 | DCHECK(in.IsRegister()); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 1185 | DCHECK(in.Equals(out)); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1186 | __ negl(out.As<Register>()); |
| 1187 | break; |
| 1188 | |
| 1189 | case Primitive::kPrimLong: |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 1190 | DCHECK(in.IsRegisterPair()); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 1191 | DCHECK(in.Equals(out)); |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 1192 | __ negl(out.AsRegisterPairLow<Register>()); |
| 1193 | // Negation is similar to subtraction from zero. The least |
| 1194 | // significant byte triggers a borrow when it is different from |
| 1195 | // zero; to take it into account, add 1 to the most significant |
| 1196 | // byte if the carry flag (CF) is set to 1 after the first NEGL |
| 1197 | // operation. |
| 1198 | __ adcl(out.AsRegisterPairHigh<Register>(), Immediate(0)); |
| 1199 | __ negl(out.AsRegisterPairHigh<Register>()); |
| 1200 | break; |
| 1201 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1202 | case Primitive::kPrimFloat: |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 1203 | DCHECK(!in.Equals(out)); |
| 1204 | // out = 0 |
| 1205 | __ xorps(out.As<XmmRegister>(), out.As<XmmRegister>()); |
| 1206 | // out = out - in |
| 1207 | __ subss(out.As<XmmRegister>(), in.As<XmmRegister>()); |
| 1208 | break; |
| 1209 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1210 | case Primitive::kPrimDouble: |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 1211 | DCHECK(!in.Equals(out)); |
| 1212 | // out = 0 |
| 1213 | __ xorpd(out.As<XmmRegister>(), out.As<XmmRegister>()); |
| 1214 | // out = out - in |
| 1215 | __ subsd(out.As<XmmRegister>(), in.As<XmmRegister>()); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1216 | break; |
| 1217 | |
| 1218 | default: |
| 1219 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 1220 | } |
| 1221 | } |
| 1222 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1223 | void LocationsBuilderX86::VisitTypeConversion(HTypeConversion* conversion) { |
| 1224 | LocationSummary* locations = |
| 1225 | new (GetGraph()->GetArena()) LocationSummary(conversion, LocationSummary::kNoCall); |
| 1226 | Primitive::Type result_type = conversion->GetResultType(); |
| 1227 | Primitive::Type input_type = conversion->GetInputType(); |
| 1228 | switch (result_type) { |
| 1229 | case Primitive::kPrimLong: |
| 1230 | switch (input_type) { |
| 1231 | case Primitive::kPrimByte: |
| 1232 | case Primitive::kPrimShort: |
| 1233 | case Primitive::kPrimInt: |
| 1234 | // int-to-long conversion. |
| 1235 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
| 1236 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); |
| 1237 | break; |
| 1238 | |
| 1239 | case Primitive::kPrimFloat: |
| 1240 | case Primitive::kPrimDouble: |
| 1241 | LOG(FATAL) << "Type conversion from " << input_type << " to " |
| 1242 | << result_type << " not yet implemented"; |
| 1243 | break; |
| 1244 | |
| 1245 | default: |
| 1246 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1247 | << " to " << result_type; |
| 1248 | } |
| 1249 | break; |
| 1250 | |
| 1251 | case Primitive::kPrimInt: |
| 1252 | case Primitive::kPrimFloat: |
| 1253 | case Primitive::kPrimDouble: |
| 1254 | LOG(FATAL) << "Type conversion from " << input_type |
| 1255 | << " to " << result_type << " not yet implemented"; |
| 1256 | break; |
| 1257 | |
| 1258 | default: |
| 1259 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1260 | << " to " << result_type; |
| 1261 | } |
| 1262 | } |
| 1263 | |
| 1264 | void InstructionCodeGeneratorX86::VisitTypeConversion(HTypeConversion* conversion) { |
| 1265 | LocationSummary* locations = conversion->GetLocations(); |
| 1266 | Location out = locations->Out(); |
| 1267 | Location in = locations->InAt(0); |
| 1268 | Primitive::Type result_type = conversion->GetResultType(); |
| 1269 | Primitive::Type input_type = conversion->GetInputType(); |
| 1270 | switch (result_type) { |
| 1271 | case Primitive::kPrimLong: |
| 1272 | switch (input_type) { |
| 1273 | case Primitive::kPrimByte: |
| 1274 | case Primitive::kPrimShort: |
| 1275 | case Primitive::kPrimInt: |
| 1276 | // int-to-long conversion. |
| 1277 | DCHECK_EQ(out.AsRegisterPairLow<Register>(), EAX); |
| 1278 | DCHECK_EQ(out.AsRegisterPairHigh<Register>(), EDX); |
| 1279 | DCHECK_EQ(in.As<Register>(), EAX); |
| 1280 | __ cdq(); |
| 1281 | break; |
| 1282 | |
| 1283 | case Primitive::kPrimFloat: |
| 1284 | case Primitive::kPrimDouble: |
| 1285 | LOG(FATAL) << "Type conversion from " << input_type << " to " |
| 1286 | << result_type << " not yet implemented"; |
| 1287 | break; |
| 1288 | |
| 1289 | default: |
| 1290 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1291 | << " to " << result_type; |
| 1292 | } |
| 1293 | break; |
| 1294 | |
| 1295 | case Primitive::kPrimInt: |
| 1296 | case Primitive::kPrimFloat: |
| 1297 | case Primitive::kPrimDouble: |
| 1298 | LOG(FATAL) << "Type conversion from " << input_type |
| 1299 | << " to " << result_type << " not yet implemented"; |
| 1300 | break; |
| 1301 | |
| 1302 | default: |
| 1303 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1304 | << " to " << result_type; |
| 1305 | } |
| 1306 | } |
| 1307 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 1308 | void LocationsBuilderX86::VisitAdd(HAdd* add) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1309 | LocationSummary* locations = |
| 1310 | new (GetGraph()->GetArena()) LocationSummary(add, LocationSummary::kNoCall); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 1311 | switch (add->GetResultType()) { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1312 | case Primitive::kPrimInt: |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1313 | case Primitive::kPrimLong: { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1314 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1315 | locations->SetInAt(1, Location::Any()); |
| 1316 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1317 | break; |
| 1318 | } |
| 1319 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1320 | case Primitive::kPrimFloat: |
| 1321 | case Primitive::kPrimDouble: { |
| 1322 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1323 | locations->SetInAt(1, Location::Any()); |
| 1324 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1325 | break; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1326 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1327 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 1328 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1329 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
| 1330 | break; |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 1331 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 1332 | } |
| 1333 | |
| 1334 | void InstructionCodeGeneratorX86::VisitAdd(HAdd* add) { |
| 1335 | LocationSummary* locations = add->GetLocations(); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1336 | Location first = locations->InAt(0); |
| 1337 | Location second = locations->InAt(1); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 1338 | DCHECK(first.Equals(locations->Out())); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 1339 | switch (add->GetResultType()) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1340 | case Primitive::kPrimInt: { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1341 | if (second.IsRegister()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1342 | __ addl(first.As<Register>(), second.As<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1343 | } else if (second.IsConstant()) { |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 1344 | __ addl(first.As<Register>(), Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1345 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1346 | __ addl(first.As<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1347 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 1348 | break; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1349 | } |
| 1350 | |
| 1351 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1352 | if (second.IsRegister()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1353 | __ addl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 1354 | __ adcl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1355 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1356 | __ addl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
| 1357 | __ adcl(first.AsRegisterPairHigh<Register>(), |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1358 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1359 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1360 | break; |
| 1361 | } |
| 1362 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1363 | case Primitive::kPrimFloat: { |
| 1364 | if (second.IsFpuRegister()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1365 | __ addss(first.As<XmmRegister>(), second.As<XmmRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1366 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1367 | __ addss(first.As<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1368 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1369 | break; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1370 | } |
| 1371 | |
| 1372 | case Primitive::kPrimDouble: { |
| 1373 | if (second.IsFpuRegister()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1374 | __ addsd(first.As<XmmRegister>(), second.As<XmmRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1375 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1376 | __ addsd(first.As<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1377 | } |
| 1378 | break; |
| 1379 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1380 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 1381 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1382 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 1383 | } |
| 1384 | } |
| 1385 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 1386 | void LocationsBuilderX86::VisitSub(HSub* sub) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1387 | LocationSummary* locations = |
| 1388 | new (GetGraph()->GetArena()) LocationSummary(sub, LocationSummary::kNoCall); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 1389 | switch (sub->GetResultType()) { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1390 | case Primitive::kPrimInt: |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1391 | case Primitive::kPrimLong: { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1392 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1393 | locations->SetInAt(1, Location::Any()); |
| 1394 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1395 | break; |
| 1396 | } |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 1397 | case Primitive::kPrimFloat: |
| 1398 | case Primitive::kPrimDouble: { |
| 1399 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1400 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 1401 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1402 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 1403 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1404 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 1405 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 1406 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 1407 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 1408 | } |
| 1409 | |
| 1410 | void InstructionCodeGeneratorX86::VisitSub(HSub* sub) { |
| 1411 | LocationSummary* locations = sub->GetLocations(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1412 | Location first = locations->InAt(0); |
| 1413 | Location second = locations->InAt(1); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 1414 | DCHECK(first.Equals(locations->Out())); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 1415 | switch (sub->GetResultType()) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1416 | case Primitive::kPrimInt: { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1417 | if (second.IsRegister()) { |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 1418 | __ subl(first.As<Register>(), second.As<Register>()); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1419 | } else if (second.IsConstant()) { |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 1420 | __ subl(first.As<Register>(), Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1421 | } else { |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 1422 | __ subl(first.As<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1423 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 1424 | break; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1425 | } |
| 1426 | |
| 1427 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1428 | if (second.IsRegister()) { |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 1429 | __ subl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 1430 | __ sbbl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1431 | } else { |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 1432 | __ subl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1433 | __ sbbl(first.AsRegisterPairHigh<Register>(), |
| 1434 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1435 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1436 | break; |
| 1437 | } |
| 1438 | |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 1439 | case Primitive::kPrimFloat: { |
| 1440 | __ subss(first.As<XmmRegister>(), second.As<XmmRegister>()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1441 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 1442 | } |
| 1443 | |
| 1444 | case Primitive::kPrimDouble: { |
| 1445 | __ subsd(first.As<XmmRegister>(), second.As<XmmRegister>()); |
| 1446 | break; |
| 1447 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1448 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 1449 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 1450 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 1451 | } |
| 1452 | } |
| 1453 | |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 1454 | void LocationsBuilderX86::VisitMul(HMul* mul) { |
| 1455 | LocationSummary* locations = |
| 1456 | new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall); |
| 1457 | switch (mul->GetResultType()) { |
| 1458 | case Primitive::kPrimInt: |
| 1459 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1460 | locations->SetInAt(1, Location::Any()); |
| 1461 | locations->SetOut(Location::SameAsFirstInput()); |
| 1462 | break; |
| 1463 | case Primitive::kPrimLong: { |
| 1464 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1465 | // TODO: Currently this handles only stack operands: |
| 1466 | // - we don't have enough registers because we currently use Quick ABI. |
| 1467 | // - by the time we have a working register allocator we will probably change the ABI |
| 1468 | // and fix the above. |
| 1469 | // - we don't have a way yet to request operands on stack but the base line compiler |
| 1470 | // will leave the operands on the stack with Any(). |
| 1471 | locations->SetInAt(1, Location::Any()); |
| 1472 | locations->SetOut(Location::SameAsFirstInput()); |
| 1473 | // Needed for imul on 32bits with 64bits output. |
| 1474 | locations->AddTemp(Location::RegisterLocation(EAX)); |
| 1475 | locations->AddTemp(Location::RegisterLocation(EDX)); |
| 1476 | break; |
| 1477 | } |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 1478 | case Primitive::kPrimFloat: |
| 1479 | case Primitive::kPrimDouble: { |
| 1480 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1481 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 1482 | locations->SetOut(Location::SameAsFirstInput()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 1483 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 1484 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 1485 | |
| 1486 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 1487 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 1488 | } |
| 1489 | } |
| 1490 | |
| 1491 | void InstructionCodeGeneratorX86::VisitMul(HMul* mul) { |
| 1492 | LocationSummary* locations = mul->GetLocations(); |
| 1493 | Location first = locations->InAt(0); |
| 1494 | Location second = locations->InAt(1); |
| 1495 | DCHECK(first.Equals(locations->Out())); |
| 1496 | |
| 1497 | switch (mul->GetResultType()) { |
| 1498 | case Primitive::kPrimInt: { |
| 1499 | if (second.IsRegister()) { |
| 1500 | __ imull(first.As<Register>(), second.As<Register>()); |
| 1501 | } else if (second.IsConstant()) { |
| 1502 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue()); |
| 1503 | __ imull(first.As<Register>(), imm); |
| 1504 | } else { |
| 1505 | DCHECK(second.IsStackSlot()); |
| 1506 | __ imull(first.As<Register>(), Address(ESP, second.GetStackIndex())); |
| 1507 | } |
| 1508 | break; |
| 1509 | } |
| 1510 | |
| 1511 | case Primitive::kPrimLong: { |
| 1512 | DCHECK(second.IsDoubleStackSlot()); |
| 1513 | |
| 1514 | Register in1_hi = first.AsRegisterPairHigh<Register>(); |
| 1515 | Register in1_lo = first.AsRegisterPairLow<Register>(); |
| 1516 | Address in2_hi(ESP, second.GetHighStackIndex(kX86WordSize)); |
| 1517 | Address in2_lo(ESP, second.GetStackIndex()); |
| 1518 | Register eax = locations->GetTemp(0).As<Register>(); |
| 1519 | Register edx = locations->GetTemp(1).As<Register>(); |
| 1520 | |
| 1521 | DCHECK_EQ(EAX, eax); |
| 1522 | DCHECK_EQ(EDX, edx); |
| 1523 | |
| 1524 | // input: in1 - 64 bits, in2 - 64 bits |
| 1525 | // output: in1 |
| 1526 | // formula: in1.hi : in1.lo = (in1.lo * in2.hi + in1.hi * in2.lo)* 2^32 + in1.lo * in2.lo |
| 1527 | // parts: in1.hi = in1.lo * in2.hi + in1.hi * in2.lo + (in1.lo * in2.lo)[63:32] |
| 1528 | // parts: in1.lo = (in1.lo * in2.lo)[31:0] |
| 1529 | |
| 1530 | __ movl(eax, in2_hi); |
| 1531 | // eax <- in1.lo * in2.hi |
| 1532 | __ imull(eax, in1_lo); |
| 1533 | // in1.hi <- in1.hi * in2.lo |
| 1534 | __ imull(in1_hi, in2_lo); |
| 1535 | // in1.hi <- in1.lo * in2.hi + in1.hi * in2.lo |
| 1536 | __ addl(in1_hi, eax); |
| 1537 | // move in1_lo to eax to prepare for double precision |
| 1538 | __ movl(eax, in1_lo); |
| 1539 | // edx:eax <- in1.lo * in2.lo |
| 1540 | __ mull(in2_lo); |
| 1541 | // in1.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32] |
| 1542 | __ addl(in1_hi, edx); |
| 1543 | // in1.lo <- (in1.lo * in2.lo)[31:0]; |
| 1544 | __ movl(in1_lo, eax); |
| 1545 | |
| 1546 | break; |
| 1547 | } |
| 1548 | |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 1549 | case Primitive::kPrimFloat: { |
| 1550 | __ mulss(first.As<XmmRegister>(), second.As<XmmRegister>()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 1551 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 1552 | } |
| 1553 | |
| 1554 | case Primitive::kPrimDouble: { |
| 1555 | __ mulsd(first.As<XmmRegister>(), second.As<XmmRegister>()); |
| 1556 | break; |
| 1557 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 1558 | |
| 1559 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 1560 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 1561 | } |
| 1562 | } |
| 1563 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1564 | void LocationsBuilderX86::VisitDiv(HDiv* div) { |
| 1565 | LocationSummary* locations = |
| 1566 | new (GetGraph()->GetArena()) LocationSummary(div, LocationSummary::kNoCall); |
| 1567 | switch (div->GetResultType()) { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 1568 | case Primitive::kPrimInt: { |
| 1569 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
| 1570 | locations->SetInAt(1, Location::RequiresRegister()); |
| 1571 | locations->SetOut(Location::SameAsFirstInput()); |
| 1572 | // Intel uses edx:eax as the dividend. |
| 1573 | locations->AddTemp(Location::RegisterLocation(EDX)); |
| 1574 | break; |
| 1575 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1576 | case Primitive::kPrimLong: { |
| 1577 | LOG(FATAL) << "Not implemented div type" << div->GetResultType(); |
| 1578 | break; |
| 1579 | } |
| 1580 | case Primitive::kPrimFloat: |
| 1581 | case Primitive::kPrimDouble: { |
| 1582 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1583 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 1584 | locations->SetOut(Location::SameAsFirstInput()); |
| 1585 | break; |
| 1586 | } |
| 1587 | |
| 1588 | default: |
| 1589 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 1590 | } |
| 1591 | } |
| 1592 | |
| 1593 | void InstructionCodeGeneratorX86::VisitDiv(HDiv* div) { |
| 1594 | LocationSummary* locations = div->GetLocations(); |
| 1595 | Location first = locations->InAt(0); |
| 1596 | Location second = locations->InAt(1); |
| 1597 | DCHECK(first.Equals(locations->Out())); |
| 1598 | |
| 1599 | switch (div->GetResultType()) { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 1600 | case Primitive::kPrimInt: { |
| 1601 | Register first_reg = first.As<Register>(); |
| 1602 | Register second_reg = second.As<Register>(); |
| 1603 | DCHECK_EQ(EAX, first_reg); |
| 1604 | DCHECK_EQ(EDX, locations->GetTemp(0).As<Register>()); |
| 1605 | |
| 1606 | SlowPathCodeX86* slow_path = |
| 1607 | new (GetGraph()->GetArena()) DivMinusOneSlowPathX86(first_reg); |
| 1608 | codegen_->AddSlowPath(slow_path); |
| 1609 | |
| 1610 | // 0x80000000/-1 triggers an arithmetic exception! |
| 1611 | // Dividing by -1 is actually negation and -0x800000000 = 0x80000000 so |
| 1612 | // it's safe to just use negl instead of more complex comparisons. |
| 1613 | |
| 1614 | __ cmpl(second_reg, Immediate(-1)); |
| 1615 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 1616 | |
| 1617 | // edx:eax <- sign-extended of eax |
| 1618 | __ cdq(); |
| 1619 | // eax = quotient, edx = remainder |
| 1620 | __ idivl(second_reg); |
| 1621 | |
| 1622 | __ Bind(slow_path->GetExitLabel()); |
| 1623 | break; |
| 1624 | } |
| 1625 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1626 | case Primitive::kPrimLong: { |
| 1627 | LOG(FATAL) << "Not implemented div type" << div->GetResultType(); |
| 1628 | break; |
| 1629 | } |
| 1630 | |
| 1631 | case Primitive::kPrimFloat: { |
| 1632 | __ divss(first.As<XmmRegister>(), second.As<XmmRegister>()); |
| 1633 | break; |
| 1634 | } |
| 1635 | |
| 1636 | case Primitive::kPrimDouble: { |
| 1637 | __ divsd(first.As<XmmRegister>(), second.As<XmmRegister>()); |
| 1638 | break; |
| 1639 | } |
| 1640 | |
| 1641 | default: |
| 1642 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 1643 | } |
| 1644 | } |
| 1645 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 1646 | void LocationsBuilderX86::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
| 1647 | LocationSummary* locations = |
| 1648 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 1649 | locations->SetInAt(0, Location::Any()); |
| 1650 | if (instruction->HasUses()) { |
| 1651 | locations->SetOut(Location::SameAsFirstInput()); |
| 1652 | } |
| 1653 | } |
| 1654 | |
| 1655 | void InstructionCodeGeneratorX86::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
| 1656 | SlowPathCodeX86* slow_path = new (GetGraph()->GetArena()) DivZeroCheckSlowPathX86(instruction); |
| 1657 | codegen_->AddSlowPath(slow_path); |
| 1658 | |
| 1659 | LocationSummary* locations = instruction->GetLocations(); |
| 1660 | Location value = locations->InAt(0); |
| 1661 | |
| 1662 | if (value.IsRegister()) { |
| 1663 | __ testl(value.As<Register>(), value.As<Register>()); |
| 1664 | } else if (value.IsStackSlot()) { |
| 1665 | __ cmpl(Address(ESP, value.GetStackIndex()), Immediate(0)); |
| 1666 | } else { |
| 1667 | DCHECK(value.IsConstant()) << value; |
| 1668 | if (value.GetConstant()->AsIntConstant()->GetValue() == 0) { |
| 1669 | __ jmp(slow_path->GetEntryLabel()); |
| 1670 | } |
| 1671 | return; |
| 1672 | } |
| 1673 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 1674 | } |
| 1675 | |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 1676 | void LocationsBuilderX86::VisitNewInstance(HNewInstance* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1677 | LocationSummary* locations = |
| 1678 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1679 | locations->SetOut(Location::RegisterLocation(EAX)); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1680 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1681 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 1682 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 1683 | } |
| 1684 | |
| 1685 | void InstructionCodeGeneratorX86::VisitNewInstance(HNewInstance* instruction) { |
| 1686 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 1687 | codegen_->LoadCurrentMethod(calling_convention.GetRegisterAt(1)); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1688 | __ movl(calling_convention.GetRegisterAt(0), Immediate(instruction->GetTypeIndex())); |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 1689 | |
Nicolas Geoffray | 707c809 | 2014-04-04 10:50:14 +0100 | [diff] [blame] | 1690 | __ fs()->call( |
| 1691 | Address::Absolute(QUICK_ENTRYPOINT_OFFSET(kX86WordSize, pAllocObjectWithAccessCheck))); |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 1692 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1693 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 1694 | DCHECK(!codegen_->IsLeafMethod()); |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 1695 | } |
| 1696 | |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 1697 | void LocationsBuilderX86::VisitNewArray(HNewArray* instruction) { |
| 1698 | LocationSummary* locations = |
| 1699 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
| 1700 | locations->SetOut(Location::RegisterLocation(EAX)); |
| 1701 | InvokeRuntimeCallingConvention calling_convention; |
| 1702 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 1703 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 1704 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(2))); |
| 1705 | } |
| 1706 | |
| 1707 | void InstructionCodeGeneratorX86::VisitNewArray(HNewArray* instruction) { |
| 1708 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 1709 | codegen_->LoadCurrentMethod(calling_convention.GetRegisterAt(1)); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 1710 | __ movl(calling_convention.GetRegisterAt(0), Immediate(instruction->GetTypeIndex())); |
| 1711 | |
| 1712 | __ fs()->call( |
| 1713 | Address::Absolute(QUICK_ENTRYPOINT_OFFSET(kX86WordSize, pAllocArrayWithAccessCheck))); |
| 1714 | |
| 1715 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
| 1716 | DCHECK(!codegen_->IsLeafMethod()); |
| 1717 | } |
| 1718 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 1719 | void LocationsBuilderX86::VisitParameterValue(HParameterValue* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1720 | LocationSummary* locations = |
| 1721 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1722 | Location location = parameter_visitor_.GetNextLocation(instruction->GetType()); |
| 1723 | if (location.IsStackSlot()) { |
| 1724 | location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 1725 | } else if (location.IsDoubleStackSlot()) { |
| 1726 | location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 1727 | } |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1728 | locations->SetOut(location); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 1729 | } |
| 1730 | |
| 1731 | void InstructionCodeGeneratorX86::VisitParameterValue(HParameterValue* instruction) { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1732 | UNUSED(instruction); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 1733 | } |
| 1734 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 1735 | void LocationsBuilderX86::VisitNot(HNot* not_) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1736 | LocationSummary* locations = |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 1737 | new (GetGraph()->GetArena()) LocationSummary(not_, LocationSummary::kNoCall); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1738 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1739 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 1740 | } |
| 1741 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 1742 | void InstructionCodeGeneratorX86::VisitNot(HNot* not_) { |
| 1743 | LocationSummary* locations = not_->GetLocations(); |
Roland Levillain | 7056643 | 2014-10-24 16:20:17 +0100 | [diff] [blame] | 1744 | Location in = locations->InAt(0); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1745 | Location out = locations->Out(); |
Roland Levillain | 7056643 | 2014-10-24 16:20:17 +0100 | [diff] [blame] | 1746 | DCHECK(in.Equals(out)); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 1747 | switch (not_->InputAt(0)->GetType()) { |
| 1748 | case Primitive::kPrimBoolean: |
| 1749 | __ xorl(out.As<Register>(), Immediate(1)); |
| 1750 | break; |
| 1751 | |
| 1752 | case Primitive::kPrimInt: |
| 1753 | __ notl(out.As<Register>()); |
| 1754 | break; |
| 1755 | |
| 1756 | case Primitive::kPrimLong: |
Roland Levillain | 7056643 | 2014-10-24 16:20:17 +0100 | [diff] [blame] | 1757 | __ notl(out.AsRegisterPairLow<Register>()); |
| 1758 | __ notl(out.AsRegisterPairHigh<Register>()); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 1759 | break; |
| 1760 | |
| 1761 | default: |
| 1762 | LOG(FATAL) << "Unimplemented type for not operation " << not_->GetResultType(); |
| 1763 | } |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 1764 | } |
| 1765 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1766 | void LocationsBuilderX86::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1767 | LocationSummary* locations = |
| 1768 | new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 1769 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1770 | locations->SetInAt(1, Location::Any()); |
| 1771 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1772 | } |
| 1773 | |
| 1774 | void InstructionCodeGeneratorX86::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1775 | LocationSummary* locations = compare->GetLocations(); |
| 1776 | switch (compare->InputAt(0)->GetType()) { |
| 1777 | case Primitive::kPrimLong: { |
| 1778 | Label less, greater, done; |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1779 | Register output = locations->Out().As<Register>(); |
| 1780 | Location left = locations->InAt(0); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1781 | Location right = locations->InAt(1); |
| 1782 | if (right.IsRegister()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1783 | __ cmpl(left.AsRegisterPairHigh<Register>(), right.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1784 | } else { |
| 1785 | DCHECK(right.IsDoubleStackSlot()); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1786 | __ cmpl(left.AsRegisterPairHigh<Register>(), |
| 1787 | Address(ESP, right.GetHighStackIndex(kX86WordSize))); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1788 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1789 | __ j(kLess, &less); // Signed compare. |
| 1790 | __ j(kGreater, &greater); // Signed compare. |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1791 | if (right.IsRegisterPair()) { |
| 1792 | __ cmpl(left.AsRegisterPairLow<Register>(), right.AsRegisterPairLow<Register>()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1793 | } else { |
| 1794 | DCHECK(right.IsDoubleStackSlot()); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1795 | __ cmpl(left.AsRegisterPairLow<Register>(), Address(ESP, right.GetStackIndex())); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1796 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1797 | __ movl(output, Immediate(0)); |
| 1798 | __ j(kEqual, &done); |
| 1799 | __ j(kBelow, &less); // Unsigned compare. |
| 1800 | |
| 1801 | __ Bind(&greater); |
| 1802 | __ movl(output, Immediate(1)); |
| 1803 | __ jmp(&done); |
| 1804 | |
| 1805 | __ Bind(&less); |
| 1806 | __ movl(output, Immediate(-1)); |
| 1807 | |
| 1808 | __ Bind(&done); |
| 1809 | break; |
| 1810 | } |
| 1811 | default: |
| 1812 | LOG(FATAL) << "Unimplemented compare type " << compare->InputAt(0)->GetType(); |
| 1813 | } |
| 1814 | } |
| 1815 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1816 | void LocationsBuilderX86::VisitPhi(HPhi* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1817 | LocationSummary* locations = |
| 1818 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 31d76b4 | 2014-06-09 15:02:22 +0100 | [diff] [blame] | 1819 | for (size_t i = 0, e = instruction->InputCount(); i < e; ++i) { |
| 1820 | locations->SetInAt(i, Location::Any()); |
| 1821 | } |
| 1822 | locations->SetOut(Location::Any()); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1823 | } |
| 1824 | |
| 1825 | void InstructionCodeGeneratorX86::VisitPhi(HPhi* instruction) { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1826 | UNUSED(instruction); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 1827 | LOG(FATAL) << "Unreachable"; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1828 | } |
| 1829 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1830 | void LocationsBuilderX86::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1831 | LocationSummary* locations = |
| 1832 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1833 | locations->SetInAt(0, Location::RequiresRegister()); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1834 | Primitive::Type field_type = instruction->GetFieldType(); |
Nicolas Geoffray | 9ae0daa | 2014-09-30 22:40:23 +0100 | [diff] [blame] | 1835 | bool is_object_type = field_type == Primitive::kPrimNot; |
Nicolas Geoffray | 7adfcc8 | 2014-10-07 12:24:52 +0100 | [diff] [blame] | 1836 | bool is_byte_type = (field_type == Primitive::kPrimBoolean) |
| 1837 | || (field_type == Primitive::kPrimByte); |
| 1838 | // The register allocator does not support multiple |
| 1839 | // inputs that die at entry with one in a specific register. |
Nicolas Geoffray | 7adfcc8 | 2014-10-07 12:24:52 +0100 | [diff] [blame] | 1840 | if (is_byte_type) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1841 | // Ensure the value is in a byte register. |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 1842 | locations->SetInAt(1, Location::RegisterLocation(EAX)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1843 | } else { |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 1844 | locations->SetInAt(1, Location::RequiresRegister()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1845 | } |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 1846 | // Temporary registers for the write barrier. |
Nicolas Geoffray | 9ae0daa | 2014-09-30 22:40:23 +0100 | [diff] [blame] | 1847 | if (is_object_type) { |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 1848 | locations->AddTemp(Location::RequiresRegister()); |
| 1849 | // Ensure the card is in a byte register. |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1850 | locations->AddTemp(Location::RegisterLocation(ECX)); |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 1851 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1852 | } |
| 1853 | |
| 1854 | void InstructionCodeGeneratorX86::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
| 1855 | LocationSummary* locations = instruction->GetLocations(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1856 | Register obj = locations->InAt(0).As<Register>(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1857 | uint32_t offset = instruction->GetFieldOffset().Uint32Value(); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1858 | Primitive::Type field_type = instruction->GetFieldType(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1859 | |
| 1860 | switch (field_type) { |
| 1861 | case Primitive::kPrimBoolean: |
| 1862 | case Primitive::kPrimByte: { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1863 | ByteRegister value = locations->InAt(1).As<ByteRegister>(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1864 | __ movb(Address(obj, offset), value); |
| 1865 | break; |
| 1866 | } |
| 1867 | |
| 1868 | case Primitive::kPrimShort: |
| 1869 | case Primitive::kPrimChar: { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1870 | Register value = locations->InAt(1).As<Register>(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1871 | __ movw(Address(obj, offset), value); |
| 1872 | break; |
| 1873 | } |
| 1874 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1875 | case Primitive::kPrimInt: |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1876 | case Primitive::kPrimNot: { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1877 | Register value = locations->InAt(1).As<Register>(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1878 | __ movl(Address(obj, offset), value); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1879 | |
| 1880 | if (field_type == Primitive::kPrimNot) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1881 | Register temp = locations->GetTemp(0).As<Register>(); |
| 1882 | Register card = locations->GetTemp(1).As<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1883 | codegen_->MarkGCCard(temp, card, obj, value); |
| 1884 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1885 | break; |
| 1886 | } |
| 1887 | |
| 1888 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1889 | Location value = locations->InAt(1); |
| 1890 | __ movl(Address(obj, offset), value.AsRegisterPairLow<Register>()); |
| 1891 | __ movl(Address(obj, kX86WordSize + offset), value.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1892 | break; |
| 1893 | } |
| 1894 | |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 1895 | case Primitive::kPrimFloat: { |
| 1896 | XmmRegister value = locations->InAt(1).As<XmmRegister>(); |
| 1897 | __ movss(Address(obj, offset), value); |
| 1898 | break; |
| 1899 | } |
| 1900 | |
| 1901 | case Primitive::kPrimDouble: { |
| 1902 | XmmRegister value = locations->InAt(1).As<XmmRegister>(); |
| 1903 | __ movsd(Address(obj, offset), value); |
| 1904 | break; |
| 1905 | } |
| 1906 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1907 | case Primitive::kPrimVoid: |
| 1908 | LOG(FATAL) << "Unreachable type " << field_type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 1909 | UNREACHABLE(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1910 | } |
| 1911 | } |
| 1912 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1913 | void CodeGeneratorX86::MarkGCCard(Register temp, Register card, Register object, Register value) { |
| 1914 | Label is_null; |
| 1915 | __ testl(value, value); |
| 1916 | __ j(kEqual, &is_null); |
| 1917 | __ fs()->movl(card, Address::Absolute(Thread::CardTableOffset<kX86WordSize>().Int32Value())); |
| 1918 | __ movl(temp, object); |
| 1919 | __ shrl(temp, Immediate(gc::accounting::CardTable::kCardShift)); |
| 1920 | __ movb(Address(temp, card, TIMES_1, 0), |
| 1921 | X86ManagedRegister::FromCpuRegister(card).AsByteRegister()); |
| 1922 | __ Bind(&is_null); |
| 1923 | } |
| 1924 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1925 | void LocationsBuilderX86::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1926 | LocationSummary* locations = |
| 1927 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 1928 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1929 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1930 | } |
| 1931 | |
| 1932 | void InstructionCodeGeneratorX86::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 1933 | LocationSummary* locations = instruction->GetLocations(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1934 | Register obj = locations->InAt(0).As<Register>(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1935 | uint32_t offset = instruction->GetFieldOffset().Uint32Value(); |
| 1936 | |
| 1937 | switch (instruction->GetType()) { |
| 1938 | case Primitive::kPrimBoolean: { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1939 | Register out = locations->Out().As<Register>(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1940 | __ movzxb(out, Address(obj, offset)); |
| 1941 | break; |
| 1942 | } |
| 1943 | |
| 1944 | case Primitive::kPrimByte: { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1945 | Register out = locations->Out().As<Register>(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1946 | __ movsxb(out, Address(obj, offset)); |
| 1947 | break; |
| 1948 | } |
| 1949 | |
| 1950 | case Primitive::kPrimShort: { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1951 | Register out = locations->Out().As<Register>(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1952 | __ movsxw(out, Address(obj, offset)); |
| 1953 | break; |
| 1954 | } |
| 1955 | |
| 1956 | case Primitive::kPrimChar: { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1957 | Register out = locations->Out().As<Register>(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1958 | __ movzxw(out, Address(obj, offset)); |
| 1959 | break; |
| 1960 | } |
| 1961 | |
| 1962 | case Primitive::kPrimInt: |
| 1963 | case Primitive::kPrimNot: { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1964 | Register out = locations->Out().As<Register>(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1965 | __ movl(out, Address(obj, offset)); |
| 1966 | break; |
| 1967 | } |
| 1968 | |
| 1969 | case Primitive::kPrimLong: { |
| 1970 | // TODO: support volatile. |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1971 | __ movl(locations->Out().AsRegisterPairLow<Register>(), Address(obj, offset)); |
| 1972 | __ movl(locations->Out().AsRegisterPairHigh<Register>(), Address(obj, kX86WordSize + offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1973 | break; |
| 1974 | } |
| 1975 | |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 1976 | case Primitive::kPrimFloat: { |
| 1977 | XmmRegister out = locations->Out().As<XmmRegister>(); |
| 1978 | __ movss(out, Address(obj, offset)); |
| 1979 | break; |
| 1980 | } |
| 1981 | |
| 1982 | case Primitive::kPrimDouble: { |
| 1983 | XmmRegister out = locations->Out().As<XmmRegister>(); |
| 1984 | __ movsd(out, Address(obj, offset)); |
| 1985 | break; |
| 1986 | } |
| 1987 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1988 | case Primitive::kPrimVoid: |
| 1989 | LOG(FATAL) << "Unreachable type " << instruction->GetType(); |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 1990 | UNREACHABLE(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1991 | } |
| 1992 | } |
| 1993 | |
| 1994 | void LocationsBuilderX86::VisitNullCheck(HNullCheck* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1995 | LocationSummary* locations = |
| 1996 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1997 | locations->SetInAt(0, Location::Any()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 1998 | if (instruction->HasUses()) { |
| 1999 | locations->SetOut(Location::SameAsFirstInput()); |
| 2000 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2001 | } |
| 2002 | |
| 2003 | void InstructionCodeGeneratorX86::VisitNullCheck(HNullCheck* instruction) { |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 2004 | SlowPathCodeX86* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathX86(instruction); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2005 | codegen_->AddSlowPath(slow_path); |
| 2006 | |
| 2007 | LocationSummary* locations = instruction->GetLocations(); |
| 2008 | Location obj = locations->InAt(0); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2009 | |
| 2010 | if (obj.IsRegister()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2011 | __ cmpl(obj.As<Register>(), Immediate(0)); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 2012 | } else if (obj.IsStackSlot()) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2013 | __ cmpl(Address(ESP, obj.GetStackIndex()), Immediate(0)); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 2014 | } else { |
| 2015 | DCHECK(obj.IsConstant()) << obj; |
| 2016 | DCHECK_EQ(obj.GetConstant()->AsIntConstant()->GetValue(), 0); |
| 2017 | __ jmp(slow_path->GetEntryLabel()); |
| 2018 | return; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2019 | } |
| 2020 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 2021 | } |
| 2022 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2023 | void LocationsBuilderX86::VisitArrayGet(HArrayGet* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2024 | LocationSummary* locations = |
| 2025 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 2026 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2027 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 2028 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2029 | } |
| 2030 | |
| 2031 | void InstructionCodeGeneratorX86::VisitArrayGet(HArrayGet* instruction) { |
| 2032 | LocationSummary* locations = instruction->GetLocations(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2033 | Register obj = locations->InAt(0).As<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2034 | Location index = locations->InAt(1); |
| 2035 | |
| 2036 | switch (instruction->GetType()) { |
| 2037 | case Primitive::kPrimBoolean: { |
| 2038 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2039 | Register out = locations->Out().As<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2040 | if (index.IsConstant()) { |
| 2041 | __ movzxb(out, Address(obj, |
| 2042 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset)); |
| 2043 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2044 | __ movzxb(out, Address(obj, index.As<Register>(), TIMES_1, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2045 | } |
| 2046 | break; |
| 2047 | } |
| 2048 | |
| 2049 | case Primitive::kPrimByte: { |
| 2050 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int8_t)).Uint32Value(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2051 | Register out = locations->Out().As<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2052 | if (index.IsConstant()) { |
| 2053 | __ movsxb(out, Address(obj, |
| 2054 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset)); |
| 2055 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2056 | __ movsxb(out, Address(obj, index.As<Register>(), TIMES_1, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2057 | } |
| 2058 | break; |
| 2059 | } |
| 2060 | |
| 2061 | case Primitive::kPrimShort: { |
| 2062 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int16_t)).Uint32Value(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2063 | Register out = locations->Out().As<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2064 | if (index.IsConstant()) { |
| 2065 | __ movsxw(out, Address(obj, |
| 2066 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset)); |
| 2067 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2068 | __ movsxw(out, Address(obj, index.As<Register>(), TIMES_2, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2069 | } |
| 2070 | break; |
| 2071 | } |
| 2072 | |
| 2073 | case Primitive::kPrimChar: { |
| 2074 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2075 | Register out = locations->Out().As<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2076 | if (index.IsConstant()) { |
| 2077 | __ movzxw(out, Address(obj, |
| 2078 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset)); |
| 2079 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2080 | __ movzxw(out, Address(obj, index.As<Register>(), TIMES_2, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2081 | } |
| 2082 | break; |
| 2083 | } |
| 2084 | |
| 2085 | case Primitive::kPrimInt: |
| 2086 | case Primitive::kPrimNot: { |
| 2087 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_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 | __ movl(out, Address(obj, |
| 2091 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset)); |
| 2092 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2093 | __ movl(out, Address(obj, index.As<Register>(), TIMES_4, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2094 | } |
| 2095 | break; |
| 2096 | } |
| 2097 | |
| 2098 | case Primitive::kPrimLong: { |
| 2099 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2100 | Location out = locations->Out(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2101 | if (index.IsConstant()) { |
| 2102 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2103 | __ movl(out.AsRegisterPairLow<Register>(), Address(obj, offset)); |
| 2104 | __ movl(out.AsRegisterPairHigh<Register>(), Address(obj, offset + kX86WordSize)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2105 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2106 | __ movl(out.AsRegisterPairLow<Register>(), |
| 2107 | Address(obj, index.As<Register>(), TIMES_8, data_offset)); |
| 2108 | __ movl(out.AsRegisterPairHigh<Register>(), |
| 2109 | Address(obj, index.As<Register>(), TIMES_8, data_offset + kX86WordSize)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2110 | } |
| 2111 | break; |
| 2112 | } |
| 2113 | |
| 2114 | case Primitive::kPrimFloat: |
| 2115 | case Primitive::kPrimDouble: |
| 2116 | LOG(FATAL) << "Unimplemented register type " << instruction->GetType(); |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 2117 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2118 | case Primitive::kPrimVoid: |
| 2119 | LOG(FATAL) << "Unreachable type " << instruction->GetType(); |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 2120 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2121 | } |
| 2122 | } |
| 2123 | |
| 2124 | void LocationsBuilderX86::VisitArraySet(HArraySet* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2125 | Primitive::Type value_type = instruction->GetComponentType(); |
| 2126 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary( |
| 2127 | instruction, |
| 2128 | value_type == Primitive::kPrimNot ? LocationSummary::kCall : LocationSummary::kNoCall); |
| 2129 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2130 | if (value_type == Primitive::kPrimNot) { |
| 2131 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2132 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 2133 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 2134 | locations->SetInAt(2, Location::RegisterLocation(calling_convention.GetRegisterAt(2))); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2135 | } else { |
Nicolas Geoffray | 7adfcc8 | 2014-10-07 12:24:52 +0100 | [diff] [blame] | 2136 | bool is_byte_type = (value_type == Primitive::kPrimBoolean) |
| 2137 | || (value_type == Primitive::kPrimByte); |
Nicolas Geoffray | 9ae0daa | 2014-09-30 22:40:23 +0100 | [diff] [blame] | 2138 | // 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] | 2139 | // In case of a byte operation, the register allocator does not support multiple |
| 2140 | // inputs that die at entry with one in a specific register. |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 2141 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2142 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Nicolas Geoffray | 7adfcc8 | 2014-10-07 12:24:52 +0100 | [diff] [blame] | 2143 | if (is_byte_type) { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2144 | // Ensure the value is in a byte register. |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 2145 | locations->SetInAt(2, Location::ByteRegisterOrConstant(EAX, instruction->InputAt(2))); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2146 | } else { |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 2147 | locations->SetInAt(2, Location::RegisterOrConstant(instruction->InputAt(2))); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2148 | } |
| 2149 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2150 | } |
| 2151 | |
| 2152 | void InstructionCodeGeneratorX86::VisitArraySet(HArraySet* instruction) { |
| 2153 | LocationSummary* locations = instruction->GetLocations(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2154 | Register obj = locations->InAt(0).As<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2155 | Location index = locations->InAt(1); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 2156 | Location value = locations->InAt(2); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2157 | Primitive::Type value_type = instruction->GetComponentType(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2158 | |
| 2159 | switch (value_type) { |
| 2160 | case Primitive::kPrimBoolean: |
| 2161 | case Primitive::kPrimByte: { |
| 2162 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2163 | if (index.IsConstant()) { |
| 2164 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset; |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 2165 | if (value.IsRegister()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2166 | __ movb(Address(obj, offset), value.As<ByteRegister>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 2167 | } else { |
| 2168 | __ movb(Address(obj, offset), |
| 2169 | Immediate(value.GetConstant()->AsIntConstant()->GetValue())); |
| 2170 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2171 | } else { |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 2172 | if (value.IsRegister()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2173 | __ movb(Address(obj, index.As<Register>(), TIMES_1, data_offset), |
| 2174 | value.As<ByteRegister>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 2175 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2176 | __ movb(Address(obj, index.As<Register>(), TIMES_1, data_offset), |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 2177 | Immediate(value.GetConstant()->AsIntConstant()->GetValue())); |
| 2178 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2179 | } |
| 2180 | break; |
| 2181 | } |
| 2182 | |
| 2183 | case Primitive::kPrimShort: |
| 2184 | case Primitive::kPrimChar: { |
| 2185 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2186 | if (index.IsConstant()) { |
| 2187 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset; |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 2188 | if (value.IsRegister()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2189 | __ movw(Address(obj, offset), value.As<Register>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 2190 | } else { |
| 2191 | __ movw(Address(obj, offset), |
| 2192 | Immediate(value.GetConstant()->AsIntConstant()->GetValue())); |
| 2193 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2194 | } else { |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 2195 | if (value.IsRegister()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2196 | __ movw(Address(obj, index.As<Register>(), TIMES_2, data_offset), |
| 2197 | value.As<Register>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 2198 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2199 | __ movw(Address(obj, index.As<Register>(), TIMES_2, data_offset), |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 2200 | Immediate(value.GetConstant()->AsIntConstant()->GetValue())); |
| 2201 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2202 | } |
| 2203 | break; |
| 2204 | } |
| 2205 | |
| 2206 | case Primitive::kPrimInt: { |
| 2207 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2208 | if (index.IsConstant()) { |
| 2209 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 2210 | if (value.IsRegister()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2211 | __ movl(Address(obj, offset), value.As<Register>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 2212 | } else { |
| 2213 | __ movl(Address(obj, offset), Immediate(value.GetConstant()->AsIntConstant()->GetValue())); |
| 2214 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2215 | } else { |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 2216 | if (value.IsRegister()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2217 | __ movl(Address(obj, index.As<Register>(), TIMES_4, data_offset), |
| 2218 | value.As<Register>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 2219 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2220 | __ movl(Address(obj, index.As<Register>(), TIMES_4, data_offset), |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 2221 | Immediate(value.GetConstant()->AsIntConstant()->GetValue())); |
| 2222 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2223 | } |
| 2224 | break; |
| 2225 | } |
| 2226 | |
| 2227 | case Primitive::kPrimNot: { |
| 2228 | DCHECK(!codegen_->IsLeafMethod()); |
| 2229 | __ fs()->call(Address::Absolute(QUICK_ENTRYPOINT_OFFSET(kX86WordSize, pAputObject))); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2230 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2231 | break; |
| 2232 | } |
| 2233 | |
| 2234 | case Primitive::kPrimLong: { |
| 2235 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2236 | if (index.IsConstant()) { |
| 2237 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2238 | if (value.IsRegisterPair()) { |
| 2239 | __ movl(Address(obj, offset), value.AsRegisterPairLow<Register>()); |
| 2240 | __ movl(Address(obj, offset + kX86WordSize), value.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 2241 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2242 | DCHECK(value.IsConstant()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 2243 | int64_t val = value.GetConstant()->AsLongConstant()->GetValue(); |
| 2244 | __ movl(Address(obj, offset), Immediate(Low32Bits(val))); |
| 2245 | __ movl(Address(obj, offset + kX86WordSize), Immediate(High32Bits(val))); |
| 2246 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2247 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2248 | if (value.IsRegisterPair()) { |
| 2249 | __ movl(Address(obj, index.As<Register>(), TIMES_8, data_offset), |
| 2250 | value.AsRegisterPairLow<Register>()); |
| 2251 | __ movl(Address(obj, index.As<Register>(), TIMES_8, data_offset + kX86WordSize), |
| 2252 | value.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 2253 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2254 | DCHECK(value.IsConstant()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 2255 | int64_t val = value.GetConstant()->AsLongConstant()->GetValue(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2256 | __ movl(Address(obj, index.As<Register>(), TIMES_8, data_offset), |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 2257 | Immediate(Low32Bits(val))); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2258 | __ movl(Address(obj, index.As<Register>(), TIMES_8, data_offset + kX86WordSize), |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 2259 | Immediate(High32Bits(val))); |
| 2260 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2261 | } |
| 2262 | break; |
| 2263 | } |
| 2264 | |
| 2265 | case Primitive::kPrimFloat: |
| 2266 | case Primitive::kPrimDouble: |
| 2267 | LOG(FATAL) << "Unimplemented register type " << instruction->GetType(); |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 2268 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2269 | case Primitive::kPrimVoid: |
| 2270 | LOG(FATAL) << "Unreachable type " << instruction->GetType(); |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 2271 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2272 | } |
| 2273 | } |
| 2274 | |
| 2275 | void LocationsBuilderX86::VisitArrayLength(HArrayLength* instruction) { |
| 2276 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 2277 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2278 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2279 | instruction->SetLocations(locations); |
| 2280 | } |
| 2281 | |
| 2282 | void InstructionCodeGeneratorX86::VisitArrayLength(HArrayLength* instruction) { |
| 2283 | LocationSummary* locations = instruction->GetLocations(); |
| 2284 | uint32_t offset = mirror::Array::LengthOffset().Uint32Value(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2285 | Register obj = locations->InAt(0).As<Register>(); |
| 2286 | Register out = locations->Out().As<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2287 | __ movl(out, Address(obj, offset)); |
| 2288 | } |
| 2289 | |
| 2290 | void LocationsBuilderX86::VisitBoundsCheck(HBoundsCheck* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2291 | LocationSummary* locations = |
| 2292 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2293 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2294 | locations->SetInAt(1, Location::RequiresRegister()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 2295 | if (instruction->HasUses()) { |
| 2296 | locations->SetOut(Location::SameAsFirstInput()); |
| 2297 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2298 | } |
| 2299 | |
| 2300 | void InstructionCodeGeneratorX86::VisitBoundsCheck(HBoundsCheck* instruction) { |
| 2301 | LocationSummary* locations = instruction->GetLocations(); |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 2302 | SlowPathCodeX86* slow_path = new (GetGraph()->GetArena()) BoundsCheckSlowPathX86( |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2303 | instruction, locations->InAt(0), locations->InAt(1)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2304 | codegen_->AddSlowPath(slow_path); |
| 2305 | |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2306 | Register index = locations->InAt(0).As<Register>(); |
| 2307 | Register length = locations->InAt(1).As<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2308 | |
| 2309 | __ cmpl(index, length); |
| 2310 | __ j(kAboveEqual, slow_path->GetEntryLabel()); |
| 2311 | } |
| 2312 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2313 | void LocationsBuilderX86::VisitTemporary(HTemporary* temp) { |
| 2314 | temp->SetLocations(nullptr); |
| 2315 | } |
| 2316 | |
| 2317 | void InstructionCodeGeneratorX86::VisitTemporary(HTemporary* temp) { |
| 2318 | // Nothing to do, this is driven by the code generator. |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 2319 | UNUSED(temp); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2320 | } |
| 2321 | |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 2322 | void LocationsBuilderX86::VisitParallelMove(HParallelMove* instruction) { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 2323 | UNUSED(instruction); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 2324 | LOG(FATAL) << "Unreachable"; |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 2325 | } |
| 2326 | |
| 2327 | void InstructionCodeGeneratorX86::VisitParallelMove(HParallelMove* instruction) { |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 2328 | codegen_->GetMoveResolver()->EmitNativeCode(instruction); |
| 2329 | } |
| 2330 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 2331 | void LocationsBuilderX86::VisitSuspendCheck(HSuspendCheck* instruction) { |
| 2332 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath); |
| 2333 | } |
| 2334 | |
| 2335 | void InstructionCodeGeneratorX86::VisitSuspendCheck(HSuspendCheck* instruction) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 2336 | HBasicBlock* block = instruction->GetBlock(); |
| 2337 | if (block->GetLoopInformation() != nullptr) { |
| 2338 | DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction); |
| 2339 | // The back edge will generate the suspend check. |
| 2340 | return; |
| 2341 | } |
| 2342 | if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) { |
| 2343 | // The goto will generate the suspend check. |
| 2344 | return; |
| 2345 | } |
| 2346 | GenerateSuspendCheck(instruction, nullptr); |
| 2347 | } |
| 2348 | |
| 2349 | void InstructionCodeGeneratorX86::GenerateSuspendCheck(HSuspendCheck* instruction, |
| 2350 | HBasicBlock* successor) { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 2351 | SuspendCheckSlowPathX86* slow_path = |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 2352 | new (GetGraph()->GetArena()) SuspendCheckSlowPathX86(instruction, successor); |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 2353 | codegen_->AddSlowPath(slow_path); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 2354 | __ fs()->cmpw(Address::Absolute( |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 2355 | Thread::ThreadFlagsOffset<kX86WordSize>().Int32Value()), Immediate(0)); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 2356 | if (successor == nullptr) { |
| 2357 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 2358 | __ Bind(slow_path->GetReturnLabel()); |
| 2359 | } else { |
| 2360 | __ j(kEqual, codegen_->GetLabelOf(successor)); |
| 2361 | __ jmp(slow_path->GetEntryLabel()); |
| 2362 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 2363 | } |
| 2364 | |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 2365 | X86Assembler* ParallelMoveResolverX86::GetAssembler() const { |
| 2366 | return codegen_->GetAssembler(); |
| 2367 | } |
| 2368 | |
| 2369 | void ParallelMoveResolverX86::MoveMemoryToMemory(int dst, int src) { |
| 2370 | ScratchRegisterScope ensure_scratch( |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 2371 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 2372 | int stack_offset = ensure_scratch.IsSpilled() ? kX86WordSize : 0; |
| 2373 | __ movl(static_cast<Register>(ensure_scratch.GetRegister()), Address(ESP, src + stack_offset)); |
| 2374 | __ movl(Address(ESP, dst + stack_offset), static_cast<Register>(ensure_scratch.GetRegister())); |
| 2375 | } |
| 2376 | |
| 2377 | void ParallelMoveResolverX86::EmitMove(size_t index) { |
| 2378 | MoveOperands* move = moves_.Get(index); |
| 2379 | Location source = move->GetSource(); |
| 2380 | Location destination = move->GetDestination(); |
| 2381 | |
| 2382 | if (source.IsRegister()) { |
| 2383 | if (destination.IsRegister()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2384 | __ movl(destination.As<Register>(), source.As<Register>()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 2385 | } else { |
| 2386 | DCHECK(destination.IsStackSlot()); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2387 | __ movl(Address(ESP, destination.GetStackIndex()), source.As<Register>()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 2388 | } |
| 2389 | } else if (source.IsStackSlot()) { |
| 2390 | if (destination.IsRegister()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2391 | __ movl(destination.As<Register>(), Address(ESP, source.GetStackIndex())); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 2392 | } else { |
| 2393 | DCHECK(destination.IsStackSlot()); |
| 2394 | MoveMemoryToMemory(destination.GetStackIndex(), |
| 2395 | source.GetStackIndex()); |
| 2396 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2397 | } else if (source.IsConstant()) { |
| 2398 | HIntConstant* instruction = source.GetConstant()->AsIntConstant(); |
| 2399 | Immediate imm(instruction->AsIntConstant()->GetValue()); |
| 2400 | if (destination.IsRegister()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2401 | __ movl(destination.As<Register>(), imm); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2402 | } else { |
| 2403 | __ movl(Address(ESP, destination.GetStackIndex()), imm); |
| 2404 | } |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 2405 | } else { |
| 2406 | LOG(FATAL) << "Unimplemented"; |
| 2407 | } |
| 2408 | } |
| 2409 | |
| 2410 | void ParallelMoveResolverX86::Exchange(Register reg, int mem) { |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 2411 | Register suggested_scratch = reg == EAX ? EBX : EAX; |
| 2412 | ScratchRegisterScope ensure_scratch( |
| 2413 | this, reg, suggested_scratch, codegen_->GetNumberOfCoreRegisters()); |
| 2414 | |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 2415 | int stack_offset = ensure_scratch.IsSpilled() ? kX86WordSize : 0; |
| 2416 | __ movl(static_cast<Register>(ensure_scratch.GetRegister()), Address(ESP, mem + stack_offset)); |
| 2417 | __ movl(Address(ESP, mem + stack_offset), reg); |
| 2418 | __ movl(reg, static_cast<Register>(ensure_scratch.GetRegister())); |
| 2419 | } |
| 2420 | |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 2421 | void ParallelMoveResolverX86::Exchange(int mem1, int mem2) { |
| 2422 | ScratchRegisterScope ensure_scratch1( |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 2423 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
| 2424 | |
| 2425 | Register suggested_scratch = ensure_scratch1.GetRegister() == EAX ? EBX : EAX; |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 2426 | ScratchRegisterScope ensure_scratch2( |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 2427 | this, ensure_scratch1.GetRegister(), suggested_scratch, codegen_->GetNumberOfCoreRegisters()); |
| 2428 | |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 2429 | int stack_offset = ensure_scratch1.IsSpilled() ? kX86WordSize : 0; |
| 2430 | stack_offset += ensure_scratch2.IsSpilled() ? kX86WordSize : 0; |
| 2431 | __ movl(static_cast<Register>(ensure_scratch1.GetRegister()), Address(ESP, mem1 + stack_offset)); |
| 2432 | __ movl(static_cast<Register>(ensure_scratch2.GetRegister()), Address(ESP, mem2 + stack_offset)); |
| 2433 | __ movl(Address(ESP, mem2 + stack_offset), static_cast<Register>(ensure_scratch1.GetRegister())); |
| 2434 | __ movl(Address(ESP, mem1 + stack_offset), static_cast<Register>(ensure_scratch2.GetRegister())); |
| 2435 | } |
| 2436 | |
| 2437 | void ParallelMoveResolverX86::EmitSwap(size_t index) { |
| 2438 | MoveOperands* move = moves_.Get(index); |
| 2439 | Location source = move->GetSource(); |
| 2440 | Location destination = move->GetDestination(); |
| 2441 | |
| 2442 | if (source.IsRegister() && destination.IsRegister()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2443 | __ xchgl(destination.As<Register>(), source.As<Register>()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 2444 | } else if (source.IsRegister() && destination.IsStackSlot()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2445 | Exchange(source.As<Register>(), destination.GetStackIndex()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 2446 | } else if (source.IsStackSlot() && destination.IsRegister()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2447 | Exchange(destination.As<Register>(), source.GetStackIndex()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 2448 | } else if (source.IsStackSlot() && destination.IsStackSlot()) { |
| 2449 | Exchange(destination.GetStackIndex(), source.GetStackIndex()); |
| 2450 | } else { |
| 2451 | LOG(FATAL) << "Unimplemented"; |
| 2452 | } |
| 2453 | } |
| 2454 | |
| 2455 | void ParallelMoveResolverX86::SpillScratch(int reg) { |
| 2456 | __ pushl(static_cast<Register>(reg)); |
| 2457 | } |
| 2458 | |
| 2459 | void ParallelMoveResolverX86::RestoreScratch(int reg) { |
| 2460 | __ popl(static_cast<Register>(reg)); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 2461 | } |
| 2462 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 2463 | void LocationsBuilderX86::VisitLoadClass(HLoadClass* cls) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 2464 | LocationSummary::CallKind call_kind = cls->CanCallRuntime() |
| 2465 | ? LocationSummary::kCallOnSlowPath |
| 2466 | : LocationSummary::kNoCall; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 2467 | LocationSummary* locations = |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 2468 | new (GetGraph()->GetArena()) LocationSummary(cls, call_kind); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 2469 | locations->SetOut(Location::RequiresRegister()); |
| 2470 | } |
| 2471 | |
| 2472 | void InstructionCodeGeneratorX86::VisitLoadClass(HLoadClass* cls) { |
| 2473 | Register out = cls->GetLocations()->Out().As<Register>(); |
| 2474 | if (cls->IsReferrersClass()) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 2475 | DCHECK(!cls->CanCallRuntime()); |
| 2476 | DCHECK(!cls->MustGenerateClinitCheck()); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 2477 | codegen_->LoadCurrentMethod(out); |
| 2478 | __ movl(out, Address(out, mirror::ArtMethod::DeclaringClassOffset().Int32Value())); |
| 2479 | } else { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 2480 | DCHECK(cls->CanCallRuntime()); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 2481 | codegen_->LoadCurrentMethod(out); |
| 2482 | __ movl(out, Address(out, mirror::ArtMethod::DexCacheResolvedTypesOffset().Int32Value())); |
| 2483 | __ movl(out, Address(out, CodeGenerator::GetCacheOffset(cls->GetTypeIndex()))); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 2484 | |
| 2485 | SlowPathCodeX86* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathX86( |
| 2486 | cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck()); |
| 2487 | codegen_->AddSlowPath(slow_path); |
| 2488 | __ testl(out, out); |
| 2489 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 2490 | if (cls->MustGenerateClinitCheck()) { |
| 2491 | GenerateClassInitializationCheck(slow_path, out); |
| 2492 | } else { |
| 2493 | __ Bind(slow_path->GetExitLabel()); |
| 2494 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 2495 | } |
| 2496 | } |
| 2497 | |
| 2498 | void LocationsBuilderX86::VisitClinitCheck(HClinitCheck* check) { |
| 2499 | LocationSummary* locations = |
| 2500 | new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath); |
| 2501 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2502 | if (check->HasUses()) { |
| 2503 | locations->SetOut(Location::SameAsFirstInput()); |
| 2504 | } |
| 2505 | } |
| 2506 | |
| 2507 | void InstructionCodeGeneratorX86::VisitClinitCheck(HClinitCheck* check) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 2508 | // We assume the class to not be null. |
| 2509 | SlowPathCodeX86* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathX86( |
| 2510 | check->GetLoadClass(), check, check->GetDexPc(), true); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 2511 | codegen_->AddSlowPath(slow_path); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 2512 | GenerateClassInitializationCheck(slow_path, check->GetLocations()->InAt(0).As<Register>()); |
| 2513 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 2514 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 2515 | void InstructionCodeGeneratorX86::GenerateClassInitializationCheck( |
| 2516 | SlowPathCodeX86* slow_path, Register class_reg) { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 2517 | __ cmpl(Address(class_reg, mirror::Class::StatusOffset().Int32Value()), |
| 2518 | Immediate(mirror::Class::kStatusInitialized)); |
| 2519 | __ j(kLess, slow_path->GetEntryLabel()); |
| 2520 | __ Bind(slow_path->GetExitLabel()); |
| 2521 | // No need for memory fence, thanks to the X86 memory model. |
| 2522 | } |
| 2523 | |
| 2524 | void LocationsBuilderX86::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 2525 | LocationSummary* locations = |
| 2526 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 2527 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2528 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2529 | } |
| 2530 | |
| 2531 | void InstructionCodeGeneratorX86::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 2532 | LocationSummary* locations = instruction->GetLocations(); |
| 2533 | Register cls = locations->InAt(0).As<Register>(); |
| 2534 | uint32_t offset = instruction->GetFieldOffset().Uint32Value(); |
| 2535 | |
| 2536 | switch (instruction->GetType()) { |
| 2537 | case Primitive::kPrimBoolean: { |
| 2538 | Register out = locations->Out().As<Register>(); |
| 2539 | __ movzxb(out, Address(cls, offset)); |
| 2540 | break; |
| 2541 | } |
| 2542 | |
| 2543 | case Primitive::kPrimByte: { |
| 2544 | Register out = locations->Out().As<Register>(); |
| 2545 | __ movsxb(out, Address(cls, offset)); |
| 2546 | break; |
| 2547 | } |
| 2548 | |
| 2549 | case Primitive::kPrimShort: { |
| 2550 | Register out = locations->Out().As<Register>(); |
| 2551 | __ movsxw(out, Address(cls, offset)); |
| 2552 | break; |
| 2553 | } |
| 2554 | |
| 2555 | case Primitive::kPrimChar: { |
| 2556 | Register out = locations->Out().As<Register>(); |
| 2557 | __ movzxw(out, Address(cls, offset)); |
| 2558 | break; |
| 2559 | } |
| 2560 | |
| 2561 | case Primitive::kPrimInt: |
| 2562 | case Primitive::kPrimNot: { |
| 2563 | Register out = locations->Out().As<Register>(); |
| 2564 | __ movl(out, Address(cls, offset)); |
| 2565 | break; |
| 2566 | } |
| 2567 | |
| 2568 | case Primitive::kPrimLong: { |
| 2569 | // TODO: support volatile. |
| 2570 | __ movl(locations->Out().AsRegisterPairLow<Register>(), Address(cls, offset)); |
| 2571 | __ movl(locations->Out().AsRegisterPairHigh<Register>(), Address(cls, kX86WordSize + offset)); |
| 2572 | break; |
| 2573 | } |
| 2574 | |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 2575 | case Primitive::kPrimFloat: { |
| 2576 | XmmRegister out = locations->Out().As<XmmRegister>(); |
| 2577 | __ movss(out, Address(cls, offset)); |
| 2578 | break; |
| 2579 | } |
| 2580 | |
| 2581 | case Primitive::kPrimDouble: { |
| 2582 | XmmRegister out = locations->Out().As<XmmRegister>(); |
| 2583 | __ movsd(out, Address(cls, offset)); |
| 2584 | break; |
| 2585 | } |
| 2586 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 2587 | case Primitive::kPrimVoid: |
| 2588 | LOG(FATAL) << "Unreachable type " << instruction->GetType(); |
| 2589 | UNREACHABLE(); |
| 2590 | } |
| 2591 | } |
| 2592 | |
| 2593 | void LocationsBuilderX86::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
| 2594 | LocationSummary* locations = |
| 2595 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 2596 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2597 | Primitive::Type field_type = instruction->GetFieldType(); |
| 2598 | bool is_object_type = field_type == Primitive::kPrimNot; |
| 2599 | bool is_byte_type = (field_type == Primitive::kPrimBoolean) |
| 2600 | || (field_type == Primitive::kPrimByte); |
| 2601 | // The register allocator does not support multiple |
| 2602 | // inputs that die at entry with one in a specific register. |
| 2603 | if (is_byte_type) { |
| 2604 | // Ensure the value is in a byte register. |
| 2605 | locations->SetInAt(1, Location::RegisterLocation(EAX)); |
| 2606 | } else { |
| 2607 | locations->SetInAt(1, Location::RequiresRegister()); |
| 2608 | } |
| 2609 | // Temporary registers for the write barrier. |
| 2610 | if (is_object_type) { |
| 2611 | locations->AddTemp(Location::RequiresRegister()); |
| 2612 | // Ensure the card is in a byte register. |
| 2613 | locations->AddTemp(Location::RegisterLocation(ECX)); |
| 2614 | } |
| 2615 | } |
| 2616 | |
| 2617 | void InstructionCodeGeneratorX86::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
| 2618 | LocationSummary* locations = instruction->GetLocations(); |
| 2619 | Register cls = locations->InAt(0).As<Register>(); |
| 2620 | uint32_t offset = instruction->GetFieldOffset().Uint32Value(); |
| 2621 | Primitive::Type field_type = instruction->GetFieldType(); |
| 2622 | |
| 2623 | switch (field_type) { |
| 2624 | case Primitive::kPrimBoolean: |
| 2625 | case Primitive::kPrimByte: { |
| 2626 | ByteRegister value = locations->InAt(1).As<ByteRegister>(); |
| 2627 | __ movb(Address(cls, offset), value); |
| 2628 | break; |
| 2629 | } |
| 2630 | |
| 2631 | case Primitive::kPrimShort: |
| 2632 | case Primitive::kPrimChar: { |
| 2633 | Register value = locations->InAt(1).As<Register>(); |
| 2634 | __ movw(Address(cls, offset), value); |
| 2635 | break; |
| 2636 | } |
| 2637 | |
| 2638 | case Primitive::kPrimInt: |
| 2639 | case Primitive::kPrimNot: { |
| 2640 | Register value = locations->InAt(1).As<Register>(); |
| 2641 | __ movl(Address(cls, offset), value); |
| 2642 | |
| 2643 | if (field_type == Primitive::kPrimNot) { |
| 2644 | Register temp = locations->GetTemp(0).As<Register>(); |
| 2645 | Register card = locations->GetTemp(1).As<Register>(); |
| 2646 | codegen_->MarkGCCard(temp, card, cls, value); |
| 2647 | } |
| 2648 | break; |
| 2649 | } |
| 2650 | |
| 2651 | case Primitive::kPrimLong: { |
| 2652 | Location value = locations->InAt(1); |
| 2653 | __ movl(Address(cls, offset), value.AsRegisterPairLow<Register>()); |
| 2654 | __ movl(Address(cls, kX86WordSize + offset), value.AsRegisterPairHigh<Register>()); |
| 2655 | break; |
| 2656 | } |
| 2657 | |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 2658 | case Primitive::kPrimFloat: { |
| 2659 | XmmRegister value = locations->InAt(1).As<XmmRegister>(); |
| 2660 | __ movss(Address(cls, offset), value); |
| 2661 | break; |
| 2662 | } |
| 2663 | |
| 2664 | case Primitive::kPrimDouble: { |
| 2665 | XmmRegister value = locations->InAt(1).As<XmmRegister>(); |
| 2666 | __ movsd(Address(cls, offset), value); |
| 2667 | break; |
| 2668 | } |
| 2669 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 2670 | case Primitive::kPrimVoid: |
| 2671 | LOG(FATAL) << "Unreachable type " << field_type; |
| 2672 | UNREACHABLE(); |
| 2673 | } |
| 2674 | } |
| 2675 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 2676 | void LocationsBuilderX86::VisitLoadString(HLoadString* load) { |
| 2677 | LocationSummary* locations = |
| 2678 | new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kCallOnSlowPath); |
| 2679 | locations->SetOut(Location::RequiresRegister()); |
| 2680 | } |
| 2681 | |
| 2682 | void InstructionCodeGeneratorX86::VisitLoadString(HLoadString* load) { |
| 2683 | SlowPathCodeX86* slow_path = new (GetGraph()->GetArena()) LoadStringSlowPathX86(load); |
| 2684 | codegen_->AddSlowPath(slow_path); |
| 2685 | |
| 2686 | Register out = load->GetLocations()->Out().As<Register>(); |
| 2687 | codegen_->LoadCurrentMethod(out); |
| 2688 | __ movl(out, Address(out, mirror::ArtMethod::DexCacheStringsOffset().Int32Value())); |
| 2689 | __ movl(out, Address(out, CodeGenerator::GetCacheOffset(load->GetStringIndex()))); |
| 2690 | __ testl(out, out); |
| 2691 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 2692 | __ Bind(slow_path->GetExitLabel()); |
| 2693 | } |
| 2694 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 2695 | void LocationsBuilderX86::VisitLoadException(HLoadException* load) { |
| 2696 | LocationSummary* locations = |
| 2697 | new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall); |
| 2698 | locations->SetOut(Location::RequiresRegister()); |
| 2699 | } |
| 2700 | |
| 2701 | void InstructionCodeGeneratorX86::VisitLoadException(HLoadException* load) { |
| 2702 | Address address = Address::Absolute(Thread::ExceptionOffset<kX86WordSize>().Int32Value()); |
| 2703 | __ fs()->movl(load->GetLocations()->Out().As<Register>(), address); |
| 2704 | __ fs()->movl(address, Immediate(0)); |
| 2705 | } |
| 2706 | |
| 2707 | void LocationsBuilderX86::VisitThrow(HThrow* instruction) { |
| 2708 | LocationSummary* locations = |
| 2709 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
| 2710 | InvokeRuntimeCallingConvention calling_convention; |
| 2711 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 2712 | } |
| 2713 | |
| 2714 | void InstructionCodeGeneratorX86::VisitThrow(HThrow* instruction) { |
| 2715 | __ fs()->call(Address::Absolute(QUICK_ENTRYPOINT_OFFSET(kX86WordSize, pDeliverException))); |
| 2716 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
| 2717 | } |
| 2718 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame^] | 2719 | void LocationsBuilderX86::VisitTypeCheck(HTypeCheck* instruction) { |
| 2720 | LocationSummary::CallKind call_kind = instruction->IsClassFinal() |
| 2721 | ? LocationSummary::kNoCall |
| 2722 | : LocationSummary::kCallOnSlowPath; |
| 2723 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
| 2724 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2725 | locations->SetInAt(1, Location::Any()); |
| 2726 | locations->SetOut(Location::RequiresRegister()); |
| 2727 | } |
| 2728 | |
| 2729 | void InstructionCodeGeneratorX86::VisitTypeCheck(HTypeCheck* instruction) { |
| 2730 | LocationSummary* locations = instruction->GetLocations(); |
| 2731 | Register obj = locations->InAt(0).As<Register>(); |
| 2732 | Location cls = locations->InAt(1); |
| 2733 | Register out = locations->Out().As<Register>(); |
| 2734 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 2735 | Label done, zero; |
| 2736 | SlowPathCodeX86* slow_path = nullptr; |
| 2737 | |
| 2738 | // Return 0 if `obj` is null. |
| 2739 | // TODO: avoid this check if we know obj is not null. |
| 2740 | __ testl(obj, obj); |
| 2741 | __ j(kEqual, &zero); |
| 2742 | __ movl(out, Address(obj, class_offset)); |
| 2743 | // Compare the class of `obj` with `cls`. |
| 2744 | if (cls.IsRegister()) { |
| 2745 | __ cmpl(out, cls.As<Register>()); |
| 2746 | } else { |
| 2747 | DCHECK(cls.IsStackSlot()) << cls; |
| 2748 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 2749 | } |
| 2750 | |
| 2751 | if (instruction->IsClassFinal()) { |
| 2752 | // Classes must be equal for the instanceof to succeed. |
| 2753 | __ j(kNotEqual, &zero); |
| 2754 | __ movl(out, Immediate(1)); |
| 2755 | __ jmp(&done); |
| 2756 | } else { |
| 2757 | // If the classes are not equal, we go into a slow path. |
| 2758 | DCHECK(locations->OnlyCallsOnSlowPath()); |
| 2759 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathX86( |
| 2760 | instruction, Location::RegisterLocation(out)); |
| 2761 | codegen_->AddSlowPath(slow_path); |
| 2762 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 2763 | __ movl(out, Immediate(1)); |
| 2764 | __ jmp(&done); |
| 2765 | } |
| 2766 | __ Bind(&zero); |
| 2767 | __ movl(out, Immediate(0)); |
| 2768 | if (slow_path != nullptr) { |
| 2769 | __ Bind(slow_path->GetExitLabel()); |
| 2770 | } |
| 2771 | __ Bind(&done); |
| 2772 | } |
| 2773 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 2774 | } // namespace x86 |
| 2775 | } // namespace art |