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