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 | |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 37 | static constexpr int kNumberOfPushedRegistersAtEntry = 1; |
| 38 | static constexpr int kCurrentMethodStackOffset = 0; |
| 39 | |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 40 | CodeGeneratorX86::CodeGeneratorX86(HGraph* graph) |
| 41 | : CodeGenerator(graph, kNumberOfRegIds), |
| 42 | location_builder_(graph, this), |
| 43 | instruction_visitor_(graph, this) {} |
| 44 | |
| 45 | static bool* GetBlockedRegisterPairs(bool* blocked_registers) { |
| 46 | return blocked_registers + kNumberOfAllocIds; |
| 47 | } |
| 48 | |
| 49 | ManagedRegister CodeGeneratorX86::AllocateFreeRegister(Primitive::Type type, |
| 50 | bool* blocked_registers) const { |
| 51 | switch (type) { |
| 52 | case Primitive::kPrimLong: { |
| 53 | size_t reg = AllocateFreeRegisterInternal( |
| 54 | GetBlockedRegisterPairs(blocked_registers), kNumberOfRegisterPairs); |
| 55 | X86ManagedRegister pair = |
| 56 | X86ManagedRegister::FromRegisterPair(static_cast<RegisterPair>(reg)); |
| 57 | blocked_registers[pair.AsRegisterPairLow()] = true; |
| 58 | blocked_registers[pair.AsRegisterPairHigh()] = true; |
| 59 | return pair; |
| 60 | } |
| 61 | |
| 62 | case Primitive::kPrimByte: |
| 63 | case Primitive::kPrimBoolean: |
| 64 | case Primitive::kPrimChar: |
| 65 | case Primitive::kPrimShort: |
| 66 | case Primitive::kPrimInt: |
| 67 | case Primitive::kPrimNot: { |
| 68 | size_t reg = AllocateFreeRegisterInternal(blocked_registers, kNumberOfCpuRegisters); |
| 69 | return X86ManagedRegister::FromCpuRegister(static_cast<Register>(reg)); |
| 70 | } |
| 71 | |
| 72 | case Primitive::kPrimFloat: |
| 73 | case Primitive::kPrimDouble: |
| 74 | LOG(FATAL) << "Unimplemented register type " << type; |
| 75 | |
| 76 | case Primitive::kPrimVoid: |
| 77 | LOG(FATAL) << "Unreachable type " << type; |
| 78 | } |
| 79 | |
| 80 | return ManagedRegister::NoRegister(); |
| 81 | } |
| 82 | |
| 83 | void CodeGeneratorX86::SetupBlockedRegisters(bool* blocked_registers) const { |
| 84 | bool* blocked_register_pairs = GetBlockedRegisterPairs(blocked_registers); |
| 85 | |
| 86 | // Don't allocate the dalvik style register pair passing. |
| 87 | blocked_register_pairs[ECX_EDX] = true; |
| 88 | |
| 89 | // Stack register is always reserved. |
| 90 | blocked_registers[ESP] = true; |
| 91 | |
| 92 | // TODO: We currently don't use Quick's callee saved registers. |
| 93 | blocked_registers[EBP] = true; |
| 94 | blocked_registers[ESI] = true; |
| 95 | blocked_registers[EDI] = true; |
| 96 | blocked_register_pairs[EAX_EDI] = true; |
| 97 | blocked_register_pairs[EDX_EDI] = true; |
| 98 | blocked_register_pairs[ECX_EDI] = true; |
| 99 | blocked_register_pairs[EBX_EDI] = true; |
| 100 | } |
| 101 | |
| 102 | size_t CodeGeneratorX86::GetNumberOfRegisters() const { |
| 103 | return kNumberOfRegIds; |
| 104 | } |
| 105 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 106 | static Location X86CpuLocation(Register reg) { |
| 107 | return Location::RegisterLocation(X86ManagedRegister::FromCpuRegister(reg)); |
| 108 | } |
| 109 | |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 110 | InstructionCodeGeneratorX86::InstructionCodeGeneratorX86(HGraph* graph, CodeGeneratorX86* codegen) |
| 111 | : HGraphVisitor(graph), |
| 112 | assembler_(codegen->GetAssembler()), |
| 113 | codegen_(codegen) {} |
| 114 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 115 | void CodeGeneratorX86::GenerateFrameEntry() { |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 116 | // Create a fake register to mimic Quick. |
| 117 | static const int kFakeReturnRegister = 8; |
| 118 | core_spill_mask_ |= (1 << kFakeReturnRegister); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 119 | |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 120 | SetFrameSize(RoundUp( |
| 121 | (GetGraph()->GetMaximumNumberOfOutVRegs() + GetGraph()->GetNumberOfVRegs()) * kVRegSize |
| 122 | + kVRegSize // filler |
| 123 | + kX86WordSize // Art method |
| 124 | + kNumberOfPushedRegistersAtEntry * kX86WordSize, |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 125 | kStackAlignment)); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 126 | |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 127 | // The return PC has already been pushed on the stack. |
Nicolas Geoffray | 707c809 | 2014-04-04 10:50:14 +0100 | [diff] [blame] | 128 | __ subl(ESP, Immediate(GetFrameSize() - kNumberOfPushedRegistersAtEntry * kX86WordSize)); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 129 | __ movl(Address(ESP, kCurrentMethodStackOffset), EAX); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 130 | } |
| 131 | |
| 132 | void CodeGeneratorX86::GenerateFrameExit() { |
Nicolas Geoffray | 707c809 | 2014-04-04 10:50:14 +0100 | [diff] [blame] | 133 | __ addl(ESP, Immediate(GetFrameSize() - kNumberOfPushedRegistersAtEntry * kX86WordSize)); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 134 | } |
| 135 | |
| 136 | void CodeGeneratorX86::Bind(Label* label) { |
| 137 | __ Bind(label); |
| 138 | } |
| 139 | |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 140 | void InstructionCodeGeneratorX86::LoadCurrentMethod(Register reg) { |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 141 | __ movl(reg, Address(ESP, kCurrentMethodStackOffset)); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 142 | } |
| 143 | |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 144 | int32_t CodeGeneratorX86::GetStackSlot(HLocal* local) const { |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 145 | uint16_t reg_number = local->GetRegNumber(); |
| 146 | uint16_t number_of_vregs = GetGraph()->GetNumberOfVRegs(); |
| 147 | uint16_t number_of_in_vregs = GetGraph()->GetNumberOfInVRegs(); |
| 148 | if (reg_number >= number_of_vregs - number_of_in_vregs) { |
| 149 | // Local is a parameter of the method. It is stored in the caller's frame. |
| 150 | return GetFrameSize() + kX86WordSize // ART method |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 151 | + (reg_number - number_of_vregs + number_of_in_vregs) * kVRegSize; |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 152 | } else { |
| 153 | // Local is a temporary in this method. It is stored in this method's frame. |
| 154 | return GetFrameSize() - (kNumberOfPushedRegistersAtEntry * kX86WordSize) |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 155 | - kVRegSize // filler. |
| 156 | - (number_of_vregs * kVRegSize) |
| 157 | + (reg_number * kVRegSize); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 158 | } |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 159 | } |
| 160 | |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 161 | |
| 162 | Location CodeGeneratorX86::GetStackLocation(HLoadLocal* load) const { |
| 163 | switch (load->GetType()) { |
| 164 | case Primitive::kPrimLong: |
| 165 | return Location::DoubleStackSlot(GetStackSlot(load->GetLocal())); |
| 166 | break; |
| 167 | |
| 168 | case Primitive::kPrimInt: |
| 169 | case Primitive::kPrimNot: |
| 170 | return Location::StackSlot(GetStackSlot(load->GetLocal())); |
| 171 | |
| 172 | case Primitive::kPrimFloat: |
| 173 | case Primitive::kPrimDouble: |
| 174 | LOG(FATAL) << "Unimplemented type " << load->GetType(); |
| 175 | |
| 176 | case Primitive::kPrimBoolean: |
| 177 | case Primitive::kPrimByte: |
| 178 | case Primitive::kPrimChar: |
| 179 | case Primitive::kPrimShort: |
| 180 | case Primitive::kPrimVoid: |
| 181 | LOG(FATAL) << "Unexpected type " << load->GetType(); |
| 182 | } |
| 183 | |
| 184 | LOG(FATAL) << "Unreachable"; |
| 185 | return Location(); |
| 186 | } |
| 187 | |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 188 | static constexpr Register kRuntimeParameterCoreRegisters[] = { EAX, ECX, EDX }; |
| 189 | static constexpr size_t kRuntimeParameterCoreRegistersLength = |
| 190 | arraysize(kRuntimeParameterCoreRegisters); |
| 191 | |
| 192 | class InvokeRuntimeCallingConvention : public CallingConvention<Register> { |
| 193 | public: |
| 194 | InvokeRuntimeCallingConvention() |
| 195 | : CallingConvention(kRuntimeParameterCoreRegisters, |
| 196 | kRuntimeParameterCoreRegistersLength) {} |
| 197 | |
| 198 | private: |
| 199 | DISALLOW_COPY_AND_ASSIGN(InvokeRuntimeCallingConvention); |
| 200 | }; |
| 201 | |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 202 | Location InvokeDexCallingConventionVisitor::GetNextLocation(Primitive::Type type) { |
| 203 | switch (type) { |
| 204 | case Primitive::kPrimBoolean: |
| 205 | case Primitive::kPrimByte: |
| 206 | case Primitive::kPrimChar: |
| 207 | case Primitive::kPrimShort: |
| 208 | case Primitive::kPrimInt: |
| 209 | case Primitive::kPrimNot: { |
| 210 | uint32_t index = gp_index_++; |
| 211 | if (index < calling_convention.GetNumberOfRegisters()) { |
| 212 | return X86CpuLocation(calling_convention.GetRegisterAt(index)); |
| 213 | } else { |
| 214 | return Location::StackSlot(calling_convention.GetStackOffsetOf(index, kX86WordSize)); |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 215 | } |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 216 | } |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 217 | |
| 218 | case Primitive::kPrimLong: { |
| 219 | uint32_t index = gp_index_; |
| 220 | gp_index_ += 2; |
| 221 | if (index + 1 < calling_convention.GetNumberOfRegisters()) { |
| 222 | return Location::RegisterLocation(X86ManagedRegister::FromRegisterPair( |
| 223 | calling_convention.GetRegisterPairAt(index))); |
| 224 | } else if (index + 1 == calling_convention.GetNumberOfRegisters()) { |
| 225 | return Location::QuickParameter(index); |
| 226 | } else { |
| 227 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(index, kX86WordSize)); |
| 228 | } |
| 229 | } |
| 230 | |
| 231 | case Primitive::kPrimDouble: |
| 232 | case Primitive::kPrimFloat: |
| 233 | LOG(FATAL) << "Unimplemented parameter type " << type; |
| 234 | break; |
| 235 | |
| 236 | case Primitive::kPrimVoid: |
| 237 | LOG(FATAL) << "Unexpected parameter type " << type; |
| 238 | break; |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 239 | } |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 240 | return Location(); |
| 241 | } |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 242 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 243 | void CodeGeneratorX86::Move32(Location destination, Location source) { |
| 244 | if (source.Equals(destination)) { |
| 245 | return; |
| 246 | } |
| 247 | if (destination.IsRegister()) { |
| 248 | if (source.IsRegister()) { |
| 249 | __ movl(destination.AsX86().AsCpuRegister(), source.AsX86().AsCpuRegister()); |
| 250 | } else { |
| 251 | DCHECK(source.IsStackSlot()); |
| 252 | __ movl(destination.AsX86().AsCpuRegister(), Address(ESP, source.GetStackIndex())); |
| 253 | } |
| 254 | } else { |
| 255 | if (source.IsRegister()) { |
| 256 | __ movl(Address(ESP, destination.GetStackIndex()), source.AsX86().AsCpuRegister()); |
| 257 | } else { |
| 258 | DCHECK(source.IsStackSlot()); |
| 259 | __ movl(EAX, Address(ESP, source.GetStackIndex())); |
| 260 | __ movl(Address(ESP, destination.GetStackIndex()), EAX); |
| 261 | } |
| 262 | } |
| 263 | } |
| 264 | |
| 265 | void CodeGeneratorX86::Move64(Location destination, Location source) { |
| 266 | if (source.Equals(destination)) { |
| 267 | return; |
| 268 | } |
| 269 | if (destination.IsRegister()) { |
| 270 | if (source.IsRegister()) { |
| 271 | __ movl(destination.AsX86().AsRegisterPairLow(), source.AsX86().AsRegisterPairLow()); |
| 272 | __ movl(destination.AsX86().AsRegisterPairHigh(), source.AsX86().AsRegisterPairHigh()); |
| 273 | } else if (source.IsQuickParameter()) { |
| 274 | uint32_t argument_index = source.GetQuickParameterIndex(); |
| 275 | InvokeDexCallingConvention calling_convention; |
| 276 | __ movl(destination.AsX86().AsRegisterPairLow(), |
| 277 | calling_convention.GetRegisterAt(argument_index)); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 278 | __ movl(destination.AsX86().AsRegisterPairHigh(), Address(ESP, |
| 279 | calling_convention.GetStackOffsetOf(argument_index + 1, kX86WordSize) + GetFrameSize())); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 280 | } else { |
| 281 | DCHECK(source.IsDoubleStackSlot()); |
| 282 | __ movl(destination.AsX86().AsRegisterPairLow(), Address(ESP, source.GetStackIndex())); |
| 283 | __ movl(destination.AsX86().AsRegisterPairHigh(), |
| 284 | Address(ESP, source.GetHighStackIndex(kX86WordSize))); |
| 285 | } |
| 286 | } else if (destination.IsQuickParameter()) { |
| 287 | InvokeDexCallingConvention calling_convention; |
| 288 | uint32_t argument_index = destination.GetQuickParameterIndex(); |
| 289 | if (source.IsRegister()) { |
| 290 | __ movl(calling_convention.GetRegisterAt(argument_index), source.AsX86().AsRegisterPairLow()); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 291 | __ movl(Address(ESP, calling_convention.GetStackOffsetOf(argument_index + 1, kX86WordSize)), |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 292 | source.AsX86().AsRegisterPairHigh()); |
| 293 | } else { |
| 294 | DCHECK(source.IsDoubleStackSlot()); |
| 295 | __ movl(calling_convention.GetRegisterAt(argument_index), |
| 296 | Address(ESP, source.GetStackIndex())); |
| 297 | __ movl(EAX, Address(ESP, source.GetHighStackIndex(kX86WordSize))); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 298 | __ movl(Address(ESP, calling_convention.GetStackOffsetOf(argument_index + 1, kX86WordSize)), EAX); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 299 | } |
| 300 | } else { |
| 301 | if (source.IsRegister()) { |
| 302 | __ movl(Address(ESP, destination.GetStackIndex()), source.AsX86().AsRegisterPairLow()); |
| 303 | __ movl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)), |
| 304 | source.AsX86().AsRegisterPairHigh()); |
| 305 | } else if (source.IsQuickParameter()) { |
| 306 | InvokeDexCallingConvention calling_convention; |
| 307 | uint32_t argument_index = source.GetQuickParameterIndex(); |
| 308 | __ movl(Address(ESP, destination.GetStackIndex()), |
| 309 | calling_convention.GetRegisterAt(argument_index)); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 310 | __ movl(EAX, Address(ESP, |
| 311 | calling_convention.GetStackOffsetOf(argument_index + 1, kX86WordSize) + GetFrameSize())); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 312 | __ movl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)), EAX); |
| 313 | } else { |
| 314 | DCHECK(source.IsDoubleStackSlot()); |
| 315 | __ movl(EAX, Address(ESP, source.GetStackIndex())); |
| 316 | __ movl(Address(ESP, destination.GetStackIndex()), EAX); |
| 317 | __ movl(EAX, Address(ESP, source.GetHighStackIndex(kX86WordSize))); |
| 318 | __ movl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)), EAX); |
| 319 | } |
| 320 | } |
| 321 | } |
| 322 | |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 323 | void CodeGeneratorX86::Move(HInstruction* instruction, Location location, HInstruction* move_for) { |
| 324 | if (instruction->AsIntConstant() != nullptr) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 325 | Immediate imm(instruction->AsIntConstant()->GetValue()); |
| 326 | if (location.IsRegister()) { |
| 327 | __ movl(location.AsX86().AsCpuRegister(), imm); |
| 328 | } else { |
| 329 | __ movl(Address(ESP, location.GetStackIndex()), imm); |
| 330 | } |
| 331 | } else if (instruction->AsLongConstant() != nullptr) { |
| 332 | int64_t value = instruction->AsLongConstant()->GetValue(); |
| 333 | if (location.IsRegister()) { |
| 334 | __ movl(location.AsX86().AsRegisterPairLow(), Immediate(Low32Bits(value))); |
| 335 | __ movl(location.AsX86().AsRegisterPairHigh(), Immediate(High32Bits(value))); |
| 336 | } else { |
| 337 | __ movl(Address(ESP, location.GetStackIndex()), Immediate(Low32Bits(value))); |
| 338 | __ movl(Address(ESP, location.GetHighStackIndex(kX86WordSize)), Immediate(High32Bits(value))); |
| 339 | } |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 340 | } else if (instruction->AsLoadLocal() != nullptr) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 341 | switch (instruction->GetType()) { |
| 342 | case Primitive::kPrimBoolean: |
| 343 | case Primitive::kPrimByte: |
| 344 | case Primitive::kPrimChar: |
| 345 | case Primitive::kPrimShort: |
| 346 | case Primitive::kPrimInt: |
| 347 | case Primitive::kPrimNot: |
| 348 | Move32(location, Location::StackSlot(GetStackSlot(instruction->AsLoadLocal()->GetLocal()))); |
| 349 | break; |
| 350 | |
| 351 | case Primitive::kPrimLong: |
| 352 | Move64(location, Location::DoubleStackSlot( |
| 353 | GetStackSlot(instruction->AsLoadLocal()->GetLocal()))); |
| 354 | break; |
| 355 | |
| 356 | default: |
| 357 | LOG(FATAL) << "Unimplemented local type " << instruction->GetType(); |
| 358 | } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 359 | } else { |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 360 | // This can currently only happen when the instruction that requests the move |
| 361 | // is the next to be compiled. |
| 362 | DCHECK_EQ(instruction->GetNext(), move_for); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 363 | switch (instruction->GetType()) { |
| 364 | case Primitive::kPrimBoolean: |
| 365 | case Primitive::kPrimByte: |
| 366 | case Primitive::kPrimChar: |
| 367 | case Primitive::kPrimShort: |
| 368 | case Primitive::kPrimInt: |
| 369 | case Primitive::kPrimNot: |
| 370 | Move32(location, instruction->GetLocations()->Out()); |
| 371 | break; |
| 372 | |
| 373 | case Primitive::kPrimLong: |
| 374 | Move64(location, instruction->GetLocations()->Out()); |
| 375 | break; |
| 376 | |
| 377 | default: |
| 378 | LOG(FATAL) << "Unimplemented type " << instruction->GetType(); |
| 379 | } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 380 | } |
| 381 | } |
| 382 | |
| 383 | void LocationsBuilderX86::VisitGoto(HGoto* got) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 384 | got->SetLocations(nullptr); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 385 | } |
| 386 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 387 | void InstructionCodeGeneratorX86::VisitGoto(HGoto* got) { |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 388 | HBasicBlock* successor = got->GetSuccessor(); |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 389 | if (GetGraph()->GetExitBlock() == successor) { |
| 390 | codegen_->GenerateFrameExit(); |
| 391 | } else if (!codegen_->GoesToNextBlock(got->GetBlock(), successor)) { |
| 392 | __ jmp(codegen_->GetLabelOf(successor)); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 393 | } |
| 394 | } |
| 395 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 396 | void LocationsBuilderX86::VisitExit(HExit* exit) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 397 | exit->SetLocations(nullptr); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 398 | } |
| 399 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 400 | void InstructionCodeGeneratorX86::VisitExit(HExit* exit) { |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 401 | if (kIsDebugBuild) { |
| 402 | __ Comment("Unreachable"); |
| 403 | __ int3(); |
| 404 | } |
| 405 | } |
| 406 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 407 | void LocationsBuilderX86::VisitIf(HIf* if_instr) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 408 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(if_instr); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 409 | locations->SetInAt(0, Location::Any()); |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 410 | if_instr->SetLocations(locations); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 411 | } |
| 412 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 413 | void InstructionCodeGeneratorX86::VisitIf(HIf* if_instr) { |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 414 | // TODO: Generate the input as a condition, instead of materializing in a register. |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 415 | Location location = if_instr->GetLocations()->InAt(0); |
| 416 | if (location.IsRegister()) { |
| 417 | __ cmpl(location.AsX86().AsCpuRegister(), Immediate(0)); |
| 418 | } else { |
| 419 | __ cmpl(Address(ESP, location.GetStackIndex()), Immediate(0)); |
| 420 | } |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 421 | __ j(kEqual, codegen_->GetLabelOf(if_instr->IfFalseSuccessor())); |
| 422 | if (!codegen_->GoesToNextBlock(if_instr->GetBlock(), if_instr->IfTrueSuccessor())) { |
| 423 | __ jmp(codegen_->GetLabelOf(if_instr->IfTrueSuccessor())); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 424 | } |
| 425 | } |
| 426 | |
| 427 | void LocationsBuilderX86::VisitLocal(HLocal* local) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 428 | local->SetLocations(nullptr); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 429 | } |
| 430 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 431 | void InstructionCodeGeneratorX86::VisitLocal(HLocal* local) { |
| 432 | DCHECK_EQ(local->GetBlock(), GetGraph()->GetEntryBlock()); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 433 | } |
| 434 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 435 | void LocationsBuilderX86::VisitLoadLocal(HLoadLocal* local) { |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 436 | local->SetLocations(nullptr); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 437 | } |
| 438 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 439 | void InstructionCodeGeneratorX86::VisitLoadLocal(HLoadLocal* load) { |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 440 | // Nothing to do, this is driven by the code generator. |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 441 | } |
| 442 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 443 | void LocationsBuilderX86::VisitStoreLocal(HStoreLocal* store) { |
| 444 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(store); |
| 445 | switch (store->InputAt(1)->GetType()) { |
| 446 | case Primitive::kPrimBoolean: |
| 447 | case Primitive::kPrimByte: |
| 448 | case Primitive::kPrimChar: |
| 449 | case Primitive::kPrimShort: |
| 450 | case Primitive::kPrimInt: |
| 451 | case Primitive::kPrimNot: |
| 452 | locations->SetInAt(1, Location::StackSlot(codegen_->GetStackSlot(store->GetLocal()))); |
| 453 | break; |
| 454 | |
| 455 | case Primitive::kPrimLong: |
| 456 | locations->SetInAt(1, Location::DoubleStackSlot(codegen_->GetStackSlot(store->GetLocal()))); |
| 457 | break; |
| 458 | |
| 459 | default: |
| 460 | LOG(FATAL) << "Unimplemented local type " << store->InputAt(1)->GetType(); |
| 461 | } |
| 462 | store->SetLocations(locations); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 463 | } |
| 464 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 465 | void InstructionCodeGeneratorX86::VisitStoreLocal(HStoreLocal* store) { |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 466 | } |
| 467 | |
| 468 | void LocationsBuilderX86::VisitEqual(HEqual* equal) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 469 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(equal); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 470 | locations->SetInAt(0, Location::RequiresRegister()); |
| 471 | locations->SetInAt(1, Location::Any()); |
| 472 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 473 | equal->SetLocations(locations); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 474 | } |
| 475 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 476 | void InstructionCodeGeneratorX86::VisitEqual(HEqual* equal) { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 477 | LocationSummary* locations = equal->GetLocations(); |
| 478 | if (locations->InAt(1).IsRegister()) { |
| 479 | __ cmpl(locations->InAt(0).AsX86().AsCpuRegister(), |
| 480 | locations->InAt(1).AsX86().AsCpuRegister()); |
| 481 | } else { |
| 482 | __ cmpl(locations->InAt(0).AsX86().AsCpuRegister(), |
| 483 | Address(ESP, locations->InAt(1).GetStackIndex())); |
| 484 | } |
| 485 | __ setb(kEqual, locations->Out().AsX86().AsCpuRegister()); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 486 | } |
| 487 | |
| 488 | void LocationsBuilderX86::VisitIntConstant(HIntConstant* constant) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 489 | constant->SetLocations(nullptr); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 490 | } |
| 491 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 492 | void InstructionCodeGeneratorX86::VisitIntConstant(HIntConstant* constant) { |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 493 | // Will be generated at use site. |
| 494 | } |
| 495 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 496 | void LocationsBuilderX86::VisitLongConstant(HLongConstant* constant) { |
| 497 | constant->SetLocations(nullptr); |
| 498 | } |
| 499 | |
| 500 | void InstructionCodeGeneratorX86::VisitLongConstant(HLongConstant* constant) { |
| 501 | // Will be generated at use site. |
| 502 | } |
| 503 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 504 | void LocationsBuilderX86::VisitReturnVoid(HReturnVoid* ret) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 505 | ret->SetLocations(nullptr); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 506 | } |
| 507 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 508 | void InstructionCodeGeneratorX86::VisitReturnVoid(HReturnVoid* ret) { |
| 509 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 510 | __ ret(); |
| 511 | } |
| 512 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 513 | void LocationsBuilderX86::VisitReturn(HReturn* ret) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 514 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(ret); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 515 | switch (ret->InputAt(0)->GetType()) { |
| 516 | case Primitive::kPrimBoolean: |
| 517 | case Primitive::kPrimByte: |
| 518 | case Primitive::kPrimChar: |
| 519 | case Primitive::kPrimShort: |
| 520 | case Primitive::kPrimInt: |
| 521 | case Primitive::kPrimNot: |
| 522 | locations->SetInAt(0, X86CpuLocation(EAX)); |
| 523 | break; |
| 524 | |
| 525 | case Primitive::kPrimLong: |
| 526 | locations->SetInAt( |
| 527 | 0, Location::RegisterLocation(X86ManagedRegister::FromRegisterPair(EAX_EDX))); |
| 528 | break; |
| 529 | |
| 530 | default: |
| 531 | LOG(FATAL) << "Unimplemented return type " << ret->InputAt(0)->GetType(); |
| 532 | } |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 533 | ret->SetLocations(locations); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 534 | } |
| 535 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 536 | void InstructionCodeGeneratorX86::VisitReturn(HReturn* ret) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 537 | if (kIsDebugBuild) { |
| 538 | switch (ret->InputAt(0)->GetType()) { |
| 539 | case Primitive::kPrimBoolean: |
| 540 | case Primitive::kPrimByte: |
| 541 | case Primitive::kPrimChar: |
| 542 | case Primitive::kPrimShort: |
| 543 | case Primitive::kPrimInt: |
| 544 | case Primitive::kPrimNot: |
| 545 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsX86().AsCpuRegister(), EAX); |
| 546 | break; |
| 547 | |
| 548 | case Primitive::kPrimLong: |
| 549 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsX86().AsRegisterPair(), EAX_EDX); |
| 550 | break; |
| 551 | |
| 552 | default: |
| 553 | LOG(FATAL) << "Unimplemented return type " << ret->InputAt(0)->GetType(); |
| 554 | } |
| 555 | } |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 556 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 557 | __ ret(); |
| 558 | } |
| 559 | |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 560 | void LocationsBuilderX86::VisitInvokeStatic(HInvokeStatic* invoke) { |
| 561 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(invoke); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 562 | locations->AddTemp(Location::RequiresRegister()); |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 563 | |
| 564 | InvokeDexCallingConventionVisitor calling_convention_visitor; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 565 | for (size_t i = 0; i < invoke->InputCount(); i++) { |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 566 | HInstruction* input = invoke->InputAt(i); |
| 567 | locations->SetInAt(i, calling_convention_visitor.GetNextLocation(input->GetType())); |
| 568 | } |
| 569 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 570 | switch (invoke->GetType()) { |
| 571 | case Primitive::kPrimBoolean: |
| 572 | case Primitive::kPrimByte: |
| 573 | case Primitive::kPrimChar: |
| 574 | case Primitive::kPrimShort: |
| 575 | case Primitive::kPrimInt: |
| 576 | case Primitive::kPrimNot: |
| 577 | locations->SetOut(X86CpuLocation(EAX)); |
| 578 | break; |
| 579 | |
| 580 | case Primitive::kPrimLong: |
| 581 | locations->SetOut(Location::RegisterLocation(X86ManagedRegister::FromRegisterPair(EAX_EDX))); |
| 582 | break; |
| 583 | |
| 584 | case Primitive::kPrimVoid: |
| 585 | break; |
| 586 | |
| 587 | case Primitive::kPrimDouble: |
| 588 | case Primitive::kPrimFloat: |
| 589 | LOG(FATAL) << "Unimplemented return type " << invoke->GetType(); |
| 590 | break; |
| 591 | } |
| 592 | |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 593 | invoke->SetLocations(locations); |
| 594 | } |
| 595 | |
| 596 | void InstructionCodeGeneratorX86::VisitInvokeStatic(HInvokeStatic* invoke) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 597 | Register temp = invoke->GetLocations()->GetTemp(0).AsX86().AsCpuRegister(); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 598 | size_t index_in_cache = mirror::Array::DataOffset(sizeof(mirror::Object*)).Int32Value() + |
Nicolas Geoffray | 707c809 | 2014-04-04 10:50:14 +0100 | [diff] [blame] | 599 | invoke->GetIndexInDexCache() * kX86WordSize; |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 600 | |
| 601 | // TODO: Implement all kinds of calls: |
| 602 | // 1) boot -> boot |
| 603 | // 2) app -> boot |
| 604 | // 3) app -> app |
| 605 | // |
| 606 | // Currently we implement the app -> app logic, which looks up in the resolve cache. |
| 607 | |
| 608 | // temp = method; |
| 609 | LoadCurrentMethod(temp); |
| 610 | // temp = temp->dex_cache_resolved_methods_; |
| 611 | __ movl(temp, Address(temp, mirror::ArtMethod::DexCacheResolvedMethodsOffset().Int32Value())); |
| 612 | // temp = temp[index_in_cache] |
| 613 | __ movl(temp, Address(temp, index_in_cache)); |
| 614 | // (temp + offset_of_quick_compiled_code)() |
| 615 | __ call(Address(temp, mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset().Int32Value())); |
| 616 | |
| 617 | codegen_->RecordPcInfo(invoke->GetDexPc()); |
| 618 | } |
| 619 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 620 | void LocationsBuilderX86::VisitAdd(HAdd* add) { |
| 621 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(add); |
| 622 | switch (add->GetResultType()) { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 623 | case Primitive::kPrimInt: |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 624 | case Primitive::kPrimLong: { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 625 | locations->SetInAt(0, Location::RequiresRegister()); |
| 626 | locations->SetInAt(1, Location::Any()); |
| 627 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 628 | break; |
| 629 | } |
| 630 | |
| 631 | case Primitive::kPrimBoolean: |
| 632 | case Primitive::kPrimByte: |
| 633 | case Primitive::kPrimChar: |
| 634 | case Primitive::kPrimShort: |
| 635 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
| 636 | break; |
| 637 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 638 | default: |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 639 | LOG(FATAL) << "Unimplemented add type " << add->GetResultType(); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 640 | } |
| 641 | add->SetLocations(locations); |
| 642 | } |
| 643 | |
| 644 | void InstructionCodeGeneratorX86::VisitAdd(HAdd* add) { |
| 645 | LocationSummary* locations = add->GetLocations(); |
| 646 | switch (add->GetResultType()) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 647 | case Primitive::kPrimInt: { |
| 648 | DCHECK_EQ(locations->InAt(0).AsX86().AsCpuRegister(), |
| 649 | locations->Out().AsX86().AsCpuRegister()); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 650 | if (locations->InAt(1).IsRegister()) { |
| 651 | __ addl(locations->InAt(0).AsX86().AsCpuRegister(), |
| 652 | locations->InAt(1).AsX86().AsCpuRegister()); |
| 653 | } else { |
| 654 | __ addl(locations->InAt(0).AsX86().AsCpuRegister(), |
| 655 | Address(ESP, locations->InAt(1).GetStackIndex())); |
| 656 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 657 | break; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 658 | } |
| 659 | |
| 660 | case Primitive::kPrimLong: { |
| 661 | DCHECK_EQ(locations->InAt(0).AsX86().AsRegisterPair(), |
| 662 | locations->Out().AsX86().AsRegisterPair()); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 663 | if (locations->InAt(1).IsRegister()) { |
| 664 | __ addl(locations->InAt(0).AsX86().AsRegisterPairLow(), |
| 665 | locations->InAt(1).AsX86().AsRegisterPairLow()); |
| 666 | __ adcl(locations->InAt(0).AsX86().AsRegisterPairHigh(), |
| 667 | locations->InAt(1).AsX86().AsRegisterPairHigh()); |
| 668 | } else { |
| 669 | __ addl(locations->InAt(0).AsX86().AsRegisterPairLow(), |
| 670 | Address(ESP, locations->InAt(1).GetStackIndex())); |
| 671 | __ adcl(locations->InAt(0).AsX86().AsRegisterPairHigh(), |
| 672 | Address(ESP, locations->InAt(1).GetHighStackIndex(kX86WordSize))); |
| 673 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 674 | break; |
| 675 | } |
| 676 | |
| 677 | case Primitive::kPrimBoolean: |
| 678 | case Primitive::kPrimByte: |
| 679 | case Primitive::kPrimChar: |
| 680 | case Primitive::kPrimShort: |
| 681 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
| 682 | break; |
| 683 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 684 | default: |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 685 | LOG(FATAL) << "Unimplemented add type " << add->GetResultType(); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 686 | } |
| 687 | } |
| 688 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 689 | void LocationsBuilderX86::VisitSub(HSub* sub) { |
| 690 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(sub); |
| 691 | switch (sub->GetResultType()) { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 692 | case Primitive::kPrimInt: |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 693 | case Primitive::kPrimLong: { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 694 | locations->SetInAt(0, Location::RequiresRegister()); |
| 695 | locations->SetInAt(1, Location::Any()); |
| 696 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 697 | break; |
| 698 | } |
| 699 | |
| 700 | case Primitive::kPrimBoolean: |
| 701 | case Primitive::kPrimByte: |
| 702 | case Primitive::kPrimChar: |
| 703 | case Primitive::kPrimShort: |
| 704 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
| 705 | break; |
| 706 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 707 | default: |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 708 | LOG(FATAL) << "Unimplemented sub type " << sub->GetResultType(); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 709 | } |
| 710 | sub->SetLocations(locations); |
| 711 | } |
| 712 | |
| 713 | void InstructionCodeGeneratorX86::VisitSub(HSub* sub) { |
| 714 | LocationSummary* locations = sub->GetLocations(); |
| 715 | switch (sub->GetResultType()) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 716 | case Primitive::kPrimInt: { |
| 717 | DCHECK_EQ(locations->InAt(0).AsX86().AsCpuRegister(), |
| 718 | locations->Out().AsX86().AsCpuRegister()); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 719 | if (locations->InAt(1).IsRegister()) { |
| 720 | __ subl(locations->InAt(0).AsX86().AsCpuRegister(), |
| 721 | locations->InAt(1).AsX86().AsCpuRegister()); |
| 722 | } else { |
| 723 | __ subl(locations->InAt(0).AsX86().AsCpuRegister(), |
| 724 | Address(ESP, locations->InAt(1).GetStackIndex())); |
| 725 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 726 | break; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 727 | } |
| 728 | |
| 729 | case Primitive::kPrimLong: { |
| 730 | DCHECK_EQ(locations->InAt(0).AsX86().AsRegisterPair(), |
| 731 | locations->Out().AsX86().AsRegisterPair()); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 732 | if (locations->InAt(1).IsRegister()) { |
| 733 | __ subl(locations->InAt(0).AsX86().AsRegisterPairLow(), |
| 734 | locations->InAt(1).AsX86().AsRegisterPairLow()); |
| 735 | __ sbbl(locations->InAt(0).AsX86().AsRegisterPairHigh(), |
| 736 | locations->InAt(1).AsX86().AsRegisterPairHigh()); |
| 737 | } else { |
| 738 | __ subl(locations->InAt(0).AsX86().AsRegisterPairLow(), |
| 739 | Address(ESP, locations->InAt(1).GetStackIndex())); |
| 740 | __ sbbl(locations->InAt(0).AsX86().AsRegisterPairHigh(), |
| 741 | Address(ESP, locations->InAt(1).GetHighStackIndex(kX86WordSize))); |
| 742 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 743 | break; |
| 744 | } |
| 745 | |
| 746 | case Primitive::kPrimBoolean: |
| 747 | case Primitive::kPrimByte: |
| 748 | case Primitive::kPrimChar: |
| 749 | case Primitive::kPrimShort: |
| 750 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
| 751 | break; |
| 752 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 753 | default: |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 754 | LOG(FATAL) << "Unimplemented sub type " << sub->GetResultType(); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 755 | } |
| 756 | } |
| 757 | |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 758 | void LocationsBuilderX86::VisitNewInstance(HNewInstance* instruction) { |
| 759 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 760 | locations->SetOut(X86CpuLocation(EAX)); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 761 | InvokeRuntimeCallingConvention calling_convention; |
| 762 | locations->AddTemp(X86CpuLocation(calling_convention.GetRegisterAt(0))); |
| 763 | locations->AddTemp(X86CpuLocation(calling_convention.GetRegisterAt(1))); |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 764 | instruction->SetLocations(locations); |
| 765 | } |
| 766 | |
| 767 | void InstructionCodeGeneratorX86::VisitNewInstance(HNewInstance* instruction) { |
| 768 | InvokeRuntimeCallingConvention calling_convention; |
| 769 | LoadCurrentMethod(calling_convention.GetRegisterAt(1)); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 770 | __ movl(calling_convention.GetRegisterAt(0), Immediate(instruction->GetTypeIndex())); |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 771 | |
Nicolas Geoffray | 707c809 | 2014-04-04 10:50:14 +0100 | [diff] [blame] | 772 | __ fs()->call( |
| 773 | Address::Absolute(QUICK_ENTRYPOINT_OFFSET(kX86WordSize, pAllocObjectWithAccessCheck))); |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 774 | |
| 775 | codegen_->RecordPcInfo(instruction->GetDexPc()); |
| 776 | } |
| 777 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 778 | void LocationsBuilderX86::VisitParameterValue(HParameterValue* instruction) { |
| 779 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 780 | Location location = parameter_visitor_.GetNextLocation(instruction->GetType()); |
| 781 | if (location.IsStackSlot()) { |
| 782 | location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 783 | } else if (location.IsDoubleStackSlot()) { |
| 784 | location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 785 | } |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 786 | locations->SetOut(location); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 787 | instruction->SetLocations(locations); |
| 788 | } |
| 789 | |
| 790 | void InstructionCodeGeneratorX86::VisitParameterValue(HParameterValue* instruction) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 791 | // Nothing to do, the parameter is already at its location. |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 792 | } |
| 793 | |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 794 | void LocationsBuilderX86::VisitNot(HNot* instruction) { |
| 795 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 796 | locations->SetInAt(0, Location::RequiresRegister()); |
| 797 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 798 | instruction->SetLocations(locations); |
| 799 | } |
| 800 | |
| 801 | void InstructionCodeGeneratorX86::VisitNot(HNot* instruction) { |
| 802 | LocationSummary* locations = instruction->GetLocations(); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 803 | Location out = locations->Out(); |
| 804 | DCHECK_EQ(locations->InAt(0).AsX86().AsCpuRegister(), out.AsX86().AsCpuRegister()); |
| 805 | __ xorl(out.AsX86().AsCpuRegister(), Immediate(1)); |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 806 | } |
| 807 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 808 | void LocationsBuilderX86::VisitPhi(HPhi* instruction) { |
| 809 | LOG(FATAL) << "Unimplemented"; |
| 810 | } |
| 811 | |
| 812 | void InstructionCodeGeneratorX86::VisitPhi(HPhi* instruction) { |
| 813 | LOG(FATAL) << "Unimplemented"; |
| 814 | } |
| 815 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 816 | } // namespace x86 |
| 817 | } // namespace art |