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" |
| 18 | #include "utils/assembler.h" |
| 19 | #include "utils/x86/assembler_x86.h" |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 20 | #include "utils/x86/managed_register_x86.h" |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 21 | |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 22 | #include "entrypoints/quick/quick_entrypoints.h" |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 23 | #include "mirror/array.h" |
| 24 | #include "mirror/art_method.h" |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 25 | #include "thread.h" |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 26 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 27 | #define __ reinterpret_cast<X86Assembler*>(GetAssembler())-> |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 28 | |
| 29 | namespace art { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 30 | |
| 31 | x86::X86ManagedRegister Location::AsX86() const { |
| 32 | return reg().AsX86(); |
| 33 | } |
| 34 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 35 | namespace x86 { |
| 36 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 37 | inline Condition X86Condition(IfCondition cond) { |
| 38 | switch (cond) { |
| 39 | case kCondEQ: return kEqual; |
| 40 | case kCondNE: return kNotEqual; |
| 41 | case kCondLT: return kLess; |
| 42 | case kCondLE: return kLessEqual; |
| 43 | case kCondGT: return kGreater; |
| 44 | case kCondGE: return kGreaterEqual; |
| 45 | default: |
| 46 | LOG(FATAL) << "Unknown if condition"; |
| 47 | } |
| 48 | return kEqual; |
| 49 | } |
| 50 | |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 51 | static constexpr int kNumberOfPushedRegistersAtEntry = 1; |
| 52 | static constexpr int kCurrentMethodStackOffset = 0; |
| 53 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 54 | void CodeGeneratorX86::DumpCoreRegister(std::ostream& stream, int reg) const { |
| 55 | stream << X86ManagedRegister::FromCpuRegister(Register(reg)); |
| 56 | } |
| 57 | |
| 58 | void CodeGeneratorX86::DumpFloatingPointRegister(std::ostream& stream, int reg) const { |
| 59 | stream << X86ManagedRegister::FromXmmRegister(XmmRegister(reg)); |
| 60 | } |
| 61 | |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 62 | CodeGeneratorX86::CodeGeneratorX86(HGraph* graph) |
| 63 | : CodeGenerator(graph, kNumberOfRegIds), |
| 64 | location_builder_(graph, this), |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 65 | instruction_visitor_(graph, this), |
| 66 | move_resolver_(graph->GetArena(), this) {} |
| 67 | |
| 68 | void CodeGeneratorX86::ComputeFrameSize(size_t number_of_spill_slots) { |
| 69 | SetFrameSize(RoundUp( |
| 70 | number_of_spill_slots * kVRegSize |
| 71 | + kVRegSize // Art method |
| 72 | + kNumberOfPushedRegistersAtEntry * kX86WordSize, |
| 73 | kStackAlignment)); |
| 74 | } |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 75 | |
| 76 | static bool* GetBlockedRegisterPairs(bool* blocked_registers) { |
| 77 | return blocked_registers + kNumberOfAllocIds; |
| 78 | } |
| 79 | |
| 80 | ManagedRegister CodeGeneratorX86::AllocateFreeRegister(Primitive::Type type, |
| 81 | bool* blocked_registers) const { |
| 82 | switch (type) { |
| 83 | case Primitive::kPrimLong: { |
| 84 | size_t reg = AllocateFreeRegisterInternal( |
| 85 | GetBlockedRegisterPairs(blocked_registers), kNumberOfRegisterPairs); |
| 86 | X86ManagedRegister pair = |
| 87 | X86ManagedRegister::FromRegisterPair(static_cast<RegisterPair>(reg)); |
| 88 | blocked_registers[pair.AsRegisterPairLow()] = true; |
| 89 | blocked_registers[pair.AsRegisterPairHigh()] = true; |
| 90 | return pair; |
| 91 | } |
| 92 | |
| 93 | case Primitive::kPrimByte: |
| 94 | case Primitive::kPrimBoolean: |
| 95 | case Primitive::kPrimChar: |
| 96 | case Primitive::kPrimShort: |
| 97 | case Primitive::kPrimInt: |
| 98 | case Primitive::kPrimNot: { |
| 99 | size_t reg = AllocateFreeRegisterInternal(blocked_registers, kNumberOfCpuRegisters); |
| 100 | return X86ManagedRegister::FromCpuRegister(static_cast<Register>(reg)); |
| 101 | } |
| 102 | |
| 103 | case Primitive::kPrimFloat: |
| 104 | case Primitive::kPrimDouble: |
| 105 | LOG(FATAL) << "Unimplemented register type " << type; |
| 106 | |
| 107 | case Primitive::kPrimVoid: |
| 108 | LOG(FATAL) << "Unreachable type " << type; |
| 109 | } |
| 110 | |
| 111 | return ManagedRegister::NoRegister(); |
| 112 | } |
| 113 | |
| 114 | void CodeGeneratorX86::SetupBlockedRegisters(bool* blocked_registers) const { |
| 115 | bool* blocked_register_pairs = GetBlockedRegisterPairs(blocked_registers); |
| 116 | |
| 117 | // Don't allocate the dalvik style register pair passing. |
| 118 | blocked_register_pairs[ECX_EDX] = true; |
| 119 | |
| 120 | // Stack register is always reserved. |
| 121 | blocked_registers[ESP] = true; |
| 122 | |
| 123 | // TODO: We currently don't use Quick's callee saved registers. |
| 124 | blocked_registers[EBP] = true; |
| 125 | blocked_registers[ESI] = true; |
| 126 | blocked_registers[EDI] = true; |
| 127 | blocked_register_pairs[EAX_EDI] = true; |
| 128 | blocked_register_pairs[EDX_EDI] = true; |
| 129 | blocked_register_pairs[ECX_EDI] = true; |
| 130 | blocked_register_pairs[EBX_EDI] = true; |
| 131 | } |
| 132 | |
| 133 | size_t CodeGeneratorX86::GetNumberOfRegisters() const { |
| 134 | return kNumberOfRegIds; |
| 135 | } |
| 136 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 137 | static Location X86CpuLocation(Register reg) { |
| 138 | return Location::RegisterLocation(X86ManagedRegister::FromCpuRegister(reg)); |
| 139 | } |
| 140 | |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 141 | InstructionCodeGeneratorX86::InstructionCodeGeneratorX86(HGraph* graph, CodeGeneratorX86* codegen) |
| 142 | : HGraphVisitor(graph), |
| 143 | assembler_(codegen->GetAssembler()), |
| 144 | codegen_(codegen) {} |
| 145 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 146 | void CodeGeneratorX86::GenerateFrameEntry() { |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 147 | // Create a fake register to mimic Quick. |
| 148 | static const int kFakeReturnRegister = 8; |
| 149 | core_spill_mask_ |= (1 << kFakeReturnRegister); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 150 | |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 151 | // The return PC has already been pushed on the stack. |
Nicolas Geoffray | 707c809 | 2014-04-04 10:50:14 +0100 | [diff] [blame] | 152 | __ subl(ESP, Immediate(GetFrameSize() - kNumberOfPushedRegistersAtEntry * kX86WordSize)); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 153 | __ movl(Address(ESP, kCurrentMethodStackOffset), EAX); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 154 | } |
| 155 | |
| 156 | void CodeGeneratorX86::GenerateFrameExit() { |
Nicolas Geoffray | 707c809 | 2014-04-04 10:50:14 +0100 | [diff] [blame] | 157 | __ addl(ESP, Immediate(GetFrameSize() - kNumberOfPushedRegistersAtEntry * kX86WordSize)); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 158 | } |
| 159 | |
| 160 | void CodeGeneratorX86::Bind(Label* label) { |
| 161 | __ Bind(label); |
| 162 | } |
| 163 | |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 164 | void InstructionCodeGeneratorX86::LoadCurrentMethod(Register reg) { |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 165 | __ movl(reg, Address(ESP, kCurrentMethodStackOffset)); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 166 | } |
| 167 | |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 168 | int32_t CodeGeneratorX86::GetStackSlot(HLocal* local) const { |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 169 | uint16_t reg_number = local->GetRegNumber(); |
| 170 | uint16_t number_of_vregs = GetGraph()->GetNumberOfVRegs(); |
| 171 | uint16_t number_of_in_vregs = GetGraph()->GetNumberOfInVRegs(); |
| 172 | if (reg_number >= number_of_vregs - number_of_in_vregs) { |
| 173 | // Local is a parameter of the method. It is stored in the caller's frame. |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 174 | return GetFrameSize() + kVRegSize // ART method |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 175 | + (reg_number - number_of_vregs + number_of_in_vregs) * kVRegSize; |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 176 | } else { |
| 177 | // Local is a temporary in this method. It is stored in this method's frame. |
| 178 | return GetFrameSize() - (kNumberOfPushedRegistersAtEntry * kX86WordSize) |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 179 | - kVRegSize // filler. |
| 180 | - (number_of_vregs * kVRegSize) |
| 181 | + (reg_number * kVRegSize); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 182 | } |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 183 | } |
| 184 | |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 185 | |
| 186 | Location CodeGeneratorX86::GetStackLocation(HLoadLocal* load) const { |
| 187 | switch (load->GetType()) { |
| 188 | case Primitive::kPrimLong: |
| 189 | return Location::DoubleStackSlot(GetStackSlot(load->GetLocal())); |
| 190 | break; |
| 191 | |
| 192 | case Primitive::kPrimInt: |
| 193 | case Primitive::kPrimNot: |
| 194 | return Location::StackSlot(GetStackSlot(load->GetLocal())); |
| 195 | |
| 196 | case Primitive::kPrimFloat: |
| 197 | case Primitive::kPrimDouble: |
| 198 | LOG(FATAL) << "Unimplemented type " << load->GetType(); |
| 199 | |
| 200 | case Primitive::kPrimBoolean: |
| 201 | case Primitive::kPrimByte: |
| 202 | case Primitive::kPrimChar: |
| 203 | case Primitive::kPrimShort: |
| 204 | case Primitive::kPrimVoid: |
| 205 | LOG(FATAL) << "Unexpected type " << load->GetType(); |
| 206 | } |
| 207 | |
| 208 | LOG(FATAL) << "Unreachable"; |
| 209 | return Location(); |
| 210 | } |
| 211 | |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 212 | static constexpr Register kRuntimeParameterCoreRegisters[] = { EAX, ECX, EDX }; |
| 213 | static constexpr size_t kRuntimeParameterCoreRegistersLength = |
| 214 | arraysize(kRuntimeParameterCoreRegisters); |
| 215 | |
| 216 | class InvokeRuntimeCallingConvention : public CallingConvention<Register> { |
| 217 | public: |
| 218 | InvokeRuntimeCallingConvention() |
| 219 | : CallingConvention(kRuntimeParameterCoreRegisters, |
| 220 | kRuntimeParameterCoreRegistersLength) {} |
| 221 | |
| 222 | private: |
| 223 | DISALLOW_COPY_AND_ASSIGN(InvokeRuntimeCallingConvention); |
| 224 | }; |
| 225 | |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 226 | Location InvokeDexCallingConventionVisitor::GetNextLocation(Primitive::Type type) { |
| 227 | switch (type) { |
| 228 | case Primitive::kPrimBoolean: |
| 229 | case Primitive::kPrimByte: |
| 230 | case Primitive::kPrimChar: |
| 231 | case Primitive::kPrimShort: |
| 232 | case Primitive::kPrimInt: |
| 233 | case Primitive::kPrimNot: { |
| 234 | uint32_t index = gp_index_++; |
| 235 | if (index < calling_convention.GetNumberOfRegisters()) { |
| 236 | return X86CpuLocation(calling_convention.GetRegisterAt(index)); |
| 237 | } else { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 238 | return Location::StackSlot(calling_convention.GetStackOffsetOf(index)); |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 239 | } |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 240 | } |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 241 | |
| 242 | case Primitive::kPrimLong: { |
| 243 | uint32_t index = gp_index_; |
| 244 | gp_index_ += 2; |
| 245 | if (index + 1 < calling_convention.GetNumberOfRegisters()) { |
| 246 | return Location::RegisterLocation(X86ManagedRegister::FromRegisterPair( |
| 247 | calling_convention.GetRegisterPairAt(index))); |
| 248 | } else if (index + 1 == calling_convention.GetNumberOfRegisters()) { |
| 249 | return Location::QuickParameter(index); |
| 250 | } else { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 251 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(index)); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 252 | } |
| 253 | } |
| 254 | |
| 255 | case Primitive::kPrimDouble: |
| 256 | case Primitive::kPrimFloat: |
| 257 | LOG(FATAL) << "Unimplemented parameter type " << type; |
| 258 | break; |
| 259 | |
| 260 | case Primitive::kPrimVoid: |
| 261 | LOG(FATAL) << "Unexpected parameter type " << type; |
| 262 | break; |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 263 | } |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 264 | return Location(); |
| 265 | } |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 266 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 267 | void CodeGeneratorX86::Move32(Location destination, Location source) { |
| 268 | if (source.Equals(destination)) { |
| 269 | return; |
| 270 | } |
| 271 | if (destination.IsRegister()) { |
| 272 | if (source.IsRegister()) { |
| 273 | __ movl(destination.AsX86().AsCpuRegister(), source.AsX86().AsCpuRegister()); |
| 274 | } else { |
| 275 | DCHECK(source.IsStackSlot()); |
| 276 | __ movl(destination.AsX86().AsCpuRegister(), Address(ESP, source.GetStackIndex())); |
| 277 | } |
| 278 | } else { |
| 279 | if (source.IsRegister()) { |
| 280 | __ movl(Address(ESP, destination.GetStackIndex()), source.AsX86().AsCpuRegister()); |
| 281 | } else { |
| 282 | DCHECK(source.IsStackSlot()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 283 | __ pushl(Address(ESP, source.GetStackIndex())); |
| 284 | __ popl(Address(ESP, destination.GetStackIndex())); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 285 | } |
| 286 | } |
| 287 | } |
| 288 | |
| 289 | void CodeGeneratorX86::Move64(Location destination, Location source) { |
| 290 | if (source.Equals(destination)) { |
| 291 | return; |
| 292 | } |
| 293 | if (destination.IsRegister()) { |
| 294 | if (source.IsRegister()) { |
| 295 | __ movl(destination.AsX86().AsRegisterPairLow(), source.AsX86().AsRegisterPairLow()); |
| 296 | __ movl(destination.AsX86().AsRegisterPairHigh(), source.AsX86().AsRegisterPairHigh()); |
| 297 | } else if (source.IsQuickParameter()) { |
| 298 | uint32_t argument_index = source.GetQuickParameterIndex(); |
| 299 | InvokeDexCallingConvention calling_convention; |
| 300 | __ movl(destination.AsX86().AsRegisterPairLow(), |
| 301 | calling_convention.GetRegisterAt(argument_index)); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 302 | __ movl(destination.AsX86().AsRegisterPairHigh(), Address(ESP, |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 303 | calling_convention.GetStackOffsetOf(argument_index + 1) + GetFrameSize())); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 304 | } else { |
| 305 | DCHECK(source.IsDoubleStackSlot()); |
| 306 | __ movl(destination.AsX86().AsRegisterPairLow(), Address(ESP, source.GetStackIndex())); |
| 307 | __ movl(destination.AsX86().AsRegisterPairHigh(), |
| 308 | Address(ESP, source.GetHighStackIndex(kX86WordSize))); |
| 309 | } |
| 310 | } else if (destination.IsQuickParameter()) { |
| 311 | InvokeDexCallingConvention calling_convention; |
| 312 | uint32_t argument_index = destination.GetQuickParameterIndex(); |
| 313 | if (source.IsRegister()) { |
| 314 | __ movl(calling_convention.GetRegisterAt(argument_index), source.AsX86().AsRegisterPairLow()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 315 | __ movl(Address(ESP, calling_convention.GetStackOffsetOf(argument_index + 1)), |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 316 | source.AsX86().AsRegisterPairHigh()); |
| 317 | } else { |
| 318 | DCHECK(source.IsDoubleStackSlot()); |
| 319 | __ movl(calling_convention.GetRegisterAt(argument_index), |
| 320 | Address(ESP, source.GetStackIndex())); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 321 | __ pushl(Address(ESP, source.GetHighStackIndex(kX86WordSize))); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 322 | __ popl(Address(ESP, calling_convention.GetStackOffsetOf(argument_index + 1))); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 323 | } |
| 324 | } else { |
| 325 | if (source.IsRegister()) { |
| 326 | __ movl(Address(ESP, destination.GetStackIndex()), source.AsX86().AsRegisterPairLow()); |
| 327 | __ movl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)), |
| 328 | source.AsX86().AsRegisterPairHigh()); |
| 329 | } else if (source.IsQuickParameter()) { |
| 330 | InvokeDexCallingConvention calling_convention; |
| 331 | uint32_t argument_index = source.GetQuickParameterIndex(); |
| 332 | __ movl(Address(ESP, destination.GetStackIndex()), |
| 333 | calling_convention.GetRegisterAt(argument_index)); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 334 | __ pushl(Address(ESP, |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 335 | calling_convention.GetStackOffsetOf(argument_index + 1) + GetFrameSize())); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 336 | __ popl(Address(ESP, destination.GetHighStackIndex(kX86WordSize))); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 337 | } else { |
| 338 | DCHECK(source.IsDoubleStackSlot()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 339 | __ pushl(Address(ESP, source.GetStackIndex())); |
| 340 | __ popl(Address(ESP, destination.GetStackIndex())); |
| 341 | __ pushl(Address(ESP, source.GetHighStackIndex(kX86WordSize))); |
| 342 | __ popl(Address(ESP, destination.GetHighStackIndex(kX86WordSize))); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 343 | } |
| 344 | } |
| 345 | } |
| 346 | |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 347 | void CodeGeneratorX86::Move(HInstruction* instruction, Location location, HInstruction* move_for) { |
| 348 | if (instruction->AsIntConstant() != nullptr) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 349 | Immediate imm(instruction->AsIntConstant()->GetValue()); |
| 350 | if (location.IsRegister()) { |
| 351 | __ movl(location.AsX86().AsCpuRegister(), imm); |
| 352 | } else { |
| 353 | __ movl(Address(ESP, location.GetStackIndex()), imm); |
| 354 | } |
| 355 | } else if (instruction->AsLongConstant() != nullptr) { |
| 356 | int64_t value = instruction->AsLongConstant()->GetValue(); |
| 357 | if (location.IsRegister()) { |
| 358 | __ movl(location.AsX86().AsRegisterPairLow(), Immediate(Low32Bits(value))); |
| 359 | __ movl(location.AsX86().AsRegisterPairHigh(), Immediate(High32Bits(value))); |
| 360 | } else { |
| 361 | __ movl(Address(ESP, location.GetStackIndex()), Immediate(Low32Bits(value))); |
| 362 | __ movl(Address(ESP, location.GetHighStackIndex(kX86WordSize)), Immediate(High32Bits(value))); |
| 363 | } |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 364 | } else if (instruction->AsLoadLocal() != nullptr) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 365 | switch (instruction->GetType()) { |
| 366 | case Primitive::kPrimBoolean: |
| 367 | case Primitive::kPrimByte: |
| 368 | case Primitive::kPrimChar: |
| 369 | case Primitive::kPrimShort: |
| 370 | case Primitive::kPrimInt: |
| 371 | case Primitive::kPrimNot: |
| 372 | Move32(location, Location::StackSlot(GetStackSlot(instruction->AsLoadLocal()->GetLocal()))); |
| 373 | break; |
| 374 | |
| 375 | case Primitive::kPrimLong: |
| 376 | Move64(location, Location::DoubleStackSlot( |
| 377 | GetStackSlot(instruction->AsLoadLocal()->GetLocal()))); |
| 378 | break; |
| 379 | |
| 380 | default: |
| 381 | LOG(FATAL) << "Unimplemented local type " << instruction->GetType(); |
| 382 | } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 383 | } else { |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 384 | // This can currently only happen when the instruction that requests the move |
| 385 | // is the next to be compiled. |
| 386 | DCHECK_EQ(instruction->GetNext(), move_for); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 387 | switch (instruction->GetType()) { |
| 388 | case Primitive::kPrimBoolean: |
| 389 | case Primitive::kPrimByte: |
| 390 | case Primitive::kPrimChar: |
| 391 | case Primitive::kPrimShort: |
| 392 | case Primitive::kPrimInt: |
| 393 | case Primitive::kPrimNot: |
| 394 | Move32(location, instruction->GetLocations()->Out()); |
| 395 | break; |
| 396 | |
| 397 | case Primitive::kPrimLong: |
| 398 | Move64(location, instruction->GetLocations()->Out()); |
| 399 | break; |
| 400 | |
| 401 | default: |
| 402 | LOG(FATAL) << "Unimplemented type " << instruction->GetType(); |
| 403 | } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 404 | } |
| 405 | } |
| 406 | |
| 407 | void LocationsBuilderX86::VisitGoto(HGoto* got) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 408 | got->SetLocations(nullptr); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 409 | } |
| 410 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 411 | void InstructionCodeGeneratorX86::VisitGoto(HGoto* got) { |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 412 | HBasicBlock* successor = got->GetSuccessor(); |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 413 | if (GetGraph()->GetExitBlock() == successor) { |
| 414 | codegen_->GenerateFrameExit(); |
| 415 | } else if (!codegen_->GoesToNextBlock(got->GetBlock(), successor)) { |
| 416 | __ jmp(codegen_->GetLabelOf(successor)); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 417 | } |
| 418 | } |
| 419 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 420 | void LocationsBuilderX86::VisitExit(HExit* exit) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 421 | exit->SetLocations(nullptr); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 422 | } |
| 423 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 424 | void InstructionCodeGeneratorX86::VisitExit(HExit* exit) { |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 425 | if (kIsDebugBuild) { |
| 426 | __ Comment("Unreachable"); |
| 427 | __ int3(); |
| 428 | } |
| 429 | } |
| 430 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 431 | void LocationsBuilderX86::VisitIf(HIf* if_instr) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 432 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(if_instr); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 433 | locations->SetInAt(0, Location::Any()); |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 434 | if_instr->SetLocations(locations); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 435 | } |
| 436 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 437 | void InstructionCodeGeneratorX86::VisitIf(HIf* if_instr) { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 438 | HInstruction* cond = if_instr->InputAt(0); |
| 439 | DCHECK(cond->IsCondition()); |
| 440 | HCondition* condition = cond->AsCondition(); |
| 441 | if (condition->NeedsMaterialization()) { |
| 442 | // Materialized condition, compare against 0 |
| 443 | Location lhs = if_instr->GetLocations()->InAt(0); |
| 444 | if (lhs.IsRegister()) { |
| 445 | __ cmpl(lhs.AsX86().AsCpuRegister(), Immediate(0)); |
| 446 | } else { |
| 447 | __ cmpl(Address(ESP, lhs.GetStackIndex()), Immediate(0)); |
| 448 | } |
| 449 | __ j(kEqual, codegen_->GetLabelOf(if_instr->IfTrueSuccessor())); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 450 | } else { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 451 | Location lhs = condition->GetLocations()->InAt(0); |
| 452 | Location rhs = condition->GetLocations()->InAt(1); |
| 453 | // LHS is guaranteed to be in a register (see LocationsBuilderX86::VisitCondition). |
| 454 | if (rhs.IsRegister()) { |
| 455 | __ cmpl(lhs.AsX86().AsCpuRegister(), rhs.AsX86().AsCpuRegister()); |
| 456 | } else { |
| 457 | __ cmpl(lhs.AsX86().AsCpuRegister(), Address(ESP, rhs.GetStackIndex())); |
| 458 | } |
| 459 | __ j(X86Condition(condition->GetCondition()), |
| 460 | codegen_->GetLabelOf(if_instr->IfTrueSuccessor())); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 461 | } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 462 | if (!codegen_->GoesToNextBlock(if_instr->GetBlock(), if_instr->IfFalseSuccessor())) { |
| 463 | __ jmp(codegen_->GetLabelOf(if_instr->IfFalseSuccessor())); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 464 | } |
| 465 | } |
| 466 | |
| 467 | void LocationsBuilderX86::VisitLocal(HLocal* local) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 468 | local->SetLocations(nullptr); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 469 | } |
| 470 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 471 | void InstructionCodeGeneratorX86::VisitLocal(HLocal* local) { |
| 472 | DCHECK_EQ(local->GetBlock(), GetGraph()->GetEntryBlock()); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 473 | } |
| 474 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 475 | void LocationsBuilderX86::VisitLoadLocal(HLoadLocal* local) { |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 476 | local->SetLocations(nullptr); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 477 | } |
| 478 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 479 | void InstructionCodeGeneratorX86::VisitLoadLocal(HLoadLocal* load) { |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 480 | // Nothing to do, this is driven by the code generator. |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 481 | } |
| 482 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 483 | void LocationsBuilderX86::VisitStoreLocal(HStoreLocal* store) { |
| 484 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(store); |
| 485 | switch (store->InputAt(1)->GetType()) { |
| 486 | case Primitive::kPrimBoolean: |
| 487 | case Primitive::kPrimByte: |
| 488 | case Primitive::kPrimChar: |
| 489 | case Primitive::kPrimShort: |
| 490 | case Primitive::kPrimInt: |
| 491 | case Primitive::kPrimNot: |
| 492 | locations->SetInAt(1, Location::StackSlot(codegen_->GetStackSlot(store->GetLocal()))); |
| 493 | break; |
| 494 | |
| 495 | case Primitive::kPrimLong: |
| 496 | locations->SetInAt(1, Location::DoubleStackSlot(codegen_->GetStackSlot(store->GetLocal()))); |
| 497 | break; |
| 498 | |
| 499 | default: |
| 500 | LOG(FATAL) << "Unimplemented local type " << store->InputAt(1)->GetType(); |
| 501 | } |
| 502 | store->SetLocations(locations); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 503 | } |
| 504 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 505 | void InstructionCodeGeneratorX86::VisitStoreLocal(HStoreLocal* store) { |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 506 | } |
| 507 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 508 | void LocationsBuilderX86::VisitCondition(HCondition* comp) { |
| 509 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(comp); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 510 | locations->SetInAt(0, Location::RequiresRegister()); |
| 511 | locations->SetInAt(1, Location::Any()); |
| 512 | locations->SetOut(Location::SameAsFirstInput()); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 513 | comp->SetLocations(locations); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 514 | } |
| 515 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 516 | void InstructionCodeGeneratorX86::VisitCondition(HCondition* comp) { |
| 517 | if (comp->NeedsMaterialization()) { |
| 518 | LocationSummary* locations = comp->GetLocations(); |
| 519 | if (locations->InAt(1).IsRegister()) { |
| 520 | __ cmpl(locations->InAt(0).AsX86().AsCpuRegister(), |
| 521 | locations->InAt(1).AsX86().AsCpuRegister()); |
| 522 | } else { |
| 523 | __ cmpl(locations->InAt(0).AsX86().AsCpuRegister(), |
| 524 | Address(ESP, locations->InAt(1).GetStackIndex())); |
| 525 | } |
| 526 | __ setb(X86Condition(comp->GetCondition()), locations->Out().AsX86().AsCpuRegister()); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 527 | } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 528 | } |
| 529 | |
| 530 | void LocationsBuilderX86::VisitEqual(HEqual* comp) { |
| 531 | VisitCondition(comp); |
| 532 | } |
| 533 | |
| 534 | void InstructionCodeGeneratorX86::VisitEqual(HEqual* comp) { |
| 535 | VisitCondition(comp); |
| 536 | } |
| 537 | |
| 538 | void LocationsBuilderX86::VisitNotEqual(HNotEqual* comp) { |
| 539 | VisitCondition(comp); |
| 540 | } |
| 541 | |
| 542 | void InstructionCodeGeneratorX86::VisitNotEqual(HNotEqual* comp) { |
| 543 | VisitCondition(comp); |
| 544 | } |
| 545 | |
| 546 | void LocationsBuilderX86::VisitLessThan(HLessThan* comp) { |
| 547 | VisitCondition(comp); |
| 548 | } |
| 549 | |
| 550 | void InstructionCodeGeneratorX86::VisitLessThan(HLessThan* comp) { |
| 551 | VisitCondition(comp); |
| 552 | } |
| 553 | |
| 554 | void LocationsBuilderX86::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
| 555 | VisitCondition(comp); |
| 556 | } |
| 557 | |
| 558 | void InstructionCodeGeneratorX86::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
| 559 | VisitCondition(comp); |
| 560 | } |
| 561 | |
| 562 | void LocationsBuilderX86::VisitGreaterThan(HGreaterThan* comp) { |
| 563 | VisitCondition(comp); |
| 564 | } |
| 565 | |
| 566 | void InstructionCodeGeneratorX86::VisitGreaterThan(HGreaterThan* comp) { |
| 567 | VisitCondition(comp); |
| 568 | } |
| 569 | |
| 570 | void LocationsBuilderX86::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
| 571 | VisitCondition(comp); |
| 572 | } |
| 573 | |
| 574 | void InstructionCodeGeneratorX86::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
| 575 | VisitCondition(comp); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 576 | } |
| 577 | |
| 578 | void LocationsBuilderX86::VisitIntConstant(HIntConstant* constant) { |
Nicolas Geoffray | 31d76b4 | 2014-06-09 15:02:22 +0100 | [diff] [blame] | 579 | // TODO: Support constant locations. |
| 580 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(constant); |
| 581 | locations->SetOut(Location::RequiresRegister()); |
| 582 | constant->SetLocations(locations); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 583 | } |
| 584 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 585 | void InstructionCodeGeneratorX86::VisitIntConstant(HIntConstant* constant) { |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 586 | codegen_->Move(constant, constant->GetLocations()->Out(), nullptr); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 587 | } |
| 588 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 589 | void LocationsBuilderX86::VisitLongConstant(HLongConstant* constant) { |
Nicolas Geoffray | 31d76b4 | 2014-06-09 15:02:22 +0100 | [diff] [blame] | 590 | // TODO: Support constant locations. |
| 591 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(constant); |
| 592 | locations->SetOut(Location::RequiresRegister()); |
| 593 | constant->SetLocations(locations); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 594 | } |
| 595 | |
| 596 | void InstructionCodeGeneratorX86::VisitLongConstant(HLongConstant* constant) { |
| 597 | // Will be generated at use site. |
| 598 | } |
| 599 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 600 | void LocationsBuilderX86::VisitReturnVoid(HReturnVoid* ret) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 601 | ret->SetLocations(nullptr); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 602 | } |
| 603 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 604 | void InstructionCodeGeneratorX86::VisitReturnVoid(HReturnVoid* ret) { |
| 605 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 606 | __ ret(); |
| 607 | } |
| 608 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 609 | void LocationsBuilderX86::VisitReturn(HReturn* ret) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 610 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(ret); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 611 | switch (ret->InputAt(0)->GetType()) { |
| 612 | case Primitive::kPrimBoolean: |
| 613 | case Primitive::kPrimByte: |
| 614 | case Primitive::kPrimChar: |
| 615 | case Primitive::kPrimShort: |
| 616 | case Primitive::kPrimInt: |
| 617 | case Primitive::kPrimNot: |
| 618 | locations->SetInAt(0, X86CpuLocation(EAX)); |
| 619 | break; |
| 620 | |
| 621 | case Primitive::kPrimLong: |
| 622 | locations->SetInAt( |
| 623 | 0, Location::RegisterLocation(X86ManagedRegister::FromRegisterPair(EAX_EDX))); |
| 624 | break; |
| 625 | |
| 626 | default: |
| 627 | LOG(FATAL) << "Unimplemented return type " << ret->InputAt(0)->GetType(); |
| 628 | } |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 629 | ret->SetLocations(locations); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 630 | } |
| 631 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 632 | void InstructionCodeGeneratorX86::VisitReturn(HReturn* ret) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 633 | if (kIsDebugBuild) { |
| 634 | switch (ret->InputAt(0)->GetType()) { |
| 635 | case Primitive::kPrimBoolean: |
| 636 | case Primitive::kPrimByte: |
| 637 | case Primitive::kPrimChar: |
| 638 | case Primitive::kPrimShort: |
| 639 | case Primitive::kPrimInt: |
| 640 | case Primitive::kPrimNot: |
| 641 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsX86().AsCpuRegister(), EAX); |
| 642 | break; |
| 643 | |
| 644 | case Primitive::kPrimLong: |
| 645 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsX86().AsRegisterPair(), EAX_EDX); |
| 646 | break; |
| 647 | |
| 648 | default: |
| 649 | LOG(FATAL) << "Unimplemented return type " << ret->InputAt(0)->GetType(); |
| 650 | } |
| 651 | } |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 652 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 653 | __ ret(); |
| 654 | } |
| 655 | |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 656 | void LocationsBuilderX86::VisitInvokeStatic(HInvokeStatic* invoke) { |
| 657 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(invoke); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 658 | locations->AddTemp(X86CpuLocation(EAX)); |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 659 | |
| 660 | InvokeDexCallingConventionVisitor calling_convention_visitor; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 661 | for (size_t i = 0; i < invoke->InputCount(); i++) { |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 662 | HInstruction* input = invoke->InputAt(i); |
| 663 | locations->SetInAt(i, calling_convention_visitor.GetNextLocation(input->GetType())); |
| 664 | } |
| 665 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 666 | switch (invoke->GetType()) { |
| 667 | case Primitive::kPrimBoolean: |
| 668 | case Primitive::kPrimByte: |
| 669 | case Primitive::kPrimChar: |
| 670 | case Primitive::kPrimShort: |
| 671 | case Primitive::kPrimInt: |
| 672 | case Primitive::kPrimNot: |
| 673 | locations->SetOut(X86CpuLocation(EAX)); |
| 674 | break; |
| 675 | |
| 676 | case Primitive::kPrimLong: |
| 677 | locations->SetOut(Location::RegisterLocation(X86ManagedRegister::FromRegisterPair(EAX_EDX))); |
| 678 | break; |
| 679 | |
| 680 | case Primitive::kPrimVoid: |
| 681 | break; |
| 682 | |
| 683 | case Primitive::kPrimDouble: |
| 684 | case Primitive::kPrimFloat: |
| 685 | LOG(FATAL) << "Unimplemented return type " << invoke->GetType(); |
| 686 | break; |
| 687 | } |
| 688 | |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 689 | invoke->SetLocations(locations); |
| 690 | } |
| 691 | |
| 692 | void InstructionCodeGeneratorX86::VisitInvokeStatic(HInvokeStatic* invoke) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 693 | Register temp = invoke->GetLocations()->GetTemp(0).AsX86().AsCpuRegister(); |
Nicolas Geoffray | f61b537 | 2014-06-25 14:35:34 +0100 | [diff] [blame] | 694 | uint32_t heap_reference_size = sizeof(mirror::HeapReference<mirror::Object>); |
| 695 | size_t index_in_cache = mirror::Array::DataOffset(heap_reference_size).Int32Value() + |
Nicolas Geoffray | 707c809 | 2014-04-04 10:50:14 +0100 | [diff] [blame] | 696 | invoke->GetIndexInDexCache() * kX86WordSize; |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 697 | |
| 698 | // TODO: Implement all kinds of calls: |
| 699 | // 1) boot -> boot |
| 700 | // 2) app -> boot |
| 701 | // 3) app -> app |
| 702 | // |
| 703 | // Currently we implement the app -> app logic, which looks up in the resolve cache. |
| 704 | |
| 705 | // temp = method; |
| 706 | LoadCurrentMethod(temp); |
| 707 | // temp = temp->dex_cache_resolved_methods_; |
| 708 | __ movl(temp, Address(temp, mirror::ArtMethod::DexCacheResolvedMethodsOffset().Int32Value())); |
| 709 | // temp = temp[index_in_cache] |
| 710 | __ movl(temp, Address(temp, index_in_cache)); |
| 711 | // (temp + offset_of_quick_compiled_code)() |
| 712 | __ call(Address(temp, mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset().Int32Value())); |
| 713 | |
| 714 | codegen_->RecordPcInfo(invoke->GetDexPc()); |
| 715 | } |
| 716 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 717 | void LocationsBuilderX86::VisitAdd(HAdd* add) { |
| 718 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(add); |
| 719 | switch (add->GetResultType()) { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 720 | case Primitive::kPrimInt: |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 721 | case Primitive::kPrimLong: { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 722 | locations->SetInAt(0, Location::RequiresRegister()); |
| 723 | locations->SetInAt(1, Location::Any()); |
| 724 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 725 | break; |
| 726 | } |
| 727 | |
| 728 | case Primitive::kPrimBoolean: |
| 729 | case Primitive::kPrimByte: |
| 730 | case Primitive::kPrimChar: |
| 731 | case Primitive::kPrimShort: |
| 732 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
| 733 | break; |
| 734 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 735 | default: |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 736 | LOG(FATAL) << "Unimplemented add type " << add->GetResultType(); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 737 | } |
| 738 | add->SetLocations(locations); |
| 739 | } |
| 740 | |
| 741 | void InstructionCodeGeneratorX86::VisitAdd(HAdd* add) { |
| 742 | LocationSummary* locations = add->GetLocations(); |
| 743 | switch (add->GetResultType()) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 744 | case Primitive::kPrimInt: { |
| 745 | DCHECK_EQ(locations->InAt(0).AsX86().AsCpuRegister(), |
| 746 | locations->Out().AsX86().AsCpuRegister()); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 747 | if (locations->InAt(1).IsRegister()) { |
| 748 | __ addl(locations->InAt(0).AsX86().AsCpuRegister(), |
| 749 | locations->InAt(1).AsX86().AsCpuRegister()); |
| 750 | } else { |
| 751 | __ addl(locations->InAt(0).AsX86().AsCpuRegister(), |
| 752 | Address(ESP, locations->InAt(1).GetStackIndex())); |
| 753 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 754 | break; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 755 | } |
| 756 | |
| 757 | case Primitive::kPrimLong: { |
| 758 | DCHECK_EQ(locations->InAt(0).AsX86().AsRegisterPair(), |
| 759 | locations->Out().AsX86().AsRegisterPair()); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 760 | if (locations->InAt(1).IsRegister()) { |
| 761 | __ addl(locations->InAt(0).AsX86().AsRegisterPairLow(), |
| 762 | locations->InAt(1).AsX86().AsRegisterPairLow()); |
| 763 | __ adcl(locations->InAt(0).AsX86().AsRegisterPairHigh(), |
| 764 | locations->InAt(1).AsX86().AsRegisterPairHigh()); |
| 765 | } else { |
| 766 | __ addl(locations->InAt(0).AsX86().AsRegisterPairLow(), |
| 767 | Address(ESP, locations->InAt(1).GetStackIndex())); |
| 768 | __ adcl(locations->InAt(0).AsX86().AsRegisterPairHigh(), |
| 769 | Address(ESP, locations->InAt(1).GetHighStackIndex(kX86WordSize))); |
| 770 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 771 | break; |
| 772 | } |
| 773 | |
| 774 | case Primitive::kPrimBoolean: |
| 775 | case Primitive::kPrimByte: |
| 776 | case Primitive::kPrimChar: |
| 777 | case Primitive::kPrimShort: |
| 778 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
| 779 | break; |
| 780 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 781 | default: |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 782 | LOG(FATAL) << "Unimplemented add type " << add->GetResultType(); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 783 | } |
| 784 | } |
| 785 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 786 | void LocationsBuilderX86::VisitSub(HSub* sub) { |
| 787 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(sub); |
| 788 | switch (sub->GetResultType()) { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 789 | case Primitive::kPrimInt: |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 790 | case Primitive::kPrimLong: { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 791 | locations->SetInAt(0, Location::RequiresRegister()); |
| 792 | locations->SetInAt(1, Location::Any()); |
| 793 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 794 | break; |
| 795 | } |
| 796 | |
| 797 | case Primitive::kPrimBoolean: |
| 798 | case Primitive::kPrimByte: |
| 799 | case Primitive::kPrimChar: |
| 800 | case Primitive::kPrimShort: |
| 801 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
| 802 | break; |
| 803 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 804 | default: |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 805 | LOG(FATAL) << "Unimplemented sub type " << sub->GetResultType(); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 806 | } |
| 807 | sub->SetLocations(locations); |
| 808 | } |
| 809 | |
| 810 | void InstructionCodeGeneratorX86::VisitSub(HSub* sub) { |
| 811 | LocationSummary* locations = sub->GetLocations(); |
| 812 | switch (sub->GetResultType()) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 813 | case Primitive::kPrimInt: { |
| 814 | DCHECK_EQ(locations->InAt(0).AsX86().AsCpuRegister(), |
| 815 | locations->Out().AsX86().AsCpuRegister()); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 816 | if (locations->InAt(1).IsRegister()) { |
| 817 | __ subl(locations->InAt(0).AsX86().AsCpuRegister(), |
| 818 | locations->InAt(1).AsX86().AsCpuRegister()); |
| 819 | } else { |
| 820 | __ subl(locations->InAt(0).AsX86().AsCpuRegister(), |
| 821 | Address(ESP, locations->InAt(1).GetStackIndex())); |
| 822 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 823 | break; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 824 | } |
| 825 | |
| 826 | case Primitive::kPrimLong: { |
| 827 | DCHECK_EQ(locations->InAt(0).AsX86().AsRegisterPair(), |
| 828 | locations->Out().AsX86().AsRegisterPair()); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 829 | if (locations->InAt(1).IsRegister()) { |
| 830 | __ subl(locations->InAt(0).AsX86().AsRegisterPairLow(), |
| 831 | locations->InAt(1).AsX86().AsRegisterPairLow()); |
| 832 | __ sbbl(locations->InAt(0).AsX86().AsRegisterPairHigh(), |
| 833 | locations->InAt(1).AsX86().AsRegisterPairHigh()); |
| 834 | } else { |
| 835 | __ subl(locations->InAt(0).AsX86().AsRegisterPairLow(), |
| 836 | Address(ESP, locations->InAt(1).GetStackIndex())); |
| 837 | __ sbbl(locations->InAt(0).AsX86().AsRegisterPairHigh(), |
| 838 | Address(ESP, locations->InAt(1).GetHighStackIndex(kX86WordSize))); |
| 839 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 840 | break; |
| 841 | } |
| 842 | |
| 843 | case Primitive::kPrimBoolean: |
| 844 | case Primitive::kPrimByte: |
| 845 | case Primitive::kPrimChar: |
| 846 | case Primitive::kPrimShort: |
| 847 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
| 848 | break; |
| 849 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 850 | default: |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 851 | LOG(FATAL) << "Unimplemented sub type " << sub->GetResultType(); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 852 | } |
| 853 | } |
| 854 | |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 855 | void LocationsBuilderX86::VisitNewInstance(HNewInstance* instruction) { |
| 856 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 857 | locations->SetOut(X86CpuLocation(EAX)); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 858 | InvokeRuntimeCallingConvention calling_convention; |
| 859 | locations->AddTemp(X86CpuLocation(calling_convention.GetRegisterAt(0))); |
| 860 | locations->AddTemp(X86CpuLocation(calling_convention.GetRegisterAt(1))); |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 861 | instruction->SetLocations(locations); |
| 862 | } |
| 863 | |
| 864 | void InstructionCodeGeneratorX86::VisitNewInstance(HNewInstance* instruction) { |
| 865 | InvokeRuntimeCallingConvention calling_convention; |
| 866 | LoadCurrentMethod(calling_convention.GetRegisterAt(1)); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 867 | __ movl(calling_convention.GetRegisterAt(0), Immediate(instruction->GetTypeIndex())); |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 868 | |
Nicolas Geoffray | 707c809 | 2014-04-04 10:50:14 +0100 | [diff] [blame] | 869 | __ fs()->call( |
| 870 | Address::Absolute(QUICK_ENTRYPOINT_OFFSET(kX86WordSize, pAllocObjectWithAccessCheck))); |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 871 | |
| 872 | codegen_->RecordPcInfo(instruction->GetDexPc()); |
| 873 | } |
| 874 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 875 | void LocationsBuilderX86::VisitParameterValue(HParameterValue* instruction) { |
| 876 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 877 | Location location = parameter_visitor_.GetNextLocation(instruction->GetType()); |
| 878 | if (location.IsStackSlot()) { |
| 879 | location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 880 | } else if (location.IsDoubleStackSlot()) { |
| 881 | location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 882 | } |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 883 | locations->SetOut(location); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 884 | instruction->SetLocations(locations); |
| 885 | } |
| 886 | |
| 887 | void InstructionCodeGeneratorX86::VisitParameterValue(HParameterValue* instruction) { |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 888 | } |
| 889 | |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 890 | void LocationsBuilderX86::VisitNot(HNot* instruction) { |
| 891 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 892 | locations->SetInAt(0, Location::RequiresRegister()); |
| 893 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 894 | instruction->SetLocations(locations); |
| 895 | } |
| 896 | |
| 897 | void InstructionCodeGeneratorX86::VisitNot(HNot* instruction) { |
| 898 | LocationSummary* locations = instruction->GetLocations(); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 899 | Location out = locations->Out(); |
| 900 | DCHECK_EQ(locations->InAt(0).AsX86().AsCpuRegister(), out.AsX86().AsCpuRegister()); |
| 901 | __ xorl(out.AsX86().AsCpuRegister(), Immediate(1)); |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 902 | } |
| 903 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 904 | void LocationsBuilderX86::VisitPhi(HPhi* instruction) { |
Nicolas Geoffray | 31d76b4 | 2014-06-09 15:02:22 +0100 | [diff] [blame] | 905 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
| 906 | for (size_t i = 0, e = instruction->InputCount(); i < e; ++i) { |
| 907 | locations->SetInAt(i, Location::Any()); |
| 908 | } |
| 909 | locations->SetOut(Location::Any()); |
| 910 | instruction->SetLocations(locations); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 911 | } |
| 912 | |
| 913 | void InstructionCodeGeneratorX86::VisitPhi(HPhi* instruction) { |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 914 | LOG(FATAL) << "Unreachable"; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 915 | } |
| 916 | |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 917 | void LocationsBuilderX86::VisitParallelMove(HParallelMove* instruction) { |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 918 | LOG(FATAL) << "Unreachable"; |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 919 | } |
| 920 | |
| 921 | void InstructionCodeGeneratorX86::VisitParallelMove(HParallelMove* instruction) { |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 922 | codegen_->GetMoveResolver()->EmitNativeCode(instruction); |
| 923 | } |
| 924 | |
| 925 | X86Assembler* ParallelMoveResolverX86::GetAssembler() const { |
| 926 | return codegen_->GetAssembler(); |
| 927 | } |
| 928 | |
| 929 | void ParallelMoveResolverX86::MoveMemoryToMemory(int dst, int src) { |
| 930 | ScratchRegisterScope ensure_scratch( |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 931 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 932 | int stack_offset = ensure_scratch.IsSpilled() ? kX86WordSize : 0; |
| 933 | __ movl(static_cast<Register>(ensure_scratch.GetRegister()), Address(ESP, src + stack_offset)); |
| 934 | __ movl(Address(ESP, dst + stack_offset), static_cast<Register>(ensure_scratch.GetRegister())); |
| 935 | } |
| 936 | |
| 937 | void ParallelMoveResolverX86::EmitMove(size_t index) { |
| 938 | MoveOperands* move = moves_.Get(index); |
| 939 | Location source = move->GetSource(); |
| 940 | Location destination = move->GetDestination(); |
| 941 | |
| 942 | if (source.IsRegister()) { |
| 943 | if (destination.IsRegister()) { |
| 944 | __ movl(destination.AsX86().AsCpuRegister(), source.AsX86().AsCpuRegister()); |
| 945 | } else { |
| 946 | DCHECK(destination.IsStackSlot()); |
| 947 | __ movl(Address(ESP, destination.GetStackIndex()), source.AsX86().AsCpuRegister()); |
| 948 | } |
| 949 | } else if (source.IsStackSlot()) { |
| 950 | if (destination.IsRegister()) { |
| 951 | __ movl(destination.AsX86().AsCpuRegister(), Address(ESP, source.GetStackIndex())); |
| 952 | } else { |
| 953 | DCHECK(destination.IsStackSlot()); |
| 954 | MoveMemoryToMemory(destination.GetStackIndex(), |
| 955 | source.GetStackIndex()); |
| 956 | } |
| 957 | } else { |
| 958 | LOG(FATAL) << "Unimplemented"; |
| 959 | } |
| 960 | } |
| 961 | |
| 962 | void ParallelMoveResolverX86::Exchange(Register reg, int mem) { |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 963 | Register suggested_scratch = reg == EAX ? EBX : EAX; |
| 964 | ScratchRegisterScope ensure_scratch( |
| 965 | this, reg, suggested_scratch, codegen_->GetNumberOfCoreRegisters()); |
| 966 | |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 967 | int stack_offset = ensure_scratch.IsSpilled() ? kX86WordSize : 0; |
| 968 | __ movl(static_cast<Register>(ensure_scratch.GetRegister()), Address(ESP, mem + stack_offset)); |
| 969 | __ movl(Address(ESP, mem + stack_offset), reg); |
| 970 | __ movl(reg, static_cast<Register>(ensure_scratch.GetRegister())); |
| 971 | } |
| 972 | |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 973 | void ParallelMoveResolverX86::Exchange(int mem1, int mem2) { |
| 974 | ScratchRegisterScope ensure_scratch1( |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 975 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
| 976 | |
| 977 | Register suggested_scratch = ensure_scratch1.GetRegister() == EAX ? EBX : EAX; |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 978 | ScratchRegisterScope ensure_scratch2( |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 979 | this, ensure_scratch1.GetRegister(), suggested_scratch, codegen_->GetNumberOfCoreRegisters()); |
| 980 | |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 981 | int stack_offset = ensure_scratch1.IsSpilled() ? kX86WordSize : 0; |
| 982 | stack_offset += ensure_scratch2.IsSpilled() ? kX86WordSize : 0; |
| 983 | __ movl(static_cast<Register>(ensure_scratch1.GetRegister()), Address(ESP, mem1 + stack_offset)); |
| 984 | __ movl(static_cast<Register>(ensure_scratch2.GetRegister()), Address(ESP, mem2 + stack_offset)); |
| 985 | __ movl(Address(ESP, mem2 + stack_offset), static_cast<Register>(ensure_scratch1.GetRegister())); |
| 986 | __ movl(Address(ESP, mem1 + stack_offset), static_cast<Register>(ensure_scratch2.GetRegister())); |
| 987 | } |
| 988 | |
| 989 | void ParallelMoveResolverX86::EmitSwap(size_t index) { |
| 990 | MoveOperands* move = moves_.Get(index); |
| 991 | Location source = move->GetSource(); |
| 992 | Location destination = move->GetDestination(); |
| 993 | |
| 994 | if (source.IsRegister() && destination.IsRegister()) { |
| 995 | __ xchgl(destination.AsX86().AsCpuRegister(), source.AsX86().AsCpuRegister()); |
| 996 | } else if (source.IsRegister() && destination.IsStackSlot()) { |
| 997 | Exchange(source.AsX86().AsCpuRegister(), destination.GetStackIndex()); |
| 998 | } else if (source.IsStackSlot() && destination.IsRegister()) { |
| 999 | Exchange(destination.AsX86().AsCpuRegister(), source.GetStackIndex()); |
| 1000 | } else if (source.IsStackSlot() && destination.IsStackSlot()) { |
| 1001 | Exchange(destination.GetStackIndex(), source.GetStackIndex()); |
| 1002 | } else { |
| 1003 | LOG(FATAL) << "Unimplemented"; |
| 1004 | } |
| 1005 | } |
| 1006 | |
| 1007 | void ParallelMoveResolverX86::SpillScratch(int reg) { |
| 1008 | __ pushl(static_cast<Register>(reg)); |
| 1009 | } |
| 1010 | |
| 1011 | void ParallelMoveResolverX86::RestoreScratch(int reg) { |
| 1012 | __ popl(static_cast<Register>(reg)); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 1013 | } |
| 1014 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1015 | } // namespace x86 |
| 1016 | } // namespace art |