| 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" |
| Andreas Gampe | d490129 | 2017-05-30 18:41:34 -0700 | [diff] [blame] | 26 | #include "lock_word.h" |
| Ian Rogers | 7e70b00 | 2014-10-08 11:47:24 -0700 | [diff] [blame] | 27 | #include "mirror/array-inl.h" |
| Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 28 | #include "mirror/class-inl.h" |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 29 | #include "mirror/object_reference.h" |
| 30 | #include "thread.h" |
| 31 | #include "utils/assembler.h" |
| Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 32 | #include "utils/stack_checks.h" |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 33 | #include "utils/x86_64/assembler_x86_64.h" |
| 34 | #include "utils/x86_64/managed_register_x86_64.h" |
| 35 | |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 36 | namespace art { |
| 37 | |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 38 | template<class MirrorType> |
| 39 | class GcRoot; |
| 40 | |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 41 | namespace x86_64 { |
| 42 | |
| Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 43 | static constexpr int kCurrentMethodStackOffset = 0; |
| Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 44 | static constexpr Register kMethodRegisterArgument = RDI; |
| Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 45 | // The compare/jump sequence will generate about (1.5 * num_entries) instructions. A jump |
| 46 | // table version generates 7 instructions and num_entries literals. Compare/jump sequence will |
| 47 | // generates less code/data with a small num_entries. |
| 48 | static constexpr uint32_t kPackedSwitchJumpTableThreshold = 5; |
| Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 49 | |
| Nicolas Geoffray | 4597b5b | 2015-01-23 21:51:55 +0000 | [diff] [blame] | 50 | static constexpr Register kCoreCalleeSaves[] = { RBX, RBP, R12, R13, R14, R15 }; |
| Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 51 | static constexpr FloatRegister kFpuCalleeSaves[] = { XMM12, XMM13, XMM14, XMM15 }; |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 52 | |
| Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 53 | static constexpr int kC2ConditionMask = 0x400; |
| 54 | |
| Roland Levillain | 7cbd27f | 2016-08-11 23:53:33 +0100 | [diff] [blame] | 55 | // NOLINT on __ macro to suppress wrong warning/fix (misc-macro-parentheses) from clang-tidy. |
| 56 | #define __ down_cast<X86_64Assembler*>(codegen->GetAssembler())-> // NOLINT |
| Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 57 | #define QUICK_ENTRY_POINT(x) QUICK_ENTRYPOINT_OFFSET(kX86_64PointerSize, x).Int32Value() |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 58 | |
| Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 59 | class NullCheckSlowPathX86_64 : public SlowPathCode { |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 60 | public: |
| David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 61 | explicit NullCheckSlowPathX86_64(HNullCheck* instruction) : SlowPathCode(instruction) {} |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 62 | |
| Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 63 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 64 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 65 | __ Bind(GetEntryLabel()); |
| David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 66 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 67 | // Live registers will be restored in the catch block if caught. |
| 68 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 69 | } |
| Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 70 | x86_64_codegen->InvokeRuntime(kQuickThrowNullPointer, |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 71 | instruction_, |
| 72 | instruction_->GetDexPc(), |
| 73 | this); |
| Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 74 | CheckEntrypointTypes<kQuickThrowNullPointer, void, void>(); |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 75 | } |
| 76 | |
| Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 77 | bool IsFatal() const OVERRIDE { return true; } |
| 78 | |
| Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 79 | const char* GetDescription() const OVERRIDE { return "NullCheckSlowPathX86_64"; } |
| 80 | |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 81 | private: |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 82 | DISALLOW_COPY_AND_ASSIGN(NullCheckSlowPathX86_64); |
| 83 | }; |
| 84 | |
| Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 85 | class DivZeroCheckSlowPathX86_64 : public SlowPathCode { |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 86 | public: |
| David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 87 | explicit DivZeroCheckSlowPathX86_64(HDivZeroCheck* instruction) : SlowPathCode(instruction) {} |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 88 | |
| Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 89 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 90 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 91 | __ Bind(GetEntryLabel()); |
| Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 92 | x86_64_codegen->InvokeRuntime(kQuickThrowDivZero, instruction_, instruction_->GetDexPc(), this); |
| Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 93 | CheckEntrypointTypes<kQuickThrowDivZero, void, void>(); |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 94 | } |
| 95 | |
| Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 96 | bool IsFatal() const OVERRIDE { return true; } |
| 97 | |
| Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 98 | const char* GetDescription() const OVERRIDE { return "DivZeroCheckSlowPathX86_64"; } |
| 99 | |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 100 | private: |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 101 | DISALLOW_COPY_AND_ASSIGN(DivZeroCheckSlowPathX86_64); |
| 102 | }; |
| 103 | |
| Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 104 | class DivRemMinusOneSlowPathX86_64 : public SlowPathCode { |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 105 | public: |
| David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 106 | DivRemMinusOneSlowPathX86_64(HInstruction* at, Register reg, Primitive::Type type, bool is_div) |
| 107 | : SlowPathCode(at), cpu_reg_(CpuRegister(reg)), type_(type), is_div_(is_div) {} |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 108 | |
| Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 109 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 110 | __ Bind(GetEntryLabel()); |
| Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 111 | if (type_ == Primitive::kPrimInt) { |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 112 | if (is_div_) { |
| 113 | __ negl(cpu_reg_); |
| 114 | } else { |
| Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 115 | __ xorl(cpu_reg_, cpu_reg_); |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 116 | } |
| 117 | |
| Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 118 | } else { |
| 119 | DCHECK_EQ(Primitive::kPrimLong, type_); |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 120 | if (is_div_) { |
| 121 | __ negq(cpu_reg_); |
| 122 | } else { |
| Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 123 | __ xorl(cpu_reg_, cpu_reg_); |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 124 | } |
| Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 125 | } |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 126 | __ jmp(GetExitLabel()); |
| 127 | } |
| 128 | |
| Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 129 | const char* GetDescription() const OVERRIDE { return "DivRemMinusOneSlowPathX86_64"; } |
| 130 | |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 131 | private: |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 132 | const CpuRegister cpu_reg_; |
| Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 133 | const Primitive::Type type_; |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 134 | const bool is_div_; |
| 135 | DISALLOW_COPY_AND_ASSIGN(DivRemMinusOneSlowPathX86_64); |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 136 | }; |
| 137 | |
| Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 138 | class SuspendCheckSlowPathX86_64 : public SlowPathCode { |
| Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 139 | public: |
| Roland Levillain | 3887c46 | 2015-08-12 18:15:42 +0100 | [diff] [blame] | 140 | SuspendCheckSlowPathX86_64(HSuspendCheck* instruction, HBasicBlock* successor) |
| David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 141 | : SlowPathCode(instruction), successor_(successor) {} |
| Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 142 | |
| Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 143 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| Aart Bik | b13c65b | 2017-03-21 20:14:07 -0700 | [diff] [blame] | 144 | LocationSummary* locations = instruction_->GetLocations(); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 145 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
| Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 146 | __ Bind(GetEntryLabel()); |
| Aart Bik | 24b905f | 2017-04-06 09:59:06 -0700 | [diff] [blame] | 147 | SaveLiveRegisters(codegen, locations); // Only saves full width XMM for SIMD. |
| Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 148 | x86_64_codegen->InvokeRuntime(kQuickTestSuspend, instruction_, instruction_->GetDexPc(), this); |
| Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 149 | CheckEntrypointTypes<kQuickTestSuspend, void, void>(); |
| Aart Bik | 24b905f | 2017-04-06 09:59:06 -0700 | [diff] [blame] | 150 | RestoreLiveRegisters(codegen, locations); // Only restores full width XMM for SIMD. |
| Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 151 | if (successor_ == nullptr) { |
| 152 | __ jmp(GetReturnLabel()); |
| 153 | } else { |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 154 | __ jmp(x86_64_codegen->GetLabelOf(successor_)); |
| Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 155 | } |
| Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 156 | } |
| 157 | |
| Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 158 | Label* GetReturnLabel() { |
| 159 | DCHECK(successor_ == nullptr); |
| 160 | return &return_label_; |
| 161 | } |
| Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 162 | |
| Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 163 | HBasicBlock* GetSuccessor() const { |
| 164 | return successor_; |
| 165 | } |
| 166 | |
| Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 167 | const char* GetDescription() const OVERRIDE { return "SuspendCheckSlowPathX86_64"; } |
| 168 | |
| Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 169 | private: |
| Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 170 | HBasicBlock* const successor_; |
| Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 171 | Label return_label_; |
| 172 | |
| 173 | DISALLOW_COPY_AND_ASSIGN(SuspendCheckSlowPathX86_64); |
| 174 | }; |
| 175 | |
| Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 176 | class BoundsCheckSlowPathX86_64 : public SlowPathCode { |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 177 | public: |
| Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 178 | explicit BoundsCheckSlowPathX86_64(HBoundsCheck* instruction) |
| David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 179 | : SlowPathCode(instruction) {} |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 180 | |
| Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 181 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 182 | LocationSummary* locations = instruction_->GetLocations(); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 183 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 184 | __ Bind(GetEntryLabel()); |
| David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 185 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 186 | // Live registers will be restored in the catch block if caught. |
| 187 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 188 | } |
| Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 189 | // Are we using an array length from memory? |
| 190 | HInstruction* array_length = instruction_->InputAt(1); |
| 191 | Location length_loc = locations->InAt(1); |
| 192 | InvokeRuntimeCallingConvention calling_convention; |
| 193 | if (array_length->IsArrayLength() && array_length->IsEmittedAtUseSite()) { |
| 194 | // Load the array length into our temporary. |
| 195 | uint32_t len_offset = CodeGenerator::GetArrayLengthOffset(array_length->AsArrayLength()); |
| 196 | Location array_loc = array_length->GetLocations()->InAt(0); |
| 197 | Address array_len(array_loc.AsRegister<CpuRegister>(), len_offset); |
| 198 | length_loc = Location::RegisterLocation(calling_convention.GetRegisterAt(1)); |
| 199 | // Check for conflicts with index. |
| 200 | if (length_loc.Equals(locations->InAt(0))) { |
| 201 | // We know we aren't using parameter 2. |
| 202 | length_loc = Location::RegisterLocation(calling_convention.GetRegisterAt(2)); |
| 203 | } |
| 204 | __ movl(length_loc.AsRegister<CpuRegister>(), array_len); |
| jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 205 | if (mirror::kUseStringCompression) { |
| Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 206 | __ shrl(length_loc.AsRegister<CpuRegister>(), Immediate(1)); |
| jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 207 | } |
| Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 208 | } |
| 209 | |
| Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 210 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 211 | // move resolver. |
| Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 212 | codegen->EmitParallelMoves( |
| Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 213 | locations->InAt(0), |
| Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 214 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 215 | Primitive::kPrimInt, |
| Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 216 | length_loc, |
| Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 217 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 218 | Primitive::kPrimInt); |
| Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 219 | QuickEntrypointEnum entrypoint = instruction_->AsBoundsCheck()->IsStringCharAt() |
| 220 | ? kQuickThrowStringBounds |
| 221 | : kQuickThrowArrayBounds; |
| 222 | x86_64_codegen->InvokeRuntime(entrypoint, instruction_, instruction_->GetDexPc(), this); |
| Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 223 | CheckEntrypointTypes<kQuickThrowStringBounds, void, int32_t, int32_t>(); |
| Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 224 | CheckEntrypointTypes<kQuickThrowArrayBounds, void, int32_t, int32_t>(); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 225 | } |
| 226 | |
| Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 227 | bool IsFatal() const OVERRIDE { return true; } |
| 228 | |
| Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 229 | const char* GetDescription() const OVERRIDE { return "BoundsCheckSlowPathX86_64"; } |
| 230 | |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 231 | private: |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 232 | DISALLOW_COPY_AND_ASSIGN(BoundsCheckSlowPathX86_64); |
| 233 | }; |
| 234 | |
| Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 235 | class LoadClassSlowPathX86_64 : public SlowPathCode { |
| Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 236 | public: |
| Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 237 | LoadClassSlowPathX86_64(HLoadClass* cls, |
| 238 | HInstruction* at, |
| 239 | uint32_t dex_pc, |
| 240 | bool do_clinit) |
| Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 241 | : SlowPathCode(at), cls_(cls), dex_pc_(dex_pc), do_clinit_(do_clinit) { |
| Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 242 | DCHECK(at->IsLoadClass() || at->IsClinitCheck()); |
| 243 | } |
| Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 244 | |
| Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 245 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 246 | LocationSummary* locations = instruction_->GetLocations(); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 247 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
| Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 248 | __ Bind(GetEntryLabel()); |
| Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 249 | |
| Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 250 | SaveLiveRegisters(codegen, locations); |
| Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 251 | |
| Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 252 | // Custom calling convention: RAX serves as both input and output. |
| 253 | __ movl(CpuRegister(RAX), Immediate(cls_->GetTypeIndex().index_)); |
| Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 254 | x86_64_codegen->InvokeRuntime(do_clinit_ ? kQuickInitializeStaticStorage : kQuickInitializeType, |
| Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 255 | instruction_, |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 256 | dex_pc_, |
| 257 | this); |
| Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 258 | if (do_clinit_) { |
| 259 | CheckEntrypointTypes<kQuickInitializeStaticStorage, void*, uint32_t>(); |
| 260 | } else { |
| 261 | CheckEntrypointTypes<kQuickInitializeType, void*, uint32_t>(); |
| 262 | } |
| Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 263 | |
| Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 264 | Location out = locations->Out(); |
| Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 265 | // Move the class to the desired location. |
| Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 266 | if (out.IsValid()) { |
| 267 | DCHECK(out.IsRegister() && !locations->GetLiveRegisters()->ContainsCoreRegister(out.reg())); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 268 | x86_64_codegen->Move(out, Location::RegisterLocation(RAX)); |
| Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 269 | } |
| 270 | |
| Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 271 | RestoreLiveRegisters(codegen, locations); |
| Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 272 | // For HLoadClass/kBssEntry, store the resolved Class to the BSS entry. |
| 273 | DCHECK_EQ(instruction_->IsLoadClass(), cls_ == instruction_); |
| 274 | if (cls_ == instruction_ && cls_->GetLoadKind() == HLoadClass::LoadKind::kBssEntry) { |
| 275 | DCHECK(out.IsValid()); |
| 276 | __ movl(Address::Absolute(CodeGeneratorX86_64::kDummy32BitOffset, /* no_rip */ false), |
| 277 | locations->Out().AsRegister<CpuRegister>()); |
| 278 | Label* fixup_label = x86_64_codegen->NewTypeBssEntryPatch(cls_); |
| 279 | __ Bind(fixup_label); |
| 280 | } |
| Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 281 | __ jmp(GetExitLabel()); |
| 282 | } |
| 283 | |
| Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 284 | const char* GetDescription() const OVERRIDE { return "LoadClassSlowPathX86_64"; } |
| 285 | |
| Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 286 | private: |
| Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 287 | // The class this slow path will load. |
| 288 | HLoadClass* const cls_; |
| Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 289 | |
| Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 290 | // The dex PC of `at_`. |
| 291 | const uint32_t dex_pc_; |
| 292 | |
| 293 | // Whether to initialize the class. |
| 294 | const bool do_clinit_; |
| 295 | |
| 296 | DISALLOW_COPY_AND_ASSIGN(LoadClassSlowPathX86_64); |
| Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 297 | }; |
| 298 | |
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 299 | class LoadStringSlowPathX86_64 : public SlowPathCode { |
| 300 | public: |
| 301 | explicit LoadStringSlowPathX86_64(HLoadString* instruction) : SlowPathCode(instruction) {} |
| 302 | |
| 303 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 304 | LocationSummary* locations = instruction_->GetLocations(); |
| 305 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
| 306 | |
| 307 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
| 308 | __ Bind(GetEntryLabel()); |
| 309 | SaveLiveRegisters(codegen, locations); |
| 310 | |
| Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 311 | const dex::StringIndex string_index = instruction_->AsLoadString()->GetStringIndex(); |
| Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 312 | // Custom calling convention: RAX serves as both input and output. |
| Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 313 | __ movl(CpuRegister(RAX), Immediate(string_index.index_)); |
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 314 | x86_64_codegen->InvokeRuntime(kQuickResolveString, |
| 315 | instruction_, |
| 316 | instruction_->GetDexPc(), |
| 317 | this); |
| 318 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
| 319 | x86_64_codegen->Move(locations->Out(), Location::RegisterLocation(RAX)); |
| 320 | RestoreLiveRegisters(codegen, locations); |
| 321 | |
| 322 | // Store the resolved String to the BSS entry. |
| 323 | __ movl(Address::Absolute(CodeGeneratorX86_64::kDummy32BitOffset, /* no_rip */ false), |
| 324 | locations->Out().AsRegister<CpuRegister>()); |
| 325 | Label* fixup_label = x86_64_codegen->NewStringBssEntryPatch(instruction_->AsLoadString()); |
| 326 | __ Bind(fixup_label); |
| 327 | |
| 328 | __ jmp(GetExitLabel()); |
| 329 | } |
| 330 | |
| 331 | const char* GetDescription() const OVERRIDE { return "LoadStringSlowPathX86_64"; } |
| 332 | |
| 333 | private: |
| 334 | DISALLOW_COPY_AND_ASSIGN(LoadStringSlowPathX86_64); |
| 335 | }; |
| 336 | |
| Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 337 | class TypeCheckSlowPathX86_64 : public SlowPathCode { |
| Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 338 | public: |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 339 | TypeCheckSlowPathX86_64(HInstruction* instruction, bool is_fatal) |
| David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 340 | : SlowPathCode(instruction), is_fatal_(is_fatal) {} |
| Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 341 | |
| Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 342 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 343 | LocationSummary* locations = instruction_->GetLocations(); |
| Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 344 | uint32_t dex_pc = instruction_->GetDexPc(); |
| Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 345 | DCHECK(instruction_->IsCheckCast() |
| 346 | || !locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
| Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 347 | |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 348 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
| Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 349 | __ Bind(GetEntryLabel()); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 350 | |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 351 | if (!is_fatal_) { |
| 352 | SaveLiveRegisters(codegen, locations); |
| 353 | } |
| Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 354 | |
| 355 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 356 | // move resolver. |
| 357 | InvokeRuntimeCallingConvention calling_convention; |
| Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 358 | codegen->EmitParallelMoves(locations->InAt(0), |
| Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 359 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| 360 | Primitive::kPrimNot, |
| Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 361 | locations->InAt(1), |
| Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 362 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 363 | Primitive::kPrimNot); |
| Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 364 | if (instruction_->IsInstanceOf()) { |
| Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 365 | x86_64_codegen->InvokeRuntime(kQuickInstanceofNonTrivial, instruction_, dex_pc, this); |
| Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 366 | CheckEntrypointTypes<kQuickInstanceofNonTrivial, size_t, mirror::Object*, mirror::Class*>(); |
| Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 367 | } else { |
| 368 | DCHECK(instruction_->IsCheckCast()); |
| Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 369 | x86_64_codegen->InvokeRuntime(kQuickCheckInstanceOf, instruction_, dex_pc, this); |
| 370 | CheckEntrypointTypes<kQuickCheckInstanceOf, void, mirror::Object*, mirror::Class*>(); |
| Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 371 | } |
| Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 372 | |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 373 | if (!is_fatal_) { |
| 374 | if (instruction_->IsInstanceOf()) { |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 375 | x86_64_codegen->Move(locations->Out(), Location::RegisterLocation(RAX)); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 376 | } |
| Nicolas Geoffray | 7537437 | 2015-09-17 17:12:19 +0000 | [diff] [blame] | 377 | |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 378 | RestoreLiveRegisters(codegen, locations); |
| 379 | __ jmp(GetExitLabel()); |
| 380 | } |
| Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 381 | } |
| 382 | |
| Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 383 | const char* GetDescription() const OVERRIDE { return "TypeCheckSlowPathX86_64"; } |
| 384 | |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 385 | bool IsFatal() const OVERRIDE { return is_fatal_; } |
| 386 | |
| Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 387 | private: |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 388 | const bool is_fatal_; |
| Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 389 | |
| 390 | DISALLOW_COPY_AND_ASSIGN(TypeCheckSlowPathX86_64); |
| 391 | }; |
| 392 | |
| Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 393 | class DeoptimizationSlowPathX86_64 : public SlowPathCode { |
| Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 394 | public: |
| Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 395 | explicit DeoptimizationSlowPathX86_64(HDeoptimize* instruction) |
| David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 396 | : SlowPathCode(instruction) {} |
| Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 397 | |
| 398 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 399 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
| Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 400 | __ Bind(GetEntryLabel()); |
| Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 401 | LocationSummary* locations = instruction_->GetLocations(); |
| 402 | SaveLiveRegisters(codegen, locations); |
| 403 | InvokeRuntimeCallingConvention calling_convention; |
| 404 | x86_64_codegen->Load32BitValue( |
| 405 | CpuRegister(calling_convention.GetRegisterAt(0)), |
| 406 | static_cast<uint32_t>(instruction_->AsDeoptimize()->GetDeoptimizationKind())); |
| Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 407 | x86_64_codegen->InvokeRuntime(kQuickDeoptimize, instruction_, instruction_->GetDexPc(), this); |
| Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 408 | CheckEntrypointTypes<kQuickDeoptimize, void, DeoptimizationKind>(); |
| Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 409 | } |
| 410 | |
| Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 411 | const char* GetDescription() const OVERRIDE { return "DeoptimizationSlowPathX86_64"; } |
| 412 | |
| Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 413 | private: |
| Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 414 | DISALLOW_COPY_AND_ASSIGN(DeoptimizationSlowPathX86_64); |
| 415 | }; |
| 416 | |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 417 | class ArraySetSlowPathX86_64 : public SlowPathCode { |
| 418 | public: |
| David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 419 | explicit ArraySetSlowPathX86_64(HInstruction* instruction) : SlowPathCode(instruction) {} |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 420 | |
| 421 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 422 | LocationSummary* locations = instruction_->GetLocations(); |
| 423 | __ Bind(GetEntryLabel()); |
| 424 | SaveLiveRegisters(codegen, locations); |
| 425 | |
| 426 | InvokeRuntimeCallingConvention calling_convention; |
| 427 | HParallelMove parallel_move(codegen->GetGraph()->GetArena()); |
| 428 | parallel_move.AddMove( |
| 429 | locations->InAt(0), |
| 430 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| 431 | Primitive::kPrimNot, |
| 432 | nullptr); |
| 433 | parallel_move.AddMove( |
| 434 | locations->InAt(1), |
| 435 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 436 | Primitive::kPrimInt, |
| 437 | nullptr); |
| 438 | parallel_move.AddMove( |
| 439 | locations->InAt(2), |
| 440 | Location::RegisterLocation(calling_convention.GetRegisterAt(2)), |
| 441 | Primitive::kPrimNot, |
| 442 | nullptr); |
| 443 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 444 | |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 445 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
| Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 446 | x86_64_codegen->InvokeRuntime(kQuickAputObject, instruction_, instruction_->GetDexPc(), this); |
| Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 447 | CheckEntrypointTypes<kQuickAputObject, void, mirror::Array*, int32_t, mirror::Object*>(); |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 448 | RestoreLiveRegisters(codegen, locations); |
| 449 | __ jmp(GetExitLabel()); |
| 450 | } |
| 451 | |
| 452 | const char* GetDescription() const OVERRIDE { return "ArraySetSlowPathX86_64"; } |
| 453 | |
| 454 | private: |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 455 | DISALLOW_COPY_AND_ASSIGN(ArraySetSlowPathX86_64); |
| 456 | }; |
| 457 | |
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 458 | // Slow path marking an object reference `ref` during a read |
| 459 | // barrier. The field `obj.field` in the object `obj` holding this |
| 460 | // reference does not get updated by this slow path after marking (see |
| 461 | // ReadBarrierMarkAndUpdateFieldSlowPathX86_64 below for that). |
| 462 | // |
| 463 | // This means that after the execution of this slow path, `ref` will |
| 464 | // always be up-to-date, but `obj.field` may not; i.e., after the |
| 465 | // flip, `ref` will be a to-space reference, but `obj.field` will |
| 466 | // probably still be a from-space reference (unless it gets updated by |
| 467 | // another thread, or if another thread installed another object |
| 468 | // reference (different from `ref`) in `obj.field`). |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 469 | class ReadBarrierMarkSlowPathX86_64 : public SlowPathCode { |
| 470 | public: |
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 471 | ReadBarrierMarkSlowPathX86_64(HInstruction* instruction, |
| 472 | Location ref, |
| 473 | bool unpoison_ref_before_marking) |
| 474 | : SlowPathCode(instruction), |
| 475 | ref_(ref), |
| 476 | unpoison_ref_before_marking_(unpoison_ref_before_marking) { |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 477 | DCHECK(kEmitCompilerReadBarrier); |
| 478 | } |
| 479 | |
| 480 | const char* GetDescription() const OVERRIDE { return "ReadBarrierMarkSlowPathX86_64"; } |
| 481 | |
| 482 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 483 | LocationSummary* locations = instruction_->GetLocations(); |
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 484 | CpuRegister ref_cpu_reg = ref_.AsRegister<CpuRegister>(); |
| 485 | Register ref_reg = ref_cpu_reg.AsRegister(); |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 486 | DCHECK(locations->CanCall()); |
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 487 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(ref_reg)) << ref_reg; |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 488 | DCHECK(instruction_->IsInstanceFieldGet() || |
| 489 | instruction_->IsStaticFieldGet() || |
| 490 | instruction_->IsArrayGet() || |
| Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 491 | instruction_->IsArraySet() || |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 492 | instruction_->IsLoadClass() || |
| 493 | instruction_->IsLoadString() || |
| 494 | instruction_->IsInstanceOf() || |
| Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 495 | instruction_->IsCheckCast() || |
| Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 496 | (instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified()) || |
| 497 | (instruction_->IsInvokeStaticOrDirect() && instruction_->GetLocations()->Intrinsified())) |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 498 | << "Unexpected instruction in read barrier marking slow path: " |
| 499 | << instruction_->DebugName(); |
| 500 | |
| 501 | __ Bind(GetEntryLabel()); |
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 502 | if (unpoison_ref_before_marking_) { |
| Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 503 | // Object* ref = ref_addr->AsMirrorPtr() |
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 504 | __ MaybeUnpoisonHeapReference(ref_cpu_reg); |
| Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 505 | } |
| Roland Levillain | 4359e61 | 2016-07-20 11:32:19 +0100 | [diff] [blame] | 506 | // No need to save live registers; it's taken care of by the |
| 507 | // entrypoint. Also, there is no need to update the stack mask, |
| 508 | // as this runtime call will not trigger a garbage collection. |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 509 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 510 | DCHECK_NE(ref_reg, RSP); |
| 511 | DCHECK(0 <= ref_reg && ref_reg < kNumberOfCpuRegisters) << ref_reg; |
| Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 512 | // "Compact" slow path, saving two moves. |
| 513 | // |
| 514 | // Instead of using the standard runtime calling convention (input |
| 515 | // and output in R0): |
| 516 | // |
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 517 | // RDI <- ref |
| Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 518 | // RAX <- ReadBarrierMark(RDI) |
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 519 | // ref <- RAX |
| Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 520 | // |
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 521 | // we just use rX (the register containing `ref`) as input and output |
| Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 522 | // of a dedicated entrypoint: |
| 523 | // |
| 524 | // rX <- ReadBarrierMarkRegX(rX) |
| 525 | // |
| 526 | int32_t entry_point_offset = |
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 527 | CodeGenerator::GetReadBarrierMarkEntryPointsOffset<kX86_64PointerSize>(ref_reg); |
| Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 528 | // This runtime call does not require a stack map. |
| 529 | x86_64_codegen->InvokeRuntimeWithoutRecordingPcInfo(entry_point_offset, instruction_, this); |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 530 | __ jmp(GetExitLabel()); |
| 531 | } |
| 532 | |
| 533 | private: |
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 534 | // The location (register) of the marked object reference. |
| 535 | const Location ref_; |
| 536 | // Should the reference in `ref_` be unpoisoned prior to marking it? |
| 537 | const bool unpoison_ref_before_marking_; |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 538 | |
| 539 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierMarkSlowPathX86_64); |
| 540 | }; |
| 541 | |
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 542 | // Slow path marking an object reference `ref` during a read barrier, |
| 543 | // and if needed, atomically updating the field `obj.field` in the |
| 544 | // object `obj` holding this reference after marking (contrary to |
| 545 | // ReadBarrierMarkSlowPathX86_64 above, which never tries to update |
| 546 | // `obj.field`). |
| 547 | // |
| 548 | // This means that after the execution of this slow path, both `ref` |
| 549 | // and `obj.field` will be up-to-date; i.e., after the flip, both will |
| 550 | // hold the same to-space reference (unless another thread installed |
| 551 | // another object reference (different from `ref`) in `obj.field`). |
| 552 | class ReadBarrierMarkAndUpdateFieldSlowPathX86_64 : public SlowPathCode { |
| 553 | public: |
| 554 | ReadBarrierMarkAndUpdateFieldSlowPathX86_64(HInstruction* instruction, |
| 555 | Location ref, |
| 556 | CpuRegister obj, |
| 557 | const Address& field_addr, |
| 558 | bool unpoison_ref_before_marking, |
| 559 | CpuRegister temp1, |
| 560 | CpuRegister temp2) |
| 561 | : SlowPathCode(instruction), |
| 562 | ref_(ref), |
| 563 | obj_(obj), |
| 564 | field_addr_(field_addr), |
| 565 | unpoison_ref_before_marking_(unpoison_ref_before_marking), |
| 566 | temp1_(temp1), |
| 567 | temp2_(temp2) { |
| 568 | DCHECK(kEmitCompilerReadBarrier); |
| 569 | } |
| 570 | |
| 571 | const char* GetDescription() const OVERRIDE { |
| 572 | return "ReadBarrierMarkAndUpdateFieldSlowPathX86_64"; |
| 573 | } |
| 574 | |
| 575 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 576 | LocationSummary* locations = instruction_->GetLocations(); |
| 577 | CpuRegister ref_cpu_reg = ref_.AsRegister<CpuRegister>(); |
| 578 | Register ref_reg = ref_cpu_reg.AsRegister(); |
| 579 | DCHECK(locations->CanCall()); |
| 580 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(ref_reg)) << ref_reg; |
| 581 | // This slow path is only used by the UnsafeCASObject intrinsic. |
| 582 | DCHECK((instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified())) |
| 583 | << "Unexpected instruction in read barrier marking and field updating slow path: " |
| 584 | << instruction_->DebugName(); |
| 585 | DCHECK(instruction_->GetLocations()->Intrinsified()); |
| 586 | DCHECK_EQ(instruction_->AsInvoke()->GetIntrinsic(), Intrinsics::kUnsafeCASObject); |
| 587 | |
| 588 | __ Bind(GetEntryLabel()); |
| 589 | if (unpoison_ref_before_marking_) { |
| 590 | // Object* ref = ref_addr->AsMirrorPtr() |
| 591 | __ MaybeUnpoisonHeapReference(ref_cpu_reg); |
| 592 | } |
| 593 | |
| 594 | // Save the old (unpoisoned) reference. |
| 595 | __ movl(temp1_, ref_cpu_reg); |
| 596 | |
| 597 | // No need to save live registers; it's taken care of by the |
| 598 | // entrypoint. Also, there is no need to update the stack mask, |
| 599 | // as this runtime call will not trigger a garbage collection. |
| 600 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
| 601 | DCHECK_NE(ref_reg, RSP); |
| 602 | DCHECK(0 <= ref_reg && ref_reg < kNumberOfCpuRegisters) << ref_reg; |
| 603 | // "Compact" slow path, saving two moves. |
| 604 | // |
| 605 | // Instead of using the standard runtime calling convention (input |
| 606 | // and output in R0): |
| 607 | // |
| 608 | // RDI <- ref |
| 609 | // RAX <- ReadBarrierMark(RDI) |
| 610 | // ref <- RAX |
| 611 | // |
| 612 | // we just use rX (the register containing `ref`) as input and output |
| 613 | // of a dedicated entrypoint: |
| 614 | // |
| 615 | // rX <- ReadBarrierMarkRegX(rX) |
| 616 | // |
| 617 | int32_t entry_point_offset = |
| 618 | CodeGenerator::GetReadBarrierMarkEntryPointsOffset<kX86_64PointerSize>(ref_reg); |
| 619 | // This runtime call does not require a stack map. |
| 620 | x86_64_codegen->InvokeRuntimeWithoutRecordingPcInfo(entry_point_offset, instruction_, this); |
| 621 | |
| 622 | // If the new reference is different from the old reference, |
| 623 | // update the field in the holder (`*field_addr`). |
| 624 | // |
| 625 | // Note that this field could also hold a different object, if |
| 626 | // another thread had concurrently changed it. In that case, the |
| 627 | // LOCK CMPXCHGL instruction in the compare-and-set (CAS) |
| 628 | // operation below would abort the CAS, leaving the field as-is. |
| 629 | NearLabel done; |
| 630 | __ cmpl(temp1_, ref_cpu_reg); |
| 631 | __ j(kEqual, &done); |
| 632 | |
| 633 | // Update the the holder's field atomically. This may fail if |
| 634 | // mutator updates before us, but it's OK. This is achived |
| 635 | // using a strong compare-and-set (CAS) operation with relaxed |
| 636 | // memory synchronization ordering, where the expected value is |
| 637 | // the old reference and the desired value is the new reference. |
| 638 | // This operation is implemented with a 32-bit LOCK CMPXLCHG |
| 639 | // instruction, which requires the expected value (the old |
| 640 | // reference) to be in EAX. Save RAX beforehand, and move the |
| 641 | // expected value (stored in `temp1_`) into EAX. |
| 642 | __ movq(temp2_, CpuRegister(RAX)); |
| 643 | __ movl(CpuRegister(RAX), temp1_); |
| 644 | |
| 645 | // Convenience aliases. |
| 646 | CpuRegister base = obj_; |
| 647 | CpuRegister expected = CpuRegister(RAX); |
| 648 | CpuRegister value = ref_cpu_reg; |
| 649 | |
| 650 | bool base_equals_value = (base.AsRegister() == value.AsRegister()); |
| 651 | Register value_reg = ref_reg; |
| 652 | if (kPoisonHeapReferences) { |
| 653 | if (base_equals_value) { |
| 654 | // If `base` and `value` are the same register location, move |
| 655 | // `value_reg` to a temporary register. This way, poisoning |
| 656 | // `value_reg` won't invalidate `base`. |
| 657 | value_reg = temp1_.AsRegister(); |
| 658 | __ movl(CpuRegister(value_reg), base); |
| 659 | } |
| 660 | |
| 661 | // Check that the register allocator did not assign the location |
| 662 | // of `expected` (RAX) to `value` nor to `base`, so that heap |
| 663 | // poisoning (when enabled) works as intended below. |
| 664 | // - If `value` were equal to `expected`, both references would |
| 665 | // be poisoned twice, meaning they would not be poisoned at |
| 666 | // all, as heap poisoning uses address negation. |
| 667 | // - If `base` were equal to `expected`, poisoning `expected` |
| 668 | // would invalidate `base`. |
| 669 | DCHECK_NE(value_reg, expected.AsRegister()); |
| 670 | DCHECK_NE(base.AsRegister(), expected.AsRegister()); |
| 671 | |
| 672 | __ PoisonHeapReference(expected); |
| 673 | __ PoisonHeapReference(CpuRegister(value_reg)); |
| 674 | } |
| 675 | |
| 676 | __ LockCmpxchgl(field_addr_, CpuRegister(value_reg)); |
| 677 | |
| 678 | // If heap poisoning is enabled, we need to unpoison the values |
| 679 | // that were poisoned earlier. |
| 680 | if (kPoisonHeapReferences) { |
| 681 | if (base_equals_value) { |
| 682 | // `value_reg` has been moved to a temporary register, no need |
| 683 | // to unpoison it. |
| 684 | } else { |
| 685 | __ UnpoisonHeapReference(CpuRegister(value_reg)); |
| 686 | } |
| 687 | // No need to unpoison `expected` (RAX), as it is be overwritten below. |
| 688 | } |
| 689 | |
| 690 | // Restore RAX. |
| 691 | __ movq(CpuRegister(RAX), temp2_); |
| 692 | |
| 693 | __ Bind(&done); |
| 694 | __ jmp(GetExitLabel()); |
| 695 | } |
| 696 | |
| 697 | private: |
| 698 | // The location (register) of the marked object reference. |
| 699 | const Location ref_; |
| 700 | // The register containing the object holding the marked object reference field. |
| 701 | const CpuRegister obj_; |
| 702 | // The address of the marked reference field. The base of this address must be `obj_`. |
| 703 | const Address field_addr_; |
| 704 | |
| 705 | // Should the reference in `ref_` be unpoisoned prior to marking it? |
| 706 | const bool unpoison_ref_before_marking_; |
| 707 | |
| 708 | const CpuRegister temp1_; |
| 709 | const CpuRegister temp2_; |
| 710 | |
| 711 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierMarkAndUpdateFieldSlowPathX86_64); |
| 712 | }; |
| 713 | |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 714 | // Slow path generating a read barrier for a heap reference. |
| 715 | class ReadBarrierForHeapReferenceSlowPathX86_64 : public SlowPathCode { |
| 716 | public: |
| 717 | ReadBarrierForHeapReferenceSlowPathX86_64(HInstruction* instruction, |
| 718 | Location out, |
| 719 | Location ref, |
| 720 | Location obj, |
| 721 | uint32_t offset, |
| 722 | Location index) |
| David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 723 | : SlowPathCode(instruction), |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 724 | out_(out), |
| 725 | ref_(ref), |
| 726 | obj_(obj), |
| 727 | offset_(offset), |
| 728 | index_(index) { |
| 729 | DCHECK(kEmitCompilerReadBarrier); |
| 730 | // If `obj` is equal to `out` or `ref`, it means the initial |
| 731 | // object has been overwritten by (or after) the heap object |
| 732 | // reference load to be instrumented, e.g.: |
| 733 | // |
| 734 | // __ movl(out, Address(out, offset)); |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 735 | // codegen_->GenerateReadBarrierSlow(instruction, out_loc, out_loc, out_loc, offset); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 736 | // |
| 737 | // In that case, we have lost the information about the original |
| 738 | // object, and the emitted read barrier cannot work properly. |
| 739 | DCHECK(!obj.Equals(out)) << "obj=" << obj << " out=" << out; |
| 740 | DCHECK(!obj.Equals(ref)) << "obj=" << obj << " ref=" << ref; |
| 741 | } |
| 742 | |
| 743 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 744 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
| 745 | LocationSummary* locations = instruction_->GetLocations(); |
| 746 | CpuRegister reg_out = out_.AsRegister<CpuRegister>(); |
| 747 | DCHECK(locations->CanCall()); |
| 748 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg_out.AsRegister())) << out_; |
| Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 749 | DCHECK(instruction_->IsInstanceFieldGet() || |
| 750 | instruction_->IsStaticFieldGet() || |
| 751 | instruction_->IsArrayGet() || |
| 752 | instruction_->IsInstanceOf() || |
| 753 | instruction_->IsCheckCast() || |
| Andreas Gampe | d9911ee | 2017-03-27 13:27:24 -0700 | [diff] [blame] | 754 | (instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified())) |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 755 | << "Unexpected instruction in read barrier for heap reference slow path: " |
| 756 | << instruction_->DebugName(); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 757 | |
| 758 | __ Bind(GetEntryLabel()); |
| 759 | SaveLiveRegisters(codegen, locations); |
| 760 | |
| 761 | // We may have to change the index's value, but as `index_` is a |
| 762 | // constant member (like other "inputs" of this slow path), |
| 763 | // introduce a copy of it, `index`. |
| 764 | Location index = index_; |
| 765 | if (index_.IsValid()) { |
| Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 766 | // Handle `index_` for HArrayGet and UnsafeGetObject/UnsafeGetObjectVolatile intrinsics. |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 767 | if (instruction_->IsArrayGet()) { |
| 768 | // Compute real offset and store it in index_. |
| 769 | Register index_reg = index_.AsRegister<CpuRegister>().AsRegister(); |
| 770 | DCHECK(locations->GetLiveRegisters()->ContainsCoreRegister(index_reg)); |
| 771 | if (codegen->IsCoreCalleeSaveRegister(index_reg)) { |
| 772 | // We are about to change the value of `index_reg` (see the |
| 773 | // calls to art::x86_64::X86_64Assembler::shll and |
| 774 | // art::x86_64::X86_64Assembler::AddImmediate below), but it |
| 775 | // has not been saved by the previous call to |
| 776 | // art::SlowPathCode::SaveLiveRegisters, as it is a |
| 777 | // callee-save register -- |
| 778 | // art::SlowPathCode::SaveLiveRegisters does not consider |
| 779 | // callee-save registers, as it has been designed with the |
| 780 | // assumption that callee-save registers are supposed to be |
| 781 | // handled by the called function. So, as a callee-save |
| 782 | // register, `index_reg` _would_ eventually be saved onto |
| 783 | // the stack, but it would be too late: we would have |
| 784 | // changed its value earlier. Therefore, we manually save |
| 785 | // it here into another freely available register, |
| 786 | // `free_reg`, chosen of course among the caller-save |
| 787 | // registers (as a callee-save `free_reg` register would |
| 788 | // exhibit the same problem). |
| 789 | // |
| 790 | // Note we could have requested a temporary register from |
| 791 | // the register allocator instead; but we prefer not to, as |
| 792 | // this is a slow path, and we know we can find a |
| 793 | // caller-save register that is available. |
| 794 | Register free_reg = FindAvailableCallerSaveRegister(codegen).AsRegister(); |
| 795 | __ movl(CpuRegister(free_reg), CpuRegister(index_reg)); |
| 796 | index_reg = free_reg; |
| 797 | index = Location::RegisterLocation(index_reg); |
| 798 | } else { |
| 799 | // The initial register stored in `index_` has already been |
| 800 | // saved in the call to art::SlowPathCode::SaveLiveRegisters |
| 801 | // (as it is not a callee-save register), so we can freely |
| 802 | // use it. |
| 803 | } |
| 804 | // Shifting the index value contained in `index_reg` by the |
| 805 | // scale factor (2) cannot overflow in practice, as the |
| 806 | // runtime is unable to allocate object arrays with a size |
| 807 | // larger than 2^26 - 1 (that is, 2^28 - 4 bytes). |
| 808 | __ shll(CpuRegister(index_reg), Immediate(TIMES_4)); |
| 809 | static_assert( |
| 810 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 811 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 812 | __ AddImmediate(CpuRegister(index_reg), Immediate(offset_)); |
| 813 | } else { |
| Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 814 | // In the case of the UnsafeGetObject/UnsafeGetObjectVolatile |
| 815 | // intrinsics, `index_` is not shifted by a scale factor of 2 |
| 816 | // (as in the case of ArrayGet), as it is actually an offset |
| 817 | // to an object field within an object. |
| 818 | DCHECK(instruction_->IsInvoke()) << instruction_->DebugName(); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 819 | DCHECK(instruction_->GetLocations()->Intrinsified()); |
| 820 | DCHECK((instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObject) || |
| 821 | (instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObjectVolatile)) |
| 822 | << instruction_->AsInvoke()->GetIntrinsic(); |
| 823 | DCHECK_EQ(offset_, 0U); |
| 824 | DCHECK(index_.IsRegister()); |
| 825 | } |
| 826 | } |
| 827 | |
| 828 | // We're moving two or three locations to locations that could |
| 829 | // overlap, so we need a parallel move resolver. |
| 830 | InvokeRuntimeCallingConvention calling_convention; |
| 831 | HParallelMove parallel_move(codegen->GetGraph()->GetArena()); |
| 832 | parallel_move.AddMove(ref_, |
| 833 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| 834 | Primitive::kPrimNot, |
| 835 | nullptr); |
| 836 | parallel_move.AddMove(obj_, |
| 837 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 838 | Primitive::kPrimNot, |
| 839 | nullptr); |
| 840 | if (index.IsValid()) { |
| 841 | parallel_move.AddMove(index, |
| 842 | Location::RegisterLocation(calling_convention.GetRegisterAt(2)), |
| 843 | Primitive::kPrimInt, |
| 844 | nullptr); |
| 845 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 846 | } else { |
| 847 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 848 | __ movl(CpuRegister(calling_convention.GetRegisterAt(2)), Immediate(offset_)); |
| 849 | } |
| Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 850 | x86_64_codegen->InvokeRuntime(kQuickReadBarrierSlow, |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 851 | instruction_, |
| 852 | instruction_->GetDexPc(), |
| 853 | this); |
| 854 | CheckEntrypointTypes< |
| 855 | kQuickReadBarrierSlow, mirror::Object*, mirror::Object*, mirror::Object*, uint32_t>(); |
| 856 | x86_64_codegen->Move(out_, Location::RegisterLocation(RAX)); |
| 857 | |
| 858 | RestoreLiveRegisters(codegen, locations); |
| 859 | __ jmp(GetExitLabel()); |
| 860 | } |
| 861 | |
| 862 | const char* GetDescription() const OVERRIDE { |
| 863 | return "ReadBarrierForHeapReferenceSlowPathX86_64"; |
| 864 | } |
| 865 | |
| 866 | private: |
| 867 | CpuRegister FindAvailableCallerSaveRegister(CodeGenerator* codegen) { |
| 868 | size_t ref = static_cast<int>(ref_.AsRegister<CpuRegister>().AsRegister()); |
| 869 | size_t obj = static_cast<int>(obj_.AsRegister<CpuRegister>().AsRegister()); |
| 870 | for (size_t i = 0, e = codegen->GetNumberOfCoreRegisters(); i < e; ++i) { |
| 871 | if (i != ref && i != obj && !codegen->IsCoreCalleeSaveRegister(i)) { |
| 872 | return static_cast<CpuRegister>(i); |
| 873 | } |
| 874 | } |
| 875 | // We shall never fail to find a free caller-save register, as |
| 876 | // there are more than two core caller-save registers on x86-64 |
| 877 | // (meaning it is possible to find one which is different from |
| 878 | // `ref` and `obj`). |
| 879 | DCHECK_GT(codegen->GetNumberOfCoreCallerSaveRegisters(), 2u); |
| 880 | LOG(FATAL) << "Could not find a free caller-save register"; |
| 881 | UNREACHABLE(); |
| 882 | } |
| 883 | |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 884 | const Location out_; |
| 885 | const Location ref_; |
| 886 | const Location obj_; |
| 887 | const uint32_t offset_; |
| 888 | // An additional location containing an index to an array. |
| 889 | // Only used for HArrayGet and the UnsafeGetObject & |
| 890 | // UnsafeGetObjectVolatile intrinsics. |
| 891 | const Location index_; |
| 892 | |
| 893 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForHeapReferenceSlowPathX86_64); |
| 894 | }; |
| 895 | |
| 896 | // Slow path generating a read barrier for a GC root. |
| 897 | class ReadBarrierForRootSlowPathX86_64 : public SlowPathCode { |
| 898 | public: |
| 899 | ReadBarrierForRootSlowPathX86_64(HInstruction* instruction, Location out, Location root) |
| David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 900 | : SlowPathCode(instruction), out_(out), root_(root) { |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 901 | DCHECK(kEmitCompilerReadBarrier); |
| 902 | } |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 903 | |
| 904 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 905 | LocationSummary* locations = instruction_->GetLocations(); |
| 906 | DCHECK(locations->CanCall()); |
| 907 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(out_.reg())); |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 908 | DCHECK(instruction_->IsLoadClass() || instruction_->IsLoadString()) |
| 909 | << "Unexpected instruction in read barrier for GC root slow path: " |
| 910 | << instruction_->DebugName(); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 911 | |
| 912 | __ Bind(GetEntryLabel()); |
| 913 | SaveLiveRegisters(codegen, locations); |
| 914 | |
| 915 | InvokeRuntimeCallingConvention calling_convention; |
| 916 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
| 917 | x86_64_codegen->Move(Location::RegisterLocation(calling_convention.GetRegisterAt(0)), root_); |
| Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 918 | x86_64_codegen->InvokeRuntime(kQuickReadBarrierForRootSlow, |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 919 | instruction_, |
| 920 | instruction_->GetDexPc(), |
| 921 | this); |
| 922 | CheckEntrypointTypes<kQuickReadBarrierForRootSlow, mirror::Object*, GcRoot<mirror::Object>*>(); |
| 923 | x86_64_codegen->Move(out_, Location::RegisterLocation(RAX)); |
| 924 | |
| 925 | RestoreLiveRegisters(codegen, locations); |
| 926 | __ jmp(GetExitLabel()); |
| 927 | } |
| 928 | |
| 929 | const char* GetDescription() const OVERRIDE { return "ReadBarrierForRootSlowPathX86_64"; } |
| 930 | |
| 931 | private: |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 932 | const Location out_; |
| 933 | const Location root_; |
| 934 | |
| 935 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForRootSlowPathX86_64); |
| 936 | }; |
| 937 | |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 938 | #undef __ |
| Roland Levillain | 7cbd27f | 2016-08-11 23:53:33 +0100 | [diff] [blame] | 939 | // NOLINT on __ macro to suppress wrong warning/fix (misc-macro-parentheses) from clang-tidy. |
| 940 | #define __ down_cast<X86_64Assembler*>(GetAssembler())-> // NOLINT |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 941 | |
| Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 942 | inline Condition X86_64IntegerCondition(IfCondition cond) { |
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 943 | switch (cond) { |
| 944 | case kCondEQ: return kEqual; |
| 945 | case kCondNE: return kNotEqual; |
| 946 | case kCondLT: return kLess; |
| 947 | case kCondLE: return kLessEqual; |
| 948 | case kCondGT: return kGreater; |
| 949 | case kCondGE: return kGreaterEqual; |
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 950 | case kCondB: return kBelow; |
| 951 | case kCondBE: return kBelowEqual; |
| 952 | case kCondA: return kAbove; |
| 953 | case kCondAE: return kAboveEqual; |
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 954 | } |
| Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 955 | LOG(FATAL) << "Unreachable"; |
| 956 | UNREACHABLE(); |
| 957 | } |
| 958 | |
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 959 | // Maps FP condition to x86_64 name. |
| Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 960 | inline Condition X86_64FPCondition(IfCondition cond) { |
| 961 | switch (cond) { |
| 962 | case kCondEQ: return kEqual; |
| 963 | case kCondNE: return kNotEqual; |
| 964 | case kCondLT: return kBelow; |
| 965 | case kCondLE: return kBelowEqual; |
| 966 | case kCondGT: return kAbove; |
| 967 | case kCondGE: return kAboveEqual; |
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 968 | default: break; // should not happen |
| Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 969 | }; |
| 970 | LOG(FATAL) << "Unreachable"; |
| 971 | UNREACHABLE(); |
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 972 | } |
| 973 | |
| Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 974 | HInvokeStaticOrDirect::DispatchInfo CodeGeneratorX86_64::GetSupportedInvokeStaticOrDirectDispatch( |
| 975 | const HInvokeStaticOrDirect::DispatchInfo& desired_dispatch_info, |
| Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 976 | HInvokeStaticOrDirect* invoke ATTRIBUTE_UNUSED) { |
| Nicolas Geoffray | c1a42cf | 2016-12-18 15:52:36 +0000 | [diff] [blame] | 977 | return desired_dispatch_info; |
| Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 978 | } |
| 979 | |
| Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 980 | void CodeGeneratorX86_64::GenerateStaticOrDirectCall( |
| 981 | HInvokeStaticOrDirect* invoke, Location temp, SlowPathCode* slow_path) { |
| Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 982 | // All registers are assumed to be correctly set up. |
| Vladimir Marko | 4ee8e29 | 2017-06-02 15:39:30 +0000 | [diff] [blame] | 983 | |
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 984 | Location callee_method = temp; // For all kinds except kRecursive, callee will be in temp. |
| 985 | switch (invoke->GetMethodLoadKind()) { |
| Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 986 | case HInvokeStaticOrDirect::MethodLoadKind::kStringInit: { |
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 987 | // temp = thread->string_init_entrypoint |
| Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 988 | uint32_t offset = |
| 989 | GetThreadOffset<kX86_64PointerSize>(invoke->GetStringInitEntryPoint()).Int32Value(); |
| 990 | __ gs()->movq(temp.AsRegister<CpuRegister>(), Address::Absolute(offset, /* no_rip */ true)); |
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 991 | break; |
| Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 992 | } |
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 993 | case HInvokeStaticOrDirect::MethodLoadKind::kRecursive: |
| Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 994 | callee_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 995 | break; |
| Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 996 | case HInvokeStaticOrDirect::MethodLoadKind::kBootImageLinkTimePcRelative: |
| 997 | DCHECK(GetCompilerOptions().IsBootImage()); |
| 998 | __ leal(temp.AsRegister<CpuRegister>(), |
| 999 | Address::Absolute(kDummy32BitOffset, /* no_rip */ false)); |
| 1000 | RecordBootMethodPatch(invoke); |
| 1001 | break; |
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 1002 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddress: |
| Vladimir Marko | 2d73f33 | 2017-03-16 15:55:49 +0000 | [diff] [blame] | 1003 | Load64BitValue(temp.AsRegister<CpuRegister>(), invoke->GetMethodAddress()); |
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 1004 | break; |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 1005 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCachePcRelative: { |
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 1006 | __ movq(temp.AsRegister<CpuRegister>(), |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 1007 | Address::Absolute(kDummy32BitOffset, /* no_rip */ false)); |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 1008 | // Bind a new fixup label at the end of the "movl" insn. |
| 1009 | uint32_t offset = invoke->GetDexCacheArrayOffset(); |
| Nicolas Geoffray | 5d37c15 | 2017-01-12 13:25:19 +0000 | [diff] [blame] | 1010 | __ Bind(NewPcRelativeDexCacheArrayPatch(invoke->GetDexFileForPcRelativeDexCache(), offset)); |
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 1011 | break; |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 1012 | } |
| Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 1013 | case HInvokeStaticOrDirect::MethodLoadKind::kRuntimeCall: { |
| 1014 | GenerateInvokeStaticOrDirectRuntimeCall(invoke, temp, slow_path); |
| 1015 | return; // No code pointer retrieval; the runtime performs the call directly. |
| Vladimir Marko | 9b688a0 | 2015-05-06 14:12:42 +0100 | [diff] [blame] | 1016 | } |
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 1017 | } |
| 1018 | |
| 1019 | switch (invoke->GetCodePtrLocation()) { |
| 1020 | case HInvokeStaticOrDirect::CodePtrLocation::kCallSelf: |
| 1021 | __ call(&frame_entry_label_); |
| 1022 | break; |
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 1023 | case HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod: |
| 1024 | // (callee_method + offset_of_quick_compiled_code)() |
| 1025 | __ call(Address(callee_method.AsRegister<CpuRegister>(), |
| 1026 | ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
| Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 1027 | kX86_64PointerSize).SizeValue())); |
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 1028 | break; |
| Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 1029 | } |
| Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 1030 | RecordPcInfo(invoke, invoke->GetDexPc(), slow_path); |
| Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 1031 | |
| 1032 | DCHECK(!IsLeafMethod()); |
| Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 1033 | } |
| 1034 | |
| Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 1035 | void CodeGeneratorX86_64::GenerateVirtualCall( |
| 1036 | HInvokeVirtual* invoke, Location temp_in, SlowPathCode* slow_path) { |
| Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 1037 | CpuRegister temp = temp_in.AsRegister<CpuRegister>(); |
| 1038 | size_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| 1039 | invoke->GetVTableIndex(), kX86_64PointerSize).SizeValue(); |
| Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 1040 | |
| 1041 | // Use the calling convention instead of the location of the receiver, as |
| 1042 | // intrinsics may have put the receiver in a different register. In the intrinsics |
| 1043 | // slow path, the arguments have been moved to the right place, so here we are |
| 1044 | // guaranteed that the receiver is the first register of the calling convention. |
| 1045 | InvokeDexCallingConvention calling_convention; |
| 1046 | Register receiver = calling_convention.GetRegisterAt(0); |
| 1047 | |
| Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 1048 | size_t class_offset = mirror::Object::ClassOffset().SizeValue(); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 1049 | // /* HeapReference<Class> */ temp = receiver->klass_ |
| Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 1050 | __ movl(temp, Address(CpuRegister(receiver), class_offset)); |
| Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 1051 | MaybeRecordImplicitNullCheck(invoke); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 1052 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 1053 | // emit a read barrier for the previous class reference load. |
| 1054 | // However this is not required in practice, as this is an |
| 1055 | // intermediate/temporary reference and because the current |
| 1056 | // concurrent copying collector keeps the from-space memory |
| 1057 | // intact/accessible until the end of the marking phase (the |
| 1058 | // concurrent copying collector may not in the future). |
| Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 1059 | __ MaybeUnpoisonHeapReference(temp); |
| 1060 | // temp = temp->GetMethodAt(method_offset); |
| 1061 | __ movq(temp, Address(temp, method_offset)); |
| 1062 | // call temp->GetEntryPoint(); |
| 1063 | __ call(Address(temp, ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
| Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 1064 | kX86_64PointerSize).SizeValue())); |
| Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 1065 | RecordPcInfo(invoke, invoke->GetDexPc(), slow_path); |
| Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 1066 | } |
| 1067 | |
| Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 1068 | void CodeGeneratorX86_64::RecordBootMethodPatch(HInvokeStaticOrDirect* invoke) { |
| 1069 | boot_image_method_patches_.emplace_back(*invoke->GetTargetMethod().dex_file, |
| 1070 | invoke->GetTargetMethod().dex_method_index); |
| 1071 | __ Bind(&boot_image_method_patches_.back().label); |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 1072 | } |
| 1073 | |
| Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 1074 | void CodeGeneratorX86_64::RecordBootTypePatch(HLoadClass* load_class) { |
| 1075 | boot_image_type_patches_.emplace_back(load_class->GetDexFile(), |
| 1076 | load_class->GetTypeIndex().index_); |
| 1077 | __ Bind(&boot_image_type_patches_.back().label); |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 1078 | } |
| 1079 | |
| Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 1080 | Label* CodeGeneratorX86_64::NewTypeBssEntryPatch(HLoadClass* load_class) { |
| Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 1081 | type_bss_entry_patches_.emplace_back(load_class->GetDexFile(), load_class->GetTypeIndex().index_); |
| 1082 | return &type_bss_entry_patches_.back().label; |
| Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 1083 | } |
| 1084 | |
| Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 1085 | void CodeGeneratorX86_64::RecordBootStringPatch(HLoadString* load_string) { |
| 1086 | DCHECK(GetCompilerOptions().IsBootImage()); |
| 1087 | string_patches_.emplace_back(load_string->GetDexFile(), load_string->GetStringIndex().index_); |
| 1088 | __ Bind(&string_patches_.back().label); |
| 1089 | } |
| 1090 | |
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 1091 | Label* CodeGeneratorX86_64::NewStringBssEntryPatch(HLoadString* load_string) { |
| 1092 | DCHECK(!GetCompilerOptions().IsBootImage()); |
| Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 1093 | string_patches_.emplace_back(load_string->GetDexFile(), load_string->GetStringIndex().index_); |
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 1094 | return &string_patches_.back().label; |
| 1095 | } |
| 1096 | |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 1097 | Label* CodeGeneratorX86_64::NewPcRelativeDexCacheArrayPatch(const DexFile& dex_file, |
| 1098 | uint32_t element_offset) { |
| 1099 | // Add a patch entry and return the label. |
| 1100 | pc_relative_dex_cache_patches_.emplace_back(dex_file, element_offset); |
| 1101 | return &pc_relative_dex_cache_patches_.back().label; |
| 1102 | } |
| 1103 | |
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 1104 | // The label points to the end of the "movl" or another instruction but the literal offset |
| 1105 | // for method patch needs to point to the embedded constant which occupies the last 4 bytes. |
| 1106 | constexpr uint32_t kLabelPositionToLiteralOffsetAdjustment = 4u; |
| 1107 | |
| 1108 | template <LinkerPatch (*Factory)(size_t, const DexFile*, uint32_t, uint32_t)> |
| 1109 | inline void CodeGeneratorX86_64::EmitPcRelativeLinkerPatches( |
| 1110 | const ArenaDeque<PatchInfo<Label>>& infos, |
| 1111 | ArenaVector<LinkerPatch>* linker_patches) { |
| 1112 | for (const PatchInfo<Label>& info : infos) { |
| 1113 | uint32_t literal_offset = info.label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
| 1114 | linker_patches->push_back( |
| 1115 | Factory(literal_offset, &info.dex_file, info.label.Position(), info.index)); |
| 1116 | } |
| 1117 | } |
| 1118 | |
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 1119 | void CodeGeneratorX86_64::EmitLinkerPatches(ArenaVector<LinkerPatch>* linker_patches) { |
| 1120 | DCHECK(linker_patches->empty()); |
| 1121 | size_t size = |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 1122 | pc_relative_dex_cache_patches_.size() + |
| Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 1123 | boot_image_method_patches_.size() + |
| Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 1124 | boot_image_type_patches_.size() + |
| Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 1125 | type_bss_entry_patches_.size() + |
| 1126 | string_patches_.size(); |
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 1127 | linker_patches->reserve(size); |
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 1128 | EmitPcRelativeLinkerPatches<LinkerPatch::DexCacheArrayPatch>(pc_relative_dex_cache_patches_, |
| 1129 | linker_patches); |
| Vladimir Marko | 764d454 | 2017-05-16 10:31:41 +0100 | [diff] [blame] | 1130 | if (GetCompilerOptions().IsBootImage()) { |
| Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 1131 | EmitPcRelativeLinkerPatches<LinkerPatch::RelativeMethodPatch>(boot_image_method_patches_, |
| 1132 | linker_patches); |
| Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 1133 | EmitPcRelativeLinkerPatches<LinkerPatch::RelativeTypePatch>(boot_image_type_patches_, |
| 1134 | linker_patches); |
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 1135 | EmitPcRelativeLinkerPatches<LinkerPatch::RelativeStringPatch>(string_patches_, linker_patches); |
| Vladimir Marko | 764d454 | 2017-05-16 10:31:41 +0100 | [diff] [blame] | 1136 | } else { |
| Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 1137 | DCHECK(boot_image_method_patches_.empty()); |
| Vladimir Marko | 764d454 | 2017-05-16 10:31:41 +0100 | [diff] [blame] | 1138 | DCHECK(boot_image_type_patches_.empty()); |
| 1139 | EmitPcRelativeLinkerPatches<LinkerPatch::StringBssEntryPatch>(string_patches_, linker_patches); |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 1140 | } |
| Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 1141 | EmitPcRelativeLinkerPatches<LinkerPatch::TypeBssEntryPatch>(type_bss_entry_patches_, |
| 1142 | linker_patches); |
| 1143 | DCHECK_EQ(size, linker_patches->size()); |
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 1144 | } |
| 1145 | |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1146 | void CodeGeneratorX86_64::DumpCoreRegister(std::ostream& stream, int reg) const { |
| David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 1147 | stream << Register(reg); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1148 | } |
| 1149 | |
| 1150 | void CodeGeneratorX86_64::DumpFloatingPointRegister(std::ostream& stream, int reg) const { |
| David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 1151 | stream << FloatRegister(reg); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1152 | } |
| 1153 | |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1154 | size_t CodeGeneratorX86_64::SaveCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 1155 | __ movq(Address(CpuRegister(RSP), stack_index), CpuRegister(reg_id)); |
| 1156 | return kX86_64WordSize; |
| Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 1157 | } |
| 1158 | |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1159 | size_t CodeGeneratorX86_64::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 1160 | __ movq(CpuRegister(reg_id), Address(CpuRegister(RSP), stack_index)); |
| 1161 | return kX86_64WordSize; |
| 1162 | } |
| 1163 | |
| 1164 | 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] | 1165 | if (GetGraph()->HasSIMD()) { |
| Aart Bik | 5576f37 | 2017-03-23 16:17:37 -0700 | [diff] [blame] | 1166 | __ movups(Address(CpuRegister(RSP), stack_index), XmmRegister(reg_id)); |
| Aart Bik | b13c65b | 2017-03-21 20:14:07 -0700 | [diff] [blame] | 1167 | } else { |
| 1168 | __ movsd(Address(CpuRegister(RSP), stack_index), XmmRegister(reg_id)); |
| 1169 | } |
| 1170 | return GetFloatingPointSpillSlotSize(); |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1171 | } |
| 1172 | |
| 1173 | 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] | 1174 | if (GetGraph()->HasSIMD()) { |
| Aart Bik | 5576f37 | 2017-03-23 16:17:37 -0700 | [diff] [blame] | 1175 | __ movups(XmmRegister(reg_id), Address(CpuRegister(RSP), stack_index)); |
| Aart Bik | b13c65b | 2017-03-21 20:14:07 -0700 | [diff] [blame] | 1176 | } else { |
| 1177 | __ movsd(XmmRegister(reg_id), Address(CpuRegister(RSP), stack_index)); |
| 1178 | } |
| 1179 | return GetFloatingPointSpillSlotSize(); |
| Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 1180 | } |
| 1181 | |
| Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1182 | void CodeGeneratorX86_64::InvokeRuntime(QuickEntrypointEnum entrypoint, |
| 1183 | HInstruction* instruction, |
| 1184 | uint32_t dex_pc, |
| 1185 | SlowPathCode* slow_path) { |
| Alexandre Rames | 91a6516 | 2016-09-19 13:54:30 +0100 | [diff] [blame] | 1186 | ValidateInvokeRuntime(entrypoint, instruction, slow_path); |
| Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 1187 | GenerateInvokeRuntime(GetThreadOffset<kX86_64PointerSize>(entrypoint).Int32Value()); |
| 1188 | if (EntrypointRequiresStackMap(entrypoint)) { |
| 1189 | RecordPcInfo(instruction, dex_pc, slow_path); |
| 1190 | } |
| Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 1191 | } |
| 1192 | |
| Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 1193 | void CodeGeneratorX86_64::InvokeRuntimeWithoutRecordingPcInfo(int32_t entry_point_offset, |
| 1194 | HInstruction* instruction, |
| 1195 | SlowPathCode* slow_path) { |
| 1196 | ValidateInvokeRuntimeWithoutRecordingPcInfo(instruction, slow_path); |
| Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 1197 | GenerateInvokeRuntime(entry_point_offset); |
| 1198 | } |
| 1199 | |
| 1200 | void CodeGeneratorX86_64::GenerateInvokeRuntime(int32_t entry_point_offset) { |
| Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 1201 | __ gs()->call(Address::Absolute(entry_point_offset, /* no_rip */ true)); |
| 1202 | } |
| 1203 | |
| Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1204 | static constexpr int kNumberOfCpuRegisterPairs = 0; |
| Nicolas Geoffray | 4597b5b | 2015-01-23 21:51:55 +0000 | [diff] [blame] | 1205 | // Use a fake return address register to mimic Quick. |
| 1206 | static constexpr Register kFakeReturnRegister = Register(kLastCpuRegister + 1); |
| Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 1207 | CodeGeneratorX86_64::CodeGeneratorX86_64(HGraph* graph, |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 1208 | const X86_64InstructionSetFeatures& isa_features, |
| 1209 | const CompilerOptions& compiler_options, |
| 1210 | OptimizingCompilerStats* stats) |
| Nicolas Geoffray | 9889396 | 2015-01-21 12:32:32 +0000 | [diff] [blame] | 1211 | : CodeGenerator(graph, |
| 1212 | kNumberOfCpuRegisters, |
| 1213 | kNumberOfFloatRegisters, |
| Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1214 | kNumberOfCpuRegisterPairs, |
| Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 1215 | ComputeRegisterMask(reinterpret_cast<const int*>(kCoreCalleeSaves), |
| 1216 | arraysize(kCoreCalleeSaves)) |
| Nicolas Geoffray | 4597b5b | 2015-01-23 21:51:55 +0000 | [diff] [blame] | 1217 | | (1 << kFakeReturnRegister), |
| Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 1218 | ComputeRegisterMask(reinterpret_cast<const int*>(kFpuCalleeSaves), |
| 1219 | arraysize(kFpuCalleeSaves)), |
| Serban Constantinescu | ecc4366 | 2015-08-13 13:33:12 +0100 | [diff] [blame] | 1220 | compiler_options, |
| 1221 | stats), |
| Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 1222 | block_labels_(nullptr), |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1223 | location_builder_(graph, this), |
| Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 1224 | instruction_visitor_(graph, this), |
| Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 1225 | move_resolver_(graph->GetArena(), this), |
| Vladimir Marko | 93205e3 | 2016-04-13 11:59:46 +0100 | [diff] [blame] | 1226 | assembler_(graph->GetArena()), |
| Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 1227 | isa_features_(isa_features), |
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 1228 | constant_area_start_(0), |
| Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 1229 | pc_relative_dex_cache_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 1230 | boot_image_method_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 1231 | boot_image_type_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 1232 | type_bss_entry_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 1233 | string_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 1234 | jit_string_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 1235 | jit_class_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 1236 | fixups_to_jump_tables_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)) { |
| Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1237 | AddAllocatedRegister(Location::RegisterLocation(kFakeReturnRegister)); |
| 1238 | } |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1239 | |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1240 | InstructionCodeGeneratorX86_64::InstructionCodeGeneratorX86_64(HGraph* graph, |
| 1241 | CodeGeneratorX86_64* codegen) |
| Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 1242 | : InstructionCodeGenerator(graph, codegen), |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1243 | assembler_(codegen->GetAssembler()), |
| 1244 | codegen_(codegen) {} |
| 1245 | |
| David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 1246 | void CodeGeneratorX86_64::SetupBlockedRegisters() const { |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1247 | // Stack register is always reserved. |
| Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 1248 | blocked_core_registers_[RSP] = true; |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1249 | |
| Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 1250 | // Block the register used as TMP. |
| Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 1251 | blocked_core_registers_[TMP] = true; |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1252 | } |
| 1253 | |
| David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1254 | static dwarf::Reg DWARFReg(Register reg) { |
| David Srbecky | 9d8606d | 2015-04-12 09:35:32 +0100 | [diff] [blame] | 1255 | return dwarf::Reg::X86_64Core(static_cast<int>(reg)); |
| David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1256 | } |
| David Srbecky | 9d8606d | 2015-04-12 09:35:32 +0100 | [diff] [blame] | 1257 | |
| David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1258 | static dwarf::Reg DWARFReg(FloatRegister reg) { |
| David Srbecky | 9d8606d | 2015-04-12 09:35:32 +0100 | [diff] [blame] | 1259 | return dwarf::Reg::X86_64Fp(static_cast<int>(reg)); |
| David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1260 | } |
| 1261 | |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1262 | void CodeGeneratorX86_64::GenerateFrameEntry() { |
| David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1263 | __ cfi().SetCurrentCFAOffset(kX86_64WordSize); // return address |
| Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 1264 | __ Bind(&frame_entry_label_); |
| Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 1265 | bool skip_overflow_check = IsLeafMethod() |
| Dave Allison | 648d711 | 2014-07-25 16:15:27 -0700 | [diff] [blame] | 1266 | && !FrameNeedsStackCheck(GetFrameSize(), InstructionSet::kX86_64); |
| Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1267 | DCHECK(GetCompilerOptions().GetImplicitStackOverflowChecks()); |
| Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 1268 | |
| Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1269 | if (!skip_overflow_check) { |
| Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 1270 | __ testq(CpuRegister(RAX), Address( |
| 1271 | CpuRegister(RSP), -static_cast<int32_t>(GetStackOverflowReservedBytes(kX86_64)))); |
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1272 | RecordPcInfo(nullptr, 0); |
| Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 1273 | } |
| Nicolas Geoffray | a26369a | 2015-01-22 08:46:05 +0000 | [diff] [blame] | 1274 | |
| Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1275 | if (HasEmptyFrame()) { |
| 1276 | return; |
| 1277 | } |
| 1278 | |
| Nicolas Geoffray | 9889396 | 2015-01-21 12:32:32 +0000 | [diff] [blame] | 1279 | for (int i = arraysize(kCoreCalleeSaves) - 1; i >= 0; --i) { |
| Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1280 | Register reg = kCoreCalleeSaves[i]; |
| Nicolas Geoffray | 4597b5b | 2015-01-23 21:51:55 +0000 | [diff] [blame] | 1281 | if (allocated_registers_.ContainsCoreRegister(reg)) { |
| Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1282 | __ pushq(CpuRegister(reg)); |
| David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1283 | __ cfi().AdjustCFAOffset(kX86_64WordSize); |
| 1284 | __ cfi().RelOffset(DWARFReg(reg), 0); |
| Nicolas Geoffray | 9889396 | 2015-01-21 12:32:32 +0000 | [diff] [blame] | 1285 | } |
| 1286 | } |
| Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 1287 | |
| David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1288 | int adjust = GetFrameSize() - GetCoreSpillSize(); |
| 1289 | __ subq(CpuRegister(RSP), Immediate(adjust)); |
| 1290 | __ cfi().AdjustCFAOffset(adjust); |
| Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1291 | uint32_t xmm_spill_location = GetFpuSpillStart(); |
| 1292 | size_t xmm_spill_slot_size = GetFloatingPointSpillSlotSize(); |
| Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 1293 | |
| Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1294 | for (int i = arraysize(kFpuCalleeSaves) - 1; i >= 0; --i) { |
| 1295 | if (allocated_registers_.ContainsFloatingPointRegister(kFpuCalleeSaves[i])) { |
| David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1296 | int offset = xmm_spill_location + (xmm_spill_slot_size * i); |
| 1297 | __ movsd(Address(CpuRegister(RSP), offset), XmmRegister(kFpuCalleeSaves[i])); |
| 1298 | __ cfi().RelOffset(DWARFReg(kFpuCalleeSaves[i]), offset); |
| Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1299 | } |
| Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 1300 | } |
| 1301 | |
| Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 1302 | if (GetGraph()->HasShouldDeoptimizeFlag()) { |
| 1303 | // Initialize should_deoptimize flag to 0. |
| 1304 | __ movl(Address(CpuRegister(RSP), xmm_spill_location - kShouldDeoptimizeFlagSize), |
| 1305 | Immediate(0)); |
| 1306 | } |
| 1307 | |
| Nicolas Geoffray | 96eeb4e | 2016-10-12 22:03:31 +0100 | [diff] [blame] | 1308 | // Save the current method if we need it. Note that we do not |
| 1309 | // do this in HCurrentMethod, as the instruction might have been removed |
| 1310 | // in the SSA graph. |
| 1311 | if (RequiresCurrentMethod()) { |
| 1312 | __ movq(Address(CpuRegister(RSP), kCurrentMethodStackOffset), |
| 1313 | CpuRegister(kMethodRegisterArgument)); |
| 1314 | } |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1315 | } |
| 1316 | |
| 1317 | void CodeGeneratorX86_64::GenerateFrameExit() { |
| David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 1318 | __ cfi().RememberState(); |
| 1319 | if (!HasEmptyFrame()) { |
| 1320 | uint32_t xmm_spill_location = GetFpuSpillStart(); |
| 1321 | size_t xmm_spill_slot_size = GetFloatingPointSpillSlotSize(); |
| 1322 | for (size_t i = 0; i < arraysize(kFpuCalleeSaves); ++i) { |
| 1323 | if (allocated_registers_.ContainsFloatingPointRegister(kFpuCalleeSaves[i])) { |
| 1324 | int offset = xmm_spill_location + (xmm_spill_slot_size * i); |
| 1325 | __ movsd(XmmRegister(kFpuCalleeSaves[i]), Address(CpuRegister(RSP), offset)); |
| 1326 | __ cfi().Restore(DWARFReg(kFpuCalleeSaves[i])); |
| 1327 | } |
| 1328 | } |
| 1329 | |
| 1330 | int adjust = GetFrameSize() - GetCoreSpillSize(); |
| 1331 | __ addq(CpuRegister(RSP), Immediate(adjust)); |
| 1332 | __ cfi().AdjustCFAOffset(-adjust); |
| 1333 | |
| 1334 | for (size_t i = 0; i < arraysize(kCoreCalleeSaves); ++i) { |
| 1335 | Register reg = kCoreCalleeSaves[i]; |
| 1336 | if (allocated_registers_.ContainsCoreRegister(reg)) { |
| 1337 | __ popq(CpuRegister(reg)); |
| 1338 | __ cfi().AdjustCFAOffset(-static_cast<int>(kX86_64WordSize)); |
| 1339 | __ cfi().Restore(DWARFReg(reg)); |
| 1340 | } |
| Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1341 | } |
| 1342 | } |
| David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 1343 | __ ret(); |
| 1344 | __ cfi().RestoreState(); |
| 1345 | __ cfi().DefCFAOffset(GetFrameSize()); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1346 | } |
| 1347 | |
| Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 1348 | void CodeGeneratorX86_64::Bind(HBasicBlock* block) { |
| 1349 | __ Bind(GetLabelOf(block)); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1350 | } |
| 1351 | |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1352 | void CodeGeneratorX86_64::Move(Location destination, Location source) { |
| 1353 | if (source.Equals(destination)) { |
| 1354 | return; |
| 1355 | } |
| 1356 | if (destination.IsRegister()) { |
| Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1357 | CpuRegister dest = destination.AsRegister<CpuRegister>(); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1358 | if (source.IsRegister()) { |
| Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1359 | __ movq(dest, source.AsRegister<CpuRegister>()); |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1360 | } else if (source.IsFpuRegister()) { |
| Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1361 | __ movd(dest, source.AsFpuRegister<XmmRegister>()); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1362 | } else if (source.IsStackSlot()) { |
| Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1363 | __ movl(dest, Address(CpuRegister(RSP), source.GetStackIndex())); |
| 1364 | } else if (source.IsConstant()) { |
| 1365 | HConstant* constant = source.GetConstant(); |
| 1366 | if (constant->IsLongConstant()) { |
| 1367 | Load64BitValue(dest, constant->AsLongConstant()->GetValue()); |
| 1368 | } else { |
| 1369 | Load32BitValue(dest, GetInt32ValueOf(constant)); |
| 1370 | } |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1371 | } else { |
| 1372 | DCHECK(source.IsDoubleStackSlot()); |
| Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1373 | __ movq(dest, Address(CpuRegister(RSP), source.GetStackIndex())); |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1374 | } |
| 1375 | } else if (destination.IsFpuRegister()) { |
| Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1376 | XmmRegister dest = destination.AsFpuRegister<XmmRegister>(); |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1377 | if (source.IsRegister()) { |
| Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1378 | __ movd(dest, source.AsRegister<CpuRegister>()); |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1379 | } else if (source.IsFpuRegister()) { |
| Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1380 | __ movaps(dest, source.AsFpuRegister<XmmRegister>()); |
| 1381 | } else if (source.IsConstant()) { |
| 1382 | HConstant* constant = source.GetConstant(); |
| 1383 | int64_t value = CodeGenerator::GetInt64ValueOf(constant); |
| 1384 | if (constant->IsFloatConstant()) { |
| 1385 | Load32BitValue(dest, static_cast<int32_t>(value)); |
| 1386 | } else { |
| 1387 | Load64BitValue(dest, value); |
| 1388 | } |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1389 | } else if (source.IsStackSlot()) { |
| Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1390 | __ movss(dest, Address(CpuRegister(RSP), source.GetStackIndex())); |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1391 | } else { |
| 1392 | DCHECK(source.IsDoubleStackSlot()); |
| Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1393 | __ movsd(dest, Address(CpuRegister(RSP), source.GetStackIndex())); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1394 | } |
| 1395 | } else if (destination.IsStackSlot()) { |
| 1396 | if (source.IsRegister()) { |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1397 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1398 | source.AsRegister<CpuRegister>()); |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1399 | } else if (source.IsFpuRegister()) { |
| 1400 | __ movss(Address(CpuRegister(RSP), destination.GetStackIndex()), |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1401 | source.AsFpuRegister<XmmRegister>()); |
| Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 1402 | } else if (source.IsConstant()) { |
| 1403 | HConstant* constant = source.GetConstant(); |
| Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1404 | int32_t value = GetInt32ValueOf(constant); |
| Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 1405 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), Immediate(value)); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1406 | } else { |
| Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 1407 | DCHECK(source.IsStackSlot()) << source; |
| Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 1408 | __ movl(CpuRegister(TMP), Address(CpuRegister(RSP), source.GetStackIndex())); |
| 1409 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), CpuRegister(TMP)); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1410 | } |
| 1411 | } else { |
| 1412 | DCHECK(destination.IsDoubleStackSlot()); |
| 1413 | if (source.IsRegister()) { |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1414 | __ movq(Address(CpuRegister(RSP), destination.GetStackIndex()), |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1415 | source.AsRegister<CpuRegister>()); |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1416 | } else if (source.IsFpuRegister()) { |
| 1417 | __ movsd(Address(CpuRegister(RSP), destination.GetStackIndex()), |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1418 | source.AsFpuRegister<XmmRegister>()); |
| Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 1419 | } else if (source.IsConstant()) { |
| 1420 | HConstant* constant = source.GetConstant(); |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 1421 | DCHECK(constant->IsLongConstant() || constant->IsDoubleConstant()); |
| 1422 | int64_t value = GetInt64ValueOf(constant); |
| Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 1423 | Store64BitValueToStack(destination, value); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1424 | } else { |
| 1425 | DCHECK(source.IsDoubleStackSlot()); |
| Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 1426 | __ movq(CpuRegister(TMP), Address(CpuRegister(RSP), source.GetStackIndex())); |
| 1427 | __ movq(Address(CpuRegister(RSP), destination.GetStackIndex()), CpuRegister(TMP)); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1428 | } |
| 1429 | } |
| 1430 | } |
| 1431 | |
| Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1432 | void CodeGeneratorX86_64::MoveConstant(Location location, int32_t value) { |
| 1433 | DCHECK(location.IsRegister()); |
| 1434 | Load64BitValue(location.AsRegister<CpuRegister>(), static_cast<int64_t>(value)); |
| 1435 | } |
| 1436 | |
| Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1437 | void CodeGeneratorX86_64::MoveLocation( |
| 1438 | Location dst, Location src, Primitive::Type dst_type ATTRIBUTE_UNUSED) { |
| 1439 | Move(dst, src); |
| 1440 | } |
| 1441 | |
| 1442 | void CodeGeneratorX86_64::AddLocationAsTemp(Location location, LocationSummary* locations) { |
| 1443 | if (location.IsRegister()) { |
| 1444 | locations->AddTemp(location); |
| 1445 | } else { |
| 1446 | UNIMPLEMENTED(FATAL) << "AddLocationAsTemp not implemented for location " << location; |
| 1447 | } |
| 1448 | } |
| 1449 | |
| David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1450 | void InstructionCodeGeneratorX86_64::HandleGoto(HInstruction* got, HBasicBlock* successor) { |
| Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1451 | DCHECK(!successor->IsExitBlock()); |
| 1452 | |
| 1453 | HBasicBlock* block = got->GetBlock(); |
| 1454 | HInstruction* previous = got->GetPrevious(); |
| 1455 | |
| 1456 | HLoopInformation* info = block->GetLoopInformation(); |
| David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1457 | if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) { |
| Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1458 | GenerateSuspendCheck(info->GetSuspendCheck(), successor); |
| 1459 | return; |
| 1460 | } |
| 1461 | |
| 1462 | if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) { |
| 1463 | GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr); |
| 1464 | } |
| 1465 | if (!codegen_->GoesToNextBlock(got->GetBlock(), successor)) { |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1466 | __ jmp(codegen_->GetLabelOf(successor)); |
| 1467 | } |
| 1468 | } |
| 1469 | |
| David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1470 | void LocationsBuilderX86_64::VisitGoto(HGoto* got) { |
| 1471 | got->SetLocations(nullptr); |
| 1472 | } |
| 1473 | |
| 1474 | void InstructionCodeGeneratorX86_64::VisitGoto(HGoto* got) { |
| 1475 | HandleGoto(got, got->GetSuccessor()); |
| 1476 | } |
| 1477 | |
| 1478 | void LocationsBuilderX86_64::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 1479 | try_boundary->SetLocations(nullptr); |
| 1480 | } |
| 1481 | |
| 1482 | void InstructionCodeGeneratorX86_64::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 1483 | HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor(); |
| 1484 | if (!successor->IsExitBlock()) { |
| 1485 | HandleGoto(try_boundary, successor); |
| 1486 | } |
| 1487 | } |
| 1488 | |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1489 | void LocationsBuilderX86_64::VisitExit(HExit* exit) { |
| 1490 | exit->SetLocations(nullptr); |
| 1491 | } |
| 1492 | |
| Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1493 | void InstructionCodeGeneratorX86_64::VisitExit(HExit* exit ATTRIBUTE_UNUSED) { |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1494 | } |
| 1495 | |
| Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1496 | template<class LabelType> |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1497 | void InstructionCodeGeneratorX86_64::GenerateFPJumps(HCondition* cond, |
| Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1498 | LabelType* true_label, |
| 1499 | LabelType* false_label) { |
| Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1500 | if (cond->IsFPConditionTrueIfNaN()) { |
| 1501 | __ j(kUnordered, true_label); |
| 1502 | } else if (cond->IsFPConditionFalseIfNaN()) { |
| 1503 | __ j(kUnordered, false_label); |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1504 | } |
| Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1505 | __ j(X86_64FPCondition(cond->GetCondition()), true_label); |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1506 | } |
| 1507 | |
| Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1508 | void InstructionCodeGeneratorX86_64::GenerateCompareTest(HCondition* condition) { |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1509 | LocationSummary* locations = condition->GetLocations(); |
| Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1510 | |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1511 | Location left = locations->InAt(0); |
| 1512 | Location right = locations->InAt(1); |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1513 | Primitive::Type type = condition->InputAt(0)->GetType(); |
| 1514 | switch (type) { |
| Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1515 | case Primitive::kPrimBoolean: |
| 1516 | case Primitive::kPrimByte: |
| 1517 | case Primitive::kPrimChar: |
| 1518 | case Primitive::kPrimShort: |
| 1519 | case Primitive::kPrimInt: |
| 1520 | case Primitive::kPrimNot: { |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 1521 | codegen_->GenerateIntCompare(left, right); |
| Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1522 | break; |
| 1523 | } |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1524 | case Primitive::kPrimLong: { |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 1525 | codegen_->GenerateLongCompare(left, right); |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1526 | break; |
| 1527 | } |
| 1528 | case Primitive::kPrimFloat: { |
| 1529 | if (right.IsFpuRegister()) { |
| 1530 | __ ucomiss(left.AsFpuRegister<XmmRegister>(), right.AsFpuRegister<XmmRegister>()); |
| 1531 | } else if (right.IsConstant()) { |
| 1532 | __ ucomiss(left.AsFpuRegister<XmmRegister>(), |
| 1533 | codegen_->LiteralFloatAddress( |
| 1534 | right.GetConstant()->AsFloatConstant()->GetValue())); |
| 1535 | } else { |
| 1536 | DCHECK(right.IsStackSlot()); |
| 1537 | __ ucomiss(left.AsFpuRegister<XmmRegister>(), |
| 1538 | Address(CpuRegister(RSP), right.GetStackIndex())); |
| 1539 | } |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1540 | break; |
| 1541 | } |
| 1542 | case Primitive::kPrimDouble: { |
| 1543 | if (right.IsFpuRegister()) { |
| 1544 | __ ucomisd(left.AsFpuRegister<XmmRegister>(), right.AsFpuRegister<XmmRegister>()); |
| 1545 | } else if (right.IsConstant()) { |
| 1546 | __ ucomisd(left.AsFpuRegister<XmmRegister>(), |
| 1547 | codegen_->LiteralDoubleAddress( |
| 1548 | right.GetConstant()->AsDoubleConstant()->GetValue())); |
| 1549 | } else { |
| 1550 | DCHECK(right.IsDoubleStackSlot()); |
| 1551 | __ ucomisd(left.AsFpuRegister<XmmRegister>(), |
| 1552 | Address(CpuRegister(RSP), right.GetStackIndex())); |
| 1553 | } |
| Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1554 | break; |
| 1555 | } |
| 1556 | default: |
| 1557 | LOG(FATAL) << "Unexpected condition type " << type; |
| 1558 | } |
| 1559 | } |
| 1560 | |
| 1561 | template<class LabelType> |
| 1562 | void InstructionCodeGeneratorX86_64::GenerateCompareTestAndBranch(HCondition* condition, |
| 1563 | LabelType* true_target_in, |
| 1564 | LabelType* false_target_in) { |
| 1565 | // Generated branching requires both targets to be explicit. If either of the |
| 1566 | // targets is nullptr (fallthrough) use and bind `fallthrough_target` instead. |
| 1567 | LabelType fallthrough_target; |
| 1568 | LabelType* true_target = true_target_in == nullptr ? &fallthrough_target : true_target_in; |
| 1569 | LabelType* false_target = false_target_in == nullptr ? &fallthrough_target : false_target_in; |
| 1570 | |
| 1571 | // Generate the comparison to set the CC. |
| 1572 | GenerateCompareTest(condition); |
| 1573 | |
| 1574 | // Now generate the correct jump(s). |
| 1575 | Primitive::Type type = condition->InputAt(0)->GetType(); |
| 1576 | switch (type) { |
| 1577 | case Primitive::kPrimLong: { |
| 1578 | __ j(X86_64IntegerCondition(condition->GetCondition()), true_target); |
| 1579 | break; |
| 1580 | } |
| 1581 | case Primitive::kPrimFloat: { |
| 1582 | GenerateFPJumps(condition, true_target, false_target); |
| 1583 | break; |
| 1584 | } |
| 1585 | case Primitive::kPrimDouble: { |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1586 | GenerateFPJumps(condition, true_target, false_target); |
| 1587 | break; |
| 1588 | } |
| 1589 | default: |
| 1590 | LOG(FATAL) << "Unexpected condition type " << type; |
| 1591 | } |
| 1592 | |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1593 | if (false_target != &fallthrough_target) { |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1594 | __ jmp(false_target); |
| 1595 | } |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1596 | |
| 1597 | if (fallthrough_target.IsLinked()) { |
| 1598 | __ Bind(&fallthrough_target); |
| 1599 | } |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1600 | } |
| 1601 | |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1602 | static bool AreEflagsSetFrom(HInstruction* cond, HInstruction* branch) { |
| 1603 | // Moves may affect the eflags register (move zero uses xorl), so the EFLAGS |
| 1604 | // are set only strictly before `branch`. We can't use the eflags on long |
| 1605 | // conditions if they are materialized due to the complex branching. |
| 1606 | return cond->IsCondition() && |
| 1607 | cond->GetNext() == branch && |
| 1608 | !Primitive::IsFloatingPointType(cond->InputAt(0)->GetType()); |
| 1609 | } |
| 1610 | |
| Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1611 | template<class LabelType> |
| Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1612 | void InstructionCodeGeneratorX86_64::GenerateTestAndBranch(HInstruction* instruction, |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1613 | size_t condition_input_index, |
| Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1614 | LabelType* true_target, |
| 1615 | LabelType* false_target) { |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1616 | HInstruction* cond = instruction->InputAt(condition_input_index); |
| 1617 | |
| 1618 | if (true_target == nullptr && false_target == nullptr) { |
| 1619 | // Nothing to do. The code always falls through. |
| 1620 | return; |
| 1621 | } else if (cond->IsIntConstant()) { |
| Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 1622 | // Constant condition, statically compared against "true" (integer value 1). |
| 1623 | if (cond->AsIntConstant()->IsTrue()) { |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1624 | if (true_target != nullptr) { |
| 1625 | __ jmp(true_target); |
| Nicolas Geoffray | 18efde5 | 2014-09-22 15:51:11 +0100 | [diff] [blame] | 1626 | } |
| Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1627 | } else { |
| Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 1628 | DCHECK(cond->AsIntConstant()->IsFalse()) << cond->AsIntConstant()->GetValue(); |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1629 | if (false_target != nullptr) { |
| 1630 | __ jmp(false_target); |
| 1631 | } |
| 1632 | } |
| 1633 | return; |
| 1634 | } |
| 1635 | |
| 1636 | // The following code generates these patterns: |
| 1637 | // (1) true_target == nullptr && false_target != nullptr |
| 1638 | // - opposite condition true => branch to false_target |
| 1639 | // (2) true_target != nullptr && false_target == nullptr |
| 1640 | // - condition true => branch to true_target |
| 1641 | // (3) true_target != nullptr && false_target != nullptr |
| 1642 | // - condition true => branch to true_target |
| 1643 | // - branch to false_target |
| 1644 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
| 1645 | if (AreEflagsSetFrom(cond, instruction)) { |
| 1646 | if (true_target == nullptr) { |
| 1647 | __ j(X86_64IntegerCondition(cond->AsCondition()->GetOppositeCondition()), false_target); |
| 1648 | } else { |
| 1649 | __ j(X86_64IntegerCondition(cond->AsCondition()->GetCondition()), true_target); |
| 1650 | } |
| 1651 | } else { |
| 1652 | // Materialized condition, compare against 0. |
| 1653 | Location lhs = instruction->GetLocations()->InAt(condition_input_index); |
| 1654 | if (lhs.IsRegister()) { |
| 1655 | __ testl(lhs.AsRegister<CpuRegister>(), lhs.AsRegister<CpuRegister>()); |
| 1656 | } else { |
| 1657 | __ cmpl(Address(CpuRegister(RSP), lhs.GetStackIndex()), Immediate(0)); |
| 1658 | } |
| 1659 | if (true_target == nullptr) { |
| 1660 | __ j(kEqual, false_target); |
| 1661 | } else { |
| 1662 | __ j(kNotEqual, true_target); |
| 1663 | } |
| Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1664 | } |
| 1665 | } else { |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1666 | // Condition has not been materialized, use its inputs as the |
| 1667 | // comparison and its condition as the branch condition. |
| Mark Mendell | b8b9769 | 2015-05-22 16:58:19 -0400 | [diff] [blame] | 1668 | HCondition* condition = cond->AsCondition(); |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1669 | |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1670 | // If this is a long or FP comparison that has been folded into |
| 1671 | // the HCondition, generate the comparison directly. |
| 1672 | Primitive::Type type = condition->InputAt(0)->GetType(); |
| 1673 | if (type == Primitive::kPrimLong || Primitive::IsFloatingPointType(type)) { |
| 1674 | GenerateCompareTestAndBranch(condition, true_target, false_target); |
| 1675 | return; |
| 1676 | } |
| 1677 | |
| 1678 | Location lhs = condition->GetLocations()->InAt(0); |
| 1679 | Location rhs = condition->GetLocations()->InAt(1); |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 1680 | codegen_->GenerateIntCompare(lhs, rhs); |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1681 | if (true_target == nullptr) { |
| 1682 | __ j(X86_64IntegerCondition(condition->GetOppositeCondition()), false_target); |
| 1683 | } else { |
| Mark Mendell | b8b9769 | 2015-05-22 16:58:19 -0400 | [diff] [blame] | 1684 | __ j(X86_64IntegerCondition(condition->GetCondition()), true_target); |
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1685 | } |
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1686 | } |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1687 | |
| 1688 | // If neither branch falls through (case 3), the conditional branch to `true_target` |
| 1689 | // was already emitted (case 2) and we need to emit a jump to `false_target`. |
| 1690 | if (true_target != nullptr && false_target != nullptr) { |
| Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1691 | __ jmp(false_target); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1692 | } |
| 1693 | } |
| 1694 | |
| Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1695 | void LocationsBuilderX86_64::VisitIf(HIf* if_instr) { |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1696 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(if_instr); |
| 1697 | if (IsBooleanValueOrMaterializedCondition(if_instr->InputAt(0))) { |
| Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1698 | locations->SetInAt(0, Location::Any()); |
| 1699 | } |
| 1700 | } |
| 1701 | |
| 1702 | void InstructionCodeGeneratorX86_64::VisitIf(HIf* if_instr) { |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1703 | HBasicBlock* true_successor = if_instr->IfTrueSuccessor(); |
| 1704 | HBasicBlock* false_successor = if_instr->IfFalseSuccessor(); |
| 1705 | Label* true_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), true_successor) ? |
| 1706 | nullptr : codegen_->GetLabelOf(true_successor); |
| 1707 | Label* false_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), false_successor) ? |
| 1708 | nullptr : codegen_->GetLabelOf(false_successor); |
| 1709 | GenerateTestAndBranch(if_instr, /* condition_input_index */ 0, true_target, false_target); |
| Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1710 | } |
| 1711 | |
| 1712 | void LocationsBuilderX86_64::VisitDeoptimize(HDeoptimize* deoptimize) { |
| 1713 | LocationSummary* locations = new (GetGraph()->GetArena()) |
| 1714 | LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath); |
| Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 1715 | InvokeRuntimeCallingConvention calling_convention; |
| 1716 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 1717 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 1718 | locations->SetCustomSlowPathCallerSaves(caller_saves); |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1719 | if (IsBooleanValueOrMaterializedCondition(deoptimize->InputAt(0))) { |
| Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1720 | locations->SetInAt(0, Location::Any()); |
| 1721 | } |
| 1722 | } |
| 1723 | |
| 1724 | void InstructionCodeGeneratorX86_64::VisitDeoptimize(HDeoptimize* deoptimize) { |
| Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 1725 | SlowPathCode* slow_path = deopt_slow_paths_.NewSlowPath<DeoptimizationSlowPathX86_64>(deoptimize); |
| David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1726 | GenerateTestAndBranch<Label>(deoptimize, |
| 1727 | /* condition_input_index */ 0, |
| 1728 | slow_path->GetEntryLabel(), |
| 1729 | /* false_target */ nullptr); |
| 1730 | } |
| 1731 | |
| Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 1732 | void LocationsBuilderX86_64::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) { |
| 1733 | LocationSummary* locations = new (GetGraph()->GetArena()) |
| 1734 | LocationSummary(flag, LocationSummary::kNoCall); |
| 1735 | locations->SetOut(Location::RequiresRegister()); |
| 1736 | } |
| 1737 | |
| 1738 | void InstructionCodeGeneratorX86_64::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) { |
| 1739 | __ movl(flag->GetLocations()->Out().AsRegister<CpuRegister>(), |
| 1740 | Address(CpuRegister(RSP), codegen_->GetStackOffsetOfShouldDeoptimizeFlag())); |
| 1741 | } |
| 1742 | |
| Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1743 | static bool SelectCanUseCMOV(HSelect* select) { |
| 1744 | // There are no conditional move instructions for XMMs. |
| 1745 | if (Primitive::IsFloatingPointType(select->GetType())) { |
| 1746 | return false; |
| 1747 | } |
| 1748 | |
| 1749 | // A FP condition doesn't generate the single CC that we need. |
| 1750 | HInstruction* condition = select->GetCondition(); |
| 1751 | if (condition->IsCondition() && |
| 1752 | Primitive::IsFloatingPointType(condition->InputAt(0)->GetType())) { |
| 1753 | return false; |
| 1754 | } |
| 1755 | |
| 1756 | // We can generate a CMOV for this Select. |
| 1757 | return true; |
| 1758 | } |
| 1759 | |
| David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1760 | void LocationsBuilderX86_64::VisitSelect(HSelect* select) { |
| 1761 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(select); |
| 1762 | if (Primitive::IsFloatingPointType(select->GetType())) { |
| 1763 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1764 | locations->SetInAt(1, Location::Any()); |
| David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1765 | } else { |
| 1766 | locations->SetInAt(0, Location::RequiresRegister()); |
| Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1767 | if (SelectCanUseCMOV(select)) { |
| Mark Mendell | dee1b9a | 2016-02-12 14:36:51 -0500 | [diff] [blame] | 1768 | if (select->InputAt(1)->IsConstant()) { |
| 1769 | locations->SetInAt(1, Location::RequiresRegister()); |
| 1770 | } else { |
| 1771 | locations->SetInAt(1, Location::Any()); |
| 1772 | } |
| Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1773 | } else { |
| Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1774 | locations->SetInAt(1, Location::Any()); |
| 1775 | } |
| David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1776 | } |
| 1777 | if (IsBooleanValueOrMaterializedCondition(select->GetCondition())) { |
| 1778 | locations->SetInAt(2, Location::RequiresRegister()); |
| 1779 | } |
| 1780 | locations->SetOut(Location::SameAsFirstInput()); |
| 1781 | } |
| 1782 | |
| 1783 | void InstructionCodeGeneratorX86_64::VisitSelect(HSelect* select) { |
| 1784 | LocationSummary* locations = select->GetLocations(); |
| Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1785 | if (SelectCanUseCMOV(select)) { |
| 1786 | // If both the condition and the source types are integer, we can generate |
| 1787 | // a CMOV to implement Select. |
| 1788 | CpuRegister value_false = locations->InAt(0).AsRegister<CpuRegister>(); |
| Mark Mendell | dee1b9a | 2016-02-12 14:36:51 -0500 | [diff] [blame] | 1789 | Location value_true_loc = locations->InAt(1); |
| Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1790 | DCHECK(locations->InAt(0).Equals(locations->Out())); |
| 1791 | |
| 1792 | HInstruction* select_condition = select->GetCondition(); |
| 1793 | Condition cond = kNotEqual; |
| 1794 | |
| 1795 | // Figure out how to test the 'condition'. |
| 1796 | if (select_condition->IsCondition()) { |
| 1797 | HCondition* condition = select_condition->AsCondition(); |
| 1798 | if (!condition->IsEmittedAtUseSite()) { |
| 1799 | // This was a previously materialized condition. |
| 1800 | // Can we use the existing condition code? |
| 1801 | if (AreEflagsSetFrom(condition, select)) { |
| 1802 | // Materialization was the previous instruction. Condition codes are right. |
| 1803 | cond = X86_64IntegerCondition(condition->GetCondition()); |
| 1804 | } else { |
| 1805 | // No, we have to recreate the condition code. |
| 1806 | CpuRegister cond_reg = locations->InAt(2).AsRegister<CpuRegister>(); |
| 1807 | __ testl(cond_reg, cond_reg); |
| 1808 | } |
| 1809 | } else { |
| 1810 | GenerateCompareTest(condition); |
| 1811 | cond = X86_64IntegerCondition(condition->GetCondition()); |
| 1812 | } |
| 1813 | } else { |
| Roland Levillain | 5e8d5f0 | 2016-10-18 18:03:43 +0100 | [diff] [blame] | 1814 | // Must be a Boolean condition, which needs to be compared to 0. |
| Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1815 | CpuRegister cond_reg = locations->InAt(2).AsRegister<CpuRegister>(); |
| 1816 | __ testl(cond_reg, cond_reg); |
| 1817 | } |
| 1818 | |
| 1819 | // If the condition is true, overwrite the output, which already contains false. |
| 1820 | // Generate the correct sized CMOV. |
| Mark Mendell | dee1b9a | 2016-02-12 14:36:51 -0500 | [diff] [blame] | 1821 | bool is_64_bit = Primitive::Is64BitType(select->GetType()); |
| 1822 | if (value_true_loc.IsRegister()) { |
| 1823 | __ cmov(cond, value_false, value_true_loc.AsRegister<CpuRegister>(), is_64_bit); |
| 1824 | } else { |
| 1825 | __ cmov(cond, |
| 1826 | value_false, |
| 1827 | Address(CpuRegister(RSP), value_true_loc.GetStackIndex()), is_64_bit); |
| 1828 | } |
| Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1829 | } else { |
| 1830 | NearLabel false_target; |
| 1831 | GenerateTestAndBranch<NearLabel>(select, |
| 1832 | /* condition_input_index */ 2, |
| 1833 | /* true_target */ nullptr, |
| 1834 | &false_target); |
| 1835 | codegen_->MoveLocation(locations->Out(), locations->InAt(1), select->GetType()); |
| 1836 | __ Bind(&false_target); |
| 1837 | } |
| Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1838 | } |
| 1839 | |
| David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 1840 | void LocationsBuilderX86_64::VisitNativeDebugInfo(HNativeDebugInfo* info) { |
| 1841 | new (GetGraph()->GetArena()) LocationSummary(info); |
| 1842 | } |
| 1843 | |
| David Srbecky | d28f4a0 | 2016-03-14 17:14:24 +0000 | [diff] [blame] | 1844 | void InstructionCodeGeneratorX86_64::VisitNativeDebugInfo(HNativeDebugInfo*) { |
| 1845 | // MaybeRecordNativeDebugInfo is already called implicitly in CodeGenerator::Compile. |
| David Srbecky | c7098ff | 2016-02-09 14:30:11 +0000 | [diff] [blame] | 1846 | } |
| 1847 | |
| 1848 | void CodeGeneratorX86_64::GenerateNop() { |
| 1849 | __ nop(); |
| David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 1850 | } |
| 1851 | |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1852 | void LocationsBuilderX86_64::HandleCondition(HCondition* cond) { |
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1853 | LocationSummary* locations = |
| Roland Levillain | 0d37cd0 | 2015-05-27 16:39:19 +0100 | [diff] [blame] | 1854 | new (GetGraph()->GetArena()) LocationSummary(cond, LocationSummary::kNoCall); |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1855 | // Handle the long/FP comparisons made in instruction simplification. |
| 1856 | switch (cond->InputAt(0)->GetType()) { |
| 1857 | case Primitive::kPrimLong: |
| 1858 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1859 | locations->SetInAt(1, Location::Any()); |
| 1860 | break; |
| 1861 | case Primitive::kPrimFloat: |
| 1862 | case Primitive::kPrimDouble: |
| 1863 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1864 | locations->SetInAt(1, Location::Any()); |
| 1865 | break; |
| 1866 | default: |
| 1867 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1868 | locations->SetInAt(1, Location::Any()); |
| 1869 | break; |
| 1870 | } |
| David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 1871 | if (!cond->IsEmittedAtUseSite()) { |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1872 | locations->SetOut(Location::RequiresRegister()); |
| 1873 | } |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1874 | } |
| 1875 | |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1876 | void InstructionCodeGeneratorX86_64::HandleCondition(HCondition* cond) { |
| David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 1877 | if (cond->IsEmittedAtUseSite()) { |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1878 | return; |
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1879 | } |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1880 | |
| 1881 | LocationSummary* locations = cond->GetLocations(); |
| 1882 | Location lhs = locations->InAt(0); |
| 1883 | Location rhs = locations->InAt(1); |
| 1884 | CpuRegister reg = locations->Out().AsRegister<CpuRegister>(); |
| Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1885 | NearLabel true_label, false_label; |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1886 | |
| 1887 | switch (cond->InputAt(0)->GetType()) { |
| 1888 | default: |
| 1889 | // Integer case. |
| 1890 | |
| 1891 | // Clear output register: setcc only sets the low byte. |
| 1892 | __ xorl(reg, reg); |
| 1893 | |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 1894 | codegen_->GenerateIntCompare(lhs, rhs); |
| Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1895 | __ setcc(X86_64IntegerCondition(cond->GetCondition()), reg); |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1896 | return; |
| 1897 | case Primitive::kPrimLong: |
| 1898 | // Clear output register: setcc only sets the low byte. |
| 1899 | __ xorl(reg, reg); |
| 1900 | |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 1901 | codegen_->GenerateLongCompare(lhs, rhs); |
| Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1902 | __ setcc(X86_64IntegerCondition(cond->GetCondition()), reg); |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1903 | return; |
| 1904 | case Primitive::kPrimFloat: { |
| 1905 | XmmRegister lhs_reg = lhs.AsFpuRegister<XmmRegister>(); |
| 1906 | if (rhs.IsConstant()) { |
| 1907 | float value = rhs.GetConstant()->AsFloatConstant()->GetValue(); |
| 1908 | __ ucomiss(lhs_reg, codegen_->LiteralFloatAddress(value)); |
| 1909 | } else if (rhs.IsStackSlot()) { |
| 1910 | __ ucomiss(lhs_reg, Address(CpuRegister(RSP), rhs.GetStackIndex())); |
| 1911 | } else { |
| 1912 | __ ucomiss(lhs_reg, rhs.AsFpuRegister<XmmRegister>()); |
| 1913 | } |
| 1914 | GenerateFPJumps(cond, &true_label, &false_label); |
| 1915 | break; |
| 1916 | } |
| 1917 | case Primitive::kPrimDouble: { |
| 1918 | XmmRegister lhs_reg = lhs.AsFpuRegister<XmmRegister>(); |
| 1919 | if (rhs.IsConstant()) { |
| 1920 | double value = rhs.GetConstant()->AsDoubleConstant()->GetValue(); |
| 1921 | __ ucomisd(lhs_reg, codegen_->LiteralDoubleAddress(value)); |
| 1922 | } else if (rhs.IsDoubleStackSlot()) { |
| 1923 | __ ucomisd(lhs_reg, Address(CpuRegister(RSP), rhs.GetStackIndex())); |
| 1924 | } else { |
| 1925 | __ ucomisd(lhs_reg, rhs.AsFpuRegister<XmmRegister>()); |
| 1926 | } |
| 1927 | GenerateFPJumps(cond, &true_label, &false_label); |
| 1928 | break; |
| 1929 | } |
| 1930 | } |
| 1931 | |
| 1932 | // Convert the jumps into the result. |
| Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 1933 | NearLabel done_label; |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1934 | |
| Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1935 | // False case: result = 0. |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1936 | __ Bind(&false_label); |
| 1937 | __ xorl(reg, reg); |
| 1938 | __ jmp(&done_label); |
| 1939 | |
| Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1940 | // True case: result = 1. |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1941 | __ Bind(&true_label); |
| 1942 | __ movl(reg, Immediate(1)); |
| 1943 | __ Bind(&done_label); |
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1944 | } |
| 1945 | |
| 1946 | void LocationsBuilderX86_64::VisitEqual(HEqual* comp) { |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1947 | HandleCondition(comp); |
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1948 | } |
| 1949 | |
| 1950 | void InstructionCodeGeneratorX86_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 LocationsBuilderX86_64::VisitNotEqual(HNotEqual* 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 InstructionCodeGeneratorX86_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 LocationsBuilderX86_64::VisitLessThan(HLessThan* 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 InstructionCodeGeneratorX86_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 LocationsBuilderX86_64::VisitLessThanOrEqual(HLessThanOrEqual* 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 InstructionCodeGeneratorX86_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 LocationsBuilderX86_64::VisitGreaterThan(HGreaterThan* 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 InstructionCodeGeneratorX86_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 LocationsBuilderX86_64::VisitGreaterThanOrEqual(HGreaterThanOrEqual* 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 InstructionCodeGeneratorX86_64::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1991 | HandleCondition(comp); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1992 | } |
| 1993 | |
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1994 | void LocationsBuilderX86_64::VisitBelow(HBelow* comp) { |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1995 | HandleCondition(comp); |
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1996 | } |
| 1997 | |
| 1998 | void InstructionCodeGeneratorX86_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 LocationsBuilderX86_64::VisitBelowOrEqual(HBelowOrEqual* 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 InstructionCodeGeneratorX86_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 LocationsBuilderX86_64::VisitAbove(HAbove* 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 InstructionCodeGeneratorX86_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 LocationsBuilderX86_64::VisitAboveOrEqual(HAboveOrEqual* 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 InstructionCodeGeneratorX86_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 | |
| Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 2026 | void LocationsBuilderX86_64::VisitCompare(HCompare* compare) { |
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2027 | LocationSummary* locations = |
| 2028 | new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall); |
| Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2029 | switch (compare->InputAt(0)->GetType()) { |
| Roland Levillain | a5c4a40 | 2016-03-15 15:02:50 +0000 | [diff] [blame] | 2030 | case Primitive::kPrimBoolean: |
| 2031 | case Primitive::kPrimByte: |
| 2032 | case Primitive::kPrimShort: |
| 2033 | case Primitive::kPrimChar: |
| Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 2034 | case Primitive::kPrimInt: |
| Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2035 | case Primitive::kPrimLong: { |
| 2036 | locations->SetInAt(0, Location::RequiresRegister()); |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2037 | locations->SetInAt(1, Location::Any()); |
| Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2038 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2039 | break; |
| 2040 | } |
| 2041 | case Primitive::kPrimFloat: |
| 2042 | case Primitive::kPrimDouble: { |
| 2043 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2044 | locations->SetInAt(1, Location::Any()); |
| Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2045 | locations->SetOut(Location::RequiresRegister()); |
| 2046 | break; |
| 2047 | } |
| 2048 | default: |
| 2049 | LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType(); |
| 2050 | } |
| Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 2051 | } |
| 2052 | |
| 2053 | void InstructionCodeGeneratorX86_64::VisitCompare(HCompare* compare) { |
| Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 2054 | LocationSummary* locations = compare->GetLocations(); |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2055 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
| Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2056 | Location left = locations->InAt(0); |
| 2057 | Location right = locations->InAt(1); |
| 2058 | |
| Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2059 | NearLabel less, greater, done; |
| Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2060 | Primitive::Type type = compare->InputAt(0)->GetType(); |
| Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 2061 | Condition less_cond = kLess; |
| 2062 | |
| Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2063 | switch (type) { |
| Roland Levillain | a5c4a40 | 2016-03-15 15:02:50 +0000 | [diff] [blame] | 2064 | case Primitive::kPrimBoolean: |
| 2065 | case Primitive::kPrimByte: |
| 2066 | case Primitive::kPrimShort: |
| 2067 | case Primitive::kPrimChar: |
| Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 2068 | case Primitive::kPrimInt: { |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 2069 | codegen_->GenerateIntCompare(left, right); |
| Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 2070 | break; |
| 2071 | } |
| Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2072 | case Primitive::kPrimLong: { |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 2073 | codegen_->GenerateLongCompare(left, right); |
| Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 2074 | break; |
| Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2075 | } |
| 2076 | case Primitive::kPrimFloat: { |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2077 | XmmRegister left_reg = left.AsFpuRegister<XmmRegister>(); |
| 2078 | if (right.IsConstant()) { |
| 2079 | float value = right.GetConstant()->AsFloatConstant()->GetValue(); |
| 2080 | __ ucomiss(left_reg, codegen_->LiteralFloatAddress(value)); |
| 2081 | } else if (right.IsStackSlot()) { |
| 2082 | __ ucomiss(left_reg, Address(CpuRegister(RSP), right.GetStackIndex())); |
| 2083 | } else { |
| 2084 | __ ucomiss(left_reg, right.AsFpuRegister<XmmRegister>()); |
| 2085 | } |
| Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2086 | __ j(kUnordered, compare->IsGtBias() ? &greater : &less); |
| Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 2087 | less_cond = kBelow; // ucomis{s,d} sets CF |
| Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2088 | break; |
| 2089 | } |
| 2090 | case Primitive::kPrimDouble: { |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2091 | XmmRegister left_reg = left.AsFpuRegister<XmmRegister>(); |
| 2092 | if (right.IsConstant()) { |
| 2093 | double value = right.GetConstant()->AsDoubleConstant()->GetValue(); |
| 2094 | __ ucomisd(left_reg, codegen_->LiteralDoubleAddress(value)); |
| 2095 | } else if (right.IsDoubleStackSlot()) { |
| 2096 | __ ucomisd(left_reg, Address(CpuRegister(RSP), right.GetStackIndex())); |
| 2097 | } else { |
| 2098 | __ ucomisd(left_reg, right.AsFpuRegister<XmmRegister>()); |
| 2099 | } |
| Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2100 | __ j(kUnordered, compare->IsGtBias() ? &greater : &less); |
| Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 2101 | less_cond = kBelow; // ucomis{s,d} sets CF |
| Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2102 | break; |
| 2103 | } |
| Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 2104 | default: |
| Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2105 | LOG(FATAL) << "Unexpected compare type " << type; |
| Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 2106 | } |
| Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 2107 | |
| Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2108 | __ movl(out, Immediate(0)); |
| Calin Juravle | 91debbc | 2014-11-26 19:01:09 +0000 | [diff] [blame] | 2109 | __ j(kEqual, &done); |
| Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 2110 | __ j(less_cond, &less); |
| Calin Juravle | fd86124 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2111 | |
| Calin Juravle | 91debbc | 2014-11-26 19:01:09 +0000 | [diff] [blame] | 2112 | __ Bind(&greater); |
| Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2113 | __ movl(out, Immediate(1)); |
| 2114 | __ jmp(&done); |
| 2115 | |
| 2116 | __ Bind(&less); |
| 2117 | __ movl(out, Immediate(-1)); |
| Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 2118 | |
| 2119 | __ Bind(&done); |
| 2120 | } |
| 2121 | |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2122 | void LocationsBuilderX86_64::VisitIntConstant(HIntConstant* constant) { |
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2123 | LocationSummary* locations = |
| 2124 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2125 | locations->SetOut(Location::ConstantLocation(constant)); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2126 | } |
| 2127 | |
| Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2128 | void InstructionCodeGeneratorX86_64::VisitIntConstant(HIntConstant* constant ATTRIBUTE_UNUSED) { |
| Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 2129 | // Will be generated at use site. |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2130 | } |
| 2131 | |
| Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 2132 | void LocationsBuilderX86_64::VisitNullConstant(HNullConstant* constant) { |
| 2133 | LocationSummary* locations = |
| 2134 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 2135 | locations->SetOut(Location::ConstantLocation(constant)); |
| 2136 | } |
| 2137 | |
| Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2138 | void InstructionCodeGeneratorX86_64::VisitNullConstant(HNullConstant* constant ATTRIBUTE_UNUSED) { |
| Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 2139 | // Will be generated at use site. |
| Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 2140 | } |
| 2141 | |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2142 | void LocationsBuilderX86_64::VisitLongConstant(HLongConstant* constant) { |
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2143 | LocationSummary* locations = |
| 2144 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2145 | locations->SetOut(Location::ConstantLocation(constant)); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2146 | } |
| 2147 | |
| Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2148 | void InstructionCodeGeneratorX86_64::VisitLongConstant(HLongConstant* constant ATTRIBUTE_UNUSED) { |
| Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 2149 | // Will be generated at use site. |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2150 | } |
| 2151 | |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2152 | void LocationsBuilderX86_64::VisitFloatConstant(HFloatConstant* constant) { |
| 2153 | LocationSummary* locations = |
| 2154 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 2155 | locations->SetOut(Location::ConstantLocation(constant)); |
| 2156 | } |
| 2157 | |
| Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2158 | void InstructionCodeGeneratorX86_64::VisitFloatConstant(HFloatConstant* constant ATTRIBUTE_UNUSED) { |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2159 | // Will be generated at use site. |
| 2160 | } |
| 2161 | |
| 2162 | void LocationsBuilderX86_64::VisitDoubleConstant(HDoubleConstant* constant) { |
| 2163 | LocationSummary* locations = |
| 2164 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 2165 | locations->SetOut(Location::ConstantLocation(constant)); |
| 2166 | } |
| 2167 | |
| Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2168 | void InstructionCodeGeneratorX86_64::VisitDoubleConstant( |
| 2169 | HDoubleConstant* constant ATTRIBUTE_UNUSED) { |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2170 | // Will be generated at use site. |
| 2171 | } |
| 2172 | |
| Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 2173 | void LocationsBuilderX86_64::VisitConstructorFence(HConstructorFence* constructor_fence) { |
| 2174 | constructor_fence->SetLocations(nullptr); |
| 2175 | } |
| 2176 | |
| 2177 | void InstructionCodeGeneratorX86_64::VisitConstructorFence( |
| 2178 | HConstructorFence* constructor_fence ATTRIBUTE_UNUSED) { |
| 2179 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kStoreStore); |
| 2180 | } |
| 2181 | |
| Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 2182 | void LocationsBuilderX86_64::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 2183 | memory_barrier->SetLocations(nullptr); |
| 2184 | } |
| 2185 | |
| 2186 | void InstructionCodeGeneratorX86_64::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 2187 | codegen_->GenerateMemoryBarrier(memory_barrier->GetBarrierKind()); |
| Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 2188 | } |
| 2189 | |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2190 | void LocationsBuilderX86_64::VisitReturnVoid(HReturnVoid* ret) { |
| 2191 | ret->SetLocations(nullptr); |
| 2192 | } |
| 2193 | |
| Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2194 | void InstructionCodeGeneratorX86_64::VisitReturnVoid(HReturnVoid* ret ATTRIBUTE_UNUSED) { |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2195 | codegen_->GenerateFrameExit(); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2196 | } |
| 2197 | |
| 2198 | void LocationsBuilderX86_64::VisitReturn(HReturn* ret) { |
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2199 | LocationSummary* locations = |
| 2200 | new (GetGraph()->GetArena()) LocationSummary(ret, LocationSummary::kNoCall); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2201 | switch (ret->InputAt(0)->GetType()) { |
| 2202 | case Primitive::kPrimBoolean: |
| 2203 | case Primitive::kPrimByte: |
| 2204 | case Primitive::kPrimChar: |
| 2205 | case Primitive::kPrimShort: |
| 2206 | case Primitive::kPrimInt: |
| 2207 | case Primitive::kPrimNot: |
| 2208 | case Primitive::kPrimLong: |
| Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2209 | locations->SetInAt(0, Location::RegisterLocation(RAX)); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2210 | break; |
| 2211 | |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2212 | case Primitive::kPrimFloat: |
| 2213 | case Primitive::kPrimDouble: |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2214 | locations->SetInAt(0, Location::FpuRegisterLocation(XMM0)); |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2215 | break; |
| 2216 | |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2217 | default: |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2218 | LOG(FATAL) << "Unexpected return type " << ret->InputAt(0)->GetType(); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2219 | } |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2220 | } |
| 2221 | |
| 2222 | void InstructionCodeGeneratorX86_64::VisitReturn(HReturn* ret) { |
| 2223 | if (kIsDebugBuild) { |
| 2224 | switch (ret->InputAt(0)->GetType()) { |
| 2225 | case Primitive::kPrimBoolean: |
| 2226 | case Primitive::kPrimByte: |
| 2227 | case Primitive::kPrimChar: |
| 2228 | case Primitive::kPrimShort: |
| 2229 | case Primitive::kPrimInt: |
| 2230 | case Primitive::kPrimNot: |
| 2231 | case Primitive::kPrimLong: |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2232 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsRegister<CpuRegister>().AsRegister(), RAX); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2233 | break; |
| 2234 | |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2235 | case Primitive::kPrimFloat: |
| 2236 | case Primitive::kPrimDouble: |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2237 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsFpuRegister<XmmRegister>().AsFloatRegister(), |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2238 | XMM0); |
| 2239 | break; |
| 2240 | |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2241 | default: |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2242 | LOG(FATAL) << "Unexpected return type " << ret->InputAt(0)->GetType(); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2243 | } |
| 2244 | } |
| 2245 | codegen_->GenerateFrameExit(); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2246 | } |
| 2247 | |
| Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 2248 | Location InvokeDexCallingConventionVisitorX86_64::GetReturnLocation(Primitive::Type type) const { |
| 2249 | switch (type) { |
| 2250 | case Primitive::kPrimBoolean: |
| 2251 | case Primitive::kPrimByte: |
| 2252 | case Primitive::kPrimChar: |
| 2253 | case Primitive::kPrimShort: |
| 2254 | case Primitive::kPrimInt: |
| 2255 | case Primitive::kPrimNot: |
| 2256 | case Primitive::kPrimLong: |
| 2257 | return Location::RegisterLocation(RAX); |
| 2258 | |
| 2259 | case Primitive::kPrimVoid: |
| 2260 | return Location::NoLocation(); |
| 2261 | |
| 2262 | case Primitive::kPrimDouble: |
| 2263 | case Primitive::kPrimFloat: |
| 2264 | return Location::FpuRegisterLocation(XMM0); |
| 2265 | } |
| Nicolas Geoffray | 0d1652e | 2015-06-03 12:12:19 +0100 | [diff] [blame] | 2266 | |
| 2267 | UNREACHABLE(); |
| Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 2268 | } |
| 2269 | |
| 2270 | Location InvokeDexCallingConventionVisitorX86_64::GetMethodLocation() const { |
| 2271 | return Location::RegisterLocation(kMethodRegisterArgument); |
| 2272 | } |
| 2273 | |
| Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 2274 | Location InvokeDexCallingConventionVisitorX86_64::GetNextLocation(Primitive::Type type) { |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2275 | switch (type) { |
| 2276 | case Primitive::kPrimBoolean: |
| 2277 | case Primitive::kPrimByte: |
| 2278 | case Primitive::kPrimChar: |
| 2279 | case Primitive::kPrimShort: |
| 2280 | case Primitive::kPrimInt: |
| 2281 | case Primitive::kPrimNot: { |
| 2282 | uint32_t index = gp_index_++; |
| 2283 | stack_index_++; |
| 2284 | if (index < calling_convention.GetNumberOfRegisters()) { |
| Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2285 | return Location::RegisterLocation(calling_convention.GetRegisterAt(index)); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2286 | } else { |
| 2287 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 1)); |
| 2288 | } |
| 2289 | } |
| 2290 | |
| 2291 | case Primitive::kPrimLong: { |
| 2292 | uint32_t index = gp_index_; |
| 2293 | stack_index_ += 2; |
| 2294 | if (index < calling_convention.GetNumberOfRegisters()) { |
| 2295 | gp_index_ += 1; |
| Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2296 | return Location::RegisterLocation(calling_convention.GetRegisterAt(index)); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2297 | } else { |
| 2298 | gp_index_ += 2; |
| 2299 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 2)); |
| 2300 | } |
| 2301 | } |
| 2302 | |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2303 | case Primitive::kPrimFloat: { |
| Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 2304 | uint32_t index = float_index_++; |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2305 | stack_index_++; |
| 2306 | if (index < calling_convention.GetNumberOfFpuRegisters()) { |
| Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2307 | return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(index)); |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2308 | } else { |
| 2309 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 1)); |
| 2310 | } |
| 2311 | } |
| 2312 | |
| 2313 | case Primitive::kPrimDouble: { |
| Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 2314 | uint32_t index = float_index_++; |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2315 | stack_index_ += 2; |
| 2316 | if (index < calling_convention.GetNumberOfFpuRegisters()) { |
| Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2317 | return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(index)); |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2318 | } else { |
| 2319 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 2)); |
| 2320 | } |
| 2321 | } |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2322 | |
| 2323 | case Primitive::kPrimVoid: |
| 2324 | LOG(FATAL) << "Unexpected parameter type " << type; |
| 2325 | break; |
| 2326 | } |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2327 | return Location::NoLocation(); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2328 | } |
| 2329 | |
| Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 2330 | void LocationsBuilderX86_64::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 2331 | // The trampoline uses the same calling convention as dex calling conventions, |
| 2332 | // except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain |
| 2333 | // the method_idx. |
| 2334 | HandleInvoke(invoke); |
| 2335 | } |
| 2336 | |
| 2337 | void InstructionCodeGeneratorX86_64::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 2338 | codegen_->GenerateInvokeUnresolvedRuntimeCall(invoke); |
| 2339 | } |
| 2340 | |
| Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 2341 | void LocationsBuilderX86_64::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
| David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 2342 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 2343 | // art::PrepareForRegisterAllocation. |
| 2344 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
| Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 2345 | |
| Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 2346 | IntrinsicLocationsBuilderX86_64 intrinsic(codegen_); |
| Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 2347 | if (intrinsic.TryDispatch(invoke)) { |
| 2348 | return; |
| 2349 | } |
| 2350 | |
| Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2351 | HandleInvoke(invoke); |
| 2352 | } |
| 2353 | |
| Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 2354 | static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorX86_64* codegen) { |
| 2355 | if (invoke->GetLocations()->Intrinsified()) { |
| 2356 | IntrinsicCodeGeneratorX86_64 intrinsic(codegen); |
| 2357 | intrinsic.Dispatch(invoke); |
| 2358 | return true; |
| 2359 | } |
| 2360 | return false; |
| 2361 | } |
| 2362 | |
| Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 2363 | void InstructionCodeGeneratorX86_64::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
| David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 2364 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 2365 | // art::PrepareForRegisterAllocation. |
| 2366 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
| Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 2367 | |
| Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 2368 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 2369 | return; |
| 2370 | } |
| Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2371 | |
| Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 2372 | LocationSummary* locations = invoke->GetLocations(); |
| Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 2373 | codegen_->GenerateStaticOrDirectCall( |
| Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 2374 | invoke, locations->HasTemps() ? locations->GetTemp(0) : Location::NoLocation()); |
| Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2375 | } |
| 2376 | |
| Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2377 | void LocationsBuilderX86_64::HandleInvoke(HInvoke* invoke) { |
| Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 2378 | InvokeDexCallingConventionVisitorX86_64 calling_convention_visitor; |
| Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 2379 | CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2380 | } |
| 2381 | |
| Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2382 | void LocationsBuilderX86_64::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
| Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 2383 | IntrinsicLocationsBuilderX86_64 intrinsic(codegen_); |
| Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 2384 | if (intrinsic.TryDispatch(invoke)) { |
| 2385 | return; |
| 2386 | } |
| 2387 | |
| Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2388 | HandleInvoke(invoke); |
| 2389 | } |
| 2390 | |
| Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2391 | void InstructionCodeGeneratorX86_64::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
| Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 2392 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 2393 | return; |
| 2394 | } |
| 2395 | |
| Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 2396 | codegen_->GenerateVirtualCall(invoke, invoke->GetLocations()->GetTemp(0)); |
| Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 2397 | DCHECK(!codegen_->IsLeafMethod()); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2398 | } |
| 2399 | |
| Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2400 | void LocationsBuilderX86_64::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 2401 | HandleInvoke(invoke); |
| 2402 | // Add the hidden argument. |
| 2403 | invoke->GetLocations()->AddTemp(Location::RegisterLocation(RAX)); |
| 2404 | } |
| 2405 | |
| 2406 | void InstructionCodeGeneratorX86_64::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 2407 | // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError. |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2408 | LocationSummary* locations = invoke->GetLocations(); |
| 2409 | CpuRegister temp = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 2410 | CpuRegister hidden_reg = locations->GetTemp(1).AsRegister<CpuRegister>(); |
| Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2411 | Location receiver = locations->InAt(0); |
| 2412 | size_t class_offset = mirror::Object::ClassOffset().SizeValue(); |
| 2413 | |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2414 | // Set the hidden argument. This is safe to do this here, as RAX |
| 2415 | // won't be modified thereafter, before the `call` instruction. |
| 2416 | DCHECK_EQ(RAX, hidden_reg.AsRegister()); |
| Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 2417 | codegen_->Load64BitValue(hidden_reg, invoke->GetDexMethodIndex()); |
| Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2418 | |
| Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2419 | if (receiver.IsStackSlot()) { |
| 2420 | __ movl(temp, Address(CpuRegister(RSP), receiver.GetStackIndex())); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2421 | // /* HeapReference<Class> */ temp = temp->klass_ |
| Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2422 | __ movl(temp, Address(temp, class_offset)); |
| 2423 | } else { |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2424 | // /* HeapReference<Class> */ temp = receiver->klass_ |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2425 | __ movl(temp, Address(receiver.AsRegister<CpuRegister>(), class_offset)); |
| Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2426 | } |
| Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 2427 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2428 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 2429 | // emit a read barrier for the previous class reference load. |
| 2430 | // However this is not required in practice, as this is an |
| 2431 | // intermediate/temporary reference and because the current |
| 2432 | // concurrent copying collector keeps the from-space memory |
| 2433 | // intact/accessible until the end of the marking phase (the |
| 2434 | // concurrent copying collector may not in the future). |
| Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2435 | __ MaybeUnpoisonHeapReference(temp); |
| Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 2436 | // temp = temp->GetAddressOfIMT() |
| 2437 | __ movq(temp, |
| 2438 | Address(temp, mirror::Class::ImtPtrOffset(kX86_64PointerSize).Uint32Value())); |
| 2439 | // temp = temp->GetImtEntryAt(method_offset); |
| 2440 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
| Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 2441 | invoke->GetImtIndex(), kX86_64PointerSize)); |
| Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2442 | // temp = temp->GetImtEntryAt(method_offset); |
| Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 2443 | __ movq(temp, Address(temp, method_offset)); |
| Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2444 | // call temp->GetEntryPoint(); |
| Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 2445 | __ call(Address( |
| 2446 | temp, ArtMethod::EntryPointFromQuickCompiledCodeOffset(kX86_64PointerSize).SizeValue())); |
| Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2447 | |
| 2448 | DCHECK(!codegen_->IsLeafMethod()); |
| 2449 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 2450 | } |
| 2451 | |
| Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 2452 | void LocationsBuilderX86_64::VisitInvokePolymorphic(HInvokePolymorphic* invoke) { |
| 2453 | HandleInvoke(invoke); |
| 2454 | } |
| 2455 | |
| 2456 | void InstructionCodeGeneratorX86_64::VisitInvokePolymorphic(HInvokePolymorphic* invoke) { |
| 2457 | codegen_->GenerateInvokePolymorphicCall(invoke); |
| 2458 | } |
| 2459 | |
| Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2460 | void LocationsBuilderX86_64::VisitNeg(HNeg* neg) { |
| 2461 | LocationSummary* locations = |
| 2462 | new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall); |
| 2463 | switch (neg->GetResultType()) { |
| 2464 | case Primitive::kPrimInt: |
| Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 2465 | case Primitive::kPrimLong: |
| Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2466 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2467 | locations->SetOut(Location::SameAsFirstInput()); |
| 2468 | break; |
| 2469 | |
| Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2470 | case Primitive::kPrimFloat: |
| 2471 | case Primitive::kPrimDouble: |
| Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2472 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2473 | locations->SetOut(Location::SameAsFirstInput()); |
| Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2474 | locations->AddTemp(Location::RequiresFpuRegister()); |
| Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2475 | break; |
| 2476 | |
| 2477 | default: |
| 2478 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 2479 | } |
| 2480 | } |
| 2481 | |
| 2482 | void InstructionCodeGeneratorX86_64::VisitNeg(HNeg* neg) { |
| 2483 | LocationSummary* locations = neg->GetLocations(); |
| 2484 | Location out = locations->Out(); |
| 2485 | Location in = locations->InAt(0); |
| 2486 | switch (neg->GetResultType()) { |
| 2487 | case Primitive::kPrimInt: |
| 2488 | DCHECK(in.IsRegister()); |
| Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2489 | DCHECK(in.Equals(out)); |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2490 | __ negl(out.AsRegister<CpuRegister>()); |
| Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2491 | break; |
| 2492 | |
| 2493 | case Primitive::kPrimLong: |
| Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 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 | __ negq(out.AsRegister<CpuRegister>()); |
| Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 2497 | break; |
| 2498 | |
| Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2499 | case Primitive::kPrimFloat: { |
| 2500 | DCHECK(in.Equals(out)); |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2501 | XmmRegister mask = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2502 | // Implement float negation with an exclusive or with value |
| 2503 | // 0x80000000 (mask for bit 31, representing the sign of a |
| 2504 | // single-precision floating-point number). |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2505 | __ movss(mask, codegen_->LiteralInt32Address(0x80000000)); |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2506 | __ xorps(out.AsFpuRegister<XmmRegister>(), mask); |
| Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2507 | break; |
| Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2508 | } |
| Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2509 | |
| Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2510 | case Primitive::kPrimDouble: { |
| 2511 | DCHECK(in.Equals(out)); |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2512 | XmmRegister mask = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2513 | // Implement double negation with an exclusive or with value |
| Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2514 | // 0x8000000000000000 (mask for bit 63, representing the sign of |
| Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2515 | // a double-precision floating-point number). |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2516 | __ movsd(mask, codegen_->LiteralInt64Address(INT64_C(0x8000000000000000))); |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2517 | __ xorpd(out.AsFpuRegister<XmmRegister>(), mask); |
| Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2518 | break; |
| Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2519 | } |
| Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2520 | |
| 2521 | default: |
| 2522 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 2523 | } |
| 2524 | } |
| 2525 | |
| Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2526 | void LocationsBuilderX86_64::VisitTypeConversion(HTypeConversion* conversion) { |
| 2527 | LocationSummary* locations = |
| 2528 | new (GetGraph()->GetArena()) LocationSummary(conversion, LocationSummary::kNoCall); |
| 2529 | Primitive::Type result_type = conversion->GetResultType(); |
| 2530 | Primitive::Type input_type = conversion->GetInputType(); |
| Nicolas Geoffray | 01fcc9e | 2014-12-01 14:16:20 +0000 | [diff] [blame] | 2531 | DCHECK_NE(result_type, input_type); |
| David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2532 | |
| David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 2533 | // The Java language does not allow treating boolean as an integral type but |
| 2534 | // our bit representation makes it safe. |
| David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2535 | |
| Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2536 | switch (result_type) { |
| Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2537 | case Primitive::kPrimByte: |
| 2538 | switch (input_type) { |
| Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2539 | case Primitive::kPrimLong: |
| 2540 | // Type conversion from long to byte is a result of code transformations. |
| David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2541 | case Primitive::kPrimBoolean: |
| 2542 | // Boolean input is a result of code transformations. |
| Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2543 | case Primitive::kPrimShort: |
| 2544 | case Primitive::kPrimInt: |
| 2545 | case Primitive::kPrimChar: |
| Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2546 | // Processing a Dex `int-to-byte' instruction. |
| Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2547 | locations->SetInAt(0, Location::Any()); |
| 2548 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2549 | break; |
| 2550 | |
| 2551 | default: |
| 2552 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2553 | << " to " << result_type; |
| 2554 | } |
| 2555 | break; |
| 2556 | |
| Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2557 | case Primitive::kPrimShort: |
| 2558 | switch (input_type) { |
| Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2559 | case Primitive::kPrimLong: |
| 2560 | // Type conversion from long to short is a result of code transformations. |
| David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2561 | case Primitive::kPrimBoolean: |
| 2562 | // Boolean input is a result of code transformations. |
| Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2563 | case Primitive::kPrimByte: |
| 2564 | case Primitive::kPrimInt: |
| 2565 | case Primitive::kPrimChar: |
| 2566 | // Processing a Dex `int-to-short' instruction. |
| 2567 | locations->SetInAt(0, Location::Any()); |
| 2568 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2569 | break; |
| 2570 | |
| 2571 | default: |
| 2572 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2573 | << " to " << result_type; |
| 2574 | } |
| 2575 | break; |
| 2576 | |
| Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2577 | case Primitive::kPrimInt: |
| 2578 | switch (input_type) { |
| 2579 | case Primitive::kPrimLong: |
| Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2580 | // Processing a Dex `long-to-int' instruction. |
| Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2581 | locations->SetInAt(0, Location::Any()); |
| 2582 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2583 | break; |
| 2584 | |
| 2585 | case Primitive::kPrimFloat: |
| Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2586 | // Processing a Dex `float-to-int' instruction. |
| 2587 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2588 | locations->SetOut(Location::RequiresRegister()); |
| Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2589 | break; |
| 2590 | |
| Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2591 | case Primitive::kPrimDouble: |
| Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2592 | // Processing a Dex `double-to-int' instruction. |
| 2593 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2594 | locations->SetOut(Location::RequiresRegister()); |
| Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2595 | break; |
| 2596 | |
| 2597 | default: |
| 2598 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2599 | << " to " << result_type; |
| 2600 | } |
| 2601 | break; |
| 2602 | |
| Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2603 | case Primitive::kPrimLong: |
| 2604 | switch (input_type) { |
| David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2605 | case Primitive::kPrimBoolean: |
| 2606 | // Boolean input is a result of code transformations. |
| Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2607 | case Primitive::kPrimByte: |
| 2608 | case Primitive::kPrimShort: |
| 2609 | case Primitive::kPrimInt: |
| Roland Levillain | 666c732 | 2014-11-10 13:39:43 +0000 | [diff] [blame] | 2610 | case Primitive::kPrimChar: |
| Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2611 | // Processing a Dex `int-to-long' instruction. |
| Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2612 | // TODO: We would benefit from a (to-be-implemented) |
| 2613 | // Location::RegisterOrStackSlot requirement for this input. |
| 2614 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2615 | locations->SetOut(Location::RequiresRegister()); |
| 2616 | break; |
| 2617 | |
| 2618 | case Primitive::kPrimFloat: |
| Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2619 | // Processing a Dex `float-to-long' instruction. |
| 2620 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2621 | locations->SetOut(Location::RequiresRegister()); |
| Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2622 | break; |
| 2623 | |
| Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2624 | case Primitive::kPrimDouble: |
| Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2625 | // Processing a Dex `double-to-long' instruction. |
| 2626 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2627 | locations->SetOut(Location::RequiresRegister()); |
| Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2628 | break; |
| 2629 | |
| 2630 | default: |
| 2631 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2632 | << " to " << result_type; |
| 2633 | } |
| 2634 | break; |
| 2635 | |
| Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2636 | case Primitive::kPrimChar: |
| 2637 | switch (input_type) { |
| Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2638 | case Primitive::kPrimLong: |
| 2639 | // Type conversion from long to char is a result of code transformations. |
| David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2640 | case Primitive::kPrimBoolean: |
| 2641 | // Boolean input is a result of code transformations. |
| Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2642 | case Primitive::kPrimByte: |
| 2643 | case Primitive::kPrimShort: |
| 2644 | case Primitive::kPrimInt: |
| Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2645 | // Processing a Dex `int-to-char' instruction. |
| 2646 | locations->SetInAt(0, Location::Any()); |
| 2647 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2648 | break; |
| 2649 | |
| 2650 | default: |
| 2651 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2652 | << " to " << result_type; |
| 2653 | } |
| 2654 | break; |
| 2655 | |
| Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2656 | case Primitive::kPrimFloat: |
| Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2657 | switch (input_type) { |
| David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2658 | case Primitive::kPrimBoolean: |
| 2659 | // Boolean input is a result of code transformations. |
| Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2660 | case Primitive::kPrimByte: |
| 2661 | case Primitive::kPrimShort: |
| 2662 | case Primitive::kPrimInt: |
| 2663 | case Primitive::kPrimChar: |
| 2664 | // Processing a Dex `int-to-float' instruction. |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2665 | locations->SetInAt(0, Location::Any()); |
| Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2666 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2667 | break; |
| 2668 | |
| 2669 | case Primitive::kPrimLong: |
| Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2670 | // Processing a Dex `long-to-float' instruction. |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2671 | locations->SetInAt(0, Location::Any()); |
| Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2672 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2673 | break; |
| 2674 | |
| Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2675 | case Primitive::kPrimDouble: |
| Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2676 | // Processing a Dex `double-to-float' instruction. |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2677 | locations->SetInAt(0, Location::Any()); |
| Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2678 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2679 | break; |
| 2680 | |
| 2681 | default: |
| 2682 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2683 | << " to " << result_type; |
| 2684 | }; |
| 2685 | break; |
| 2686 | |
| Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2687 | case Primitive::kPrimDouble: |
| Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2688 | switch (input_type) { |
| David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2689 | case Primitive::kPrimBoolean: |
| 2690 | // Boolean input is a result of code transformations. |
| Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2691 | case Primitive::kPrimByte: |
| 2692 | case Primitive::kPrimShort: |
| 2693 | case Primitive::kPrimInt: |
| 2694 | case Primitive::kPrimChar: |
| 2695 | // Processing a Dex `int-to-double' instruction. |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2696 | locations->SetInAt(0, Location::Any()); |
| Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2697 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2698 | break; |
| 2699 | |
| 2700 | case Primitive::kPrimLong: |
| Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2701 | // Processing a Dex `long-to-double' instruction. |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2702 | locations->SetInAt(0, Location::Any()); |
| Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2703 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2704 | break; |
| 2705 | |
| Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2706 | case Primitive::kPrimFloat: |
| Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2707 | // Processing a Dex `float-to-double' instruction. |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2708 | locations->SetInAt(0, Location::Any()); |
| Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2709 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2710 | break; |
| 2711 | |
| 2712 | default: |
| 2713 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2714 | << " to " << result_type; |
| 2715 | } |
| Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2716 | break; |
| 2717 | |
| 2718 | default: |
| 2719 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2720 | << " to " << result_type; |
| 2721 | } |
| 2722 | } |
| 2723 | |
| 2724 | void InstructionCodeGeneratorX86_64::VisitTypeConversion(HTypeConversion* conversion) { |
| 2725 | LocationSummary* locations = conversion->GetLocations(); |
| 2726 | Location out = locations->Out(); |
| 2727 | Location in = locations->InAt(0); |
| 2728 | Primitive::Type result_type = conversion->GetResultType(); |
| 2729 | Primitive::Type input_type = conversion->GetInputType(); |
| Nicolas Geoffray | 01fcc9e | 2014-12-01 14:16:20 +0000 | [diff] [blame] | 2730 | DCHECK_NE(result_type, input_type); |
| Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2731 | switch (result_type) { |
| Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2732 | case Primitive::kPrimByte: |
| 2733 | switch (input_type) { |
| Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2734 | case Primitive::kPrimLong: |
| 2735 | // Type conversion from long to byte is a result of code transformations. |
| David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2736 | case Primitive::kPrimBoolean: |
| 2737 | // Boolean input is a result of code transformations. |
| Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2738 | case Primitive::kPrimShort: |
| 2739 | case Primitive::kPrimInt: |
| 2740 | case Primitive::kPrimChar: |
| Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2741 | // Processing a Dex `int-to-byte' instruction. |
| Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2742 | if (in.IsRegister()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2743 | __ movsxb(out.AsRegister<CpuRegister>(), in.AsRegister<CpuRegister>()); |
| Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2744 | } else if (in.IsStackSlot() || in.IsDoubleStackSlot()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2745 | __ movsxb(out.AsRegister<CpuRegister>(), |
| Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2746 | Address(CpuRegister(RSP), in.GetStackIndex())); |
| 2747 | } else { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2748 | __ movl(out.AsRegister<CpuRegister>(), |
| Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2749 | Immediate(static_cast<int8_t>(Int64FromConstant(in.GetConstant())))); |
| Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2750 | } |
| 2751 | break; |
| 2752 | |
| 2753 | default: |
| 2754 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2755 | << " to " << result_type; |
| 2756 | } |
| 2757 | break; |
| 2758 | |
| Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2759 | case Primitive::kPrimShort: |
| 2760 | switch (input_type) { |
| Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2761 | case Primitive::kPrimLong: |
| 2762 | // Type conversion from long to short is a result of code transformations. |
| David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2763 | case Primitive::kPrimBoolean: |
| 2764 | // Boolean input is a result of code transformations. |
| Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2765 | case Primitive::kPrimByte: |
| 2766 | case Primitive::kPrimInt: |
| 2767 | case Primitive::kPrimChar: |
| 2768 | // Processing a Dex `int-to-short' instruction. |
| 2769 | if (in.IsRegister()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2770 | __ movsxw(out.AsRegister<CpuRegister>(), in.AsRegister<CpuRegister>()); |
| Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2771 | } else if (in.IsStackSlot() || in.IsDoubleStackSlot()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2772 | __ movsxw(out.AsRegister<CpuRegister>(), |
| Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2773 | Address(CpuRegister(RSP), in.GetStackIndex())); |
| 2774 | } else { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2775 | __ movl(out.AsRegister<CpuRegister>(), |
| Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2776 | Immediate(static_cast<int16_t>(Int64FromConstant(in.GetConstant())))); |
| Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2777 | } |
| 2778 | break; |
| 2779 | |
| 2780 | default: |
| 2781 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2782 | << " to " << result_type; |
| 2783 | } |
| 2784 | break; |
| 2785 | |
| Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2786 | case Primitive::kPrimInt: |
| 2787 | switch (input_type) { |
| 2788 | case Primitive::kPrimLong: |
| Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2789 | // Processing a Dex `long-to-int' instruction. |
| Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2790 | if (in.IsRegister()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2791 | __ movl(out.AsRegister<CpuRegister>(), in.AsRegister<CpuRegister>()); |
| Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2792 | } else if (in.IsDoubleStackSlot()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2793 | __ movl(out.AsRegister<CpuRegister>(), |
| Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2794 | Address(CpuRegister(RSP), in.GetStackIndex())); |
| 2795 | } else { |
| 2796 | DCHECK(in.IsConstant()); |
| 2797 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 2798 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2799 | __ movl(out.AsRegister<CpuRegister>(), Immediate(static_cast<int32_t>(value))); |
| Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2800 | } |
| 2801 | break; |
| 2802 | |
| Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2803 | case Primitive::kPrimFloat: { |
| 2804 | // Processing a Dex `float-to-int' instruction. |
| 2805 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 2806 | CpuRegister output = out.AsRegister<CpuRegister>(); |
| Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2807 | NearLabel done, nan; |
| Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2808 | |
| 2809 | __ movl(output, Immediate(kPrimIntMax)); |
| Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 2810 | // if input >= (float)INT_MAX goto done |
| 2811 | __ comiss(input, codegen_->LiteralFloatAddress(kPrimIntMax)); |
| Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2812 | __ j(kAboveEqual, &done); |
| 2813 | // if input == NaN goto nan |
| 2814 | __ j(kUnordered, &nan); |
| 2815 | // output = float-to-int-truncate(input) |
| Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2816 | __ cvttss2si(output, input, false); |
| Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2817 | __ jmp(&done); |
| 2818 | __ Bind(&nan); |
| 2819 | // output = 0 |
| 2820 | __ xorl(output, output); |
| 2821 | __ Bind(&done); |
| 2822 | break; |
| 2823 | } |
| 2824 | |
| Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2825 | case Primitive::kPrimDouble: { |
| 2826 | // Processing a Dex `double-to-int' instruction. |
| 2827 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 2828 | CpuRegister output = out.AsRegister<CpuRegister>(); |
| Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2829 | NearLabel done, nan; |
| Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2830 | |
| 2831 | __ movl(output, Immediate(kPrimIntMax)); |
| Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 2832 | // if input >= (double)INT_MAX goto done |
| 2833 | __ comisd(input, codegen_->LiteralDoubleAddress(kPrimIntMax)); |
| Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2834 | __ j(kAboveEqual, &done); |
| 2835 | // if input == NaN goto nan |
| 2836 | __ j(kUnordered, &nan); |
| 2837 | // output = double-to-int-truncate(input) |
| 2838 | __ cvttsd2si(output, input); |
| 2839 | __ jmp(&done); |
| 2840 | __ Bind(&nan); |
| 2841 | // output = 0 |
| 2842 | __ xorl(output, output); |
| 2843 | __ Bind(&done); |
| Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2844 | break; |
| Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2845 | } |
| Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2846 | |
| 2847 | default: |
| 2848 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2849 | << " to " << result_type; |
| 2850 | } |
| 2851 | break; |
| 2852 | |
| Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2853 | case Primitive::kPrimLong: |
| 2854 | switch (input_type) { |
| 2855 | DCHECK(out.IsRegister()); |
| David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2856 | case Primitive::kPrimBoolean: |
| 2857 | // Boolean input is a result of code transformations. |
| Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2858 | case Primitive::kPrimByte: |
| 2859 | case Primitive::kPrimShort: |
| 2860 | case Primitive::kPrimInt: |
| Roland Levillain | 666c732 | 2014-11-10 13:39:43 +0000 | [diff] [blame] | 2861 | case Primitive::kPrimChar: |
| Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2862 | // Processing a Dex `int-to-long' instruction. |
| Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2863 | DCHECK(in.IsRegister()); |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2864 | __ movsxd(out.AsRegister<CpuRegister>(), in.AsRegister<CpuRegister>()); |
| Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2865 | break; |
| 2866 | |
| Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2867 | case Primitive::kPrimFloat: { |
| 2868 | // Processing a Dex `float-to-long' instruction. |
| 2869 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 2870 | CpuRegister output = out.AsRegister<CpuRegister>(); |
| Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2871 | NearLabel done, nan; |
| Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2872 | |
| Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 2873 | codegen_->Load64BitValue(output, kPrimLongMax); |
| Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 2874 | // if input >= (float)LONG_MAX goto done |
| 2875 | __ comiss(input, codegen_->LiteralFloatAddress(kPrimLongMax)); |
| Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2876 | __ j(kAboveEqual, &done); |
| 2877 | // if input == NaN goto nan |
| 2878 | __ j(kUnordered, &nan); |
| Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2879 | // output = float-to-long-truncate(input) |
| Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2880 | __ cvttss2si(output, input, true); |
| 2881 | __ jmp(&done); |
| 2882 | __ Bind(&nan); |
| 2883 | // output = 0 |
| Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 2884 | __ xorl(output, output); |
| Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2885 | __ Bind(&done); |
| 2886 | break; |
| 2887 | } |
| 2888 | |
| Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2889 | case Primitive::kPrimDouble: { |
| 2890 | // Processing a Dex `double-to-long' instruction. |
| 2891 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 2892 | CpuRegister output = out.AsRegister<CpuRegister>(); |
| Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2893 | NearLabel done, nan; |
| Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2894 | |
| Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 2895 | codegen_->Load64BitValue(output, kPrimLongMax); |
| Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 2896 | // if input >= (double)LONG_MAX goto done |
| 2897 | __ comisd(input, codegen_->LiteralDoubleAddress(kPrimLongMax)); |
| Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2898 | __ j(kAboveEqual, &done); |
| 2899 | // if input == NaN goto nan |
| 2900 | __ j(kUnordered, &nan); |
| 2901 | // output = double-to-long-truncate(input) |
| 2902 | __ cvttsd2si(output, input, true); |
| 2903 | __ jmp(&done); |
| 2904 | __ Bind(&nan); |
| 2905 | // output = 0 |
| Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 2906 | __ xorl(output, output); |
| Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2907 | __ Bind(&done); |
| Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2908 | break; |
| Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2909 | } |
| Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2910 | |
| 2911 | default: |
| 2912 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2913 | << " to " << result_type; |
| 2914 | } |
| 2915 | break; |
| 2916 | |
| Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2917 | case Primitive::kPrimChar: |
| 2918 | switch (input_type) { |
| Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2919 | case Primitive::kPrimLong: |
| 2920 | // Type conversion from long to char is a result of code transformations. |
| David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2921 | case Primitive::kPrimBoolean: |
| 2922 | // Boolean input is a result of code transformations. |
| Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2923 | case Primitive::kPrimByte: |
| 2924 | case Primitive::kPrimShort: |
| 2925 | case Primitive::kPrimInt: |
| Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2926 | // Processing a Dex `int-to-char' instruction. |
| 2927 | if (in.IsRegister()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2928 | __ movzxw(out.AsRegister<CpuRegister>(), in.AsRegister<CpuRegister>()); |
| Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2929 | } else if (in.IsStackSlot() || in.IsDoubleStackSlot()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2930 | __ movzxw(out.AsRegister<CpuRegister>(), |
| Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2931 | Address(CpuRegister(RSP), in.GetStackIndex())); |
| 2932 | } else { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2933 | __ movl(out.AsRegister<CpuRegister>(), |
| Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2934 | Immediate(static_cast<uint16_t>(Int64FromConstant(in.GetConstant())))); |
| Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2935 | } |
| 2936 | break; |
| 2937 | |
| 2938 | default: |
| 2939 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2940 | << " to " << result_type; |
| 2941 | } |
| 2942 | break; |
| 2943 | |
| Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2944 | case Primitive::kPrimFloat: |
| Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2945 | switch (input_type) { |
| David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2946 | case Primitive::kPrimBoolean: |
| 2947 | // Boolean input is a result of code transformations. |
| Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2948 | case Primitive::kPrimByte: |
| 2949 | case Primitive::kPrimShort: |
| 2950 | case Primitive::kPrimInt: |
| 2951 | case Primitive::kPrimChar: |
| Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2952 | // Processing a Dex `int-to-float' instruction. |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2953 | if (in.IsRegister()) { |
| 2954 | __ cvtsi2ss(out.AsFpuRegister<XmmRegister>(), in.AsRegister<CpuRegister>(), false); |
| 2955 | } else if (in.IsConstant()) { |
| 2956 | int32_t v = in.GetConstant()->AsIntConstant()->GetValue(); |
| 2957 | XmmRegister dest = out.AsFpuRegister<XmmRegister>(); |
| Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 2958 | codegen_->Load32BitValue(dest, static_cast<float>(v)); |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2959 | } else { |
| 2960 | __ cvtsi2ss(out.AsFpuRegister<XmmRegister>(), |
| 2961 | Address(CpuRegister(RSP), in.GetStackIndex()), false); |
| 2962 | } |
| Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2963 | break; |
| 2964 | |
| 2965 | case Primitive::kPrimLong: |
| Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2966 | // Processing a Dex `long-to-float' instruction. |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2967 | if (in.IsRegister()) { |
| 2968 | __ cvtsi2ss(out.AsFpuRegister<XmmRegister>(), in.AsRegister<CpuRegister>(), true); |
| 2969 | } else if (in.IsConstant()) { |
| 2970 | int64_t v = in.GetConstant()->AsLongConstant()->GetValue(); |
| 2971 | XmmRegister dest = out.AsFpuRegister<XmmRegister>(); |
| Pavel Vyssotski | 4c858cd | 2016-03-16 13:59:53 +0600 | [diff] [blame] | 2972 | codegen_->Load32BitValue(dest, static_cast<float>(v)); |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2973 | } else { |
| 2974 | __ cvtsi2ss(out.AsFpuRegister<XmmRegister>(), |
| 2975 | Address(CpuRegister(RSP), in.GetStackIndex()), true); |
| 2976 | } |
| Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2977 | break; |
| 2978 | |
| Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2979 | case Primitive::kPrimDouble: |
| Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2980 | // Processing a Dex `double-to-float' instruction. |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2981 | if (in.IsFpuRegister()) { |
| 2982 | __ cvtsd2ss(out.AsFpuRegister<XmmRegister>(), in.AsFpuRegister<XmmRegister>()); |
| 2983 | } else if (in.IsConstant()) { |
| 2984 | double v = in.GetConstant()->AsDoubleConstant()->GetValue(); |
| 2985 | XmmRegister dest = out.AsFpuRegister<XmmRegister>(); |
| Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 2986 | codegen_->Load32BitValue(dest, static_cast<float>(v)); |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2987 | } else { |
| 2988 | __ cvtsd2ss(out.AsFpuRegister<XmmRegister>(), |
| 2989 | Address(CpuRegister(RSP), in.GetStackIndex())); |
| 2990 | } |
| Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2991 | break; |
| 2992 | |
| 2993 | default: |
| 2994 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2995 | << " to " << result_type; |
| 2996 | }; |
| 2997 | break; |
| 2998 | |
| Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2999 | case Primitive::kPrimDouble: |
| Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3000 | switch (input_type) { |
| David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 3001 | case Primitive::kPrimBoolean: |
| 3002 | // Boolean input is a result of code transformations. |
| Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3003 | case Primitive::kPrimByte: |
| 3004 | case Primitive::kPrimShort: |
| 3005 | case Primitive::kPrimInt: |
| 3006 | case Primitive::kPrimChar: |
| Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 3007 | // Processing a Dex `int-to-double' instruction. |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 3008 | if (in.IsRegister()) { |
| 3009 | __ cvtsi2sd(out.AsFpuRegister<XmmRegister>(), in.AsRegister<CpuRegister>(), false); |
| 3010 | } else if (in.IsConstant()) { |
| 3011 | int32_t v = in.GetConstant()->AsIntConstant()->GetValue(); |
| 3012 | XmmRegister dest = out.AsFpuRegister<XmmRegister>(); |
| Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 3013 | codegen_->Load64BitValue(dest, static_cast<double>(v)); |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 3014 | } else { |
| 3015 | __ cvtsi2sd(out.AsFpuRegister<XmmRegister>(), |
| 3016 | Address(CpuRegister(RSP), in.GetStackIndex()), false); |
| 3017 | } |
| Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3018 | break; |
| 3019 | |
| 3020 | case Primitive::kPrimLong: |
| Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 3021 | // Processing a Dex `long-to-double' instruction. |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 3022 | if (in.IsRegister()) { |
| 3023 | __ cvtsi2sd(out.AsFpuRegister<XmmRegister>(), in.AsRegister<CpuRegister>(), true); |
| 3024 | } else if (in.IsConstant()) { |
| 3025 | int64_t v = in.GetConstant()->AsLongConstant()->GetValue(); |
| 3026 | XmmRegister dest = out.AsFpuRegister<XmmRegister>(); |
| Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 3027 | codegen_->Load64BitValue(dest, static_cast<double>(v)); |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 3028 | } else { |
| 3029 | __ cvtsi2sd(out.AsFpuRegister<XmmRegister>(), |
| 3030 | Address(CpuRegister(RSP), in.GetStackIndex()), true); |
| 3031 | } |
| Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 3032 | break; |
| 3033 | |
| Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3034 | case Primitive::kPrimFloat: |
| Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 3035 | // Processing a Dex `float-to-double' instruction. |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 3036 | if (in.IsFpuRegister()) { |
| 3037 | __ cvtss2sd(out.AsFpuRegister<XmmRegister>(), in.AsFpuRegister<XmmRegister>()); |
| 3038 | } else if (in.IsConstant()) { |
| 3039 | float v = in.GetConstant()->AsFloatConstant()->GetValue(); |
| 3040 | XmmRegister dest = out.AsFpuRegister<XmmRegister>(); |
| Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 3041 | codegen_->Load64BitValue(dest, static_cast<double>(v)); |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 3042 | } else { |
| 3043 | __ cvtss2sd(out.AsFpuRegister<XmmRegister>(), |
| 3044 | Address(CpuRegister(RSP), in.GetStackIndex())); |
| 3045 | } |
| Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3046 | break; |
| 3047 | |
| 3048 | default: |
| 3049 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3050 | << " to " << result_type; |
| 3051 | }; |
| Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3052 | break; |
| 3053 | |
| 3054 | default: |
| 3055 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3056 | << " to " << result_type; |
| 3057 | } |
| 3058 | } |
| 3059 | |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3060 | void LocationsBuilderX86_64::VisitAdd(HAdd* add) { |
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3061 | LocationSummary* locations = |
| 3062 | new (GetGraph()->GetArena()) LocationSummary(add, LocationSummary::kNoCall); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3063 | switch (add->GetResultType()) { |
| Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 3064 | case Primitive::kPrimInt: { |
| 3065 | locations->SetInAt(0, Location::RequiresRegister()); |
| Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 3066 | locations->SetInAt(1, Location::RegisterOrConstant(add->InputAt(1))); |
| 3067 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 3068 | break; |
| 3069 | } |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3070 | |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3071 | case Primitive::kPrimLong: { |
| Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 3072 | locations->SetInAt(0, Location::RequiresRegister()); |
| Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 3073 | // 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] | 3074 | locations->SetInAt(1, Location::RegisterOrInt32Constant(add->InputAt(1))); |
| Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 3075 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3076 | break; |
| 3077 | } |
| 3078 | |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3079 | case Primitive::kPrimDouble: |
| 3080 | case Primitive::kPrimFloat: { |
| 3081 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3082 | locations->SetInAt(1, Location::Any()); |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3083 | locations->SetOut(Location::SameAsFirstInput()); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3084 | break; |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3085 | } |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3086 | |
| 3087 | default: |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3088 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3089 | } |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3090 | } |
| 3091 | |
| 3092 | void InstructionCodeGeneratorX86_64::VisitAdd(HAdd* add) { |
| 3093 | LocationSummary* locations = add->GetLocations(); |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3094 | Location first = locations->InAt(0); |
| 3095 | Location second = locations->InAt(1); |
| Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 3096 | Location out = locations->Out(); |
| Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3097 | |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3098 | switch (add->GetResultType()) { |
| Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 3099 | case Primitive::kPrimInt: { |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3100 | if (second.IsRegister()) { |
| Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 3101 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 3102 | __ addl(out.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
| Mark Mendell | 33bf245 | 2015-05-27 10:08:24 -0400 | [diff] [blame] | 3103 | } else if (out.AsRegister<Register>() == second.AsRegister<Register>()) { |
| 3104 | __ addl(out.AsRegister<CpuRegister>(), first.AsRegister<CpuRegister>()); |
| Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 3105 | } else { |
| 3106 | __ leal(out.AsRegister<CpuRegister>(), Address( |
| 3107 | first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>(), TIMES_1, 0)); |
| 3108 | } |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3109 | } else if (second.IsConstant()) { |
| Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 3110 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 3111 | __ addl(out.AsRegister<CpuRegister>(), |
| 3112 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
| 3113 | } else { |
| 3114 | __ leal(out.AsRegister<CpuRegister>(), Address( |
| 3115 | first.AsRegister<CpuRegister>(), second.GetConstant()->AsIntConstant()->GetValue())); |
| 3116 | } |
| Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 3117 | } else { |
| Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 3118 | DCHECK(first.Equals(locations->Out())); |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3119 | __ addl(first.AsRegister<CpuRegister>(), Address(CpuRegister(RSP), second.GetStackIndex())); |
| Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 3120 | } |
| Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 3121 | break; |
| 3122 | } |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3123 | |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3124 | case Primitive::kPrimLong: { |
| Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 3125 | if (second.IsRegister()) { |
| 3126 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 3127 | __ addq(out.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
| Mark Mendell | 33bf245 | 2015-05-27 10:08:24 -0400 | [diff] [blame] | 3128 | } else if (out.AsRegister<Register>() == second.AsRegister<Register>()) { |
| 3129 | __ addq(out.AsRegister<CpuRegister>(), first.AsRegister<CpuRegister>()); |
| Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 3130 | } else { |
| 3131 | __ leaq(out.AsRegister<CpuRegister>(), Address( |
| 3132 | first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>(), TIMES_1, 0)); |
| 3133 | } |
| 3134 | } else { |
| 3135 | DCHECK(second.IsConstant()); |
| 3136 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 3137 | int32_t int32_value = Low32Bits(value); |
| 3138 | DCHECK_EQ(int32_value, value); |
| 3139 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 3140 | __ addq(out.AsRegister<CpuRegister>(), Immediate(int32_value)); |
| 3141 | } else { |
| 3142 | __ leaq(out.AsRegister<CpuRegister>(), Address( |
| 3143 | first.AsRegister<CpuRegister>(), int32_value)); |
| 3144 | } |
| 3145 | } |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3146 | break; |
| 3147 | } |
| 3148 | |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3149 | case Primitive::kPrimFloat: { |
| Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3150 | if (second.IsFpuRegister()) { |
| 3151 | __ addss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3152 | } else if (second.IsConstant()) { |
| 3153 | __ addss(first.AsFpuRegister<XmmRegister>(), |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 3154 | codegen_->LiteralFloatAddress( |
| 3155 | second.GetConstant()->AsFloatConstant()->GetValue())); |
| Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3156 | } else { |
| 3157 | DCHECK(second.IsStackSlot()); |
| 3158 | __ addss(first.AsFpuRegister<XmmRegister>(), |
| 3159 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 3160 | } |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3161 | break; |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3162 | } |
| 3163 | |
| 3164 | case Primitive::kPrimDouble: { |
| Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3165 | if (second.IsFpuRegister()) { |
| 3166 | __ addsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3167 | } else if (second.IsConstant()) { |
| 3168 | __ addsd(first.AsFpuRegister<XmmRegister>(), |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 3169 | codegen_->LiteralDoubleAddress( |
| 3170 | second.GetConstant()->AsDoubleConstant()->GetValue())); |
| Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3171 | } else { |
| 3172 | DCHECK(second.IsDoubleStackSlot()); |
| 3173 | __ addsd(first.AsFpuRegister<XmmRegister>(), |
| 3174 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 3175 | } |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3176 | break; |
| 3177 | } |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3178 | |
| 3179 | default: |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3180 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3181 | } |
| 3182 | } |
| 3183 | |
| 3184 | void LocationsBuilderX86_64::VisitSub(HSub* sub) { |
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3185 | LocationSummary* locations = |
| 3186 | new (GetGraph()->GetArena()) LocationSummary(sub, LocationSummary::kNoCall); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3187 | switch (sub->GetResultType()) { |
| Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 3188 | case Primitive::kPrimInt: { |
| 3189 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3190 | locations->SetInAt(1, Location::Any()); |
| 3191 | locations->SetOut(Location::SameAsFirstInput()); |
| 3192 | break; |
| 3193 | } |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3194 | case Primitive::kPrimLong: { |
| Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 3195 | locations->SetInAt(0, Location::RequiresRegister()); |
| Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 3196 | locations->SetInAt(1, Location::RegisterOrInt32Constant(sub->InputAt(1))); |
| Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 3197 | locations->SetOut(Location::SameAsFirstInput()); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3198 | break; |
| 3199 | } |
| Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3200 | case Primitive::kPrimFloat: |
| 3201 | case Primitive::kPrimDouble: { |
| 3202 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3203 | locations->SetInAt(1, Location::Any()); |
| Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3204 | locations->SetOut(Location::SameAsFirstInput()); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3205 | break; |
| Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3206 | } |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3207 | default: |
| Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3208 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3209 | } |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3210 | } |
| 3211 | |
| 3212 | void InstructionCodeGeneratorX86_64::VisitSub(HSub* sub) { |
| 3213 | LocationSummary* locations = sub->GetLocations(); |
| Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3214 | Location first = locations->InAt(0); |
| 3215 | Location second = locations->InAt(1); |
| 3216 | DCHECK(first.Equals(locations->Out())); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3217 | switch (sub->GetResultType()) { |
| Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 3218 | case Primitive::kPrimInt: { |
| Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3219 | if (second.IsRegister()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3220 | __ subl(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
| Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3221 | } else if (second.IsConstant()) { |
| 3222 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue()); |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3223 | __ subl(first.AsRegister<CpuRegister>(), imm); |
| Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 3224 | } else { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3225 | __ subl(first.AsRegister<CpuRegister>(), Address(CpuRegister(RSP), second.GetStackIndex())); |
| Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 3226 | } |
| Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 3227 | break; |
| 3228 | } |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3229 | case Primitive::kPrimLong: { |
| Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 3230 | if (second.IsConstant()) { |
| 3231 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 3232 | DCHECK(IsInt<32>(value)); |
| 3233 | __ subq(first.AsRegister<CpuRegister>(), Immediate(static_cast<int32_t>(value))); |
| 3234 | } else { |
| 3235 | __ subq(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
| 3236 | } |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3237 | break; |
| 3238 | } |
| 3239 | |
| Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3240 | case Primitive::kPrimFloat: { |
| Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3241 | if (second.IsFpuRegister()) { |
| 3242 | __ subss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3243 | } else if (second.IsConstant()) { |
| 3244 | __ subss(first.AsFpuRegister<XmmRegister>(), |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 3245 | codegen_->LiteralFloatAddress( |
| 3246 | second.GetConstant()->AsFloatConstant()->GetValue())); |
| Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3247 | } else { |
| 3248 | DCHECK(second.IsStackSlot()); |
| 3249 | __ subss(first.AsFpuRegister<XmmRegister>(), |
| 3250 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 3251 | } |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3252 | break; |
| Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3253 | } |
| 3254 | |
| 3255 | case Primitive::kPrimDouble: { |
| Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3256 | if (second.IsFpuRegister()) { |
| 3257 | __ subsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3258 | } else if (second.IsConstant()) { |
| 3259 | __ subsd(first.AsFpuRegister<XmmRegister>(), |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 3260 | codegen_->LiteralDoubleAddress( |
| 3261 | second.GetConstant()->AsDoubleConstant()->GetValue())); |
| Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3262 | } else { |
| 3263 | DCHECK(second.IsDoubleStackSlot()); |
| 3264 | __ subsd(first.AsFpuRegister<XmmRegister>(), |
| 3265 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 3266 | } |
| Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3267 | break; |
| 3268 | } |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3269 | |
| 3270 | default: |
| Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3271 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3272 | } |
| 3273 | } |
| 3274 | |
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3275 | void LocationsBuilderX86_64::VisitMul(HMul* mul) { |
| 3276 | LocationSummary* locations = |
| 3277 | new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall); |
| 3278 | switch (mul->GetResultType()) { |
| 3279 | case Primitive::kPrimInt: { |
| 3280 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3281 | locations->SetInAt(1, Location::Any()); |
| Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3282 | if (mul->InputAt(1)->IsIntConstant()) { |
| 3283 | // Can use 3 operand multiply. |
| 3284 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3285 | } else { |
| 3286 | locations->SetOut(Location::SameAsFirstInput()); |
| 3287 | } |
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3288 | break; |
| 3289 | } |
| 3290 | case Primitive::kPrimLong: { |
| 3291 | locations->SetInAt(0, Location::RequiresRegister()); |
| Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3292 | locations->SetInAt(1, Location::Any()); |
| 3293 | if (mul->InputAt(1)->IsLongConstant() && |
| 3294 | IsInt<32>(mul->InputAt(1)->AsLongConstant()->GetValue())) { |
| Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 3295 | // Can use 3 operand multiply. |
| 3296 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3297 | } else { |
| 3298 | locations->SetOut(Location::SameAsFirstInput()); |
| 3299 | } |
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3300 | break; |
| 3301 | } |
| Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3302 | case Primitive::kPrimFloat: |
| 3303 | case Primitive::kPrimDouble: { |
| 3304 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3305 | locations->SetInAt(1, Location::Any()); |
| Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3306 | locations->SetOut(Location::SameAsFirstInput()); |
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3307 | break; |
| Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3308 | } |
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3309 | |
| 3310 | default: |
| Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3311 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3312 | } |
| 3313 | } |
| 3314 | |
| 3315 | void InstructionCodeGeneratorX86_64::VisitMul(HMul* mul) { |
| 3316 | LocationSummary* locations = mul->GetLocations(); |
| 3317 | Location first = locations->InAt(0); |
| 3318 | Location second = locations->InAt(1); |
| Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3319 | Location out = locations->Out(); |
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3320 | switch (mul->GetResultType()) { |
| Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3321 | case Primitive::kPrimInt: |
| 3322 | // The constant may have ended up in a register, so test explicitly to avoid |
| 3323 | // problems where the output may not be the same as the first operand. |
| 3324 | if (mul->InputAt(1)->IsIntConstant()) { |
| 3325 | Immediate imm(mul->InputAt(1)->AsIntConstant()->GetValue()); |
| 3326 | __ imull(out.AsRegister<CpuRegister>(), first.AsRegister<CpuRegister>(), imm); |
| 3327 | } else if (second.IsRegister()) { |
| 3328 | DCHECK(first.Equals(out)); |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3329 | __ imull(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3330 | } else { |
| Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3331 | DCHECK(first.Equals(out)); |
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3332 | DCHECK(second.IsStackSlot()); |
| Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 3333 | __ imull(first.AsRegister<CpuRegister>(), |
| 3334 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3335 | } |
| 3336 | break; |
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3337 | case Primitive::kPrimLong: { |
| Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3338 | // The constant may have ended up in a register, so test explicitly to avoid |
| 3339 | // problems where the output may not be the same as the first operand. |
| 3340 | if (mul->InputAt(1)->IsLongConstant()) { |
| 3341 | int64_t value = mul->InputAt(1)->AsLongConstant()->GetValue(); |
| 3342 | if (IsInt<32>(value)) { |
| 3343 | __ imulq(out.AsRegister<CpuRegister>(), first.AsRegister<CpuRegister>(), |
| 3344 | Immediate(static_cast<int32_t>(value))); |
| 3345 | } else { |
| 3346 | // Have to use the constant area. |
| 3347 | DCHECK(first.Equals(out)); |
| 3348 | __ imulq(first.AsRegister<CpuRegister>(), codegen_->LiteralInt64Address(value)); |
| 3349 | } |
| 3350 | } else if (second.IsRegister()) { |
| 3351 | DCHECK(first.Equals(out)); |
| Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 3352 | __ imulq(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
| Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3353 | } else { |
| 3354 | DCHECK(second.IsDoubleStackSlot()); |
| 3355 | DCHECK(first.Equals(out)); |
| 3356 | __ imulq(first.AsRegister<CpuRegister>(), |
| 3357 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 3358 | } |
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3359 | break; |
| 3360 | } |
| 3361 | |
| Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3362 | case Primitive::kPrimFloat: { |
| Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3363 | DCHECK(first.Equals(out)); |
| Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3364 | if (second.IsFpuRegister()) { |
| 3365 | __ mulss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3366 | } else if (second.IsConstant()) { |
| 3367 | __ mulss(first.AsFpuRegister<XmmRegister>(), |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 3368 | codegen_->LiteralFloatAddress( |
| 3369 | second.GetConstant()->AsFloatConstant()->GetValue())); |
| Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3370 | } else { |
| 3371 | DCHECK(second.IsStackSlot()); |
| 3372 | __ mulss(first.AsFpuRegister<XmmRegister>(), |
| 3373 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 3374 | } |
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3375 | break; |
| Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3376 | } |
| 3377 | |
| 3378 | case Primitive::kPrimDouble: { |
| Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3379 | DCHECK(first.Equals(out)); |
| Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3380 | if (second.IsFpuRegister()) { |
| 3381 | __ mulsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3382 | } else if (second.IsConstant()) { |
| 3383 | __ mulsd(first.AsFpuRegister<XmmRegister>(), |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 3384 | codegen_->LiteralDoubleAddress( |
| 3385 | second.GetConstant()->AsDoubleConstant()->GetValue())); |
| Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3386 | } else { |
| 3387 | DCHECK(second.IsDoubleStackSlot()); |
| 3388 | __ mulsd(first.AsFpuRegister<XmmRegister>(), |
| 3389 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 3390 | } |
| Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3391 | break; |
| 3392 | } |
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3393 | |
| 3394 | default: |
| Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3395 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3396 | } |
| 3397 | } |
| 3398 | |
| Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3399 | void InstructionCodeGeneratorX86_64::PushOntoFPStack(Location source, uint32_t temp_offset, |
| 3400 | uint32_t stack_adjustment, bool is_float) { |
| 3401 | if (source.IsStackSlot()) { |
| 3402 | DCHECK(is_float); |
| 3403 | __ flds(Address(CpuRegister(RSP), source.GetStackIndex() + stack_adjustment)); |
| 3404 | } else if (source.IsDoubleStackSlot()) { |
| 3405 | DCHECK(!is_float); |
| 3406 | __ fldl(Address(CpuRegister(RSP), source.GetStackIndex() + stack_adjustment)); |
| 3407 | } else { |
| 3408 | // Write the value to the temporary location on the stack and load to FP stack. |
| 3409 | if (is_float) { |
| 3410 | Location stack_temp = Location::StackSlot(temp_offset); |
| 3411 | codegen_->Move(stack_temp, source); |
| 3412 | __ flds(Address(CpuRegister(RSP), temp_offset)); |
| 3413 | } else { |
| 3414 | Location stack_temp = Location::DoubleStackSlot(temp_offset); |
| 3415 | codegen_->Move(stack_temp, source); |
| 3416 | __ fldl(Address(CpuRegister(RSP), temp_offset)); |
| 3417 | } |
| 3418 | } |
| 3419 | } |
| 3420 | |
| 3421 | void InstructionCodeGeneratorX86_64::GenerateRemFP(HRem *rem) { |
| 3422 | Primitive::Type type = rem->GetResultType(); |
| 3423 | bool is_float = type == Primitive::kPrimFloat; |
| 3424 | size_t elem_size = Primitive::ComponentSize(type); |
| 3425 | LocationSummary* locations = rem->GetLocations(); |
| 3426 | Location first = locations->InAt(0); |
| 3427 | Location second = locations->InAt(1); |
| 3428 | Location out = locations->Out(); |
| 3429 | |
| 3430 | // Create stack space for 2 elements. |
| 3431 | // TODO: enhance register allocator to ask for stack temporaries. |
| 3432 | __ subq(CpuRegister(RSP), Immediate(2 * elem_size)); |
| 3433 | |
| 3434 | // Load the values to the FP stack in reverse order, using temporaries if needed. |
| 3435 | PushOntoFPStack(second, elem_size, 2 * elem_size, is_float); |
| 3436 | PushOntoFPStack(first, 0, 2 * elem_size, is_float); |
| 3437 | |
| 3438 | // Loop doing FPREM until we stabilize. |
| Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 3439 | NearLabel retry; |
| Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3440 | __ Bind(&retry); |
| 3441 | __ fprem(); |
| 3442 | |
| 3443 | // Move FP status to AX. |
| 3444 | __ fstsw(); |
| 3445 | |
| 3446 | // And see if the argument reduction is complete. This is signaled by the |
| 3447 | // C2 FPU flag bit set to 0. |
| 3448 | __ andl(CpuRegister(RAX), Immediate(kC2ConditionMask)); |
| 3449 | __ j(kNotEqual, &retry); |
| 3450 | |
| 3451 | // We have settled on the final value. Retrieve it into an XMM register. |
| 3452 | // Store FP top of stack to real stack. |
| 3453 | if (is_float) { |
| 3454 | __ fsts(Address(CpuRegister(RSP), 0)); |
| 3455 | } else { |
| 3456 | __ fstl(Address(CpuRegister(RSP), 0)); |
| 3457 | } |
| 3458 | |
| 3459 | // Pop the 2 items from the FP stack. |
| 3460 | __ fucompp(); |
| 3461 | |
| 3462 | // Load the value from the stack into an XMM register. |
| 3463 | DCHECK(out.IsFpuRegister()) << out; |
| 3464 | if (is_float) { |
| 3465 | __ movss(out.AsFpuRegister<XmmRegister>(), Address(CpuRegister(RSP), 0)); |
| 3466 | } else { |
| 3467 | __ movsd(out.AsFpuRegister<XmmRegister>(), Address(CpuRegister(RSP), 0)); |
| 3468 | } |
| 3469 | |
| 3470 | // And remove the temporary stack space we allocated. |
| 3471 | __ addq(CpuRegister(RSP), Immediate(2 * elem_size)); |
| 3472 | } |
| 3473 | |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3474 | void InstructionCodeGeneratorX86_64::DivRemOneOrMinusOne(HBinaryOperation* instruction) { |
| 3475 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3476 | |
| 3477 | LocationSummary* locations = instruction->GetLocations(); |
| 3478 | Location second = locations->InAt(1); |
| 3479 | DCHECK(second.IsConstant()); |
| 3480 | |
| 3481 | CpuRegister output_register = locations->Out().AsRegister<CpuRegister>(); |
| 3482 | CpuRegister input_register = locations->InAt(0).AsRegister<CpuRegister>(); |
| Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3483 | int64_t imm = Int64FromConstant(second.GetConstant()); |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3484 | |
| 3485 | DCHECK(imm == 1 || imm == -1); |
| 3486 | |
| 3487 | switch (instruction->GetResultType()) { |
| 3488 | case Primitive::kPrimInt: { |
| 3489 | if (instruction->IsRem()) { |
| 3490 | __ xorl(output_register, output_register); |
| 3491 | } else { |
| 3492 | __ movl(output_register, input_register); |
| 3493 | if (imm == -1) { |
| 3494 | __ negl(output_register); |
| 3495 | } |
| 3496 | } |
| 3497 | break; |
| 3498 | } |
| 3499 | |
| 3500 | case Primitive::kPrimLong: { |
| 3501 | if (instruction->IsRem()) { |
| Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 3502 | __ xorl(output_register, output_register); |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3503 | } else { |
| 3504 | __ movq(output_register, input_register); |
| 3505 | if (imm == -1) { |
| 3506 | __ negq(output_register); |
| 3507 | } |
| 3508 | } |
| 3509 | break; |
| 3510 | } |
| 3511 | |
| 3512 | default: |
| Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3513 | LOG(FATAL) << "Unexpected type for div by (-)1 " << instruction->GetResultType(); |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3514 | } |
| 3515 | } |
| 3516 | |
| Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3517 | void InstructionCodeGeneratorX86_64::DivByPowerOfTwo(HDiv* instruction) { |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3518 | LocationSummary* locations = instruction->GetLocations(); |
| 3519 | Location second = locations->InAt(1); |
| 3520 | |
| 3521 | CpuRegister output_register = locations->Out().AsRegister<CpuRegister>(); |
| 3522 | CpuRegister numerator = locations->InAt(0).AsRegister<CpuRegister>(); |
| 3523 | |
| Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3524 | int64_t imm = Int64FromConstant(second.GetConstant()); |
| Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3525 | DCHECK(IsPowerOfTwo(AbsOrMin(imm))); |
| 3526 | uint64_t abs_imm = AbsOrMin(imm); |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3527 | |
| 3528 | CpuRegister tmp = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 3529 | |
| 3530 | if (instruction->GetResultType() == Primitive::kPrimInt) { |
| Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3531 | __ leal(tmp, Address(numerator, abs_imm - 1)); |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3532 | __ testl(numerator, numerator); |
| 3533 | __ cmov(kGreaterEqual, tmp, numerator); |
| 3534 | int shift = CTZ(imm); |
| 3535 | __ sarl(tmp, Immediate(shift)); |
| 3536 | |
| 3537 | if (imm < 0) { |
| 3538 | __ negl(tmp); |
| 3539 | } |
| 3540 | |
| 3541 | __ movl(output_register, tmp); |
| 3542 | } else { |
| 3543 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong); |
| 3544 | CpuRegister rdx = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 3545 | |
| Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3546 | codegen_->Load64BitValue(rdx, abs_imm - 1); |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3547 | __ addq(rdx, numerator); |
| 3548 | __ testq(numerator, numerator); |
| 3549 | __ cmov(kGreaterEqual, rdx, numerator); |
| 3550 | int shift = CTZ(imm); |
| 3551 | __ sarq(rdx, Immediate(shift)); |
| 3552 | |
| 3553 | if (imm < 0) { |
| 3554 | __ negq(rdx); |
| 3555 | } |
| 3556 | |
| 3557 | __ movq(output_register, rdx); |
| 3558 | } |
| 3559 | } |
| 3560 | |
| 3561 | void InstructionCodeGeneratorX86_64::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) { |
| 3562 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3563 | |
| 3564 | LocationSummary* locations = instruction->GetLocations(); |
| 3565 | Location second = locations->InAt(1); |
| 3566 | |
| 3567 | CpuRegister numerator = instruction->IsDiv() ? locations->GetTemp(1).AsRegister<CpuRegister>() |
| 3568 | : locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 3569 | CpuRegister eax = locations->InAt(0).AsRegister<CpuRegister>(); |
| 3570 | CpuRegister edx = instruction->IsDiv() ? locations->GetTemp(0).AsRegister<CpuRegister>() |
| 3571 | : locations->Out().AsRegister<CpuRegister>(); |
| 3572 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
| 3573 | |
| 3574 | DCHECK_EQ(RAX, eax.AsRegister()); |
| 3575 | DCHECK_EQ(RDX, edx.AsRegister()); |
| 3576 | if (instruction->IsDiv()) { |
| 3577 | DCHECK_EQ(RAX, out.AsRegister()); |
| 3578 | } else { |
| 3579 | DCHECK_EQ(RDX, out.AsRegister()); |
| 3580 | } |
| 3581 | |
| 3582 | int64_t magic; |
| 3583 | int shift; |
| 3584 | |
| Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3585 | // TODO: can these branches be written as one? |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3586 | if (instruction->GetResultType() == Primitive::kPrimInt) { |
| 3587 | int imm = second.GetConstant()->AsIntConstant()->GetValue(); |
| 3588 | |
| 3589 | CalculateMagicAndShiftForDivRem(imm, false /* is_long */, &magic, &shift); |
| 3590 | |
| 3591 | __ movl(numerator, eax); |
| 3592 | |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3593 | __ movl(eax, Immediate(magic)); |
| 3594 | __ imull(numerator); |
| 3595 | |
| 3596 | if (imm > 0 && magic < 0) { |
| 3597 | __ addl(edx, numerator); |
| 3598 | } else if (imm < 0 && magic > 0) { |
| 3599 | __ subl(edx, numerator); |
| 3600 | } |
| 3601 | |
| 3602 | if (shift != 0) { |
| 3603 | __ sarl(edx, Immediate(shift)); |
| 3604 | } |
| 3605 | |
| 3606 | __ movl(eax, edx); |
| 3607 | __ shrl(edx, Immediate(31)); |
| 3608 | __ addl(edx, eax); |
| 3609 | |
| 3610 | if (instruction->IsRem()) { |
| 3611 | __ movl(eax, numerator); |
| 3612 | __ imull(edx, Immediate(imm)); |
| 3613 | __ subl(eax, edx); |
| 3614 | __ movl(edx, eax); |
| 3615 | } else { |
| 3616 | __ movl(eax, edx); |
| 3617 | } |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3618 | } else { |
| 3619 | int64_t imm = second.GetConstant()->AsLongConstant()->GetValue(); |
| 3620 | |
| 3621 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong); |
| 3622 | |
| 3623 | CpuRegister rax = eax; |
| 3624 | CpuRegister rdx = edx; |
| 3625 | |
| 3626 | CalculateMagicAndShiftForDivRem(imm, true /* is_long */, &magic, &shift); |
| 3627 | |
| 3628 | // Save the numerator. |
| 3629 | __ movq(numerator, rax); |
| 3630 | |
| 3631 | // RAX = magic |
| Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 3632 | codegen_->Load64BitValue(rax, magic); |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3633 | |
| 3634 | // RDX:RAX = magic * numerator |
| 3635 | __ imulq(numerator); |
| 3636 | |
| 3637 | if (imm > 0 && magic < 0) { |
| Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3638 | // RDX += numerator |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3639 | __ addq(rdx, numerator); |
| 3640 | } else if (imm < 0 && magic > 0) { |
| 3641 | // RDX -= numerator |
| 3642 | __ subq(rdx, numerator); |
| 3643 | } |
| 3644 | |
| 3645 | // Shift if needed. |
| 3646 | if (shift != 0) { |
| 3647 | __ sarq(rdx, Immediate(shift)); |
| 3648 | } |
| 3649 | |
| 3650 | // RDX += 1 if RDX < 0 |
| 3651 | __ movq(rax, rdx); |
| 3652 | __ shrq(rdx, Immediate(63)); |
| 3653 | __ addq(rdx, rax); |
| 3654 | |
| 3655 | if (instruction->IsRem()) { |
| 3656 | __ movq(rax, numerator); |
| 3657 | |
| 3658 | if (IsInt<32>(imm)) { |
| 3659 | __ imulq(rdx, Immediate(static_cast<int32_t>(imm))); |
| 3660 | } else { |
| Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 3661 | __ imulq(rdx, codegen_->LiteralInt64Address(imm)); |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3662 | } |
| 3663 | |
| 3664 | __ subq(rax, rdx); |
| 3665 | __ movq(rdx, rax); |
| 3666 | } else { |
| 3667 | __ movq(rax, rdx); |
| 3668 | } |
| 3669 | } |
| 3670 | } |
| 3671 | |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3672 | void InstructionCodeGeneratorX86_64::GenerateDivRemIntegral(HBinaryOperation* instruction) { |
| 3673 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3674 | Primitive::Type type = instruction->GetResultType(); |
| Calin Juravle | c70d1d9 | 2017-03-27 18:10:04 -0700 | [diff] [blame] | 3675 | DCHECK(type == Primitive::kPrimInt || type == Primitive::kPrimLong); |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3676 | |
| 3677 | bool is_div = instruction->IsDiv(); |
| 3678 | LocationSummary* locations = instruction->GetLocations(); |
| 3679 | |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3680 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
| 3681 | Location second = locations->InAt(1); |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3682 | |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3683 | DCHECK_EQ(RAX, locations->InAt(0).AsRegister<CpuRegister>().AsRegister()); |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3684 | DCHECK_EQ(is_div ? RAX : RDX, out.AsRegister()); |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3685 | |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3686 | if (second.IsConstant()) { |
| Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3687 | int64_t imm = Int64FromConstant(second.GetConstant()); |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3688 | |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3689 | if (imm == 0) { |
| 3690 | // Do not generate anything. DivZeroCheck would prevent any code to be executed. |
| 3691 | } else if (imm == 1 || imm == -1) { |
| 3692 | DivRemOneOrMinusOne(instruction); |
| Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3693 | } else if (instruction->IsDiv() && IsPowerOfTwo(AbsOrMin(imm))) { |
| Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3694 | DivByPowerOfTwo(instruction->AsDiv()); |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3695 | } else { |
| 3696 | DCHECK(imm <= -2 || imm >= 2); |
| 3697 | GenerateDivRemWithAnyConstant(instruction); |
| 3698 | } |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3699 | } else { |
| Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 3700 | SlowPathCode* slow_path = |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3701 | new (GetGraph()->GetArena()) DivRemMinusOneSlowPathX86_64( |
| David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 3702 | instruction, out.AsRegister(), type, is_div); |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3703 | codegen_->AddSlowPath(slow_path); |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3704 | |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3705 | CpuRegister second_reg = second.AsRegister<CpuRegister>(); |
| 3706 | // 0x80000000(00000000)/-1 triggers an arithmetic exception! |
| 3707 | // Dividing by -1 is actually negation and -0x800000000(00000000) = 0x80000000(00000000) |
| 3708 | // so it's safe to just use negl instead of more complex comparisons. |
| 3709 | if (type == Primitive::kPrimInt) { |
| 3710 | __ cmpl(second_reg, Immediate(-1)); |
| 3711 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3712 | // edx:eax <- sign-extended of eax |
| 3713 | __ cdq(); |
| 3714 | // eax = quotient, edx = remainder |
| 3715 | __ idivl(second_reg); |
| 3716 | } else { |
| 3717 | __ cmpq(second_reg, Immediate(-1)); |
| 3718 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3719 | // rdx:rax <- sign-extended of rax |
| 3720 | __ cqo(); |
| 3721 | // rax = quotient, rdx = remainder |
| 3722 | __ idivq(second_reg); |
| 3723 | } |
| 3724 | __ Bind(slow_path->GetExitLabel()); |
| 3725 | } |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3726 | } |
| 3727 | |
| Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3728 | void LocationsBuilderX86_64::VisitDiv(HDiv* div) { |
| 3729 | LocationSummary* locations = |
| 3730 | new (GetGraph()->GetArena()) LocationSummary(div, LocationSummary::kNoCall); |
| 3731 | switch (div->GetResultType()) { |
| Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3732 | case Primitive::kPrimInt: |
| 3733 | case Primitive::kPrimLong: { |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3734 | locations->SetInAt(0, Location::RegisterLocation(RAX)); |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3735 | locations->SetInAt(1, Location::RegisterOrConstant(div->InputAt(1))); |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3736 | locations->SetOut(Location::SameAsFirstInput()); |
| 3737 | // Intel uses edx:eax as the dividend. |
| 3738 | locations->AddTemp(Location::RegisterLocation(RDX)); |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3739 | // We need to save the numerator while we tweak rax and rdx. As we are using imul in a way |
| 3740 | // which enforces results to be in RAX and RDX, things are simpler if we use RDX also as |
| 3741 | // output and request another temp. |
| 3742 | if (div->InputAt(1)->IsConstant()) { |
| 3743 | locations->AddTemp(Location::RequiresRegister()); |
| 3744 | } |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3745 | break; |
| 3746 | } |
| Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3747 | |
| Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3748 | case Primitive::kPrimFloat: |
| 3749 | case Primitive::kPrimDouble: { |
| 3750 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3751 | locations->SetInAt(1, Location::Any()); |
| Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3752 | locations->SetOut(Location::SameAsFirstInput()); |
| 3753 | break; |
| 3754 | } |
| 3755 | |
| 3756 | default: |
| 3757 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 3758 | } |
| 3759 | } |
| 3760 | |
| 3761 | void InstructionCodeGeneratorX86_64::VisitDiv(HDiv* div) { |
| 3762 | LocationSummary* locations = div->GetLocations(); |
| 3763 | Location first = locations->InAt(0); |
| 3764 | Location second = locations->InAt(1); |
| 3765 | DCHECK(first.Equals(locations->Out())); |
| 3766 | |
| Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3767 | Primitive::Type type = div->GetResultType(); |
| 3768 | switch (type) { |
| 3769 | case Primitive::kPrimInt: |
| 3770 | case Primitive::kPrimLong: { |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3771 | GenerateDivRemIntegral(div); |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3772 | break; |
| 3773 | } |
| 3774 | |
| Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3775 | case Primitive::kPrimFloat: { |
| Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3776 | if (second.IsFpuRegister()) { |
| 3777 | __ divss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3778 | } else if (second.IsConstant()) { |
| 3779 | __ divss(first.AsFpuRegister<XmmRegister>(), |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 3780 | codegen_->LiteralFloatAddress( |
| 3781 | second.GetConstant()->AsFloatConstant()->GetValue())); |
| Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3782 | } else { |
| 3783 | DCHECK(second.IsStackSlot()); |
| 3784 | __ divss(first.AsFpuRegister<XmmRegister>(), |
| 3785 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 3786 | } |
| Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3787 | break; |
| 3788 | } |
| 3789 | |
| 3790 | case Primitive::kPrimDouble: { |
| Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3791 | if (second.IsFpuRegister()) { |
| 3792 | __ divsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3793 | } else if (second.IsConstant()) { |
| 3794 | __ divsd(first.AsFpuRegister<XmmRegister>(), |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 3795 | codegen_->LiteralDoubleAddress( |
| 3796 | second.GetConstant()->AsDoubleConstant()->GetValue())); |
| Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3797 | } else { |
| 3798 | DCHECK(second.IsDoubleStackSlot()); |
| 3799 | __ divsd(first.AsFpuRegister<XmmRegister>(), |
| 3800 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 3801 | } |
| Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3802 | break; |
| 3803 | } |
| 3804 | |
| 3805 | default: |
| 3806 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 3807 | } |
| 3808 | } |
| 3809 | |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3810 | void LocationsBuilderX86_64::VisitRem(HRem* rem) { |
| Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3811 | Primitive::Type type = rem->GetResultType(); |
| Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3812 | LocationSummary* locations = |
| 3813 | new (GetGraph()->GetArena()) LocationSummary(rem, LocationSummary::kNoCall); |
| Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3814 | |
| 3815 | switch (type) { |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3816 | case Primitive::kPrimInt: |
| 3817 | case Primitive::kPrimLong: { |
| 3818 | locations->SetInAt(0, Location::RegisterLocation(RAX)); |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3819 | locations->SetInAt(1, Location::RegisterOrConstant(rem->InputAt(1))); |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3820 | // Intel uses rdx:rax as the dividend and puts the remainder in rdx |
| 3821 | locations->SetOut(Location::RegisterLocation(RDX)); |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3822 | // We need to save the numerator while we tweak eax and edx. As we are using imul in a way |
| 3823 | // which enforces results to be in RAX and RDX, things are simpler if we use EAX also as |
| 3824 | // output and request another temp. |
| 3825 | if (rem->InputAt(1)->IsConstant()) { |
| 3826 | locations->AddTemp(Location::RequiresRegister()); |
| 3827 | } |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3828 | break; |
| 3829 | } |
| 3830 | |
| 3831 | case Primitive::kPrimFloat: |
| 3832 | case Primitive::kPrimDouble: { |
| Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3833 | locations->SetInAt(0, Location::Any()); |
| 3834 | locations->SetInAt(1, Location::Any()); |
| 3835 | locations->SetOut(Location::RequiresFpuRegister()); |
| 3836 | locations->AddTemp(Location::RegisterLocation(RAX)); |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3837 | break; |
| 3838 | } |
| 3839 | |
| 3840 | default: |
| Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3841 | LOG(FATAL) << "Unexpected rem type " << type; |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3842 | } |
| 3843 | } |
| 3844 | |
| 3845 | void InstructionCodeGeneratorX86_64::VisitRem(HRem* rem) { |
| 3846 | Primitive::Type type = rem->GetResultType(); |
| 3847 | switch (type) { |
| 3848 | case Primitive::kPrimInt: |
| 3849 | case Primitive::kPrimLong: { |
| 3850 | GenerateDivRemIntegral(rem); |
| 3851 | break; |
| 3852 | } |
| Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3853 | case Primitive::kPrimFloat: |
| Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3854 | case Primitive::kPrimDouble: { |
| Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3855 | GenerateRemFP(rem); |
| Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3856 | break; |
| 3857 | } |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3858 | default: |
| 3859 | LOG(FATAL) << "Unexpected rem type " << rem->GetResultType(); |
| 3860 | } |
| 3861 | } |
| 3862 | |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3863 | void LocationsBuilderX86_64::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
| Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 3864 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3865 | locations->SetInAt(0, Location::Any()); |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3866 | } |
| 3867 | |
| 3868 | void InstructionCodeGeneratorX86_64::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
| Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 3869 | SlowPathCode* slow_path = |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3870 | new (GetGraph()->GetArena()) DivZeroCheckSlowPathX86_64(instruction); |
| 3871 | codegen_->AddSlowPath(slow_path); |
| 3872 | |
| 3873 | LocationSummary* locations = instruction->GetLocations(); |
| 3874 | Location value = locations->InAt(0); |
| 3875 | |
| Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3876 | switch (instruction->GetType()) { |
| Nicolas Geoffray | e567161 | 2016-03-16 11:03:54 +0000 | [diff] [blame] | 3877 | case Primitive::kPrimBoolean: |
| Serguei Katkov | 8c0676c | 2015-08-03 13:55:33 +0600 | [diff] [blame] | 3878 | case Primitive::kPrimByte: |
| 3879 | case Primitive::kPrimChar: |
| 3880 | case Primitive::kPrimShort: |
| Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3881 | case Primitive::kPrimInt: { |
| 3882 | if (value.IsRegister()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3883 | __ testl(value.AsRegister<CpuRegister>(), value.AsRegister<CpuRegister>()); |
| Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3884 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3885 | } else if (value.IsStackSlot()) { |
| 3886 | __ cmpl(Address(CpuRegister(RSP), value.GetStackIndex()), Immediate(0)); |
| 3887 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3888 | } else { |
| 3889 | DCHECK(value.IsConstant()) << value; |
| 3890 | if (value.GetConstant()->AsIntConstant()->GetValue() == 0) { |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 3891 | __ jmp(slow_path->GetEntryLabel()); |
| Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3892 | } |
| 3893 | } |
| 3894 | break; |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3895 | } |
| Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3896 | case Primitive::kPrimLong: { |
| 3897 | if (value.IsRegister()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3898 | __ testq(value.AsRegister<CpuRegister>(), value.AsRegister<CpuRegister>()); |
| Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3899 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3900 | } else if (value.IsDoubleStackSlot()) { |
| 3901 | __ cmpq(Address(CpuRegister(RSP), value.GetStackIndex()), Immediate(0)); |
| 3902 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3903 | } else { |
| 3904 | DCHECK(value.IsConstant()) << value; |
| 3905 | if (value.GetConstant()->AsLongConstant()->GetValue() == 0) { |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 3906 | __ jmp(slow_path->GetEntryLabel()); |
| Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3907 | } |
| 3908 | } |
| 3909 | break; |
| 3910 | } |
| 3911 | default: |
| 3912 | LOG(FATAL) << "Unexpected type for HDivZeroCheck " << instruction->GetType(); |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3913 | } |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3914 | } |
| 3915 | |
| Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3916 | void LocationsBuilderX86_64::HandleShift(HBinaryOperation* op) { |
| 3917 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 3918 | |
| 3919 | LocationSummary* locations = |
| 3920 | new (GetGraph()->GetArena()) LocationSummary(op, LocationSummary::kNoCall); |
| 3921 | |
| 3922 | switch (op->GetResultType()) { |
| 3923 | case Primitive::kPrimInt: |
| 3924 | case Primitive::kPrimLong: { |
| 3925 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3926 | // The shift count needs to be in CL. |
| 3927 | locations->SetInAt(1, Location::ByteRegisterOrConstant(RCX, op->InputAt(1))); |
| 3928 | locations->SetOut(Location::SameAsFirstInput()); |
| 3929 | break; |
| 3930 | } |
| 3931 | default: |
| 3932 | LOG(FATAL) << "Unexpected operation type " << op->GetResultType(); |
| 3933 | } |
| 3934 | } |
| 3935 | |
| 3936 | void InstructionCodeGeneratorX86_64::HandleShift(HBinaryOperation* op) { |
| 3937 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 3938 | |
| 3939 | LocationSummary* locations = op->GetLocations(); |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3940 | CpuRegister first_reg = locations->InAt(0).AsRegister<CpuRegister>(); |
| Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3941 | Location second = locations->InAt(1); |
| 3942 | |
| 3943 | switch (op->GetResultType()) { |
| 3944 | case Primitive::kPrimInt: { |
| 3945 | if (second.IsRegister()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3946 | CpuRegister second_reg = second.AsRegister<CpuRegister>(); |
| Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3947 | if (op->IsShl()) { |
| 3948 | __ shll(first_reg, second_reg); |
| 3949 | } else if (op->IsShr()) { |
| 3950 | __ sarl(first_reg, second_reg); |
| 3951 | } else { |
| 3952 | __ shrl(first_reg, second_reg); |
| 3953 | } |
| 3954 | } else { |
| Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 3955 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue() & kMaxIntShiftDistance); |
| Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3956 | if (op->IsShl()) { |
| 3957 | __ shll(first_reg, imm); |
| 3958 | } else if (op->IsShr()) { |
| 3959 | __ sarl(first_reg, imm); |
| 3960 | } else { |
| 3961 | __ shrl(first_reg, imm); |
| 3962 | } |
| 3963 | } |
| 3964 | break; |
| 3965 | } |
| 3966 | case Primitive::kPrimLong: { |
| 3967 | if (second.IsRegister()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3968 | CpuRegister second_reg = second.AsRegister<CpuRegister>(); |
| Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3969 | if (op->IsShl()) { |
| 3970 | __ shlq(first_reg, second_reg); |
| 3971 | } else if (op->IsShr()) { |
| 3972 | __ sarq(first_reg, second_reg); |
| 3973 | } else { |
| 3974 | __ shrq(first_reg, second_reg); |
| 3975 | } |
| 3976 | } else { |
| Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 3977 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue() & kMaxLongShiftDistance); |
| Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3978 | if (op->IsShl()) { |
| 3979 | __ shlq(first_reg, imm); |
| 3980 | } else if (op->IsShr()) { |
| 3981 | __ sarq(first_reg, imm); |
| 3982 | } else { |
| 3983 | __ shrq(first_reg, imm); |
| 3984 | } |
| 3985 | } |
| 3986 | break; |
| 3987 | } |
| 3988 | default: |
| 3989 | LOG(FATAL) << "Unexpected operation type " << op->GetResultType(); |
| Vladimir Marko | 351dddf | 2015-12-11 16:34:46 +0000 | [diff] [blame] | 3990 | UNREACHABLE(); |
| Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3991 | } |
| 3992 | } |
| 3993 | |
| Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 3994 | void LocationsBuilderX86_64::VisitRor(HRor* ror) { |
| 3995 | LocationSummary* locations = |
| 3996 | new (GetGraph()->GetArena()) LocationSummary(ror, LocationSummary::kNoCall); |
| 3997 | |
| 3998 | switch (ror->GetResultType()) { |
| 3999 | case Primitive::kPrimInt: |
| 4000 | case Primitive::kPrimLong: { |
| 4001 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4002 | // The shift count needs to be in CL (unless it is a constant). |
| 4003 | locations->SetInAt(1, Location::ByteRegisterOrConstant(RCX, ror->InputAt(1))); |
| 4004 | locations->SetOut(Location::SameAsFirstInput()); |
| 4005 | break; |
| 4006 | } |
| 4007 | default: |
| 4008 | LOG(FATAL) << "Unexpected operation type " << ror->GetResultType(); |
| 4009 | UNREACHABLE(); |
| 4010 | } |
| 4011 | } |
| 4012 | |
| 4013 | void InstructionCodeGeneratorX86_64::VisitRor(HRor* ror) { |
| 4014 | LocationSummary* locations = ror->GetLocations(); |
| 4015 | CpuRegister first_reg = locations->InAt(0).AsRegister<CpuRegister>(); |
| 4016 | Location second = locations->InAt(1); |
| 4017 | |
| 4018 | switch (ror->GetResultType()) { |
| 4019 | case Primitive::kPrimInt: |
| 4020 | if (second.IsRegister()) { |
| 4021 | CpuRegister second_reg = second.AsRegister<CpuRegister>(); |
| 4022 | __ rorl(first_reg, second_reg); |
| 4023 | } else { |
| Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4024 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue() & kMaxIntShiftDistance); |
| Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4025 | __ rorl(first_reg, imm); |
| 4026 | } |
| 4027 | break; |
| 4028 | case Primitive::kPrimLong: |
| 4029 | if (second.IsRegister()) { |
| 4030 | CpuRegister second_reg = second.AsRegister<CpuRegister>(); |
| 4031 | __ rorq(first_reg, second_reg); |
| 4032 | } else { |
| Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4033 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue() & kMaxLongShiftDistance); |
| Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4034 | __ rorq(first_reg, imm); |
| 4035 | } |
| 4036 | break; |
| 4037 | default: |
| 4038 | LOG(FATAL) << "Unexpected operation type " << ror->GetResultType(); |
| 4039 | UNREACHABLE(); |
| 4040 | } |
| 4041 | } |
| 4042 | |
| Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4043 | void LocationsBuilderX86_64::VisitShl(HShl* shl) { |
| 4044 | HandleShift(shl); |
| 4045 | } |
| 4046 | |
| 4047 | void InstructionCodeGeneratorX86_64::VisitShl(HShl* shl) { |
| 4048 | HandleShift(shl); |
| 4049 | } |
| 4050 | |
| 4051 | void LocationsBuilderX86_64::VisitShr(HShr* shr) { |
| 4052 | HandleShift(shr); |
| 4053 | } |
| 4054 | |
| 4055 | void InstructionCodeGeneratorX86_64::VisitShr(HShr* shr) { |
| 4056 | HandleShift(shr); |
| 4057 | } |
| 4058 | |
| 4059 | void LocationsBuilderX86_64::VisitUShr(HUShr* ushr) { |
| 4060 | HandleShift(ushr); |
| 4061 | } |
| 4062 | |
| 4063 | void InstructionCodeGeneratorX86_64::VisitUShr(HUShr* ushr) { |
| 4064 | HandleShift(ushr); |
| 4065 | } |
| 4066 | |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4067 | void LocationsBuilderX86_64::VisitNewInstance(HNewInstance* instruction) { |
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4068 | LocationSummary* locations = |
| Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 4069 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
| Nicolas Geoffray | 9ae0daa | 2014-09-30 22:40:23 +0100 | [diff] [blame] | 4070 | InvokeRuntimeCallingConvention calling_convention; |
| David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4071 | if (instruction->IsStringAlloc()) { |
| 4072 | locations->AddTemp(Location::RegisterLocation(kMethodRegisterArgument)); |
| 4073 | } else { |
| 4074 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4075 | } |
| Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4076 | locations->SetOut(Location::RegisterLocation(RAX)); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4077 | } |
| 4078 | |
| 4079 | void InstructionCodeGeneratorX86_64::VisitNewInstance(HNewInstance* instruction) { |
| Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4080 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 4081 | // of poisoning the reference. |
| David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4082 | if (instruction->IsStringAlloc()) { |
| 4083 | // String is allocated through StringFactory. Call NewEmptyString entry point. |
| 4084 | CpuRegister temp = instruction->GetLocations()->GetTemp(0).AsRegister<CpuRegister>(); |
| Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 4085 | MemberOffset code_offset = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kX86_64PointerSize); |
| David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4086 | __ gs()->movq(temp, Address::Absolute(QUICK_ENTRY_POINT(pNewEmptyString), /* no_rip */ true)); |
| 4087 | __ call(Address(temp, code_offset.SizeValue())); |
| 4088 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
| 4089 | } else { |
| Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 4090 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), instruction, instruction->GetDexPc()); |
| Nicolas Geoffray | 0d3998b | 2017-01-12 15:35:12 +0000 | [diff] [blame] | 4091 | CheckEntrypointTypes<kQuickAllocObjectWithChecks, void*, mirror::Class*>(); |
| David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4092 | DCHECK(!codegen_->IsLeafMethod()); |
| 4093 | } |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4094 | } |
| 4095 | |
| Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4096 | void LocationsBuilderX86_64::VisitNewArray(HNewArray* instruction) { |
| 4097 | LocationSummary* locations = |
| Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 4098 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
| Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4099 | InvokeRuntimeCallingConvention calling_convention; |
| Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4100 | locations->SetOut(Location::RegisterLocation(RAX)); |
| Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 4101 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 4102 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4103 | } |
| 4104 | |
| 4105 | void InstructionCodeGeneratorX86_64::VisitNewArray(HNewArray* instruction) { |
| Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4106 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 4107 | // of poisoning the reference. |
| Nicolas Geoffray | b048cb7 | 2017-01-23 22:50:24 +0000 | [diff] [blame] | 4108 | QuickEntrypointEnum entrypoint = |
| 4109 | CodeGenerator::GetArrayAllocationEntrypoint(instruction->GetLoadClass()->GetClass()); |
| 4110 | codegen_->InvokeRuntime(entrypoint, instruction, instruction->GetDexPc()); |
| Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 4111 | CheckEntrypointTypes<kQuickAllocArrayResolved, void*, mirror::Class*, int32_t>(); |
| Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4112 | DCHECK(!codegen_->IsLeafMethod()); |
| Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4113 | } |
| 4114 | |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4115 | void LocationsBuilderX86_64::VisitParameterValue(HParameterValue* instruction) { |
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4116 | LocationSummary* locations = |
| 4117 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4118 | Location location = parameter_visitor_.GetNextLocation(instruction->GetType()); |
| 4119 | if (location.IsStackSlot()) { |
| 4120 | location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 4121 | } else if (location.IsDoubleStackSlot()) { |
| 4122 | location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 4123 | } |
| 4124 | locations->SetOut(location); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4125 | } |
| 4126 | |
| Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4127 | void InstructionCodeGeneratorX86_64::VisitParameterValue( |
| 4128 | HParameterValue* instruction ATTRIBUTE_UNUSED) { |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4129 | // Nothing to do, the parameter is already at its location. |
| Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4130 | } |
| 4131 | |
| 4132 | void LocationsBuilderX86_64::VisitCurrentMethod(HCurrentMethod* instruction) { |
| 4133 | LocationSummary* locations = |
| 4134 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 4135 | locations->SetOut(Location::RegisterLocation(kMethodRegisterArgument)); |
| 4136 | } |
| 4137 | |
| 4138 | void InstructionCodeGeneratorX86_64::VisitCurrentMethod( |
| 4139 | HCurrentMethod* instruction ATTRIBUTE_UNUSED) { |
| 4140 | // Nothing to do, the method is already at its location. |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4141 | } |
| 4142 | |
| Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4143 | void LocationsBuilderX86_64::VisitClassTableGet(HClassTableGet* instruction) { |
| 4144 | LocationSummary* locations = |
| 4145 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 4146 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4147 | locations->SetOut(Location::RequiresRegister()); |
| 4148 | } |
| 4149 | |
| 4150 | void InstructionCodeGeneratorX86_64::VisitClassTableGet(HClassTableGet* instruction) { |
| 4151 | LocationSummary* locations = instruction->GetLocations(); |
| Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4152 | if (instruction->GetTableKind() == HClassTableGet::TableKind::kVTable) { |
| Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 4153 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4154 | instruction->GetIndex(), kX86_64PointerSize).SizeValue(); |
| Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 4155 | __ movq(locations->Out().AsRegister<CpuRegister>(), |
| 4156 | Address(locations->InAt(0).AsRegister<CpuRegister>(), method_offset)); |
| Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4157 | } else { |
| Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 4158 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
| Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 4159 | instruction->GetIndex(), kX86_64PointerSize)); |
| Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 4160 | __ movq(locations->Out().AsRegister<CpuRegister>(), |
| 4161 | Address(locations->InAt(0).AsRegister<CpuRegister>(), |
| 4162 | mirror::Class::ImtPtrOffset(kX86_64PointerSize).Uint32Value())); |
| Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 4163 | __ movq(locations->Out().AsRegister<CpuRegister>(), |
| 4164 | Address(locations->Out().AsRegister<CpuRegister>(), method_offset)); |
| Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4165 | } |
| Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4166 | } |
| 4167 | |
| Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4168 | void LocationsBuilderX86_64::VisitNot(HNot* not_) { |
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4169 | LocationSummary* locations = |
| Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4170 | new (GetGraph()->GetArena()) LocationSummary(not_, LocationSummary::kNoCall); |
| Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 4171 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4172 | locations->SetOut(Location::SameAsFirstInput()); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4173 | } |
| 4174 | |
| Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4175 | void InstructionCodeGeneratorX86_64::VisitNot(HNot* not_) { |
| 4176 | LocationSummary* locations = not_->GetLocations(); |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4177 | DCHECK_EQ(locations->InAt(0).AsRegister<CpuRegister>().AsRegister(), |
| 4178 | locations->Out().AsRegister<CpuRegister>().AsRegister()); |
| Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4179 | Location out = locations->Out(); |
| Nicolas Geoffray | d8ef2e9 | 2015-02-24 16:02:06 +0000 | [diff] [blame] | 4180 | switch (not_->GetResultType()) { |
| Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4181 | case Primitive::kPrimInt: |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4182 | __ notl(out.AsRegister<CpuRegister>()); |
| Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4183 | break; |
| 4184 | |
| 4185 | case Primitive::kPrimLong: |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4186 | __ notq(out.AsRegister<CpuRegister>()); |
| Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4187 | break; |
| 4188 | |
| 4189 | default: |
| 4190 | LOG(FATAL) << "Unimplemented type for not operation " << not_->GetResultType(); |
| 4191 | } |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4192 | } |
| 4193 | |
| David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4194 | void LocationsBuilderX86_64::VisitBooleanNot(HBooleanNot* bool_not) { |
| 4195 | LocationSummary* locations = |
| 4196 | new (GetGraph()->GetArena()) LocationSummary(bool_not, LocationSummary::kNoCall); |
| 4197 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4198 | locations->SetOut(Location::SameAsFirstInput()); |
| 4199 | } |
| 4200 | |
| 4201 | void InstructionCodeGeneratorX86_64::VisitBooleanNot(HBooleanNot* bool_not) { |
| David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4202 | LocationSummary* locations = bool_not->GetLocations(); |
| 4203 | DCHECK_EQ(locations->InAt(0).AsRegister<CpuRegister>().AsRegister(), |
| 4204 | locations->Out().AsRegister<CpuRegister>().AsRegister()); |
| 4205 | Location out = locations->Out(); |
| 4206 | __ xorl(out.AsRegister<CpuRegister>(), Immediate(1)); |
| 4207 | } |
| 4208 | |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4209 | void LocationsBuilderX86_64::VisitPhi(HPhi* instruction) { |
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4210 | LocationSummary* locations = |
| 4211 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 4212 | for (size_t i = 0, e = locations->GetInputCount(); i < e; ++i) { |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4213 | locations->SetInAt(i, Location::Any()); |
| 4214 | } |
| 4215 | locations->SetOut(Location::Any()); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4216 | } |
| 4217 | |
| Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4218 | void InstructionCodeGeneratorX86_64::VisitPhi(HPhi* instruction ATTRIBUTE_UNUSED) { |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4219 | LOG(FATAL) << "Unimplemented"; |
| 4220 | } |
| 4221 | |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4222 | void CodeGeneratorX86_64::GenerateMemoryBarrier(MemBarrierKind kind) { |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4223 | /* |
| Roland Levillain | 5e8d5f0 | 2016-10-18 18:03:43 +0100 | [diff] [blame] | 4224 | * 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] | 4225 | * 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] | 4226 | * For those cases, all we need to ensure is that there is a scheduling barrier in place. |
| 4227 | */ |
| 4228 | switch (kind) { |
| 4229 | case MemBarrierKind::kAnyAny: { |
| Mark P Mendell | 17077d8 | 2015-12-16 19:15:59 +0000 | [diff] [blame] | 4230 | MemoryFence(); |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4231 | break; |
| 4232 | } |
| 4233 | case MemBarrierKind::kAnyStore: |
| 4234 | case MemBarrierKind::kLoadAny: |
| 4235 | case MemBarrierKind::kStoreStore: { |
| 4236 | // nop |
| 4237 | break; |
| 4238 | } |
| Mark Mendell | 7aa04a1 | 2016-01-27 22:39:07 -0500 | [diff] [blame] | 4239 | case MemBarrierKind::kNTStoreStore: |
| 4240 | // Non-Temporal Store/Store needs an explicit fence. |
| 4241 | MemoryFence(/* non-temporal */ true); |
| 4242 | break; |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4243 | } |
| 4244 | } |
| 4245 | |
| 4246 | void LocationsBuilderX86_64::HandleFieldGet(HInstruction* instruction) { |
| 4247 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
| 4248 | |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4249 | bool object_field_get_with_read_barrier = |
| 4250 | kEmitCompilerReadBarrier && (instruction->GetType() == Primitive::kPrimNot); |
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4251 | LocationSummary* locations = |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4252 | new (GetGraph()->GetArena()) LocationSummary(instruction, |
| 4253 | object_field_get_with_read_barrier ? |
| 4254 | LocationSummary::kCallOnSlowPath : |
| 4255 | LocationSummary::kNoCall); |
| Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 4256 | if (object_field_get_with_read_barrier && kUseBakerReadBarrier) { |
| Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 4257 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
| Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 4258 | } |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4259 | locations->SetInAt(0, Location::RequiresRegister()); |
| Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4260 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 4261 | locations->SetOut(Location::RequiresFpuRegister()); |
| 4262 | } else { |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4263 | // The output overlaps for an object field get when read barriers |
| 4264 | // are enabled: we do not want the move to overwrite the object's |
| 4265 | // location, as we need it to emit the read barrier. |
| 4266 | locations->SetOut( |
| 4267 | Location::RequiresRegister(), |
| 4268 | object_field_get_with_read_barrier ? Location::kOutputOverlap : Location::kNoOutputOverlap); |
| Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4269 | } |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4270 | } |
| 4271 | |
| 4272 | void InstructionCodeGeneratorX86_64::HandleFieldGet(HInstruction* instruction, |
| 4273 | const FieldInfo& field_info) { |
| 4274 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
| 4275 | |
| 4276 | LocationSummary* locations = instruction->GetLocations(); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4277 | Location base_loc = locations->InAt(0); |
| 4278 | CpuRegister base = base_loc.AsRegister<CpuRegister>(); |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4279 | Location out = locations->Out(); |
| 4280 | bool is_volatile = field_info.IsVolatile(); |
| 4281 | Primitive::Type field_type = field_info.GetFieldType(); |
| 4282 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
| 4283 | |
| 4284 | switch (field_type) { |
| 4285 | case Primitive::kPrimBoolean: { |
| 4286 | __ movzxb(out.AsRegister<CpuRegister>(), Address(base, offset)); |
| 4287 | break; |
| 4288 | } |
| 4289 | |
| 4290 | case Primitive::kPrimByte: { |
| 4291 | __ movsxb(out.AsRegister<CpuRegister>(), Address(base, offset)); |
| 4292 | break; |
| 4293 | } |
| 4294 | |
| 4295 | case Primitive::kPrimShort: { |
| 4296 | __ movsxw(out.AsRegister<CpuRegister>(), Address(base, offset)); |
| 4297 | break; |
| 4298 | } |
| 4299 | |
| 4300 | case Primitive::kPrimChar: { |
| 4301 | __ movzxw(out.AsRegister<CpuRegister>(), Address(base, offset)); |
| 4302 | break; |
| 4303 | } |
| 4304 | |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4305 | case Primitive::kPrimInt: { |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4306 | __ movl(out.AsRegister<CpuRegister>(), Address(base, offset)); |
| 4307 | break; |
| 4308 | } |
| 4309 | |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4310 | case Primitive::kPrimNot: { |
| 4311 | // /* HeapReference<Object> */ out = *(base + offset) |
| 4312 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4313 | // Note that a potential implicit null check is handled in this |
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 4314 | // CodeGeneratorX86_64::GenerateFieldLoadWithBakerReadBarrier call. |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4315 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
| Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 4316 | instruction, out, base, offset, /* needs_null_check */ true); |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4317 | if (is_volatile) { |
| 4318 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4319 | } |
| 4320 | } else { |
| 4321 | __ movl(out.AsRegister<CpuRegister>(), Address(base, offset)); |
| 4322 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4323 | if (is_volatile) { |
| 4324 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4325 | } |
| 4326 | // If read barriers are enabled, emit read barriers other than |
| 4327 | // Baker's using a slow path (and also unpoison the loaded |
| 4328 | // reference, if heap poisoning is enabled). |
| 4329 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out, out, base_loc, offset); |
| 4330 | } |
| 4331 | break; |
| 4332 | } |
| 4333 | |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4334 | case Primitive::kPrimLong: { |
| 4335 | __ movq(out.AsRegister<CpuRegister>(), Address(base, offset)); |
| 4336 | break; |
| 4337 | } |
| 4338 | |
| 4339 | case Primitive::kPrimFloat: { |
| 4340 | __ movss(out.AsFpuRegister<XmmRegister>(), Address(base, offset)); |
| 4341 | break; |
| 4342 | } |
| 4343 | |
| 4344 | case Primitive::kPrimDouble: { |
| 4345 | __ movsd(out.AsFpuRegister<XmmRegister>(), Address(base, offset)); |
| 4346 | break; |
| 4347 | } |
| 4348 | |
| 4349 | case Primitive::kPrimVoid: |
| 4350 | LOG(FATAL) << "Unreachable type " << field_type; |
| 4351 | UNREACHABLE(); |
| 4352 | } |
| 4353 | |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4354 | if (field_type == Primitive::kPrimNot) { |
| 4355 | // Potential implicit null checks, in the case of reference |
| 4356 | // fields, are handled in the previous switch statement. |
| 4357 | } else { |
| 4358 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4359 | } |
| Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4360 | |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4361 | if (is_volatile) { |
| 4362 | if (field_type == Primitive::kPrimNot) { |
| 4363 | // Memory barriers, in the case of references, are also handled |
| 4364 | // in the previous switch statement. |
| 4365 | } else { |
| 4366 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4367 | } |
| Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4368 | } |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4369 | } |
| 4370 | |
| 4371 | void LocationsBuilderX86_64::HandleFieldSet(HInstruction* instruction, |
| 4372 | const FieldInfo& field_info) { |
| 4373 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 4374 | |
| 4375 | LocationSummary* locations = |
| 4376 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4377 | Primitive::Type field_type = field_info.GetFieldType(); |
| Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4378 | bool is_volatile = field_info.IsVolatile(); |
| Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4379 | bool needs_write_barrier = |
| Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4380 | CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1)); |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4381 | |
| Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 4382 | locations->SetInAt(0, Location::RequiresRegister()); |
| Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4383 | if (Primitive::IsFloatingPointType(instruction->InputAt(1)->GetType())) { |
| Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4384 | if (is_volatile) { |
| 4385 | // In order to satisfy the semantics of volatile, this must be a single instruction store. |
| 4386 | locations->SetInAt(1, Location::FpuRegisterOrInt32Constant(instruction->InputAt(1))); |
| 4387 | } else { |
| 4388 | locations->SetInAt(1, Location::FpuRegisterOrConstant(instruction->InputAt(1))); |
| 4389 | } |
| Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4390 | } else { |
| Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4391 | if (is_volatile) { |
| 4392 | // In order to satisfy the semantics of volatile, this must be a single instruction store. |
| 4393 | locations->SetInAt(1, Location::RegisterOrInt32Constant(instruction->InputAt(1))); |
| 4394 | } else { |
| 4395 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 4396 | } |
| Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4397 | } |
| Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4398 | if (needs_write_barrier) { |
| Nicolas Geoffray | 9ae0daa | 2014-09-30 22:40:23 +0100 | [diff] [blame] | 4399 | // Temporary registers for the write barrier. |
| Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4400 | locations->AddTemp(Location::RequiresRegister()); // Possibly used for reference poisoning too. |
| Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 4401 | locations->AddTemp(Location::RequiresRegister()); |
| Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4402 | } else if (kPoisonHeapReferences && field_type == Primitive::kPrimNot) { |
| 4403 | // Temporary register for the reference poisoning. |
| Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 4404 | locations->AddTemp(Location::RequiresRegister()); |
| 4405 | } |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4406 | } |
| 4407 | |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4408 | void InstructionCodeGeneratorX86_64::HandleFieldSet(HInstruction* instruction, |
| Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4409 | const FieldInfo& field_info, |
| 4410 | bool value_can_be_null) { |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4411 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 4412 | |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4413 | LocationSummary* locations = instruction->GetLocations(); |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4414 | CpuRegister base = locations->InAt(0).AsRegister<CpuRegister>(); |
| 4415 | Location value = locations->InAt(1); |
| 4416 | bool is_volatile = field_info.IsVolatile(); |
| 4417 | Primitive::Type field_type = field_info.GetFieldType(); |
| 4418 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
| 4419 | |
| 4420 | if (is_volatile) { |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4421 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyStore); |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4422 | } |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4423 | |
| Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4424 | bool maybe_record_implicit_null_check_done = false; |
| 4425 | |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4426 | switch (field_type) { |
| 4427 | case Primitive::kPrimBoolean: |
| 4428 | case Primitive::kPrimByte: { |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4429 | if (value.IsConstant()) { |
| Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4430 | int8_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4431 | __ movb(Address(base, offset), Immediate(v)); |
| 4432 | } else { |
| 4433 | __ movb(Address(base, offset), value.AsRegister<CpuRegister>()); |
| 4434 | } |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4435 | break; |
| 4436 | } |
| 4437 | |
| 4438 | case Primitive::kPrimShort: |
| 4439 | case Primitive::kPrimChar: { |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4440 | if (value.IsConstant()) { |
| Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4441 | int16_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4442 | __ movw(Address(base, offset), Immediate(v)); |
| 4443 | } else { |
| 4444 | __ movw(Address(base, offset), value.AsRegister<CpuRegister>()); |
| 4445 | } |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4446 | break; |
| 4447 | } |
| 4448 | |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4449 | case Primitive::kPrimInt: |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4450 | case Primitive::kPrimNot: { |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4451 | if (value.IsConstant()) { |
| 4452 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
| Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4453 | // `field_type == Primitive::kPrimNot` implies `v == 0`. |
| 4454 | DCHECK((field_type != Primitive::kPrimNot) || (v == 0)); |
| 4455 | // Note: if heap poisoning is enabled, no need to poison |
| 4456 | // (negate) `v` if it is a reference, as it would be null. |
| Roland Levillain | 06b66d0 | 2015-07-01 12:47:25 +0100 | [diff] [blame] | 4457 | __ movl(Address(base, offset), Immediate(v)); |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4458 | } else { |
| Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4459 | if (kPoisonHeapReferences && field_type == Primitive::kPrimNot) { |
| 4460 | CpuRegister temp = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 4461 | __ movl(temp, value.AsRegister<CpuRegister>()); |
| 4462 | __ PoisonHeapReference(temp); |
| 4463 | __ movl(Address(base, offset), temp); |
| 4464 | } else { |
| 4465 | __ movl(Address(base, offset), value.AsRegister<CpuRegister>()); |
| 4466 | } |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4467 | } |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4468 | break; |
| 4469 | } |
| 4470 | |
| 4471 | case Primitive::kPrimLong: { |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4472 | if (value.IsConstant()) { |
| 4473 | int64_t v = value.GetConstant()->AsLongConstant()->GetValue(); |
| Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4474 | codegen_->MoveInt64ToAddress(Address(base, offset), |
| 4475 | Address(base, offset + sizeof(int32_t)), |
| 4476 | v, |
| 4477 | instruction); |
| 4478 | maybe_record_implicit_null_check_done = true; |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4479 | } else { |
| 4480 | __ movq(Address(base, offset), value.AsRegister<CpuRegister>()); |
| 4481 | } |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4482 | break; |
| 4483 | } |
| 4484 | |
| Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4485 | case Primitive::kPrimFloat: { |
| Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4486 | if (value.IsConstant()) { |
| 4487 | int32_t v = |
| 4488 | bit_cast<int32_t, float>(value.GetConstant()->AsFloatConstant()->GetValue()); |
| 4489 | __ movl(Address(base, offset), Immediate(v)); |
| 4490 | } else { |
| 4491 | __ movss(Address(base, offset), value.AsFpuRegister<XmmRegister>()); |
| 4492 | } |
| Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4493 | break; |
| 4494 | } |
| 4495 | |
| 4496 | case Primitive::kPrimDouble: { |
| Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4497 | if (value.IsConstant()) { |
| 4498 | int64_t v = |
| 4499 | bit_cast<int64_t, double>(value.GetConstant()->AsDoubleConstant()->GetValue()); |
| 4500 | codegen_->MoveInt64ToAddress(Address(base, offset), |
| 4501 | Address(base, offset + sizeof(int32_t)), |
| 4502 | v, |
| 4503 | instruction); |
| 4504 | maybe_record_implicit_null_check_done = true; |
| 4505 | } else { |
| 4506 | __ movsd(Address(base, offset), value.AsFpuRegister<XmmRegister>()); |
| 4507 | } |
| Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4508 | break; |
| 4509 | } |
| 4510 | |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4511 | case Primitive::kPrimVoid: |
| 4512 | LOG(FATAL) << "Unreachable type " << field_type; |
| Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 4513 | UNREACHABLE(); |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4514 | } |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4515 | |
| Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4516 | if (!maybe_record_implicit_null_check_done) { |
| 4517 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4518 | } |
| Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4519 | |
| 4520 | if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) { |
| 4521 | CpuRegister temp = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 4522 | CpuRegister card = locations->GetTemp(1).AsRegister<CpuRegister>(); |
| Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4523 | codegen_->MarkGCCard(temp, card, base, value.AsRegister<CpuRegister>(), value_can_be_null); |
| Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4524 | } |
| 4525 | |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4526 | if (is_volatile) { |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4527 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyAny); |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4528 | } |
| 4529 | } |
| 4530 | |
| 4531 | void LocationsBuilderX86_64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
| 4532 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 4533 | } |
| 4534 | |
| 4535 | void InstructionCodeGeneratorX86_64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
| Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4536 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4537 | } |
| 4538 | |
| 4539 | void LocationsBuilderX86_64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4540 | HandleFieldGet(instruction); |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4541 | } |
| 4542 | |
| 4543 | void InstructionCodeGeneratorX86_64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4544 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 4545 | } |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4546 | |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4547 | void LocationsBuilderX86_64::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 4548 | HandleFieldGet(instruction); |
| 4549 | } |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4550 | |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4551 | void InstructionCodeGeneratorX86_64::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 4552 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 4553 | } |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4554 | |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4555 | void LocationsBuilderX86_64::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
| 4556 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 4557 | } |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4558 | |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4559 | void InstructionCodeGeneratorX86_64::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
| Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4560 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4561 | } |
| 4562 | |
| Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 4563 | void LocationsBuilderX86_64::VisitUnresolvedInstanceFieldGet( |
| 4564 | HUnresolvedInstanceFieldGet* instruction) { |
| 4565 | FieldAccessCallingConventionX86_64 calling_convention; |
| 4566 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4567 | instruction, instruction->GetFieldType(), calling_convention); |
| 4568 | } |
| 4569 | |
| 4570 | void InstructionCodeGeneratorX86_64::VisitUnresolvedInstanceFieldGet( |
| 4571 | HUnresolvedInstanceFieldGet* instruction) { |
| 4572 | FieldAccessCallingConventionX86_64 calling_convention; |
| 4573 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4574 | instruction->GetFieldType(), |
| 4575 | instruction->GetFieldIndex(), |
| 4576 | instruction->GetDexPc(), |
| 4577 | calling_convention); |
| 4578 | } |
| 4579 | |
| 4580 | void LocationsBuilderX86_64::VisitUnresolvedInstanceFieldSet( |
| 4581 | HUnresolvedInstanceFieldSet* instruction) { |
| 4582 | FieldAccessCallingConventionX86_64 calling_convention; |
| 4583 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4584 | instruction, instruction->GetFieldType(), calling_convention); |
| 4585 | } |
| 4586 | |
| 4587 | void InstructionCodeGeneratorX86_64::VisitUnresolvedInstanceFieldSet( |
| 4588 | HUnresolvedInstanceFieldSet* instruction) { |
| 4589 | FieldAccessCallingConventionX86_64 calling_convention; |
| 4590 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4591 | instruction->GetFieldType(), |
| 4592 | instruction->GetFieldIndex(), |
| 4593 | instruction->GetDexPc(), |
| 4594 | calling_convention); |
| 4595 | } |
| 4596 | |
| 4597 | void LocationsBuilderX86_64::VisitUnresolvedStaticFieldGet( |
| 4598 | HUnresolvedStaticFieldGet* instruction) { |
| 4599 | FieldAccessCallingConventionX86_64 calling_convention; |
| 4600 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4601 | instruction, instruction->GetFieldType(), calling_convention); |
| 4602 | } |
| 4603 | |
| 4604 | void InstructionCodeGeneratorX86_64::VisitUnresolvedStaticFieldGet( |
| 4605 | HUnresolvedStaticFieldGet* instruction) { |
| 4606 | FieldAccessCallingConventionX86_64 calling_convention; |
| 4607 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4608 | instruction->GetFieldType(), |
| 4609 | instruction->GetFieldIndex(), |
| 4610 | instruction->GetDexPc(), |
| 4611 | calling_convention); |
| 4612 | } |
| 4613 | |
| 4614 | void LocationsBuilderX86_64::VisitUnresolvedStaticFieldSet( |
| 4615 | HUnresolvedStaticFieldSet* instruction) { |
| 4616 | FieldAccessCallingConventionX86_64 calling_convention; |
| 4617 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4618 | instruction, instruction->GetFieldType(), calling_convention); |
| 4619 | } |
| 4620 | |
| 4621 | void InstructionCodeGeneratorX86_64::VisitUnresolvedStaticFieldSet( |
| 4622 | HUnresolvedStaticFieldSet* instruction) { |
| 4623 | FieldAccessCallingConventionX86_64 calling_convention; |
| 4624 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4625 | instruction->GetFieldType(), |
| 4626 | instruction->GetFieldIndex(), |
| 4627 | instruction->GetDexPc(), |
| 4628 | calling_convention); |
| 4629 | } |
| 4630 | |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4631 | void LocationsBuilderX86_64::VisitNullCheck(HNullCheck* instruction) { |
| Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 4632 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
| 4633 | Location loc = codegen_->GetCompilerOptions().GetImplicitNullChecks() |
| 4634 | ? Location::RequiresRegister() |
| 4635 | : Location::Any(); |
| 4636 | locations->SetInAt(0, loc); |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4637 | } |
| 4638 | |
| Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 4639 | void CodeGeneratorX86_64::GenerateImplicitNullCheck(HNullCheck* instruction) { |
| 4640 | if (CanMoveNullCheckToUser(instruction)) { |
| Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4641 | return; |
| 4642 | } |
| Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4643 | LocationSummary* locations = instruction->GetLocations(); |
| 4644 | Location obj = locations->InAt(0); |
| 4645 | |
| 4646 | __ testl(CpuRegister(RAX), Address(obj.AsRegister<CpuRegister>(), 0)); |
| Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 4647 | RecordPcInfo(instruction, instruction->GetDexPc()); |
| Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4648 | } |
| 4649 | |
| Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 4650 | void CodeGeneratorX86_64::GenerateExplicitNullCheck(HNullCheck* instruction) { |
| Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 4651 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathX86_64(instruction); |
| Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 4652 | AddSlowPath(slow_path); |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4653 | |
| 4654 | LocationSummary* locations = instruction->GetLocations(); |
| 4655 | Location obj = locations->InAt(0); |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4656 | |
| 4657 | if (obj.IsRegister()) { |
| Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 4658 | __ testl(obj.AsRegister<CpuRegister>(), obj.AsRegister<CpuRegister>()); |
| Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4659 | } else if (obj.IsStackSlot()) { |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4660 | __ cmpl(Address(CpuRegister(RSP), obj.GetStackIndex()), Immediate(0)); |
| Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4661 | } else { |
| 4662 | DCHECK(obj.IsConstant()) << obj; |
| David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 4663 | DCHECK(obj.GetConstant()->IsNullConstant()); |
| Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4664 | __ jmp(slow_path->GetEntryLabel()); |
| 4665 | return; |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4666 | } |
| 4667 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 4668 | } |
| 4669 | |
| Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4670 | void InstructionCodeGeneratorX86_64::VisitNullCheck(HNullCheck* instruction) { |
| Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 4671 | codegen_->GenerateNullCheck(instruction); |
| Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4672 | } |
| 4673 | |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4674 | void LocationsBuilderX86_64::VisitArrayGet(HArrayGet* instruction) { |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4675 | bool object_array_get_with_read_barrier = |
| 4676 | kEmitCompilerReadBarrier && (instruction->GetType() == Primitive::kPrimNot); |
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4677 | LocationSummary* locations = |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4678 | new (GetGraph()->GetArena()) LocationSummary(instruction, |
| 4679 | object_array_get_with_read_barrier ? |
| 4680 | LocationSummary::kCallOnSlowPath : |
| 4681 | LocationSummary::kNoCall); |
| Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 4682 | if (object_array_get_with_read_barrier && kUseBakerReadBarrier) { |
| Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 4683 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
| Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 4684 | } |
| Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 4685 | locations->SetInAt(0, Location::RequiresRegister()); |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4686 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4687 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 4688 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 4689 | } else { |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4690 | // The output overlaps for an object array get when read barriers |
| 4691 | // are enabled: we do not want the move to overwrite the array's |
| 4692 | // location, as we need it to emit the read barrier. |
| 4693 | locations->SetOut( |
| 4694 | Location::RequiresRegister(), |
| 4695 | object_array_get_with_read_barrier ? Location::kOutputOverlap : Location::kNoOutputOverlap); |
| Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4696 | } |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4697 | } |
| 4698 | |
| 4699 | void InstructionCodeGeneratorX86_64::VisitArrayGet(HArrayGet* instruction) { |
| 4700 | LocationSummary* locations = instruction->GetLocations(); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4701 | Location obj_loc = locations->InAt(0); |
| 4702 | CpuRegister obj = obj_loc.AsRegister<CpuRegister>(); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4703 | Location index = locations->InAt(1); |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4704 | Location out_loc = locations->Out(); |
| Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 4705 | uint32_t data_offset = CodeGenerator::GetArrayDataOffset(instruction); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4706 | |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4707 | Primitive::Type type = instruction->GetType(); |
| Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4708 | switch (type) { |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4709 | case Primitive::kPrimBoolean: { |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4710 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 4711 | __ movzxb(out, CodeGeneratorX86_64::ArrayAddress(obj, index, TIMES_1, data_offset)); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4712 | break; |
| 4713 | } |
| 4714 | |
| 4715 | case Primitive::kPrimByte: { |
| 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 | __ movsxb(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::kPrimShort: { |
| 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 | __ movsxw(out, CodeGeneratorX86_64::ArrayAddress(obj, index, TIMES_2, data_offset)); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4724 | break; |
| 4725 | } |
| 4726 | |
| 4727 | case Primitive::kPrimChar: { |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4728 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
| jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 4729 | if (mirror::kUseStringCompression && instruction->IsStringCharAt()) { |
| 4730 | // Branch cases into compressed and uncompressed for each index's type. |
| 4731 | uint32_t count_offset = mirror::String::CountOffset().Uint32Value(); |
| 4732 | NearLabel done, not_compressed; |
| Vladimir Marko | 3c89d42 | 2017-02-17 11:30:23 +0000 | [diff] [blame] | 4733 | __ testb(Address(obj, count_offset), Immediate(1)); |
| jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 4734 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 4735 | static_assert(static_cast<uint32_t>(mirror::StringCompressionFlag::kCompressed) == 0u, |
| 4736 | "Expecting 0=compressed, 1=uncompressed"); |
| 4737 | __ j(kNotZero, ¬_compressed); |
| jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 4738 | __ movzxb(out, CodeGeneratorX86_64::ArrayAddress(obj, index, TIMES_1, data_offset)); |
| 4739 | __ jmp(&done); |
| 4740 | __ Bind(¬_compressed); |
| 4741 | __ movzxw(out, CodeGeneratorX86_64::ArrayAddress(obj, index, TIMES_2, data_offset)); |
| 4742 | __ Bind(&done); |
| 4743 | } else { |
| 4744 | __ movzxw(out, CodeGeneratorX86_64::ArrayAddress(obj, index, TIMES_2, data_offset)); |
| 4745 | } |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4746 | break; |
| 4747 | } |
| 4748 | |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4749 | case Primitive::kPrimInt: { |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4750 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 4751 | __ movl(out, CodeGeneratorX86_64::ArrayAddress(obj, index, TIMES_4, data_offset)); |
| 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::kPrimNot: { |
| 4756 | static_assert( |
| 4757 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 4758 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4759 | // /* HeapReference<Object> */ out = |
| 4760 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
| 4761 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4762 | // Note that a potential implicit null check is handled in this |
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 4763 | // CodeGeneratorX86_64::GenerateArrayLoadWithBakerReadBarrier call. |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4764 | codegen_->GenerateArrayLoadWithBakerReadBarrier( |
| Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 4765 | instruction, out_loc, obj, data_offset, index, /* needs_null_check */ true); |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4766 | } else { |
| 4767 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 4768 | __ movl(out, CodeGeneratorX86_64::ArrayAddress(obj, index, TIMES_4, data_offset)); |
| 4769 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4770 | // If read barriers are enabled, emit read barriers other than |
| 4771 | // Baker's using a slow path (and also unpoison the loaded |
| 4772 | // reference, if heap poisoning is enabled). |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4773 | if (index.IsConstant()) { |
| 4774 | uint32_t offset = |
| 4775 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4776 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out_loc, out_loc, obj_loc, offset); |
| 4777 | } else { |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4778 | codegen_->MaybeGenerateReadBarrierSlow( |
| 4779 | instruction, out_loc, out_loc, obj_loc, data_offset, index); |
| 4780 | } |
| 4781 | } |
| 4782 | break; |
| 4783 | } |
| 4784 | |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4785 | case Primitive::kPrimLong: { |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4786 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 4787 | __ movq(out, CodeGeneratorX86_64::ArrayAddress(obj, index, TIMES_8, data_offset)); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4788 | break; |
| 4789 | } |
| 4790 | |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4791 | case Primitive::kPrimFloat: { |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4792 | XmmRegister out = out_loc.AsFpuRegister<XmmRegister>(); |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 4793 | __ movss(out, CodeGeneratorX86_64::ArrayAddress(obj, index, TIMES_4, data_offset)); |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4794 | break; |
| 4795 | } |
| 4796 | |
| 4797 | case Primitive::kPrimDouble: { |
| 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 | __ movsd(out, CodeGeneratorX86_64::ArrayAddress(obj, index, TIMES_8, data_offset)); |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4800 | break; |
| 4801 | } |
| 4802 | |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4803 | case Primitive::kPrimVoid: |
| Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4804 | LOG(FATAL) << "Unreachable type " << type; |
| Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 4805 | UNREACHABLE(); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4806 | } |
| Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4807 | |
| 4808 | if (type == Primitive::kPrimNot) { |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4809 | // Potential implicit null checks, in the case of reference |
| 4810 | // arrays, are handled in the previous switch statement. |
| 4811 | } else { |
| 4812 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4813 | } |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4814 | } |
| 4815 | |
| 4816 | void LocationsBuilderX86_64::VisitArraySet(HArraySet* instruction) { |
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4817 | Primitive::Type value_type = instruction->GetComponentType(); |
| Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4818 | |
| 4819 | bool needs_write_barrier = |
| 4820 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
| Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 4821 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
| Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4822 | |
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4823 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary( |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4824 | instruction, |
| Vladimir Marko | 8d49fd7 | 2016-08-25 15:20:47 +0100 | [diff] [blame] | 4825 | may_need_runtime_call_for_type_check ? |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4826 | LocationSummary::kCallOnSlowPath : |
| 4827 | LocationSummary::kNoCall); |
| Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4828 | |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4829 | locations->SetInAt(0, Location::RequiresRegister()); |
| Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4830 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 4831 | if (Primitive::IsFloatingPointType(value_type)) { |
| 4832 | locations->SetInAt(2, Location::FpuRegisterOrConstant(instruction->InputAt(2))); |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4833 | } else { |
| 4834 | locations->SetInAt(2, Location::RegisterOrConstant(instruction->InputAt(2))); |
| 4835 | } |
| 4836 | |
| 4837 | if (needs_write_barrier) { |
| 4838 | // Temporary registers for the write barrier. |
| Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 4839 | locations->AddTemp(Location::RequiresRegister()); // Possibly used for ref. poisoning too. |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4840 | locations->AddTemp(Location::RequiresRegister()); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4841 | } |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4842 | } |
| 4843 | |
| 4844 | void InstructionCodeGeneratorX86_64::VisitArraySet(HArraySet* instruction) { |
| 4845 | LocationSummary* locations = instruction->GetLocations(); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4846 | Location array_loc = locations->InAt(0); |
| 4847 | CpuRegister array = array_loc.AsRegister<CpuRegister>(); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4848 | Location index = locations->InAt(1); |
| Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4849 | Location value = locations->InAt(2); |
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4850 | Primitive::Type value_type = instruction->GetComponentType(); |
| Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 4851 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
| Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4852 | bool needs_write_barrier = |
| 4853 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4854 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 4855 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 4856 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4857 | |
| 4858 | switch (value_type) { |
| 4859 | case Primitive::kPrimBoolean: |
| 4860 | case Primitive::kPrimByte: { |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4861 | uint32_t offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value(); |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 4862 | Address address = CodeGeneratorX86_64::ArrayAddress(array, index, TIMES_1, offset); |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4863 | if (value.IsRegister()) { |
| 4864 | __ movb(address, value.AsRegister<CpuRegister>()); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4865 | } else { |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4866 | __ movb(address, Immediate(value.GetConstant()->AsIntConstant()->GetValue())); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4867 | } |
| Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4868 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4869 | break; |
| 4870 | } |
| 4871 | |
| 4872 | case Primitive::kPrimShort: |
| 4873 | case Primitive::kPrimChar: { |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4874 | uint32_t offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value(); |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 4875 | Address address = CodeGeneratorX86_64::ArrayAddress(array, index, TIMES_2, offset); |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4876 | if (value.IsRegister()) { |
| 4877 | __ movw(address, value.AsRegister<CpuRegister>()); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4878 | } else { |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4879 | DCHECK(value.IsConstant()) << value; |
| 4880 | __ movw(address, Immediate(value.GetConstant()->AsIntConstant()->GetValue())); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4881 | } |
| Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4882 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4883 | break; |
| 4884 | } |
| 4885 | |
| 4886 | case Primitive::kPrimNot: { |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4887 | uint32_t offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 4888 | Address address = CodeGeneratorX86_64::ArrayAddress(array, index, TIMES_4, offset); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4889 | |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4890 | if (!value.IsRegister()) { |
| 4891 | // Just setting null. |
| 4892 | DCHECK(instruction->InputAt(2)->IsNullConstant()); |
| 4893 | DCHECK(value.IsConstant()) << value; |
| 4894 | __ movl(address, Immediate(0)); |
| Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4895 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4896 | DCHECK(!needs_write_barrier); |
| Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 4897 | DCHECK(!may_need_runtime_call_for_type_check); |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4898 | break; |
| Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4899 | } |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4900 | |
| 4901 | DCHECK(needs_write_barrier); |
| 4902 | CpuRegister register_value = value.AsRegister<CpuRegister>(); |
| Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 4903 | // We cannot use a NearLabel for `done`, as its range may be too |
| 4904 | // short when Baker read barriers are enabled. |
| 4905 | Label done; |
| 4906 | NearLabel not_null, do_put; |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4907 | SlowPathCode* slow_path = nullptr; |
| Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 4908 | Location temp_loc = locations->GetTemp(0); |
| 4909 | CpuRegister temp = temp_loc.AsRegister<CpuRegister>(); |
| Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 4910 | if (may_need_runtime_call_for_type_check) { |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4911 | slow_path = new (GetGraph()->GetArena()) ArraySetSlowPathX86_64(instruction); |
| 4912 | codegen_->AddSlowPath(slow_path); |
| 4913 | if (instruction->GetValueCanBeNull()) { |
| 4914 | __ testl(register_value, register_value); |
| 4915 | __ j(kNotEqual, ¬_null); |
| 4916 | __ movl(address, Immediate(0)); |
| 4917 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4918 | __ jmp(&done); |
| 4919 | __ Bind(¬_null); |
| 4920 | } |
| 4921 | |
| Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 4922 | // Note that when Baker read barriers are enabled, the type |
| 4923 | // checks are performed without read barriers. This is fine, |
| 4924 | // even in the case where a class object is in the from-space |
| 4925 | // after the flip, as a comparison involving such a type would |
| 4926 | // not produce a false positive; it may of course produce a |
| 4927 | // false negative, in which case we would take the ArraySet |
| 4928 | // slow path. |
| Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 4929 | |
| Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 4930 | // /* HeapReference<Class> */ temp = array->klass_ |
| 4931 | __ movl(temp, Address(array, class_offset)); |
| 4932 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4933 | __ MaybeUnpoisonHeapReference(temp); |
| Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 4934 | |
| Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 4935 | // /* HeapReference<Class> */ temp = temp->component_type_ |
| 4936 | __ movl(temp, Address(temp, component_offset)); |
| 4937 | // If heap poisoning is enabled, no need to unpoison `temp` |
| 4938 | // nor the object reference in `register_value->klass`, as |
| 4939 | // we are comparing two poisoned references. |
| 4940 | __ cmpl(temp, Address(register_value, class_offset)); |
| Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 4941 | |
| Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 4942 | if (instruction->StaticTypeOfArrayIsObjectArray()) { |
| 4943 | __ j(kEqual, &do_put); |
| 4944 | // If heap poisoning is enabled, the `temp` reference has |
| 4945 | // not been unpoisoned yet; unpoison it now. |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4946 | __ MaybeUnpoisonHeapReference(temp); |
| 4947 | |
| Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 4948 | // If heap poisoning is enabled, no need to unpoison the |
| 4949 | // heap reference loaded below, as it is only used for a |
| 4950 | // comparison with null. |
| 4951 | __ cmpl(Address(temp, super_offset), Immediate(0)); |
| 4952 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 4953 | __ Bind(&do_put); |
| 4954 | } else { |
| 4955 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4956 | } |
| 4957 | } |
| 4958 | |
| 4959 | if (kPoisonHeapReferences) { |
| 4960 | __ movl(temp, register_value); |
| 4961 | __ PoisonHeapReference(temp); |
| 4962 | __ movl(address, temp); |
| 4963 | } else { |
| 4964 | __ movl(address, register_value); |
| 4965 | } |
| Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 4966 | if (!may_need_runtime_call_for_type_check) { |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4967 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4968 | } |
| 4969 | |
| 4970 | CpuRegister card = locations->GetTemp(1).AsRegister<CpuRegister>(); |
| 4971 | codegen_->MarkGCCard( |
| 4972 | temp, card, array, value.AsRegister<CpuRegister>(), instruction->GetValueCanBeNull()); |
| 4973 | __ Bind(&done); |
| 4974 | |
| 4975 | if (slow_path != nullptr) { |
| 4976 | __ Bind(slow_path->GetExitLabel()); |
| 4977 | } |
| 4978 | |
| 4979 | break; |
| 4980 | } |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4981 | |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4982 | case Primitive::kPrimInt: { |
| 4983 | uint32_t offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 4984 | Address address = CodeGeneratorX86_64::ArrayAddress(array, index, TIMES_4, offset); |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4985 | if (value.IsRegister()) { |
| 4986 | __ movl(address, value.AsRegister<CpuRegister>()); |
| 4987 | } else { |
| 4988 | DCHECK(value.IsConstant()) << value; |
| 4989 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
| 4990 | __ movl(address, Immediate(v)); |
| 4991 | } |
| 4992 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4993 | break; |
| 4994 | } |
| 4995 | |
| 4996 | case Primitive::kPrimLong: { |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4997 | uint32_t offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value(); |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 4998 | Address address = CodeGeneratorX86_64::ArrayAddress(array, index, TIMES_8, offset); |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4999 | if (value.IsRegister()) { |
| 5000 | __ movq(address, value.AsRegister<CpuRegister>()); |
| Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 5001 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5002 | } else { |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5003 | int64_t v = value.GetConstant()->AsLongConstant()->GetValue(); |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5004 | Address address_high = |
| 5005 | CodeGeneratorX86_64::ArrayAddress(array, index, TIMES_8, offset + sizeof(int32_t)); |
| Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 5006 | codegen_->MoveInt64ToAddress(address, address_high, v, instruction); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5007 | } |
| 5008 | break; |
| 5009 | } |
| 5010 | |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5011 | case Primitive::kPrimFloat: { |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5012 | uint32_t offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value(); |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5013 | Address address = CodeGeneratorX86_64::ArrayAddress(array, index, TIMES_4, offset); |
| Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 5014 | if (value.IsFpuRegister()) { |
| 5015 | __ movss(address, value.AsFpuRegister<XmmRegister>()); |
| 5016 | } else { |
| 5017 | DCHECK(value.IsConstant()); |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5018 | int32_t v = bit_cast<int32_t, float>(value.GetConstant()->AsFloatConstant()->GetValue()); |
| Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 5019 | __ movl(address, Immediate(v)); |
| 5020 | } |
| Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5021 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5022 | break; |
| 5023 | } |
| 5024 | |
| 5025 | case Primitive::kPrimDouble: { |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5026 | uint32_t offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value(); |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5027 | Address address = CodeGeneratorX86_64::ArrayAddress(array, index, TIMES_8, offset); |
| Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 5028 | if (value.IsFpuRegister()) { |
| 5029 | __ movsd(address, value.AsFpuRegister<XmmRegister>()); |
| 5030 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5031 | } else { |
| 5032 | int64_t v = |
| 5033 | bit_cast<int64_t, double>(value.GetConstant()->AsDoubleConstant()->GetValue()); |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5034 | Address address_high = |
| 5035 | CodeGeneratorX86_64::ArrayAddress(array, index, TIMES_8, offset + sizeof(int32_t)); |
| Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 5036 | codegen_->MoveInt64ToAddress(address, address_high, v, instruction); |
| 5037 | } |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5038 | break; |
| 5039 | } |
| 5040 | |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5041 | case Primitive::kPrimVoid: |
| 5042 | LOG(FATAL) << "Unreachable type " << instruction->GetType(); |
| Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 5043 | UNREACHABLE(); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5044 | } |
| 5045 | } |
| 5046 | |
| 5047 | void LocationsBuilderX86_64::VisitArrayLength(HArrayLength* instruction) { |
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5048 | LocationSummary* locations = |
| 5049 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 5050 | locations->SetInAt(0, Location::RequiresRegister()); |
| Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 5051 | if (!instruction->IsEmittedAtUseSite()) { |
| 5052 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 5053 | } |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5054 | } |
| 5055 | |
| 5056 | void InstructionCodeGeneratorX86_64::VisitArrayLength(HArrayLength* instruction) { |
| Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 5057 | if (instruction->IsEmittedAtUseSite()) { |
| 5058 | return; |
| 5059 | } |
| 5060 | |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5061 | LocationSummary* locations = instruction->GetLocations(); |
| Vladimir Marko | dce016e | 2016-04-28 13:10:02 +0100 | [diff] [blame] | 5062 | uint32_t offset = CodeGenerator::GetArrayLengthOffset(instruction); |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5063 | CpuRegister obj = locations->InAt(0).AsRegister<CpuRegister>(); |
| 5064 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5065 | __ movl(out, Address(obj, offset)); |
| Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5066 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5067 | // Mask out most significant bit in case the array is String's array of char. |
| 5068 | if (mirror::kUseStringCompression && instruction->IsStringLength()) { |
| Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 5069 | __ shrl(out, Immediate(1)); |
| jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5070 | } |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5071 | } |
| 5072 | |
| 5073 | void LocationsBuilderX86_64::VisitBoundsCheck(HBoundsCheck* instruction) { |
| Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 5074 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 5075 | InvokeRuntimeCallingConvention calling_convention; |
| 5076 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 5077 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 5078 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction, caller_saves); |
| Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 5079 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
| Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 5080 | HInstruction* length = instruction->InputAt(1); |
| 5081 | if (!length->IsEmittedAtUseSite()) { |
| 5082 | locations->SetInAt(1, Location::RegisterOrConstant(length)); |
| 5083 | } |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5084 | } |
| 5085 | |
| 5086 | void InstructionCodeGeneratorX86_64::VisitBoundsCheck(HBoundsCheck* instruction) { |
| 5087 | LocationSummary* locations = instruction->GetLocations(); |
| Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 5088 | Location index_loc = locations->InAt(0); |
| 5089 | Location length_loc = locations->InAt(1); |
| Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 5090 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) BoundsCheckSlowPathX86_64(instruction); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5091 | |
| Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 5092 | if (length_loc.IsConstant()) { |
| 5093 | int32_t length = CodeGenerator::GetInt32ValueOf(length_loc.GetConstant()); |
| 5094 | if (index_loc.IsConstant()) { |
| 5095 | // BCE will remove the bounds check if we are guarenteed to pass. |
| 5096 | int32_t index = CodeGenerator::GetInt32ValueOf(index_loc.GetConstant()); |
| 5097 | if (index < 0 || index >= length) { |
| 5098 | codegen_->AddSlowPath(slow_path); |
| 5099 | __ jmp(slow_path->GetEntryLabel()); |
| 5100 | } else { |
| 5101 | // Some optimization after BCE may have generated this, and we should not |
| 5102 | // generate a bounds check if it is a valid range. |
| 5103 | } |
| 5104 | return; |
| 5105 | } |
| 5106 | |
| 5107 | // We have to reverse the jump condition because the length is the constant. |
| 5108 | CpuRegister index_reg = index_loc.AsRegister<CpuRegister>(); |
| 5109 | __ cmpl(index_reg, Immediate(length)); |
| 5110 | codegen_->AddSlowPath(slow_path); |
| 5111 | __ j(kAboveEqual, slow_path->GetEntryLabel()); |
| Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 5112 | } else { |
| Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 5113 | HInstruction* array_length = instruction->InputAt(1); |
| 5114 | if (array_length->IsEmittedAtUseSite()) { |
| 5115 | // Address the length field in the array. |
| 5116 | DCHECK(array_length->IsArrayLength()); |
| 5117 | uint32_t len_offset = CodeGenerator::GetArrayLengthOffset(array_length->AsArrayLength()); |
| 5118 | Location array_loc = array_length->GetLocations()->InAt(0); |
| 5119 | Address array_len(array_loc.AsRegister<CpuRegister>(), len_offset); |
| jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5120 | if (mirror::kUseStringCompression && instruction->IsStringCharAt()) { |
| Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 5121 | // TODO: if index_loc.IsConstant(), compare twice the index (to compensate for |
| 5122 | // the string compression flag) with the in-memory length and avoid the temporary. |
| jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5123 | CpuRegister length_reg = CpuRegister(TMP); |
| 5124 | __ movl(length_reg, array_len); |
| 5125 | codegen_->MaybeRecordImplicitNullCheck(array_length); |
| Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 5126 | __ shrl(length_reg, Immediate(1)); |
| jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5127 | codegen_->GenerateIntCompare(length_reg, index_loc); |
| Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 5128 | } else { |
| jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5129 | // Checking the bound for general case: |
| 5130 | // Array of char or String's array when the compression feature off. |
| 5131 | if (index_loc.IsConstant()) { |
| 5132 | int32_t value = CodeGenerator::GetInt32ValueOf(index_loc.GetConstant()); |
| 5133 | __ cmpl(array_len, Immediate(value)); |
| 5134 | } else { |
| 5135 | __ cmpl(array_len, index_loc.AsRegister<CpuRegister>()); |
| 5136 | } |
| 5137 | codegen_->MaybeRecordImplicitNullCheck(array_length); |
| Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 5138 | } |
| Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 5139 | } else { |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5140 | codegen_->GenerateIntCompare(length_loc, index_loc); |
| Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 5141 | } |
| 5142 | codegen_->AddSlowPath(slow_path); |
| 5143 | __ j(kBelowEqual, slow_path->GetEntryLabel()); |
| Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 5144 | } |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5145 | } |
| 5146 | |
| 5147 | void CodeGeneratorX86_64::MarkGCCard(CpuRegister temp, |
| 5148 | CpuRegister card, |
| 5149 | CpuRegister object, |
| Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5150 | CpuRegister value, |
| 5151 | bool value_can_be_null) { |
| Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 5152 | NearLabel is_null; |
| Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5153 | if (value_can_be_null) { |
| 5154 | __ testl(value, value); |
| 5155 | __ j(kEqual, &is_null); |
| 5156 | } |
| Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 5157 | __ gs()->movq(card, Address::Absolute(Thread::CardTableOffset<kX86_64PointerSize>().Int32Value(), |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5158 | /* no_rip */ true)); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5159 | __ movq(temp, object); |
| 5160 | __ shrq(temp, Immediate(gc::accounting::CardTable::kCardShift)); |
| Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5161 | __ movb(Address(temp, card, TIMES_1, 0), card); |
| Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5162 | if (value_can_be_null) { |
| 5163 | __ Bind(&is_null); |
| 5164 | } |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5165 | } |
| 5166 | |
| Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5167 | void LocationsBuilderX86_64::VisitParallelMove(HParallelMove* instruction ATTRIBUTE_UNUSED) { |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 5168 | LOG(FATAL) << "Unimplemented"; |
| 5169 | } |
| 5170 | |
| 5171 | void InstructionCodeGeneratorX86_64::VisitParallelMove(HParallelMove* instruction) { |
| Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5172 | codegen_->GetMoveResolver()->EmitNativeCode(instruction); |
| 5173 | } |
| 5174 | |
| Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5175 | void LocationsBuilderX86_64::VisitSuspendCheck(HSuspendCheck* instruction) { |
| Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5176 | LocationSummary* locations = |
| 5177 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath); |
| Aart Bik | b13c65b | 2017-03-21 20:14:07 -0700 | [diff] [blame] | 5178 | // In suspend check slow path, usually there are no caller-save registers at all. |
| 5179 | // If SIMD instructions are present, however, we force spilling all live SIMD |
| 5180 | // registers in full width (since the runtime only saves/restores lower part). |
| Aart Bik | 5576f37 | 2017-03-23 16:17:37 -0700 | [diff] [blame] | 5181 | locations->SetCustomSlowPathCallerSaves( |
| 5182 | GetGraph()->HasSIMD() ? RegisterSet::AllFpu() : RegisterSet::Empty()); |
| Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5183 | } |
| 5184 | |
| 5185 | void InstructionCodeGeneratorX86_64::VisitSuspendCheck(HSuspendCheck* instruction) { |
| Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 5186 | HBasicBlock* block = instruction->GetBlock(); |
| 5187 | if (block->GetLoopInformation() != nullptr) { |
| 5188 | DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction); |
| 5189 | // The back edge will generate the suspend check. |
| 5190 | return; |
| 5191 | } |
| 5192 | if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) { |
| 5193 | // The goto will generate the suspend check. |
| 5194 | return; |
| 5195 | } |
| 5196 | GenerateSuspendCheck(instruction, nullptr); |
| 5197 | } |
| 5198 | |
| 5199 | void InstructionCodeGeneratorX86_64::GenerateSuspendCheck(HSuspendCheck* instruction, |
| 5200 | HBasicBlock* successor) { |
| Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5201 | SuspendCheckSlowPathX86_64* slow_path = |
| Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 5202 | down_cast<SuspendCheckSlowPathX86_64*>(instruction->GetSlowPath()); |
| 5203 | if (slow_path == nullptr) { |
| 5204 | slow_path = new (GetGraph()->GetArena()) SuspendCheckSlowPathX86_64(instruction, successor); |
| 5205 | instruction->SetSlowPath(slow_path); |
| 5206 | codegen_->AddSlowPath(slow_path); |
| 5207 | if (successor != nullptr) { |
| 5208 | DCHECK(successor->IsLoopHeader()); |
| 5209 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(instruction); |
| 5210 | } |
| 5211 | } else { |
| 5212 | DCHECK_EQ(slow_path->GetSuccessor(), successor); |
| 5213 | } |
| 5214 | |
| Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 5215 | __ gs()->cmpw(Address::Absolute(Thread::ThreadFlagsOffset<kX86_64PointerSize>().Int32Value(), |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5216 | /* no_rip */ true), |
| 5217 | Immediate(0)); |
| Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 5218 | if (successor == nullptr) { |
| 5219 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 5220 | __ Bind(slow_path->GetReturnLabel()); |
| 5221 | } else { |
| 5222 | __ j(kEqual, codegen_->GetLabelOf(successor)); |
| 5223 | __ jmp(slow_path->GetEntryLabel()); |
| 5224 | } |
| Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5225 | } |
| 5226 | |
| Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5227 | X86_64Assembler* ParallelMoveResolverX86_64::GetAssembler() const { |
| 5228 | return codegen_->GetAssembler(); |
| 5229 | } |
| 5230 | |
| 5231 | void ParallelMoveResolverX86_64::EmitMove(size_t index) { |
| Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5232 | MoveOperands* move = moves_[index]; |
| Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5233 | Location source = move->GetSource(); |
| 5234 | Location destination = move->GetDestination(); |
| 5235 | |
| 5236 | if (source.IsRegister()) { |
| 5237 | if (destination.IsRegister()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5238 | __ movq(destination.AsRegister<CpuRegister>(), source.AsRegister<CpuRegister>()); |
| Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5239 | } else if (destination.IsStackSlot()) { |
| Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5240 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5241 | source.AsRegister<CpuRegister>()); |
| Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5242 | } else { |
| 5243 | DCHECK(destination.IsDoubleStackSlot()); |
| 5244 | __ movq(Address(CpuRegister(RSP), destination.GetStackIndex()), |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5245 | source.AsRegister<CpuRegister>()); |
| Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5246 | } |
| 5247 | } else if (source.IsStackSlot()) { |
| 5248 | if (destination.IsRegister()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5249 | __ movl(destination.AsRegister<CpuRegister>(), |
| Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5250 | Address(CpuRegister(RSP), source.GetStackIndex())); |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5251 | } else if (destination.IsFpuRegister()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5252 | __ movss(destination.AsFpuRegister<XmmRegister>(), |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5253 | Address(CpuRegister(RSP), source.GetStackIndex())); |
| Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5254 | } else { |
| 5255 | DCHECK(destination.IsStackSlot()); |
| 5256 | __ movl(CpuRegister(TMP), Address(CpuRegister(RSP), source.GetStackIndex())); |
| 5257 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), CpuRegister(TMP)); |
| 5258 | } |
| Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5259 | } else if (source.IsDoubleStackSlot()) { |
| 5260 | if (destination.IsRegister()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5261 | __ movq(destination.AsRegister<CpuRegister>(), |
| Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5262 | Address(CpuRegister(RSP), source.GetStackIndex())); |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5263 | } else if (destination.IsFpuRegister()) { |
| Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 5264 | __ movsd(destination.AsFpuRegister<XmmRegister>(), |
| 5265 | Address(CpuRegister(RSP), source.GetStackIndex())); |
| Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5266 | } else { |
| Nicolas Geoffray | c8147a7 | 2014-10-21 16:06:20 +0100 | [diff] [blame] | 5267 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5268 | __ movq(CpuRegister(TMP), Address(CpuRegister(RSP), source.GetStackIndex())); |
| 5269 | __ movq(Address(CpuRegister(RSP), destination.GetStackIndex()), CpuRegister(TMP)); |
| 5270 | } |
| Aart Bik | 5576f37 | 2017-03-23 16:17:37 -0700 | [diff] [blame] | 5271 | } else if (source.IsSIMDStackSlot()) { |
| 5272 | DCHECK(destination.IsFpuRegister()); |
| 5273 | __ movups(destination.AsFpuRegister<XmmRegister>(), |
| 5274 | Address(CpuRegister(RSP), source.GetStackIndex())); |
| Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5275 | } else if (source.IsConstant()) { |
| 5276 | HConstant* constant = source.GetConstant(); |
| Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 5277 | if (constant->IsIntConstant() || constant->IsNullConstant()) { |
| 5278 | int32_t value = CodeGenerator::GetInt32ValueOf(constant); |
| Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5279 | if (destination.IsRegister()) { |
| Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 5280 | if (value == 0) { |
| 5281 | __ xorl(destination.AsRegister<CpuRegister>(), destination.AsRegister<CpuRegister>()); |
| 5282 | } else { |
| 5283 | __ movl(destination.AsRegister<CpuRegister>(), Immediate(value)); |
| 5284 | } |
| Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5285 | } else { |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5286 | DCHECK(destination.IsStackSlot()) << destination; |
| Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 5287 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), Immediate(value)); |
| Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5288 | } |
| 5289 | } else if (constant->IsLongConstant()) { |
| 5290 | int64_t value = constant->AsLongConstant()->GetValue(); |
| 5291 | if (destination.IsRegister()) { |
| Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 5292 | codegen_->Load64BitValue(destination.AsRegister<CpuRegister>(), value); |
| Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5293 | } else { |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5294 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 5295 | codegen_->Store64BitValueToStack(destination, value); |
| Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5296 | } |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5297 | } else if (constant->IsFloatConstant()) { |
| Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5298 | float fp_value = constant->AsFloatConstant()->GetValue(); |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5299 | if (destination.IsFpuRegister()) { |
| Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5300 | XmmRegister dest = destination.AsFpuRegister<XmmRegister>(); |
| Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 5301 | codegen_->Load32BitValue(dest, fp_value); |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5302 | } else { |
| 5303 | DCHECK(destination.IsStackSlot()) << destination; |
| Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 5304 | Immediate imm(bit_cast<int32_t, float>(fp_value)); |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5305 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), imm); |
| 5306 | } |
| Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5307 | } else { |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5308 | DCHECK(constant->IsDoubleConstant()) << constant->DebugName(); |
| Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5309 | double fp_value = constant->AsDoubleConstant()->GetValue(); |
| Roland Levillain | da4d79b | 2015-03-24 14:36:11 +0000 | [diff] [blame] | 5310 | int64_t value = bit_cast<int64_t, double>(fp_value); |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5311 | if (destination.IsFpuRegister()) { |
| Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5312 | XmmRegister dest = destination.AsFpuRegister<XmmRegister>(); |
| Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 5313 | codegen_->Load64BitValue(dest, fp_value); |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5314 | } else { |
| 5315 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 5316 | codegen_->Store64BitValueToStack(destination, value); |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5317 | } |
| Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5318 | } |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5319 | } else if (source.IsFpuRegister()) { |
| 5320 | if (destination.IsFpuRegister()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5321 | __ movaps(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5322 | } else if (destination.IsStackSlot()) { |
| 5323 | __ movss(Address(CpuRegister(RSP), destination.GetStackIndex()), |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5324 | source.AsFpuRegister<XmmRegister>()); |
| Aart Bik | 5576f37 | 2017-03-23 16:17:37 -0700 | [diff] [blame] | 5325 | } else if (destination.IsDoubleStackSlot()) { |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5326 | __ movsd(Address(CpuRegister(RSP), destination.GetStackIndex()), |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5327 | source.AsFpuRegister<XmmRegister>()); |
| Aart Bik | 5576f37 | 2017-03-23 16:17:37 -0700 | [diff] [blame] | 5328 | } else { |
| 5329 | DCHECK(destination.IsSIMDStackSlot()); |
| 5330 | __ movups(Address(CpuRegister(RSP), destination.GetStackIndex()), |
| 5331 | source.AsFpuRegister<XmmRegister>()); |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5332 | } |
| Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5333 | } |
| 5334 | } |
| 5335 | |
| Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5336 | void ParallelMoveResolverX86_64::Exchange32(CpuRegister reg, int mem) { |
| Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5337 | __ movl(CpuRegister(TMP), Address(CpuRegister(RSP), mem)); |
| Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5338 | __ movl(Address(CpuRegister(RSP), mem), reg); |
| 5339 | __ movl(reg, CpuRegister(TMP)); |
| Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5340 | } |
| 5341 | |
| Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5342 | void ParallelMoveResolverX86_64::Exchange32(int mem1, int mem2) { |
| Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5343 | ScratchRegisterScope ensure_scratch( |
| 5344 | this, TMP, RAX, codegen_->GetNumberOfCoreRegisters()); |
| 5345 | |
| 5346 | int stack_offset = ensure_scratch.IsSpilled() ? kX86_64WordSize : 0; |
| 5347 | __ movl(CpuRegister(TMP), Address(CpuRegister(RSP), mem1 + stack_offset)); |
| 5348 | __ movl(CpuRegister(ensure_scratch.GetRegister()), |
| 5349 | Address(CpuRegister(RSP), mem2 + stack_offset)); |
| 5350 | __ movl(Address(CpuRegister(RSP), mem2 + stack_offset), CpuRegister(TMP)); |
| 5351 | __ movl(Address(CpuRegister(RSP), mem1 + stack_offset), |
| 5352 | CpuRegister(ensure_scratch.GetRegister())); |
| 5353 | } |
| 5354 | |
| Mark Mendell | 8a1c728 | 2015-06-29 15:41:28 -0400 | [diff] [blame] | 5355 | void ParallelMoveResolverX86_64::Exchange64(CpuRegister reg1, CpuRegister reg2) { |
| 5356 | __ movq(CpuRegister(TMP), reg1); |
| 5357 | __ movq(reg1, reg2); |
| 5358 | __ movq(reg2, CpuRegister(TMP)); |
| 5359 | } |
| 5360 | |
| Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5361 | void ParallelMoveResolverX86_64::Exchange64(CpuRegister reg, int mem) { |
| 5362 | __ movq(CpuRegister(TMP), Address(CpuRegister(RSP), mem)); |
| 5363 | __ movq(Address(CpuRegister(RSP), mem), reg); |
| 5364 | __ movq(reg, CpuRegister(TMP)); |
| 5365 | } |
| 5366 | |
| 5367 | void ParallelMoveResolverX86_64::Exchange64(int mem1, int mem2) { |
| 5368 | ScratchRegisterScope ensure_scratch( |
| Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5369 | this, TMP, RAX, codegen_->GetNumberOfCoreRegisters()); |
| Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5370 | |
| Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5371 | int stack_offset = ensure_scratch.IsSpilled() ? kX86_64WordSize : 0; |
| 5372 | __ movq(CpuRegister(TMP), Address(CpuRegister(RSP), mem1 + stack_offset)); |
| 5373 | __ movq(CpuRegister(ensure_scratch.GetRegister()), |
| 5374 | Address(CpuRegister(RSP), mem2 + stack_offset)); |
| 5375 | __ movq(Address(CpuRegister(RSP), mem2 + stack_offset), CpuRegister(TMP)); |
| 5376 | __ movq(Address(CpuRegister(RSP), mem1 + stack_offset), |
| 5377 | CpuRegister(ensure_scratch.GetRegister())); |
| Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5378 | } |
| 5379 | |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5380 | void ParallelMoveResolverX86_64::Exchange32(XmmRegister reg, int mem) { |
| 5381 | __ movl(CpuRegister(TMP), Address(CpuRegister(RSP), mem)); |
| 5382 | __ movss(Address(CpuRegister(RSP), mem), reg); |
| 5383 | __ movd(reg, CpuRegister(TMP)); |
| 5384 | } |
| 5385 | |
| 5386 | void ParallelMoveResolverX86_64::Exchange64(XmmRegister reg, int mem) { |
| 5387 | __ movq(CpuRegister(TMP), Address(CpuRegister(RSP), mem)); |
| 5388 | __ movsd(Address(CpuRegister(RSP), mem), reg); |
| 5389 | __ movd(reg, CpuRegister(TMP)); |
| 5390 | } |
| 5391 | |
| Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5392 | void ParallelMoveResolverX86_64::EmitSwap(size_t index) { |
| Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5393 | MoveOperands* move = moves_[index]; |
| Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5394 | Location source = move->GetSource(); |
| 5395 | Location destination = move->GetDestination(); |
| 5396 | |
| 5397 | if (source.IsRegister() && destination.IsRegister()) { |
| Mark Mendell | 8a1c728 | 2015-06-29 15:41:28 -0400 | [diff] [blame] | 5398 | Exchange64(source.AsRegister<CpuRegister>(), destination.AsRegister<CpuRegister>()); |
| Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5399 | } else if (source.IsRegister() && destination.IsStackSlot()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5400 | Exchange32(source.AsRegister<CpuRegister>(), destination.GetStackIndex()); |
| Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5401 | } else if (source.IsStackSlot() && destination.IsRegister()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5402 | Exchange32(destination.AsRegister<CpuRegister>(), source.GetStackIndex()); |
| Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5403 | } else if (source.IsStackSlot() && destination.IsStackSlot()) { |
| Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5404 | Exchange32(destination.GetStackIndex(), source.GetStackIndex()); |
| 5405 | } else if (source.IsRegister() && destination.IsDoubleStackSlot()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5406 | Exchange64(source.AsRegister<CpuRegister>(), destination.GetStackIndex()); |
| Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5407 | } else if (source.IsDoubleStackSlot() && destination.IsRegister()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5408 | Exchange64(destination.AsRegister<CpuRegister>(), source.GetStackIndex()); |
| Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5409 | } else if (source.IsDoubleStackSlot() && destination.IsDoubleStackSlot()) { |
| 5410 | Exchange64(destination.GetStackIndex(), source.GetStackIndex()); |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5411 | } else if (source.IsFpuRegister() && destination.IsFpuRegister()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5412 | __ movd(CpuRegister(TMP), source.AsFpuRegister<XmmRegister>()); |
| 5413 | __ movaps(source.AsFpuRegister<XmmRegister>(), destination.AsFpuRegister<XmmRegister>()); |
| 5414 | __ movd(destination.AsFpuRegister<XmmRegister>(), CpuRegister(TMP)); |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5415 | } else if (source.IsFpuRegister() && destination.IsStackSlot()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5416 | Exchange32(source.AsFpuRegister<XmmRegister>(), destination.GetStackIndex()); |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5417 | } else if (source.IsStackSlot() && destination.IsFpuRegister()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5418 | Exchange32(destination.AsFpuRegister<XmmRegister>(), source.GetStackIndex()); |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5419 | } else if (source.IsFpuRegister() && destination.IsDoubleStackSlot()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5420 | Exchange64(source.AsFpuRegister<XmmRegister>(), destination.GetStackIndex()); |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5421 | } else if (source.IsDoubleStackSlot() && destination.IsFpuRegister()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5422 | Exchange64(destination.AsFpuRegister<XmmRegister>(), source.GetStackIndex()); |
| Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5423 | } else { |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5424 | LOG(FATAL) << "Unimplemented swap between " << source << " and " << destination; |
| Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5425 | } |
| 5426 | } |
| 5427 | |
| 5428 | |
| 5429 | void ParallelMoveResolverX86_64::SpillScratch(int reg) { |
| 5430 | __ pushq(CpuRegister(reg)); |
| 5431 | } |
| 5432 | |
| 5433 | |
| 5434 | void ParallelMoveResolverX86_64::RestoreScratch(int reg) { |
| 5435 | __ popq(CpuRegister(reg)); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 5436 | } |
| 5437 | |
| Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5438 | void InstructionCodeGeneratorX86_64::GenerateClassInitializationCheck( |
| Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 5439 | SlowPathCode* slow_path, CpuRegister class_reg) { |
| Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5440 | __ cmpl(Address(class_reg, mirror::Class::StatusOffset().Int32Value()), |
| 5441 | Immediate(mirror::Class::kStatusInitialized)); |
| 5442 | __ j(kLess, slow_path->GetEntryLabel()); |
| 5443 | __ Bind(slow_path->GetExitLabel()); |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5444 | // No need for memory fence, thanks to the x86-64 memory model. |
| Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5445 | } |
| 5446 | |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5447 | HLoadClass::LoadKind CodeGeneratorX86_64::GetSupportedLoadClassKind( |
| 5448 | HLoadClass::LoadKind desired_class_load_kind) { |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5449 | switch (desired_class_load_kind) { |
| Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 5450 | case HLoadClass::LoadKind::kInvalid: |
| 5451 | LOG(FATAL) << "UNREACHABLE"; |
| 5452 | UNREACHABLE(); |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5453 | case HLoadClass::LoadKind::kReferrersClass: |
| 5454 | break; |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5455 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: |
| Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5456 | case HLoadClass::LoadKind::kBssEntry: |
| 5457 | DCHECK(!Runtime::Current()->UseJitCompilation()); |
| 5458 | break; |
| Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 5459 | case HLoadClass::LoadKind::kJitTableAddress: |
| Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5460 | DCHECK(Runtime::Current()->UseJitCompilation()); |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5461 | break; |
| Vladimir Marko | 764d454 | 2017-05-16 10:31:41 +0100 | [diff] [blame] | 5462 | case HLoadClass::LoadKind::kBootImageAddress: |
| Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 5463 | case HLoadClass::LoadKind::kRuntimeCall: |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5464 | break; |
| 5465 | } |
| 5466 | return desired_class_load_kind; |
| 5467 | } |
| 5468 | |
| Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5469 | void LocationsBuilderX86_64::VisitLoadClass(HLoadClass* cls) { |
| Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5470 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
| Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 5471 | if (load_kind == HLoadClass::LoadKind::kRuntimeCall) { |
| Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 5472 | // Custom calling convention: RAX serves as both input and output. |
| Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5473 | CodeGenerator::CreateLoadClassRuntimeCallLocationSummary( |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5474 | cls, |
| Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 5475 | Location::RegisterLocation(RAX), |
| Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5476 | Location::RegisterLocation(RAX)); |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5477 | return; |
| 5478 | } |
| Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5479 | DCHECK(!cls->NeedsAccessCheck()); |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5480 | |
| Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5481 | const bool requires_read_barrier = kEmitCompilerReadBarrier && !cls->IsInBootImage(); |
| 5482 | LocationSummary::CallKind call_kind = (cls->NeedsEnvironment() || requires_read_barrier) |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5483 | ? LocationSummary::kCallOnSlowPath |
| 5484 | : LocationSummary::kNoCall; |
| 5485 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(cls, call_kind); |
| Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5486 | if (kUseBakerReadBarrier && requires_read_barrier && !cls->NeedsEnvironment()) { |
| Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 5487 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
| Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5488 | } |
| 5489 | |
| Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5490 | if (load_kind == HLoadClass::LoadKind::kReferrersClass) { |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5491 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5492 | } |
| 5493 | locations->SetOut(Location::RequiresRegister()); |
| Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 5494 | if (load_kind == HLoadClass::LoadKind::kBssEntry) { |
| 5495 | if (!kUseReadBarrier || kUseBakerReadBarrier) { |
| 5496 | // Rely on the type resolution and/or initialization to save everything. |
| 5497 | // Custom calling convention: RAX serves as both input and output. |
| 5498 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 5499 | caller_saves.Add(Location::RegisterLocation(RAX)); |
| 5500 | locations->SetCustomSlowPathCallerSaves(caller_saves); |
| 5501 | } else { |
| 5502 | // For non-Baker read barrier we have a temp-clobbering call. |
| 5503 | } |
| 5504 | } |
| Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5505 | } |
| 5506 | |
| Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 5507 | Label* CodeGeneratorX86_64::NewJitRootClassPatch(const DexFile& dex_file, |
| 5508 | dex::TypeIndex dex_index, |
| Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 5509 | Handle<mirror::Class> handle) { |
| 5510 | jit_class_roots_.Overwrite( |
| 5511 | TypeReference(&dex_file, dex_index), reinterpret_cast64<uint64_t>(handle.GetReference())); |
| Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 5512 | // Add a patch entry and return the label. |
| 5513 | jit_class_patches_.emplace_back(dex_file, dex_index.index_); |
| 5514 | PatchInfo<Label>* info = &jit_class_patches_.back(); |
| 5515 | return &info->label; |
| 5516 | } |
| 5517 | |
| Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 5518 | // NO_THREAD_SAFETY_ANALYSIS as we manipulate handles whose internal object we know does not |
| 5519 | // move. |
| 5520 | void InstructionCodeGeneratorX86_64::VisitLoadClass(HLoadClass* cls) NO_THREAD_SAFETY_ANALYSIS { |
| Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5521 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
| Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 5522 | if (load_kind == HLoadClass::LoadKind::kRuntimeCall) { |
| Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5523 | codegen_->GenerateLoadClassRuntimeCall(cls); |
| Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 5524 | return; |
| 5525 | } |
| Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5526 | DCHECK(!cls->NeedsAccessCheck()); |
| Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 5527 | |
| Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5528 | LocationSummary* locations = cls->GetLocations(); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5529 | Location out_loc = locations->Out(); |
| 5530 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5531 | |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 5532 | const ReadBarrierOption read_barrier_option = cls->IsInBootImage() |
| 5533 | ? kWithoutReadBarrier |
| 5534 | : kCompilerReadBarrierOption; |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5535 | bool generate_null_check = false; |
| Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5536 | switch (load_kind) { |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5537 | case HLoadClass::LoadKind::kReferrersClass: { |
| 5538 | DCHECK(!cls->CanCallRuntime()); |
| 5539 | DCHECK(!cls->MustGenerateClinitCheck()); |
| 5540 | // /* GcRoot<mirror::Class> */ out = current_method->declaring_class_ |
| 5541 | CpuRegister current_method = locations->InAt(0).AsRegister<CpuRegister>(); |
| 5542 | GenerateGcRootFieldLoad( |
| Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5543 | cls, |
| 5544 | out_loc, |
| 5545 | Address(current_method, ArtMethod::DeclaringClassOffset().Int32Value()), |
| Roland Levillain | 00468f3 | 2016-10-27 18:02:48 +0100 | [diff] [blame] | 5546 | /* fixup_label */ nullptr, |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 5547 | read_barrier_option); |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5548 | break; |
| 5549 | } |
| 5550 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: |
| Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5551 | DCHECK(codegen_->GetCompilerOptions().IsBootImage()); |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 5552 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5553 | __ leal(out, Address::Absolute(CodeGeneratorX86_64::kDummy32BitOffset, /* no_rip */ false)); |
| Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 5554 | codegen_->RecordBootTypePatch(cls); |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5555 | break; |
| 5556 | case HLoadClass::LoadKind::kBootImageAddress: { |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 5557 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
| Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 5558 | uint32_t address = dchecked_integral_cast<uint32_t>( |
| 5559 | reinterpret_cast<uintptr_t>(cls->GetClass().Get())); |
| 5560 | DCHECK_NE(address, 0u); |
| Colin Cross | 0bd9717 | 2017-03-15 16:33:27 -0700 | [diff] [blame] | 5561 | __ movl(out, Immediate(static_cast<int32_t>(address))); // Zero-extended. |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5562 | break; |
| 5563 | } |
| Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5564 | case HLoadClass::LoadKind::kBssEntry: { |
| 5565 | Address address = Address::Absolute(CodeGeneratorX86_64::kDummy32BitOffset, |
| 5566 | /* no_rip */ false); |
| 5567 | Label* fixup_label = codegen_->NewTypeBssEntryPatch(cls); |
| 5568 | // /* GcRoot<mirror::Class> */ out = *address /* PC-relative */ |
| 5569 | GenerateGcRootFieldLoad(cls, out_loc, address, fixup_label, read_barrier_option); |
| 5570 | generate_null_check = true; |
| 5571 | break; |
| 5572 | } |
| Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 5573 | case HLoadClass::LoadKind::kJitTableAddress: { |
| 5574 | Address address = Address::Absolute(CodeGeneratorX86_64::kDummy32BitOffset, |
| 5575 | /* no_rip */ true); |
| 5576 | Label* fixup_label = |
| Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 5577 | codegen_->NewJitRootClassPatch(cls->GetDexFile(), cls->GetTypeIndex(), cls->GetClass()); |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5578 | // /* GcRoot<mirror::Class> */ out = *address |
| Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 5579 | GenerateGcRootFieldLoad(cls, out_loc, address, fixup_label, read_barrier_option); |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5580 | break; |
| 5581 | } |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5582 | default: |
| 5583 | LOG(FATAL) << "Unexpected load kind: " << cls->GetLoadKind(); |
| 5584 | UNREACHABLE(); |
| 5585 | } |
| 5586 | |
| 5587 | if (generate_null_check || cls->MustGenerateClinitCheck()) { |
| 5588 | DCHECK(cls->CanCallRuntime()); |
| 5589 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathX86_64( |
| 5590 | cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck()); |
| 5591 | codegen_->AddSlowPath(slow_path); |
| 5592 | if (generate_null_check) { |
| 5593 | __ testl(out, out); |
| 5594 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 5595 | } |
| 5596 | if (cls->MustGenerateClinitCheck()) { |
| 5597 | GenerateClassInitializationCheck(slow_path, out); |
| 5598 | } else { |
| 5599 | __ Bind(slow_path->GetExitLabel()); |
| Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5600 | } |
| Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5601 | } |
| 5602 | } |
| 5603 | |
| 5604 | void LocationsBuilderX86_64::VisitClinitCheck(HClinitCheck* check) { |
| 5605 | LocationSummary* locations = |
| 5606 | new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath); |
| 5607 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5608 | if (check->HasUses()) { |
| 5609 | locations->SetOut(Location::SameAsFirstInput()); |
| 5610 | } |
| 5611 | } |
| 5612 | |
| 5613 | void InstructionCodeGeneratorX86_64::VisitClinitCheck(HClinitCheck* check) { |
| Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5614 | // We assume the class to not be null. |
| Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 5615 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathX86_64( |
| Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5616 | check->GetLoadClass(), check, check->GetDexPc(), true); |
| Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5617 | codegen_->AddSlowPath(slow_path); |
| Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 5618 | GenerateClassInitializationCheck(slow_path, |
| 5619 | check->GetLocations()->InAt(0).AsRegister<CpuRegister>()); |
| Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5620 | } |
| 5621 | |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5622 | HLoadString::LoadKind CodeGeneratorX86_64::GetSupportedLoadStringKind( |
| 5623 | HLoadString::LoadKind desired_string_load_kind) { |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5624 | switch (desired_string_load_kind) { |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5625 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: |
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5626 | case HLoadString::LoadKind::kBssEntry: |
| Calin Juravle | ffc8707 | 2016-04-20 14:22:09 +0100 | [diff] [blame] | 5627 | DCHECK(!Runtime::Current()->UseJitCompilation()); |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5628 | break; |
| Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 5629 | case HLoadString::LoadKind::kJitTableAddress: |
| 5630 | DCHECK(Runtime::Current()->UseJitCompilation()); |
| 5631 | break; |
| Vladimir Marko | 764d454 | 2017-05-16 10:31:41 +0100 | [diff] [blame] | 5632 | case HLoadString::LoadKind::kBootImageAddress: |
| Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 5633 | case HLoadString::LoadKind::kRuntimeCall: |
| Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5634 | break; |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5635 | } |
| 5636 | return desired_string_load_kind; |
| 5637 | } |
| 5638 | |
| Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5639 | void LocationsBuilderX86_64::VisitLoadString(HLoadString* load) { |
| Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 5640 | LocationSummary::CallKind call_kind = CodeGenerator::GetLoadStringCallKind(load); |
| Nicolas Geoffray | 917d016 | 2015-11-24 18:25:35 +0000 | [diff] [blame] | 5641 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(load, call_kind); |
| Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 5642 | if (load->GetLoadKind() == HLoadString::LoadKind::kRuntimeCall) { |
| Christina Wadsworth | abb341b | 2016-08-31 16:29:44 -0700 | [diff] [blame] | 5643 | locations->SetOut(Location::RegisterLocation(RAX)); |
| 5644 | } else { |
| 5645 | locations->SetOut(Location::RequiresRegister()); |
| Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 5646 | if (load->GetLoadKind() == HLoadString::LoadKind::kBssEntry) { |
| 5647 | if (!kUseReadBarrier || kUseBakerReadBarrier) { |
| Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 5648 | // Rely on the pResolveString to save everything. |
| Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 5649 | // Custom calling convention: RAX serves as both input and output. |
| 5650 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 5651 | caller_saves.Add(Location::RegisterLocation(RAX)); |
| 5652 | locations->SetCustomSlowPathCallerSaves(caller_saves); |
| 5653 | } else { |
| 5654 | // For non-Baker read barrier we have a temp-clobbering call. |
| 5655 | } |
| 5656 | } |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5657 | } |
| Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5658 | } |
| 5659 | |
| Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 5660 | Label* CodeGeneratorX86_64::NewJitRootStringPatch(const DexFile& dex_file, |
| Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 5661 | dex::StringIndex dex_index, |
| 5662 | Handle<mirror::String> handle) { |
| 5663 | jit_string_roots_.Overwrite( |
| 5664 | StringReference(&dex_file, dex_index), reinterpret_cast64<uint64_t>(handle.GetReference())); |
| Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 5665 | // Add a patch entry and return the label. |
| Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 5666 | jit_string_patches_.emplace_back(dex_file, dex_index.index_); |
| Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 5667 | PatchInfo<Label>* info = &jit_string_patches_.back(); |
| 5668 | return &info->label; |
| 5669 | } |
| 5670 | |
| Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 5671 | // NO_THREAD_SAFETY_ANALYSIS as we manipulate handles whose internal object we know does not |
| 5672 | // move. |
| 5673 | void InstructionCodeGeneratorX86_64::VisitLoadString(HLoadString* load) NO_THREAD_SAFETY_ANALYSIS { |
| Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 5674 | LocationSummary* locations = load->GetLocations(); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5675 | Location out_loc = locations->Out(); |
| 5676 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5677 | |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5678 | switch (load->GetLoadKind()) { |
| 5679 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: { |
| Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5680 | DCHECK(codegen_->GetCompilerOptions().IsBootImage()); |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5681 | __ leal(out, Address::Absolute(CodeGeneratorX86_64::kDummy32BitOffset, /* no_rip */ false)); |
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5682 | codegen_->RecordBootStringPatch(load); |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5683 | return; // No dex cache slow path. |
| 5684 | } |
| 5685 | case HLoadString::LoadKind::kBootImageAddress: { |
| Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 5686 | uint32_t address = dchecked_integral_cast<uint32_t>( |
| 5687 | reinterpret_cast<uintptr_t>(load->GetString().Get())); |
| 5688 | DCHECK_NE(address, 0u); |
| Colin Cross | 0bd9717 | 2017-03-15 16:33:27 -0700 | [diff] [blame] | 5689 | __ movl(out, Immediate(static_cast<int32_t>(address))); // Zero-extended. |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5690 | return; // No dex cache slow path. |
| 5691 | } |
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5692 | case HLoadString::LoadKind::kBssEntry: { |
| 5693 | Address address = Address::Absolute(CodeGeneratorX86_64::kDummy32BitOffset, |
| 5694 | /* no_rip */ false); |
| 5695 | Label* fixup_label = codegen_->NewStringBssEntryPatch(load); |
| 5696 | // /* GcRoot<mirror::Class> */ out = *address /* PC-relative */ |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 5697 | GenerateGcRootFieldLoad(load, out_loc, address, fixup_label, kCompilerReadBarrierOption); |
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5698 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) LoadStringSlowPathX86_64(load); |
| 5699 | codegen_->AddSlowPath(slow_path); |
| 5700 | __ testl(out, out); |
| 5701 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 5702 | __ Bind(slow_path->GetExitLabel()); |
| 5703 | return; |
| 5704 | } |
| Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 5705 | case HLoadString::LoadKind::kJitTableAddress: { |
| 5706 | Address address = Address::Absolute(CodeGeneratorX86_64::kDummy32BitOffset, |
| 5707 | /* no_rip */ true); |
| Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 5708 | Label* fixup_label = codegen_->NewJitRootStringPatch( |
| 5709 | load->GetDexFile(), load->GetStringIndex(), load->GetString()); |
| Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 5710 | // /* GcRoot<mirror::String> */ out = *address |
| 5711 | GenerateGcRootFieldLoad(load, out_loc, address, fixup_label, kCompilerReadBarrierOption); |
| 5712 | return; |
| 5713 | } |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5714 | default: |
| Christina Wadsworth | bf44e0e | 2016-08-18 10:37:42 -0700 | [diff] [blame] | 5715 | break; |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5716 | } |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5717 | |
| Christina Wadsworth | bf44e0e | 2016-08-18 10:37:42 -0700 | [diff] [blame] | 5718 | // 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] | 5719 | // Custom calling convention: RAX serves as both input and output. |
| Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 5720 | __ movl(CpuRegister(RAX), Immediate(load->GetStringIndex().index_)); |
| Christina Wadsworth | abb341b | 2016-08-31 16:29:44 -0700 | [diff] [blame] | 5721 | codegen_->InvokeRuntime(kQuickResolveString, |
| 5722 | load, |
| 5723 | load->GetDexPc()); |
| 5724 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
| Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5725 | } |
| 5726 | |
| David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 5727 | static Address GetExceptionTlsAddress() { |
| Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 5728 | return Address::Absolute(Thread::ExceptionOffset<kX86_64PointerSize>().Int32Value(), |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5729 | /* no_rip */ true); |
| David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 5730 | } |
| 5731 | |
| Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5732 | void LocationsBuilderX86_64::VisitLoadException(HLoadException* load) { |
| 5733 | LocationSummary* locations = |
| 5734 | new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall); |
| 5735 | locations->SetOut(Location::RequiresRegister()); |
| 5736 | } |
| 5737 | |
| 5738 | void InstructionCodeGeneratorX86_64::VisitLoadException(HLoadException* load) { |
| David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 5739 | __ gs()->movl(load->GetLocations()->Out().AsRegister<CpuRegister>(), GetExceptionTlsAddress()); |
| 5740 | } |
| 5741 | |
| 5742 | void LocationsBuilderX86_64::VisitClearException(HClearException* clear) { |
| 5743 | new (GetGraph()->GetArena()) LocationSummary(clear, LocationSummary::kNoCall); |
| 5744 | } |
| 5745 | |
| 5746 | void InstructionCodeGeneratorX86_64::VisitClearException(HClearException* clear ATTRIBUTE_UNUSED) { |
| 5747 | __ gs()->movl(GetExceptionTlsAddress(), Immediate(0)); |
| Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5748 | } |
| 5749 | |
| 5750 | void LocationsBuilderX86_64::VisitThrow(HThrow* instruction) { |
| 5751 | LocationSummary* locations = |
| Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 5752 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
| Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5753 | InvokeRuntimeCallingConvention calling_convention; |
| 5754 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 5755 | } |
| 5756 | |
| 5757 | void InstructionCodeGeneratorX86_64::VisitThrow(HThrow* instruction) { |
| Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 5758 | codegen_->InvokeRuntime(kQuickDeliverException, instruction, instruction->GetDexPc()); |
| Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 5759 | CheckEntrypointTypes<kQuickDeliverException, void, mirror::Object*>(); |
| Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5760 | } |
| 5761 | |
| Nicolas Geoffray | 53b07bd | 2016-11-05 15:09:19 +0000 | [diff] [blame] | 5762 | static bool CheckCastTypeCheckNeedsATemporary(TypeCheckKind type_check_kind) { |
| 5763 | if (type_check_kind == TypeCheckKind::kInterfaceCheck && !kPoisonHeapReferences) { |
| Mathieu Chartier | cdba73b | 2016-11-03 19:23:06 -0700 | [diff] [blame] | 5764 | // We need a temporary for holding the iftable length. |
| 5765 | return true; |
| 5766 | } |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5767 | return kEmitCompilerReadBarrier && |
| Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 5768 | !kUseBakerReadBarrier && |
| 5769 | (type_check_kind == TypeCheckKind::kAbstractClassCheck || |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5770 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 5771 | type_check_kind == TypeCheckKind::kArrayObjectCheck); |
| 5772 | } |
| 5773 | |
| Nicolas Geoffray | 53b07bd | 2016-11-05 15:09:19 +0000 | [diff] [blame] | 5774 | static bool InstanceOfTypeCheckNeedsATemporary(TypeCheckKind type_check_kind) { |
| 5775 | return kEmitCompilerReadBarrier && |
| 5776 | !kUseBakerReadBarrier && |
| 5777 | (type_check_kind == TypeCheckKind::kAbstractClassCheck || |
| 5778 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 5779 | type_check_kind == TypeCheckKind::kArrayObjectCheck); |
| 5780 | } |
| 5781 | |
| Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5782 | void LocationsBuilderX86_64::VisitInstanceOf(HInstanceOf* instruction) { |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5783 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5784 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5785 | bool baker_read_barrier_slow_path = false; |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5786 | switch (type_check_kind) { |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5787 | case TypeCheckKind::kExactCheck: |
| 5788 | case TypeCheckKind::kAbstractClassCheck: |
| 5789 | case TypeCheckKind::kClassHierarchyCheck: |
| 5790 | case TypeCheckKind::kArrayObjectCheck: |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5791 | call_kind = |
| 5792 | kEmitCompilerReadBarrier ? LocationSummary::kCallOnSlowPath : LocationSummary::kNoCall; |
| Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5793 | baker_read_barrier_slow_path = kUseBakerReadBarrier; |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5794 | break; |
| 5795 | case TypeCheckKind::kArrayCheck: |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5796 | case TypeCheckKind::kUnresolvedCheck: |
| 5797 | case TypeCheckKind::kInterfaceCheck: |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5798 | call_kind = LocationSummary::kCallOnSlowPath; |
| 5799 | break; |
| 5800 | } |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5801 | |
| Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5802 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
| Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5803 | if (baker_read_barrier_slow_path) { |
| Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 5804 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
| Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5805 | } |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5806 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5807 | locations->SetInAt(1, Location::Any()); |
| 5808 | // Note that TypeCheckSlowPathX86_64 uses this "out" register too. |
| 5809 | locations->SetOut(Location::RequiresRegister()); |
| 5810 | // When read barriers are enabled, we need a temporary register for |
| 5811 | // some cases. |
| Nicolas Geoffray | 53b07bd | 2016-11-05 15:09:19 +0000 | [diff] [blame] | 5812 | if (InstanceOfTypeCheckNeedsATemporary(type_check_kind)) { |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5813 | locations->AddTemp(Location::RequiresRegister()); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5814 | } |
| Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5815 | } |
| 5816 | |
| Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5817 | void InstructionCodeGeneratorX86_64::VisitInstanceOf(HInstanceOf* instruction) { |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5818 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5819 | LocationSummary* locations = instruction->GetLocations(); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5820 | Location obj_loc = locations->InAt(0); |
| 5821 | CpuRegister obj = obj_loc.AsRegister<CpuRegister>(); |
| Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5822 | Location cls = locations->InAt(1); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5823 | Location out_loc = locations->Out(); |
| 5824 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
| Nicolas Geoffray | 53b07bd | 2016-11-05 15:09:19 +0000 | [diff] [blame] | 5825 | Location maybe_temp_loc = InstanceOfTypeCheckNeedsATemporary(type_check_kind) ? |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5826 | locations->GetTemp(0) : |
| 5827 | Location::NoLocation(); |
| Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5828 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5829 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 5830 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 5831 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
| Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 5832 | SlowPathCode* slow_path = nullptr; |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5833 | NearLabel done, zero; |
| Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5834 | |
| 5835 | // Return 0 if `obj` is null. |
| Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 5836 | // Avoid null check if we know obj is not null. |
| 5837 | if (instruction->MustDoNullCheck()) { |
| 5838 | __ testl(obj, obj); |
| 5839 | __ j(kEqual, &zero); |
| 5840 | } |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5841 | |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5842 | switch (type_check_kind) { |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5843 | case TypeCheckKind::kExactCheck: { |
| Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 5844 | // /* HeapReference<Class> */ out = obj->klass_ |
| 5845 | GenerateReferenceLoadTwoRegisters(instruction, |
| 5846 | out_loc, |
| 5847 | obj_loc, |
| 5848 | class_offset, |
| 5849 | kCompilerReadBarrierOption); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5850 | if (cls.IsRegister()) { |
| 5851 | __ cmpl(out, cls.AsRegister<CpuRegister>()); |
| 5852 | } else { |
| 5853 | DCHECK(cls.IsStackSlot()) << cls; |
| 5854 | __ cmpl(out, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 5855 | } |
| Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 5856 | if (zero.IsLinked()) { |
| 5857 | // Classes must be equal for the instanceof to succeed. |
| 5858 | __ j(kNotEqual, &zero); |
| 5859 | __ movl(out, Immediate(1)); |
| 5860 | __ jmp(&done); |
| 5861 | } else { |
| 5862 | __ setcc(kEqual, out); |
| 5863 | // setcc only sets the low byte. |
| 5864 | __ andl(out, Immediate(1)); |
| 5865 | } |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5866 | break; |
| 5867 | } |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5868 | |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5869 | case TypeCheckKind::kAbstractClassCheck: { |
| Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 5870 | // /* HeapReference<Class> */ out = obj->klass_ |
| 5871 | GenerateReferenceLoadTwoRegisters(instruction, |
| 5872 | out_loc, |
| 5873 | obj_loc, |
| 5874 | class_offset, |
| 5875 | kCompilerReadBarrierOption); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5876 | // If the class is abstract, we eagerly fetch the super class of the |
| 5877 | // object to avoid doing a comparison we know will fail. |
| 5878 | NearLabel loop, success; |
| 5879 | __ Bind(&loop); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5880 | // /* HeapReference<Class> */ out = out->super_class_ |
| Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 5881 | GenerateReferenceLoadOneRegister(instruction, |
| 5882 | out_loc, |
| 5883 | super_offset, |
| 5884 | maybe_temp_loc, |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 5885 | kCompilerReadBarrierOption); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5886 | __ testl(out, out); |
| 5887 | // If `out` is null, we use it for the result, and jump to `done`. |
| 5888 | __ j(kEqual, &done); |
| 5889 | if (cls.IsRegister()) { |
| 5890 | __ cmpl(out, cls.AsRegister<CpuRegister>()); |
| 5891 | } else { |
| 5892 | DCHECK(cls.IsStackSlot()) << cls; |
| 5893 | __ cmpl(out, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 5894 | } |
| 5895 | __ j(kNotEqual, &loop); |
| 5896 | __ movl(out, Immediate(1)); |
| 5897 | if (zero.IsLinked()) { |
| 5898 | __ jmp(&done); |
| 5899 | } |
| 5900 | break; |
| 5901 | } |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5902 | |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5903 | case TypeCheckKind::kClassHierarchyCheck: { |
| Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 5904 | // /* HeapReference<Class> */ out = obj->klass_ |
| 5905 | GenerateReferenceLoadTwoRegisters(instruction, |
| 5906 | out_loc, |
| 5907 | obj_loc, |
| 5908 | class_offset, |
| 5909 | kCompilerReadBarrierOption); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5910 | // Walk over the class hierarchy to find a match. |
| 5911 | NearLabel loop, success; |
| 5912 | __ Bind(&loop); |
| 5913 | if (cls.IsRegister()) { |
| 5914 | __ cmpl(out, cls.AsRegister<CpuRegister>()); |
| 5915 | } else { |
| 5916 | DCHECK(cls.IsStackSlot()) << cls; |
| 5917 | __ cmpl(out, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 5918 | } |
| 5919 | __ j(kEqual, &success); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5920 | // /* HeapReference<Class> */ out = out->super_class_ |
| Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 5921 | GenerateReferenceLoadOneRegister(instruction, |
| 5922 | out_loc, |
| 5923 | super_offset, |
| 5924 | maybe_temp_loc, |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 5925 | kCompilerReadBarrierOption); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5926 | __ testl(out, out); |
| 5927 | __ j(kNotEqual, &loop); |
| 5928 | // If `out` is null, we use it for the result, and jump to `done`. |
| 5929 | __ jmp(&done); |
| 5930 | __ Bind(&success); |
| 5931 | __ movl(out, Immediate(1)); |
| 5932 | if (zero.IsLinked()) { |
| 5933 | __ jmp(&done); |
| 5934 | } |
| 5935 | break; |
| 5936 | } |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5937 | |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5938 | case TypeCheckKind::kArrayObjectCheck: { |
| Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 5939 | // /* HeapReference<Class> */ out = obj->klass_ |
| 5940 | GenerateReferenceLoadTwoRegisters(instruction, |
| 5941 | out_loc, |
| 5942 | obj_loc, |
| 5943 | class_offset, |
| 5944 | kCompilerReadBarrierOption); |
| Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 5945 | // Do an exact check. |
| 5946 | NearLabel exact_check; |
| 5947 | if (cls.IsRegister()) { |
| 5948 | __ cmpl(out, cls.AsRegister<CpuRegister>()); |
| 5949 | } else { |
| 5950 | DCHECK(cls.IsStackSlot()) << cls; |
| 5951 | __ cmpl(out, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 5952 | } |
| 5953 | __ j(kEqual, &exact_check); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5954 | // 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] | 5955 | // /* HeapReference<Class> */ out = out->component_type_ |
| Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 5956 | GenerateReferenceLoadOneRegister(instruction, |
| 5957 | out_loc, |
| 5958 | component_offset, |
| 5959 | maybe_temp_loc, |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 5960 | kCompilerReadBarrierOption); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5961 | __ testl(out, out); |
| 5962 | // If `out` is null, we use it for the result, and jump to `done`. |
| 5963 | __ j(kEqual, &done); |
| 5964 | __ cmpw(Address(out, primitive_offset), Immediate(Primitive::kPrimNot)); |
| 5965 | __ j(kNotEqual, &zero); |
| Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 5966 | __ Bind(&exact_check); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5967 | __ movl(out, Immediate(1)); |
| 5968 | __ jmp(&done); |
| 5969 | break; |
| 5970 | } |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5971 | |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5972 | case TypeCheckKind::kArrayCheck: { |
| Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 5973 | // No read barrier since the slow path will retry upon failure. |
| 5974 | // /* HeapReference<Class> */ out = obj->klass_ |
| 5975 | GenerateReferenceLoadTwoRegisters(instruction, |
| 5976 | out_loc, |
| 5977 | obj_loc, |
| 5978 | class_offset, |
| 5979 | kWithoutReadBarrier); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5980 | if (cls.IsRegister()) { |
| 5981 | __ cmpl(out, cls.AsRegister<CpuRegister>()); |
| 5982 | } else { |
| 5983 | DCHECK(cls.IsStackSlot()) << cls; |
| 5984 | __ cmpl(out, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 5985 | } |
| 5986 | DCHECK(locations->OnlyCallsOnSlowPath()); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5987 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathX86_64(instruction, |
| 5988 | /* is_fatal */ false); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5989 | codegen_->AddSlowPath(slow_path); |
| 5990 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 5991 | __ movl(out, Immediate(1)); |
| 5992 | if (zero.IsLinked()) { |
| 5993 | __ jmp(&done); |
| 5994 | } |
| 5995 | break; |
| 5996 | } |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5997 | |
| Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 5998 | case TypeCheckKind::kUnresolvedCheck: |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5999 | case TypeCheckKind::kInterfaceCheck: { |
| 6000 | // 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] | 6001 | // into the slow path for the unresolved and interface check |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6002 | // cases. |
| 6003 | // |
| 6004 | // We cannot directly call the InstanceofNonTrivial runtime |
| 6005 | // entry point without resorting to a type checking slow path |
| 6006 | // here (i.e. by calling InvokeRuntime directly), as it would |
| 6007 | // require to assign fixed registers for the inputs of this |
| 6008 | // HInstanceOf instruction (following the runtime calling |
| 6009 | // convention), which might be cluttered by the potential first |
| 6010 | // read barrier emission at the beginning of this method. |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6011 | // |
| 6012 | // TODO: Introduce a new runtime entry point taking the object |
| 6013 | // to test (instead of its class) as argument, and let it deal |
| 6014 | // with the read barrier issues. This will let us refactor this |
| 6015 | // case of the `switch` code as it was previously (with a direct |
| 6016 | // call to the runtime not using a type checking slow path). |
| 6017 | // This should also be beneficial for the other cases above. |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6018 | DCHECK(locations->OnlyCallsOnSlowPath()); |
| 6019 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathX86_64(instruction, |
| 6020 | /* is_fatal */ false); |
| 6021 | codegen_->AddSlowPath(slow_path); |
| 6022 | __ jmp(slow_path->GetEntryLabel()); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6023 | if (zero.IsLinked()) { |
| 6024 | __ jmp(&done); |
| 6025 | } |
| 6026 | break; |
| 6027 | } |
| Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6028 | } |
| Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6029 | |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6030 | if (zero.IsLinked()) { |
| Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6031 | __ Bind(&zero); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6032 | __ xorl(out, out); |
| 6033 | } |
| 6034 | |
| 6035 | if (done.IsLinked()) { |
| 6036 | __ Bind(&done); |
| Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6037 | } |
| 6038 | |
| Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6039 | if (slow_path != nullptr) { |
| 6040 | __ Bind(slow_path->GetExitLabel()); |
| 6041 | } |
| Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6042 | } |
| 6043 | |
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6044 | static bool IsTypeCheckSlowPathFatal(TypeCheckKind type_check_kind, bool throws_into_catch) { |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6045 | switch (type_check_kind) { |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6046 | case TypeCheckKind::kExactCheck: |
| 6047 | case TypeCheckKind::kAbstractClassCheck: |
| 6048 | case TypeCheckKind::kClassHierarchyCheck: |
| 6049 | case TypeCheckKind::kArrayObjectCheck: |
| Andreas Gampe | b5f3d81 | 2016-11-04 19:25:20 -0700 | [diff] [blame] | 6050 | return !throws_into_catch && !kEmitCompilerReadBarrier; |
| Nicolas Geoffray | 53b07bd | 2016-11-05 15:09:19 +0000 | [diff] [blame] | 6051 | case TypeCheckKind::kInterfaceCheck: |
| 6052 | return !throws_into_catch && !kEmitCompilerReadBarrier && !kPoisonHeapReferences; |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6053 | case TypeCheckKind::kArrayCheck: |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6054 | case TypeCheckKind::kUnresolvedCheck: |
| Andreas Gampe | b5f3d81 | 2016-11-04 19:25:20 -0700 | [diff] [blame] | 6055 | return false; |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6056 | } |
| Andreas Gampe | b5f3d81 | 2016-11-04 19:25:20 -0700 | [diff] [blame] | 6057 | LOG(FATAL) << "Unreachable"; |
| 6058 | UNREACHABLE(); |
| 6059 | } |
| 6060 | |
| 6061 | void LocationsBuilderX86_64::VisitCheckCast(HCheckCast* instruction) { |
| 6062 | bool throws_into_catch = instruction->CanThrowIntoCatchBlock(); |
| 6063 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| 6064 | bool is_fatal_slow_path = IsTypeCheckSlowPathFatal(type_check_kind, throws_into_catch); |
| 6065 | LocationSummary::CallKind call_kind = is_fatal_slow_path |
| 6066 | ? LocationSummary::kNoCall |
| 6067 | : LocationSummary::kCallOnSlowPath; |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6068 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
| 6069 | locations->SetInAt(0, Location::RequiresRegister()); |
| Mathieu Chartier | cdba73b | 2016-11-03 19:23:06 -0700 | [diff] [blame] | 6070 | if (type_check_kind == TypeCheckKind::kInterfaceCheck) { |
| 6071 | // Require a register for the interface check since there is a loop that compares the class to |
| 6072 | // a memory address. |
| 6073 | locations->SetInAt(1, Location::RequiresRegister()); |
| 6074 | } else { |
| 6075 | locations->SetInAt(1, Location::Any()); |
| 6076 | } |
| 6077 | |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6078 | // Note that TypeCheckSlowPathX86_64 uses this "temp" register too. |
| 6079 | locations->AddTemp(Location::RequiresRegister()); |
| 6080 | // When read barriers are enabled, we need an additional temporary |
| 6081 | // register for some cases. |
| Nicolas Geoffray | 53b07bd | 2016-11-05 15:09:19 +0000 | [diff] [blame] | 6082 | if (CheckCastTypeCheckNeedsATemporary(type_check_kind)) { |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6083 | locations->AddTemp(Location::RequiresRegister()); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6084 | } |
| Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6085 | } |
| 6086 | |
| 6087 | void InstructionCodeGeneratorX86_64::VisitCheckCast(HCheckCast* instruction) { |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6088 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6089 | LocationSummary* locations = instruction->GetLocations(); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6090 | Location obj_loc = locations->InAt(0); |
| 6091 | CpuRegister obj = obj_loc.AsRegister<CpuRegister>(); |
| Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6092 | Location cls = locations->InAt(1); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6093 | Location temp_loc = locations->GetTemp(0); |
| 6094 | CpuRegister temp = temp_loc.AsRegister<CpuRegister>(); |
| Nicolas Geoffray | 53b07bd | 2016-11-05 15:09:19 +0000 | [diff] [blame] | 6095 | Location maybe_temp2_loc = CheckCastTypeCheckNeedsATemporary(type_check_kind) ? |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6096 | locations->GetTemp(1) : |
| 6097 | Location::NoLocation(); |
| Mathieu Chartier | cdba73b | 2016-11-03 19:23:06 -0700 | [diff] [blame] | 6098 | const uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 6099 | const uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 6100 | const uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 6101 | const uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
| 6102 | const uint32_t iftable_offset = mirror::Class::IfTableOffset().Uint32Value(); |
| 6103 | const uint32_t array_length_offset = mirror::Array::LengthOffset().Uint32Value(); |
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6104 | const uint32_t object_array_data_offset = |
| 6105 | mirror::Array::DataOffset(kHeapReferenceSize).Uint32Value(); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6106 | |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6107 | // Always false for read barriers since we may need to go to the entrypoint for non-fatal cases |
| 6108 | // from false negatives. The false negatives may come from avoiding read barriers below. Avoiding |
| 6109 | // read barriers is done for performance and code size reasons. |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6110 | bool is_type_check_slow_path_fatal = |
| Andreas Gampe | b5f3d81 | 2016-11-04 19:25:20 -0700 | [diff] [blame] | 6111 | IsTypeCheckSlowPathFatal(type_check_kind, instruction->CanThrowIntoCatchBlock()); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6112 | SlowPathCode* type_check_slow_path = |
| 6113 | new (GetGraph()->GetArena()) TypeCheckSlowPathX86_64(instruction, |
| 6114 | is_type_check_slow_path_fatal); |
| 6115 | codegen_->AddSlowPath(type_check_slow_path); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6116 | |
| Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6117 | |
| 6118 | NearLabel done; |
| 6119 | // Avoid null check if we know obj is not null. |
| 6120 | if (instruction->MustDoNullCheck()) { |
| 6121 | __ testl(obj, obj); |
| 6122 | __ j(kEqual, &done); |
| 6123 | } |
| 6124 | |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6125 | switch (type_check_kind) { |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6126 | case TypeCheckKind::kExactCheck: |
| 6127 | case TypeCheckKind::kArrayCheck: { |
| Roland Levillain | 8650378 | 2016-02-11 19:07:30 +0000 | [diff] [blame] | 6128 | // /* HeapReference<Class> */ temp = obj->klass_ |
| Mathieu Chartier | cdba73b | 2016-11-03 19:23:06 -0700 | [diff] [blame] | 6129 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6130 | temp_loc, |
| 6131 | obj_loc, |
| 6132 | class_offset, |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6133 | kWithoutReadBarrier); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6134 | if (cls.IsRegister()) { |
| 6135 | __ cmpl(temp, cls.AsRegister<CpuRegister>()); |
| 6136 | } else { |
| 6137 | DCHECK(cls.IsStackSlot()) << cls; |
| 6138 | __ cmpl(temp, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 6139 | } |
| 6140 | // Jump to slow path for throwing the exception or doing a |
| 6141 | // more involved array check. |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6142 | __ j(kNotEqual, type_check_slow_path->GetEntryLabel()); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6143 | break; |
| 6144 | } |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6145 | |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6146 | case TypeCheckKind::kAbstractClassCheck: { |
| Roland Levillain | 8650378 | 2016-02-11 19:07:30 +0000 | [diff] [blame] | 6147 | // /* HeapReference<Class> */ temp = obj->klass_ |
| Mathieu Chartier | cdba73b | 2016-11-03 19:23:06 -0700 | [diff] [blame] | 6148 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6149 | temp_loc, |
| 6150 | obj_loc, |
| 6151 | class_offset, |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6152 | kWithoutReadBarrier); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6153 | // If the class is abstract, we eagerly fetch the super class of the |
| 6154 | // object to avoid doing a comparison we know will fail. |
| Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 6155 | NearLabel loop; |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6156 | __ Bind(&loop); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6157 | // /* HeapReference<Class> */ temp = temp->super_class_ |
| Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6158 | GenerateReferenceLoadOneRegister(instruction, |
| 6159 | temp_loc, |
| 6160 | super_offset, |
| 6161 | maybe_temp2_loc, |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6162 | kWithoutReadBarrier); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6163 | |
| Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 6164 | // If the class reference currently in `temp` is null, jump to the slow path to throw the |
| 6165 | // exception. |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6166 | __ testl(temp, temp); |
| Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 6167 | // Otherwise, compare the classes. |
| 6168 | __ j(kZero, type_check_slow_path->GetEntryLabel()); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6169 | if (cls.IsRegister()) { |
| 6170 | __ cmpl(temp, cls.AsRegister<CpuRegister>()); |
| 6171 | } else { |
| 6172 | DCHECK(cls.IsStackSlot()) << cls; |
| 6173 | __ cmpl(temp, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 6174 | } |
| 6175 | __ j(kNotEqual, &loop); |
| 6176 | break; |
| 6177 | } |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6178 | |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6179 | case TypeCheckKind::kClassHierarchyCheck: { |
| Roland Levillain | 8650378 | 2016-02-11 19:07:30 +0000 | [diff] [blame] | 6180 | // /* HeapReference<Class> */ temp = obj->klass_ |
| Mathieu Chartier | cdba73b | 2016-11-03 19:23:06 -0700 | [diff] [blame] | 6181 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6182 | temp_loc, |
| 6183 | obj_loc, |
| 6184 | class_offset, |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6185 | kWithoutReadBarrier); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6186 | // Walk over the class hierarchy to find a match. |
| Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6187 | NearLabel loop; |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6188 | __ Bind(&loop); |
| 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 | } |
| Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6195 | __ j(kEqual, &done); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6196 | |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6197 | // /* HeapReference<Class> */ temp = temp->super_class_ |
| Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6198 | GenerateReferenceLoadOneRegister(instruction, |
| 6199 | temp_loc, |
| 6200 | super_offset, |
| 6201 | maybe_temp2_loc, |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6202 | kWithoutReadBarrier); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6203 | |
| 6204 | // If the class reference currently in `temp` is not null, jump |
| 6205 | // back at the beginning of the loop. |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6206 | __ testl(temp, temp); |
| Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 6207 | __ j(kNotZero, &loop); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6208 | // Otherwise, jump to the slow path to throw the exception. |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6209 | __ jmp(type_check_slow_path->GetEntryLabel()); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6210 | break; |
| 6211 | } |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6212 | |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6213 | case TypeCheckKind::kArrayObjectCheck: { |
| Roland Levillain | 8650378 | 2016-02-11 19:07:30 +0000 | [diff] [blame] | 6214 | // /* HeapReference<Class> */ temp = obj->klass_ |
| Mathieu Chartier | cdba73b | 2016-11-03 19:23:06 -0700 | [diff] [blame] | 6215 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6216 | temp_loc, |
| 6217 | obj_loc, |
| 6218 | class_offset, |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6219 | kWithoutReadBarrier); |
| Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6220 | // Do an exact check. |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6221 | NearLabel check_non_primitive_component_type; |
| Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6222 | if (cls.IsRegister()) { |
| 6223 | __ cmpl(temp, cls.AsRegister<CpuRegister>()); |
| 6224 | } else { |
| 6225 | DCHECK(cls.IsStackSlot()) << cls; |
| 6226 | __ cmpl(temp, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 6227 | } |
| 6228 | __ j(kEqual, &done); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6229 | |
| 6230 | // 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] | 6231 | // /* HeapReference<Class> */ temp = temp->component_type_ |
| Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6232 | GenerateReferenceLoadOneRegister(instruction, |
| 6233 | temp_loc, |
| 6234 | component_offset, |
| 6235 | maybe_temp2_loc, |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6236 | kWithoutReadBarrier); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6237 | |
| 6238 | // If the component type is not null (i.e. the object is indeed |
| 6239 | // an array), jump to label `check_non_primitive_component_type` |
| 6240 | // to further check that this component type is not a primitive |
| 6241 | // type. |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6242 | __ testl(temp, temp); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6243 | // Otherwise, jump to the slow path to throw the exception. |
| Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 6244 | __ j(kZero, type_check_slow_path->GetEntryLabel()); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6245 | __ cmpw(Address(temp, primitive_offset), Immediate(Primitive::kPrimNot)); |
| Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 6246 | __ j(kNotEqual, type_check_slow_path->GetEntryLabel()); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6247 | break; |
| 6248 | } |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6249 | |
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6250 | case TypeCheckKind::kUnresolvedCheck: { |
| Mathieu Chartier | cdba73b | 2016-11-03 19:23:06 -0700 | [diff] [blame] | 6251 | // 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] | 6252 | // |
| 6253 | // We cannot directly call the CheckCast runtime entry point |
| 6254 | // without resorting to a type checking slow path here (i.e. by |
| 6255 | // calling InvokeRuntime directly), as it would require to |
| 6256 | // assign fixed registers for the inputs of this HInstanceOf |
| 6257 | // instruction (following the runtime calling convention), which |
| 6258 | // might be cluttered by the potential first read barrier |
| 6259 | // emission at the beginning of this method. |
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6260 | __ jmp(type_check_slow_path->GetEntryLabel()); |
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6261 | break; |
| 6262 | } |
| 6263 | |
| 6264 | case TypeCheckKind::kInterfaceCheck: |
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6265 | // Fast path for the interface check. We always go slow path for heap poisoning since |
| 6266 | // unpoisoning cls would require an extra temp. |
| 6267 | if (!kPoisonHeapReferences) { |
| Mathieu Chartier | cdba73b | 2016-11-03 19:23:06 -0700 | [diff] [blame] | 6268 | // Try to avoid read barriers to improve the fast path. We can not get false positives by |
| 6269 | // doing this. |
| 6270 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 6271 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6272 | temp_loc, |
| 6273 | obj_loc, |
| 6274 | class_offset, |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6275 | kWithoutReadBarrier); |
| Mathieu Chartier | cdba73b | 2016-11-03 19:23:06 -0700 | [diff] [blame] | 6276 | |
| 6277 | // /* HeapReference<Class> */ temp = temp->iftable_ |
| 6278 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6279 | temp_loc, |
| 6280 | temp_loc, |
| 6281 | iftable_offset, |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6282 | kWithoutReadBarrier); |
| Mathieu Chartier | 6beced4 | 2016-11-15 15:51:31 -0800 | [diff] [blame] | 6283 | // Iftable is never null. |
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6284 | __ movl(maybe_temp2_loc.AsRegister<CpuRegister>(), Address(temp, array_length_offset)); |
| Mathieu Chartier | 6beced4 | 2016-11-15 15:51:31 -0800 | [diff] [blame] | 6285 | // Loop through the iftable and check if any class matches. |
| Mathieu Chartier | cdba73b | 2016-11-03 19:23:06 -0700 | [diff] [blame] | 6286 | NearLabel start_loop; |
| 6287 | __ Bind(&start_loop); |
| Mathieu Chartier | 6beced4 | 2016-11-15 15:51:31 -0800 | [diff] [blame] | 6288 | // Need to subtract first to handle the empty array case. |
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6289 | __ subl(maybe_temp2_loc.AsRegister<CpuRegister>(), Immediate(2)); |
| Mathieu Chartier | 6beced4 | 2016-11-15 15:51:31 -0800 | [diff] [blame] | 6290 | __ j(kNegative, type_check_slow_path->GetEntryLabel()); |
| 6291 | // Go to next interface if the classes do not match. |
| 6292 | __ cmpl(cls.AsRegister<CpuRegister>(), |
| 6293 | CodeGeneratorX86_64::ArrayAddress(temp, |
| 6294 | maybe_temp2_loc, |
| 6295 | TIMES_4, |
| 6296 | object_array_data_offset)); |
| 6297 | __ j(kNotEqual, &start_loop); // Return if same class. |
| 6298 | } else { |
| 6299 | __ jmp(type_check_slow_path->GetEntryLabel()); |
| Mathieu Chartier | cdba73b | 2016-11-03 19:23:06 -0700 | [diff] [blame] | 6300 | } |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6301 | break; |
| 6302 | } |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6303 | |
| Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6304 | if (done.IsLinked()) { |
| 6305 | __ Bind(&done); |
| 6306 | } |
| 6307 | |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6308 | __ Bind(type_check_slow_path->GetExitLabel()); |
| Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6309 | } |
| 6310 | |
| Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6311 | void LocationsBuilderX86_64::VisitMonitorOperation(HMonitorOperation* instruction) { |
| 6312 | LocationSummary* locations = |
| Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 6313 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
| Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6314 | InvokeRuntimeCallingConvention calling_convention; |
| 6315 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 6316 | } |
| 6317 | |
| 6318 | void InstructionCodeGeneratorX86_64::VisitMonitorOperation(HMonitorOperation* instruction) { |
| Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 6319 | codegen_->InvokeRuntime(instruction->IsEnter() ? kQuickLockObject : kQuickUnlockObject, |
| Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 6320 | instruction, |
| Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 6321 | instruction->GetDexPc()); |
| Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 6322 | if (instruction->IsEnter()) { |
| 6323 | CheckEntrypointTypes<kQuickLockObject, void, mirror::Object*>(); |
| 6324 | } else { |
| 6325 | CheckEntrypointTypes<kQuickUnlockObject, void, mirror::Object*>(); |
| 6326 | } |
| Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6327 | } |
| 6328 | |
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6329 | void LocationsBuilderX86_64::VisitAnd(HAnd* instruction) { HandleBitwiseOperation(instruction); } |
| 6330 | void LocationsBuilderX86_64::VisitOr(HOr* instruction) { HandleBitwiseOperation(instruction); } |
| 6331 | void LocationsBuilderX86_64::VisitXor(HXor* instruction) { HandleBitwiseOperation(instruction); } |
| 6332 | |
| 6333 | void LocationsBuilderX86_64::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 6334 | LocationSummary* locations = |
| 6335 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 6336 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt |
| 6337 | || instruction->GetResultType() == Primitive::kPrimLong); |
| 6338 | locations->SetInAt(0, Location::RequiresRegister()); |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 6339 | locations->SetInAt(1, Location::Any()); |
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6340 | locations->SetOut(Location::SameAsFirstInput()); |
| 6341 | } |
| 6342 | |
| 6343 | void InstructionCodeGeneratorX86_64::VisitAnd(HAnd* instruction) { |
| 6344 | HandleBitwiseOperation(instruction); |
| 6345 | } |
| 6346 | |
| 6347 | void InstructionCodeGeneratorX86_64::VisitOr(HOr* instruction) { |
| 6348 | HandleBitwiseOperation(instruction); |
| 6349 | } |
| 6350 | |
| 6351 | void InstructionCodeGeneratorX86_64::VisitXor(HXor* instruction) { |
| 6352 | HandleBitwiseOperation(instruction); |
| 6353 | } |
| 6354 | |
| 6355 | void InstructionCodeGeneratorX86_64::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 6356 | LocationSummary* locations = instruction->GetLocations(); |
| 6357 | Location first = locations->InAt(0); |
| 6358 | Location second = locations->InAt(1); |
| 6359 | DCHECK(first.Equals(locations->Out())); |
| 6360 | |
| 6361 | if (instruction->GetResultType() == Primitive::kPrimInt) { |
| 6362 | if (second.IsRegister()) { |
| 6363 | if (instruction->IsAnd()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6364 | __ andl(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6365 | } else if (instruction->IsOr()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6366 | __ orl(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6367 | } else { |
| 6368 | DCHECK(instruction->IsXor()); |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6369 | __ xorl(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6370 | } |
| 6371 | } else if (second.IsConstant()) { |
| 6372 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue()); |
| 6373 | if (instruction->IsAnd()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6374 | __ andl(first.AsRegister<CpuRegister>(), imm); |
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6375 | } else if (instruction->IsOr()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6376 | __ orl(first.AsRegister<CpuRegister>(), imm); |
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6377 | } else { |
| 6378 | DCHECK(instruction->IsXor()); |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6379 | __ xorl(first.AsRegister<CpuRegister>(), imm); |
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6380 | } |
| 6381 | } else { |
| 6382 | Address address(CpuRegister(RSP), second.GetStackIndex()); |
| 6383 | if (instruction->IsAnd()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6384 | __ andl(first.AsRegister<CpuRegister>(), address); |
| 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>(), address); |
| 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>(), address); |
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6390 | } |
| 6391 | } |
| 6392 | } else { |
| 6393 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong); |
| Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6394 | CpuRegister first_reg = first.AsRegister<CpuRegister>(); |
| 6395 | bool second_is_constant = false; |
| 6396 | int64_t value = 0; |
| 6397 | if (second.IsConstant()) { |
| 6398 | second_is_constant = true; |
| 6399 | value = second.GetConstant()->AsLongConstant()->GetValue(); |
| Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6400 | } |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 6401 | bool is_int32_value = IsInt<32>(value); |
| Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6402 | |
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6403 | if (instruction->IsAnd()) { |
| Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6404 | if (second_is_constant) { |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 6405 | if (is_int32_value) { |
| 6406 | __ andq(first_reg, Immediate(static_cast<int32_t>(value))); |
| 6407 | } else { |
| 6408 | __ andq(first_reg, codegen_->LiteralInt64Address(value)); |
| 6409 | } |
| 6410 | } else if (second.IsDoubleStackSlot()) { |
| 6411 | __ andq(first_reg, Address(CpuRegister(RSP), second.GetStackIndex())); |
| Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6412 | } else { |
| 6413 | __ andq(first_reg, second.AsRegister<CpuRegister>()); |
| 6414 | } |
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6415 | } else if (instruction->IsOr()) { |
| Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6416 | if (second_is_constant) { |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 6417 | if (is_int32_value) { |
| 6418 | __ orq(first_reg, Immediate(static_cast<int32_t>(value))); |
| 6419 | } else { |
| 6420 | __ orq(first_reg, codegen_->LiteralInt64Address(value)); |
| 6421 | } |
| 6422 | } else if (second.IsDoubleStackSlot()) { |
| 6423 | __ orq(first_reg, Address(CpuRegister(RSP), second.GetStackIndex())); |
| Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6424 | } else { |
| 6425 | __ orq(first_reg, second.AsRegister<CpuRegister>()); |
| 6426 | } |
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6427 | } else { |
| 6428 | DCHECK(instruction->IsXor()); |
| Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6429 | if (second_is_constant) { |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 6430 | if (is_int32_value) { |
| 6431 | __ xorq(first_reg, Immediate(static_cast<int32_t>(value))); |
| 6432 | } else { |
| 6433 | __ xorq(first_reg, codegen_->LiteralInt64Address(value)); |
| 6434 | } |
| 6435 | } else if (second.IsDoubleStackSlot()) { |
| 6436 | __ xorq(first_reg, Address(CpuRegister(RSP), second.GetStackIndex())); |
| Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6437 | } else { |
| 6438 | __ xorq(first_reg, second.AsRegister<CpuRegister>()); |
| 6439 | } |
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6440 | } |
| 6441 | } |
| 6442 | } |
| 6443 | |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6444 | void InstructionCodeGeneratorX86_64::GenerateReferenceLoadOneRegister( |
| 6445 | HInstruction* instruction, |
| 6446 | Location out, |
| 6447 | uint32_t offset, |
| 6448 | Location maybe_temp, |
| 6449 | ReadBarrierOption read_barrier_option) { |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6450 | CpuRegister out_reg = out.AsRegister<CpuRegister>(); |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6451 | if (read_barrier_option == kWithReadBarrier) { |
| Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6452 | CHECK(kEmitCompilerReadBarrier); |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6453 | if (kUseBakerReadBarrier) { |
| 6454 | // Load with fast path based Baker's read barrier. |
| 6455 | // /* HeapReference<Object> */ out = *(out + offset) |
| 6456 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
| Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 6457 | instruction, out, out_reg, offset, /* needs_null_check */ false); |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6458 | } else { |
| 6459 | // Load with slow path based read barrier. |
| Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6460 | // Save the value of `out` into `maybe_temp` before overwriting it |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6461 | // in the following move operation, as we will need it for the |
| 6462 | // read barrier below. |
| Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 6463 | DCHECK(maybe_temp.IsRegister()) << maybe_temp; |
| Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6464 | __ movl(maybe_temp.AsRegister<CpuRegister>(), out_reg); |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6465 | // /* HeapReference<Object> */ out = *(out + offset) |
| 6466 | __ movl(out_reg, Address(out_reg, offset)); |
| Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6467 | codegen_->GenerateReadBarrierSlow(instruction, out, out, maybe_temp, offset); |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6468 | } |
| 6469 | } else { |
| 6470 | // Plain load with no read barrier. |
| 6471 | // /* HeapReference<Object> */ out = *(out + offset) |
| 6472 | __ movl(out_reg, Address(out_reg, offset)); |
| 6473 | __ MaybeUnpoisonHeapReference(out_reg); |
| 6474 | } |
| 6475 | } |
| 6476 | |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6477 | void InstructionCodeGeneratorX86_64::GenerateReferenceLoadTwoRegisters( |
| 6478 | HInstruction* instruction, |
| 6479 | Location out, |
| 6480 | Location obj, |
| 6481 | uint32_t offset, |
| 6482 | ReadBarrierOption read_barrier_option) { |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6483 | CpuRegister out_reg = out.AsRegister<CpuRegister>(); |
| 6484 | CpuRegister obj_reg = obj.AsRegister<CpuRegister>(); |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6485 | if (read_barrier_option == kWithReadBarrier) { |
| Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6486 | CHECK(kEmitCompilerReadBarrier); |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6487 | if (kUseBakerReadBarrier) { |
| 6488 | // Load with fast path based Baker's read barrier. |
| 6489 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 6490 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
| Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 6491 | instruction, out, obj_reg, offset, /* needs_null_check */ false); |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6492 | } else { |
| 6493 | // Load with slow path based read barrier. |
| 6494 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 6495 | __ movl(out_reg, Address(obj_reg, offset)); |
| 6496 | codegen_->GenerateReadBarrierSlow(instruction, out, out, obj, offset); |
| 6497 | } |
| 6498 | } else { |
| 6499 | // Plain load with no read barrier. |
| 6500 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 6501 | __ movl(out_reg, Address(obj_reg, offset)); |
| 6502 | __ MaybeUnpoisonHeapReference(out_reg); |
| 6503 | } |
| 6504 | } |
| 6505 | |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6506 | void InstructionCodeGeneratorX86_64::GenerateGcRootFieldLoad( |
| 6507 | HInstruction* instruction, |
| 6508 | Location root, |
| 6509 | const Address& address, |
| 6510 | Label* fixup_label, |
| 6511 | ReadBarrierOption read_barrier_option) { |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6512 | CpuRegister root_reg = root.AsRegister<CpuRegister>(); |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6513 | if (read_barrier_option == kWithReadBarrier) { |
| Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 6514 | DCHECK(kEmitCompilerReadBarrier); |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6515 | if (kUseBakerReadBarrier) { |
| 6516 | // Fast path implementation of art::ReadBarrier::BarrierForRoot when |
| 6517 | // Baker's read barrier are used: |
| 6518 | // |
| Roland Levillain | d966ce7 | 2017-02-09 16:20:14 +0000 | [diff] [blame] | 6519 | // root = obj.field; |
| 6520 | // temp = Thread::Current()->pReadBarrierMarkReg ## root.reg() |
| 6521 | // if (temp != null) { |
| 6522 | // root = temp(root) |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6523 | // } |
| 6524 | |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6525 | // /* GcRoot<mirror::Object> */ root = *address |
| 6526 | __ movl(root_reg, address); |
| 6527 | if (fixup_label != nullptr) { |
| 6528 | __ Bind(fixup_label); |
| 6529 | } |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6530 | static_assert( |
| 6531 | sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(GcRoot<mirror::Object>), |
| 6532 | "art::mirror::CompressedReference<mirror::Object> and art::GcRoot<mirror::Object> " |
| 6533 | "have different sizes."); |
| 6534 | static_assert(sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(int32_t), |
| 6535 | "art::mirror::CompressedReference<mirror::Object> and int32_t " |
| 6536 | "have different sizes."); |
| 6537 | |
| Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 6538 | // Slow path marking the GC root `root`. |
| 6539 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) ReadBarrierMarkSlowPathX86_64( |
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 6540 | instruction, root, /* unpoison_ref_before_marking */ false); |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6541 | codegen_->AddSlowPath(slow_path); |
| 6542 | |
| Roland Levillain | d966ce7 | 2017-02-09 16:20:14 +0000 | [diff] [blame] | 6543 | // Test the `Thread::Current()->pReadBarrierMarkReg ## root.reg()` entrypoint. |
| 6544 | const int32_t entry_point_offset = |
| 6545 | CodeGenerator::GetReadBarrierMarkEntryPointsOffset<kX86_64PointerSize>(root.reg()); |
| 6546 | __ gs()->cmpl(Address::Absolute(entry_point_offset, /* no_rip */ true), Immediate(0)); |
| 6547 | // The entrypoint is null when the GC is not marking. |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6548 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 6549 | __ Bind(slow_path->GetExitLabel()); |
| 6550 | } else { |
| 6551 | // GC root loaded through a slow path for read barriers other |
| 6552 | // than Baker's. |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6553 | // /* GcRoot<mirror::Object>* */ root = address |
| 6554 | __ leaq(root_reg, address); |
| 6555 | if (fixup_label != nullptr) { |
| 6556 | __ Bind(fixup_label); |
| 6557 | } |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6558 | // /* mirror::Object* */ root = root->Read() |
| 6559 | codegen_->GenerateReadBarrierForRootSlow(instruction, root, root); |
| 6560 | } |
| 6561 | } else { |
| 6562 | // Plain GC root load with no read barrier. |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6563 | // /* GcRoot<mirror::Object> */ root = *address |
| 6564 | __ movl(root_reg, address); |
| 6565 | if (fixup_label != nullptr) { |
| 6566 | __ Bind(fixup_label); |
| 6567 | } |
| Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 6568 | // Note that GC roots are not affected by heap poisoning, thus we |
| 6569 | // do not have to unpoison `root_reg` here. |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6570 | } |
| 6571 | } |
| 6572 | |
| 6573 | void CodeGeneratorX86_64::GenerateFieldLoadWithBakerReadBarrier(HInstruction* instruction, |
| 6574 | Location ref, |
| 6575 | CpuRegister obj, |
| 6576 | uint32_t offset, |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6577 | bool needs_null_check) { |
| 6578 | DCHECK(kEmitCompilerReadBarrier); |
| 6579 | DCHECK(kUseBakerReadBarrier); |
| 6580 | |
| 6581 | // /* HeapReference<Object> */ ref = *(obj + offset) |
| 6582 | Address src(obj, offset); |
| Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 6583 | GenerateReferenceLoadWithBakerReadBarrier(instruction, ref, obj, src, needs_null_check); |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6584 | } |
| 6585 | |
| 6586 | void CodeGeneratorX86_64::GenerateArrayLoadWithBakerReadBarrier(HInstruction* instruction, |
| 6587 | Location ref, |
| 6588 | CpuRegister obj, |
| 6589 | uint32_t data_offset, |
| 6590 | Location index, |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6591 | bool needs_null_check) { |
| 6592 | DCHECK(kEmitCompilerReadBarrier); |
| 6593 | DCHECK(kUseBakerReadBarrier); |
| 6594 | |
| Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 6595 | static_assert( |
| 6596 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 6597 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6598 | // /* HeapReference<Object> */ ref = |
| 6599 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 6600 | Address src = CodeGeneratorX86_64::ArrayAddress(obj, index, TIMES_4, data_offset); |
| Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 6601 | GenerateReferenceLoadWithBakerReadBarrier(instruction, ref, obj, src, needs_null_check); |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6602 | } |
| 6603 | |
| 6604 | void CodeGeneratorX86_64::GenerateReferenceLoadWithBakerReadBarrier(HInstruction* instruction, |
| 6605 | Location ref, |
| 6606 | CpuRegister obj, |
| 6607 | const Address& src, |
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 6608 | bool needs_null_check, |
| 6609 | bool always_update_field, |
| 6610 | CpuRegister* temp1, |
| 6611 | CpuRegister* temp2) { |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6612 | DCHECK(kEmitCompilerReadBarrier); |
| 6613 | DCHECK(kUseBakerReadBarrier); |
| 6614 | |
| 6615 | // In slow path based read barriers, the read barrier call is |
| 6616 | // inserted after the original load. However, in fast path based |
| 6617 | // Baker's read barriers, we need to perform the load of |
| 6618 | // mirror::Object::monitor_ *before* the original reference load. |
| 6619 | // This load-load ordering is required by the read barrier. |
| 6620 | // The fast path/slow path (for Baker's algorithm) should look like: |
| 6621 | // |
| 6622 | // uint32_t rb_state = Lockword(obj->monitor_).ReadBarrierState(); |
| 6623 | // lfence; // Load fence or artificial data dependency to prevent load-load reordering |
| 6624 | // HeapReference<Object> ref = *src; // Original reference load. |
| Hiroshi Yamauchi | 12b58b2 | 2016-11-01 11:55:29 -0700 | [diff] [blame] | 6625 | // bool is_gray = (rb_state == ReadBarrier::GrayState()); |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6626 | // if (is_gray) { |
| 6627 | // ref = ReadBarrier::Mark(ref); // Performed by runtime entrypoint slow path. |
| 6628 | // } |
| 6629 | // |
| 6630 | // Note: the original implementation in ReadBarrier::Barrier is |
| 6631 | // slightly more complex as: |
| 6632 | // - it implements the load-load fence using a data dependency on |
| Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 6633 | // the high-bits of rb_state, which are expected to be all zeroes |
| 6634 | // (we use CodeGeneratorX86_64::GenerateMemoryBarrier instead |
| 6635 | // 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] | 6636 | // - it performs additional checks that we do not do here for |
| 6637 | // performance reasons. |
| 6638 | |
| 6639 | CpuRegister ref_reg = ref.AsRegister<CpuRegister>(); |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6640 | uint32_t monitor_offset = mirror::Object::MonitorOffset().Int32Value(); |
| 6641 | |
| Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 6642 | // 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] | 6643 | static_assert(ReadBarrier::WhiteState() == 0, "Expecting white to have value 0"); |
| 6644 | static_assert(ReadBarrier::GrayState() == 1, "Expecting gray to have value 1"); |
| Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 6645 | constexpr uint32_t gray_byte_position = LockWord::kReadBarrierStateShift / kBitsPerByte; |
| 6646 | constexpr uint32_t gray_bit_position = LockWord::kReadBarrierStateShift % kBitsPerByte; |
| 6647 | constexpr int32_t test_value = static_cast<int8_t>(1 << gray_bit_position); |
| 6648 | |
| Hiroshi Yamauchi | 12b58b2 | 2016-11-01 11:55:29 -0700 | [diff] [blame] | 6649 | // if (rb_state == ReadBarrier::GrayState()) |
| Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 6650 | // ref = ReadBarrier::Mark(ref); |
| 6651 | // At this point, just do the "if" and make sure that flags are preserved until the branch. |
| 6652 | __ testb(Address(obj, monitor_offset + gray_byte_position), Immediate(test_value)); |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6653 | if (needs_null_check) { |
| 6654 | MaybeRecordImplicitNullCheck(instruction); |
| 6655 | } |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6656 | |
| 6657 | // Load fence to prevent load-load reordering. |
| 6658 | // Note that this is a no-op, thanks to the x86-64 memory model. |
| 6659 | GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 6660 | |
| 6661 | // The actual reference load. |
| 6662 | // /* HeapReference<Object> */ ref = *src |
| Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 6663 | __ movl(ref_reg, src); // Flags are unaffected. |
| 6664 | |
| 6665 | // Note: Reference unpoisoning modifies the flags, so we need to delay it after the branch. |
| 6666 | // Slow path marking the object `ref` when it is gray. |
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 6667 | SlowPathCode* slow_path; |
| 6668 | if (always_update_field) { |
| 6669 | DCHECK(temp1 != nullptr); |
| 6670 | DCHECK(temp2 != nullptr); |
| 6671 | slow_path = new (GetGraph()->GetArena()) ReadBarrierMarkAndUpdateFieldSlowPathX86_64( |
| 6672 | instruction, ref, obj, src, /* unpoison_ref_before_marking */ true, *temp1, *temp2); |
| 6673 | } else { |
| 6674 | slow_path = new (GetGraph()->GetArena()) ReadBarrierMarkSlowPathX86_64( |
| 6675 | instruction, ref, /* unpoison_ref_before_marking */ true); |
| 6676 | } |
| Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 6677 | AddSlowPath(slow_path); |
| 6678 | |
| 6679 | // We have done the "if" of the gray bit check above, now branch based on the flags. |
| 6680 | __ j(kNotZero, slow_path->GetEntryLabel()); |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6681 | |
| 6682 | // Object* ref = ref_addr->AsMirrorPtr() |
| 6683 | __ MaybeUnpoisonHeapReference(ref_reg); |
| 6684 | |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6685 | __ Bind(slow_path->GetExitLabel()); |
| 6686 | } |
| 6687 | |
| 6688 | void CodeGeneratorX86_64::GenerateReadBarrierSlow(HInstruction* instruction, |
| 6689 | Location out, |
| 6690 | Location ref, |
| 6691 | Location obj, |
| 6692 | uint32_t offset, |
| 6693 | Location index) { |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6694 | DCHECK(kEmitCompilerReadBarrier); |
| 6695 | |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6696 | // Insert a slow path based read barrier *after* the reference load. |
| 6697 | // |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6698 | // If heap poisoning is enabled, the unpoisoning of the loaded |
| 6699 | // reference will be carried out by the runtime within the slow |
| 6700 | // path. |
| 6701 | // |
| 6702 | // Note that `ref` currently does not get unpoisoned (when heap |
| 6703 | // poisoning is enabled), which is alright as the `ref` argument is |
| 6704 | // not used by the artReadBarrierSlow entry point. |
| 6705 | // |
| 6706 | // TODO: Unpoison `ref` when it is used by artReadBarrierSlow. |
| 6707 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) |
| 6708 | ReadBarrierForHeapReferenceSlowPathX86_64(instruction, out, ref, obj, offset, index); |
| 6709 | AddSlowPath(slow_path); |
| 6710 | |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6711 | __ jmp(slow_path->GetEntryLabel()); |
| 6712 | __ Bind(slow_path->GetExitLabel()); |
| 6713 | } |
| 6714 | |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6715 | void CodeGeneratorX86_64::MaybeGenerateReadBarrierSlow(HInstruction* instruction, |
| 6716 | Location out, |
| 6717 | Location ref, |
| 6718 | Location obj, |
| 6719 | uint32_t offset, |
| 6720 | Location index) { |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6721 | if (kEmitCompilerReadBarrier) { |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6722 | // Baker's read barriers shall be handled by the fast path |
| 6723 | // (CodeGeneratorX86_64::GenerateReferenceLoadWithBakerReadBarrier). |
| 6724 | DCHECK(!kUseBakerReadBarrier); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6725 | // If heap poisoning is enabled, unpoisoning will be taken care of |
| 6726 | // by the runtime within the slow path. |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6727 | GenerateReadBarrierSlow(instruction, out, ref, obj, offset, index); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6728 | } else if (kPoisonHeapReferences) { |
| 6729 | __ UnpoisonHeapReference(out.AsRegister<CpuRegister>()); |
| 6730 | } |
| 6731 | } |
| 6732 | |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6733 | void CodeGeneratorX86_64::GenerateReadBarrierForRootSlow(HInstruction* instruction, |
| 6734 | Location out, |
| 6735 | Location root) { |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6736 | DCHECK(kEmitCompilerReadBarrier); |
| 6737 | |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6738 | // Insert a slow path based read barrier *after* the GC root load. |
| 6739 | // |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6740 | // Note that GC roots are not affected by heap poisoning, so we do |
| 6741 | // not need to do anything special for this here. |
| 6742 | SlowPathCode* slow_path = |
| 6743 | new (GetGraph()->GetArena()) ReadBarrierForRootSlowPathX86_64(instruction, out, root); |
| 6744 | AddSlowPath(slow_path); |
| 6745 | |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6746 | __ jmp(slow_path->GetEntryLabel()); |
| 6747 | __ Bind(slow_path->GetExitLabel()); |
| 6748 | } |
| 6749 | |
| Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 6750 | void LocationsBuilderX86_64::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
| Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6751 | // Nothing to do, this should be removed during prepare for register allocator. |
| Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6752 | LOG(FATAL) << "Unreachable"; |
| 6753 | } |
| 6754 | |
| Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 6755 | void InstructionCodeGeneratorX86_64::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
| Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6756 | // Nothing to do, this should be removed during prepare for register allocator. |
| Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6757 | LOG(FATAL) << "Unreachable"; |
| 6758 | } |
| 6759 | |
| Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6760 | // Simple implementation of packed switch - generate cascaded compare/jumps. |
| 6761 | void LocationsBuilderX86_64::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 6762 | LocationSummary* locations = |
| 6763 | new (GetGraph()->GetArena()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
| 6764 | locations->SetInAt(0, Location::RequiresRegister()); |
| Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 6765 | locations->AddTemp(Location::RequiresRegister()); |
| 6766 | locations->AddTemp(Location::RequiresRegister()); |
| Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6767 | } |
| 6768 | |
| 6769 | void InstructionCodeGeneratorX86_64::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 6770 | int32_t lower_bound = switch_instr->GetStartValue(); |
| Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 6771 | uint32_t num_entries = switch_instr->GetNumEntries(); |
| Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6772 | LocationSummary* locations = switch_instr->GetLocations(); |
| Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 6773 | CpuRegister value_reg_in = locations->InAt(0).AsRegister<CpuRegister>(); |
| 6774 | CpuRegister temp_reg = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 6775 | CpuRegister base_reg = locations->GetTemp(1).AsRegister<CpuRegister>(); |
| Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 6776 | HBasicBlock* default_block = switch_instr->GetDefaultBlock(); |
| 6777 | |
| 6778 | // Should we generate smaller inline compare/jumps? |
| 6779 | if (num_entries <= kPackedSwitchJumpTableThreshold) { |
| 6780 | // Figure out the correct compare values and jump conditions. |
| 6781 | // Handle the first compare/branch as a special case because it might |
| 6782 | // jump to the default case. |
| 6783 | DCHECK_GT(num_entries, 2u); |
| 6784 | Condition first_condition; |
| 6785 | uint32_t index; |
| 6786 | const ArenaVector<HBasicBlock*>& successors = switch_instr->GetBlock()->GetSuccessors(); |
| 6787 | if (lower_bound != 0) { |
| 6788 | first_condition = kLess; |
| 6789 | __ cmpl(value_reg_in, Immediate(lower_bound)); |
| 6790 | __ j(first_condition, codegen_->GetLabelOf(default_block)); |
| 6791 | __ j(kEqual, codegen_->GetLabelOf(successors[0])); |
| 6792 | |
| 6793 | index = 1; |
| 6794 | } else { |
| 6795 | // Handle all the compare/jumps below. |
| 6796 | first_condition = kBelow; |
| 6797 | index = 0; |
| 6798 | } |
| 6799 | |
| 6800 | // Handle the rest of the compare/jumps. |
| 6801 | for (; index + 1 < num_entries; index += 2) { |
| 6802 | int32_t compare_to_value = lower_bound + index + 1; |
| 6803 | __ cmpl(value_reg_in, Immediate(compare_to_value)); |
| 6804 | // Jump to successors[index] if value < case_value[index]. |
| 6805 | __ j(first_condition, codegen_->GetLabelOf(successors[index])); |
| 6806 | // Jump to successors[index + 1] if value == case_value[index + 1]. |
| 6807 | __ j(kEqual, codegen_->GetLabelOf(successors[index + 1])); |
| 6808 | } |
| 6809 | |
| 6810 | if (index != num_entries) { |
| 6811 | // There are an odd number of entries. Handle the last one. |
| 6812 | DCHECK_EQ(index + 1, num_entries); |
| Nicolas Geoffray | 6ce0173 | 2015-12-30 14:10:13 +0000 | [diff] [blame] | 6813 | __ cmpl(value_reg_in, Immediate(static_cast<int32_t>(lower_bound + index))); |
| Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 6814 | __ j(kEqual, codegen_->GetLabelOf(successors[index])); |
| 6815 | } |
| 6816 | |
| 6817 | // And the default for any other value. |
| 6818 | if (!codegen_->GoesToNextBlock(switch_instr->GetBlock(), default_block)) { |
| 6819 | __ jmp(codegen_->GetLabelOf(default_block)); |
| 6820 | } |
| 6821 | return; |
| 6822 | } |
| Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 6823 | |
| 6824 | // Remove the bias, if needed. |
| 6825 | Register value_reg_out = value_reg_in.AsRegister(); |
| 6826 | if (lower_bound != 0) { |
| 6827 | __ leal(temp_reg, Address(value_reg_in, -lower_bound)); |
| 6828 | value_reg_out = temp_reg.AsRegister(); |
| 6829 | } |
| 6830 | CpuRegister value_reg(value_reg_out); |
| 6831 | |
| 6832 | // Is the value in range? |
| Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 6833 | __ cmpl(value_reg, Immediate(num_entries - 1)); |
| 6834 | __ j(kAbove, codegen_->GetLabelOf(default_block)); |
| Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6835 | |
| Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 6836 | // We are in the range of the table. |
| 6837 | // Load the address of the jump table in the constant area. |
| 6838 | __ leaq(base_reg, codegen_->LiteralCaseTable(switch_instr)); |
| Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6839 | |
| Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 6840 | // Load the (signed) offset from the jump table. |
| 6841 | __ movsxd(temp_reg, Address(base_reg, value_reg, TIMES_4, 0)); |
| 6842 | |
| 6843 | // Add the offset to the address of the table base. |
| 6844 | __ addq(temp_reg, base_reg); |
| 6845 | |
| 6846 | // And jump. |
| 6847 | __ jmp(temp_reg); |
| Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6848 | } |
| 6849 | |
| Aart Bik | c5d4754 | 2016-01-27 17:00:35 -0800 | [diff] [blame] | 6850 | void CodeGeneratorX86_64::Load32BitValue(CpuRegister dest, int32_t value) { |
| 6851 | if (value == 0) { |
| 6852 | __ xorl(dest, dest); |
| 6853 | } else { |
| 6854 | __ movl(dest, Immediate(value)); |
| 6855 | } |
| 6856 | } |
| 6857 | |
| Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 6858 | void CodeGeneratorX86_64::Load64BitValue(CpuRegister dest, int64_t value) { |
| 6859 | if (value == 0) { |
| Aart Bik | c5d4754 | 2016-01-27 17:00:35 -0800 | [diff] [blame] | 6860 | // Clears upper bits too. |
| Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 6861 | __ xorl(dest, dest); |
| Vladimir Marko | ed00978 | 2016-02-22 16:54:39 +0000 | [diff] [blame] | 6862 | } else if (IsUint<32>(value)) { |
| 6863 | // 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] | 6864 | __ movl(dest, Immediate(static_cast<int32_t>(value))); |
| 6865 | } else { |
| 6866 | __ movq(dest, Immediate(value)); |
| 6867 | } |
| 6868 | } |
| 6869 | |
| Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 6870 | void CodeGeneratorX86_64::Load32BitValue(XmmRegister dest, int32_t value) { |
| 6871 | if (value == 0) { |
| 6872 | __ xorps(dest, dest); |
| 6873 | } else { |
| 6874 | __ movss(dest, LiteralInt32Address(value)); |
| 6875 | } |
| 6876 | } |
| 6877 | |
| 6878 | void CodeGeneratorX86_64::Load64BitValue(XmmRegister dest, int64_t value) { |
| 6879 | if (value == 0) { |
| 6880 | __ xorpd(dest, dest); |
| 6881 | } else { |
| 6882 | __ movsd(dest, LiteralInt64Address(value)); |
| 6883 | } |
| 6884 | } |
| 6885 | |
| 6886 | void CodeGeneratorX86_64::Load32BitValue(XmmRegister dest, float value) { |
| 6887 | Load32BitValue(dest, bit_cast<int32_t, float>(value)); |
| 6888 | } |
| 6889 | |
| 6890 | void CodeGeneratorX86_64::Load64BitValue(XmmRegister dest, double value) { |
| 6891 | Load64BitValue(dest, bit_cast<int64_t, double>(value)); |
| 6892 | } |
| 6893 | |
| Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 6894 | void CodeGeneratorX86_64::Compare32BitValue(CpuRegister dest, int32_t value) { |
| 6895 | if (value == 0) { |
| 6896 | __ testl(dest, dest); |
| 6897 | } else { |
| 6898 | __ cmpl(dest, Immediate(value)); |
| 6899 | } |
| 6900 | } |
| 6901 | |
| 6902 | void CodeGeneratorX86_64::Compare64BitValue(CpuRegister dest, int64_t value) { |
| 6903 | if (IsInt<32>(value)) { |
| 6904 | if (value == 0) { |
| 6905 | __ testq(dest, dest); |
| 6906 | } else { |
| 6907 | __ cmpq(dest, Immediate(static_cast<int32_t>(value))); |
| 6908 | } |
| 6909 | } else { |
| 6910 | // Value won't fit in an int. |
| 6911 | __ cmpq(dest, LiteralInt64Address(value)); |
| 6912 | } |
| 6913 | } |
| 6914 | |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 6915 | void CodeGeneratorX86_64::GenerateIntCompare(Location lhs, Location rhs) { |
| 6916 | CpuRegister lhs_reg = lhs.AsRegister<CpuRegister>(); |
| jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 6917 | GenerateIntCompare(lhs_reg, rhs); |
| 6918 | } |
| 6919 | |
| 6920 | void CodeGeneratorX86_64::GenerateIntCompare(CpuRegister lhs, Location rhs) { |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 6921 | if (rhs.IsConstant()) { |
| 6922 | int32_t value = CodeGenerator::GetInt32ValueOf(rhs.GetConstant()); |
| jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 6923 | Compare32BitValue(lhs, value); |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 6924 | } else if (rhs.IsStackSlot()) { |
| jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 6925 | __ cmpl(lhs, Address(CpuRegister(RSP), rhs.GetStackIndex())); |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 6926 | } else { |
| jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 6927 | __ cmpl(lhs, rhs.AsRegister<CpuRegister>()); |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 6928 | } |
| 6929 | } |
| 6930 | |
| 6931 | void CodeGeneratorX86_64::GenerateLongCompare(Location lhs, Location rhs) { |
| 6932 | CpuRegister lhs_reg = lhs.AsRegister<CpuRegister>(); |
| 6933 | if (rhs.IsConstant()) { |
| 6934 | int64_t value = rhs.GetConstant()->AsLongConstant()->GetValue(); |
| 6935 | Compare64BitValue(lhs_reg, value); |
| 6936 | } else if (rhs.IsDoubleStackSlot()) { |
| 6937 | __ cmpq(lhs_reg, Address(CpuRegister(RSP), rhs.GetStackIndex())); |
| 6938 | } else { |
| 6939 | __ cmpq(lhs_reg, rhs.AsRegister<CpuRegister>()); |
| 6940 | } |
| 6941 | } |
| 6942 | |
| 6943 | Address CodeGeneratorX86_64::ArrayAddress(CpuRegister obj, |
| 6944 | Location index, |
| 6945 | ScaleFactor scale, |
| 6946 | uint32_t data_offset) { |
| 6947 | return index.IsConstant() ? |
| 6948 | Address(obj, (index.GetConstant()->AsIntConstant()->GetValue() << scale) + data_offset) : |
| 6949 | Address(obj, index.AsRegister<CpuRegister>(), scale, data_offset); |
| 6950 | } |
| 6951 | |
| Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 6952 | void CodeGeneratorX86_64::Store64BitValueToStack(Location dest, int64_t value) { |
| 6953 | DCHECK(dest.IsDoubleStackSlot()); |
| 6954 | if (IsInt<32>(value)) { |
| 6955 | // Can move directly as an int32 constant. |
| 6956 | __ movq(Address(CpuRegister(RSP), dest.GetStackIndex()), |
| 6957 | Immediate(static_cast<int32_t>(value))); |
| 6958 | } else { |
| 6959 | Load64BitValue(CpuRegister(TMP), value); |
| 6960 | __ movq(Address(CpuRegister(RSP), dest.GetStackIndex()), CpuRegister(TMP)); |
| 6961 | } |
| 6962 | } |
| 6963 | |
| Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 6964 | /** |
| 6965 | * Class to handle late fixup of offsets into constant area. |
| 6966 | */ |
| 6967 | class RIPFixup : public AssemblerFixup, public ArenaObject<kArenaAllocCodeGenerator> { |
| 6968 | public: |
| 6969 | RIPFixup(CodeGeneratorX86_64& codegen, size_t offset) |
| 6970 | : codegen_(&codegen), offset_into_constant_area_(offset) {} |
| 6971 | |
| 6972 | protected: |
| 6973 | void SetOffset(size_t offset) { offset_into_constant_area_ = offset; } |
| 6974 | |
| 6975 | CodeGeneratorX86_64* codegen_; |
| 6976 | |
| 6977 | private: |
| 6978 | void Process(const MemoryRegion& region, int pos) OVERRIDE { |
| 6979 | // Patch the correct offset for the instruction. We use the address of the |
| 6980 | // 'next' instruction, which is 'pos' (patch the 4 bytes before). |
| 6981 | int32_t constant_offset = codegen_->ConstantAreaStart() + offset_into_constant_area_; |
| 6982 | int32_t relative_position = constant_offset - pos; |
| 6983 | |
| 6984 | // Patch in the right value. |
| 6985 | region.StoreUnaligned<int32_t>(pos - 4, relative_position); |
| 6986 | } |
| 6987 | |
| 6988 | // Location in constant area that the fixup refers to. |
| 6989 | size_t offset_into_constant_area_; |
| 6990 | }; |
| 6991 | |
| 6992 | /** |
| 6993 | t * Class to handle late fixup of offsets to a jump table that will be created in the |
| 6994 | * constant area. |
| 6995 | */ |
| 6996 | class JumpTableRIPFixup : public RIPFixup { |
| 6997 | public: |
| 6998 | JumpTableRIPFixup(CodeGeneratorX86_64& codegen, HPackedSwitch* switch_instr) |
| 6999 | : RIPFixup(codegen, -1), switch_instr_(switch_instr) {} |
| 7000 | |
| 7001 | void CreateJumpTable() { |
| 7002 | X86_64Assembler* assembler = codegen_->GetAssembler(); |
| 7003 | |
| 7004 | // Ensure that the reference to the jump table has the correct offset. |
| 7005 | const int32_t offset_in_constant_table = assembler->ConstantAreaSize(); |
| 7006 | SetOffset(offset_in_constant_table); |
| 7007 | |
| 7008 | // Compute the offset from the start of the function to this jump table. |
| 7009 | const int32_t current_table_offset = assembler->CodeSize() + offset_in_constant_table; |
| 7010 | |
| 7011 | // Populate the jump table with the correct values for the jump table. |
| 7012 | int32_t num_entries = switch_instr_->GetNumEntries(); |
| 7013 | HBasicBlock* block = switch_instr_->GetBlock(); |
| 7014 | const ArenaVector<HBasicBlock*>& successors = block->GetSuccessors(); |
| 7015 | // The value that we want is the target offset - the position of the table. |
| 7016 | for (int32_t i = 0; i < num_entries; i++) { |
| 7017 | HBasicBlock* b = successors[i]; |
| 7018 | Label* l = codegen_->GetLabelOf(b); |
| 7019 | DCHECK(l->IsBound()); |
| 7020 | int32_t offset_to_block = l->Position() - current_table_offset; |
| 7021 | assembler->AppendInt32(offset_to_block); |
| 7022 | } |
| 7023 | } |
| 7024 | |
| 7025 | private: |
| 7026 | const HPackedSwitch* switch_instr_; |
| 7027 | }; |
| 7028 | |
| Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 7029 | void CodeGeneratorX86_64::Finalize(CodeAllocator* allocator) { |
| 7030 | // Generate the constant area if needed. |
| Mark Mendell | 39dcf55 | 2015-04-09 20:42:42 -0400 | [diff] [blame] | 7031 | X86_64Assembler* assembler = GetAssembler(); |
| Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 7032 | if (!assembler->IsConstantAreaEmpty() || !fixups_to_jump_tables_.empty()) { |
| 7033 | // 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] | 7034 | assembler->Align(4, 0); |
| 7035 | constant_area_start_ = assembler->CodeSize(); |
| Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 7036 | |
| 7037 | // Populate any jump tables. |
| Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 7038 | for (JumpTableRIPFixup* jump_table : fixups_to_jump_tables_) { |
| Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 7039 | jump_table->CreateJumpTable(); |
| 7040 | } |
| 7041 | |
| 7042 | // And now add the constant area to the generated code. |
| Mark Mendell | 39dcf55 | 2015-04-09 20:42:42 -0400 | [diff] [blame] | 7043 | assembler->AddConstantArea(); |
| Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 7044 | } |
| 7045 | |
| 7046 | // And finish up. |
| 7047 | CodeGenerator::Finalize(allocator); |
| 7048 | } |
| 7049 | |
| Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 7050 | Address CodeGeneratorX86_64::LiteralDoubleAddress(double v) { |
| 7051 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddDouble(v)); |
| 7052 | return Address::RIP(fixup); |
| 7053 | } |
| 7054 | |
| 7055 | Address CodeGeneratorX86_64::LiteralFloatAddress(float v) { |
| 7056 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddFloat(v)); |
| 7057 | return Address::RIP(fixup); |
| 7058 | } |
| 7059 | |
| 7060 | Address CodeGeneratorX86_64::LiteralInt32Address(int32_t v) { |
| 7061 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddInt32(v)); |
| 7062 | return Address::RIP(fixup); |
| 7063 | } |
| 7064 | |
| 7065 | Address CodeGeneratorX86_64::LiteralInt64Address(int64_t v) { |
| 7066 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddInt64(v)); |
| 7067 | return Address::RIP(fixup); |
| 7068 | } |
| 7069 | |
| Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 7070 | // TODO: trg as memory. |
| 7071 | void CodeGeneratorX86_64::MoveFromReturnRegister(Location trg, Primitive::Type type) { |
| 7072 | if (!trg.IsValid()) { |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 7073 | DCHECK_EQ(type, Primitive::kPrimVoid); |
| Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 7074 | return; |
| 7075 | } |
| 7076 | |
| 7077 | DCHECK_NE(type, Primitive::kPrimVoid); |
| 7078 | |
| 7079 | Location return_loc = InvokeDexCallingConventionVisitorX86_64().GetReturnLocation(type); |
| 7080 | if (trg.Equals(return_loc)) { |
| 7081 | return; |
| 7082 | } |
| 7083 | |
| 7084 | // Let the parallel move resolver take care of all of this. |
| 7085 | HParallelMove parallel_move(GetGraph()->GetArena()); |
| 7086 | parallel_move.AddMove(return_loc, trg, type, nullptr); |
| 7087 | GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 7088 | } |
| 7089 | |
| Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 7090 | Address CodeGeneratorX86_64::LiteralCaseTable(HPackedSwitch* switch_instr) { |
| 7091 | // Create a fixup to be used to create and address the jump table. |
| 7092 | JumpTableRIPFixup* table_fixup = |
| 7093 | new (GetGraph()->GetArena()) JumpTableRIPFixup(*this, switch_instr); |
| 7094 | |
| 7095 | // We have to populate the jump tables. |
| 7096 | fixups_to_jump_tables_.push_back(table_fixup); |
| 7097 | return Address::RIP(table_fixup); |
| 7098 | } |
| 7099 | |
| Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 7100 | void CodeGeneratorX86_64::MoveInt64ToAddress(const Address& addr_low, |
| 7101 | const Address& addr_high, |
| 7102 | int64_t v, |
| 7103 | HInstruction* instruction) { |
| 7104 | if (IsInt<32>(v)) { |
| 7105 | int32_t v_32 = v; |
| 7106 | __ movq(addr_low, Immediate(v_32)); |
| 7107 | MaybeRecordImplicitNullCheck(instruction); |
| 7108 | } else { |
| 7109 | // Didn't fit in a register. Do it in pieces. |
| 7110 | int32_t low_v = Low32Bits(v); |
| 7111 | int32_t high_v = High32Bits(v); |
| 7112 | __ movl(addr_low, Immediate(low_v)); |
| 7113 | MaybeRecordImplicitNullCheck(instruction); |
| 7114 | __ movl(addr_high, Immediate(high_v)); |
| 7115 | } |
| 7116 | } |
| 7117 | |
| Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 7118 | void CodeGeneratorX86_64::PatchJitRootUse(uint8_t* code, |
| 7119 | const uint8_t* roots_data, |
| 7120 | const PatchInfo<Label>& info, |
| 7121 | uint64_t index_in_table) const { |
| 7122 | uint32_t code_offset = info.label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
| 7123 | uintptr_t address = |
| 7124 | reinterpret_cast<uintptr_t>(roots_data) + index_in_table * sizeof(GcRoot<mirror::Object>); |
| 7125 | typedef __attribute__((__aligned__(1))) uint32_t unaligned_uint32_t; |
| 7126 | reinterpret_cast<unaligned_uint32_t*>(code + code_offset)[0] = |
| 7127 | dchecked_integral_cast<uint32_t>(address); |
| 7128 | } |
| 7129 | |
| Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 7130 | void CodeGeneratorX86_64::EmitJitRootPatches(uint8_t* code, const uint8_t* roots_data) { |
| 7131 | for (const PatchInfo<Label>& info : jit_string_patches_) { |
| Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 7132 | const auto it = jit_string_roots_.find( |
| Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 7133 | StringReference(&info.dex_file, dex::StringIndex(info.index))); |
| Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 7134 | DCHECK(it != jit_string_roots_.end()); |
| Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 7135 | uint64_t index_in_table = it->second; |
| 7136 | PatchJitRootUse(code, roots_data, info, index_in_table); |
| Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 7137 | } |
| 7138 | |
| 7139 | for (const PatchInfo<Label>& info : jit_class_patches_) { |
| Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 7140 | const auto it = jit_class_roots_.find( |
| Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 7141 | TypeReference(&info.dex_file, dex::TypeIndex(info.index))); |
| 7142 | DCHECK(it != jit_class_roots_.end()); |
| Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 7143 | uint64_t index_in_table = it->second; |
| 7144 | PatchJitRootUse(code, roots_data, info, index_in_table); |
| Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 7145 | } |
| 7146 | } |
| 7147 | |
| Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 7148 | #undef __ |
| 7149 | |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 7150 | } // namespace x86_64 |
| 7151 | } // namespace art |