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" |
Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 21 | #include "mirror/array.h" |
| 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 | |
| 32 | x86::X86ManagedRegister Location::AsX86() const { |
| 33 | return reg().AsX86(); |
| 34 | } |
| 35 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 36 | namespace x86 { |
| 37 | |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 38 | static constexpr bool kExplicitStackOverflowCheck = false; |
| 39 | |
| 40 | static constexpr int kNumberOfPushedRegistersAtEntry = 1; |
| 41 | static constexpr int kCurrentMethodStackOffset = 0; |
| 42 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 43 | static Location X86CpuLocation(Register reg) { |
| 44 | return Location::RegisterLocation(X86ManagedRegister::FromCpuRegister(reg)); |
| 45 | } |
| 46 | |
| 47 | static constexpr Register kRuntimeParameterCoreRegisters[] = { EAX, ECX, EDX }; |
| 48 | static constexpr size_t kRuntimeParameterCoreRegistersLength = |
| 49 | arraysize(kRuntimeParameterCoreRegisters); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame^] | 50 | static constexpr XmmRegister kRuntimeParameterFpuRegisters[] = { }; |
| 51 | static constexpr size_t kRuntimeParameterFpuRegistersLength = 0; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 52 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame^] | 53 | class InvokeRuntimeCallingConvention : public CallingConvention<Register, XmmRegister> { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 54 | public: |
| 55 | InvokeRuntimeCallingConvention() |
| 56 | : CallingConvention(kRuntimeParameterCoreRegisters, |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame^] | 57 | kRuntimeParameterCoreRegistersLength, |
| 58 | kRuntimeParameterFpuRegisters, |
| 59 | kRuntimeParameterFpuRegistersLength) {} |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 60 | |
| 61 | private: |
| 62 | DISALLOW_COPY_AND_ASSIGN(InvokeRuntimeCallingConvention); |
| 63 | }; |
| 64 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 65 | #define __ reinterpret_cast<X86Assembler*>(codegen->GetAssembler())-> |
| 66 | |
| 67 | class NullCheckSlowPathX86 : public SlowPathCode { |
| 68 | public: |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 69 | explicit NullCheckSlowPathX86(HNullCheck* instruction) : instruction_(instruction) {} |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 70 | |
| 71 | virtual void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 72 | __ Bind(GetEntryLabel()); |
| 73 | __ fs()->call(Address::Absolute(QUICK_ENTRYPOINT_OFFSET(kX86WordSize, pThrowNullPointer))); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 74 | codegen->RecordPcInfo(instruction_, instruction_->GetDexPc()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 75 | } |
| 76 | |
| 77 | private: |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 78 | HNullCheck* const instruction_; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 79 | DISALLOW_COPY_AND_ASSIGN(NullCheckSlowPathX86); |
| 80 | }; |
| 81 | |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 82 | class StackOverflowCheckSlowPathX86 : public SlowPathCode { |
| 83 | public: |
| 84 | StackOverflowCheckSlowPathX86() {} |
| 85 | |
| 86 | virtual void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 87 | __ Bind(GetEntryLabel()); |
| 88 | __ addl(ESP, |
| 89 | Immediate(codegen->GetFrameSize() - kNumberOfPushedRegistersAtEntry * kX86WordSize)); |
| 90 | __ fs()->jmp(Address::Absolute(QUICK_ENTRYPOINT_OFFSET(kX86WordSize, pThrowStackOverflow))); |
| 91 | } |
| 92 | |
| 93 | private: |
| 94 | DISALLOW_COPY_AND_ASSIGN(StackOverflowCheckSlowPathX86); |
| 95 | }; |
| 96 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 97 | class BoundsCheckSlowPathX86 : public SlowPathCode { |
| 98 | public: |
Roland Levillain | 5799fc0 | 2014-09-25 12:15:20 +0100 | [diff] [blame] | 99 | BoundsCheckSlowPathX86(HBoundsCheck* instruction, |
| 100 | Location index_location, |
| 101 | Location length_location) |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 102 | : instruction_(instruction), index_location_(index_location), length_location_(length_location) {} |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 103 | |
| 104 | virtual void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 105 | CodeGeneratorX86* x86_codegen = reinterpret_cast<CodeGeneratorX86*>(codegen); |
| 106 | __ Bind(GetEntryLabel()); |
| 107 | InvokeRuntimeCallingConvention calling_convention; |
| 108 | x86_codegen->Move32(X86CpuLocation(calling_convention.GetRegisterAt(0)), index_location_); |
| 109 | x86_codegen->Move32(X86CpuLocation(calling_convention.GetRegisterAt(1)), length_location_); |
| 110 | __ fs()->call(Address::Absolute(QUICK_ENTRYPOINT_OFFSET(kX86WordSize, pThrowArrayBounds))); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 111 | codegen->RecordPcInfo(instruction_, instruction_->GetDexPc()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 112 | } |
| 113 | |
| 114 | private: |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 115 | HBoundsCheck* const instruction_; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 116 | const Location index_location_; |
| 117 | const Location length_location_; |
| 118 | |
| 119 | DISALLOW_COPY_AND_ASSIGN(BoundsCheckSlowPathX86); |
| 120 | }; |
| 121 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 122 | class SuspendCheckSlowPathX86 : public SlowPathCode { |
| 123 | public: |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 124 | explicit SuspendCheckSlowPathX86(HSuspendCheck* instruction, HBasicBlock* successor) |
| 125 | : instruction_(instruction), successor_(successor) {} |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 126 | |
| 127 | virtual void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 128 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 129 | codegen->SaveLiveRegisters(instruction_->GetLocations()); |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 130 | __ fs()->call(Address::Absolute(QUICK_ENTRYPOINT_OFFSET(kX86WordSize, pTestSuspend))); |
| 131 | codegen->RecordPcInfo(instruction_, instruction_->GetDexPc()); |
Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 132 | codegen->RestoreLiveRegisters(instruction_->GetLocations()); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 133 | if (successor_ == nullptr) { |
| 134 | __ jmp(GetReturnLabel()); |
| 135 | } else { |
| 136 | __ jmp(codegen->GetLabelOf(successor_)); |
| 137 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 138 | } |
| 139 | |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 140 | Label* GetReturnLabel() { |
| 141 | DCHECK(successor_ == nullptr); |
| 142 | return &return_label_; |
| 143 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 144 | |
| 145 | private: |
| 146 | HSuspendCheck* const instruction_; |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 147 | HBasicBlock* const successor_; |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 148 | Label return_label_; |
| 149 | |
| 150 | DISALLOW_COPY_AND_ASSIGN(SuspendCheckSlowPathX86); |
| 151 | }; |
| 152 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 153 | #undef __ |
| 154 | #define __ reinterpret_cast<X86Assembler*>(GetAssembler())-> |
| 155 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 156 | inline Condition X86Condition(IfCondition cond) { |
| 157 | switch (cond) { |
| 158 | case kCondEQ: return kEqual; |
| 159 | case kCondNE: return kNotEqual; |
| 160 | case kCondLT: return kLess; |
| 161 | case kCondLE: return kLessEqual; |
| 162 | case kCondGT: return kGreater; |
| 163 | case kCondGE: return kGreaterEqual; |
| 164 | default: |
| 165 | LOG(FATAL) << "Unknown if condition"; |
| 166 | } |
| 167 | return kEqual; |
| 168 | } |
| 169 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 170 | void CodeGeneratorX86::DumpCoreRegister(std::ostream& stream, int reg) const { |
| 171 | stream << X86ManagedRegister::FromCpuRegister(Register(reg)); |
| 172 | } |
| 173 | |
| 174 | void CodeGeneratorX86::DumpFloatingPointRegister(std::ostream& stream, int reg) const { |
| 175 | stream << X86ManagedRegister::FromXmmRegister(XmmRegister(reg)); |
| 176 | } |
| 177 | |
Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 178 | void CodeGeneratorX86::SaveCoreRegister(Location stack_location, uint32_t reg_id) { |
| 179 | __ movl(Address(ESP, stack_location.GetStackIndex()), static_cast<Register>(reg_id)); |
| 180 | } |
| 181 | |
| 182 | void CodeGeneratorX86::RestoreCoreRegister(Location stack_location, uint32_t reg_id) { |
| 183 | __ movl(static_cast<Register>(reg_id), Address(ESP, stack_location.GetStackIndex())); |
| 184 | } |
| 185 | |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 186 | CodeGeneratorX86::CodeGeneratorX86(HGraph* graph) |
| 187 | : CodeGenerator(graph, kNumberOfRegIds), |
| 188 | location_builder_(graph, this), |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 189 | instruction_visitor_(graph, this), |
| 190 | move_resolver_(graph->GetArena(), this) {} |
| 191 | |
Nicolas Geoffray | ab032bc | 2014-07-15 12:55:21 +0100 | [diff] [blame] | 192 | size_t CodeGeneratorX86::FrameEntrySpillSize() const { |
| 193 | return kNumberOfPushedRegistersAtEntry * kX86WordSize; |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 194 | } |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 195 | |
| 196 | static bool* GetBlockedRegisterPairs(bool* blocked_registers) { |
| 197 | return blocked_registers + kNumberOfAllocIds; |
| 198 | } |
| 199 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame^] | 200 | static bool* GetBlockedXmmRegisters(bool* blocked_registers) { |
| 201 | return blocked_registers + kNumberOfCpuRegisters; |
| 202 | } |
| 203 | |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 204 | ManagedRegister CodeGeneratorX86::AllocateFreeRegister(Primitive::Type type, |
| 205 | bool* blocked_registers) const { |
| 206 | switch (type) { |
| 207 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 208 | bool* blocked_register_pairs = GetBlockedRegisterPairs(blocked_registers); |
| 209 | size_t reg = AllocateFreeRegisterInternal(blocked_register_pairs, kNumberOfRegisterPairs); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 210 | X86ManagedRegister pair = |
| 211 | X86ManagedRegister::FromRegisterPair(static_cast<RegisterPair>(reg)); |
| 212 | blocked_registers[pair.AsRegisterPairLow()] = true; |
| 213 | blocked_registers[pair.AsRegisterPairHigh()] = true; |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 214 | // Block all other register pairs that share a register with `pair`. |
| 215 | for (int i = 0; i < kNumberOfRegisterPairs; i++) { |
| 216 | X86ManagedRegister current = |
| 217 | X86ManagedRegister::FromRegisterPair(static_cast<RegisterPair>(i)); |
| 218 | if (current.AsRegisterPairLow() == pair.AsRegisterPairLow() |
| 219 | || current.AsRegisterPairLow() == pair.AsRegisterPairHigh() |
| 220 | || current.AsRegisterPairHigh() == pair.AsRegisterPairLow() |
| 221 | || current.AsRegisterPairHigh() == pair.AsRegisterPairHigh()) { |
| 222 | blocked_register_pairs[i] = true; |
| 223 | } |
| 224 | } |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 225 | return pair; |
| 226 | } |
| 227 | |
| 228 | case Primitive::kPrimByte: |
| 229 | case Primitive::kPrimBoolean: |
| 230 | case Primitive::kPrimChar: |
| 231 | case Primitive::kPrimShort: |
| 232 | case Primitive::kPrimInt: |
| 233 | case Primitive::kPrimNot: { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 234 | Register reg = static_cast<Register>( |
| 235 | AllocateFreeRegisterInternal(blocked_registers, kNumberOfCpuRegisters)); |
| 236 | // Block all register pairs that contain `reg`. |
| 237 | bool* blocked_register_pairs = GetBlockedRegisterPairs(blocked_registers); |
| 238 | for (int i = 0; i < kNumberOfRegisterPairs; i++) { |
| 239 | X86ManagedRegister current = |
| 240 | X86ManagedRegister::FromRegisterPair(static_cast<RegisterPair>(i)); |
| 241 | if (current.AsRegisterPairLow() == reg || current.AsRegisterPairHigh() == reg) { |
| 242 | blocked_register_pairs[i] = true; |
| 243 | } |
| 244 | } |
| 245 | return X86ManagedRegister::FromCpuRegister(reg); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 246 | } |
| 247 | |
| 248 | case Primitive::kPrimFloat: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame^] | 249 | case Primitive::kPrimDouble: { |
| 250 | XmmRegister reg = static_cast<XmmRegister>(AllocateFreeRegisterInternal( |
| 251 | GetBlockedXmmRegisters(blocked_registers), kNumberOfXmmRegisters)); |
| 252 | return X86ManagedRegister::FromXmmRegister(reg); |
| 253 | } |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 254 | |
| 255 | case Primitive::kPrimVoid: |
| 256 | LOG(FATAL) << "Unreachable type " << type; |
| 257 | } |
| 258 | |
| 259 | return ManagedRegister::NoRegister(); |
| 260 | } |
| 261 | |
| 262 | void CodeGeneratorX86::SetupBlockedRegisters(bool* blocked_registers) const { |
| 263 | bool* blocked_register_pairs = GetBlockedRegisterPairs(blocked_registers); |
| 264 | |
| 265 | // Don't allocate the dalvik style register pair passing. |
| 266 | blocked_register_pairs[ECX_EDX] = true; |
| 267 | |
| 268 | // Stack register is always reserved. |
| 269 | blocked_registers[ESP] = true; |
| 270 | |
| 271 | // TODO: We currently don't use Quick's callee saved registers. |
| 272 | blocked_registers[EBP] = true; |
| 273 | blocked_registers[ESI] = true; |
| 274 | blocked_registers[EDI] = true; |
| 275 | blocked_register_pairs[EAX_EDI] = true; |
| 276 | blocked_register_pairs[EDX_EDI] = true; |
| 277 | blocked_register_pairs[ECX_EDI] = true; |
| 278 | blocked_register_pairs[EBX_EDI] = true; |
| 279 | } |
| 280 | |
| 281 | size_t CodeGeneratorX86::GetNumberOfRegisters() const { |
| 282 | return kNumberOfRegIds; |
| 283 | } |
| 284 | |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 285 | InstructionCodeGeneratorX86::InstructionCodeGeneratorX86(HGraph* graph, CodeGeneratorX86* codegen) |
| 286 | : HGraphVisitor(graph), |
| 287 | assembler_(codegen->GetAssembler()), |
| 288 | codegen_(codegen) {} |
| 289 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 290 | void CodeGeneratorX86::GenerateFrameEntry() { |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 291 | // Create a fake register to mimic Quick. |
| 292 | static const int kFakeReturnRegister = 8; |
| 293 | core_spill_mask_ |= (1 << kFakeReturnRegister); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 294 | |
Dave Allison | 648d711 | 2014-07-25 16:15:27 -0700 | [diff] [blame] | 295 | bool skip_overflow_check = IsLeafMethod() && !FrameNeedsStackCheck(GetFrameSize(), InstructionSet::kX86); |
Nicolas Geoffray | 397f2e4 | 2014-07-23 12:57:19 +0100 | [diff] [blame] | 296 | if (!skip_overflow_check && !kExplicitStackOverflowCheck) { |
| 297 | __ testl(EAX, Address(ESP, -static_cast<int32_t>(GetStackOverflowReservedBytes(kX86)))); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 298 | RecordPcInfo(nullptr, 0); |
Nicolas Geoffray | 397f2e4 | 2014-07-23 12:57:19 +0100 | [diff] [blame] | 299 | } |
| 300 | |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 301 | // The return PC has already been pushed on the stack. |
Nicolas Geoffray | 707c809 | 2014-04-04 10:50:14 +0100 | [diff] [blame] | 302 | __ subl(ESP, Immediate(GetFrameSize() - kNumberOfPushedRegistersAtEntry * kX86WordSize)); |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 303 | |
Nicolas Geoffray | 397f2e4 | 2014-07-23 12:57:19 +0100 | [diff] [blame] | 304 | if (!skip_overflow_check && kExplicitStackOverflowCheck) { |
| 305 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) StackOverflowCheckSlowPathX86(); |
| 306 | AddSlowPath(slow_path); |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 307 | |
Nicolas Geoffray | 397f2e4 | 2014-07-23 12:57:19 +0100 | [diff] [blame] | 308 | __ fs()->cmpl(ESP, Address::Absolute(Thread::StackEndOffset<kX86WordSize>())); |
| 309 | __ j(kLess, slow_path->GetEntryLabel()); |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 310 | } |
| 311 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 312 | __ movl(Address(ESP, kCurrentMethodStackOffset), EAX); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 313 | } |
| 314 | |
| 315 | void CodeGeneratorX86::GenerateFrameExit() { |
Nicolas Geoffray | 707c809 | 2014-04-04 10:50:14 +0100 | [diff] [blame] | 316 | __ addl(ESP, Immediate(GetFrameSize() - kNumberOfPushedRegistersAtEntry * kX86WordSize)); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 317 | } |
| 318 | |
| 319 | void CodeGeneratorX86::Bind(Label* label) { |
| 320 | __ Bind(label); |
| 321 | } |
| 322 | |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 323 | void InstructionCodeGeneratorX86::LoadCurrentMethod(Register reg) { |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 324 | __ movl(reg, Address(ESP, kCurrentMethodStackOffset)); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 325 | } |
| 326 | |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 327 | Location CodeGeneratorX86::GetStackLocation(HLoadLocal* load) const { |
| 328 | switch (load->GetType()) { |
| 329 | case Primitive::kPrimLong: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame^] | 330 | case Primitive::kPrimDouble: |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 331 | return Location::DoubleStackSlot(GetStackSlot(load->GetLocal())); |
| 332 | break; |
| 333 | |
| 334 | case Primitive::kPrimInt: |
| 335 | case Primitive::kPrimNot: |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 336 | case Primitive::kPrimFloat: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame^] | 337 | return Location::StackSlot(GetStackSlot(load->GetLocal())); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 338 | |
| 339 | case Primitive::kPrimBoolean: |
| 340 | case Primitive::kPrimByte: |
| 341 | case Primitive::kPrimChar: |
| 342 | case Primitive::kPrimShort: |
| 343 | case Primitive::kPrimVoid: |
| 344 | LOG(FATAL) << "Unexpected type " << load->GetType(); |
| 345 | } |
| 346 | |
| 347 | LOG(FATAL) << "Unreachable"; |
| 348 | return Location(); |
| 349 | } |
| 350 | |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 351 | Location InvokeDexCallingConventionVisitor::GetNextLocation(Primitive::Type type) { |
| 352 | switch (type) { |
| 353 | case Primitive::kPrimBoolean: |
| 354 | case Primitive::kPrimByte: |
| 355 | case Primitive::kPrimChar: |
| 356 | case Primitive::kPrimShort: |
| 357 | case Primitive::kPrimInt: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame^] | 358 | case Primitive::kPrimFloat: |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 359 | case Primitive::kPrimNot: { |
| 360 | uint32_t index = gp_index_++; |
| 361 | if (index < calling_convention.GetNumberOfRegisters()) { |
| 362 | return X86CpuLocation(calling_convention.GetRegisterAt(index)); |
| 363 | } else { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 364 | return Location::StackSlot(calling_convention.GetStackOffsetOf(index)); |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 365 | } |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 366 | } |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 367 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame^] | 368 | case Primitive::kPrimLong: |
| 369 | case Primitive::kPrimDouble: { |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 370 | uint32_t index = gp_index_; |
| 371 | gp_index_ += 2; |
| 372 | if (index + 1 < calling_convention.GetNumberOfRegisters()) { |
| 373 | return Location::RegisterLocation(X86ManagedRegister::FromRegisterPair( |
| 374 | calling_convention.GetRegisterPairAt(index))); |
| 375 | } else if (index + 1 == calling_convention.GetNumberOfRegisters()) { |
| 376 | return Location::QuickParameter(index); |
| 377 | } else { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 378 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(index)); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 379 | } |
| 380 | } |
| 381 | |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 382 | case Primitive::kPrimVoid: |
| 383 | LOG(FATAL) << "Unexpected parameter type " << type; |
| 384 | break; |
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 | return Location(); |
| 387 | } |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 388 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 389 | void CodeGeneratorX86::Move32(Location destination, Location source) { |
| 390 | if (source.Equals(destination)) { |
| 391 | return; |
| 392 | } |
| 393 | if (destination.IsRegister()) { |
| 394 | if (source.IsRegister()) { |
| 395 | __ movl(destination.AsX86().AsCpuRegister(), source.AsX86().AsCpuRegister()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame^] | 396 | } else if (source.IsFpuRegister()) { |
| 397 | __ movd(destination.AsX86().AsCpuRegister(), source.AsX86().AsXmmRegister()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 398 | } else { |
| 399 | DCHECK(source.IsStackSlot()); |
| 400 | __ movl(destination.AsX86().AsCpuRegister(), Address(ESP, source.GetStackIndex())); |
| 401 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame^] | 402 | } else if (destination.IsFpuRegister()) { |
| 403 | if (source.IsRegister()) { |
| 404 | __ movd(destination.AsX86().AsXmmRegister(), source.AsX86().AsCpuRegister()); |
| 405 | } else if (source.IsFpuRegister()) { |
| 406 | __ movaps(destination.AsX86().AsXmmRegister(), source.AsX86().AsXmmRegister()); |
| 407 | } else { |
| 408 | DCHECK(source.IsStackSlot()); |
| 409 | __ movss(destination.AsX86().AsXmmRegister(), Address(ESP, source.GetStackIndex())); |
| 410 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 411 | } else { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame^] | 412 | DCHECK(destination.IsStackSlot()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 413 | if (source.IsRegister()) { |
| 414 | __ movl(Address(ESP, destination.GetStackIndex()), source.AsX86().AsCpuRegister()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame^] | 415 | } else if (source.IsFpuRegister()) { |
| 416 | __ movss(Address(ESP, destination.GetStackIndex()), source.AsX86().AsXmmRegister()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 417 | } else { |
| 418 | DCHECK(source.IsStackSlot()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 419 | __ pushl(Address(ESP, source.GetStackIndex())); |
| 420 | __ popl(Address(ESP, destination.GetStackIndex())); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 421 | } |
| 422 | } |
| 423 | } |
| 424 | |
| 425 | void CodeGeneratorX86::Move64(Location destination, Location source) { |
| 426 | if (source.Equals(destination)) { |
| 427 | return; |
| 428 | } |
| 429 | if (destination.IsRegister()) { |
| 430 | if (source.IsRegister()) { |
| 431 | __ movl(destination.AsX86().AsRegisterPairLow(), source.AsX86().AsRegisterPairLow()); |
| 432 | __ movl(destination.AsX86().AsRegisterPairHigh(), source.AsX86().AsRegisterPairHigh()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame^] | 433 | } else if (source.IsFpuRegister()) { |
| 434 | LOG(FATAL) << "Unimplemented"; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 435 | } else if (source.IsQuickParameter()) { |
| 436 | uint32_t argument_index = source.GetQuickParameterIndex(); |
| 437 | InvokeDexCallingConvention calling_convention; |
| 438 | __ movl(destination.AsX86().AsRegisterPairLow(), |
| 439 | calling_convention.GetRegisterAt(argument_index)); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 440 | __ movl(destination.AsX86().AsRegisterPairHigh(), Address(ESP, |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 441 | calling_convention.GetStackOffsetOf(argument_index + 1) + GetFrameSize())); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 442 | } else { |
| 443 | DCHECK(source.IsDoubleStackSlot()); |
| 444 | __ movl(destination.AsX86().AsRegisterPairLow(), Address(ESP, source.GetStackIndex())); |
| 445 | __ movl(destination.AsX86().AsRegisterPairHigh(), |
| 446 | Address(ESP, source.GetHighStackIndex(kX86WordSize))); |
| 447 | } |
| 448 | } else if (destination.IsQuickParameter()) { |
| 449 | InvokeDexCallingConvention calling_convention; |
| 450 | uint32_t argument_index = destination.GetQuickParameterIndex(); |
| 451 | if (source.IsRegister()) { |
| 452 | __ movl(calling_convention.GetRegisterAt(argument_index), source.AsX86().AsRegisterPairLow()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 453 | __ movl(Address(ESP, calling_convention.GetStackOffsetOf(argument_index + 1)), |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 454 | source.AsX86().AsRegisterPairHigh()); |
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 { |
| 458 | DCHECK(source.IsDoubleStackSlot()); |
| 459 | __ movl(calling_convention.GetRegisterAt(argument_index), |
| 460 | Address(ESP, source.GetStackIndex())); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 461 | __ pushl(Address(ESP, source.GetHighStackIndex(kX86WordSize))); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 462 | __ popl(Address(ESP, calling_convention.GetStackOffsetOf(argument_index + 1))); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 463 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame^] | 464 | } else if (destination.IsFpuRegister()) { |
| 465 | if (source.IsDoubleStackSlot()) { |
| 466 | __ movsd(destination.AsX86().AsXmmRegister(), Address(ESP, source.GetStackIndex())); |
| 467 | } else { |
| 468 | LOG(FATAL) << "Unimplemented"; |
| 469 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 470 | } else { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 471 | DCHECK(destination.IsDoubleStackSlot()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 472 | if (source.IsRegister()) { |
| 473 | __ movl(Address(ESP, destination.GetStackIndex()), source.AsX86().AsRegisterPairLow()); |
| 474 | __ movl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)), |
| 475 | source.AsX86().AsRegisterPairHigh()); |
| 476 | } else if (source.IsQuickParameter()) { |
| 477 | InvokeDexCallingConvention calling_convention; |
| 478 | uint32_t argument_index = source.GetQuickParameterIndex(); |
| 479 | __ movl(Address(ESP, destination.GetStackIndex()), |
| 480 | calling_convention.GetRegisterAt(argument_index)); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame^] | 481 | DCHECK_EQ(calling_convention.GetStackOffsetOf(argument_index + 1) + GetFrameSize(), |
| 482 | static_cast<size_t>(destination.GetHighStackIndex(kX86WordSize))); |
| 483 | } else if (source.IsFpuRegister()) { |
| 484 | __ movsd(Address(ESP, destination.GetStackIndex()), source.AsX86().AsXmmRegister()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 485 | } else { |
| 486 | DCHECK(source.IsDoubleStackSlot()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 487 | __ pushl(Address(ESP, source.GetStackIndex())); |
| 488 | __ popl(Address(ESP, destination.GetStackIndex())); |
| 489 | __ pushl(Address(ESP, source.GetHighStackIndex(kX86WordSize))); |
| 490 | __ popl(Address(ESP, destination.GetHighStackIndex(kX86WordSize))); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 491 | } |
| 492 | } |
| 493 | } |
| 494 | |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 495 | void CodeGeneratorX86::Move(HInstruction* instruction, Location location, HInstruction* move_for) { |
| 496 | if (instruction->AsIntConstant() != nullptr) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 497 | Immediate imm(instruction->AsIntConstant()->GetValue()); |
| 498 | if (location.IsRegister()) { |
| 499 | __ movl(location.AsX86().AsCpuRegister(), imm); |
| 500 | } else { |
| 501 | __ movl(Address(ESP, location.GetStackIndex()), imm); |
| 502 | } |
| 503 | } else if (instruction->AsLongConstant() != nullptr) { |
| 504 | int64_t value = instruction->AsLongConstant()->GetValue(); |
| 505 | if (location.IsRegister()) { |
| 506 | __ movl(location.AsX86().AsRegisterPairLow(), Immediate(Low32Bits(value))); |
| 507 | __ movl(location.AsX86().AsRegisterPairHigh(), Immediate(High32Bits(value))); |
| 508 | } else { |
| 509 | __ movl(Address(ESP, location.GetStackIndex()), Immediate(Low32Bits(value))); |
| 510 | __ movl(Address(ESP, location.GetHighStackIndex(kX86WordSize)), Immediate(High32Bits(value))); |
| 511 | } |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 512 | } else if (instruction->AsLoadLocal() != nullptr) { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame^] | 513 | int slot = GetStackSlot(instruction->AsLoadLocal()->GetLocal()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 514 | switch (instruction->GetType()) { |
| 515 | case Primitive::kPrimBoolean: |
| 516 | case Primitive::kPrimByte: |
| 517 | case Primitive::kPrimChar: |
| 518 | case Primitive::kPrimShort: |
| 519 | case Primitive::kPrimInt: |
| 520 | case Primitive::kPrimNot: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame^] | 521 | case Primitive::kPrimFloat: |
| 522 | Move32(location, Location::StackSlot(slot)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 523 | break; |
| 524 | |
| 525 | case Primitive::kPrimLong: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame^] | 526 | case Primitive::kPrimDouble: |
| 527 | Move64(location, Location::DoubleStackSlot(slot)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 528 | break; |
| 529 | |
| 530 | default: |
| 531 | LOG(FATAL) << "Unimplemented local type " << instruction->GetType(); |
| 532 | } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 533 | } else { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 534 | DCHECK((instruction->GetNext() == move_for) || instruction->GetNext()->IsTemporary()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 535 | switch (instruction->GetType()) { |
| 536 | case Primitive::kPrimBoolean: |
| 537 | case Primitive::kPrimByte: |
| 538 | case Primitive::kPrimChar: |
| 539 | case Primitive::kPrimShort: |
| 540 | case Primitive::kPrimInt: |
| 541 | case Primitive::kPrimNot: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame^] | 542 | case Primitive::kPrimFloat: |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 543 | Move32(location, instruction->GetLocations()->Out()); |
| 544 | break; |
| 545 | |
| 546 | case Primitive::kPrimLong: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame^] | 547 | case Primitive::kPrimDouble: |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 548 | Move64(location, instruction->GetLocations()->Out()); |
| 549 | break; |
| 550 | |
| 551 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame^] | 552 | LOG(FATAL) << "Unexpected type " << instruction->GetType(); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 553 | } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 554 | } |
| 555 | } |
| 556 | |
| 557 | void LocationsBuilderX86::VisitGoto(HGoto* got) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 558 | got->SetLocations(nullptr); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 559 | } |
| 560 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 561 | void InstructionCodeGeneratorX86::VisitGoto(HGoto* got) { |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 562 | HBasicBlock* successor = got->GetSuccessor(); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 563 | DCHECK(!successor->IsExitBlock()); |
| 564 | |
| 565 | HBasicBlock* block = got->GetBlock(); |
| 566 | HInstruction* previous = got->GetPrevious(); |
| 567 | |
| 568 | HLoopInformation* info = block->GetLoopInformation(); |
| 569 | if (info != nullptr && info->IsBackEdge(block) && info->HasSuspendCheck()) { |
| 570 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(info->GetSuspendCheck()); |
| 571 | GenerateSuspendCheck(info->GetSuspendCheck(), successor); |
| 572 | return; |
| 573 | } |
| 574 | |
| 575 | if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) { |
| 576 | GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr); |
| 577 | } |
| 578 | if (!codegen_->GoesToNextBlock(got->GetBlock(), successor)) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 579 | __ jmp(codegen_->GetLabelOf(successor)); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 580 | } |
| 581 | } |
| 582 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 583 | void LocationsBuilderX86::VisitExit(HExit* exit) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 584 | exit->SetLocations(nullptr); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 585 | } |
| 586 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 587 | void InstructionCodeGeneratorX86::VisitExit(HExit* exit) { |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 588 | if (kIsDebugBuild) { |
| 589 | __ Comment("Unreachable"); |
| 590 | __ int3(); |
| 591 | } |
| 592 | } |
| 593 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 594 | void LocationsBuilderX86::VisitIf(HIf* if_instr) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 595 | LocationSummary* locations = |
| 596 | new (GetGraph()->GetArena()) LocationSummary(if_instr, LocationSummary::kNoCall); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 597 | HInstruction* cond = if_instr->InputAt(0); |
| 598 | DCHECK(cond->IsCondition()); |
| 599 | HCondition* condition = cond->AsCondition(); |
| 600 | if (condition->NeedsMaterialization()) { |
Nicolas Geoffray | 9ae0daa | 2014-09-30 22:40:23 +0100 | [diff] [blame] | 601 | locations->SetInAt(0, Location::Any(), Location::kDiesAtEntry); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 602 | } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 603 | } |
| 604 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 605 | void InstructionCodeGeneratorX86::VisitIf(HIf* if_instr) { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 606 | HInstruction* cond = if_instr->InputAt(0); |
| 607 | DCHECK(cond->IsCondition()); |
| 608 | HCondition* condition = cond->AsCondition(); |
| 609 | if (condition->NeedsMaterialization()) { |
Nicolas Geoffray | 18efde5 | 2014-09-22 15:51:11 +0100 | [diff] [blame] | 610 | // Moves do not affect the eflags register, so if the condition is evaluated |
| 611 | // just before the if, we don't need to evaluate it again. |
| 612 | if (!condition->IsBeforeWhenDisregardMoves(if_instr)) { |
| 613 | // Materialized condition, compare against 0 |
| 614 | Location lhs = if_instr->GetLocations()->InAt(0); |
| 615 | if (lhs.IsRegister()) { |
| 616 | __ cmpl(lhs.AsX86().AsCpuRegister(), Immediate(0)); |
| 617 | } else { |
| 618 | __ cmpl(Address(ESP, lhs.GetStackIndex()), Immediate(0)); |
| 619 | } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 620 | } |
Nicolas Geoffray | 18efde5 | 2014-09-22 15:51:11 +0100 | [diff] [blame] | 621 | __ j(kNotEqual, codegen_->GetLabelOf(if_instr->IfTrueSuccessor())); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 622 | } else { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 623 | Location lhs = condition->GetLocations()->InAt(0); |
| 624 | Location rhs = condition->GetLocations()->InAt(1); |
| 625 | // LHS is guaranteed to be in a register (see LocationsBuilderX86::VisitCondition). |
| 626 | if (rhs.IsRegister()) { |
| 627 | __ cmpl(lhs.AsX86().AsCpuRegister(), rhs.AsX86().AsCpuRegister()); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 628 | } else if (rhs.IsConstant()) { |
| 629 | HIntConstant* instruction = rhs.GetConstant()->AsIntConstant(); |
| 630 | Immediate imm(instruction->AsIntConstant()->GetValue()); |
| 631 | __ cmpl(lhs.AsX86().AsCpuRegister(), imm); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 632 | } else { |
| 633 | __ cmpl(lhs.AsX86().AsCpuRegister(), Address(ESP, rhs.GetStackIndex())); |
| 634 | } |
| 635 | __ j(X86Condition(condition->GetCondition()), |
| 636 | codegen_->GetLabelOf(if_instr->IfTrueSuccessor())); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 637 | } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 638 | if (!codegen_->GoesToNextBlock(if_instr->GetBlock(), if_instr->IfFalseSuccessor())) { |
| 639 | __ jmp(codegen_->GetLabelOf(if_instr->IfFalseSuccessor())); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 640 | } |
| 641 | } |
| 642 | |
| 643 | void LocationsBuilderX86::VisitLocal(HLocal* local) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 644 | local->SetLocations(nullptr); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 645 | } |
| 646 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 647 | void InstructionCodeGeneratorX86::VisitLocal(HLocal* local) { |
| 648 | DCHECK_EQ(local->GetBlock(), GetGraph()->GetEntryBlock()); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 649 | } |
| 650 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 651 | void LocationsBuilderX86::VisitLoadLocal(HLoadLocal* local) { |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 652 | local->SetLocations(nullptr); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 653 | } |
| 654 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 655 | void InstructionCodeGeneratorX86::VisitLoadLocal(HLoadLocal* load) { |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 656 | // Nothing to do, this is driven by the code generator. |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 657 | } |
| 658 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 659 | void LocationsBuilderX86::VisitStoreLocal(HStoreLocal* store) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 660 | LocationSummary* locations = |
| 661 | new (GetGraph()->GetArena()) LocationSummary(store, LocationSummary::kNoCall); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 662 | switch (store->InputAt(1)->GetType()) { |
| 663 | case Primitive::kPrimBoolean: |
| 664 | case Primitive::kPrimByte: |
| 665 | case Primitive::kPrimChar: |
| 666 | case Primitive::kPrimShort: |
| 667 | case Primitive::kPrimInt: |
| 668 | case Primitive::kPrimNot: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame^] | 669 | case Primitive::kPrimFloat: |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 670 | locations->SetInAt(1, Location::StackSlot(codegen_->GetStackSlot(store->GetLocal()))); |
| 671 | break; |
| 672 | |
| 673 | case Primitive::kPrimLong: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame^] | 674 | case Primitive::kPrimDouble: |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 675 | locations->SetInAt(1, Location::DoubleStackSlot(codegen_->GetStackSlot(store->GetLocal()))); |
| 676 | break; |
| 677 | |
| 678 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame^] | 679 | LOG(FATAL) << "Unknown local type " << store->InputAt(1)->GetType(); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 680 | } |
| 681 | store->SetLocations(locations); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 682 | } |
| 683 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 684 | void InstructionCodeGeneratorX86::VisitStoreLocal(HStoreLocal* store) { |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 685 | } |
| 686 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 687 | void LocationsBuilderX86::VisitCondition(HCondition* comp) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 688 | LocationSummary* locations = |
| 689 | new (GetGraph()->GetArena()) LocationSummary(comp, LocationSummary::kNoCall); |
Nicolas Geoffray | 9ae0daa | 2014-09-30 22:40:23 +0100 | [diff] [blame] | 690 | locations->SetInAt(0, Location::RequiresRegister(), Location::kDiesAtEntry); |
| 691 | locations->SetInAt(1, Location::Any(), Location::kDiesAtEntry); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 692 | if (comp->NeedsMaterialization()) { |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 693 | locations->SetOut(Location::RequiresRegister()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 694 | } |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 695 | } |
| 696 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 697 | void InstructionCodeGeneratorX86::VisitCondition(HCondition* comp) { |
| 698 | if (comp->NeedsMaterialization()) { |
| 699 | LocationSummary* locations = comp->GetLocations(); |
Nicolas Geoffray | 18efde5 | 2014-09-22 15:51:11 +0100 | [diff] [blame] | 700 | Register reg = locations->Out().AsX86().AsCpuRegister(); |
| 701 | // Clear register: setcc only sets the low byte. |
| 702 | __ xorl(reg, reg); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 703 | if (locations->InAt(1).IsRegister()) { |
| 704 | __ cmpl(locations->InAt(0).AsX86().AsCpuRegister(), |
| 705 | locations->InAt(1).AsX86().AsCpuRegister()); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 706 | } else if (locations->InAt(1).IsConstant()) { |
| 707 | HConstant* instruction = locations->InAt(1).GetConstant(); |
| 708 | Immediate imm(instruction->AsIntConstant()->GetValue()); |
| 709 | __ cmpl(locations->InAt(0).AsX86().AsCpuRegister(), imm); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 710 | } else { |
| 711 | __ cmpl(locations->InAt(0).AsX86().AsCpuRegister(), |
| 712 | Address(ESP, locations->InAt(1).GetStackIndex())); |
| 713 | } |
Nicolas Geoffray | 18efde5 | 2014-09-22 15:51:11 +0100 | [diff] [blame] | 714 | __ setb(X86Condition(comp->GetCondition()), reg); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 715 | } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 716 | } |
| 717 | |
| 718 | void LocationsBuilderX86::VisitEqual(HEqual* comp) { |
| 719 | VisitCondition(comp); |
| 720 | } |
| 721 | |
| 722 | void InstructionCodeGeneratorX86::VisitEqual(HEqual* comp) { |
| 723 | VisitCondition(comp); |
| 724 | } |
| 725 | |
| 726 | void LocationsBuilderX86::VisitNotEqual(HNotEqual* comp) { |
| 727 | VisitCondition(comp); |
| 728 | } |
| 729 | |
| 730 | void InstructionCodeGeneratorX86::VisitNotEqual(HNotEqual* comp) { |
| 731 | VisitCondition(comp); |
| 732 | } |
| 733 | |
| 734 | void LocationsBuilderX86::VisitLessThan(HLessThan* comp) { |
| 735 | VisitCondition(comp); |
| 736 | } |
| 737 | |
| 738 | void InstructionCodeGeneratorX86::VisitLessThan(HLessThan* comp) { |
| 739 | VisitCondition(comp); |
| 740 | } |
| 741 | |
| 742 | void LocationsBuilderX86::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
| 743 | VisitCondition(comp); |
| 744 | } |
| 745 | |
| 746 | void InstructionCodeGeneratorX86::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
| 747 | VisitCondition(comp); |
| 748 | } |
| 749 | |
| 750 | void LocationsBuilderX86::VisitGreaterThan(HGreaterThan* comp) { |
| 751 | VisitCondition(comp); |
| 752 | } |
| 753 | |
| 754 | void InstructionCodeGeneratorX86::VisitGreaterThan(HGreaterThan* comp) { |
| 755 | VisitCondition(comp); |
| 756 | } |
| 757 | |
| 758 | void LocationsBuilderX86::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
| 759 | VisitCondition(comp); |
| 760 | } |
| 761 | |
| 762 | void InstructionCodeGeneratorX86::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
| 763 | VisitCondition(comp); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 764 | } |
| 765 | |
| 766 | void LocationsBuilderX86::VisitIntConstant(HIntConstant* constant) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 767 | LocationSummary* locations = |
| 768 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 769 | locations->SetOut(Location::ConstantLocation(constant)); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 770 | } |
| 771 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 772 | void InstructionCodeGeneratorX86::VisitIntConstant(HIntConstant* constant) { |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 773 | } |
| 774 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 775 | void LocationsBuilderX86::VisitLongConstant(HLongConstant* constant) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 776 | LocationSummary* locations = |
| 777 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 778 | locations->SetOut(Location::ConstantLocation(constant)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 779 | } |
| 780 | |
| 781 | void InstructionCodeGeneratorX86::VisitLongConstant(HLongConstant* constant) { |
| 782 | // Will be generated at use site. |
| 783 | } |
| 784 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 785 | void LocationsBuilderX86::VisitReturnVoid(HReturnVoid* ret) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 786 | ret->SetLocations(nullptr); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 787 | } |
| 788 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 789 | void InstructionCodeGeneratorX86::VisitReturnVoid(HReturnVoid* ret) { |
| 790 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 791 | __ ret(); |
| 792 | } |
| 793 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 794 | void LocationsBuilderX86::VisitReturn(HReturn* ret) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 795 | LocationSummary* locations = |
| 796 | new (GetGraph()->GetArena()) LocationSummary(ret, LocationSummary::kNoCall); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 797 | switch (ret->InputAt(0)->GetType()) { |
| 798 | case Primitive::kPrimBoolean: |
| 799 | case Primitive::kPrimByte: |
| 800 | case Primitive::kPrimChar: |
| 801 | case Primitive::kPrimShort: |
| 802 | case Primitive::kPrimInt: |
| 803 | case Primitive::kPrimNot: |
| 804 | locations->SetInAt(0, X86CpuLocation(EAX)); |
| 805 | break; |
| 806 | |
| 807 | case Primitive::kPrimLong: |
| 808 | locations->SetInAt( |
| 809 | 0, Location::RegisterLocation(X86ManagedRegister::FromRegisterPair(EAX_EDX))); |
| 810 | break; |
| 811 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame^] | 812 | case Primitive::kPrimFloat: |
| 813 | case Primitive::kPrimDouble: |
| 814 | locations->SetInAt( |
| 815 | 0, Location::FpuRegisterLocation(X86ManagedRegister::FromXmmRegister(XMM0))); |
| 816 | break; |
| 817 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 818 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame^] | 819 | LOG(FATAL) << "Unknown return type " << ret->InputAt(0)->GetType(); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 820 | } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 821 | } |
| 822 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 823 | void InstructionCodeGeneratorX86::VisitReturn(HReturn* ret) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 824 | if (kIsDebugBuild) { |
| 825 | switch (ret->InputAt(0)->GetType()) { |
| 826 | case Primitive::kPrimBoolean: |
| 827 | case Primitive::kPrimByte: |
| 828 | case Primitive::kPrimChar: |
| 829 | case Primitive::kPrimShort: |
| 830 | case Primitive::kPrimInt: |
| 831 | case Primitive::kPrimNot: |
| 832 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsX86().AsCpuRegister(), EAX); |
| 833 | break; |
| 834 | |
| 835 | case Primitive::kPrimLong: |
| 836 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsX86().AsRegisterPair(), EAX_EDX); |
| 837 | break; |
| 838 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame^] | 839 | case Primitive::kPrimFloat: |
| 840 | case Primitive::kPrimDouble: |
| 841 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsX86().AsXmmRegister(), XMM0); |
| 842 | break; |
| 843 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 844 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame^] | 845 | LOG(FATAL) << "Unknown return type " << ret->InputAt(0)->GetType(); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 846 | } |
| 847 | } |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 848 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 849 | __ ret(); |
| 850 | } |
| 851 | |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 852 | void LocationsBuilderX86::VisitInvokeStatic(HInvokeStatic* invoke) { |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 853 | HandleInvoke(invoke); |
| 854 | } |
| 855 | |
| 856 | void InstructionCodeGeneratorX86::VisitInvokeStatic(HInvokeStatic* invoke) { |
| 857 | Register temp = invoke->GetLocations()->GetTemp(0).AsX86().AsCpuRegister(); |
| 858 | uint32_t heap_reference_size = sizeof(mirror::HeapReference<mirror::Object>); |
| 859 | size_t index_in_cache = mirror::Array::DataOffset(heap_reference_size).Int32Value() + |
| 860 | invoke->GetIndexInDexCache() * kX86WordSize; |
| 861 | |
| 862 | // TODO: Implement all kinds of calls: |
| 863 | // 1) boot -> boot |
| 864 | // 2) app -> boot |
| 865 | // 3) app -> app |
| 866 | // |
| 867 | // Currently we implement the app -> app logic, which looks up in the resolve cache. |
| 868 | |
| 869 | // temp = method; |
| 870 | LoadCurrentMethod(temp); |
| 871 | // temp = temp->dex_cache_resolved_methods_; |
| 872 | __ movl(temp, Address(temp, mirror::ArtMethod::DexCacheResolvedMethodsOffset().Int32Value())); |
| 873 | // temp = temp[index_in_cache] |
| 874 | __ movl(temp, Address(temp, index_in_cache)); |
| 875 | // (temp + offset_of_quick_compiled_code)() |
| 876 | __ call(Address(temp, mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset().Int32Value())); |
| 877 | |
| 878 | DCHECK(!codegen_->IsLeafMethod()); |
| 879 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 880 | } |
| 881 | |
| 882 | void LocationsBuilderX86::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
| 883 | HandleInvoke(invoke); |
| 884 | } |
| 885 | |
| 886 | void LocationsBuilderX86::HandleInvoke(HInvoke* invoke) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 887 | LocationSummary* locations = |
| 888 | new (GetGraph()->GetArena()) LocationSummary(invoke, LocationSummary::kCall); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 889 | locations->AddTemp(X86CpuLocation(EAX)); |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 890 | |
| 891 | InvokeDexCallingConventionVisitor calling_convention_visitor; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 892 | for (size_t i = 0; i < invoke->InputCount(); i++) { |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 893 | HInstruction* input = invoke->InputAt(i); |
| 894 | locations->SetInAt(i, calling_convention_visitor.GetNextLocation(input->GetType())); |
| 895 | } |
| 896 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 897 | switch (invoke->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: |
| 904 | locations->SetOut(X86CpuLocation(EAX)); |
| 905 | break; |
| 906 | |
| 907 | case Primitive::kPrimLong: |
| 908 | locations->SetOut(Location::RegisterLocation(X86ManagedRegister::FromRegisterPair(EAX_EDX))); |
| 909 | break; |
| 910 | |
| 911 | case Primitive::kPrimVoid: |
| 912 | break; |
| 913 | |
| 914 | case Primitive::kPrimDouble: |
| 915 | case Primitive::kPrimFloat: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame^] | 916 | locations->SetOut(Location::FpuRegisterLocation(X86ManagedRegister::FromXmmRegister(XMM0))); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 917 | break; |
| 918 | } |
| 919 | |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 920 | invoke->SetLocations(locations); |
| 921 | } |
| 922 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 923 | void InstructionCodeGeneratorX86::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 924 | Register temp = invoke->GetLocations()->GetTemp(0).AsX86().AsCpuRegister(); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 925 | uint32_t method_offset = mirror::Class::EmbeddedVTableOffset().Uint32Value() + |
| 926 | invoke->GetVTableIndex() * sizeof(mirror::Class::VTableEntry); |
| 927 | LocationSummary* locations = invoke->GetLocations(); |
| 928 | Location receiver = locations->InAt(0); |
| 929 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 930 | // temp = object->GetClass(); |
| 931 | if (receiver.IsStackSlot()) { |
| 932 | __ movl(temp, Address(ESP, receiver.GetStackIndex())); |
| 933 | __ movl(temp, Address(temp, class_offset)); |
| 934 | } else { |
| 935 | __ movl(temp, Address(receiver.AsX86().AsCpuRegister(), class_offset)); |
| 936 | } |
| 937 | // temp = temp->GetMethodAt(method_offset); |
| 938 | __ movl(temp, Address(temp, method_offset)); |
| 939 | // call temp->GetEntryPoint(); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 940 | __ call(Address(temp, mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset().Int32Value())); |
| 941 | |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 942 | DCHECK(!codegen_->IsLeafMethod()); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 943 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 944 | } |
| 945 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 946 | void LocationsBuilderX86::VisitAdd(HAdd* add) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 947 | LocationSummary* locations = |
| 948 | new (GetGraph()->GetArena()) LocationSummary(add, LocationSummary::kNoCall); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 949 | switch (add->GetResultType()) { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 950 | case Primitive::kPrimInt: |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 951 | case Primitive::kPrimLong: { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 952 | locations->SetInAt(0, Location::RequiresRegister()); |
| 953 | locations->SetInAt(1, Location::Any()); |
| 954 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 955 | break; |
| 956 | } |
| 957 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame^] | 958 | case Primitive::kPrimFloat: |
| 959 | case Primitive::kPrimDouble: { |
| 960 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 961 | locations->SetInAt(1, Location::Any()); |
| 962 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 963 | break; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame^] | 964 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 965 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 966 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame^] | 967 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
| 968 | break; |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 969 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 970 | } |
| 971 | |
| 972 | void InstructionCodeGeneratorX86::VisitAdd(HAdd* add) { |
| 973 | LocationSummary* locations = add->GetLocations(); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame^] | 974 | Location first = locations->InAt(0); |
| 975 | Location second = locations->InAt(1); |
| 976 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 977 | switch (add->GetResultType()) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 978 | case Primitive::kPrimInt: { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame^] | 979 | DCHECK_EQ(first.AsX86().AsCpuRegister(), locations->Out().AsX86().AsCpuRegister()); |
| 980 | if (second.IsRegister()) { |
| 981 | __ addl(first.AsX86().AsCpuRegister(), second.AsX86().AsCpuRegister()); |
| 982 | } else if (second.IsConstant()) { |
| 983 | HConstant* instruction = second.GetConstant(); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 984 | Immediate imm(instruction->AsIntConstant()->GetValue()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame^] | 985 | __ addl(first.AsX86().AsCpuRegister(), imm); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 986 | } else { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame^] | 987 | __ addl(first.AsX86().AsCpuRegister(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 988 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 989 | break; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 990 | } |
| 991 | |
| 992 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame^] | 993 | DCHECK_EQ(first.AsX86().AsRegisterPair(), |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 994 | locations->Out().AsX86().AsRegisterPair()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame^] | 995 | if (second.IsRegister()) { |
| 996 | __ addl(first.AsX86().AsRegisterPairLow(), second.AsX86().AsRegisterPairLow()); |
| 997 | __ adcl(first.AsX86().AsRegisterPairHigh(), second.AsX86().AsRegisterPairHigh()); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 998 | } else { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame^] | 999 | __ addl(first.AsX86().AsRegisterPairLow(), Address(ESP, second.GetStackIndex())); |
| 1000 | __ adcl(first.AsX86().AsRegisterPairHigh(), |
| 1001 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1002 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1003 | break; |
| 1004 | } |
| 1005 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame^] | 1006 | case Primitive::kPrimFloat: { |
| 1007 | if (second.IsFpuRegister()) { |
| 1008 | __ addss(first.AsX86().AsXmmRegister(), second.AsX86().AsXmmRegister()); |
| 1009 | } else { |
| 1010 | __ addss(first.AsX86().AsXmmRegister(), Address(ESP, second.GetStackIndex())); |
| 1011 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1012 | break; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame^] | 1013 | } |
| 1014 | |
| 1015 | case Primitive::kPrimDouble: { |
| 1016 | if (second.IsFpuRegister()) { |
| 1017 | __ addsd(first.AsX86().AsXmmRegister(), second.AsX86().AsXmmRegister()); |
| 1018 | } else { |
| 1019 | __ addsd(first.AsX86().AsXmmRegister(), Address(ESP, second.GetStackIndex())); |
| 1020 | } |
| 1021 | break; |
| 1022 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1023 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 1024 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame^] | 1025 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 1026 | } |
| 1027 | } |
| 1028 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 1029 | void LocationsBuilderX86::VisitSub(HSub* sub) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1030 | LocationSummary* locations = |
| 1031 | new (GetGraph()->GetArena()) LocationSummary(sub, LocationSummary::kNoCall); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 1032 | switch (sub->GetResultType()) { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1033 | case Primitive::kPrimInt: |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1034 | case Primitive::kPrimLong: { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1035 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1036 | locations->SetInAt(1, Location::Any()); |
| 1037 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1038 | break; |
| 1039 | } |
| 1040 | |
| 1041 | case Primitive::kPrimBoolean: |
| 1042 | case Primitive::kPrimByte: |
| 1043 | case Primitive::kPrimChar: |
| 1044 | case Primitive::kPrimShort: |
| 1045 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
| 1046 | break; |
| 1047 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 1048 | default: |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1049 | LOG(FATAL) << "Unimplemented sub type " << sub->GetResultType(); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 1050 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 1051 | } |
| 1052 | |
| 1053 | void InstructionCodeGeneratorX86::VisitSub(HSub* sub) { |
| 1054 | LocationSummary* locations = sub->GetLocations(); |
| 1055 | switch (sub->GetResultType()) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1056 | case Primitive::kPrimInt: { |
| 1057 | DCHECK_EQ(locations->InAt(0).AsX86().AsCpuRegister(), |
| 1058 | locations->Out().AsX86().AsCpuRegister()); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1059 | if (locations->InAt(1).IsRegister()) { |
| 1060 | __ subl(locations->InAt(0).AsX86().AsCpuRegister(), |
| 1061 | locations->InAt(1).AsX86().AsCpuRegister()); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1062 | } else if (locations->InAt(1).IsConstant()) { |
| 1063 | HConstant* instruction = locations->InAt(1).GetConstant(); |
| 1064 | Immediate imm(instruction->AsIntConstant()->GetValue()); |
| 1065 | __ subl(locations->InAt(0).AsX86().AsCpuRegister(), imm); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1066 | } else { |
| 1067 | __ subl(locations->InAt(0).AsX86().AsCpuRegister(), |
| 1068 | Address(ESP, locations->InAt(1).GetStackIndex())); |
| 1069 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 1070 | break; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1071 | } |
| 1072 | |
| 1073 | case Primitive::kPrimLong: { |
| 1074 | DCHECK_EQ(locations->InAt(0).AsX86().AsRegisterPair(), |
| 1075 | locations->Out().AsX86().AsRegisterPair()); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1076 | if (locations->InAt(1).IsRegister()) { |
| 1077 | __ subl(locations->InAt(0).AsX86().AsRegisterPairLow(), |
| 1078 | locations->InAt(1).AsX86().AsRegisterPairLow()); |
| 1079 | __ sbbl(locations->InAt(0).AsX86().AsRegisterPairHigh(), |
| 1080 | locations->InAt(1).AsX86().AsRegisterPairHigh()); |
| 1081 | } else { |
| 1082 | __ subl(locations->InAt(0).AsX86().AsRegisterPairLow(), |
| 1083 | Address(ESP, locations->InAt(1).GetStackIndex())); |
| 1084 | __ sbbl(locations->InAt(0).AsX86().AsRegisterPairHigh(), |
| 1085 | Address(ESP, locations->InAt(1).GetHighStackIndex(kX86WordSize))); |
| 1086 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1087 | break; |
| 1088 | } |
| 1089 | |
| 1090 | case Primitive::kPrimBoolean: |
| 1091 | case Primitive::kPrimByte: |
| 1092 | case Primitive::kPrimChar: |
| 1093 | case Primitive::kPrimShort: |
| 1094 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
| 1095 | break; |
| 1096 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 1097 | default: |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1098 | LOG(FATAL) << "Unimplemented sub type " << sub->GetResultType(); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 1099 | } |
| 1100 | } |
| 1101 | |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 1102 | void LocationsBuilderX86::VisitNewInstance(HNewInstance* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1103 | LocationSummary* locations = |
| 1104 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1105 | locations->SetOut(X86CpuLocation(EAX)); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1106 | InvokeRuntimeCallingConvention calling_convention; |
| 1107 | locations->AddTemp(X86CpuLocation(calling_convention.GetRegisterAt(0))); |
| 1108 | locations->AddTemp(X86CpuLocation(calling_convention.GetRegisterAt(1))); |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 1109 | } |
| 1110 | |
| 1111 | void InstructionCodeGeneratorX86::VisitNewInstance(HNewInstance* instruction) { |
| 1112 | InvokeRuntimeCallingConvention calling_convention; |
| 1113 | LoadCurrentMethod(calling_convention.GetRegisterAt(1)); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1114 | __ movl(calling_convention.GetRegisterAt(0), Immediate(instruction->GetTypeIndex())); |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 1115 | |
Nicolas Geoffray | 707c809 | 2014-04-04 10:50:14 +0100 | [diff] [blame] | 1116 | __ fs()->call( |
| 1117 | Address::Absolute(QUICK_ENTRYPOINT_OFFSET(kX86WordSize, pAllocObjectWithAccessCheck))); |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 1118 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1119 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 1120 | DCHECK(!codegen_->IsLeafMethod()); |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 1121 | } |
| 1122 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 1123 | void LocationsBuilderX86::VisitParameterValue(HParameterValue* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1124 | LocationSummary* locations = |
| 1125 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1126 | Location location = parameter_visitor_.GetNextLocation(instruction->GetType()); |
| 1127 | if (location.IsStackSlot()) { |
| 1128 | location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 1129 | } else if (location.IsDoubleStackSlot()) { |
| 1130 | location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 1131 | } |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1132 | locations->SetOut(location); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 1133 | } |
| 1134 | |
| 1135 | void InstructionCodeGeneratorX86::VisitParameterValue(HParameterValue* instruction) { |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 1136 | } |
| 1137 | |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 1138 | void LocationsBuilderX86::VisitNot(HNot* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1139 | LocationSummary* locations = |
| 1140 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1141 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1142 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 1143 | } |
| 1144 | |
| 1145 | void InstructionCodeGeneratorX86::VisitNot(HNot* instruction) { |
| 1146 | LocationSummary* locations = instruction->GetLocations(); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1147 | Location out = locations->Out(); |
| 1148 | DCHECK_EQ(locations->InAt(0).AsX86().AsCpuRegister(), out.AsX86().AsCpuRegister()); |
| 1149 | __ xorl(out.AsX86().AsCpuRegister(), Immediate(1)); |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 1150 | } |
| 1151 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1152 | void LocationsBuilderX86::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1153 | LocationSummary* locations = |
| 1154 | new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall); |
Nicolas Geoffray | 9ae0daa | 2014-09-30 22:40:23 +0100 | [diff] [blame] | 1155 | locations->SetInAt(0, Location::RequiresRegister(), Location::kDiesAtEntry); |
| 1156 | locations->SetInAt(1, Location::Any(), Location::kDiesAtEntry); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1157 | locations->SetOut(Location::RequiresRegister()); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1158 | } |
| 1159 | |
| 1160 | void InstructionCodeGeneratorX86::VisitCompare(HCompare* compare) { |
| 1161 | Label greater, done; |
| 1162 | LocationSummary* locations = compare->GetLocations(); |
| 1163 | switch (compare->InputAt(0)->GetType()) { |
| 1164 | case Primitive::kPrimLong: { |
| 1165 | Label less, greater, done; |
| 1166 | Register output = locations->Out().AsX86().AsCpuRegister(); |
| 1167 | X86ManagedRegister left = locations->InAt(0).AsX86(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1168 | Location right = locations->InAt(1); |
| 1169 | if (right.IsRegister()) { |
| 1170 | __ cmpl(left.AsRegisterPairHigh(), right.AsX86().AsRegisterPairHigh()); |
| 1171 | } else { |
| 1172 | DCHECK(right.IsDoubleStackSlot()); |
| 1173 | __ cmpl(left.AsRegisterPairHigh(), Address(ESP, right.GetHighStackIndex(kX86WordSize))); |
| 1174 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1175 | __ j(kLess, &less); // Signed compare. |
| 1176 | __ j(kGreater, &greater); // Signed compare. |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1177 | if (right.IsRegister()) { |
| 1178 | __ cmpl(left.AsRegisterPairLow(), right.AsX86().AsRegisterPairLow()); |
| 1179 | } else { |
| 1180 | DCHECK(right.IsDoubleStackSlot()); |
| 1181 | __ cmpl(left.AsRegisterPairLow(), Address(ESP, right.GetStackIndex())); |
| 1182 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1183 | __ movl(output, Immediate(0)); |
| 1184 | __ j(kEqual, &done); |
| 1185 | __ j(kBelow, &less); // Unsigned compare. |
| 1186 | |
| 1187 | __ Bind(&greater); |
| 1188 | __ movl(output, Immediate(1)); |
| 1189 | __ jmp(&done); |
| 1190 | |
| 1191 | __ Bind(&less); |
| 1192 | __ movl(output, Immediate(-1)); |
| 1193 | |
| 1194 | __ Bind(&done); |
| 1195 | break; |
| 1196 | } |
| 1197 | default: |
| 1198 | LOG(FATAL) << "Unimplemented compare type " << compare->InputAt(0)->GetType(); |
| 1199 | } |
| 1200 | } |
| 1201 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1202 | void LocationsBuilderX86::VisitPhi(HPhi* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1203 | LocationSummary* locations = |
| 1204 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 31d76b4 | 2014-06-09 15:02:22 +0100 | [diff] [blame] | 1205 | for (size_t i = 0, e = instruction->InputCount(); i < e; ++i) { |
| 1206 | locations->SetInAt(i, Location::Any()); |
| 1207 | } |
| 1208 | locations->SetOut(Location::Any()); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1209 | } |
| 1210 | |
| 1211 | void InstructionCodeGeneratorX86::VisitPhi(HPhi* instruction) { |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 1212 | LOG(FATAL) << "Unreachable"; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1213 | } |
| 1214 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1215 | void LocationsBuilderX86::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1216 | LocationSummary* locations = |
| 1217 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1218 | locations->SetInAt(0, Location::RequiresRegister()); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1219 | Primitive::Type field_type = instruction->GetFieldType(); |
Nicolas Geoffray | 9ae0daa | 2014-09-30 22:40:23 +0100 | [diff] [blame] | 1220 | bool is_object_type = field_type == Primitive::kPrimNot; |
Nicolas Geoffray | 7adfcc8 | 2014-10-07 12:24:52 +0100 | [diff] [blame] | 1221 | bool is_byte_type = (field_type == Primitive::kPrimBoolean) |
| 1222 | || (field_type == Primitive::kPrimByte); |
| 1223 | // The register allocator does not support multiple |
| 1224 | // inputs that die at entry with one in a specific register. |
| 1225 | bool dies_at_entry = !is_object_type && !is_byte_type; |
| 1226 | if (is_byte_type) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1227 | // Ensure the value is in a byte register. |
Nicolas Geoffray | 9ae0daa | 2014-09-30 22:40:23 +0100 | [diff] [blame] | 1228 | locations->SetInAt(1, X86CpuLocation(EAX), dies_at_entry); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1229 | } else { |
Nicolas Geoffray | 9ae0daa | 2014-09-30 22:40:23 +0100 | [diff] [blame] | 1230 | locations->SetInAt(1, Location::RequiresRegister(), dies_at_entry); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1231 | } |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 1232 | // Temporary registers for the write barrier. |
Nicolas Geoffray | 9ae0daa | 2014-09-30 22:40:23 +0100 | [diff] [blame] | 1233 | if (is_object_type) { |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 1234 | locations->AddTemp(Location::RequiresRegister()); |
| 1235 | // Ensure the card is in a byte register. |
| 1236 | locations->AddTemp(X86CpuLocation(ECX)); |
| 1237 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1238 | } |
| 1239 | |
| 1240 | void InstructionCodeGeneratorX86::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
| 1241 | LocationSummary* locations = instruction->GetLocations(); |
| 1242 | Register obj = locations->InAt(0).AsX86().AsCpuRegister(); |
| 1243 | uint32_t offset = instruction->GetFieldOffset().Uint32Value(); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1244 | Primitive::Type field_type = instruction->GetFieldType(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1245 | |
| 1246 | switch (field_type) { |
| 1247 | case Primitive::kPrimBoolean: |
| 1248 | case Primitive::kPrimByte: { |
| 1249 | ByteRegister value = locations->InAt(1).AsX86().AsByteRegister(); |
| 1250 | __ movb(Address(obj, offset), value); |
| 1251 | break; |
| 1252 | } |
| 1253 | |
| 1254 | case Primitive::kPrimShort: |
| 1255 | case Primitive::kPrimChar: { |
| 1256 | Register value = locations->InAt(1).AsX86().AsCpuRegister(); |
| 1257 | __ movw(Address(obj, offset), value); |
| 1258 | break; |
| 1259 | } |
| 1260 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1261 | case Primitive::kPrimInt: |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1262 | case Primitive::kPrimNot: { |
| 1263 | Register value = locations->InAt(1).AsX86().AsCpuRegister(); |
| 1264 | __ movl(Address(obj, offset), value); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1265 | |
| 1266 | if (field_type == Primitive::kPrimNot) { |
| 1267 | Register temp = locations->GetTemp(0).AsX86().AsCpuRegister(); |
| 1268 | Register card = locations->GetTemp(1).AsX86().AsCpuRegister(); |
| 1269 | codegen_->MarkGCCard(temp, card, obj, value); |
| 1270 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1271 | break; |
| 1272 | } |
| 1273 | |
| 1274 | case Primitive::kPrimLong: { |
| 1275 | X86ManagedRegister value = locations->InAt(1).AsX86(); |
| 1276 | __ movl(Address(obj, offset), value.AsRegisterPairLow()); |
| 1277 | __ movl(Address(obj, kX86WordSize + offset), value.AsRegisterPairHigh()); |
| 1278 | break; |
| 1279 | } |
| 1280 | |
| 1281 | case Primitive::kPrimFloat: |
| 1282 | case Primitive::kPrimDouble: |
| 1283 | LOG(FATAL) << "Unimplemented register type " << field_type; |
| 1284 | |
| 1285 | case Primitive::kPrimVoid: |
| 1286 | LOG(FATAL) << "Unreachable type " << field_type; |
| 1287 | } |
| 1288 | } |
| 1289 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1290 | void CodeGeneratorX86::MarkGCCard(Register temp, Register card, Register object, Register value) { |
| 1291 | Label is_null; |
| 1292 | __ testl(value, value); |
| 1293 | __ j(kEqual, &is_null); |
| 1294 | __ fs()->movl(card, Address::Absolute(Thread::CardTableOffset<kX86WordSize>().Int32Value())); |
| 1295 | __ movl(temp, object); |
| 1296 | __ shrl(temp, Immediate(gc::accounting::CardTable::kCardShift)); |
| 1297 | __ movb(Address(temp, card, TIMES_1, 0), |
| 1298 | X86ManagedRegister::FromCpuRegister(card).AsByteRegister()); |
| 1299 | __ Bind(&is_null); |
| 1300 | } |
| 1301 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1302 | void LocationsBuilderX86::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1303 | LocationSummary* locations = |
| 1304 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 9ae0daa | 2014-09-30 22:40:23 +0100 | [diff] [blame] | 1305 | locations->SetInAt(0, Location::RequiresRegister(), Location::kDiesAtEntry); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1306 | locations->SetOut(Location::RequiresRegister()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1307 | } |
| 1308 | |
| 1309 | void InstructionCodeGeneratorX86::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 1310 | LocationSummary* locations = instruction->GetLocations(); |
| 1311 | Register obj = locations->InAt(0).AsX86().AsCpuRegister(); |
| 1312 | uint32_t offset = instruction->GetFieldOffset().Uint32Value(); |
| 1313 | |
| 1314 | switch (instruction->GetType()) { |
| 1315 | case Primitive::kPrimBoolean: { |
| 1316 | Register out = locations->Out().AsX86().AsCpuRegister(); |
| 1317 | __ movzxb(out, Address(obj, offset)); |
| 1318 | break; |
| 1319 | } |
| 1320 | |
| 1321 | case Primitive::kPrimByte: { |
| 1322 | Register out = locations->Out().AsX86().AsCpuRegister(); |
| 1323 | __ movsxb(out, Address(obj, offset)); |
| 1324 | break; |
| 1325 | } |
| 1326 | |
| 1327 | case Primitive::kPrimShort: { |
| 1328 | Register out = locations->Out().AsX86().AsCpuRegister(); |
| 1329 | __ movsxw(out, Address(obj, offset)); |
| 1330 | break; |
| 1331 | } |
| 1332 | |
| 1333 | case Primitive::kPrimChar: { |
| 1334 | Register out = locations->Out().AsX86().AsCpuRegister(); |
| 1335 | __ movzxw(out, Address(obj, offset)); |
| 1336 | break; |
| 1337 | } |
| 1338 | |
| 1339 | case Primitive::kPrimInt: |
| 1340 | case Primitive::kPrimNot: { |
| 1341 | Register out = locations->Out().AsX86().AsCpuRegister(); |
| 1342 | __ movl(out, Address(obj, offset)); |
| 1343 | break; |
| 1344 | } |
| 1345 | |
| 1346 | case Primitive::kPrimLong: { |
| 1347 | // TODO: support volatile. |
| 1348 | X86ManagedRegister out = locations->Out().AsX86(); |
| 1349 | __ movl(out.AsRegisterPairLow(), Address(obj, offset)); |
| 1350 | __ movl(out.AsRegisterPairHigh(), Address(obj, kX86WordSize + offset)); |
| 1351 | break; |
| 1352 | } |
| 1353 | |
| 1354 | case Primitive::kPrimFloat: |
| 1355 | case Primitive::kPrimDouble: |
| 1356 | LOG(FATAL) << "Unimplemented register type " << instruction->GetType(); |
| 1357 | |
| 1358 | case Primitive::kPrimVoid: |
| 1359 | LOG(FATAL) << "Unreachable type " << instruction->GetType(); |
| 1360 | } |
| 1361 | } |
| 1362 | |
| 1363 | void LocationsBuilderX86::VisitNullCheck(HNullCheck* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1364 | LocationSummary* locations = |
| 1365 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1366 | locations->SetInAt(0, Location::Any()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 1367 | if (instruction->HasUses()) { |
| 1368 | locations->SetOut(Location::SameAsFirstInput()); |
| 1369 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1370 | } |
| 1371 | |
| 1372 | void InstructionCodeGeneratorX86::VisitNullCheck(HNullCheck* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1373 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathX86(instruction); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1374 | codegen_->AddSlowPath(slow_path); |
| 1375 | |
| 1376 | LocationSummary* locations = instruction->GetLocations(); |
| 1377 | Location obj = locations->InAt(0); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1378 | |
| 1379 | if (obj.IsRegister()) { |
| 1380 | __ cmpl(obj.AsX86().AsCpuRegister(), Immediate(0)); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 1381 | } else if (obj.IsStackSlot()) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1382 | __ cmpl(Address(ESP, obj.GetStackIndex()), Immediate(0)); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 1383 | } else { |
| 1384 | DCHECK(obj.IsConstant()) << obj; |
| 1385 | DCHECK_EQ(obj.GetConstant()->AsIntConstant()->GetValue(), 0); |
| 1386 | __ jmp(slow_path->GetEntryLabel()); |
| 1387 | return; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1388 | } |
| 1389 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 1390 | } |
| 1391 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1392 | void LocationsBuilderX86::VisitArrayGet(HArrayGet* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1393 | LocationSummary* locations = |
| 1394 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 9ae0daa | 2014-09-30 22:40:23 +0100 | [diff] [blame] | 1395 | locations->SetInAt(0, Location::RequiresRegister(), Location::kDiesAtEntry); |
| 1396 | locations->SetInAt( |
| 1397 | 1, Location::RegisterOrConstant(instruction->InputAt(1)), Location::kDiesAtEntry); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1398 | locations->SetOut(Location::RequiresRegister()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1399 | } |
| 1400 | |
| 1401 | void InstructionCodeGeneratorX86::VisitArrayGet(HArrayGet* instruction) { |
| 1402 | LocationSummary* locations = instruction->GetLocations(); |
| 1403 | Register obj = locations->InAt(0).AsX86().AsCpuRegister(); |
| 1404 | Location index = locations->InAt(1); |
| 1405 | |
| 1406 | switch (instruction->GetType()) { |
| 1407 | case Primitive::kPrimBoolean: { |
| 1408 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value(); |
| 1409 | Register out = locations->Out().AsX86().AsCpuRegister(); |
| 1410 | if (index.IsConstant()) { |
| 1411 | __ movzxb(out, Address(obj, |
| 1412 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset)); |
| 1413 | } else { |
| 1414 | __ movzxb(out, Address(obj, index.AsX86().AsCpuRegister(), TIMES_1, data_offset)); |
| 1415 | } |
| 1416 | break; |
| 1417 | } |
| 1418 | |
| 1419 | case Primitive::kPrimByte: { |
| 1420 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int8_t)).Uint32Value(); |
| 1421 | Register out = locations->Out().AsX86().AsCpuRegister(); |
| 1422 | if (index.IsConstant()) { |
| 1423 | __ movsxb(out, Address(obj, |
| 1424 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset)); |
| 1425 | } else { |
| 1426 | __ movsxb(out, Address(obj, index.AsX86().AsCpuRegister(), TIMES_1, data_offset)); |
| 1427 | } |
| 1428 | break; |
| 1429 | } |
| 1430 | |
| 1431 | case Primitive::kPrimShort: { |
| 1432 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int16_t)).Uint32Value(); |
| 1433 | Register out = locations->Out().AsX86().AsCpuRegister(); |
| 1434 | if (index.IsConstant()) { |
| 1435 | __ movsxw(out, Address(obj, |
| 1436 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset)); |
| 1437 | } else { |
| 1438 | __ movsxw(out, Address(obj, index.AsX86().AsCpuRegister(), TIMES_2, data_offset)); |
| 1439 | } |
| 1440 | break; |
| 1441 | } |
| 1442 | |
| 1443 | case Primitive::kPrimChar: { |
| 1444 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value(); |
| 1445 | Register out = locations->Out().AsX86().AsCpuRegister(); |
| 1446 | if (index.IsConstant()) { |
| 1447 | __ movzxw(out, Address(obj, |
| 1448 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset)); |
| 1449 | } else { |
| 1450 | __ movzxw(out, Address(obj, index.AsX86().AsCpuRegister(), TIMES_2, data_offset)); |
| 1451 | } |
| 1452 | break; |
| 1453 | } |
| 1454 | |
| 1455 | case Primitive::kPrimInt: |
| 1456 | case Primitive::kPrimNot: { |
| 1457 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
| 1458 | Register out = locations->Out().AsX86().AsCpuRegister(); |
| 1459 | if (index.IsConstant()) { |
| 1460 | __ movl(out, Address(obj, |
| 1461 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset)); |
| 1462 | } else { |
| 1463 | __ movl(out, Address(obj, index.AsX86().AsCpuRegister(), TIMES_4, data_offset)); |
| 1464 | } |
| 1465 | break; |
| 1466 | } |
| 1467 | |
| 1468 | case Primitive::kPrimLong: { |
| 1469 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value(); |
| 1470 | X86ManagedRegister out = locations->Out().AsX86(); |
| 1471 | if (index.IsConstant()) { |
| 1472 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
| 1473 | __ movl(out.AsRegisterPairLow(), Address(obj, offset)); |
| 1474 | __ movl(out.AsRegisterPairHigh(), Address(obj, offset + kX86WordSize)); |
| 1475 | } else { |
| 1476 | __ movl(out.AsRegisterPairLow(), |
| 1477 | Address(obj, index.AsX86().AsCpuRegister(), TIMES_8, data_offset)); |
| 1478 | __ movl(out.AsRegisterPairHigh(), |
| 1479 | Address(obj, index.AsX86().AsCpuRegister(), TIMES_8, data_offset + kX86WordSize)); |
| 1480 | } |
| 1481 | break; |
| 1482 | } |
| 1483 | |
| 1484 | case Primitive::kPrimFloat: |
| 1485 | case Primitive::kPrimDouble: |
| 1486 | LOG(FATAL) << "Unimplemented register type " << instruction->GetType(); |
| 1487 | |
| 1488 | case Primitive::kPrimVoid: |
| 1489 | LOG(FATAL) << "Unreachable type " << instruction->GetType(); |
| 1490 | } |
| 1491 | } |
| 1492 | |
| 1493 | void LocationsBuilderX86::VisitArraySet(HArraySet* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1494 | Primitive::Type value_type = instruction->GetComponentType(); |
| 1495 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary( |
| 1496 | instruction, |
| 1497 | value_type == Primitive::kPrimNot ? LocationSummary::kCall : LocationSummary::kNoCall); |
| 1498 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1499 | if (value_type == Primitive::kPrimNot) { |
| 1500 | InvokeRuntimeCallingConvention calling_convention; |
| 1501 | locations->SetInAt(0, X86CpuLocation(calling_convention.GetRegisterAt(0))); |
| 1502 | locations->SetInAt(1, X86CpuLocation(calling_convention.GetRegisterAt(1))); |
| 1503 | locations->SetInAt(2, X86CpuLocation(calling_convention.GetRegisterAt(2))); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1504 | } else { |
Nicolas Geoffray | 7adfcc8 | 2014-10-07 12:24:52 +0100 | [diff] [blame] | 1505 | bool is_byte_type = (value_type == Primitive::kPrimBoolean) |
| 1506 | || (value_type == Primitive::kPrimByte); |
Nicolas Geoffray | 9ae0daa | 2014-09-30 22:40:23 +0100 | [diff] [blame] | 1507 | // 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] | 1508 | // In case of a byte operation, the register allocator does not support multiple |
| 1509 | // inputs that die at entry with one in a specific register. |
| 1510 | bool dies_at_entry = value_type != Primitive::kPrimLong && !is_byte_type; |
Nicolas Geoffray | 9ae0daa | 2014-09-30 22:40:23 +0100 | [diff] [blame] | 1511 | locations->SetInAt(0, Location::RequiresRegister(), dies_at_entry); |
| 1512 | locations->SetInAt( |
| 1513 | 1, Location::RegisterOrConstant(instruction->InputAt(1)), dies_at_entry); |
Nicolas Geoffray | 7adfcc8 | 2014-10-07 12:24:52 +0100 | [diff] [blame] | 1514 | if (is_byte_type) { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1515 | // Ensure the value is in a byte register. |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 1516 | locations->SetInAt(2, Location::ByteRegisterOrConstant( |
| 1517 | X86ManagedRegister::FromCpuRegister(EAX), instruction->InputAt(2)), dies_at_entry); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1518 | } else { |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 1519 | locations->SetInAt(2, Location::RegisterOrConstant(instruction->InputAt(2)), dies_at_entry); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1520 | } |
| 1521 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1522 | } |
| 1523 | |
| 1524 | void InstructionCodeGeneratorX86::VisitArraySet(HArraySet* instruction) { |
| 1525 | LocationSummary* locations = instruction->GetLocations(); |
| 1526 | Register obj = locations->InAt(0).AsX86().AsCpuRegister(); |
| 1527 | Location index = locations->InAt(1); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 1528 | Location value = locations->InAt(2); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1529 | Primitive::Type value_type = instruction->GetComponentType(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1530 | |
| 1531 | switch (value_type) { |
| 1532 | case Primitive::kPrimBoolean: |
| 1533 | case Primitive::kPrimByte: { |
| 1534 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1535 | if (index.IsConstant()) { |
| 1536 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset; |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 1537 | if (value.IsRegister()) { |
| 1538 | __ movb(Address(obj, offset), value.AsX86().AsByteRegister()); |
| 1539 | } else { |
| 1540 | __ movb(Address(obj, offset), |
| 1541 | Immediate(value.GetConstant()->AsIntConstant()->GetValue())); |
| 1542 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1543 | } else { |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 1544 | if (value.IsRegister()) { |
| 1545 | __ movb(Address(obj, index.AsX86().AsCpuRegister(), TIMES_1, data_offset), |
| 1546 | value.AsX86().AsByteRegister()); |
| 1547 | } else { |
| 1548 | __ movb(Address(obj, index.AsX86().AsCpuRegister(), TIMES_1, data_offset), |
| 1549 | Immediate(value.GetConstant()->AsIntConstant()->GetValue())); |
| 1550 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1551 | } |
| 1552 | break; |
| 1553 | } |
| 1554 | |
| 1555 | case Primitive::kPrimShort: |
| 1556 | case Primitive::kPrimChar: { |
| 1557 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1558 | if (index.IsConstant()) { |
| 1559 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset; |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 1560 | if (value.IsRegister()) { |
| 1561 | __ movw(Address(obj, offset), value.AsX86().AsCpuRegister()); |
| 1562 | } else { |
| 1563 | __ movw(Address(obj, offset), |
| 1564 | Immediate(value.GetConstant()->AsIntConstant()->GetValue())); |
| 1565 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1566 | } else { |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 1567 | if (value.IsRegister()) { |
| 1568 | __ movw(Address(obj, index.AsX86().AsCpuRegister(), TIMES_2, data_offset), |
| 1569 | value.AsX86().AsCpuRegister()); |
| 1570 | } else { |
| 1571 | __ movw(Address(obj, index.AsX86().AsCpuRegister(), TIMES_2, data_offset), |
| 1572 | Immediate(value.GetConstant()->AsIntConstant()->GetValue())); |
| 1573 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1574 | } |
| 1575 | break; |
| 1576 | } |
| 1577 | |
| 1578 | case Primitive::kPrimInt: { |
| 1579 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1580 | if (index.IsConstant()) { |
| 1581 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 1582 | if (value.IsRegister()) { |
| 1583 | __ movl(Address(obj, offset), value.AsX86().AsCpuRegister()); |
| 1584 | } else { |
| 1585 | __ movl(Address(obj, offset), Immediate(value.GetConstant()->AsIntConstant()->GetValue())); |
| 1586 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1587 | } else { |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 1588 | if (value.IsRegister()) { |
| 1589 | __ movl(Address(obj, index.AsX86().AsCpuRegister(), TIMES_4, data_offset), |
| 1590 | value.AsX86().AsCpuRegister()); |
| 1591 | } else { |
| 1592 | __ movl(Address(obj, index.AsX86().AsCpuRegister(), TIMES_4, data_offset), |
| 1593 | Immediate(value.GetConstant()->AsIntConstant()->GetValue())); |
| 1594 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1595 | } |
| 1596 | break; |
| 1597 | } |
| 1598 | |
| 1599 | case Primitive::kPrimNot: { |
| 1600 | DCHECK(!codegen_->IsLeafMethod()); |
| 1601 | __ fs()->call(Address::Absolute(QUICK_ENTRYPOINT_OFFSET(kX86WordSize, pAputObject))); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1602 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1603 | break; |
| 1604 | } |
| 1605 | |
| 1606 | case Primitive::kPrimLong: { |
| 1607 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1608 | if (index.IsConstant()) { |
| 1609 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 1610 | if (value.IsRegister()) { |
| 1611 | __ movl(Address(obj, offset), value.AsX86().AsRegisterPairLow()); |
| 1612 | __ movl(Address(obj, offset + kX86WordSize), value.AsX86().AsRegisterPairHigh()); |
| 1613 | } else { |
| 1614 | int64_t val = value.GetConstant()->AsLongConstant()->GetValue(); |
| 1615 | __ movl(Address(obj, offset), Immediate(Low32Bits(val))); |
| 1616 | __ movl(Address(obj, offset + kX86WordSize), Immediate(High32Bits(val))); |
| 1617 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1618 | } else { |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 1619 | if (value.IsRegister()) { |
| 1620 | __ movl(Address(obj, index.AsX86().AsCpuRegister(), TIMES_8, data_offset), |
| 1621 | value.AsX86().AsRegisterPairLow()); |
| 1622 | __ movl(Address(obj, index.AsX86().AsCpuRegister(), TIMES_8, data_offset + kX86WordSize), |
| 1623 | value.AsX86().AsRegisterPairHigh()); |
| 1624 | } else { |
| 1625 | int64_t val = value.GetConstant()->AsLongConstant()->GetValue(); |
| 1626 | __ movl(Address(obj, index.AsX86().AsCpuRegister(), TIMES_8, data_offset), |
| 1627 | Immediate(Low32Bits(val))); |
| 1628 | __ movl(Address(obj, index.AsX86().AsCpuRegister(), TIMES_8, data_offset + kX86WordSize), |
| 1629 | Immediate(High32Bits(val))); |
| 1630 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1631 | } |
| 1632 | break; |
| 1633 | } |
| 1634 | |
| 1635 | case Primitive::kPrimFloat: |
| 1636 | case Primitive::kPrimDouble: |
| 1637 | LOG(FATAL) << "Unimplemented register type " << instruction->GetType(); |
| 1638 | |
| 1639 | case Primitive::kPrimVoid: |
| 1640 | LOG(FATAL) << "Unreachable type " << instruction->GetType(); |
| 1641 | } |
| 1642 | } |
| 1643 | |
| 1644 | void LocationsBuilderX86::VisitArrayLength(HArrayLength* instruction) { |
| 1645 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
Nicolas Geoffray | 9ae0daa | 2014-09-30 22:40:23 +0100 | [diff] [blame] | 1646 | locations->SetInAt(0, Location::RequiresRegister(), Location::kDiesAtEntry); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1647 | locations->SetOut(Location::RequiresRegister()); |
| 1648 | instruction->SetLocations(locations); |
| 1649 | } |
| 1650 | |
| 1651 | void InstructionCodeGeneratorX86::VisitArrayLength(HArrayLength* instruction) { |
| 1652 | LocationSummary* locations = instruction->GetLocations(); |
| 1653 | uint32_t offset = mirror::Array::LengthOffset().Uint32Value(); |
| 1654 | Register obj = locations->InAt(0).AsX86().AsCpuRegister(); |
| 1655 | Register out = locations->Out().AsX86().AsCpuRegister(); |
| 1656 | __ movl(out, Address(obj, offset)); |
| 1657 | } |
| 1658 | |
| 1659 | void LocationsBuilderX86::VisitBoundsCheck(HBoundsCheck* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1660 | LocationSummary* locations = |
| 1661 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1662 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1663 | locations->SetInAt(1, Location::RequiresRegister()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 1664 | if (instruction->HasUses()) { |
| 1665 | locations->SetOut(Location::SameAsFirstInput()); |
| 1666 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1667 | } |
| 1668 | |
| 1669 | void InstructionCodeGeneratorX86::VisitBoundsCheck(HBoundsCheck* instruction) { |
| 1670 | LocationSummary* locations = instruction->GetLocations(); |
| 1671 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) BoundsCheckSlowPathX86( |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1672 | instruction, locations->InAt(0), locations->InAt(1)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1673 | codegen_->AddSlowPath(slow_path); |
| 1674 | |
| 1675 | Register index = locations->InAt(0).AsX86().AsCpuRegister(); |
| 1676 | Register length = locations->InAt(1).AsX86().AsCpuRegister(); |
| 1677 | |
| 1678 | __ cmpl(index, length); |
| 1679 | __ j(kAboveEqual, slow_path->GetEntryLabel()); |
| 1680 | } |
| 1681 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1682 | void LocationsBuilderX86::VisitTemporary(HTemporary* temp) { |
| 1683 | temp->SetLocations(nullptr); |
| 1684 | } |
| 1685 | |
| 1686 | void InstructionCodeGeneratorX86::VisitTemporary(HTemporary* temp) { |
| 1687 | // Nothing to do, this is driven by the code generator. |
| 1688 | } |
| 1689 | |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 1690 | void LocationsBuilderX86::VisitParallelMove(HParallelMove* instruction) { |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 1691 | LOG(FATAL) << "Unreachable"; |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 1692 | } |
| 1693 | |
| 1694 | void InstructionCodeGeneratorX86::VisitParallelMove(HParallelMove* instruction) { |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 1695 | codegen_->GetMoveResolver()->EmitNativeCode(instruction); |
| 1696 | } |
| 1697 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 1698 | void LocationsBuilderX86::VisitSuspendCheck(HSuspendCheck* instruction) { |
| 1699 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath); |
| 1700 | } |
| 1701 | |
| 1702 | void InstructionCodeGeneratorX86::VisitSuspendCheck(HSuspendCheck* instruction) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1703 | HBasicBlock* block = instruction->GetBlock(); |
| 1704 | if (block->GetLoopInformation() != nullptr) { |
| 1705 | DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction); |
| 1706 | // The back edge will generate the suspend check. |
| 1707 | return; |
| 1708 | } |
| 1709 | if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) { |
| 1710 | // The goto will generate the suspend check. |
| 1711 | return; |
| 1712 | } |
| 1713 | GenerateSuspendCheck(instruction, nullptr); |
| 1714 | } |
| 1715 | |
| 1716 | void InstructionCodeGeneratorX86::GenerateSuspendCheck(HSuspendCheck* instruction, |
| 1717 | HBasicBlock* successor) { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 1718 | SuspendCheckSlowPathX86* slow_path = |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1719 | new (GetGraph()->GetArena()) SuspendCheckSlowPathX86(instruction, successor); |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 1720 | codegen_->AddSlowPath(slow_path); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1721 | __ fs()->cmpw(Address::Absolute( |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 1722 | Thread::ThreadFlagsOffset<kX86WordSize>().Int32Value()), Immediate(0)); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1723 | if (successor == nullptr) { |
| 1724 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 1725 | __ Bind(slow_path->GetReturnLabel()); |
| 1726 | } else { |
| 1727 | __ j(kEqual, codegen_->GetLabelOf(successor)); |
| 1728 | __ jmp(slow_path->GetEntryLabel()); |
| 1729 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 1730 | } |
| 1731 | |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 1732 | X86Assembler* ParallelMoveResolverX86::GetAssembler() const { |
| 1733 | return codegen_->GetAssembler(); |
| 1734 | } |
| 1735 | |
| 1736 | void ParallelMoveResolverX86::MoveMemoryToMemory(int dst, int src) { |
| 1737 | ScratchRegisterScope ensure_scratch( |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 1738 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 1739 | int stack_offset = ensure_scratch.IsSpilled() ? kX86WordSize : 0; |
| 1740 | __ movl(static_cast<Register>(ensure_scratch.GetRegister()), Address(ESP, src + stack_offset)); |
| 1741 | __ movl(Address(ESP, dst + stack_offset), static_cast<Register>(ensure_scratch.GetRegister())); |
| 1742 | } |
| 1743 | |
| 1744 | void ParallelMoveResolverX86::EmitMove(size_t index) { |
| 1745 | MoveOperands* move = moves_.Get(index); |
| 1746 | Location source = move->GetSource(); |
| 1747 | Location destination = move->GetDestination(); |
| 1748 | |
| 1749 | if (source.IsRegister()) { |
| 1750 | if (destination.IsRegister()) { |
| 1751 | __ movl(destination.AsX86().AsCpuRegister(), source.AsX86().AsCpuRegister()); |
| 1752 | } else { |
| 1753 | DCHECK(destination.IsStackSlot()); |
| 1754 | __ movl(Address(ESP, destination.GetStackIndex()), source.AsX86().AsCpuRegister()); |
| 1755 | } |
| 1756 | } else if (source.IsStackSlot()) { |
| 1757 | if (destination.IsRegister()) { |
| 1758 | __ movl(destination.AsX86().AsCpuRegister(), Address(ESP, source.GetStackIndex())); |
| 1759 | } else { |
| 1760 | DCHECK(destination.IsStackSlot()); |
| 1761 | MoveMemoryToMemory(destination.GetStackIndex(), |
| 1762 | source.GetStackIndex()); |
| 1763 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1764 | } else if (source.IsConstant()) { |
| 1765 | HIntConstant* instruction = source.GetConstant()->AsIntConstant(); |
| 1766 | Immediate imm(instruction->AsIntConstant()->GetValue()); |
| 1767 | if (destination.IsRegister()) { |
| 1768 | __ movl(destination.AsX86().AsCpuRegister(), imm); |
| 1769 | } else { |
| 1770 | __ movl(Address(ESP, destination.GetStackIndex()), imm); |
| 1771 | } |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 1772 | } else { |
| 1773 | LOG(FATAL) << "Unimplemented"; |
| 1774 | } |
| 1775 | } |
| 1776 | |
| 1777 | void ParallelMoveResolverX86::Exchange(Register reg, int mem) { |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 1778 | Register suggested_scratch = reg == EAX ? EBX : EAX; |
| 1779 | ScratchRegisterScope ensure_scratch( |
| 1780 | this, reg, suggested_scratch, codegen_->GetNumberOfCoreRegisters()); |
| 1781 | |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 1782 | int stack_offset = ensure_scratch.IsSpilled() ? kX86WordSize : 0; |
| 1783 | __ movl(static_cast<Register>(ensure_scratch.GetRegister()), Address(ESP, mem + stack_offset)); |
| 1784 | __ movl(Address(ESP, mem + stack_offset), reg); |
| 1785 | __ movl(reg, static_cast<Register>(ensure_scratch.GetRegister())); |
| 1786 | } |
| 1787 | |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 1788 | void ParallelMoveResolverX86::Exchange(int mem1, int mem2) { |
| 1789 | ScratchRegisterScope ensure_scratch1( |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 1790 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
| 1791 | |
| 1792 | Register suggested_scratch = ensure_scratch1.GetRegister() == EAX ? EBX : EAX; |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 1793 | ScratchRegisterScope ensure_scratch2( |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 1794 | this, ensure_scratch1.GetRegister(), suggested_scratch, codegen_->GetNumberOfCoreRegisters()); |
| 1795 | |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 1796 | int stack_offset = ensure_scratch1.IsSpilled() ? kX86WordSize : 0; |
| 1797 | stack_offset += ensure_scratch2.IsSpilled() ? kX86WordSize : 0; |
| 1798 | __ movl(static_cast<Register>(ensure_scratch1.GetRegister()), Address(ESP, mem1 + stack_offset)); |
| 1799 | __ movl(static_cast<Register>(ensure_scratch2.GetRegister()), Address(ESP, mem2 + stack_offset)); |
| 1800 | __ movl(Address(ESP, mem2 + stack_offset), static_cast<Register>(ensure_scratch1.GetRegister())); |
| 1801 | __ movl(Address(ESP, mem1 + stack_offset), static_cast<Register>(ensure_scratch2.GetRegister())); |
| 1802 | } |
| 1803 | |
| 1804 | void ParallelMoveResolverX86::EmitSwap(size_t index) { |
| 1805 | MoveOperands* move = moves_.Get(index); |
| 1806 | Location source = move->GetSource(); |
| 1807 | Location destination = move->GetDestination(); |
| 1808 | |
| 1809 | if (source.IsRegister() && destination.IsRegister()) { |
| 1810 | __ xchgl(destination.AsX86().AsCpuRegister(), source.AsX86().AsCpuRegister()); |
| 1811 | } else if (source.IsRegister() && destination.IsStackSlot()) { |
| 1812 | Exchange(source.AsX86().AsCpuRegister(), destination.GetStackIndex()); |
| 1813 | } else if (source.IsStackSlot() && destination.IsRegister()) { |
| 1814 | Exchange(destination.AsX86().AsCpuRegister(), source.GetStackIndex()); |
| 1815 | } else if (source.IsStackSlot() && destination.IsStackSlot()) { |
| 1816 | Exchange(destination.GetStackIndex(), source.GetStackIndex()); |
| 1817 | } else { |
| 1818 | LOG(FATAL) << "Unimplemented"; |
| 1819 | } |
| 1820 | } |
| 1821 | |
| 1822 | void ParallelMoveResolverX86::SpillScratch(int reg) { |
| 1823 | __ pushl(static_cast<Register>(reg)); |
| 1824 | } |
| 1825 | |
| 1826 | void ParallelMoveResolverX86::RestoreScratch(int reg) { |
| 1827 | __ popl(static_cast<Register>(reg)); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 1828 | } |
| 1829 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1830 | } // namespace x86 |
| 1831 | } // namespace art |