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