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