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