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