| 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 | |
| Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 19 | #include "art_method.h" |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 20 | #include "code_generator_utils.h" |
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 21 | #include "compiled_method.h" |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 22 | #include "entrypoints/quick/quick_entrypoints.h" |
| Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 23 | #include "gc/accounting/card_table.h" |
| Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 24 | #include "intrinsics.h" |
| 25 | #include "intrinsics_x86_64.h" |
| Ian Rogers | 7e70b00 | 2014-10-08 11:47:24 -0700 | [diff] [blame] | 26 | #include "mirror/array-inl.h" |
| Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 27 | #include "mirror/class-inl.h" |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 28 | #include "mirror/object_reference.h" |
| 29 | #include "thread.h" |
| 30 | #include "utils/assembler.h" |
| Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 31 | #include "utils/stack_checks.h" |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 32 | #include "utils/x86_64/assembler_x86_64.h" |
| 33 | #include "utils/x86_64/managed_register_x86_64.h" |
| 34 | |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 35 | namespace art { |
| 36 | |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 37 | template<class MirrorType> |
| 38 | class GcRoot; |
| 39 | |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 40 | namespace x86_64 { |
| 41 | |
| Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 42 | static constexpr int kCurrentMethodStackOffset = 0; |
| Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 43 | static constexpr Register kMethodRegisterArgument = RDI; |
| Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 44 | // The compare/jump sequence will generate about (1.5 * num_entries) instructions. A jump |
| 45 | // table version generates 7 instructions and num_entries literals. Compare/jump sequence will |
| 46 | // generates less code/data with a small num_entries. |
| 47 | static constexpr uint32_t kPackedSwitchJumpTableThreshold = 5; |
| Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 48 | |
| Nicolas Geoffray | 4597b5b | 2015-01-23 21:51:55 +0000 | [diff] [blame] | 49 | static constexpr Register kCoreCalleeSaves[] = { RBX, RBP, R12, R13, R14, R15 }; |
| Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 50 | static constexpr FloatRegister kFpuCalleeSaves[] = { XMM12, XMM13, XMM14, XMM15 }; |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 51 | |
| Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 52 | static constexpr int kC2ConditionMask = 0x400; |
| 53 | |
| Roland Levillain | 7cbd27f | 2016-08-11 23:53:33 +0100 | [diff] [blame] | 54 | // NOLINT on __ macro to suppress wrong warning/fix (misc-macro-parentheses) from clang-tidy. |
| 55 | #define __ down_cast<X86_64Assembler*>(codegen->GetAssembler())-> // NOLINT |
| Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 56 | #define QUICK_ENTRY_POINT(x) QUICK_ENTRYPOINT_OFFSET(kX86_64PointerSize, x).Int32Value() |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 57 | |
| Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 58 | class NullCheckSlowPathX86_64 : public SlowPathCode { |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 59 | public: |
| David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 60 | explicit NullCheckSlowPathX86_64(HNullCheck* instruction) : SlowPathCode(instruction) {} |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 61 | |
| Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 62 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 63 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 64 | __ Bind(GetEntryLabel()); |
| David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 65 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 66 | // Live registers will be restored in the catch block if caught. |
| 67 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 68 | } |
| Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 69 | x86_64_codegen->InvokeRuntime(kQuickThrowNullPointer, |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 70 | instruction_, |
| 71 | instruction_->GetDexPc(), |
| 72 | this); |
| Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 73 | CheckEntrypointTypes<kQuickThrowNullPointer, void, void>(); |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 74 | } |
| 75 | |
| Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 76 | bool IsFatal() const OVERRIDE { return true; } |
| 77 | |
| Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 78 | const char* GetDescription() const OVERRIDE { return "NullCheckSlowPathX86_64"; } |
| 79 | |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 80 | private: |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 81 | DISALLOW_COPY_AND_ASSIGN(NullCheckSlowPathX86_64); |
| 82 | }; |
| 83 | |
| Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 84 | class DivZeroCheckSlowPathX86_64 : public SlowPathCode { |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 85 | public: |
| David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 86 | explicit DivZeroCheckSlowPathX86_64(HDivZeroCheck* instruction) : SlowPathCode(instruction) {} |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 87 | |
| Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 88 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 89 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 90 | __ Bind(GetEntryLabel()); |
| Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 91 | x86_64_codegen->InvokeRuntime(kQuickThrowDivZero, instruction_, instruction_->GetDexPc(), this); |
| Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 92 | CheckEntrypointTypes<kQuickThrowDivZero, void, void>(); |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 93 | } |
| 94 | |
| Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 95 | bool IsFatal() const OVERRIDE { return true; } |
| 96 | |
| Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 97 | const char* GetDescription() const OVERRIDE { return "DivZeroCheckSlowPathX86_64"; } |
| 98 | |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 99 | private: |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 100 | DISALLOW_COPY_AND_ASSIGN(DivZeroCheckSlowPathX86_64); |
| 101 | }; |
| 102 | |
| Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 103 | class DivRemMinusOneSlowPathX86_64 : public SlowPathCode { |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 104 | public: |
| David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 105 | DivRemMinusOneSlowPathX86_64(HInstruction* at, Register reg, Primitive::Type type, bool is_div) |
| 106 | : SlowPathCode(at), cpu_reg_(CpuRegister(reg)), type_(type), is_div_(is_div) {} |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 107 | |
| Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 108 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 109 | __ Bind(GetEntryLabel()); |
| Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 110 | if (type_ == Primitive::kPrimInt) { |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 111 | if (is_div_) { |
| 112 | __ negl(cpu_reg_); |
| 113 | } else { |
| Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 114 | __ xorl(cpu_reg_, cpu_reg_); |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 115 | } |
| 116 | |
| Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 117 | } else { |
| 118 | DCHECK_EQ(Primitive::kPrimLong, type_); |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 119 | if (is_div_) { |
| 120 | __ negq(cpu_reg_); |
| 121 | } else { |
| Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 122 | __ xorl(cpu_reg_, cpu_reg_); |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 123 | } |
| Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 124 | } |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 125 | __ jmp(GetExitLabel()); |
| 126 | } |
| 127 | |
| Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 128 | const char* GetDescription() const OVERRIDE { return "DivRemMinusOneSlowPathX86_64"; } |
| 129 | |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 130 | private: |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 131 | const CpuRegister cpu_reg_; |
| Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 132 | const Primitive::Type type_; |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 133 | const bool is_div_; |
| 134 | DISALLOW_COPY_AND_ASSIGN(DivRemMinusOneSlowPathX86_64); |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 135 | }; |
| 136 | |
| Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 137 | class SuspendCheckSlowPathX86_64 : public SlowPathCode { |
| Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 138 | public: |
| Roland Levillain | 3887c46 | 2015-08-12 18:15:42 +0100 | [diff] [blame] | 139 | SuspendCheckSlowPathX86_64(HSuspendCheck* instruction, HBasicBlock* successor) |
| David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 140 | : SlowPathCode(instruction), successor_(successor) {} |
| Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 141 | |
| Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 142 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| Aart Bik | b13c65b | 2017-03-21 20:14:07 -0700 | [diff] [blame] | 143 | LocationSummary* locations = instruction_->GetLocations(); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 144 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
| Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 145 | __ Bind(GetEntryLabel()); |
| Aart Bik | 24b905f | 2017-04-06 09:59:06 -0700 | [diff] [blame] | 146 | SaveLiveRegisters(codegen, locations); // Only saves full width XMM for SIMD. |
| Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 147 | x86_64_codegen->InvokeRuntime(kQuickTestSuspend, instruction_, instruction_->GetDexPc(), this); |
| Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 148 | CheckEntrypointTypes<kQuickTestSuspend, void, void>(); |
| Aart Bik | 24b905f | 2017-04-06 09:59:06 -0700 | [diff] [blame] | 149 | RestoreLiveRegisters(codegen, locations); // Only restores full width XMM for SIMD. |
| Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 150 | if (successor_ == nullptr) { |
| 151 | __ jmp(GetReturnLabel()); |
| 152 | } else { |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 153 | __ jmp(x86_64_codegen->GetLabelOf(successor_)); |
| Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 154 | } |
| Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 155 | } |
| 156 | |
| Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 157 | Label* GetReturnLabel() { |
| 158 | DCHECK(successor_ == nullptr); |
| 159 | return &return_label_; |
| 160 | } |
| Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 161 | |
| Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 162 | HBasicBlock* GetSuccessor() const { |
| 163 | return successor_; |
| 164 | } |
| 165 | |
| Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 166 | const char* GetDescription() const OVERRIDE { return "SuspendCheckSlowPathX86_64"; } |
| 167 | |
| Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 168 | private: |
| Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 169 | HBasicBlock* const successor_; |
| Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 170 | Label return_label_; |
| 171 | |
| 172 | DISALLOW_COPY_AND_ASSIGN(SuspendCheckSlowPathX86_64); |
| 173 | }; |
| 174 | |
| Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 175 | class BoundsCheckSlowPathX86_64 : public SlowPathCode { |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 176 | public: |
| Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 177 | explicit BoundsCheckSlowPathX86_64(HBoundsCheck* instruction) |
| David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 178 | : SlowPathCode(instruction) {} |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 179 | |
| Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 180 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 181 | LocationSummary* locations = instruction_->GetLocations(); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 182 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 183 | __ Bind(GetEntryLabel()); |
| David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 184 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 185 | // Live registers will be restored in the catch block if caught. |
| 186 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 187 | } |
| Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 188 | // Are we using an array length from memory? |
| 189 | HInstruction* array_length = instruction_->InputAt(1); |
| 190 | Location length_loc = locations->InAt(1); |
| 191 | InvokeRuntimeCallingConvention calling_convention; |
| 192 | if (array_length->IsArrayLength() && array_length->IsEmittedAtUseSite()) { |
| 193 | // Load the array length into our temporary. |
| 194 | uint32_t len_offset = CodeGenerator::GetArrayLengthOffset(array_length->AsArrayLength()); |
| 195 | Location array_loc = array_length->GetLocations()->InAt(0); |
| 196 | Address array_len(array_loc.AsRegister<CpuRegister>(), len_offset); |
| 197 | length_loc = Location::RegisterLocation(calling_convention.GetRegisterAt(1)); |
| 198 | // Check for conflicts with index. |
| 199 | if (length_loc.Equals(locations->InAt(0))) { |
| 200 | // We know we aren't using parameter 2. |
| 201 | length_loc = Location::RegisterLocation(calling_convention.GetRegisterAt(2)); |
| 202 | } |
| 203 | __ movl(length_loc.AsRegister<CpuRegister>(), array_len); |
| jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 204 | if (mirror::kUseStringCompression) { |
| Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 205 | __ shrl(length_loc.AsRegister<CpuRegister>(), Immediate(1)); |
| jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 206 | } |
| Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 207 | } |
| 208 | |
| Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 209 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 210 | // move resolver. |
| Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 211 | codegen->EmitParallelMoves( |
| Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 212 | locations->InAt(0), |
| Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 213 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 214 | Primitive::kPrimInt, |
| Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 215 | length_loc, |
| Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 216 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 217 | Primitive::kPrimInt); |
| Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 218 | QuickEntrypointEnum entrypoint = instruction_->AsBoundsCheck()->IsStringCharAt() |
| 219 | ? kQuickThrowStringBounds |
| 220 | : kQuickThrowArrayBounds; |
| 221 | x86_64_codegen->InvokeRuntime(entrypoint, instruction_, instruction_->GetDexPc(), this); |
| Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 222 | CheckEntrypointTypes<kQuickThrowStringBounds, void, int32_t, int32_t>(); |
| Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 223 | CheckEntrypointTypes<kQuickThrowArrayBounds, void, int32_t, int32_t>(); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 224 | } |
| 225 | |
| Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 226 | bool IsFatal() const OVERRIDE { return true; } |
| 227 | |
| Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 228 | const char* GetDescription() const OVERRIDE { return "BoundsCheckSlowPathX86_64"; } |
| 229 | |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 230 | private: |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 231 | DISALLOW_COPY_AND_ASSIGN(BoundsCheckSlowPathX86_64); |
| 232 | }; |
| 233 | |
| Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 234 | class LoadClassSlowPathX86_64 : public SlowPathCode { |
| Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 235 | public: |
| Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 236 | LoadClassSlowPathX86_64(HLoadClass* cls, |
| 237 | HInstruction* at, |
| 238 | uint32_t dex_pc, |
| 239 | bool do_clinit) |
| Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 240 | : SlowPathCode(at), cls_(cls), dex_pc_(dex_pc), do_clinit_(do_clinit) { |
| Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 241 | DCHECK(at->IsLoadClass() || at->IsClinitCheck()); |
| 242 | } |
| Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 243 | |
| Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 244 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 245 | LocationSummary* locations = instruction_->GetLocations(); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 246 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
| Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 247 | __ Bind(GetEntryLabel()); |
| Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 248 | |
| Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 249 | SaveLiveRegisters(codegen, locations); |
| Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 250 | |
| Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 251 | // Custom calling convention: RAX serves as both input and output. |
| 252 | __ movl(CpuRegister(RAX), Immediate(cls_->GetTypeIndex().index_)); |
| Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 253 | x86_64_codegen->InvokeRuntime(do_clinit_ ? kQuickInitializeStaticStorage : kQuickInitializeType, |
| Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 254 | instruction_, |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 255 | dex_pc_, |
| 256 | this); |
| Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 257 | if (do_clinit_) { |
| 258 | CheckEntrypointTypes<kQuickInitializeStaticStorage, void*, uint32_t>(); |
| 259 | } else { |
| 260 | CheckEntrypointTypes<kQuickInitializeType, void*, uint32_t>(); |
| 261 | } |
| Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 262 | |
| Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 263 | Location out = locations->Out(); |
| Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 264 | // Move the class to the desired location. |
| Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 265 | if (out.IsValid()) { |
| 266 | DCHECK(out.IsRegister() && !locations->GetLiveRegisters()->ContainsCoreRegister(out.reg())); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 267 | x86_64_codegen->Move(out, Location::RegisterLocation(RAX)); |
| Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 268 | } |
| 269 | |
| Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 270 | RestoreLiveRegisters(codegen, locations); |
| Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 271 | // For HLoadClass/kBssEntry, store the resolved Class to the BSS entry. |
| 272 | DCHECK_EQ(instruction_->IsLoadClass(), cls_ == instruction_); |
| 273 | if (cls_ == instruction_ && cls_->GetLoadKind() == HLoadClass::LoadKind::kBssEntry) { |
| 274 | DCHECK(out.IsValid()); |
| 275 | __ movl(Address::Absolute(CodeGeneratorX86_64::kDummy32BitOffset, /* no_rip */ false), |
| 276 | locations->Out().AsRegister<CpuRegister>()); |
| 277 | Label* fixup_label = x86_64_codegen->NewTypeBssEntryPatch(cls_); |
| 278 | __ Bind(fixup_label); |
| 279 | } |
| Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 280 | __ jmp(GetExitLabel()); |
| 281 | } |
| 282 | |
| Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 283 | const char* GetDescription() const OVERRIDE { return "LoadClassSlowPathX86_64"; } |
| 284 | |
| Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 285 | private: |
| Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 286 | // The class this slow path will load. |
| 287 | HLoadClass* const cls_; |
| Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 288 | |
| Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 289 | // The dex PC of `at_`. |
| 290 | const uint32_t dex_pc_; |
| 291 | |
| 292 | // Whether to initialize the class. |
| 293 | const bool do_clinit_; |
| 294 | |
| 295 | DISALLOW_COPY_AND_ASSIGN(LoadClassSlowPathX86_64); |
| Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 296 | }; |
| 297 | |
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 298 | class LoadStringSlowPathX86_64 : public SlowPathCode { |
| 299 | public: |
| 300 | explicit LoadStringSlowPathX86_64(HLoadString* instruction) : SlowPathCode(instruction) {} |
| 301 | |
| 302 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 303 | LocationSummary* locations = instruction_->GetLocations(); |
| 304 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
| 305 | |
| 306 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
| 307 | __ Bind(GetEntryLabel()); |
| 308 | SaveLiveRegisters(codegen, locations); |
| 309 | |
| Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 310 | const dex::StringIndex string_index = instruction_->AsLoadString()->GetStringIndex(); |
| Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 311 | // Custom calling convention: RAX serves as both input and output. |
| Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 312 | __ movl(CpuRegister(RAX), Immediate(string_index.index_)); |
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 313 | x86_64_codegen->InvokeRuntime(kQuickResolveString, |
| 314 | instruction_, |
| 315 | instruction_->GetDexPc(), |
| 316 | this); |
| 317 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
| 318 | x86_64_codegen->Move(locations->Out(), Location::RegisterLocation(RAX)); |
| 319 | RestoreLiveRegisters(codegen, locations); |
| 320 | |
| 321 | // Store the resolved String to the BSS entry. |
| 322 | __ movl(Address::Absolute(CodeGeneratorX86_64::kDummy32BitOffset, /* no_rip */ false), |
| 323 | locations->Out().AsRegister<CpuRegister>()); |
| 324 | Label* fixup_label = x86_64_codegen->NewStringBssEntryPatch(instruction_->AsLoadString()); |
| 325 | __ Bind(fixup_label); |
| 326 | |
| 327 | __ jmp(GetExitLabel()); |
| 328 | } |
| 329 | |
| 330 | const char* GetDescription() const OVERRIDE { return "LoadStringSlowPathX86_64"; } |
| 331 | |
| 332 | private: |
| 333 | DISALLOW_COPY_AND_ASSIGN(LoadStringSlowPathX86_64); |
| 334 | }; |
| 335 | |
| Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 336 | class TypeCheckSlowPathX86_64 : public SlowPathCode { |
| Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 337 | public: |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 338 | TypeCheckSlowPathX86_64(HInstruction* instruction, bool is_fatal) |
| David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 339 | : SlowPathCode(instruction), is_fatal_(is_fatal) {} |
| Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 340 | |
| Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 341 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 342 | LocationSummary* locations = instruction_->GetLocations(); |
| Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 343 | uint32_t dex_pc = instruction_->GetDexPc(); |
| Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 344 | DCHECK(instruction_->IsCheckCast() |
| 345 | || !locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
| Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 346 | |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 347 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
| Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 348 | __ Bind(GetEntryLabel()); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 349 | |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 350 | if (!is_fatal_) { |
| 351 | SaveLiveRegisters(codegen, locations); |
| 352 | } |
| Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 353 | |
| 354 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 355 | // move resolver. |
| 356 | InvokeRuntimeCallingConvention calling_convention; |
| Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 357 | codegen->EmitParallelMoves(locations->InAt(0), |
| Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 358 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| 359 | Primitive::kPrimNot, |
| Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 360 | locations->InAt(1), |
| Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 361 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 362 | Primitive::kPrimNot); |
| Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 363 | if (instruction_->IsInstanceOf()) { |
| Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 364 | x86_64_codegen->InvokeRuntime(kQuickInstanceofNonTrivial, instruction_, dex_pc, this); |
| Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 365 | CheckEntrypointTypes<kQuickInstanceofNonTrivial, size_t, mirror::Object*, mirror::Class*>(); |
| Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 366 | } else { |
| 367 | DCHECK(instruction_->IsCheckCast()); |
| Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 368 | x86_64_codegen->InvokeRuntime(kQuickCheckInstanceOf, instruction_, dex_pc, this); |
| 369 | CheckEntrypointTypes<kQuickCheckInstanceOf, void, mirror::Object*, mirror::Class*>(); |
| Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 370 | } |
| Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 371 | |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 372 | if (!is_fatal_) { |
| 373 | if (instruction_->IsInstanceOf()) { |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 374 | x86_64_codegen->Move(locations->Out(), Location::RegisterLocation(RAX)); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 375 | } |
| Nicolas Geoffray | 7537437 | 2015-09-17 17:12:19 +0000 | [diff] [blame] | 376 | |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 377 | RestoreLiveRegisters(codegen, locations); |
| 378 | __ jmp(GetExitLabel()); |
| 379 | } |
| Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 380 | } |
| 381 | |
| Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 382 | const char* GetDescription() const OVERRIDE { return "TypeCheckSlowPathX86_64"; } |
| 383 | |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 384 | bool IsFatal() const OVERRIDE { return is_fatal_; } |
| 385 | |
| Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 386 | private: |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 387 | const bool is_fatal_; |
| Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 388 | |
| 389 | DISALLOW_COPY_AND_ASSIGN(TypeCheckSlowPathX86_64); |
| 390 | }; |
| 391 | |
| Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 392 | class DeoptimizationSlowPathX86_64 : public SlowPathCode { |
| Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 393 | public: |
| Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 394 | explicit DeoptimizationSlowPathX86_64(HDeoptimize* instruction) |
| David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 395 | : SlowPathCode(instruction) {} |
| Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 396 | |
| 397 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 398 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
| Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 399 | __ Bind(GetEntryLabel()); |
| Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 400 | LocationSummary* locations = instruction_->GetLocations(); |
| 401 | SaveLiveRegisters(codegen, locations); |
| 402 | InvokeRuntimeCallingConvention calling_convention; |
| 403 | x86_64_codegen->Load32BitValue( |
| 404 | CpuRegister(calling_convention.GetRegisterAt(0)), |
| 405 | static_cast<uint32_t>(instruction_->AsDeoptimize()->GetDeoptimizationKind())); |
| Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 406 | x86_64_codegen->InvokeRuntime(kQuickDeoptimize, instruction_, instruction_->GetDexPc(), this); |
| Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 407 | CheckEntrypointTypes<kQuickDeoptimize, void, DeoptimizationKind>(); |
| Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 408 | } |
| 409 | |
| Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 410 | const char* GetDescription() const OVERRIDE { return "DeoptimizationSlowPathX86_64"; } |
| 411 | |
| Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 412 | private: |
| Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 413 | DISALLOW_COPY_AND_ASSIGN(DeoptimizationSlowPathX86_64); |
| 414 | }; |
| 415 | |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 416 | class ArraySetSlowPathX86_64 : public SlowPathCode { |
| 417 | public: |
| David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 418 | explicit ArraySetSlowPathX86_64(HInstruction* instruction) : SlowPathCode(instruction) {} |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 419 | |
| 420 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 421 | LocationSummary* locations = instruction_->GetLocations(); |
| 422 | __ Bind(GetEntryLabel()); |
| 423 | SaveLiveRegisters(codegen, locations); |
| 424 | |
| 425 | InvokeRuntimeCallingConvention calling_convention; |
| 426 | HParallelMove parallel_move(codegen->GetGraph()->GetArena()); |
| 427 | parallel_move.AddMove( |
| 428 | locations->InAt(0), |
| 429 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| 430 | Primitive::kPrimNot, |
| 431 | nullptr); |
| 432 | parallel_move.AddMove( |
| 433 | locations->InAt(1), |
| 434 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 435 | Primitive::kPrimInt, |
| 436 | nullptr); |
| 437 | parallel_move.AddMove( |
| 438 | locations->InAt(2), |
| 439 | Location::RegisterLocation(calling_convention.GetRegisterAt(2)), |
| 440 | Primitive::kPrimNot, |
| 441 | nullptr); |
| 442 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 443 | |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 444 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
| Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 445 | x86_64_codegen->InvokeRuntime(kQuickAputObject, instruction_, instruction_->GetDexPc(), this); |
| Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 446 | CheckEntrypointTypes<kQuickAputObject, void, mirror::Array*, int32_t, mirror::Object*>(); |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 447 | RestoreLiveRegisters(codegen, locations); |
| 448 | __ jmp(GetExitLabel()); |
| 449 | } |
| 450 | |
| 451 | const char* GetDescription() const OVERRIDE { return "ArraySetSlowPathX86_64"; } |
| 452 | |
| 453 | private: |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 454 | DISALLOW_COPY_AND_ASSIGN(ArraySetSlowPathX86_64); |
| 455 | }; |
| 456 | |
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 457 | // Slow path marking an object reference `ref` during a read |
| 458 | // barrier. The field `obj.field` in the object `obj` holding this |
| 459 | // reference does not get updated by this slow path after marking (see |
| 460 | // ReadBarrierMarkAndUpdateFieldSlowPathX86_64 below for that). |
| 461 | // |
| 462 | // This means that after the execution of this slow path, `ref` will |
| 463 | // always be up-to-date, but `obj.field` may not; i.e., after the |
| 464 | // flip, `ref` will be a to-space reference, but `obj.field` will |
| 465 | // probably still be a from-space reference (unless it gets updated by |
| 466 | // another thread, or if another thread installed another object |
| 467 | // reference (different from `ref`) in `obj.field`). |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 468 | class ReadBarrierMarkSlowPathX86_64 : public SlowPathCode { |
| 469 | public: |
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 470 | ReadBarrierMarkSlowPathX86_64(HInstruction* instruction, |
| 471 | Location ref, |
| 472 | bool unpoison_ref_before_marking) |
| 473 | : SlowPathCode(instruction), |
| 474 | ref_(ref), |
| 475 | unpoison_ref_before_marking_(unpoison_ref_before_marking) { |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 476 | DCHECK(kEmitCompilerReadBarrier); |
| 477 | } |
| 478 | |
| 479 | const char* GetDescription() const OVERRIDE { return "ReadBarrierMarkSlowPathX86_64"; } |
| 480 | |
| 481 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 482 | LocationSummary* locations = instruction_->GetLocations(); |
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 483 | CpuRegister ref_cpu_reg = ref_.AsRegister<CpuRegister>(); |
| 484 | Register ref_reg = ref_cpu_reg.AsRegister(); |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 485 | DCHECK(locations->CanCall()); |
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 486 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(ref_reg)) << ref_reg; |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 487 | DCHECK(instruction_->IsInstanceFieldGet() || |
| 488 | instruction_->IsStaticFieldGet() || |
| 489 | instruction_->IsArrayGet() || |
| Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 490 | instruction_->IsArraySet() || |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 491 | instruction_->IsLoadClass() || |
| 492 | instruction_->IsLoadString() || |
| 493 | instruction_->IsInstanceOf() || |
| Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 494 | instruction_->IsCheckCast() || |
| Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 495 | (instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified()) || |
| 496 | (instruction_->IsInvokeStaticOrDirect() && instruction_->GetLocations()->Intrinsified())) |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 497 | << "Unexpected instruction in read barrier marking slow path: " |
| 498 | << instruction_->DebugName(); |
| 499 | |
| 500 | __ Bind(GetEntryLabel()); |
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 501 | if (unpoison_ref_before_marking_) { |
| Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 502 | // Object* ref = ref_addr->AsMirrorPtr() |
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 503 | __ MaybeUnpoisonHeapReference(ref_cpu_reg); |
| Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 504 | } |
| Roland Levillain | 4359e61 | 2016-07-20 11:32:19 +0100 | [diff] [blame] | 505 | // No need to save live registers; it's taken care of by the |
| 506 | // entrypoint. Also, there is no need to update the stack mask, |
| 507 | // as this runtime call will not trigger a garbage collection. |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 508 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 509 | DCHECK_NE(ref_reg, RSP); |
| 510 | DCHECK(0 <= ref_reg && ref_reg < kNumberOfCpuRegisters) << ref_reg; |
| Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 511 | // "Compact" slow path, saving two moves. |
| 512 | // |
| 513 | // Instead of using the standard runtime calling convention (input |
| 514 | // and output in R0): |
| 515 | // |
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 516 | // RDI <- ref |
| Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 517 | // RAX <- ReadBarrierMark(RDI) |
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 518 | // ref <- RAX |
| Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 519 | // |
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 520 | // we just use rX (the register containing `ref`) as input and output |
| Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 521 | // of a dedicated entrypoint: |
| 522 | // |
| 523 | // rX <- ReadBarrierMarkRegX(rX) |
| 524 | // |
| 525 | int32_t entry_point_offset = |
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 526 | CodeGenerator::GetReadBarrierMarkEntryPointsOffset<kX86_64PointerSize>(ref_reg); |
| Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 527 | // This runtime call does not require a stack map. |
| 528 | x86_64_codegen->InvokeRuntimeWithoutRecordingPcInfo(entry_point_offset, instruction_, this); |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 529 | __ jmp(GetExitLabel()); |
| 530 | } |
| 531 | |
| 532 | private: |
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 533 | // The location (register) of the marked object reference. |
| 534 | const Location ref_; |
| 535 | // Should the reference in `ref_` be unpoisoned prior to marking it? |
| 536 | const bool unpoison_ref_before_marking_; |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 537 | |
| 538 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierMarkSlowPathX86_64); |
| 539 | }; |
| 540 | |
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 541 | // Slow path marking an object reference `ref` during a read barrier, |
| 542 | // and if needed, atomically updating the field `obj.field` in the |
| 543 | // object `obj` holding this reference after marking (contrary to |
| 544 | // ReadBarrierMarkSlowPathX86_64 above, which never tries to update |
| 545 | // `obj.field`). |
| 546 | // |
| 547 | // This means that after the execution of this slow path, both `ref` |
| 548 | // and `obj.field` will be up-to-date; i.e., after the flip, both will |
| 549 | // hold the same to-space reference (unless another thread installed |
| 550 | // another object reference (different from `ref`) in `obj.field`). |
| 551 | class ReadBarrierMarkAndUpdateFieldSlowPathX86_64 : public SlowPathCode { |
| 552 | public: |
| 553 | ReadBarrierMarkAndUpdateFieldSlowPathX86_64(HInstruction* instruction, |
| 554 | Location ref, |
| 555 | CpuRegister obj, |
| 556 | const Address& field_addr, |
| 557 | bool unpoison_ref_before_marking, |
| 558 | CpuRegister temp1, |
| 559 | CpuRegister temp2) |
| 560 | : SlowPathCode(instruction), |
| 561 | ref_(ref), |
| 562 | obj_(obj), |
| 563 | field_addr_(field_addr), |
| 564 | unpoison_ref_before_marking_(unpoison_ref_before_marking), |
| 565 | temp1_(temp1), |
| 566 | temp2_(temp2) { |
| 567 | DCHECK(kEmitCompilerReadBarrier); |
| 568 | } |
| 569 | |
| 570 | const char* GetDescription() const OVERRIDE { |
| 571 | return "ReadBarrierMarkAndUpdateFieldSlowPathX86_64"; |
| 572 | } |
| 573 | |
| 574 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 575 | LocationSummary* locations = instruction_->GetLocations(); |
| 576 | CpuRegister ref_cpu_reg = ref_.AsRegister<CpuRegister>(); |
| 577 | Register ref_reg = ref_cpu_reg.AsRegister(); |
| 578 | DCHECK(locations->CanCall()); |
| 579 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(ref_reg)) << ref_reg; |
| 580 | // This slow path is only used by the UnsafeCASObject intrinsic. |
| 581 | DCHECK((instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified())) |
| 582 | << "Unexpected instruction in read barrier marking and field updating slow path: " |
| 583 | << instruction_->DebugName(); |
| 584 | DCHECK(instruction_->GetLocations()->Intrinsified()); |
| 585 | DCHECK_EQ(instruction_->AsInvoke()->GetIntrinsic(), Intrinsics::kUnsafeCASObject); |
| 586 | |
| 587 | __ Bind(GetEntryLabel()); |
| 588 | if (unpoison_ref_before_marking_) { |
| 589 | // Object* ref = ref_addr->AsMirrorPtr() |
| 590 | __ MaybeUnpoisonHeapReference(ref_cpu_reg); |
| 591 | } |
| 592 | |
| 593 | // Save the old (unpoisoned) reference. |
| 594 | __ movl(temp1_, ref_cpu_reg); |
| 595 | |
| 596 | // No need to save live registers; it's taken care of by the |
| 597 | // entrypoint. Also, there is no need to update the stack mask, |
| 598 | // as this runtime call will not trigger a garbage collection. |
| 599 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
| 600 | DCHECK_NE(ref_reg, RSP); |
| 601 | DCHECK(0 <= ref_reg && ref_reg < kNumberOfCpuRegisters) << ref_reg; |
| 602 | // "Compact" slow path, saving two moves. |
| 603 | // |
| 604 | // Instead of using the standard runtime calling convention (input |
| 605 | // and output in R0): |
| 606 | // |
| 607 | // RDI <- ref |
| 608 | // RAX <- ReadBarrierMark(RDI) |
| 609 | // ref <- RAX |
| 610 | // |
| 611 | // we just use rX (the register containing `ref`) as input and output |
| 612 | // of a dedicated entrypoint: |
| 613 | // |
| 614 | // rX <- ReadBarrierMarkRegX(rX) |
| 615 | // |
| 616 | int32_t entry_point_offset = |
| 617 | CodeGenerator::GetReadBarrierMarkEntryPointsOffset<kX86_64PointerSize>(ref_reg); |
| 618 | // This runtime call does not require a stack map. |
| 619 | x86_64_codegen->InvokeRuntimeWithoutRecordingPcInfo(entry_point_offset, instruction_, this); |
| 620 | |
| 621 | // If the new reference is different from the old reference, |
| 622 | // update the field in the holder (`*field_addr`). |
| 623 | // |
| 624 | // Note that this field could also hold a different object, if |
| 625 | // another thread had concurrently changed it. In that case, the |
| 626 | // LOCK CMPXCHGL instruction in the compare-and-set (CAS) |
| 627 | // operation below would abort the CAS, leaving the field as-is. |
| 628 | NearLabel done; |
| 629 | __ cmpl(temp1_, ref_cpu_reg); |
| 630 | __ j(kEqual, &done); |
| 631 | |
| 632 | // Update the the holder's field atomically. This may fail if |
| 633 | // mutator updates before us, but it's OK. This is achived |
| 634 | // using a strong compare-and-set (CAS) operation with relaxed |
| 635 | // memory synchronization ordering, where the expected value is |
| 636 | // the old reference and the desired value is the new reference. |
| 637 | // This operation is implemented with a 32-bit LOCK CMPXLCHG |
| 638 | // instruction, which requires the expected value (the old |
| 639 | // reference) to be in EAX. Save RAX beforehand, and move the |
| 640 | // expected value (stored in `temp1_`) into EAX. |
| 641 | __ movq(temp2_, CpuRegister(RAX)); |
| 642 | __ movl(CpuRegister(RAX), temp1_); |
| 643 | |
| 644 | // Convenience aliases. |
| 645 | CpuRegister base = obj_; |
| 646 | CpuRegister expected = CpuRegister(RAX); |
| 647 | CpuRegister value = ref_cpu_reg; |
| 648 | |
| 649 | bool base_equals_value = (base.AsRegister() == value.AsRegister()); |
| 650 | Register value_reg = ref_reg; |
| 651 | if (kPoisonHeapReferences) { |
| 652 | if (base_equals_value) { |
| 653 | // If `base` and `value` are the same register location, move |
| 654 | // `value_reg` to a temporary register. This way, poisoning |
| 655 | // `value_reg` won't invalidate `base`. |
| 656 | value_reg = temp1_.AsRegister(); |
| 657 | __ movl(CpuRegister(value_reg), base); |
| 658 | } |
| 659 | |
| 660 | // Check that the register allocator did not assign the location |
| 661 | // of `expected` (RAX) to `value` nor to `base`, so that heap |
| 662 | // poisoning (when enabled) works as intended below. |
| 663 | // - If `value` were equal to `expected`, both references would |
| 664 | // be poisoned twice, meaning they would not be poisoned at |
| 665 | // all, as heap poisoning uses address negation. |
| 666 | // - If `base` were equal to `expected`, poisoning `expected` |
| 667 | // would invalidate `base`. |
| 668 | DCHECK_NE(value_reg, expected.AsRegister()); |
| 669 | DCHECK_NE(base.AsRegister(), expected.AsRegister()); |
| 670 | |
| 671 | __ PoisonHeapReference(expected); |
| 672 | __ PoisonHeapReference(CpuRegister(value_reg)); |
| 673 | } |
| 674 | |
| 675 | __ LockCmpxchgl(field_addr_, CpuRegister(value_reg)); |
| 676 | |
| 677 | // If heap poisoning is enabled, we need to unpoison the values |
| 678 | // that were poisoned earlier. |
| 679 | if (kPoisonHeapReferences) { |
| 680 | if (base_equals_value) { |
| 681 | // `value_reg` has been moved to a temporary register, no need |
| 682 | // to unpoison it. |
| 683 | } else { |
| 684 | __ UnpoisonHeapReference(CpuRegister(value_reg)); |
| 685 | } |
| 686 | // No need to unpoison `expected` (RAX), as it is be overwritten below. |
| 687 | } |
| 688 | |
| 689 | // Restore RAX. |
| 690 | __ movq(CpuRegister(RAX), temp2_); |
| 691 | |
| 692 | __ Bind(&done); |
| 693 | __ jmp(GetExitLabel()); |
| 694 | } |
| 695 | |
| 696 | private: |
| 697 | // The location (register) of the marked object reference. |
| 698 | const Location ref_; |
| 699 | // The register containing the object holding the marked object reference field. |
| 700 | const CpuRegister obj_; |
| 701 | // The address of the marked reference field. The base of this address must be `obj_`. |
| 702 | const Address field_addr_; |
| 703 | |
| 704 | // Should the reference in `ref_` be unpoisoned prior to marking it? |
| 705 | const bool unpoison_ref_before_marking_; |
| 706 | |
| 707 | const CpuRegister temp1_; |
| 708 | const CpuRegister temp2_; |
| 709 | |
| 710 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierMarkAndUpdateFieldSlowPathX86_64); |
| 711 | }; |
| 712 | |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 713 | // Slow path generating a read barrier for a heap reference. |
| 714 | class ReadBarrierForHeapReferenceSlowPathX86_64 : public SlowPathCode { |
| 715 | public: |
| 716 | ReadBarrierForHeapReferenceSlowPathX86_64(HInstruction* instruction, |
| 717 | Location out, |
| 718 | Location ref, |
| 719 | Location obj, |
| 720 | uint32_t offset, |
| 721 | Location index) |
| David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 722 | : SlowPathCode(instruction), |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 723 | out_(out), |
| 724 | ref_(ref), |
| 725 | obj_(obj), |
| 726 | offset_(offset), |
| 727 | index_(index) { |
| 728 | DCHECK(kEmitCompilerReadBarrier); |
| 729 | // If `obj` is equal to `out` or `ref`, it means the initial |
| 730 | // object has been overwritten by (or after) the heap object |
| 731 | // reference load to be instrumented, e.g.: |
| 732 | // |
| 733 | // __ movl(out, Address(out, offset)); |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 734 | // codegen_->GenerateReadBarrierSlow(instruction, out_loc, out_loc, out_loc, offset); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 735 | // |
| 736 | // In that case, we have lost the information about the original |
| 737 | // object, and the emitted read barrier cannot work properly. |
| 738 | DCHECK(!obj.Equals(out)) << "obj=" << obj << " out=" << out; |
| 739 | DCHECK(!obj.Equals(ref)) << "obj=" << obj << " ref=" << ref; |
| 740 | } |
| 741 | |
| 742 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 743 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
| 744 | LocationSummary* locations = instruction_->GetLocations(); |
| 745 | CpuRegister reg_out = out_.AsRegister<CpuRegister>(); |
| 746 | DCHECK(locations->CanCall()); |
| 747 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg_out.AsRegister())) << out_; |
| Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 748 | DCHECK(instruction_->IsInstanceFieldGet() || |
| 749 | instruction_->IsStaticFieldGet() || |
| 750 | instruction_->IsArrayGet() || |
| 751 | instruction_->IsInstanceOf() || |
| 752 | instruction_->IsCheckCast() || |
| Andreas Gampe | d9911ee | 2017-03-27 13:27:24 -0700 | [diff] [blame] | 753 | (instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified())) |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 754 | << "Unexpected instruction in read barrier for heap reference slow path: " |
| 755 | << instruction_->DebugName(); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 756 | |
| 757 | __ Bind(GetEntryLabel()); |
| 758 | SaveLiveRegisters(codegen, locations); |
| 759 | |
| 760 | // We may have to change the index's value, but as `index_` is a |
| 761 | // constant member (like other "inputs" of this slow path), |
| 762 | // introduce a copy of it, `index`. |
| 763 | Location index = index_; |
| 764 | if (index_.IsValid()) { |
| Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 765 | // Handle `index_` for HArrayGet and UnsafeGetObject/UnsafeGetObjectVolatile intrinsics. |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 766 | if (instruction_->IsArrayGet()) { |
| 767 | // Compute real offset and store it in index_. |
| 768 | Register index_reg = index_.AsRegister<CpuRegister>().AsRegister(); |
| 769 | DCHECK(locations->GetLiveRegisters()->ContainsCoreRegister(index_reg)); |
| 770 | if (codegen->IsCoreCalleeSaveRegister(index_reg)) { |
| 771 | // We are about to change the value of `index_reg` (see the |
| 772 | // calls to art::x86_64::X86_64Assembler::shll and |
| 773 | // art::x86_64::X86_64Assembler::AddImmediate below), but it |
| 774 | // has not been saved by the previous call to |
| 775 | // art::SlowPathCode::SaveLiveRegisters, as it is a |
| 776 | // callee-save register -- |
| 777 | // art::SlowPathCode::SaveLiveRegisters does not consider |
| 778 | // callee-save registers, as it has been designed with the |
| 779 | // assumption that callee-save registers are supposed to be |
| 780 | // handled by the called function. So, as a callee-save |
| 781 | // register, `index_reg` _would_ eventually be saved onto |
| 782 | // the stack, but it would be too late: we would have |
| 783 | // changed its value earlier. Therefore, we manually save |
| 784 | // it here into another freely available register, |
| 785 | // `free_reg`, chosen of course among the caller-save |
| 786 | // registers (as a callee-save `free_reg` register would |
| 787 | // exhibit the same problem). |
| 788 | // |
| 789 | // Note we could have requested a temporary register from |
| 790 | // the register allocator instead; but we prefer not to, as |
| 791 | // this is a slow path, and we know we can find a |
| 792 | // caller-save register that is available. |
| 793 | Register free_reg = FindAvailableCallerSaveRegister(codegen).AsRegister(); |
| 794 | __ movl(CpuRegister(free_reg), CpuRegister(index_reg)); |
| 795 | index_reg = free_reg; |
| 796 | index = Location::RegisterLocation(index_reg); |
| 797 | } else { |
| 798 | // The initial register stored in `index_` has already been |
| 799 | // saved in the call to art::SlowPathCode::SaveLiveRegisters |
| 800 | // (as it is not a callee-save register), so we can freely |
| 801 | // use it. |
| 802 | } |
| 803 | // Shifting the index value contained in `index_reg` by the |
| 804 | // scale factor (2) cannot overflow in practice, as the |
| 805 | // runtime is unable to allocate object arrays with a size |
| 806 | // larger than 2^26 - 1 (that is, 2^28 - 4 bytes). |
| 807 | __ shll(CpuRegister(index_reg), Immediate(TIMES_4)); |
| 808 | static_assert( |
| 809 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 810 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 811 | __ AddImmediate(CpuRegister(index_reg), Immediate(offset_)); |
| 812 | } else { |
| Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 813 | // In the case of the UnsafeGetObject/UnsafeGetObjectVolatile |
| 814 | // intrinsics, `index_` is not shifted by a scale factor of 2 |
| 815 | // (as in the case of ArrayGet), as it is actually an offset |
| 816 | // to an object field within an object. |
| 817 | DCHECK(instruction_->IsInvoke()) << instruction_->DebugName(); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 818 | DCHECK(instruction_->GetLocations()->Intrinsified()); |
| 819 | DCHECK((instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObject) || |
| 820 | (instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObjectVolatile)) |
| 821 | << instruction_->AsInvoke()->GetIntrinsic(); |
| 822 | DCHECK_EQ(offset_, 0U); |
| 823 | DCHECK(index_.IsRegister()); |
| 824 | } |
| 825 | } |
| 826 | |
| 827 | // We're moving two or three locations to locations that could |
| 828 | // overlap, so we need a parallel move resolver. |
| 829 | InvokeRuntimeCallingConvention calling_convention; |
| 830 | HParallelMove parallel_move(codegen->GetGraph()->GetArena()); |
| 831 | parallel_move.AddMove(ref_, |
| 832 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| 833 | Primitive::kPrimNot, |
| 834 | nullptr); |
| 835 | parallel_move.AddMove(obj_, |
| 836 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 837 | Primitive::kPrimNot, |
| 838 | nullptr); |
| 839 | if (index.IsValid()) { |
| 840 | parallel_move.AddMove(index, |
| 841 | Location::RegisterLocation(calling_convention.GetRegisterAt(2)), |
| 842 | Primitive::kPrimInt, |
| 843 | nullptr); |
| 844 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 845 | } else { |
| 846 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 847 | __ movl(CpuRegister(calling_convention.GetRegisterAt(2)), Immediate(offset_)); |
| 848 | } |
| Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 849 | x86_64_codegen->InvokeRuntime(kQuickReadBarrierSlow, |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 850 | instruction_, |
| 851 | instruction_->GetDexPc(), |
| 852 | this); |
| 853 | CheckEntrypointTypes< |
| 854 | kQuickReadBarrierSlow, mirror::Object*, mirror::Object*, mirror::Object*, uint32_t>(); |
| 855 | x86_64_codegen->Move(out_, Location::RegisterLocation(RAX)); |
| 856 | |
| 857 | RestoreLiveRegisters(codegen, locations); |
| 858 | __ jmp(GetExitLabel()); |
| 859 | } |
| 860 | |
| 861 | const char* GetDescription() const OVERRIDE { |
| 862 | return "ReadBarrierForHeapReferenceSlowPathX86_64"; |
| 863 | } |
| 864 | |
| 865 | private: |
| 866 | CpuRegister FindAvailableCallerSaveRegister(CodeGenerator* codegen) { |
| 867 | size_t ref = static_cast<int>(ref_.AsRegister<CpuRegister>().AsRegister()); |
| 868 | size_t obj = static_cast<int>(obj_.AsRegister<CpuRegister>().AsRegister()); |
| 869 | for (size_t i = 0, e = codegen->GetNumberOfCoreRegisters(); i < e; ++i) { |
| 870 | if (i != ref && i != obj && !codegen->IsCoreCalleeSaveRegister(i)) { |
| 871 | return static_cast<CpuRegister>(i); |
| 872 | } |
| 873 | } |
| 874 | // We shall never fail to find a free caller-save register, as |
| 875 | // there are more than two core caller-save registers on x86-64 |
| 876 | // (meaning it is possible to find one which is different from |
| 877 | // `ref` and `obj`). |
| 878 | DCHECK_GT(codegen->GetNumberOfCoreCallerSaveRegisters(), 2u); |
| 879 | LOG(FATAL) << "Could not find a free caller-save register"; |
| 880 | UNREACHABLE(); |
| 881 | } |
| 882 | |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 883 | const Location out_; |
| 884 | const Location ref_; |
| 885 | const Location obj_; |
| 886 | const uint32_t offset_; |
| 887 | // An additional location containing an index to an array. |
| 888 | // Only used for HArrayGet and the UnsafeGetObject & |
| 889 | // UnsafeGetObjectVolatile intrinsics. |
| 890 | const Location index_; |
| 891 | |
| 892 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForHeapReferenceSlowPathX86_64); |
| 893 | }; |
| 894 | |
| 895 | // Slow path generating a read barrier for a GC root. |
| 896 | class ReadBarrierForRootSlowPathX86_64 : public SlowPathCode { |
| 897 | public: |
| 898 | ReadBarrierForRootSlowPathX86_64(HInstruction* instruction, Location out, Location root) |
| David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 899 | : SlowPathCode(instruction), out_(out), root_(root) { |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 900 | DCHECK(kEmitCompilerReadBarrier); |
| 901 | } |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 902 | |
| 903 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 904 | LocationSummary* locations = instruction_->GetLocations(); |
| 905 | DCHECK(locations->CanCall()); |
| 906 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(out_.reg())); |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 907 | DCHECK(instruction_->IsLoadClass() || instruction_->IsLoadString()) |
| 908 | << "Unexpected instruction in read barrier for GC root slow path: " |
| 909 | << instruction_->DebugName(); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 910 | |
| 911 | __ Bind(GetEntryLabel()); |
| 912 | SaveLiveRegisters(codegen, locations); |
| 913 | |
| 914 | InvokeRuntimeCallingConvention calling_convention; |
| 915 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
| 916 | x86_64_codegen->Move(Location::RegisterLocation(calling_convention.GetRegisterAt(0)), root_); |
| Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 917 | x86_64_codegen->InvokeRuntime(kQuickReadBarrierForRootSlow, |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 918 | instruction_, |
| 919 | instruction_->GetDexPc(), |
| 920 | this); |
| 921 | CheckEntrypointTypes<kQuickReadBarrierForRootSlow, mirror::Object*, GcRoot<mirror::Object>*>(); |
| 922 | x86_64_codegen->Move(out_, Location::RegisterLocation(RAX)); |
| 923 | |
| 924 | RestoreLiveRegisters(codegen, locations); |
| 925 | __ jmp(GetExitLabel()); |
| 926 | } |
| 927 | |
| 928 | const char* GetDescription() const OVERRIDE { return "ReadBarrierForRootSlowPathX86_64"; } |
| 929 | |
| 930 | private: |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 931 | const Location out_; |
| 932 | const Location root_; |
| 933 | |
| 934 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForRootSlowPathX86_64); |
| 935 | }; |
| 936 | |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 937 | #undef __ |
| Roland Levillain | 7cbd27f | 2016-08-11 23:53:33 +0100 | [diff] [blame] | 938 | // NOLINT on __ macro to suppress wrong warning/fix (misc-macro-parentheses) from clang-tidy. |
| 939 | #define __ down_cast<X86_64Assembler*>(GetAssembler())-> // NOLINT |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 940 | |
| Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 941 | inline Condition X86_64IntegerCondition(IfCondition cond) { |
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 942 | switch (cond) { |
| 943 | case kCondEQ: return kEqual; |
| 944 | case kCondNE: return kNotEqual; |
| 945 | case kCondLT: return kLess; |
| 946 | case kCondLE: return kLessEqual; |
| 947 | case kCondGT: return kGreater; |
| 948 | case kCondGE: return kGreaterEqual; |
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 949 | case kCondB: return kBelow; |
| 950 | case kCondBE: return kBelowEqual; |
| 951 | case kCondA: return kAbove; |
| 952 | case kCondAE: return kAboveEqual; |
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 953 | } |
| Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 954 | LOG(FATAL) << "Unreachable"; |
| 955 | UNREACHABLE(); |
| 956 | } |
| 957 | |
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 958 | // Maps FP condition to x86_64 name. |
| Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 959 | inline Condition X86_64FPCondition(IfCondition cond) { |
| 960 | switch (cond) { |
| 961 | case kCondEQ: return kEqual; |
| 962 | case kCondNE: return kNotEqual; |
| 963 | case kCondLT: return kBelow; |
| 964 | case kCondLE: return kBelowEqual; |
| 965 | case kCondGT: return kAbove; |
| 966 | case kCondGE: return kAboveEqual; |
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 967 | default: break; // should not happen |
| Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 968 | }; |
| 969 | LOG(FATAL) << "Unreachable"; |
| 970 | UNREACHABLE(); |
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 971 | } |
| 972 | |
| Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 973 | HInvokeStaticOrDirect::DispatchInfo CodeGeneratorX86_64::GetSupportedInvokeStaticOrDirectDispatch( |
| 974 | const HInvokeStaticOrDirect::DispatchInfo& desired_dispatch_info, |
| Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 975 | HInvokeStaticOrDirect* invoke ATTRIBUTE_UNUSED) { |
| Nicolas Geoffray | c1a42cf | 2016-12-18 15:52:36 +0000 | [diff] [blame] | 976 | return desired_dispatch_info; |
| Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 977 | } |
| 978 | |
| Serguei Katkov | 288c7a8 | 2016-05-16 11:53:15 +0600 | [diff] [blame] | 979 | Location CodeGeneratorX86_64::GenerateCalleeMethodStaticOrDirectCall(HInvokeStaticOrDirect* invoke, |
| 980 | Location temp) { |
| Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 981 | // All registers are assumed to be correctly set up. |
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 982 | Location callee_method = temp; // For all kinds except kRecursive, callee will be in temp. |
| 983 | switch (invoke->GetMethodLoadKind()) { |
| Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 984 | case HInvokeStaticOrDirect::MethodLoadKind::kStringInit: { |
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 985 | // temp = thread->string_init_entrypoint |
| Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 986 | uint32_t offset = |
| 987 | GetThreadOffset<kX86_64PointerSize>(invoke->GetStringInitEntryPoint()).Int32Value(); |
| 988 | __ gs()->movq(temp.AsRegister<CpuRegister>(), Address::Absolute(offset, /* no_rip */ true)); |
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 989 | break; |
| Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 990 | } |
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 991 | case HInvokeStaticOrDirect::MethodLoadKind::kRecursive: |
| Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 992 | callee_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 993 | break; |
| 994 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddress: |
| Vladimir Marko | 2d73f33 | 2017-03-16 15:55:49 +0000 | [diff] [blame] | 995 | Load64BitValue(temp.AsRegister<CpuRegister>(), invoke->GetMethodAddress()); |
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 996 | break; |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 997 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCachePcRelative: { |
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 998 | __ movq(temp.AsRegister<CpuRegister>(), |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 999 | Address::Absolute(kDummy32BitOffset, /* no_rip */ false)); |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 1000 | // Bind a new fixup label at the end of the "movl" insn. |
| 1001 | uint32_t offset = invoke->GetDexCacheArrayOffset(); |
| Nicolas Geoffray | 5d37c15 | 2017-01-12 13:25:19 +0000 | [diff] [blame] | 1002 | __ Bind(NewPcRelativeDexCacheArrayPatch(invoke->GetDexFileForPcRelativeDexCache(), offset)); |
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 1003 | break; |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 1004 | } |
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 1005 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCacheViaMethod: { |
| Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 1006 | Location current_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 1007 | Register method_reg; |
| 1008 | CpuRegister reg = temp.AsRegister<CpuRegister>(); |
| 1009 | if (current_method.IsRegister()) { |
| 1010 | method_reg = current_method.AsRegister<Register>(); |
| 1011 | } else { |
| 1012 | DCHECK(invoke->GetLocations()->Intrinsified()); |
| 1013 | DCHECK(!current_method.IsValid()); |
| 1014 | method_reg = reg.AsRegister(); |
| 1015 | __ movq(reg, Address(CpuRegister(RSP), kCurrentMethodStackOffset)); |
| 1016 | } |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 1017 | // /* ArtMethod*[] */ temp = temp.ptr_sized_fields_->dex_cache_resolved_methods_; |
| Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 1018 | __ movq(reg, |
| 1019 | Address(CpuRegister(method_reg), |
| 1020 | ArtMethod::DexCacheResolvedMethodsOffset(kX86_64PointerSize).SizeValue())); |
| Vladimir Marko | 40ecb12 | 2016-04-06 17:33:41 +0100 | [diff] [blame] | 1021 | // temp = temp[index_in_cache]; |
| 1022 | // Note: Don't use invoke->GetTargetMethod() as it may point to a different dex file. |
| 1023 | uint32_t index_in_cache = invoke->GetDexMethodIndex(); |
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 1024 | __ movq(reg, Address(reg, CodeGenerator::GetCachePointerOffset(index_in_cache))); |
| 1025 | break; |
| Vladimir Marko | 9b688a0 | 2015-05-06 14:12:42 +0100 | [diff] [blame] | 1026 | } |
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 1027 | } |
| Serguei Katkov | 288c7a8 | 2016-05-16 11:53:15 +0600 | [diff] [blame] | 1028 | return callee_method; |
| 1029 | } |
| 1030 | |
| 1031 | void CodeGeneratorX86_64::GenerateStaticOrDirectCall(HInvokeStaticOrDirect* invoke, |
| 1032 | Location temp) { |
| 1033 | // All registers are assumed to be correctly set up. |
| 1034 | Location callee_method = GenerateCalleeMethodStaticOrDirectCall(invoke, temp); |
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 1035 | |
| 1036 | switch (invoke->GetCodePtrLocation()) { |
| 1037 | case HInvokeStaticOrDirect::CodePtrLocation::kCallSelf: |
| 1038 | __ call(&frame_entry_label_); |
| 1039 | break; |
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 1040 | case HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod: |
| 1041 | // (callee_method + offset_of_quick_compiled_code)() |
| 1042 | __ call(Address(callee_method.AsRegister<CpuRegister>(), |
| 1043 | ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
| Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 1044 | kX86_64PointerSize).SizeValue())); |
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 1045 | break; |
| Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 1046 | } |
| Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 1047 | |
| 1048 | DCHECK(!IsLeafMethod()); |
| Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 1049 | } |
| 1050 | |
| Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 1051 | void CodeGeneratorX86_64::GenerateVirtualCall(HInvokeVirtual* invoke, Location temp_in) { |
| 1052 | CpuRegister temp = temp_in.AsRegister<CpuRegister>(); |
| 1053 | size_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| 1054 | invoke->GetVTableIndex(), kX86_64PointerSize).SizeValue(); |
| Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 1055 | |
| 1056 | // Use the calling convention instead of the location of the receiver, as |
| 1057 | // intrinsics may have put the receiver in a different register. In the intrinsics |
| 1058 | // slow path, the arguments have been moved to the right place, so here we are |
| 1059 | // guaranteed that the receiver is the first register of the calling convention. |
| 1060 | InvokeDexCallingConvention calling_convention; |
| 1061 | Register receiver = calling_convention.GetRegisterAt(0); |
| 1062 | |
| Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 1063 | size_t class_offset = mirror::Object::ClassOffset().SizeValue(); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 1064 | // /* HeapReference<Class> */ temp = receiver->klass_ |
| Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 1065 | __ movl(temp, Address(CpuRegister(receiver), class_offset)); |
| Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 1066 | MaybeRecordImplicitNullCheck(invoke); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 1067 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 1068 | // emit a read barrier for the previous class reference load. |
| 1069 | // However this is not required in practice, as this is an |
| 1070 | // intermediate/temporary reference and because the current |
| 1071 | // concurrent copying collector keeps the from-space memory |
| 1072 | // intact/accessible until the end of the marking phase (the |
| 1073 | // concurrent copying collector may not in the future). |
| Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 1074 | __ MaybeUnpoisonHeapReference(temp); |
| 1075 | // temp = temp->GetMethodAt(method_offset); |
| 1076 | __ movq(temp, Address(temp, method_offset)); |
| 1077 | // call temp->GetEntryPoint(); |
| 1078 | __ call(Address(temp, ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
| Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 1079 | kX86_64PointerSize).SizeValue())); |
| Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 1080 | } |
| 1081 | |
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 1082 | void CodeGeneratorX86_64::RecordBootStringPatch(HLoadString* load_string) { |
| 1083 | DCHECK(GetCompilerOptions().IsBootImage()); |
| Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 1084 | string_patches_.emplace_back(load_string->GetDexFile(), load_string->GetStringIndex().index_); |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 1085 | __ Bind(&string_patches_.back().label); |
| 1086 | } |
| 1087 | |
| Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 1088 | void CodeGeneratorX86_64::RecordBootTypePatch(HLoadClass* load_class) { |
| 1089 | boot_image_type_patches_.emplace_back(load_class->GetDexFile(), |
| 1090 | load_class->GetTypeIndex().index_); |
| 1091 | __ Bind(&boot_image_type_patches_.back().label); |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 1092 | } |
| 1093 | |
| Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 1094 | Label* CodeGeneratorX86_64::NewTypeBssEntryPatch(HLoadClass* load_class) { |
| Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 1095 | type_bss_entry_patches_.emplace_back(load_class->GetDexFile(), load_class->GetTypeIndex().index_); |
| 1096 | return &type_bss_entry_patches_.back().label; |
| Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 1097 | } |
| 1098 | |
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 1099 | Label* CodeGeneratorX86_64::NewStringBssEntryPatch(HLoadString* load_string) { |
| 1100 | DCHECK(!GetCompilerOptions().IsBootImage()); |
| Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 1101 | string_patches_.emplace_back(load_string->GetDexFile(), load_string->GetStringIndex().index_); |
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 1102 | return &string_patches_.back().label; |
| 1103 | } |
| 1104 | |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 1105 | Label* CodeGeneratorX86_64::NewPcRelativeDexCacheArrayPatch(const DexFile& dex_file, |
| 1106 | uint32_t element_offset) { |
| 1107 | // Add a patch entry and return the label. |
| 1108 | pc_relative_dex_cache_patches_.emplace_back(dex_file, element_offset); |
| 1109 | return &pc_relative_dex_cache_patches_.back().label; |
| 1110 | } |
| 1111 | |
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 1112 | // The label points to the end of the "movl" or another instruction but the literal offset |
| 1113 | // for method patch needs to point to the embedded constant which occupies the last 4 bytes. |
| 1114 | constexpr uint32_t kLabelPositionToLiteralOffsetAdjustment = 4u; |
| 1115 | |
| 1116 | template <LinkerPatch (*Factory)(size_t, const DexFile*, uint32_t, uint32_t)> |
| 1117 | inline void CodeGeneratorX86_64::EmitPcRelativeLinkerPatches( |
| 1118 | const ArenaDeque<PatchInfo<Label>>& infos, |
| 1119 | ArenaVector<LinkerPatch>* linker_patches) { |
| 1120 | for (const PatchInfo<Label>& info : infos) { |
| 1121 | uint32_t literal_offset = info.label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
| 1122 | linker_patches->push_back( |
| 1123 | Factory(literal_offset, &info.dex_file, info.label.Position(), info.index)); |
| 1124 | } |
| 1125 | } |
| 1126 | |
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 1127 | void CodeGeneratorX86_64::EmitLinkerPatches(ArenaVector<LinkerPatch>* linker_patches) { |
| 1128 | DCHECK(linker_patches->empty()); |
| 1129 | size_t size = |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 1130 | pc_relative_dex_cache_patches_.size() + |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 1131 | string_patches_.size() + |
| Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 1132 | boot_image_type_patches_.size() + |
| 1133 | type_bss_entry_patches_.size(); |
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 1134 | linker_patches->reserve(size); |
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 1135 | EmitPcRelativeLinkerPatches<LinkerPatch::DexCacheArrayPatch>(pc_relative_dex_cache_patches_, |
| 1136 | linker_patches); |
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 1137 | if (!GetCompilerOptions().IsBootImage()) { |
| Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 1138 | DCHECK(boot_image_type_patches_.empty()); |
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 1139 | EmitPcRelativeLinkerPatches<LinkerPatch::StringBssEntryPatch>(string_patches_, linker_patches); |
| 1140 | } else { |
| Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 1141 | // These are always PC-relative, see GetSupportedLoadClassKind()/GetSupportedLoadStringKind(). |
| Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 1142 | EmitPcRelativeLinkerPatches<LinkerPatch::RelativeTypePatch>(boot_image_type_patches_, |
| 1143 | linker_patches); |
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 1144 | EmitPcRelativeLinkerPatches<LinkerPatch::RelativeStringPatch>(string_patches_, linker_patches); |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 1145 | } |
| Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 1146 | EmitPcRelativeLinkerPatches<LinkerPatch::TypeBssEntryPatch>(type_bss_entry_patches_, |
| 1147 | linker_patches); |
| 1148 | DCHECK_EQ(size, linker_patches->size()); |
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 1149 | } |
| 1150 | |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1151 | void CodeGeneratorX86_64::DumpCoreRegister(std::ostream& stream, int reg) const { |
| David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 1152 | stream << Register(reg); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1153 | } |
| 1154 | |
| 1155 | void CodeGeneratorX86_64::DumpFloatingPointRegister(std::ostream& stream, int reg) const { |
| David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 1156 | stream << FloatRegister(reg); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1157 | } |
| 1158 | |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1159 | size_t CodeGeneratorX86_64::SaveCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 1160 | __ movq(Address(CpuRegister(RSP), stack_index), CpuRegister(reg_id)); |
| 1161 | return kX86_64WordSize; |
| Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 1162 | } |
| 1163 | |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1164 | size_t CodeGeneratorX86_64::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 1165 | __ movq(CpuRegister(reg_id), Address(CpuRegister(RSP), stack_index)); |
| 1166 | return kX86_64WordSize; |
| 1167 | } |
| 1168 | |
| 1169 | size_t CodeGeneratorX86_64::SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| Aart Bik | b13c65b | 2017-03-21 20:14:07 -0700 | [diff] [blame] | 1170 | if (GetGraph()->HasSIMD()) { |
| Aart Bik | 5576f37 | 2017-03-23 16:17:37 -0700 | [diff] [blame] | 1171 | __ movups(Address(CpuRegister(RSP), stack_index), XmmRegister(reg_id)); |
| Aart Bik | b13c65b | 2017-03-21 20:14:07 -0700 | [diff] [blame] | 1172 | } else { |
| 1173 | __ movsd(Address(CpuRegister(RSP), stack_index), XmmRegister(reg_id)); |
| 1174 | } |
| 1175 | return GetFloatingPointSpillSlotSize(); |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1176 | } |
| 1177 | |
| 1178 | size_t CodeGeneratorX86_64::RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| Aart Bik | b13c65b | 2017-03-21 20:14:07 -0700 | [diff] [blame] | 1179 | if (GetGraph()->HasSIMD()) { |
| Aart Bik | 5576f37 | 2017-03-23 16:17:37 -0700 | [diff] [blame] | 1180 | __ movups(XmmRegister(reg_id), Address(CpuRegister(RSP), stack_index)); |
| Aart Bik | b13c65b | 2017-03-21 20:14:07 -0700 | [diff] [blame] | 1181 | } else { |
| 1182 | __ movsd(XmmRegister(reg_id), Address(CpuRegister(RSP), stack_index)); |
| 1183 | } |
| 1184 | return GetFloatingPointSpillSlotSize(); |
| Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 1185 | } |
| 1186 | |
| Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1187 | void CodeGeneratorX86_64::InvokeRuntime(QuickEntrypointEnum entrypoint, |
| 1188 | HInstruction* instruction, |
| 1189 | uint32_t dex_pc, |
| 1190 | SlowPathCode* slow_path) { |
| Alexandre Rames | 91a6516 | 2016-09-19 13:54:30 +0100 | [diff] [blame] | 1191 | ValidateInvokeRuntime(entrypoint, instruction, slow_path); |
| Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 1192 | GenerateInvokeRuntime(GetThreadOffset<kX86_64PointerSize>(entrypoint).Int32Value()); |
| 1193 | if (EntrypointRequiresStackMap(entrypoint)) { |
| 1194 | RecordPcInfo(instruction, dex_pc, slow_path); |
| 1195 | } |
| Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 1196 | } |
| 1197 | |
| Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 1198 | void CodeGeneratorX86_64::InvokeRuntimeWithoutRecordingPcInfo(int32_t entry_point_offset, |
| 1199 | HInstruction* instruction, |
| 1200 | SlowPathCode* slow_path) { |
| 1201 | ValidateInvokeRuntimeWithoutRecordingPcInfo(instruction, slow_path); |
| Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 1202 | GenerateInvokeRuntime(entry_point_offset); |
| 1203 | } |
| 1204 | |
| 1205 | void CodeGeneratorX86_64::GenerateInvokeRuntime(int32_t entry_point_offset) { |
| Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 1206 | __ gs()->call(Address::Absolute(entry_point_offset, /* no_rip */ true)); |
| 1207 | } |
| 1208 | |
| Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1209 | static constexpr int kNumberOfCpuRegisterPairs = 0; |
| Nicolas Geoffray | 4597b5b | 2015-01-23 21:51:55 +0000 | [diff] [blame] | 1210 | // Use a fake return address register to mimic Quick. |
| 1211 | static constexpr Register kFakeReturnRegister = Register(kLastCpuRegister + 1); |
| Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 1212 | CodeGeneratorX86_64::CodeGeneratorX86_64(HGraph* graph, |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 1213 | const X86_64InstructionSetFeatures& isa_features, |
| 1214 | const CompilerOptions& compiler_options, |
| 1215 | OptimizingCompilerStats* stats) |
| Nicolas Geoffray | 9889396 | 2015-01-21 12:32:32 +0000 | [diff] [blame] | 1216 | : CodeGenerator(graph, |
| 1217 | kNumberOfCpuRegisters, |
| 1218 | kNumberOfFloatRegisters, |
| Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1219 | kNumberOfCpuRegisterPairs, |
| Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 1220 | ComputeRegisterMask(reinterpret_cast<const int*>(kCoreCalleeSaves), |
| 1221 | arraysize(kCoreCalleeSaves)) |
| Nicolas Geoffray | 4597b5b | 2015-01-23 21:51:55 +0000 | [diff] [blame] | 1222 | | (1 << kFakeReturnRegister), |
| Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 1223 | ComputeRegisterMask(reinterpret_cast<const int*>(kFpuCalleeSaves), |
| 1224 | arraysize(kFpuCalleeSaves)), |
| Serban Constantinescu | ecc4366 | 2015-08-13 13:33:12 +0100 | [diff] [blame] | 1225 | compiler_options, |
| 1226 | stats), |
| Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 1227 | block_labels_(nullptr), |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1228 | location_builder_(graph, this), |
| Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 1229 | instruction_visitor_(graph, this), |
| Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 1230 | move_resolver_(graph->GetArena(), this), |
| Vladimir Marko | 93205e3 | 2016-04-13 11:59:46 +0100 | [diff] [blame] | 1231 | assembler_(graph->GetArena()), |
| Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 1232 | isa_features_(isa_features), |
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 1233 | constant_area_start_(0), |
| Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 1234 | pc_relative_dex_cache_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 1235 | string_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 1236 | boot_image_type_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 1237 | type_bss_entry_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 1238 | fixups_to_jump_tables_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 1239 | jit_string_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 1240 | jit_class_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)) { |
| Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1241 | AddAllocatedRegister(Location::RegisterLocation(kFakeReturnRegister)); |
| 1242 | } |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1243 | |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1244 | InstructionCodeGeneratorX86_64::InstructionCodeGeneratorX86_64(HGraph* graph, |
| 1245 | CodeGeneratorX86_64* codegen) |
| Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 1246 | : InstructionCodeGenerator(graph, codegen), |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1247 | assembler_(codegen->GetAssembler()), |
| 1248 | codegen_(codegen) {} |
| 1249 | |
| David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 1250 | void CodeGeneratorX86_64::SetupBlockedRegisters() const { |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1251 | // Stack register is always reserved. |
| Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 1252 | blocked_core_registers_[RSP] = true; |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1253 | |
| Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 1254 | // Block the register used as TMP. |
| Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 1255 | blocked_core_registers_[TMP] = true; |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1256 | } |
| 1257 | |
| David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1258 | static dwarf::Reg DWARFReg(Register reg) { |
| David Srbecky | 9d8606d | 2015-04-12 09:35:32 +0100 | [diff] [blame] | 1259 | return dwarf::Reg::X86_64Core(static_cast<int>(reg)); |
| David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1260 | } |
| David Srbecky | 9d8606d | 2015-04-12 09:35:32 +0100 | [diff] [blame] | 1261 | |
| David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1262 | static dwarf::Reg DWARFReg(FloatRegister reg) { |
| David Srbecky | 9d8606d | 2015-04-12 09:35:32 +0100 | [diff] [blame] | 1263 | return dwarf::Reg::X86_64Fp(static_cast<int>(reg)); |
| David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1264 | } |
| 1265 | |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1266 | void CodeGeneratorX86_64::GenerateFrameEntry() { |
| David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1267 | __ cfi().SetCurrentCFAOffset(kX86_64WordSize); // return address |
| Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 1268 | __ Bind(&frame_entry_label_); |
| Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 1269 | bool skip_overflow_check = IsLeafMethod() |
| Dave Allison | 648d711 | 2014-07-25 16:15:27 -0700 | [diff] [blame] | 1270 | && !FrameNeedsStackCheck(GetFrameSize(), InstructionSet::kX86_64); |
| Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1271 | DCHECK(GetCompilerOptions().GetImplicitStackOverflowChecks()); |
| Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 1272 | |
| Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1273 | if (!skip_overflow_check) { |
| Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 1274 | __ testq(CpuRegister(RAX), Address( |
| 1275 | CpuRegister(RSP), -static_cast<int32_t>(GetStackOverflowReservedBytes(kX86_64)))); |
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1276 | RecordPcInfo(nullptr, 0); |
| Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 1277 | } |
| Nicolas Geoffray | a26369a | 2015-01-22 08:46:05 +0000 | [diff] [blame] | 1278 | |
| Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1279 | if (HasEmptyFrame()) { |
| 1280 | return; |
| 1281 | } |
| 1282 | |
| Nicolas Geoffray | 9889396 | 2015-01-21 12:32:32 +0000 | [diff] [blame] | 1283 | for (int i = arraysize(kCoreCalleeSaves) - 1; i >= 0; --i) { |
| Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1284 | Register reg = kCoreCalleeSaves[i]; |
| Nicolas Geoffray | 4597b5b | 2015-01-23 21:51:55 +0000 | [diff] [blame] | 1285 | if (allocated_registers_.ContainsCoreRegister(reg)) { |
| Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1286 | __ pushq(CpuRegister(reg)); |
| David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1287 | __ cfi().AdjustCFAOffset(kX86_64WordSize); |
| 1288 | __ cfi().RelOffset(DWARFReg(reg), 0); |
| Nicolas Geoffray | 9889396 | 2015-01-21 12:32:32 +0000 | [diff] [blame] | 1289 | } |
| 1290 | } |
| Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 1291 | |
| David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1292 | int adjust = GetFrameSize() - GetCoreSpillSize(); |
| 1293 | __ subq(CpuRegister(RSP), Immediate(adjust)); |
| 1294 | __ cfi().AdjustCFAOffset(adjust); |
| Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1295 | uint32_t xmm_spill_location = GetFpuSpillStart(); |
| 1296 | size_t xmm_spill_slot_size = GetFloatingPointSpillSlotSize(); |
| Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 1297 | |
| Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1298 | for (int i = arraysize(kFpuCalleeSaves) - 1; i >= 0; --i) { |
| 1299 | if (allocated_registers_.ContainsFloatingPointRegister(kFpuCalleeSaves[i])) { |
| David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1300 | int offset = xmm_spill_location + (xmm_spill_slot_size * i); |
| 1301 | __ movsd(Address(CpuRegister(RSP), offset), XmmRegister(kFpuCalleeSaves[i])); |
| 1302 | __ cfi().RelOffset(DWARFReg(kFpuCalleeSaves[i]), offset); |
| Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1303 | } |
| Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 1304 | } |
| 1305 | |
| Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 1306 | if (GetGraph()->HasShouldDeoptimizeFlag()) { |
| 1307 | // Initialize should_deoptimize flag to 0. |
| 1308 | __ movl(Address(CpuRegister(RSP), xmm_spill_location - kShouldDeoptimizeFlagSize), |
| 1309 | Immediate(0)); |
| 1310 | } |
| 1311 | |
| Nicolas Geoffray | 96eeb4e | 2016-10-12 22:03:31 +0100 | [diff] [blame] | 1312 | // Save the current method if we need it. Note that we do not |
| 1313 | // do this in HCurrentMethod, as the instruction might have been removed |
| 1314 | // in the SSA graph. |
| 1315 | if (RequiresCurrentMethod()) { |
| 1316 | __ movq(Address(CpuRegister(RSP), kCurrentMethodStackOffset), |
| 1317 | CpuRegister(kMethodRegisterArgument)); |
| 1318 | } |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1319 | } |
| 1320 | |
| 1321 | void CodeGeneratorX86_64::GenerateFrameExit() { |
| David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 1322 | __ cfi().RememberState(); |
| 1323 | if (!HasEmptyFrame()) { |
| 1324 | uint32_t xmm_spill_location = GetFpuSpillStart(); |
| 1325 | size_t xmm_spill_slot_size = GetFloatingPointSpillSlotSize(); |
| 1326 | for (size_t i = 0; i < arraysize(kFpuCalleeSaves); ++i) { |
| 1327 | if (allocated_registers_.ContainsFloatingPointRegister(kFpuCalleeSaves[i])) { |
| 1328 | int offset = xmm_spill_location + (xmm_spill_slot_size * i); |
| 1329 | __ movsd(XmmRegister(kFpuCalleeSaves[i]), Address(CpuRegister(RSP), offset)); |
| 1330 | __ cfi().Restore(DWARFReg(kFpuCalleeSaves[i])); |
| 1331 | } |
| 1332 | } |
| 1333 | |
| 1334 | int adjust = GetFrameSize() - GetCoreSpillSize(); |
| 1335 | __ addq(CpuRegister(RSP), Immediate(adjust)); |
| 1336 | __ cfi().AdjustCFAOffset(-adjust); |
| 1337 | |
| 1338 | for (size_t i = 0; i < arraysize(kCoreCalleeSaves); ++i) { |
| 1339 | Register reg = kCoreCalleeSaves[i]; |
| 1340 | if (allocated_registers_.ContainsCoreRegister(reg)) { |
| 1341 | __ popq(CpuRegister(reg)); |
| 1342 | __ cfi().AdjustCFAOffset(-static_cast<int>(kX86_64WordSize)); |
| 1343 | __ cfi().Restore(DWARFReg(reg)); |
| 1344 | } |
| Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1345 | } |
| 1346 | } |
| David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 1347 | __ ret(); |
| 1348 | __ cfi().RestoreState(); |
| 1349 | __ cfi().DefCFAOffset(GetFrameSize()); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1350 | } |
| 1351 | |
| Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 1352 | void CodeGeneratorX86_64::Bind(HBasicBlock* block) { |
| 1353 | __ Bind(GetLabelOf(block)); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1354 | } |
| 1355 | |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1356 | void CodeGeneratorX86_64::Move(Location destination, Location source) { |
| 1357 | if (source.Equals(destination)) { |
| 1358 | return; |
| 1359 | } |
| 1360 | if (destination.IsRegister()) { |
| Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1361 | CpuRegister dest = destination.AsRegister<CpuRegister>(); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1362 | if (source.IsRegister()) { |
| Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1363 | __ movq(dest, source.AsRegister<CpuRegister>()); |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1364 | } else if (source.IsFpuRegister()) { |
| Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1365 | __ movd(dest, source.AsFpuRegister<XmmRegister>()); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1366 | } else if (source.IsStackSlot()) { |
| Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1367 | __ movl(dest, Address(CpuRegister(RSP), source.GetStackIndex())); |
| 1368 | } else if (source.IsConstant()) { |
| 1369 | HConstant* constant = source.GetConstant(); |
| 1370 | if (constant->IsLongConstant()) { |
| 1371 | Load64BitValue(dest, constant->AsLongConstant()->GetValue()); |
| 1372 | } else { |
| 1373 | Load32BitValue(dest, GetInt32ValueOf(constant)); |
| 1374 | } |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1375 | } else { |
| 1376 | DCHECK(source.IsDoubleStackSlot()); |
| Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1377 | __ movq(dest, Address(CpuRegister(RSP), source.GetStackIndex())); |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1378 | } |
| 1379 | } else if (destination.IsFpuRegister()) { |
| Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1380 | XmmRegister dest = destination.AsFpuRegister<XmmRegister>(); |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1381 | if (source.IsRegister()) { |
| Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1382 | __ movd(dest, source.AsRegister<CpuRegister>()); |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1383 | } else if (source.IsFpuRegister()) { |
| Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1384 | __ movaps(dest, source.AsFpuRegister<XmmRegister>()); |
| 1385 | } else if (source.IsConstant()) { |
| 1386 | HConstant* constant = source.GetConstant(); |
| 1387 | int64_t value = CodeGenerator::GetInt64ValueOf(constant); |
| 1388 | if (constant->IsFloatConstant()) { |
| 1389 | Load32BitValue(dest, static_cast<int32_t>(value)); |
| 1390 | } else { |
| 1391 | Load64BitValue(dest, value); |
| 1392 | } |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1393 | } else if (source.IsStackSlot()) { |
| Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1394 | __ movss(dest, Address(CpuRegister(RSP), source.GetStackIndex())); |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1395 | } else { |
| 1396 | DCHECK(source.IsDoubleStackSlot()); |
| Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1397 | __ movsd(dest, Address(CpuRegister(RSP), source.GetStackIndex())); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1398 | } |
| 1399 | } else if (destination.IsStackSlot()) { |
| 1400 | if (source.IsRegister()) { |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1401 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1402 | source.AsRegister<CpuRegister>()); |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1403 | } else if (source.IsFpuRegister()) { |
| 1404 | __ movss(Address(CpuRegister(RSP), destination.GetStackIndex()), |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1405 | source.AsFpuRegister<XmmRegister>()); |
| Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 1406 | } else if (source.IsConstant()) { |
| 1407 | HConstant* constant = source.GetConstant(); |
| Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1408 | int32_t value = GetInt32ValueOf(constant); |
| Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 1409 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), Immediate(value)); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1410 | } else { |
| Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 1411 | DCHECK(source.IsStackSlot()) << source; |
| Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 1412 | __ movl(CpuRegister(TMP), Address(CpuRegister(RSP), source.GetStackIndex())); |
| 1413 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), CpuRegister(TMP)); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1414 | } |
| 1415 | } else { |
| 1416 | DCHECK(destination.IsDoubleStackSlot()); |
| 1417 | if (source.IsRegister()) { |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1418 | __ movq(Address(CpuRegister(RSP), destination.GetStackIndex()), |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1419 | source.AsRegister<CpuRegister>()); |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1420 | } else if (source.IsFpuRegister()) { |
| 1421 | __ movsd(Address(CpuRegister(RSP), destination.GetStackIndex()), |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1422 | source.AsFpuRegister<XmmRegister>()); |
| Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 1423 | } else if (source.IsConstant()) { |
| 1424 | HConstant* constant = source.GetConstant(); |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 1425 | DCHECK(constant->IsLongConstant() || constant->IsDoubleConstant()); |
| 1426 | int64_t value = GetInt64ValueOf(constant); |
| Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 1427 | Store64BitValueToStack(destination, value); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1428 | } else { |
| 1429 | DCHECK(source.IsDoubleStackSlot()); |
| Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 1430 | __ movq(CpuRegister(TMP), Address(CpuRegister(RSP), source.GetStackIndex())); |
| 1431 | __ movq(Address(CpuRegister(RSP), destination.GetStackIndex()), CpuRegister(TMP)); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1432 | } |
| 1433 | } |
| 1434 | } |
| 1435 | |
| Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1436 | void CodeGeneratorX86_64::MoveConstant(Location location, int32_t value) { |
| 1437 | DCHECK(location.IsRegister()); |
| 1438 | Load64BitValue(location.AsRegister<CpuRegister>(), static_cast<int64_t>(value)); |
| 1439 | } |
| 1440 | |
| Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1441 | void CodeGeneratorX86_64::MoveLocation( |
| 1442 | Location dst, Location src, Primitive::Type dst_type ATTRIBUTE_UNUSED) { |
| 1443 | Move(dst, src); |
| 1444 | } |
| 1445 | |
| 1446 | void CodeGeneratorX86_64::AddLocationAsTemp(Location location, LocationSummary* locations) { |
| 1447 | if (location.IsRegister()) { |
| 1448 | locations->AddTemp(location); |
| 1449 | } else { |
| 1450 | UNIMPLEMENTED(FATAL) << "AddLocationAsTemp not implemented for location " << location; |
| 1451 | } |
| 1452 | } |
| 1453 | |
| David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1454 | void InstructionCodeGeneratorX86_64::HandleGoto(HInstruction* got, HBasicBlock* successor) { |
| Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1455 | DCHECK(!successor->IsExitBlock()); |
| 1456 | |
| 1457 | HBasicBlock* block = got->GetBlock(); |
| 1458 | HInstruction* previous = got->GetPrevious(); |
| 1459 | |
| 1460 | HLoopInformation* info = block->GetLoopInformation(); |
| David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1461 | if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) { |
| Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1462 | GenerateSuspendCheck(info->GetSuspendCheck(), successor); |
| 1463 | return; |
| 1464 | } |
| 1465 | |
| 1466 | if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) { |
| 1467 | GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr); |
| 1468 | } |
| 1469 | if (!codegen_->GoesToNextBlock(got->GetBlock(), successor)) { |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1470 | __ jmp(codegen_->GetLabelOf(successor)); |
| 1471 | } |
| 1472 | } |
| 1473 | |
| David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1474 | void LocationsBuilderX86_64::VisitGoto(HGoto* got) { |
| 1475 | got->SetLocations(nullptr); |
| 1476 | } |
| 1477 | |
| 1478 | void InstructionCodeGeneratorX86_64::VisitGoto(HGoto* got) { |
| 1479 | HandleGoto(got, got->GetSuccessor()); |
| 1480 | } |
| 1481 | |
| 1482 | void LocationsBuilderX86_64::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 1483 | try_boundary->SetLocations(nullptr); |
| 1484 | } |
| 1485 | |
| 1486 | void InstructionCodeGeneratorX86_64::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 1487 | HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor(); |
| 1488 | if (!successor->IsExitBlock()) { |
| 1489 | HandleGoto(try_boundary, successor); |
| 1490 | } |
| 1491 | } |
| 1492 | |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1493 | void LocationsBuilderX86_64::VisitExit(HExit* exit) { |
| 1494 | exit->SetLocations(nullptr); |
| 1495 | } |
| 1496 | |
| Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1497 | void InstructionCodeGeneratorX86_64::VisitExit(HExit* exit ATTRIBUTE_UNUSED) { |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1498 | } |
| 1499 | |
| Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1500 | template<class LabelType> |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1501 | void InstructionCodeGeneratorX86_64::GenerateFPJumps(HCondition* cond, |
| Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1502 | LabelType* true_label, |
| 1503 | LabelType* false_label) { |
| Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1504 | if (cond->IsFPConditionTrueIfNaN()) { |
| 1505 | __ j(kUnordered, true_label); |
| 1506 | } else if (cond->IsFPConditionFalseIfNaN()) { |
| 1507 | __ j(kUnordered, false_label); |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1508 | } |
| Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1509 | __ j(X86_64FPCondition(cond->GetCondition()), true_label); |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1510 | } |
| 1511 | |
| Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1512 | void InstructionCodeGeneratorX86_64::GenerateCompareTest(HCondition* condition) { |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1513 | LocationSummary* locations = condition->GetLocations(); |
| Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1514 | |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1515 | Location left = locations->InAt(0); |
| 1516 | Location right = locations->InAt(1); |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1517 | Primitive::Type type = condition->InputAt(0)->GetType(); |
| 1518 | switch (type) { |
| Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1519 | case Primitive::kPrimBoolean: |
| 1520 | case Primitive::kPrimByte: |
| 1521 | case Primitive::kPrimChar: |
| 1522 | case Primitive::kPrimShort: |
| 1523 | case Primitive::kPrimInt: |
| 1524 | case Primitive::kPrimNot: { |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 1525 | codegen_->GenerateIntCompare(left, right); |
| Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1526 | break; |
| 1527 | } |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1528 | case Primitive::kPrimLong: { |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 1529 | codegen_->GenerateLongCompare(left, right); |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1530 | break; |
| 1531 | } |
| 1532 | case Primitive::kPrimFloat: { |
| 1533 | if (right.IsFpuRegister()) { |
| 1534 | __ ucomiss(left.AsFpuRegister<XmmRegister>(), right.AsFpuRegister<XmmRegister>()); |
| 1535 | } else if (right.IsConstant()) { |
| 1536 | __ ucomiss(left.AsFpuRegister<XmmRegister>(), |
| 1537 | codegen_->LiteralFloatAddress( |
| 1538 | right.GetConstant()->AsFloatConstant()->GetValue())); |
| 1539 | } else { |
| 1540 | DCHECK(right.IsStackSlot()); |
| 1541 | __ ucomiss(left.AsFpuRegister<XmmRegister>(), |
| 1542 | Address(CpuRegister(RSP), right.GetStackIndex())); |
| 1543 | } |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1544 | break; |
| 1545 | } |
| 1546 | case Primitive::kPrimDouble: { |
| 1547 | if (right.IsFpuRegister()) { |
| 1548 | __ ucomisd(left.AsFpuRegister<XmmRegister>(), right.AsFpuRegister<XmmRegister>()); |
| 1549 | } else if (right.IsConstant()) { |
| 1550 | __ ucomisd(left.AsFpuRegister<XmmRegister>(), |
| 1551 | codegen_->LiteralDoubleAddress( |
| 1552 | right.GetConstant()->AsDoubleConstant()->GetValue())); |
| 1553 | } else { |
| 1554 | DCHECK(right.IsDoubleStackSlot()); |
| 1555 | __ ucomisd(left.AsFpuRegister<XmmRegister>(), |
| 1556 | Address(CpuRegister(RSP), right.GetStackIndex())); |
| 1557 | } |
| Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1558 | break; |
| 1559 | } |
| 1560 | default: |
| 1561 | LOG(FATAL) << "Unexpected condition type " << type; |
| 1562 | } |
| 1563 | } |
| 1564 | |
| 1565 | template<class LabelType> |
| 1566 | void InstructionCodeGeneratorX86_64::GenerateCompareTestAndBranch(HCondition* condition, |
| 1567 | LabelType* true_target_in, |
| 1568 | LabelType* false_target_in) { |
| 1569 | // Generated branching requires both targets to be explicit. If either of the |
| 1570 | // targets is nullptr (fallthrough) use and bind `fallthrough_target` instead. |
| 1571 | LabelType fallthrough_target; |
| 1572 | LabelType* true_target = true_target_in == nullptr ? &fallthrough_target : true_target_in; |
| 1573 | LabelType* false_target = false_target_in == nullptr ? &fallthrough_target : false_target_in; |
| 1574 | |
| 1575 | // Generate the comparison to set the CC. |
| 1576 | GenerateCompareTest(condition); |
| 1577 | |
| 1578 | // Now generate the correct jump(s). |
| 1579 | Primitive::Type type = condition->InputAt(0)->GetType(); |
| 1580 | switch (type) { |
| 1581 | case Primitive::kPrimLong: { |
| 1582 | __ j(X86_64IntegerCondition(condition->GetCondition()), true_target); |
| 1583 | break; |
| 1584 | } |
| 1585 | case Primitive::kPrimFloat: { |
| 1586 | GenerateFPJumps(condition, true_target, false_target); |
| 1587 | break; |
| 1588 | } |
| 1589 | case Primitive::kPrimDouble: { |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1590 | GenerateFPJumps(condition, true_target, false_target); |
| 1591 | break; |
| 1592 | } |
| 1593 | default: |
| 1594 | LOG(FATAL) << "Unexpected condition type " << type; |
| 1595 | } |
| 1596 | |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1597 | if (false_target != &fallthrough_target) { |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1598 | __ jmp(false_target); |
| 1599 | } |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1600 | |
| 1601 | if (fallthrough_target.IsLinked()) { |
| 1602 | __ Bind(&fallthrough_target); |
| 1603 | } |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1604 | } |
| 1605 | |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1606 | static bool AreEflagsSetFrom(HInstruction* cond, HInstruction* branch) { |
| 1607 | // Moves may affect the eflags register (move zero uses xorl), so the EFLAGS |
| 1608 | // are set only strictly before `branch`. We can't use the eflags on long |
| 1609 | // conditions if they are materialized due to the complex branching. |
| 1610 | return cond->IsCondition() && |
| 1611 | cond->GetNext() == branch && |
| 1612 | !Primitive::IsFloatingPointType(cond->InputAt(0)->GetType()); |
| 1613 | } |
| 1614 | |
| Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1615 | template<class LabelType> |
| Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1616 | void InstructionCodeGeneratorX86_64::GenerateTestAndBranch(HInstruction* instruction, |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1617 | size_t condition_input_index, |
| Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1618 | LabelType* true_target, |
| 1619 | LabelType* false_target) { |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1620 | HInstruction* cond = instruction->InputAt(condition_input_index); |
| 1621 | |
| 1622 | if (true_target == nullptr && false_target == nullptr) { |
| 1623 | // Nothing to do. The code always falls through. |
| 1624 | return; |
| 1625 | } else if (cond->IsIntConstant()) { |
| Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 1626 | // Constant condition, statically compared against "true" (integer value 1). |
| 1627 | if (cond->AsIntConstant()->IsTrue()) { |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1628 | if (true_target != nullptr) { |
| 1629 | __ jmp(true_target); |
| Nicolas Geoffray | 18efde5 | 2014-09-22 15:51:11 +0100 | [diff] [blame] | 1630 | } |
| Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1631 | } else { |
| Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 1632 | DCHECK(cond->AsIntConstant()->IsFalse()) << cond->AsIntConstant()->GetValue(); |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1633 | if (false_target != nullptr) { |
| 1634 | __ jmp(false_target); |
| 1635 | } |
| 1636 | } |
| 1637 | return; |
| 1638 | } |
| 1639 | |
| 1640 | // The following code generates these patterns: |
| 1641 | // (1) true_target == nullptr && false_target != nullptr |
| 1642 | // - opposite condition true => branch to false_target |
| 1643 | // (2) true_target != nullptr && false_target == nullptr |
| 1644 | // - condition true => branch to true_target |
| 1645 | // (3) true_target != nullptr && false_target != nullptr |
| 1646 | // - condition true => branch to true_target |
| 1647 | // - branch to false_target |
| 1648 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
| 1649 | if (AreEflagsSetFrom(cond, instruction)) { |
| 1650 | if (true_target == nullptr) { |
| 1651 | __ j(X86_64IntegerCondition(cond->AsCondition()->GetOppositeCondition()), false_target); |
| 1652 | } else { |
| 1653 | __ j(X86_64IntegerCondition(cond->AsCondition()->GetCondition()), true_target); |
| 1654 | } |
| 1655 | } else { |
| 1656 | // Materialized condition, compare against 0. |
| 1657 | Location lhs = instruction->GetLocations()->InAt(condition_input_index); |
| 1658 | if (lhs.IsRegister()) { |
| 1659 | __ testl(lhs.AsRegister<CpuRegister>(), lhs.AsRegister<CpuRegister>()); |
| 1660 | } else { |
| 1661 | __ cmpl(Address(CpuRegister(RSP), lhs.GetStackIndex()), Immediate(0)); |
| 1662 | } |
| 1663 | if (true_target == nullptr) { |
| 1664 | __ j(kEqual, false_target); |
| 1665 | } else { |
| 1666 | __ j(kNotEqual, true_target); |
| 1667 | } |
| Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1668 | } |
| 1669 | } else { |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1670 | // Condition has not been materialized, use its inputs as the |
| 1671 | // comparison and its condition as the branch condition. |
| Mark Mendell | b8b9769 | 2015-05-22 16:58:19 -0400 | [diff] [blame] | 1672 | HCondition* condition = cond->AsCondition(); |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1673 | |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1674 | // If this is a long or FP comparison that has been folded into |
| 1675 | // the HCondition, generate the comparison directly. |
| 1676 | Primitive::Type type = condition->InputAt(0)->GetType(); |
| 1677 | if (type == Primitive::kPrimLong || Primitive::IsFloatingPointType(type)) { |
| 1678 | GenerateCompareTestAndBranch(condition, true_target, false_target); |
| 1679 | return; |
| 1680 | } |
| 1681 | |
| 1682 | Location lhs = condition->GetLocations()->InAt(0); |
| 1683 | Location rhs = condition->GetLocations()->InAt(1); |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 1684 | codegen_->GenerateIntCompare(lhs, rhs); |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1685 | if (true_target == nullptr) { |
| 1686 | __ j(X86_64IntegerCondition(condition->GetOppositeCondition()), false_target); |
| 1687 | } else { |
| Mark Mendell | b8b9769 | 2015-05-22 16:58:19 -0400 | [diff] [blame] | 1688 | __ j(X86_64IntegerCondition(condition->GetCondition()), true_target); |
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1689 | } |
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1690 | } |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1691 | |
| 1692 | // If neither branch falls through (case 3), the conditional branch to `true_target` |
| 1693 | // was already emitted (case 2) and we need to emit a jump to `false_target`. |
| 1694 | if (true_target != nullptr && false_target != nullptr) { |
| Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1695 | __ jmp(false_target); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1696 | } |
| 1697 | } |
| 1698 | |
| Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1699 | void LocationsBuilderX86_64::VisitIf(HIf* if_instr) { |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1700 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(if_instr); |
| 1701 | if (IsBooleanValueOrMaterializedCondition(if_instr->InputAt(0))) { |
| Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1702 | locations->SetInAt(0, Location::Any()); |
| 1703 | } |
| 1704 | } |
| 1705 | |
| 1706 | void InstructionCodeGeneratorX86_64::VisitIf(HIf* if_instr) { |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1707 | HBasicBlock* true_successor = if_instr->IfTrueSuccessor(); |
| 1708 | HBasicBlock* false_successor = if_instr->IfFalseSuccessor(); |
| 1709 | Label* true_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), true_successor) ? |
| 1710 | nullptr : codegen_->GetLabelOf(true_successor); |
| 1711 | Label* false_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), false_successor) ? |
| 1712 | nullptr : codegen_->GetLabelOf(false_successor); |
| 1713 | GenerateTestAndBranch(if_instr, /* condition_input_index */ 0, true_target, false_target); |
| Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1714 | } |
| 1715 | |
| 1716 | void LocationsBuilderX86_64::VisitDeoptimize(HDeoptimize* deoptimize) { |
| 1717 | LocationSummary* locations = new (GetGraph()->GetArena()) |
| 1718 | LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath); |
| Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 1719 | InvokeRuntimeCallingConvention calling_convention; |
| 1720 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 1721 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 1722 | locations->SetCustomSlowPathCallerSaves(caller_saves); |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1723 | if (IsBooleanValueOrMaterializedCondition(deoptimize->InputAt(0))) { |
| Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1724 | locations->SetInAt(0, Location::Any()); |
| 1725 | } |
| 1726 | } |
| 1727 | |
| 1728 | void InstructionCodeGeneratorX86_64::VisitDeoptimize(HDeoptimize* deoptimize) { |
| Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 1729 | SlowPathCode* slow_path = deopt_slow_paths_.NewSlowPath<DeoptimizationSlowPathX86_64>(deoptimize); |
| David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1730 | GenerateTestAndBranch<Label>(deoptimize, |
| 1731 | /* condition_input_index */ 0, |
| 1732 | slow_path->GetEntryLabel(), |
| 1733 | /* false_target */ nullptr); |
| 1734 | } |
| 1735 | |
| Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 1736 | void LocationsBuilderX86_64::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) { |
| 1737 | LocationSummary* locations = new (GetGraph()->GetArena()) |
| 1738 | LocationSummary(flag, LocationSummary::kNoCall); |
| 1739 | locations->SetOut(Location::RequiresRegister()); |
| 1740 | } |
| 1741 | |
| 1742 | void InstructionCodeGeneratorX86_64::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) { |
| 1743 | __ movl(flag->GetLocations()->Out().AsRegister<CpuRegister>(), |
| 1744 | Address(CpuRegister(RSP), codegen_->GetStackOffsetOfShouldDeoptimizeFlag())); |
| 1745 | } |
| 1746 | |
| Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1747 | static bool SelectCanUseCMOV(HSelect* select) { |
| 1748 | // There are no conditional move instructions for XMMs. |
| 1749 | if (Primitive::IsFloatingPointType(select->GetType())) { |
| 1750 | return false; |
| 1751 | } |
| 1752 | |
| 1753 | // A FP condition doesn't generate the single CC that we need. |
| 1754 | HInstruction* condition = select->GetCondition(); |
| 1755 | if (condition->IsCondition() && |
| 1756 | Primitive::IsFloatingPointType(condition->InputAt(0)->GetType())) { |
| 1757 | return false; |
| 1758 | } |
| 1759 | |
| 1760 | // We can generate a CMOV for this Select. |
| 1761 | return true; |
| 1762 | } |
| 1763 | |
| David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1764 | void LocationsBuilderX86_64::VisitSelect(HSelect* select) { |
| 1765 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(select); |
| 1766 | if (Primitive::IsFloatingPointType(select->GetType())) { |
| 1767 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1768 | locations->SetInAt(1, Location::Any()); |
| David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1769 | } else { |
| 1770 | locations->SetInAt(0, Location::RequiresRegister()); |
| Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1771 | if (SelectCanUseCMOV(select)) { |
| Mark Mendell | dee1b9a | 2016-02-12 14:36:51 -0500 | [diff] [blame] | 1772 | if (select->InputAt(1)->IsConstant()) { |
| 1773 | locations->SetInAt(1, Location::RequiresRegister()); |
| 1774 | } else { |
| 1775 | locations->SetInAt(1, Location::Any()); |
| 1776 | } |
| Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1777 | } else { |
| Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1778 | locations->SetInAt(1, Location::Any()); |
| 1779 | } |
| David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1780 | } |
| 1781 | if (IsBooleanValueOrMaterializedCondition(select->GetCondition())) { |
| 1782 | locations->SetInAt(2, Location::RequiresRegister()); |
| 1783 | } |
| 1784 | locations->SetOut(Location::SameAsFirstInput()); |
| 1785 | } |
| 1786 | |
| 1787 | void InstructionCodeGeneratorX86_64::VisitSelect(HSelect* select) { |
| 1788 | LocationSummary* locations = select->GetLocations(); |
| Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1789 | if (SelectCanUseCMOV(select)) { |
| 1790 | // If both the condition and the source types are integer, we can generate |
| 1791 | // a CMOV to implement Select. |
| 1792 | CpuRegister value_false = locations->InAt(0).AsRegister<CpuRegister>(); |
| Mark Mendell | dee1b9a | 2016-02-12 14:36:51 -0500 | [diff] [blame] | 1793 | Location value_true_loc = locations->InAt(1); |
| Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1794 | DCHECK(locations->InAt(0).Equals(locations->Out())); |
| 1795 | |
| 1796 | HInstruction* select_condition = select->GetCondition(); |
| 1797 | Condition cond = kNotEqual; |
| 1798 | |
| 1799 | // Figure out how to test the 'condition'. |
| 1800 | if (select_condition->IsCondition()) { |
| 1801 | HCondition* condition = select_condition->AsCondition(); |
| 1802 | if (!condition->IsEmittedAtUseSite()) { |
| 1803 | // This was a previously materialized condition. |
| 1804 | // Can we use the existing condition code? |
| 1805 | if (AreEflagsSetFrom(condition, select)) { |
| 1806 | // Materialization was the previous instruction. Condition codes are right. |
| 1807 | cond = X86_64IntegerCondition(condition->GetCondition()); |
| 1808 | } else { |
| 1809 | // No, we have to recreate the condition code. |
| 1810 | CpuRegister cond_reg = locations->InAt(2).AsRegister<CpuRegister>(); |
| 1811 | __ testl(cond_reg, cond_reg); |
| 1812 | } |
| 1813 | } else { |
| 1814 | GenerateCompareTest(condition); |
| 1815 | cond = X86_64IntegerCondition(condition->GetCondition()); |
| 1816 | } |
| 1817 | } else { |
| Roland Levillain | 5e8d5f0 | 2016-10-18 18:03:43 +0100 | [diff] [blame] | 1818 | // Must be a Boolean condition, which needs to be compared to 0. |
| Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1819 | CpuRegister cond_reg = locations->InAt(2).AsRegister<CpuRegister>(); |
| 1820 | __ testl(cond_reg, cond_reg); |
| 1821 | } |
| 1822 | |
| 1823 | // If the condition is true, overwrite the output, which already contains false. |
| 1824 | // Generate the correct sized CMOV. |
| Mark Mendell | dee1b9a | 2016-02-12 14:36:51 -0500 | [diff] [blame] | 1825 | bool is_64_bit = Primitive::Is64BitType(select->GetType()); |
| 1826 | if (value_true_loc.IsRegister()) { |
| 1827 | __ cmov(cond, value_false, value_true_loc.AsRegister<CpuRegister>(), is_64_bit); |
| 1828 | } else { |
| 1829 | __ cmov(cond, |
| 1830 | value_false, |
| 1831 | Address(CpuRegister(RSP), value_true_loc.GetStackIndex()), is_64_bit); |
| 1832 | } |
| Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1833 | } else { |
| 1834 | NearLabel false_target; |
| 1835 | GenerateTestAndBranch<NearLabel>(select, |
| 1836 | /* condition_input_index */ 2, |
| 1837 | /* true_target */ nullptr, |
| 1838 | &false_target); |
| 1839 | codegen_->MoveLocation(locations->Out(), locations->InAt(1), select->GetType()); |
| 1840 | __ Bind(&false_target); |
| 1841 | } |
| Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1842 | } |
| 1843 | |
| David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 1844 | void LocationsBuilderX86_64::VisitNativeDebugInfo(HNativeDebugInfo* info) { |
| 1845 | new (GetGraph()->GetArena()) LocationSummary(info); |
| 1846 | } |
| 1847 | |
| David Srbecky | d28f4a0 | 2016-03-14 17:14:24 +0000 | [diff] [blame] | 1848 | void InstructionCodeGeneratorX86_64::VisitNativeDebugInfo(HNativeDebugInfo*) { |
| 1849 | // MaybeRecordNativeDebugInfo is already called implicitly in CodeGenerator::Compile. |
| David Srbecky | c7098ff | 2016-02-09 14:30:11 +0000 | [diff] [blame] | 1850 | } |
| 1851 | |
| 1852 | void CodeGeneratorX86_64::GenerateNop() { |
| 1853 | __ nop(); |
| David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 1854 | } |
| 1855 | |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1856 | void LocationsBuilderX86_64::HandleCondition(HCondition* cond) { |
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1857 | LocationSummary* locations = |
| Roland Levillain | 0d37cd0 | 2015-05-27 16:39:19 +0100 | [diff] [blame] | 1858 | new (GetGraph()->GetArena()) LocationSummary(cond, LocationSummary::kNoCall); |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1859 | // Handle the long/FP comparisons made in instruction simplification. |
| 1860 | switch (cond->InputAt(0)->GetType()) { |
| 1861 | case Primitive::kPrimLong: |
| 1862 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1863 | locations->SetInAt(1, Location::Any()); |
| 1864 | break; |
| 1865 | case Primitive::kPrimFloat: |
| 1866 | case Primitive::kPrimDouble: |
| 1867 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1868 | locations->SetInAt(1, Location::Any()); |
| 1869 | break; |
| 1870 | default: |
| 1871 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1872 | locations->SetInAt(1, Location::Any()); |
| 1873 | break; |
| 1874 | } |
| David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 1875 | if (!cond->IsEmittedAtUseSite()) { |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1876 | locations->SetOut(Location::RequiresRegister()); |
| 1877 | } |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1878 | } |
| 1879 | |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1880 | void InstructionCodeGeneratorX86_64::HandleCondition(HCondition* cond) { |
| David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 1881 | if (cond->IsEmittedAtUseSite()) { |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1882 | return; |
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1883 | } |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1884 | |
| 1885 | LocationSummary* locations = cond->GetLocations(); |
| 1886 | Location lhs = locations->InAt(0); |
| 1887 | Location rhs = locations->InAt(1); |
| 1888 | CpuRegister reg = locations->Out().AsRegister<CpuRegister>(); |
| Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1889 | NearLabel true_label, false_label; |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1890 | |
| 1891 | switch (cond->InputAt(0)->GetType()) { |
| 1892 | default: |
| 1893 | // Integer case. |
| 1894 | |
| 1895 | // Clear output register: setcc only sets the low byte. |
| 1896 | __ xorl(reg, reg); |
| 1897 | |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 1898 | codegen_->GenerateIntCompare(lhs, rhs); |
| Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1899 | __ setcc(X86_64IntegerCondition(cond->GetCondition()), reg); |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1900 | return; |
| 1901 | case Primitive::kPrimLong: |
| 1902 | // Clear output register: setcc only sets the low byte. |
| 1903 | __ xorl(reg, reg); |
| 1904 | |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 1905 | codegen_->GenerateLongCompare(lhs, rhs); |
| Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1906 | __ setcc(X86_64IntegerCondition(cond->GetCondition()), reg); |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1907 | return; |
| 1908 | case Primitive::kPrimFloat: { |
| 1909 | XmmRegister lhs_reg = lhs.AsFpuRegister<XmmRegister>(); |
| 1910 | if (rhs.IsConstant()) { |
| 1911 | float value = rhs.GetConstant()->AsFloatConstant()->GetValue(); |
| 1912 | __ ucomiss(lhs_reg, codegen_->LiteralFloatAddress(value)); |
| 1913 | } else if (rhs.IsStackSlot()) { |
| 1914 | __ ucomiss(lhs_reg, Address(CpuRegister(RSP), rhs.GetStackIndex())); |
| 1915 | } else { |
| 1916 | __ ucomiss(lhs_reg, rhs.AsFpuRegister<XmmRegister>()); |
| 1917 | } |
| 1918 | GenerateFPJumps(cond, &true_label, &false_label); |
| 1919 | break; |
| 1920 | } |
| 1921 | case Primitive::kPrimDouble: { |
| 1922 | XmmRegister lhs_reg = lhs.AsFpuRegister<XmmRegister>(); |
| 1923 | if (rhs.IsConstant()) { |
| 1924 | double value = rhs.GetConstant()->AsDoubleConstant()->GetValue(); |
| 1925 | __ ucomisd(lhs_reg, codegen_->LiteralDoubleAddress(value)); |
| 1926 | } else if (rhs.IsDoubleStackSlot()) { |
| 1927 | __ ucomisd(lhs_reg, Address(CpuRegister(RSP), rhs.GetStackIndex())); |
| 1928 | } else { |
| 1929 | __ ucomisd(lhs_reg, rhs.AsFpuRegister<XmmRegister>()); |
| 1930 | } |
| 1931 | GenerateFPJumps(cond, &true_label, &false_label); |
| 1932 | break; |
| 1933 | } |
| 1934 | } |
| 1935 | |
| 1936 | // Convert the jumps into the result. |
| Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 1937 | NearLabel done_label; |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1938 | |
| Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1939 | // False case: result = 0. |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1940 | __ Bind(&false_label); |
| 1941 | __ xorl(reg, reg); |
| 1942 | __ jmp(&done_label); |
| 1943 | |
| Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1944 | // True case: result = 1. |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1945 | __ Bind(&true_label); |
| 1946 | __ movl(reg, Immediate(1)); |
| 1947 | __ Bind(&done_label); |
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1948 | } |
| 1949 | |
| 1950 | void LocationsBuilderX86_64::VisitEqual(HEqual* comp) { |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1951 | HandleCondition(comp); |
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1952 | } |
| 1953 | |
| 1954 | void InstructionCodeGeneratorX86_64::VisitEqual(HEqual* comp) { |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1955 | HandleCondition(comp); |
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1956 | } |
| 1957 | |
| 1958 | void LocationsBuilderX86_64::VisitNotEqual(HNotEqual* comp) { |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1959 | HandleCondition(comp); |
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1960 | } |
| 1961 | |
| 1962 | void InstructionCodeGeneratorX86_64::VisitNotEqual(HNotEqual* comp) { |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1963 | HandleCondition(comp); |
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1964 | } |
| 1965 | |
| 1966 | void LocationsBuilderX86_64::VisitLessThan(HLessThan* comp) { |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1967 | HandleCondition(comp); |
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1968 | } |
| 1969 | |
| 1970 | void InstructionCodeGeneratorX86_64::VisitLessThan(HLessThan* comp) { |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1971 | HandleCondition(comp); |
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1972 | } |
| 1973 | |
| 1974 | void LocationsBuilderX86_64::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1975 | HandleCondition(comp); |
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1976 | } |
| 1977 | |
| 1978 | void InstructionCodeGeneratorX86_64::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1979 | HandleCondition(comp); |
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1980 | } |
| 1981 | |
| 1982 | void LocationsBuilderX86_64::VisitGreaterThan(HGreaterThan* comp) { |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1983 | HandleCondition(comp); |
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1984 | } |
| 1985 | |
| 1986 | void InstructionCodeGeneratorX86_64::VisitGreaterThan(HGreaterThan* comp) { |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1987 | HandleCondition(comp); |
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1988 | } |
| 1989 | |
| 1990 | void LocationsBuilderX86_64::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1991 | HandleCondition(comp); |
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1992 | } |
| 1993 | |
| 1994 | void InstructionCodeGeneratorX86_64::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1995 | HandleCondition(comp); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1996 | } |
| 1997 | |
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1998 | void LocationsBuilderX86_64::VisitBelow(HBelow* comp) { |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1999 | HandleCondition(comp); |
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2000 | } |
| 2001 | |
| 2002 | void InstructionCodeGeneratorX86_64::VisitBelow(HBelow* comp) { |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2003 | HandleCondition(comp); |
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2004 | } |
| 2005 | |
| 2006 | void LocationsBuilderX86_64::VisitBelowOrEqual(HBelowOrEqual* comp) { |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2007 | HandleCondition(comp); |
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2008 | } |
| 2009 | |
| 2010 | void InstructionCodeGeneratorX86_64::VisitBelowOrEqual(HBelowOrEqual* comp) { |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2011 | HandleCondition(comp); |
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2012 | } |
| 2013 | |
| 2014 | void LocationsBuilderX86_64::VisitAbove(HAbove* comp) { |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2015 | HandleCondition(comp); |
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2016 | } |
| 2017 | |
| 2018 | void InstructionCodeGeneratorX86_64::VisitAbove(HAbove* comp) { |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2019 | HandleCondition(comp); |
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2020 | } |
| 2021 | |
| 2022 | void LocationsBuilderX86_64::VisitAboveOrEqual(HAboveOrEqual* comp) { |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2023 | HandleCondition(comp); |
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2024 | } |
| 2025 | |
| 2026 | void InstructionCodeGeneratorX86_64::VisitAboveOrEqual(HAboveOrEqual* comp) { |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2027 | HandleCondition(comp); |
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2028 | } |
| 2029 | |
| Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 2030 | void LocationsBuilderX86_64::VisitCompare(HCompare* compare) { |
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2031 | LocationSummary* locations = |
| 2032 | new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall); |
| Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2033 | switch (compare->InputAt(0)->GetType()) { |
| Roland Levillain | a5c4a40 | 2016-03-15 15:02:50 +0000 | [diff] [blame] | 2034 | case Primitive::kPrimBoolean: |
| 2035 | case Primitive::kPrimByte: |
| 2036 | case Primitive::kPrimShort: |
| 2037 | case Primitive::kPrimChar: |
| Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 2038 | case Primitive::kPrimInt: |
| Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2039 | case Primitive::kPrimLong: { |
| 2040 | locations->SetInAt(0, Location::RequiresRegister()); |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2041 | locations->SetInAt(1, Location::Any()); |
| Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2042 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2043 | break; |
| 2044 | } |
| 2045 | case Primitive::kPrimFloat: |
| 2046 | case Primitive::kPrimDouble: { |
| 2047 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2048 | locations->SetInAt(1, Location::Any()); |
| Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2049 | locations->SetOut(Location::RequiresRegister()); |
| 2050 | break; |
| 2051 | } |
| 2052 | default: |
| 2053 | LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType(); |
| 2054 | } |
| Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 2055 | } |
| 2056 | |
| 2057 | void InstructionCodeGeneratorX86_64::VisitCompare(HCompare* compare) { |
| Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 2058 | LocationSummary* locations = compare->GetLocations(); |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2059 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
| Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2060 | Location left = locations->InAt(0); |
| 2061 | Location right = locations->InAt(1); |
| 2062 | |
| Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2063 | NearLabel less, greater, done; |
| Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2064 | Primitive::Type type = compare->InputAt(0)->GetType(); |
| Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 2065 | Condition less_cond = kLess; |
| 2066 | |
| Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2067 | switch (type) { |
| Roland Levillain | a5c4a40 | 2016-03-15 15:02:50 +0000 | [diff] [blame] | 2068 | case Primitive::kPrimBoolean: |
| 2069 | case Primitive::kPrimByte: |
| 2070 | case Primitive::kPrimShort: |
| 2071 | case Primitive::kPrimChar: |
| Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 2072 | case Primitive::kPrimInt: { |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 2073 | codegen_->GenerateIntCompare(left, right); |
| Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 2074 | break; |
| 2075 | } |
| Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2076 | case Primitive::kPrimLong: { |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 2077 | codegen_->GenerateLongCompare(left, right); |
| Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 2078 | break; |
| Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2079 | } |
| 2080 | case Primitive::kPrimFloat: { |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2081 | XmmRegister left_reg = left.AsFpuRegister<XmmRegister>(); |
| 2082 | if (right.IsConstant()) { |
| 2083 | float value = right.GetConstant()->AsFloatConstant()->GetValue(); |
| 2084 | __ ucomiss(left_reg, codegen_->LiteralFloatAddress(value)); |
| 2085 | } else if (right.IsStackSlot()) { |
| 2086 | __ ucomiss(left_reg, Address(CpuRegister(RSP), right.GetStackIndex())); |
| 2087 | } else { |
| 2088 | __ ucomiss(left_reg, right.AsFpuRegister<XmmRegister>()); |
| 2089 | } |
| Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2090 | __ j(kUnordered, compare->IsGtBias() ? &greater : &less); |
| Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 2091 | less_cond = kBelow; // ucomis{s,d} sets CF |
| Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2092 | break; |
| 2093 | } |
| 2094 | case Primitive::kPrimDouble: { |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2095 | XmmRegister left_reg = left.AsFpuRegister<XmmRegister>(); |
| 2096 | if (right.IsConstant()) { |
| 2097 | double value = right.GetConstant()->AsDoubleConstant()->GetValue(); |
| 2098 | __ ucomisd(left_reg, codegen_->LiteralDoubleAddress(value)); |
| 2099 | } else if (right.IsDoubleStackSlot()) { |
| 2100 | __ ucomisd(left_reg, Address(CpuRegister(RSP), right.GetStackIndex())); |
| 2101 | } else { |
| 2102 | __ ucomisd(left_reg, right.AsFpuRegister<XmmRegister>()); |
| 2103 | } |
| Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2104 | __ j(kUnordered, compare->IsGtBias() ? &greater : &less); |
| Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 2105 | less_cond = kBelow; // ucomis{s,d} sets CF |
| Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2106 | break; |
| 2107 | } |
| Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 2108 | default: |
| Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2109 | LOG(FATAL) << "Unexpected compare type " << type; |
| Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 2110 | } |
| Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 2111 | |
| Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2112 | __ movl(out, Immediate(0)); |
| Calin Juravle | 91debbc | 2014-11-26 19:01:09 +0000 | [diff] [blame] | 2113 | __ j(kEqual, &done); |
| Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 2114 | __ j(less_cond, &less); |
| Calin Juravle | fd86124 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2115 | |
| Calin Juravle | 91debbc | 2014-11-26 19:01:09 +0000 | [diff] [blame] | 2116 | __ Bind(&greater); |
| Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2117 | __ movl(out, Immediate(1)); |
| 2118 | __ jmp(&done); |
| 2119 | |
| 2120 | __ Bind(&less); |
| 2121 | __ movl(out, Immediate(-1)); |
| Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 2122 | |
| 2123 | __ Bind(&done); |
| 2124 | } |
| 2125 | |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2126 | void LocationsBuilderX86_64::VisitIntConstant(HIntConstant* constant) { |
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2127 | LocationSummary* locations = |
| 2128 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2129 | locations->SetOut(Location::ConstantLocation(constant)); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2130 | } |
| 2131 | |
| Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2132 | void InstructionCodeGeneratorX86_64::VisitIntConstant(HIntConstant* constant ATTRIBUTE_UNUSED) { |
| Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 2133 | // Will be generated at use site. |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2134 | } |
| 2135 | |
| Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 2136 | void LocationsBuilderX86_64::VisitNullConstant(HNullConstant* constant) { |
| 2137 | LocationSummary* locations = |
| 2138 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 2139 | locations->SetOut(Location::ConstantLocation(constant)); |
| 2140 | } |
| 2141 | |
| Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2142 | void InstructionCodeGeneratorX86_64::VisitNullConstant(HNullConstant* constant ATTRIBUTE_UNUSED) { |
| Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 2143 | // Will be generated at use site. |
| Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 2144 | } |
| 2145 | |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2146 | void LocationsBuilderX86_64::VisitLongConstant(HLongConstant* constant) { |
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2147 | LocationSummary* locations = |
| 2148 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2149 | locations->SetOut(Location::ConstantLocation(constant)); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2150 | } |
| 2151 | |
| Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2152 | void InstructionCodeGeneratorX86_64::VisitLongConstant(HLongConstant* constant ATTRIBUTE_UNUSED) { |
| Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 2153 | // Will be generated at use site. |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2154 | } |
| 2155 | |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2156 | void LocationsBuilderX86_64::VisitFloatConstant(HFloatConstant* constant) { |
| 2157 | LocationSummary* locations = |
| 2158 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 2159 | locations->SetOut(Location::ConstantLocation(constant)); |
| 2160 | } |
| 2161 | |
| Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2162 | void InstructionCodeGeneratorX86_64::VisitFloatConstant(HFloatConstant* constant ATTRIBUTE_UNUSED) { |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2163 | // Will be generated at use site. |
| 2164 | } |
| 2165 | |
| 2166 | void LocationsBuilderX86_64::VisitDoubleConstant(HDoubleConstant* constant) { |
| 2167 | LocationSummary* locations = |
| 2168 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 2169 | locations->SetOut(Location::ConstantLocation(constant)); |
| 2170 | } |
| 2171 | |
| Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2172 | void InstructionCodeGeneratorX86_64::VisitDoubleConstant( |
| 2173 | HDoubleConstant* constant ATTRIBUTE_UNUSED) { |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2174 | // Will be generated at use site. |
| 2175 | } |
| 2176 | |
| Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 2177 | void LocationsBuilderX86_64::VisitConstructorFence(HConstructorFence* constructor_fence) { |
| 2178 | constructor_fence->SetLocations(nullptr); |
| 2179 | } |
| 2180 | |
| 2181 | void InstructionCodeGeneratorX86_64::VisitConstructorFence( |
| 2182 | HConstructorFence* constructor_fence ATTRIBUTE_UNUSED) { |
| 2183 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kStoreStore); |
| 2184 | } |
| 2185 | |
| Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 2186 | void LocationsBuilderX86_64::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 2187 | memory_barrier->SetLocations(nullptr); |
| 2188 | } |
| 2189 | |
| 2190 | void InstructionCodeGeneratorX86_64::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 2191 | codegen_->GenerateMemoryBarrier(memory_barrier->GetBarrierKind()); |
| Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 2192 | } |
| 2193 | |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2194 | void LocationsBuilderX86_64::VisitReturnVoid(HReturnVoid* ret) { |
| 2195 | ret->SetLocations(nullptr); |
| 2196 | } |
| 2197 | |
| Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2198 | void InstructionCodeGeneratorX86_64::VisitReturnVoid(HReturnVoid* ret ATTRIBUTE_UNUSED) { |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2199 | codegen_->GenerateFrameExit(); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2200 | } |
| 2201 | |
| 2202 | void LocationsBuilderX86_64::VisitReturn(HReturn* ret) { |
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2203 | LocationSummary* locations = |
| 2204 | new (GetGraph()->GetArena()) LocationSummary(ret, LocationSummary::kNoCall); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2205 | switch (ret->InputAt(0)->GetType()) { |
| 2206 | case Primitive::kPrimBoolean: |
| 2207 | case Primitive::kPrimByte: |
| 2208 | case Primitive::kPrimChar: |
| 2209 | case Primitive::kPrimShort: |
| 2210 | case Primitive::kPrimInt: |
| 2211 | case Primitive::kPrimNot: |
| 2212 | case Primitive::kPrimLong: |
| Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2213 | locations->SetInAt(0, Location::RegisterLocation(RAX)); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2214 | break; |
| 2215 | |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2216 | case Primitive::kPrimFloat: |
| 2217 | case Primitive::kPrimDouble: |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2218 | locations->SetInAt(0, Location::FpuRegisterLocation(XMM0)); |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2219 | break; |
| 2220 | |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2221 | default: |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2222 | LOG(FATAL) << "Unexpected return type " << ret->InputAt(0)->GetType(); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2223 | } |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2224 | } |
| 2225 | |
| 2226 | void InstructionCodeGeneratorX86_64::VisitReturn(HReturn* ret) { |
| 2227 | if (kIsDebugBuild) { |
| 2228 | switch (ret->InputAt(0)->GetType()) { |
| 2229 | case Primitive::kPrimBoolean: |
| 2230 | case Primitive::kPrimByte: |
| 2231 | case Primitive::kPrimChar: |
| 2232 | case Primitive::kPrimShort: |
| 2233 | case Primitive::kPrimInt: |
| 2234 | case Primitive::kPrimNot: |
| 2235 | case Primitive::kPrimLong: |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2236 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsRegister<CpuRegister>().AsRegister(), RAX); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2237 | break; |
| 2238 | |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2239 | case Primitive::kPrimFloat: |
| 2240 | case Primitive::kPrimDouble: |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2241 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsFpuRegister<XmmRegister>().AsFloatRegister(), |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2242 | XMM0); |
| 2243 | break; |
| 2244 | |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2245 | default: |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2246 | LOG(FATAL) << "Unexpected return type " << ret->InputAt(0)->GetType(); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2247 | } |
| 2248 | } |
| 2249 | codegen_->GenerateFrameExit(); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2250 | } |
| 2251 | |
| Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 2252 | Location InvokeDexCallingConventionVisitorX86_64::GetReturnLocation(Primitive::Type type) const { |
| 2253 | switch (type) { |
| 2254 | case Primitive::kPrimBoolean: |
| 2255 | case Primitive::kPrimByte: |
| 2256 | case Primitive::kPrimChar: |
| 2257 | case Primitive::kPrimShort: |
| 2258 | case Primitive::kPrimInt: |
| 2259 | case Primitive::kPrimNot: |
| 2260 | case Primitive::kPrimLong: |
| 2261 | return Location::RegisterLocation(RAX); |
| 2262 | |
| 2263 | case Primitive::kPrimVoid: |
| 2264 | return Location::NoLocation(); |
| 2265 | |
| 2266 | case Primitive::kPrimDouble: |
| 2267 | case Primitive::kPrimFloat: |
| 2268 | return Location::FpuRegisterLocation(XMM0); |
| 2269 | } |
| Nicolas Geoffray | 0d1652e | 2015-06-03 12:12:19 +0100 | [diff] [blame] | 2270 | |
| 2271 | UNREACHABLE(); |
| Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 2272 | } |
| 2273 | |
| 2274 | Location InvokeDexCallingConventionVisitorX86_64::GetMethodLocation() const { |
| 2275 | return Location::RegisterLocation(kMethodRegisterArgument); |
| 2276 | } |
| 2277 | |
| Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 2278 | Location InvokeDexCallingConventionVisitorX86_64::GetNextLocation(Primitive::Type type) { |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2279 | switch (type) { |
| 2280 | case Primitive::kPrimBoolean: |
| 2281 | case Primitive::kPrimByte: |
| 2282 | case Primitive::kPrimChar: |
| 2283 | case Primitive::kPrimShort: |
| 2284 | case Primitive::kPrimInt: |
| 2285 | case Primitive::kPrimNot: { |
| 2286 | uint32_t index = gp_index_++; |
| 2287 | stack_index_++; |
| 2288 | if (index < calling_convention.GetNumberOfRegisters()) { |
| Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2289 | return Location::RegisterLocation(calling_convention.GetRegisterAt(index)); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2290 | } else { |
| 2291 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 1)); |
| 2292 | } |
| 2293 | } |
| 2294 | |
| 2295 | case Primitive::kPrimLong: { |
| 2296 | uint32_t index = gp_index_; |
| 2297 | stack_index_ += 2; |
| 2298 | if (index < calling_convention.GetNumberOfRegisters()) { |
| 2299 | gp_index_ += 1; |
| Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2300 | return Location::RegisterLocation(calling_convention.GetRegisterAt(index)); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2301 | } else { |
| 2302 | gp_index_ += 2; |
| 2303 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 2)); |
| 2304 | } |
| 2305 | } |
| 2306 | |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2307 | case Primitive::kPrimFloat: { |
| Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 2308 | uint32_t index = float_index_++; |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2309 | stack_index_++; |
| 2310 | if (index < calling_convention.GetNumberOfFpuRegisters()) { |
| Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2311 | return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(index)); |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2312 | } else { |
| 2313 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 1)); |
| 2314 | } |
| 2315 | } |
| 2316 | |
| 2317 | case Primitive::kPrimDouble: { |
| Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 2318 | uint32_t index = float_index_++; |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2319 | stack_index_ += 2; |
| 2320 | if (index < calling_convention.GetNumberOfFpuRegisters()) { |
| Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2321 | return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(index)); |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2322 | } else { |
| 2323 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 2)); |
| 2324 | } |
| 2325 | } |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2326 | |
| 2327 | case Primitive::kPrimVoid: |
| 2328 | LOG(FATAL) << "Unexpected parameter type " << type; |
| 2329 | break; |
| 2330 | } |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2331 | return Location::NoLocation(); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2332 | } |
| 2333 | |
| Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 2334 | void LocationsBuilderX86_64::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 2335 | // The trampoline uses the same calling convention as dex calling conventions, |
| 2336 | // except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain |
| 2337 | // the method_idx. |
| 2338 | HandleInvoke(invoke); |
| 2339 | } |
| 2340 | |
| 2341 | void InstructionCodeGeneratorX86_64::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 2342 | codegen_->GenerateInvokeUnresolvedRuntimeCall(invoke); |
| 2343 | } |
| 2344 | |
| Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 2345 | void LocationsBuilderX86_64::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
| David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 2346 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 2347 | // art::PrepareForRegisterAllocation. |
| 2348 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
| Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 2349 | |
| Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 2350 | IntrinsicLocationsBuilderX86_64 intrinsic(codegen_); |
| Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 2351 | if (intrinsic.TryDispatch(invoke)) { |
| 2352 | return; |
| 2353 | } |
| 2354 | |
| Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2355 | HandleInvoke(invoke); |
| 2356 | } |
| 2357 | |
| Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 2358 | static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorX86_64* codegen) { |
| 2359 | if (invoke->GetLocations()->Intrinsified()) { |
| 2360 | IntrinsicCodeGeneratorX86_64 intrinsic(codegen); |
| 2361 | intrinsic.Dispatch(invoke); |
| 2362 | return true; |
| 2363 | } |
| 2364 | return false; |
| 2365 | } |
| 2366 | |
| Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 2367 | void InstructionCodeGeneratorX86_64::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
| David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 2368 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 2369 | // art::PrepareForRegisterAllocation. |
| 2370 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
| Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 2371 | |
| Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 2372 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 2373 | return; |
| 2374 | } |
| Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2375 | |
| Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 2376 | LocationSummary* locations = invoke->GetLocations(); |
| Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 2377 | codegen_->GenerateStaticOrDirectCall( |
| Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 2378 | invoke, locations->HasTemps() ? locations->GetTemp(0) : Location::NoLocation()); |
| Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 2379 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2380 | } |
| 2381 | |
| Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2382 | void LocationsBuilderX86_64::HandleInvoke(HInvoke* invoke) { |
| Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 2383 | InvokeDexCallingConventionVisitorX86_64 calling_convention_visitor; |
| Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 2384 | CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2385 | } |
| 2386 | |
| Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2387 | void LocationsBuilderX86_64::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
| Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 2388 | IntrinsicLocationsBuilderX86_64 intrinsic(codegen_); |
| Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 2389 | if (intrinsic.TryDispatch(invoke)) { |
| 2390 | return; |
| 2391 | } |
| 2392 | |
| Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2393 | HandleInvoke(invoke); |
| 2394 | } |
| 2395 | |
| Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2396 | void InstructionCodeGeneratorX86_64::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
| Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 2397 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 2398 | return; |
| 2399 | } |
| 2400 | |
| Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 2401 | codegen_->GenerateVirtualCall(invoke, invoke->GetLocations()->GetTemp(0)); |
| Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 2402 | DCHECK(!codegen_->IsLeafMethod()); |
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2403 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2404 | } |
| 2405 | |
| Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2406 | void LocationsBuilderX86_64::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 2407 | HandleInvoke(invoke); |
| 2408 | // Add the hidden argument. |
| 2409 | invoke->GetLocations()->AddTemp(Location::RegisterLocation(RAX)); |
| 2410 | } |
| 2411 | |
| 2412 | void InstructionCodeGeneratorX86_64::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 2413 | // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError. |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2414 | LocationSummary* locations = invoke->GetLocations(); |
| 2415 | CpuRegister temp = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 2416 | CpuRegister hidden_reg = locations->GetTemp(1).AsRegister<CpuRegister>(); |
| Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2417 | Location receiver = locations->InAt(0); |
| 2418 | size_t class_offset = mirror::Object::ClassOffset().SizeValue(); |
| 2419 | |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2420 | // Set the hidden argument. This is safe to do this here, as RAX |
| 2421 | // won't be modified thereafter, before the `call` instruction. |
| 2422 | DCHECK_EQ(RAX, hidden_reg.AsRegister()); |
| Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 2423 | codegen_->Load64BitValue(hidden_reg, invoke->GetDexMethodIndex()); |
| Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2424 | |
| Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2425 | if (receiver.IsStackSlot()) { |
| 2426 | __ movl(temp, Address(CpuRegister(RSP), receiver.GetStackIndex())); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2427 | // /* HeapReference<Class> */ temp = temp->klass_ |
| Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2428 | __ movl(temp, Address(temp, class_offset)); |
| 2429 | } else { |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2430 | // /* HeapReference<Class> */ temp = receiver->klass_ |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2431 | __ movl(temp, Address(receiver.AsRegister<CpuRegister>(), class_offset)); |
| Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2432 | } |
| Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 2433 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2434 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 2435 | // emit a read barrier for the previous class reference load. |
| 2436 | // However this is not required in practice, as this is an |
| 2437 | // intermediate/temporary reference and because the current |
| 2438 | // concurrent copying collector keeps the from-space memory |
| 2439 | // intact/accessible until the end of the marking phase (the |
| 2440 | // concurrent copying collector may not in the future). |
| Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2441 | __ MaybeUnpoisonHeapReference(temp); |
| Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 2442 | // temp = temp->GetAddressOfIMT() |
| 2443 | __ movq(temp, |
| 2444 | Address(temp, mirror::Class::ImtPtrOffset(kX86_64PointerSize).Uint32Value())); |
| 2445 | // temp = temp->GetImtEntryAt(method_offset); |
| 2446 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
| Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 2447 | invoke->GetImtIndex(), kX86_64PointerSize)); |
| Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2448 | // temp = temp->GetImtEntryAt(method_offset); |
| Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 2449 | __ movq(temp, Address(temp, method_offset)); |
| Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2450 | // call temp->GetEntryPoint(); |
| Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 2451 | __ call(Address( |
| 2452 | temp, ArtMethod::EntryPointFromQuickCompiledCodeOffset(kX86_64PointerSize).SizeValue())); |
| Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2453 | |
| 2454 | DCHECK(!codegen_->IsLeafMethod()); |
| 2455 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 2456 | } |
| 2457 | |
| Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 2458 | void LocationsBuilderX86_64::VisitInvokePolymorphic(HInvokePolymorphic* invoke) { |
| 2459 | HandleInvoke(invoke); |
| 2460 | } |
| 2461 | |
| 2462 | void InstructionCodeGeneratorX86_64::VisitInvokePolymorphic(HInvokePolymorphic* invoke) { |
| 2463 | codegen_->GenerateInvokePolymorphicCall(invoke); |
| 2464 | } |
| 2465 | |
| Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2466 | void LocationsBuilderX86_64::VisitNeg(HNeg* neg) { |
| 2467 | LocationSummary* locations = |
| 2468 | new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall); |
| 2469 | switch (neg->GetResultType()) { |
| 2470 | case Primitive::kPrimInt: |
| Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 2471 | case Primitive::kPrimLong: |
| Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2472 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2473 | locations->SetOut(Location::SameAsFirstInput()); |
| 2474 | break; |
| 2475 | |
| Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2476 | case Primitive::kPrimFloat: |
| 2477 | case Primitive::kPrimDouble: |
| Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2478 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2479 | locations->SetOut(Location::SameAsFirstInput()); |
| Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2480 | locations->AddTemp(Location::RequiresFpuRegister()); |
| Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2481 | break; |
| 2482 | |
| 2483 | default: |
| 2484 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 2485 | } |
| 2486 | } |
| 2487 | |
| 2488 | void InstructionCodeGeneratorX86_64::VisitNeg(HNeg* neg) { |
| 2489 | LocationSummary* locations = neg->GetLocations(); |
| 2490 | Location out = locations->Out(); |
| 2491 | Location in = locations->InAt(0); |
| 2492 | switch (neg->GetResultType()) { |
| 2493 | case Primitive::kPrimInt: |
| 2494 | DCHECK(in.IsRegister()); |
| Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2495 | DCHECK(in.Equals(out)); |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2496 | __ negl(out.AsRegister<CpuRegister>()); |
| Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2497 | break; |
| 2498 | |
| 2499 | case Primitive::kPrimLong: |
| Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 2500 | DCHECK(in.IsRegister()); |
| Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2501 | DCHECK(in.Equals(out)); |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2502 | __ negq(out.AsRegister<CpuRegister>()); |
| Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 2503 | break; |
| 2504 | |
| Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2505 | case Primitive::kPrimFloat: { |
| 2506 | DCHECK(in.Equals(out)); |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2507 | XmmRegister mask = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2508 | // Implement float negation with an exclusive or with value |
| 2509 | // 0x80000000 (mask for bit 31, representing the sign of a |
| 2510 | // single-precision floating-point number). |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2511 | __ movss(mask, codegen_->LiteralInt32Address(0x80000000)); |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2512 | __ xorps(out.AsFpuRegister<XmmRegister>(), mask); |
| Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2513 | break; |
| Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2514 | } |
| Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2515 | |
| Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2516 | case Primitive::kPrimDouble: { |
| 2517 | DCHECK(in.Equals(out)); |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2518 | XmmRegister mask = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2519 | // Implement double negation with an exclusive or with value |
| Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2520 | // 0x8000000000000000 (mask for bit 63, representing the sign of |
| Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2521 | // a double-precision floating-point number). |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2522 | __ movsd(mask, codegen_->LiteralInt64Address(INT64_C(0x8000000000000000))); |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2523 | __ xorpd(out.AsFpuRegister<XmmRegister>(), mask); |
| Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2524 | break; |
| Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2525 | } |
| Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2526 | |
| 2527 | default: |
| 2528 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 2529 | } |
| 2530 | } |
| 2531 | |
| Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2532 | void LocationsBuilderX86_64::VisitTypeConversion(HTypeConversion* conversion) { |
| 2533 | LocationSummary* locations = |
| 2534 | new (GetGraph()->GetArena()) LocationSummary(conversion, LocationSummary::kNoCall); |
| 2535 | Primitive::Type result_type = conversion->GetResultType(); |
| 2536 | Primitive::Type input_type = conversion->GetInputType(); |
| Nicolas Geoffray | 01fcc9e | 2014-12-01 14:16:20 +0000 | [diff] [blame] | 2537 | DCHECK_NE(result_type, input_type); |
| David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2538 | |
| David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 2539 | // The Java language does not allow treating boolean as an integral type but |
| 2540 | // our bit representation makes it safe. |
| David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2541 | |
| Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2542 | switch (result_type) { |
| Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2543 | case Primitive::kPrimByte: |
| 2544 | switch (input_type) { |
| Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2545 | case Primitive::kPrimLong: |
| 2546 | // Type conversion from long to byte is a result of code transformations. |
| David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2547 | case Primitive::kPrimBoolean: |
| 2548 | // Boolean input is a result of code transformations. |
| Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2549 | case Primitive::kPrimShort: |
| 2550 | case Primitive::kPrimInt: |
| 2551 | case Primitive::kPrimChar: |
| Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2552 | // Processing a Dex `int-to-byte' instruction. |
| Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2553 | locations->SetInAt(0, Location::Any()); |
| 2554 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2555 | break; |
| 2556 | |
| 2557 | default: |
| 2558 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2559 | << " to " << result_type; |
| 2560 | } |
| 2561 | break; |
| 2562 | |
| Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2563 | case Primitive::kPrimShort: |
| 2564 | switch (input_type) { |
| Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2565 | case Primitive::kPrimLong: |
| 2566 | // Type conversion from long to short is a result of code transformations. |
| David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2567 | case Primitive::kPrimBoolean: |
| 2568 | // Boolean input is a result of code transformations. |
| Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2569 | case Primitive::kPrimByte: |
| 2570 | case Primitive::kPrimInt: |
| 2571 | case Primitive::kPrimChar: |
| 2572 | // Processing a Dex `int-to-short' instruction. |
| 2573 | locations->SetInAt(0, Location::Any()); |
| 2574 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2575 | break; |
| 2576 | |
| 2577 | default: |
| 2578 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2579 | << " to " << result_type; |
| 2580 | } |
| 2581 | break; |
| 2582 | |
| Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2583 | case Primitive::kPrimInt: |
| 2584 | switch (input_type) { |
| 2585 | case Primitive::kPrimLong: |
| Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2586 | // Processing a Dex `long-to-int' instruction. |
| Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2587 | locations->SetInAt(0, Location::Any()); |
| 2588 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2589 | break; |
| 2590 | |
| 2591 | case Primitive::kPrimFloat: |
| Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2592 | // Processing a Dex `float-to-int' instruction. |
| 2593 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2594 | locations->SetOut(Location::RequiresRegister()); |
| Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2595 | break; |
| 2596 | |
| Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2597 | case Primitive::kPrimDouble: |
| Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2598 | // Processing a Dex `double-to-int' instruction. |
| 2599 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2600 | locations->SetOut(Location::RequiresRegister()); |
| Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2601 | break; |
| 2602 | |
| 2603 | default: |
| 2604 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2605 | << " to " << result_type; |
| 2606 | } |
| 2607 | break; |
| 2608 | |
| Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2609 | case Primitive::kPrimLong: |
| 2610 | switch (input_type) { |
| David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2611 | case Primitive::kPrimBoolean: |
| 2612 | // Boolean input is a result of code transformations. |
| Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2613 | case Primitive::kPrimByte: |
| 2614 | case Primitive::kPrimShort: |
| 2615 | case Primitive::kPrimInt: |
| Roland Levillain | 666c732 | 2014-11-10 13:39:43 +0000 | [diff] [blame] | 2616 | case Primitive::kPrimChar: |
| Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2617 | // Processing a Dex `int-to-long' instruction. |
| Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2618 | // TODO: We would benefit from a (to-be-implemented) |
| 2619 | // Location::RegisterOrStackSlot requirement for this input. |
| 2620 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2621 | locations->SetOut(Location::RequiresRegister()); |
| 2622 | break; |
| 2623 | |
| 2624 | case Primitive::kPrimFloat: |
| Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2625 | // Processing a Dex `float-to-long' instruction. |
| 2626 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2627 | locations->SetOut(Location::RequiresRegister()); |
| Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2628 | break; |
| 2629 | |
| Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2630 | case Primitive::kPrimDouble: |
| Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2631 | // Processing a Dex `double-to-long' instruction. |
| 2632 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2633 | locations->SetOut(Location::RequiresRegister()); |
| Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2634 | break; |
| 2635 | |
| 2636 | default: |
| 2637 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2638 | << " to " << result_type; |
| 2639 | } |
| 2640 | break; |
| 2641 | |
| Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2642 | case Primitive::kPrimChar: |
| 2643 | switch (input_type) { |
| Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2644 | case Primitive::kPrimLong: |
| 2645 | // Type conversion from long to char is a result of code transformations. |
| David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2646 | case Primitive::kPrimBoolean: |
| 2647 | // Boolean input is a result of code transformations. |
| Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2648 | case Primitive::kPrimByte: |
| 2649 | case Primitive::kPrimShort: |
| 2650 | case Primitive::kPrimInt: |
| Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2651 | // Processing a Dex `int-to-char' instruction. |
| 2652 | locations->SetInAt(0, Location::Any()); |
| 2653 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2654 | break; |
| 2655 | |
| 2656 | default: |
| 2657 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2658 | << " to " << result_type; |
| 2659 | } |
| 2660 | break; |
| 2661 | |
| Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2662 | case Primitive::kPrimFloat: |
| Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2663 | switch (input_type) { |
| David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2664 | case Primitive::kPrimBoolean: |
| 2665 | // Boolean input is a result of code transformations. |
| Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2666 | case Primitive::kPrimByte: |
| 2667 | case Primitive::kPrimShort: |
| 2668 | case Primitive::kPrimInt: |
| 2669 | case Primitive::kPrimChar: |
| 2670 | // Processing a Dex `int-to-float' instruction. |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2671 | locations->SetInAt(0, Location::Any()); |
| Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2672 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2673 | break; |
| 2674 | |
| 2675 | case Primitive::kPrimLong: |
| Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2676 | // Processing a Dex `long-to-float' instruction. |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2677 | locations->SetInAt(0, Location::Any()); |
| Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2678 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2679 | break; |
| 2680 | |
| Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2681 | case Primitive::kPrimDouble: |
| Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2682 | // Processing a Dex `double-to-float' instruction. |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2683 | locations->SetInAt(0, Location::Any()); |
| Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2684 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2685 | break; |
| 2686 | |
| 2687 | default: |
| 2688 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2689 | << " to " << result_type; |
| 2690 | }; |
| 2691 | break; |
| 2692 | |
| Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2693 | case Primitive::kPrimDouble: |
| Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2694 | switch (input_type) { |
| David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2695 | case Primitive::kPrimBoolean: |
| 2696 | // Boolean input is a result of code transformations. |
| Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2697 | case Primitive::kPrimByte: |
| 2698 | case Primitive::kPrimShort: |
| 2699 | case Primitive::kPrimInt: |
| 2700 | case Primitive::kPrimChar: |
| 2701 | // Processing a Dex `int-to-double' instruction. |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2702 | locations->SetInAt(0, Location::Any()); |
| Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2703 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2704 | break; |
| 2705 | |
| 2706 | case Primitive::kPrimLong: |
| Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2707 | // Processing a Dex `long-to-double' instruction. |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2708 | locations->SetInAt(0, Location::Any()); |
| Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2709 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2710 | break; |
| 2711 | |
| Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2712 | case Primitive::kPrimFloat: |
| Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2713 | // Processing a Dex `float-to-double' instruction. |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2714 | locations->SetInAt(0, Location::Any()); |
| Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2715 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2716 | break; |
| 2717 | |
| 2718 | default: |
| 2719 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2720 | << " to " << result_type; |
| 2721 | } |
| Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2722 | break; |
| 2723 | |
| 2724 | default: |
| 2725 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2726 | << " to " << result_type; |
| 2727 | } |
| 2728 | } |
| 2729 | |
| 2730 | void InstructionCodeGeneratorX86_64::VisitTypeConversion(HTypeConversion* conversion) { |
| 2731 | LocationSummary* locations = conversion->GetLocations(); |
| 2732 | Location out = locations->Out(); |
| 2733 | Location in = locations->InAt(0); |
| 2734 | Primitive::Type result_type = conversion->GetResultType(); |
| 2735 | Primitive::Type input_type = conversion->GetInputType(); |
| Nicolas Geoffray | 01fcc9e | 2014-12-01 14:16:20 +0000 | [diff] [blame] | 2736 | DCHECK_NE(result_type, input_type); |
| Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2737 | switch (result_type) { |
| Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2738 | case Primitive::kPrimByte: |
| 2739 | switch (input_type) { |
| Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2740 | case Primitive::kPrimLong: |
| 2741 | // Type conversion from long to byte is a result of code transformations. |
| David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2742 | case Primitive::kPrimBoolean: |
| 2743 | // Boolean input is a result of code transformations. |
| Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2744 | case Primitive::kPrimShort: |
| 2745 | case Primitive::kPrimInt: |
| 2746 | case Primitive::kPrimChar: |
| Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2747 | // Processing a Dex `int-to-byte' instruction. |
| Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2748 | if (in.IsRegister()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2749 | __ movsxb(out.AsRegister<CpuRegister>(), in.AsRegister<CpuRegister>()); |
| Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2750 | } else if (in.IsStackSlot() || in.IsDoubleStackSlot()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2751 | __ movsxb(out.AsRegister<CpuRegister>(), |
| Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2752 | Address(CpuRegister(RSP), in.GetStackIndex())); |
| 2753 | } else { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2754 | __ movl(out.AsRegister<CpuRegister>(), |
| Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2755 | Immediate(static_cast<int8_t>(Int64FromConstant(in.GetConstant())))); |
| Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2756 | } |
| 2757 | break; |
| 2758 | |
| 2759 | default: |
| 2760 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2761 | << " to " << result_type; |
| 2762 | } |
| 2763 | break; |
| 2764 | |
| Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2765 | case Primitive::kPrimShort: |
| 2766 | switch (input_type) { |
| Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2767 | case Primitive::kPrimLong: |
| 2768 | // Type conversion from long to short is a result of code transformations. |
| David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2769 | case Primitive::kPrimBoolean: |
| 2770 | // Boolean input is a result of code transformations. |
| Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2771 | case Primitive::kPrimByte: |
| 2772 | case Primitive::kPrimInt: |
| 2773 | case Primitive::kPrimChar: |
| 2774 | // Processing a Dex `int-to-short' instruction. |
| 2775 | if (in.IsRegister()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2776 | __ movsxw(out.AsRegister<CpuRegister>(), in.AsRegister<CpuRegister>()); |
| Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2777 | } else if (in.IsStackSlot() || in.IsDoubleStackSlot()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2778 | __ movsxw(out.AsRegister<CpuRegister>(), |
| Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2779 | Address(CpuRegister(RSP), in.GetStackIndex())); |
| 2780 | } else { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2781 | __ movl(out.AsRegister<CpuRegister>(), |
| Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2782 | Immediate(static_cast<int16_t>(Int64FromConstant(in.GetConstant())))); |
| Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2783 | } |
| 2784 | break; |
| 2785 | |
| 2786 | default: |
| 2787 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2788 | << " to " << result_type; |
| 2789 | } |
| 2790 | break; |
| 2791 | |
| Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2792 | case Primitive::kPrimInt: |
| 2793 | switch (input_type) { |
| 2794 | case Primitive::kPrimLong: |
| Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2795 | // Processing a Dex `long-to-int' instruction. |
| Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2796 | if (in.IsRegister()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2797 | __ movl(out.AsRegister<CpuRegister>(), in.AsRegister<CpuRegister>()); |
| Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2798 | } else if (in.IsDoubleStackSlot()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2799 | __ movl(out.AsRegister<CpuRegister>(), |
| Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2800 | Address(CpuRegister(RSP), in.GetStackIndex())); |
| 2801 | } else { |
| 2802 | DCHECK(in.IsConstant()); |
| 2803 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 2804 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2805 | __ movl(out.AsRegister<CpuRegister>(), Immediate(static_cast<int32_t>(value))); |
| Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2806 | } |
| 2807 | break; |
| 2808 | |
| Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2809 | case Primitive::kPrimFloat: { |
| 2810 | // Processing a Dex `float-to-int' instruction. |
| 2811 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 2812 | CpuRegister output = out.AsRegister<CpuRegister>(); |
| Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2813 | NearLabel done, nan; |
| Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2814 | |
| 2815 | __ movl(output, Immediate(kPrimIntMax)); |
| Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 2816 | // if input >= (float)INT_MAX goto done |
| 2817 | __ comiss(input, codegen_->LiteralFloatAddress(kPrimIntMax)); |
| Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2818 | __ j(kAboveEqual, &done); |
| 2819 | // if input == NaN goto nan |
| 2820 | __ j(kUnordered, &nan); |
| 2821 | // output = float-to-int-truncate(input) |
| Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2822 | __ cvttss2si(output, input, false); |
| Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2823 | __ jmp(&done); |
| 2824 | __ Bind(&nan); |
| 2825 | // output = 0 |
| 2826 | __ xorl(output, output); |
| 2827 | __ Bind(&done); |
| 2828 | break; |
| 2829 | } |
| 2830 | |
| Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2831 | case Primitive::kPrimDouble: { |
| 2832 | // Processing a Dex `double-to-int' instruction. |
| 2833 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 2834 | CpuRegister output = out.AsRegister<CpuRegister>(); |
| Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2835 | NearLabel done, nan; |
| Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2836 | |
| 2837 | __ movl(output, Immediate(kPrimIntMax)); |
| Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 2838 | // if input >= (double)INT_MAX goto done |
| 2839 | __ comisd(input, codegen_->LiteralDoubleAddress(kPrimIntMax)); |
| Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2840 | __ j(kAboveEqual, &done); |
| 2841 | // if input == NaN goto nan |
| 2842 | __ j(kUnordered, &nan); |
| 2843 | // output = double-to-int-truncate(input) |
| 2844 | __ cvttsd2si(output, input); |
| 2845 | __ jmp(&done); |
| 2846 | __ Bind(&nan); |
| 2847 | // output = 0 |
| 2848 | __ xorl(output, output); |
| 2849 | __ Bind(&done); |
| Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2850 | break; |
| Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2851 | } |
| Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2852 | |
| 2853 | default: |
| 2854 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2855 | << " to " << result_type; |
| 2856 | } |
| 2857 | break; |
| 2858 | |
| Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2859 | case Primitive::kPrimLong: |
| 2860 | switch (input_type) { |
| 2861 | DCHECK(out.IsRegister()); |
| David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2862 | case Primitive::kPrimBoolean: |
| 2863 | // Boolean input is a result of code transformations. |
| Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2864 | case Primitive::kPrimByte: |
| 2865 | case Primitive::kPrimShort: |
| 2866 | case Primitive::kPrimInt: |
| Roland Levillain | 666c732 | 2014-11-10 13:39:43 +0000 | [diff] [blame] | 2867 | case Primitive::kPrimChar: |
| Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2868 | // Processing a Dex `int-to-long' instruction. |
| Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2869 | DCHECK(in.IsRegister()); |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2870 | __ movsxd(out.AsRegister<CpuRegister>(), in.AsRegister<CpuRegister>()); |
| Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2871 | break; |
| 2872 | |
| Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2873 | case Primitive::kPrimFloat: { |
| 2874 | // Processing a Dex `float-to-long' instruction. |
| 2875 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 2876 | CpuRegister output = out.AsRegister<CpuRegister>(); |
| Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2877 | NearLabel done, nan; |
| Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2878 | |
| Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 2879 | codegen_->Load64BitValue(output, kPrimLongMax); |
| Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 2880 | // if input >= (float)LONG_MAX goto done |
| 2881 | __ comiss(input, codegen_->LiteralFloatAddress(kPrimLongMax)); |
| Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2882 | __ j(kAboveEqual, &done); |
| 2883 | // if input == NaN goto nan |
| 2884 | __ j(kUnordered, &nan); |
| Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2885 | // output = float-to-long-truncate(input) |
| Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2886 | __ cvttss2si(output, input, true); |
| 2887 | __ jmp(&done); |
| 2888 | __ Bind(&nan); |
| 2889 | // output = 0 |
| Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 2890 | __ xorl(output, output); |
| Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2891 | __ Bind(&done); |
| 2892 | break; |
| 2893 | } |
| 2894 | |
| Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2895 | case Primitive::kPrimDouble: { |
| 2896 | // Processing a Dex `double-to-long' instruction. |
| 2897 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 2898 | CpuRegister output = out.AsRegister<CpuRegister>(); |
| Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2899 | NearLabel done, nan; |
| Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2900 | |
| Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 2901 | codegen_->Load64BitValue(output, kPrimLongMax); |
| Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 2902 | // if input >= (double)LONG_MAX goto done |
| 2903 | __ comisd(input, codegen_->LiteralDoubleAddress(kPrimLongMax)); |
| Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2904 | __ j(kAboveEqual, &done); |
| 2905 | // if input == NaN goto nan |
| 2906 | __ j(kUnordered, &nan); |
| 2907 | // output = double-to-long-truncate(input) |
| 2908 | __ cvttsd2si(output, input, true); |
| 2909 | __ jmp(&done); |
| 2910 | __ Bind(&nan); |
| 2911 | // output = 0 |
| Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 2912 | __ xorl(output, output); |
| Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2913 | __ Bind(&done); |
| Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2914 | break; |
| Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2915 | } |
| Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2916 | |
| 2917 | default: |
| 2918 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2919 | << " to " << result_type; |
| 2920 | } |
| 2921 | break; |
| 2922 | |
| Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2923 | case Primitive::kPrimChar: |
| 2924 | switch (input_type) { |
| Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2925 | case Primitive::kPrimLong: |
| 2926 | // Type conversion from long to char is a result of code transformations. |
| David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2927 | case Primitive::kPrimBoolean: |
| 2928 | // Boolean input is a result of code transformations. |
| Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2929 | case Primitive::kPrimByte: |
| 2930 | case Primitive::kPrimShort: |
| 2931 | case Primitive::kPrimInt: |
| Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2932 | // Processing a Dex `int-to-char' instruction. |
| 2933 | if (in.IsRegister()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2934 | __ movzxw(out.AsRegister<CpuRegister>(), in.AsRegister<CpuRegister>()); |
| Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2935 | } else if (in.IsStackSlot() || in.IsDoubleStackSlot()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2936 | __ movzxw(out.AsRegister<CpuRegister>(), |
| Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2937 | Address(CpuRegister(RSP), in.GetStackIndex())); |
| 2938 | } else { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2939 | __ movl(out.AsRegister<CpuRegister>(), |
| Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2940 | Immediate(static_cast<uint16_t>(Int64FromConstant(in.GetConstant())))); |
| Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2941 | } |
| 2942 | break; |
| 2943 | |
| 2944 | default: |
| 2945 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2946 | << " to " << result_type; |
| 2947 | } |
| 2948 | break; |
| 2949 | |
| Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2950 | case Primitive::kPrimFloat: |
| Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2951 | switch (input_type) { |
| David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2952 | case Primitive::kPrimBoolean: |
| 2953 | // Boolean input is a result of code transformations. |
| Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2954 | case Primitive::kPrimByte: |
| 2955 | case Primitive::kPrimShort: |
| 2956 | case Primitive::kPrimInt: |
| 2957 | case Primitive::kPrimChar: |
| Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2958 | // Processing a Dex `int-to-float' instruction. |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2959 | if (in.IsRegister()) { |
| 2960 | __ cvtsi2ss(out.AsFpuRegister<XmmRegister>(), in.AsRegister<CpuRegister>(), false); |
| 2961 | } else if (in.IsConstant()) { |
| 2962 | int32_t v = in.GetConstant()->AsIntConstant()->GetValue(); |
| 2963 | XmmRegister dest = out.AsFpuRegister<XmmRegister>(); |
| Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 2964 | codegen_->Load32BitValue(dest, static_cast<float>(v)); |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2965 | } else { |
| 2966 | __ cvtsi2ss(out.AsFpuRegister<XmmRegister>(), |
| 2967 | Address(CpuRegister(RSP), in.GetStackIndex()), false); |
| 2968 | } |
| Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2969 | break; |
| 2970 | |
| 2971 | case Primitive::kPrimLong: |
| Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2972 | // Processing a Dex `long-to-float' instruction. |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2973 | if (in.IsRegister()) { |
| 2974 | __ cvtsi2ss(out.AsFpuRegister<XmmRegister>(), in.AsRegister<CpuRegister>(), true); |
| 2975 | } else if (in.IsConstant()) { |
| 2976 | int64_t v = in.GetConstant()->AsLongConstant()->GetValue(); |
| 2977 | XmmRegister dest = out.AsFpuRegister<XmmRegister>(); |
| Pavel Vyssotski | 4c858cd | 2016-03-16 13:59:53 +0600 | [diff] [blame] | 2978 | codegen_->Load32BitValue(dest, static_cast<float>(v)); |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2979 | } else { |
| 2980 | __ cvtsi2ss(out.AsFpuRegister<XmmRegister>(), |
| 2981 | Address(CpuRegister(RSP), in.GetStackIndex()), true); |
| 2982 | } |
| Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2983 | break; |
| 2984 | |
| Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2985 | case Primitive::kPrimDouble: |
| Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2986 | // Processing a Dex `double-to-float' instruction. |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2987 | if (in.IsFpuRegister()) { |
| 2988 | __ cvtsd2ss(out.AsFpuRegister<XmmRegister>(), in.AsFpuRegister<XmmRegister>()); |
| 2989 | } else if (in.IsConstant()) { |
| 2990 | double v = in.GetConstant()->AsDoubleConstant()->GetValue(); |
| 2991 | XmmRegister dest = out.AsFpuRegister<XmmRegister>(); |
| Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 2992 | codegen_->Load32BitValue(dest, static_cast<float>(v)); |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2993 | } else { |
| 2994 | __ cvtsd2ss(out.AsFpuRegister<XmmRegister>(), |
| 2995 | Address(CpuRegister(RSP), in.GetStackIndex())); |
| 2996 | } |
| Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2997 | break; |
| 2998 | |
| 2999 | default: |
| 3000 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3001 | << " to " << result_type; |
| 3002 | }; |
| 3003 | break; |
| 3004 | |
| Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3005 | case Primitive::kPrimDouble: |
| Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3006 | switch (input_type) { |
| David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 3007 | case Primitive::kPrimBoolean: |
| 3008 | // Boolean input is a result of code transformations. |
| Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3009 | case Primitive::kPrimByte: |
| 3010 | case Primitive::kPrimShort: |
| 3011 | case Primitive::kPrimInt: |
| 3012 | case Primitive::kPrimChar: |
| Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 3013 | // Processing a Dex `int-to-double' instruction. |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 3014 | if (in.IsRegister()) { |
| 3015 | __ cvtsi2sd(out.AsFpuRegister<XmmRegister>(), in.AsRegister<CpuRegister>(), false); |
| 3016 | } else if (in.IsConstant()) { |
| 3017 | int32_t v = in.GetConstant()->AsIntConstant()->GetValue(); |
| 3018 | XmmRegister dest = out.AsFpuRegister<XmmRegister>(); |
| Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 3019 | codegen_->Load64BitValue(dest, static_cast<double>(v)); |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 3020 | } else { |
| 3021 | __ cvtsi2sd(out.AsFpuRegister<XmmRegister>(), |
| 3022 | Address(CpuRegister(RSP), in.GetStackIndex()), false); |
| 3023 | } |
| Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3024 | break; |
| 3025 | |
| 3026 | case Primitive::kPrimLong: |
| Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 3027 | // Processing a Dex `long-to-double' instruction. |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 3028 | if (in.IsRegister()) { |
| 3029 | __ cvtsi2sd(out.AsFpuRegister<XmmRegister>(), in.AsRegister<CpuRegister>(), true); |
| 3030 | } else if (in.IsConstant()) { |
| 3031 | int64_t v = in.GetConstant()->AsLongConstant()->GetValue(); |
| 3032 | XmmRegister dest = out.AsFpuRegister<XmmRegister>(); |
| Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 3033 | codegen_->Load64BitValue(dest, static_cast<double>(v)); |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 3034 | } else { |
| 3035 | __ cvtsi2sd(out.AsFpuRegister<XmmRegister>(), |
| 3036 | Address(CpuRegister(RSP), in.GetStackIndex()), true); |
| 3037 | } |
| Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 3038 | break; |
| 3039 | |
| Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3040 | case Primitive::kPrimFloat: |
| Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 3041 | // Processing a Dex `float-to-double' instruction. |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 3042 | if (in.IsFpuRegister()) { |
| 3043 | __ cvtss2sd(out.AsFpuRegister<XmmRegister>(), in.AsFpuRegister<XmmRegister>()); |
| 3044 | } else if (in.IsConstant()) { |
| 3045 | float v = in.GetConstant()->AsFloatConstant()->GetValue(); |
| 3046 | XmmRegister dest = out.AsFpuRegister<XmmRegister>(); |
| Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 3047 | codegen_->Load64BitValue(dest, static_cast<double>(v)); |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 3048 | } else { |
| 3049 | __ cvtss2sd(out.AsFpuRegister<XmmRegister>(), |
| 3050 | Address(CpuRegister(RSP), in.GetStackIndex())); |
| 3051 | } |
| Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3052 | break; |
| 3053 | |
| 3054 | default: |
| 3055 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3056 | << " to " << result_type; |
| 3057 | }; |
| Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3058 | break; |
| 3059 | |
| 3060 | default: |
| 3061 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3062 | << " to " << result_type; |
| 3063 | } |
| 3064 | } |
| 3065 | |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3066 | void LocationsBuilderX86_64::VisitAdd(HAdd* add) { |
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3067 | LocationSummary* locations = |
| 3068 | new (GetGraph()->GetArena()) LocationSummary(add, LocationSummary::kNoCall); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3069 | switch (add->GetResultType()) { |
| Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 3070 | case Primitive::kPrimInt: { |
| 3071 | locations->SetInAt(0, Location::RequiresRegister()); |
| Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 3072 | locations->SetInAt(1, Location::RegisterOrConstant(add->InputAt(1))); |
| 3073 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 3074 | break; |
| 3075 | } |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3076 | |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3077 | case Primitive::kPrimLong: { |
| Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 3078 | locations->SetInAt(0, Location::RequiresRegister()); |
| Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 3079 | // We can use a leaq or addq if the constant can fit in an immediate. |
| Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 3080 | locations->SetInAt(1, Location::RegisterOrInt32Constant(add->InputAt(1))); |
| Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 3081 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3082 | break; |
| 3083 | } |
| 3084 | |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3085 | case Primitive::kPrimDouble: |
| 3086 | case Primitive::kPrimFloat: { |
| 3087 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3088 | locations->SetInAt(1, Location::Any()); |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3089 | locations->SetOut(Location::SameAsFirstInput()); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3090 | break; |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3091 | } |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3092 | |
| 3093 | default: |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3094 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3095 | } |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3096 | } |
| 3097 | |
| 3098 | void InstructionCodeGeneratorX86_64::VisitAdd(HAdd* add) { |
| 3099 | LocationSummary* locations = add->GetLocations(); |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3100 | Location first = locations->InAt(0); |
| 3101 | Location second = locations->InAt(1); |
| Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 3102 | Location out = locations->Out(); |
| Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3103 | |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3104 | switch (add->GetResultType()) { |
| Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 3105 | case Primitive::kPrimInt: { |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3106 | if (second.IsRegister()) { |
| Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 3107 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 3108 | __ addl(out.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
| Mark Mendell | 33bf245 | 2015-05-27 10:08:24 -0400 | [diff] [blame] | 3109 | } else if (out.AsRegister<Register>() == second.AsRegister<Register>()) { |
| 3110 | __ addl(out.AsRegister<CpuRegister>(), first.AsRegister<CpuRegister>()); |
| Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 3111 | } else { |
| 3112 | __ leal(out.AsRegister<CpuRegister>(), Address( |
| 3113 | first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>(), TIMES_1, 0)); |
| 3114 | } |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3115 | } else if (second.IsConstant()) { |
| Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 3116 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 3117 | __ addl(out.AsRegister<CpuRegister>(), |
| 3118 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
| 3119 | } else { |
| 3120 | __ leal(out.AsRegister<CpuRegister>(), Address( |
| 3121 | first.AsRegister<CpuRegister>(), second.GetConstant()->AsIntConstant()->GetValue())); |
| 3122 | } |
| Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 3123 | } else { |
| Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 3124 | DCHECK(first.Equals(locations->Out())); |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3125 | __ addl(first.AsRegister<CpuRegister>(), Address(CpuRegister(RSP), second.GetStackIndex())); |
| Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 3126 | } |
| Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 3127 | break; |
| 3128 | } |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3129 | |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3130 | case Primitive::kPrimLong: { |
| Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 3131 | if (second.IsRegister()) { |
| 3132 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 3133 | __ addq(out.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
| Mark Mendell | 33bf245 | 2015-05-27 10:08:24 -0400 | [diff] [blame] | 3134 | } else if (out.AsRegister<Register>() == second.AsRegister<Register>()) { |
| 3135 | __ addq(out.AsRegister<CpuRegister>(), first.AsRegister<CpuRegister>()); |
| Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 3136 | } else { |
| 3137 | __ leaq(out.AsRegister<CpuRegister>(), Address( |
| 3138 | first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>(), TIMES_1, 0)); |
| 3139 | } |
| 3140 | } else { |
| 3141 | DCHECK(second.IsConstant()); |
| 3142 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 3143 | int32_t int32_value = Low32Bits(value); |
| 3144 | DCHECK_EQ(int32_value, value); |
| 3145 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 3146 | __ addq(out.AsRegister<CpuRegister>(), Immediate(int32_value)); |
| 3147 | } else { |
| 3148 | __ leaq(out.AsRegister<CpuRegister>(), Address( |
| 3149 | first.AsRegister<CpuRegister>(), int32_value)); |
| 3150 | } |
| 3151 | } |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3152 | break; |
| 3153 | } |
| 3154 | |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3155 | case Primitive::kPrimFloat: { |
| Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3156 | if (second.IsFpuRegister()) { |
| 3157 | __ addss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3158 | } else if (second.IsConstant()) { |
| 3159 | __ addss(first.AsFpuRegister<XmmRegister>(), |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 3160 | codegen_->LiteralFloatAddress( |
| 3161 | second.GetConstant()->AsFloatConstant()->GetValue())); |
| Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3162 | } else { |
| 3163 | DCHECK(second.IsStackSlot()); |
| 3164 | __ addss(first.AsFpuRegister<XmmRegister>(), |
| 3165 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 3166 | } |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3167 | break; |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3168 | } |
| 3169 | |
| 3170 | case Primitive::kPrimDouble: { |
| Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3171 | if (second.IsFpuRegister()) { |
| 3172 | __ addsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3173 | } else if (second.IsConstant()) { |
| 3174 | __ addsd(first.AsFpuRegister<XmmRegister>(), |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 3175 | codegen_->LiteralDoubleAddress( |
| 3176 | second.GetConstant()->AsDoubleConstant()->GetValue())); |
| Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3177 | } else { |
| 3178 | DCHECK(second.IsDoubleStackSlot()); |
| 3179 | __ addsd(first.AsFpuRegister<XmmRegister>(), |
| 3180 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 3181 | } |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3182 | break; |
| 3183 | } |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3184 | |
| 3185 | default: |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3186 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3187 | } |
| 3188 | } |
| 3189 | |
| 3190 | void LocationsBuilderX86_64::VisitSub(HSub* sub) { |
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3191 | LocationSummary* locations = |
| 3192 | new (GetGraph()->GetArena()) LocationSummary(sub, LocationSummary::kNoCall); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3193 | switch (sub->GetResultType()) { |
| Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 3194 | case Primitive::kPrimInt: { |
| 3195 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3196 | locations->SetInAt(1, Location::Any()); |
| 3197 | locations->SetOut(Location::SameAsFirstInput()); |
| 3198 | break; |
| 3199 | } |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3200 | case Primitive::kPrimLong: { |
| Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 3201 | locations->SetInAt(0, Location::RequiresRegister()); |
| Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 3202 | locations->SetInAt(1, Location::RegisterOrInt32Constant(sub->InputAt(1))); |
| Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 3203 | locations->SetOut(Location::SameAsFirstInput()); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3204 | break; |
| 3205 | } |
| Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3206 | case Primitive::kPrimFloat: |
| 3207 | case Primitive::kPrimDouble: { |
| 3208 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3209 | locations->SetInAt(1, Location::Any()); |
| Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3210 | locations->SetOut(Location::SameAsFirstInput()); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3211 | break; |
| Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3212 | } |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3213 | default: |
| Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3214 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3215 | } |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3216 | } |
| 3217 | |
| 3218 | void InstructionCodeGeneratorX86_64::VisitSub(HSub* sub) { |
| 3219 | LocationSummary* locations = sub->GetLocations(); |
| Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3220 | Location first = locations->InAt(0); |
| 3221 | Location second = locations->InAt(1); |
| 3222 | DCHECK(first.Equals(locations->Out())); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3223 | switch (sub->GetResultType()) { |
| Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 3224 | case Primitive::kPrimInt: { |
| Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3225 | if (second.IsRegister()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3226 | __ subl(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
| Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3227 | } else if (second.IsConstant()) { |
| 3228 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue()); |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3229 | __ subl(first.AsRegister<CpuRegister>(), imm); |
| Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 3230 | } else { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3231 | __ subl(first.AsRegister<CpuRegister>(), Address(CpuRegister(RSP), second.GetStackIndex())); |
| Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 3232 | } |
| Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 3233 | break; |
| 3234 | } |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3235 | case Primitive::kPrimLong: { |
| Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 3236 | if (second.IsConstant()) { |
| 3237 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 3238 | DCHECK(IsInt<32>(value)); |
| 3239 | __ subq(first.AsRegister<CpuRegister>(), Immediate(static_cast<int32_t>(value))); |
| 3240 | } else { |
| 3241 | __ subq(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
| 3242 | } |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3243 | break; |
| 3244 | } |
| 3245 | |
| Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3246 | case Primitive::kPrimFloat: { |
| Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3247 | if (second.IsFpuRegister()) { |
| 3248 | __ subss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3249 | } else if (second.IsConstant()) { |
| 3250 | __ subss(first.AsFpuRegister<XmmRegister>(), |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 3251 | codegen_->LiteralFloatAddress( |
| 3252 | second.GetConstant()->AsFloatConstant()->GetValue())); |
| Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3253 | } else { |
| 3254 | DCHECK(second.IsStackSlot()); |
| 3255 | __ subss(first.AsFpuRegister<XmmRegister>(), |
| 3256 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 3257 | } |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3258 | break; |
| Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3259 | } |
| 3260 | |
| 3261 | case Primitive::kPrimDouble: { |
| Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3262 | if (second.IsFpuRegister()) { |
| 3263 | __ subsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3264 | } else if (second.IsConstant()) { |
| 3265 | __ subsd(first.AsFpuRegister<XmmRegister>(), |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 3266 | codegen_->LiteralDoubleAddress( |
| 3267 | second.GetConstant()->AsDoubleConstant()->GetValue())); |
| Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3268 | } else { |
| 3269 | DCHECK(second.IsDoubleStackSlot()); |
| 3270 | __ subsd(first.AsFpuRegister<XmmRegister>(), |
| 3271 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 3272 | } |
| Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3273 | break; |
| 3274 | } |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3275 | |
| 3276 | default: |
| Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3277 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3278 | } |
| 3279 | } |
| 3280 | |
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3281 | void LocationsBuilderX86_64::VisitMul(HMul* mul) { |
| 3282 | LocationSummary* locations = |
| 3283 | new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall); |
| 3284 | switch (mul->GetResultType()) { |
| 3285 | case Primitive::kPrimInt: { |
| 3286 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3287 | locations->SetInAt(1, Location::Any()); |
| Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3288 | if (mul->InputAt(1)->IsIntConstant()) { |
| 3289 | // Can use 3 operand multiply. |
| 3290 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3291 | } else { |
| 3292 | locations->SetOut(Location::SameAsFirstInput()); |
| 3293 | } |
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3294 | break; |
| 3295 | } |
| 3296 | case Primitive::kPrimLong: { |
| 3297 | locations->SetInAt(0, Location::RequiresRegister()); |
| Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3298 | locations->SetInAt(1, Location::Any()); |
| 3299 | if (mul->InputAt(1)->IsLongConstant() && |
| 3300 | IsInt<32>(mul->InputAt(1)->AsLongConstant()->GetValue())) { |
| Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 3301 | // Can use 3 operand multiply. |
| 3302 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3303 | } else { |
| 3304 | locations->SetOut(Location::SameAsFirstInput()); |
| 3305 | } |
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3306 | break; |
| 3307 | } |
| Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3308 | case Primitive::kPrimFloat: |
| 3309 | case Primitive::kPrimDouble: { |
| 3310 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3311 | locations->SetInAt(1, Location::Any()); |
| Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3312 | locations->SetOut(Location::SameAsFirstInput()); |
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3313 | break; |
| Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3314 | } |
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3315 | |
| 3316 | default: |
| Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3317 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3318 | } |
| 3319 | } |
| 3320 | |
| 3321 | void InstructionCodeGeneratorX86_64::VisitMul(HMul* mul) { |
| 3322 | LocationSummary* locations = mul->GetLocations(); |
| 3323 | Location first = locations->InAt(0); |
| 3324 | Location second = locations->InAt(1); |
| Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3325 | Location out = locations->Out(); |
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3326 | switch (mul->GetResultType()) { |
| Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3327 | case Primitive::kPrimInt: |
| 3328 | // The constant may have ended up in a register, so test explicitly to avoid |
| 3329 | // problems where the output may not be the same as the first operand. |
| 3330 | if (mul->InputAt(1)->IsIntConstant()) { |
| 3331 | Immediate imm(mul->InputAt(1)->AsIntConstant()->GetValue()); |
| 3332 | __ imull(out.AsRegister<CpuRegister>(), first.AsRegister<CpuRegister>(), imm); |
| 3333 | } else if (second.IsRegister()) { |
| 3334 | DCHECK(first.Equals(out)); |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3335 | __ imull(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3336 | } else { |
| Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3337 | DCHECK(first.Equals(out)); |
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3338 | DCHECK(second.IsStackSlot()); |
| Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 3339 | __ imull(first.AsRegister<CpuRegister>(), |
| 3340 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3341 | } |
| 3342 | break; |
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3343 | case Primitive::kPrimLong: { |
| Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3344 | // The constant may have ended up in a register, so test explicitly to avoid |
| 3345 | // problems where the output may not be the same as the first operand. |
| 3346 | if (mul->InputAt(1)->IsLongConstant()) { |
| 3347 | int64_t value = mul->InputAt(1)->AsLongConstant()->GetValue(); |
| 3348 | if (IsInt<32>(value)) { |
| 3349 | __ imulq(out.AsRegister<CpuRegister>(), first.AsRegister<CpuRegister>(), |
| 3350 | Immediate(static_cast<int32_t>(value))); |
| 3351 | } else { |
| 3352 | // Have to use the constant area. |
| 3353 | DCHECK(first.Equals(out)); |
| 3354 | __ imulq(first.AsRegister<CpuRegister>(), codegen_->LiteralInt64Address(value)); |
| 3355 | } |
| 3356 | } else if (second.IsRegister()) { |
| 3357 | DCHECK(first.Equals(out)); |
| Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 3358 | __ imulq(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
| Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3359 | } else { |
| 3360 | DCHECK(second.IsDoubleStackSlot()); |
| 3361 | DCHECK(first.Equals(out)); |
| 3362 | __ imulq(first.AsRegister<CpuRegister>(), |
| 3363 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 3364 | } |
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3365 | break; |
| 3366 | } |
| 3367 | |
| Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3368 | case Primitive::kPrimFloat: { |
| Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3369 | DCHECK(first.Equals(out)); |
| Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3370 | if (second.IsFpuRegister()) { |
| 3371 | __ mulss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3372 | } else if (second.IsConstant()) { |
| 3373 | __ mulss(first.AsFpuRegister<XmmRegister>(), |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 3374 | codegen_->LiteralFloatAddress( |
| 3375 | second.GetConstant()->AsFloatConstant()->GetValue())); |
| Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3376 | } else { |
| 3377 | DCHECK(second.IsStackSlot()); |
| 3378 | __ mulss(first.AsFpuRegister<XmmRegister>(), |
| 3379 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 3380 | } |
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3381 | break; |
| Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3382 | } |
| 3383 | |
| 3384 | case Primitive::kPrimDouble: { |
| Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3385 | DCHECK(first.Equals(out)); |
| Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3386 | if (second.IsFpuRegister()) { |
| 3387 | __ mulsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3388 | } else if (second.IsConstant()) { |
| 3389 | __ mulsd(first.AsFpuRegister<XmmRegister>(), |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 3390 | codegen_->LiteralDoubleAddress( |
| 3391 | second.GetConstant()->AsDoubleConstant()->GetValue())); |
| Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3392 | } else { |
| 3393 | DCHECK(second.IsDoubleStackSlot()); |
| 3394 | __ mulsd(first.AsFpuRegister<XmmRegister>(), |
| 3395 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 3396 | } |
| Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3397 | break; |
| 3398 | } |
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3399 | |
| 3400 | default: |
| Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3401 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3402 | } |
| 3403 | } |
| 3404 | |
| Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3405 | void InstructionCodeGeneratorX86_64::PushOntoFPStack(Location source, uint32_t temp_offset, |
| 3406 | uint32_t stack_adjustment, bool is_float) { |
| 3407 | if (source.IsStackSlot()) { |
| 3408 | DCHECK(is_float); |
| 3409 | __ flds(Address(CpuRegister(RSP), source.GetStackIndex() + stack_adjustment)); |
| 3410 | } else if (source.IsDoubleStackSlot()) { |
| 3411 | DCHECK(!is_float); |
| 3412 | __ fldl(Address(CpuRegister(RSP), source.GetStackIndex() + stack_adjustment)); |
| 3413 | } else { |
| 3414 | // Write the value to the temporary location on the stack and load to FP stack. |
| 3415 | if (is_float) { |
| 3416 | Location stack_temp = Location::StackSlot(temp_offset); |
| 3417 | codegen_->Move(stack_temp, source); |
| 3418 | __ flds(Address(CpuRegister(RSP), temp_offset)); |
| 3419 | } else { |
| 3420 | Location stack_temp = Location::DoubleStackSlot(temp_offset); |
| 3421 | codegen_->Move(stack_temp, source); |
| 3422 | __ fldl(Address(CpuRegister(RSP), temp_offset)); |
| 3423 | } |
| 3424 | } |
| 3425 | } |
| 3426 | |
| 3427 | void InstructionCodeGeneratorX86_64::GenerateRemFP(HRem *rem) { |
| 3428 | Primitive::Type type = rem->GetResultType(); |
| 3429 | bool is_float = type == Primitive::kPrimFloat; |
| 3430 | size_t elem_size = Primitive::ComponentSize(type); |
| 3431 | LocationSummary* locations = rem->GetLocations(); |
| 3432 | Location first = locations->InAt(0); |
| 3433 | Location second = locations->InAt(1); |
| 3434 | Location out = locations->Out(); |
| 3435 | |
| 3436 | // Create stack space for 2 elements. |
| 3437 | // TODO: enhance register allocator to ask for stack temporaries. |
| 3438 | __ subq(CpuRegister(RSP), Immediate(2 * elem_size)); |
| 3439 | |
| 3440 | // Load the values to the FP stack in reverse order, using temporaries if needed. |
| 3441 | PushOntoFPStack(second, elem_size, 2 * elem_size, is_float); |
| 3442 | PushOntoFPStack(first, 0, 2 * elem_size, is_float); |
| 3443 | |
| 3444 | // Loop doing FPREM until we stabilize. |
| Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 3445 | NearLabel retry; |
| Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3446 | __ Bind(&retry); |
| 3447 | __ fprem(); |
| 3448 | |
| 3449 | // Move FP status to AX. |
| 3450 | __ fstsw(); |
| 3451 | |
| 3452 | // And see if the argument reduction is complete. This is signaled by the |
| 3453 | // C2 FPU flag bit set to 0. |
| 3454 | __ andl(CpuRegister(RAX), Immediate(kC2ConditionMask)); |
| 3455 | __ j(kNotEqual, &retry); |
| 3456 | |
| 3457 | // We have settled on the final value. Retrieve it into an XMM register. |
| 3458 | // Store FP top of stack to real stack. |
| 3459 | if (is_float) { |
| 3460 | __ fsts(Address(CpuRegister(RSP), 0)); |
| 3461 | } else { |
| 3462 | __ fstl(Address(CpuRegister(RSP), 0)); |
| 3463 | } |
| 3464 | |
| 3465 | // Pop the 2 items from the FP stack. |
| 3466 | __ fucompp(); |
| 3467 | |
| 3468 | // Load the value from the stack into an XMM register. |
| 3469 | DCHECK(out.IsFpuRegister()) << out; |
| 3470 | if (is_float) { |
| 3471 | __ movss(out.AsFpuRegister<XmmRegister>(), Address(CpuRegister(RSP), 0)); |
| 3472 | } else { |
| 3473 | __ movsd(out.AsFpuRegister<XmmRegister>(), Address(CpuRegister(RSP), 0)); |
| 3474 | } |
| 3475 | |
| 3476 | // And remove the temporary stack space we allocated. |
| 3477 | __ addq(CpuRegister(RSP), Immediate(2 * elem_size)); |
| 3478 | } |
| 3479 | |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3480 | void InstructionCodeGeneratorX86_64::DivRemOneOrMinusOne(HBinaryOperation* instruction) { |
| 3481 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3482 | |
| 3483 | LocationSummary* locations = instruction->GetLocations(); |
| 3484 | Location second = locations->InAt(1); |
| 3485 | DCHECK(second.IsConstant()); |
| 3486 | |
| 3487 | CpuRegister output_register = locations->Out().AsRegister<CpuRegister>(); |
| 3488 | CpuRegister input_register = locations->InAt(0).AsRegister<CpuRegister>(); |
| Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3489 | int64_t imm = Int64FromConstant(second.GetConstant()); |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3490 | |
| 3491 | DCHECK(imm == 1 || imm == -1); |
| 3492 | |
| 3493 | switch (instruction->GetResultType()) { |
| 3494 | case Primitive::kPrimInt: { |
| 3495 | if (instruction->IsRem()) { |
| 3496 | __ xorl(output_register, output_register); |
| 3497 | } else { |
| 3498 | __ movl(output_register, input_register); |
| 3499 | if (imm == -1) { |
| 3500 | __ negl(output_register); |
| 3501 | } |
| 3502 | } |
| 3503 | break; |
| 3504 | } |
| 3505 | |
| 3506 | case Primitive::kPrimLong: { |
| 3507 | if (instruction->IsRem()) { |
| Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 3508 | __ xorl(output_register, output_register); |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3509 | } else { |
| 3510 | __ movq(output_register, input_register); |
| 3511 | if (imm == -1) { |
| 3512 | __ negq(output_register); |
| 3513 | } |
| 3514 | } |
| 3515 | break; |
| 3516 | } |
| 3517 | |
| 3518 | default: |
| Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3519 | LOG(FATAL) << "Unexpected type for div by (-)1 " << instruction->GetResultType(); |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3520 | } |
| 3521 | } |
| 3522 | |
| Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3523 | void InstructionCodeGeneratorX86_64::DivByPowerOfTwo(HDiv* instruction) { |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3524 | LocationSummary* locations = instruction->GetLocations(); |
| 3525 | Location second = locations->InAt(1); |
| 3526 | |
| 3527 | CpuRegister output_register = locations->Out().AsRegister<CpuRegister>(); |
| 3528 | CpuRegister numerator = locations->InAt(0).AsRegister<CpuRegister>(); |
| 3529 | |
| Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3530 | int64_t imm = Int64FromConstant(second.GetConstant()); |
| Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3531 | DCHECK(IsPowerOfTwo(AbsOrMin(imm))); |
| 3532 | uint64_t abs_imm = AbsOrMin(imm); |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3533 | |
| 3534 | CpuRegister tmp = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 3535 | |
| 3536 | if (instruction->GetResultType() == Primitive::kPrimInt) { |
| Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3537 | __ leal(tmp, Address(numerator, abs_imm - 1)); |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3538 | __ testl(numerator, numerator); |
| 3539 | __ cmov(kGreaterEqual, tmp, numerator); |
| 3540 | int shift = CTZ(imm); |
| 3541 | __ sarl(tmp, Immediate(shift)); |
| 3542 | |
| 3543 | if (imm < 0) { |
| 3544 | __ negl(tmp); |
| 3545 | } |
| 3546 | |
| 3547 | __ movl(output_register, tmp); |
| 3548 | } else { |
| 3549 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong); |
| 3550 | CpuRegister rdx = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 3551 | |
| Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3552 | codegen_->Load64BitValue(rdx, abs_imm - 1); |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3553 | __ addq(rdx, numerator); |
| 3554 | __ testq(numerator, numerator); |
| 3555 | __ cmov(kGreaterEqual, rdx, numerator); |
| 3556 | int shift = CTZ(imm); |
| 3557 | __ sarq(rdx, Immediate(shift)); |
| 3558 | |
| 3559 | if (imm < 0) { |
| 3560 | __ negq(rdx); |
| 3561 | } |
| 3562 | |
| 3563 | __ movq(output_register, rdx); |
| 3564 | } |
| 3565 | } |
| 3566 | |
| 3567 | void InstructionCodeGeneratorX86_64::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) { |
| 3568 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3569 | |
| 3570 | LocationSummary* locations = instruction->GetLocations(); |
| 3571 | Location second = locations->InAt(1); |
| 3572 | |
| 3573 | CpuRegister numerator = instruction->IsDiv() ? locations->GetTemp(1).AsRegister<CpuRegister>() |
| 3574 | : locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 3575 | CpuRegister eax = locations->InAt(0).AsRegister<CpuRegister>(); |
| 3576 | CpuRegister edx = instruction->IsDiv() ? locations->GetTemp(0).AsRegister<CpuRegister>() |
| 3577 | : locations->Out().AsRegister<CpuRegister>(); |
| 3578 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
| 3579 | |
| 3580 | DCHECK_EQ(RAX, eax.AsRegister()); |
| 3581 | DCHECK_EQ(RDX, edx.AsRegister()); |
| 3582 | if (instruction->IsDiv()) { |
| 3583 | DCHECK_EQ(RAX, out.AsRegister()); |
| 3584 | } else { |
| 3585 | DCHECK_EQ(RDX, out.AsRegister()); |
| 3586 | } |
| 3587 | |
| 3588 | int64_t magic; |
| 3589 | int shift; |
| 3590 | |
| Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3591 | // TODO: can these branches be written as one? |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3592 | if (instruction->GetResultType() == Primitive::kPrimInt) { |
| 3593 | int imm = second.GetConstant()->AsIntConstant()->GetValue(); |
| 3594 | |
| 3595 | CalculateMagicAndShiftForDivRem(imm, false /* is_long */, &magic, &shift); |
| 3596 | |
| 3597 | __ movl(numerator, eax); |
| 3598 | |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3599 | __ movl(eax, Immediate(magic)); |
| 3600 | __ imull(numerator); |
| 3601 | |
| 3602 | if (imm > 0 && magic < 0) { |
| 3603 | __ addl(edx, numerator); |
| 3604 | } else if (imm < 0 && magic > 0) { |
| 3605 | __ subl(edx, numerator); |
| 3606 | } |
| 3607 | |
| 3608 | if (shift != 0) { |
| 3609 | __ sarl(edx, Immediate(shift)); |
| 3610 | } |
| 3611 | |
| 3612 | __ movl(eax, edx); |
| 3613 | __ shrl(edx, Immediate(31)); |
| 3614 | __ addl(edx, eax); |
| 3615 | |
| 3616 | if (instruction->IsRem()) { |
| 3617 | __ movl(eax, numerator); |
| 3618 | __ imull(edx, Immediate(imm)); |
| 3619 | __ subl(eax, edx); |
| 3620 | __ movl(edx, eax); |
| 3621 | } else { |
| 3622 | __ movl(eax, edx); |
| 3623 | } |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3624 | } else { |
| 3625 | int64_t imm = second.GetConstant()->AsLongConstant()->GetValue(); |
| 3626 | |
| 3627 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong); |
| 3628 | |
| 3629 | CpuRegister rax = eax; |
| 3630 | CpuRegister rdx = edx; |
| 3631 | |
| 3632 | CalculateMagicAndShiftForDivRem(imm, true /* is_long */, &magic, &shift); |
| 3633 | |
| 3634 | // Save the numerator. |
| 3635 | __ movq(numerator, rax); |
| 3636 | |
| 3637 | // RAX = magic |
| Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 3638 | codegen_->Load64BitValue(rax, magic); |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3639 | |
| 3640 | // RDX:RAX = magic * numerator |
| 3641 | __ imulq(numerator); |
| 3642 | |
| 3643 | if (imm > 0 && magic < 0) { |
| Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3644 | // RDX += numerator |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3645 | __ addq(rdx, numerator); |
| 3646 | } else if (imm < 0 && magic > 0) { |
| 3647 | // RDX -= numerator |
| 3648 | __ subq(rdx, numerator); |
| 3649 | } |
| 3650 | |
| 3651 | // Shift if needed. |
| 3652 | if (shift != 0) { |
| 3653 | __ sarq(rdx, Immediate(shift)); |
| 3654 | } |
| 3655 | |
| 3656 | // RDX += 1 if RDX < 0 |
| 3657 | __ movq(rax, rdx); |
| 3658 | __ shrq(rdx, Immediate(63)); |
| 3659 | __ addq(rdx, rax); |
| 3660 | |
| 3661 | if (instruction->IsRem()) { |
| 3662 | __ movq(rax, numerator); |
| 3663 | |
| 3664 | if (IsInt<32>(imm)) { |
| 3665 | __ imulq(rdx, Immediate(static_cast<int32_t>(imm))); |
| 3666 | } else { |
| Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 3667 | __ imulq(rdx, codegen_->LiteralInt64Address(imm)); |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3668 | } |
| 3669 | |
| 3670 | __ subq(rax, rdx); |
| 3671 | __ movq(rdx, rax); |
| 3672 | } else { |
| 3673 | __ movq(rax, rdx); |
| 3674 | } |
| 3675 | } |
| 3676 | } |
| 3677 | |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3678 | void InstructionCodeGeneratorX86_64::GenerateDivRemIntegral(HBinaryOperation* instruction) { |
| 3679 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3680 | Primitive::Type type = instruction->GetResultType(); |
| Calin Juravle | c70d1d9 | 2017-03-27 18:10:04 -0700 | [diff] [blame] | 3681 | DCHECK(type == Primitive::kPrimInt || type == Primitive::kPrimLong); |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3682 | |
| 3683 | bool is_div = instruction->IsDiv(); |
| 3684 | LocationSummary* locations = instruction->GetLocations(); |
| 3685 | |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3686 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
| 3687 | Location second = locations->InAt(1); |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3688 | |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3689 | DCHECK_EQ(RAX, locations->InAt(0).AsRegister<CpuRegister>().AsRegister()); |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3690 | DCHECK_EQ(is_div ? RAX : RDX, out.AsRegister()); |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3691 | |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3692 | if (second.IsConstant()) { |
| Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3693 | int64_t imm = Int64FromConstant(second.GetConstant()); |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3694 | |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3695 | if (imm == 0) { |
| 3696 | // Do not generate anything. DivZeroCheck would prevent any code to be executed. |
| 3697 | } else if (imm == 1 || imm == -1) { |
| 3698 | DivRemOneOrMinusOne(instruction); |
| Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3699 | } else if (instruction->IsDiv() && IsPowerOfTwo(AbsOrMin(imm))) { |
| Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3700 | DivByPowerOfTwo(instruction->AsDiv()); |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3701 | } else { |
| 3702 | DCHECK(imm <= -2 || imm >= 2); |
| 3703 | GenerateDivRemWithAnyConstant(instruction); |
| 3704 | } |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3705 | } else { |
| Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 3706 | SlowPathCode* slow_path = |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3707 | new (GetGraph()->GetArena()) DivRemMinusOneSlowPathX86_64( |
| David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 3708 | instruction, out.AsRegister(), type, is_div); |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3709 | codegen_->AddSlowPath(slow_path); |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3710 | |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3711 | CpuRegister second_reg = second.AsRegister<CpuRegister>(); |
| 3712 | // 0x80000000(00000000)/-1 triggers an arithmetic exception! |
| 3713 | // Dividing by -1 is actually negation and -0x800000000(00000000) = 0x80000000(00000000) |
| 3714 | // so it's safe to just use negl instead of more complex comparisons. |
| 3715 | if (type == Primitive::kPrimInt) { |
| 3716 | __ cmpl(second_reg, Immediate(-1)); |
| 3717 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3718 | // edx:eax <- sign-extended of eax |
| 3719 | __ cdq(); |
| 3720 | // eax = quotient, edx = remainder |
| 3721 | __ idivl(second_reg); |
| 3722 | } else { |
| 3723 | __ cmpq(second_reg, Immediate(-1)); |
| 3724 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3725 | // rdx:rax <- sign-extended of rax |
| 3726 | __ cqo(); |
| 3727 | // rax = quotient, rdx = remainder |
| 3728 | __ idivq(second_reg); |
| 3729 | } |
| 3730 | __ Bind(slow_path->GetExitLabel()); |
| 3731 | } |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3732 | } |
| 3733 | |
| Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3734 | void LocationsBuilderX86_64::VisitDiv(HDiv* div) { |
| 3735 | LocationSummary* locations = |
| 3736 | new (GetGraph()->GetArena()) LocationSummary(div, LocationSummary::kNoCall); |
| 3737 | switch (div->GetResultType()) { |
| Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3738 | case Primitive::kPrimInt: |
| 3739 | case Primitive::kPrimLong: { |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3740 | locations->SetInAt(0, Location::RegisterLocation(RAX)); |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3741 | locations->SetInAt(1, Location::RegisterOrConstant(div->InputAt(1))); |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3742 | locations->SetOut(Location::SameAsFirstInput()); |
| 3743 | // Intel uses edx:eax as the dividend. |
| 3744 | locations->AddTemp(Location::RegisterLocation(RDX)); |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3745 | // We need to save the numerator while we tweak rax and rdx. As we are using imul in a way |
| 3746 | // which enforces results to be in RAX and RDX, things are simpler if we use RDX also as |
| 3747 | // output and request another temp. |
| 3748 | if (div->InputAt(1)->IsConstant()) { |
| 3749 | locations->AddTemp(Location::RequiresRegister()); |
| 3750 | } |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3751 | break; |
| 3752 | } |
| Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3753 | |
| Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3754 | case Primitive::kPrimFloat: |
| 3755 | case Primitive::kPrimDouble: { |
| 3756 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3757 | locations->SetInAt(1, Location::Any()); |
| Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3758 | locations->SetOut(Location::SameAsFirstInput()); |
| 3759 | break; |
| 3760 | } |
| 3761 | |
| 3762 | default: |
| 3763 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 3764 | } |
| 3765 | } |
| 3766 | |
| 3767 | void InstructionCodeGeneratorX86_64::VisitDiv(HDiv* div) { |
| 3768 | LocationSummary* locations = div->GetLocations(); |
| 3769 | Location first = locations->InAt(0); |
| 3770 | Location second = locations->InAt(1); |
| 3771 | DCHECK(first.Equals(locations->Out())); |
| 3772 | |
| Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3773 | Primitive::Type type = div->GetResultType(); |
| 3774 | switch (type) { |
| 3775 | case Primitive::kPrimInt: |
| 3776 | case Primitive::kPrimLong: { |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3777 | GenerateDivRemIntegral(div); |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3778 | break; |
| 3779 | } |
| 3780 | |
| Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3781 | case Primitive::kPrimFloat: { |
| Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3782 | if (second.IsFpuRegister()) { |
| 3783 | __ divss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3784 | } else if (second.IsConstant()) { |
| 3785 | __ divss(first.AsFpuRegister<XmmRegister>(), |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 3786 | codegen_->LiteralFloatAddress( |
| 3787 | second.GetConstant()->AsFloatConstant()->GetValue())); |
| Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3788 | } else { |
| 3789 | DCHECK(second.IsStackSlot()); |
| 3790 | __ divss(first.AsFpuRegister<XmmRegister>(), |
| 3791 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 3792 | } |
| Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3793 | break; |
| 3794 | } |
| 3795 | |
| 3796 | case Primitive::kPrimDouble: { |
| Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3797 | if (second.IsFpuRegister()) { |
| 3798 | __ divsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3799 | } else if (second.IsConstant()) { |
| 3800 | __ divsd(first.AsFpuRegister<XmmRegister>(), |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 3801 | codegen_->LiteralDoubleAddress( |
| 3802 | second.GetConstant()->AsDoubleConstant()->GetValue())); |
| Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3803 | } else { |
| 3804 | DCHECK(second.IsDoubleStackSlot()); |
| 3805 | __ divsd(first.AsFpuRegister<XmmRegister>(), |
| 3806 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 3807 | } |
| Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3808 | break; |
| 3809 | } |
| 3810 | |
| 3811 | default: |
| 3812 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 3813 | } |
| 3814 | } |
| 3815 | |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3816 | void LocationsBuilderX86_64::VisitRem(HRem* rem) { |
| Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3817 | Primitive::Type type = rem->GetResultType(); |
| Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3818 | LocationSummary* locations = |
| 3819 | new (GetGraph()->GetArena()) LocationSummary(rem, LocationSummary::kNoCall); |
| Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3820 | |
| 3821 | switch (type) { |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3822 | case Primitive::kPrimInt: |
| 3823 | case Primitive::kPrimLong: { |
| 3824 | locations->SetInAt(0, Location::RegisterLocation(RAX)); |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3825 | locations->SetInAt(1, Location::RegisterOrConstant(rem->InputAt(1))); |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3826 | // Intel uses rdx:rax as the dividend and puts the remainder in rdx |
| 3827 | locations->SetOut(Location::RegisterLocation(RDX)); |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3828 | // We need to save the numerator while we tweak eax and edx. As we are using imul in a way |
| 3829 | // which enforces results to be in RAX and RDX, things are simpler if we use EAX also as |
| 3830 | // output and request another temp. |
| 3831 | if (rem->InputAt(1)->IsConstant()) { |
| 3832 | locations->AddTemp(Location::RequiresRegister()); |
| 3833 | } |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3834 | break; |
| 3835 | } |
| 3836 | |
| 3837 | case Primitive::kPrimFloat: |
| 3838 | case Primitive::kPrimDouble: { |
| Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3839 | locations->SetInAt(0, Location::Any()); |
| 3840 | locations->SetInAt(1, Location::Any()); |
| 3841 | locations->SetOut(Location::RequiresFpuRegister()); |
| 3842 | locations->AddTemp(Location::RegisterLocation(RAX)); |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3843 | break; |
| 3844 | } |
| 3845 | |
| 3846 | default: |
| Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3847 | LOG(FATAL) << "Unexpected rem type " << type; |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3848 | } |
| 3849 | } |
| 3850 | |
| 3851 | void InstructionCodeGeneratorX86_64::VisitRem(HRem* rem) { |
| 3852 | Primitive::Type type = rem->GetResultType(); |
| 3853 | switch (type) { |
| 3854 | case Primitive::kPrimInt: |
| 3855 | case Primitive::kPrimLong: { |
| 3856 | GenerateDivRemIntegral(rem); |
| 3857 | break; |
| 3858 | } |
| Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3859 | case Primitive::kPrimFloat: |
| Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3860 | case Primitive::kPrimDouble: { |
| Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3861 | GenerateRemFP(rem); |
| Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3862 | break; |
| 3863 | } |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3864 | default: |
| 3865 | LOG(FATAL) << "Unexpected rem type " << rem->GetResultType(); |
| 3866 | } |
| 3867 | } |
| 3868 | |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3869 | void LocationsBuilderX86_64::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
| Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 3870 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3871 | locations->SetInAt(0, Location::Any()); |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3872 | } |
| 3873 | |
| 3874 | void InstructionCodeGeneratorX86_64::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
| Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 3875 | SlowPathCode* slow_path = |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3876 | new (GetGraph()->GetArena()) DivZeroCheckSlowPathX86_64(instruction); |
| 3877 | codegen_->AddSlowPath(slow_path); |
| 3878 | |
| 3879 | LocationSummary* locations = instruction->GetLocations(); |
| 3880 | Location value = locations->InAt(0); |
| 3881 | |
| Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3882 | switch (instruction->GetType()) { |
| Nicolas Geoffray | e567161 | 2016-03-16 11:03:54 +0000 | [diff] [blame] | 3883 | case Primitive::kPrimBoolean: |
| Serguei Katkov | 8c0676c | 2015-08-03 13:55:33 +0600 | [diff] [blame] | 3884 | case Primitive::kPrimByte: |
| 3885 | case Primitive::kPrimChar: |
| 3886 | case Primitive::kPrimShort: |
| Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3887 | case Primitive::kPrimInt: { |
| 3888 | if (value.IsRegister()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3889 | __ testl(value.AsRegister<CpuRegister>(), value.AsRegister<CpuRegister>()); |
| Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3890 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3891 | } else if (value.IsStackSlot()) { |
| 3892 | __ cmpl(Address(CpuRegister(RSP), value.GetStackIndex()), Immediate(0)); |
| 3893 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3894 | } else { |
| 3895 | DCHECK(value.IsConstant()) << value; |
| 3896 | if (value.GetConstant()->AsIntConstant()->GetValue() == 0) { |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 3897 | __ jmp(slow_path->GetEntryLabel()); |
| Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3898 | } |
| 3899 | } |
| 3900 | break; |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3901 | } |
| Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3902 | case Primitive::kPrimLong: { |
| 3903 | if (value.IsRegister()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3904 | __ testq(value.AsRegister<CpuRegister>(), value.AsRegister<CpuRegister>()); |
| Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3905 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3906 | } else if (value.IsDoubleStackSlot()) { |
| 3907 | __ cmpq(Address(CpuRegister(RSP), value.GetStackIndex()), Immediate(0)); |
| 3908 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3909 | } else { |
| 3910 | DCHECK(value.IsConstant()) << value; |
| 3911 | if (value.GetConstant()->AsLongConstant()->GetValue() == 0) { |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 3912 | __ jmp(slow_path->GetEntryLabel()); |
| Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3913 | } |
| 3914 | } |
| 3915 | break; |
| 3916 | } |
| 3917 | default: |
| 3918 | LOG(FATAL) << "Unexpected type for HDivZeroCheck " << instruction->GetType(); |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3919 | } |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3920 | } |
| 3921 | |
| Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3922 | void LocationsBuilderX86_64::HandleShift(HBinaryOperation* op) { |
| 3923 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 3924 | |
| 3925 | LocationSummary* locations = |
| 3926 | new (GetGraph()->GetArena()) LocationSummary(op, LocationSummary::kNoCall); |
| 3927 | |
| 3928 | switch (op->GetResultType()) { |
| 3929 | case Primitive::kPrimInt: |
| 3930 | case Primitive::kPrimLong: { |
| 3931 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3932 | // The shift count needs to be in CL. |
| 3933 | locations->SetInAt(1, Location::ByteRegisterOrConstant(RCX, op->InputAt(1))); |
| 3934 | locations->SetOut(Location::SameAsFirstInput()); |
| 3935 | break; |
| 3936 | } |
| 3937 | default: |
| 3938 | LOG(FATAL) << "Unexpected operation type " << op->GetResultType(); |
| 3939 | } |
| 3940 | } |
| 3941 | |
| 3942 | void InstructionCodeGeneratorX86_64::HandleShift(HBinaryOperation* op) { |
| 3943 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 3944 | |
| 3945 | LocationSummary* locations = op->GetLocations(); |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3946 | CpuRegister first_reg = locations->InAt(0).AsRegister<CpuRegister>(); |
| Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3947 | Location second = locations->InAt(1); |
| 3948 | |
| 3949 | switch (op->GetResultType()) { |
| 3950 | case Primitive::kPrimInt: { |
| 3951 | if (second.IsRegister()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3952 | CpuRegister second_reg = second.AsRegister<CpuRegister>(); |
| Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3953 | if (op->IsShl()) { |
| 3954 | __ shll(first_reg, second_reg); |
| 3955 | } else if (op->IsShr()) { |
| 3956 | __ sarl(first_reg, second_reg); |
| 3957 | } else { |
| 3958 | __ shrl(first_reg, second_reg); |
| 3959 | } |
| 3960 | } else { |
| Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 3961 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue() & kMaxIntShiftDistance); |
| Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3962 | if (op->IsShl()) { |
| 3963 | __ shll(first_reg, imm); |
| 3964 | } else if (op->IsShr()) { |
| 3965 | __ sarl(first_reg, imm); |
| 3966 | } else { |
| 3967 | __ shrl(first_reg, imm); |
| 3968 | } |
| 3969 | } |
| 3970 | break; |
| 3971 | } |
| 3972 | case Primitive::kPrimLong: { |
| 3973 | if (second.IsRegister()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3974 | CpuRegister second_reg = second.AsRegister<CpuRegister>(); |
| Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3975 | if (op->IsShl()) { |
| 3976 | __ shlq(first_reg, second_reg); |
| 3977 | } else if (op->IsShr()) { |
| 3978 | __ sarq(first_reg, second_reg); |
| 3979 | } else { |
| 3980 | __ shrq(first_reg, second_reg); |
| 3981 | } |
| 3982 | } else { |
| Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 3983 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue() & kMaxLongShiftDistance); |
| Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3984 | if (op->IsShl()) { |
| 3985 | __ shlq(first_reg, imm); |
| 3986 | } else if (op->IsShr()) { |
| 3987 | __ sarq(first_reg, imm); |
| 3988 | } else { |
| 3989 | __ shrq(first_reg, imm); |
| 3990 | } |
| 3991 | } |
| 3992 | break; |
| 3993 | } |
| 3994 | default: |
| 3995 | LOG(FATAL) << "Unexpected operation type " << op->GetResultType(); |
| Vladimir Marko | 351dddf | 2015-12-11 16:34:46 +0000 | [diff] [blame] | 3996 | UNREACHABLE(); |
| Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3997 | } |
| 3998 | } |
| 3999 | |
| Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4000 | void LocationsBuilderX86_64::VisitRor(HRor* ror) { |
| 4001 | LocationSummary* locations = |
| 4002 | new (GetGraph()->GetArena()) LocationSummary(ror, LocationSummary::kNoCall); |
| 4003 | |
| 4004 | switch (ror->GetResultType()) { |
| 4005 | case Primitive::kPrimInt: |
| 4006 | case Primitive::kPrimLong: { |
| 4007 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4008 | // The shift count needs to be in CL (unless it is a constant). |
| 4009 | locations->SetInAt(1, Location::ByteRegisterOrConstant(RCX, ror->InputAt(1))); |
| 4010 | locations->SetOut(Location::SameAsFirstInput()); |
| 4011 | break; |
| 4012 | } |
| 4013 | default: |
| 4014 | LOG(FATAL) << "Unexpected operation type " << ror->GetResultType(); |
| 4015 | UNREACHABLE(); |
| 4016 | } |
| 4017 | } |
| 4018 | |
| 4019 | void InstructionCodeGeneratorX86_64::VisitRor(HRor* ror) { |
| 4020 | LocationSummary* locations = ror->GetLocations(); |
| 4021 | CpuRegister first_reg = locations->InAt(0).AsRegister<CpuRegister>(); |
| 4022 | Location second = locations->InAt(1); |
| 4023 | |
| 4024 | switch (ror->GetResultType()) { |
| 4025 | case Primitive::kPrimInt: |
| 4026 | if (second.IsRegister()) { |
| 4027 | CpuRegister second_reg = second.AsRegister<CpuRegister>(); |
| 4028 | __ rorl(first_reg, second_reg); |
| 4029 | } else { |
| Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4030 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue() & kMaxIntShiftDistance); |
| Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4031 | __ rorl(first_reg, imm); |
| 4032 | } |
| 4033 | break; |
| 4034 | case Primitive::kPrimLong: |
| 4035 | if (second.IsRegister()) { |
| 4036 | CpuRegister second_reg = second.AsRegister<CpuRegister>(); |
| 4037 | __ rorq(first_reg, second_reg); |
| 4038 | } else { |
| Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4039 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue() & kMaxLongShiftDistance); |
| Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4040 | __ rorq(first_reg, imm); |
| 4041 | } |
| 4042 | break; |
| 4043 | default: |
| 4044 | LOG(FATAL) << "Unexpected operation type " << ror->GetResultType(); |
| 4045 | UNREACHABLE(); |
| 4046 | } |
| 4047 | } |
| 4048 | |
| Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4049 | void LocationsBuilderX86_64::VisitShl(HShl* shl) { |
| 4050 | HandleShift(shl); |
| 4051 | } |
| 4052 | |
| 4053 | void InstructionCodeGeneratorX86_64::VisitShl(HShl* shl) { |
| 4054 | HandleShift(shl); |
| 4055 | } |
| 4056 | |
| 4057 | void LocationsBuilderX86_64::VisitShr(HShr* shr) { |
| 4058 | HandleShift(shr); |
| 4059 | } |
| 4060 | |
| 4061 | void InstructionCodeGeneratorX86_64::VisitShr(HShr* shr) { |
| 4062 | HandleShift(shr); |
| 4063 | } |
| 4064 | |
| 4065 | void LocationsBuilderX86_64::VisitUShr(HUShr* ushr) { |
| 4066 | HandleShift(ushr); |
| 4067 | } |
| 4068 | |
| 4069 | void InstructionCodeGeneratorX86_64::VisitUShr(HUShr* ushr) { |
| 4070 | HandleShift(ushr); |
| 4071 | } |
| 4072 | |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4073 | void LocationsBuilderX86_64::VisitNewInstance(HNewInstance* instruction) { |
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4074 | LocationSummary* locations = |
| Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 4075 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
| Nicolas Geoffray | 9ae0daa | 2014-09-30 22:40:23 +0100 | [diff] [blame] | 4076 | InvokeRuntimeCallingConvention calling_convention; |
| David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4077 | if (instruction->IsStringAlloc()) { |
| 4078 | locations->AddTemp(Location::RegisterLocation(kMethodRegisterArgument)); |
| 4079 | } else { |
| 4080 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4081 | } |
| Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4082 | locations->SetOut(Location::RegisterLocation(RAX)); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4083 | } |
| 4084 | |
| 4085 | void InstructionCodeGeneratorX86_64::VisitNewInstance(HNewInstance* instruction) { |
| Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4086 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 4087 | // of poisoning the reference. |
| David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4088 | if (instruction->IsStringAlloc()) { |
| 4089 | // String is allocated through StringFactory. Call NewEmptyString entry point. |
| 4090 | CpuRegister temp = instruction->GetLocations()->GetTemp(0).AsRegister<CpuRegister>(); |
| Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 4091 | MemberOffset code_offset = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kX86_64PointerSize); |
| David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4092 | __ gs()->movq(temp, Address::Absolute(QUICK_ENTRY_POINT(pNewEmptyString), /* no_rip */ true)); |
| 4093 | __ call(Address(temp, code_offset.SizeValue())); |
| 4094 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
| 4095 | } else { |
| Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 4096 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), instruction, instruction->GetDexPc()); |
| Nicolas Geoffray | 0d3998b | 2017-01-12 15:35:12 +0000 | [diff] [blame] | 4097 | CheckEntrypointTypes<kQuickAllocObjectWithChecks, void*, mirror::Class*>(); |
| David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4098 | DCHECK(!codegen_->IsLeafMethod()); |
| 4099 | } |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4100 | } |
| 4101 | |
| Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4102 | void LocationsBuilderX86_64::VisitNewArray(HNewArray* instruction) { |
| 4103 | LocationSummary* locations = |
| Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 4104 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
| Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4105 | InvokeRuntimeCallingConvention calling_convention; |
| Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4106 | locations->SetOut(Location::RegisterLocation(RAX)); |
| Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 4107 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 4108 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4109 | } |
| 4110 | |
| 4111 | void InstructionCodeGeneratorX86_64::VisitNewArray(HNewArray* instruction) { |
| Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4112 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 4113 | // of poisoning the reference. |
| Nicolas Geoffray | b048cb7 | 2017-01-23 22:50:24 +0000 | [diff] [blame] | 4114 | QuickEntrypointEnum entrypoint = |
| 4115 | CodeGenerator::GetArrayAllocationEntrypoint(instruction->GetLoadClass()->GetClass()); |
| 4116 | codegen_->InvokeRuntime(entrypoint, instruction, instruction->GetDexPc()); |
| Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 4117 | CheckEntrypointTypes<kQuickAllocArrayResolved, void*, mirror::Class*, int32_t>(); |
| Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4118 | DCHECK(!codegen_->IsLeafMethod()); |
| Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4119 | } |
| 4120 | |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4121 | void LocationsBuilderX86_64::VisitParameterValue(HParameterValue* instruction) { |
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4122 | LocationSummary* locations = |
| 4123 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4124 | Location location = parameter_visitor_.GetNextLocation(instruction->GetType()); |
| 4125 | if (location.IsStackSlot()) { |
| 4126 | location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 4127 | } else if (location.IsDoubleStackSlot()) { |
| 4128 | location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 4129 | } |
| 4130 | locations->SetOut(location); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4131 | } |
| 4132 | |
| Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4133 | void InstructionCodeGeneratorX86_64::VisitParameterValue( |
| 4134 | HParameterValue* instruction ATTRIBUTE_UNUSED) { |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4135 | // Nothing to do, the parameter is already at its location. |
| Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4136 | } |
| 4137 | |
| 4138 | void LocationsBuilderX86_64::VisitCurrentMethod(HCurrentMethod* instruction) { |
| 4139 | LocationSummary* locations = |
| 4140 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 4141 | locations->SetOut(Location::RegisterLocation(kMethodRegisterArgument)); |
| 4142 | } |
| 4143 | |
| 4144 | void InstructionCodeGeneratorX86_64::VisitCurrentMethod( |
| 4145 | HCurrentMethod* instruction ATTRIBUTE_UNUSED) { |
| 4146 | // Nothing to do, the method is already at its location. |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4147 | } |
| 4148 | |
| Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4149 | void LocationsBuilderX86_64::VisitClassTableGet(HClassTableGet* instruction) { |
| 4150 | LocationSummary* locations = |
| 4151 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 4152 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4153 | locations->SetOut(Location::RequiresRegister()); |
| 4154 | } |
| 4155 | |
| 4156 | void InstructionCodeGeneratorX86_64::VisitClassTableGet(HClassTableGet* instruction) { |
| 4157 | LocationSummary* locations = instruction->GetLocations(); |
| Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4158 | if (instruction->GetTableKind() == HClassTableGet::TableKind::kVTable) { |
| Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 4159 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4160 | instruction->GetIndex(), kX86_64PointerSize).SizeValue(); |
| Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 4161 | __ movq(locations->Out().AsRegister<CpuRegister>(), |
| 4162 | Address(locations->InAt(0).AsRegister<CpuRegister>(), method_offset)); |
| Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4163 | } else { |
| Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 4164 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
| Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 4165 | instruction->GetIndex(), kX86_64PointerSize)); |
| Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 4166 | __ movq(locations->Out().AsRegister<CpuRegister>(), |
| 4167 | Address(locations->InAt(0).AsRegister<CpuRegister>(), |
| 4168 | mirror::Class::ImtPtrOffset(kX86_64PointerSize).Uint32Value())); |
| Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 4169 | __ movq(locations->Out().AsRegister<CpuRegister>(), |
| 4170 | Address(locations->Out().AsRegister<CpuRegister>(), method_offset)); |
| Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4171 | } |
| Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4172 | } |
| 4173 | |
| Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4174 | void LocationsBuilderX86_64::VisitNot(HNot* not_) { |
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4175 | LocationSummary* locations = |
| Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4176 | new (GetGraph()->GetArena()) LocationSummary(not_, LocationSummary::kNoCall); |
| Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 4177 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4178 | locations->SetOut(Location::SameAsFirstInput()); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4179 | } |
| 4180 | |
| Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4181 | void InstructionCodeGeneratorX86_64::VisitNot(HNot* not_) { |
| 4182 | LocationSummary* locations = not_->GetLocations(); |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4183 | DCHECK_EQ(locations->InAt(0).AsRegister<CpuRegister>().AsRegister(), |
| 4184 | locations->Out().AsRegister<CpuRegister>().AsRegister()); |
| Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4185 | Location out = locations->Out(); |
| Nicolas Geoffray | d8ef2e9 | 2015-02-24 16:02:06 +0000 | [diff] [blame] | 4186 | switch (not_->GetResultType()) { |
| Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4187 | case Primitive::kPrimInt: |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4188 | __ notl(out.AsRegister<CpuRegister>()); |
| Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4189 | break; |
| 4190 | |
| 4191 | case Primitive::kPrimLong: |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4192 | __ notq(out.AsRegister<CpuRegister>()); |
| Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4193 | break; |
| 4194 | |
| 4195 | default: |
| 4196 | LOG(FATAL) << "Unimplemented type for not operation " << not_->GetResultType(); |
| 4197 | } |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4198 | } |
| 4199 | |
| David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4200 | void LocationsBuilderX86_64::VisitBooleanNot(HBooleanNot* bool_not) { |
| 4201 | LocationSummary* locations = |
| 4202 | new (GetGraph()->GetArena()) LocationSummary(bool_not, LocationSummary::kNoCall); |
| 4203 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4204 | locations->SetOut(Location::SameAsFirstInput()); |
| 4205 | } |
| 4206 | |
| 4207 | void InstructionCodeGeneratorX86_64::VisitBooleanNot(HBooleanNot* bool_not) { |
| David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4208 | LocationSummary* locations = bool_not->GetLocations(); |
| 4209 | DCHECK_EQ(locations->InAt(0).AsRegister<CpuRegister>().AsRegister(), |
| 4210 | locations->Out().AsRegister<CpuRegister>().AsRegister()); |
| 4211 | Location out = locations->Out(); |
| 4212 | __ xorl(out.AsRegister<CpuRegister>(), Immediate(1)); |
| 4213 | } |
| 4214 | |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4215 | void LocationsBuilderX86_64::VisitPhi(HPhi* instruction) { |
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4216 | LocationSummary* locations = |
| 4217 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 4218 | for (size_t i = 0, e = locations->GetInputCount(); i < e; ++i) { |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4219 | locations->SetInAt(i, Location::Any()); |
| 4220 | } |
| 4221 | locations->SetOut(Location::Any()); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4222 | } |
| 4223 | |
| Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4224 | void InstructionCodeGeneratorX86_64::VisitPhi(HPhi* instruction ATTRIBUTE_UNUSED) { |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4225 | LOG(FATAL) << "Unimplemented"; |
| 4226 | } |
| 4227 | |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4228 | void CodeGeneratorX86_64::GenerateMemoryBarrier(MemBarrierKind kind) { |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4229 | /* |
| Roland Levillain | 5e8d5f0 | 2016-10-18 18:03:43 +0100 | [diff] [blame] | 4230 | * According to the JSR-133 Cookbook, for x86-64 only StoreLoad/AnyAny barriers need memory fence. |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4231 | * All other barriers (LoadAny, AnyStore, StoreStore) are nops due to the x86-64 memory model. |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4232 | * For those cases, all we need to ensure is that there is a scheduling barrier in place. |
| 4233 | */ |
| 4234 | switch (kind) { |
| 4235 | case MemBarrierKind::kAnyAny: { |
| Mark P Mendell | 17077d8 | 2015-12-16 19:15:59 +0000 | [diff] [blame] | 4236 | MemoryFence(); |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4237 | break; |
| 4238 | } |
| 4239 | case MemBarrierKind::kAnyStore: |
| 4240 | case MemBarrierKind::kLoadAny: |
| 4241 | case MemBarrierKind::kStoreStore: { |
| 4242 | // nop |
| 4243 | break; |
| 4244 | } |
| Mark Mendell | 7aa04a1 | 2016-01-27 22:39:07 -0500 | [diff] [blame] | 4245 | case MemBarrierKind::kNTStoreStore: |
| 4246 | // Non-Temporal Store/Store needs an explicit fence. |
| 4247 | MemoryFence(/* non-temporal */ true); |
| 4248 | break; |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4249 | } |
| 4250 | } |
| 4251 | |
| 4252 | void LocationsBuilderX86_64::HandleFieldGet(HInstruction* instruction) { |
| 4253 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
| 4254 | |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4255 | bool object_field_get_with_read_barrier = |
| 4256 | kEmitCompilerReadBarrier && (instruction->GetType() == Primitive::kPrimNot); |
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4257 | LocationSummary* locations = |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4258 | new (GetGraph()->GetArena()) LocationSummary(instruction, |
| 4259 | object_field_get_with_read_barrier ? |
| 4260 | LocationSummary::kCallOnSlowPath : |
| 4261 | LocationSummary::kNoCall); |
| Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 4262 | if (object_field_get_with_read_barrier && kUseBakerReadBarrier) { |
| Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 4263 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
| Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 4264 | } |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4265 | locations->SetInAt(0, Location::RequiresRegister()); |
| Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4266 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 4267 | locations->SetOut(Location::RequiresFpuRegister()); |
| 4268 | } else { |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4269 | // The output overlaps for an object field get when read barriers |
| 4270 | // are enabled: we do not want the move to overwrite the object's |
| 4271 | // location, as we need it to emit the read barrier. |
| 4272 | locations->SetOut( |
| 4273 | Location::RequiresRegister(), |
| 4274 | object_field_get_with_read_barrier ? Location::kOutputOverlap : Location::kNoOutputOverlap); |
| Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4275 | } |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4276 | } |
| 4277 | |
| 4278 | void InstructionCodeGeneratorX86_64::HandleFieldGet(HInstruction* instruction, |
| 4279 | const FieldInfo& field_info) { |
| 4280 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
| 4281 | |
| 4282 | LocationSummary* locations = instruction->GetLocations(); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4283 | Location base_loc = locations->InAt(0); |
| 4284 | CpuRegister base = base_loc.AsRegister<CpuRegister>(); |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4285 | Location out = locations->Out(); |
| 4286 | bool is_volatile = field_info.IsVolatile(); |
| 4287 | Primitive::Type field_type = field_info.GetFieldType(); |
| 4288 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
| 4289 | |
| 4290 | switch (field_type) { |
| 4291 | case Primitive::kPrimBoolean: { |
| 4292 | __ movzxb(out.AsRegister<CpuRegister>(), Address(base, offset)); |
| 4293 | break; |
| 4294 | } |
| 4295 | |
| 4296 | case Primitive::kPrimByte: { |
| 4297 | __ movsxb(out.AsRegister<CpuRegister>(), Address(base, offset)); |
| 4298 | break; |
| 4299 | } |
| 4300 | |
| 4301 | case Primitive::kPrimShort: { |
| 4302 | __ movsxw(out.AsRegister<CpuRegister>(), Address(base, offset)); |
| 4303 | break; |
| 4304 | } |
| 4305 | |
| 4306 | case Primitive::kPrimChar: { |
| 4307 | __ movzxw(out.AsRegister<CpuRegister>(), Address(base, offset)); |
| 4308 | break; |
| 4309 | } |
| 4310 | |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4311 | case Primitive::kPrimInt: { |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4312 | __ movl(out.AsRegister<CpuRegister>(), Address(base, offset)); |
| 4313 | break; |
| 4314 | } |
| 4315 | |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4316 | case Primitive::kPrimNot: { |
| 4317 | // /* HeapReference<Object> */ out = *(base + offset) |
| 4318 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4319 | // Note that a potential implicit null check is handled in this |
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 4320 | // CodeGeneratorX86_64::GenerateFieldLoadWithBakerReadBarrier call. |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4321 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
| Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 4322 | instruction, out, base, offset, /* needs_null_check */ true); |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4323 | if (is_volatile) { |
| 4324 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4325 | } |
| 4326 | } else { |
| 4327 | __ movl(out.AsRegister<CpuRegister>(), Address(base, offset)); |
| 4328 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4329 | if (is_volatile) { |
| 4330 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4331 | } |
| 4332 | // If read barriers are enabled, emit read barriers other than |
| 4333 | // Baker's using a slow path (and also unpoison the loaded |
| 4334 | // reference, if heap poisoning is enabled). |
| 4335 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out, out, base_loc, offset); |
| 4336 | } |
| 4337 | break; |
| 4338 | } |
| 4339 | |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4340 | case Primitive::kPrimLong: { |
| 4341 | __ movq(out.AsRegister<CpuRegister>(), Address(base, offset)); |
| 4342 | break; |
| 4343 | } |
| 4344 | |
| 4345 | case Primitive::kPrimFloat: { |
| 4346 | __ movss(out.AsFpuRegister<XmmRegister>(), Address(base, offset)); |
| 4347 | break; |
| 4348 | } |
| 4349 | |
| 4350 | case Primitive::kPrimDouble: { |
| 4351 | __ movsd(out.AsFpuRegister<XmmRegister>(), Address(base, offset)); |
| 4352 | break; |
| 4353 | } |
| 4354 | |
| 4355 | case Primitive::kPrimVoid: |
| 4356 | LOG(FATAL) << "Unreachable type " << field_type; |
| 4357 | UNREACHABLE(); |
| 4358 | } |
| 4359 | |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4360 | if (field_type == Primitive::kPrimNot) { |
| 4361 | // Potential implicit null checks, in the case of reference |
| 4362 | // fields, are handled in the previous switch statement. |
| 4363 | } else { |
| 4364 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4365 | } |
| Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4366 | |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4367 | if (is_volatile) { |
| 4368 | if (field_type == Primitive::kPrimNot) { |
| 4369 | // Memory barriers, in the case of references, are also handled |
| 4370 | // in the previous switch statement. |
| 4371 | } else { |
| 4372 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4373 | } |
| Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4374 | } |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4375 | } |
| 4376 | |
| 4377 | void LocationsBuilderX86_64::HandleFieldSet(HInstruction* instruction, |
| 4378 | const FieldInfo& field_info) { |
| 4379 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 4380 | |
| 4381 | LocationSummary* locations = |
| 4382 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4383 | Primitive::Type field_type = field_info.GetFieldType(); |
| Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4384 | bool is_volatile = field_info.IsVolatile(); |
| Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4385 | bool needs_write_barrier = |
| Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4386 | CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1)); |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4387 | |
| Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 4388 | locations->SetInAt(0, Location::RequiresRegister()); |
| Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4389 | if (Primitive::IsFloatingPointType(instruction->InputAt(1)->GetType())) { |
| Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4390 | if (is_volatile) { |
| 4391 | // In order to satisfy the semantics of volatile, this must be a single instruction store. |
| 4392 | locations->SetInAt(1, Location::FpuRegisterOrInt32Constant(instruction->InputAt(1))); |
| 4393 | } else { |
| 4394 | locations->SetInAt(1, Location::FpuRegisterOrConstant(instruction->InputAt(1))); |
| 4395 | } |
| Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4396 | } else { |
| Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4397 | if (is_volatile) { |
| 4398 | // In order to satisfy the semantics of volatile, this must be a single instruction store. |
| 4399 | locations->SetInAt(1, Location::RegisterOrInt32Constant(instruction->InputAt(1))); |
| 4400 | } else { |
| 4401 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 4402 | } |
| Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4403 | } |
| Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4404 | if (needs_write_barrier) { |
| Nicolas Geoffray | 9ae0daa | 2014-09-30 22:40:23 +0100 | [diff] [blame] | 4405 | // Temporary registers for the write barrier. |
| Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4406 | locations->AddTemp(Location::RequiresRegister()); // Possibly used for reference poisoning too. |
| Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 4407 | locations->AddTemp(Location::RequiresRegister()); |
| Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4408 | } else if (kPoisonHeapReferences && field_type == Primitive::kPrimNot) { |
| 4409 | // Temporary register for the reference poisoning. |
| Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 4410 | locations->AddTemp(Location::RequiresRegister()); |
| 4411 | } |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4412 | } |
| 4413 | |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4414 | void InstructionCodeGeneratorX86_64::HandleFieldSet(HInstruction* instruction, |
| Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4415 | const FieldInfo& field_info, |
| 4416 | bool value_can_be_null) { |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4417 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 4418 | |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4419 | LocationSummary* locations = instruction->GetLocations(); |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4420 | CpuRegister base = locations->InAt(0).AsRegister<CpuRegister>(); |
| 4421 | Location value = locations->InAt(1); |
| 4422 | bool is_volatile = field_info.IsVolatile(); |
| 4423 | Primitive::Type field_type = field_info.GetFieldType(); |
| 4424 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
| 4425 | |
| 4426 | if (is_volatile) { |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4427 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyStore); |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4428 | } |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4429 | |
| Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4430 | bool maybe_record_implicit_null_check_done = false; |
| 4431 | |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4432 | switch (field_type) { |
| 4433 | case Primitive::kPrimBoolean: |
| 4434 | case Primitive::kPrimByte: { |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4435 | if (value.IsConstant()) { |
| Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4436 | int8_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4437 | __ movb(Address(base, offset), Immediate(v)); |
| 4438 | } else { |
| 4439 | __ movb(Address(base, offset), value.AsRegister<CpuRegister>()); |
| 4440 | } |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4441 | break; |
| 4442 | } |
| 4443 | |
| 4444 | case Primitive::kPrimShort: |
| 4445 | case Primitive::kPrimChar: { |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4446 | if (value.IsConstant()) { |
| Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4447 | int16_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4448 | __ movw(Address(base, offset), Immediate(v)); |
| 4449 | } else { |
| 4450 | __ movw(Address(base, offset), value.AsRegister<CpuRegister>()); |
| 4451 | } |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4452 | break; |
| 4453 | } |
| 4454 | |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4455 | case Primitive::kPrimInt: |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4456 | case Primitive::kPrimNot: { |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4457 | if (value.IsConstant()) { |
| 4458 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
| Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4459 | // `field_type == Primitive::kPrimNot` implies `v == 0`. |
| 4460 | DCHECK((field_type != Primitive::kPrimNot) || (v == 0)); |
| 4461 | // Note: if heap poisoning is enabled, no need to poison |
| 4462 | // (negate) `v` if it is a reference, as it would be null. |
| Roland Levillain | 06b66d0 | 2015-07-01 12:47:25 +0100 | [diff] [blame] | 4463 | __ movl(Address(base, offset), Immediate(v)); |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4464 | } else { |
| Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4465 | if (kPoisonHeapReferences && field_type == Primitive::kPrimNot) { |
| 4466 | CpuRegister temp = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 4467 | __ movl(temp, value.AsRegister<CpuRegister>()); |
| 4468 | __ PoisonHeapReference(temp); |
| 4469 | __ movl(Address(base, offset), temp); |
| 4470 | } else { |
| 4471 | __ movl(Address(base, offset), value.AsRegister<CpuRegister>()); |
| 4472 | } |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4473 | } |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4474 | break; |
| 4475 | } |
| 4476 | |
| 4477 | case Primitive::kPrimLong: { |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4478 | if (value.IsConstant()) { |
| 4479 | int64_t v = value.GetConstant()->AsLongConstant()->GetValue(); |
| Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4480 | codegen_->MoveInt64ToAddress(Address(base, offset), |
| 4481 | Address(base, offset + sizeof(int32_t)), |
| 4482 | v, |
| 4483 | instruction); |
| 4484 | maybe_record_implicit_null_check_done = true; |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4485 | } else { |
| 4486 | __ movq(Address(base, offset), value.AsRegister<CpuRegister>()); |
| 4487 | } |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4488 | break; |
| 4489 | } |
| 4490 | |
| Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4491 | case Primitive::kPrimFloat: { |
| Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4492 | if (value.IsConstant()) { |
| 4493 | int32_t v = |
| 4494 | bit_cast<int32_t, float>(value.GetConstant()->AsFloatConstant()->GetValue()); |
| 4495 | __ movl(Address(base, offset), Immediate(v)); |
| 4496 | } else { |
| 4497 | __ movss(Address(base, offset), value.AsFpuRegister<XmmRegister>()); |
| 4498 | } |
| Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4499 | break; |
| 4500 | } |
| 4501 | |
| 4502 | case Primitive::kPrimDouble: { |
| Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4503 | if (value.IsConstant()) { |
| 4504 | int64_t v = |
| 4505 | bit_cast<int64_t, double>(value.GetConstant()->AsDoubleConstant()->GetValue()); |
| 4506 | codegen_->MoveInt64ToAddress(Address(base, offset), |
| 4507 | Address(base, offset + sizeof(int32_t)), |
| 4508 | v, |
| 4509 | instruction); |
| 4510 | maybe_record_implicit_null_check_done = true; |
| 4511 | } else { |
| 4512 | __ movsd(Address(base, offset), value.AsFpuRegister<XmmRegister>()); |
| 4513 | } |
| Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4514 | break; |
| 4515 | } |
| 4516 | |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4517 | case Primitive::kPrimVoid: |
| 4518 | LOG(FATAL) << "Unreachable type " << field_type; |
| Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 4519 | UNREACHABLE(); |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4520 | } |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4521 | |
| Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4522 | if (!maybe_record_implicit_null_check_done) { |
| 4523 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4524 | } |
| Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4525 | |
| 4526 | if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) { |
| 4527 | CpuRegister temp = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 4528 | CpuRegister card = locations->GetTemp(1).AsRegister<CpuRegister>(); |
| Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4529 | codegen_->MarkGCCard(temp, card, base, value.AsRegister<CpuRegister>(), value_can_be_null); |
| Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4530 | } |
| 4531 | |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4532 | if (is_volatile) { |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4533 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyAny); |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4534 | } |
| 4535 | } |
| 4536 | |
| 4537 | void LocationsBuilderX86_64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
| 4538 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 4539 | } |
| 4540 | |
| 4541 | void InstructionCodeGeneratorX86_64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
| Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4542 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4543 | } |
| 4544 | |
| 4545 | void LocationsBuilderX86_64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4546 | HandleFieldGet(instruction); |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4547 | } |
| 4548 | |
| 4549 | void InstructionCodeGeneratorX86_64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4550 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 4551 | } |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4552 | |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4553 | void LocationsBuilderX86_64::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 4554 | HandleFieldGet(instruction); |
| 4555 | } |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4556 | |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4557 | void InstructionCodeGeneratorX86_64::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 4558 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 4559 | } |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4560 | |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4561 | void LocationsBuilderX86_64::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
| 4562 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 4563 | } |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4564 | |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4565 | void InstructionCodeGeneratorX86_64::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
| Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4566 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4567 | } |
| 4568 | |
| Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 4569 | void LocationsBuilderX86_64::VisitUnresolvedInstanceFieldGet( |
| 4570 | HUnresolvedInstanceFieldGet* instruction) { |
| 4571 | FieldAccessCallingConventionX86_64 calling_convention; |
| 4572 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4573 | instruction, instruction->GetFieldType(), calling_convention); |
| 4574 | } |
| 4575 | |
| 4576 | void InstructionCodeGeneratorX86_64::VisitUnresolvedInstanceFieldGet( |
| 4577 | HUnresolvedInstanceFieldGet* instruction) { |
| 4578 | FieldAccessCallingConventionX86_64 calling_convention; |
| 4579 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4580 | instruction->GetFieldType(), |
| 4581 | instruction->GetFieldIndex(), |
| 4582 | instruction->GetDexPc(), |
| 4583 | calling_convention); |
| 4584 | } |
| 4585 | |
| 4586 | void LocationsBuilderX86_64::VisitUnresolvedInstanceFieldSet( |
| 4587 | HUnresolvedInstanceFieldSet* instruction) { |
| 4588 | FieldAccessCallingConventionX86_64 calling_convention; |
| 4589 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4590 | instruction, instruction->GetFieldType(), calling_convention); |
| 4591 | } |
| 4592 | |
| 4593 | void InstructionCodeGeneratorX86_64::VisitUnresolvedInstanceFieldSet( |
| 4594 | HUnresolvedInstanceFieldSet* instruction) { |
| 4595 | FieldAccessCallingConventionX86_64 calling_convention; |
| 4596 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4597 | instruction->GetFieldType(), |
| 4598 | instruction->GetFieldIndex(), |
| 4599 | instruction->GetDexPc(), |
| 4600 | calling_convention); |
| 4601 | } |
| 4602 | |
| 4603 | void LocationsBuilderX86_64::VisitUnresolvedStaticFieldGet( |
| 4604 | HUnresolvedStaticFieldGet* instruction) { |
| 4605 | FieldAccessCallingConventionX86_64 calling_convention; |
| 4606 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4607 | instruction, instruction->GetFieldType(), calling_convention); |
| 4608 | } |
| 4609 | |
| 4610 | void InstructionCodeGeneratorX86_64::VisitUnresolvedStaticFieldGet( |
| 4611 | HUnresolvedStaticFieldGet* instruction) { |
| 4612 | FieldAccessCallingConventionX86_64 calling_convention; |
| 4613 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4614 | instruction->GetFieldType(), |
| 4615 | instruction->GetFieldIndex(), |
| 4616 | instruction->GetDexPc(), |
| 4617 | calling_convention); |
| 4618 | } |
| 4619 | |
| 4620 | void LocationsBuilderX86_64::VisitUnresolvedStaticFieldSet( |
| 4621 | HUnresolvedStaticFieldSet* instruction) { |
| 4622 | FieldAccessCallingConventionX86_64 calling_convention; |
| 4623 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4624 | instruction, instruction->GetFieldType(), calling_convention); |
| 4625 | } |
| 4626 | |
| 4627 | void InstructionCodeGeneratorX86_64::VisitUnresolvedStaticFieldSet( |
| 4628 | HUnresolvedStaticFieldSet* instruction) { |
| 4629 | FieldAccessCallingConventionX86_64 calling_convention; |
| 4630 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4631 | instruction->GetFieldType(), |
| 4632 | instruction->GetFieldIndex(), |
| 4633 | instruction->GetDexPc(), |
| 4634 | calling_convention); |
| 4635 | } |
| 4636 | |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4637 | void LocationsBuilderX86_64::VisitNullCheck(HNullCheck* instruction) { |
| Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 4638 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
| 4639 | Location loc = codegen_->GetCompilerOptions().GetImplicitNullChecks() |
| 4640 | ? Location::RequiresRegister() |
| 4641 | : Location::Any(); |
| 4642 | locations->SetInAt(0, loc); |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4643 | } |
| 4644 | |
| Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 4645 | void CodeGeneratorX86_64::GenerateImplicitNullCheck(HNullCheck* instruction) { |
| 4646 | if (CanMoveNullCheckToUser(instruction)) { |
| Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4647 | return; |
| 4648 | } |
| Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4649 | LocationSummary* locations = instruction->GetLocations(); |
| 4650 | Location obj = locations->InAt(0); |
| 4651 | |
| 4652 | __ testl(CpuRegister(RAX), Address(obj.AsRegister<CpuRegister>(), 0)); |
| Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 4653 | RecordPcInfo(instruction, instruction->GetDexPc()); |
| Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4654 | } |
| 4655 | |
| Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 4656 | void CodeGeneratorX86_64::GenerateExplicitNullCheck(HNullCheck* instruction) { |
| Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 4657 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathX86_64(instruction); |
| Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 4658 | AddSlowPath(slow_path); |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4659 | |
| 4660 | LocationSummary* locations = instruction->GetLocations(); |
| 4661 | Location obj = locations->InAt(0); |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4662 | |
| 4663 | if (obj.IsRegister()) { |
| Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 4664 | __ testl(obj.AsRegister<CpuRegister>(), obj.AsRegister<CpuRegister>()); |
| Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4665 | } else if (obj.IsStackSlot()) { |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4666 | __ cmpl(Address(CpuRegister(RSP), obj.GetStackIndex()), Immediate(0)); |
| Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4667 | } else { |
| 4668 | DCHECK(obj.IsConstant()) << obj; |
| David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 4669 | DCHECK(obj.GetConstant()->IsNullConstant()); |
| Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4670 | __ jmp(slow_path->GetEntryLabel()); |
| 4671 | return; |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4672 | } |
| 4673 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 4674 | } |
| 4675 | |
| Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4676 | void InstructionCodeGeneratorX86_64::VisitNullCheck(HNullCheck* instruction) { |
| Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 4677 | codegen_->GenerateNullCheck(instruction); |
| Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4678 | } |
| 4679 | |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4680 | void LocationsBuilderX86_64::VisitArrayGet(HArrayGet* instruction) { |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4681 | bool object_array_get_with_read_barrier = |
| 4682 | kEmitCompilerReadBarrier && (instruction->GetType() == Primitive::kPrimNot); |
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4683 | LocationSummary* locations = |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4684 | new (GetGraph()->GetArena()) LocationSummary(instruction, |
| 4685 | object_array_get_with_read_barrier ? |
| 4686 | LocationSummary::kCallOnSlowPath : |
| 4687 | LocationSummary::kNoCall); |
| Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 4688 | if (object_array_get_with_read_barrier && kUseBakerReadBarrier) { |
| Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 4689 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
| Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 4690 | } |
| Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 4691 | locations->SetInAt(0, Location::RequiresRegister()); |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4692 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4693 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 4694 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 4695 | } else { |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4696 | // The output overlaps for an object array get when read barriers |
| 4697 | // are enabled: we do not want the move to overwrite the array's |
| 4698 | // location, as we need it to emit the read barrier. |
| 4699 | locations->SetOut( |
| 4700 | Location::RequiresRegister(), |
| 4701 | object_array_get_with_read_barrier ? Location::kOutputOverlap : Location::kNoOutputOverlap); |
| Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4702 | } |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4703 | } |
| 4704 | |
| 4705 | void InstructionCodeGeneratorX86_64::VisitArrayGet(HArrayGet* instruction) { |
| 4706 | LocationSummary* locations = instruction->GetLocations(); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4707 | Location obj_loc = locations->InAt(0); |
| 4708 | CpuRegister obj = obj_loc.AsRegister<CpuRegister>(); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4709 | Location index = locations->InAt(1); |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4710 | Location out_loc = locations->Out(); |
| Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 4711 | uint32_t data_offset = CodeGenerator::GetArrayDataOffset(instruction); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4712 | |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4713 | Primitive::Type type = instruction->GetType(); |
| Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4714 | switch (type) { |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4715 | case Primitive::kPrimBoolean: { |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4716 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 4717 | __ movzxb(out, CodeGeneratorX86_64::ArrayAddress(obj, index, TIMES_1, data_offset)); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4718 | break; |
| 4719 | } |
| 4720 | |
| 4721 | case Primitive::kPrimByte: { |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4722 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 4723 | __ movsxb(out, CodeGeneratorX86_64::ArrayAddress(obj, index, TIMES_1, data_offset)); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4724 | break; |
| 4725 | } |
| 4726 | |
| 4727 | case Primitive::kPrimShort: { |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4728 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 4729 | __ movsxw(out, CodeGeneratorX86_64::ArrayAddress(obj, index, TIMES_2, data_offset)); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4730 | break; |
| 4731 | } |
| 4732 | |
| 4733 | case Primitive::kPrimChar: { |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4734 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
| jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 4735 | if (mirror::kUseStringCompression && instruction->IsStringCharAt()) { |
| 4736 | // Branch cases into compressed and uncompressed for each index's type. |
| 4737 | uint32_t count_offset = mirror::String::CountOffset().Uint32Value(); |
| 4738 | NearLabel done, not_compressed; |
| Vladimir Marko | 3c89d42 | 2017-02-17 11:30:23 +0000 | [diff] [blame] | 4739 | __ testb(Address(obj, count_offset), Immediate(1)); |
| jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 4740 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 4741 | static_assert(static_cast<uint32_t>(mirror::StringCompressionFlag::kCompressed) == 0u, |
| 4742 | "Expecting 0=compressed, 1=uncompressed"); |
| 4743 | __ j(kNotZero, ¬_compressed); |
| jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 4744 | __ movzxb(out, CodeGeneratorX86_64::ArrayAddress(obj, index, TIMES_1, data_offset)); |
| 4745 | __ jmp(&done); |
| 4746 | __ Bind(¬_compressed); |
| 4747 | __ movzxw(out, CodeGeneratorX86_64::ArrayAddress(obj, index, TIMES_2, data_offset)); |
| 4748 | __ Bind(&done); |
| 4749 | } else { |
| 4750 | __ movzxw(out, CodeGeneratorX86_64::ArrayAddress(obj, index, TIMES_2, data_offset)); |
| 4751 | } |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4752 | break; |
| 4753 | } |
| 4754 | |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4755 | case Primitive::kPrimInt: { |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4756 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 4757 | __ movl(out, CodeGeneratorX86_64::ArrayAddress(obj, index, TIMES_4, data_offset)); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4758 | break; |
| 4759 | } |
| 4760 | |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4761 | case Primitive::kPrimNot: { |
| 4762 | static_assert( |
| 4763 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 4764 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4765 | // /* HeapReference<Object> */ out = |
| 4766 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
| 4767 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4768 | // Note that a potential implicit null check is handled in this |
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 4769 | // CodeGeneratorX86_64::GenerateArrayLoadWithBakerReadBarrier call. |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4770 | codegen_->GenerateArrayLoadWithBakerReadBarrier( |
| Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 4771 | instruction, out_loc, obj, data_offset, index, /* needs_null_check */ true); |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4772 | } else { |
| 4773 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 4774 | __ movl(out, CodeGeneratorX86_64::ArrayAddress(obj, index, TIMES_4, data_offset)); |
| 4775 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4776 | // If read barriers are enabled, emit read barriers other than |
| 4777 | // Baker's using a slow path (and also unpoison the loaded |
| 4778 | // reference, if heap poisoning is enabled). |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4779 | if (index.IsConstant()) { |
| 4780 | uint32_t offset = |
| 4781 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4782 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out_loc, out_loc, obj_loc, offset); |
| 4783 | } else { |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4784 | codegen_->MaybeGenerateReadBarrierSlow( |
| 4785 | instruction, out_loc, out_loc, obj_loc, data_offset, index); |
| 4786 | } |
| 4787 | } |
| 4788 | break; |
| 4789 | } |
| 4790 | |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4791 | case Primitive::kPrimLong: { |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4792 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 4793 | __ movq(out, CodeGeneratorX86_64::ArrayAddress(obj, index, TIMES_8, data_offset)); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4794 | break; |
| 4795 | } |
| 4796 | |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4797 | case Primitive::kPrimFloat: { |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4798 | XmmRegister out = out_loc.AsFpuRegister<XmmRegister>(); |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 4799 | __ movss(out, CodeGeneratorX86_64::ArrayAddress(obj, index, TIMES_4, data_offset)); |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4800 | break; |
| 4801 | } |
| 4802 | |
| 4803 | case Primitive::kPrimDouble: { |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4804 | XmmRegister out = out_loc.AsFpuRegister<XmmRegister>(); |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 4805 | __ movsd(out, CodeGeneratorX86_64::ArrayAddress(obj, index, TIMES_8, data_offset)); |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4806 | break; |
| 4807 | } |
| 4808 | |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4809 | case Primitive::kPrimVoid: |
| Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4810 | LOG(FATAL) << "Unreachable type " << type; |
| Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 4811 | UNREACHABLE(); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4812 | } |
| Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4813 | |
| 4814 | if (type == Primitive::kPrimNot) { |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4815 | // Potential implicit null checks, in the case of reference |
| 4816 | // arrays, are handled in the previous switch statement. |
| 4817 | } else { |
| 4818 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4819 | } |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4820 | } |
| 4821 | |
| 4822 | void LocationsBuilderX86_64::VisitArraySet(HArraySet* instruction) { |
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4823 | Primitive::Type value_type = instruction->GetComponentType(); |
| Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4824 | |
| 4825 | bool needs_write_barrier = |
| 4826 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
| Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 4827 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
| Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4828 | |
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4829 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary( |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4830 | instruction, |
| Vladimir Marko | 8d49fd7 | 2016-08-25 15:20:47 +0100 | [diff] [blame] | 4831 | may_need_runtime_call_for_type_check ? |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4832 | LocationSummary::kCallOnSlowPath : |
| 4833 | LocationSummary::kNoCall); |
| Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4834 | |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4835 | locations->SetInAt(0, Location::RequiresRegister()); |
| Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4836 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 4837 | if (Primitive::IsFloatingPointType(value_type)) { |
| 4838 | locations->SetInAt(2, Location::FpuRegisterOrConstant(instruction->InputAt(2))); |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4839 | } else { |
| 4840 | locations->SetInAt(2, Location::RegisterOrConstant(instruction->InputAt(2))); |
| 4841 | } |
| 4842 | |
| 4843 | if (needs_write_barrier) { |
| 4844 | // Temporary registers for the write barrier. |
| Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 4845 | locations->AddTemp(Location::RequiresRegister()); // Possibly used for ref. poisoning too. |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4846 | locations->AddTemp(Location::RequiresRegister()); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4847 | } |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4848 | } |
| 4849 | |
| 4850 | void InstructionCodeGeneratorX86_64::VisitArraySet(HArraySet* instruction) { |
| 4851 | LocationSummary* locations = instruction->GetLocations(); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4852 | Location array_loc = locations->InAt(0); |
| 4853 | CpuRegister array = array_loc.AsRegister<CpuRegister>(); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4854 | Location index = locations->InAt(1); |
| Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4855 | Location value = locations->InAt(2); |
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4856 | Primitive::Type value_type = instruction->GetComponentType(); |
| Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 4857 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
| Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4858 | bool needs_write_barrier = |
| 4859 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4860 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 4861 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 4862 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4863 | |
| 4864 | switch (value_type) { |
| 4865 | case Primitive::kPrimBoolean: |
| 4866 | case Primitive::kPrimByte: { |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4867 | uint32_t offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value(); |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 4868 | Address address = CodeGeneratorX86_64::ArrayAddress(array, index, TIMES_1, offset); |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4869 | if (value.IsRegister()) { |
| 4870 | __ movb(address, value.AsRegister<CpuRegister>()); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4871 | } else { |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4872 | __ movb(address, Immediate(value.GetConstant()->AsIntConstant()->GetValue())); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4873 | } |
| Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4874 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4875 | break; |
| 4876 | } |
| 4877 | |
| 4878 | case Primitive::kPrimShort: |
| 4879 | case Primitive::kPrimChar: { |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4880 | uint32_t offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value(); |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 4881 | Address address = CodeGeneratorX86_64::ArrayAddress(array, index, TIMES_2, offset); |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4882 | if (value.IsRegister()) { |
| 4883 | __ movw(address, value.AsRegister<CpuRegister>()); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4884 | } else { |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4885 | DCHECK(value.IsConstant()) << value; |
| 4886 | __ movw(address, Immediate(value.GetConstant()->AsIntConstant()->GetValue())); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4887 | } |
| Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4888 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4889 | break; |
| 4890 | } |
| 4891 | |
| 4892 | case Primitive::kPrimNot: { |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4893 | uint32_t offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 4894 | Address address = CodeGeneratorX86_64::ArrayAddress(array, index, TIMES_4, offset); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4895 | |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4896 | if (!value.IsRegister()) { |
| 4897 | // Just setting null. |
| 4898 | DCHECK(instruction->InputAt(2)->IsNullConstant()); |
| 4899 | DCHECK(value.IsConstant()) << value; |
| 4900 | __ movl(address, Immediate(0)); |
| Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4901 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4902 | DCHECK(!needs_write_barrier); |
| Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 4903 | DCHECK(!may_need_runtime_call_for_type_check); |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4904 | break; |
| Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4905 | } |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4906 | |
| 4907 | DCHECK(needs_write_barrier); |
| 4908 | CpuRegister register_value = value.AsRegister<CpuRegister>(); |
| Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 4909 | // We cannot use a NearLabel for `done`, as its range may be too |
| 4910 | // short when Baker read barriers are enabled. |
| 4911 | Label done; |
| 4912 | NearLabel not_null, do_put; |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4913 | SlowPathCode* slow_path = nullptr; |
| Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 4914 | Location temp_loc = locations->GetTemp(0); |
| 4915 | CpuRegister temp = temp_loc.AsRegister<CpuRegister>(); |
| Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 4916 | if (may_need_runtime_call_for_type_check) { |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4917 | slow_path = new (GetGraph()->GetArena()) ArraySetSlowPathX86_64(instruction); |
| 4918 | codegen_->AddSlowPath(slow_path); |
| 4919 | if (instruction->GetValueCanBeNull()) { |
| 4920 | __ testl(register_value, register_value); |
| 4921 | __ j(kNotEqual, ¬_null); |
| 4922 | __ movl(address, Immediate(0)); |
| 4923 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4924 | __ jmp(&done); |
| 4925 | __ Bind(¬_null); |
| 4926 | } |
| 4927 | |
| Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 4928 | // Note that when Baker read barriers are enabled, the type |
| 4929 | // checks are performed without read barriers. This is fine, |
| 4930 | // even in the case where a class object is in the from-space |
| 4931 | // after the flip, as a comparison involving such a type would |
| 4932 | // not produce a false positive; it may of course produce a |
| 4933 | // false negative, in which case we would take the ArraySet |
| 4934 | // slow path. |
| Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 4935 | |
| Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 4936 | // /* HeapReference<Class> */ temp = array->klass_ |
| 4937 | __ movl(temp, Address(array, class_offset)); |
| 4938 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4939 | __ MaybeUnpoisonHeapReference(temp); |
| Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 4940 | |
| Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 4941 | // /* HeapReference<Class> */ temp = temp->component_type_ |
| 4942 | __ movl(temp, Address(temp, component_offset)); |
| 4943 | // If heap poisoning is enabled, no need to unpoison `temp` |
| 4944 | // nor the object reference in `register_value->klass`, as |
| 4945 | // we are comparing two poisoned references. |
| 4946 | __ cmpl(temp, Address(register_value, class_offset)); |
| Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 4947 | |
| Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 4948 | if (instruction->StaticTypeOfArrayIsObjectArray()) { |
| 4949 | __ j(kEqual, &do_put); |
| 4950 | // If heap poisoning is enabled, the `temp` reference has |
| 4951 | // not been unpoisoned yet; unpoison it now. |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4952 | __ MaybeUnpoisonHeapReference(temp); |
| 4953 | |
| Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 4954 | // If heap poisoning is enabled, no need to unpoison the |
| 4955 | // heap reference loaded below, as it is only used for a |
| 4956 | // comparison with null. |
| 4957 | __ cmpl(Address(temp, super_offset), Immediate(0)); |
| 4958 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 4959 | __ Bind(&do_put); |
| 4960 | } else { |
| 4961 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4962 | } |
| 4963 | } |
| 4964 | |
| 4965 | if (kPoisonHeapReferences) { |
| 4966 | __ movl(temp, register_value); |
| 4967 | __ PoisonHeapReference(temp); |
| 4968 | __ movl(address, temp); |
| 4969 | } else { |
| 4970 | __ movl(address, register_value); |
| 4971 | } |
| Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 4972 | if (!may_need_runtime_call_for_type_check) { |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4973 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4974 | } |
| 4975 | |
| 4976 | CpuRegister card = locations->GetTemp(1).AsRegister<CpuRegister>(); |
| 4977 | codegen_->MarkGCCard( |
| 4978 | temp, card, array, value.AsRegister<CpuRegister>(), instruction->GetValueCanBeNull()); |
| 4979 | __ Bind(&done); |
| 4980 | |
| 4981 | if (slow_path != nullptr) { |
| 4982 | __ Bind(slow_path->GetExitLabel()); |
| 4983 | } |
| 4984 | |
| 4985 | break; |
| 4986 | } |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4987 | |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4988 | case Primitive::kPrimInt: { |
| 4989 | uint32_t offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 4990 | Address address = CodeGeneratorX86_64::ArrayAddress(array, index, TIMES_4, offset); |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4991 | if (value.IsRegister()) { |
| 4992 | __ movl(address, value.AsRegister<CpuRegister>()); |
| 4993 | } else { |
| 4994 | DCHECK(value.IsConstant()) << value; |
| 4995 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
| 4996 | __ movl(address, Immediate(v)); |
| 4997 | } |
| 4998 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4999 | break; |
| 5000 | } |
| 5001 | |
| 5002 | case Primitive::kPrimLong: { |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5003 | uint32_t offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value(); |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5004 | Address address = CodeGeneratorX86_64::ArrayAddress(array, index, TIMES_8, offset); |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5005 | if (value.IsRegister()) { |
| 5006 | __ movq(address, value.AsRegister<CpuRegister>()); |
| Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 5007 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5008 | } else { |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5009 | int64_t v = value.GetConstant()->AsLongConstant()->GetValue(); |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5010 | Address address_high = |
| 5011 | CodeGeneratorX86_64::ArrayAddress(array, index, TIMES_8, offset + sizeof(int32_t)); |
| Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 5012 | codegen_->MoveInt64ToAddress(address, address_high, v, instruction); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5013 | } |
| 5014 | break; |
| 5015 | } |
| 5016 | |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5017 | case Primitive::kPrimFloat: { |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5018 | uint32_t offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value(); |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5019 | Address address = CodeGeneratorX86_64::ArrayAddress(array, index, TIMES_4, offset); |
| Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 5020 | if (value.IsFpuRegister()) { |
| 5021 | __ movss(address, value.AsFpuRegister<XmmRegister>()); |
| 5022 | } else { |
| 5023 | DCHECK(value.IsConstant()); |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5024 | int32_t v = bit_cast<int32_t, float>(value.GetConstant()->AsFloatConstant()->GetValue()); |
| Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 5025 | __ movl(address, Immediate(v)); |
| 5026 | } |
| Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5027 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5028 | break; |
| 5029 | } |
| 5030 | |
| 5031 | case Primitive::kPrimDouble: { |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5032 | uint32_t offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value(); |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5033 | Address address = CodeGeneratorX86_64::ArrayAddress(array, index, TIMES_8, offset); |
| Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 5034 | if (value.IsFpuRegister()) { |
| 5035 | __ movsd(address, value.AsFpuRegister<XmmRegister>()); |
| 5036 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5037 | } else { |
| 5038 | int64_t v = |
| 5039 | bit_cast<int64_t, double>(value.GetConstant()->AsDoubleConstant()->GetValue()); |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5040 | Address address_high = |
| 5041 | CodeGeneratorX86_64::ArrayAddress(array, index, TIMES_8, offset + sizeof(int32_t)); |
| Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 5042 | codegen_->MoveInt64ToAddress(address, address_high, v, instruction); |
| 5043 | } |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5044 | break; |
| 5045 | } |
| 5046 | |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5047 | case Primitive::kPrimVoid: |
| 5048 | LOG(FATAL) << "Unreachable type " << instruction->GetType(); |
| Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 5049 | UNREACHABLE(); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5050 | } |
| 5051 | } |
| 5052 | |
| 5053 | void LocationsBuilderX86_64::VisitArrayLength(HArrayLength* instruction) { |
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5054 | LocationSummary* locations = |
| 5055 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 5056 | locations->SetInAt(0, Location::RequiresRegister()); |
| Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 5057 | if (!instruction->IsEmittedAtUseSite()) { |
| 5058 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 5059 | } |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5060 | } |
| 5061 | |
| 5062 | void InstructionCodeGeneratorX86_64::VisitArrayLength(HArrayLength* instruction) { |
| Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 5063 | if (instruction->IsEmittedAtUseSite()) { |
| 5064 | return; |
| 5065 | } |
| 5066 | |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5067 | LocationSummary* locations = instruction->GetLocations(); |
| Vladimir Marko | dce016e | 2016-04-28 13:10:02 +0100 | [diff] [blame] | 5068 | uint32_t offset = CodeGenerator::GetArrayLengthOffset(instruction); |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5069 | CpuRegister obj = locations->InAt(0).AsRegister<CpuRegister>(); |
| 5070 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5071 | __ movl(out, Address(obj, offset)); |
| Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5072 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5073 | // Mask out most significant bit in case the array is String's array of char. |
| 5074 | if (mirror::kUseStringCompression && instruction->IsStringLength()) { |
| Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 5075 | __ shrl(out, Immediate(1)); |
| jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5076 | } |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5077 | } |
| 5078 | |
| 5079 | void LocationsBuilderX86_64::VisitBoundsCheck(HBoundsCheck* instruction) { |
| Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 5080 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 5081 | InvokeRuntimeCallingConvention calling_convention; |
| 5082 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 5083 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 5084 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction, caller_saves); |
| Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 5085 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
| Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 5086 | HInstruction* length = instruction->InputAt(1); |
| 5087 | if (!length->IsEmittedAtUseSite()) { |
| 5088 | locations->SetInAt(1, Location::RegisterOrConstant(length)); |
| 5089 | } |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5090 | } |
| 5091 | |
| 5092 | void InstructionCodeGeneratorX86_64::VisitBoundsCheck(HBoundsCheck* instruction) { |
| 5093 | LocationSummary* locations = instruction->GetLocations(); |
| Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 5094 | Location index_loc = locations->InAt(0); |
| 5095 | Location length_loc = locations->InAt(1); |
| Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 5096 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) BoundsCheckSlowPathX86_64(instruction); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5097 | |
| Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 5098 | if (length_loc.IsConstant()) { |
| 5099 | int32_t length = CodeGenerator::GetInt32ValueOf(length_loc.GetConstant()); |
| 5100 | if (index_loc.IsConstant()) { |
| 5101 | // BCE will remove the bounds check if we are guarenteed to pass. |
| 5102 | int32_t index = CodeGenerator::GetInt32ValueOf(index_loc.GetConstant()); |
| 5103 | if (index < 0 || index >= length) { |
| 5104 | codegen_->AddSlowPath(slow_path); |
| 5105 | __ jmp(slow_path->GetEntryLabel()); |
| 5106 | } else { |
| 5107 | // Some optimization after BCE may have generated this, and we should not |
| 5108 | // generate a bounds check if it is a valid range. |
| 5109 | } |
| 5110 | return; |
| 5111 | } |
| 5112 | |
| 5113 | // We have to reverse the jump condition because the length is the constant. |
| 5114 | CpuRegister index_reg = index_loc.AsRegister<CpuRegister>(); |
| 5115 | __ cmpl(index_reg, Immediate(length)); |
| 5116 | codegen_->AddSlowPath(slow_path); |
| 5117 | __ j(kAboveEqual, slow_path->GetEntryLabel()); |
| Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 5118 | } else { |
| Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 5119 | HInstruction* array_length = instruction->InputAt(1); |
| 5120 | if (array_length->IsEmittedAtUseSite()) { |
| 5121 | // Address the length field in the array. |
| 5122 | DCHECK(array_length->IsArrayLength()); |
| 5123 | uint32_t len_offset = CodeGenerator::GetArrayLengthOffset(array_length->AsArrayLength()); |
| 5124 | Location array_loc = array_length->GetLocations()->InAt(0); |
| 5125 | Address array_len(array_loc.AsRegister<CpuRegister>(), len_offset); |
| jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5126 | if (mirror::kUseStringCompression && instruction->IsStringCharAt()) { |
| Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 5127 | // TODO: if index_loc.IsConstant(), compare twice the index (to compensate for |
| 5128 | // the string compression flag) with the in-memory length and avoid the temporary. |
| jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5129 | CpuRegister length_reg = CpuRegister(TMP); |
| 5130 | __ movl(length_reg, array_len); |
| 5131 | codegen_->MaybeRecordImplicitNullCheck(array_length); |
| Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 5132 | __ shrl(length_reg, Immediate(1)); |
| jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5133 | codegen_->GenerateIntCompare(length_reg, index_loc); |
| Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 5134 | } else { |
| jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5135 | // Checking the bound for general case: |
| 5136 | // Array of char or String's array when the compression feature off. |
| 5137 | if (index_loc.IsConstant()) { |
| 5138 | int32_t value = CodeGenerator::GetInt32ValueOf(index_loc.GetConstant()); |
| 5139 | __ cmpl(array_len, Immediate(value)); |
| 5140 | } else { |
| 5141 | __ cmpl(array_len, index_loc.AsRegister<CpuRegister>()); |
| 5142 | } |
| 5143 | codegen_->MaybeRecordImplicitNullCheck(array_length); |
| Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 5144 | } |
| Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 5145 | } else { |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5146 | codegen_->GenerateIntCompare(length_loc, index_loc); |
| Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 5147 | } |
| 5148 | codegen_->AddSlowPath(slow_path); |
| 5149 | __ j(kBelowEqual, slow_path->GetEntryLabel()); |
| Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 5150 | } |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5151 | } |
| 5152 | |
| 5153 | void CodeGeneratorX86_64::MarkGCCard(CpuRegister temp, |
| 5154 | CpuRegister card, |
| 5155 | CpuRegister object, |
| Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5156 | CpuRegister value, |
| 5157 | bool value_can_be_null) { |
| Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 5158 | NearLabel is_null; |
| Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5159 | if (value_can_be_null) { |
| 5160 | __ testl(value, value); |
| 5161 | __ j(kEqual, &is_null); |
| 5162 | } |
| Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 5163 | __ gs()->movq(card, Address::Absolute(Thread::CardTableOffset<kX86_64PointerSize>().Int32Value(), |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5164 | /* no_rip */ true)); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5165 | __ movq(temp, object); |
| 5166 | __ shrq(temp, Immediate(gc::accounting::CardTable::kCardShift)); |
| Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5167 | __ movb(Address(temp, card, TIMES_1, 0), card); |
| Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5168 | if (value_can_be_null) { |
| 5169 | __ Bind(&is_null); |
| 5170 | } |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5171 | } |
| 5172 | |
| Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5173 | void LocationsBuilderX86_64::VisitParallelMove(HParallelMove* instruction ATTRIBUTE_UNUSED) { |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 5174 | LOG(FATAL) << "Unimplemented"; |
| 5175 | } |
| 5176 | |
| 5177 | void InstructionCodeGeneratorX86_64::VisitParallelMove(HParallelMove* instruction) { |
| Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5178 | codegen_->GetMoveResolver()->EmitNativeCode(instruction); |
| 5179 | } |
| 5180 | |
| Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5181 | void LocationsBuilderX86_64::VisitSuspendCheck(HSuspendCheck* instruction) { |
| Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5182 | LocationSummary* locations = |
| 5183 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath); |
| Aart Bik | b13c65b | 2017-03-21 20:14:07 -0700 | [diff] [blame] | 5184 | // In suspend check slow path, usually there are no caller-save registers at all. |
| 5185 | // If SIMD instructions are present, however, we force spilling all live SIMD |
| 5186 | // registers in full width (since the runtime only saves/restores lower part). |
| Aart Bik | 5576f37 | 2017-03-23 16:17:37 -0700 | [diff] [blame] | 5187 | locations->SetCustomSlowPathCallerSaves( |
| 5188 | GetGraph()->HasSIMD() ? RegisterSet::AllFpu() : RegisterSet::Empty()); |
| Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5189 | } |
| 5190 | |
| 5191 | void InstructionCodeGeneratorX86_64::VisitSuspendCheck(HSuspendCheck* instruction) { |
| Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 5192 | HBasicBlock* block = instruction->GetBlock(); |
| 5193 | if (block->GetLoopInformation() != nullptr) { |
| 5194 | DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction); |
| 5195 | // The back edge will generate the suspend check. |
| 5196 | return; |
| 5197 | } |
| 5198 | if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) { |
| 5199 | // The goto will generate the suspend check. |
| 5200 | return; |
| 5201 | } |
| 5202 | GenerateSuspendCheck(instruction, nullptr); |
| 5203 | } |
| 5204 | |
| 5205 | void InstructionCodeGeneratorX86_64::GenerateSuspendCheck(HSuspendCheck* instruction, |
| 5206 | HBasicBlock* successor) { |
| Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5207 | SuspendCheckSlowPathX86_64* slow_path = |
| Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 5208 | down_cast<SuspendCheckSlowPathX86_64*>(instruction->GetSlowPath()); |
| 5209 | if (slow_path == nullptr) { |
| 5210 | slow_path = new (GetGraph()->GetArena()) SuspendCheckSlowPathX86_64(instruction, successor); |
| 5211 | instruction->SetSlowPath(slow_path); |
| 5212 | codegen_->AddSlowPath(slow_path); |
| 5213 | if (successor != nullptr) { |
| 5214 | DCHECK(successor->IsLoopHeader()); |
| 5215 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(instruction); |
| 5216 | } |
| 5217 | } else { |
| 5218 | DCHECK_EQ(slow_path->GetSuccessor(), successor); |
| 5219 | } |
| 5220 | |
| Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 5221 | __ gs()->cmpw(Address::Absolute(Thread::ThreadFlagsOffset<kX86_64PointerSize>().Int32Value(), |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5222 | /* no_rip */ true), |
| 5223 | Immediate(0)); |
| Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 5224 | if (successor == nullptr) { |
| 5225 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 5226 | __ Bind(slow_path->GetReturnLabel()); |
| 5227 | } else { |
| 5228 | __ j(kEqual, codegen_->GetLabelOf(successor)); |
| 5229 | __ jmp(slow_path->GetEntryLabel()); |
| 5230 | } |
| Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5231 | } |
| 5232 | |
| Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5233 | X86_64Assembler* ParallelMoveResolverX86_64::GetAssembler() const { |
| 5234 | return codegen_->GetAssembler(); |
| 5235 | } |
| 5236 | |
| 5237 | void ParallelMoveResolverX86_64::EmitMove(size_t index) { |
| Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5238 | MoveOperands* move = moves_[index]; |
| Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5239 | Location source = move->GetSource(); |
| 5240 | Location destination = move->GetDestination(); |
| 5241 | |
| 5242 | if (source.IsRegister()) { |
| 5243 | if (destination.IsRegister()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5244 | __ movq(destination.AsRegister<CpuRegister>(), source.AsRegister<CpuRegister>()); |
| Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5245 | } else if (destination.IsStackSlot()) { |
| Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5246 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5247 | source.AsRegister<CpuRegister>()); |
| Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5248 | } else { |
| 5249 | DCHECK(destination.IsDoubleStackSlot()); |
| 5250 | __ movq(Address(CpuRegister(RSP), destination.GetStackIndex()), |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5251 | source.AsRegister<CpuRegister>()); |
| Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5252 | } |
| 5253 | } else if (source.IsStackSlot()) { |
| 5254 | if (destination.IsRegister()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5255 | __ movl(destination.AsRegister<CpuRegister>(), |
| Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5256 | Address(CpuRegister(RSP), source.GetStackIndex())); |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5257 | } else if (destination.IsFpuRegister()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5258 | __ movss(destination.AsFpuRegister<XmmRegister>(), |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5259 | Address(CpuRegister(RSP), source.GetStackIndex())); |
| Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5260 | } else { |
| 5261 | DCHECK(destination.IsStackSlot()); |
| 5262 | __ movl(CpuRegister(TMP), Address(CpuRegister(RSP), source.GetStackIndex())); |
| 5263 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), CpuRegister(TMP)); |
| 5264 | } |
| Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5265 | } else if (source.IsDoubleStackSlot()) { |
| 5266 | if (destination.IsRegister()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5267 | __ movq(destination.AsRegister<CpuRegister>(), |
| Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5268 | Address(CpuRegister(RSP), source.GetStackIndex())); |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5269 | } else if (destination.IsFpuRegister()) { |
| Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 5270 | __ movsd(destination.AsFpuRegister<XmmRegister>(), |
| 5271 | Address(CpuRegister(RSP), source.GetStackIndex())); |
| Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5272 | } else { |
| Nicolas Geoffray | c8147a7 | 2014-10-21 16:06:20 +0100 | [diff] [blame] | 5273 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5274 | __ movq(CpuRegister(TMP), Address(CpuRegister(RSP), source.GetStackIndex())); |
| 5275 | __ movq(Address(CpuRegister(RSP), destination.GetStackIndex()), CpuRegister(TMP)); |
| 5276 | } |
| Aart Bik | 5576f37 | 2017-03-23 16:17:37 -0700 | [diff] [blame] | 5277 | } else if (source.IsSIMDStackSlot()) { |
| 5278 | DCHECK(destination.IsFpuRegister()); |
| 5279 | __ movups(destination.AsFpuRegister<XmmRegister>(), |
| 5280 | Address(CpuRegister(RSP), source.GetStackIndex())); |
| Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5281 | } else if (source.IsConstant()) { |
| 5282 | HConstant* constant = source.GetConstant(); |
| Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 5283 | if (constant->IsIntConstant() || constant->IsNullConstant()) { |
| 5284 | int32_t value = CodeGenerator::GetInt32ValueOf(constant); |
| Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5285 | if (destination.IsRegister()) { |
| Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 5286 | if (value == 0) { |
| 5287 | __ xorl(destination.AsRegister<CpuRegister>(), destination.AsRegister<CpuRegister>()); |
| 5288 | } else { |
| 5289 | __ movl(destination.AsRegister<CpuRegister>(), Immediate(value)); |
| 5290 | } |
| Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5291 | } else { |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5292 | DCHECK(destination.IsStackSlot()) << destination; |
| Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 5293 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), Immediate(value)); |
| Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5294 | } |
| 5295 | } else if (constant->IsLongConstant()) { |
| 5296 | int64_t value = constant->AsLongConstant()->GetValue(); |
| 5297 | if (destination.IsRegister()) { |
| Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 5298 | codegen_->Load64BitValue(destination.AsRegister<CpuRegister>(), value); |
| Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5299 | } else { |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5300 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 5301 | codegen_->Store64BitValueToStack(destination, value); |
| Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5302 | } |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5303 | } else if (constant->IsFloatConstant()) { |
| Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5304 | float fp_value = constant->AsFloatConstant()->GetValue(); |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5305 | if (destination.IsFpuRegister()) { |
| Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5306 | XmmRegister dest = destination.AsFpuRegister<XmmRegister>(); |
| Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 5307 | codegen_->Load32BitValue(dest, fp_value); |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5308 | } else { |
| 5309 | DCHECK(destination.IsStackSlot()) << destination; |
| Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 5310 | Immediate imm(bit_cast<int32_t, float>(fp_value)); |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5311 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), imm); |
| 5312 | } |
| Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5313 | } else { |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5314 | DCHECK(constant->IsDoubleConstant()) << constant->DebugName(); |
| Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5315 | double fp_value = constant->AsDoubleConstant()->GetValue(); |
| Roland Levillain | da4d79b | 2015-03-24 14:36:11 +0000 | [diff] [blame] | 5316 | int64_t value = bit_cast<int64_t, double>(fp_value); |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5317 | if (destination.IsFpuRegister()) { |
| Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5318 | XmmRegister dest = destination.AsFpuRegister<XmmRegister>(); |
| Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 5319 | codegen_->Load64BitValue(dest, fp_value); |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5320 | } else { |
| 5321 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 5322 | codegen_->Store64BitValueToStack(destination, value); |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5323 | } |
| Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5324 | } |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5325 | } else if (source.IsFpuRegister()) { |
| 5326 | if (destination.IsFpuRegister()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5327 | __ movaps(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5328 | } else if (destination.IsStackSlot()) { |
| 5329 | __ movss(Address(CpuRegister(RSP), destination.GetStackIndex()), |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5330 | source.AsFpuRegister<XmmRegister>()); |
| Aart Bik | 5576f37 | 2017-03-23 16:17:37 -0700 | [diff] [blame] | 5331 | } else if (destination.IsDoubleStackSlot()) { |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5332 | __ movsd(Address(CpuRegister(RSP), destination.GetStackIndex()), |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5333 | source.AsFpuRegister<XmmRegister>()); |
| Aart Bik | 5576f37 | 2017-03-23 16:17:37 -0700 | [diff] [blame] | 5334 | } else { |
| 5335 | DCHECK(destination.IsSIMDStackSlot()); |
| 5336 | __ movups(Address(CpuRegister(RSP), destination.GetStackIndex()), |
| 5337 | source.AsFpuRegister<XmmRegister>()); |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5338 | } |
| Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5339 | } |
| 5340 | } |
| 5341 | |
| Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5342 | void ParallelMoveResolverX86_64::Exchange32(CpuRegister reg, int mem) { |
| Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5343 | __ movl(CpuRegister(TMP), Address(CpuRegister(RSP), mem)); |
| Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5344 | __ movl(Address(CpuRegister(RSP), mem), reg); |
| 5345 | __ movl(reg, CpuRegister(TMP)); |
| Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5346 | } |
| 5347 | |
| Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5348 | void ParallelMoveResolverX86_64::Exchange32(int mem1, int mem2) { |
| Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5349 | ScratchRegisterScope ensure_scratch( |
| 5350 | this, TMP, RAX, codegen_->GetNumberOfCoreRegisters()); |
| 5351 | |
| 5352 | int stack_offset = ensure_scratch.IsSpilled() ? kX86_64WordSize : 0; |
| 5353 | __ movl(CpuRegister(TMP), Address(CpuRegister(RSP), mem1 + stack_offset)); |
| 5354 | __ movl(CpuRegister(ensure_scratch.GetRegister()), |
| 5355 | Address(CpuRegister(RSP), mem2 + stack_offset)); |
| 5356 | __ movl(Address(CpuRegister(RSP), mem2 + stack_offset), CpuRegister(TMP)); |
| 5357 | __ movl(Address(CpuRegister(RSP), mem1 + stack_offset), |
| 5358 | CpuRegister(ensure_scratch.GetRegister())); |
| 5359 | } |
| 5360 | |
| Mark Mendell | 8a1c728 | 2015-06-29 15:41:28 -0400 | [diff] [blame] | 5361 | void ParallelMoveResolverX86_64::Exchange64(CpuRegister reg1, CpuRegister reg2) { |
| 5362 | __ movq(CpuRegister(TMP), reg1); |
| 5363 | __ movq(reg1, reg2); |
| 5364 | __ movq(reg2, CpuRegister(TMP)); |
| 5365 | } |
| 5366 | |
| Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5367 | void ParallelMoveResolverX86_64::Exchange64(CpuRegister reg, int mem) { |
| 5368 | __ movq(CpuRegister(TMP), Address(CpuRegister(RSP), mem)); |
| 5369 | __ movq(Address(CpuRegister(RSP), mem), reg); |
| 5370 | __ movq(reg, CpuRegister(TMP)); |
| 5371 | } |
| 5372 | |
| 5373 | void ParallelMoveResolverX86_64::Exchange64(int mem1, int mem2) { |
| 5374 | ScratchRegisterScope ensure_scratch( |
| Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5375 | this, TMP, RAX, codegen_->GetNumberOfCoreRegisters()); |
| Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5376 | |
| Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5377 | int stack_offset = ensure_scratch.IsSpilled() ? kX86_64WordSize : 0; |
| 5378 | __ movq(CpuRegister(TMP), Address(CpuRegister(RSP), mem1 + stack_offset)); |
| 5379 | __ movq(CpuRegister(ensure_scratch.GetRegister()), |
| 5380 | Address(CpuRegister(RSP), mem2 + stack_offset)); |
| 5381 | __ movq(Address(CpuRegister(RSP), mem2 + stack_offset), CpuRegister(TMP)); |
| 5382 | __ movq(Address(CpuRegister(RSP), mem1 + stack_offset), |
| 5383 | CpuRegister(ensure_scratch.GetRegister())); |
| Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5384 | } |
| 5385 | |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5386 | void ParallelMoveResolverX86_64::Exchange32(XmmRegister reg, int mem) { |
| 5387 | __ movl(CpuRegister(TMP), Address(CpuRegister(RSP), mem)); |
| 5388 | __ movss(Address(CpuRegister(RSP), mem), reg); |
| 5389 | __ movd(reg, CpuRegister(TMP)); |
| 5390 | } |
| 5391 | |
| 5392 | void ParallelMoveResolverX86_64::Exchange64(XmmRegister reg, int mem) { |
| 5393 | __ movq(CpuRegister(TMP), Address(CpuRegister(RSP), mem)); |
| 5394 | __ movsd(Address(CpuRegister(RSP), mem), reg); |
| 5395 | __ movd(reg, CpuRegister(TMP)); |
| 5396 | } |
| 5397 | |
| Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5398 | void ParallelMoveResolverX86_64::EmitSwap(size_t index) { |
| Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5399 | MoveOperands* move = moves_[index]; |
| Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5400 | Location source = move->GetSource(); |
| 5401 | Location destination = move->GetDestination(); |
| 5402 | |
| 5403 | if (source.IsRegister() && destination.IsRegister()) { |
| Mark Mendell | 8a1c728 | 2015-06-29 15:41:28 -0400 | [diff] [blame] | 5404 | Exchange64(source.AsRegister<CpuRegister>(), destination.AsRegister<CpuRegister>()); |
| Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5405 | } else if (source.IsRegister() && destination.IsStackSlot()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5406 | Exchange32(source.AsRegister<CpuRegister>(), destination.GetStackIndex()); |
| Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5407 | } else if (source.IsStackSlot() && destination.IsRegister()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5408 | Exchange32(destination.AsRegister<CpuRegister>(), source.GetStackIndex()); |
| Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5409 | } else if (source.IsStackSlot() && destination.IsStackSlot()) { |
| Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5410 | Exchange32(destination.GetStackIndex(), source.GetStackIndex()); |
| 5411 | } else if (source.IsRegister() && destination.IsDoubleStackSlot()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5412 | Exchange64(source.AsRegister<CpuRegister>(), destination.GetStackIndex()); |
| Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5413 | } else if (source.IsDoubleStackSlot() && destination.IsRegister()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5414 | Exchange64(destination.AsRegister<CpuRegister>(), source.GetStackIndex()); |
| Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5415 | } else if (source.IsDoubleStackSlot() && destination.IsDoubleStackSlot()) { |
| 5416 | Exchange64(destination.GetStackIndex(), source.GetStackIndex()); |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5417 | } else if (source.IsFpuRegister() && destination.IsFpuRegister()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5418 | __ movd(CpuRegister(TMP), source.AsFpuRegister<XmmRegister>()); |
| 5419 | __ movaps(source.AsFpuRegister<XmmRegister>(), destination.AsFpuRegister<XmmRegister>()); |
| 5420 | __ movd(destination.AsFpuRegister<XmmRegister>(), CpuRegister(TMP)); |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5421 | } else if (source.IsFpuRegister() && destination.IsStackSlot()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5422 | Exchange32(source.AsFpuRegister<XmmRegister>(), destination.GetStackIndex()); |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5423 | } else if (source.IsStackSlot() && destination.IsFpuRegister()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5424 | Exchange32(destination.AsFpuRegister<XmmRegister>(), source.GetStackIndex()); |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5425 | } else if (source.IsFpuRegister() && destination.IsDoubleStackSlot()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5426 | Exchange64(source.AsFpuRegister<XmmRegister>(), destination.GetStackIndex()); |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5427 | } else if (source.IsDoubleStackSlot() && destination.IsFpuRegister()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5428 | Exchange64(destination.AsFpuRegister<XmmRegister>(), source.GetStackIndex()); |
| Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5429 | } else { |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5430 | LOG(FATAL) << "Unimplemented swap between " << source << " and " << destination; |
| Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5431 | } |
| 5432 | } |
| 5433 | |
| 5434 | |
| 5435 | void ParallelMoveResolverX86_64::SpillScratch(int reg) { |
| 5436 | __ pushq(CpuRegister(reg)); |
| 5437 | } |
| 5438 | |
| 5439 | |
| 5440 | void ParallelMoveResolverX86_64::RestoreScratch(int reg) { |
| 5441 | __ popq(CpuRegister(reg)); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 5442 | } |
| 5443 | |
| Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5444 | void InstructionCodeGeneratorX86_64::GenerateClassInitializationCheck( |
| Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 5445 | SlowPathCode* slow_path, CpuRegister class_reg) { |
| Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5446 | __ cmpl(Address(class_reg, mirror::Class::StatusOffset().Int32Value()), |
| 5447 | Immediate(mirror::Class::kStatusInitialized)); |
| 5448 | __ j(kLess, slow_path->GetEntryLabel()); |
| 5449 | __ Bind(slow_path->GetExitLabel()); |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5450 | // No need for memory fence, thanks to the x86-64 memory model. |
| Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5451 | } |
| 5452 | |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5453 | HLoadClass::LoadKind CodeGeneratorX86_64::GetSupportedLoadClassKind( |
| 5454 | HLoadClass::LoadKind desired_class_load_kind) { |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5455 | switch (desired_class_load_kind) { |
| Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 5456 | case HLoadClass::LoadKind::kInvalid: |
| 5457 | LOG(FATAL) << "UNREACHABLE"; |
| 5458 | UNREACHABLE(); |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5459 | case HLoadClass::LoadKind::kReferrersClass: |
| 5460 | break; |
| 5461 | case HLoadClass::LoadKind::kBootImageLinkTimeAddress: |
| 5462 | DCHECK(!GetCompilerOptions().GetCompilePic()); |
| 5463 | // We prefer the always-available RIP-relative address for the x86-64 boot image. |
| 5464 | return HLoadClass::LoadKind::kBootImageLinkTimePcRelative; |
| 5465 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: |
| 5466 | DCHECK(GetCompilerOptions().GetCompilePic()); |
| 5467 | break; |
| 5468 | case HLoadClass::LoadKind::kBootImageAddress: |
| 5469 | break; |
| Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5470 | case HLoadClass::LoadKind::kBssEntry: |
| 5471 | DCHECK(!Runtime::Current()->UseJitCompilation()); |
| 5472 | break; |
| Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 5473 | case HLoadClass::LoadKind::kJitTableAddress: |
| Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5474 | DCHECK(Runtime::Current()->UseJitCompilation()); |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5475 | break; |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5476 | case HLoadClass::LoadKind::kDexCacheViaMethod: |
| 5477 | break; |
| 5478 | } |
| 5479 | return desired_class_load_kind; |
| 5480 | } |
| 5481 | |
| Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5482 | void LocationsBuilderX86_64::VisitLoadClass(HLoadClass* cls) { |
| Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5483 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
| 5484 | if (load_kind == HLoadClass::LoadKind::kDexCacheViaMethod) { |
| Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 5485 | // Custom calling convention: RAX serves as both input and output. |
| Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5486 | CodeGenerator::CreateLoadClassRuntimeCallLocationSummary( |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5487 | cls, |
| Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 5488 | Location::RegisterLocation(RAX), |
| Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5489 | Location::RegisterLocation(RAX)); |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5490 | return; |
| 5491 | } |
| Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5492 | DCHECK(!cls->NeedsAccessCheck()); |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5493 | |
| Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5494 | const bool requires_read_barrier = kEmitCompilerReadBarrier && !cls->IsInBootImage(); |
| 5495 | LocationSummary::CallKind call_kind = (cls->NeedsEnvironment() || requires_read_barrier) |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5496 | ? LocationSummary::kCallOnSlowPath |
| 5497 | : LocationSummary::kNoCall; |
| 5498 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(cls, call_kind); |
| Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5499 | if (kUseBakerReadBarrier && requires_read_barrier && !cls->NeedsEnvironment()) { |
| Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 5500 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
| Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5501 | } |
| 5502 | |
| Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5503 | if (load_kind == HLoadClass::LoadKind::kReferrersClass) { |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5504 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5505 | } |
| 5506 | locations->SetOut(Location::RequiresRegister()); |
| Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 5507 | if (load_kind == HLoadClass::LoadKind::kBssEntry) { |
| 5508 | if (!kUseReadBarrier || kUseBakerReadBarrier) { |
| 5509 | // Rely on the type resolution and/or initialization to save everything. |
| 5510 | // Custom calling convention: RAX serves as both input and output. |
| 5511 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 5512 | caller_saves.Add(Location::RegisterLocation(RAX)); |
| 5513 | locations->SetCustomSlowPathCallerSaves(caller_saves); |
| 5514 | } else { |
| 5515 | // For non-Baker read barrier we have a temp-clobbering call. |
| 5516 | } |
| 5517 | } |
| Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5518 | } |
| 5519 | |
| Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 5520 | Label* CodeGeneratorX86_64::NewJitRootClassPatch(const DexFile& dex_file, |
| 5521 | dex::TypeIndex dex_index, |
| Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 5522 | Handle<mirror::Class> handle) { |
| 5523 | jit_class_roots_.Overwrite( |
| 5524 | TypeReference(&dex_file, dex_index), reinterpret_cast64<uint64_t>(handle.GetReference())); |
| Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 5525 | // Add a patch entry and return the label. |
| 5526 | jit_class_patches_.emplace_back(dex_file, dex_index.index_); |
| 5527 | PatchInfo<Label>* info = &jit_class_patches_.back(); |
| 5528 | return &info->label; |
| 5529 | } |
| 5530 | |
| Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 5531 | // NO_THREAD_SAFETY_ANALYSIS as we manipulate handles whose internal object we know does not |
| 5532 | // move. |
| 5533 | void InstructionCodeGeneratorX86_64::VisitLoadClass(HLoadClass* cls) NO_THREAD_SAFETY_ANALYSIS { |
| Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5534 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
| 5535 | if (load_kind == HLoadClass::LoadKind::kDexCacheViaMethod) { |
| 5536 | codegen_->GenerateLoadClassRuntimeCall(cls); |
| Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 5537 | return; |
| 5538 | } |
| Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5539 | DCHECK(!cls->NeedsAccessCheck()); |
| Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 5540 | |
| Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5541 | LocationSummary* locations = cls->GetLocations(); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5542 | Location out_loc = locations->Out(); |
| 5543 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5544 | |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 5545 | const ReadBarrierOption read_barrier_option = cls->IsInBootImage() |
| 5546 | ? kWithoutReadBarrier |
| 5547 | : kCompilerReadBarrierOption; |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5548 | bool generate_null_check = false; |
| Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5549 | switch (load_kind) { |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5550 | case HLoadClass::LoadKind::kReferrersClass: { |
| 5551 | DCHECK(!cls->CanCallRuntime()); |
| 5552 | DCHECK(!cls->MustGenerateClinitCheck()); |
| 5553 | // /* GcRoot<mirror::Class> */ out = current_method->declaring_class_ |
| 5554 | CpuRegister current_method = locations->InAt(0).AsRegister<CpuRegister>(); |
| 5555 | GenerateGcRootFieldLoad( |
| Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5556 | cls, |
| 5557 | out_loc, |
| 5558 | Address(current_method, ArtMethod::DeclaringClassOffset().Int32Value()), |
| Roland Levillain | 00468f3 | 2016-10-27 18:02:48 +0100 | [diff] [blame] | 5559 | /* fixup_label */ nullptr, |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 5560 | read_barrier_option); |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5561 | break; |
| 5562 | } |
| 5563 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: |
| Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5564 | DCHECK(codegen_->GetCompilerOptions().IsBootImage()); |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 5565 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5566 | __ leal(out, Address::Absolute(CodeGeneratorX86_64::kDummy32BitOffset, /* no_rip */ false)); |
| Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 5567 | codegen_->RecordBootTypePatch(cls); |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5568 | break; |
| 5569 | case HLoadClass::LoadKind::kBootImageAddress: { |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 5570 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
| Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 5571 | uint32_t address = dchecked_integral_cast<uint32_t>( |
| 5572 | reinterpret_cast<uintptr_t>(cls->GetClass().Get())); |
| 5573 | DCHECK_NE(address, 0u); |
| Colin Cross | 0bd9717 | 2017-03-15 16:33:27 -0700 | [diff] [blame] | 5574 | __ movl(out, Immediate(static_cast<int32_t>(address))); // Zero-extended. |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5575 | break; |
| 5576 | } |
| Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5577 | case HLoadClass::LoadKind::kBssEntry: { |
| 5578 | Address address = Address::Absolute(CodeGeneratorX86_64::kDummy32BitOffset, |
| 5579 | /* no_rip */ false); |
| 5580 | Label* fixup_label = codegen_->NewTypeBssEntryPatch(cls); |
| 5581 | // /* GcRoot<mirror::Class> */ out = *address /* PC-relative */ |
| 5582 | GenerateGcRootFieldLoad(cls, out_loc, address, fixup_label, read_barrier_option); |
| 5583 | generate_null_check = true; |
| 5584 | break; |
| 5585 | } |
| Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 5586 | case HLoadClass::LoadKind::kJitTableAddress: { |
| 5587 | Address address = Address::Absolute(CodeGeneratorX86_64::kDummy32BitOffset, |
| 5588 | /* no_rip */ true); |
| 5589 | Label* fixup_label = |
| Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 5590 | codegen_->NewJitRootClassPatch(cls->GetDexFile(), cls->GetTypeIndex(), cls->GetClass()); |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5591 | // /* GcRoot<mirror::Class> */ out = *address |
| Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 5592 | GenerateGcRootFieldLoad(cls, out_loc, address, fixup_label, read_barrier_option); |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5593 | break; |
| 5594 | } |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5595 | default: |
| 5596 | LOG(FATAL) << "Unexpected load kind: " << cls->GetLoadKind(); |
| 5597 | UNREACHABLE(); |
| 5598 | } |
| 5599 | |
| 5600 | if (generate_null_check || cls->MustGenerateClinitCheck()) { |
| 5601 | DCHECK(cls->CanCallRuntime()); |
| 5602 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathX86_64( |
| 5603 | cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck()); |
| 5604 | codegen_->AddSlowPath(slow_path); |
| 5605 | if (generate_null_check) { |
| 5606 | __ testl(out, out); |
| 5607 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 5608 | } |
| 5609 | if (cls->MustGenerateClinitCheck()) { |
| 5610 | GenerateClassInitializationCheck(slow_path, out); |
| 5611 | } else { |
| 5612 | __ Bind(slow_path->GetExitLabel()); |
| Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5613 | } |
| Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5614 | } |
| 5615 | } |
| 5616 | |
| 5617 | void LocationsBuilderX86_64::VisitClinitCheck(HClinitCheck* check) { |
| 5618 | LocationSummary* locations = |
| 5619 | new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath); |
| 5620 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5621 | if (check->HasUses()) { |
| 5622 | locations->SetOut(Location::SameAsFirstInput()); |
| 5623 | } |
| 5624 | } |
| 5625 | |
| 5626 | void InstructionCodeGeneratorX86_64::VisitClinitCheck(HClinitCheck* check) { |
| Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5627 | // We assume the class to not be null. |
| Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 5628 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathX86_64( |
| Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5629 | check->GetLoadClass(), check, check->GetDexPc(), true); |
| Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5630 | codegen_->AddSlowPath(slow_path); |
| Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 5631 | GenerateClassInitializationCheck(slow_path, |
| 5632 | check->GetLocations()->InAt(0).AsRegister<CpuRegister>()); |
| Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5633 | } |
| 5634 | |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5635 | HLoadString::LoadKind CodeGeneratorX86_64::GetSupportedLoadStringKind( |
| 5636 | HLoadString::LoadKind desired_string_load_kind) { |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5637 | switch (desired_string_load_kind) { |
| 5638 | case HLoadString::LoadKind::kBootImageLinkTimeAddress: |
| 5639 | DCHECK(!GetCompilerOptions().GetCompilePic()); |
| 5640 | // We prefer the always-available RIP-relative address for the x86-64 boot image. |
| 5641 | return HLoadString::LoadKind::kBootImageLinkTimePcRelative; |
| 5642 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: |
| 5643 | DCHECK(GetCompilerOptions().GetCompilePic()); |
| 5644 | break; |
| 5645 | case HLoadString::LoadKind::kBootImageAddress: |
| 5646 | break; |
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5647 | case HLoadString::LoadKind::kBssEntry: |
| Calin Juravle | ffc8707 | 2016-04-20 14:22:09 +0100 | [diff] [blame] | 5648 | DCHECK(!Runtime::Current()->UseJitCompilation()); |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5649 | break; |
| Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 5650 | case HLoadString::LoadKind::kJitTableAddress: |
| 5651 | DCHECK(Runtime::Current()->UseJitCompilation()); |
| 5652 | break; |
| Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5653 | case HLoadString::LoadKind::kDexCacheViaMethod: |
| 5654 | break; |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5655 | } |
| 5656 | return desired_string_load_kind; |
| 5657 | } |
| 5658 | |
| Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5659 | void LocationsBuilderX86_64::VisitLoadString(HLoadString* load) { |
| Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 5660 | LocationSummary::CallKind call_kind = CodeGenerator::GetLoadStringCallKind(load); |
| Nicolas Geoffray | 917d016 | 2015-11-24 18:25:35 +0000 | [diff] [blame] | 5661 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(load, call_kind); |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5662 | if (load->GetLoadKind() == HLoadString::LoadKind::kDexCacheViaMethod) { |
| Christina Wadsworth | abb341b | 2016-08-31 16:29:44 -0700 | [diff] [blame] | 5663 | locations->SetOut(Location::RegisterLocation(RAX)); |
| 5664 | } else { |
| 5665 | locations->SetOut(Location::RequiresRegister()); |
| Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 5666 | if (load->GetLoadKind() == HLoadString::LoadKind::kBssEntry) { |
| 5667 | if (!kUseReadBarrier || kUseBakerReadBarrier) { |
| Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 5668 | // Rely on the pResolveString to save everything. |
| Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 5669 | // Custom calling convention: RAX serves as both input and output. |
| 5670 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 5671 | caller_saves.Add(Location::RegisterLocation(RAX)); |
| 5672 | locations->SetCustomSlowPathCallerSaves(caller_saves); |
| 5673 | } else { |
| 5674 | // For non-Baker read barrier we have a temp-clobbering call. |
| 5675 | } |
| 5676 | } |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5677 | } |
| Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5678 | } |
| 5679 | |
| Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 5680 | Label* CodeGeneratorX86_64::NewJitRootStringPatch(const DexFile& dex_file, |
| Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 5681 | dex::StringIndex dex_index, |
| 5682 | Handle<mirror::String> handle) { |
| 5683 | jit_string_roots_.Overwrite( |
| 5684 | StringReference(&dex_file, dex_index), reinterpret_cast64<uint64_t>(handle.GetReference())); |
| Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 5685 | // Add a patch entry and return the label. |
| Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 5686 | jit_string_patches_.emplace_back(dex_file, dex_index.index_); |
| Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 5687 | PatchInfo<Label>* info = &jit_string_patches_.back(); |
| 5688 | return &info->label; |
| 5689 | } |
| 5690 | |
| Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 5691 | // NO_THREAD_SAFETY_ANALYSIS as we manipulate handles whose internal object we know does not |
| 5692 | // move. |
| 5693 | void InstructionCodeGeneratorX86_64::VisitLoadString(HLoadString* load) NO_THREAD_SAFETY_ANALYSIS { |
| Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 5694 | LocationSummary* locations = load->GetLocations(); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5695 | Location out_loc = locations->Out(); |
| 5696 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5697 | |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5698 | switch (load->GetLoadKind()) { |
| 5699 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: { |
| Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5700 | DCHECK(codegen_->GetCompilerOptions().IsBootImage()); |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5701 | __ leal(out, Address::Absolute(CodeGeneratorX86_64::kDummy32BitOffset, /* no_rip */ false)); |
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5702 | codegen_->RecordBootStringPatch(load); |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5703 | return; // No dex cache slow path. |
| 5704 | } |
| 5705 | case HLoadString::LoadKind::kBootImageAddress: { |
| Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 5706 | uint32_t address = dchecked_integral_cast<uint32_t>( |
| 5707 | reinterpret_cast<uintptr_t>(load->GetString().Get())); |
| 5708 | DCHECK_NE(address, 0u); |
| Colin Cross | 0bd9717 | 2017-03-15 16:33:27 -0700 | [diff] [blame] | 5709 | __ movl(out, Immediate(static_cast<int32_t>(address))); // Zero-extended. |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5710 | return; // No dex cache slow path. |
| 5711 | } |
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5712 | case HLoadString::LoadKind::kBssEntry: { |
| 5713 | Address address = Address::Absolute(CodeGeneratorX86_64::kDummy32BitOffset, |
| 5714 | /* no_rip */ false); |
| 5715 | Label* fixup_label = codegen_->NewStringBssEntryPatch(load); |
| 5716 | // /* GcRoot<mirror::Class> */ out = *address /* PC-relative */ |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 5717 | GenerateGcRootFieldLoad(load, out_loc, address, fixup_label, kCompilerReadBarrierOption); |
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5718 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) LoadStringSlowPathX86_64(load); |
| 5719 | codegen_->AddSlowPath(slow_path); |
| 5720 | __ testl(out, out); |
| 5721 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 5722 | __ Bind(slow_path->GetExitLabel()); |
| 5723 | return; |
| 5724 | } |
| Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 5725 | case HLoadString::LoadKind::kJitTableAddress: { |
| 5726 | Address address = Address::Absolute(CodeGeneratorX86_64::kDummy32BitOffset, |
| 5727 | /* no_rip */ true); |
| Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 5728 | Label* fixup_label = codegen_->NewJitRootStringPatch( |
| 5729 | load->GetDexFile(), load->GetStringIndex(), load->GetString()); |
| Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 5730 | // /* GcRoot<mirror::String> */ out = *address |
| 5731 | GenerateGcRootFieldLoad(load, out_loc, address, fixup_label, kCompilerReadBarrierOption); |
| 5732 | return; |
| 5733 | } |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5734 | default: |
| Christina Wadsworth | bf44e0e | 2016-08-18 10:37:42 -0700 | [diff] [blame] | 5735 | break; |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5736 | } |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5737 | |
| Christina Wadsworth | bf44e0e | 2016-08-18 10:37:42 -0700 | [diff] [blame] | 5738 | // TODO: Re-add the compiler code to do string dex cache lookup again. |
| Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 5739 | // Custom calling convention: RAX serves as both input and output. |
| Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 5740 | __ movl(CpuRegister(RAX), Immediate(load->GetStringIndex().index_)); |
| Christina Wadsworth | abb341b | 2016-08-31 16:29:44 -0700 | [diff] [blame] | 5741 | codegen_->InvokeRuntime(kQuickResolveString, |
| 5742 | load, |
| 5743 | load->GetDexPc()); |
| 5744 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
| Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5745 | } |
| 5746 | |
| David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 5747 | static Address GetExceptionTlsAddress() { |
| Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 5748 | return Address::Absolute(Thread::ExceptionOffset<kX86_64PointerSize>().Int32Value(), |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5749 | /* no_rip */ true); |
| David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 5750 | } |
| 5751 | |
| Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5752 | void LocationsBuilderX86_64::VisitLoadException(HLoadException* load) { |
| 5753 | LocationSummary* locations = |
| 5754 | new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall); |
| 5755 | locations->SetOut(Location::RequiresRegister()); |
| 5756 | } |
| 5757 | |
| 5758 | void InstructionCodeGeneratorX86_64::VisitLoadException(HLoadException* load) { |
| David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 5759 | __ gs()->movl(load->GetLocations()->Out().AsRegister<CpuRegister>(), GetExceptionTlsAddress()); |
| 5760 | } |
| 5761 | |
| 5762 | void LocationsBuilderX86_64::VisitClearException(HClearException* clear) { |
| 5763 | new (GetGraph()->GetArena()) LocationSummary(clear, LocationSummary::kNoCall); |
| 5764 | } |
| 5765 | |
| 5766 | void InstructionCodeGeneratorX86_64::VisitClearException(HClearException* clear ATTRIBUTE_UNUSED) { |
| 5767 | __ gs()->movl(GetExceptionTlsAddress(), Immediate(0)); |
| Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5768 | } |
| 5769 | |
| 5770 | void LocationsBuilderX86_64::VisitThrow(HThrow* instruction) { |
| 5771 | LocationSummary* locations = |
| Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 5772 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
| Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5773 | InvokeRuntimeCallingConvention calling_convention; |
| 5774 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 5775 | } |
| 5776 | |
| 5777 | void InstructionCodeGeneratorX86_64::VisitThrow(HThrow* instruction) { |
| Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 5778 | codegen_->InvokeRuntime(kQuickDeliverException, instruction, instruction->GetDexPc()); |
| Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 5779 | CheckEntrypointTypes<kQuickDeliverException, void, mirror::Object*>(); |
| Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5780 | } |
| 5781 | |
| Nicolas Geoffray | 53b07bd | 2016-11-05 15:09:19 +0000 | [diff] [blame] | 5782 | static bool CheckCastTypeCheckNeedsATemporary(TypeCheckKind type_check_kind) { |
| 5783 | if (type_check_kind == TypeCheckKind::kInterfaceCheck && !kPoisonHeapReferences) { |
| Mathieu Chartier | cdba73b | 2016-11-03 19:23:06 -0700 | [diff] [blame] | 5784 | // We need a temporary for holding the iftable length. |
| 5785 | return true; |
| 5786 | } |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5787 | return kEmitCompilerReadBarrier && |
| Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 5788 | !kUseBakerReadBarrier && |
| 5789 | (type_check_kind == TypeCheckKind::kAbstractClassCheck || |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5790 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 5791 | type_check_kind == TypeCheckKind::kArrayObjectCheck); |
| 5792 | } |
| 5793 | |
| Nicolas Geoffray | 53b07bd | 2016-11-05 15:09:19 +0000 | [diff] [blame] | 5794 | static bool InstanceOfTypeCheckNeedsATemporary(TypeCheckKind type_check_kind) { |
| 5795 | return kEmitCompilerReadBarrier && |
| 5796 | !kUseBakerReadBarrier && |
| 5797 | (type_check_kind == TypeCheckKind::kAbstractClassCheck || |
| 5798 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 5799 | type_check_kind == TypeCheckKind::kArrayObjectCheck); |
| 5800 | } |
| 5801 | |
| Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5802 | void LocationsBuilderX86_64::VisitInstanceOf(HInstanceOf* instruction) { |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5803 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5804 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5805 | bool baker_read_barrier_slow_path = false; |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5806 | switch (type_check_kind) { |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5807 | case TypeCheckKind::kExactCheck: |
| 5808 | case TypeCheckKind::kAbstractClassCheck: |
| 5809 | case TypeCheckKind::kClassHierarchyCheck: |
| 5810 | case TypeCheckKind::kArrayObjectCheck: |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5811 | call_kind = |
| 5812 | kEmitCompilerReadBarrier ? LocationSummary::kCallOnSlowPath : LocationSummary::kNoCall; |
| Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5813 | baker_read_barrier_slow_path = kUseBakerReadBarrier; |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5814 | break; |
| 5815 | case TypeCheckKind::kArrayCheck: |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5816 | case TypeCheckKind::kUnresolvedCheck: |
| 5817 | case TypeCheckKind::kInterfaceCheck: |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5818 | call_kind = LocationSummary::kCallOnSlowPath; |
| 5819 | break; |
| 5820 | } |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5821 | |
| Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5822 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
| Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5823 | if (baker_read_barrier_slow_path) { |
| Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 5824 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
| Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5825 | } |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5826 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5827 | locations->SetInAt(1, Location::Any()); |
| 5828 | // Note that TypeCheckSlowPathX86_64 uses this "out" register too. |
| 5829 | locations->SetOut(Location::RequiresRegister()); |
| 5830 | // When read barriers are enabled, we need a temporary register for |
| 5831 | // some cases. |
| Nicolas Geoffray | 53b07bd | 2016-11-05 15:09:19 +0000 | [diff] [blame] | 5832 | if (InstanceOfTypeCheckNeedsATemporary(type_check_kind)) { |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5833 | locations->AddTemp(Location::RequiresRegister()); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5834 | } |
| Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5835 | } |
| 5836 | |
| Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5837 | void InstructionCodeGeneratorX86_64::VisitInstanceOf(HInstanceOf* instruction) { |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5838 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5839 | LocationSummary* locations = instruction->GetLocations(); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5840 | Location obj_loc = locations->InAt(0); |
| 5841 | CpuRegister obj = obj_loc.AsRegister<CpuRegister>(); |
| Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5842 | Location cls = locations->InAt(1); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5843 | Location out_loc = locations->Out(); |
| 5844 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
| Nicolas Geoffray | 53b07bd | 2016-11-05 15:09:19 +0000 | [diff] [blame] | 5845 | Location maybe_temp_loc = InstanceOfTypeCheckNeedsATemporary(type_check_kind) ? |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5846 | locations->GetTemp(0) : |
| 5847 | Location::NoLocation(); |
| Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5848 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5849 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 5850 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 5851 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
| Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 5852 | SlowPathCode* slow_path = nullptr; |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5853 | NearLabel done, zero; |
| Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5854 | |
| 5855 | // Return 0 if `obj` is null. |
| Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 5856 | // Avoid null check if we know obj is not null. |
| 5857 | if (instruction->MustDoNullCheck()) { |
| 5858 | __ testl(obj, obj); |
| 5859 | __ j(kEqual, &zero); |
| 5860 | } |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5861 | |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5862 | switch (type_check_kind) { |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5863 | case TypeCheckKind::kExactCheck: { |
| Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 5864 | // /* HeapReference<Class> */ out = obj->klass_ |
| 5865 | GenerateReferenceLoadTwoRegisters(instruction, |
| 5866 | out_loc, |
| 5867 | obj_loc, |
| 5868 | class_offset, |
| 5869 | kCompilerReadBarrierOption); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5870 | if (cls.IsRegister()) { |
| 5871 | __ cmpl(out, cls.AsRegister<CpuRegister>()); |
| 5872 | } else { |
| 5873 | DCHECK(cls.IsStackSlot()) << cls; |
| 5874 | __ cmpl(out, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 5875 | } |
| Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 5876 | if (zero.IsLinked()) { |
| 5877 | // Classes must be equal for the instanceof to succeed. |
| 5878 | __ j(kNotEqual, &zero); |
| 5879 | __ movl(out, Immediate(1)); |
| 5880 | __ jmp(&done); |
| 5881 | } else { |
| 5882 | __ setcc(kEqual, out); |
| 5883 | // setcc only sets the low byte. |
| 5884 | __ andl(out, Immediate(1)); |
| 5885 | } |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5886 | break; |
| 5887 | } |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5888 | |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5889 | case TypeCheckKind::kAbstractClassCheck: { |
| Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 5890 | // /* HeapReference<Class> */ out = obj->klass_ |
| 5891 | GenerateReferenceLoadTwoRegisters(instruction, |
| 5892 | out_loc, |
| 5893 | obj_loc, |
| 5894 | class_offset, |
| 5895 | kCompilerReadBarrierOption); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5896 | // If the class is abstract, we eagerly fetch the super class of the |
| 5897 | // object to avoid doing a comparison we know will fail. |
| 5898 | NearLabel loop, success; |
| 5899 | __ Bind(&loop); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5900 | // /* HeapReference<Class> */ out = out->super_class_ |
| Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 5901 | GenerateReferenceLoadOneRegister(instruction, |
| 5902 | out_loc, |
| 5903 | super_offset, |
| 5904 | maybe_temp_loc, |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 5905 | kCompilerReadBarrierOption); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5906 | __ testl(out, out); |
| 5907 | // If `out` is null, we use it for the result, and jump to `done`. |
| 5908 | __ j(kEqual, &done); |
| 5909 | if (cls.IsRegister()) { |
| 5910 | __ cmpl(out, cls.AsRegister<CpuRegister>()); |
| 5911 | } else { |
| 5912 | DCHECK(cls.IsStackSlot()) << cls; |
| 5913 | __ cmpl(out, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 5914 | } |
| 5915 | __ j(kNotEqual, &loop); |
| 5916 | __ movl(out, Immediate(1)); |
| 5917 | if (zero.IsLinked()) { |
| 5918 | __ jmp(&done); |
| 5919 | } |
| 5920 | break; |
| 5921 | } |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5922 | |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5923 | case TypeCheckKind::kClassHierarchyCheck: { |
| Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 5924 | // /* HeapReference<Class> */ out = obj->klass_ |
| 5925 | GenerateReferenceLoadTwoRegisters(instruction, |
| 5926 | out_loc, |
| 5927 | obj_loc, |
| 5928 | class_offset, |
| 5929 | kCompilerReadBarrierOption); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5930 | // Walk over the class hierarchy to find a match. |
| 5931 | NearLabel loop, success; |
| 5932 | __ Bind(&loop); |
| 5933 | if (cls.IsRegister()) { |
| 5934 | __ cmpl(out, cls.AsRegister<CpuRegister>()); |
| 5935 | } else { |
| 5936 | DCHECK(cls.IsStackSlot()) << cls; |
| 5937 | __ cmpl(out, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 5938 | } |
| 5939 | __ j(kEqual, &success); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5940 | // /* HeapReference<Class> */ out = out->super_class_ |
| Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 5941 | GenerateReferenceLoadOneRegister(instruction, |
| 5942 | out_loc, |
| 5943 | super_offset, |
| 5944 | maybe_temp_loc, |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 5945 | kCompilerReadBarrierOption); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5946 | __ testl(out, out); |
| 5947 | __ j(kNotEqual, &loop); |
| 5948 | // If `out` is null, we use it for the result, and jump to `done`. |
| 5949 | __ jmp(&done); |
| 5950 | __ Bind(&success); |
| 5951 | __ movl(out, Immediate(1)); |
| 5952 | if (zero.IsLinked()) { |
| 5953 | __ jmp(&done); |
| 5954 | } |
| 5955 | break; |
| 5956 | } |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5957 | |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5958 | case TypeCheckKind::kArrayObjectCheck: { |
| Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 5959 | // /* HeapReference<Class> */ out = obj->klass_ |
| 5960 | GenerateReferenceLoadTwoRegisters(instruction, |
| 5961 | out_loc, |
| 5962 | obj_loc, |
| 5963 | class_offset, |
| 5964 | kCompilerReadBarrierOption); |
| Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 5965 | // Do an exact check. |
| 5966 | NearLabel exact_check; |
| 5967 | if (cls.IsRegister()) { |
| 5968 | __ cmpl(out, cls.AsRegister<CpuRegister>()); |
| 5969 | } else { |
| 5970 | DCHECK(cls.IsStackSlot()) << cls; |
| 5971 | __ cmpl(out, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 5972 | } |
| 5973 | __ j(kEqual, &exact_check); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5974 | // Otherwise, we need to check that the object's class is a non-primitive array. |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5975 | // /* HeapReference<Class> */ out = out->component_type_ |
| Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 5976 | GenerateReferenceLoadOneRegister(instruction, |
| 5977 | out_loc, |
| 5978 | component_offset, |
| 5979 | maybe_temp_loc, |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 5980 | kCompilerReadBarrierOption); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5981 | __ testl(out, out); |
| 5982 | // If `out` is null, we use it for the result, and jump to `done`. |
| 5983 | __ j(kEqual, &done); |
| 5984 | __ cmpw(Address(out, primitive_offset), Immediate(Primitive::kPrimNot)); |
| 5985 | __ j(kNotEqual, &zero); |
| Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 5986 | __ Bind(&exact_check); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5987 | __ movl(out, Immediate(1)); |
| 5988 | __ jmp(&done); |
| 5989 | break; |
| 5990 | } |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5991 | |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5992 | case TypeCheckKind::kArrayCheck: { |
| Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 5993 | // No read barrier since the slow path will retry upon failure. |
| 5994 | // /* HeapReference<Class> */ out = obj->klass_ |
| 5995 | GenerateReferenceLoadTwoRegisters(instruction, |
| 5996 | out_loc, |
| 5997 | obj_loc, |
| 5998 | class_offset, |
| 5999 | kWithoutReadBarrier); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6000 | if (cls.IsRegister()) { |
| 6001 | __ cmpl(out, cls.AsRegister<CpuRegister>()); |
| 6002 | } else { |
| 6003 | DCHECK(cls.IsStackSlot()) << cls; |
| 6004 | __ cmpl(out, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 6005 | } |
| 6006 | DCHECK(locations->OnlyCallsOnSlowPath()); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6007 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathX86_64(instruction, |
| 6008 | /* is_fatal */ false); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6009 | codegen_->AddSlowPath(slow_path); |
| 6010 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 6011 | __ movl(out, Immediate(1)); |
| 6012 | if (zero.IsLinked()) { |
| 6013 | __ jmp(&done); |
| 6014 | } |
| 6015 | break; |
| 6016 | } |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6017 | |
| Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 6018 | case TypeCheckKind::kUnresolvedCheck: |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6019 | case TypeCheckKind::kInterfaceCheck: { |
| 6020 | // Note that we indeed only call on slow path, but we always go |
| Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 6021 | // into the slow path for the unresolved and interface check |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6022 | // cases. |
| 6023 | // |
| 6024 | // We cannot directly call the InstanceofNonTrivial runtime |
| 6025 | // entry point without resorting to a type checking slow path |
| 6026 | // here (i.e. by calling InvokeRuntime directly), as it would |
| 6027 | // require to assign fixed registers for the inputs of this |
| 6028 | // HInstanceOf instruction (following the runtime calling |
| 6029 | // convention), which might be cluttered by the potential first |
| 6030 | // read barrier emission at the beginning of this method. |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6031 | // |
| 6032 | // TODO: Introduce a new runtime entry point taking the object |
| 6033 | // to test (instead of its class) as argument, and let it deal |
| 6034 | // with the read barrier issues. This will let us refactor this |
| 6035 | // case of the `switch` code as it was previously (with a direct |
| 6036 | // call to the runtime not using a type checking slow path). |
| 6037 | // This should also be beneficial for the other cases above. |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6038 | DCHECK(locations->OnlyCallsOnSlowPath()); |
| 6039 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathX86_64(instruction, |
| 6040 | /* is_fatal */ false); |
| 6041 | codegen_->AddSlowPath(slow_path); |
| 6042 | __ jmp(slow_path->GetEntryLabel()); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6043 | if (zero.IsLinked()) { |
| 6044 | __ jmp(&done); |
| 6045 | } |
| 6046 | break; |
| 6047 | } |
| Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6048 | } |
| Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6049 | |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6050 | if (zero.IsLinked()) { |
| Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6051 | __ Bind(&zero); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6052 | __ xorl(out, out); |
| 6053 | } |
| 6054 | |
| 6055 | if (done.IsLinked()) { |
| 6056 | __ Bind(&done); |
| Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6057 | } |
| 6058 | |
| Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6059 | if (slow_path != nullptr) { |
| 6060 | __ Bind(slow_path->GetExitLabel()); |
| 6061 | } |
| Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6062 | } |
| 6063 | |
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6064 | static bool IsTypeCheckSlowPathFatal(TypeCheckKind type_check_kind, bool throws_into_catch) { |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6065 | switch (type_check_kind) { |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6066 | case TypeCheckKind::kExactCheck: |
| 6067 | case TypeCheckKind::kAbstractClassCheck: |
| 6068 | case TypeCheckKind::kClassHierarchyCheck: |
| 6069 | case TypeCheckKind::kArrayObjectCheck: |
| Andreas Gampe | b5f3d81 | 2016-11-04 19:25:20 -0700 | [diff] [blame] | 6070 | return !throws_into_catch && !kEmitCompilerReadBarrier; |
| Nicolas Geoffray | 53b07bd | 2016-11-05 15:09:19 +0000 | [diff] [blame] | 6071 | case TypeCheckKind::kInterfaceCheck: |
| 6072 | return !throws_into_catch && !kEmitCompilerReadBarrier && !kPoisonHeapReferences; |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6073 | case TypeCheckKind::kArrayCheck: |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6074 | case TypeCheckKind::kUnresolvedCheck: |
| Andreas Gampe | b5f3d81 | 2016-11-04 19:25:20 -0700 | [diff] [blame] | 6075 | return false; |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6076 | } |
| Andreas Gampe | b5f3d81 | 2016-11-04 19:25:20 -0700 | [diff] [blame] | 6077 | LOG(FATAL) << "Unreachable"; |
| 6078 | UNREACHABLE(); |
| 6079 | } |
| 6080 | |
| 6081 | void LocationsBuilderX86_64::VisitCheckCast(HCheckCast* instruction) { |
| 6082 | bool throws_into_catch = instruction->CanThrowIntoCatchBlock(); |
| 6083 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| 6084 | bool is_fatal_slow_path = IsTypeCheckSlowPathFatal(type_check_kind, throws_into_catch); |
| 6085 | LocationSummary::CallKind call_kind = is_fatal_slow_path |
| 6086 | ? LocationSummary::kNoCall |
| 6087 | : LocationSummary::kCallOnSlowPath; |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6088 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
| 6089 | locations->SetInAt(0, Location::RequiresRegister()); |
| Mathieu Chartier | cdba73b | 2016-11-03 19:23:06 -0700 | [diff] [blame] | 6090 | if (type_check_kind == TypeCheckKind::kInterfaceCheck) { |
| 6091 | // Require a register for the interface check since there is a loop that compares the class to |
| 6092 | // a memory address. |
| 6093 | locations->SetInAt(1, Location::RequiresRegister()); |
| 6094 | } else { |
| 6095 | locations->SetInAt(1, Location::Any()); |
| 6096 | } |
| 6097 | |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6098 | // Note that TypeCheckSlowPathX86_64 uses this "temp" register too. |
| 6099 | locations->AddTemp(Location::RequiresRegister()); |
| 6100 | // When read barriers are enabled, we need an additional temporary |
| 6101 | // register for some cases. |
| Nicolas Geoffray | 53b07bd | 2016-11-05 15:09:19 +0000 | [diff] [blame] | 6102 | if (CheckCastTypeCheckNeedsATemporary(type_check_kind)) { |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6103 | locations->AddTemp(Location::RequiresRegister()); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6104 | } |
| Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6105 | } |
| 6106 | |
| 6107 | void InstructionCodeGeneratorX86_64::VisitCheckCast(HCheckCast* instruction) { |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6108 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6109 | LocationSummary* locations = instruction->GetLocations(); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6110 | Location obj_loc = locations->InAt(0); |
| 6111 | CpuRegister obj = obj_loc.AsRegister<CpuRegister>(); |
| Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6112 | Location cls = locations->InAt(1); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6113 | Location temp_loc = locations->GetTemp(0); |
| 6114 | CpuRegister temp = temp_loc.AsRegister<CpuRegister>(); |
| Nicolas Geoffray | 53b07bd | 2016-11-05 15:09:19 +0000 | [diff] [blame] | 6115 | Location maybe_temp2_loc = CheckCastTypeCheckNeedsATemporary(type_check_kind) ? |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6116 | locations->GetTemp(1) : |
| 6117 | Location::NoLocation(); |
| Mathieu Chartier | cdba73b | 2016-11-03 19:23:06 -0700 | [diff] [blame] | 6118 | const uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 6119 | const uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 6120 | const uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 6121 | const uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
| 6122 | const uint32_t iftable_offset = mirror::Class::IfTableOffset().Uint32Value(); |
| 6123 | const uint32_t array_length_offset = mirror::Array::LengthOffset().Uint32Value(); |
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6124 | const uint32_t object_array_data_offset = |
| 6125 | mirror::Array::DataOffset(kHeapReferenceSize).Uint32Value(); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6126 | |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6127 | // Always false for read barriers since we may need to go to the entrypoint for non-fatal cases |
| 6128 | // from false negatives. The false negatives may come from avoiding read barriers below. Avoiding |
| 6129 | // read barriers is done for performance and code size reasons. |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6130 | bool is_type_check_slow_path_fatal = |
| Andreas Gampe | b5f3d81 | 2016-11-04 19:25:20 -0700 | [diff] [blame] | 6131 | IsTypeCheckSlowPathFatal(type_check_kind, instruction->CanThrowIntoCatchBlock()); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6132 | SlowPathCode* type_check_slow_path = |
| 6133 | new (GetGraph()->GetArena()) TypeCheckSlowPathX86_64(instruction, |
| 6134 | is_type_check_slow_path_fatal); |
| 6135 | codegen_->AddSlowPath(type_check_slow_path); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6136 | |
| Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6137 | |
| 6138 | NearLabel done; |
| 6139 | // Avoid null check if we know obj is not null. |
| 6140 | if (instruction->MustDoNullCheck()) { |
| 6141 | __ testl(obj, obj); |
| 6142 | __ j(kEqual, &done); |
| 6143 | } |
| 6144 | |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6145 | switch (type_check_kind) { |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6146 | case TypeCheckKind::kExactCheck: |
| 6147 | case TypeCheckKind::kArrayCheck: { |
| Roland Levillain | 8650378 | 2016-02-11 19:07:30 +0000 | [diff] [blame] | 6148 | // /* HeapReference<Class> */ temp = obj->klass_ |
| Mathieu Chartier | cdba73b | 2016-11-03 19:23:06 -0700 | [diff] [blame] | 6149 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6150 | temp_loc, |
| 6151 | obj_loc, |
| 6152 | class_offset, |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6153 | kWithoutReadBarrier); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6154 | if (cls.IsRegister()) { |
| 6155 | __ cmpl(temp, cls.AsRegister<CpuRegister>()); |
| 6156 | } else { |
| 6157 | DCHECK(cls.IsStackSlot()) << cls; |
| 6158 | __ cmpl(temp, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 6159 | } |
| 6160 | // Jump to slow path for throwing the exception or doing a |
| 6161 | // more involved array check. |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6162 | __ j(kNotEqual, type_check_slow_path->GetEntryLabel()); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6163 | break; |
| 6164 | } |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6165 | |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6166 | case TypeCheckKind::kAbstractClassCheck: { |
| Roland Levillain | 8650378 | 2016-02-11 19:07:30 +0000 | [diff] [blame] | 6167 | // /* HeapReference<Class> */ temp = obj->klass_ |
| Mathieu Chartier | cdba73b | 2016-11-03 19:23:06 -0700 | [diff] [blame] | 6168 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6169 | temp_loc, |
| 6170 | obj_loc, |
| 6171 | class_offset, |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6172 | kWithoutReadBarrier); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6173 | // If the class is abstract, we eagerly fetch the super class of the |
| 6174 | // object to avoid doing a comparison we know will fail. |
| Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 6175 | NearLabel loop; |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6176 | __ Bind(&loop); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6177 | // /* HeapReference<Class> */ temp = temp->super_class_ |
| Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6178 | GenerateReferenceLoadOneRegister(instruction, |
| 6179 | temp_loc, |
| 6180 | super_offset, |
| 6181 | maybe_temp2_loc, |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6182 | kWithoutReadBarrier); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6183 | |
| Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 6184 | // If the class reference currently in `temp` is null, jump to the slow path to throw the |
| 6185 | // exception. |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6186 | __ testl(temp, temp); |
| Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 6187 | // Otherwise, compare the classes. |
| 6188 | __ j(kZero, type_check_slow_path->GetEntryLabel()); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6189 | if (cls.IsRegister()) { |
| 6190 | __ cmpl(temp, cls.AsRegister<CpuRegister>()); |
| 6191 | } else { |
| 6192 | DCHECK(cls.IsStackSlot()) << cls; |
| 6193 | __ cmpl(temp, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 6194 | } |
| 6195 | __ j(kNotEqual, &loop); |
| 6196 | break; |
| 6197 | } |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6198 | |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6199 | case TypeCheckKind::kClassHierarchyCheck: { |
| Roland Levillain | 8650378 | 2016-02-11 19:07:30 +0000 | [diff] [blame] | 6200 | // /* HeapReference<Class> */ temp = obj->klass_ |
| Mathieu Chartier | cdba73b | 2016-11-03 19:23:06 -0700 | [diff] [blame] | 6201 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6202 | temp_loc, |
| 6203 | obj_loc, |
| 6204 | class_offset, |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6205 | kWithoutReadBarrier); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6206 | // Walk over the class hierarchy to find a match. |
| Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6207 | NearLabel loop; |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6208 | __ Bind(&loop); |
| 6209 | if (cls.IsRegister()) { |
| 6210 | __ cmpl(temp, cls.AsRegister<CpuRegister>()); |
| 6211 | } else { |
| 6212 | DCHECK(cls.IsStackSlot()) << cls; |
| 6213 | __ cmpl(temp, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 6214 | } |
| Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6215 | __ j(kEqual, &done); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6216 | |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6217 | // /* HeapReference<Class> */ temp = temp->super_class_ |
| Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6218 | GenerateReferenceLoadOneRegister(instruction, |
| 6219 | temp_loc, |
| 6220 | super_offset, |
| 6221 | maybe_temp2_loc, |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6222 | kWithoutReadBarrier); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6223 | |
| 6224 | // If the class reference currently in `temp` is not null, jump |
| 6225 | // back at the beginning of the loop. |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6226 | __ testl(temp, temp); |
| Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 6227 | __ j(kNotZero, &loop); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6228 | // Otherwise, jump to the slow path to throw the exception. |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6229 | __ jmp(type_check_slow_path->GetEntryLabel()); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6230 | break; |
| 6231 | } |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6232 | |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6233 | case TypeCheckKind::kArrayObjectCheck: { |
| Roland Levillain | 8650378 | 2016-02-11 19:07:30 +0000 | [diff] [blame] | 6234 | // /* HeapReference<Class> */ temp = obj->klass_ |
| Mathieu Chartier | cdba73b | 2016-11-03 19:23:06 -0700 | [diff] [blame] | 6235 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6236 | temp_loc, |
| 6237 | obj_loc, |
| 6238 | class_offset, |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6239 | kWithoutReadBarrier); |
| Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6240 | // Do an exact check. |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6241 | NearLabel check_non_primitive_component_type; |
| Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6242 | if (cls.IsRegister()) { |
| 6243 | __ cmpl(temp, cls.AsRegister<CpuRegister>()); |
| 6244 | } else { |
| 6245 | DCHECK(cls.IsStackSlot()) << cls; |
| 6246 | __ cmpl(temp, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 6247 | } |
| 6248 | __ j(kEqual, &done); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6249 | |
| 6250 | // Otherwise, we need to check that the object's class is a non-primitive array. |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6251 | // /* HeapReference<Class> */ temp = temp->component_type_ |
| Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6252 | GenerateReferenceLoadOneRegister(instruction, |
| 6253 | temp_loc, |
| 6254 | component_offset, |
| 6255 | maybe_temp2_loc, |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6256 | kWithoutReadBarrier); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6257 | |
| 6258 | // If the component type is not null (i.e. the object is indeed |
| 6259 | // an array), jump to label `check_non_primitive_component_type` |
| 6260 | // to further check that this component type is not a primitive |
| 6261 | // type. |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6262 | __ testl(temp, temp); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6263 | // Otherwise, jump to the slow path to throw the exception. |
| Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 6264 | __ j(kZero, type_check_slow_path->GetEntryLabel()); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6265 | __ cmpw(Address(temp, primitive_offset), Immediate(Primitive::kPrimNot)); |
| Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 6266 | __ j(kNotEqual, type_check_slow_path->GetEntryLabel()); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6267 | break; |
| 6268 | } |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6269 | |
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6270 | case TypeCheckKind::kUnresolvedCheck: { |
| Mathieu Chartier | cdba73b | 2016-11-03 19:23:06 -0700 | [diff] [blame] | 6271 | // We always go into the type check slow path for the unresolved case. |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6272 | // |
| 6273 | // We cannot directly call the CheckCast runtime entry point |
| 6274 | // without resorting to a type checking slow path here (i.e. by |
| 6275 | // calling InvokeRuntime directly), as it would require to |
| 6276 | // assign fixed registers for the inputs of this HInstanceOf |
| 6277 | // instruction (following the runtime calling convention), which |
| 6278 | // might be cluttered by the potential first read barrier |
| 6279 | // emission at the beginning of this method. |
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6280 | __ jmp(type_check_slow_path->GetEntryLabel()); |
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6281 | break; |
| 6282 | } |
| 6283 | |
| 6284 | case TypeCheckKind::kInterfaceCheck: |
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6285 | // Fast path for the interface check. We always go slow path for heap poisoning since |
| 6286 | // unpoisoning cls would require an extra temp. |
| 6287 | if (!kPoisonHeapReferences) { |
| Mathieu Chartier | cdba73b | 2016-11-03 19:23:06 -0700 | [diff] [blame] | 6288 | // Try to avoid read barriers to improve the fast path. We can not get false positives by |
| 6289 | // doing this. |
| 6290 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 6291 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6292 | temp_loc, |
| 6293 | obj_loc, |
| 6294 | class_offset, |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6295 | kWithoutReadBarrier); |
| Mathieu Chartier | cdba73b | 2016-11-03 19:23:06 -0700 | [diff] [blame] | 6296 | |
| 6297 | // /* HeapReference<Class> */ temp = temp->iftable_ |
| 6298 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6299 | temp_loc, |
| 6300 | temp_loc, |
| 6301 | iftable_offset, |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6302 | kWithoutReadBarrier); |
| Mathieu Chartier | 6beced4 | 2016-11-15 15:51:31 -0800 | [diff] [blame] | 6303 | // Iftable is never null. |
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6304 | __ movl(maybe_temp2_loc.AsRegister<CpuRegister>(), Address(temp, array_length_offset)); |
| Mathieu Chartier | 6beced4 | 2016-11-15 15:51:31 -0800 | [diff] [blame] | 6305 | // Loop through the iftable and check if any class matches. |
| Mathieu Chartier | cdba73b | 2016-11-03 19:23:06 -0700 | [diff] [blame] | 6306 | NearLabel start_loop; |
| 6307 | __ Bind(&start_loop); |
| Mathieu Chartier | 6beced4 | 2016-11-15 15:51:31 -0800 | [diff] [blame] | 6308 | // Need to subtract first to handle the empty array case. |
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6309 | __ subl(maybe_temp2_loc.AsRegister<CpuRegister>(), Immediate(2)); |
| Mathieu Chartier | 6beced4 | 2016-11-15 15:51:31 -0800 | [diff] [blame] | 6310 | __ j(kNegative, type_check_slow_path->GetEntryLabel()); |
| 6311 | // Go to next interface if the classes do not match. |
| 6312 | __ cmpl(cls.AsRegister<CpuRegister>(), |
| 6313 | CodeGeneratorX86_64::ArrayAddress(temp, |
| 6314 | maybe_temp2_loc, |
| 6315 | TIMES_4, |
| 6316 | object_array_data_offset)); |
| 6317 | __ j(kNotEqual, &start_loop); // Return if same class. |
| 6318 | } else { |
| 6319 | __ jmp(type_check_slow_path->GetEntryLabel()); |
| Mathieu Chartier | cdba73b | 2016-11-03 19:23:06 -0700 | [diff] [blame] | 6320 | } |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6321 | break; |
| 6322 | } |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6323 | |
| Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6324 | if (done.IsLinked()) { |
| 6325 | __ Bind(&done); |
| 6326 | } |
| 6327 | |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6328 | __ Bind(type_check_slow_path->GetExitLabel()); |
| Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6329 | } |
| 6330 | |
| Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6331 | void LocationsBuilderX86_64::VisitMonitorOperation(HMonitorOperation* instruction) { |
| 6332 | LocationSummary* locations = |
| Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 6333 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
| Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6334 | InvokeRuntimeCallingConvention calling_convention; |
| 6335 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 6336 | } |
| 6337 | |
| 6338 | void InstructionCodeGeneratorX86_64::VisitMonitorOperation(HMonitorOperation* instruction) { |
| Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 6339 | codegen_->InvokeRuntime(instruction->IsEnter() ? kQuickLockObject : kQuickUnlockObject, |
| Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 6340 | instruction, |
| Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 6341 | instruction->GetDexPc()); |
| Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 6342 | if (instruction->IsEnter()) { |
| 6343 | CheckEntrypointTypes<kQuickLockObject, void, mirror::Object*>(); |
| 6344 | } else { |
| 6345 | CheckEntrypointTypes<kQuickUnlockObject, void, mirror::Object*>(); |
| 6346 | } |
| Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6347 | } |
| 6348 | |
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6349 | void LocationsBuilderX86_64::VisitAnd(HAnd* instruction) { HandleBitwiseOperation(instruction); } |
| 6350 | void LocationsBuilderX86_64::VisitOr(HOr* instruction) { HandleBitwiseOperation(instruction); } |
| 6351 | void LocationsBuilderX86_64::VisitXor(HXor* instruction) { HandleBitwiseOperation(instruction); } |
| 6352 | |
| 6353 | void LocationsBuilderX86_64::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 6354 | LocationSummary* locations = |
| 6355 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 6356 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt |
| 6357 | || instruction->GetResultType() == Primitive::kPrimLong); |
| 6358 | locations->SetInAt(0, Location::RequiresRegister()); |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 6359 | locations->SetInAt(1, Location::Any()); |
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6360 | locations->SetOut(Location::SameAsFirstInput()); |
| 6361 | } |
| 6362 | |
| 6363 | void InstructionCodeGeneratorX86_64::VisitAnd(HAnd* instruction) { |
| 6364 | HandleBitwiseOperation(instruction); |
| 6365 | } |
| 6366 | |
| 6367 | void InstructionCodeGeneratorX86_64::VisitOr(HOr* instruction) { |
| 6368 | HandleBitwiseOperation(instruction); |
| 6369 | } |
| 6370 | |
| 6371 | void InstructionCodeGeneratorX86_64::VisitXor(HXor* instruction) { |
| 6372 | HandleBitwiseOperation(instruction); |
| 6373 | } |
| 6374 | |
| 6375 | void InstructionCodeGeneratorX86_64::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 6376 | LocationSummary* locations = instruction->GetLocations(); |
| 6377 | Location first = locations->InAt(0); |
| 6378 | Location second = locations->InAt(1); |
| 6379 | DCHECK(first.Equals(locations->Out())); |
| 6380 | |
| 6381 | if (instruction->GetResultType() == Primitive::kPrimInt) { |
| 6382 | if (second.IsRegister()) { |
| 6383 | if (instruction->IsAnd()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6384 | __ andl(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6385 | } else if (instruction->IsOr()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6386 | __ orl(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6387 | } else { |
| 6388 | DCHECK(instruction->IsXor()); |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6389 | __ xorl(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6390 | } |
| 6391 | } else if (second.IsConstant()) { |
| 6392 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue()); |
| 6393 | if (instruction->IsAnd()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6394 | __ andl(first.AsRegister<CpuRegister>(), imm); |
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6395 | } else if (instruction->IsOr()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6396 | __ orl(first.AsRegister<CpuRegister>(), imm); |
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6397 | } else { |
| 6398 | DCHECK(instruction->IsXor()); |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6399 | __ xorl(first.AsRegister<CpuRegister>(), imm); |
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6400 | } |
| 6401 | } else { |
| 6402 | Address address(CpuRegister(RSP), second.GetStackIndex()); |
| 6403 | if (instruction->IsAnd()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6404 | __ andl(first.AsRegister<CpuRegister>(), address); |
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6405 | } else if (instruction->IsOr()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6406 | __ orl(first.AsRegister<CpuRegister>(), address); |
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6407 | } else { |
| 6408 | DCHECK(instruction->IsXor()); |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6409 | __ xorl(first.AsRegister<CpuRegister>(), address); |
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6410 | } |
| 6411 | } |
| 6412 | } else { |
| 6413 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong); |
| Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6414 | CpuRegister first_reg = first.AsRegister<CpuRegister>(); |
| 6415 | bool second_is_constant = false; |
| 6416 | int64_t value = 0; |
| 6417 | if (second.IsConstant()) { |
| 6418 | second_is_constant = true; |
| 6419 | value = second.GetConstant()->AsLongConstant()->GetValue(); |
| Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6420 | } |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 6421 | bool is_int32_value = IsInt<32>(value); |
| Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6422 | |
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6423 | if (instruction->IsAnd()) { |
| Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6424 | if (second_is_constant) { |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 6425 | if (is_int32_value) { |
| 6426 | __ andq(first_reg, Immediate(static_cast<int32_t>(value))); |
| 6427 | } else { |
| 6428 | __ andq(first_reg, codegen_->LiteralInt64Address(value)); |
| 6429 | } |
| 6430 | } else if (second.IsDoubleStackSlot()) { |
| 6431 | __ andq(first_reg, Address(CpuRegister(RSP), second.GetStackIndex())); |
| Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6432 | } else { |
| 6433 | __ andq(first_reg, second.AsRegister<CpuRegister>()); |
| 6434 | } |
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6435 | } else if (instruction->IsOr()) { |
| Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6436 | if (second_is_constant) { |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 6437 | if (is_int32_value) { |
| 6438 | __ orq(first_reg, Immediate(static_cast<int32_t>(value))); |
| 6439 | } else { |
| 6440 | __ orq(first_reg, codegen_->LiteralInt64Address(value)); |
| 6441 | } |
| 6442 | } else if (second.IsDoubleStackSlot()) { |
| 6443 | __ orq(first_reg, Address(CpuRegister(RSP), second.GetStackIndex())); |
| Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6444 | } else { |
| 6445 | __ orq(first_reg, second.AsRegister<CpuRegister>()); |
| 6446 | } |
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6447 | } else { |
| 6448 | DCHECK(instruction->IsXor()); |
| Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6449 | if (second_is_constant) { |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 6450 | if (is_int32_value) { |
| 6451 | __ xorq(first_reg, Immediate(static_cast<int32_t>(value))); |
| 6452 | } else { |
| 6453 | __ xorq(first_reg, codegen_->LiteralInt64Address(value)); |
| 6454 | } |
| 6455 | } else if (second.IsDoubleStackSlot()) { |
| 6456 | __ xorq(first_reg, Address(CpuRegister(RSP), second.GetStackIndex())); |
| Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6457 | } else { |
| 6458 | __ xorq(first_reg, second.AsRegister<CpuRegister>()); |
| 6459 | } |
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6460 | } |
| 6461 | } |
| 6462 | } |
| 6463 | |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6464 | void InstructionCodeGeneratorX86_64::GenerateReferenceLoadOneRegister( |
| 6465 | HInstruction* instruction, |
| 6466 | Location out, |
| 6467 | uint32_t offset, |
| 6468 | Location maybe_temp, |
| 6469 | ReadBarrierOption read_barrier_option) { |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6470 | CpuRegister out_reg = out.AsRegister<CpuRegister>(); |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6471 | if (read_barrier_option == kWithReadBarrier) { |
| Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6472 | CHECK(kEmitCompilerReadBarrier); |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6473 | if (kUseBakerReadBarrier) { |
| 6474 | // Load with fast path based Baker's read barrier. |
| 6475 | // /* HeapReference<Object> */ out = *(out + offset) |
| 6476 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
| Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 6477 | instruction, out, out_reg, offset, /* needs_null_check */ false); |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6478 | } else { |
| 6479 | // Load with slow path based read barrier. |
| Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6480 | // Save the value of `out` into `maybe_temp` before overwriting it |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6481 | // in the following move operation, as we will need it for the |
| 6482 | // read barrier below. |
| Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 6483 | DCHECK(maybe_temp.IsRegister()) << maybe_temp; |
| Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6484 | __ movl(maybe_temp.AsRegister<CpuRegister>(), out_reg); |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6485 | // /* HeapReference<Object> */ out = *(out + offset) |
| 6486 | __ movl(out_reg, Address(out_reg, offset)); |
| Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6487 | codegen_->GenerateReadBarrierSlow(instruction, out, out, maybe_temp, offset); |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6488 | } |
| 6489 | } else { |
| 6490 | // Plain load with no read barrier. |
| 6491 | // /* HeapReference<Object> */ out = *(out + offset) |
| 6492 | __ movl(out_reg, Address(out_reg, offset)); |
| 6493 | __ MaybeUnpoisonHeapReference(out_reg); |
| 6494 | } |
| 6495 | } |
| 6496 | |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6497 | void InstructionCodeGeneratorX86_64::GenerateReferenceLoadTwoRegisters( |
| 6498 | HInstruction* instruction, |
| 6499 | Location out, |
| 6500 | Location obj, |
| 6501 | uint32_t offset, |
| 6502 | ReadBarrierOption read_barrier_option) { |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6503 | CpuRegister out_reg = out.AsRegister<CpuRegister>(); |
| 6504 | CpuRegister obj_reg = obj.AsRegister<CpuRegister>(); |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6505 | if (read_barrier_option == kWithReadBarrier) { |
| Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6506 | CHECK(kEmitCompilerReadBarrier); |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6507 | if (kUseBakerReadBarrier) { |
| 6508 | // Load with fast path based Baker's read barrier. |
| 6509 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 6510 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
| Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 6511 | instruction, out, obj_reg, offset, /* needs_null_check */ false); |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6512 | } else { |
| 6513 | // Load with slow path based read barrier. |
| 6514 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 6515 | __ movl(out_reg, Address(obj_reg, offset)); |
| 6516 | codegen_->GenerateReadBarrierSlow(instruction, out, out, obj, offset); |
| 6517 | } |
| 6518 | } else { |
| 6519 | // Plain load with no read barrier. |
| 6520 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 6521 | __ movl(out_reg, Address(obj_reg, offset)); |
| 6522 | __ MaybeUnpoisonHeapReference(out_reg); |
| 6523 | } |
| 6524 | } |
| 6525 | |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6526 | void InstructionCodeGeneratorX86_64::GenerateGcRootFieldLoad( |
| 6527 | HInstruction* instruction, |
| 6528 | Location root, |
| 6529 | const Address& address, |
| 6530 | Label* fixup_label, |
| 6531 | ReadBarrierOption read_barrier_option) { |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6532 | CpuRegister root_reg = root.AsRegister<CpuRegister>(); |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6533 | if (read_barrier_option == kWithReadBarrier) { |
| Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 6534 | DCHECK(kEmitCompilerReadBarrier); |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6535 | if (kUseBakerReadBarrier) { |
| 6536 | // Fast path implementation of art::ReadBarrier::BarrierForRoot when |
| 6537 | // Baker's read barrier are used: |
| 6538 | // |
| Roland Levillain | d966ce7 | 2017-02-09 16:20:14 +0000 | [diff] [blame] | 6539 | // root = obj.field; |
| 6540 | // temp = Thread::Current()->pReadBarrierMarkReg ## root.reg() |
| 6541 | // if (temp != null) { |
| 6542 | // root = temp(root) |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6543 | // } |
| 6544 | |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6545 | // /* GcRoot<mirror::Object> */ root = *address |
| 6546 | __ movl(root_reg, address); |
| 6547 | if (fixup_label != nullptr) { |
| 6548 | __ Bind(fixup_label); |
| 6549 | } |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6550 | static_assert( |
| 6551 | sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(GcRoot<mirror::Object>), |
| 6552 | "art::mirror::CompressedReference<mirror::Object> and art::GcRoot<mirror::Object> " |
| 6553 | "have different sizes."); |
| 6554 | static_assert(sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(int32_t), |
| 6555 | "art::mirror::CompressedReference<mirror::Object> and int32_t " |
| 6556 | "have different sizes."); |
| 6557 | |
| Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 6558 | // Slow path marking the GC root `root`. |
| 6559 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) ReadBarrierMarkSlowPathX86_64( |
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 6560 | instruction, root, /* unpoison_ref_before_marking */ false); |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6561 | codegen_->AddSlowPath(slow_path); |
| 6562 | |
| Roland Levillain | d966ce7 | 2017-02-09 16:20:14 +0000 | [diff] [blame] | 6563 | // Test the `Thread::Current()->pReadBarrierMarkReg ## root.reg()` entrypoint. |
| 6564 | const int32_t entry_point_offset = |
| 6565 | CodeGenerator::GetReadBarrierMarkEntryPointsOffset<kX86_64PointerSize>(root.reg()); |
| 6566 | __ gs()->cmpl(Address::Absolute(entry_point_offset, /* no_rip */ true), Immediate(0)); |
| 6567 | // The entrypoint is null when the GC is not marking. |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6568 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 6569 | __ Bind(slow_path->GetExitLabel()); |
| 6570 | } else { |
| 6571 | // GC root loaded through a slow path for read barriers other |
| 6572 | // than Baker's. |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6573 | // /* GcRoot<mirror::Object>* */ root = address |
| 6574 | __ leaq(root_reg, address); |
| 6575 | if (fixup_label != nullptr) { |
| 6576 | __ Bind(fixup_label); |
| 6577 | } |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6578 | // /* mirror::Object* */ root = root->Read() |
| 6579 | codegen_->GenerateReadBarrierForRootSlow(instruction, root, root); |
| 6580 | } |
| 6581 | } else { |
| 6582 | // Plain GC root load with no read barrier. |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6583 | // /* GcRoot<mirror::Object> */ root = *address |
| 6584 | __ movl(root_reg, address); |
| 6585 | if (fixup_label != nullptr) { |
| 6586 | __ Bind(fixup_label); |
| 6587 | } |
| Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 6588 | // Note that GC roots are not affected by heap poisoning, thus we |
| 6589 | // do not have to unpoison `root_reg` here. |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6590 | } |
| 6591 | } |
| 6592 | |
| 6593 | void CodeGeneratorX86_64::GenerateFieldLoadWithBakerReadBarrier(HInstruction* instruction, |
| 6594 | Location ref, |
| 6595 | CpuRegister obj, |
| 6596 | uint32_t offset, |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6597 | bool needs_null_check) { |
| 6598 | DCHECK(kEmitCompilerReadBarrier); |
| 6599 | DCHECK(kUseBakerReadBarrier); |
| 6600 | |
| 6601 | // /* HeapReference<Object> */ ref = *(obj + offset) |
| 6602 | Address src(obj, offset); |
| Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 6603 | GenerateReferenceLoadWithBakerReadBarrier(instruction, ref, obj, src, needs_null_check); |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6604 | } |
| 6605 | |
| 6606 | void CodeGeneratorX86_64::GenerateArrayLoadWithBakerReadBarrier(HInstruction* instruction, |
| 6607 | Location ref, |
| 6608 | CpuRegister obj, |
| 6609 | uint32_t data_offset, |
| 6610 | Location index, |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6611 | bool needs_null_check) { |
| 6612 | DCHECK(kEmitCompilerReadBarrier); |
| 6613 | DCHECK(kUseBakerReadBarrier); |
| 6614 | |
| Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 6615 | static_assert( |
| 6616 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 6617 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6618 | // /* HeapReference<Object> */ ref = |
| 6619 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 6620 | Address src = CodeGeneratorX86_64::ArrayAddress(obj, index, TIMES_4, data_offset); |
| Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 6621 | GenerateReferenceLoadWithBakerReadBarrier(instruction, ref, obj, src, needs_null_check); |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6622 | } |
| 6623 | |
| 6624 | void CodeGeneratorX86_64::GenerateReferenceLoadWithBakerReadBarrier(HInstruction* instruction, |
| 6625 | Location ref, |
| 6626 | CpuRegister obj, |
| 6627 | const Address& src, |
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 6628 | bool needs_null_check, |
| 6629 | bool always_update_field, |
| 6630 | CpuRegister* temp1, |
| 6631 | CpuRegister* temp2) { |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6632 | DCHECK(kEmitCompilerReadBarrier); |
| 6633 | DCHECK(kUseBakerReadBarrier); |
| 6634 | |
| 6635 | // In slow path based read barriers, the read barrier call is |
| 6636 | // inserted after the original load. However, in fast path based |
| 6637 | // Baker's read barriers, we need to perform the load of |
| 6638 | // mirror::Object::monitor_ *before* the original reference load. |
| 6639 | // This load-load ordering is required by the read barrier. |
| 6640 | // The fast path/slow path (for Baker's algorithm) should look like: |
| 6641 | // |
| 6642 | // uint32_t rb_state = Lockword(obj->monitor_).ReadBarrierState(); |
| 6643 | // lfence; // Load fence or artificial data dependency to prevent load-load reordering |
| 6644 | // HeapReference<Object> ref = *src; // Original reference load. |
| Hiroshi Yamauchi | 12b58b2 | 2016-11-01 11:55:29 -0700 | [diff] [blame] | 6645 | // bool is_gray = (rb_state == ReadBarrier::GrayState()); |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6646 | // if (is_gray) { |
| 6647 | // ref = ReadBarrier::Mark(ref); // Performed by runtime entrypoint slow path. |
| 6648 | // } |
| 6649 | // |
| 6650 | // Note: the original implementation in ReadBarrier::Barrier is |
| 6651 | // slightly more complex as: |
| 6652 | // - it implements the load-load fence using a data dependency on |
| Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 6653 | // the high-bits of rb_state, which are expected to be all zeroes |
| 6654 | // (we use CodeGeneratorX86_64::GenerateMemoryBarrier instead |
| 6655 | // here, which is a no-op thanks to the x86-64 memory model); |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6656 | // - it performs additional checks that we do not do here for |
| 6657 | // performance reasons. |
| 6658 | |
| 6659 | CpuRegister ref_reg = ref.AsRegister<CpuRegister>(); |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6660 | uint32_t monitor_offset = mirror::Object::MonitorOffset().Int32Value(); |
| 6661 | |
| Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 6662 | // Given the numeric representation, it's enough to check the low bit of the rb_state. |
| Hiroshi Yamauchi | 12b58b2 | 2016-11-01 11:55:29 -0700 | [diff] [blame] | 6663 | static_assert(ReadBarrier::WhiteState() == 0, "Expecting white to have value 0"); |
| 6664 | static_assert(ReadBarrier::GrayState() == 1, "Expecting gray to have value 1"); |
| Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 6665 | constexpr uint32_t gray_byte_position = LockWord::kReadBarrierStateShift / kBitsPerByte; |
| 6666 | constexpr uint32_t gray_bit_position = LockWord::kReadBarrierStateShift % kBitsPerByte; |
| 6667 | constexpr int32_t test_value = static_cast<int8_t>(1 << gray_bit_position); |
| 6668 | |
| Hiroshi Yamauchi | 12b58b2 | 2016-11-01 11:55:29 -0700 | [diff] [blame] | 6669 | // if (rb_state == ReadBarrier::GrayState()) |
| Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 6670 | // ref = ReadBarrier::Mark(ref); |
| 6671 | // At this point, just do the "if" and make sure that flags are preserved until the branch. |
| 6672 | __ testb(Address(obj, monitor_offset + gray_byte_position), Immediate(test_value)); |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6673 | if (needs_null_check) { |
| 6674 | MaybeRecordImplicitNullCheck(instruction); |
| 6675 | } |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6676 | |
| 6677 | // Load fence to prevent load-load reordering. |
| 6678 | // Note that this is a no-op, thanks to the x86-64 memory model. |
| 6679 | GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 6680 | |
| 6681 | // The actual reference load. |
| 6682 | // /* HeapReference<Object> */ ref = *src |
| Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 6683 | __ movl(ref_reg, src); // Flags are unaffected. |
| 6684 | |
| 6685 | // Note: Reference unpoisoning modifies the flags, so we need to delay it after the branch. |
| 6686 | // Slow path marking the object `ref` when it is gray. |
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 6687 | SlowPathCode* slow_path; |
| 6688 | if (always_update_field) { |
| 6689 | DCHECK(temp1 != nullptr); |
| 6690 | DCHECK(temp2 != nullptr); |
| 6691 | slow_path = new (GetGraph()->GetArena()) ReadBarrierMarkAndUpdateFieldSlowPathX86_64( |
| 6692 | instruction, ref, obj, src, /* unpoison_ref_before_marking */ true, *temp1, *temp2); |
| 6693 | } else { |
| 6694 | slow_path = new (GetGraph()->GetArena()) ReadBarrierMarkSlowPathX86_64( |
| 6695 | instruction, ref, /* unpoison_ref_before_marking */ true); |
| 6696 | } |
| Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 6697 | AddSlowPath(slow_path); |
| 6698 | |
| 6699 | // We have done the "if" of the gray bit check above, now branch based on the flags. |
| 6700 | __ j(kNotZero, slow_path->GetEntryLabel()); |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6701 | |
| 6702 | // Object* ref = ref_addr->AsMirrorPtr() |
| 6703 | __ MaybeUnpoisonHeapReference(ref_reg); |
| 6704 | |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6705 | __ Bind(slow_path->GetExitLabel()); |
| 6706 | } |
| 6707 | |
| 6708 | void CodeGeneratorX86_64::GenerateReadBarrierSlow(HInstruction* instruction, |
| 6709 | Location out, |
| 6710 | Location ref, |
| 6711 | Location obj, |
| 6712 | uint32_t offset, |
| 6713 | Location index) { |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6714 | DCHECK(kEmitCompilerReadBarrier); |
| 6715 | |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6716 | // Insert a slow path based read barrier *after* the reference load. |
| 6717 | // |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6718 | // If heap poisoning is enabled, the unpoisoning of the loaded |
| 6719 | // reference will be carried out by the runtime within the slow |
| 6720 | // path. |
| 6721 | // |
| 6722 | // Note that `ref` currently does not get unpoisoned (when heap |
| 6723 | // poisoning is enabled), which is alright as the `ref` argument is |
| 6724 | // not used by the artReadBarrierSlow entry point. |
| 6725 | // |
| 6726 | // TODO: Unpoison `ref` when it is used by artReadBarrierSlow. |
| 6727 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) |
| 6728 | ReadBarrierForHeapReferenceSlowPathX86_64(instruction, out, ref, obj, offset, index); |
| 6729 | AddSlowPath(slow_path); |
| 6730 | |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6731 | __ jmp(slow_path->GetEntryLabel()); |
| 6732 | __ Bind(slow_path->GetExitLabel()); |
| 6733 | } |
| 6734 | |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6735 | void CodeGeneratorX86_64::MaybeGenerateReadBarrierSlow(HInstruction* instruction, |
| 6736 | Location out, |
| 6737 | Location ref, |
| 6738 | Location obj, |
| 6739 | uint32_t offset, |
| 6740 | Location index) { |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6741 | if (kEmitCompilerReadBarrier) { |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6742 | // Baker's read barriers shall be handled by the fast path |
| 6743 | // (CodeGeneratorX86_64::GenerateReferenceLoadWithBakerReadBarrier). |
| 6744 | DCHECK(!kUseBakerReadBarrier); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6745 | // If heap poisoning is enabled, unpoisoning will be taken care of |
| 6746 | // by the runtime within the slow path. |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6747 | GenerateReadBarrierSlow(instruction, out, ref, obj, offset, index); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6748 | } else if (kPoisonHeapReferences) { |
| 6749 | __ UnpoisonHeapReference(out.AsRegister<CpuRegister>()); |
| 6750 | } |
| 6751 | } |
| 6752 | |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6753 | void CodeGeneratorX86_64::GenerateReadBarrierForRootSlow(HInstruction* instruction, |
| 6754 | Location out, |
| 6755 | Location root) { |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6756 | DCHECK(kEmitCompilerReadBarrier); |
| 6757 | |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6758 | // Insert a slow path based read barrier *after* the GC root load. |
| 6759 | // |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6760 | // Note that GC roots are not affected by heap poisoning, so we do |
| 6761 | // not need to do anything special for this here. |
| 6762 | SlowPathCode* slow_path = |
| 6763 | new (GetGraph()->GetArena()) ReadBarrierForRootSlowPathX86_64(instruction, out, root); |
| 6764 | AddSlowPath(slow_path); |
| 6765 | |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6766 | __ jmp(slow_path->GetEntryLabel()); |
| 6767 | __ Bind(slow_path->GetExitLabel()); |
| 6768 | } |
| 6769 | |
| Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 6770 | void LocationsBuilderX86_64::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
| Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6771 | // Nothing to do, this should be removed during prepare for register allocator. |
| Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6772 | LOG(FATAL) << "Unreachable"; |
| 6773 | } |
| 6774 | |
| Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 6775 | void InstructionCodeGeneratorX86_64::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
| Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6776 | // Nothing to do, this should be removed during prepare for register allocator. |
| Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6777 | LOG(FATAL) << "Unreachable"; |
| 6778 | } |
| 6779 | |
| Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6780 | // Simple implementation of packed switch - generate cascaded compare/jumps. |
| 6781 | void LocationsBuilderX86_64::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 6782 | LocationSummary* locations = |
| 6783 | new (GetGraph()->GetArena()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
| 6784 | locations->SetInAt(0, Location::RequiresRegister()); |
| Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 6785 | locations->AddTemp(Location::RequiresRegister()); |
| 6786 | locations->AddTemp(Location::RequiresRegister()); |
| Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6787 | } |
| 6788 | |
| 6789 | void InstructionCodeGeneratorX86_64::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 6790 | int32_t lower_bound = switch_instr->GetStartValue(); |
| Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 6791 | uint32_t num_entries = switch_instr->GetNumEntries(); |
| Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6792 | LocationSummary* locations = switch_instr->GetLocations(); |
| Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 6793 | CpuRegister value_reg_in = locations->InAt(0).AsRegister<CpuRegister>(); |
| 6794 | CpuRegister temp_reg = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 6795 | CpuRegister base_reg = locations->GetTemp(1).AsRegister<CpuRegister>(); |
| Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 6796 | HBasicBlock* default_block = switch_instr->GetDefaultBlock(); |
| 6797 | |
| 6798 | // Should we generate smaller inline compare/jumps? |
| 6799 | if (num_entries <= kPackedSwitchJumpTableThreshold) { |
| 6800 | // Figure out the correct compare values and jump conditions. |
| 6801 | // Handle the first compare/branch as a special case because it might |
| 6802 | // jump to the default case. |
| 6803 | DCHECK_GT(num_entries, 2u); |
| 6804 | Condition first_condition; |
| 6805 | uint32_t index; |
| 6806 | const ArenaVector<HBasicBlock*>& successors = switch_instr->GetBlock()->GetSuccessors(); |
| 6807 | if (lower_bound != 0) { |
| 6808 | first_condition = kLess; |
| 6809 | __ cmpl(value_reg_in, Immediate(lower_bound)); |
| 6810 | __ j(first_condition, codegen_->GetLabelOf(default_block)); |
| 6811 | __ j(kEqual, codegen_->GetLabelOf(successors[0])); |
| 6812 | |
| 6813 | index = 1; |
| 6814 | } else { |
| 6815 | // Handle all the compare/jumps below. |
| 6816 | first_condition = kBelow; |
| 6817 | index = 0; |
| 6818 | } |
| 6819 | |
| 6820 | // Handle the rest of the compare/jumps. |
| 6821 | for (; index + 1 < num_entries; index += 2) { |
| 6822 | int32_t compare_to_value = lower_bound + index + 1; |
| 6823 | __ cmpl(value_reg_in, Immediate(compare_to_value)); |
| 6824 | // Jump to successors[index] if value < case_value[index]. |
| 6825 | __ j(first_condition, codegen_->GetLabelOf(successors[index])); |
| 6826 | // Jump to successors[index + 1] if value == case_value[index + 1]. |
| 6827 | __ j(kEqual, codegen_->GetLabelOf(successors[index + 1])); |
| 6828 | } |
| 6829 | |
| 6830 | if (index != num_entries) { |
| 6831 | // There are an odd number of entries. Handle the last one. |
| 6832 | DCHECK_EQ(index + 1, num_entries); |
| Nicolas Geoffray | 6ce0173 | 2015-12-30 14:10:13 +0000 | [diff] [blame] | 6833 | __ cmpl(value_reg_in, Immediate(static_cast<int32_t>(lower_bound + index))); |
| Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 6834 | __ j(kEqual, codegen_->GetLabelOf(successors[index])); |
| 6835 | } |
| 6836 | |
| 6837 | // And the default for any other value. |
| 6838 | if (!codegen_->GoesToNextBlock(switch_instr->GetBlock(), default_block)) { |
| 6839 | __ jmp(codegen_->GetLabelOf(default_block)); |
| 6840 | } |
| 6841 | return; |
| 6842 | } |
| Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 6843 | |
| 6844 | // Remove the bias, if needed. |
| 6845 | Register value_reg_out = value_reg_in.AsRegister(); |
| 6846 | if (lower_bound != 0) { |
| 6847 | __ leal(temp_reg, Address(value_reg_in, -lower_bound)); |
| 6848 | value_reg_out = temp_reg.AsRegister(); |
| 6849 | } |
| 6850 | CpuRegister value_reg(value_reg_out); |
| 6851 | |
| 6852 | // Is the value in range? |
| Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 6853 | __ cmpl(value_reg, Immediate(num_entries - 1)); |
| 6854 | __ j(kAbove, codegen_->GetLabelOf(default_block)); |
| Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6855 | |
| Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 6856 | // We are in the range of the table. |
| 6857 | // Load the address of the jump table in the constant area. |
| 6858 | __ leaq(base_reg, codegen_->LiteralCaseTable(switch_instr)); |
| Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6859 | |
| Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 6860 | // Load the (signed) offset from the jump table. |
| 6861 | __ movsxd(temp_reg, Address(base_reg, value_reg, TIMES_4, 0)); |
| 6862 | |
| 6863 | // Add the offset to the address of the table base. |
| 6864 | __ addq(temp_reg, base_reg); |
| 6865 | |
| 6866 | // And jump. |
| 6867 | __ jmp(temp_reg); |
| Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6868 | } |
| 6869 | |
| Aart Bik | c5d4754 | 2016-01-27 17:00:35 -0800 | [diff] [blame] | 6870 | void CodeGeneratorX86_64::Load32BitValue(CpuRegister dest, int32_t value) { |
| 6871 | if (value == 0) { |
| 6872 | __ xorl(dest, dest); |
| 6873 | } else { |
| 6874 | __ movl(dest, Immediate(value)); |
| 6875 | } |
| 6876 | } |
| 6877 | |
| Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 6878 | void CodeGeneratorX86_64::Load64BitValue(CpuRegister dest, int64_t value) { |
| 6879 | if (value == 0) { |
| Aart Bik | c5d4754 | 2016-01-27 17:00:35 -0800 | [diff] [blame] | 6880 | // Clears upper bits too. |
| Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 6881 | __ xorl(dest, dest); |
| Vladimir Marko | ed00978 | 2016-02-22 16:54:39 +0000 | [diff] [blame] | 6882 | } else if (IsUint<32>(value)) { |
| 6883 | // We can use a 32 bit move, as it will zero-extend and is shorter. |
| Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 6884 | __ movl(dest, Immediate(static_cast<int32_t>(value))); |
| 6885 | } else { |
| 6886 | __ movq(dest, Immediate(value)); |
| 6887 | } |
| 6888 | } |
| 6889 | |
| Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 6890 | void CodeGeneratorX86_64::Load32BitValue(XmmRegister dest, int32_t value) { |
| 6891 | if (value == 0) { |
| 6892 | __ xorps(dest, dest); |
| 6893 | } else { |
| 6894 | __ movss(dest, LiteralInt32Address(value)); |
| 6895 | } |
| 6896 | } |
| 6897 | |
| 6898 | void CodeGeneratorX86_64::Load64BitValue(XmmRegister dest, int64_t value) { |
| 6899 | if (value == 0) { |
| 6900 | __ xorpd(dest, dest); |
| 6901 | } else { |
| 6902 | __ movsd(dest, LiteralInt64Address(value)); |
| 6903 | } |
| 6904 | } |
| 6905 | |
| 6906 | void CodeGeneratorX86_64::Load32BitValue(XmmRegister dest, float value) { |
| 6907 | Load32BitValue(dest, bit_cast<int32_t, float>(value)); |
| 6908 | } |
| 6909 | |
| 6910 | void CodeGeneratorX86_64::Load64BitValue(XmmRegister dest, double value) { |
| 6911 | Load64BitValue(dest, bit_cast<int64_t, double>(value)); |
| 6912 | } |
| 6913 | |
| Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 6914 | void CodeGeneratorX86_64::Compare32BitValue(CpuRegister dest, int32_t value) { |
| 6915 | if (value == 0) { |
| 6916 | __ testl(dest, dest); |
| 6917 | } else { |
| 6918 | __ cmpl(dest, Immediate(value)); |
| 6919 | } |
| 6920 | } |
| 6921 | |
| 6922 | void CodeGeneratorX86_64::Compare64BitValue(CpuRegister dest, int64_t value) { |
| 6923 | if (IsInt<32>(value)) { |
| 6924 | if (value == 0) { |
| 6925 | __ testq(dest, dest); |
| 6926 | } else { |
| 6927 | __ cmpq(dest, Immediate(static_cast<int32_t>(value))); |
| 6928 | } |
| 6929 | } else { |
| 6930 | // Value won't fit in an int. |
| 6931 | __ cmpq(dest, LiteralInt64Address(value)); |
| 6932 | } |
| 6933 | } |
| 6934 | |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 6935 | void CodeGeneratorX86_64::GenerateIntCompare(Location lhs, Location rhs) { |
| 6936 | CpuRegister lhs_reg = lhs.AsRegister<CpuRegister>(); |
| jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 6937 | GenerateIntCompare(lhs_reg, rhs); |
| 6938 | } |
| 6939 | |
| 6940 | void CodeGeneratorX86_64::GenerateIntCompare(CpuRegister lhs, Location rhs) { |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 6941 | if (rhs.IsConstant()) { |
| 6942 | int32_t value = CodeGenerator::GetInt32ValueOf(rhs.GetConstant()); |
| jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 6943 | Compare32BitValue(lhs, value); |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 6944 | } else if (rhs.IsStackSlot()) { |
| jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 6945 | __ cmpl(lhs, Address(CpuRegister(RSP), rhs.GetStackIndex())); |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 6946 | } else { |
| jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 6947 | __ cmpl(lhs, rhs.AsRegister<CpuRegister>()); |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 6948 | } |
| 6949 | } |
| 6950 | |
| 6951 | void CodeGeneratorX86_64::GenerateLongCompare(Location lhs, Location rhs) { |
| 6952 | CpuRegister lhs_reg = lhs.AsRegister<CpuRegister>(); |
| 6953 | if (rhs.IsConstant()) { |
| 6954 | int64_t value = rhs.GetConstant()->AsLongConstant()->GetValue(); |
| 6955 | Compare64BitValue(lhs_reg, value); |
| 6956 | } else if (rhs.IsDoubleStackSlot()) { |
| 6957 | __ cmpq(lhs_reg, Address(CpuRegister(RSP), rhs.GetStackIndex())); |
| 6958 | } else { |
| 6959 | __ cmpq(lhs_reg, rhs.AsRegister<CpuRegister>()); |
| 6960 | } |
| 6961 | } |
| 6962 | |
| 6963 | Address CodeGeneratorX86_64::ArrayAddress(CpuRegister obj, |
| 6964 | Location index, |
| 6965 | ScaleFactor scale, |
| 6966 | uint32_t data_offset) { |
| 6967 | return index.IsConstant() ? |
| 6968 | Address(obj, (index.GetConstant()->AsIntConstant()->GetValue() << scale) + data_offset) : |
| 6969 | Address(obj, index.AsRegister<CpuRegister>(), scale, data_offset); |
| 6970 | } |
| 6971 | |
| Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 6972 | void CodeGeneratorX86_64::Store64BitValueToStack(Location dest, int64_t value) { |
| 6973 | DCHECK(dest.IsDoubleStackSlot()); |
| 6974 | if (IsInt<32>(value)) { |
| 6975 | // Can move directly as an int32 constant. |
| 6976 | __ movq(Address(CpuRegister(RSP), dest.GetStackIndex()), |
| 6977 | Immediate(static_cast<int32_t>(value))); |
| 6978 | } else { |
| 6979 | Load64BitValue(CpuRegister(TMP), value); |
| 6980 | __ movq(Address(CpuRegister(RSP), dest.GetStackIndex()), CpuRegister(TMP)); |
| 6981 | } |
| 6982 | } |
| 6983 | |
| Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 6984 | /** |
| 6985 | * Class to handle late fixup of offsets into constant area. |
| 6986 | */ |
| 6987 | class RIPFixup : public AssemblerFixup, public ArenaObject<kArenaAllocCodeGenerator> { |
| 6988 | public: |
| 6989 | RIPFixup(CodeGeneratorX86_64& codegen, size_t offset) |
| 6990 | : codegen_(&codegen), offset_into_constant_area_(offset) {} |
| 6991 | |
| 6992 | protected: |
| 6993 | void SetOffset(size_t offset) { offset_into_constant_area_ = offset; } |
| 6994 | |
| 6995 | CodeGeneratorX86_64* codegen_; |
| 6996 | |
| 6997 | private: |
| 6998 | void Process(const MemoryRegion& region, int pos) OVERRIDE { |
| 6999 | // Patch the correct offset for the instruction. We use the address of the |
| 7000 | // 'next' instruction, which is 'pos' (patch the 4 bytes before). |
| 7001 | int32_t constant_offset = codegen_->ConstantAreaStart() + offset_into_constant_area_; |
| 7002 | int32_t relative_position = constant_offset - pos; |
| 7003 | |
| 7004 | // Patch in the right value. |
| 7005 | region.StoreUnaligned<int32_t>(pos - 4, relative_position); |
| 7006 | } |
| 7007 | |
| 7008 | // Location in constant area that the fixup refers to. |
| 7009 | size_t offset_into_constant_area_; |
| 7010 | }; |
| 7011 | |
| 7012 | /** |
| 7013 | t * Class to handle late fixup of offsets to a jump table that will be created in the |
| 7014 | * constant area. |
| 7015 | */ |
| 7016 | class JumpTableRIPFixup : public RIPFixup { |
| 7017 | public: |
| 7018 | JumpTableRIPFixup(CodeGeneratorX86_64& codegen, HPackedSwitch* switch_instr) |
| 7019 | : RIPFixup(codegen, -1), switch_instr_(switch_instr) {} |
| 7020 | |
| 7021 | void CreateJumpTable() { |
| 7022 | X86_64Assembler* assembler = codegen_->GetAssembler(); |
| 7023 | |
| 7024 | // Ensure that the reference to the jump table has the correct offset. |
| 7025 | const int32_t offset_in_constant_table = assembler->ConstantAreaSize(); |
| 7026 | SetOffset(offset_in_constant_table); |
| 7027 | |
| 7028 | // Compute the offset from the start of the function to this jump table. |
| 7029 | const int32_t current_table_offset = assembler->CodeSize() + offset_in_constant_table; |
| 7030 | |
| 7031 | // Populate the jump table with the correct values for the jump table. |
| 7032 | int32_t num_entries = switch_instr_->GetNumEntries(); |
| 7033 | HBasicBlock* block = switch_instr_->GetBlock(); |
| 7034 | const ArenaVector<HBasicBlock*>& successors = block->GetSuccessors(); |
| 7035 | // The value that we want is the target offset - the position of the table. |
| 7036 | for (int32_t i = 0; i < num_entries; i++) { |
| 7037 | HBasicBlock* b = successors[i]; |
| 7038 | Label* l = codegen_->GetLabelOf(b); |
| 7039 | DCHECK(l->IsBound()); |
| 7040 | int32_t offset_to_block = l->Position() - current_table_offset; |
| 7041 | assembler->AppendInt32(offset_to_block); |
| 7042 | } |
| 7043 | } |
| 7044 | |
| 7045 | private: |
| 7046 | const HPackedSwitch* switch_instr_; |
| 7047 | }; |
| 7048 | |
| Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 7049 | void CodeGeneratorX86_64::Finalize(CodeAllocator* allocator) { |
| 7050 | // Generate the constant area if needed. |
| Mark Mendell | 39dcf55 | 2015-04-09 20:42:42 -0400 | [diff] [blame] | 7051 | X86_64Assembler* assembler = GetAssembler(); |
| Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 7052 | if (!assembler->IsConstantAreaEmpty() || !fixups_to_jump_tables_.empty()) { |
| 7053 | // Align to 4 byte boundary to reduce cache misses, as the data is 4 and 8 byte values. |
| Mark Mendell | 39dcf55 | 2015-04-09 20:42:42 -0400 | [diff] [blame] | 7054 | assembler->Align(4, 0); |
| 7055 | constant_area_start_ = assembler->CodeSize(); |
| Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 7056 | |
| 7057 | // Populate any jump tables. |
| Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame^] | 7058 | for (JumpTableRIPFixup* jump_table : fixups_to_jump_tables_) { |
| Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 7059 | jump_table->CreateJumpTable(); |
| 7060 | } |
| 7061 | |
| 7062 | // And now add the constant area to the generated code. |
| Mark Mendell | 39dcf55 | 2015-04-09 20:42:42 -0400 | [diff] [blame] | 7063 | assembler->AddConstantArea(); |
| Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 7064 | } |
| 7065 | |
| 7066 | // And finish up. |
| 7067 | CodeGenerator::Finalize(allocator); |
| 7068 | } |
| 7069 | |
| Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 7070 | Address CodeGeneratorX86_64::LiteralDoubleAddress(double v) { |
| 7071 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddDouble(v)); |
| 7072 | return Address::RIP(fixup); |
| 7073 | } |
| 7074 | |
| 7075 | Address CodeGeneratorX86_64::LiteralFloatAddress(float v) { |
| 7076 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddFloat(v)); |
| 7077 | return Address::RIP(fixup); |
| 7078 | } |
| 7079 | |
| 7080 | Address CodeGeneratorX86_64::LiteralInt32Address(int32_t v) { |
| 7081 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddInt32(v)); |
| 7082 | return Address::RIP(fixup); |
| 7083 | } |
| 7084 | |
| 7085 | Address CodeGeneratorX86_64::LiteralInt64Address(int64_t v) { |
| 7086 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddInt64(v)); |
| 7087 | return Address::RIP(fixup); |
| 7088 | } |
| 7089 | |
| Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 7090 | // TODO: trg as memory. |
| 7091 | void CodeGeneratorX86_64::MoveFromReturnRegister(Location trg, Primitive::Type type) { |
| 7092 | if (!trg.IsValid()) { |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 7093 | DCHECK_EQ(type, Primitive::kPrimVoid); |
| Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 7094 | return; |
| 7095 | } |
| 7096 | |
| 7097 | DCHECK_NE(type, Primitive::kPrimVoid); |
| 7098 | |
| 7099 | Location return_loc = InvokeDexCallingConventionVisitorX86_64().GetReturnLocation(type); |
| 7100 | if (trg.Equals(return_loc)) { |
| 7101 | return; |
| 7102 | } |
| 7103 | |
| 7104 | // Let the parallel move resolver take care of all of this. |
| 7105 | HParallelMove parallel_move(GetGraph()->GetArena()); |
| 7106 | parallel_move.AddMove(return_loc, trg, type, nullptr); |
| 7107 | GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 7108 | } |
| 7109 | |
| Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 7110 | Address CodeGeneratorX86_64::LiteralCaseTable(HPackedSwitch* switch_instr) { |
| 7111 | // Create a fixup to be used to create and address the jump table. |
| 7112 | JumpTableRIPFixup* table_fixup = |
| 7113 | new (GetGraph()->GetArena()) JumpTableRIPFixup(*this, switch_instr); |
| 7114 | |
| 7115 | // We have to populate the jump tables. |
| 7116 | fixups_to_jump_tables_.push_back(table_fixup); |
| 7117 | return Address::RIP(table_fixup); |
| 7118 | } |
| 7119 | |
| Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 7120 | void CodeGeneratorX86_64::MoveInt64ToAddress(const Address& addr_low, |
| 7121 | const Address& addr_high, |
| 7122 | int64_t v, |
| 7123 | HInstruction* instruction) { |
| 7124 | if (IsInt<32>(v)) { |
| 7125 | int32_t v_32 = v; |
| 7126 | __ movq(addr_low, Immediate(v_32)); |
| 7127 | MaybeRecordImplicitNullCheck(instruction); |
| 7128 | } else { |
| 7129 | // Didn't fit in a register. Do it in pieces. |
| 7130 | int32_t low_v = Low32Bits(v); |
| 7131 | int32_t high_v = High32Bits(v); |
| 7132 | __ movl(addr_low, Immediate(low_v)); |
| 7133 | MaybeRecordImplicitNullCheck(instruction); |
| 7134 | __ movl(addr_high, Immediate(high_v)); |
| 7135 | } |
| 7136 | } |
| 7137 | |
| Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 7138 | void CodeGeneratorX86_64::PatchJitRootUse(uint8_t* code, |
| 7139 | const uint8_t* roots_data, |
| 7140 | const PatchInfo<Label>& info, |
| 7141 | uint64_t index_in_table) const { |
| 7142 | uint32_t code_offset = info.label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
| 7143 | uintptr_t address = |
| 7144 | reinterpret_cast<uintptr_t>(roots_data) + index_in_table * sizeof(GcRoot<mirror::Object>); |
| 7145 | typedef __attribute__((__aligned__(1))) uint32_t unaligned_uint32_t; |
| 7146 | reinterpret_cast<unaligned_uint32_t*>(code + code_offset)[0] = |
| 7147 | dchecked_integral_cast<uint32_t>(address); |
| 7148 | } |
| 7149 | |
| Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 7150 | void CodeGeneratorX86_64::EmitJitRootPatches(uint8_t* code, const uint8_t* roots_data) { |
| 7151 | for (const PatchInfo<Label>& info : jit_string_patches_) { |
| Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame^] | 7152 | const auto it = jit_string_roots_.find( |
| Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 7153 | StringReference(&info.dex_file, dex::StringIndex(info.index))); |
| Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 7154 | DCHECK(it != jit_string_roots_.end()); |
| Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame^] | 7155 | uint64_t index_in_table = it->second; |
| 7156 | PatchJitRootUse(code, roots_data, info, index_in_table); |
| Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 7157 | } |
| 7158 | |
| 7159 | for (const PatchInfo<Label>& info : jit_class_patches_) { |
| Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame^] | 7160 | const auto it = jit_class_roots_.find( |
| Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 7161 | TypeReference(&info.dex_file, dex::TypeIndex(info.index))); |
| 7162 | DCHECK(it != jit_class_roots_.end()); |
| Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame^] | 7163 | uint64_t index_in_table = it->second; |
| 7164 | PatchJitRootUse(code, roots_data, info, index_in_table); |
| Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 7165 | } |
| 7166 | } |
| 7167 | |
| Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 7168 | #undef __ |
| 7169 | |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 7170 | } // namespace x86_64 |
| 7171 | } // namespace art |