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