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