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