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