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