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()) { |
| 566 | locations->SetInAt(0, Location::Any()); |
| 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 | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 653 | locations->SetInAt(0, Location::RequiresRegister()); |
| 654 | locations->SetInAt(1, Location::Any()); |
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 | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1097 | locations->SetInAt(0, Location::RequiresRegister()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1098 | locations->SetInAt(1, Location::Any()); |
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 | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1162 | if (field_type == Primitive::kPrimBoolean || field_type == Primitive::kPrimByte) { |
| 1163 | // Ensure the value is in a byte register. |
| 1164 | locations->SetInAt(1, X86CpuLocation(EAX)); |
| 1165 | } else { |
| 1166 | locations->SetInAt(1, Location::RequiresRegister()); |
| 1167 | } |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 1168 | // Temporary registers for the write barrier. |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1169 | if (field_type == Primitive::kPrimNot) { |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 1170 | locations->AddTemp(Location::RequiresRegister()); |
| 1171 | // Ensure the card is in a byte register. |
| 1172 | locations->AddTemp(X86CpuLocation(ECX)); |
| 1173 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1174 | } |
| 1175 | |
| 1176 | void InstructionCodeGeneratorX86::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
| 1177 | LocationSummary* locations = instruction->GetLocations(); |
| 1178 | Register obj = locations->InAt(0).AsX86().AsCpuRegister(); |
| 1179 | uint32_t offset = instruction->GetFieldOffset().Uint32Value(); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1180 | Primitive::Type field_type = instruction->GetFieldType(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1181 | |
| 1182 | switch (field_type) { |
| 1183 | case Primitive::kPrimBoolean: |
| 1184 | case Primitive::kPrimByte: { |
| 1185 | ByteRegister value = locations->InAt(1).AsX86().AsByteRegister(); |
| 1186 | __ movb(Address(obj, offset), value); |
| 1187 | break; |
| 1188 | } |
| 1189 | |
| 1190 | case Primitive::kPrimShort: |
| 1191 | case Primitive::kPrimChar: { |
| 1192 | Register value = locations->InAt(1).AsX86().AsCpuRegister(); |
| 1193 | __ movw(Address(obj, offset), value); |
| 1194 | break; |
| 1195 | } |
| 1196 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1197 | case Primitive::kPrimInt: |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1198 | case Primitive::kPrimNot: { |
| 1199 | Register value = locations->InAt(1).AsX86().AsCpuRegister(); |
| 1200 | __ movl(Address(obj, offset), value); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1201 | |
| 1202 | if (field_type == Primitive::kPrimNot) { |
| 1203 | Register temp = locations->GetTemp(0).AsX86().AsCpuRegister(); |
| 1204 | Register card = locations->GetTemp(1).AsX86().AsCpuRegister(); |
| 1205 | codegen_->MarkGCCard(temp, card, obj, value); |
| 1206 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1207 | break; |
| 1208 | } |
| 1209 | |
| 1210 | case Primitive::kPrimLong: { |
| 1211 | X86ManagedRegister value = locations->InAt(1).AsX86(); |
| 1212 | __ movl(Address(obj, offset), value.AsRegisterPairLow()); |
| 1213 | __ movl(Address(obj, kX86WordSize + offset), value.AsRegisterPairHigh()); |
| 1214 | break; |
| 1215 | } |
| 1216 | |
| 1217 | case Primitive::kPrimFloat: |
| 1218 | case Primitive::kPrimDouble: |
| 1219 | LOG(FATAL) << "Unimplemented register type " << field_type; |
| 1220 | |
| 1221 | case Primitive::kPrimVoid: |
| 1222 | LOG(FATAL) << "Unreachable type " << field_type; |
| 1223 | } |
| 1224 | } |
| 1225 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1226 | void CodeGeneratorX86::MarkGCCard(Register temp, Register card, Register object, Register value) { |
| 1227 | Label is_null; |
| 1228 | __ testl(value, value); |
| 1229 | __ j(kEqual, &is_null); |
| 1230 | __ fs()->movl(card, Address::Absolute(Thread::CardTableOffset<kX86WordSize>().Int32Value())); |
| 1231 | __ movl(temp, object); |
| 1232 | __ shrl(temp, Immediate(gc::accounting::CardTable::kCardShift)); |
| 1233 | __ movb(Address(temp, card, TIMES_1, 0), |
| 1234 | X86ManagedRegister::FromCpuRegister(card).AsByteRegister()); |
| 1235 | __ Bind(&is_null); |
| 1236 | } |
| 1237 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1238 | void LocationsBuilderX86::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1239 | LocationSummary* locations = |
| 1240 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1241 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1242 | locations->SetOut(Location::RequiresRegister()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1243 | } |
| 1244 | |
| 1245 | void InstructionCodeGeneratorX86::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 1246 | LocationSummary* locations = instruction->GetLocations(); |
| 1247 | Register obj = locations->InAt(0).AsX86().AsCpuRegister(); |
| 1248 | uint32_t offset = instruction->GetFieldOffset().Uint32Value(); |
| 1249 | |
| 1250 | switch (instruction->GetType()) { |
| 1251 | case Primitive::kPrimBoolean: { |
| 1252 | Register out = locations->Out().AsX86().AsCpuRegister(); |
| 1253 | __ movzxb(out, Address(obj, offset)); |
| 1254 | break; |
| 1255 | } |
| 1256 | |
| 1257 | case Primitive::kPrimByte: { |
| 1258 | Register out = locations->Out().AsX86().AsCpuRegister(); |
| 1259 | __ movsxb(out, Address(obj, offset)); |
| 1260 | break; |
| 1261 | } |
| 1262 | |
| 1263 | case Primitive::kPrimShort: { |
| 1264 | Register out = locations->Out().AsX86().AsCpuRegister(); |
| 1265 | __ movsxw(out, Address(obj, offset)); |
| 1266 | break; |
| 1267 | } |
| 1268 | |
| 1269 | case Primitive::kPrimChar: { |
| 1270 | Register out = locations->Out().AsX86().AsCpuRegister(); |
| 1271 | __ movzxw(out, Address(obj, offset)); |
| 1272 | break; |
| 1273 | } |
| 1274 | |
| 1275 | case Primitive::kPrimInt: |
| 1276 | case Primitive::kPrimNot: { |
| 1277 | Register out = locations->Out().AsX86().AsCpuRegister(); |
| 1278 | __ movl(out, Address(obj, offset)); |
| 1279 | break; |
| 1280 | } |
| 1281 | |
| 1282 | case Primitive::kPrimLong: { |
| 1283 | // TODO: support volatile. |
| 1284 | X86ManagedRegister out = locations->Out().AsX86(); |
| 1285 | __ movl(out.AsRegisterPairLow(), Address(obj, offset)); |
| 1286 | __ movl(out.AsRegisterPairHigh(), Address(obj, kX86WordSize + offset)); |
| 1287 | break; |
| 1288 | } |
| 1289 | |
| 1290 | case Primitive::kPrimFloat: |
| 1291 | case Primitive::kPrimDouble: |
| 1292 | LOG(FATAL) << "Unimplemented register type " << instruction->GetType(); |
| 1293 | |
| 1294 | case Primitive::kPrimVoid: |
| 1295 | LOG(FATAL) << "Unreachable type " << instruction->GetType(); |
| 1296 | } |
| 1297 | } |
| 1298 | |
| 1299 | void LocationsBuilderX86::VisitNullCheck(HNullCheck* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1300 | LocationSummary* locations = |
| 1301 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1302 | locations->SetInAt(0, Location::Any()); |
| 1303 | // TODO: Have a normalization phase that makes this instruction never used. |
| 1304 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1305 | } |
| 1306 | |
| 1307 | void InstructionCodeGeneratorX86::VisitNullCheck(HNullCheck* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1308 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathX86(instruction); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1309 | codegen_->AddSlowPath(slow_path); |
| 1310 | |
| 1311 | LocationSummary* locations = instruction->GetLocations(); |
| 1312 | Location obj = locations->InAt(0); |
| 1313 | DCHECK(obj.Equals(locations->Out())); |
| 1314 | |
| 1315 | if (obj.IsRegister()) { |
| 1316 | __ cmpl(obj.AsX86().AsCpuRegister(), Immediate(0)); |
| 1317 | } else { |
| 1318 | DCHECK(locations->InAt(0).IsStackSlot()); |
| 1319 | __ cmpl(Address(ESP, obj.GetStackIndex()), Immediate(0)); |
| 1320 | } |
| 1321 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 1322 | } |
| 1323 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1324 | void LocationsBuilderX86::VisitArrayGet(HArrayGet* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1325 | LocationSummary* locations = |
| 1326 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1327 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1328 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 1329 | locations->SetOut(Location::RequiresRegister()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1330 | } |
| 1331 | |
| 1332 | void InstructionCodeGeneratorX86::VisitArrayGet(HArrayGet* instruction) { |
| 1333 | LocationSummary* locations = instruction->GetLocations(); |
| 1334 | Register obj = locations->InAt(0).AsX86().AsCpuRegister(); |
| 1335 | Location index = locations->InAt(1); |
| 1336 | |
| 1337 | switch (instruction->GetType()) { |
| 1338 | case Primitive::kPrimBoolean: { |
| 1339 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value(); |
| 1340 | Register out = locations->Out().AsX86().AsCpuRegister(); |
| 1341 | if (index.IsConstant()) { |
| 1342 | __ movzxb(out, Address(obj, |
| 1343 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset)); |
| 1344 | } else { |
| 1345 | __ movzxb(out, Address(obj, index.AsX86().AsCpuRegister(), TIMES_1, data_offset)); |
| 1346 | } |
| 1347 | break; |
| 1348 | } |
| 1349 | |
| 1350 | case Primitive::kPrimByte: { |
| 1351 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int8_t)).Uint32Value(); |
| 1352 | Register out = locations->Out().AsX86().AsCpuRegister(); |
| 1353 | if (index.IsConstant()) { |
| 1354 | __ movsxb(out, Address(obj, |
| 1355 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset)); |
| 1356 | } else { |
| 1357 | __ movsxb(out, Address(obj, index.AsX86().AsCpuRegister(), TIMES_1, data_offset)); |
| 1358 | } |
| 1359 | break; |
| 1360 | } |
| 1361 | |
| 1362 | case Primitive::kPrimShort: { |
| 1363 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int16_t)).Uint32Value(); |
| 1364 | Register out = locations->Out().AsX86().AsCpuRegister(); |
| 1365 | if (index.IsConstant()) { |
| 1366 | __ movsxw(out, Address(obj, |
| 1367 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset)); |
| 1368 | } else { |
| 1369 | __ movsxw(out, Address(obj, index.AsX86().AsCpuRegister(), TIMES_2, data_offset)); |
| 1370 | } |
| 1371 | break; |
| 1372 | } |
| 1373 | |
| 1374 | case Primitive::kPrimChar: { |
| 1375 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value(); |
| 1376 | Register out = locations->Out().AsX86().AsCpuRegister(); |
| 1377 | if (index.IsConstant()) { |
| 1378 | __ movzxw(out, Address(obj, |
| 1379 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset)); |
| 1380 | } else { |
| 1381 | __ movzxw(out, Address(obj, index.AsX86().AsCpuRegister(), TIMES_2, data_offset)); |
| 1382 | } |
| 1383 | break; |
| 1384 | } |
| 1385 | |
| 1386 | case Primitive::kPrimInt: |
| 1387 | case Primitive::kPrimNot: { |
| 1388 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
| 1389 | Register out = locations->Out().AsX86().AsCpuRegister(); |
| 1390 | if (index.IsConstant()) { |
| 1391 | __ movl(out, Address(obj, |
| 1392 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset)); |
| 1393 | } else { |
| 1394 | __ movl(out, Address(obj, index.AsX86().AsCpuRegister(), TIMES_4, data_offset)); |
| 1395 | } |
| 1396 | break; |
| 1397 | } |
| 1398 | |
| 1399 | case Primitive::kPrimLong: { |
| 1400 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value(); |
| 1401 | X86ManagedRegister out = locations->Out().AsX86(); |
| 1402 | if (index.IsConstant()) { |
| 1403 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
| 1404 | __ movl(out.AsRegisterPairLow(), Address(obj, offset)); |
| 1405 | __ movl(out.AsRegisterPairHigh(), Address(obj, offset + kX86WordSize)); |
| 1406 | } else { |
| 1407 | __ movl(out.AsRegisterPairLow(), |
| 1408 | Address(obj, index.AsX86().AsCpuRegister(), TIMES_8, data_offset)); |
| 1409 | __ movl(out.AsRegisterPairHigh(), |
| 1410 | Address(obj, index.AsX86().AsCpuRegister(), TIMES_8, data_offset + kX86WordSize)); |
| 1411 | } |
| 1412 | break; |
| 1413 | } |
| 1414 | |
| 1415 | case Primitive::kPrimFloat: |
| 1416 | case Primitive::kPrimDouble: |
| 1417 | LOG(FATAL) << "Unimplemented register type " << instruction->GetType(); |
| 1418 | |
| 1419 | case Primitive::kPrimVoid: |
| 1420 | LOG(FATAL) << "Unreachable type " << instruction->GetType(); |
| 1421 | } |
| 1422 | } |
| 1423 | |
| 1424 | void LocationsBuilderX86::VisitArraySet(HArraySet* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1425 | Primitive::Type value_type = instruction->GetComponentType(); |
| 1426 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary( |
| 1427 | instruction, |
| 1428 | value_type == Primitive::kPrimNot ? LocationSummary::kCall : LocationSummary::kNoCall); |
| 1429 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1430 | if (value_type == Primitive::kPrimNot) { |
| 1431 | InvokeRuntimeCallingConvention calling_convention; |
| 1432 | locations->SetInAt(0, X86CpuLocation(calling_convention.GetRegisterAt(0))); |
| 1433 | locations->SetInAt(1, X86CpuLocation(calling_convention.GetRegisterAt(1))); |
| 1434 | locations->SetInAt(2, X86CpuLocation(calling_convention.GetRegisterAt(2))); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1435 | } else { |
| 1436 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1437 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 1438 | if (value_type == Primitive::kPrimBoolean || value_type == Primitive::kPrimByte) { |
| 1439 | // Ensure the value is in a byte register. |
| 1440 | locations->SetInAt(2, X86CpuLocation(EAX)); |
| 1441 | } else { |
| 1442 | locations->SetInAt(2, Location::RequiresRegister()); |
| 1443 | } |
| 1444 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1445 | } |
| 1446 | |
| 1447 | void InstructionCodeGeneratorX86::VisitArraySet(HArraySet* instruction) { |
| 1448 | LocationSummary* locations = instruction->GetLocations(); |
| 1449 | Register obj = locations->InAt(0).AsX86().AsCpuRegister(); |
| 1450 | Location index = locations->InAt(1); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1451 | Primitive::Type value_type = instruction->GetComponentType(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1452 | |
| 1453 | switch (value_type) { |
| 1454 | case Primitive::kPrimBoolean: |
| 1455 | case Primitive::kPrimByte: { |
| 1456 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value(); |
| 1457 | ByteRegister value = locations->InAt(2).AsX86().AsByteRegister(); |
| 1458 | if (index.IsConstant()) { |
| 1459 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset; |
| 1460 | __ movb(Address(obj, offset), value); |
| 1461 | } else { |
| 1462 | __ movb(Address(obj, index.AsX86().AsCpuRegister(), TIMES_1, data_offset), value); |
| 1463 | } |
| 1464 | break; |
| 1465 | } |
| 1466 | |
| 1467 | case Primitive::kPrimShort: |
| 1468 | case Primitive::kPrimChar: { |
| 1469 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value(); |
| 1470 | Register value = locations->InAt(2).AsX86().AsCpuRegister(); |
| 1471 | if (index.IsConstant()) { |
| 1472 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset; |
| 1473 | __ movw(Address(obj, offset), value); |
| 1474 | } else { |
| 1475 | __ movw(Address(obj, index.AsX86().AsCpuRegister(), TIMES_2, data_offset), value); |
| 1476 | } |
| 1477 | break; |
| 1478 | } |
| 1479 | |
| 1480 | case Primitive::kPrimInt: { |
| 1481 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
| 1482 | Register value = locations->InAt(2).AsX86().AsCpuRegister(); |
| 1483 | if (index.IsConstant()) { |
| 1484 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
| 1485 | __ movl(Address(obj, offset), value); |
| 1486 | } else { |
| 1487 | __ movl(Address(obj, index.AsX86().AsCpuRegister(), TIMES_4, data_offset), value); |
| 1488 | } |
| 1489 | break; |
| 1490 | } |
| 1491 | |
| 1492 | case Primitive::kPrimNot: { |
| 1493 | DCHECK(!codegen_->IsLeafMethod()); |
| 1494 | __ fs()->call(Address::Absolute(QUICK_ENTRYPOINT_OFFSET(kX86WordSize, pAputObject))); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1495 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1496 | break; |
| 1497 | } |
| 1498 | |
| 1499 | case Primitive::kPrimLong: { |
| 1500 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value(); |
| 1501 | X86ManagedRegister value = locations->InAt(2).AsX86(); |
| 1502 | if (index.IsConstant()) { |
| 1503 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
| 1504 | __ movl(Address(obj, offset), value.AsRegisterPairLow()); |
| 1505 | __ movl(Address(obj, offset + kX86WordSize), value.AsRegisterPairHigh()); |
| 1506 | } else { |
| 1507 | __ movl(Address(obj, index.AsX86().AsCpuRegister(), TIMES_8, data_offset), |
| 1508 | value.AsRegisterPairLow()); |
| 1509 | __ movl(Address(obj, index.AsX86().AsCpuRegister(), TIMES_8, data_offset + kX86WordSize), |
| 1510 | value.AsRegisterPairHigh()); |
| 1511 | } |
| 1512 | break; |
| 1513 | } |
| 1514 | |
| 1515 | case Primitive::kPrimFloat: |
| 1516 | case Primitive::kPrimDouble: |
| 1517 | LOG(FATAL) << "Unimplemented register type " << instruction->GetType(); |
| 1518 | |
| 1519 | case Primitive::kPrimVoid: |
| 1520 | LOG(FATAL) << "Unreachable type " << instruction->GetType(); |
| 1521 | } |
| 1522 | } |
| 1523 | |
| 1524 | void LocationsBuilderX86::VisitArrayLength(HArrayLength* instruction) { |
| 1525 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
| 1526 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1527 | locations->SetOut(Location::RequiresRegister()); |
| 1528 | instruction->SetLocations(locations); |
| 1529 | } |
| 1530 | |
| 1531 | void InstructionCodeGeneratorX86::VisitArrayLength(HArrayLength* instruction) { |
| 1532 | LocationSummary* locations = instruction->GetLocations(); |
| 1533 | uint32_t offset = mirror::Array::LengthOffset().Uint32Value(); |
| 1534 | Register obj = locations->InAt(0).AsX86().AsCpuRegister(); |
| 1535 | Register out = locations->Out().AsX86().AsCpuRegister(); |
| 1536 | __ movl(out, Address(obj, offset)); |
| 1537 | } |
| 1538 | |
| 1539 | void LocationsBuilderX86::VisitBoundsCheck(HBoundsCheck* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1540 | LocationSummary* locations = |
| 1541 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1542 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1543 | locations->SetInAt(1, Location::RequiresRegister()); |
| 1544 | // TODO: Have a normalization phase that makes this instruction never used. |
| 1545 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1546 | } |
| 1547 | |
| 1548 | void InstructionCodeGeneratorX86::VisitBoundsCheck(HBoundsCheck* instruction) { |
| 1549 | LocationSummary* locations = instruction->GetLocations(); |
| 1550 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) BoundsCheckSlowPathX86( |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1551 | instruction, locations->InAt(0), locations->InAt(1)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1552 | codegen_->AddSlowPath(slow_path); |
| 1553 | |
| 1554 | Register index = locations->InAt(0).AsX86().AsCpuRegister(); |
| 1555 | Register length = locations->InAt(1).AsX86().AsCpuRegister(); |
| 1556 | |
| 1557 | __ cmpl(index, length); |
| 1558 | __ j(kAboveEqual, slow_path->GetEntryLabel()); |
| 1559 | } |
| 1560 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1561 | void LocationsBuilderX86::VisitTemporary(HTemporary* temp) { |
| 1562 | temp->SetLocations(nullptr); |
| 1563 | } |
| 1564 | |
| 1565 | void InstructionCodeGeneratorX86::VisitTemporary(HTemporary* temp) { |
| 1566 | // Nothing to do, this is driven by the code generator. |
| 1567 | } |
| 1568 | |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 1569 | void LocationsBuilderX86::VisitParallelMove(HParallelMove* instruction) { |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 1570 | LOG(FATAL) << "Unreachable"; |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 1571 | } |
| 1572 | |
| 1573 | void InstructionCodeGeneratorX86::VisitParallelMove(HParallelMove* instruction) { |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 1574 | codegen_->GetMoveResolver()->EmitNativeCode(instruction); |
| 1575 | } |
| 1576 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 1577 | void LocationsBuilderX86::VisitSuspendCheck(HSuspendCheck* instruction) { |
| 1578 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath); |
| 1579 | } |
| 1580 | |
| 1581 | void InstructionCodeGeneratorX86::VisitSuspendCheck(HSuspendCheck* instruction) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1582 | HBasicBlock* block = instruction->GetBlock(); |
| 1583 | if (block->GetLoopInformation() != nullptr) { |
| 1584 | DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction); |
| 1585 | // The back edge will generate the suspend check. |
| 1586 | return; |
| 1587 | } |
| 1588 | if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) { |
| 1589 | // The goto will generate the suspend check. |
| 1590 | return; |
| 1591 | } |
| 1592 | GenerateSuspendCheck(instruction, nullptr); |
| 1593 | } |
| 1594 | |
| 1595 | void InstructionCodeGeneratorX86::GenerateSuspendCheck(HSuspendCheck* instruction, |
| 1596 | HBasicBlock* successor) { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 1597 | SuspendCheckSlowPathX86* slow_path = |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1598 | new (GetGraph()->GetArena()) SuspendCheckSlowPathX86(instruction, successor); |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 1599 | codegen_->AddSlowPath(slow_path); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1600 | __ fs()->cmpw(Address::Absolute( |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 1601 | Thread::ThreadFlagsOffset<kX86WordSize>().Int32Value()), Immediate(0)); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1602 | if (successor == nullptr) { |
| 1603 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 1604 | __ Bind(slow_path->GetReturnLabel()); |
| 1605 | } else { |
| 1606 | __ j(kEqual, codegen_->GetLabelOf(successor)); |
| 1607 | __ jmp(slow_path->GetEntryLabel()); |
| 1608 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 1609 | } |
| 1610 | |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 1611 | X86Assembler* ParallelMoveResolverX86::GetAssembler() const { |
| 1612 | return codegen_->GetAssembler(); |
| 1613 | } |
| 1614 | |
| 1615 | void ParallelMoveResolverX86::MoveMemoryToMemory(int dst, int src) { |
| 1616 | ScratchRegisterScope ensure_scratch( |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 1617 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 1618 | int stack_offset = ensure_scratch.IsSpilled() ? kX86WordSize : 0; |
| 1619 | __ movl(static_cast<Register>(ensure_scratch.GetRegister()), Address(ESP, src + stack_offset)); |
| 1620 | __ movl(Address(ESP, dst + stack_offset), static_cast<Register>(ensure_scratch.GetRegister())); |
| 1621 | } |
| 1622 | |
| 1623 | void ParallelMoveResolverX86::EmitMove(size_t index) { |
| 1624 | MoveOperands* move = moves_.Get(index); |
| 1625 | Location source = move->GetSource(); |
| 1626 | Location destination = move->GetDestination(); |
| 1627 | |
| 1628 | if (source.IsRegister()) { |
| 1629 | if (destination.IsRegister()) { |
| 1630 | __ movl(destination.AsX86().AsCpuRegister(), source.AsX86().AsCpuRegister()); |
| 1631 | } else { |
| 1632 | DCHECK(destination.IsStackSlot()); |
| 1633 | __ movl(Address(ESP, destination.GetStackIndex()), source.AsX86().AsCpuRegister()); |
| 1634 | } |
| 1635 | } else if (source.IsStackSlot()) { |
| 1636 | if (destination.IsRegister()) { |
| 1637 | __ movl(destination.AsX86().AsCpuRegister(), Address(ESP, source.GetStackIndex())); |
| 1638 | } else { |
| 1639 | DCHECK(destination.IsStackSlot()); |
| 1640 | MoveMemoryToMemory(destination.GetStackIndex(), |
| 1641 | source.GetStackIndex()); |
| 1642 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1643 | } else if (source.IsConstant()) { |
| 1644 | HIntConstant* instruction = source.GetConstant()->AsIntConstant(); |
| 1645 | Immediate imm(instruction->AsIntConstant()->GetValue()); |
| 1646 | if (destination.IsRegister()) { |
| 1647 | __ movl(destination.AsX86().AsCpuRegister(), imm); |
| 1648 | } else { |
| 1649 | __ movl(Address(ESP, destination.GetStackIndex()), imm); |
| 1650 | } |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 1651 | } else { |
| 1652 | LOG(FATAL) << "Unimplemented"; |
| 1653 | } |
| 1654 | } |
| 1655 | |
| 1656 | void ParallelMoveResolverX86::Exchange(Register reg, int mem) { |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 1657 | Register suggested_scratch = reg == EAX ? EBX : EAX; |
| 1658 | ScratchRegisterScope ensure_scratch( |
| 1659 | this, reg, suggested_scratch, codegen_->GetNumberOfCoreRegisters()); |
| 1660 | |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 1661 | int stack_offset = ensure_scratch.IsSpilled() ? kX86WordSize : 0; |
| 1662 | __ movl(static_cast<Register>(ensure_scratch.GetRegister()), Address(ESP, mem + stack_offset)); |
| 1663 | __ movl(Address(ESP, mem + stack_offset), reg); |
| 1664 | __ movl(reg, static_cast<Register>(ensure_scratch.GetRegister())); |
| 1665 | } |
| 1666 | |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 1667 | void ParallelMoveResolverX86::Exchange(int mem1, int mem2) { |
| 1668 | ScratchRegisterScope ensure_scratch1( |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 1669 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
| 1670 | |
| 1671 | Register suggested_scratch = ensure_scratch1.GetRegister() == EAX ? EBX : EAX; |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 1672 | ScratchRegisterScope ensure_scratch2( |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 1673 | this, ensure_scratch1.GetRegister(), suggested_scratch, codegen_->GetNumberOfCoreRegisters()); |
| 1674 | |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 1675 | int stack_offset = ensure_scratch1.IsSpilled() ? kX86WordSize : 0; |
| 1676 | stack_offset += ensure_scratch2.IsSpilled() ? kX86WordSize : 0; |
| 1677 | __ movl(static_cast<Register>(ensure_scratch1.GetRegister()), Address(ESP, mem1 + stack_offset)); |
| 1678 | __ movl(static_cast<Register>(ensure_scratch2.GetRegister()), Address(ESP, mem2 + stack_offset)); |
| 1679 | __ movl(Address(ESP, mem2 + stack_offset), static_cast<Register>(ensure_scratch1.GetRegister())); |
| 1680 | __ movl(Address(ESP, mem1 + stack_offset), static_cast<Register>(ensure_scratch2.GetRegister())); |
| 1681 | } |
| 1682 | |
| 1683 | void ParallelMoveResolverX86::EmitSwap(size_t index) { |
| 1684 | MoveOperands* move = moves_.Get(index); |
| 1685 | Location source = move->GetSource(); |
| 1686 | Location destination = move->GetDestination(); |
| 1687 | |
| 1688 | if (source.IsRegister() && destination.IsRegister()) { |
| 1689 | __ xchgl(destination.AsX86().AsCpuRegister(), source.AsX86().AsCpuRegister()); |
| 1690 | } else if (source.IsRegister() && destination.IsStackSlot()) { |
| 1691 | Exchange(source.AsX86().AsCpuRegister(), destination.GetStackIndex()); |
| 1692 | } else if (source.IsStackSlot() && destination.IsRegister()) { |
| 1693 | Exchange(destination.AsX86().AsCpuRegister(), source.GetStackIndex()); |
| 1694 | } else if (source.IsStackSlot() && destination.IsStackSlot()) { |
| 1695 | Exchange(destination.GetStackIndex(), source.GetStackIndex()); |
| 1696 | } else { |
| 1697 | LOG(FATAL) << "Unimplemented"; |
| 1698 | } |
| 1699 | } |
| 1700 | |
| 1701 | void ParallelMoveResolverX86::SpillScratch(int reg) { |
| 1702 | __ pushl(static_cast<Register>(reg)); |
| 1703 | } |
| 1704 | |
| 1705 | void ParallelMoveResolverX86::RestoreScratch(int reg) { |
| 1706 | __ popl(static_cast<Register>(reg)); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 1707 | } |
| 1708 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1709 | } // namespace x86 |
| 1710 | } // namespace art |