| 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" |
| Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 20 | #include "class_table.h" |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 21 | #include "code_generator_utils.h" |
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 22 | #include "compiled_method.h" |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 23 | #include "entrypoints/quick/quick_entrypoints.h" |
| Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 24 | #include "gc/accounting/card_table.h" |
| Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 25 | #include "intrinsics.h" |
| 26 | #include "intrinsics_x86_64.h" |
| Andreas Gampe | d490129 | 2017-05-30 18:41:34 -0700 | [diff] [blame] | 27 | #include "lock_word.h" |
| Ian Rogers | 7e70b00 | 2014-10-08 11:47:24 -0700 | [diff] [blame] | 28 | #include "mirror/array-inl.h" |
| Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 29 | #include "mirror/class-inl.h" |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 30 | #include "mirror/object_reference.h" |
| 31 | #include "thread.h" |
| 32 | #include "utils/assembler.h" |
| Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 33 | #include "utils/stack_checks.h" |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 34 | #include "utils/x86_64/assembler_x86_64.h" |
| 35 | #include "utils/x86_64/managed_register_x86_64.h" |
| 36 | |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 37 | namespace art { |
| 38 | |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 39 | template<class MirrorType> |
| 40 | class GcRoot; |
| 41 | |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 42 | namespace x86_64 { |
| 43 | |
| Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 44 | static constexpr int kCurrentMethodStackOffset = 0; |
| Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 45 | static constexpr Register kMethodRegisterArgument = RDI; |
| Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 46 | // The compare/jump sequence will generate about (1.5 * num_entries) instructions. A jump |
| 47 | // table version generates 7 instructions and num_entries literals. Compare/jump sequence will |
| 48 | // generates less code/data with a small num_entries. |
| 49 | static constexpr uint32_t kPackedSwitchJumpTableThreshold = 5; |
| Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 50 | |
| Nicolas Geoffray | 4597b5b | 2015-01-23 21:51:55 +0000 | [diff] [blame] | 51 | static constexpr Register kCoreCalleeSaves[] = { RBX, RBP, R12, R13, R14, R15 }; |
| Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 52 | static constexpr FloatRegister kFpuCalleeSaves[] = { XMM12, XMM13, XMM14, XMM15 }; |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 53 | |
| Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 54 | static constexpr int kC2ConditionMask = 0x400; |
| 55 | |
| Roland Levillain | 7cbd27f | 2016-08-11 23:53:33 +0100 | [diff] [blame] | 56 | // NOLINT on __ macro to suppress wrong warning/fix (misc-macro-parentheses) from clang-tidy. |
| 57 | #define __ down_cast<X86_64Assembler*>(codegen->GetAssembler())-> // NOLINT |
| Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 58 | #define QUICK_ENTRY_POINT(x) QUICK_ENTRYPOINT_OFFSET(kX86_64PointerSize, x).Int32Value() |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 59 | |
| Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 60 | class NullCheckSlowPathX86_64 : public SlowPathCode { |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 61 | public: |
| David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 62 | explicit NullCheckSlowPathX86_64(HNullCheck* instruction) : SlowPathCode(instruction) {} |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 63 | |
| Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 64 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 65 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 66 | __ Bind(GetEntryLabel()); |
| David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 67 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 68 | // Live registers will be restored in the catch block if caught. |
| 69 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 70 | } |
| Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 71 | x86_64_codegen->InvokeRuntime(kQuickThrowNullPointer, |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 72 | instruction_, |
| 73 | instruction_->GetDexPc(), |
| 74 | this); |
| Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 75 | CheckEntrypointTypes<kQuickThrowNullPointer, void, void>(); |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 76 | } |
| 77 | |
| Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 78 | bool IsFatal() const OVERRIDE { return true; } |
| 79 | |
| Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 80 | const char* GetDescription() const OVERRIDE { return "NullCheckSlowPathX86_64"; } |
| 81 | |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 82 | private: |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 83 | DISALLOW_COPY_AND_ASSIGN(NullCheckSlowPathX86_64); |
| 84 | }; |
| 85 | |
| Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 86 | class DivZeroCheckSlowPathX86_64 : public SlowPathCode { |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 87 | public: |
| David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 88 | explicit DivZeroCheckSlowPathX86_64(HDivZeroCheck* instruction) : SlowPathCode(instruction) {} |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 89 | |
| Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 90 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 91 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 92 | __ Bind(GetEntryLabel()); |
| Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 93 | x86_64_codegen->InvokeRuntime(kQuickThrowDivZero, instruction_, instruction_->GetDexPc(), this); |
| Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 94 | CheckEntrypointTypes<kQuickThrowDivZero, void, void>(); |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 95 | } |
| 96 | |
| Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 97 | bool IsFatal() const OVERRIDE { return true; } |
| 98 | |
| Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 99 | const char* GetDescription() const OVERRIDE { return "DivZeroCheckSlowPathX86_64"; } |
| 100 | |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 101 | private: |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 102 | DISALLOW_COPY_AND_ASSIGN(DivZeroCheckSlowPathX86_64); |
| 103 | }; |
| 104 | |
| Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 105 | class DivRemMinusOneSlowPathX86_64 : public SlowPathCode { |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 106 | public: |
| David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 107 | DivRemMinusOneSlowPathX86_64(HInstruction* at, Register reg, Primitive::Type type, bool is_div) |
| 108 | : SlowPathCode(at), cpu_reg_(CpuRegister(reg)), type_(type), is_div_(is_div) {} |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 109 | |
| Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 110 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 111 | __ Bind(GetEntryLabel()); |
| Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 112 | if (type_ == Primitive::kPrimInt) { |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 113 | if (is_div_) { |
| 114 | __ negl(cpu_reg_); |
| 115 | } else { |
| Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 116 | __ xorl(cpu_reg_, cpu_reg_); |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 117 | } |
| 118 | |
| Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 119 | } else { |
| 120 | DCHECK_EQ(Primitive::kPrimLong, type_); |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 121 | if (is_div_) { |
| 122 | __ negq(cpu_reg_); |
| 123 | } else { |
| Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 124 | __ xorl(cpu_reg_, cpu_reg_); |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 125 | } |
| Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 126 | } |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 127 | __ jmp(GetExitLabel()); |
| 128 | } |
| 129 | |
| Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 130 | const char* GetDescription() const OVERRIDE { return "DivRemMinusOneSlowPathX86_64"; } |
| 131 | |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 132 | private: |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 133 | const CpuRegister cpu_reg_; |
| Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 134 | const Primitive::Type type_; |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 135 | const bool is_div_; |
| 136 | DISALLOW_COPY_AND_ASSIGN(DivRemMinusOneSlowPathX86_64); |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 137 | }; |
| 138 | |
| Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 139 | class SuspendCheckSlowPathX86_64 : public SlowPathCode { |
| Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 140 | public: |
| Roland Levillain | 3887c46 | 2015-08-12 18:15:42 +0100 | [diff] [blame] | 141 | SuspendCheckSlowPathX86_64(HSuspendCheck* instruction, HBasicBlock* successor) |
| David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 142 | : SlowPathCode(instruction), successor_(successor) {} |
| Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 143 | |
| Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 144 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| Aart Bik | b13c65b | 2017-03-21 20:14:07 -0700 | [diff] [blame] | 145 | LocationSummary* locations = instruction_->GetLocations(); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 146 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
| Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 147 | __ Bind(GetEntryLabel()); |
| Aart Bik | 24b905f | 2017-04-06 09:59:06 -0700 | [diff] [blame] | 148 | SaveLiveRegisters(codegen, locations); // Only saves full width XMM for SIMD. |
| Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 149 | x86_64_codegen->InvokeRuntime(kQuickTestSuspend, instruction_, instruction_->GetDexPc(), this); |
| Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 150 | CheckEntrypointTypes<kQuickTestSuspend, void, void>(); |
| Aart Bik | 24b905f | 2017-04-06 09:59:06 -0700 | [diff] [blame] | 151 | RestoreLiveRegisters(codegen, locations); // Only restores full width XMM for SIMD. |
| Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 152 | if (successor_ == nullptr) { |
| 153 | __ jmp(GetReturnLabel()); |
| 154 | } else { |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 155 | __ jmp(x86_64_codegen->GetLabelOf(successor_)); |
| Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 156 | } |
| Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 157 | } |
| 158 | |
| Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 159 | Label* GetReturnLabel() { |
| 160 | DCHECK(successor_ == nullptr); |
| 161 | return &return_label_; |
| 162 | } |
| Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 163 | |
| Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 164 | HBasicBlock* GetSuccessor() const { |
| 165 | return successor_; |
| 166 | } |
| 167 | |
| Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 168 | const char* GetDescription() const OVERRIDE { return "SuspendCheckSlowPathX86_64"; } |
| 169 | |
| Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 170 | private: |
| Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 171 | HBasicBlock* const successor_; |
| Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 172 | Label return_label_; |
| 173 | |
| 174 | DISALLOW_COPY_AND_ASSIGN(SuspendCheckSlowPathX86_64); |
| 175 | }; |
| 176 | |
| Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 177 | class BoundsCheckSlowPathX86_64 : public SlowPathCode { |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 178 | public: |
| Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 179 | explicit BoundsCheckSlowPathX86_64(HBoundsCheck* instruction) |
| David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 180 | : SlowPathCode(instruction) {} |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 181 | |
| Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 182 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 183 | LocationSummary* locations = instruction_->GetLocations(); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 184 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 185 | __ Bind(GetEntryLabel()); |
| David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 186 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 187 | // Live registers will be restored in the catch block if caught. |
| 188 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 189 | } |
| Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 190 | // Are we using an array length from memory? |
| 191 | HInstruction* array_length = instruction_->InputAt(1); |
| 192 | Location length_loc = locations->InAt(1); |
| 193 | InvokeRuntimeCallingConvention calling_convention; |
| 194 | if (array_length->IsArrayLength() && array_length->IsEmittedAtUseSite()) { |
| 195 | // Load the array length into our temporary. |
| 196 | uint32_t len_offset = CodeGenerator::GetArrayLengthOffset(array_length->AsArrayLength()); |
| 197 | Location array_loc = array_length->GetLocations()->InAt(0); |
| 198 | Address array_len(array_loc.AsRegister<CpuRegister>(), len_offset); |
| 199 | length_loc = Location::RegisterLocation(calling_convention.GetRegisterAt(1)); |
| 200 | // Check for conflicts with index. |
| 201 | if (length_loc.Equals(locations->InAt(0))) { |
| 202 | // We know we aren't using parameter 2. |
| 203 | length_loc = Location::RegisterLocation(calling_convention.GetRegisterAt(2)); |
| 204 | } |
| 205 | __ movl(length_loc.AsRegister<CpuRegister>(), array_len); |
| jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 206 | if (mirror::kUseStringCompression) { |
| Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 207 | __ shrl(length_loc.AsRegister<CpuRegister>(), Immediate(1)); |
| jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 208 | } |
| Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 209 | } |
| 210 | |
| Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 211 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 212 | // move resolver. |
| Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 213 | codegen->EmitParallelMoves( |
| Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 214 | locations->InAt(0), |
| Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 215 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 216 | Primitive::kPrimInt, |
| Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 217 | length_loc, |
| Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 218 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 219 | Primitive::kPrimInt); |
| Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 220 | QuickEntrypointEnum entrypoint = instruction_->AsBoundsCheck()->IsStringCharAt() |
| 221 | ? kQuickThrowStringBounds |
| 222 | : kQuickThrowArrayBounds; |
| 223 | x86_64_codegen->InvokeRuntime(entrypoint, instruction_, instruction_->GetDexPc(), this); |
| Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 224 | CheckEntrypointTypes<kQuickThrowStringBounds, void, int32_t, int32_t>(); |
| Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 225 | CheckEntrypointTypes<kQuickThrowArrayBounds, void, int32_t, int32_t>(); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 226 | } |
| 227 | |
| Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 228 | bool IsFatal() const OVERRIDE { return true; } |
| 229 | |
| Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 230 | const char* GetDescription() const OVERRIDE { return "BoundsCheckSlowPathX86_64"; } |
| 231 | |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 232 | private: |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 233 | DISALLOW_COPY_AND_ASSIGN(BoundsCheckSlowPathX86_64); |
| 234 | }; |
| 235 | |
| Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 236 | class LoadClassSlowPathX86_64 : public SlowPathCode { |
| Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 237 | public: |
| Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 238 | LoadClassSlowPathX86_64(HLoadClass* cls, |
| 239 | HInstruction* at, |
| 240 | uint32_t dex_pc, |
| 241 | bool do_clinit) |
| Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 242 | : SlowPathCode(at), cls_(cls), dex_pc_(dex_pc), do_clinit_(do_clinit) { |
| Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 243 | DCHECK(at->IsLoadClass() || at->IsClinitCheck()); |
| 244 | } |
| Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 245 | |
| Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 246 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 247 | LocationSummary* locations = instruction_->GetLocations(); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 248 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
| Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 249 | __ Bind(GetEntryLabel()); |
| Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 250 | |
| Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 251 | SaveLiveRegisters(codegen, locations); |
| Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 252 | |
| Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 253 | // Custom calling convention: RAX serves as both input and output. |
| 254 | __ movl(CpuRegister(RAX), Immediate(cls_->GetTypeIndex().index_)); |
| Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 255 | x86_64_codegen->InvokeRuntime(do_clinit_ ? kQuickInitializeStaticStorage : kQuickInitializeType, |
| Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 256 | instruction_, |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 257 | dex_pc_, |
| 258 | this); |
| Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 259 | if (do_clinit_) { |
| 260 | CheckEntrypointTypes<kQuickInitializeStaticStorage, void*, uint32_t>(); |
| 261 | } else { |
| 262 | CheckEntrypointTypes<kQuickInitializeType, void*, uint32_t>(); |
| 263 | } |
| Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 264 | |
| Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 265 | Location out = locations->Out(); |
| Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 266 | // Move the class to the desired location. |
| Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 267 | if (out.IsValid()) { |
| 268 | DCHECK(out.IsRegister() && !locations->GetLiveRegisters()->ContainsCoreRegister(out.reg())); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 269 | x86_64_codegen->Move(out, Location::RegisterLocation(RAX)); |
| Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 270 | } |
| 271 | |
| Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 272 | RestoreLiveRegisters(codegen, locations); |
| Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 273 | // For HLoadClass/kBssEntry, store the resolved Class to the BSS entry. |
| 274 | DCHECK_EQ(instruction_->IsLoadClass(), cls_ == instruction_); |
| 275 | if (cls_ == instruction_ && cls_->GetLoadKind() == HLoadClass::LoadKind::kBssEntry) { |
| 276 | DCHECK(out.IsValid()); |
| 277 | __ movl(Address::Absolute(CodeGeneratorX86_64::kDummy32BitOffset, /* no_rip */ false), |
| 278 | locations->Out().AsRegister<CpuRegister>()); |
| 279 | Label* fixup_label = x86_64_codegen->NewTypeBssEntryPatch(cls_); |
| 280 | __ Bind(fixup_label); |
| 281 | } |
| Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 282 | __ jmp(GetExitLabel()); |
| 283 | } |
| 284 | |
| Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 285 | const char* GetDescription() const OVERRIDE { return "LoadClassSlowPathX86_64"; } |
| 286 | |
| Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 287 | private: |
| Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 288 | // The class this slow path will load. |
| 289 | HLoadClass* const cls_; |
| Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 290 | |
| Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 291 | // The dex PC of `at_`. |
| 292 | const uint32_t dex_pc_; |
| 293 | |
| 294 | // Whether to initialize the class. |
| 295 | const bool do_clinit_; |
| 296 | |
| 297 | DISALLOW_COPY_AND_ASSIGN(LoadClassSlowPathX86_64); |
| Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 298 | }; |
| 299 | |
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 300 | class LoadStringSlowPathX86_64 : public SlowPathCode { |
| 301 | public: |
| 302 | explicit LoadStringSlowPathX86_64(HLoadString* instruction) : SlowPathCode(instruction) {} |
| 303 | |
| 304 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 305 | LocationSummary* locations = instruction_->GetLocations(); |
| 306 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
| 307 | |
| 308 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
| 309 | __ Bind(GetEntryLabel()); |
| 310 | SaveLiveRegisters(codegen, locations); |
| 311 | |
| Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 312 | const dex::StringIndex string_index = instruction_->AsLoadString()->GetStringIndex(); |
| Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 313 | // Custom calling convention: RAX serves as both input and output. |
| Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 314 | __ movl(CpuRegister(RAX), Immediate(string_index.index_)); |
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 315 | x86_64_codegen->InvokeRuntime(kQuickResolveString, |
| 316 | instruction_, |
| 317 | instruction_->GetDexPc(), |
| 318 | this); |
| 319 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
| 320 | x86_64_codegen->Move(locations->Out(), Location::RegisterLocation(RAX)); |
| 321 | RestoreLiveRegisters(codegen, locations); |
| 322 | |
| 323 | // Store the resolved String to the BSS entry. |
| 324 | __ movl(Address::Absolute(CodeGeneratorX86_64::kDummy32BitOffset, /* no_rip */ false), |
| 325 | locations->Out().AsRegister<CpuRegister>()); |
| 326 | Label* fixup_label = x86_64_codegen->NewStringBssEntryPatch(instruction_->AsLoadString()); |
| 327 | __ Bind(fixup_label); |
| 328 | |
| 329 | __ jmp(GetExitLabel()); |
| 330 | } |
| 331 | |
| 332 | const char* GetDescription() const OVERRIDE { return "LoadStringSlowPathX86_64"; } |
| 333 | |
| 334 | private: |
| 335 | DISALLOW_COPY_AND_ASSIGN(LoadStringSlowPathX86_64); |
| 336 | }; |
| 337 | |
| Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 338 | class TypeCheckSlowPathX86_64 : public SlowPathCode { |
| Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 339 | public: |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 340 | TypeCheckSlowPathX86_64(HInstruction* instruction, bool is_fatal) |
| David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 341 | : SlowPathCode(instruction), is_fatal_(is_fatal) {} |
| Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 342 | |
| Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 343 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 344 | LocationSummary* locations = instruction_->GetLocations(); |
| Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 345 | uint32_t dex_pc = instruction_->GetDexPc(); |
| Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 346 | DCHECK(instruction_->IsCheckCast() |
| 347 | || !locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
| Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 348 | |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 349 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
| Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 350 | __ Bind(GetEntryLabel()); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 351 | |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 352 | if (!is_fatal_) { |
| 353 | SaveLiveRegisters(codegen, locations); |
| 354 | } |
| Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 355 | |
| 356 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 357 | // move resolver. |
| 358 | InvokeRuntimeCallingConvention calling_convention; |
| Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 359 | codegen->EmitParallelMoves(locations->InAt(0), |
| Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 360 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| 361 | Primitive::kPrimNot, |
| Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 362 | locations->InAt(1), |
| Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 363 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 364 | Primitive::kPrimNot); |
| Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 365 | if (instruction_->IsInstanceOf()) { |
| Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 366 | x86_64_codegen->InvokeRuntime(kQuickInstanceofNonTrivial, instruction_, dex_pc, this); |
| Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 367 | CheckEntrypointTypes<kQuickInstanceofNonTrivial, size_t, mirror::Object*, mirror::Class*>(); |
| Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 368 | } else { |
| 369 | DCHECK(instruction_->IsCheckCast()); |
| Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 370 | x86_64_codegen->InvokeRuntime(kQuickCheckInstanceOf, instruction_, dex_pc, this); |
| 371 | CheckEntrypointTypes<kQuickCheckInstanceOf, void, mirror::Object*, mirror::Class*>(); |
| Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 372 | } |
| Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 373 | |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 374 | if (!is_fatal_) { |
| 375 | if (instruction_->IsInstanceOf()) { |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 376 | x86_64_codegen->Move(locations->Out(), Location::RegisterLocation(RAX)); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 377 | } |
| Nicolas Geoffray | 7537437 | 2015-09-17 17:12:19 +0000 | [diff] [blame] | 378 | |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 379 | RestoreLiveRegisters(codegen, locations); |
| 380 | __ jmp(GetExitLabel()); |
| 381 | } |
| Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 382 | } |
| 383 | |
| Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 384 | const char* GetDescription() const OVERRIDE { return "TypeCheckSlowPathX86_64"; } |
| 385 | |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 386 | bool IsFatal() const OVERRIDE { return is_fatal_; } |
| 387 | |
| Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 388 | private: |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 389 | const bool is_fatal_; |
| Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 390 | |
| 391 | DISALLOW_COPY_AND_ASSIGN(TypeCheckSlowPathX86_64); |
| 392 | }; |
| 393 | |
| Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 394 | class DeoptimizationSlowPathX86_64 : public SlowPathCode { |
| Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 395 | public: |
| Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 396 | explicit DeoptimizationSlowPathX86_64(HDeoptimize* instruction) |
| David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 397 | : SlowPathCode(instruction) {} |
| Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 398 | |
| 399 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 400 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
| Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 401 | __ Bind(GetEntryLabel()); |
| Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 402 | LocationSummary* locations = instruction_->GetLocations(); |
| 403 | SaveLiveRegisters(codegen, locations); |
| 404 | InvokeRuntimeCallingConvention calling_convention; |
| 405 | x86_64_codegen->Load32BitValue( |
| 406 | CpuRegister(calling_convention.GetRegisterAt(0)), |
| 407 | static_cast<uint32_t>(instruction_->AsDeoptimize()->GetDeoptimizationKind())); |
| Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 408 | x86_64_codegen->InvokeRuntime(kQuickDeoptimize, instruction_, instruction_->GetDexPc(), this); |
| Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 409 | CheckEntrypointTypes<kQuickDeoptimize, void, DeoptimizationKind>(); |
| Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 410 | } |
| 411 | |
| Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 412 | const char* GetDescription() const OVERRIDE { return "DeoptimizationSlowPathX86_64"; } |
| 413 | |
| Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 414 | private: |
| Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 415 | DISALLOW_COPY_AND_ASSIGN(DeoptimizationSlowPathX86_64); |
| 416 | }; |
| 417 | |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 418 | class ArraySetSlowPathX86_64 : public SlowPathCode { |
| 419 | public: |
| David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 420 | explicit ArraySetSlowPathX86_64(HInstruction* instruction) : SlowPathCode(instruction) {} |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 421 | |
| 422 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 423 | LocationSummary* locations = instruction_->GetLocations(); |
| 424 | __ Bind(GetEntryLabel()); |
| 425 | SaveLiveRegisters(codegen, locations); |
| 426 | |
| 427 | InvokeRuntimeCallingConvention calling_convention; |
| 428 | HParallelMove parallel_move(codegen->GetGraph()->GetArena()); |
| 429 | parallel_move.AddMove( |
| 430 | locations->InAt(0), |
| 431 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| 432 | Primitive::kPrimNot, |
| 433 | nullptr); |
| 434 | parallel_move.AddMove( |
| 435 | locations->InAt(1), |
| 436 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 437 | Primitive::kPrimInt, |
| 438 | nullptr); |
| 439 | parallel_move.AddMove( |
| 440 | locations->InAt(2), |
| 441 | Location::RegisterLocation(calling_convention.GetRegisterAt(2)), |
| 442 | Primitive::kPrimNot, |
| 443 | nullptr); |
| 444 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 445 | |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 446 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
| Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 447 | x86_64_codegen->InvokeRuntime(kQuickAputObject, instruction_, instruction_->GetDexPc(), this); |
| Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 448 | CheckEntrypointTypes<kQuickAputObject, void, mirror::Array*, int32_t, mirror::Object*>(); |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 449 | RestoreLiveRegisters(codegen, locations); |
| 450 | __ jmp(GetExitLabel()); |
| 451 | } |
| 452 | |
| 453 | const char* GetDescription() const OVERRIDE { return "ArraySetSlowPathX86_64"; } |
| 454 | |
| 455 | private: |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 456 | DISALLOW_COPY_AND_ASSIGN(ArraySetSlowPathX86_64); |
| 457 | }; |
| 458 | |
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 459 | // Slow path marking an object reference `ref` during a read |
| 460 | // barrier. The field `obj.field` in the object `obj` holding this |
| 461 | // reference does not get updated by this slow path after marking (see |
| 462 | // ReadBarrierMarkAndUpdateFieldSlowPathX86_64 below for that). |
| 463 | // |
| 464 | // This means that after the execution of this slow path, `ref` will |
| 465 | // always be up-to-date, but `obj.field` may not; i.e., after the |
| 466 | // flip, `ref` will be a to-space reference, but `obj.field` will |
| 467 | // probably still be a from-space reference (unless it gets updated by |
| 468 | // another thread, or if another thread installed another object |
| 469 | // reference (different from `ref`) in `obj.field`). |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 470 | class ReadBarrierMarkSlowPathX86_64 : public SlowPathCode { |
| 471 | public: |
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 472 | ReadBarrierMarkSlowPathX86_64(HInstruction* instruction, |
| 473 | Location ref, |
| 474 | bool unpoison_ref_before_marking) |
| 475 | : SlowPathCode(instruction), |
| 476 | ref_(ref), |
| 477 | unpoison_ref_before_marking_(unpoison_ref_before_marking) { |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 478 | DCHECK(kEmitCompilerReadBarrier); |
| 479 | } |
| 480 | |
| 481 | const char* GetDescription() const OVERRIDE { return "ReadBarrierMarkSlowPathX86_64"; } |
| 482 | |
| 483 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 484 | LocationSummary* locations = instruction_->GetLocations(); |
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 485 | CpuRegister ref_cpu_reg = ref_.AsRegister<CpuRegister>(); |
| 486 | Register ref_reg = ref_cpu_reg.AsRegister(); |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 487 | DCHECK(locations->CanCall()); |
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 488 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(ref_reg)) << ref_reg; |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 489 | DCHECK(instruction_->IsInstanceFieldGet() || |
| 490 | instruction_->IsStaticFieldGet() || |
| 491 | instruction_->IsArrayGet() || |
| Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 492 | instruction_->IsArraySet() || |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 493 | instruction_->IsLoadClass() || |
| 494 | instruction_->IsLoadString() || |
| 495 | instruction_->IsInstanceOf() || |
| Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 496 | instruction_->IsCheckCast() || |
| Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 497 | (instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified()) || |
| 498 | (instruction_->IsInvokeStaticOrDirect() && instruction_->GetLocations()->Intrinsified())) |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 499 | << "Unexpected instruction in read barrier marking slow path: " |
| 500 | << instruction_->DebugName(); |
| 501 | |
| 502 | __ Bind(GetEntryLabel()); |
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 503 | if (unpoison_ref_before_marking_) { |
| Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 504 | // Object* ref = ref_addr->AsMirrorPtr() |
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 505 | __ MaybeUnpoisonHeapReference(ref_cpu_reg); |
| Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 506 | } |
| Roland Levillain | 4359e61 | 2016-07-20 11:32:19 +0100 | [diff] [blame] | 507 | // No need to save live registers; it's taken care of by the |
| 508 | // entrypoint. Also, there is no need to update the stack mask, |
| 509 | // as this runtime call will not trigger a garbage collection. |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 510 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 511 | DCHECK_NE(ref_reg, RSP); |
| 512 | DCHECK(0 <= ref_reg && ref_reg < kNumberOfCpuRegisters) << ref_reg; |
| Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 513 | // "Compact" slow path, saving two moves. |
| 514 | // |
| 515 | // Instead of using the standard runtime calling convention (input |
| 516 | // and output in R0): |
| 517 | // |
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 518 | // RDI <- ref |
| Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 519 | // RAX <- ReadBarrierMark(RDI) |
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 520 | // ref <- RAX |
| Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 521 | // |
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 522 | // we just use rX (the register containing `ref`) as input and output |
| Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 523 | // of a dedicated entrypoint: |
| 524 | // |
| 525 | // rX <- ReadBarrierMarkRegX(rX) |
| 526 | // |
| 527 | int32_t entry_point_offset = |
| Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 528 | Thread::ReadBarrierMarkEntryPointsOffset<kX86_64PointerSize>(ref_reg); |
| Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 529 | // This runtime call does not require a stack map. |
| 530 | x86_64_codegen->InvokeRuntimeWithoutRecordingPcInfo(entry_point_offset, instruction_, this); |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 531 | __ jmp(GetExitLabel()); |
| 532 | } |
| 533 | |
| 534 | private: |
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 535 | // The location (register) of the marked object reference. |
| 536 | const Location ref_; |
| 537 | // Should the reference in `ref_` be unpoisoned prior to marking it? |
| 538 | const bool unpoison_ref_before_marking_; |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 539 | |
| 540 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierMarkSlowPathX86_64); |
| 541 | }; |
| 542 | |
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 543 | // Slow path marking an object reference `ref` during a read barrier, |
| 544 | // and if needed, atomically updating the field `obj.field` in the |
| 545 | // object `obj` holding this reference after marking (contrary to |
| 546 | // ReadBarrierMarkSlowPathX86_64 above, which never tries to update |
| 547 | // `obj.field`). |
| 548 | // |
| 549 | // This means that after the execution of this slow path, both `ref` |
| 550 | // and `obj.field` will be up-to-date; i.e., after the flip, both will |
| 551 | // hold the same to-space reference (unless another thread installed |
| 552 | // another object reference (different from `ref`) in `obj.field`). |
| 553 | class ReadBarrierMarkAndUpdateFieldSlowPathX86_64 : public SlowPathCode { |
| 554 | public: |
| 555 | ReadBarrierMarkAndUpdateFieldSlowPathX86_64(HInstruction* instruction, |
| 556 | Location ref, |
| 557 | CpuRegister obj, |
| 558 | const Address& field_addr, |
| 559 | bool unpoison_ref_before_marking, |
| 560 | CpuRegister temp1, |
| 561 | CpuRegister temp2) |
| 562 | : SlowPathCode(instruction), |
| 563 | ref_(ref), |
| 564 | obj_(obj), |
| 565 | field_addr_(field_addr), |
| 566 | unpoison_ref_before_marking_(unpoison_ref_before_marking), |
| 567 | temp1_(temp1), |
| 568 | temp2_(temp2) { |
| 569 | DCHECK(kEmitCompilerReadBarrier); |
| 570 | } |
| 571 | |
| 572 | const char* GetDescription() const OVERRIDE { |
| 573 | return "ReadBarrierMarkAndUpdateFieldSlowPathX86_64"; |
| 574 | } |
| 575 | |
| 576 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 577 | LocationSummary* locations = instruction_->GetLocations(); |
| 578 | CpuRegister ref_cpu_reg = ref_.AsRegister<CpuRegister>(); |
| 579 | Register ref_reg = ref_cpu_reg.AsRegister(); |
| 580 | DCHECK(locations->CanCall()); |
| 581 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(ref_reg)) << ref_reg; |
| 582 | // This slow path is only used by the UnsafeCASObject intrinsic. |
| 583 | DCHECK((instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified())) |
| 584 | << "Unexpected instruction in read barrier marking and field updating slow path: " |
| 585 | << instruction_->DebugName(); |
| 586 | DCHECK(instruction_->GetLocations()->Intrinsified()); |
| 587 | DCHECK_EQ(instruction_->AsInvoke()->GetIntrinsic(), Intrinsics::kUnsafeCASObject); |
| 588 | |
| 589 | __ Bind(GetEntryLabel()); |
| 590 | if (unpoison_ref_before_marking_) { |
| 591 | // Object* ref = ref_addr->AsMirrorPtr() |
| 592 | __ MaybeUnpoisonHeapReference(ref_cpu_reg); |
| 593 | } |
| 594 | |
| 595 | // Save the old (unpoisoned) reference. |
| 596 | __ movl(temp1_, ref_cpu_reg); |
| 597 | |
| 598 | // No need to save live registers; it's taken care of by the |
| 599 | // entrypoint. Also, there is no need to update the stack mask, |
| 600 | // as this runtime call will not trigger a garbage collection. |
| 601 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
| 602 | DCHECK_NE(ref_reg, RSP); |
| 603 | DCHECK(0 <= ref_reg && ref_reg < kNumberOfCpuRegisters) << ref_reg; |
| 604 | // "Compact" slow path, saving two moves. |
| 605 | // |
| 606 | // Instead of using the standard runtime calling convention (input |
| 607 | // and output in R0): |
| 608 | // |
| 609 | // RDI <- ref |
| 610 | // RAX <- ReadBarrierMark(RDI) |
| 611 | // ref <- RAX |
| 612 | // |
| 613 | // we just use rX (the register containing `ref`) as input and output |
| 614 | // of a dedicated entrypoint: |
| 615 | // |
| 616 | // rX <- ReadBarrierMarkRegX(rX) |
| 617 | // |
| 618 | int32_t entry_point_offset = |
| Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 619 | Thread::ReadBarrierMarkEntryPointsOffset<kX86_64PointerSize>(ref_reg); |
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 620 | // This runtime call does not require a stack map. |
| 621 | x86_64_codegen->InvokeRuntimeWithoutRecordingPcInfo(entry_point_offset, instruction_, this); |
| 622 | |
| 623 | // If the new reference is different from the old reference, |
| 624 | // update the field in the holder (`*field_addr`). |
| 625 | // |
| 626 | // Note that this field could also hold a different object, if |
| 627 | // another thread had concurrently changed it. In that case, the |
| 628 | // LOCK CMPXCHGL instruction in the compare-and-set (CAS) |
| 629 | // operation below would abort the CAS, leaving the field as-is. |
| 630 | NearLabel done; |
| 631 | __ cmpl(temp1_, ref_cpu_reg); |
| 632 | __ j(kEqual, &done); |
| 633 | |
| 634 | // Update the the holder's field atomically. This may fail if |
| 635 | // mutator updates before us, but it's OK. This is achived |
| 636 | // using a strong compare-and-set (CAS) operation with relaxed |
| 637 | // memory synchronization ordering, where the expected value is |
| 638 | // the old reference and the desired value is the new reference. |
| 639 | // This operation is implemented with a 32-bit LOCK CMPXLCHG |
| 640 | // instruction, which requires the expected value (the old |
| 641 | // reference) to be in EAX. Save RAX beforehand, and move the |
| 642 | // expected value (stored in `temp1_`) into EAX. |
| 643 | __ movq(temp2_, CpuRegister(RAX)); |
| 644 | __ movl(CpuRegister(RAX), temp1_); |
| 645 | |
| 646 | // Convenience aliases. |
| 647 | CpuRegister base = obj_; |
| 648 | CpuRegister expected = CpuRegister(RAX); |
| 649 | CpuRegister value = ref_cpu_reg; |
| 650 | |
| 651 | bool base_equals_value = (base.AsRegister() == value.AsRegister()); |
| 652 | Register value_reg = ref_reg; |
| 653 | if (kPoisonHeapReferences) { |
| 654 | if (base_equals_value) { |
| 655 | // If `base` and `value` are the same register location, move |
| 656 | // `value_reg` to a temporary register. This way, poisoning |
| 657 | // `value_reg` won't invalidate `base`. |
| 658 | value_reg = temp1_.AsRegister(); |
| 659 | __ movl(CpuRegister(value_reg), base); |
| 660 | } |
| 661 | |
| 662 | // Check that the register allocator did not assign the location |
| 663 | // of `expected` (RAX) to `value` nor to `base`, so that heap |
| 664 | // poisoning (when enabled) works as intended below. |
| 665 | // - If `value` were equal to `expected`, both references would |
| 666 | // be poisoned twice, meaning they would not be poisoned at |
| 667 | // all, as heap poisoning uses address negation. |
| 668 | // - If `base` were equal to `expected`, poisoning `expected` |
| 669 | // would invalidate `base`. |
| 670 | DCHECK_NE(value_reg, expected.AsRegister()); |
| 671 | DCHECK_NE(base.AsRegister(), expected.AsRegister()); |
| 672 | |
| 673 | __ PoisonHeapReference(expected); |
| 674 | __ PoisonHeapReference(CpuRegister(value_reg)); |
| 675 | } |
| 676 | |
| 677 | __ LockCmpxchgl(field_addr_, CpuRegister(value_reg)); |
| 678 | |
| 679 | // If heap poisoning is enabled, we need to unpoison the values |
| 680 | // that were poisoned earlier. |
| 681 | if (kPoisonHeapReferences) { |
| 682 | if (base_equals_value) { |
| 683 | // `value_reg` has been moved to a temporary register, no need |
| 684 | // to unpoison it. |
| 685 | } else { |
| 686 | __ UnpoisonHeapReference(CpuRegister(value_reg)); |
| 687 | } |
| 688 | // No need to unpoison `expected` (RAX), as it is be overwritten below. |
| 689 | } |
| 690 | |
| 691 | // Restore RAX. |
| 692 | __ movq(CpuRegister(RAX), temp2_); |
| 693 | |
| 694 | __ Bind(&done); |
| 695 | __ jmp(GetExitLabel()); |
| 696 | } |
| 697 | |
| 698 | private: |
| 699 | // The location (register) of the marked object reference. |
| 700 | const Location ref_; |
| 701 | // The register containing the object holding the marked object reference field. |
| 702 | const CpuRegister obj_; |
| 703 | // The address of the marked reference field. The base of this address must be `obj_`. |
| 704 | const Address field_addr_; |
| 705 | |
| 706 | // Should the reference in `ref_` be unpoisoned prior to marking it? |
| 707 | const bool unpoison_ref_before_marking_; |
| 708 | |
| 709 | const CpuRegister temp1_; |
| 710 | const CpuRegister temp2_; |
| 711 | |
| 712 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierMarkAndUpdateFieldSlowPathX86_64); |
| 713 | }; |
| 714 | |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 715 | // Slow path generating a read barrier for a heap reference. |
| 716 | class ReadBarrierForHeapReferenceSlowPathX86_64 : public SlowPathCode { |
| 717 | public: |
| 718 | ReadBarrierForHeapReferenceSlowPathX86_64(HInstruction* instruction, |
| 719 | Location out, |
| 720 | Location ref, |
| 721 | Location obj, |
| 722 | uint32_t offset, |
| 723 | Location index) |
| David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 724 | : SlowPathCode(instruction), |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 725 | out_(out), |
| 726 | ref_(ref), |
| 727 | obj_(obj), |
| 728 | offset_(offset), |
| 729 | index_(index) { |
| 730 | DCHECK(kEmitCompilerReadBarrier); |
| 731 | // If `obj` is equal to `out` or `ref`, it means the initial |
| 732 | // object has been overwritten by (or after) the heap object |
| 733 | // reference load to be instrumented, e.g.: |
| 734 | // |
| 735 | // __ movl(out, Address(out, offset)); |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 736 | // codegen_->GenerateReadBarrierSlow(instruction, out_loc, out_loc, out_loc, offset); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 737 | // |
| 738 | // In that case, we have lost the information about the original |
| 739 | // object, and the emitted read barrier cannot work properly. |
| 740 | DCHECK(!obj.Equals(out)) << "obj=" << obj << " out=" << out; |
| 741 | DCHECK(!obj.Equals(ref)) << "obj=" << obj << " ref=" << ref; |
| 742 | } |
| 743 | |
| 744 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 745 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
| 746 | LocationSummary* locations = instruction_->GetLocations(); |
| 747 | CpuRegister reg_out = out_.AsRegister<CpuRegister>(); |
| 748 | DCHECK(locations->CanCall()); |
| 749 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg_out.AsRegister())) << out_; |
| Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 750 | DCHECK(instruction_->IsInstanceFieldGet() || |
| 751 | instruction_->IsStaticFieldGet() || |
| 752 | instruction_->IsArrayGet() || |
| 753 | instruction_->IsInstanceOf() || |
| 754 | instruction_->IsCheckCast() || |
| Andreas Gampe | d9911ee | 2017-03-27 13:27:24 -0700 | [diff] [blame] | 755 | (instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified())) |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 756 | << "Unexpected instruction in read barrier for heap reference slow path: " |
| 757 | << instruction_->DebugName(); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 758 | |
| 759 | __ Bind(GetEntryLabel()); |
| 760 | SaveLiveRegisters(codegen, locations); |
| 761 | |
| 762 | // We may have to change the index's value, but as `index_` is a |
| 763 | // constant member (like other "inputs" of this slow path), |
| 764 | // introduce a copy of it, `index`. |
| 765 | Location index = index_; |
| 766 | if (index_.IsValid()) { |
| Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 767 | // Handle `index_` for HArrayGet and UnsafeGetObject/UnsafeGetObjectVolatile intrinsics. |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 768 | if (instruction_->IsArrayGet()) { |
| 769 | // Compute real offset and store it in index_. |
| 770 | Register index_reg = index_.AsRegister<CpuRegister>().AsRegister(); |
| 771 | DCHECK(locations->GetLiveRegisters()->ContainsCoreRegister(index_reg)); |
| 772 | if (codegen->IsCoreCalleeSaveRegister(index_reg)) { |
| 773 | // We are about to change the value of `index_reg` (see the |
| 774 | // calls to art::x86_64::X86_64Assembler::shll and |
| 775 | // art::x86_64::X86_64Assembler::AddImmediate below), but it |
| 776 | // has not been saved by the previous call to |
| 777 | // art::SlowPathCode::SaveLiveRegisters, as it is a |
| 778 | // callee-save register -- |
| 779 | // art::SlowPathCode::SaveLiveRegisters does not consider |
| 780 | // callee-save registers, as it has been designed with the |
| 781 | // assumption that callee-save registers are supposed to be |
| 782 | // handled by the called function. So, as a callee-save |
| 783 | // register, `index_reg` _would_ eventually be saved onto |
| 784 | // the stack, but it would be too late: we would have |
| 785 | // changed its value earlier. Therefore, we manually save |
| 786 | // it here into another freely available register, |
| 787 | // `free_reg`, chosen of course among the caller-save |
| 788 | // registers (as a callee-save `free_reg` register would |
| 789 | // exhibit the same problem). |
| 790 | // |
| 791 | // Note we could have requested a temporary register from |
| 792 | // the register allocator instead; but we prefer not to, as |
| 793 | // this is a slow path, and we know we can find a |
| 794 | // caller-save register that is available. |
| 795 | Register free_reg = FindAvailableCallerSaveRegister(codegen).AsRegister(); |
| 796 | __ movl(CpuRegister(free_reg), CpuRegister(index_reg)); |
| 797 | index_reg = free_reg; |
| 798 | index = Location::RegisterLocation(index_reg); |
| 799 | } else { |
| 800 | // The initial register stored in `index_` has already been |
| 801 | // saved in the call to art::SlowPathCode::SaveLiveRegisters |
| 802 | // (as it is not a callee-save register), so we can freely |
| 803 | // use it. |
| 804 | } |
| 805 | // Shifting the index value contained in `index_reg` by the |
| 806 | // scale factor (2) cannot overflow in practice, as the |
| 807 | // runtime is unable to allocate object arrays with a size |
| 808 | // larger than 2^26 - 1 (that is, 2^28 - 4 bytes). |
| 809 | __ shll(CpuRegister(index_reg), Immediate(TIMES_4)); |
| 810 | static_assert( |
| 811 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 812 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 813 | __ AddImmediate(CpuRegister(index_reg), Immediate(offset_)); |
| 814 | } else { |
| Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 815 | // In the case of the UnsafeGetObject/UnsafeGetObjectVolatile |
| 816 | // intrinsics, `index_` is not shifted by a scale factor of 2 |
| 817 | // (as in the case of ArrayGet), as it is actually an offset |
| 818 | // to an object field within an object. |
| 819 | DCHECK(instruction_->IsInvoke()) << instruction_->DebugName(); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 820 | DCHECK(instruction_->GetLocations()->Intrinsified()); |
| 821 | DCHECK((instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObject) || |
| 822 | (instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObjectVolatile)) |
| 823 | << instruction_->AsInvoke()->GetIntrinsic(); |
| 824 | DCHECK_EQ(offset_, 0U); |
| 825 | DCHECK(index_.IsRegister()); |
| 826 | } |
| 827 | } |
| 828 | |
| 829 | // We're moving two or three locations to locations that could |
| 830 | // overlap, so we need a parallel move resolver. |
| 831 | InvokeRuntimeCallingConvention calling_convention; |
| 832 | HParallelMove parallel_move(codegen->GetGraph()->GetArena()); |
| 833 | parallel_move.AddMove(ref_, |
| 834 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| 835 | Primitive::kPrimNot, |
| 836 | nullptr); |
| 837 | parallel_move.AddMove(obj_, |
| 838 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 839 | Primitive::kPrimNot, |
| 840 | nullptr); |
| 841 | if (index.IsValid()) { |
| 842 | parallel_move.AddMove(index, |
| 843 | Location::RegisterLocation(calling_convention.GetRegisterAt(2)), |
| 844 | Primitive::kPrimInt, |
| 845 | nullptr); |
| 846 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 847 | } else { |
| 848 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 849 | __ movl(CpuRegister(calling_convention.GetRegisterAt(2)), Immediate(offset_)); |
| 850 | } |
| Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 851 | x86_64_codegen->InvokeRuntime(kQuickReadBarrierSlow, |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 852 | instruction_, |
| 853 | instruction_->GetDexPc(), |
| 854 | this); |
| 855 | CheckEntrypointTypes< |
| 856 | kQuickReadBarrierSlow, mirror::Object*, mirror::Object*, mirror::Object*, uint32_t>(); |
| 857 | x86_64_codegen->Move(out_, Location::RegisterLocation(RAX)); |
| 858 | |
| 859 | RestoreLiveRegisters(codegen, locations); |
| 860 | __ jmp(GetExitLabel()); |
| 861 | } |
| 862 | |
| 863 | const char* GetDescription() const OVERRIDE { |
| 864 | return "ReadBarrierForHeapReferenceSlowPathX86_64"; |
| 865 | } |
| 866 | |
| 867 | private: |
| 868 | CpuRegister FindAvailableCallerSaveRegister(CodeGenerator* codegen) { |
| 869 | size_t ref = static_cast<int>(ref_.AsRegister<CpuRegister>().AsRegister()); |
| 870 | size_t obj = static_cast<int>(obj_.AsRegister<CpuRegister>().AsRegister()); |
| 871 | for (size_t i = 0, e = codegen->GetNumberOfCoreRegisters(); i < e; ++i) { |
| 872 | if (i != ref && i != obj && !codegen->IsCoreCalleeSaveRegister(i)) { |
| 873 | return static_cast<CpuRegister>(i); |
| 874 | } |
| 875 | } |
| 876 | // We shall never fail to find a free caller-save register, as |
| 877 | // there are more than two core caller-save registers on x86-64 |
| 878 | // (meaning it is possible to find one which is different from |
| 879 | // `ref` and `obj`). |
| 880 | DCHECK_GT(codegen->GetNumberOfCoreCallerSaveRegisters(), 2u); |
| 881 | LOG(FATAL) << "Could not find a free caller-save register"; |
| 882 | UNREACHABLE(); |
| 883 | } |
| 884 | |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 885 | const Location out_; |
| 886 | const Location ref_; |
| 887 | const Location obj_; |
| 888 | const uint32_t offset_; |
| 889 | // An additional location containing an index to an array. |
| 890 | // Only used for HArrayGet and the UnsafeGetObject & |
| 891 | // UnsafeGetObjectVolatile intrinsics. |
| 892 | const Location index_; |
| 893 | |
| 894 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForHeapReferenceSlowPathX86_64); |
| 895 | }; |
| 896 | |
| 897 | // Slow path generating a read barrier for a GC root. |
| 898 | class ReadBarrierForRootSlowPathX86_64 : public SlowPathCode { |
| 899 | public: |
| 900 | ReadBarrierForRootSlowPathX86_64(HInstruction* instruction, Location out, Location root) |
| David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 901 | : SlowPathCode(instruction), out_(out), root_(root) { |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 902 | DCHECK(kEmitCompilerReadBarrier); |
| 903 | } |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 904 | |
| 905 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 906 | LocationSummary* locations = instruction_->GetLocations(); |
| 907 | DCHECK(locations->CanCall()); |
| 908 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(out_.reg())); |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 909 | DCHECK(instruction_->IsLoadClass() || instruction_->IsLoadString()) |
| 910 | << "Unexpected instruction in read barrier for GC root slow path: " |
| 911 | << instruction_->DebugName(); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 912 | |
| 913 | __ Bind(GetEntryLabel()); |
| 914 | SaveLiveRegisters(codegen, locations); |
| 915 | |
| 916 | InvokeRuntimeCallingConvention calling_convention; |
| 917 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
| 918 | x86_64_codegen->Move(Location::RegisterLocation(calling_convention.GetRegisterAt(0)), root_); |
| Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 919 | x86_64_codegen->InvokeRuntime(kQuickReadBarrierForRootSlow, |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 920 | instruction_, |
| 921 | instruction_->GetDexPc(), |
| 922 | this); |
| 923 | CheckEntrypointTypes<kQuickReadBarrierForRootSlow, mirror::Object*, GcRoot<mirror::Object>*>(); |
| 924 | x86_64_codegen->Move(out_, Location::RegisterLocation(RAX)); |
| 925 | |
| 926 | RestoreLiveRegisters(codegen, locations); |
| 927 | __ jmp(GetExitLabel()); |
| 928 | } |
| 929 | |
| 930 | const char* GetDescription() const OVERRIDE { return "ReadBarrierForRootSlowPathX86_64"; } |
| 931 | |
| 932 | private: |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 933 | const Location out_; |
| 934 | const Location root_; |
| 935 | |
| 936 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForRootSlowPathX86_64); |
| 937 | }; |
| 938 | |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 939 | #undef __ |
| Roland Levillain | 7cbd27f | 2016-08-11 23:53:33 +0100 | [diff] [blame] | 940 | // NOLINT on __ macro to suppress wrong warning/fix (misc-macro-parentheses) from clang-tidy. |
| 941 | #define __ down_cast<X86_64Assembler*>(GetAssembler())-> // NOLINT |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 942 | |
| Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 943 | inline Condition X86_64IntegerCondition(IfCondition cond) { |
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 944 | switch (cond) { |
| 945 | case kCondEQ: return kEqual; |
| 946 | case kCondNE: return kNotEqual; |
| 947 | case kCondLT: return kLess; |
| 948 | case kCondLE: return kLessEqual; |
| 949 | case kCondGT: return kGreater; |
| 950 | case kCondGE: return kGreaterEqual; |
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 951 | case kCondB: return kBelow; |
| 952 | case kCondBE: return kBelowEqual; |
| 953 | case kCondA: return kAbove; |
| 954 | case kCondAE: return kAboveEqual; |
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 955 | } |
| Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 956 | LOG(FATAL) << "Unreachable"; |
| 957 | UNREACHABLE(); |
| 958 | } |
| 959 | |
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 960 | // Maps FP condition to x86_64 name. |
| Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 961 | inline Condition X86_64FPCondition(IfCondition cond) { |
| 962 | switch (cond) { |
| 963 | case kCondEQ: return kEqual; |
| 964 | case kCondNE: return kNotEqual; |
| 965 | case kCondLT: return kBelow; |
| 966 | case kCondLE: return kBelowEqual; |
| 967 | case kCondGT: return kAbove; |
| 968 | case kCondGE: return kAboveEqual; |
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 969 | default: break; // should not happen |
| Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 970 | }; |
| 971 | LOG(FATAL) << "Unreachable"; |
| 972 | UNREACHABLE(); |
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 973 | } |
| 974 | |
| Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 975 | HInvokeStaticOrDirect::DispatchInfo CodeGeneratorX86_64::GetSupportedInvokeStaticOrDirectDispatch( |
| 976 | const HInvokeStaticOrDirect::DispatchInfo& desired_dispatch_info, |
| Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 977 | HInvokeStaticOrDirect* invoke ATTRIBUTE_UNUSED) { |
| Nicolas Geoffray | c1a42cf | 2016-12-18 15:52:36 +0000 | [diff] [blame] | 978 | return desired_dispatch_info; |
| Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 979 | } |
| 980 | |
| Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 981 | void CodeGeneratorX86_64::GenerateStaticOrDirectCall( |
| 982 | HInvokeStaticOrDirect* invoke, Location temp, SlowPathCode* slow_path) { |
| Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 983 | // All registers are assumed to be correctly set up. |
| Vladimir Marko | 4ee8e29 | 2017-06-02 15:39:30 +0000 | [diff] [blame] | 984 | |
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 985 | Location callee_method = temp; // For all kinds except kRecursive, callee will be in temp. |
| 986 | switch (invoke->GetMethodLoadKind()) { |
| Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 987 | case HInvokeStaticOrDirect::MethodLoadKind::kStringInit: { |
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 988 | // temp = thread->string_init_entrypoint |
| Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 989 | uint32_t offset = |
| 990 | GetThreadOffset<kX86_64PointerSize>(invoke->GetStringInitEntryPoint()).Int32Value(); |
| 991 | __ gs()->movq(temp.AsRegister<CpuRegister>(), Address::Absolute(offset, /* no_rip */ true)); |
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 992 | break; |
| Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 993 | } |
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 994 | case HInvokeStaticOrDirect::MethodLoadKind::kRecursive: |
| Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 995 | callee_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 996 | break; |
| Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 997 | case HInvokeStaticOrDirect::MethodLoadKind::kBootImageLinkTimePcRelative: |
| 998 | DCHECK(GetCompilerOptions().IsBootImage()); |
| 999 | __ leal(temp.AsRegister<CpuRegister>(), |
| 1000 | Address::Absolute(kDummy32BitOffset, /* no_rip */ false)); |
| 1001 | RecordBootMethodPatch(invoke); |
| 1002 | break; |
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 1003 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddress: |
| Vladimir Marko | 2d73f33 | 2017-03-16 15:55:49 +0000 | [diff] [blame] | 1004 | Load64BitValue(temp.AsRegister<CpuRegister>(), invoke->GetMethodAddress()); |
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 1005 | break; |
| Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 1006 | case HInvokeStaticOrDirect::MethodLoadKind::kBssEntry: { |
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 1007 | __ movq(temp.AsRegister<CpuRegister>(), |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 1008 | Address::Absolute(kDummy32BitOffset, /* no_rip */ false)); |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 1009 | // Bind a new fixup label at the end of the "movl" insn. |
| Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 1010 | __ Bind(NewMethodBssEntryPatch( |
| 1011 | MethodReference(&GetGraph()->GetDexFile(), invoke->GetDexMethodIndex()))); |
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 1012 | break; |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 1013 | } |
| Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 1014 | case HInvokeStaticOrDirect::MethodLoadKind::kRuntimeCall: { |
| 1015 | GenerateInvokeStaticOrDirectRuntimeCall(invoke, temp, slow_path); |
| 1016 | return; // No code pointer retrieval; the runtime performs the call directly. |
| Vladimir Marko | 9b688a0 | 2015-05-06 14:12:42 +0100 | [diff] [blame] | 1017 | } |
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 1018 | } |
| 1019 | |
| 1020 | switch (invoke->GetCodePtrLocation()) { |
| 1021 | case HInvokeStaticOrDirect::CodePtrLocation::kCallSelf: |
| 1022 | __ call(&frame_entry_label_); |
| 1023 | break; |
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 1024 | case HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod: |
| 1025 | // (callee_method + offset_of_quick_compiled_code)() |
| 1026 | __ call(Address(callee_method.AsRegister<CpuRegister>(), |
| 1027 | ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
| Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 1028 | kX86_64PointerSize).SizeValue())); |
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 1029 | break; |
| Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 1030 | } |
| Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 1031 | RecordPcInfo(invoke, invoke->GetDexPc(), slow_path); |
| Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 1032 | |
| 1033 | DCHECK(!IsLeafMethod()); |
| Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 1034 | } |
| 1035 | |
| Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 1036 | void CodeGeneratorX86_64::GenerateVirtualCall( |
| 1037 | HInvokeVirtual* invoke, Location temp_in, SlowPathCode* slow_path) { |
| Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 1038 | CpuRegister temp = temp_in.AsRegister<CpuRegister>(); |
| 1039 | size_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| 1040 | invoke->GetVTableIndex(), kX86_64PointerSize).SizeValue(); |
| Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 1041 | |
| 1042 | // Use the calling convention instead of the location of the receiver, as |
| 1043 | // intrinsics may have put the receiver in a different register. In the intrinsics |
| 1044 | // slow path, the arguments have been moved to the right place, so here we are |
| 1045 | // guaranteed that the receiver is the first register of the calling convention. |
| 1046 | InvokeDexCallingConvention calling_convention; |
| 1047 | Register receiver = calling_convention.GetRegisterAt(0); |
| 1048 | |
| Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 1049 | size_t class_offset = mirror::Object::ClassOffset().SizeValue(); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 1050 | // /* HeapReference<Class> */ temp = receiver->klass_ |
| Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 1051 | __ movl(temp, Address(CpuRegister(receiver), class_offset)); |
| Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 1052 | MaybeRecordImplicitNullCheck(invoke); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 1053 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 1054 | // emit a read barrier for the previous class reference load. |
| 1055 | // However this is not required in practice, as this is an |
| 1056 | // intermediate/temporary reference and because the current |
| 1057 | // concurrent copying collector keeps the from-space memory |
| 1058 | // intact/accessible until the end of the marking phase (the |
| 1059 | // concurrent copying collector may not in the future). |
| Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 1060 | __ MaybeUnpoisonHeapReference(temp); |
| 1061 | // temp = temp->GetMethodAt(method_offset); |
| 1062 | __ movq(temp, Address(temp, method_offset)); |
| 1063 | // call temp->GetEntryPoint(); |
| 1064 | __ call(Address(temp, ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
| Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 1065 | kX86_64PointerSize).SizeValue())); |
| Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 1066 | RecordPcInfo(invoke, invoke->GetDexPc(), slow_path); |
| Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 1067 | } |
| 1068 | |
| Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 1069 | void CodeGeneratorX86_64::RecordBootMethodPatch(HInvokeStaticOrDirect* invoke) { |
| 1070 | boot_image_method_patches_.emplace_back(*invoke->GetTargetMethod().dex_file, |
| 1071 | invoke->GetTargetMethod().dex_method_index); |
| 1072 | __ Bind(&boot_image_method_patches_.back().label); |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 1073 | } |
| 1074 | |
| Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 1075 | Label* CodeGeneratorX86_64::NewMethodBssEntryPatch(MethodReference target_method) { |
| 1076 | // Add a patch entry and return the label. |
| 1077 | method_bss_entry_patches_.emplace_back(*target_method.dex_file, target_method.dex_method_index); |
| 1078 | return &method_bss_entry_patches_.back().label; |
| 1079 | } |
| 1080 | |
| Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 1081 | void CodeGeneratorX86_64::RecordBootTypePatch(HLoadClass* load_class) { |
| 1082 | boot_image_type_patches_.emplace_back(load_class->GetDexFile(), |
| 1083 | load_class->GetTypeIndex().index_); |
| 1084 | __ Bind(&boot_image_type_patches_.back().label); |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 1085 | } |
| 1086 | |
| Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 1087 | Label* CodeGeneratorX86_64::NewTypeBssEntryPatch(HLoadClass* load_class) { |
| Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 1088 | type_bss_entry_patches_.emplace_back(load_class->GetDexFile(), load_class->GetTypeIndex().index_); |
| 1089 | return &type_bss_entry_patches_.back().label; |
| Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 1090 | } |
| 1091 | |
| Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 1092 | void CodeGeneratorX86_64::RecordBootStringPatch(HLoadString* load_string) { |
| Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 1093 | string_patches_.emplace_back(load_string->GetDexFile(), load_string->GetStringIndex().index_); |
| 1094 | __ Bind(&string_patches_.back().label); |
| 1095 | } |
| 1096 | |
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 1097 | Label* CodeGeneratorX86_64::NewStringBssEntryPatch(HLoadString* load_string) { |
| 1098 | DCHECK(!GetCompilerOptions().IsBootImage()); |
| Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 1099 | string_bss_entry_patches_.emplace_back( |
| 1100 | load_string->GetDexFile(), load_string->GetStringIndex().index_); |
| 1101 | return &string_bss_entry_patches_.back().label; |
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 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 | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 1122 | boot_image_method_patches_.size() + |
| Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 1123 | method_bss_entry_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() + |
| Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 1126 | string_patches_.size() + |
| 1127 | string_bss_entry_patches_.size(); |
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 1128 | linker_patches->reserve(size); |
| Vladimir Marko | 764d454 | 2017-05-16 10:31:41 +0100 | [diff] [blame] | 1129 | if (GetCompilerOptions().IsBootImage()) { |
| Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 1130 | EmitPcRelativeLinkerPatches<LinkerPatch::RelativeMethodPatch>(boot_image_method_patches_, |
| 1131 | linker_patches); |
| Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 1132 | EmitPcRelativeLinkerPatches<LinkerPatch::RelativeTypePatch>(boot_image_type_patches_, |
| 1133 | linker_patches); |
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 1134 | EmitPcRelativeLinkerPatches<LinkerPatch::RelativeStringPatch>(string_patches_, linker_patches); |
| Vladimir Marko | 764d454 | 2017-05-16 10:31:41 +0100 | [diff] [blame] | 1135 | } else { |
| Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 1136 | DCHECK(boot_image_method_patches_.empty()); |
| Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 1137 | EmitPcRelativeLinkerPatches<LinkerPatch::TypeClassTablePatch>(boot_image_type_patches_, |
| 1138 | linker_patches); |
| Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 1139 | EmitPcRelativeLinkerPatches<LinkerPatch::StringInternTablePatch>(string_patches_, |
| 1140 | linker_patches); |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 1141 | } |
| Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 1142 | EmitPcRelativeLinkerPatches<LinkerPatch::MethodBssEntryPatch>(method_bss_entry_patches_, |
| 1143 | linker_patches); |
| Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 1144 | EmitPcRelativeLinkerPatches<LinkerPatch::TypeBssEntryPatch>(type_bss_entry_patches_, |
| 1145 | linker_patches); |
| Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 1146 | EmitPcRelativeLinkerPatches<LinkerPatch::StringBssEntryPatch>(string_bss_entry_patches_, |
| 1147 | linker_patches); |
| Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 1148 | DCHECK_EQ(size, linker_patches->size()); |
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 1149 | } |
| 1150 | |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1151 | void CodeGeneratorX86_64::DumpCoreRegister(std::ostream& stream, int reg) const { |
| David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 1152 | stream << Register(reg); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1153 | } |
| 1154 | |
| 1155 | void CodeGeneratorX86_64::DumpFloatingPointRegister(std::ostream& stream, int reg) const { |
| David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 1156 | stream << FloatRegister(reg); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1157 | } |
| 1158 | |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1159 | size_t CodeGeneratorX86_64::SaveCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 1160 | __ movq(Address(CpuRegister(RSP), stack_index), CpuRegister(reg_id)); |
| 1161 | return kX86_64WordSize; |
| Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 1162 | } |
| 1163 | |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1164 | size_t CodeGeneratorX86_64::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 1165 | __ movq(CpuRegister(reg_id), Address(CpuRegister(RSP), stack_index)); |
| 1166 | return kX86_64WordSize; |
| 1167 | } |
| 1168 | |
| 1169 | size_t CodeGeneratorX86_64::SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| Aart Bik | b13c65b | 2017-03-21 20:14:07 -0700 | [diff] [blame] | 1170 | if (GetGraph()->HasSIMD()) { |
| Aart Bik | 5576f37 | 2017-03-23 16:17:37 -0700 | [diff] [blame] | 1171 | __ movups(Address(CpuRegister(RSP), stack_index), XmmRegister(reg_id)); |
| Aart Bik | b13c65b | 2017-03-21 20:14:07 -0700 | [diff] [blame] | 1172 | } else { |
| 1173 | __ movsd(Address(CpuRegister(RSP), stack_index), XmmRegister(reg_id)); |
| 1174 | } |
| 1175 | return GetFloatingPointSpillSlotSize(); |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1176 | } |
| 1177 | |
| 1178 | size_t CodeGeneratorX86_64::RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| Aart Bik | b13c65b | 2017-03-21 20:14:07 -0700 | [diff] [blame] | 1179 | if (GetGraph()->HasSIMD()) { |
| Aart Bik | 5576f37 | 2017-03-23 16:17:37 -0700 | [diff] [blame] | 1180 | __ movups(XmmRegister(reg_id), Address(CpuRegister(RSP), stack_index)); |
| Aart Bik | b13c65b | 2017-03-21 20:14:07 -0700 | [diff] [blame] | 1181 | } else { |
| 1182 | __ movsd(XmmRegister(reg_id), Address(CpuRegister(RSP), stack_index)); |
| 1183 | } |
| 1184 | return GetFloatingPointSpillSlotSize(); |
| Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 1185 | } |
| 1186 | |
| Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1187 | void CodeGeneratorX86_64::InvokeRuntime(QuickEntrypointEnum entrypoint, |
| 1188 | HInstruction* instruction, |
| 1189 | uint32_t dex_pc, |
| 1190 | SlowPathCode* slow_path) { |
| Alexandre Rames | 91a6516 | 2016-09-19 13:54:30 +0100 | [diff] [blame] | 1191 | ValidateInvokeRuntime(entrypoint, instruction, slow_path); |
| Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 1192 | GenerateInvokeRuntime(GetThreadOffset<kX86_64PointerSize>(entrypoint).Int32Value()); |
| 1193 | if (EntrypointRequiresStackMap(entrypoint)) { |
| 1194 | RecordPcInfo(instruction, dex_pc, slow_path); |
| 1195 | } |
| Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 1196 | } |
| 1197 | |
| Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 1198 | void CodeGeneratorX86_64::InvokeRuntimeWithoutRecordingPcInfo(int32_t entry_point_offset, |
| 1199 | HInstruction* instruction, |
| 1200 | SlowPathCode* slow_path) { |
| 1201 | ValidateInvokeRuntimeWithoutRecordingPcInfo(instruction, slow_path); |
| Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 1202 | GenerateInvokeRuntime(entry_point_offset); |
| 1203 | } |
| 1204 | |
| 1205 | void CodeGeneratorX86_64::GenerateInvokeRuntime(int32_t entry_point_offset) { |
| Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 1206 | __ gs()->call(Address::Absolute(entry_point_offset, /* no_rip */ true)); |
| 1207 | } |
| 1208 | |
| Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1209 | static constexpr int kNumberOfCpuRegisterPairs = 0; |
| Nicolas Geoffray | 4597b5b | 2015-01-23 21:51:55 +0000 | [diff] [blame] | 1210 | // Use a fake return address register to mimic Quick. |
| 1211 | static constexpr Register kFakeReturnRegister = Register(kLastCpuRegister + 1); |
| Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 1212 | CodeGeneratorX86_64::CodeGeneratorX86_64(HGraph* graph, |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 1213 | const X86_64InstructionSetFeatures& isa_features, |
| 1214 | const CompilerOptions& compiler_options, |
| 1215 | OptimizingCompilerStats* stats) |
| Nicolas Geoffray | 9889396 | 2015-01-21 12:32:32 +0000 | [diff] [blame] | 1216 | : CodeGenerator(graph, |
| 1217 | kNumberOfCpuRegisters, |
| 1218 | kNumberOfFloatRegisters, |
| Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1219 | kNumberOfCpuRegisterPairs, |
| Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 1220 | ComputeRegisterMask(reinterpret_cast<const int*>(kCoreCalleeSaves), |
| 1221 | arraysize(kCoreCalleeSaves)) |
| Nicolas Geoffray | 4597b5b | 2015-01-23 21:51:55 +0000 | [diff] [blame] | 1222 | | (1 << kFakeReturnRegister), |
| Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 1223 | ComputeRegisterMask(reinterpret_cast<const int*>(kFpuCalleeSaves), |
| 1224 | arraysize(kFpuCalleeSaves)), |
| Serban Constantinescu | ecc4366 | 2015-08-13 13:33:12 +0100 | [diff] [blame] | 1225 | compiler_options, |
| 1226 | stats), |
| Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 1227 | block_labels_(nullptr), |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1228 | location_builder_(graph, this), |
| Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 1229 | instruction_visitor_(graph, this), |
| Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 1230 | move_resolver_(graph->GetArena(), this), |
| Vladimir Marko | 93205e3 | 2016-04-13 11:59:46 +0100 | [diff] [blame] | 1231 | assembler_(graph->GetArena()), |
| Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 1232 | isa_features_(isa_features), |
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 1233 | constant_area_start_(0), |
| Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 1234 | boot_image_method_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 1235 | method_bss_entry_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 1236 | boot_image_type_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 1237 | type_bss_entry_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 1238 | string_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 1239 | string_bss_entry_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 1240 | jit_string_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 1241 | jit_class_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 1242 | fixups_to_jump_tables_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)) { |
| Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1243 | AddAllocatedRegister(Location::RegisterLocation(kFakeReturnRegister)); |
| 1244 | } |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1245 | |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1246 | InstructionCodeGeneratorX86_64::InstructionCodeGeneratorX86_64(HGraph* graph, |
| 1247 | CodeGeneratorX86_64* codegen) |
| Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 1248 | : InstructionCodeGenerator(graph, codegen), |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1249 | assembler_(codegen->GetAssembler()), |
| 1250 | codegen_(codegen) {} |
| 1251 | |
| David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 1252 | void CodeGeneratorX86_64::SetupBlockedRegisters() const { |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1253 | // Stack register is always reserved. |
| Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 1254 | blocked_core_registers_[RSP] = true; |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1255 | |
| Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 1256 | // Block the register used as TMP. |
| Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 1257 | blocked_core_registers_[TMP] = true; |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1258 | } |
| 1259 | |
| David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1260 | static dwarf::Reg DWARFReg(Register reg) { |
| David Srbecky | 9d8606d | 2015-04-12 09:35:32 +0100 | [diff] [blame] | 1261 | return dwarf::Reg::X86_64Core(static_cast<int>(reg)); |
| David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1262 | } |
| David Srbecky | 9d8606d | 2015-04-12 09:35:32 +0100 | [diff] [blame] | 1263 | |
| David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1264 | static dwarf::Reg DWARFReg(FloatRegister reg) { |
| David Srbecky | 9d8606d | 2015-04-12 09:35:32 +0100 | [diff] [blame] | 1265 | return dwarf::Reg::X86_64Fp(static_cast<int>(reg)); |
| David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1266 | } |
| 1267 | |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1268 | void CodeGeneratorX86_64::GenerateFrameEntry() { |
| David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1269 | __ cfi().SetCurrentCFAOffset(kX86_64WordSize); // return address |
| Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 1270 | __ Bind(&frame_entry_label_); |
| Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 1271 | bool skip_overflow_check = IsLeafMethod() |
| Dave Allison | 648d711 | 2014-07-25 16:15:27 -0700 | [diff] [blame] | 1272 | && !FrameNeedsStackCheck(GetFrameSize(), InstructionSet::kX86_64); |
| Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1273 | DCHECK(GetCompilerOptions().GetImplicitStackOverflowChecks()); |
| Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 1274 | |
| Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1275 | if (!skip_overflow_check) { |
| Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 1276 | __ testq(CpuRegister(RAX), Address( |
| 1277 | CpuRegister(RSP), -static_cast<int32_t>(GetStackOverflowReservedBytes(kX86_64)))); |
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1278 | RecordPcInfo(nullptr, 0); |
| Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 1279 | } |
| Nicolas Geoffray | a26369a | 2015-01-22 08:46:05 +0000 | [diff] [blame] | 1280 | |
| Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1281 | if (HasEmptyFrame()) { |
| 1282 | return; |
| 1283 | } |
| 1284 | |
| Nicolas Geoffray | 9889396 | 2015-01-21 12:32:32 +0000 | [diff] [blame] | 1285 | for (int i = arraysize(kCoreCalleeSaves) - 1; i >= 0; --i) { |
| Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1286 | Register reg = kCoreCalleeSaves[i]; |
| Nicolas Geoffray | 4597b5b | 2015-01-23 21:51:55 +0000 | [diff] [blame] | 1287 | if (allocated_registers_.ContainsCoreRegister(reg)) { |
| Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1288 | __ pushq(CpuRegister(reg)); |
| David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1289 | __ cfi().AdjustCFAOffset(kX86_64WordSize); |
| 1290 | __ cfi().RelOffset(DWARFReg(reg), 0); |
| Nicolas Geoffray | 9889396 | 2015-01-21 12:32:32 +0000 | [diff] [blame] | 1291 | } |
| 1292 | } |
| Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 1293 | |
| David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1294 | int adjust = GetFrameSize() - GetCoreSpillSize(); |
| 1295 | __ subq(CpuRegister(RSP), Immediate(adjust)); |
| 1296 | __ cfi().AdjustCFAOffset(adjust); |
| Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1297 | uint32_t xmm_spill_location = GetFpuSpillStart(); |
| 1298 | size_t xmm_spill_slot_size = GetFloatingPointSpillSlotSize(); |
| Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 1299 | |
| Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1300 | for (int i = arraysize(kFpuCalleeSaves) - 1; i >= 0; --i) { |
| 1301 | if (allocated_registers_.ContainsFloatingPointRegister(kFpuCalleeSaves[i])) { |
| David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1302 | int offset = xmm_spill_location + (xmm_spill_slot_size * i); |
| 1303 | __ movsd(Address(CpuRegister(RSP), offset), XmmRegister(kFpuCalleeSaves[i])); |
| 1304 | __ cfi().RelOffset(DWARFReg(kFpuCalleeSaves[i]), offset); |
| Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1305 | } |
| Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 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 | f789353 | 2017-06-15 12:34:36 +0100 | [diff] [blame] | 1315 | |
| 1316 | if (GetGraph()->HasShouldDeoptimizeFlag()) { |
| 1317 | // Initialize should_deoptimize flag to 0. |
| 1318 | __ movl(Address(CpuRegister(RSP), GetStackOffsetOfShouldDeoptimizeFlag()), Immediate(0)); |
| 1319 | } |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1320 | } |
| 1321 | |
| 1322 | void CodeGeneratorX86_64::GenerateFrameExit() { |
| David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 1323 | __ cfi().RememberState(); |
| 1324 | if (!HasEmptyFrame()) { |
| 1325 | uint32_t xmm_spill_location = GetFpuSpillStart(); |
| 1326 | size_t xmm_spill_slot_size = GetFloatingPointSpillSlotSize(); |
| 1327 | for (size_t i = 0; i < arraysize(kFpuCalleeSaves); ++i) { |
| 1328 | if (allocated_registers_.ContainsFloatingPointRegister(kFpuCalleeSaves[i])) { |
| 1329 | int offset = xmm_spill_location + (xmm_spill_slot_size * i); |
| 1330 | __ movsd(XmmRegister(kFpuCalleeSaves[i]), Address(CpuRegister(RSP), offset)); |
| 1331 | __ cfi().Restore(DWARFReg(kFpuCalleeSaves[i])); |
| 1332 | } |
| 1333 | } |
| 1334 | |
| 1335 | int adjust = GetFrameSize() - GetCoreSpillSize(); |
| 1336 | __ addq(CpuRegister(RSP), Immediate(adjust)); |
| 1337 | __ cfi().AdjustCFAOffset(-adjust); |
| 1338 | |
| 1339 | for (size_t i = 0; i < arraysize(kCoreCalleeSaves); ++i) { |
| 1340 | Register reg = kCoreCalleeSaves[i]; |
| 1341 | if (allocated_registers_.ContainsCoreRegister(reg)) { |
| 1342 | __ popq(CpuRegister(reg)); |
| 1343 | __ cfi().AdjustCFAOffset(-static_cast<int>(kX86_64WordSize)); |
| 1344 | __ cfi().Restore(DWARFReg(reg)); |
| 1345 | } |
| Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1346 | } |
| 1347 | } |
| David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 1348 | __ ret(); |
| 1349 | __ cfi().RestoreState(); |
| 1350 | __ cfi().DefCFAOffset(GetFrameSize()); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1351 | } |
| 1352 | |
| Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 1353 | void CodeGeneratorX86_64::Bind(HBasicBlock* block) { |
| 1354 | __ Bind(GetLabelOf(block)); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1355 | } |
| 1356 | |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1357 | void CodeGeneratorX86_64::Move(Location destination, Location source) { |
| 1358 | if (source.Equals(destination)) { |
| 1359 | return; |
| 1360 | } |
| 1361 | if (destination.IsRegister()) { |
| Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1362 | CpuRegister dest = destination.AsRegister<CpuRegister>(); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1363 | if (source.IsRegister()) { |
| Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1364 | __ movq(dest, source.AsRegister<CpuRegister>()); |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1365 | } else if (source.IsFpuRegister()) { |
| Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1366 | __ movd(dest, source.AsFpuRegister<XmmRegister>()); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1367 | } else if (source.IsStackSlot()) { |
| Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1368 | __ movl(dest, Address(CpuRegister(RSP), source.GetStackIndex())); |
| 1369 | } else if (source.IsConstant()) { |
| 1370 | HConstant* constant = source.GetConstant(); |
| 1371 | if (constant->IsLongConstant()) { |
| 1372 | Load64BitValue(dest, constant->AsLongConstant()->GetValue()); |
| 1373 | } else { |
| 1374 | Load32BitValue(dest, GetInt32ValueOf(constant)); |
| 1375 | } |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1376 | } else { |
| 1377 | DCHECK(source.IsDoubleStackSlot()); |
| Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1378 | __ movq(dest, Address(CpuRegister(RSP), source.GetStackIndex())); |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1379 | } |
| 1380 | } else if (destination.IsFpuRegister()) { |
| Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1381 | XmmRegister dest = destination.AsFpuRegister<XmmRegister>(); |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1382 | if (source.IsRegister()) { |
| Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1383 | __ movd(dest, source.AsRegister<CpuRegister>()); |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1384 | } else if (source.IsFpuRegister()) { |
| Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1385 | __ movaps(dest, source.AsFpuRegister<XmmRegister>()); |
| 1386 | } else if (source.IsConstant()) { |
| 1387 | HConstant* constant = source.GetConstant(); |
| 1388 | int64_t value = CodeGenerator::GetInt64ValueOf(constant); |
| 1389 | if (constant->IsFloatConstant()) { |
| 1390 | Load32BitValue(dest, static_cast<int32_t>(value)); |
| 1391 | } else { |
| 1392 | Load64BitValue(dest, value); |
| 1393 | } |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1394 | } else if (source.IsStackSlot()) { |
| Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1395 | __ movss(dest, Address(CpuRegister(RSP), source.GetStackIndex())); |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1396 | } else { |
| 1397 | DCHECK(source.IsDoubleStackSlot()); |
| Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1398 | __ movsd(dest, Address(CpuRegister(RSP), source.GetStackIndex())); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1399 | } |
| 1400 | } else if (destination.IsStackSlot()) { |
| 1401 | if (source.IsRegister()) { |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1402 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1403 | source.AsRegister<CpuRegister>()); |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1404 | } else if (source.IsFpuRegister()) { |
| 1405 | __ movss(Address(CpuRegister(RSP), destination.GetStackIndex()), |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1406 | source.AsFpuRegister<XmmRegister>()); |
| Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 1407 | } else if (source.IsConstant()) { |
| 1408 | HConstant* constant = source.GetConstant(); |
| Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1409 | int32_t value = GetInt32ValueOf(constant); |
| Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 1410 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), Immediate(value)); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1411 | } else { |
| Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 1412 | DCHECK(source.IsStackSlot()) << source; |
| Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 1413 | __ movl(CpuRegister(TMP), Address(CpuRegister(RSP), source.GetStackIndex())); |
| 1414 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), CpuRegister(TMP)); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1415 | } |
| 1416 | } else { |
| 1417 | DCHECK(destination.IsDoubleStackSlot()); |
| 1418 | if (source.IsRegister()) { |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1419 | __ movq(Address(CpuRegister(RSP), destination.GetStackIndex()), |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1420 | source.AsRegister<CpuRegister>()); |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1421 | } else if (source.IsFpuRegister()) { |
| 1422 | __ movsd(Address(CpuRegister(RSP), destination.GetStackIndex()), |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1423 | source.AsFpuRegister<XmmRegister>()); |
| Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 1424 | } else if (source.IsConstant()) { |
| 1425 | HConstant* constant = source.GetConstant(); |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 1426 | DCHECK(constant->IsLongConstant() || constant->IsDoubleConstant()); |
| 1427 | int64_t value = GetInt64ValueOf(constant); |
| Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 1428 | Store64BitValueToStack(destination, value); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1429 | } else { |
| 1430 | DCHECK(source.IsDoubleStackSlot()); |
| Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 1431 | __ movq(CpuRegister(TMP), Address(CpuRegister(RSP), source.GetStackIndex())); |
| 1432 | __ movq(Address(CpuRegister(RSP), destination.GetStackIndex()), CpuRegister(TMP)); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1433 | } |
| 1434 | } |
| 1435 | } |
| 1436 | |
| Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1437 | void CodeGeneratorX86_64::MoveConstant(Location location, int32_t value) { |
| 1438 | DCHECK(location.IsRegister()); |
| 1439 | Load64BitValue(location.AsRegister<CpuRegister>(), static_cast<int64_t>(value)); |
| 1440 | } |
| 1441 | |
| Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1442 | void CodeGeneratorX86_64::MoveLocation( |
| 1443 | Location dst, Location src, Primitive::Type dst_type ATTRIBUTE_UNUSED) { |
| 1444 | Move(dst, src); |
| 1445 | } |
| 1446 | |
| 1447 | void CodeGeneratorX86_64::AddLocationAsTemp(Location location, LocationSummary* locations) { |
| 1448 | if (location.IsRegister()) { |
| 1449 | locations->AddTemp(location); |
| 1450 | } else { |
| 1451 | UNIMPLEMENTED(FATAL) << "AddLocationAsTemp not implemented for location " << location; |
| 1452 | } |
| 1453 | } |
| 1454 | |
| David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1455 | void InstructionCodeGeneratorX86_64::HandleGoto(HInstruction* got, HBasicBlock* successor) { |
| Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1456 | DCHECK(!successor->IsExitBlock()); |
| 1457 | |
| 1458 | HBasicBlock* block = got->GetBlock(); |
| 1459 | HInstruction* previous = got->GetPrevious(); |
| 1460 | |
| 1461 | HLoopInformation* info = block->GetLoopInformation(); |
| David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1462 | if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) { |
| Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1463 | GenerateSuspendCheck(info->GetSuspendCheck(), successor); |
| 1464 | return; |
| 1465 | } |
| 1466 | |
| 1467 | if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) { |
| 1468 | GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr); |
| 1469 | } |
| 1470 | if (!codegen_->GoesToNextBlock(got->GetBlock(), successor)) { |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1471 | __ jmp(codegen_->GetLabelOf(successor)); |
| 1472 | } |
| 1473 | } |
| 1474 | |
| David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1475 | void LocationsBuilderX86_64::VisitGoto(HGoto* got) { |
| 1476 | got->SetLocations(nullptr); |
| 1477 | } |
| 1478 | |
| 1479 | void InstructionCodeGeneratorX86_64::VisitGoto(HGoto* got) { |
| 1480 | HandleGoto(got, got->GetSuccessor()); |
| 1481 | } |
| 1482 | |
| 1483 | void LocationsBuilderX86_64::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 1484 | try_boundary->SetLocations(nullptr); |
| 1485 | } |
| 1486 | |
| 1487 | void InstructionCodeGeneratorX86_64::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 1488 | HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor(); |
| 1489 | if (!successor->IsExitBlock()) { |
| 1490 | HandleGoto(try_boundary, successor); |
| 1491 | } |
| 1492 | } |
| 1493 | |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1494 | void LocationsBuilderX86_64::VisitExit(HExit* exit) { |
| 1495 | exit->SetLocations(nullptr); |
| 1496 | } |
| 1497 | |
| Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1498 | void InstructionCodeGeneratorX86_64::VisitExit(HExit* exit ATTRIBUTE_UNUSED) { |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1499 | } |
| 1500 | |
| Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1501 | template<class LabelType> |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1502 | void InstructionCodeGeneratorX86_64::GenerateFPJumps(HCondition* cond, |
| Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1503 | LabelType* true_label, |
| 1504 | LabelType* false_label) { |
| Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1505 | if (cond->IsFPConditionTrueIfNaN()) { |
| 1506 | __ j(kUnordered, true_label); |
| 1507 | } else if (cond->IsFPConditionFalseIfNaN()) { |
| 1508 | __ j(kUnordered, false_label); |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1509 | } |
| Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1510 | __ j(X86_64FPCondition(cond->GetCondition()), true_label); |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1511 | } |
| 1512 | |
| Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1513 | void InstructionCodeGeneratorX86_64::GenerateCompareTest(HCondition* condition) { |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1514 | LocationSummary* locations = condition->GetLocations(); |
| Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1515 | |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1516 | Location left = locations->InAt(0); |
| 1517 | Location right = locations->InAt(1); |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1518 | Primitive::Type type = condition->InputAt(0)->GetType(); |
| 1519 | switch (type) { |
| Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1520 | case Primitive::kPrimBoolean: |
| 1521 | case Primitive::kPrimByte: |
| 1522 | case Primitive::kPrimChar: |
| 1523 | case Primitive::kPrimShort: |
| 1524 | case Primitive::kPrimInt: |
| 1525 | case Primitive::kPrimNot: { |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 1526 | codegen_->GenerateIntCompare(left, right); |
| Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1527 | break; |
| 1528 | } |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1529 | case Primitive::kPrimLong: { |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 1530 | codegen_->GenerateLongCompare(left, right); |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1531 | break; |
| 1532 | } |
| 1533 | case Primitive::kPrimFloat: { |
| 1534 | if (right.IsFpuRegister()) { |
| 1535 | __ ucomiss(left.AsFpuRegister<XmmRegister>(), right.AsFpuRegister<XmmRegister>()); |
| 1536 | } else if (right.IsConstant()) { |
| 1537 | __ ucomiss(left.AsFpuRegister<XmmRegister>(), |
| 1538 | codegen_->LiteralFloatAddress( |
| 1539 | right.GetConstant()->AsFloatConstant()->GetValue())); |
| 1540 | } else { |
| 1541 | DCHECK(right.IsStackSlot()); |
| 1542 | __ ucomiss(left.AsFpuRegister<XmmRegister>(), |
| 1543 | Address(CpuRegister(RSP), right.GetStackIndex())); |
| 1544 | } |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1545 | break; |
| 1546 | } |
| 1547 | case Primitive::kPrimDouble: { |
| 1548 | if (right.IsFpuRegister()) { |
| 1549 | __ ucomisd(left.AsFpuRegister<XmmRegister>(), right.AsFpuRegister<XmmRegister>()); |
| 1550 | } else if (right.IsConstant()) { |
| 1551 | __ ucomisd(left.AsFpuRegister<XmmRegister>(), |
| 1552 | codegen_->LiteralDoubleAddress( |
| 1553 | right.GetConstant()->AsDoubleConstant()->GetValue())); |
| 1554 | } else { |
| 1555 | DCHECK(right.IsDoubleStackSlot()); |
| 1556 | __ ucomisd(left.AsFpuRegister<XmmRegister>(), |
| 1557 | Address(CpuRegister(RSP), right.GetStackIndex())); |
| 1558 | } |
| Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1559 | break; |
| 1560 | } |
| 1561 | default: |
| 1562 | LOG(FATAL) << "Unexpected condition type " << type; |
| 1563 | } |
| 1564 | } |
| 1565 | |
| 1566 | template<class LabelType> |
| 1567 | void InstructionCodeGeneratorX86_64::GenerateCompareTestAndBranch(HCondition* condition, |
| 1568 | LabelType* true_target_in, |
| 1569 | LabelType* false_target_in) { |
| 1570 | // Generated branching requires both targets to be explicit. If either of the |
| 1571 | // targets is nullptr (fallthrough) use and bind `fallthrough_target` instead. |
| 1572 | LabelType fallthrough_target; |
| 1573 | LabelType* true_target = true_target_in == nullptr ? &fallthrough_target : true_target_in; |
| 1574 | LabelType* false_target = false_target_in == nullptr ? &fallthrough_target : false_target_in; |
| 1575 | |
| 1576 | // Generate the comparison to set the CC. |
| 1577 | GenerateCompareTest(condition); |
| 1578 | |
| 1579 | // Now generate the correct jump(s). |
| 1580 | Primitive::Type type = condition->InputAt(0)->GetType(); |
| 1581 | switch (type) { |
| 1582 | case Primitive::kPrimLong: { |
| 1583 | __ j(X86_64IntegerCondition(condition->GetCondition()), true_target); |
| 1584 | break; |
| 1585 | } |
| 1586 | case Primitive::kPrimFloat: { |
| 1587 | GenerateFPJumps(condition, true_target, false_target); |
| 1588 | break; |
| 1589 | } |
| 1590 | case Primitive::kPrimDouble: { |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1591 | GenerateFPJumps(condition, true_target, false_target); |
| 1592 | break; |
| 1593 | } |
| 1594 | default: |
| 1595 | LOG(FATAL) << "Unexpected condition type " << type; |
| 1596 | } |
| 1597 | |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1598 | if (false_target != &fallthrough_target) { |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1599 | __ jmp(false_target); |
| 1600 | } |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1601 | |
| 1602 | if (fallthrough_target.IsLinked()) { |
| 1603 | __ Bind(&fallthrough_target); |
| 1604 | } |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1605 | } |
| 1606 | |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1607 | static bool AreEflagsSetFrom(HInstruction* cond, HInstruction* branch) { |
| 1608 | // Moves may affect the eflags register (move zero uses xorl), so the EFLAGS |
| 1609 | // are set only strictly before `branch`. We can't use the eflags on long |
| 1610 | // conditions if they are materialized due to the complex branching. |
| 1611 | return cond->IsCondition() && |
| 1612 | cond->GetNext() == branch && |
| 1613 | !Primitive::IsFloatingPointType(cond->InputAt(0)->GetType()); |
| 1614 | } |
| 1615 | |
| Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1616 | template<class LabelType> |
| Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1617 | void InstructionCodeGeneratorX86_64::GenerateTestAndBranch(HInstruction* instruction, |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1618 | size_t condition_input_index, |
| Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1619 | LabelType* true_target, |
| 1620 | LabelType* false_target) { |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1621 | HInstruction* cond = instruction->InputAt(condition_input_index); |
| 1622 | |
| 1623 | if (true_target == nullptr && false_target == nullptr) { |
| 1624 | // Nothing to do. The code always falls through. |
| 1625 | return; |
| 1626 | } else if (cond->IsIntConstant()) { |
| Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 1627 | // Constant condition, statically compared against "true" (integer value 1). |
| 1628 | if (cond->AsIntConstant()->IsTrue()) { |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1629 | if (true_target != nullptr) { |
| 1630 | __ jmp(true_target); |
| Nicolas Geoffray | 18efde5 | 2014-09-22 15:51:11 +0100 | [diff] [blame] | 1631 | } |
| Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1632 | } else { |
| Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 1633 | DCHECK(cond->AsIntConstant()->IsFalse()) << cond->AsIntConstant()->GetValue(); |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1634 | if (false_target != nullptr) { |
| 1635 | __ jmp(false_target); |
| 1636 | } |
| 1637 | } |
| 1638 | return; |
| 1639 | } |
| 1640 | |
| 1641 | // The following code generates these patterns: |
| 1642 | // (1) true_target == nullptr && false_target != nullptr |
| 1643 | // - opposite condition true => branch to false_target |
| 1644 | // (2) true_target != nullptr && false_target == nullptr |
| 1645 | // - condition true => branch to true_target |
| 1646 | // (3) true_target != nullptr && false_target != nullptr |
| 1647 | // - condition true => branch to true_target |
| 1648 | // - branch to false_target |
| 1649 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
| 1650 | if (AreEflagsSetFrom(cond, instruction)) { |
| 1651 | if (true_target == nullptr) { |
| 1652 | __ j(X86_64IntegerCondition(cond->AsCondition()->GetOppositeCondition()), false_target); |
| 1653 | } else { |
| 1654 | __ j(X86_64IntegerCondition(cond->AsCondition()->GetCondition()), true_target); |
| 1655 | } |
| 1656 | } else { |
| 1657 | // Materialized condition, compare against 0. |
| 1658 | Location lhs = instruction->GetLocations()->InAt(condition_input_index); |
| 1659 | if (lhs.IsRegister()) { |
| 1660 | __ testl(lhs.AsRegister<CpuRegister>(), lhs.AsRegister<CpuRegister>()); |
| 1661 | } else { |
| 1662 | __ cmpl(Address(CpuRegister(RSP), lhs.GetStackIndex()), Immediate(0)); |
| 1663 | } |
| 1664 | if (true_target == nullptr) { |
| 1665 | __ j(kEqual, false_target); |
| 1666 | } else { |
| 1667 | __ j(kNotEqual, true_target); |
| 1668 | } |
| Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1669 | } |
| 1670 | } else { |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1671 | // Condition has not been materialized, use its inputs as the |
| 1672 | // comparison and its condition as the branch condition. |
| Mark Mendell | b8b9769 | 2015-05-22 16:58:19 -0400 | [diff] [blame] | 1673 | HCondition* condition = cond->AsCondition(); |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1674 | |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1675 | // If this is a long or FP comparison that has been folded into |
| 1676 | // the HCondition, generate the comparison directly. |
| 1677 | Primitive::Type type = condition->InputAt(0)->GetType(); |
| 1678 | if (type == Primitive::kPrimLong || Primitive::IsFloatingPointType(type)) { |
| 1679 | GenerateCompareTestAndBranch(condition, true_target, false_target); |
| 1680 | return; |
| 1681 | } |
| 1682 | |
| 1683 | Location lhs = condition->GetLocations()->InAt(0); |
| 1684 | Location rhs = condition->GetLocations()->InAt(1); |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 1685 | codegen_->GenerateIntCompare(lhs, rhs); |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1686 | if (true_target == nullptr) { |
| 1687 | __ j(X86_64IntegerCondition(condition->GetOppositeCondition()), false_target); |
| 1688 | } else { |
| Mark Mendell | b8b9769 | 2015-05-22 16:58:19 -0400 | [diff] [blame] | 1689 | __ j(X86_64IntegerCondition(condition->GetCondition()), true_target); |
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1690 | } |
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1691 | } |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1692 | |
| 1693 | // If neither branch falls through (case 3), the conditional branch to `true_target` |
| 1694 | // was already emitted (case 2) and we need to emit a jump to `false_target`. |
| 1695 | if (true_target != nullptr && false_target != nullptr) { |
| Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1696 | __ jmp(false_target); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1697 | } |
| 1698 | } |
| 1699 | |
| Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1700 | void LocationsBuilderX86_64::VisitIf(HIf* if_instr) { |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1701 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(if_instr); |
| 1702 | if (IsBooleanValueOrMaterializedCondition(if_instr->InputAt(0))) { |
| Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1703 | locations->SetInAt(0, Location::Any()); |
| 1704 | } |
| 1705 | } |
| 1706 | |
| 1707 | void InstructionCodeGeneratorX86_64::VisitIf(HIf* if_instr) { |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1708 | HBasicBlock* true_successor = if_instr->IfTrueSuccessor(); |
| 1709 | HBasicBlock* false_successor = if_instr->IfFalseSuccessor(); |
| 1710 | Label* true_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), true_successor) ? |
| 1711 | nullptr : codegen_->GetLabelOf(true_successor); |
| 1712 | Label* false_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), false_successor) ? |
| 1713 | nullptr : codegen_->GetLabelOf(false_successor); |
| 1714 | GenerateTestAndBranch(if_instr, /* condition_input_index */ 0, true_target, false_target); |
| Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1715 | } |
| 1716 | |
| 1717 | void LocationsBuilderX86_64::VisitDeoptimize(HDeoptimize* deoptimize) { |
| 1718 | LocationSummary* locations = new (GetGraph()->GetArena()) |
| 1719 | LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath); |
| Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 1720 | InvokeRuntimeCallingConvention calling_convention; |
| 1721 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 1722 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 1723 | locations->SetCustomSlowPathCallerSaves(caller_saves); |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1724 | if (IsBooleanValueOrMaterializedCondition(deoptimize->InputAt(0))) { |
| Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1725 | locations->SetInAt(0, Location::Any()); |
| 1726 | } |
| 1727 | } |
| 1728 | |
| 1729 | void InstructionCodeGeneratorX86_64::VisitDeoptimize(HDeoptimize* deoptimize) { |
| Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 1730 | SlowPathCode* slow_path = deopt_slow_paths_.NewSlowPath<DeoptimizationSlowPathX86_64>(deoptimize); |
| David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1731 | GenerateTestAndBranch<Label>(deoptimize, |
| 1732 | /* condition_input_index */ 0, |
| 1733 | slow_path->GetEntryLabel(), |
| 1734 | /* false_target */ nullptr); |
| 1735 | } |
| 1736 | |
| Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 1737 | void LocationsBuilderX86_64::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) { |
| 1738 | LocationSummary* locations = new (GetGraph()->GetArena()) |
| 1739 | LocationSummary(flag, LocationSummary::kNoCall); |
| 1740 | locations->SetOut(Location::RequiresRegister()); |
| 1741 | } |
| 1742 | |
| 1743 | void InstructionCodeGeneratorX86_64::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) { |
| 1744 | __ movl(flag->GetLocations()->Out().AsRegister<CpuRegister>(), |
| 1745 | Address(CpuRegister(RSP), codegen_->GetStackOffsetOfShouldDeoptimizeFlag())); |
| 1746 | } |
| 1747 | |
| Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1748 | static bool SelectCanUseCMOV(HSelect* select) { |
| 1749 | // There are no conditional move instructions for XMMs. |
| 1750 | if (Primitive::IsFloatingPointType(select->GetType())) { |
| 1751 | return false; |
| 1752 | } |
| 1753 | |
| 1754 | // A FP condition doesn't generate the single CC that we need. |
| 1755 | HInstruction* condition = select->GetCondition(); |
| 1756 | if (condition->IsCondition() && |
| 1757 | Primitive::IsFloatingPointType(condition->InputAt(0)->GetType())) { |
| 1758 | return false; |
| 1759 | } |
| 1760 | |
| 1761 | // We can generate a CMOV for this Select. |
| 1762 | return true; |
| 1763 | } |
| 1764 | |
| David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1765 | void LocationsBuilderX86_64::VisitSelect(HSelect* select) { |
| 1766 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(select); |
| 1767 | if (Primitive::IsFloatingPointType(select->GetType())) { |
| 1768 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1769 | locations->SetInAt(1, Location::Any()); |
| David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1770 | } else { |
| 1771 | locations->SetInAt(0, Location::RequiresRegister()); |
| Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1772 | if (SelectCanUseCMOV(select)) { |
| Mark Mendell | dee1b9a | 2016-02-12 14:36:51 -0500 | [diff] [blame] | 1773 | if (select->InputAt(1)->IsConstant()) { |
| 1774 | locations->SetInAt(1, Location::RequiresRegister()); |
| 1775 | } else { |
| 1776 | locations->SetInAt(1, Location::Any()); |
| 1777 | } |
| Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1778 | } else { |
| Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1779 | locations->SetInAt(1, Location::Any()); |
| 1780 | } |
| David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1781 | } |
| 1782 | if (IsBooleanValueOrMaterializedCondition(select->GetCondition())) { |
| 1783 | locations->SetInAt(2, Location::RequiresRegister()); |
| 1784 | } |
| 1785 | locations->SetOut(Location::SameAsFirstInput()); |
| 1786 | } |
| 1787 | |
| 1788 | void InstructionCodeGeneratorX86_64::VisitSelect(HSelect* select) { |
| 1789 | LocationSummary* locations = select->GetLocations(); |
| Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1790 | if (SelectCanUseCMOV(select)) { |
| 1791 | // If both the condition and the source types are integer, we can generate |
| 1792 | // a CMOV to implement Select. |
| 1793 | CpuRegister value_false = locations->InAt(0).AsRegister<CpuRegister>(); |
| Mark Mendell | dee1b9a | 2016-02-12 14:36:51 -0500 | [diff] [blame] | 1794 | Location value_true_loc = locations->InAt(1); |
| Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1795 | DCHECK(locations->InAt(0).Equals(locations->Out())); |
| 1796 | |
| 1797 | HInstruction* select_condition = select->GetCondition(); |
| 1798 | Condition cond = kNotEqual; |
| 1799 | |
| 1800 | // Figure out how to test the 'condition'. |
| 1801 | if (select_condition->IsCondition()) { |
| 1802 | HCondition* condition = select_condition->AsCondition(); |
| 1803 | if (!condition->IsEmittedAtUseSite()) { |
| 1804 | // This was a previously materialized condition. |
| 1805 | // Can we use the existing condition code? |
| 1806 | if (AreEflagsSetFrom(condition, select)) { |
| 1807 | // Materialization was the previous instruction. Condition codes are right. |
| 1808 | cond = X86_64IntegerCondition(condition->GetCondition()); |
| 1809 | } else { |
| 1810 | // No, we have to recreate the condition code. |
| 1811 | CpuRegister cond_reg = locations->InAt(2).AsRegister<CpuRegister>(); |
| 1812 | __ testl(cond_reg, cond_reg); |
| 1813 | } |
| 1814 | } else { |
| 1815 | GenerateCompareTest(condition); |
| 1816 | cond = X86_64IntegerCondition(condition->GetCondition()); |
| 1817 | } |
| 1818 | } else { |
| Roland Levillain | 5e8d5f0 | 2016-10-18 18:03:43 +0100 | [diff] [blame] | 1819 | // Must be a Boolean condition, which needs to be compared to 0. |
| Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1820 | CpuRegister cond_reg = locations->InAt(2).AsRegister<CpuRegister>(); |
| 1821 | __ testl(cond_reg, cond_reg); |
| 1822 | } |
| 1823 | |
| 1824 | // If the condition is true, overwrite the output, which already contains false. |
| 1825 | // Generate the correct sized CMOV. |
| Mark Mendell | dee1b9a | 2016-02-12 14:36:51 -0500 | [diff] [blame] | 1826 | bool is_64_bit = Primitive::Is64BitType(select->GetType()); |
| 1827 | if (value_true_loc.IsRegister()) { |
| 1828 | __ cmov(cond, value_false, value_true_loc.AsRegister<CpuRegister>(), is_64_bit); |
| 1829 | } else { |
| 1830 | __ cmov(cond, |
| 1831 | value_false, |
| 1832 | Address(CpuRegister(RSP), value_true_loc.GetStackIndex()), is_64_bit); |
| 1833 | } |
| Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1834 | } else { |
| 1835 | NearLabel false_target; |
| 1836 | GenerateTestAndBranch<NearLabel>(select, |
| 1837 | /* condition_input_index */ 2, |
| 1838 | /* true_target */ nullptr, |
| 1839 | &false_target); |
| 1840 | codegen_->MoveLocation(locations->Out(), locations->InAt(1), select->GetType()); |
| 1841 | __ Bind(&false_target); |
| 1842 | } |
| Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1843 | } |
| 1844 | |
| David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 1845 | void LocationsBuilderX86_64::VisitNativeDebugInfo(HNativeDebugInfo* info) { |
| 1846 | new (GetGraph()->GetArena()) LocationSummary(info); |
| 1847 | } |
| 1848 | |
| David Srbecky | d28f4a0 | 2016-03-14 17:14:24 +0000 | [diff] [blame] | 1849 | void InstructionCodeGeneratorX86_64::VisitNativeDebugInfo(HNativeDebugInfo*) { |
| 1850 | // MaybeRecordNativeDebugInfo is already called implicitly in CodeGenerator::Compile. |
| David Srbecky | c7098ff | 2016-02-09 14:30:11 +0000 | [diff] [blame] | 1851 | } |
| 1852 | |
| 1853 | void CodeGeneratorX86_64::GenerateNop() { |
| 1854 | __ nop(); |
| David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 1855 | } |
| 1856 | |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1857 | void LocationsBuilderX86_64::HandleCondition(HCondition* cond) { |
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1858 | LocationSummary* locations = |
| Roland Levillain | 0d37cd0 | 2015-05-27 16:39:19 +0100 | [diff] [blame] | 1859 | new (GetGraph()->GetArena()) LocationSummary(cond, LocationSummary::kNoCall); |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1860 | // Handle the long/FP comparisons made in instruction simplification. |
| 1861 | switch (cond->InputAt(0)->GetType()) { |
| 1862 | case Primitive::kPrimLong: |
| 1863 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1864 | locations->SetInAt(1, Location::Any()); |
| 1865 | break; |
| 1866 | case Primitive::kPrimFloat: |
| 1867 | case Primitive::kPrimDouble: |
| 1868 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1869 | locations->SetInAt(1, Location::Any()); |
| 1870 | break; |
| 1871 | default: |
| 1872 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1873 | locations->SetInAt(1, Location::Any()); |
| 1874 | break; |
| 1875 | } |
| David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 1876 | if (!cond->IsEmittedAtUseSite()) { |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1877 | locations->SetOut(Location::RequiresRegister()); |
| 1878 | } |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1879 | } |
| 1880 | |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1881 | void InstructionCodeGeneratorX86_64::HandleCondition(HCondition* cond) { |
| David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 1882 | if (cond->IsEmittedAtUseSite()) { |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1883 | return; |
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1884 | } |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1885 | |
| 1886 | LocationSummary* locations = cond->GetLocations(); |
| 1887 | Location lhs = locations->InAt(0); |
| 1888 | Location rhs = locations->InAt(1); |
| 1889 | CpuRegister reg = locations->Out().AsRegister<CpuRegister>(); |
| Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1890 | NearLabel true_label, false_label; |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1891 | |
| 1892 | switch (cond->InputAt(0)->GetType()) { |
| 1893 | default: |
| 1894 | // Integer case. |
| 1895 | |
| 1896 | // Clear output register: setcc only sets the low byte. |
| 1897 | __ xorl(reg, reg); |
| 1898 | |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 1899 | codegen_->GenerateIntCompare(lhs, rhs); |
| Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1900 | __ setcc(X86_64IntegerCondition(cond->GetCondition()), reg); |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1901 | return; |
| 1902 | case Primitive::kPrimLong: |
| 1903 | // Clear output register: setcc only sets the low byte. |
| 1904 | __ xorl(reg, reg); |
| 1905 | |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 1906 | codegen_->GenerateLongCompare(lhs, rhs); |
| Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1907 | __ setcc(X86_64IntegerCondition(cond->GetCondition()), reg); |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1908 | return; |
| 1909 | case Primitive::kPrimFloat: { |
| 1910 | XmmRegister lhs_reg = lhs.AsFpuRegister<XmmRegister>(); |
| 1911 | if (rhs.IsConstant()) { |
| 1912 | float value = rhs.GetConstant()->AsFloatConstant()->GetValue(); |
| 1913 | __ ucomiss(lhs_reg, codegen_->LiteralFloatAddress(value)); |
| 1914 | } else if (rhs.IsStackSlot()) { |
| 1915 | __ ucomiss(lhs_reg, Address(CpuRegister(RSP), rhs.GetStackIndex())); |
| 1916 | } else { |
| 1917 | __ ucomiss(lhs_reg, rhs.AsFpuRegister<XmmRegister>()); |
| 1918 | } |
| 1919 | GenerateFPJumps(cond, &true_label, &false_label); |
| 1920 | break; |
| 1921 | } |
| 1922 | case Primitive::kPrimDouble: { |
| 1923 | XmmRegister lhs_reg = lhs.AsFpuRegister<XmmRegister>(); |
| 1924 | if (rhs.IsConstant()) { |
| 1925 | double value = rhs.GetConstant()->AsDoubleConstant()->GetValue(); |
| 1926 | __ ucomisd(lhs_reg, codegen_->LiteralDoubleAddress(value)); |
| 1927 | } else if (rhs.IsDoubleStackSlot()) { |
| 1928 | __ ucomisd(lhs_reg, Address(CpuRegister(RSP), rhs.GetStackIndex())); |
| 1929 | } else { |
| 1930 | __ ucomisd(lhs_reg, rhs.AsFpuRegister<XmmRegister>()); |
| 1931 | } |
| 1932 | GenerateFPJumps(cond, &true_label, &false_label); |
| 1933 | break; |
| 1934 | } |
| 1935 | } |
| 1936 | |
| 1937 | // Convert the jumps into the result. |
| Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 1938 | NearLabel done_label; |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1939 | |
| Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1940 | // False case: result = 0. |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1941 | __ Bind(&false_label); |
| 1942 | __ xorl(reg, reg); |
| 1943 | __ jmp(&done_label); |
| 1944 | |
| Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1945 | // True case: result = 1. |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1946 | __ Bind(&true_label); |
| 1947 | __ movl(reg, Immediate(1)); |
| 1948 | __ Bind(&done_label); |
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1949 | } |
| 1950 | |
| 1951 | void LocationsBuilderX86_64::VisitEqual(HEqual* comp) { |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1952 | HandleCondition(comp); |
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1953 | } |
| 1954 | |
| 1955 | void InstructionCodeGeneratorX86_64::VisitEqual(HEqual* comp) { |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1956 | HandleCondition(comp); |
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1957 | } |
| 1958 | |
| 1959 | void LocationsBuilderX86_64::VisitNotEqual(HNotEqual* comp) { |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1960 | HandleCondition(comp); |
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1961 | } |
| 1962 | |
| 1963 | void InstructionCodeGeneratorX86_64::VisitNotEqual(HNotEqual* comp) { |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1964 | HandleCondition(comp); |
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1965 | } |
| 1966 | |
| 1967 | void LocationsBuilderX86_64::VisitLessThan(HLessThan* comp) { |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1968 | HandleCondition(comp); |
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1969 | } |
| 1970 | |
| 1971 | void InstructionCodeGeneratorX86_64::VisitLessThan(HLessThan* comp) { |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1972 | HandleCondition(comp); |
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1973 | } |
| 1974 | |
| 1975 | void LocationsBuilderX86_64::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1976 | HandleCondition(comp); |
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1977 | } |
| 1978 | |
| 1979 | void InstructionCodeGeneratorX86_64::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1980 | HandleCondition(comp); |
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1981 | } |
| 1982 | |
| 1983 | void LocationsBuilderX86_64::VisitGreaterThan(HGreaterThan* comp) { |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1984 | HandleCondition(comp); |
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1985 | } |
| 1986 | |
| 1987 | void InstructionCodeGeneratorX86_64::VisitGreaterThan(HGreaterThan* comp) { |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1988 | HandleCondition(comp); |
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1989 | } |
| 1990 | |
| 1991 | void LocationsBuilderX86_64::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1992 | HandleCondition(comp); |
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1993 | } |
| 1994 | |
| 1995 | void InstructionCodeGeneratorX86_64::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1996 | HandleCondition(comp); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1997 | } |
| 1998 | |
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1999 | void LocationsBuilderX86_64::VisitBelow(HBelow* comp) { |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2000 | HandleCondition(comp); |
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2001 | } |
| 2002 | |
| 2003 | void InstructionCodeGeneratorX86_64::VisitBelow(HBelow* comp) { |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2004 | HandleCondition(comp); |
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2005 | } |
| 2006 | |
| 2007 | void LocationsBuilderX86_64::VisitBelowOrEqual(HBelowOrEqual* comp) { |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2008 | HandleCondition(comp); |
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2009 | } |
| 2010 | |
| 2011 | void InstructionCodeGeneratorX86_64::VisitBelowOrEqual(HBelowOrEqual* comp) { |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2012 | HandleCondition(comp); |
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2013 | } |
| 2014 | |
| 2015 | void LocationsBuilderX86_64::VisitAbove(HAbove* comp) { |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2016 | HandleCondition(comp); |
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2017 | } |
| 2018 | |
| 2019 | void InstructionCodeGeneratorX86_64::VisitAbove(HAbove* comp) { |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2020 | HandleCondition(comp); |
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2021 | } |
| 2022 | |
| 2023 | void LocationsBuilderX86_64::VisitAboveOrEqual(HAboveOrEqual* comp) { |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2024 | HandleCondition(comp); |
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2025 | } |
| 2026 | |
| 2027 | void InstructionCodeGeneratorX86_64::VisitAboveOrEqual(HAboveOrEqual* comp) { |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2028 | HandleCondition(comp); |
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2029 | } |
| 2030 | |
| Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 2031 | void LocationsBuilderX86_64::VisitCompare(HCompare* compare) { |
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2032 | LocationSummary* locations = |
| 2033 | new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall); |
| Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2034 | switch (compare->InputAt(0)->GetType()) { |
| Roland Levillain | a5c4a40 | 2016-03-15 15:02:50 +0000 | [diff] [blame] | 2035 | case Primitive::kPrimBoolean: |
| 2036 | case Primitive::kPrimByte: |
| 2037 | case Primitive::kPrimShort: |
| 2038 | case Primitive::kPrimChar: |
| Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 2039 | case Primitive::kPrimInt: |
| Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2040 | case Primitive::kPrimLong: { |
| 2041 | locations->SetInAt(0, Location::RequiresRegister()); |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2042 | locations->SetInAt(1, Location::Any()); |
| Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2043 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2044 | break; |
| 2045 | } |
| 2046 | case Primitive::kPrimFloat: |
| 2047 | case Primitive::kPrimDouble: { |
| 2048 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2049 | locations->SetInAt(1, Location::Any()); |
| Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2050 | locations->SetOut(Location::RequiresRegister()); |
| 2051 | break; |
| 2052 | } |
| 2053 | default: |
| 2054 | LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType(); |
| 2055 | } |
| Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 2056 | } |
| 2057 | |
| 2058 | void InstructionCodeGeneratorX86_64::VisitCompare(HCompare* compare) { |
| Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 2059 | LocationSummary* locations = compare->GetLocations(); |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2060 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
| Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2061 | Location left = locations->InAt(0); |
| 2062 | Location right = locations->InAt(1); |
| 2063 | |
| Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2064 | NearLabel less, greater, done; |
| Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2065 | Primitive::Type type = compare->InputAt(0)->GetType(); |
| Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 2066 | Condition less_cond = kLess; |
| 2067 | |
| Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2068 | switch (type) { |
| Roland Levillain | a5c4a40 | 2016-03-15 15:02:50 +0000 | [diff] [blame] | 2069 | case Primitive::kPrimBoolean: |
| 2070 | case Primitive::kPrimByte: |
| 2071 | case Primitive::kPrimShort: |
| 2072 | case Primitive::kPrimChar: |
| Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 2073 | case Primitive::kPrimInt: { |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 2074 | codegen_->GenerateIntCompare(left, right); |
| Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 2075 | break; |
| 2076 | } |
| Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2077 | case Primitive::kPrimLong: { |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 2078 | codegen_->GenerateLongCompare(left, right); |
| Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 2079 | break; |
| Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2080 | } |
| 2081 | case Primitive::kPrimFloat: { |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2082 | XmmRegister left_reg = left.AsFpuRegister<XmmRegister>(); |
| 2083 | if (right.IsConstant()) { |
| 2084 | float value = right.GetConstant()->AsFloatConstant()->GetValue(); |
| 2085 | __ ucomiss(left_reg, codegen_->LiteralFloatAddress(value)); |
| 2086 | } else if (right.IsStackSlot()) { |
| 2087 | __ ucomiss(left_reg, Address(CpuRegister(RSP), right.GetStackIndex())); |
| 2088 | } else { |
| 2089 | __ ucomiss(left_reg, right.AsFpuRegister<XmmRegister>()); |
| 2090 | } |
| Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2091 | __ j(kUnordered, compare->IsGtBias() ? &greater : &less); |
| Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 2092 | less_cond = kBelow; // ucomis{s,d} sets CF |
| Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2093 | break; |
| 2094 | } |
| 2095 | case Primitive::kPrimDouble: { |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2096 | XmmRegister left_reg = left.AsFpuRegister<XmmRegister>(); |
| 2097 | if (right.IsConstant()) { |
| 2098 | double value = right.GetConstant()->AsDoubleConstant()->GetValue(); |
| 2099 | __ ucomisd(left_reg, codegen_->LiteralDoubleAddress(value)); |
| 2100 | } else if (right.IsDoubleStackSlot()) { |
| 2101 | __ ucomisd(left_reg, Address(CpuRegister(RSP), right.GetStackIndex())); |
| 2102 | } else { |
| 2103 | __ ucomisd(left_reg, right.AsFpuRegister<XmmRegister>()); |
| 2104 | } |
| Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2105 | __ j(kUnordered, compare->IsGtBias() ? &greater : &less); |
| Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 2106 | less_cond = kBelow; // ucomis{s,d} sets CF |
| Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2107 | break; |
| 2108 | } |
| Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 2109 | default: |
| Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2110 | LOG(FATAL) << "Unexpected compare type " << type; |
| Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 2111 | } |
| Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 2112 | |
| Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2113 | __ movl(out, Immediate(0)); |
| Calin Juravle | 91debbc | 2014-11-26 19:01:09 +0000 | [diff] [blame] | 2114 | __ j(kEqual, &done); |
| Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 2115 | __ j(less_cond, &less); |
| Calin Juravle | fd86124 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2116 | |
| Calin Juravle | 91debbc | 2014-11-26 19:01:09 +0000 | [diff] [blame] | 2117 | __ Bind(&greater); |
| Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2118 | __ movl(out, Immediate(1)); |
| 2119 | __ jmp(&done); |
| 2120 | |
| 2121 | __ Bind(&less); |
| 2122 | __ movl(out, Immediate(-1)); |
| Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 2123 | |
| 2124 | __ Bind(&done); |
| 2125 | } |
| 2126 | |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2127 | void LocationsBuilderX86_64::VisitIntConstant(HIntConstant* constant) { |
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2128 | LocationSummary* locations = |
| 2129 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2130 | locations->SetOut(Location::ConstantLocation(constant)); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2131 | } |
| 2132 | |
| Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2133 | void InstructionCodeGeneratorX86_64::VisitIntConstant(HIntConstant* constant ATTRIBUTE_UNUSED) { |
| Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 2134 | // Will be generated at use site. |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2135 | } |
| 2136 | |
| Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 2137 | void LocationsBuilderX86_64::VisitNullConstant(HNullConstant* constant) { |
| 2138 | LocationSummary* locations = |
| 2139 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 2140 | locations->SetOut(Location::ConstantLocation(constant)); |
| 2141 | } |
| 2142 | |
| Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2143 | void InstructionCodeGeneratorX86_64::VisitNullConstant(HNullConstant* constant ATTRIBUTE_UNUSED) { |
| Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 2144 | // Will be generated at use site. |
| Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 2145 | } |
| 2146 | |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2147 | void LocationsBuilderX86_64::VisitLongConstant(HLongConstant* constant) { |
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2148 | LocationSummary* locations = |
| 2149 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2150 | locations->SetOut(Location::ConstantLocation(constant)); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2151 | } |
| 2152 | |
| Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2153 | void InstructionCodeGeneratorX86_64::VisitLongConstant(HLongConstant* constant ATTRIBUTE_UNUSED) { |
| Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 2154 | // Will be generated at use site. |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2155 | } |
| 2156 | |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2157 | void LocationsBuilderX86_64::VisitFloatConstant(HFloatConstant* constant) { |
| 2158 | LocationSummary* locations = |
| 2159 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 2160 | locations->SetOut(Location::ConstantLocation(constant)); |
| 2161 | } |
| 2162 | |
| Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2163 | void InstructionCodeGeneratorX86_64::VisitFloatConstant(HFloatConstant* constant ATTRIBUTE_UNUSED) { |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2164 | // Will be generated at use site. |
| 2165 | } |
| 2166 | |
| 2167 | void LocationsBuilderX86_64::VisitDoubleConstant(HDoubleConstant* constant) { |
| 2168 | LocationSummary* locations = |
| 2169 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 2170 | locations->SetOut(Location::ConstantLocation(constant)); |
| 2171 | } |
| 2172 | |
| Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2173 | void InstructionCodeGeneratorX86_64::VisitDoubleConstant( |
| 2174 | HDoubleConstant* constant ATTRIBUTE_UNUSED) { |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2175 | // Will be generated at use site. |
| 2176 | } |
| 2177 | |
| Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 2178 | void LocationsBuilderX86_64::VisitConstructorFence(HConstructorFence* constructor_fence) { |
| 2179 | constructor_fence->SetLocations(nullptr); |
| 2180 | } |
| 2181 | |
| 2182 | void InstructionCodeGeneratorX86_64::VisitConstructorFence( |
| 2183 | HConstructorFence* constructor_fence ATTRIBUTE_UNUSED) { |
| 2184 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kStoreStore); |
| 2185 | } |
| 2186 | |
| Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 2187 | void LocationsBuilderX86_64::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 2188 | memory_barrier->SetLocations(nullptr); |
| 2189 | } |
| 2190 | |
| 2191 | void InstructionCodeGeneratorX86_64::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 2192 | codegen_->GenerateMemoryBarrier(memory_barrier->GetBarrierKind()); |
| Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 2193 | } |
| 2194 | |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2195 | void LocationsBuilderX86_64::VisitReturnVoid(HReturnVoid* ret) { |
| 2196 | ret->SetLocations(nullptr); |
| 2197 | } |
| 2198 | |
| Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2199 | void InstructionCodeGeneratorX86_64::VisitReturnVoid(HReturnVoid* ret ATTRIBUTE_UNUSED) { |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2200 | codegen_->GenerateFrameExit(); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2201 | } |
| 2202 | |
| 2203 | void LocationsBuilderX86_64::VisitReturn(HReturn* ret) { |
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2204 | LocationSummary* locations = |
| 2205 | new (GetGraph()->GetArena()) LocationSummary(ret, LocationSummary::kNoCall); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2206 | switch (ret->InputAt(0)->GetType()) { |
| 2207 | case Primitive::kPrimBoolean: |
| 2208 | case Primitive::kPrimByte: |
| 2209 | case Primitive::kPrimChar: |
| 2210 | case Primitive::kPrimShort: |
| 2211 | case Primitive::kPrimInt: |
| 2212 | case Primitive::kPrimNot: |
| 2213 | case Primitive::kPrimLong: |
| Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2214 | locations->SetInAt(0, Location::RegisterLocation(RAX)); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2215 | break; |
| 2216 | |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2217 | case Primitive::kPrimFloat: |
| 2218 | case Primitive::kPrimDouble: |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2219 | locations->SetInAt(0, Location::FpuRegisterLocation(XMM0)); |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2220 | break; |
| 2221 | |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2222 | default: |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2223 | LOG(FATAL) << "Unexpected return type " << ret->InputAt(0)->GetType(); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2224 | } |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2225 | } |
| 2226 | |
| 2227 | void InstructionCodeGeneratorX86_64::VisitReturn(HReturn* ret) { |
| 2228 | if (kIsDebugBuild) { |
| 2229 | switch (ret->InputAt(0)->GetType()) { |
| 2230 | case Primitive::kPrimBoolean: |
| 2231 | case Primitive::kPrimByte: |
| 2232 | case Primitive::kPrimChar: |
| 2233 | case Primitive::kPrimShort: |
| 2234 | case Primitive::kPrimInt: |
| 2235 | case Primitive::kPrimNot: |
| 2236 | case Primitive::kPrimLong: |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2237 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsRegister<CpuRegister>().AsRegister(), RAX); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2238 | break; |
| 2239 | |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2240 | case Primitive::kPrimFloat: |
| 2241 | case Primitive::kPrimDouble: |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2242 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsFpuRegister<XmmRegister>().AsFloatRegister(), |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2243 | XMM0); |
| 2244 | break; |
| 2245 | |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2246 | default: |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2247 | LOG(FATAL) << "Unexpected return type " << ret->InputAt(0)->GetType(); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2248 | } |
| 2249 | } |
| 2250 | codegen_->GenerateFrameExit(); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2251 | } |
| 2252 | |
| Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 2253 | Location InvokeDexCallingConventionVisitorX86_64::GetReturnLocation(Primitive::Type type) const { |
| 2254 | switch (type) { |
| 2255 | case Primitive::kPrimBoolean: |
| 2256 | case Primitive::kPrimByte: |
| 2257 | case Primitive::kPrimChar: |
| 2258 | case Primitive::kPrimShort: |
| 2259 | case Primitive::kPrimInt: |
| 2260 | case Primitive::kPrimNot: |
| 2261 | case Primitive::kPrimLong: |
| 2262 | return Location::RegisterLocation(RAX); |
| 2263 | |
| 2264 | case Primitive::kPrimVoid: |
| 2265 | return Location::NoLocation(); |
| 2266 | |
| 2267 | case Primitive::kPrimDouble: |
| 2268 | case Primitive::kPrimFloat: |
| 2269 | return Location::FpuRegisterLocation(XMM0); |
| 2270 | } |
| Nicolas Geoffray | 0d1652e | 2015-06-03 12:12:19 +0100 | [diff] [blame] | 2271 | |
| 2272 | UNREACHABLE(); |
| Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 2273 | } |
| 2274 | |
| 2275 | Location InvokeDexCallingConventionVisitorX86_64::GetMethodLocation() const { |
| 2276 | return Location::RegisterLocation(kMethodRegisterArgument); |
| 2277 | } |
| 2278 | |
| Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 2279 | Location InvokeDexCallingConventionVisitorX86_64::GetNextLocation(Primitive::Type type) { |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2280 | switch (type) { |
| 2281 | case Primitive::kPrimBoolean: |
| 2282 | case Primitive::kPrimByte: |
| 2283 | case Primitive::kPrimChar: |
| 2284 | case Primitive::kPrimShort: |
| 2285 | case Primitive::kPrimInt: |
| 2286 | case Primitive::kPrimNot: { |
| 2287 | uint32_t index = gp_index_++; |
| 2288 | stack_index_++; |
| 2289 | if (index < calling_convention.GetNumberOfRegisters()) { |
| Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2290 | return Location::RegisterLocation(calling_convention.GetRegisterAt(index)); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2291 | } else { |
| 2292 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 1)); |
| 2293 | } |
| 2294 | } |
| 2295 | |
| 2296 | case Primitive::kPrimLong: { |
| 2297 | uint32_t index = gp_index_; |
| 2298 | stack_index_ += 2; |
| 2299 | if (index < calling_convention.GetNumberOfRegisters()) { |
| 2300 | gp_index_ += 1; |
| Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2301 | return Location::RegisterLocation(calling_convention.GetRegisterAt(index)); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2302 | } else { |
| 2303 | gp_index_ += 2; |
| 2304 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 2)); |
| 2305 | } |
| 2306 | } |
| 2307 | |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2308 | case Primitive::kPrimFloat: { |
| Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 2309 | uint32_t index = float_index_++; |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2310 | stack_index_++; |
| 2311 | if (index < calling_convention.GetNumberOfFpuRegisters()) { |
| Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2312 | return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(index)); |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2313 | } else { |
| 2314 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 1)); |
| 2315 | } |
| 2316 | } |
| 2317 | |
| 2318 | case Primitive::kPrimDouble: { |
| Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 2319 | uint32_t index = float_index_++; |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2320 | stack_index_ += 2; |
| 2321 | if (index < calling_convention.GetNumberOfFpuRegisters()) { |
| Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2322 | return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(index)); |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2323 | } else { |
| 2324 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 2)); |
| 2325 | } |
| 2326 | } |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2327 | |
| 2328 | case Primitive::kPrimVoid: |
| 2329 | LOG(FATAL) << "Unexpected parameter type " << type; |
| 2330 | break; |
| 2331 | } |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2332 | return Location::NoLocation(); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2333 | } |
| 2334 | |
| Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 2335 | void LocationsBuilderX86_64::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 2336 | // The trampoline uses the same calling convention as dex calling conventions, |
| 2337 | // except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain |
| 2338 | // the method_idx. |
| 2339 | HandleInvoke(invoke); |
| 2340 | } |
| 2341 | |
| 2342 | void InstructionCodeGeneratorX86_64::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 2343 | codegen_->GenerateInvokeUnresolvedRuntimeCall(invoke); |
| 2344 | } |
| 2345 | |
| Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 2346 | void LocationsBuilderX86_64::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
| David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 2347 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 2348 | // art::PrepareForRegisterAllocation. |
| 2349 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
| Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 2350 | |
| Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 2351 | IntrinsicLocationsBuilderX86_64 intrinsic(codegen_); |
| Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 2352 | if (intrinsic.TryDispatch(invoke)) { |
| 2353 | return; |
| 2354 | } |
| 2355 | |
| Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2356 | HandleInvoke(invoke); |
| 2357 | } |
| 2358 | |
| Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 2359 | static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorX86_64* codegen) { |
| 2360 | if (invoke->GetLocations()->Intrinsified()) { |
| 2361 | IntrinsicCodeGeneratorX86_64 intrinsic(codegen); |
| 2362 | intrinsic.Dispatch(invoke); |
| 2363 | return true; |
| 2364 | } |
| 2365 | return false; |
| 2366 | } |
| 2367 | |
| Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 2368 | void InstructionCodeGeneratorX86_64::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
| David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 2369 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 2370 | // art::PrepareForRegisterAllocation. |
| 2371 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
| Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 2372 | |
| Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 2373 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 2374 | return; |
| 2375 | } |
| Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2376 | |
| Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 2377 | LocationSummary* locations = invoke->GetLocations(); |
| Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 2378 | codegen_->GenerateStaticOrDirectCall( |
| Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 2379 | invoke, locations->HasTemps() ? locations->GetTemp(0) : Location::NoLocation()); |
| Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2380 | } |
| 2381 | |
| Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2382 | void LocationsBuilderX86_64::HandleInvoke(HInvoke* invoke) { |
| Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 2383 | InvokeDexCallingConventionVisitorX86_64 calling_convention_visitor; |
| Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 2384 | CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2385 | } |
| 2386 | |
| Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2387 | void LocationsBuilderX86_64::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
| Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 2388 | IntrinsicLocationsBuilderX86_64 intrinsic(codegen_); |
| Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 2389 | if (intrinsic.TryDispatch(invoke)) { |
| 2390 | return; |
| 2391 | } |
| 2392 | |
| Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2393 | HandleInvoke(invoke); |
| 2394 | } |
| 2395 | |
| Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2396 | void InstructionCodeGeneratorX86_64::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
| Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 2397 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 2398 | return; |
| 2399 | } |
| 2400 | |
| Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 2401 | codegen_->GenerateVirtualCall(invoke, invoke->GetLocations()->GetTemp(0)); |
| Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 2402 | DCHECK(!codegen_->IsLeafMethod()); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2403 | } |
| 2404 | |
| Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2405 | void LocationsBuilderX86_64::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 2406 | HandleInvoke(invoke); |
| 2407 | // Add the hidden argument. |
| 2408 | invoke->GetLocations()->AddTemp(Location::RegisterLocation(RAX)); |
| 2409 | } |
| 2410 | |
| 2411 | void InstructionCodeGeneratorX86_64::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 2412 | // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError. |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2413 | LocationSummary* locations = invoke->GetLocations(); |
| 2414 | CpuRegister temp = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 2415 | CpuRegister hidden_reg = locations->GetTemp(1).AsRegister<CpuRegister>(); |
| Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2416 | Location receiver = locations->InAt(0); |
| 2417 | size_t class_offset = mirror::Object::ClassOffset().SizeValue(); |
| 2418 | |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2419 | // Set the hidden argument. This is safe to do this here, as RAX |
| 2420 | // won't be modified thereafter, before the `call` instruction. |
| 2421 | DCHECK_EQ(RAX, hidden_reg.AsRegister()); |
| Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 2422 | codegen_->Load64BitValue(hidden_reg, invoke->GetDexMethodIndex()); |
| Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2423 | |
| Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2424 | if (receiver.IsStackSlot()) { |
| 2425 | __ movl(temp, Address(CpuRegister(RSP), receiver.GetStackIndex())); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2426 | // /* HeapReference<Class> */ temp = temp->klass_ |
| Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2427 | __ movl(temp, Address(temp, class_offset)); |
| 2428 | } else { |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2429 | // /* HeapReference<Class> */ temp = receiver->klass_ |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2430 | __ movl(temp, Address(receiver.AsRegister<CpuRegister>(), class_offset)); |
| Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2431 | } |
| Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 2432 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2433 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 2434 | // emit a read barrier for the previous class reference load. |
| 2435 | // However this is not required in practice, as this is an |
| 2436 | // intermediate/temporary reference and because the current |
| 2437 | // concurrent copying collector keeps the from-space memory |
| 2438 | // intact/accessible until the end of the marking phase (the |
| 2439 | // concurrent copying collector may not in the future). |
| Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2440 | __ MaybeUnpoisonHeapReference(temp); |
| Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 2441 | // temp = temp->GetAddressOfIMT() |
| 2442 | __ movq(temp, |
| 2443 | Address(temp, mirror::Class::ImtPtrOffset(kX86_64PointerSize).Uint32Value())); |
| 2444 | // temp = temp->GetImtEntryAt(method_offset); |
| 2445 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
| Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 2446 | invoke->GetImtIndex(), kX86_64PointerSize)); |
| Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2447 | // temp = temp->GetImtEntryAt(method_offset); |
| Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 2448 | __ movq(temp, Address(temp, method_offset)); |
| Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2449 | // call temp->GetEntryPoint(); |
| Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 2450 | __ call(Address( |
| 2451 | temp, ArtMethod::EntryPointFromQuickCompiledCodeOffset(kX86_64PointerSize).SizeValue())); |
| Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2452 | |
| 2453 | DCHECK(!codegen_->IsLeafMethod()); |
| 2454 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 2455 | } |
| 2456 | |
| Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 2457 | void LocationsBuilderX86_64::VisitInvokePolymorphic(HInvokePolymorphic* invoke) { |
| 2458 | HandleInvoke(invoke); |
| 2459 | } |
| 2460 | |
| 2461 | void InstructionCodeGeneratorX86_64::VisitInvokePolymorphic(HInvokePolymorphic* invoke) { |
| 2462 | codegen_->GenerateInvokePolymorphicCall(invoke); |
| 2463 | } |
| 2464 | |
| Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2465 | void LocationsBuilderX86_64::VisitNeg(HNeg* neg) { |
| 2466 | LocationSummary* locations = |
| 2467 | new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall); |
| 2468 | switch (neg->GetResultType()) { |
| 2469 | case Primitive::kPrimInt: |
| Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 2470 | case Primitive::kPrimLong: |
| Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2471 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2472 | locations->SetOut(Location::SameAsFirstInput()); |
| 2473 | break; |
| 2474 | |
| Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2475 | case Primitive::kPrimFloat: |
| 2476 | case Primitive::kPrimDouble: |
| Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2477 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2478 | locations->SetOut(Location::SameAsFirstInput()); |
| Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2479 | locations->AddTemp(Location::RequiresFpuRegister()); |
| Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2480 | break; |
| 2481 | |
| 2482 | default: |
| 2483 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 2484 | } |
| 2485 | } |
| 2486 | |
| 2487 | void InstructionCodeGeneratorX86_64::VisitNeg(HNeg* neg) { |
| 2488 | LocationSummary* locations = neg->GetLocations(); |
| 2489 | Location out = locations->Out(); |
| 2490 | Location in = locations->InAt(0); |
| 2491 | switch (neg->GetResultType()) { |
| 2492 | case Primitive::kPrimInt: |
| 2493 | DCHECK(in.IsRegister()); |
| Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2494 | DCHECK(in.Equals(out)); |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2495 | __ negl(out.AsRegister<CpuRegister>()); |
| Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2496 | break; |
| 2497 | |
| 2498 | case Primitive::kPrimLong: |
| Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 2499 | DCHECK(in.IsRegister()); |
| Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2500 | DCHECK(in.Equals(out)); |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2501 | __ negq(out.AsRegister<CpuRegister>()); |
| Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 2502 | break; |
| 2503 | |
| Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2504 | case Primitive::kPrimFloat: { |
| 2505 | DCHECK(in.Equals(out)); |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2506 | XmmRegister mask = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2507 | // Implement float negation with an exclusive or with value |
| 2508 | // 0x80000000 (mask for bit 31, representing the sign of a |
| 2509 | // single-precision floating-point number). |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2510 | __ movss(mask, codegen_->LiteralInt32Address(0x80000000)); |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2511 | __ xorps(out.AsFpuRegister<XmmRegister>(), mask); |
| Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2512 | break; |
| Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2513 | } |
| Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2514 | |
| Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2515 | case Primitive::kPrimDouble: { |
| 2516 | DCHECK(in.Equals(out)); |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2517 | XmmRegister mask = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2518 | // Implement double negation with an exclusive or with value |
| Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2519 | // 0x8000000000000000 (mask for bit 63, representing the sign of |
| Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2520 | // a double-precision floating-point number). |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2521 | __ movsd(mask, codegen_->LiteralInt64Address(INT64_C(0x8000000000000000))); |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2522 | __ xorpd(out.AsFpuRegister<XmmRegister>(), mask); |
| Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2523 | break; |
| Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2524 | } |
| Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2525 | |
| 2526 | default: |
| 2527 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 2528 | } |
| 2529 | } |
| 2530 | |
| Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2531 | void LocationsBuilderX86_64::VisitTypeConversion(HTypeConversion* conversion) { |
| 2532 | LocationSummary* locations = |
| 2533 | new (GetGraph()->GetArena()) LocationSummary(conversion, LocationSummary::kNoCall); |
| 2534 | Primitive::Type result_type = conversion->GetResultType(); |
| 2535 | Primitive::Type input_type = conversion->GetInputType(); |
| Nicolas Geoffray | 01fcc9e | 2014-12-01 14:16:20 +0000 | [diff] [blame] | 2536 | DCHECK_NE(result_type, input_type); |
| David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2537 | |
| David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 2538 | // The Java language does not allow treating boolean as an integral type but |
| 2539 | // our bit representation makes it safe. |
| David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2540 | |
| Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2541 | switch (result_type) { |
| Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2542 | case Primitive::kPrimByte: |
| 2543 | switch (input_type) { |
| Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2544 | case Primitive::kPrimLong: |
| 2545 | // Type conversion from long to byte is a result of code transformations. |
| David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2546 | case Primitive::kPrimBoolean: |
| 2547 | // Boolean input is a result of code transformations. |
| Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2548 | case Primitive::kPrimShort: |
| 2549 | case Primitive::kPrimInt: |
| 2550 | case Primitive::kPrimChar: |
| Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2551 | // Processing a Dex `int-to-byte' instruction. |
| Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2552 | locations->SetInAt(0, Location::Any()); |
| 2553 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2554 | break; |
| 2555 | |
| 2556 | default: |
| 2557 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2558 | << " to " << result_type; |
| 2559 | } |
| 2560 | break; |
| 2561 | |
| Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2562 | case Primitive::kPrimShort: |
| 2563 | switch (input_type) { |
| Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2564 | case Primitive::kPrimLong: |
| 2565 | // Type conversion from long to short is a result of code transformations. |
| David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2566 | case Primitive::kPrimBoolean: |
| 2567 | // Boolean input is a result of code transformations. |
| Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2568 | case Primitive::kPrimByte: |
| 2569 | case Primitive::kPrimInt: |
| 2570 | case Primitive::kPrimChar: |
| 2571 | // Processing a Dex `int-to-short' instruction. |
| 2572 | locations->SetInAt(0, Location::Any()); |
| 2573 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2574 | break; |
| 2575 | |
| 2576 | default: |
| 2577 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2578 | << " to " << result_type; |
| 2579 | } |
| 2580 | break; |
| 2581 | |
| Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2582 | case Primitive::kPrimInt: |
| 2583 | switch (input_type) { |
| 2584 | case Primitive::kPrimLong: |
| Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2585 | // Processing a Dex `long-to-int' instruction. |
| Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2586 | locations->SetInAt(0, Location::Any()); |
| 2587 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2588 | break; |
| 2589 | |
| 2590 | case Primitive::kPrimFloat: |
| Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2591 | // Processing a Dex `float-to-int' instruction. |
| 2592 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2593 | locations->SetOut(Location::RequiresRegister()); |
| Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2594 | break; |
| 2595 | |
| Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2596 | case Primitive::kPrimDouble: |
| Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2597 | // Processing a Dex `double-to-int' instruction. |
| 2598 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2599 | locations->SetOut(Location::RequiresRegister()); |
| Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2600 | break; |
| 2601 | |
| 2602 | default: |
| 2603 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2604 | << " to " << result_type; |
| 2605 | } |
| 2606 | break; |
| 2607 | |
| Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2608 | case Primitive::kPrimLong: |
| 2609 | switch (input_type) { |
| David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2610 | case Primitive::kPrimBoolean: |
| 2611 | // Boolean input is a result of code transformations. |
| Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2612 | case Primitive::kPrimByte: |
| 2613 | case Primitive::kPrimShort: |
| 2614 | case Primitive::kPrimInt: |
| Roland Levillain | 666c732 | 2014-11-10 13:39:43 +0000 | [diff] [blame] | 2615 | case Primitive::kPrimChar: |
| Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2616 | // Processing a Dex `int-to-long' instruction. |
| Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2617 | // TODO: We would benefit from a (to-be-implemented) |
| 2618 | // Location::RegisterOrStackSlot requirement for this input. |
| 2619 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2620 | locations->SetOut(Location::RequiresRegister()); |
| 2621 | break; |
| 2622 | |
| 2623 | case Primitive::kPrimFloat: |
| Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2624 | // Processing a Dex `float-to-long' instruction. |
| 2625 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2626 | locations->SetOut(Location::RequiresRegister()); |
| Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2627 | break; |
| 2628 | |
| Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2629 | case Primitive::kPrimDouble: |
| Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2630 | // Processing a Dex `double-to-long' instruction. |
| 2631 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2632 | locations->SetOut(Location::RequiresRegister()); |
| Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2633 | break; |
| 2634 | |
| 2635 | default: |
| 2636 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2637 | << " to " << result_type; |
| 2638 | } |
| 2639 | break; |
| 2640 | |
| Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2641 | case Primitive::kPrimChar: |
| 2642 | switch (input_type) { |
| Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2643 | case Primitive::kPrimLong: |
| 2644 | // Type conversion from long to char is a result of code transformations. |
| David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2645 | case Primitive::kPrimBoolean: |
| 2646 | // Boolean input is a result of code transformations. |
| Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2647 | case Primitive::kPrimByte: |
| 2648 | case Primitive::kPrimShort: |
| 2649 | case Primitive::kPrimInt: |
| Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2650 | // Processing a Dex `int-to-char' instruction. |
| 2651 | locations->SetInAt(0, Location::Any()); |
| 2652 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2653 | break; |
| 2654 | |
| 2655 | default: |
| 2656 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2657 | << " to " << result_type; |
| 2658 | } |
| 2659 | break; |
| 2660 | |
| Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2661 | case Primitive::kPrimFloat: |
| Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2662 | switch (input_type) { |
| David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2663 | case Primitive::kPrimBoolean: |
| 2664 | // Boolean input is a result of code transformations. |
| Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2665 | case Primitive::kPrimByte: |
| 2666 | case Primitive::kPrimShort: |
| 2667 | case Primitive::kPrimInt: |
| 2668 | case Primitive::kPrimChar: |
| 2669 | // Processing a Dex `int-to-float' instruction. |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2670 | locations->SetInAt(0, Location::Any()); |
| Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2671 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2672 | break; |
| 2673 | |
| 2674 | case Primitive::kPrimLong: |
| Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2675 | // Processing a Dex `long-to-float' instruction. |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2676 | locations->SetInAt(0, Location::Any()); |
| Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2677 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2678 | break; |
| 2679 | |
| Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2680 | case Primitive::kPrimDouble: |
| Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2681 | // Processing a Dex `double-to-float' instruction. |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2682 | locations->SetInAt(0, Location::Any()); |
| Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2683 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2684 | break; |
| 2685 | |
| 2686 | default: |
| 2687 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2688 | << " to " << result_type; |
| 2689 | }; |
| 2690 | break; |
| 2691 | |
| Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2692 | case Primitive::kPrimDouble: |
| Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2693 | switch (input_type) { |
| David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2694 | case Primitive::kPrimBoolean: |
| 2695 | // Boolean input is a result of code transformations. |
| Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2696 | case Primitive::kPrimByte: |
| 2697 | case Primitive::kPrimShort: |
| 2698 | case Primitive::kPrimInt: |
| 2699 | case Primitive::kPrimChar: |
| 2700 | // Processing a Dex `int-to-double' instruction. |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2701 | locations->SetInAt(0, Location::Any()); |
| Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2702 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2703 | break; |
| 2704 | |
| 2705 | case Primitive::kPrimLong: |
| Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2706 | // Processing a Dex `long-to-double' instruction. |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2707 | locations->SetInAt(0, Location::Any()); |
| Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2708 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2709 | break; |
| 2710 | |
| Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2711 | case Primitive::kPrimFloat: |
| Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2712 | // Processing a Dex `float-to-double' instruction. |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2713 | locations->SetInAt(0, Location::Any()); |
| Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2714 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2715 | break; |
| 2716 | |
| 2717 | default: |
| 2718 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2719 | << " to " << result_type; |
| 2720 | } |
| Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2721 | break; |
| 2722 | |
| 2723 | default: |
| 2724 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2725 | << " to " << result_type; |
| 2726 | } |
| 2727 | } |
| 2728 | |
| 2729 | void InstructionCodeGeneratorX86_64::VisitTypeConversion(HTypeConversion* conversion) { |
| 2730 | LocationSummary* locations = conversion->GetLocations(); |
| 2731 | Location out = locations->Out(); |
| 2732 | Location in = locations->InAt(0); |
| 2733 | Primitive::Type result_type = conversion->GetResultType(); |
| 2734 | Primitive::Type input_type = conversion->GetInputType(); |
| Nicolas Geoffray | 01fcc9e | 2014-12-01 14:16:20 +0000 | [diff] [blame] | 2735 | DCHECK_NE(result_type, input_type); |
| Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2736 | switch (result_type) { |
| Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2737 | case Primitive::kPrimByte: |
| 2738 | switch (input_type) { |
| Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2739 | case Primitive::kPrimLong: |
| 2740 | // Type conversion from long to byte is a result of code transformations. |
| David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2741 | case Primitive::kPrimBoolean: |
| 2742 | // Boolean input is a result of code transformations. |
| Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2743 | case Primitive::kPrimShort: |
| 2744 | case Primitive::kPrimInt: |
| 2745 | case Primitive::kPrimChar: |
| Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2746 | // Processing a Dex `int-to-byte' instruction. |
| Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2747 | if (in.IsRegister()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2748 | __ movsxb(out.AsRegister<CpuRegister>(), in.AsRegister<CpuRegister>()); |
| Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2749 | } else if (in.IsStackSlot() || in.IsDoubleStackSlot()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2750 | __ movsxb(out.AsRegister<CpuRegister>(), |
| Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2751 | Address(CpuRegister(RSP), in.GetStackIndex())); |
| 2752 | } else { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2753 | __ movl(out.AsRegister<CpuRegister>(), |
| Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2754 | Immediate(static_cast<int8_t>(Int64FromConstant(in.GetConstant())))); |
| Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2755 | } |
| 2756 | break; |
| 2757 | |
| 2758 | default: |
| 2759 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2760 | << " to " << result_type; |
| 2761 | } |
| 2762 | break; |
| 2763 | |
| Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2764 | case Primitive::kPrimShort: |
| 2765 | switch (input_type) { |
| Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2766 | case Primitive::kPrimLong: |
| 2767 | // Type conversion from long to short is a result of code transformations. |
| David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2768 | case Primitive::kPrimBoolean: |
| 2769 | // Boolean input is a result of code transformations. |
| Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2770 | case Primitive::kPrimByte: |
| 2771 | case Primitive::kPrimInt: |
| 2772 | case Primitive::kPrimChar: |
| 2773 | // Processing a Dex `int-to-short' instruction. |
| 2774 | if (in.IsRegister()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2775 | __ movsxw(out.AsRegister<CpuRegister>(), in.AsRegister<CpuRegister>()); |
| Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2776 | } else if (in.IsStackSlot() || in.IsDoubleStackSlot()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2777 | __ movsxw(out.AsRegister<CpuRegister>(), |
| Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2778 | Address(CpuRegister(RSP), in.GetStackIndex())); |
| 2779 | } else { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2780 | __ movl(out.AsRegister<CpuRegister>(), |
| Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2781 | Immediate(static_cast<int16_t>(Int64FromConstant(in.GetConstant())))); |
| Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2782 | } |
| 2783 | break; |
| 2784 | |
| 2785 | default: |
| 2786 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2787 | << " to " << result_type; |
| 2788 | } |
| 2789 | break; |
| 2790 | |
| Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2791 | case Primitive::kPrimInt: |
| 2792 | switch (input_type) { |
| 2793 | case Primitive::kPrimLong: |
| Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2794 | // Processing a Dex `long-to-int' instruction. |
| Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2795 | if (in.IsRegister()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2796 | __ movl(out.AsRegister<CpuRegister>(), in.AsRegister<CpuRegister>()); |
| Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2797 | } else if (in.IsDoubleStackSlot()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2798 | __ movl(out.AsRegister<CpuRegister>(), |
| Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2799 | Address(CpuRegister(RSP), in.GetStackIndex())); |
| 2800 | } else { |
| 2801 | DCHECK(in.IsConstant()); |
| 2802 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 2803 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2804 | __ movl(out.AsRegister<CpuRegister>(), Immediate(static_cast<int32_t>(value))); |
| Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2805 | } |
| 2806 | break; |
| 2807 | |
| Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2808 | case Primitive::kPrimFloat: { |
| 2809 | // Processing a Dex `float-to-int' instruction. |
| 2810 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 2811 | CpuRegister output = out.AsRegister<CpuRegister>(); |
| Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2812 | NearLabel done, nan; |
| Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2813 | |
| 2814 | __ movl(output, Immediate(kPrimIntMax)); |
| Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 2815 | // if input >= (float)INT_MAX goto done |
| 2816 | __ comiss(input, codegen_->LiteralFloatAddress(kPrimIntMax)); |
| Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2817 | __ j(kAboveEqual, &done); |
| 2818 | // if input == NaN goto nan |
| 2819 | __ j(kUnordered, &nan); |
| 2820 | // output = float-to-int-truncate(input) |
| Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2821 | __ cvttss2si(output, input, false); |
| Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2822 | __ jmp(&done); |
| 2823 | __ Bind(&nan); |
| 2824 | // output = 0 |
| 2825 | __ xorl(output, output); |
| 2826 | __ Bind(&done); |
| 2827 | break; |
| 2828 | } |
| 2829 | |
| Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2830 | case Primitive::kPrimDouble: { |
| 2831 | // Processing a Dex `double-to-int' instruction. |
| 2832 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 2833 | CpuRegister output = out.AsRegister<CpuRegister>(); |
| Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2834 | NearLabel done, nan; |
| Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2835 | |
| 2836 | __ movl(output, Immediate(kPrimIntMax)); |
| Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 2837 | // if input >= (double)INT_MAX goto done |
| 2838 | __ comisd(input, codegen_->LiteralDoubleAddress(kPrimIntMax)); |
| Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2839 | __ j(kAboveEqual, &done); |
| 2840 | // if input == NaN goto nan |
| 2841 | __ j(kUnordered, &nan); |
| 2842 | // output = double-to-int-truncate(input) |
| 2843 | __ cvttsd2si(output, input); |
| 2844 | __ jmp(&done); |
| 2845 | __ Bind(&nan); |
| 2846 | // output = 0 |
| 2847 | __ xorl(output, output); |
| 2848 | __ Bind(&done); |
| Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2849 | break; |
| Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2850 | } |
| Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2851 | |
| 2852 | default: |
| 2853 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2854 | << " to " << result_type; |
| 2855 | } |
| 2856 | break; |
| 2857 | |
| Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2858 | case Primitive::kPrimLong: |
| 2859 | switch (input_type) { |
| 2860 | DCHECK(out.IsRegister()); |
| David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2861 | case Primitive::kPrimBoolean: |
| 2862 | // Boolean input is a result of code transformations. |
| Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2863 | case Primitive::kPrimByte: |
| 2864 | case Primitive::kPrimShort: |
| 2865 | case Primitive::kPrimInt: |
| Roland Levillain | 666c732 | 2014-11-10 13:39:43 +0000 | [diff] [blame] | 2866 | case Primitive::kPrimChar: |
| Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2867 | // Processing a Dex `int-to-long' instruction. |
| Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2868 | DCHECK(in.IsRegister()); |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2869 | __ movsxd(out.AsRegister<CpuRegister>(), in.AsRegister<CpuRegister>()); |
| Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2870 | break; |
| 2871 | |
| Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2872 | case Primitive::kPrimFloat: { |
| 2873 | // Processing a Dex `float-to-long' instruction. |
| 2874 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 2875 | CpuRegister output = out.AsRegister<CpuRegister>(); |
| Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2876 | NearLabel done, nan; |
| Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2877 | |
| Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 2878 | codegen_->Load64BitValue(output, kPrimLongMax); |
| Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 2879 | // if input >= (float)LONG_MAX goto done |
| 2880 | __ comiss(input, codegen_->LiteralFloatAddress(kPrimLongMax)); |
| Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2881 | __ j(kAboveEqual, &done); |
| 2882 | // if input == NaN goto nan |
| 2883 | __ j(kUnordered, &nan); |
| Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2884 | // output = float-to-long-truncate(input) |
| Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2885 | __ cvttss2si(output, input, true); |
| 2886 | __ jmp(&done); |
| 2887 | __ Bind(&nan); |
| 2888 | // output = 0 |
| Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 2889 | __ xorl(output, output); |
| Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2890 | __ Bind(&done); |
| 2891 | break; |
| 2892 | } |
| 2893 | |
| Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2894 | case Primitive::kPrimDouble: { |
| 2895 | // Processing a Dex `double-to-long' instruction. |
| 2896 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 2897 | CpuRegister output = out.AsRegister<CpuRegister>(); |
| Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2898 | NearLabel done, nan; |
| Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2899 | |
| Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 2900 | codegen_->Load64BitValue(output, kPrimLongMax); |
| Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 2901 | // if input >= (double)LONG_MAX goto done |
| 2902 | __ comisd(input, codegen_->LiteralDoubleAddress(kPrimLongMax)); |
| Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2903 | __ j(kAboveEqual, &done); |
| 2904 | // if input == NaN goto nan |
| 2905 | __ j(kUnordered, &nan); |
| 2906 | // output = double-to-long-truncate(input) |
| 2907 | __ cvttsd2si(output, input, true); |
| 2908 | __ jmp(&done); |
| 2909 | __ Bind(&nan); |
| 2910 | // output = 0 |
| Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 2911 | __ xorl(output, output); |
| Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2912 | __ Bind(&done); |
| Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2913 | break; |
| Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2914 | } |
| Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2915 | |
| 2916 | default: |
| 2917 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2918 | << " to " << result_type; |
| 2919 | } |
| 2920 | break; |
| 2921 | |
| Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2922 | case Primitive::kPrimChar: |
| 2923 | switch (input_type) { |
| Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2924 | case Primitive::kPrimLong: |
| 2925 | // Type conversion from long to char is a result of code transformations. |
| David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2926 | case Primitive::kPrimBoolean: |
| 2927 | // Boolean input is a result of code transformations. |
| Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2928 | case Primitive::kPrimByte: |
| 2929 | case Primitive::kPrimShort: |
| 2930 | case Primitive::kPrimInt: |
| Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2931 | // Processing a Dex `int-to-char' instruction. |
| 2932 | if (in.IsRegister()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2933 | __ movzxw(out.AsRegister<CpuRegister>(), in.AsRegister<CpuRegister>()); |
| Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2934 | } else if (in.IsStackSlot() || in.IsDoubleStackSlot()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2935 | __ movzxw(out.AsRegister<CpuRegister>(), |
| Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2936 | Address(CpuRegister(RSP), in.GetStackIndex())); |
| 2937 | } else { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2938 | __ movl(out.AsRegister<CpuRegister>(), |
| Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2939 | Immediate(static_cast<uint16_t>(Int64FromConstant(in.GetConstant())))); |
| Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2940 | } |
| 2941 | break; |
| 2942 | |
| 2943 | default: |
| 2944 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2945 | << " to " << result_type; |
| 2946 | } |
| 2947 | break; |
| 2948 | |
| Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2949 | case Primitive::kPrimFloat: |
| Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2950 | switch (input_type) { |
| David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2951 | case Primitive::kPrimBoolean: |
| 2952 | // Boolean input is a result of code transformations. |
| Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2953 | case Primitive::kPrimByte: |
| 2954 | case Primitive::kPrimShort: |
| 2955 | case Primitive::kPrimInt: |
| 2956 | case Primitive::kPrimChar: |
| Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2957 | // Processing a Dex `int-to-float' instruction. |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2958 | if (in.IsRegister()) { |
| 2959 | __ cvtsi2ss(out.AsFpuRegister<XmmRegister>(), in.AsRegister<CpuRegister>(), false); |
| 2960 | } else if (in.IsConstant()) { |
| 2961 | int32_t v = in.GetConstant()->AsIntConstant()->GetValue(); |
| 2962 | XmmRegister dest = out.AsFpuRegister<XmmRegister>(); |
| Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 2963 | codegen_->Load32BitValue(dest, static_cast<float>(v)); |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2964 | } else { |
| 2965 | __ cvtsi2ss(out.AsFpuRegister<XmmRegister>(), |
| 2966 | Address(CpuRegister(RSP), in.GetStackIndex()), false); |
| 2967 | } |
| Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2968 | break; |
| 2969 | |
| 2970 | case Primitive::kPrimLong: |
| Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2971 | // Processing a Dex `long-to-float' instruction. |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2972 | if (in.IsRegister()) { |
| 2973 | __ cvtsi2ss(out.AsFpuRegister<XmmRegister>(), in.AsRegister<CpuRegister>(), true); |
| 2974 | } else if (in.IsConstant()) { |
| 2975 | int64_t v = in.GetConstant()->AsLongConstant()->GetValue(); |
| 2976 | XmmRegister dest = out.AsFpuRegister<XmmRegister>(); |
| Pavel Vyssotski | 4c858cd | 2016-03-16 13:59:53 +0600 | [diff] [blame] | 2977 | codegen_->Load32BitValue(dest, static_cast<float>(v)); |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2978 | } else { |
| 2979 | __ cvtsi2ss(out.AsFpuRegister<XmmRegister>(), |
| 2980 | Address(CpuRegister(RSP), in.GetStackIndex()), true); |
| 2981 | } |
| Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2982 | break; |
| 2983 | |
| Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2984 | case Primitive::kPrimDouble: |
| Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2985 | // Processing a Dex `double-to-float' instruction. |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2986 | if (in.IsFpuRegister()) { |
| 2987 | __ cvtsd2ss(out.AsFpuRegister<XmmRegister>(), in.AsFpuRegister<XmmRegister>()); |
| 2988 | } else if (in.IsConstant()) { |
| 2989 | double v = in.GetConstant()->AsDoubleConstant()->GetValue(); |
| 2990 | XmmRegister dest = out.AsFpuRegister<XmmRegister>(); |
| Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 2991 | codegen_->Load32BitValue(dest, static_cast<float>(v)); |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2992 | } else { |
| 2993 | __ cvtsd2ss(out.AsFpuRegister<XmmRegister>(), |
| 2994 | Address(CpuRegister(RSP), in.GetStackIndex())); |
| 2995 | } |
| Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2996 | break; |
| 2997 | |
| 2998 | default: |
| 2999 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3000 | << " to " << result_type; |
| 3001 | }; |
| 3002 | break; |
| 3003 | |
| Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3004 | case Primitive::kPrimDouble: |
| Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3005 | switch (input_type) { |
| David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 3006 | case Primitive::kPrimBoolean: |
| 3007 | // Boolean input is a result of code transformations. |
| Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3008 | case Primitive::kPrimByte: |
| 3009 | case Primitive::kPrimShort: |
| 3010 | case Primitive::kPrimInt: |
| 3011 | case Primitive::kPrimChar: |
| Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 3012 | // Processing a Dex `int-to-double' instruction. |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 3013 | if (in.IsRegister()) { |
| 3014 | __ cvtsi2sd(out.AsFpuRegister<XmmRegister>(), in.AsRegister<CpuRegister>(), false); |
| 3015 | } else if (in.IsConstant()) { |
| 3016 | int32_t v = in.GetConstant()->AsIntConstant()->GetValue(); |
| 3017 | XmmRegister dest = out.AsFpuRegister<XmmRegister>(); |
| Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 3018 | codegen_->Load64BitValue(dest, static_cast<double>(v)); |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 3019 | } else { |
| 3020 | __ cvtsi2sd(out.AsFpuRegister<XmmRegister>(), |
| 3021 | Address(CpuRegister(RSP), in.GetStackIndex()), false); |
| 3022 | } |
| Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3023 | break; |
| 3024 | |
| 3025 | case Primitive::kPrimLong: |
| Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 3026 | // Processing a Dex `long-to-double' instruction. |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 3027 | if (in.IsRegister()) { |
| 3028 | __ cvtsi2sd(out.AsFpuRegister<XmmRegister>(), in.AsRegister<CpuRegister>(), true); |
| 3029 | } else if (in.IsConstant()) { |
| 3030 | int64_t v = in.GetConstant()->AsLongConstant()->GetValue(); |
| 3031 | XmmRegister dest = out.AsFpuRegister<XmmRegister>(); |
| Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 3032 | codegen_->Load64BitValue(dest, static_cast<double>(v)); |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 3033 | } else { |
| 3034 | __ cvtsi2sd(out.AsFpuRegister<XmmRegister>(), |
| 3035 | Address(CpuRegister(RSP), in.GetStackIndex()), true); |
| 3036 | } |
| Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 3037 | break; |
| 3038 | |
| Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3039 | case Primitive::kPrimFloat: |
| Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 3040 | // Processing a Dex `float-to-double' instruction. |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 3041 | if (in.IsFpuRegister()) { |
| 3042 | __ cvtss2sd(out.AsFpuRegister<XmmRegister>(), in.AsFpuRegister<XmmRegister>()); |
| 3043 | } else if (in.IsConstant()) { |
| 3044 | float v = in.GetConstant()->AsFloatConstant()->GetValue(); |
| 3045 | XmmRegister dest = out.AsFpuRegister<XmmRegister>(); |
| Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 3046 | codegen_->Load64BitValue(dest, static_cast<double>(v)); |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 3047 | } else { |
| 3048 | __ cvtss2sd(out.AsFpuRegister<XmmRegister>(), |
| 3049 | Address(CpuRegister(RSP), in.GetStackIndex())); |
| 3050 | } |
| Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3051 | break; |
| 3052 | |
| 3053 | default: |
| 3054 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3055 | << " to " << result_type; |
| 3056 | }; |
| Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3057 | break; |
| 3058 | |
| 3059 | default: |
| 3060 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3061 | << " to " << result_type; |
| 3062 | } |
| 3063 | } |
| 3064 | |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3065 | void LocationsBuilderX86_64::VisitAdd(HAdd* add) { |
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3066 | LocationSummary* locations = |
| 3067 | new (GetGraph()->GetArena()) LocationSummary(add, LocationSummary::kNoCall); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3068 | switch (add->GetResultType()) { |
| Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 3069 | case Primitive::kPrimInt: { |
| 3070 | locations->SetInAt(0, Location::RequiresRegister()); |
| Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 3071 | locations->SetInAt(1, Location::RegisterOrConstant(add->InputAt(1))); |
| 3072 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 3073 | break; |
| 3074 | } |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3075 | |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3076 | case Primitive::kPrimLong: { |
| Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 3077 | locations->SetInAt(0, Location::RequiresRegister()); |
| Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 3078 | // 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] | 3079 | locations->SetInAt(1, Location::RegisterOrInt32Constant(add->InputAt(1))); |
| Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 3080 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3081 | break; |
| 3082 | } |
| 3083 | |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3084 | case Primitive::kPrimDouble: |
| 3085 | case Primitive::kPrimFloat: { |
| 3086 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3087 | locations->SetInAt(1, Location::Any()); |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3088 | locations->SetOut(Location::SameAsFirstInput()); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3089 | break; |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3090 | } |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3091 | |
| 3092 | default: |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3093 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3094 | } |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3095 | } |
| 3096 | |
| 3097 | void InstructionCodeGeneratorX86_64::VisitAdd(HAdd* add) { |
| 3098 | LocationSummary* locations = add->GetLocations(); |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3099 | Location first = locations->InAt(0); |
| 3100 | Location second = locations->InAt(1); |
| Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 3101 | Location out = locations->Out(); |
| Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3102 | |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3103 | switch (add->GetResultType()) { |
| Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 3104 | case Primitive::kPrimInt: { |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3105 | if (second.IsRegister()) { |
| Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 3106 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 3107 | __ addl(out.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
| Mark Mendell | 33bf245 | 2015-05-27 10:08:24 -0400 | [diff] [blame] | 3108 | } else if (out.AsRegister<Register>() == second.AsRegister<Register>()) { |
| 3109 | __ addl(out.AsRegister<CpuRegister>(), first.AsRegister<CpuRegister>()); |
| Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 3110 | } else { |
| 3111 | __ leal(out.AsRegister<CpuRegister>(), Address( |
| 3112 | first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>(), TIMES_1, 0)); |
| 3113 | } |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3114 | } else if (second.IsConstant()) { |
| Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 3115 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 3116 | __ addl(out.AsRegister<CpuRegister>(), |
| 3117 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
| 3118 | } else { |
| 3119 | __ leal(out.AsRegister<CpuRegister>(), Address( |
| 3120 | first.AsRegister<CpuRegister>(), second.GetConstant()->AsIntConstant()->GetValue())); |
| 3121 | } |
| Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 3122 | } else { |
| Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 3123 | DCHECK(first.Equals(locations->Out())); |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3124 | __ addl(first.AsRegister<CpuRegister>(), Address(CpuRegister(RSP), second.GetStackIndex())); |
| Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 3125 | } |
| Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 3126 | break; |
| 3127 | } |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3128 | |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3129 | case Primitive::kPrimLong: { |
| Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 3130 | if (second.IsRegister()) { |
| 3131 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 3132 | __ addq(out.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
| Mark Mendell | 33bf245 | 2015-05-27 10:08:24 -0400 | [diff] [blame] | 3133 | } else if (out.AsRegister<Register>() == second.AsRegister<Register>()) { |
| 3134 | __ addq(out.AsRegister<CpuRegister>(), first.AsRegister<CpuRegister>()); |
| Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 3135 | } else { |
| 3136 | __ leaq(out.AsRegister<CpuRegister>(), Address( |
| 3137 | first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>(), TIMES_1, 0)); |
| 3138 | } |
| 3139 | } else { |
| 3140 | DCHECK(second.IsConstant()); |
| 3141 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 3142 | int32_t int32_value = Low32Bits(value); |
| 3143 | DCHECK_EQ(int32_value, value); |
| 3144 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 3145 | __ addq(out.AsRegister<CpuRegister>(), Immediate(int32_value)); |
| 3146 | } else { |
| 3147 | __ leaq(out.AsRegister<CpuRegister>(), Address( |
| 3148 | first.AsRegister<CpuRegister>(), int32_value)); |
| 3149 | } |
| 3150 | } |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3151 | break; |
| 3152 | } |
| 3153 | |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3154 | case Primitive::kPrimFloat: { |
| Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3155 | if (second.IsFpuRegister()) { |
| 3156 | __ addss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3157 | } else if (second.IsConstant()) { |
| 3158 | __ addss(first.AsFpuRegister<XmmRegister>(), |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 3159 | codegen_->LiteralFloatAddress( |
| 3160 | second.GetConstant()->AsFloatConstant()->GetValue())); |
| Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3161 | } else { |
| 3162 | DCHECK(second.IsStackSlot()); |
| 3163 | __ addss(first.AsFpuRegister<XmmRegister>(), |
| 3164 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 3165 | } |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3166 | break; |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3167 | } |
| 3168 | |
| 3169 | case Primitive::kPrimDouble: { |
| Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3170 | if (second.IsFpuRegister()) { |
| 3171 | __ addsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3172 | } else if (second.IsConstant()) { |
| 3173 | __ addsd(first.AsFpuRegister<XmmRegister>(), |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 3174 | codegen_->LiteralDoubleAddress( |
| 3175 | second.GetConstant()->AsDoubleConstant()->GetValue())); |
| Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3176 | } else { |
| 3177 | DCHECK(second.IsDoubleStackSlot()); |
| 3178 | __ addsd(first.AsFpuRegister<XmmRegister>(), |
| 3179 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 3180 | } |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3181 | break; |
| 3182 | } |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3183 | |
| 3184 | default: |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3185 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3186 | } |
| 3187 | } |
| 3188 | |
| 3189 | void LocationsBuilderX86_64::VisitSub(HSub* sub) { |
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3190 | LocationSummary* locations = |
| 3191 | new (GetGraph()->GetArena()) LocationSummary(sub, LocationSummary::kNoCall); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3192 | switch (sub->GetResultType()) { |
| Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 3193 | case Primitive::kPrimInt: { |
| 3194 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3195 | locations->SetInAt(1, Location::Any()); |
| 3196 | locations->SetOut(Location::SameAsFirstInput()); |
| 3197 | break; |
| 3198 | } |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3199 | case Primitive::kPrimLong: { |
| Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 3200 | locations->SetInAt(0, Location::RequiresRegister()); |
| Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 3201 | locations->SetInAt(1, Location::RegisterOrInt32Constant(sub->InputAt(1))); |
| Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 3202 | locations->SetOut(Location::SameAsFirstInput()); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3203 | break; |
| 3204 | } |
| Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3205 | case Primitive::kPrimFloat: |
| 3206 | case Primitive::kPrimDouble: { |
| 3207 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3208 | locations->SetInAt(1, Location::Any()); |
| Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3209 | locations->SetOut(Location::SameAsFirstInput()); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3210 | break; |
| Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3211 | } |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3212 | default: |
| Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3213 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3214 | } |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3215 | } |
| 3216 | |
| 3217 | void InstructionCodeGeneratorX86_64::VisitSub(HSub* sub) { |
| 3218 | LocationSummary* locations = sub->GetLocations(); |
| Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3219 | Location first = locations->InAt(0); |
| 3220 | Location second = locations->InAt(1); |
| 3221 | DCHECK(first.Equals(locations->Out())); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3222 | switch (sub->GetResultType()) { |
| Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 3223 | case Primitive::kPrimInt: { |
| Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3224 | if (second.IsRegister()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3225 | __ subl(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
| Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3226 | } else if (second.IsConstant()) { |
| 3227 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue()); |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3228 | __ subl(first.AsRegister<CpuRegister>(), imm); |
| Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 3229 | } else { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3230 | __ subl(first.AsRegister<CpuRegister>(), Address(CpuRegister(RSP), second.GetStackIndex())); |
| Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 3231 | } |
| Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 3232 | break; |
| 3233 | } |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3234 | case Primitive::kPrimLong: { |
| Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 3235 | if (second.IsConstant()) { |
| 3236 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 3237 | DCHECK(IsInt<32>(value)); |
| 3238 | __ subq(first.AsRegister<CpuRegister>(), Immediate(static_cast<int32_t>(value))); |
| 3239 | } else { |
| 3240 | __ subq(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
| 3241 | } |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3242 | break; |
| 3243 | } |
| 3244 | |
| Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3245 | case Primitive::kPrimFloat: { |
| Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3246 | if (second.IsFpuRegister()) { |
| 3247 | __ subss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3248 | } else if (second.IsConstant()) { |
| 3249 | __ subss(first.AsFpuRegister<XmmRegister>(), |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 3250 | codegen_->LiteralFloatAddress( |
| 3251 | second.GetConstant()->AsFloatConstant()->GetValue())); |
| Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3252 | } else { |
| 3253 | DCHECK(second.IsStackSlot()); |
| 3254 | __ subss(first.AsFpuRegister<XmmRegister>(), |
| 3255 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 3256 | } |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3257 | break; |
| Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3258 | } |
| 3259 | |
| 3260 | case Primitive::kPrimDouble: { |
| Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3261 | if (second.IsFpuRegister()) { |
| 3262 | __ subsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3263 | } else if (second.IsConstant()) { |
| 3264 | __ subsd(first.AsFpuRegister<XmmRegister>(), |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 3265 | codegen_->LiteralDoubleAddress( |
| 3266 | second.GetConstant()->AsDoubleConstant()->GetValue())); |
| Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3267 | } else { |
| 3268 | DCHECK(second.IsDoubleStackSlot()); |
| 3269 | __ subsd(first.AsFpuRegister<XmmRegister>(), |
| 3270 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 3271 | } |
| Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3272 | break; |
| 3273 | } |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3274 | |
| 3275 | default: |
| Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3276 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3277 | } |
| 3278 | } |
| 3279 | |
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3280 | void LocationsBuilderX86_64::VisitMul(HMul* mul) { |
| 3281 | LocationSummary* locations = |
| 3282 | new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall); |
| 3283 | switch (mul->GetResultType()) { |
| 3284 | case Primitive::kPrimInt: { |
| 3285 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3286 | locations->SetInAt(1, Location::Any()); |
| Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3287 | if (mul->InputAt(1)->IsIntConstant()) { |
| 3288 | // Can use 3 operand multiply. |
| 3289 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3290 | } else { |
| 3291 | locations->SetOut(Location::SameAsFirstInput()); |
| 3292 | } |
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3293 | break; |
| 3294 | } |
| 3295 | case Primitive::kPrimLong: { |
| 3296 | locations->SetInAt(0, Location::RequiresRegister()); |
| Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3297 | locations->SetInAt(1, Location::Any()); |
| 3298 | if (mul->InputAt(1)->IsLongConstant() && |
| 3299 | IsInt<32>(mul->InputAt(1)->AsLongConstant()->GetValue())) { |
| Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 3300 | // Can use 3 operand multiply. |
| 3301 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3302 | } else { |
| 3303 | locations->SetOut(Location::SameAsFirstInput()); |
| 3304 | } |
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3305 | break; |
| 3306 | } |
| Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3307 | case Primitive::kPrimFloat: |
| 3308 | case Primitive::kPrimDouble: { |
| 3309 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3310 | locations->SetInAt(1, Location::Any()); |
| Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3311 | locations->SetOut(Location::SameAsFirstInput()); |
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3312 | break; |
| Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3313 | } |
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3314 | |
| 3315 | default: |
| Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3316 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3317 | } |
| 3318 | } |
| 3319 | |
| 3320 | void InstructionCodeGeneratorX86_64::VisitMul(HMul* mul) { |
| 3321 | LocationSummary* locations = mul->GetLocations(); |
| 3322 | Location first = locations->InAt(0); |
| 3323 | Location second = locations->InAt(1); |
| Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3324 | Location out = locations->Out(); |
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3325 | switch (mul->GetResultType()) { |
| Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3326 | case Primitive::kPrimInt: |
| 3327 | // The constant may have ended up in a register, so test explicitly to avoid |
| 3328 | // problems where the output may not be the same as the first operand. |
| 3329 | if (mul->InputAt(1)->IsIntConstant()) { |
| 3330 | Immediate imm(mul->InputAt(1)->AsIntConstant()->GetValue()); |
| 3331 | __ imull(out.AsRegister<CpuRegister>(), first.AsRegister<CpuRegister>(), imm); |
| 3332 | } else if (second.IsRegister()) { |
| 3333 | DCHECK(first.Equals(out)); |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3334 | __ imull(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3335 | } else { |
| Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3336 | DCHECK(first.Equals(out)); |
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3337 | DCHECK(second.IsStackSlot()); |
| Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 3338 | __ imull(first.AsRegister<CpuRegister>(), |
| 3339 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3340 | } |
| 3341 | break; |
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3342 | case Primitive::kPrimLong: { |
| Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3343 | // The constant may have ended up in a register, so test explicitly to avoid |
| 3344 | // problems where the output may not be the same as the first operand. |
| 3345 | if (mul->InputAt(1)->IsLongConstant()) { |
| 3346 | int64_t value = mul->InputAt(1)->AsLongConstant()->GetValue(); |
| 3347 | if (IsInt<32>(value)) { |
| 3348 | __ imulq(out.AsRegister<CpuRegister>(), first.AsRegister<CpuRegister>(), |
| 3349 | Immediate(static_cast<int32_t>(value))); |
| 3350 | } else { |
| 3351 | // Have to use the constant area. |
| 3352 | DCHECK(first.Equals(out)); |
| 3353 | __ imulq(first.AsRegister<CpuRegister>(), codegen_->LiteralInt64Address(value)); |
| 3354 | } |
| 3355 | } else if (second.IsRegister()) { |
| 3356 | DCHECK(first.Equals(out)); |
| Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 3357 | __ imulq(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
| Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3358 | } else { |
| 3359 | DCHECK(second.IsDoubleStackSlot()); |
| 3360 | DCHECK(first.Equals(out)); |
| 3361 | __ imulq(first.AsRegister<CpuRegister>(), |
| 3362 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 3363 | } |
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3364 | break; |
| 3365 | } |
| 3366 | |
| Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3367 | case Primitive::kPrimFloat: { |
| Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3368 | DCHECK(first.Equals(out)); |
| Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3369 | if (second.IsFpuRegister()) { |
| 3370 | __ mulss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3371 | } else if (second.IsConstant()) { |
| 3372 | __ mulss(first.AsFpuRegister<XmmRegister>(), |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 3373 | codegen_->LiteralFloatAddress( |
| 3374 | second.GetConstant()->AsFloatConstant()->GetValue())); |
| Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3375 | } else { |
| 3376 | DCHECK(second.IsStackSlot()); |
| 3377 | __ mulss(first.AsFpuRegister<XmmRegister>(), |
| 3378 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 3379 | } |
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3380 | break; |
| Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3381 | } |
| 3382 | |
| 3383 | case Primitive::kPrimDouble: { |
| Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3384 | DCHECK(first.Equals(out)); |
| Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3385 | if (second.IsFpuRegister()) { |
| 3386 | __ mulsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3387 | } else if (second.IsConstant()) { |
| 3388 | __ mulsd(first.AsFpuRegister<XmmRegister>(), |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 3389 | codegen_->LiteralDoubleAddress( |
| 3390 | second.GetConstant()->AsDoubleConstant()->GetValue())); |
| Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3391 | } else { |
| 3392 | DCHECK(second.IsDoubleStackSlot()); |
| 3393 | __ mulsd(first.AsFpuRegister<XmmRegister>(), |
| 3394 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 3395 | } |
| Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3396 | break; |
| 3397 | } |
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3398 | |
| 3399 | default: |
| Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3400 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3401 | } |
| 3402 | } |
| 3403 | |
| Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3404 | void InstructionCodeGeneratorX86_64::PushOntoFPStack(Location source, uint32_t temp_offset, |
| 3405 | uint32_t stack_adjustment, bool is_float) { |
| 3406 | if (source.IsStackSlot()) { |
| 3407 | DCHECK(is_float); |
| 3408 | __ flds(Address(CpuRegister(RSP), source.GetStackIndex() + stack_adjustment)); |
| 3409 | } else if (source.IsDoubleStackSlot()) { |
| 3410 | DCHECK(!is_float); |
| 3411 | __ fldl(Address(CpuRegister(RSP), source.GetStackIndex() + stack_adjustment)); |
| 3412 | } else { |
| 3413 | // Write the value to the temporary location on the stack and load to FP stack. |
| 3414 | if (is_float) { |
| 3415 | Location stack_temp = Location::StackSlot(temp_offset); |
| 3416 | codegen_->Move(stack_temp, source); |
| 3417 | __ flds(Address(CpuRegister(RSP), temp_offset)); |
| 3418 | } else { |
| 3419 | Location stack_temp = Location::DoubleStackSlot(temp_offset); |
| 3420 | codegen_->Move(stack_temp, source); |
| 3421 | __ fldl(Address(CpuRegister(RSP), temp_offset)); |
| 3422 | } |
| 3423 | } |
| 3424 | } |
| 3425 | |
| 3426 | void InstructionCodeGeneratorX86_64::GenerateRemFP(HRem *rem) { |
| 3427 | Primitive::Type type = rem->GetResultType(); |
| 3428 | bool is_float = type == Primitive::kPrimFloat; |
| 3429 | size_t elem_size = Primitive::ComponentSize(type); |
| 3430 | LocationSummary* locations = rem->GetLocations(); |
| 3431 | Location first = locations->InAt(0); |
| 3432 | Location second = locations->InAt(1); |
| 3433 | Location out = locations->Out(); |
| 3434 | |
| 3435 | // Create stack space for 2 elements. |
| 3436 | // TODO: enhance register allocator to ask for stack temporaries. |
| 3437 | __ subq(CpuRegister(RSP), Immediate(2 * elem_size)); |
| 3438 | |
| 3439 | // Load the values to the FP stack in reverse order, using temporaries if needed. |
| 3440 | PushOntoFPStack(second, elem_size, 2 * elem_size, is_float); |
| 3441 | PushOntoFPStack(first, 0, 2 * elem_size, is_float); |
| 3442 | |
| 3443 | // Loop doing FPREM until we stabilize. |
| Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 3444 | NearLabel retry; |
| Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3445 | __ Bind(&retry); |
| 3446 | __ fprem(); |
| 3447 | |
| 3448 | // Move FP status to AX. |
| 3449 | __ fstsw(); |
| 3450 | |
| 3451 | // And see if the argument reduction is complete. This is signaled by the |
| 3452 | // C2 FPU flag bit set to 0. |
| 3453 | __ andl(CpuRegister(RAX), Immediate(kC2ConditionMask)); |
| 3454 | __ j(kNotEqual, &retry); |
| 3455 | |
| 3456 | // We have settled on the final value. Retrieve it into an XMM register. |
| 3457 | // Store FP top of stack to real stack. |
| 3458 | if (is_float) { |
| 3459 | __ fsts(Address(CpuRegister(RSP), 0)); |
| 3460 | } else { |
| 3461 | __ fstl(Address(CpuRegister(RSP), 0)); |
| 3462 | } |
| 3463 | |
| 3464 | // Pop the 2 items from the FP stack. |
| 3465 | __ fucompp(); |
| 3466 | |
| 3467 | // Load the value from the stack into an XMM register. |
| 3468 | DCHECK(out.IsFpuRegister()) << out; |
| 3469 | if (is_float) { |
| 3470 | __ movss(out.AsFpuRegister<XmmRegister>(), Address(CpuRegister(RSP), 0)); |
| 3471 | } else { |
| 3472 | __ movsd(out.AsFpuRegister<XmmRegister>(), Address(CpuRegister(RSP), 0)); |
| 3473 | } |
| 3474 | |
| 3475 | // And remove the temporary stack space we allocated. |
| 3476 | __ addq(CpuRegister(RSP), Immediate(2 * elem_size)); |
| 3477 | } |
| 3478 | |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3479 | void InstructionCodeGeneratorX86_64::DivRemOneOrMinusOne(HBinaryOperation* instruction) { |
| 3480 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3481 | |
| 3482 | LocationSummary* locations = instruction->GetLocations(); |
| 3483 | Location second = locations->InAt(1); |
| 3484 | DCHECK(second.IsConstant()); |
| 3485 | |
| 3486 | CpuRegister output_register = locations->Out().AsRegister<CpuRegister>(); |
| 3487 | CpuRegister input_register = locations->InAt(0).AsRegister<CpuRegister>(); |
| Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3488 | int64_t imm = Int64FromConstant(second.GetConstant()); |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3489 | |
| 3490 | DCHECK(imm == 1 || imm == -1); |
| 3491 | |
| 3492 | switch (instruction->GetResultType()) { |
| 3493 | case Primitive::kPrimInt: { |
| 3494 | if (instruction->IsRem()) { |
| 3495 | __ xorl(output_register, output_register); |
| 3496 | } else { |
| 3497 | __ movl(output_register, input_register); |
| 3498 | if (imm == -1) { |
| 3499 | __ negl(output_register); |
| 3500 | } |
| 3501 | } |
| 3502 | break; |
| 3503 | } |
| 3504 | |
| 3505 | case Primitive::kPrimLong: { |
| 3506 | if (instruction->IsRem()) { |
| Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 3507 | __ xorl(output_register, output_register); |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3508 | } else { |
| 3509 | __ movq(output_register, input_register); |
| 3510 | if (imm == -1) { |
| 3511 | __ negq(output_register); |
| 3512 | } |
| 3513 | } |
| 3514 | break; |
| 3515 | } |
| 3516 | |
| 3517 | default: |
| Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3518 | LOG(FATAL) << "Unexpected type for div by (-)1 " << instruction->GetResultType(); |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3519 | } |
| 3520 | } |
| 3521 | |
| Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3522 | void InstructionCodeGeneratorX86_64::DivByPowerOfTwo(HDiv* instruction) { |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3523 | LocationSummary* locations = instruction->GetLocations(); |
| 3524 | Location second = locations->InAt(1); |
| 3525 | |
| 3526 | CpuRegister output_register = locations->Out().AsRegister<CpuRegister>(); |
| 3527 | CpuRegister numerator = locations->InAt(0).AsRegister<CpuRegister>(); |
| 3528 | |
| Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3529 | int64_t imm = Int64FromConstant(second.GetConstant()); |
| Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3530 | DCHECK(IsPowerOfTwo(AbsOrMin(imm))); |
| 3531 | uint64_t abs_imm = AbsOrMin(imm); |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3532 | |
| 3533 | CpuRegister tmp = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 3534 | |
| 3535 | if (instruction->GetResultType() == Primitive::kPrimInt) { |
| Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3536 | __ leal(tmp, Address(numerator, abs_imm - 1)); |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3537 | __ testl(numerator, numerator); |
| 3538 | __ cmov(kGreaterEqual, tmp, numerator); |
| 3539 | int shift = CTZ(imm); |
| 3540 | __ sarl(tmp, Immediate(shift)); |
| 3541 | |
| 3542 | if (imm < 0) { |
| 3543 | __ negl(tmp); |
| 3544 | } |
| 3545 | |
| 3546 | __ movl(output_register, tmp); |
| 3547 | } else { |
| 3548 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong); |
| 3549 | CpuRegister rdx = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 3550 | |
| Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3551 | codegen_->Load64BitValue(rdx, abs_imm - 1); |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3552 | __ addq(rdx, numerator); |
| 3553 | __ testq(numerator, numerator); |
| 3554 | __ cmov(kGreaterEqual, rdx, numerator); |
| 3555 | int shift = CTZ(imm); |
| 3556 | __ sarq(rdx, Immediate(shift)); |
| 3557 | |
| 3558 | if (imm < 0) { |
| 3559 | __ negq(rdx); |
| 3560 | } |
| 3561 | |
| 3562 | __ movq(output_register, rdx); |
| 3563 | } |
| 3564 | } |
| 3565 | |
| 3566 | void InstructionCodeGeneratorX86_64::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) { |
| 3567 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3568 | |
| 3569 | LocationSummary* locations = instruction->GetLocations(); |
| 3570 | Location second = locations->InAt(1); |
| 3571 | |
| 3572 | CpuRegister numerator = instruction->IsDiv() ? locations->GetTemp(1).AsRegister<CpuRegister>() |
| 3573 | : locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 3574 | CpuRegister eax = locations->InAt(0).AsRegister<CpuRegister>(); |
| 3575 | CpuRegister edx = instruction->IsDiv() ? locations->GetTemp(0).AsRegister<CpuRegister>() |
| 3576 | : locations->Out().AsRegister<CpuRegister>(); |
| 3577 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
| 3578 | |
| 3579 | DCHECK_EQ(RAX, eax.AsRegister()); |
| 3580 | DCHECK_EQ(RDX, edx.AsRegister()); |
| 3581 | if (instruction->IsDiv()) { |
| 3582 | DCHECK_EQ(RAX, out.AsRegister()); |
| 3583 | } else { |
| 3584 | DCHECK_EQ(RDX, out.AsRegister()); |
| 3585 | } |
| 3586 | |
| 3587 | int64_t magic; |
| 3588 | int shift; |
| 3589 | |
| Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3590 | // TODO: can these branches be written as one? |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3591 | if (instruction->GetResultType() == Primitive::kPrimInt) { |
| 3592 | int imm = second.GetConstant()->AsIntConstant()->GetValue(); |
| 3593 | |
| 3594 | CalculateMagicAndShiftForDivRem(imm, false /* is_long */, &magic, &shift); |
| 3595 | |
| 3596 | __ movl(numerator, eax); |
| 3597 | |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3598 | __ movl(eax, Immediate(magic)); |
| 3599 | __ imull(numerator); |
| 3600 | |
| 3601 | if (imm > 0 && magic < 0) { |
| 3602 | __ addl(edx, numerator); |
| 3603 | } else if (imm < 0 && magic > 0) { |
| 3604 | __ subl(edx, numerator); |
| 3605 | } |
| 3606 | |
| 3607 | if (shift != 0) { |
| 3608 | __ sarl(edx, Immediate(shift)); |
| 3609 | } |
| 3610 | |
| 3611 | __ movl(eax, edx); |
| 3612 | __ shrl(edx, Immediate(31)); |
| 3613 | __ addl(edx, eax); |
| 3614 | |
| 3615 | if (instruction->IsRem()) { |
| 3616 | __ movl(eax, numerator); |
| 3617 | __ imull(edx, Immediate(imm)); |
| 3618 | __ subl(eax, edx); |
| 3619 | __ movl(edx, eax); |
| 3620 | } else { |
| 3621 | __ movl(eax, edx); |
| 3622 | } |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3623 | } else { |
| 3624 | int64_t imm = second.GetConstant()->AsLongConstant()->GetValue(); |
| 3625 | |
| 3626 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong); |
| 3627 | |
| 3628 | CpuRegister rax = eax; |
| 3629 | CpuRegister rdx = edx; |
| 3630 | |
| 3631 | CalculateMagicAndShiftForDivRem(imm, true /* is_long */, &magic, &shift); |
| 3632 | |
| 3633 | // Save the numerator. |
| 3634 | __ movq(numerator, rax); |
| 3635 | |
| 3636 | // RAX = magic |
| Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 3637 | codegen_->Load64BitValue(rax, magic); |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3638 | |
| 3639 | // RDX:RAX = magic * numerator |
| 3640 | __ imulq(numerator); |
| 3641 | |
| 3642 | if (imm > 0 && magic < 0) { |
| Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3643 | // RDX += numerator |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3644 | __ addq(rdx, numerator); |
| 3645 | } else if (imm < 0 && magic > 0) { |
| 3646 | // RDX -= numerator |
| 3647 | __ subq(rdx, numerator); |
| 3648 | } |
| 3649 | |
| 3650 | // Shift if needed. |
| 3651 | if (shift != 0) { |
| 3652 | __ sarq(rdx, Immediate(shift)); |
| 3653 | } |
| 3654 | |
| 3655 | // RDX += 1 if RDX < 0 |
| 3656 | __ movq(rax, rdx); |
| 3657 | __ shrq(rdx, Immediate(63)); |
| 3658 | __ addq(rdx, rax); |
| 3659 | |
| 3660 | if (instruction->IsRem()) { |
| 3661 | __ movq(rax, numerator); |
| 3662 | |
| 3663 | if (IsInt<32>(imm)) { |
| 3664 | __ imulq(rdx, Immediate(static_cast<int32_t>(imm))); |
| 3665 | } else { |
| Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 3666 | __ imulq(rdx, codegen_->LiteralInt64Address(imm)); |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3667 | } |
| 3668 | |
| 3669 | __ subq(rax, rdx); |
| 3670 | __ movq(rdx, rax); |
| 3671 | } else { |
| 3672 | __ movq(rax, rdx); |
| 3673 | } |
| 3674 | } |
| 3675 | } |
| 3676 | |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3677 | void InstructionCodeGeneratorX86_64::GenerateDivRemIntegral(HBinaryOperation* instruction) { |
| 3678 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3679 | Primitive::Type type = instruction->GetResultType(); |
| Calin Juravle | c70d1d9 | 2017-03-27 18:10:04 -0700 | [diff] [blame] | 3680 | DCHECK(type == Primitive::kPrimInt || type == Primitive::kPrimLong); |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3681 | |
| 3682 | bool is_div = instruction->IsDiv(); |
| 3683 | LocationSummary* locations = instruction->GetLocations(); |
| 3684 | |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3685 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
| 3686 | Location second = locations->InAt(1); |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3687 | |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3688 | DCHECK_EQ(RAX, locations->InAt(0).AsRegister<CpuRegister>().AsRegister()); |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3689 | DCHECK_EQ(is_div ? RAX : RDX, out.AsRegister()); |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3690 | |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3691 | if (second.IsConstant()) { |
| Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3692 | int64_t imm = Int64FromConstant(second.GetConstant()); |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3693 | |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3694 | if (imm == 0) { |
| 3695 | // Do not generate anything. DivZeroCheck would prevent any code to be executed. |
| 3696 | } else if (imm == 1 || imm == -1) { |
| 3697 | DivRemOneOrMinusOne(instruction); |
| Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3698 | } else if (instruction->IsDiv() && IsPowerOfTwo(AbsOrMin(imm))) { |
| Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3699 | DivByPowerOfTwo(instruction->AsDiv()); |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3700 | } else { |
| 3701 | DCHECK(imm <= -2 || imm >= 2); |
| 3702 | GenerateDivRemWithAnyConstant(instruction); |
| 3703 | } |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3704 | } else { |
| Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 3705 | SlowPathCode* slow_path = |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3706 | new (GetGraph()->GetArena()) DivRemMinusOneSlowPathX86_64( |
| David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 3707 | instruction, out.AsRegister(), type, is_div); |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3708 | codegen_->AddSlowPath(slow_path); |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3709 | |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3710 | CpuRegister second_reg = second.AsRegister<CpuRegister>(); |
| 3711 | // 0x80000000(00000000)/-1 triggers an arithmetic exception! |
| 3712 | // Dividing by -1 is actually negation and -0x800000000(00000000) = 0x80000000(00000000) |
| 3713 | // so it's safe to just use negl instead of more complex comparisons. |
| 3714 | if (type == Primitive::kPrimInt) { |
| 3715 | __ cmpl(second_reg, Immediate(-1)); |
| 3716 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3717 | // edx:eax <- sign-extended of eax |
| 3718 | __ cdq(); |
| 3719 | // eax = quotient, edx = remainder |
| 3720 | __ idivl(second_reg); |
| 3721 | } else { |
| 3722 | __ cmpq(second_reg, Immediate(-1)); |
| 3723 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3724 | // rdx:rax <- sign-extended of rax |
| 3725 | __ cqo(); |
| 3726 | // rax = quotient, rdx = remainder |
| 3727 | __ idivq(second_reg); |
| 3728 | } |
| 3729 | __ Bind(slow_path->GetExitLabel()); |
| 3730 | } |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3731 | } |
| 3732 | |
| Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3733 | void LocationsBuilderX86_64::VisitDiv(HDiv* div) { |
| 3734 | LocationSummary* locations = |
| 3735 | new (GetGraph()->GetArena()) LocationSummary(div, LocationSummary::kNoCall); |
| 3736 | switch (div->GetResultType()) { |
| Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3737 | case Primitive::kPrimInt: |
| 3738 | case Primitive::kPrimLong: { |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3739 | locations->SetInAt(0, Location::RegisterLocation(RAX)); |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3740 | locations->SetInAt(1, Location::RegisterOrConstant(div->InputAt(1))); |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3741 | locations->SetOut(Location::SameAsFirstInput()); |
| 3742 | // Intel uses edx:eax as the dividend. |
| 3743 | locations->AddTemp(Location::RegisterLocation(RDX)); |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3744 | // We need to save the numerator while we tweak rax and rdx. As we are using imul in a way |
| 3745 | // which enforces results to be in RAX and RDX, things are simpler if we use RDX also as |
| 3746 | // output and request another temp. |
| 3747 | if (div->InputAt(1)->IsConstant()) { |
| 3748 | locations->AddTemp(Location::RequiresRegister()); |
| 3749 | } |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3750 | break; |
| 3751 | } |
| Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3752 | |
| Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3753 | case Primitive::kPrimFloat: |
| 3754 | case Primitive::kPrimDouble: { |
| 3755 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3756 | locations->SetInAt(1, Location::Any()); |
| Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3757 | locations->SetOut(Location::SameAsFirstInput()); |
| 3758 | break; |
| 3759 | } |
| 3760 | |
| 3761 | default: |
| 3762 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 3763 | } |
| 3764 | } |
| 3765 | |
| 3766 | void InstructionCodeGeneratorX86_64::VisitDiv(HDiv* div) { |
| 3767 | LocationSummary* locations = div->GetLocations(); |
| 3768 | Location first = locations->InAt(0); |
| 3769 | Location second = locations->InAt(1); |
| 3770 | DCHECK(first.Equals(locations->Out())); |
| 3771 | |
| Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3772 | Primitive::Type type = div->GetResultType(); |
| 3773 | switch (type) { |
| 3774 | case Primitive::kPrimInt: |
| 3775 | case Primitive::kPrimLong: { |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3776 | GenerateDivRemIntegral(div); |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3777 | break; |
| 3778 | } |
| 3779 | |
| Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3780 | case Primitive::kPrimFloat: { |
| Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3781 | if (second.IsFpuRegister()) { |
| 3782 | __ divss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3783 | } else if (second.IsConstant()) { |
| 3784 | __ divss(first.AsFpuRegister<XmmRegister>(), |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 3785 | codegen_->LiteralFloatAddress( |
| 3786 | second.GetConstant()->AsFloatConstant()->GetValue())); |
| Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3787 | } else { |
| 3788 | DCHECK(second.IsStackSlot()); |
| 3789 | __ divss(first.AsFpuRegister<XmmRegister>(), |
| 3790 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 3791 | } |
| Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3792 | break; |
| 3793 | } |
| 3794 | |
| 3795 | case Primitive::kPrimDouble: { |
| Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3796 | if (second.IsFpuRegister()) { |
| 3797 | __ divsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3798 | } else if (second.IsConstant()) { |
| 3799 | __ divsd(first.AsFpuRegister<XmmRegister>(), |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 3800 | codegen_->LiteralDoubleAddress( |
| 3801 | second.GetConstant()->AsDoubleConstant()->GetValue())); |
| Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3802 | } else { |
| 3803 | DCHECK(second.IsDoubleStackSlot()); |
| 3804 | __ divsd(first.AsFpuRegister<XmmRegister>(), |
| 3805 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 3806 | } |
| Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3807 | break; |
| 3808 | } |
| 3809 | |
| 3810 | default: |
| 3811 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 3812 | } |
| 3813 | } |
| 3814 | |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3815 | void LocationsBuilderX86_64::VisitRem(HRem* rem) { |
| Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3816 | Primitive::Type type = rem->GetResultType(); |
| Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3817 | LocationSummary* locations = |
| 3818 | new (GetGraph()->GetArena()) LocationSummary(rem, LocationSummary::kNoCall); |
| Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3819 | |
| 3820 | switch (type) { |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3821 | case Primitive::kPrimInt: |
| 3822 | case Primitive::kPrimLong: { |
| 3823 | locations->SetInAt(0, Location::RegisterLocation(RAX)); |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3824 | locations->SetInAt(1, Location::RegisterOrConstant(rem->InputAt(1))); |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3825 | // Intel uses rdx:rax as the dividend and puts the remainder in rdx |
| 3826 | locations->SetOut(Location::RegisterLocation(RDX)); |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3827 | // We need to save the numerator while we tweak eax and edx. As we are using imul in a way |
| 3828 | // which enforces results to be in RAX and RDX, things are simpler if we use EAX also as |
| 3829 | // output and request another temp. |
| 3830 | if (rem->InputAt(1)->IsConstant()) { |
| 3831 | locations->AddTemp(Location::RequiresRegister()); |
| 3832 | } |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3833 | break; |
| 3834 | } |
| 3835 | |
| 3836 | case Primitive::kPrimFloat: |
| 3837 | case Primitive::kPrimDouble: { |
| Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3838 | locations->SetInAt(0, Location::Any()); |
| 3839 | locations->SetInAt(1, Location::Any()); |
| 3840 | locations->SetOut(Location::RequiresFpuRegister()); |
| 3841 | locations->AddTemp(Location::RegisterLocation(RAX)); |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3842 | break; |
| 3843 | } |
| 3844 | |
| 3845 | default: |
| Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3846 | LOG(FATAL) << "Unexpected rem type " << type; |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3847 | } |
| 3848 | } |
| 3849 | |
| 3850 | void InstructionCodeGeneratorX86_64::VisitRem(HRem* rem) { |
| 3851 | Primitive::Type type = rem->GetResultType(); |
| 3852 | switch (type) { |
| 3853 | case Primitive::kPrimInt: |
| 3854 | case Primitive::kPrimLong: { |
| 3855 | GenerateDivRemIntegral(rem); |
| 3856 | break; |
| 3857 | } |
| Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3858 | case Primitive::kPrimFloat: |
| Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3859 | case Primitive::kPrimDouble: { |
| Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3860 | GenerateRemFP(rem); |
| Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3861 | break; |
| 3862 | } |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3863 | default: |
| 3864 | LOG(FATAL) << "Unexpected rem type " << rem->GetResultType(); |
| 3865 | } |
| 3866 | } |
| 3867 | |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3868 | void LocationsBuilderX86_64::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
| Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 3869 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3870 | locations->SetInAt(0, Location::Any()); |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3871 | } |
| 3872 | |
| 3873 | void InstructionCodeGeneratorX86_64::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
| Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 3874 | SlowPathCode* slow_path = |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3875 | new (GetGraph()->GetArena()) DivZeroCheckSlowPathX86_64(instruction); |
| 3876 | codegen_->AddSlowPath(slow_path); |
| 3877 | |
| 3878 | LocationSummary* locations = instruction->GetLocations(); |
| 3879 | Location value = locations->InAt(0); |
| 3880 | |
| Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3881 | switch (instruction->GetType()) { |
| Nicolas Geoffray | e567161 | 2016-03-16 11:03:54 +0000 | [diff] [blame] | 3882 | case Primitive::kPrimBoolean: |
| Serguei Katkov | 8c0676c | 2015-08-03 13:55:33 +0600 | [diff] [blame] | 3883 | case Primitive::kPrimByte: |
| 3884 | case Primitive::kPrimChar: |
| 3885 | case Primitive::kPrimShort: |
| Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3886 | case Primitive::kPrimInt: { |
| 3887 | if (value.IsRegister()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3888 | __ testl(value.AsRegister<CpuRegister>(), value.AsRegister<CpuRegister>()); |
| Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3889 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3890 | } else if (value.IsStackSlot()) { |
| 3891 | __ cmpl(Address(CpuRegister(RSP), value.GetStackIndex()), Immediate(0)); |
| 3892 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3893 | } else { |
| 3894 | DCHECK(value.IsConstant()) << value; |
| 3895 | if (value.GetConstant()->AsIntConstant()->GetValue() == 0) { |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 3896 | __ jmp(slow_path->GetEntryLabel()); |
| Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3897 | } |
| 3898 | } |
| 3899 | break; |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3900 | } |
| Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3901 | case Primitive::kPrimLong: { |
| 3902 | if (value.IsRegister()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3903 | __ testq(value.AsRegister<CpuRegister>(), value.AsRegister<CpuRegister>()); |
| Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3904 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3905 | } else if (value.IsDoubleStackSlot()) { |
| 3906 | __ cmpq(Address(CpuRegister(RSP), value.GetStackIndex()), Immediate(0)); |
| 3907 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3908 | } else { |
| 3909 | DCHECK(value.IsConstant()) << value; |
| 3910 | if (value.GetConstant()->AsLongConstant()->GetValue() == 0) { |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 3911 | __ jmp(slow_path->GetEntryLabel()); |
| Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3912 | } |
| 3913 | } |
| 3914 | break; |
| 3915 | } |
| 3916 | default: |
| 3917 | LOG(FATAL) << "Unexpected type for HDivZeroCheck " << instruction->GetType(); |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3918 | } |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3919 | } |
| 3920 | |
| Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3921 | void LocationsBuilderX86_64::HandleShift(HBinaryOperation* op) { |
| 3922 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 3923 | |
| 3924 | LocationSummary* locations = |
| 3925 | new (GetGraph()->GetArena()) LocationSummary(op, LocationSummary::kNoCall); |
| 3926 | |
| 3927 | switch (op->GetResultType()) { |
| 3928 | case Primitive::kPrimInt: |
| 3929 | case Primitive::kPrimLong: { |
| 3930 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3931 | // The shift count needs to be in CL. |
| 3932 | locations->SetInAt(1, Location::ByteRegisterOrConstant(RCX, op->InputAt(1))); |
| 3933 | locations->SetOut(Location::SameAsFirstInput()); |
| 3934 | break; |
| 3935 | } |
| 3936 | default: |
| 3937 | LOG(FATAL) << "Unexpected operation type " << op->GetResultType(); |
| 3938 | } |
| 3939 | } |
| 3940 | |
| 3941 | void InstructionCodeGeneratorX86_64::HandleShift(HBinaryOperation* op) { |
| 3942 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 3943 | |
| 3944 | LocationSummary* locations = op->GetLocations(); |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3945 | CpuRegister first_reg = locations->InAt(0).AsRegister<CpuRegister>(); |
| Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3946 | Location second = locations->InAt(1); |
| 3947 | |
| 3948 | switch (op->GetResultType()) { |
| 3949 | case Primitive::kPrimInt: { |
| 3950 | if (second.IsRegister()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3951 | CpuRegister second_reg = second.AsRegister<CpuRegister>(); |
| Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3952 | if (op->IsShl()) { |
| 3953 | __ shll(first_reg, second_reg); |
| 3954 | } else if (op->IsShr()) { |
| 3955 | __ sarl(first_reg, second_reg); |
| 3956 | } else { |
| 3957 | __ shrl(first_reg, second_reg); |
| 3958 | } |
| 3959 | } else { |
| Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 3960 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue() & kMaxIntShiftDistance); |
| Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3961 | if (op->IsShl()) { |
| 3962 | __ shll(first_reg, imm); |
| 3963 | } else if (op->IsShr()) { |
| 3964 | __ sarl(first_reg, imm); |
| 3965 | } else { |
| 3966 | __ shrl(first_reg, imm); |
| 3967 | } |
| 3968 | } |
| 3969 | break; |
| 3970 | } |
| 3971 | case Primitive::kPrimLong: { |
| 3972 | if (second.IsRegister()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3973 | CpuRegister second_reg = second.AsRegister<CpuRegister>(); |
| Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3974 | if (op->IsShl()) { |
| 3975 | __ shlq(first_reg, second_reg); |
| 3976 | } else if (op->IsShr()) { |
| 3977 | __ sarq(first_reg, second_reg); |
| 3978 | } else { |
| 3979 | __ shrq(first_reg, second_reg); |
| 3980 | } |
| 3981 | } else { |
| Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 3982 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue() & kMaxLongShiftDistance); |
| Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3983 | if (op->IsShl()) { |
| 3984 | __ shlq(first_reg, imm); |
| 3985 | } else if (op->IsShr()) { |
| 3986 | __ sarq(first_reg, imm); |
| 3987 | } else { |
| 3988 | __ shrq(first_reg, imm); |
| 3989 | } |
| 3990 | } |
| 3991 | break; |
| 3992 | } |
| 3993 | default: |
| 3994 | LOG(FATAL) << "Unexpected operation type " << op->GetResultType(); |
| Vladimir Marko | 351dddf | 2015-12-11 16:34:46 +0000 | [diff] [blame] | 3995 | UNREACHABLE(); |
| Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3996 | } |
| 3997 | } |
| 3998 | |
| Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 3999 | void LocationsBuilderX86_64::VisitRor(HRor* ror) { |
| 4000 | LocationSummary* locations = |
| 4001 | new (GetGraph()->GetArena()) LocationSummary(ror, LocationSummary::kNoCall); |
| 4002 | |
| 4003 | switch (ror->GetResultType()) { |
| 4004 | case Primitive::kPrimInt: |
| 4005 | case Primitive::kPrimLong: { |
| 4006 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4007 | // The shift count needs to be in CL (unless it is a constant). |
| 4008 | locations->SetInAt(1, Location::ByteRegisterOrConstant(RCX, ror->InputAt(1))); |
| 4009 | locations->SetOut(Location::SameAsFirstInput()); |
| 4010 | break; |
| 4011 | } |
| 4012 | default: |
| 4013 | LOG(FATAL) << "Unexpected operation type " << ror->GetResultType(); |
| 4014 | UNREACHABLE(); |
| 4015 | } |
| 4016 | } |
| 4017 | |
| 4018 | void InstructionCodeGeneratorX86_64::VisitRor(HRor* ror) { |
| 4019 | LocationSummary* locations = ror->GetLocations(); |
| 4020 | CpuRegister first_reg = locations->InAt(0).AsRegister<CpuRegister>(); |
| 4021 | Location second = locations->InAt(1); |
| 4022 | |
| 4023 | switch (ror->GetResultType()) { |
| 4024 | case Primitive::kPrimInt: |
| 4025 | if (second.IsRegister()) { |
| 4026 | CpuRegister second_reg = second.AsRegister<CpuRegister>(); |
| 4027 | __ rorl(first_reg, second_reg); |
| 4028 | } else { |
| Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4029 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue() & kMaxIntShiftDistance); |
| Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4030 | __ rorl(first_reg, imm); |
| 4031 | } |
| 4032 | break; |
| 4033 | case Primitive::kPrimLong: |
| 4034 | if (second.IsRegister()) { |
| 4035 | CpuRegister second_reg = second.AsRegister<CpuRegister>(); |
| 4036 | __ rorq(first_reg, second_reg); |
| 4037 | } else { |
| Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4038 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue() & kMaxLongShiftDistance); |
| Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4039 | __ rorq(first_reg, imm); |
| 4040 | } |
| 4041 | break; |
| 4042 | default: |
| 4043 | LOG(FATAL) << "Unexpected operation type " << ror->GetResultType(); |
| 4044 | UNREACHABLE(); |
| 4045 | } |
| 4046 | } |
| 4047 | |
| Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4048 | void LocationsBuilderX86_64::VisitShl(HShl* shl) { |
| 4049 | HandleShift(shl); |
| 4050 | } |
| 4051 | |
| 4052 | void InstructionCodeGeneratorX86_64::VisitShl(HShl* shl) { |
| 4053 | HandleShift(shl); |
| 4054 | } |
| 4055 | |
| 4056 | void LocationsBuilderX86_64::VisitShr(HShr* shr) { |
| 4057 | HandleShift(shr); |
| 4058 | } |
| 4059 | |
| 4060 | void InstructionCodeGeneratorX86_64::VisitShr(HShr* shr) { |
| 4061 | HandleShift(shr); |
| 4062 | } |
| 4063 | |
| 4064 | void LocationsBuilderX86_64::VisitUShr(HUShr* ushr) { |
| 4065 | HandleShift(ushr); |
| 4066 | } |
| 4067 | |
| 4068 | void InstructionCodeGeneratorX86_64::VisitUShr(HUShr* ushr) { |
| 4069 | HandleShift(ushr); |
| 4070 | } |
| 4071 | |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4072 | void LocationsBuilderX86_64::VisitNewInstance(HNewInstance* instruction) { |
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4073 | LocationSummary* locations = |
| Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 4074 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
| Nicolas Geoffray | 9ae0daa | 2014-09-30 22:40:23 +0100 | [diff] [blame] | 4075 | InvokeRuntimeCallingConvention calling_convention; |
| David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4076 | if (instruction->IsStringAlloc()) { |
| 4077 | locations->AddTemp(Location::RegisterLocation(kMethodRegisterArgument)); |
| 4078 | } else { |
| 4079 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4080 | } |
| Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4081 | locations->SetOut(Location::RegisterLocation(RAX)); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4082 | } |
| 4083 | |
| 4084 | void InstructionCodeGeneratorX86_64::VisitNewInstance(HNewInstance* instruction) { |
| Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4085 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 4086 | // of poisoning the reference. |
| David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4087 | if (instruction->IsStringAlloc()) { |
| 4088 | // String is allocated through StringFactory. Call NewEmptyString entry point. |
| 4089 | CpuRegister temp = instruction->GetLocations()->GetTemp(0).AsRegister<CpuRegister>(); |
| Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 4090 | MemberOffset code_offset = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kX86_64PointerSize); |
| David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4091 | __ gs()->movq(temp, Address::Absolute(QUICK_ENTRY_POINT(pNewEmptyString), /* no_rip */ true)); |
| 4092 | __ call(Address(temp, code_offset.SizeValue())); |
| 4093 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
| 4094 | } else { |
| Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 4095 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), instruction, instruction->GetDexPc()); |
| Nicolas Geoffray | 0d3998b | 2017-01-12 15:35:12 +0000 | [diff] [blame] | 4096 | CheckEntrypointTypes<kQuickAllocObjectWithChecks, void*, mirror::Class*>(); |
| David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4097 | DCHECK(!codegen_->IsLeafMethod()); |
| 4098 | } |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4099 | } |
| 4100 | |
| Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4101 | void LocationsBuilderX86_64::VisitNewArray(HNewArray* instruction) { |
| 4102 | LocationSummary* locations = |
| Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 4103 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
| Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4104 | InvokeRuntimeCallingConvention calling_convention; |
| Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4105 | locations->SetOut(Location::RegisterLocation(RAX)); |
| Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 4106 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 4107 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4108 | } |
| 4109 | |
| 4110 | void InstructionCodeGeneratorX86_64::VisitNewArray(HNewArray* instruction) { |
| Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4111 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 4112 | // of poisoning the reference. |
| Nicolas Geoffray | b048cb7 | 2017-01-23 22:50:24 +0000 | [diff] [blame] | 4113 | QuickEntrypointEnum entrypoint = |
| 4114 | CodeGenerator::GetArrayAllocationEntrypoint(instruction->GetLoadClass()->GetClass()); |
| 4115 | codegen_->InvokeRuntime(entrypoint, instruction, instruction->GetDexPc()); |
| Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 4116 | CheckEntrypointTypes<kQuickAllocArrayResolved, void*, mirror::Class*, int32_t>(); |
| Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4117 | DCHECK(!codegen_->IsLeafMethod()); |
| Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4118 | } |
| 4119 | |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4120 | void LocationsBuilderX86_64::VisitParameterValue(HParameterValue* instruction) { |
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4121 | LocationSummary* locations = |
| 4122 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4123 | Location location = parameter_visitor_.GetNextLocation(instruction->GetType()); |
| 4124 | if (location.IsStackSlot()) { |
| 4125 | location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 4126 | } else if (location.IsDoubleStackSlot()) { |
| 4127 | location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 4128 | } |
| 4129 | locations->SetOut(location); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4130 | } |
| 4131 | |
| Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4132 | void InstructionCodeGeneratorX86_64::VisitParameterValue( |
| 4133 | HParameterValue* instruction ATTRIBUTE_UNUSED) { |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4134 | // Nothing to do, the parameter is already at its location. |
| Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4135 | } |
| 4136 | |
| 4137 | void LocationsBuilderX86_64::VisitCurrentMethod(HCurrentMethod* instruction) { |
| 4138 | LocationSummary* locations = |
| 4139 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 4140 | locations->SetOut(Location::RegisterLocation(kMethodRegisterArgument)); |
| 4141 | } |
| 4142 | |
| 4143 | void InstructionCodeGeneratorX86_64::VisitCurrentMethod( |
| 4144 | HCurrentMethod* instruction ATTRIBUTE_UNUSED) { |
| 4145 | // Nothing to do, the method is already at its location. |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4146 | } |
| 4147 | |
| Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4148 | void LocationsBuilderX86_64::VisitClassTableGet(HClassTableGet* instruction) { |
| 4149 | LocationSummary* locations = |
| 4150 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 4151 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4152 | locations->SetOut(Location::RequiresRegister()); |
| 4153 | } |
| 4154 | |
| 4155 | void InstructionCodeGeneratorX86_64::VisitClassTableGet(HClassTableGet* instruction) { |
| 4156 | LocationSummary* locations = instruction->GetLocations(); |
| Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4157 | if (instruction->GetTableKind() == HClassTableGet::TableKind::kVTable) { |
| Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 4158 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4159 | instruction->GetIndex(), kX86_64PointerSize).SizeValue(); |
| Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 4160 | __ movq(locations->Out().AsRegister<CpuRegister>(), |
| 4161 | Address(locations->InAt(0).AsRegister<CpuRegister>(), method_offset)); |
| Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4162 | } else { |
| Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 4163 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
| Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 4164 | instruction->GetIndex(), kX86_64PointerSize)); |
| Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 4165 | __ movq(locations->Out().AsRegister<CpuRegister>(), |
| 4166 | Address(locations->InAt(0).AsRegister<CpuRegister>(), |
| 4167 | mirror::Class::ImtPtrOffset(kX86_64PointerSize).Uint32Value())); |
| Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 4168 | __ movq(locations->Out().AsRegister<CpuRegister>(), |
| 4169 | Address(locations->Out().AsRegister<CpuRegister>(), method_offset)); |
| Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4170 | } |
| Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4171 | } |
| 4172 | |
| Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4173 | void LocationsBuilderX86_64::VisitNot(HNot* not_) { |
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4174 | LocationSummary* locations = |
| Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4175 | new (GetGraph()->GetArena()) LocationSummary(not_, LocationSummary::kNoCall); |
| Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 4176 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4177 | locations->SetOut(Location::SameAsFirstInput()); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4178 | } |
| 4179 | |
| Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4180 | void InstructionCodeGeneratorX86_64::VisitNot(HNot* not_) { |
| 4181 | LocationSummary* locations = not_->GetLocations(); |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4182 | DCHECK_EQ(locations->InAt(0).AsRegister<CpuRegister>().AsRegister(), |
| 4183 | locations->Out().AsRegister<CpuRegister>().AsRegister()); |
| Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4184 | Location out = locations->Out(); |
| Nicolas Geoffray | d8ef2e9 | 2015-02-24 16:02:06 +0000 | [diff] [blame] | 4185 | switch (not_->GetResultType()) { |
| Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4186 | case Primitive::kPrimInt: |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4187 | __ notl(out.AsRegister<CpuRegister>()); |
| Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4188 | break; |
| 4189 | |
| 4190 | case Primitive::kPrimLong: |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4191 | __ notq(out.AsRegister<CpuRegister>()); |
| Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4192 | break; |
| 4193 | |
| 4194 | default: |
| 4195 | LOG(FATAL) << "Unimplemented type for not operation " << not_->GetResultType(); |
| 4196 | } |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4197 | } |
| 4198 | |
| David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4199 | void LocationsBuilderX86_64::VisitBooleanNot(HBooleanNot* bool_not) { |
| 4200 | LocationSummary* locations = |
| 4201 | new (GetGraph()->GetArena()) LocationSummary(bool_not, LocationSummary::kNoCall); |
| 4202 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4203 | locations->SetOut(Location::SameAsFirstInput()); |
| 4204 | } |
| 4205 | |
| 4206 | void InstructionCodeGeneratorX86_64::VisitBooleanNot(HBooleanNot* bool_not) { |
| David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4207 | LocationSummary* locations = bool_not->GetLocations(); |
| 4208 | DCHECK_EQ(locations->InAt(0).AsRegister<CpuRegister>().AsRegister(), |
| 4209 | locations->Out().AsRegister<CpuRegister>().AsRegister()); |
| 4210 | Location out = locations->Out(); |
| 4211 | __ xorl(out.AsRegister<CpuRegister>(), Immediate(1)); |
| 4212 | } |
| 4213 | |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4214 | void LocationsBuilderX86_64::VisitPhi(HPhi* instruction) { |
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4215 | LocationSummary* locations = |
| 4216 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 4217 | for (size_t i = 0, e = locations->GetInputCount(); i < e; ++i) { |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4218 | locations->SetInAt(i, Location::Any()); |
| 4219 | } |
| 4220 | locations->SetOut(Location::Any()); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4221 | } |
| 4222 | |
| Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4223 | void InstructionCodeGeneratorX86_64::VisitPhi(HPhi* instruction ATTRIBUTE_UNUSED) { |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4224 | LOG(FATAL) << "Unimplemented"; |
| 4225 | } |
| 4226 | |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4227 | void CodeGeneratorX86_64::GenerateMemoryBarrier(MemBarrierKind kind) { |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4228 | /* |
| Roland Levillain | 5e8d5f0 | 2016-10-18 18:03:43 +0100 | [diff] [blame] | 4229 | * 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] | 4230 | * 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] | 4231 | * For those cases, all we need to ensure is that there is a scheduling barrier in place. |
| 4232 | */ |
| 4233 | switch (kind) { |
| 4234 | case MemBarrierKind::kAnyAny: { |
| Mark P Mendell | 17077d8 | 2015-12-16 19:15:59 +0000 | [diff] [blame] | 4235 | MemoryFence(); |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4236 | break; |
| 4237 | } |
| 4238 | case MemBarrierKind::kAnyStore: |
| 4239 | case MemBarrierKind::kLoadAny: |
| 4240 | case MemBarrierKind::kStoreStore: { |
| 4241 | // nop |
| 4242 | break; |
| 4243 | } |
| Mark Mendell | 7aa04a1 | 2016-01-27 22:39:07 -0500 | [diff] [blame] | 4244 | case MemBarrierKind::kNTStoreStore: |
| 4245 | // Non-Temporal Store/Store needs an explicit fence. |
| 4246 | MemoryFence(/* non-temporal */ true); |
| 4247 | break; |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4248 | } |
| 4249 | } |
| 4250 | |
| 4251 | void LocationsBuilderX86_64::HandleFieldGet(HInstruction* instruction) { |
| 4252 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
| 4253 | |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4254 | bool object_field_get_with_read_barrier = |
| 4255 | kEmitCompilerReadBarrier && (instruction->GetType() == Primitive::kPrimNot); |
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4256 | LocationSummary* locations = |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4257 | new (GetGraph()->GetArena()) LocationSummary(instruction, |
| 4258 | object_field_get_with_read_barrier ? |
| 4259 | LocationSummary::kCallOnSlowPath : |
| 4260 | LocationSummary::kNoCall); |
| Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 4261 | if (object_field_get_with_read_barrier && kUseBakerReadBarrier) { |
| Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 4262 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
| Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 4263 | } |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4264 | locations->SetInAt(0, Location::RequiresRegister()); |
| Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4265 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 4266 | locations->SetOut(Location::RequiresFpuRegister()); |
| 4267 | } else { |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4268 | // The output overlaps for an object field get when read barriers |
| 4269 | // are enabled: we do not want the move to overwrite the object's |
| 4270 | // location, as we need it to emit the read barrier. |
| 4271 | locations->SetOut( |
| 4272 | Location::RequiresRegister(), |
| 4273 | object_field_get_with_read_barrier ? Location::kOutputOverlap : Location::kNoOutputOverlap); |
| Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4274 | } |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4275 | } |
| 4276 | |
| 4277 | void InstructionCodeGeneratorX86_64::HandleFieldGet(HInstruction* instruction, |
| 4278 | const FieldInfo& field_info) { |
| 4279 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
| 4280 | |
| 4281 | LocationSummary* locations = instruction->GetLocations(); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4282 | Location base_loc = locations->InAt(0); |
| 4283 | CpuRegister base = base_loc.AsRegister<CpuRegister>(); |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4284 | Location out = locations->Out(); |
| 4285 | bool is_volatile = field_info.IsVolatile(); |
| 4286 | Primitive::Type field_type = field_info.GetFieldType(); |
| 4287 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
| 4288 | |
| 4289 | switch (field_type) { |
| 4290 | case Primitive::kPrimBoolean: { |
| 4291 | __ movzxb(out.AsRegister<CpuRegister>(), Address(base, offset)); |
| 4292 | break; |
| 4293 | } |
| 4294 | |
| 4295 | case Primitive::kPrimByte: { |
| 4296 | __ movsxb(out.AsRegister<CpuRegister>(), Address(base, offset)); |
| 4297 | break; |
| 4298 | } |
| 4299 | |
| 4300 | case Primitive::kPrimShort: { |
| 4301 | __ movsxw(out.AsRegister<CpuRegister>(), Address(base, offset)); |
| 4302 | break; |
| 4303 | } |
| 4304 | |
| 4305 | case Primitive::kPrimChar: { |
| 4306 | __ movzxw(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::kPrimInt: { |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4311 | __ movl(out.AsRegister<CpuRegister>(), Address(base, offset)); |
| 4312 | break; |
| 4313 | } |
| 4314 | |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4315 | case Primitive::kPrimNot: { |
| 4316 | // /* HeapReference<Object> */ out = *(base + offset) |
| 4317 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4318 | // Note that a potential implicit null check is handled in this |
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 4319 | // CodeGeneratorX86_64::GenerateFieldLoadWithBakerReadBarrier call. |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4320 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
| Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 4321 | instruction, out, base, offset, /* needs_null_check */ true); |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4322 | if (is_volatile) { |
| 4323 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4324 | } |
| 4325 | } else { |
| 4326 | __ movl(out.AsRegister<CpuRegister>(), Address(base, offset)); |
| 4327 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4328 | if (is_volatile) { |
| 4329 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4330 | } |
| 4331 | // If read barriers are enabled, emit read barriers other than |
| 4332 | // Baker's using a slow path (and also unpoison the loaded |
| 4333 | // reference, if heap poisoning is enabled). |
| 4334 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out, out, base_loc, offset); |
| 4335 | } |
| 4336 | break; |
| 4337 | } |
| 4338 | |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4339 | case Primitive::kPrimLong: { |
| 4340 | __ movq(out.AsRegister<CpuRegister>(), Address(base, offset)); |
| 4341 | break; |
| 4342 | } |
| 4343 | |
| 4344 | case Primitive::kPrimFloat: { |
| 4345 | __ movss(out.AsFpuRegister<XmmRegister>(), Address(base, offset)); |
| 4346 | break; |
| 4347 | } |
| 4348 | |
| 4349 | case Primitive::kPrimDouble: { |
| 4350 | __ movsd(out.AsFpuRegister<XmmRegister>(), Address(base, offset)); |
| 4351 | break; |
| 4352 | } |
| 4353 | |
| 4354 | case Primitive::kPrimVoid: |
| 4355 | LOG(FATAL) << "Unreachable type " << field_type; |
| 4356 | UNREACHABLE(); |
| 4357 | } |
| 4358 | |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4359 | if (field_type == Primitive::kPrimNot) { |
| 4360 | // Potential implicit null checks, in the case of reference |
| 4361 | // fields, are handled in the previous switch statement. |
| 4362 | } else { |
| 4363 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4364 | } |
| Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4365 | |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4366 | if (is_volatile) { |
| 4367 | if (field_type == Primitive::kPrimNot) { |
| 4368 | // Memory barriers, in the case of references, are also handled |
| 4369 | // in the previous switch statement. |
| 4370 | } else { |
| 4371 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4372 | } |
| Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4373 | } |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4374 | } |
| 4375 | |
| 4376 | void LocationsBuilderX86_64::HandleFieldSet(HInstruction* instruction, |
| 4377 | const FieldInfo& field_info) { |
| 4378 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 4379 | |
| 4380 | LocationSummary* locations = |
| 4381 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4382 | Primitive::Type field_type = field_info.GetFieldType(); |
| Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4383 | bool is_volatile = field_info.IsVolatile(); |
| Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4384 | bool needs_write_barrier = |
| Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4385 | CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1)); |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4386 | |
| Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 4387 | locations->SetInAt(0, Location::RequiresRegister()); |
| Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4388 | if (Primitive::IsFloatingPointType(instruction->InputAt(1)->GetType())) { |
| Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4389 | if (is_volatile) { |
| 4390 | // In order to satisfy the semantics of volatile, this must be a single instruction store. |
| 4391 | locations->SetInAt(1, Location::FpuRegisterOrInt32Constant(instruction->InputAt(1))); |
| 4392 | } else { |
| 4393 | locations->SetInAt(1, Location::FpuRegisterOrConstant(instruction->InputAt(1))); |
| 4394 | } |
| Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4395 | } else { |
| Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4396 | if (is_volatile) { |
| 4397 | // In order to satisfy the semantics of volatile, this must be a single instruction store. |
| 4398 | locations->SetInAt(1, Location::RegisterOrInt32Constant(instruction->InputAt(1))); |
| 4399 | } else { |
| 4400 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 4401 | } |
| Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4402 | } |
| Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4403 | if (needs_write_barrier) { |
| Nicolas Geoffray | 9ae0daa | 2014-09-30 22:40:23 +0100 | [diff] [blame] | 4404 | // Temporary registers for the write barrier. |
| Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4405 | locations->AddTemp(Location::RequiresRegister()); // Possibly used for reference poisoning too. |
| Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 4406 | locations->AddTemp(Location::RequiresRegister()); |
| Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4407 | } else if (kPoisonHeapReferences && field_type == Primitive::kPrimNot) { |
| 4408 | // Temporary register for the reference poisoning. |
| Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 4409 | locations->AddTemp(Location::RequiresRegister()); |
| 4410 | } |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4411 | } |
| 4412 | |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4413 | void InstructionCodeGeneratorX86_64::HandleFieldSet(HInstruction* instruction, |
| Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4414 | const FieldInfo& field_info, |
| 4415 | bool value_can_be_null) { |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4416 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 4417 | |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4418 | LocationSummary* locations = instruction->GetLocations(); |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4419 | CpuRegister base = locations->InAt(0).AsRegister<CpuRegister>(); |
| 4420 | Location value = locations->InAt(1); |
| 4421 | bool is_volatile = field_info.IsVolatile(); |
| 4422 | Primitive::Type field_type = field_info.GetFieldType(); |
| 4423 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
| 4424 | |
| 4425 | if (is_volatile) { |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4426 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyStore); |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4427 | } |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4428 | |
| Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4429 | bool maybe_record_implicit_null_check_done = false; |
| 4430 | |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4431 | switch (field_type) { |
| 4432 | case Primitive::kPrimBoolean: |
| 4433 | case Primitive::kPrimByte: { |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4434 | if (value.IsConstant()) { |
| Nicolas Geoffray | 7861208 | 2017-07-24 14:18:53 +0100 | [diff] [blame] | 4435 | __ movb(Address(base, offset), |
| 4436 | Immediate(CodeGenerator::GetInt8ValueOf(value.GetConstant()))); |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4437 | } else { |
| 4438 | __ movb(Address(base, offset), value.AsRegister<CpuRegister>()); |
| 4439 | } |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4440 | break; |
| 4441 | } |
| 4442 | |
| 4443 | case Primitive::kPrimShort: |
| 4444 | case Primitive::kPrimChar: { |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4445 | if (value.IsConstant()) { |
| Nicolas Geoffray | 7861208 | 2017-07-24 14:18:53 +0100 | [diff] [blame] | 4446 | __ movw(Address(base, offset), |
| 4447 | Immediate(CodeGenerator::GetInt16ValueOf(value.GetConstant()))); |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4448 | } else { |
| 4449 | __ movw(Address(base, offset), value.AsRegister<CpuRegister>()); |
| 4450 | } |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4451 | break; |
| 4452 | } |
| 4453 | |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4454 | case Primitive::kPrimInt: |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4455 | case Primitive::kPrimNot: { |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4456 | if (value.IsConstant()) { |
| 4457 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
| Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4458 | // `field_type == Primitive::kPrimNot` implies `v == 0`. |
| 4459 | DCHECK((field_type != Primitive::kPrimNot) || (v == 0)); |
| 4460 | // Note: if heap poisoning is enabled, no need to poison |
| 4461 | // (negate) `v` if it is a reference, as it would be null. |
| Roland Levillain | 06b66d0 | 2015-07-01 12:47:25 +0100 | [diff] [blame] | 4462 | __ movl(Address(base, offset), Immediate(v)); |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4463 | } else { |
| Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4464 | if (kPoisonHeapReferences && field_type == Primitive::kPrimNot) { |
| 4465 | CpuRegister temp = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 4466 | __ movl(temp, value.AsRegister<CpuRegister>()); |
| 4467 | __ PoisonHeapReference(temp); |
| 4468 | __ movl(Address(base, offset), temp); |
| 4469 | } else { |
| 4470 | __ movl(Address(base, offset), value.AsRegister<CpuRegister>()); |
| 4471 | } |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4472 | } |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4473 | break; |
| 4474 | } |
| 4475 | |
| 4476 | case Primitive::kPrimLong: { |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4477 | if (value.IsConstant()) { |
| 4478 | int64_t v = value.GetConstant()->AsLongConstant()->GetValue(); |
| Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4479 | codegen_->MoveInt64ToAddress(Address(base, offset), |
| 4480 | Address(base, offset + sizeof(int32_t)), |
| 4481 | v, |
| 4482 | instruction); |
| 4483 | maybe_record_implicit_null_check_done = true; |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4484 | } else { |
| 4485 | __ movq(Address(base, offset), value.AsRegister<CpuRegister>()); |
| 4486 | } |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4487 | break; |
| 4488 | } |
| 4489 | |
| Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4490 | case Primitive::kPrimFloat: { |
| Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4491 | if (value.IsConstant()) { |
| 4492 | int32_t v = |
| 4493 | bit_cast<int32_t, float>(value.GetConstant()->AsFloatConstant()->GetValue()); |
| 4494 | __ movl(Address(base, offset), Immediate(v)); |
| 4495 | } else { |
| 4496 | __ movss(Address(base, offset), value.AsFpuRegister<XmmRegister>()); |
| 4497 | } |
| Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4498 | break; |
| 4499 | } |
| 4500 | |
| 4501 | case Primitive::kPrimDouble: { |
| Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4502 | if (value.IsConstant()) { |
| 4503 | int64_t v = |
| 4504 | bit_cast<int64_t, double>(value.GetConstant()->AsDoubleConstant()->GetValue()); |
| 4505 | codegen_->MoveInt64ToAddress(Address(base, offset), |
| 4506 | Address(base, offset + sizeof(int32_t)), |
| 4507 | v, |
| 4508 | instruction); |
| 4509 | maybe_record_implicit_null_check_done = true; |
| 4510 | } else { |
| 4511 | __ movsd(Address(base, offset), value.AsFpuRegister<XmmRegister>()); |
| 4512 | } |
| Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4513 | break; |
| 4514 | } |
| 4515 | |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4516 | case Primitive::kPrimVoid: |
| 4517 | LOG(FATAL) << "Unreachable type " << field_type; |
| Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 4518 | UNREACHABLE(); |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4519 | } |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4520 | |
| Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4521 | if (!maybe_record_implicit_null_check_done) { |
| 4522 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4523 | } |
| Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4524 | |
| 4525 | if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) { |
| 4526 | CpuRegister temp = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 4527 | CpuRegister card = locations->GetTemp(1).AsRegister<CpuRegister>(); |
| Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4528 | codegen_->MarkGCCard(temp, card, base, value.AsRegister<CpuRegister>(), value_can_be_null); |
| Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4529 | } |
| 4530 | |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4531 | if (is_volatile) { |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4532 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyAny); |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4533 | } |
| 4534 | } |
| 4535 | |
| 4536 | void LocationsBuilderX86_64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
| 4537 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 4538 | } |
| 4539 | |
| 4540 | void InstructionCodeGeneratorX86_64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
| Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4541 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4542 | } |
| 4543 | |
| 4544 | void LocationsBuilderX86_64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4545 | HandleFieldGet(instruction); |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4546 | } |
| 4547 | |
| 4548 | void InstructionCodeGeneratorX86_64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4549 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 4550 | } |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4551 | |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4552 | void LocationsBuilderX86_64::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 4553 | HandleFieldGet(instruction); |
| 4554 | } |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4555 | |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4556 | void InstructionCodeGeneratorX86_64::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 4557 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 4558 | } |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4559 | |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4560 | void LocationsBuilderX86_64::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
| 4561 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 4562 | } |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4563 | |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4564 | void InstructionCodeGeneratorX86_64::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
| Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4565 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4566 | } |
| 4567 | |
| Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 4568 | void LocationsBuilderX86_64::VisitUnresolvedInstanceFieldGet( |
| 4569 | HUnresolvedInstanceFieldGet* instruction) { |
| 4570 | FieldAccessCallingConventionX86_64 calling_convention; |
| 4571 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4572 | instruction, instruction->GetFieldType(), calling_convention); |
| 4573 | } |
| 4574 | |
| 4575 | void InstructionCodeGeneratorX86_64::VisitUnresolvedInstanceFieldGet( |
| 4576 | HUnresolvedInstanceFieldGet* instruction) { |
| 4577 | FieldAccessCallingConventionX86_64 calling_convention; |
| 4578 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4579 | instruction->GetFieldType(), |
| 4580 | instruction->GetFieldIndex(), |
| 4581 | instruction->GetDexPc(), |
| 4582 | calling_convention); |
| 4583 | } |
| 4584 | |
| 4585 | void LocationsBuilderX86_64::VisitUnresolvedInstanceFieldSet( |
| 4586 | HUnresolvedInstanceFieldSet* instruction) { |
| 4587 | FieldAccessCallingConventionX86_64 calling_convention; |
| 4588 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4589 | instruction, instruction->GetFieldType(), calling_convention); |
| 4590 | } |
| 4591 | |
| 4592 | void InstructionCodeGeneratorX86_64::VisitUnresolvedInstanceFieldSet( |
| 4593 | HUnresolvedInstanceFieldSet* instruction) { |
| 4594 | FieldAccessCallingConventionX86_64 calling_convention; |
| 4595 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4596 | instruction->GetFieldType(), |
| 4597 | instruction->GetFieldIndex(), |
| 4598 | instruction->GetDexPc(), |
| 4599 | calling_convention); |
| 4600 | } |
| 4601 | |
| 4602 | void LocationsBuilderX86_64::VisitUnresolvedStaticFieldGet( |
| 4603 | HUnresolvedStaticFieldGet* instruction) { |
| 4604 | FieldAccessCallingConventionX86_64 calling_convention; |
| 4605 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4606 | instruction, instruction->GetFieldType(), calling_convention); |
| 4607 | } |
| 4608 | |
| 4609 | void InstructionCodeGeneratorX86_64::VisitUnresolvedStaticFieldGet( |
| 4610 | HUnresolvedStaticFieldGet* instruction) { |
| 4611 | FieldAccessCallingConventionX86_64 calling_convention; |
| 4612 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4613 | instruction->GetFieldType(), |
| 4614 | instruction->GetFieldIndex(), |
| 4615 | instruction->GetDexPc(), |
| 4616 | calling_convention); |
| 4617 | } |
| 4618 | |
| 4619 | void LocationsBuilderX86_64::VisitUnresolvedStaticFieldSet( |
| 4620 | HUnresolvedStaticFieldSet* instruction) { |
| 4621 | FieldAccessCallingConventionX86_64 calling_convention; |
| 4622 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4623 | instruction, instruction->GetFieldType(), calling_convention); |
| 4624 | } |
| 4625 | |
| 4626 | void InstructionCodeGeneratorX86_64::VisitUnresolvedStaticFieldSet( |
| 4627 | HUnresolvedStaticFieldSet* instruction) { |
| 4628 | FieldAccessCallingConventionX86_64 calling_convention; |
| 4629 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4630 | instruction->GetFieldType(), |
| 4631 | instruction->GetFieldIndex(), |
| 4632 | instruction->GetDexPc(), |
| 4633 | calling_convention); |
| 4634 | } |
| 4635 | |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4636 | void LocationsBuilderX86_64::VisitNullCheck(HNullCheck* instruction) { |
| Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 4637 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
| 4638 | Location loc = codegen_->GetCompilerOptions().GetImplicitNullChecks() |
| 4639 | ? Location::RequiresRegister() |
| 4640 | : Location::Any(); |
| 4641 | locations->SetInAt(0, loc); |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4642 | } |
| 4643 | |
| Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 4644 | void CodeGeneratorX86_64::GenerateImplicitNullCheck(HNullCheck* instruction) { |
| 4645 | if (CanMoveNullCheckToUser(instruction)) { |
| Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4646 | return; |
| 4647 | } |
| Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4648 | LocationSummary* locations = instruction->GetLocations(); |
| 4649 | Location obj = locations->InAt(0); |
| 4650 | |
| 4651 | __ testl(CpuRegister(RAX), Address(obj.AsRegister<CpuRegister>(), 0)); |
| Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 4652 | RecordPcInfo(instruction, instruction->GetDexPc()); |
| Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4653 | } |
| 4654 | |
| Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 4655 | void CodeGeneratorX86_64::GenerateExplicitNullCheck(HNullCheck* instruction) { |
| Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 4656 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathX86_64(instruction); |
| Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 4657 | AddSlowPath(slow_path); |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4658 | |
| 4659 | LocationSummary* locations = instruction->GetLocations(); |
| 4660 | Location obj = locations->InAt(0); |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4661 | |
| 4662 | if (obj.IsRegister()) { |
| Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 4663 | __ testl(obj.AsRegister<CpuRegister>(), obj.AsRegister<CpuRegister>()); |
| Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4664 | } else if (obj.IsStackSlot()) { |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4665 | __ cmpl(Address(CpuRegister(RSP), obj.GetStackIndex()), Immediate(0)); |
| Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4666 | } else { |
| 4667 | DCHECK(obj.IsConstant()) << obj; |
| David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 4668 | DCHECK(obj.GetConstant()->IsNullConstant()); |
| Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4669 | __ jmp(slow_path->GetEntryLabel()); |
| 4670 | return; |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4671 | } |
| 4672 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 4673 | } |
| 4674 | |
| Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4675 | void InstructionCodeGeneratorX86_64::VisitNullCheck(HNullCheck* instruction) { |
| Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 4676 | codegen_->GenerateNullCheck(instruction); |
| Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4677 | } |
| 4678 | |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4679 | void LocationsBuilderX86_64::VisitArrayGet(HArrayGet* instruction) { |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4680 | bool object_array_get_with_read_barrier = |
| 4681 | kEmitCompilerReadBarrier && (instruction->GetType() == Primitive::kPrimNot); |
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4682 | LocationSummary* locations = |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4683 | new (GetGraph()->GetArena()) LocationSummary(instruction, |
| 4684 | object_array_get_with_read_barrier ? |
| 4685 | LocationSummary::kCallOnSlowPath : |
| 4686 | LocationSummary::kNoCall); |
| Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 4687 | if (object_array_get_with_read_barrier && kUseBakerReadBarrier) { |
| Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 4688 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
| Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 4689 | } |
| Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 4690 | locations->SetInAt(0, Location::RequiresRegister()); |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4691 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4692 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 4693 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 4694 | } else { |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4695 | // The output overlaps for an object array get when read barriers |
| 4696 | // are enabled: we do not want the move to overwrite the array's |
| 4697 | // location, as we need it to emit the read barrier. |
| 4698 | locations->SetOut( |
| 4699 | Location::RequiresRegister(), |
| 4700 | object_array_get_with_read_barrier ? Location::kOutputOverlap : Location::kNoOutputOverlap); |
| Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4701 | } |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4702 | } |
| 4703 | |
| 4704 | void InstructionCodeGeneratorX86_64::VisitArrayGet(HArrayGet* instruction) { |
| 4705 | LocationSummary* locations = instruction->GetLocations(); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4706 | Location obj_loc = locations->InAt(0); |
| 4707 | CpuRegister obj = obj_loc.AsRegister<CpuRegister>(); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4708 | Location index = locations->InAt(1); |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4709 | Location out_loc = locations->Out(); |
| Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 4710 | uint32_t data_offset = CodeGenerator::GetArrayDataOffset(instruction); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4711 | |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4712 | Primitive::Type type = instruction->GetType(); |
| Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4713 | switch (type) { |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4714 | case Primitive::kPrimBoolean: { |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4715 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 4716 | __ movzxb(out, CodeGeneratorX86_64::ArrayAddress(obj, index, TIMES_1, data_offset)); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4717 | break; |
| 4718 | } |
| 4719 | |
| 4720 | case Primitive::kPrimByte: { |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4721 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 4722 | __ movsxb(out, CodeGeneratorX86_64::ArrayAddress(obj, index, TIMES_1, data_offset)); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4723 | break; |
| 4724 | } |
| 4725 | |
| 4726 | case Primitive::kPrimShort: { |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4727 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 4728 | __ movsxw(out, CodeGeneratorX86_64::ArrayAddress(obj, index, TIMES_2, data_offset)); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4729 | break; |
| 4730 | } |
| 4731 | |
| 4732 | case Primitive::kPrimChar: { |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4733 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
| jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 4734 | if (mirror::kUseStringCompression && instruction->IsStringCharAt()) { |
| 4735 | // Branch cases into compressed and uncompressed for each index's type. |
| 4736 | uint32_t count_offset = mirror::String::CountOffset().Uint32Value(); |
| 4737 | NearLabel done, not_compressed; |
| Vladimir Marko | 3c89d42 | 2017-02-17 11:30:23 +0000 | [diff] [blame] | 4738 | __ testb(Address(obj, count_offset), Immediate(1)); |
| jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 4739 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 4740 | static_assert(static_cast<uint32_t>(mirror::StringCompressionFlag::kCompressed) == 0u, |
| 4741 | "Expecting 0=compressed, 1=uncompressed"); |
| 4742 | __ j(kNotZero, ¬_compressed); |
| jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 4743 | __ movzxb(out, CodeGeneratorX86_64::ArrayAddress(obj, index, TIMES_1, data_offset)); |
| 4744 | __ jmp(&done); |
| 4745 | __ Bind(¬_compressed); |
| 4746 | __ movzxw(out, CodeGeneratorX86_64::ArrayAddress(obj, index, TIMES_2, data_offset)); |
| 4747 | __ Bind(&done); |
| 4748 | } else { |
| 4749 | __ movzxw(out, CodeGeneratorX86_64::ArrayAddress(obj, index, TIMES_2, data_offset)); |
| 4750 | } |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4751 | break; |
| 4752 | } |
| 4753 | |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4754 | case Primitive::kPrimInt: { |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4755 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 4756 | __ movl(out, CodeGeneratorX86_64::ArrayAddress(obj, index, TIMES_4, data_offset)); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4757 | break; |
| 4758 | } |
| 4759 | |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4760 | case Primitive::kPrimNot: { |
| 4761 | static_assert( |
| 4762 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 4763 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4764 | // /* HeapReference<Object> */ out = |
| 4765 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
| 4766 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4767 | // Note that a potential implicit null check is handled in this |
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 4768 | // CodeGeneratorX86_64::GenerateArrayLoadWithBakerReadBarrier call. |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4769 | codegen_->GenerateArrayLoadWithBakerReadBarrier( |
| Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 4770 | instruction, out_loc, obj, data_offset, index, /* needs_null_check */ true); |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4771 | } else { |
| 4772 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 4773 | __ movl(out, CodeGeneratorX86_64::ArrayAddress(obj, index, TIMES_4, data_offset)); |
| 4774 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4775 | // If read barriers are enabled, emit read barriers other than |
| 4776 | // Baker's using a slow path (and also unpoison the loaded |
| 4777 | // reference, if heap poisoning is enabled). |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4778 | if (index.IsConstant()) { |
| 4779 | uint32_t offset = |
| 4780 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4781 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out_loc, out_loc, obj_loc, offset); |
| 4782 | } else { |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4783 | codegen_->MaybeGenerateReadBarrierSlow( |
| 4784 | instruction, out_loc, out_loc, obj_loc, data_offset, index); |
| 4785 | } |
| 4786 | } |
| 4787 | break; |
| 4788 | } |
| 4789 | |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4790 | case Primitive::kPrimLong: { |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4791 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 4792 | __ movq(out, CodeGeneratorX86_64::ArrayAddress(obj, index, TIMES_8, data_offset)); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4793 | break; |
| 4794 | } |
| 4795 | |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4796 | case Primitive::kPrimFloat: { |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4797 | XmmRegister out = out_loc.AsFpuRegister<XmmRegister>(); |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 4798 | __ movss(out, CodeGeneratorX86_64::ArrayAddress(obj, index, TIMES_4, data_offset)); |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4799 | break; |
| 4800 | } |
| 4801 | |
| 4802 | case Primitive::kPrimDouble: { |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4803 | XmmRegister out = out_loc.AsFpuRegister<XmmRegister>(); |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 4804 | __ movsd(out, CodeGeneratorX86_64::ArrayAddress(obj, index, TIMES_8, data_offset)); |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4805 | break; |
| 4806 | } |
| 4807 | |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4808 | case Primitive::kPrimVoid: |
| Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4809 | LOG(FATAL) << "Unreachable type " << type; |
| Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 4810 | UNREACHABLE(); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4811 | } |
| Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4812 | |
| 4813 | if (type == Primitive::kPrimNot) { |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4814 | // Potential implicit null checks, in the case of reference |
| 4815 | // arrays, are handled in the previous switch statement. |
| 4816 | } else { |
| 4817 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4818 | } |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4819 | } |
| 4820 | |
| 4821 | void LocationsBuilderX86_64::VisitArraySet(HArraySet* instruction) { |
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4822 | Primitive::Type value_type = instruction->GetComponentType(); |
| Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4823 | |
| 4824 | bool needs_write_barrier = |
| 4825 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
| Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 4826 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
| Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4827 | |
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4828 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary( |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4829 | instruction, |
| Vladimir Marko | 8d49fd7 | 2016-08-25 15:20:47 +0100 | [diff] [blame] | 4830 | may_need_runtime_call_for_type_check ? |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4831 | LocationSummary::kCallOnSlowPath : |
| 4832 | LocationSummary::kNoCall); |
| Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4833 | |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4834 | locations->SetInAt(0, Location::RequiresRegister()); |
| Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4835 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 4836 | if (Primitive::IsFloatingPointType(value_type)) { |
| 4837 | locations->SetInAt(2, Location::FpuRegisterOrConstant(instruction->InputAt(2))); |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4838 | } else { |
| 4839 | locations->SetInAt(2, Location::RegisterOrConstant(instruction->InputAt(2))); |
| 4840 | } |
| 4841 | |
| 4842 | if (needs_write_barrier) { |
| 4843 | // Temporary registers for the write barrier. |
| Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 4844 | locations->AddTemp(Location::RequiresRegister()); // Possibly used for ref. poisoning too. |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4845 | locations->AddTemp(Location::RequiresRegister()); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4846 | } |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4847 | } |
| 4848 | |
| 4849 | void InstructionCodeGeneratorX86_64::VisitArraySet(HArraySet* instruction) { |
| 4850 | LocationSummary* locations = instruction->GetLocations(); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4851 | Location array_loc = locations->InAt(0); |
| 4852 | CpuRegister array = array_loc.AsRegister<CpuRegister>(); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4853 | Location index = locations->InAt(1); |
| Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4854 | Location value = locations->InAt(2); |
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4855 | Primitive::Type value_type = instruction->GetComponentType(); |
| Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 4856 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
| Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4857 | bool needs_write_barrier = |
| 4858 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4859 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 4860 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 4861 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4862 | |
| 4863 | switch (value_type) { |
| 4864 | case Primitive::kPrimBoolean: |
| 4865 | case Primitive::kPrimByte: { |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4866 | uint32_t offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value(); |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 4867 | Address address = CodeGeneratorX86_64::ArrayAddress(array, index, TIMES_1, offset); |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4868 | if (value.IsRegister()) { |
| 4869 | __ movb(address, value.AsRegister<CpuRegister>()); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4870 | } else { |
| Nicolas Geoffray | 7861208 | 2017-07-24 14:18:53 +0100 | [diff] [blame] | 4871 | __ movb(address, Immediate(CodeGenerator::GetInt8ValueOf(value.GetConstant()))); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4872 | } |
| Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4873 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4874 | break; |
| 4875 | } |
| 4876 | |
| 4877 | case Primitive::kPrimShort: |
| 4878 | case Primitive::kPrimChar: { |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4879 | uint32_t offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value(); |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 4880 | Address address = CodeGeneratorX86_64::ArrayAddress(array, index, TIMES_2, offset); |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4881 | if (value.IsRegister()) { |
| 4882 | __ movw(address, value.AsRegister<CpuRegister>()); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4883 | } else { |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4884 | DCHECK(value.IsConstant()) << value; |
| Nicolas Geoffray | 7861208 | 2017-07-24 14:18:53 +0100 | [diff] [blame] | 4885 | __ movw(address, Immediate(CodeGenerator::GetInt16ValueOf(value.GetConstant()))); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4886 | } |
| Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4887 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4888 | break; |
| 4889 | } |
| 4890 | |
| 4891 | case Primitive::kPrimNot: { |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4892 | uint32_t offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 4893 | Address address = CodeGeneratorX86_64::ArrayAddress(array, index, TIMES_4, offset); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4894 | |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4895 | if (!value.IsRegister()) { |
| 4896 | // Just setting null. |
| 4897 | DCHECK(instruction->InputAt(2)->IsNullConstant()); |
| 4898 | DCHECK(value.IsConstant()) << value; |
| 4899 | __ movl(address, Immediate(0)); |
| Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4900 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4901 | DCHECK(!needs_write_barrier); |
| Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 4902 | DCHECK(!may_need_runtime_call_for_type_check); |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4903 | break; |
| Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4904 | } |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4905 | |
| 4906 | DCHECK(needs_write_barrier); |
| 4907 | CpuRegister register_value = value.AsRegister<CpuRegister>(); |
| Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 4908 | // We cannot use a NearLabel for `done`, as its range may be too |
| 4909 | // short when Baker read barriers are enabled. |
| 4910 | Label done; |
| 4911 | NearLabel not_null, do_put; |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4912 | SlowPathCode* slow_path = nullptr; |
| Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 4913 | Location temp_loc = locations->GetTemp(0); |
| 4914 | CpuRegister temp = temp_loc.AsRegister<CpuRegister>(); |
| Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 4915 | if (may_need_runtime_call_for_type_check) { |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4916 | slow_path = new (GetGraph()->GetArena()) ArraySetSlowPathX86_64(instruction); |
| 4917 | codegen_->AddSlowPath(slow_path); |
| 4918 | if (instruction->GetValueCanBeNull()) { |
| 4919 | __ testl(register_value, register_value); |
| 4920 | __ j(kNotEqual, ¬_null); |
| 4921 | __ movl(address, Immediate(0)); |
| 4922 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4923 | __ jmp(&done); |
| 4924 | __ Bind(¬_null); |
| 4925 | } |
| 4926 | |
| Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 4927 | // Note that when Baker read barriers are enabled, the type |
| 4928 | // checks are performed without read barriers. This is fine, |
| 4929 | // even in the case where a class object is in the from-space |
| 4930 | // after the flip, as a comparison involving such a type would |
| 4931 | // not produce a false positive; it may of course produce a |
| 4932 | // false negative, in which case we would take the ArraySet |
| 4933 | // slow path. |
| 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 = array->klass_ |
| 4936 | __ movl(temp, Address(array, class_offset)); |
| 4937 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4938 | __ MaybeUnpoisonHeapReference(temp); |
| Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 4939 | |
| Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 4940 | // /* HeapReference<Class> */ temp = temp->component_type_ |
| 4941 | __ movl(temp, Address(temp, component_offset)); |
| 4942 | // If heap poisoning is enabled, no need to unpoison `temp` |
| 4943 | // nor the object reference in `register_value->klass`, as |
| 4944 | // we are comparing two poisoned references. |
| 4945 | __ cmpl(temp, Address(register_value, class_offset)); |
| Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 4946 | |
| Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 4947 | if (instruction->StaticTypeOfArrayIsObjectArray()) { |
| 4948 | __ j(kEqual, &do_put); |
| 4949 | // If heap poisoning is enabled, the `temp` reference has |
| 4950 | // not been unpoisoned yet; unpoison it now. |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4951 | __ MaybeUnpoisonHeapReference(temp); |
| 4952 | |
| Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 4953 | // If heap poisoning is enabled, no need to unpoison the |
| 4954 | // heap reference loaded below, as it is only used for a |
| 4955 | // comparison with null. |
| 4956 | __ cmpl(Address(temp, super_offset), Immediate(0)); |
| 4957 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 4958 | __ Bind(&do_put); |
| 4959 | } else { |
| 4960 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4961 | } |
| 4962 | } |
| 4963 | |
| 4964 | if (kPoisonHeapReferences) { |
| 4965 | __ movl(temp, register_value); |
| 4966 | __ PoisonHeapReference(temp); |
| 4967 | __ movl(address, temp); |
| 4968 | } else { |
| 4969 | __ movl(address, register_value); |
| 4970 | } |
| Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 4971 | if (!may_need_runtime_call_for_type_check) { |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4972 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4973 | } |
| 4974 | |
| 4975 | CpuRegister card = locations->GetTemp(1).AsRegister<CpuRegister>(); |
| 4976 | codegen_->MarkGCCard( |
| 4977 | temp, card, array, value.AsRegister<CpuRegister>(), instruction->GetValueCanBeNull()); |
| 4978 | __ Bind(&done); |
| 4979 | |
| 4980 | if (slow_path != nullptr) { |
| 4981 | __ Bind(slow_path->GetExitLabel()); |
| 4982 | } |
| 4983 | |
| 4984 | break; |
| 4985 | } |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4986 | |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4987 | case Primitive::kPrimInt: { |
| 4988 | uint32_t offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 4989 | Address address = CodeGeneratorX86_64::ArrayAddress(array, index, TIMES_4, offset); |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4990 | if (value.IsRegister()) { |
| 4991 | __ movl(address, value.AsRegister<CpuRegister>()); |
| 4992 | } else { |
| 4993 | DCHECK(value.IsConstant()) << value; |
| 4994 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
| 4995 | __ movl(address, Immediate(v)); |
| 4996 | } |
| 4997 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4998 | break; |
| 4999 | } |
| 5000 | |
| 5001 | case Primitive::kPrimLong: { |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5002 | uint32_t offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value(); |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5003 | Address address = CodeGeneratorX86_64::ArrayAddress(array, index, TIMES_8, offset); |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5004 | if (value.IsRegister()) { |
| 5005 | __ movq(address, value.AsRegister<CpuRegister>()); |
| Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 5006 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5007 | } else { |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5008 | int64_t v = value.GetConstant()->AsLongConstant()->GetValue(); |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5009 | Address address_high = |
| 5010 | CodeGeneratorX86_64::ArrayAddress(array, index, TIMES_8, offset + sizeof(int32_t)); |
| Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 5011 | codegen_->MoveInt64ToAddress(address, address_high, v, instruction); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5012 | } |
| 5013 | break; |
| 5014 | } |
| 5015 | |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5016 | case Primitive::kPrimFloat: { |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5017 | uint32_t offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value(); |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5018 | Address address = CodeGeneratorX86_64::ArrayAddress(array, index, TIMES_4, offset); |
| Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 5019 | if (value.IsFpuRegister()) { |
| 5020 | __ movss(address, value.AsFpuRegister<XmmRegister>()); |
| 5021 | } else { |
| 5022 | DCHECK(value.IsConstant()); |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5023 | int32_t v = bit_cast<int32_t, float>(value.GetConstant()->AsFloatConstant()->GetValue()); |
| Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 5024 | __ movl(address, Immediate(v)); |
| 5025 | } |
| Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5026 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5027 | break; |
| 5028 | } |
| 5029 | |
| 5030 | case Primitive::kPrimDouble: { |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5031 | uint32_t offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value(); |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5032 | Address address = CodeGeneratorX86_64::ArrayAddress(array, index, TIMES_8, offset); |
| Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 5033 | if (value.IsFpuRegister()) { |
| 5034 | __ movsd(address, value.AsFpuRegister<XmmRegister>()); |
| 5035 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5036 | } else { |
| 5037 | int64_t v = |
| 5038 | bit_cast<int64_t, double>(value.GetConstant()->AsDoubleConstant()->GetValue()); |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5039 | Address address_high = |
| 5040 | CodeGeneratorX86_64::ArrayAddress(array, index, TIMES_8, offset + sizeof(int32_t)); |
| Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 5041 | codegen_->MoveInt64ToAddress(address, address_high, v, instruction); |
| 5042 | } |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5043 | break; |
| 5044 | } |
| 5045 | |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5046 | case Primitive::kPrimVoid: |
| 5047 | LOG(FATAL) << "Unreachable type " << instruction->GetType(); |
| Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 5048 | UNREACHABLE(); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5049 | } |
| 5050 | } |
| 5051 | |
| 5052 | void LocationsBuilderX86_64::VisitArrayLength(HArrayLength* instruction) { |
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5053 | LocationSummary* locations = |
| 5054 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 5055 | locations->SetInAt(0, Location::RequiresRegister()); |
| Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 5056 | if (!instruction->IsEmittedAtUseSite()) { |
| 5057 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 5058 | } |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5059 | } |
| 5060 | |
| 5061 | void InstructionCodeGeneratorX86_64::VisitArrayLength(HArrayLength* instruction) { |
| Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 5062 | if (instruction->IsEmittedAtUseSite()) { |
| 5063 | return; |
| 5064 | } |
| 5065 | |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5066 | LocationSummary* locations = instruction->GetLocations(); |
| Vladimir Marko | dce016e | 2016-04-28 13:10:02 +0100 | [diff] [blame] | 5067 | uint32_t offset = CodeGenerator::GetArrayLengthOffset(instruction); |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5068 | CpuRegister obj = locations->InAt(0).AsRegister<CpuRegister>(); |
| 5069 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5070 | __ movl(out, Address(obj, offset)); |
| Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5071 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5072 | // Mask out most significant bit in case the array is String's array of char. |
| 5073 | if (mirror::kUseStringCompression && instruction->IsStringLength()) { |
| Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 5074 | __ shrl(out, Immediate(1)); |
| jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5075 | } |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5076 | } |
| 5077 | |
| 5078 | void LocationsBuilderX86_64::VisitBoundsCheck(HBoundsCheck* instruction) { |
| Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 5079 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 5080 | InvokeRuntimeCallingConvention calling_convention; |
| 5081 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 5082 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 5083 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction, caller_saves); |
| Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 5084 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
| Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 5085 | HInstruction* length = instruction->InputAt(1); |
| 5086 | if (!length->IsEmittedAtUseSite()) { |
| 5087 | locations->SetInAt(1, Location::RegisterOrConstant(length)); |
| 5088 | } |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5089 | } |
| 5090 | |
| 5091 | void InstructionCodeGeneratorX86_64::VisitBoundsCheck(HBoundsCheck* instruction) { |
| 5092 | LocationSummary* locations = instruction->GetLocations(); |
| Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 5093 | Location index_loc = locations->InAt(0); |
| 5094 | Location length_loc = locations->InAt(1); |
| Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 5095 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) BoundsCheckSlowPathX86_64(instruction); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5096 | |
| Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 5097 | if (length_loc.IsConstant()) { |
| 5098 | int32_t length = CodeGenerator::GetInt32ValueOf(length_loc.GetConstant()); |
| 5099 | if (index_loc.IsConstant()) { |
| 5100 | // BCE will remove the bounds check if we are guarenteed to pass. |
| 5101 | int32_t index = CodeGenerator::GetInt32ValueOf(index_loc.GetConstant()); |
| 5102 | if (index < 0 || index >= length) { |
| 5103 | codegen_->AddSlowPath(slow_path); |
| 5104 | __ jmp(slow_path->GetEntryLabel()); |
| 5105 | } else { |
| 5106 | // Some optimization after BCE may have generated this, and we should not |
| 5107 | // generate a bounds check if it is a valid range. |
| 5108 | } |
| 5109 | return; |
| 5110 | } |
| 5111 | |
| 5112 | // We have to reverse the jump condition because the length is the constant. |
| 5113 | CpuRegister index_reg = index_loc.AsRegister<CpuRegister>(); |
| 5114 | __ cmpl(index_reg, Immediate(length)); |
| 5115 | codegen_->AddSlowPath(slow_path); |
| 5116 | __ j(kAboveEqual, slow_path->GetEntryLabel()); |
| Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 5117 | } else { |
| Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 5118 | HInstruction* array_length = instruction->InputAt(1); |
| 5119 | if (array_length->IsEmittedAtUseSite()) { |
| 5120 | // Address the length field in the array. |
| 5121 | DCHECK(array_length->IsArrayLength()); |
| 5122 | uint32_t len_offset = CodeGenerator::GetArrayLengthOffset(array_length->AsArrayLength()); |
| 5123 | Location array_loc = array_length->GetLocations()->InAt(0); |
| 5124 | Address array_len(array_loc.AsRegister<CpuRegister>(), len_offset); |
| jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5125 | if (mirror::kUseStringCompression && instruction->IsStringCharAt()) { |
| Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 5126 | // TODO: if index_loc.IsConstant(), compare twice the index (to compensate for |
| 5127 | // the string compression flag) with the in-memory length and avoid the temporary. |
| jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5128 | CpuRegister length_reg = CpuRegister(TMP); |
| 5129 | __ movl(length_reg, array_len); |
| 5130 | codegen_->MaybeRecordImplicitNullCheck(array_length); |
| Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 5131 | __ shrl(length_reg, Immediate(1)); |
| jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5132 | codegen_->GenerateIntCompare(length_reg, index_loc); |
| Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 5133 | } else { |
| jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5134 | // Checking the bound for general case: |
| 5135 | // Array of char or String's array when the compression feature off. |
| 5136 | if (index_loc.IsConstant()) { |
| 5137 | int32_t value = CodeGenerator::GetInt32ValueOf(index_loc.GetConstant()); |
| 5138 | __ cmpl(array_len, Immediate(value)); |
| 5139 | } else { |
| 5140 | __ cmpl(array_len, index_loc.AsRegister<CpuRegister>()); |
| 5141 | } |
| 5142 | codegen_->MaybeRecordImplicitNullCheck(array_length); |
| Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 5143 | } |
| Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 5144 | } else { |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5145 | codegen_->GenerateIntCompare(length_loc, index_loc); |
| Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 5146 | } |
| 5147 | codegen_->AddSlowPath(slow_path); |
| 5148 | __ j(kBelowEqual, slow_path->GetEntryLabel()); |
| Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 5149 | } |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5150 | } |
| 5151 | |
| 5152 | void CodeGeneratorX86_64::MarkGCCard(CpuRegister temp, |
| 5153 | CpuRegister card, |
| 5154 | CpuRegister object, |
| Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5155 | CpuRegister value, |
| 5156 | bool value_can_be_null) { |
| Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 5157 | NearLabel is_null; |
| Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5158 | if (value_can_be_null) { |
| 5159 | __ testl(value, value); |
| 5160 | __ j(kEqual, &is_null); |
| 5161 | } |
| Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 5162 | __ gs()->movq(card, Address::Absolute(Thread::CardTableOffset<kX86_64PointerSize>().Int32Value(), |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5163 | /* no_rip */ true)); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5164 | __ movq(temp, object); |
| 5165 | __ shrq(temp, Immediate(gc::accounting::CardTable::kCardShift)); |
| Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5166 | __ movb(Address(temp, card, TIMES_1, 0), card); |
| Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5167 | if (value_can_be_null) { |
| 5168 | __ Bind(&is_null); |
| 5169 | } |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5170 | } |
| 5171 | |
| Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5172 | void LocationsBuilderX86_64::VisitParallelMove(HParallelMove* instruction ATTRIBUTE_UNUSED) { |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 5173 | LOG(FATAL) << "Unimplemented"; |
| 5174 | } |
| 5175 | |
| 5176 | void InstructionCodeGeneratorX86_64::VisitParallelMove(HParallelMove* instruction) { |
| Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5177 | codegen_->GetMoveResolver()->EmitNativeCode(instruction); |
| 5178 | } |
| 5179 | |
| Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5180 | void LocationsBuilderX86_64::VisitSuspendCheck(HSuspendCheck* instruction) { |
| Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5181 | LocationSummary* locations = |
| 5182 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath); |
| Aart Bik | b13c65b | 2017-03-21 20:14:07 -0700 | [diff] [blame] | 5183 | // In suspend check slow path, usually there are no caller-save registers at all. |
| 5184 | // If SIMD instructions are present, however, we force spilling all live SIMD |
| 5185 | // registers in full width (since the runtime only saves/restores lower part). |
| Aart Bik | 5576f37 | 2017-03-23 16:17:37 -0700 | [diff] [blame] | 5186 | locations->SetCustomSlowPathCallerSaves( |
| 5187 | GetGraph()->HasSIMD() ? RegisterSet::AllFpu() : RegisterSet::Empty()); |
| Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5188 | } |
| 5189 | |
| 5190 | void InstructionCodeGeneratorX86_64::VisitSuspendCheck(HSuspendCheck* instruction) { |
| Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 5191 | HBasicBlock* block = instruction->GetBlock(); |
| 5192 | if (block->GetLoopInformation() != nullptr) { |
| 5193 | DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction); |
| 5194 | // The back edge will generate the suspend check. |
| 5195 | return; |
| 5196 | } |
| 5197 | if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) { |
| 5198 | // The goto will generate the suspend check. |
| 5199 | return; |
| 5200 | } |
| 5201 | GenerateSuspendCheck(instruction, nullptr); |
| 5202 | } |
| 5203 | |
| 5204 | void InstructionCodeGeneratorX86_64::GenerateSuspendCheck(HSuspendCheck* instruction, |
| 5205 | HBasicBlock* successor) { |
| Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5206 | SuspendCheckSlowPathX86_64* slow_path = |
| Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 5207 | down_cast<SuspendCheckSlowPathX86_64*>(instruction->GetSlowPath()); |
| 5208 | if (slow_path == nullptr) { |
| 5209 | slow_path = new (GetGraph()->GetArena()) SuspendCheckSlowPathX86_64(instruction, successor); |
| 5210 | instruction->SetSlowPath(slow_path); |
| 5211 | codegen_->AddSlowPath(slow_path); |
| 5212 | if (successor != nullptr) { |
| 5213 | DCHECK(successor->IsLoopHeader()); |
| 5214 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(instruction); |
| 5215 | } |
| 5216 | } else { |
| 5217 | DCHECK_EQ(slow_path->GetSuccessor(), successor); |
| 5218 | } |
| 5219 | |
| Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 5220 | __ gs()->cmpw(Address::Absolute(Thread::ThreadFlagsOffset<kX86_64PointerSize>().Int32Value(), |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5221 | /* no_rip */ true), |
| 5222 | Immediate(0)); |
| Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 5223 | if (successor == nullptr) { |
| 5224 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 5225 | __ Bind(slow_path->GetReturnLabel()); |
| 5226 | } else { |
| 5227 | __ j(kEqual, codegen_->GetLabelOf(successor)); |
| 5228 | __ jmp(slow_path->GetEntryLabel()); |
| 5229 | } |
| Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5230 | } |
| 5231 | |
| Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5232 | X86_64Assembler* ParallelMoveResolverX86_64::GetAssembler() const { |
| 5233 | return codegen_->GetAssembler(); |
| 5234 | } |
| 5235 | |
| 5236 | void ParallelMoveResolverX86_64::EmitMove(size_t index) { |
| Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5237 | MoveOperands* move = moves_[index]; |
| Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5238 | Location source = move->GetSource(); |
| 5239 | Location destination = move->GetDestination(); |
| 5240 | |
| 5241 | if (source.IsRegister()) { |
| 5242 | if (destination.IsRegister()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5243 | __ movq(destination.AsRegister<CpuRegister>(), source.AsRegister<CpuRegister>()); |
| Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5244 | } else if (destination.IsStackSlot()) { |
| Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5245 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5246 | source.AsRegister<CpuRegister>()); |
| Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5247 | } else { |
| 5248 | DCHECK(destination.IsDoubleStackSlot()); |
| 5249 | __ movq(Address(CpuRegister(RSP), destination.GetStackIndex()), |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5250 | source.AsRegister<CpuRegister>()); |
| Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5251 | } |
| 5252 | } else if (source.IsStackSlot()) { |
| 5253 | if (destination.IsRegister()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5254 | __ movl(destination.AsRegister<CpuRegister>(), |
| Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5255 | Address(CpuRegister(RSP), source.GetStackIndex())); |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5256 | } else if (destination.IsFpuRegister()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5257 | __ movss(destination.AsFpuRegister<XmmRegister>(), |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5258 | Address(CpuRegister(RSP), source.GetStackIndex())); |
| Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5259 | } else { |
| 5260 | DCHECK(destination.IsStackSlot()); |
| 5261 | __ movl(CpuRegister(TMP), Address(CpuRegister(RSP), source.GetStackIndex())); |
| 5262 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), CpuRegister(TMP)); |
| 5263 | } |
| Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5264 | } else if (source.IsDoubleStackSlot()) { |
| 5265 | if (destination.IsRegister()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5266 | __ movq(destination.AsRegister<CpuRegister>(), |
| Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5267 | Address(CpuRegister(RSP), source.GetStackIndex())); |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5268 | } else if (destination.IsFpuRegister()) { |
| Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 5269 | __ movsd(destination.AsFpuRegister<XmmRegister>(), |
| 5270 | Address(CpuRegister(RSP), source.GetStackIndex())); |
| Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5271 | } else { |
| Nicolas Geoffray | c8147a7 | 2014-10-21 16:06:20 +0100 | [diff] [blame] | 5272 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5273 | __ movq(CpuRegister(TMP), Address(CpuRegister(RSP), source.GetStackIndex())); |
| 5274 | __ movq(Address(CpuRegister(RSP), destination.GetStackIndex()), CpuRegister(TMP)); |
| 5275 | } |
| Aart Bik | 5576f37 | 2017-03-23 16:17:37 -0700 | [diff] [blame] | 5276 | } else if (source.IsSIMDStackSlot()) { |
| 5277 | DCHECK(destination.IsFpuRegister()); |
| 5278 | __ movups(destination.AsFpuRegister<XmmRegister>(), |
| 5279 | Address(CpuRegister(RSP), source.GetStackIndex())); |
| Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5280 | } else if (source.IsConstant()) { |
| 5281 | HConstant* constant = source.GetConstant(); |
| Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 5282 | if (constant->IsIntConstant() || constant->IsNullConstant()) { |
| 5283 | int32_t value = CodeGenerator::GetInt32ValueOf(constant); |
| Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5284 | if (destination.IsRegister()) { |
| Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 5285 | if (value == 0) { |
| 5286 | __ xorl(destination.AsRegister<CpuRegister>(), destination.AsRegister<CpuRegister>()); |
| 5287 | } else { |
| 5288 | __ movl(destination.AsRegister<CpuRegister>(), Immediate(value)); |
| 5289 | } |
| Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5290 | } else { |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5291 | DCHECK(destination.IsStackSlot()) << destination; |
| Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 5292 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), Immediate(value)); |
| Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5293 | } |
| 5294 | } else if (constant->IsLongConstant()) { |
| 5295 | int64_t value = constant->AsLongConstant()->GetValue(); |
| 5296 | if (destination.IsRegister()) { |
| Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 5297 | codegen_->Load64BitValue(destination.AsRegister<CpuRegister>(), value); |
| Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5298 | } else { |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5299 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 5300 | codegen_->Store64BitValueToStack(destination, value); |
| Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5301 | } |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5302 | } else if (constant->IsFloatConstant()) { |
| Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5303 | float fp_value = constant->AsFloatConstant()->GetValue(); |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5304 | if (destination.IsFpuRegister()) { |
| Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5305 | XmmRegister dest = destination.AsFpuRegister<XmmRegister>(); |
| Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 5306 | codegen_->Load32BitValue(dest, fp_value); |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5307 | } else { |
| 5308 | DCHECK(destination.IsStackSlot()) << destination; |
| Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 5309 | Immediate imm(bit_cast<int32_t, float>(fp_value)); |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5310 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), imm); |
| 5311 | } |
| Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5312 | } else { |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5313 | DCHECK(constant->IsDoubleConstant()) << constant->DebugName(); |
| Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5314 | double fp_value = constant->AsDoubleConstant()->GetValue(); |
| Roland Levillain | da4d79b | 2015-03-24 14:36:11 +0000 | [diff] [blame] | 5315 | int64_t value = bit_cast<int64_t, double>(fp_value); |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5316 | if (destination.IsFpuRegister()) { |
| Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5317 | XmmRegister dest = destination.AsFpuRegister<XmmRegister>(); |
| Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 5318 | codegen_->Load64BitValue(dest, fp_value); |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5319 | } else { |
| 5320 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 5321 | codegen_->Store64BitValueToStack(destination, value); |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5322 | } |
| Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5323 | } |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5324 | } else if (source.IsFpuRegister()) { |
| 5325 | if (destination.IsFpuRegister()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5326 | __ movaps(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5327 | } else if (destination.IsStackSlot()) { |
| 5328 | __ movss(Address(CpuRegister(RSP), destination.GetStackIndex()), |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5329 | source.AsFpuRegister<XmmRegister>()); |
| Aart Bik | 5576f37 | 2017-03-23 16:17:37 -0700 | [diff] [blame] | 5330 | } else if (destination.IsDoubleStackSlot()) { |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5331 | __ movsd(Address(CpuRegister(RSP), destination.GetStackIndex()), |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5332 | source.AsFpuRegister<XmmRegister>()); |
| Aart Bik | 5576f37 | 2017-03-23 16:17:37 -0700 | [diff] [blame] | 5333 | } else { |
| 5334 | DCHECK(destination.IsSIMDStackSlot()); |
| 5335 | __ movups(Address(CpuRegister(RSP), destination.GetStackIndex()), |
| 5336 | source.AsFpuRegister<XmmRegister>()); |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5337 | } |
| Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5338 | } |
| 5339 | } |
| 5340 | |
| Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5341 | void ParallelMoveResolverX86_64::Exchange32(CpuRegister reg, int mem) { |
| Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5342 | __ movl(CpuRegister(TMP), Address(CpuRegister(RSP), mem)); |
| Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5343 | __ movl(Address(CpuRegister(RSP), mem), reg); |
| 5344 | __ movl(reg, CpuRegister(TMP)); |
| Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5345 | } |
| 5346 | |
| Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5347 | void ParallelMoveResolverX86_64::Exchange32(int mem1, int mem2) { |
| Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5348 | ScratchRegisterScope ensure_scratch( |
| 5349 | this, TMP, RAX, codegen_->GetNumberOfCoreRegisters()); |
| 5350 | |
| 5351 | int stack_offset = ensure_scratch.IsSpilled() ? kX86_64WordSize : 0; |
| 5352 | __ movl(CpuRegister(TMP), Address(CpuRegister(RSP), mem1 + stack_offset)); |
| 5353 | __ movl(CpuRegister(ensure_scratch.GetRegister()), |
| 5354 | Address(CpuRegister(RSP), mem2 + stack_offset)); |
| 5355 | __ movl(Address(CpuRegister(RSP), mem2 + stack_offset), CpuRegister(TMP)); |
| 5356 | __ movl(Address(CpuRegister(RSP), mem1 + stack_offset), |
| 5357 | CpuRegister(ensure_scratch.GetRegister())); |
| 5358 | } |
| 5359 | |
| Mark Mendell | 8a1c728 | 2015-06-29 15:41:28 -0400 | [diff] [blame] | 5360 | void ParallelMoveResolverX86_64::Exchange64(CpuRegister reg1, CpuRegister reg2) { |
| 5361 | __ movq(CpuRegister(TMP), reg1); |
| 5362 | __ movq(reg1, reg2); |
| 5363 | __ movq(reg2, CpuRegister(TMP)); |
| 5364 | } |
| 5365 | |
| Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5366 | void ParallelMoveResolverX86_64::Exchange64(CpuRegister reg, int mem) { |
| 5367 | __ movq(CpuRegister(TMP), Address(CpuRegister(RSP), mem)); |
| 5368 | __ movq(Address(CpuRegister(RSP), mem), reg); |
| 5369 | __ movq(reg, CpuRegister(TMP)); |
| 5370 | } |
| 5371 | |
| 5372 | void ParallelMoveResolverX86_64::Exchange64(int mem1, int mem2) { |
| 5373 | ScratchRegisterScope ensure_scratch( |
| Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5374 | this, TMP, RAX, codegen_->GetNumberOfCoreRegisters()); |
| Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5375 | |
| Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5376 | int stack_offset = ensure_scratch.IsSpilled() ? kX86_64WordSize : 0; |
| 5377 | __ movq(CpuRegister(TMP), Address(CpuRegister(RSP), mem1 + stack_offset)); |
| 5378 | __ movq(CpuRegister(ensure_scratch.GetRegister()), |
| 5379 | Address(CpuRegister(RSP), mem2 + stack_offset)); |
| 5380 | __ movq(Address(CpuRegister(RSP), mem2 + stack_offset), CpuRegister(TMP)); |
| 5381 | __ movq(Address(CpuRegister(RSP), mem1 + stack_offset), |
| 5382 | CpuRegister(ensure_scratch.GetRegister())); |
| Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5383 | } |
| 5384 | |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5385 | void ParallelMoveResolverX86_64::Exchange32(XmmRegister reg, int mem) { |
| 5386 | __ movl(CpuRegister(TMP), Address(CpuRegister(RSP), mem)); |
| 5387 | __ movss(Address(CpuRegister(RSP), mem), reg); |
| 5388 | __ movd(reg, CpuRegister(TMP)); |
| 5389 | } |
| 5390 | |
| 5391 | void ParallelMoveResolverX86_64::Exchange64(XmmRegister reg, int mem) { |
| 5392 | __ movq(CpuRegister(TMP), Address(CpuRegister(RSP), mem)); |
| 5393 | __ movsd(Address(CpuRegister(RSP), mem), reg); |
| 5394 | __ movd(reg, CpuRegister(TMP)); |
| 5395 | } |
| 5396 | |
| Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5397 | void ParallelMoveResolverX86_64::EmitSwap(size_t index) { |
| Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5398 | MoveOperands* move = moves_[index]; |
| Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5399 | Location source = move->GetSource(); |
| 5400 | Location destination = move->GetDestination(); |
| 5401 | |
| 5402 | if (source.IsRegister() && destination.IsRegister()) { |
| Mark Mendell | 8a1c728 | 2015-06-29 15:41:28 -0400 | [diff] [blame] | 5403 | Exchange64(source.AsRegister<CpuRegister>(), destination.AsRegister<CpuRegister>()); |
| Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5404 | } else if (source.IsRegister() && destination.IsStackSlot()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5405 | Exchange32(source.AsRegister<CpuRegister>(), destination.GetStackIndex()); |
| Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5406 | } else if (source.IsStackSlot() && destination.IsRegister()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5407 | Exchange32(destination.AsRegister<CpuRegister>(), source.GetStackIndex()); |
| Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5408 | } else if (source.IsStackSlot() && destination.IsStackSlot()) { |
| Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5409 | Exchange32(destination.GetStackIndex(), source.GetStackIndex()); |
| 5410 | } else if (source.IsRegister() && destination.IsDoubleStackSlot()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5411 | Exchange64(source.AsRegister<CpuRegister>(), destination.GetStackIndex()); |
| Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5412 | } else if (source.IsDoubleStackSlot() && destination.IsRegister()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5413 | Exchange64(destination.AsRegister<CpuRegister>(), source.GetStackIndex()); |
| Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5414 | } else if (source.IsDoubleStackSlot() && destination.IsDoubleStackSlot()) { |
| 5415 | Exchange64(destination.GetStackIndex(), source.GetStackIndex()); |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5416 | } else if (source.IsFpuRegister() && destination.IsFpuRegister()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5417 | __ movd(CpuRegister(TMP), source.AsFpuRegister<XmmRegister>()); |
| 5418 | __ movaps(source.AsFpuRegister<XmmRegister>(), destination.AsFpuRegister<XmmRegister>()); |
| 5419 | __ movd(destination.AsFpuRegister<XmmRegister>(), CpuRegister(TMP)); |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5420 | } else if (source.IsFpuRegister() && destination.IsStackSlot()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5421 | Exchange32(source.AsFpuRegister<XmmRegister>(), destination.GetStackIndex()); |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5422 | } else if (source.IsStackSlot() && destination.IsFpuRegister()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5423 | Exchange32(destination.AsFpuRegister<XmmRegister>(), source.GetStackIndex()); |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5424 | } else if (source.IsFpuRegister() && destination.IsDoubleStackSlot()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5425 | Exchange64(source.AsFpuRegister<XmmRegister>(), destination.GetStackIndex()); |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5426 | } else if (source.IsDoubleStackSlot() && destination.IsFpuRegister()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5427 | Exchange64(destination.AsFpuRegister<XmmRegister>(), source.GetStackIndex()); |
| Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5428 | } else { |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5429 | LOG(FATAL) << "Unimplemented swap between " << source << " and " << destination; |
| Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5430 | } |
| 5431 | } |
| 5432 | |
| 5433 | |
| 5434 | void ParallelMoveResolverX86_64::SpillScratch(int reg) { |
| 5435 | __ pushq(CpuRegister(reg)); |
| 5436 | } |
| 5437 | |
| 5438 | |
| 5439 | void ParallelMoveResolverX86_64::RestoreScratch(int reg) { |
| 5440 | __ popq(CpuRegister(reg)); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 5441 | } |
| 5442 | |
| Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5443 | void InstructionCodeGeneratorX86_64::GenerateClassInitializationCheck( |
| Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 5444 | SlowPathCode* slow_path, CpuRegister class_reg) { |
| Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5445 | __ cmpl(Address(class_reg, mirror::Class::StatusOffset().Int32Value()), |
| 5446 | Immediate(mirror::Class::kStatusInitialized)); |
| 5447 | __ j(kLess, slow_path->GetEntryLabel()); |
| 5448 | __ Bind(slow_path->GetExitLabel()); |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5449 | // No need for memory fence, thanks to the x86-64 memory model. |
| Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5450 | } |
| 5451 | |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5452 | HLoadClass::LoadKind CodeGeneratorX86_64::GetSupportedLoadClassKind( |
| 5453 | HLoadClass::LoadKind desired_class_load_kind) { |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5454 | switch (desired_class_load_kind) { |
| Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 5455 | case HLoadClass::LoadKind::kInvalid: |
| 5456 | LOG(FATAL) << "UNREACHABLE"; |
| 5457 | UNREACHABLE(); |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5458 | case HLoadClass::LoadKind::kReferrersClass: |
| 5459 | break; |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5460 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: |
| Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 5461 | case HLoadClass::LoadKind::kBootImageClassTable: |
| Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5462 | case HLoadClass::LoadKind::kBssEntry: |
| 5463 | DCHECK(!Runtime::Current()->UseJitCompilation()); |
| 5464 | break; |
| Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 5465 | case HLoadClass::LoadKind::kJitTableAddress: |
| Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5466 | DCHECK(Runtime::Current()->UseJitCompilation()); |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5467 | break; |
| Vladimir Marko | 764d454 | 2017-05-16 10:31:41 +0100 | [diff] [blame] | 5468 | case HLoadClass::LoadKind::kBootImageAddress: |
| Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 5469 | case HLoadClass::LoadKind::kRuntimeCall: |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5470 | break; |
| 5471 | } |
| 5472 | return desired_class_load_kind; |
| 5473 | } |
| 5474 | |
| Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5475 | void LocationsBuilderX86_64::VisitLoadClass(HLoadClass* cls) { |
| Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5476 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
| Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 5477 | if (load_kind == HLoadClass::LoadKind::kRuntimeCall) { |
| Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 5478 | // Custom calling convention: RAX serves as both input and output. |
| Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5479 | CodeGenerator::CreateLoadClassRuntimeCallLocationSummary( |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5480 | cls, |
| Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 5481 | Location::RegisterLocation(RAX), |
| Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5482 | Location::RegisterLocation(RAX)); |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5483 | return; |
| 5484 | } |
| Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5485 | DCHECK(!cls->NeedsAccessCheck()); |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5486 | |
| Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5487 | const bool requires_read_barrier = kEmitCompilerReadBarrier && !cls->IsInBootImage(); |
| 5488 | LocationSummary::CallKind call_kind = (cls->NeedsEnvironment() || requires_read_barrier) |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5489 | ? LocationSummary::kCallOnSlowPath |
| 5490 | : LocationSummary::kNoCall; |
| 5491 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(cls, call_kind); |
| Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5492 | if (kUseBakerReadBarrier && requires_read_barrier && !cls->NeedsEnvironment()) { |
| Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 5493 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
| Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5494 | } |
| 5495 | |
| Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5496 | if (load_kind == HLoadClass::LoadKind::kReferrersClass) { |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5497 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5498 | } |
| 5499 | locations->SetOut(Location::RequiresRegister()); |
| Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 5500 | if (load_kind == HLoadClass::LoadKind::kBssEntry) { |
| 5501 | if (!kUseReadBarrier || kUseBakerReadBarrier) { |
| 5502 | // Rely on the type resolution and/or initialization to save everything. |
| 5503 | // Custom calling convention: RAX serves as both input and output. |
| 5504 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 5505 | caller_saves.Add(Location::RegisterLocation(RAX)); |
| 5506 | locations->SetCustomSlowPathCallerSaves(caller_saves); |
| 5507 | } else { |
| 5508 | // For non-Baker read barrier we have a temp-clobbering call. |
| 5509 | } |
| 5510 | } |
| Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5511 | } |
| 5512 | |
| Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 5513 | Label* CodeGeneratorX86_64::NewJitRootClassPatch(const DexFile& dex_file, |
| 5514 | dex::TypeIndex dex_index, |
| Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 5515 | Handle<mirror::Class> handle) { |
| 5516 | jit_class_roots_.Overwrite( |
| 5517 | TypeReference(&dex_file, dex_index), reinterpret_cast64<uint64_t>(handle.GetReference())); |
| Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 5518 | // Add a patch entry and return the label. |
| 5519 | jit_class_patches_.emplace_back(dex_file, dex_index.index_); |
| 5520 | PatchInfo<Label>* info = &jit_class_patches_.back(); |
| 5521 | return &info->label; |
| 5522 | } |
| 5523 | |
| Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 5524 | // NO_THREAD_SAFETY_ANALYSIS as we manipulate handles whose internal object we know does not |
| 5525 | // move. |
| 5526 | void InstructionCodeGeneratorX86_64::VisitLoadClass(HLoadClass* cls) NO_THREAD_SAFETY_ANALYSIS { |
| Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5527 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
| Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 5528 | if (load_kind == HLoadClass::LoadKind::kRuntimeCall) { |
| Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5529 | codegen_->GenerateLoadClassRuntimeCall(cls); |
| Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 5530 | return; |
| 5531 | } |
| Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5532 | DCHECK(!cls->NeedsAccessCheck()); |
| Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 5533 | |
| Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5534 | LocationSummary* locations = cls->GetLocations(); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5535 | Location out_loc = locations->Out(); |
| 5536 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5537 | |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 5538 | const ReadBarrierOption read_barrier_option = cls->IsInBootImage() |
| 5539 | ? kWithoutReadBarrier |
| 5540 | : kCompilerReadBarrierOption; |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5541 | bool generate_null_check = false; |
| Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5542 | switch (load_kind) { |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5543 | case HLoadClass::LoadKind::kReferrersClass: { |
| 5544 | DCHECK(!cls->CanCallRuntime()); |
| 5545 | DCHECK(!cls->MustGenerateClinitCheck()); |
| 5546 | // /* GcRoot<mirror::Class> */ out = current_method->declaring_class_ |
| 5547 | CpuRegister current_method = locations->InAt(0).AsRegister<CpuRegister>(); |
| 5548 | GenerateGcRootFieldLoad( |
| Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5549 | cls, |
| 5550 | out_loc, |
| 5551 | Address(current_method, ArtMethod::DeclaringClassOffset().Int32Value()), |
| Roland Levillain | 00468f3 | 2016-10-27 18:02:48 +0100 | [diff] [blame] | 5552 | /* fixup_label */ nullptr, |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 5553 | read_barrier_option); |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5554 | break; |
| 5555 | } |
| 5556 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: |
| Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5557 | DCHECK(codegen_->GetCompilerOptions().IsBootImage()); |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 5558 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5559 | __ leal(out, Address::Absolute(CodeGeneratorX86_64::kDummy32BitOffset, /* no_rip */ false)); |
| Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 5560 | codegen_->RecordBootTypePatch(cls); |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5561 | break; |
| 5562 | case HLoadClass::LoadKind::kBootImageAddress: { |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 5563 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
| Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 5564 | uint32_t address = dchecked_integral_cast<uint32_t>( |
| 5565 | reinterpret_cast<uintptr_t>(cls->GetClass().Get())); |
| 5566 | DCHECK_NE(address, 0u); |
| Colin Cross | 0bd9717 | 2017-03-15 16:33:27 -0700 | [diff] [blame] | 5567 | __ movl(out, Immediate(static_cast<int32_t>(address))); // Zero-extended. |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5568 | break; |
| 5569 | } |
| Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 5570 | case HLoadClass::LoadKind::kBootImageClassTable: { |
| 5571 | DCHECK(!codegen_->GetCompilerOptions().IsBootImage()); |
| 5572 | __ movl(out, Address::Absolute(CodeGeneratorX86_64::kDummy32BitOffset, /* no_rip */ false)); |
| 5573 | codegen_->RecordBootTypePatch(cls); |
| 5574 | // Extract the reference from the slot data, i.e. clear the hash bits. |
| 5575 | int32_t masked_hash = ClassTable::TableSlot::MaskHash( |
| 5576 | ComputeModifiedUtf8Hash(cls->GetDexFile().StringByTypeIdx(cls->GetTypeIndex()))); |
| 5577 | if (masked_hash != 0) { |
| 5578 | __ subl(out, Immediate(masked_hash)); |
| 5579 | } |
| 5580 | break; |
| 5581 | } |
| Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5582 | case HLoadClass::LoadKind::kBssEntry: { |
| 5583 | Address address = Address::Absolute(CodeGeneratorX86_64::kDummy32BitOffset, |
| 5584 | /* no_rip */ false); |
| 5585 | Label* fixup_label = codegen_->NewTypeBssEntryPatch(cls); |
| 5586 | // /* GcRoot<mirror::Class> */ out = *address /* PC-relative */ |
| 5587 | GenerateGcRootFieldLoad(cls, out_loc, address, fixup_label, read_barrier_option); |
| 5588 | generate_null_check = true; |
| 5589 | break; |
| 5590 | } |
| Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 5591 | case HLoadClass::LoadKind::kJitTableAddress: { |
| 5592 | Address address = Address::Absolute(CodeGeneratorX86_64::kDummy32BitOffset, |
| 5593 | /* no_rip */ true); |
| 5594 | Label* fixup_label = |
| Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 5595 | codegen_->NewJitRootClassPatch(cls->GetDexFile(), cls->GetTypeIndex(), cls->GetClass()); |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5596 | // /* GcRoot<mirror::Class> */ out = *address |
| Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 5597 | GenerateGcRootFieldLoad(cls, out_loc, address, fixup_label, read_barrier_option); |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5598 | break; |
| 5599 | } |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5600 | default: |
| 5601 | LOG(FATAL) << "Unexpected load kind: " << cls->GetLoadKind(); |
| 5602 | UNREACHABLE(); |
| 5603 | } |
| 5604 | |
| 5605 | if (generate_null_check || cls->MustGenerateClinitCheck()) { |
| 5606 | DCHECK(cls->CanCallRuntime()); |
| 5607 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathX86_64( |
| 5608 | cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck()); |
| 5609 | codegen_->AddSlowPath(slow_path); |
| 5610 | if (generate_null_check) { |
| 5611 | __ testl(out, out); |
| 5612 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 5613 | } |
| 5614 | if (cls->MustGenerateClinitCheck()) { |
| 5615 | GenerateClassInitializationCheck(slow_path, out); |
| 5616 | } else { |
| 5617 | __ Bind(slow_path->GetExitLabel()); |
| Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5618 | } |
| Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5619 | } |
| 5620 | } |
| 5621 | |
| 5622 | void LocationsBuilderX86_64::VisitClinitCheck(HClinitCheck* check) { |
| 5623 | LocationSummary* locations = |
| 5624 | new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath); |
| 5625 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5626 | if (check->HasUses()) { |
| 5627 | locations->SetOut(Location::SameAsFirstInput()); |
| 5628 | } |
| 5629 | } |
| 5630 | |
| 5631 | void InstructionCodeGeneratorX86_64::VisitClinitCheck(HClinitCheck* check) { |
| Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5632 | // We assume the class to not be null. |
| Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 5633 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathX86_64( |
| Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5634 | check->GetLoadClass(), check, check->GetDexPc(), true); |
| Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5635 | codegen_->AddSlowPath(slow_path); |
| Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 5636 | GenerateClassInitializationCheck(slow_path, |
| 5637 | check->GetLocations()->InAt(0).AsRegister<CpuRegister>()); |
| Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5638 | } |
| 5639 | |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5640 | HLoadString::LoadKind CodeGeneratorX86_64::GetSupportedLoadStringKind( |
| 5641 | HLoadString::LoadKind desired_string_load_kind) { |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5642 | switch (desired_string_load_kind) { |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5643 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: |
| Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 5644 | case HLoadString::LoadKind::kBootImageInternTable: |
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5645 | case HLoadString::LoadKind::kBssEntry: |
| Calin Juravle | ffc8707 | 2016-04-20 14:22:09 +0100 | [diff] [blame] | 5646 | DCHECK(!Runtime::Current()->UseJitCompilation()); |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5647 | break; |
| Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 5648 | case HLoadString::LoadKind::kJitTableAddress: |
| 5649 | DCHECK(Runtime::Current()->UseJitCompilation()); |
| 5650 | break; |
| Vladimir Marko | 764d454 | 2017-05-16 10:31:41 +0100 | [diff] [blame] | 5651 | case HLoadString::LoadKind::kBootImageAddress: |
| Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 5652 | case HLoadString::LoadKind::kRuntimeCall: |
| Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5653 | break; |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5654 | } |
| 5655 | return desired_string_load_kind; |
| 5656 | } |
| 5657 | |
| Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5658 | void LocationsBuilderX86_64::VisitLoadString(HLoadString* load) { |
| Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 5659 | LocationSummary::CallKind call_kind = CodeGenerator::GetLoadStringCallKind(load); |
| Nicolas Geoffray | 917d016 | 2015-11-24 18:25:35 +0000 | [diff] [blame] | 5660 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(load, call_kind); |
| Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 5661 | if (load->GetLoadKind() == HLoadString::LoadKind::kRuntimeCall) { |
| Christina Wadsworth | abb341b | 2016-08-31 16:29:44 -0700 | [diff] [blame] | 5662 | locations->SetOut(Location::RegisterLocation(RAX)); |
| 5663 | } else { |
| 5664 | locations->SetOut(Location::RequiresRegister()); |
| Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 5665 | if (load->GetLoadKind() == HLoadString::LoadKind::kBssEntry) { |
| 5666 | if (!kUseReadBarrier || kUseBakerReadBarrier) { |
| Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 5667 | // Rely on the pResolveString to save everything. |
| Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 5668 | // Custom calling convention: RAX serves as both input and output. |
| 5669 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 5670 | caller_saves.Add(Location::RegisterLocation(RAX)); |
| 5671 | locations->SetCustomSlowPathCallerSaves(caller_saves); |
| 5672 | } else { |
| 5673 | // For non-Baker read barrier we have a temp-clobbering call. |
| 5674 | } |
| 5675 | } |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5676 | } |
| Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5677 | } |
| 5678 | |
| Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 5679 | Label* CodeGeneratorX86_64::NewJitRootStringPatch(const DexFile& dex_file, |
| Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 5680 | dex::StringIndex dex_index, |
| 5681 | Handle<mirror::String> handle) { |
| 5682 | jit_string_roots_.Overwrite( |
| 5683 | StringReference(&dex_file, dex_index), reinterpret_cast64<uint64_t>(handle.GetReference())); |
| Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 5684 | // Add a patch entry and return the label. |
| Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 5685 | jit_string_patches_.emplace_back(dex_file, dex_index.index_); |
| Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 5686 | PatchInfo<Label>* info = &jit_string_patches_.back(); |
| 5687 | return &info->label; |
| 5688 | } |
| 5689 | |
| Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 5690 | // NO_THREAD_SAFETY_ANALYSIS as we manipulate handles whose internal object we know does not |
| 5691 | // move. |
| 5692 | void InstructionCodeGeneratorX86_64::VisitLoadString(HLoadString* load) NO_THREAD_SAFETY_ANALYSIS { |
| Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 5693 | LocationSummary* locations = load->GetLocations(); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5694 | Location out_loc = locations->Out(); |
| 5695 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5696 | |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5697 | switch (load->GetLoadKind()) { |
| 5698 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: { |
| Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5699 | DCHECK(codegen_->GetCompilerOptions().IsBootImage()); |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5700 | __ leal(out, Address::Absolute(CodeGeneratorX86_64::kDummy32BitOffset, /* no_rip */ false)); |
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5701 | codegen_->RecordBootStringPatch(load); |
| Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 5702 | return; |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5703 | } |
| 5704 | case HLoadString::LoadKind::kBootImageAddress: { |
| Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 5705 | uint32_t address = dchecked_integral_cast<uint32_t>( |
| 5706 | reinterpret_cast<uintptr_t>(load->GetString().Get())); |
| 5707 | DCHECK_NE(address, 0u); |
| Colin Cross | 0bd9717 | 2017-03-15 16:33:27 -0700 | [diff] [blame] | 5708 | __ movl(out, Immediate(static_cast<int32_t>(address))); // Zero-extended. |
| Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 5709 | return; |
| 5710 | } |
| 5711 | case HLoadString::LoadKind::kBootImageInternTable: { |
| 5712 | DCHECK(!codegen_->GetCompilerOptions().IsBootImage()); |
| 5713 | __ movl(out, Address::Absolute(CodeGeneratorX86_64::kDummy32BitOffset, /* no_rip */ false)); |
| 5714 | codegen_->RecordBootStringPatch(load); |
| 5715 | return; |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5716 | } |
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5717 | case HLoadString::LoadKind::kBssEntry: { |
| 5718 | Address address = Address::Absolute(CodeGeneratorX86_64::kDummy32BitOffset, |
| 5719 | /* no_rip */ false); |
| 5720 | Label* fixup_label = codegen_->NewStringBssEntryPatch(load); |
| 5721 | // /* GcRoot<mirror::Class> */ out = *address /* PC-relative */ |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 5722 | GenerateGcRootFieldLoad(load, out_loc, address, fixup_label, kCompilerReadBarrierOption); |
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5723 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) LoadStringSlowPathX86_64(load); |
| 5724 | codegen_->AddSlowPath(slow_path); |
| 5725 | __ testl(out, out); |
| 5726 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 5727 | __ Bind(slow_path->GetExitLabel()); |
| 5728 | return; |
| 5729 | } |
| Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 5730 | case HLoadString::LoadKind::kJitTableAddress: { |
| 5731 | Address address = Address::Absolute(CodeGeneratorX86_64::kDummy32BitOffset, |
| 5732 | /* no_rip */ true); |
| Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 5733 | Label* fixup_label = codegen_->NewJitRootStringPatch( |
| 5734 | load->GetDexFile(), load->GetStringIndex(), load->GetString()); |
| Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 5735 | // /* GcRoot<mirror::String> */ out = *address |
| 5736 | GenerateGcRootFieldLoad(load, out_loc, address, fixup_label, kCompilerReadBarrierOption); |
| 5737 | return; |
| 5738 | } |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5739 | default: |
| Christina Wadsworth | bf44e0e | 2016-08-18 10:37:42 -0700 | [diff] [blame] | 5740 | break; |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5741 | } |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5742 | |
| Christina Wadsworth | bf44e0e | 2016-08-18 10:37:42 -0700 | [diff] [blame] | 5743 | // 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] | 5744 | // Custom calling convention: RAX serves as both input and output. |
| Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 5745 | __ movl(CpuRegister(RAX), Immediate(load->GetStringIndex().index_)); |
| Christina Wadsworth | abb341b | 2016-08-31 16:29:44 -0700 | [diff] [blame] | 5746 | codegen_->InvokeRuntime(kQuickResolveString, |
| 5747 | load, |
| 5748 | load->GetDexPc()); |
| 5749 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
| Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5750 | } |
| 5751 | |
| David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 5752 | static Address GetExceptionTlsAddress() { |
| Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 5753 | return Address::Absolute(Thread::ExceptionOffset<kX86_64PointerSize>().Int32Value(), |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5754 | /* no_rip */ true); |
| David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 5755 | } |
| 5756 | |
| Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5757 | void LocationsBuilderX86_64::VisitLoadException(HLoadException* load) { |
| 5758 | LocationSummary* locations = |
| 5759 | new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall); |
| 5760 | locations->SetOut(Location::RequiresRegister()); |
| 5761 | } |
| 5762 | |
| 5763 | void InstructionCodeGeneratorX86_64::VisitLoadException(HLoadException* load) { |
| David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 5764 | __ gs()->movl(load->GetLocations()->Out().AsRegister<CpuRegister>(), GetExceptionTlsAddress()); |
| 5765 | } |
| 5766 | |
| 5767 | void LocationsBuilderX86_64::VisitClearException(HClearException* clear) { |
| 5768 | new (GetGraph()->GetArena()) LocationSummary(clear, LocationSummary::kNoCall); |
| 5769 | } |
| 5770 | |
| 5771 | void InstructionCodeGeneratorX86_64::VisitClearException(HClearException* clear ATTRIBUTE_UNUSED) { |
| 5772 | __ gs()->movl(GetExceptionTlsAddress(), Immediate(0)); |
| Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5773 | } |
| 5774 | |
| 5775 | void LocationsBuilderX86_64::VisitThrow(HThrow* instruction) { |
| 5776 | LocationSummary* locations = |
| Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 5777 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
| Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5778 | InvokeRuntimeCallingConvention calling_convention; |
| 5779 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 5780 | } |
| 5781 | |
| 5782 | void InstructionCodeGeneratorX86_64::VisitThrow(HThrow* instruction) { |
| Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 5783 | codegen_->InvokeRuntime(kQuickDeliverException, instruction, instruction->GetDexPc()); |
| Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 5784 | CheckEntrypointTypes<kQuickDeliverException, void, mirror::Object*>(); |
| Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5785 | } |
| 5786 | |
| Nicolas Geoffray | 53b07bd | 2016-11-05 15:09:19 +0000 | [diff] [blame] | 5787 | static bool CheckCastTypeCheckNeedsATemporary(TypeCheckKind type_check_kind) { |
| 5788 | if (type_check_kind == TypeCheckKind::kInterfaceCheck && !kPoisonHeapReferences) { |
| Mathieu Chartier | cdba73b | 2016-11-03 19:23:06 -0700 | [diff] [blame] | 5789 | // We need a temporary for holding the iftable length. |
| 5790 | return true; |
| 5791 | } |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5792 | return kEmitCompilerReadBarrier && |
| Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 5793 | !kUseBakerReadBarrier && |
| 5794 | (type_check_kind == TypeCheckKind::kAbstractClassCheck || |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5795 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 5796 | type_check_kind == TypeCheckKind::kArrayObjectCheck); |
| 5797 | } |
| 5798 | |
| Nicolas Geoffray | 53b07bd | 2016-11-05 15:09:19 +0000 | [diff] [blame] | 5799 | static bool InstanceOfTypeCheckNeedsATemporary(TypeCheckKind type_check_kind) { |
| 5800 | return kEmitCompilerReadBarrier && |
| 5801 | !kUseBakerReadBarrier && |
| 5802 | (type_check_kind == TypeCheckKind::kAbstractClassCheck || |
| 5803 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 5804 | type_check_kind == TypeCheckKind::kArrayObjectCheck); |
| 5805 | } |
| 5806 | |
| Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5807 | void LocationsBuilderX86_64::VisitInstanceOf(HInstanceOf* instruction) { |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5808 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5809 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5810 | bool baker_read_barrier_slow_path = false; |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5811 | switch (type_check_kind) { |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5812 | case TypeCheckKind::kExactCheck: |
| 5813 | case TypeCheckKind::kAbstractClassCheck: |
| 5814 | case TypeCheckKind::kClassHierarchyCheck: |
| 5815 | case TypeCheckKind::kArrayObjectCheck: |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5816 | call_kind = |
| 5817 | kEmitCompilerReadBarrier ? LocationSummary::kCallOnSlowPath : LocationSummary::kNoCall; |
| Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5818 | baker_read_barrier_slow_path = kUseBakerReadBarrier; |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5819 | break; |
| 5820 | case TypeCheckKind::kArrayCheck: |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5821 | case TypeCheckKind::kUnresolvedCheck: |
| 5822 | case TypeCheckKind::kInterfaceCheck: |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5823 | call_kind = LocationSummary::kCallOnSlowPath; |
| 5824 | break; |
| 5825 | } |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5826 | |
| Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5827 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
| Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5828 | if (baker_read_barrier_slow_path) { |
| Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 5829 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
| Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5830 | } |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5831 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5832 | locations->SetInAt(1, Location::Any()); |
| 5833 | // Note that TypeCheckSlowPathX86_64 uses this "out" register too. |
| 5834 | locations->SetOut(Location::RequiresRegister()); |
| 5835 | // When read barriers are enabled, we need a temporary register for |
| 5836 | // some cases. |
| Nicolas Geoffray | 53b07bd | 2016-11-05 15:09:19 +0000 | [diff] [blame] | 5837 | if (InstanceOfTypeCheckNeedsATemporary(type_check_kind)) { |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5838 | locations->AddTemp(Location::RequiresRegister()); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5839 | } |
| Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5840 | } |
| 5841 | |
| Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5842 | void InstructionCodeGeneratorX86_64::VisitInstanceOf(HInstanceOf* instruction) { |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5843 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5844 | LocationSummary* locations = instruction->GetLocations(); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5845 | Location obj_loc = locations->InAt(0); |
| 5846 | CpuRegister obj = obj_loc.AsRegister<CpuRegister>(); |
| Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5847 | Location cls = locations->InAt(1); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5848 | Location out_loc = locations->Out(); |
| 5849 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
| Nicolas Geoffray | 53b07bd | 2016-11-05 15:09:19 +0000 | [diff] [blame] | 5850 | Location maybe_temp_loc = InstanceOfTypeCheckNeedsATemporary(type_check_kind) ? |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5851 | locations->GetTemp(0) : |
| 5852 | Location::NoLocation(); |
| Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5853 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5854 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 5855 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 5856 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
| Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 5857 | SlowPathCode* slow_path = nullptr; |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5858 | NearLabel done, zero; |
| Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5859 | |
| 5860 | // Return 0 if `obj` is null. |
| Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 5861 | // Avoid null check if we know obj is not null. |
| 5862 | if (instruction->MustDoNullCheck()) { |
| 5863 | __ testl(obj, obj); |
| 5864 | __ j(kEqual, &zero); |
| 5865 | } |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5866 | |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5867 | switch (type_check_kind) { |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5868 | case TypeCheckKind::kExactCheck: { |
| Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 5869 | // /* HeapReference<Class> */ out = obj->klass_ |
| 5870 | GenerateReferenceLoadTwoRegisters(instruction, |
| 5871 | out_loc, |
| 5872 | obj_loc, |
| 5873 | class_offset, |
| 5874 | kCompilerReadBarrierOption); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5875 | if (cls.IsRegister()) { |
| 5876 | __ cmpl(out, cls.AsRegister<CpuRegister>()); |
| 5877 | } else { |
| 5878 | DCHECK(cls.IsStackSlot()) << cls; |
| 5879 | __ cmpl(out, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 5880 | } |
| Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 5881 | if (zero.IsLinked()) { |
| 5882 | // Classes must be equal for the instanceof to succeed. |
| 5883 | __ j(kNotEqual, &zero); |
| 5884 | __ movl(out, Immediate(1)); |
| 5885 | __ jmp(&done); |
| 5886 | } else { |
| 5887 | __ setcc(kEqual, out); |
| 5888 | // setcc only sets the low byte. |
| 5889 | __ andl(out, Immediate(1)); |
| 5890 | } |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5891 | break; |
| 5892 | } |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5893 | |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5894 | case TypeCheckKind::kAbstractClassCheck: { |
| Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 5895 | // /* HeapReference<Class> */ out = obj->klass_ |
| 5896 | GenerateReferenceLoadTwoRegisters(instruction, |
| 5897 | out_loc, |
| 5898 | obj_loc, |
| 5899 | class_offset, |
| 5900 | kCompilerReadBarrierOption); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5901 | // If the class is abstract, we eagerly fetch the super class of the |
| 5902 | // object to avoid doing a comparison we know will fail. |
| 5903 | NearLabel loop, success; |
| 5904 | __ Bind(&loop); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5905 | // /* HeapReference<Class> */ out = out->super_class_ |
| Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 5906 | GenerateReferenceLoadOneRegister(instruction, |
| 5907 | out_loc, |
| 5908 | super_offset, |
| 5909 | maybe_temp_loc, |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 5910 | kCompilerReadBarrierOption); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5911 | __ testl(out, out); |
| 5912 | // If `out` is null, we use it for the result, and jump to `done`. |
| 5913 | __ j(kEqual, &done); |
| 5914 | if (cls.IsRegister()) { |
| 5915 | __ cmpl(out, cls.AsRegister<CpuRegister>()); |
| 5916 | } else { |
| 5917 | DCHECK(cls.IsStackSlot()) << cls; |
| 5918 | __ cmpl(out, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 5919 | } |
| 5920 | __ j(kNotEqual, &loop); |
| 5921 | __ movl(out, Immediate(1)); |
| 5922 | if (zero.IsLinked()) { |
| 5923 | __ jmp(&done); |
| 5924 | } |
| 5925 | break; |
| 5926 | } |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5927 | |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5928 | case TypeCheckKind::kClassHierarchyCheck: { |
| Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 5929 | // /* HeapReference<Class> */ out = obj->klass_ |
| 5930 | GenerateReferenceLoadTwoRegisters(instruction, |
| 5931 | out_loc, |
| 5932 | obj_loc, |
| 5933 | class_offset, |
| 5934 | kCompilerReadBarrierOption); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5935 | // Walk over the class hierarchy to find a match. |
| 5936 | NearLabel loop, success; |
| 5937 | __ Bind(&loop); |
| 5938 | if (cls.IsRegister()) { |
| 5939 | __ cmpl(out, cls.AsRegister<CpuRegister>()); |
| 5940 | } else { |
| 5941 | DCHECK(cls.IsStackSlot()) << cls; |
| 5942 | __ cmpl(out, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 5943 | } |
| 5944 | __ j(kEqual, &success); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5945 | // /* HeapReference<Class> */ out = out->super_class_ |
| Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 5946 | GenerateReferenceLoadOneRegister(instruction, |
| 5947 | out_loc, |
| 5948 | super_offset, |
| 5949 | maybe_temp_loc, |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 5950 | kCompilerReadBarrierOption); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5951 | __ testl(out, out); |
| 5952 | __ j(kNotEqual, &loop); |
| 5953 | // If `out` is null, we use it for the result, and jump to `done`. |
| 5954 | __ jmp(&done); |
| 5955 | __ Bind(&success); |
| 5956 | __ movl(out, Immediate(1)); |
| 5957 | if (zero.IsLinked()) { |
| 5958 | __ jmp(&done); |
| 5959 | } |
| 5960 | break; |
| 5961 | } |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5962 | |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5963 | case TypeCheckKind::kArrayObjectCheck: { |
| Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 5964 | // /* HeapReference<Class> */ out = obj->klass_ |
| 5965 | GenerateReferenceLoadTwoRegisters(instruction, |
| 5966 | out_loc, |
| 5967 | obj_loc, |
| 5968 | class_offset, |
| 5969 | kCompilerReadBarrierOption); |
| Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 5970 | // Do an exact check. |
| 5971 | NearLabel exact_check; |
| 5972 | if (cls.IsRegister()) { |
| 5973 | __ cmpl(out, cls.AsRegister<CpuRegister>()); |
| 5974 | } else { |
| 5975 | DCHECK(cls.IsStackSlot()) << cls; |
| 5976 | __ cmpl(out, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 5977 | } |
| 5978 | __ j(kEqual, &exact_check); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5979 | // 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] | 5980 | // /* HeapReference<Class> */ out = out->component_type_ |
| Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 5981 | GenerateReferenceLoadOneRegister(instruction, |
| 5982 | out_loc, |
| 5983 | component_offset, |
| 5984 | maybe_temp_loc, |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 5985 | kCompilerReadBarrierOption); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5986 | __ testl(out, out); |
| 5987 | // If `out` is null, we use it for the result, and jump to `done`. |
| 5988 | __ j(kEqual, &done); |
| 5989 | __ cmpw(Address(out, primitive_offset), Immediate(Primitive::kPrimNot)); |
| 5990 | __ j(kNotEqual, &zero); |
| Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 5991 | __ Bind(&exact_check); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5992 | __ movl(out, Immediate(1)); |
| 5993 | __ jmp(&done); |
| 5994 | break; |
| 5995 | } |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5996 | |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5997 | case TypeCheckKind::kArrayCheck: { |
| Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 5998 | // No read barrier since the slow path will retry upon failure. |
| 5999 | // /* HeapReference<Class> */ out = obj->klass_ |
| 6000 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6001 | out_loc, |
| 6002 | obj_loc, |
| 6003 | class_offset, |
| 6004 | kWithoutReadBarrier); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6005 | if (cls.IsRegister()) { |
| 6006 | __ cmpl(out, cls.AsRegister<CpuRegister>()); |
| 6007 | } else { |
| 6008 | DCHECK(cls.IsStackSlot()) << cls; |
| 6009 | __ cmpl(out, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 6010 | } |
| 6011 | DCHECK(locations->OnlyCallsOnSlowPath()); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6012 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathX86_64(instruction, |
| 6013 | /* is_fatal */ false); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6014 | codegen_->AddSlowPath(slow_path); |
| 6015 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 6016 | __ movl(out, Immediate(1)); |
| 6017 | if (zero.IsLinked()) { |
| 6018 | __ jmp(&done); |
| 6019 | } |
| 6020 | break; |
| 6021 | } |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6022 | |
| Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 6023 | case TypeCheckKind::kUnresolvedCheck: |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6024 | case TypeCheckKind::kInterfaceCheck: { |
| 6025 | // 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] | 6026 | // into the slow path for the unresolved and interface check |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6027 | // cases. |
| 6028 | // |
| 6029 | // We cannot directly call the InstanceofNonTrivial runtime |
| 6030 | // entry point without resorting to a type checking slow path |
| 6031 | // here (i.e. by calling InvokeRuntime directly), as it would |
| 6032 | // require to assign fixed registers for the inputs of this |
| 6033 | // HInstanceOf instruction (following the runtime calling |
| 6034 | // convention), which might be cluttered by the potential first |
| 6035 | // read barrier emission at the beginning of this method. |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6036 | // |
| 6037 | // TODO: Introduce a new runtime entry point taking the object |
| 6038 | // to test (instead of its class) as argument, and let it deal |
| 6039 | // with the read barrier issues. This will let us refactor this |
| 6040 | // case of the `switch` code as it was previously (with a direct |
| 6041 | // call to the runtime not using a type checking slow path). |
| 6042 | // This should also be beneficial for the other cases above. |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6043 | DCHECK(locations->OnlyCallsOnSlowPath()); |
| 6044 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathX86_64(instruction, |
| 6045 | /* is_fatal */ false); |
| 6046 | codegen_->AddSlowPath(slow_path); |
| 6047 | __ jmp(slow_path->GetEntryLabel()); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6048 | if (zero.IsLinked()) { |
| 6049 | __ jmp(&done); |
| 6050 | } |
| 6051 | break; |
| 6052 | } |
| Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6053 | } |
| Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6054 | |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6055 | if (zero.IsLinked()) { |
| Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6056 | __ Bind(&zero); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6057 | __ xorl(out, out); |
| 6058 | } |
| 6059 | |
| 6060 | if (done.IsLinked()) { |
| 6061 | __ Bind(&done); |
| Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6062 | } |
| 6063 | |
| Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6064 | if (slow_path != nullptr) { |
| 6065 | __ Bind(slow_path->GetExitLabel()); |
| 6066 | } |
| Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6067 | } |
| 6068 | |
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6069 | static bool IsTypeCheckSlowPathFatal(TypeCheckKind type_check_kind, bool throws_into_catch) { |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6070 | switch (type_check_kind) { |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6071 | case TypeCheckKind::kExactCheck: |
| 6072 | case TypeCheckKind::kAbstractClassCheck: |
| 6073 | case TypeCheckKind::kClassHierarchyCheck: |
| 6074 | case TypeCheckKind::kArrayObjectCheck: |
| Andreas Gampe | b5f3d81 | 2016-11-04 19:25:20 -0700 | [diff] [blame] | 6075 | return !throws_into_catch && !kEmitCompilerReadBarrier; |
| Nicolas Geoffray | 53b07bd | 2016-11-05 15:09:19 +0000 | [diff] [blame] | 6076 | case TypeCheckKind::kInterfaceCheck: |
| 6077 | return !throws_into_catch && !kEmitCompilerReadBarrier && !kPoisonHeapReferences; |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6078 | case TypeCheckKind::kArrayCheck: |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6079 | case TypeCheckKind::kUnresolvedCheck: |
| Andreas Gampe | b5f3d81 | 2016-11-04 19:25:20 -0700 | [diff] [blame] | 6080 | return false; |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6081 | } |
| Andreas Gampe | b5f3d81 | 2016-11-04 19:25:20 -0700 | [diff] [blame] | 6082 | LOG(FATAL) << "Unreachable"; |
| 6083 | UNREACHABLE(); |
| 6084 | } |
| 6085 | |
| 6086 | void LocationsBuilderX86_64::VisitCheckCast(HCheckCast* instruction) { |
| 6087 | bool throws_into_catch = instruction->CanThrowIntoCatchBlock(); |
| 6088 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| 6089 | bool is_fatal_slow_path = IsTypeCheckSlowPathFatal(type_check_kind, throws_into_catch); |
| 6090 | LocationSummary::CallKind call_kind = is_fatal_slow_path |
| 6091 | ? LocationSummary::kNoCall |
| 6092 | : LocationSummary::kCallOnSlowPath; |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6093 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
| 6094 | locations->SetInAt(0, Location::RequiresRegister()); |
| Mathieu Chartier | cdba73b | 2016-11-03 19:23:06 -0700 | [diff] [blame] | 6095 | if (type_check_kind == TypeCheckKind::kInterfaceCheck) { |
| 6096 | // Require a register for the interface check since there is a loop that compares the class to |
| 6097 | // a memory address. |
| 6098 | locations->SetInAt(1, Location::RequiresRegister()); |
| 6099 | } else { |
| 6100 | locations->SetInAt(1, Location::Any()); |
| 6101 | } |
| 6102 | |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6103 | // Note that TypeCheckSlowPathX86_64 uses this "temp" register too. |
| 6104 | locations->AddTemp(Location::RequiresRegister()); |
| 6105 | // When read barriers are enabled, we need an additional temporary |
| 6106 | // register for some cases. |
| Nicolas Geoffray | 53b07bd | 2016-11-05 15:09:19 +0000 | [diff] [blame] | 6107 | if (CheckCastTypeCheckNeedsATemporary(type_check_kind)) { |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6108 | locations->AddTemp(Location::RequiresRegister()); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6109 | } |
| Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6110 | } |
| 6111 | |
| 6112 | void InstructionCodeGeneratorX86_64::VisitCheckCast(HCheckCast* instruction) { |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6113 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6114 | LocationSummary* locations = instruction->GetLocations(); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6115 | Location obj_loc = locations->InAt(0); |
| 6116 | CpuRegister obj = obj_loc.AsRegister<CpuRegister>(); |
| Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6117 | Location cls = locations->InAt(1); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6118 | Location temp_loc = locations->GetTemp(0); |
| 6119 | CpuRegister temp = temp_loc.AsRegister<CpuRegister>(); |
| Nicolas Geoffray | 53b07bd | 2016-11-05 15:09:19 +0000 | [diff] [blame] | 6120 | Location maybe_temp2_loc = CheckCastTypeCheckNeedsATemporary(type_check_kind) ? |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6121 | locations->GetTemp(1) : |
| 6122 | Location::NoLocation(); |
| Mathieu Chartier | cdba73b | 2016-11-03 19:23:06 -0700 | [diff] [blame] | 6123 | const uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 6124 | const uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 6125 | const uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 6126 | const uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
| 6127 | const uint32_t iftable_offset = mirror::Class::IfTableOffset().Uint32Value(); |
| 6128 | const uint32_t array_length_offset = mirror::Array::LengthOffset().Uint32Value(); |
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6129 | const uint32_t object_array_data_offset = |
| 6130 | mirror::Array::DataOffset(kHeapReferenceSize).Uint32Value(); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6131 | |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6132 | // Always false for read barriers since we may need to go to the entrypoint for non-fatal cases |
| 6133 | // from false negatives. The false negatives may come from avoiding read barriers below. Avoiding |
| 6134 | // read barriers is done for performance and code size reasons. |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6135 | bool is_type_check_slow_path_fatal = |
| Andreas Gampe | b5f3d81 | 2016-11-04 19:25:20 -0700 | [diff] [blame] | 6136 | IsTypeCheckSlowPathFatal(type_check_kind, instruction->CanThrowIntoCatchBlock()); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6137 | SlowPathCode* type_check_slow_path = |
| 6138 | new (GetGraph()->GetArena()) TypeCheckSlowPathX86_64(instruction, |
| 6139 | is_type_check_slow_path_fatal); |
| 6140 | codegen_->AddSlowPath(type_check_slow_path); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6141 | |
| Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6142 | |
| 6143 | NearLabel done; |
| 6144 | // Avoid null check if we know obj is not null. |
| 6145 | if (instruction->MustDoNullCheck()) { |
| 6146 | __ testl(obj, obj); |
| 6147 | __ j(kEqual, &done); |
| 6148 | } |
| 6149 | |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6150 | switch (type_check_kind) { |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6151 | case TypeCheckKind::kExactCheck: |
| 6152 | case TypeCheckKind::kArrayCheck: { |
| Roland Levillain | 8650378 | 2016-02-11 19:07:30 +0000 | [diff] [blame] | 6153 | // /* HeapReference<Class> */ temp = obj->klass_ |
| Mathieu Chartier | cdba73b | 2016-11-03 19:23:06 -0700 | [diff] [blame] | 6154 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6155 | temp_loc, |
| 6156 | obj_loc, |
| 6157 | class_offset, |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6158 | kWithoutReadBarrier); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6159 | if (cls.IsRegister()) { |
| 6160 | __ cmpl(temp, cls.AsRegister<CpuRegister>()); |
| 6161 | } else { |
| 6162 | DCHECK(cls.IsStackSlot()) << cls; |
| 6163 | __ cmpl(temp, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 6164 | } |
| 6165 | // Jump to slow path for throwing the exception or doing a |
| 6166 | // more involved array check. |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6167 | __ j(kNotEqual, type_check_slow_path->GetEntryLabel()); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6168 | break; |
| 6169 | } |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6170 | |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6171 | case TypeCheckKind::kAbstractClassCheck: { |
| Roland Levillain | 8650378 | 2016-02-11 19:07:30 +0000 | [diff] [blame] | 6172 | // /* HeapReference<Class> */ temp = obj->klass_ |
| Mathieu Chartier | cdba73b | 2016-11-03 19:23:06 -0700 | [diff] [blame] | 6173 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6174 | temp_loc, |
| 6175 | obj_loc, |
| 6176 | class_offset, |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6177 | kWithoutReadBarrier); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6178 | // If the class is abstract, we eagerly fetch the super class of the |
| 6179 | // object to avoid doing a comparison we know will fail. |
| Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 6180 | NearLabel loop; |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6181 | __ Bind(&loop); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6182 | // /* HeapReference<Class> */ temp = temp->super_class_ |
| Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6183 | GenerateReferenceLoadOneRegister(instruction, |
| 6184 | temp_loc, |
| 6185 | super_offset, |
| 6186 | maybe_temp2_loc, |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6187 | kWithoutReadBarrier); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6188 | |
| Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 6189 | // If the class reference currently in `temp` is null, jump to the slow path to throw the |
| 6190 | // exception. |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6191 | __ testl(temp, temp); |
| Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 6192 | // Otherwise, compare the classes. |
| 6193 | __ j(kZero, type_check_slow_path->GetEntryLabel()); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6194 | if (cls.IsRegister()) { |
| 6195 | __ cmpl(temp, cls.AsRegister<CpuRegister>()); |
| 6196 | } else { |
| 6197 | DCHECK(cls.IsStackSlot()) << cls; |
| 6198 | __ cmpl(temp, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 6199 | } |
| 6200 | __ j(kNotEqual, &loop); |
| 6201 | break; |
| 6202 | } |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6203 | |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6204 | case TypeCheckKind::kClassHierarchyCheck: { |
| Roland Levillain | 8650378 | 2016-02-11 19:07:30 +0000 | [diff] [blame] | 6205 | // /* HeapReference<Class> */ temp = obj->klass_ |
| Mathieu Chartier | cdba73b | 2016-11-03 19:23:06 -0700 | [diff] [blame] | 6206 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6207 | temp_loc, |
| 6208 | obj_loc, |
| 6209 | class_offset, |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6210 | kWithoutReadBarrier); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6211 | // Walk over the class hierarchy to find a match. |
| Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6212 | NearLabel loop; |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6213 | __ Bind(&loop); |
| 6214 | if (cls.IsRegister()) { |
| 6215 | __ cmpl(temp, cls.AsRegister<CpuRegister>()); |
| 6216 | } else { |
| 6217 | DCHECK(cls.IsStackSlot()) << cls; |
| 6218 | __ cmpl(temp, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 6219 | } |
| Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6220 | __ j(kEqual, &done); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6221 | |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6222 | // /* HeapReference<Class> */ temp = temp->super_class_ |
| Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6223 | GenerateReferenceLoadOneRegister(instruction, |
| 6224 | temp_loc, |
| 6225 | super_offset, |
| 6226 | maybe_temp2_loc, |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6227 | kWithoutReadBarrier); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6228 | |
| 6229 | // If the class reference currently in `temp` is not null, jump |
| 6230 | // back at the beginning of the loop. |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6231 | __ testl(temp, temp); |
| Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 6232 | __ j(kNotZero, &loop); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6233 | // Otherwise, jump to the slow path to throw the exception. |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6234 | __ jmp(type_check_slow_path->GetEntryLabel()); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6235 | break; |
| 6236 | } |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6237 | |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6238 | case TypeCheckKind::kArrayObjectCheck: { |
| Roland Levillain | 8650378 | 2016-02-11 19:07:30 +0000 | [diff] [blame] | 6239 | // /* HeapReference<Class> */ temp = obj->klass_ |
| Mathieu Chartier | cdba73b | 2016-11-03 19:23:06 -0700 | [diff] [blame] | 6240 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6241 | temp_loc, |
| 6242 | obj_loc, |
| 6243 | class_offset, |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6244 | kWithoutReadBarrier); |
| Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6245 | // Do an exact check. |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6246 | NearLabel check_non_primitive_component_type; |
| Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6247 | if (cls.IsRegister()) { |
| 6248 | __ cmpl(temp, cls.AsRegister<CpuRegister>()); |
| 6249 | } else { |
| 6250 | DCHECK(cls.IsStackSlot()) << cls; |
| 6251 | __ cmpl(temp, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 6252 | } |
| 6253 | __ j(kEqual, &done); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6254 | |
| 6255 | // 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] | 6256 | // /* HeapReference<Class> */ temp = temp->component_type_ |
| Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6257 | GenerateReferenceLoadOneRegister(instruction, |
| 6258 | temp_loc, |
| 6259 | component_offset, |
| 6260 | maybe_temp2_loc, |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6261 | kWithoutReadBarrier); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6262 | |
| 6263 | // If the component type is not null (i.e. the object is indeed |
| 6264 | // an array), jump to label `check_non_primitive_component_type` |
| 6265 | // to further check that this component type is not a primitive |
| 6266 | // type. |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6267 | __ testl(temp, temp); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6268 | // Otherwise, jump to the slow path to throw the exception. |
| Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 6269 | __ j(kZero, type_check_slow_path->GetEntryLabel()); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6270 | __ cmpw(Address(temp, primitive_offset), Immediate(Primitive::kPrimNot)); |
| Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 6271 | __ j(kNotEqual, type_check_slow_path->GetEntryLabel()); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6272 | break; |
| 6273 | } |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6274 | |
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6275 | case TypeCheckKind::kUnresolvedCheck: { |
| Mathieu Chartier | cdba73b | 2016-11-03 19:23:06 -0700 | [diff] [blame] | 6276 | // 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] | 6277 | // |
| 6278 | // We cannot directly call the CheckCast runtime entry point |
| 6279 | // without resorting to a type checking slow path here (i.e. by |
| 6280 | // calling InvokeRuntime directly), as it would require to |
| 6281 | // assign fixed registers for the inputs of this HInstanceOf |
| 6282 | // instruction (following the runtime calling convention), which |
| 6283 | // might be cluttered by the potential first read barrier |
| 6284 | // emission at the beginning of this method. |
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6285 | __ jmp(type_check_slow_path->GetEntryLabel()); |
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6286 | break; |
| 6287 | } |
| 6288 | |
| 6289 | case TypeCheckKind::kInterfaceCheck: |
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6290 | // Fast path for the interface check. We always go slow path for heap poisoning since |
| 6291 | // unpoisoning cls would require an extra temp. |
| 6292 | if (!kPoisonHeapReferences) { |
| Mathieu Chartier | cdba73b | 2016-11-03 19:23:06 -0700 | [diff] [blame] | 6293 | // Try to avoid read barriers to improve the fast path. We can not get false positives by |
| 6294 | // doing this. |
| 6295 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 6296 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6297 | temp_loc, |
| 6298 | obj_loc, |
| 6299 | class_offset, |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6300 | kWithoutReadBarrier); |
| Mathieu Chartier | cdba73b | 2016-11-03 19:23:06 -0700 | [diff] [blame] | 6301 | |
| 6302 | // /* HeapReference<Class> */ temp = temp->iftable_ |
| 6303 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6304 | temp_loc, |
| 6305 | temp_loc, |
| 6306 | iftable_offset, |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6307 | kWithoutReadBarrier); |
| Mathieu Chartier | 6beced4 | 2016-11-15 15:51:31 -0800 | [diff] [blame] | 6308 | // Iftable is never null. |
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6309 | __ movl(maybe_temp2_loc.AsRegister<CpuRegister>(), Address(temp, array_length_offset)); |
| Mathieu Chartier | 6beced4 | 2016-11-15 15:51:31 -0800 | [diff] [blame] | 6310 | // Loop through the iftable and check if any class matches. |
| Mathieu Chartier | cdba73b | 2016-11-03 19:23:06 -0700 | [diff] [blame] | 6311 | NearLabel start_loop; |
| 6312 | __ Bind(&start_loop); |
| Mathieu Chartier | 6beced4 | 2016-11-15 15:51:31 -0800 | [diff] [blame] | 6313 | // Need to subtract first to handle the empty array case. |
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6314 | __ subl(maybe_temp2_loc.AsRegister<CpuRegister>(), Immediate(2)); |
| Mathieu Chartier | 6beced4 | 2016-11-15 15:51:31 -0800 | [diff] [blame] | 6315 | __ j(kNegative, type_check_slow_path->GetEntryLabel()); |
| 6316 | // Go to next interface if the classes do not match. |
| 6317 | __ cmpl(cls.AsRegister<CpuRegister>(), |
| 6318 | CodeGeneratorX86_64::ArrayAddress(temp, |
| 6319 | maybe_temp2_loc, |
| 6320 | TIMES_4, |
| 6321 | object_array_data_offset)); |
| 6322 | __ j(kNotEqual, &start_loop); // Return if same class. |
| 6323 | } else { |
| 6324 | __ jmp(type_check_slow_path->GetEntryLabel()); |
| Mathieu Chartier | cdba73b | 2016-11-03 19:23:06 -0700 | [diff] [blame] | 6325 | } |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6326 | break; |
| 6327 | } |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6328 | |
| Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6329 | if (done.IsLinked()) { |
| 6330 | __ Bind(&done); |
| 6331 | } |
| 6332 | |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6333 | __ Bind(type_check_slow_path->GetExitLabel()); |
| Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6334 | } |
| 6335 | |
| Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6336 | void LocationsBuilderX86_64::VisitMonitorOperation(HMonitorOperation* instruction) { |
| 6337 | LocationSummary* locations = |
| Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 6338 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
| Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6339 | InvokeRuntimeCallingConvention calling_convention; |
| 6340 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 6341 | } |
| 6342 | |
| 6343 | void InstructionCodeGeneratorX86_64::VisitMonitorOperation(HMonitorOperation* instruction) { |
| Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 6344 | codegen_->InvokeRuntime(instruction->IsEnter() ? kQuickLockObject : kQuickUnlockObject, |
| Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 6345 | instruction, |
| Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 6346 | instruction->GetDexPc()); |
| Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 6347 | if (instruction->IsEnter()) { |
| 6348 | CheckEntrypointTypes<kQuickLockObject, void, mirror::Object*>(); |
| 6349 | } else { |
| 6350 | CheckEntrypointTypes<kQuickUnlockObject, void, mirror::Object*>(); |
| 6351 | } |
| Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6352 | } |
| 6353 | |
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6354 | void LocationsBuilderX86_64::VisitAnd(HAnd* instruction) { HandleBitwiseOperation(instruction); } |
| 6355 | void LocationsBuilderX86_64::VisitOr(HOr* instruction) { HandleBitwiseOperation(instruction); } |
| 6356 | void LocationsBuilderX86_64::VisitXor(HXor* instruction) { HandleBitwiseOperation(instruction); } |
| 6357 | |
| 6358 | void LocationsBuilderX86_64::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 6359 | LocationSummary* locations = |
| 6360 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 6361 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt |
| 6362 | || instruction->GetResultType() == Primitive::kPrimLong); |
| 6363 | locations->SetInAt(0, Location::RequiresRegister()); |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 6364 | locations->SetInAt(1, Location::Any()); |
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6365 | locations->SetOut(Location::SameAsFirstInput()); |
| 6366 | } |
| 6367 | |
| 6368 | void InstructionCodeGeneratorX86_64::VisitAnd(HAnd* instruction) { |
| 6369 | HandleBitwiseOperation(instruction); |
| 6370 | } |
| 6371 | |
| 6372 | void InstructionCodeGeneratorX86_64::VisitOr(HOr* instruction) { |
| 6373 | HandleBitwiseOperation(instruction); |
| 6374 | } |
| 6375 | |
| 6376 | void InstructionCodeGeneratorX86_64::VisitXor(HXor* instruction) { |
| 6377 | HandleBitwiseOperation(instruction); |
| 6378 | } |
| 6379 | |
| 6380 | void InstructionCodeGeneratorX86_64::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 6381 | LocationSummary* locations = instruction->GetLocations(); |
| 6382 | Location first = locations->InAt(0); |
| 6383 | Location second = locations->InAt(1); |
| 6384 | DCHECK(first.Equals(locations->Out())); |
| 6385 | |
| 6386 | if (instruction->GetResultType() == Primitive::kPrimInt) { |
| 6387 | if (second.IsRegister()) { |
| 6388 | if (instruction->IsAnd()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6389 | __ andl(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6390 | } else if (instruction->IsOr()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6391 | __ orl(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6392 | } else { |
| 6393 | DCHECK(instruction->IsXor()); |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6394 | __ xorl(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6395 | } |
| 6396 | } else if (second.IsConstant()) { |
| 6397 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue()); |
| 6398 | if (instruction->IsAnd()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6399 | __ andl(first.AsRegister<CpuRegister>(), imm); |
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6400 | } else if (instruction->IsOr()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6401 | __ orl(first.AsRegister<CpuRegister>(), imm); |
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6402 | } else { |
| 6403 | DCHECK(instruction->IsXor()); |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6404 | __ xorl(first.AsRegister<CpuRegister>(), imm); |
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6405 | } |
| 6406 | } else { |
| 6407 | Address address(CpuRegister(RSP), second.GetStackIndex()); |
| 6408 | if (instruction->IsAnd()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6409 | __ andl(first.AsRegister<CpuRegister>(), address); |
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6410 | } else if (instruction->IsOr()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6411 | __ orl(first.AsRegister<CpuRegister>(), address); |
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6412 | } else { |
| 6413 | DCHECK(instruction->IsXor()); |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6414 | __ xorl(first.AsRegister<CpuRegister>(), address); |
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6415 | } |
| 6416 | } |
| 6417 | } else { |
| 6418 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong); |
| Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6419 | CpuRegister first_reg = first.AsRegister<CpuRegister>(); |
| 6420 | bool second_is_constant = false; |
| 6421 | int64_t value = 0; |
| 6422 | if (second.IsConstant()) { |
| 6423 | second_is_constant = true; |
| 6424 | value = second.GetConstant()->AsLongConstant()->GetValue(); |
| Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6425 | } |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 6426 | bool is_int32_value = IsInt<32>(value); |
| Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6427 | |
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6428 | if (instruction->IsAnd()) { |
| 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 | __ andq(first_reg, Immediate(static_cast<int32_t>(value))); |
| 6432 | } else { |
| 6433 | __ andq(first_reg, codegen_->LiteralInt64Address(value)); |
| 6434 | } |
| 6435 | } else if (second.IsDoubleStackSlot()) { |
| 6436 | __ andq(first_reg, Address(CpuRegister(RSP), second.GetStackIndex())); |
| Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6437 | } else { |
| 6438 | __ andq(first_reg, second.AsRegister<CpuRegister>()); |
| 6439 | } |
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6440 | } else if (instruction->IsOr()) { |
| Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6441 | if (second_is_constant) { |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 6442 | if (is_int32_value) { |
| 6443 | __ orq(first_reg, Immediate(static_cast<int32_t>(value))); |
| 6444 | } else { |
| 6445 | __ orq(first_reg, codegen_->LiteralInt64Address(value)); |
| 6446 | } |
| 6447 | } else if (second.IsDoubleStackSlot()) { |
| 6448 | __ orq(first_reg, Address(CpuRegister(RSP), second.GetStackIndex())); |
| Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6449 | } else { |
| 6450 | __ orq(first_reg, second.AsRegister<CpuRegister>()); |
| 6451 | } |
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6452 | } else { |
| 6453 | DCHECK(instruction->IsXor()); |
| Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6454 | if (second_is_constant) { |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 6455 | if (is_int32_value) { |
| 6456 | __ xorq(first_reg, Immediate(static_cast<int32_t>(value))); |
| 6457 | } else { |
| 6458 | __ xorq(first_reg, codegen_->LiteralInt64Address(value)); |
| 6459 | } |
| 6460 | } else if (second.IsDoubleStackSlot()) { |
| 6461 | __ xorq(first_reg, Address(CpuRegister(RSP), second.GetStackIndex())); |
| Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6462 | } else { |
| 6463 | __ xorq(first_reg, second.AsRegister<CpuRegister>()); |
| 6464 | } |
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6465 | } |
| 6466 | } |
| 6467 | } |
| 6468 | |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6469 | void InstructionCodeGeneratorX86_64::GenerateReferenceLoadOneRegister( |
| 6470 | HInstruction* instruction, |
| 6471 | Location out, |
| 6472 | uint32_t offset, |
| 6473 | Location maybe_temp, |
| 6474 | ReadBarrierOption read_barrier_option) { |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6475 | CpuRegister out_reg = out.AsRegister<CpuRegister>(); |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6476 | if (read_barrier_option == kWithReadBarrier) { |
| Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6477 | CHECK(kEmitCompilerReadBarrier); |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6478 | if (kUseBakerReadBarrier) { |
| 6479 | // Load with fast path based Baker's read barrier. |
| 6480 | // /* HeapReference<Object> */ out = *(out + offset) |
| 6481 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
| Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 6482 | instruction, out, out_reg, offset, /* needs_null_check */ false); |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6483 | } else { |
| 6484 | // Load with slow path based read barrier. |
| Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6485 | // Save the value of `out` into `maybe_temp` before overwriting it |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6486 | // in the following move operation, as we will need it for the |
| 6487 | // read barrier below. |
| Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 6488 | DCHECK(maybe_temp.IsRegister()) << maybe_temp; |
| Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6489 | __ movl(maybe_temp.AsRegister<CpuRegister>(), out_reg); |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6490 | // /* HeapReference<Object> */ out = *(out + offset) |
| 6491 | __ movl(out_reg, Address(out_reg, offset)); |
| Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6492 | codegen_->GenerateReadBarrierSlow(instruction, out, out, maybe_temp, offset); |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6493 | } |
| 6494 | } else { |
| 6495 | // Plain load with no read barrier. |
| 6496 | // /* HeapReference<Object> */ out = *(out + offset) |
| 6497 | __ movl(out_reg, Address(out_reg, offset)); |
| 6498 | __ MaybeUnpoisonHeapReference(out_reg); |
| 6499 | } |
| 6500 | } |
| 6501 | |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6502 | void InstructionCodeGeneratorX86_64::GenerateReferenceLoadTwoRegisters( |
| 6503 | HInstruction* instruction, |
| 6504 | Location out, |
| 6505 | Location obj, |
| 6506 | uint32_t offset, |
| 6507 | ReadBarrierOption read_barrier_option) { |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6508 | CpuRegister out_reg = out.AsRegister<CpuRegister>(); |
| 6509 | CpuRegister obj_reg = obj.AsRegister<CpuRegister>(); |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6510 | if (read_barrier_option == kWithReadBarrier) { |
| Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6511 | CHECK(kEmitCompilerReadBarrier); |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6512 | if (kUseBakerReadBarrier) { |
| 6513 | // Load with fast path based Baker's read barrier. |
| 6514 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 6515 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
| Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 6516 | instruction, out, obj_reg, offset, /* needs_null_check */ false); |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6517 | } else { |
| 6518 | // Load with slow path based read barrier. |
| 6519 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 6520 | __ movl(out_reg, Address(obj_reg, offset)); |
| 6521 | codegen_->GenerateReadBarrierSlow(instruction, out, out, obj, offset); |
| 6522 | } |
| 6523 | } else { |
| 6524 | // Plain load with no read barrier. |
| 6525 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 6526 | __ movl(out_reg, Address(obj_reg, offset)); |
| 6527 | __ MaybeUnpoisonHeapReference(out_reg); |
| 6528 | } |
| 6529 | } |
| 6530 | |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6531 | void InstructionCodeGeneratorX86_64::GenerateGcRootFieldLoad( |
| 6532 | HInstruction* instruction, |
| 6533 | Location root, |
| 6534 | const Address& address, |
| 6535 | Label* fixup_label, |
| 6536 | ReadBarrierOption read_barrier_option) { |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6537 | CpuRegister root_reg = root.AsRegister<CpuRegister>(); |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6538 | if (read_barrier_option == kWithReadBarrier) { |
| Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 6539 | DCHECK(kEmitCompilerReadBarrier); |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6540 | if (kUseBakerReadBarrier) { |
| 6541 | // Fast path implementation of art::ReadBarrier::BarrierForRoot when |
| 6542 | // Baker's read barrier are used: |
| 6543 | // |
| Roland Levillain | d966ce7 | 2017-02-09 16:20:14 +0000 | [diff] [blame] | 6544 | // root = obj.field; |
| 6545 | // temp = Thread::Current()->pReadBarrierMarkReg ## root.reg() |
| 6546 | // if (temp != null) { |
| 6547 | // root = temp(root) |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6548 | // } |
| 6549 | |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6550 | // /* GcRoot<mirror::Object> */ root = *address |
| 6551 | __ movl(root_reg, address); |
| 6552 | if (fixup_label != nullptr) { |
| 6553 | __ Bind(fixup_label); |
| 6554 | } |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6555 | static_assert( |
| 6556 | sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(GcRoot<mirror::Object>), |
| 6557 | "art::mirror::CompressedReference<mirror::Object> and art::GcRoot<mirror::Object> " |
| 6558 | "have different sizes."); |
| 6559 | static_assert(sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(int32_t), |
| 6560 | "art::mirror::CompressedReference<mirror::Object> and int32_t " |
| 6561 | "have different sizes."); |
| 6562 | |
| Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 6563 | // Slow path marking the GC root `root`. |
| 6564 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) ReadBarrierMarkSlowPathX86_64( |
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 6565 | instruction, root, /* unpoison_ref_before_marking */ false); |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6566 | codegen_->AddSlowPath(slow_path); |
| 6567 | |
| Roland Levillain | d966ce7 | 2017-02-09 16:20:14 +0000 | [diff] [blame] | 6568 | // Test the `Thread::Current()->pReadBarrierMarkReg ## root.reg()` entrypoint. |
| 6569 | const int32_t entry_point_offset = |
| Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 6570 | Thread::ReadBarrierMarkEntryPointsOffset<kX86_64PointerSize>(root.reg()); |
| Roland Levillain | d966ce7 | 2017-02-09 16:20:14 +0000 | [diff] [blame] | 6571 | __ gs()->cmpl(Address::Absolute(entry_point_offset, /* no_rip */ true), Immediate(0)); |
| 6572 | // The entrypoint is null when the GC is not marking. |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6573 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 6574 | __ Bind(slow_path->GetExitLabel()); |
| 6575 | } else { |
| 6576 | // GC root loaded through a slow path for read barriers other |
| 6577 | // than Baker's. |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6578 | // /* GcRoot<mirror::Object>* */ root = address |
| 6579 | __ leaq(root_reg, address); |
| 6580 | if (fixup_label != nullptr) { |
| 6581 | __ Bind(fixup_label); |
| 6582 | } |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6583 | // /* mirror::Object* */ root = root->Read() |
| 6584 | codegen_->GenerateReadBarrierForRootSlow(instruction, root, root); |
| 6585 | } |
| 6586 | } else { |
| 6587 | // Plain GC root load with no read barrier. |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6588 | // /* GcRoot<mirror::Object> */ root = *address |
| 6589 | __ movl(root_reg, address); |
| 6590 | if (fixup_label != nullptr) { |
| 6591 | __ Bind(fixup_label); |
| 6592 | } |
| Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 6593 | // Note that GC roots are not affected by heap poisoning, thus we |
| 6594 | // do not have to unpoison `root_reg` here. |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6595 | } |
| 6596 | } |
| 6597 | |
| 6598 | void CodeGeneratorX86_64::GenerateFieldLoadWithBakerReadBarrier(HInstruction* instruction, |
| 6599 | Location ref, |
| 6600 | CpuRegister obj, |
| 6601 | uint32_t offset, |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6602 | bool needs_null_check) { |
| 6603 | DCHECK(kEmitCompilerReadBarrier); |
| 6604 | DCHECK(kUseBakerReadBarrier); |
| 6605 | |
| 6606 | // /* HeapReference<Object> */ ref = *(obj + offset) |
| 6607 | Address src(obj, offset); |
| Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 6608 | GenerateReferenceLoadWithBakerReadBarrier(instruction, ref, obj, src, needs_null_check); |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6609 | } |
| 6610 | |
| 6611 | void CodeGeneratorX86_64::GenerateArrayLoadWithBakerReadBarrier(HInstruction* instruction, |
| 6612 | Location ref, |
| 6613 | CpuRegister obj, |
| 6614 | uint32_t data_offset, |
| 6615 | Location index, |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6616 | bool needs_null_check) { |
| 6617 | DCHECK(kEmitCompilerReadBarrier); |
| 6618 | DCHECK(kUseBakerReadBarrier); |
| 6619 | |
| Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 6620 | static_assert( |
| 6621 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 6622 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6623 | // /* HeapReference<Object> */ ref = |
| 6624 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 6625 | Address src = CodeGeneratorX86_64::ArrayAddress(obj, index, TIMES_4, data_offset); |
| Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 6626 | GenerateReferenceLoadWithBakerReadBarrier(instruction, ref, obj, src, needs_null_check); |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6627 | } |
| 6628 | |
| 6629 | void CodeGeneratorX86_64::GenerateReferenceLoadWithBakerReadBarrier(HInstruction* instruction, |
| 6630 | Location ref, |
| 6631 | CpuRegister obj, |
| 6632 | const Address& src, |
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 6633 | bool needs_null_check, |
| 6634 | bool always_update_field, |
| 6635 | CpuRegister* temp1, |
| 6636 | CpuRegister* temp2) { |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6637 | DCHECK(kEmitCompilerReadBarrier); |
| 6638 | DCHECK(kUseBakerReadBarrier); |
| 6639 | |
| 6640 | // In slow path based read barriers, the read barrier call is |
| 6641 | // inserted after the original load. However, in fast path based |
| 6642 | // Baker's read barriers, we need to perform the load of |
| 6643 | // mirror::Object::monitor_ *before* the original reference load. |
| 6644 | // This load-load ordering is required by the read barrier. |
| 6645 | // The fast path/slow path (for Baker's algorithm) should look like: |
| 6646 | // |
| 6647 | // uint32_t rb_state = Lockword(obj->monitor_).ReadBarrierState(); |
| 6648 | // lfence; // Load fence or artificial data dependency to prevent load-load reordering |
| 6649 | // HeapReference<Object> ref = *src; // Original reference load. |
| Hiroshi Yamauchi | 12b58b2 | 2016-11-01 11:55:29 -0700 | [diff] [blame] | 6650 | // bool is_gray = (rb_state == ReadBarrier::GrayState()); |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6651 | // if (is_gray) { |
| 6652 | // ref = ReadBarrier::Mark(ref); // Performed by runtime entrypoint slow path. |
| 6653 | // } |
| 6654 | // |
| 6655 | // Note: the original implementation in ReadBarrier::Barrier is |
| 6656 | // slightly more complex as: |
| 6657 | // - it implements the load-load fence using a data dependency on |
| Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 6658 | // the high-bits of rb_state, which are expected to be all zeroes |
| 6659 | // (we use CodeGeneratorX86_64::GenerateMemoryBarrier instead |
| 6660 | // 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] | 6661 | // - it performs additional checks that we do not do here for |
| 6662 | // performance reasons. |
| 6663 | |
| 6664 | CpuRegister ref_reg = ref.AsRegister<CpuRegister>(); |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6665 | uint32_t monitor_offset = mirror::Object::MonitorOffset().Int32Value(); |
| 6666 | |
| Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 6667 | // 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] | 6668 | static_assert(ReadBarrier::WhiteState() == 0, "Expecting white to have value 0"); |
| 6669 | static_assert(ReadBarrier::GrayState() == 1, "Expecting gray to have value 1"); |
| Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 6670 | constexpr uint32_t gray_byte_position = LockWord::kReadBarrierStateShift / kBitsPerByte; |
| 6671 | constexpr uint32_t gray_bit_position = LockWord::kReadBarrierStateShift % kBitsPerByte; |
| 6672 | constexpr int32_t test_value = static_cast<int8_t>(1 << gray_bit_position); |
| 6673 | |
| Hiroshi Yamauchi | 12b58b2 | 2016-11-01 11:55:29 -0700 | [diff] [blame] | 6674 | // if (rb_state == ReadBarrier::GrayState()) |
| Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 6675 | // ref = ReadBarrier::Mark(ref); |
| 6676 | // At this point, just do the "if" and make sure that flags are preserved until the branch. |
| 6677 | __ testb(Address(obj, monitor_offset + gray_byte_position), Immediate(test_value)); |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6678 | if (needs_null_check) { |
| 6679 | MaybeRecordImplicitNullCheck(instruction); |
| 6680 | } |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6681 | |
| 6682 | // Load fence to prevent load-load reordering. |
| 6683 | // Note that this is a no-op, thanks to the x86-64 memory model. |
| 6684 | GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 6685 | |
| 6686 | // The actual reference load. |
| 6687 | // /* HeapReference<Object> */ ref = *src |
| Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 6688 | __ movl(ref_reg, src); // Flags are unaffected. |
| 6689 | |
| 6690 | // Note: Reference unpoisoning modifies the flags, so we need to delay it after the branch. |
| 6691 | // Slow path marking the object `ref` when it is gray. |
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 6692 | SlowPathCode* slow_path; |
| 6693 | if (always_update_field) { |
| 6694 | DCHECK(temp1 != nullptr); |
| 6695 | DCHECK(temp2 != nullptr); |
| 6696 | slow_path = new (GetGraph()->GetArena()) ReadBarrierMarkAndUpdateFieldSlowPathX86_64( |
| 6697 | instruction, ref, obj, src, /* unpoison_ref_before_marking */ true, *temp1, *temp2); |
| 6698 | } else { |
| 6699 | slow_path = new (GetGraph()->GetArena()) ReadBarrierMarkSlowPathX86_64( |
| 6700 | instruction, ref, /* unpoison_ref_before_marking */ true); |
| 6701 | } |
| Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 6702 | AddSlowPath(slow_path); |
| 6703 | |
| 6704 | // We have done the "if" of the gray bit check above, now branch based on the flags. |
| 6705 | __ j(kNotZero, slow_path->GetEntryLabel()); |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6706 | |
| 6707 | // Object* ref = ref_addr->AsMirrorPtr() |
| 6708 | __ MaybeUnpoisonHeapReference(ref_reg); |
| 6709 | |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6710 | __ Bind(slow_path->GetExitLabel()); |
| 6711 | } |
| 6712 | |
| 6713 | void CodeGeneratorX86_64::GenerateReadBarrierSlow(HInstruction* instruction, |
| 6714 | Location out, |
| 6715 | Location ref, |
| 6716 | Location obj, |
| 6717 | uint32_t offset, |
| 6718 | Location index) { |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6719 | DCHECK(kEmitCompilerReadBarrier); |
| 6720 | |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6721 | // Insert a slow path based read barrier *after* the reference load. |
| 6722 | // |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6723 | // If heap poisoning is enabled, the unpoisoning of the loaded |
| 6724 | // reference will be carried out by the runtime within the slow |
| 6725 | // path. |
| 6726 | // |
| 6727 | // Note that `ref` currently does not get unpoisoned (when heap |
| 6728 | // poisoning is enabled), which is alright as the `ref` argument is |
| 6729 | // not used by the artReadBarrierSlow entry point. |
| 6730 | // |
| 6731 | // TODO: Unpoison `ref` when it is used by artReadBarrierSlow. |
| 6732 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) |
| 6733 | ReadBarrierForHeapReferenceSlowPathX86_64(instruction, out, ref, obj, offset, index); |
| 6734 | AddSlowPath(slow_path); |
| 6735 | |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6736 | __ jmp(slow_path->GetEntryLabel()); |
| 6737 | __ Bind(slow_path->GetExitLabel()); |
| 6738 | } |
| 6739 | |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6740 | void CodeGeneratorX86_64::MaybeGenerateReadBarrierSlow(HInstruction* instruction, |
| 6741 | Location out, |
| 6742 | Location ref, |
| 6743 | Location obj, |
| 6744 | uint32_t offset, |
| 6745 | Location index) { |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6746 | if (kEmitCompilerReadBarrier) { |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6747 | // Baker's read barriers shall be handled by the fast path |
| 6748 | // (CodeGeneratorX86_64::GenerateReferenceLoadWithBakerReadBarrier). |
| 6749 | DCHECK(!kUseBakerReadBarrier); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6750 | // If heap poisoning is enabled, unpoisoning will be taken care of |
| 6751 | // by the runtime within the slow path. |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6752 | GenerateReadBarrierSlow(instruction, out, ref, obj, offset, index); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6753 | } else if (kPoisonHeapReferences) { |
| 6754 | __ UnpoisonHeapReference(out.AsRegister<CpuRegister>()); |
| 6755 | } |
| 6756 | } |
| 6757 | |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6758 | void CodeGeneratorX86_64::GenerateReadBarrierForRootSlow(HInstruction* instruction, |
| 6759 | Location out, |
| 6760 | Location root) { |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6761 | DCHECK(kEmitCompilerReadBarrier); |
| 6762 | |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6763 | // Insert a slow path based read barrier *after* the GC root load. |
| 6764 | // |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6765 | // Note that GC roots are not affected by heap poisoning, so we do |
| 6766 | // not need to do anything special for this here. |
| 6767 | SlowPathCode* slow_path = |
| 6768 | new (GetGraph()->GetArena()) ReadBarrierForRootSlowPathX86_64(instruction, out, root); |
| 6769 | AddSlowPath(slow_path); |
| 6770 | |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6771 | __ jmp(slow_path->GetEntryLabel()); |
| 6772 | __ Bind(slow_path->GetExitLabel()); |
| 6773 | } |
| 6774 | |
| Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 6775 | void LocationsBuilderX86_64::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
| Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6776 | // Nothing to do, this should be removed during prepare for register allocator. |
| Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6777 | LOG(FATAL) << "Unreachable"; |
| 6778 | } |
| 6779 | |
| Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 6780 | void InstructionCodeGeneratorX86_64::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
| Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6781 | // Nothing to do, this should be removed during prepare for register allocator. |
| Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6782 | LOG(FATAL) << "Unreachable"; |
| 6783 | } |
| 6784 | |
| Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6785 | // Simple implementation of packed switch - generate cascaded compare/jumps. |
| 6786 | void LocationsBuilderX86_64::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 6787 | LocationSummary* locations = |
| 6788 | new (GetGraph()->GetArena()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
| 6789 | locations->SetInAt(0, Location::RequiresRegister()); |
| Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 6790 | locations->AddTemp(Location::RequiresRegister()); |
| 6791 | locations->AddTemp(Location::RequiresRegister()); |
| Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6792 | } |
| 6793 | |
| 6794 | void InstructionCodeGeneratorX86_64::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 6795 | int32_t lower_bound = switch_instr->GetStartValue(); |
| Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 6796 | uint32_t num_entries = switch_instr->GetNumEntries(); |
| Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6797 | LocationSummary* locations = switch_instr->GetLocations(); |
| Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 6798 | CpuRegister value_reg_in = locations->InAt(0).AsRegister<CpuRegister>(); |
| 6799 | CpuRegister temp_reg = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 6800 | CpuRegister base_reg = locations->GetTemp(1).AsRegister<CpuRegister>(); |
| Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 6801 | HBasicBlock* default_block = switch_instr->GetDefaultBlock(); |
| 6802 | |
| 6803 | // Should we generate smaller inline compare/jumps? |
| 6804 | if (num_entries <= kPackedSwitchJumpTableThreshold) { |
| 6805 | // Figure out the correct compare values and jump conditions. |
| 6806 | // Handle the first compare/branch as a special case because it might |
| 6807 | // jump to the default case. |
| 6808 | DCHECK_GT(num_entries, 2u); |
| 6809 | Condition first_condition; |
| 6810 | uint32_t index; |
| 6811 | const ArenaVector<HBasicBlock*>& successors = switch_instr->GetBlock()->GetSuccessors(); |
| 6812 | if (lower_bound != 0) { |
| 6813 | first_condition = kLess; |
| 6814 | __ cmpl(value_reg_in, Immediate(lower_bound)); |
| 6815 | __ j(first_condition, codegen_->GetLabelOf(default_block)); |
| 6816 | __ j(kEqual, codegen_->GetLabelOf(successors[0])); |
| 6817 | |
| 6818 | index = 1; |
| 6819 | } else { |
| 6820 | // Handle all the compare/jumps below. |
| 6821 | first_condition = kBelow; |
| 6822 | index = 0; |
| 6823 | } |
| 6824 | |
| 6825 | // Handle the rest of the compare/jumps. |
| 6826 | for (; index + 1 < num_entries; index += 2) { |
| 6827 | int32_t compare_to_value = lower_bound + index + 1; |
| 6828 | __ cmpl(value_reg_in, Immediate(compare_to_value)); |
| 6829 | // Jump to successors[index] if value < case_value[index]. |
| 6830 | __ j(first_condition, codegen_->GetLabelOf(successors[index])); |
| 6831 | // Jump to successors[index + 1] if value == case_value[index + 1]. |
| 6832 | __ j(kEqual, codegen_->GetLabelOf(successors[index + 1])); |
| 6833 | } |
| 6834 | |
| 6835 | if (index != num_entries) { |
| 6836 | // There are an odd number of entries. Handle the last one. |
| 6837 | DCHECK_EQ(index + 1, num_entries); |
| Nicolas Geoffray | 6ce0173 | 2015-12-30 14:10:13 +0000 | [diff] [blame] | 6838 | __ cmpl(value_reg_in, Immediate(static_cast<int32_t>(lower_bound + index))); |
| Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 6839 | __ j(kEqual, codegen_->GetLabelOf(successors[index])); |
| 6840 | } |
| 6841 | |
| 6842 | // And the default for any other value. |
| 6843 | if (!codegen_->GoesToNextBlock(switch_instr->GetBlock(), default_block)) { |
| 6844 | __ jmp(codegen_->GetLabelOf(default_block)); |
| 6845 | } |
| 6846 | return; |
| 6847 | } |
| Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 6848 | |
| 6849 | // Remove the bias, if needed. |
| 6850 | Register value_reg_out = value_reg_in.AsRegister(); |
| 6851 | if (lower_bound != 0) { |
| 6852 | __ leal(temp_reg, Address(value_reg_in, -lower_bound)); |
| 6853 | value_reg_out = temp_reg.AsRegister(); |
| 6854 | } |
| 6855 | CpuRegister value_reg(value_reg_out); |
| 6856 | |
| 6857 | // Is the value in range? |
| Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 6858 | __ cmpl(value_reg, Immediate(num_entries - 1)); |
| 6859 | __ j(kAbove, codegen_->GetLabelOf(default_block)); |
| Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6860 | |
| Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 6861 | // We are in the range of the table. |
| 6862 | // Load the address of the jump table in the constant area. |
| 6863 | __ leaq(base_reg, codegen_->LiteralCaseTable(switch_instr)); |
| Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6864 | |
| Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 6865 | // Load the (signed) offset from the jump table. |
| 6866 | __ movsxd(temp_reg, Address(base_reg, value_reg, TIMES_4, 0)); |
| 6867 | |
| 6868 | // Add the offset to the address of the table base. |
| 6869 | __ addq(temp_reg, base_reg); |
| 6870 | |
| 6871 | // And jump. |
| 6872 | __ jmp(temp_reg); |
| Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6873 | } |
| 6874 | |
| Aart Bik | c5d4754 | 2016-01-27 17:00:35 -0800 | [diff] [blame] | 6875 | void CodeGeneratorX86_64::Load32BitValue(CpuRegister dest, int32_t value) { |
| 6876 | if (value == 0) { |
| 6877 | __ xorl(dest, dest); |
| 6878 | } else { |
| 6879 | __ movl(dest, Immediate(value)); |
| 6880 | } |
| 6881 | } |
| 6882 | |
| Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 6883 | void CodeGeneratorX86_64::Load64BitValue(CpuRegister dest, int64_t value) { |
| 6884 | if (value == 0) { |
| Aart Bik | c5d4754 | 2016-01-27 17:00:35 -0800 | [diff] [blame] | 6885 | // Clears upper bits too. |
| Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 6886 | __ xorl(dest, dest); |
| Vladimir Marko | ed00978 | 2016-02-22 16:54:39 +0000 | [diff] [blame] | 6887 | } else if (IsUint<32>(value)) { |
| 6888 | // 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] | 6889 | __ movl(dest, Immediate(static_cast<int32_t>(value))); |
| 6890 | } else { |
| 6891 | __ movq(dest, Immediate(value)); |
| 6892 | } |
| 6893 | } |
| 6894 | |
| Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 6895 | void CodeGeneratorX86_64::Load32BitValue(XmmRegister dest, int32_t value) { |
| 6896 | if (value == 0) { |
| 6897 | __ xorps(dest, dest); |
| 6898 | } else { |
| 6899 | __ movss(dest, LiteralInt32Address(value)); |
| 6900 | } |
| 6901 | } |
| 6902 | |
| 6903 | void CodeGeneratorX86_64::Load64BitValue(XmmRegister dest, int64_t value) { |
| 6904 | if (value == 0) { |
| 6905 | __ xorpd(dest, dest); |
| 6906 | } else { |
| 6907 | __ movsd(dest, LiteralInt64Address(value)); |
| 6908 | } |
| 6909 | } |
| 6910 | |
| 6911 | void CodeGeneratorX86_64::Load32BitValue(XmmRegister dest, float value) { |
| 6912 | Load32BitValue(dest, bit_cast<int32_t, float>(value)); |
| 6913 | } |
| 6914 | |
| 6915 | void CodeGeneratorX86_64::Load64BitValue(XmmRegister dest, double value) { |
| 6916 | Load64BitValue(dest, bit_cast<int64_t, double>(value)); |
| 6917 | } |
| 6918 | |
| Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 6919 | void CodeGeneratorX86_64::Compare32BitValue(CpuRegister dest, int32_t value) { |
| 6920 | if (value == 0) { |
| 6921 | __ testl(dest, dest); |
| 6922 | } else { |
| 6923 | __ cmpl(dest, Immediate(value)); |
| 6924 | } |
| 6925 | } |
| 6926 | |
| 6927 | void CodeGeneratorX86_64::Compare64BitValue(CpuRegister dest, int64_t value) { |
| 6928 | if (IsInt<32>(value)) { |
| 6929 | if (value == 0) { |
| 6930 | __ testq(dest, dest); |
| 6931 | } else { |
| 6932 | __ cmpq(dest, Immediate(static_cast<int32_t>(value))); |
| 6933 | } |
| 6934 | } else { |
| 6935 | // Value won't fit in an int. |
| 6936 | __ cmpq(dest, LiteralInt64Address(value)); |
| 6937 | } |
| 6938 | } |
| 6939 | |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 6940 | void CodeGeneratorX86_64::GenerateIntCompare(Location lhs, Location rhs) { |
| 6941 | CpuRegister lhs_reg = lhs.AsRegister<CpuRegister>(); |
| jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 6942 | GenerateIntCompare(lhs_reg, rhs); |
| 6943 | } |
| 6944 | |
| 6945 | void CodeGeneratorX86_64::GenerateIntCompare(CpuRegister lhs, Location rhs) { |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 6946 | if (rhs.IsConstant()) { |
| 6947 | int32_t value = CodeGenerator::GetInt32ValueOf(rhs.GetConstant()); |
| jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 6948 | Compare32BitValue(lhs, value); |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 6949 | } else if (rhs.IsStackSlot()) { |
| jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 6950 | __ cmpl(lhs, Address(CpuRegister(RSP), rhs.GetStackIndex())); |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 6951 | } else { |
| jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 6952 | __ cmpl(lhs, rhs.AsRegister<CpuRegister>()); |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 6953 | } |
| 6954 | } |
| 6955 | |
| 6956 | void CodeGeneratorX86_64::GenerateLongCompare(Location lhs, Location rhs) { |
| 6957 | CpuRegister lhs_reg = lhs.AsRegister<CpuRegister>(); |
| 6958 | if (rhs.IsConstant()) { |
| 6959 | int64_t value = rhs.GetConstant()->AsLongConstant()->GetValue(); |
| 6960 | Compare64BitValue(lhs_reg, value); |
| 6961 | } else if (rhs.IsDoubleStackSlot()) { |
| 6962 | __ cmpq(lhs_reg, Address(CpuRegister(RSP), rhs.GetStackIndex())); |
| 6963 | } else { |
| 6964 | __ cmpq(lhs_reg, rhs.AsRegister<CpuRegister>()); |
| 6965 | } |
| 6966 | } |
| 6967 | |
| 6968 | Address CodeGeneratorX86_64::ArrayAddress(CpuRegister obj, |
| 6969 | Location index, |
| 6970 | ScaleFactor scale, |
| 6971 | uint32_t data_offset) { |
| 6972 | return index.IsConstant() ? |
| 6973 | Address(obj, (index.GetConstant()->AsIntConstant()->GetValue() << scale) + data_offset) : |
| 6974 | Address(obj, index.AsRegister<CpuRegister>(), scale, data_offset); |
| 6975 | } |
| 6976 | |
| Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 6977 | void CodeGeneratorX86_64::Store64BitValueToStack(Location dest, int64_t value) { |
| 6978 | DCHECK(dest.IsDoubleStackSlot()); |
| 6979 | if (IsInt<32>(value)) { |
| 6980 | // Can move directly as an int32 constant. |
| 6981 | __ movq(Address(CpuRegister(RSP), dest.GetStackIndex()), |
| 6982 | Immediate(static_cast<int32_t>(value))); |
| 6983 | } else { |
| 6984 | Load64BitValue(CpuRegister(TMP), value); |
| 6985 | __ movq(Address(CpuRegister(RSP), dest.GetStackIndex()), CpuRegister(TMP)); |
| 6986 | } |
| 6987 | } |
| 6988 | |
| Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 6989 | /** |
| 6990 | * Class to handle late fixup of offsets into constant area. |
| 6991 | */ |
| 6992 | class RIPFixup : public AssemblerFixup, public ArenaObject<kArenaAllocCodeGenerator> { |
| 6993 | public: |
| 6994 | RIPFixup(CodeGeneratorX86_64& codegen, size_t offset) |
| 6995 | : codegen_(&codegen), offset_into_constant_area_(offset) {} |
| 6996 | |
| 6997 | protected: |
| 6998 | void SetOffset(size_t offset) { offset_into_constant_area_ = offset; } |
| 6999 | |
| 7000 | CodeGeneratorX86_64* codegen_; |
| 7001 | |
| 7002 | private: |
| 7003 | void Process(const MemoryRegion& region, int pos) OVERRIDE { |
| 7004 | // Patch the correct offset for the instruction. We use the address of the |
| 7005 | // 'next' instruction, which is 'pos' (patch the 4 bytes before). |
| 7006 | int32_t constant_offset = codegen_->ConstantAreaStart() + offset_into_constant_area_; |
| 7007 | int32_t relative_position = constant_offset - pos; |
| 7008 | |
| 7009 | // Patch in the right value. |
| 7010 | region.StoreUnaligned<int32_t>(pos - 4, relative_position); |
| 7011 | } |
| 7012 | |
| 7013 | // Location in constant area that the fixup refers to. |
| 7014 | size_t offset_into_constant_area_; |
| 7015 | }; |
| 7016 | |
| 7017 | /** |
| 7018 | t * Class to handle late fixup of offsets to a jump table that will be created in the |
| 7019 | * constant area. |
| 7020 | */ |
| 7021 | class JumpTableRIPFixup : public RIPFixup { |
| 7022 | public: |
| 7023 | JumpTableRIPFixup(CodeGeneratorX86_64& codegen, HPackedSwitch* switch_instr) |
| 7024 | : RIPFixup(codegen, -1), switch_instr_(switch_instr) {} |
| 7025 | |
| 7026 | void CreateJumpTable() { |
| 7027 | X86_64Assembler* assembler = codegen_->GetAssembler(); |
| 7028 | |
| 7029 | // Ensure that the reference to the jump table has the correct offset. |
| 7030 | const int32_t offset_in_constant_table = assembler->ConstantAreaSize(); |
| 7031 | SetOffset(offset_in_constant_table); |
| 7032 | |
| 7033 | // Compute the offset from the start of the function to this jump table. |
| 7034 | const int32_t current_table_offset = assembler->CodeSize() + offset_in_constant_table; |
| 7035 | |
| 7036 | // Populate the jump table with the correct values for the jump table. |
| 7037 | int32_t num_entries = switch_instr_->GetNumEntries(); |
| 7038 | HBasicBlock* block = switch_instr_->GetBlock(); |
| 7039 | const ArenaVector<HBasicBlock*>& successors = block->GetSuccessors(); |
| 7040 | // The value that we want is the target offset - the position of the table. |
| 7041 | for (int32_t i = 0; i < num_entries; i++) { |
| 7042 | HBasicBlock* b = successors[i]; |
| 7043 | Label* l = codegen_->GetLabelOf(b); |
| 7044 | DCHECK(l->IsBound()); |
| 7045 | int32_t offset_to_block = l->Position() - current_table_offset; |
| 7046 | assembler->AppendInt32(offset_to_block); |
| 7047 | } |
| 7048 | } |
| 7049 | |
| 7050 | private: |
| 7051 | const HPackedSwitch* switch_instr_; |
| 7052 | }; |
| 7053 | |
| Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 7054 | void CodeGeneratorX86_64::Finalize(CodeAllocator* allocator) { |
| 7055 | // Generate the constant area if needed. |
| Mark Mendell | 39dcf55 | 2015-04-09 20:42:42 -0400 | [diff] [blame] | 7056 | X86_64Assembler* assembler = GetAssembler(); |
| Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 7057 | if (!assembler->IsConstantAreaEmpty() || !fixups_to_jump_tables_.empty()) { |
| 7058 | // 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] | 7059 | assembler->Align(4, 0); |
| 7060 | constant_area_start_ = assembler->CodeSize(); |
| Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 7061 | |
| 7062 | // Populate any jump tables. |
| Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 7063 | for (JumpTableRIPFixup* jump_table : fixups_to_jump_tables_) { |
| Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 7064 | jump_table->CreateJumpTable(); |
| 7065 | } |
| 7066 | |
| 7067 | // And now add the constant area to the generated code. |
| Mark Mendell | 39dcf55 | 2015-04-09 20:42:42 -0400 | [diff] [blame] | 7068 | assembler->AddConstantArea(); |
| Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 7069 | } |
| 7070 | |
| 7071 | // And finish up. |
| 7072 | CodeGenerator::Finalize(allocator); |
| 7073 | } |
| 7074 | |
| Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 7075 | Address CodeGeneratorX86_64::LiteralDoubleAddress(double v) { |
| 7076 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddDouble(v)); |
| 7077 | return Address::RIP(fixup); |
| 7078 | } |
| 7079 | |
| 7080 | Address CodeGeneratorX86_64::LiteralFloatAddress(float v) { |
| 7081 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddFloat(v)); |
| 7082 | return Address::RIP(fixup); |
| 7083 | } |
| 7084 | |
| 7085 | Address CodeGeneratorX86_64::LiteralInt32Address(int32_t v) { |
| 7086 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddInt32(v)); |
| 7087 | return Address::RIP(fixup); |
| 7088 | } |
| 7089 | |
| 7090 | Address CodeGeneratorX86_64::LiteralInt64Address(int64_t v) { |
| 7091 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddInt64(v)); |
| 7092 | return Address::RIP(fixup); |
| 7093 | } |
| 7094 | |
| Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 7095 | // TODO: trg as memory. |
| 7096 | void CodeGeneratorX86_64::MoveFromReturnRegister(Location trg, Primitive::Type type) { |
| 7097 | if (!trg.IsValid()) { |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 7098 | DCHECK_EQ(type, Primitive::kPrimVoid); |
| Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 7099 | return; |
| 7100 | } |
| 7101 | |
| 7102 | DCHECK_NE(type, Primitive::kPrimVoid); |
| 7103 | |
| 7104 | Location return_loc = InvokeDexCallingConventionVisitorX86_64().GetReturnLocation(type); |
| 7105 | if (trg.Equals(return_loc)) { |
| 7106 | return; |
| 7107 | } |
| 7108 | |
| 7109 | // Let the parallel move resolver take care of all of this. |
| 7110 | HParallelMove parallel_move(GetGraph()->GetArena()); |
| 7111 | parallel_move.AddMove(return_loc, trg, type, nullptr); |
| 7112 | GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 7113 | } |
| 7114 | |
| Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 7115 | Address CodeGeneratorX86_64::LiteralCaseTable(HPackedSwitch* switch_instr) { |
| 7116 | // Create a fixup to be used to create and address the jump table. |
| 7117 | JumpTableRIPFixup* table_fixup = |
| 7118 | new (GetGraph()->GetArena()) JumpTableRIPFixup(*this, switch_instr); |
| 7119 | |
| 7120 | // We have to populate the jump tables. |
| 7121 | fixups_to_jump_tables_.push_back(table_fixup); |
| 7122 | return Address::RIP(table_fixup); |
| 7123 | } |
| 7124 | |
| Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 7125 | void CodeGeneratorX86_64::MoveInt64ToAddress(const Address& addr_low, |
| 7126 | const Address& addr_high, |
| 7127 | int64_t v, |
| 7128 | HInstruction* instruction) { |
| 7129 | if (IsInt<32>(v)) { |
| 7130 | int32_t v_32 = v; |
| 7131 | __ movq(addr_low, Immediate(v_32)); |
| 7132 | MaybeRecordImplicitNullCheck(instruction); |
| 7133 | } else { |
| 7134 | // Didn't fit in a register. Do it in pieces. |
| 7135 | int32_t low_v = Low32Bits(v); |
| 7136 | int32_t high_v = High32Bits(v); |
| 7137 | __ movl(addr_low, Immediate(low_v)); |
| 7138 | MaybeRecordImplicitNullCheck(instruction); |
| 7139 | __ movl(addr_high, Immediate(high_v)); |
| 7140 | } |
| 7141 | } |
| 7142 | |
| Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 7143 | void CodeGeneratorX86_64::PatchJitRootUse(uint8_t* code, |
| 7144 | const uint8_t* roots_data, |
| 7145 | const PatchInfo<Label>& info, |
| 7146 | uint64_t index_in_table) const { |
| 7147 | uint32_t code_offset = info.label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
| 7148 | uintptr_t address = |
| 7149 | reinterpret_cast<uintptr_t>(roots_data) + index_in_table * sizeof(GcRoot<mirror::Object>); |
| 7150 | typedef __attribute__((__aligned__(1))) uint32_t unaligned_uint32_t; |
| 7151 | reinterpret_cast<unaligned_uint32_t*>(code + code_offset)[0] = |
| 7152 | dchecked_integral_cast<uint32_t>(address); |
| 7153 | } |
| 7154 | |
| Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 7155 | void CodeGeneratorX86_64::EmitJitRootPatches(uint8_t* code, const uint8_t* roots_data) { |
| 7156 | for (const PatchInfo<Label>& info : jit_string_patches_) { |
| Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 7157 | const auto it = jit_string_roots_.find( |
| Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 7158 | StringReference(&info.dex_file, dex::StringIndex(info.index))); |
| Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 7159 | DCHECK(it != jit_string_roots_.end()); |
| Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 7160 | uint64_t index_in_table = it->second; |
| 7161 | PatchJitRootUse(code, roots_data, info, index_in_table); |
| Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 7162 | } |
| 7163 | |
| 7164 | for (const PatchInfo<Label>& info : jit_class_patches_) { |
| Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 7165 | const auto it = jit_class_roots_.find( |
| Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 7166 | TypeReference(&info.dex_file, dex::TypeIndex(info.index))); |
| 7167 | DCHECK(it != jit_class_roots_.end()); |
| Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 7168 | uint64_t index_in_table = it->second; |
| 7169 | PatchJitRootUse(code, roots_data, info, index_in_table); |
| Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 7170 | } |
| 7171 | } |
| 7172 | |
| Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 7173 | #undef __ |
| 7174 | |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 7175 | } // namespace x86_64 |
| 7176 | } // namespace art |