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