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