Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2014 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #include "code_generator_x86_64.h" |
| 18 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 19 | #include "art_method.h" |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 20 | #include "code_generator_utils.h" |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 21 | #include "compiled_method.h" |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 22 | #include "entrypoints/quick/quick_entrypoints.h" |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 23 | #include "gc/accounting/card_table.h" |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 24 | #include "intrinsics.h" |
| 25 | #include "intrinsics_x86_64.h" |
Ian Rogers | 7e70b00 | 2014-10-08 11:47:24 -0700 | [diff] [blame] | 26 | #include "mirror/array-inl.h" |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 27 | #include "mirror/class-inl.h" |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 28 | #include "mirror/object_reference.h" |
| 29 | #include "thread.h" |
| 30 | #include "utils/assembler.h" |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 31 | #include "utils/stack_checks.h" |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 32 | #include "utils/x86_64/assembler_x86_64.h" |
| 33 | #include "utils/x86_64/managed_register_x86_64.h" |
| 34 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 35 | namespace art { |
| 36 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 37 | template<class MirrorType> |
| 38 | class GcRoot; |
| 39 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 40 | namespace x86_64 { |
| 41 | |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 42 | static constexpr int kCurrentMethodStackOffset = 0; |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 43 | static constexpr Register kMethodRegisterArgument = RDI; |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 44 | // The compare/jump sequence will generate about (1.5 * num_entries) instructions. A jump |
| 45 | // table version generates 7 instructions and num_entries literals. Compare/jump sequence will |
| 46 | // generates less code/data with a small num_entries. |
| 47 | static constexpr uint32_t kPackedSwitchJumpTableThreshold = 5; |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 48 | |
Nicolas Geoffray | 4597b5b | 2015-01-23 21:51:55 +0000 | [diff] [blame] | 49 | static constexpr Register kCoreCalleeSaves[] = { RBX, RBP, R12, R13, R14, R15 }; |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 50 | static constexpr FloatRegister kFpuCalleeSaves[] = { XMM12, XMM13, XMM14, XMM15 }; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 51 | |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 52 | static constexpr int kC2ConditionMask = 0x400; |
| 53 | |
Roland Levillain | 7cbd27f | 2016-08-11 23:53:33 +0100 | [diff] [blame] | 54 | // NOLINT on __ macro to suppress wrong warning/fix (misc-macro-parentheses) from clang-tidy. |
| 55 | #define __ down_cast<X86_64Assembler*>(codegen->GetAssembler())-> // NOLINT |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 56 | #define QUICK_ENTRY_POINT(x) QUICK_ENTRYPOINT_OFFSET(kX86_64PointerSize, x).Int32Value() |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 57 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 58 | class NullCheckSlowPathX86_64 : public SlowPathCode { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 59 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 60 | explicit NullCheckSlowPathX86_64(HNullCheck* instruction) : SlowPathCode(instruction) {} |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 61 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 62 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 63 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 64 | __ Bind(GetEntryLabel()); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 65 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 66 | // Live registers will be restored in the catch block if caught. |
| 67 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 68 | } |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 69 | x86_64_codegen->InvokeRuntime(kQuickThrowNullPointer, |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 70 | instruction_, |
| 71 | instruction_->GetDexPc(), |
| 72 | this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 73 | CheckEntrypointTypes<kQuickThrowNullPointer, void, void>(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 74 | } |
| 75 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 76 | bool IsFatal() const OVERRIDE { return true; } |
| 77 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 78 | const char* GetDescription() const OVERRIDE { return "NullCheckSlowPathX86_64"; } |
| 79 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 80 | private: |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 81 | DISALLOW_COPY_AND_ASSIGN(NullCheckSlowPathX86_64); |
| 82 | }; |
| 83 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 84 | class DivZeroCheckSlowPathX86_64 : public SlowPathCode { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 85 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 86 | explicit DivZeroCheckSlowPathX86_64(HDivZeroCheck* instruction) : SlowPathCode(instruction) {} |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 87 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 88 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 89 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 90 | __ Bind(GetEntryLabel()); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 91 | x86_64_codegen->InvokeRuntime(kQuickThrowDivZero, instruction_, instruction_->GetDexPc(), this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 92 | CheckEntrypointTypes<kQuickThrowDivZero, void, void>(); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 93 | } |
| 94 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 95 | bool IsFatal() const OVERRIDE { return true; } |
| 96 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 97 | const char* GetDescription() const OVERRIDE { return "DivZeroCheckSlowPathX86_64"; } |
| 98 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 99 | private: |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 100 | DISALLOW_COPY_AND_ASSIGN(DivZeroCheckSlowPathX86_64); |
| 101 | }; |
| 102 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 103 | class DivRemMinusOneSlowPathX86_64 : public SlowPathCode { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 104 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 105 | DivRemMinusOneSlowPathX86_64(HInstruction* at, Register reg, Primitive::Type type, bool is_div) |
| 106 | : SlowPathCode(at), cpu_reg_(CpuRegister(reg)), type_(type), is_div_(is_div) {} |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 107 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 108 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 109 | __ Bind(GetEntryLabel()); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 110 | if (type_ == Primitive::kPrimInt) { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 111 | if (is_div_) { |
| 112 | __ negl(cpu_reg_); |
| 113 | } else { |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 114 | __ xorl(cpu_reg_, cpu_reg_); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 115 | } |
| 116 | |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 117 | } else { |
| 118 | DCHECK_EQ(Primitive::kPrimLong, type_); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 119 | if (is_div_) { |
| 120 | __ negq(cpu_reg_); |
| 121 | } else { |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 122 | __ xorl(cpu_reg_, cpu_reg_); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 123 | } |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 124 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 125 | __ jmp(GetExitLabel()); |
| 126 | } |
| 127 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 128 | const char* GetDescription() const OVERRIDE { return "DivRemMinusOneSlowPathX86_64"; } |
| 129 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 130 | private: |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 131 | const CpuRegister cpu_reg_; |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 132 | const Primitive::Type type_; |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 133 | const bool is_div_; |
| 134 | DISALLOW_COPY_AND_ASSIGN(DivRemMinusOneSlowPathX86_64); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 135 | }; |
| 136 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 137 | class SuspendCheckSlowPathX86_64 : public SlowPathCode { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 138 | public: |
Roland Levillain | 3887c46 | 2015-08-12 18:15:42 +0100 | [diff] [blame] | 139 | SuspendCheckSlowPathX86_64(HSuspendCheck* instruction, HBasicBlock* successor) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 140 | : SlowPathCode(instruction), successor_(successor) {} |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 141 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 142 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Aart Bik | b13c65b | 2017-03-21 20:14:07 -0700 | [diff] [blame] | 143 | LocationSummary* locations = instruction_->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 144 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 145 | __ Bind(GetEntryLabel()); |
Aart Bik | b13c65b | 2017-03-21 20:14:07 -0700 | [diff] [blame] | 146 | SaveLiveRegisters(codegen, locations); // only saves full width XMM for SIMD |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 147 | x86_64_codegen->InvokeRuntime(kQuickTestSuspend, instruction_, instruction_->GetDexPc(), this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 148 | CheckEntrypointTypes<kQuickTestSuspend, void, void>(); |
Aart Bik | b13c65b | 2017-03-21 20:14:07 -0700 | [diff] [blame] | 149 | RestoreLiveRegisters(codegen, locations); // only saves full width XMM for SIMD |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 150 | if (successor_ == nullptr) { |
| 151 | __ jmp(GetReturnLabel()); |
| 152 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 153 | __ jmp(x86_64_codegen->GetLabelOf(successor_)); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 154 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 155 | } |
| 156 | |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 157 | Label* GetReturnLabel() { |
| 158 | DCHECK(successor_ == nullptr); |
| 159 | return &return_label_; |
| 160 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 161 | |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 162 | HBasicBlock* GetSuccessor() const { |
| 163 | return successor_; |
| 164 | } |
| 165 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 166 | const char* GetDescription() const OVERRIDE { return "SuspendCheckSlowPathX86_64"; } |
| 167 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 168 | private: |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 169 | HBasicBlock* const successor_; |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 170 | Label return_label_; |
| 171 | |
| 172 | DISALLOW_COPY_AND_ASSIGN(SuspendCheckSlowPathX86_64); |
| 173 | }; |
| 174 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 175 | class BoundsCheckSlowPathX86_64 : public SlowPathCode { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 176 | public: |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 177 | explicit BoundsCheckSlowPathX86_64(HBoundsCheck* instruction) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 178 | : SlowPathCode(instruction) {} |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 179 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 180 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 181 | LocationSummary* locations = instruction_->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 182 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 183 | __ Bind(GetEntryLabel()); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 184 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 185 | // Live registers will be restored in the catch block if caught. |
| 186 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 187 | } |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 188 | // Are we using an array length from memory? |
| 189 | HInstruction* array_length = instruction_->InputAt(1); |
| 190 | Location length_loc = locations->InAt(1); |
| 191 | InvokeRuntimeCallingConvention calling_convention; |
| 192 | if (array_length->IsArrayLength() && array_length->IsEmittedAtUseSite()) { |
| 193 | // Load the array length into our temporary. |
| 194 | uint32_t len_offset = CodeGenerator::GetArrayLengthOffset(array_length->AsArrayLength()); |
| 195 | Location array_loc = array_length->GetLocations()->InAt(0); |
| 196 | Address array_len(array_loc.AsRegister<CpuRegister>(), len_offset); |
| 197 | length_loc = Location::RegisterLocation(calling_convention.GetRegisterAt(1)); |
| 198 | // Check for conflicts with index. |
| 199 | if (length_loc.Equals(locations->InAt(0))) { |
| 200 | // We know we aren't using parameter 2. |
| 201 | length_loc = Location::RegisterLocation(calling_convention.GetRegisterAt(2)); |
| 202 | } |
| 203 | __ movl(length_loc.AsRegister<CpuRegister>(), array_len); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 204 | if (mirror::kUseStringCompression) { |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 205 | __ shrl(length_loc.AsRegister<CpuRegister>(), Immediate(1)); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 206 | } |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 207 | } |
| 208 | |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 209 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 210 | // move resolver. |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 211 | codegen->EmitParallelMoves( |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 212 | locations->InAt(0), |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 213 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 214 | Primitive::kPrimInt, |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 215 | length_loc, |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 216 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 217 | Primitive::kPrimInt); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 218 | QuickEntrypointEnum entrypoint = instruction_->AsBoundsCheck()->IsStringCharAt() |
| 219 | ? kQuickThrowStringBounds |
| 220 | : kQuickThrowArrayBounds; |
| 221 | x86_64_codegen->InvokeRuntime(entrypoint, instruction_, instruction_->GetDexPc(), this); |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 222 | CheckEntrypointTypes<kQuickThrowStringBounds, void, int32_t, int32_t>(); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 223 | CheckEntrypointTypes<kQuickThrowArrayBounds, void, int32_t, int32_t>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 224 | } |
| 225 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 226 | bool IsFatal() const OVERRIDE { return true; } |
| 227 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 228 | const char* GetDescription() const OVERRIDE { return "BoundsCheckSlowPathX86_64"; } |
| 229 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 230 | private: |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 231 | DISALLOW_COPY_AND_ASSIGN(BoundsCheckSlowPathX86_64); |
| 232 | }; |
| 233 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 234 | class LoadClassSlowPathX86_64 : public SlowPathCode { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 235 | public: |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 236 | LoadClassSlowPathX86_64(HLoadClass* cls, |
| 237 | HInstruction* at, |
| 238 | uint32_t dex_pc, |
| 239 | bool do_clinit) |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 240 | : SlowPathCode(at), cls_(cls), dex_pc_(dex_pc), do_clinit_(do_clinit) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 241 | DCHECK(at->IsLoadClass() || at->IsClinitCheck()); |
| 242 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 243 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 244 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 245 | LocationSummary* locations = instruction_->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 246 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 247 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 248 | |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 249 | SaveLiveRegisters(codegen, locations); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 250 | |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 251 | // Custom calling convention: RAX serves as both input and output. |
| 252 | __ movl(CpuRegister(RAX), Immediate(cls_->GetTypeIndex().index_)); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 253 | x86_64_codegen->InvokeRuntime(do_clinit_ ? kQuickInitializeStaticStorage : kQuickInitializeType, |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 254 | instruction_, |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 255 | dex_pc_, |
| 256 | this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 257 | if (do_clinit_) { |
| 258 | CheckEntrypointTypes<kQuickInitializeStaticStorage, void*, uint32_t>(); |
| 259 | } else { |
| 260 | CheckEntrypointTypes<kQuickInitializeType, void*, uint32_t>(); |
| 261 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 262 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 263 | Location out = locations->Out(); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 264 | // Move the class to the desired location. |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 265 | if (out.IsValid()) { |
| 266 | DCHECK(out.IsRegister() && !locations->GetLiveRegisters()->ContainsCoreRegister(out.reg())); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 267 | x86_64_codegen->Move(out, Location::RegisterLocation(RAX)); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 268 | } |
| 269 | |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 270 | RestoreLiveRegisters(codegen, locations); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 271 | // For HLoadClass/kBssEntry, store the resolved Class to the BSS entry. |
| 272 | DCHECK_EQ(instruction_->IsLoadClass(), cls_ == instruction_); |
| 273 | if (cls_ == instruction_ && cls_->GetLoadKind() == HLoadClass::LoadKind::kBssEntry) { |
| 274 | DCHECK(out.IsValid()); |
| 275 | __ movl(Address::Absolute(CodeGeneratorX86_64::kDummy32BitOffset, /* no_rip */ false), |
| 276 | locations->Out().AsRegister<CpuRegister>()); |
| 277 | Label* fixup_label = x86_64_codegen->NewTypeBssEntryPatch(cls_); |
| 278 | __ Bind(fixup_label); |
| 279 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 280 | __ jmp(GetExitLabel()); |
| 281 | } |
| 282 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 283 | const char* GetDescription() const OVERRIDE { return "LoadClassSlowPathX86_64"; } |
| 284 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 285 | private: |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 286 | // The class this slow path will load. |
| 287 | HLoadClass* const cls_; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 288 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 289 | // The dex PC of `at_`. |
| 290 | const uint32_t dex_pc_; |
| 291 | |
| 292 | // Whether to initialize the class. |
| 293 | const bool do_clinit_; |
| 294 | |
| 295 | DISALLOW_COPY_AND_ASSIGN(LoadClassSlowPathX86_64); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 296 | }; |
| 297 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 298 | class LoadStringSlowPathX86_64 : public SlowPathCode { |
| 299 | public: |
| 300 | explicit LoadStringSlowPathX86_64(HLoadString* instruction) : SlowPathCode(instruction) {} |
| 301 | |
| 302 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 303 | LocationSummary* locations = instruction_->GetLocations(); |
| 304 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
| 305 | |
| 306 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
| 307 | __ Bind(GetEntryLabel()); |
| 308 | SaveLiveRegisters(codegen, locations); |
| 309 | |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 310 | const dex::StringIndex string_index = instruction_->AsLoadString()->GetStringIndex(); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 311 | // Custom calling convention: RAX serves as both input and output. |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 312 | __ movl(CpuRegister(RAX), Immediate(string_index.index_)); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 313 | x86_64_codegen->InvokeRuntime(kQuickResolveString, |
| 314 | instruction_, |
| 315 | instruction_->GetDexPc(), |
| 316 | this); |
| 317 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
| 318 | x86_64_codegen->Move(locations->Out(), Location::RegisterLocation(RAX)); |
| 319 | RestoreLiveRegisters(codegen, locations); |
| 320 | |
| 321 | // Store the resolved String to the BSS entry. |
| 322 | __ movl(Address::Absolute(CodeGeneratorX86_64::kDummy32BitOffset, /* no_rip */ false), |
| 323 | locations->Out().AsRegister<CpuRegister>()); |
| 324 | Label* fixup_label = x86_64_codegen->NewStringBssEntryPatch(instruction_->AsLoadString()); |
| 325 | __ Bind(fixup_label); |
| 326 | |
| 327 | __ jmp(GetExitLabel()); |
| 328 | } |
| 329 | |
| 330 | const char* GetDescription() const OVERRIDE { return "LoadStringSlowPathX86_64"; } |
| 331 | |
| 332 | private: |
| 333 | DISALLOW_COPY_AND_ASSIGN(LoadStringSlowPathX86_64); |
| 334 | }; |
| 335 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 336 | class TypeCheckSlowPathX86_64 : public SlowPathCode { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 337 | public: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 338 | TypeCheckSlowPathX86_64(HInstruction* instruction, bool is_fatal) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 339 | : SlowPathCode(instruction), is_fatal_(is_fatal) {} |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 340 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 341 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 342 | LocationSummary* locations = instruction_->GetLocations(); |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 343 | uint32_t dex_pc = instruction_->GetDexPc(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 344 | DCHECK(instruction_->IsCheckCast() |
| 345 | || !locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 346 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 347 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 348 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 349 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 350 | if (!is_fatal_) { |
| 351 | SaveLiveRegisters(codegen, locations); |
| 352 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 353 | |
| 354 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 355 | // move resolver. |
| 356 | InvokeRuntimeCallingConvention calling_convention; |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 357 | codegen->EmitParallelMoves(locations->InAt(0), |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 358 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| 359 | Primitive::kPrimNot, |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 360 | locations->InAt(1), |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 361 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 362 | Primitive::kPrimNot); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 363 | if (instruction_->IsInstanceOf()) { |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 364 | x86_64_codegen->InvokeRuntime(kQuickInstanceofNonTrivial, instruction_, dex_pc, this); |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 365 | CheckEntrypointTypes<kQuickInstanceofNonTrivial, size_t, mirror::Object*, mirror::Class*>(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 366 | } else { |
| 367 | DCHECK(instruction_->IsCheckCast()); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 368 | x86_64_codegen->InvokeRuntime(kQuickCheckInstanceOf, instruction_, dex_pc, this); |
| 369 | CheckEntrypointTypes<kQuickCheckInstanceOf, void, mirror::Object*, mirror::Class*>(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 370 | } |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 371 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 372 | if (!is_fatal_) { |
| 373 | if (instruction_->IsInstanceOf()) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 374 | x86_64_codegen->Move(locations->Out(), Location::RegisterLocation(RAX)); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 375 | } |
Nicolas Geoffray | 7537437 | 2015-09-17 17:12:19 +0000 | [diff] [blame] | 376 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 377 | RestoreLiveRegisters(codegen, locations); |
| 378 | __ jmp(GetExitLabel()); |
| 379 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 380 | } |
| 381 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 382 | const char* GetDescription() const OVERRIDE { return "TypeCheckSlowPathX86_64"; } |
| 383 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 384 | bool IsFatal() const OVERRIDE { return is_fatal_; } |
| 385 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 386 | private: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 387 | const bool is_fatal_; |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 388 | |
| 389 | DISALLOW_COPY_AND_ASSIGN(TypeCheckSlowPathX86_64); |
| 390 | }; |
| 391 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 392 | class DeoptimizationSlowPathX86_64 : public SlowPathCode { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 393 | public: |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 394 | explicit DeoptimizationSlowPathX86_64(HDeoptimize* instruction) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 395 | : SlowPathCode(instruction) {} |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 396 | |
| 397 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 398 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 399 | __ Bind(GetEntryLabel()); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 400 | x86_64_codegen->InvokeRuntime(kQuickDeoptimize, instruction_, instruction_->GetDexPc(), this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 401 | CheckEntrypointTypes<kQuickDeoptimize, void, void>(); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 402 | } |
| 403 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 404 | const char* GetDescription() const OVERRIDE { return "DeoptimizationSlowPathX86_64"; } |
| 405 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 406 | private: |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 407 | DISALLOW_COPY_AND_ASSIGN(DeoptimizationSlowPathX86_64); |
| 408 | }; |
| 409 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 410 | class ArraySetSlowPathX86_64 : public SlowPathCode { |
| 411 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 412 | explicit ArraySetSlowPathX86_64(HInstruction* instruction) : SlowPathCode(instruction) {} |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 413 | |
| 414 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 415 | LocationSummary* locations = instruction_->GetLocations(); |
| 416 | __ Bind(GetEntryLabel()); |
| 417 | SaveLiveRegisters(codegen, locations); |
| 418 | |
| 419 | InvokeRuntimeCallingConvention calling_convention; |
| 420 | HParallelMove parallel_move(codegen->GetGraph()->GetArena()); |
| 421 | parallel_move.AddMove( |
| 422 | locations->InAt(0), |
| 423 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| 424 | Primitive::kPrimNot, |
| 425 | nullptr); |
| 426 | parallel_move.AddMove( |
| 427 | locations->InAt(1), |
| 428 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 429 | Primitive::kPrimInt, |
| 430 | nullptr); |
| 431 | parallel_move.AddMove( |
| 432 | locations->InAt(2), |
| 433 | Location::RegisterLocation(calling_convention.GetRegisterAt(2)), |
| 434 | Primitive::kPrimNot, |
| 435 | nullptr); |
| 436 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 437 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 438 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 439 | x86_64_codegen->InvokeRuntime(kQuickAputObject, instruction_, instruction_->GetDexPc(), this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 440 | CheckEntrypointTypes<kQuickAputObject, void, mirror::Array*, int32_t, mirror::Object*>(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 441 | RestoreLiveRegisters(codegen, locations); |
| 442 | __ jmp(GetExitLabel()); |
| 443 | } |
| 444 | |
| 445 | const char* GetDescription() const OVERRIDE { return "ArraySetSlowPathX86_64"; } |
| 446 | |
| 447 | private: |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 448 | DISALLOW_COPY_AND_ASSIGN(ArraySetSlowPathX86_64); |
| 449 | }; |
| 450 | |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 451 | // Slow path marking an object reference `ref` during a read |
| 452 | // barrier. The field `obj.field` in the object `obj` holding this |
| 453 | // reference does not get updated by this slow path after marking (see |
| 454 | // ReadBarrierMarkAndUpdateFieldSlowPathX86_64 below for that). |
| 455 | // |
| 456 | // This means that after the execution of this slow path, `ref` will |
| 457 | // always be up-to-date, but `obj.field` may not; i.e., after the |
| 458 | // flip, `ref` will be a to-space reference, but `obj.field` will |
| 459 | // probably still be a from-space reference (unless it gets updated by |
| 460 | // another thread, or if another thread installed another object |
| 461 | // reference (different from `ref`) in `obj.field`). |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 462 | class ReadBarrierMarkSlowPathX86_64 : public SlowPathCode { |
| 463 | public: |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 464 | ReadBarrierMarkSlowPathX86_64(HInstruction* instruction, |
| 465 | Location ref, |
| 466 | bool unpoison_ref_before_marking) |
| 467 | : SlowPathCode(instruction), |
| 468 | ref_(ref), |
| 469 | unpoison_ref_before_marking_(unpoison_ref_before_marking) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 470 | DCHECK(kEmitCompilerReadBarrier); |
| 471 | } |
| 472 | |
| 473 | const char* GetDescription() const OVERRIDE { return "ReadBarrierMarkSlowPathX86_64"; } |
| 474 | |
| 475 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 476 | LocationSummary* locations = instruction_->GetLocations(); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 477 | CpuRegister ref_cpu_reg = ref_.AsRegister<CpuRegister>(); |
| 478 | Register ref_reg = ref_cpu_reg.AsRegister(); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 479 | DCHECK(locations->CanCall()); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 480 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(ref_reg)) << ref_reg; |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 481 | DCHECK(instruction_->IsInstanceFieldGet() || |
| 482 | instruction_->IsStaticFieldGet() || |
| 483 | instruction_->IsArrayGet() || |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 484 | instruction_->IsArraySet() || |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 485 | instruction_->IsLoadClass() || |
| 486 | instruction_->IsLoadString() || |
| 487 | instruction_->IsInstanceOf() || |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 488 | instruction_->IsCheckCast() || |
Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 489 | (instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified()) || |
| 490 | (instruction_->IsInvokeStaticOrDirect() && instruction_->GetLocations()->Intrinsified())) |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 491 | << "Unexpected instruction in read barrier marking slow path: " |
| 492 | << instruction_->DebugName(); |
| 493 | |
| 494 | __ Bind(GetEntryLabel()); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 495 | if (unpoison_ref_before_marking_) { |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 496 | // Object* ref = ref_addr->AsMirrorPtr() |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 497 | __ MaybeUnpoisonHeapReference(ref_cpu_reg); |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 498 | } |
Roland Levillain | 4359e61 | 2016-07-20 11:32:19 +0100 | [diff] [blame] | 499 | // No need to save live registers; it's taken care of by the |
| 500 | // entrypoint. Also, there is no need to update the stack mask, |
| 501 | // as this runtime call will not trigger a garbage collection. |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 502 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 503 | DCHECK_NE(ref_reg, RSP); |
| 504 | DCHECK(0 <= ref_reg && ref_reg < kNumberOfCpuRegisters) << ref_reg; |
Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 505 | // "Compact" slow path, saving two moves. |
| 506 | // |
| 507 | // Instead of using the standard runtime calling convention (input |
| 508 | // and output in R0): |
| 509 | // |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 510 | // RDI <- ref |
Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 511 | // RAX <- ReadBarrierMark(RDI) |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 512 | // ref <- RAX |
Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 513 | // |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 514 | // we just use rX (the register containing `ref`) as input and output |
Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 515 | // of a dedicated entrypoint: |
| 516 | // |
| 517 | // rX <- ReadBarrierMarkRegX(rX) |
| 518 | // |
| 519 | int32_t entry_point_offset = |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 520 | CodeGenerator::GetReadBarrierMarkEntryPointsOffset<kX86_64PointerSize>(ref_reg); |
Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 521 | // This runtime call does not require a stack map. |
| 522 | x86_64_codegen->InvokeRuntimeWithoutRecordingPcInfo(entry_point_offset, instruction_, this); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 523 | __ jmp(GetExitLabel()); |
| 524 | } |
| 525 | |
| 526 | private: |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 527 | // The location (register) of the marked object reference. |
| 528 | const Location ref_; |
| 529 | // Should the reference in `ref_` be unpoisoned prior to marking it? |
| 530 | const bool unpoison_ref_before_marking_; |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 531 | |
| 532 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierMarkSlowPathX86_64); |
| 533 | }; |
| 534 | |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 535 | // Slow path marking an object reference `ref` during a read barrier, |
| 536 | // and if needed, atomically updating the field `obj.field` in the |
| 537 | // object `obj` holding this reference after marking (contrary to |
| 538 | // ReadBarrierMarkSlowPathX86_64 above, which never tries to update |
| 539 | // `obj.field`). |
| 540 | // |
| 541 | // This means that after the execution of this slow path, both `ref` |
| 542 | // and `obj.field` will be up-to-date; i.e., after the flip, both will |
| 543 | // hold the same to-space reference (unless another thread installed |
| 544 | // another object reference (different from `ref`) in `obj.field`). |
| 545 | class ReadBarrierMarkAndUpdateFieldSlowPathX86_64 : public SlowPathCode { |
| 546 | public: |
| 547 | ReadBarrierMarkAndUpdateFieldSlowPathX86_64(HInstruction* instruction, |
| 548 | Location ref, |
| 549 | CpuRegister obj, |
| 550 | const Address& field_addr, |
| 551 | bool unpoison_ref_before_marking, |
| 552 | CpuRegister temp1, |
| 553 | CpuRegister temp2) |
| 554 | : SlowPathCode(instruction), |
| 555 | ref_(ref), |
| 556 | obj_(obj), |
| 557 | field_addr_(field_addr), |
| 558 | unpoison_ref_before_marking_(unpoison_ref_before_marking), |
| 559 | temp1_(temp1), |
| 560 | temp2_(temp2) { |
| 561 | DCHECK(kEmitCompilerReadBarrier); |
| 562 | } |
| 563 | |
| 564 | const char* GetDescription() const OVERRIDE { |
| 565 | return "ReadBarrierMarkAndUpdateFieldSlowPathX86_64"; |
| 566 | } |
| 567 | |
| 568 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 569 | LocationSummary* locations = instruction_->GetLocations(); |
| 570 | CpuRegister ref_cpu_reg = ref_.AsRegister<CpuRegister>(); |
| 571 | Register ref_reg = ref_cpu_reg.AsRegister(); |
| 572 | DCHECK(locations->CanCall()); |
| 573 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(ref_reg)) << ref_reg; |
| 574 | // This slow path is only used by the UnsafeCASObject intrinsic. |
| 575 | DCHECK((instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified())) |
| 576 | << "Unexpected instruction in read barrier marking and field updating slow path: " |
| 577 | << instruction_->DebugName(); |
| 578 | DCHECK(instruction_->GetLocations()->Intrinsified()); |
| 579 | DCHECK_EQ(instruction_->AsInvoke()->GetIntrinsic(), Intrinsics::kUnsafeCASObject); |
| 580 | |
| 581 | __ Bind(GetEntryLabel()); |
| 582 | if (unpoison_ref_before_marking_) { |
| 583 | // Object* ref = ref_addr->AsMirrorPtr() |
| 584 | __ MaybeUnpoisonHeapReference(ref_cpu_reg); |
| 585 | } |
| 586 | |
| 587 | // Save the old (unpoisoned) reference. |
| 588 | __ movl(temp1_, ref_cpu_reg); |
| 589 | |
| 590 | // No need to save live registers; it's taken care of by the |
| 591 | // entrypoint. Also, there is no need to update the stack mask, |
| 592 | // as this runtime call will not trigger a garbage collection. |
| 593 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
| 594 | DCHECK_NE(ref_reg, RSP); |
| 595 | DCHECK(0 <= ref_reg && ref_reg < kNumberOfCpuRegisters) << ref_reg; |
| 596 | // "Compact" slow path, saving two moves. |
| 597 | // |
| 598 | // Instead of using the standard runtime calling convention (input |
| 599 | // and output in R0): |
| 600 | // |
| 601 | // RDI <- ref |
| 602 | // RAX <- ReadBarrierMark(RDI) |
| 603 | // ref <- RAX |
| 604 | // |
| 605 | // we just use rX (the register containing `ref`) as input and output |
| 606 | // of a dedicated entrypoint: |
| 607 | // |
| 608 | // rX <- ReadBarrierMarkRegX(rX) |
| 609 | // |
| 610 | int32_t entry_point_offset = |
| 611 | CodeGenerator::GetReadBarrierMarkEntryPointsOffset<kX86_64PointerSize>(ref_reg); |
| 612 | // This runtime call does not require a stack map. |
| 613 | x86_64_codegen->InvokeRuntimeWithoutRecordingPcInfo(entry_point_offset, instruction_, this); |
| 614 | |
| 615 | // If the new reference is different from the old reference, |
| 616 | // update the field in the holder (`*field_addr`). |
| 617 | // |
| 618 | // Note that this field could also hold a different object, if |
| 619 | // another thread had concurrently changed it. In that case, the |
| 620 | // LOCK CMPXCHGL instruction in the compare-and-set (CAS) |
| 621 | // operation below would abort the CAS, leaving the field as-is. |
| 622 | NearLabel done; |
| 623 | __ cmpl(temp1_, ref_cpu_reg); |
| 624 | __ j(kEqual, &done); |
| 625 | |
| 626 | // Update the the holder's field atomically. This may fail if |
| 627 | // mutator updates before us, but it's OK. This is achived |
| 628 | // using a strong compare-and-set (CAS) operation with relaxed |
| 629 | // memory synchronization ordering, where the expected value is |
| 630 | // the old reference and the desired value is the new reference. |
| 631 | // This operation is implemented with a 32-bit LOCK CMPXLCHG |
| 632 | // instruction, which requires the expected value (the old |
| 633 | // reference) to be in EAX. Save RAX beforehand, and move the |
| 634 | // expected value (stored in `temp1_`) into EAX. |
| 635 | __ movq(temp2_, CpuRegister(RAX)); |
| 636 | __ movl(CpuRegister(RAX), temp1_); |
| 637 | |
| 638 | // Convenience aliases. |
| 639 | CpuRegister base = obj_; |
| 640 | CpuRegister expected = CpuRegister(RAX); |
| 641 | CpuRegister value = ref_cpu_reg; |
| 642 | |
| 643 | bool base_equals_value = (base.AsRegister() == value.AsRegister()); |
| 644 | Register value_reg = ref_reg; |
| 645 | if (kPoisonHeapReferences) { |
| 646 | if (base_equals_value) { |
| 647 | // If `base` and `value` are the same register location, move |
| 648 | // `value_reg` to a temporary register. This way, poisoning |
| 649 | // `value_reg` won't invalidate `base`. |
| 650 | value_reg = temp1_.AsRegister(); |
| 651 | __ movl(CpuRegister(value_reg), base); |
| 652 | } |
| 653 | |
| 654 | // Check that the register allocator did not assign the location |
| 655 | // of `expected` (RAX) to `value` nor to `base`, so that heap |
| 656 | // poisoning (when enabled) works as intended below. |
| 657 | // - If `value` were equal to `expected`, both references would |
| 658 | // be poisoned twice, meaning they would not be poisoned at |
| 659 | // all, as heap poisoning uses address negation. |
| 660 | // - If `base` were equal to `expected`, poisoning `expected` |
| 661 | // would invalidate `base`. |
| 662 | DCHECK_NE(value_reg, expected.AsRegister()); |
| 663 | DCHECK_NE(base.AsRegister(), expected.AsRegister()); |
| 664 | |
| 665 | __ PoisonHeapReference(expected); |
| 666 | __ PoisonHeapReference(CpuRegister(value_reg)); |
| 667 | } |
| 668 | |
| 669 | __ LockCmpxchgl(field_addr_, CpuRegister(value_reg)); |
| 670 | |
| 671 | // If heap poisoning is enabled, we need to unpoison the values |
| 672 | // that were poisoned earlier. |
| 673 | if (kPoisonHeapReferences) { |
| 674 | if (base_equals_value) { |
| 675 | // `value_reg` has been moved to a temporary register, no need |
| 676 | // to unpoison it. |
| 677 | } else { |
| 678 | __ UnpoisonHeapReference(CpuRegister(value_reg)); |
| 679 | } |
| 680 | // No need to unpoison `expected` (RAX), as it is be overwritten below. |
| 681 | } |
| 682 | |
| 683 | // Restore RAX. |
| 684 | __ movq(CpuRegister(RAX), temp2_); |
| 685 | |
| 686 | __ Bind(&done); |
| 687 | __ jmp(GetExitLabel()); |
| 688 | } |
| 689 | |
| 690 | private: |
| 691 | // The location (register) of the marked object reference. |
| 692 | const Location ref_; |
| 693 | // The register containing the object holding the marked object reference field. |
| 694 | const CpuRegister obj_; |
| 695 | // The address of the marked reference field. The base of this address must be `obj_`. |
| 696 | const Address field_addr_; |
| 697 | |
| 698 | // Should the reference in `ref_` be unpoisoned prior to marking it? |
| 699 | const bool unpoison_ref_before_marking_; |
| 700 | |
| 701 | const CpuRegister temp1_; |
| 702 | const CpuRegister temp2_; |
| 703 | |
| 704 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierMarkAndUpdateFieldSlowPathX86_64); |
| 705 | }; |
| 706 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 707 | // Slow path generating a read barrier for a heap reference. |
| 708 | class ReadBarrierForHeapReferenceSlowPathX86_64 : public SlowPathCode { |
| 709 | public: |
| 710 | ReadBarrierForHeapReferenceSlowPathX86_64(HInstruction* instruction, |
| 711 | Location out, |
| 712 | Location ref, |
| 713 | Location obj, |
| 714 | uint32_t offset, |
| 715 | Location index) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 716 | : SlowPathCode(instruction), |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 717 | out_(out), |
| 718 | ref_(ref), |
| 719 | obj_(obj), |
| 720 | offset_(offset), |
| 721 | index_(index) { |
| 722 | DCHECK(kEmitCompilerReadBarrier); |
| 723 | // If `obj` is equal to `out` or `ref`, it means the initial |
| 724 | // object has been overwritten by (or after) the heap object |
| 725 | // reference load to be instrumented, e.g.: |
| 726 | // |
| 727 | // __ movl(out, Address(out, offset)); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 728 | // codegen_->GenerateReadBarrierSlow(instruction, out_loc, out_loc, out_loc, offset); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 729 | // |
| 730 | // In that case, we have lost the information about the original |
| 731 | // object, and the emitted read barrier cannot work properly. |
| 732 | DCHECK(!obj.Equals(out)) << "obj=" << obj << " out=" << out; |
| 733 | DCHECK(!obj.Equals(ref)) << "obj=" << obj << " ref=" << ref; |
| 734 | } |
| 735 | |
| 736 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 737 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
| 738 | LocationSummary* locations = instruction_->GetLocations(); |
| 739 | CpuRegister reg_out = out_.AsRegister<CpuRegister>(); |
| 740 | DCHECK(locations->CanCall()); |
| 741 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg_out.AsRegister())) << out_; |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 742 | DCHECK(instruction_->IsInstanceFieldGet() || |
| 743 | instruction_->IsStaticFieldGet() || |
| 744 | instruction_->IsArrayGet() || |
| 745 | instruction_->IsInstanceOf() || |
| 746 | instruction_->IsCheckCast() || |
Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 747 | (instruction_->IsInvokeVirtual()) && instruction_->GetLocations()->Intrinsified()) |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 748 | << "Unexpected instruction in read barrier for heap reference slow path: " |
| 749 | << instruction_->DebugName(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 750 | |
| 751 | __ Bind(GetEntryLabel()); |
| 752 | SaveLiveRegisters(codegen, locations); |
| 753 | |
| 754 | // We may have to change the index's value, but as `index_` is a |
| 755 | // constant member (like other "inputs" of this slow path), |
| 756 | // introduce a copy of it, `index`. |
| 757 | Location index = index_; |
| 758 | if (index_.IsValid()) { |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 759 | // Handle `index_` for HArrayGet and UnsafeGetObject/UnsafeGetObjectVolatile intrinsics. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 760 | if (instruction_->IsArrayGet()) { |
| 761 | // Compute real offset and store it in index_. |
| 762 | Register index_reg = index_.AsRegister<CpuRegister>().AsRegister(); |
| 763 | DCHECK(locations->GetLiveRegisters()->ContainsCoreRegister(index_reg)); |
| 764 | if (codegen->IsCoreCalleeSaveRegister(index_reg)) { |
| 765 | // We are about to change the value of `index_reg` (see the |
| 766 | // calls to art::x86_64::X86_64Assembler::shll and |
| 767 | // art::x86_64::X86_64Assembler::AddImmediate below), but it |
| 768 | // has not been saved by the previous call to |
| 769 | // art::SlowPathCode::SaveLiveRegisters, as it is a |
| 770 | // callee-save register -- |
| 771 | // art::SlowPathCode::SaveLiveRegisters does not consider |
| 772 | // callee-save registers, as it has been designed with the |
| 773 | // assumption that callee-save registers are supposed to be |
| 774 | // handled by the called function. So, as a callee-save |
| 775 | // register, `index_reg` _would_ eventually be saved onto |
| 776 | // the stack, but it would be too late: we would have |
| 777 | // changed its value earlier. Therefore, we manually save |
| 778 | // it here into another freely available register, |
| 779 | // `free_reg`, chosen of course among the caller-save |
| 780 | // registers (as a callee-save `free_reg` register would |
| 781 | // exhibit the same problem). |
| 782 | // |
| 783 | // Note we could have requested a temporary register from |
| 784 | // the register allocator instead; but we prefer not to, as |
| 785 | // this is a slow path, and we know we can find a |
| 786 | // caller-save register that is available. |
| 787 | Register free_reg = FindAvailableCallerSaveRegister(codegen).AsRegister(); |
| 788 | __ movl(CpuRegister(free_reg), CpuRegister(index_reg)); |
| 789 | index_reg = free_reg; |
| 790 | index = Location::RegisterLocation(index_reg); |
| 791 | } else { |
| 792 | // The initial register stored in `index_` has already been |
| 793 | // saved in the call to art::SlowPathCode::SaveLiveRegisters |
| 794 | // (as it is not a callee-save register), so we can freely |
| 795 | // use it. |
| 796 | } |
| 797 | // Shifting the index value contained in `index_reg` by the |
| 798 | // scale factor (2) cannot overflow in practice, as the |
| 799 | // runtime is unable to allocate object arrays with a size |
| 800 | // larger than 2^26 - 1 (that is, 2^28 - 4 bytes). |
| 801 | __ shll(CpuRegister(index_reg), Immediate(TIMES_4)); |
| 802 | static_assert( |
| 803 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 804 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 805 | __ AddImmediate(CpuRegister(index_reg), Immediate(offset_)); |
| 806 | } else { |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 807 | // In the case of the UnsafeGetObject/UnsafeGetObjectVolatile |
| 808 | // intrinsics, `index_` is not shifted by a scale factor of 2 |
| 809 | // (as in the case of ArrayGet), as it is actually an offset |
| 810 | // to an object field within an object. |
| 811 | DCHECK(instruction_->IsInvoke()) << instruction_->DebugName(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 812 | DCHECK(instruction_->GetLocations()->Intrinsified()); |
| 813 | DCHECK((instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObject) || |
| 814 | (instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObjectVolatile)) |
| 815 | << instruction_->AsInvoke()->GetIntrinsic(); |
| 816 | DCHECK_EQ(offset_, 0U); |
| 817 | DCHECK(index_.IsRegister()); |
| 818 | } |
| 819 | } |
| 820 | |
| 821 | // We're moving two or three locations to locations that could |
| 822 | // overlap, so we need a parallel move resolver. |
| 823 | InvokeRuntimeCallingConvention calling_convention; |
| 824 | HParallelMove parallel_move(codegen->GetGraph()->GetArena()); |
| 825 | parallel_move.AddMove(ref_, |
| 826 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| 827 | Primitive::kPrimNot, |
| 828 | nullptr); |
| 829 | parallel_move.AddMove(obj_, |
| 830 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 831 | Primitive::kPrimNot, |
| 832 | nullptr); |
| 833 | if (index.IsValid()) { |
| 834 | parallel_move.AddMove(index, |
| 835 | Location::RegisterLocation(calling_convention.GetRegisterAt(2)), |
| 836 | Primitive::kPrimInt, |
| 837 | nullptr); |
| 838 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 839 | } else { |
| 840 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 841 | __ movl(CpuRegister(calling_convention.GetRegisterAt(2)), Immediate(offset_)); |
| 842 | } |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 843 | x86_64_codegen->InvokeRuntime(kQuickReadBarrierSlow, |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 844 | instruction_, |
| 845 | instruction_->GetDexPc(), |
| 846 | this); |
| 847 | CheckEntrypointTypes< |
| 848 | kQuickReadBarrierSlow, mirror::Object*, mirror::Object*, mirror::Object*, uint32_t>(); |
| 849 | x86_64_codegen->Move(out_, Location::RegisterLocation(RAX)); |
| 850 | |
| 851 | RestoreLiveRegisters(codegen, locations); |
| 852 | __ jmp(GetExitLabel()); |
| 853 | } |
| 854 | |
| 855 | const char* GetDescription() const OVERRIDE { |
| 856 | return "ReadBarrierForHeapReferenceSlowPathX86_64"; |
| 857 | } |
| 858 | |
| 859 | private: |
| 860 | CpuRegister FindAvailableCallerSaveRegister(CodeGenerator* codegen) { |
| 861 | size_t ref = static_cast<int>(ref_.AsRegister<CpuRegister>().AsRegister()); |
| 862 | size_t obj = static_cast<int>(obj_.AsRegister<CpuRegister>().AsRegister()); |
| 863 | for (size_t i = 0, e = codegen->GetNumberOfCoreRegisters(); i < e; ++i) { |
| 864 | if (i != ref && i != obj && !codegen->IsCoreCalleeSaveRegister(i)) { |
| 865 | return static_cast<CpuRegister>(i); |
| 866 | } |
| 867 | } |
| 868 | // We shall never fail to find a free caller-save register, as |
| 869 | // there are more than two core caller-save registers on x86-64 |
| 870 | // (meaning it is possible to find one which is different from |
| 871 | // `ref` and `obj`). |
| 872 | DCHECK_GT(codegen->GetNumberOfCoreCallerSaveRegisters(), 2u); |
| 873 | LOG(FATAL) << "Could not find a free caller-save register"; |
| 874 | UNREACHABLE(); |
| 875 | } |
| 876 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 877 | const Location out_; |
| 878 | const Location ref_; |
| 879 | const Location obj_; |
| 880 | const uint32_t offset_; |
| 881 | // An additional location containing an index to an array. |
| 882 | // Only used for HArrayGet and the UnsafeGetObject & |
| 883 | // UnsafeGetObjectVolatile intrinsics. |
| 884 | const Location index_; |
| 885 | |
| 886 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForHeapReferenceSlowPathX86_64); |
| 887 | }; |
| 888 | |
| 889 | // Slow path generating a read barrier for a GC root. |
| 890 | class ReadBarrierForRootSlowPathX86_64 : public SlowPathCode { |
| 891 | public: |
| 892 | ReadBarrierForRootSlowPathX86_64(HInstruction* instruction, Location out, Location root) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 893 | : SlowPathCode(instruction), out_(out), root_(root) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 894 | DCHECK(kEmitCompilerReadBarrier); |
| 895 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 896 | |
| 897 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 898 | LocationSummary* locations = instruction_->GetLocations(); |
| 899 | DCHECK(locations->CanCall()); |
| 900 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(out_.reg())); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 901 | DCHECK(instruction_->IsLoadClass() || instruction_->IsLoadString()) |
| 902 | << "Unexpected instruction in read barrier for GC root slow path: " |
| 903 | << instruction_->DebugName(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 904 | |
| 905 | __ Bind(GetEntryLabel()); |
| 906 | SaveLiveRegisters(codegen, locations); |
| 907 | |
| 908 | InvokeRuntimeCallingConvention calling_convention; |
| 909 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
| 910 | x86_64_codegen->Move(Location::RegisterLocation(calling_convention.GetRegisterAt(0)), root_); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 911 | x86_64_codegen->InvokeRuntime(kQuickReadBarrierForRootSlow, |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 912 | instruction_, |
| 913 | instruction_->GetDexPc(), |
| 914 | this); |
| 915 | CheckEntrypointTypes<kQuickReadBarrierForRootSlow, mirror::Object*, GcRoot<mirror::Object>*>(); |
| 916 | x86_64_codegen->Move(out_, Location::RegisterLocation(RAX)); |
| 917 | |
| 918 | RestoreLiveRegisters(codegen, locations); |
| 919 | __ jmp(GetExitLabel()); |
| 920 | } |
| 921 | |
| 922 | const char* GetDescription() const OVERRIDE { return "ReadBarrierForRootSlowPathX86_64"; } |
| 923 | |
| 924 | private: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 925 | const Location out_; |
| 926 | const Location root_; |
| 927 | |
| 928 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForRootSlowPathX86_64); |
| 929 | }; |
| 930 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 931 | #undef __ |
Roland Levillain | 7cbd27f | 2016-08-11 23:53:33 +0100 | [diff] [blame] | 932 | // NOLINT on __ macro to suppress wrong warning/fix (misc-macro-parentheses) from clang-tidy. |
| 933 | #define __ down_cast<X86_64Assembler*>(GetAssembler())-> // NOLINT |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 934 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 935 | inline Condition X86_64IntegerCondition(IfCondition cond) { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 936 | switch (cond) { |
| 937 | case kCondEQ: return kEqual; |
| 938 | case kCondNE: return kNotEqual; |
| 939 | case kCondLT: return kLess; |
| 940 | case kCondLE: return kLessEqual; |
| 941 | case kCondGT: return kGreater; |
| 942 | case kCondGE: return kGreaterEqual; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 943 | case kCondB: return kBelow; |
| 944 | case kCondBE: return kBelowEqual; |
| 945 | case kCondA: return kAbove; |
| 946 | case kCondAE: return kAboveEqual; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 947 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 948 | LOG(FATAL) << "Unreachable"; |
| 949 | UNREACHABLE(); |
| 950 | } |
| 951 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 952 | // Maps FP condition to x86_64 name. |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 953 | inline Condition X86_64FPCondition(IfCondition cond) { |
| 954 | switch (cond) { |
| 955 | case kCondEQ: return kEqual; |
| 956 | case kCondNE: return kNotEqual; |
| 957 | case kCondLT: return kBelow; |
| 958 | case kCondLE: return kBelowEqual; |
| 959 | case kCondGT: return kAbove; |
| 960 | case kCondGE: return kAboveEqual; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 961 | default: break; // should not happen |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 962 | }; |
| 963 | LOG(FATAL) << "Unreachable"; |
| 964 | UNREACHABLE(); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 965 | } |
| 966 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 967 | HInvokeStaticOrDirect::DispatchInfo CodeGeneratorX86_64::GetSupportedInvokeStaticOrDirectDispatch( |
| 968 | const HInvokeStaticOrDirect::DispatchInfo& desired_dispatch_info, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 969 | HInvokeStaticOrDirect* invoke ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | c1a42cf | 2016-12-18 15:52:36 +0000 | [diff] [blame] | 970 | return desired_dispatch_info; |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 971 | } |
| 972 | |
Serguei Katkov | 288c7a8 | 2016-05-16 11:53:15 +0600 | [diff] [blame] | 973 | Location CodeGeneratorX86_64::GenerateCalleeMethodStaticOrDirectCall(HInvokeStaticOrDirect* invoke, |
| 974 | Location temp) { |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 975 | // All registers are assumed to be correctly set up. |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 976 | Location callee_method = temp; // For all kinds except kRecursive, callee will be in temp. |
| 977 | switch (invoke->GetMethodLoadKind()) { |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 978 | case HInvokeStaticOrDirect::MethodLoadKind::kStringInit: { |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 979 | // temp = thread->string_init_entrypoint |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 980 | uint32_t offset = |
| 981 | GetThreadOffset<kX86_64PointerSize>(invoke->GetStringInitEntryPoint()).Int32Value(); |
| 982 | __ gs()->movq(temp.AsRegister<CpuRegister>(), Address::Absolute(offset, /* no_rip */ true)); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 983 | break; |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 984 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 985 | case HInvokeStaticOrDirect::MethodLoadKind::kRecursive: |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 986 | callee_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 987 | break; |
| 988 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddress: |
Vladimir Marko | 2d73f33 | 2017-03-16 15:55:49 +0000 | [diff] [blame] | 989 | Load64BitValue(temp.AsRegister<CpuRegister>(), invoke->GetMethodAddress()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 990 | break; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 991 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCachePcRelative: { |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 992 | __ movq(temp.AsRegister<CpuRegister>(), |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 993 | Address::Absolute(kDummy32BitOffset, /* no_rip */ false)); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 994 | // Bind a new fixup label at the end of the "movl" insn. |
| 995 | uint32_t offset = invoke->GetDexCacheArrayOffset(); |
Nicolas Geoffray | 5d37c15 | 2017-01-12 13:25:19 +0000 | [diff] [blame] | 996 | __ Bind(NewPcRelativeDexCacheArrayPatch(invoke->GetDexFileForPcRelativeDexCache(), offset)); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 997 | break; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 998 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 999 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCacheViaMethod: { |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 1000 | Location current_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 1001 | Register method_reg; |
| 1002 | CpuRegister reg = temp.AsRegister<CpuRegister>(); |
| 1003 | if (current_method.IsRegister()) { |
| 1004 | method_reg = current_method.AsRegister<Register>(); |
| 1005 | } else { |
| 1006 | DCHECK(invoke->GetLocations()->Intrinsified()); |
| 1007 | DCHECK(!current_method.IsValid()); |
| 1008 | method_reg = reg.AsRegister(); |
| 1009 | __ movq(reg, Address(CpuRegister(RSP), kCurrentMethodStackOffset)); |
| 1010 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 1011 | // /* ArtMethod*[] */ temp = temp.ptr_sized_fields_->dex_cache_resolved_methods_; |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 1012 | __ movq(reg, |
| 1013 | Address(CpuRegister(method_reg), |
| 1014 | ArtMethod::DexCacheResolvedMethodsOffset(kX86_64PointerSize).SizeValue())); |
Vladimir Marko | 40ecb12 | 2016-04-06 17:33:41 +0100 | [diff] [blame] | 1015 | // temp = temp[index_in_cache]; |
| 1016 | // Note: Don't use invoke->GetTargetMethod() as it may point to a different dex file. |
| 1017 | uint32_t index_in_cache = invoke->GetDexMethodIndex(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 1018 | __ movq(reg, Address(reg, CodeGenerator::GetCachePointerOffset(index_in_cache))); |
| 1019 | break; |
Vladimir Marko | 9b688a0 | 2015-05-06 14:12:42 +0100 | [diff] [blame] | 1020 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 1021 | } |
Serguei Katkov | 288c7a8 | 2016-05-16 11:53:15 +0600 | [diff] [blame] | 1022 | return callee_method; |
| 1023 | } |
| 1024 | |
| 1025 | void CodeGeneratorX86_64::GenerateStaticOrDirectCall(HInvokeStaticOrDirect* invoke, |
| 1026 | Location temp) { |
| 1027 | // All registers are assumed to be correctly set up. |
| 1028 | Location callee_method = GenerateCalleeMethodStaticOrDirectCall(invoke, temp); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 1029 | |
| 1030 | switch (invoke->GetCodePtrLocation()) { |
| 1031 | case HInvokeStaticOrDirect::CodePtrLocation::kCallSelf: |
| 1032 | __ call(&frame_entry_label_); |
| 1033 | break; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 1034 | case HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod: |
| 1035 | // (callee_method + offset_of_quick_compiled_code)() |
| 1036 | __ call(Address(callee_method.AsRegister<CpuRegister>(), |
| 1037 | ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 1038 | kX86_64PointerSize).SizeValue())); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 1039 | break; |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 1040 | } |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 1041 | |
| 1042 | DCHECK(!IsLeafMethod()); |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 1043 | } |
| 1044 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 1045 | void CodeGeneratorX86_64::GenerateVirtualCall(HInvokeVirtual* invoke, Location temp_in) { |
| 1046 | CpuRegister temp = temp_in.AsRegister<CpuRegister>(); |
| 1047 | size_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| 1048 | invoke->GetVTableIndex(), kX86_64PointerSize).SizeValue(); |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 1049 | |
| 1050 | // Use the calling convention instead of the location of the receiver, as |
| 1051 | // intrinsics may have put the receiver in a different register. In the intrinsics |
| 1052 | // slow path, the arguments have been moved to the right place, so here we are |
| 1053 | // guaranteed that the receiver is the first register of the calling convention. |
| 1054 | InvokeDexCallingConvention calling_convention; |
| 1055 | Register receiver = calling_convention.GetRegisterAt(0); |
| 1056 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 1057 | size_t class_offset = mirror::Object::ClassOffset().SizeValue(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 1058 | // /* HeapReference<Class> */ temp = receiver->klass_ |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 1059 | __ movl(temp, Address(CpuRegister(receiver), class_offset)); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 1060 | MaybeRecordImplicitNullCheck(invoke); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 1061 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 1062 | // emit a read barrier for the previous class reference load. |
| 1063 | // However this is not required in practice, as this is an |
| 1064 | // intermediate/temporary reference and because the current |
| 1065 | // concurrent copying collector keeps the from-space memory |
| 1066 | // intact/accessible until the end of the marking phase (the |
| 1067 | // concurrent copying collector may not in the future). |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 1068 | __ MaybeUnpoisonHeapReference(temp); |
| 1069 | // temp = temp->GetMethodAt(method_offset); |
| 1070 | __ movq(temp, Address(temp, method_offset)); |
| 1071 | // call temp->GetEntryPoint(); |
| 1072 | __ call(Address(temp, ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 1073 | kX86_64PointerSize).SizeValue())); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 1074 | } |
| 1075 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 1076 | void CodeGeneratorX86_64::RecordBootStringPatch(HLoadString* load_string) { |
| 1077 | DCHECK(GetCompilerOptions().IsBootImage()); |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 1078 | string_patches_.emplace_back(load_string->GetDexFile(), load_string->GetStringIndex().index_); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 1079 | __ Bind(&string_patches_.back().label); |
| 1080 | } |
| 1081 | |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 1082 | void CodeGeneratorX86_64::RecordBootTypePatch(HLoadClass* load_class) { |
| 1083 | boot_image_type_patches_.emplace_back(load_class->GetDexFile(), |
| 1084 | load_class->GetTypeIndex().index_); |
| 1085 | __ Bind(&boot_image_type_patches_.back().label); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 1086 | } |
| 1087 | |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 1088 | Label* CodeGeneratorX86_64::NewTypeBssEntryPatch(HLoadClass* load_class) { |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 1089 | type_bss_entry_patches_.emplace_back(load_class->GetDexFile(), load_class->GetTypeIndex().index_); |
| 1090 | return &type_bss_entry_patches_.back().label; |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 1091 | } |
| 1092 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 1093 | Label* CodeGeneratorX86_64::NewStringBssEntryPatch(HLoadString* load_string) { |
| 1094 | DCHECK(!GetCompilerOptions().IsBootImage()); |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 1095 | string_patches_.emplace_back(load_string->GetDexFile(), load_string->GetStringIndex().index_); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 1096 | return &string_patches_.back().label; |
| 1097 | } |
| 1098 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 1099 | Label* CodeGeneratorX86_64::NewPcRelativeDexCacheArrayPatch(const DexFile& dex_file, |
| 1100 | uint32_t element_offset) { |
| 1101 | // Add a patch entry and return the label. |
| 1102 | pc_relative_dex_cache_patches_.emplace_back(dex_file, element_offset); |
| 1103 | return &pc_relative_dex_cache_patches_.back().label; |
| 1104 | } |
| 1105 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 1106 | // The label points to the end of the "movl" or another instruction but the literal offset |
| 1107 | // for method patch needs to point to the embedded constant which occupies the last 4 bytes. |
| 1108 | constexpr uint32_t kLabelPositionToLiteralOffsetAdjustment = 4u; |
| 1109 | |
| 1110 | template <LinkerPatch (*Factory)(size_t, const DexFile*, uint32_t, uint32_t)> |
| 1111 | inline void CodeGeneratorX86_64::EmitPcRelativeLinkerPatches( |
| 1112 | const ArenaDeque<PatchInfo<Label>>& infos, |
| 1113 | ArenaVector<LinkerPatch>* linker_patches) { |
| 1114 | for (const PatchInfo<Label>& info : infos) { |
| 1115 | uint32_t literal_offset = info.label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
| 1116 | linker_patches->push_back( |
| 1117 | Factory(literal_offset, &info.dex_file, info.label.Position(), info.index)); |
| 1118 | } |
| 1119 | } |
| 1120 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 1121 | void CodeGeneratorX86_64::EmitLinkerPatches(ArenaVector<LinkerPatch>* linker_patches) { |
| 1122 | DCHECK(linker_patches->empty()); |
| 1123 | size_t size = |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 1124 | pc_relative_dex_cache_patches_.size() + |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 1125 | string_patches_.size() + |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 1126 | boot_image_type_patches_.size() + |
| 1127 | type_bss_entry_patches_.size(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 1128 | linker_patches->reserve(size); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 1129 | EmitPcRelativeLinkerPatches<LinkerPatch::DexCacheArrayPatch>(pc_relative_dex_cache_patches_, |
| 1130 | linker_patches); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 1131 | if (!GetCompilerOptions().IsBootImage()) { |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 1132 | DCHECK(boot_image_type_patches_.empty()); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 1133 | EmitPcRelativeLinkerPatches<LinkerPatch::StringBssEntryPatch>(string_patches_, linker_patches); |
| 1134 | } else { |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 1135 | // These are always PC-relative, see GetSupportedLoadClassKind()/GetSupportedLoadStringKind(). |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 1136 | EmitPcRelativeLinkerPatches<LinkerPatch::RelativeTypePatch>(boot_image_type_patches_, |
| 1137 | linker_patches); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 1138 | EmitPcRelativeLinkerPatches<LinkerPatch::RelativeStringPatch>(string_patches_, linker_patches); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 1139 | } |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 1140 | EmitPcRelativeLinkerPatches<LinkerPatch::TypeBssEntryPatch>(type_bss_entry_patches_, |
| 1141 | linker_patches); |
| 1142 | DCHECK_EQ(size, linker_patches->size()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 1143 | } |
| 1144 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1145 | void CodeGeneratorX86_64::DumpCoreRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 1146 | stream << Register(reg); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1147 | } |
| 1148 | |
| 1149 | void CodeGeneratorX86_64::DumpFloatingPointRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 1150 | stream << FloatRegister(reg); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1151 | } |
| 1152 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1153 | size_t CodeGeneratorX86_64::SaveCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 1154 | __ movq(Address(CpuRegister(RSP), stack_index), CpuRegister(reg_id)); |
| 1155 | return kX86_64WordSize; |
Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 1156 | } |
| 1157 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1158 | size_t CodeGeneratorX86_64::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 1159 | __ movq(CpuRegister(reg_id), Address(CpuRegister(RSP), stack_index)); |
| 1160 | return kX86_64WordSize; |
| 1161 | } |
| 1162 | |
| 1163 | 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] | 1164 | if (GetGraph()->HasSIMD()) { |
Aart Bik | 5576f37 | 2017-03-23 16:17:37 -0700 | [diff] [blame^] | 1165 | __ movups(Address(CpuRegister(RSP), stack_index), XmmRegister(reg_id)); |
Aart Bik | b13c65b | 2017-03-21 20:14:07 -0700 | [diff] [blame] | 1166 | } else { |
| 1167 | __ movsd(Address(CpuRegister(RSP), stack_index), XmmRegister(reg_id)); |
| 1168 | } |
| 1169 | return GetFloatingPointSpillSlotSize(); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1170 | } |
| 1171 | |
| 1172 | 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] | 1173 | if (GetGraph()->HasSIMD()) { |
Aart Bik | 5576f37 | 2017-03-23 16:17:37 -0700 | [diff] [blame^] | 1174 | __ movups(XmmRegister(reg_id), Address(CpuRegister(RSP), stack_index)); |
Aart Bik | b13c65b | 2017-03-21 20:14:07 -0700 | [diff] [blame] | 1175 | } else { |
| 1176 | __ movsd(XmmRegister(reg_id), Address(CpuRegister(RSP), stack_index)); |
| 1177 | } |
| 1178 | return GetFloatingPointSpillSlotSize(); |
Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 1179 | } |
| 1180 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1181 | void CodeGeneratorX86_64::InvokeRuntime(QuickEntrypointEnum entrypoint, |
| 1182 | HInstruction* instruction, |
| 1183 | uint32_t dex_pc, |
| 1184 | SlowPathCode* slow_path) { |
Alexandre Rames | 91a6516 | 2016-09-19 13:54:30 +0100 | [diff] [blame] | 1185 | ValidateInvokeRuntime(entrypoint, instruction, slow_path); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 1186 | GenerateInvokeRuntime(GetThreadOffset<kX86_64PointerSize>(entrypoint).Int32Value()); |
| 1187 | if (EntrypointRequiresStackMap(entrypoint)) { |
| 1188 | RecordPcInfo(instruction, dex_pc, slow_path); |
| 1189 | } |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 1190 | } |
| 1191 | |
Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 1192 | void CodeGeneratorX86_64::InvokeRuntimeWithoutRecordingPcInfo(int32_t entry_point_offset, |
| 1193 | HInstruction* instruction, |
| 1194 | SlowPathCode* slow_path) { |
| 1195 | ValidateInvokeRuntimeWithoutRecordingPcInfo(instruction, slow_path); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 1196 | GenerateInvokeRuntime(entry_point_offset); |
| 1197 | } |
| 1198 | |
| 1199 | void CodeGeneratorX86_64::GenerateInvokeRuntime(int32_t entry_point_offset) { |
Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 1200 | __ gs()->call(Address::Absolute(entry_point_offset, /* no_rip */ true)); |
| 1201 | } |
| 1202 | |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1203 | static constexpr int kNumberOfCpuRegisterPairs = 0; |
Nicolas Geoffray | 4597b5b | 2015-01-23 21:51:55 +0000 | [diff] [blame] | 1204 | // Use a fake return address register to mimic Quick. |
| 1205 | static constexpr Register kFakeReturnRegister = Register(kLastCpuRegister + 1); |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 1206 | CodeGeneratorX86_64::CodeGeneratorX86_64(HGraph* graph, |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 1207 | const X86_64InstructionSetFeatures& isa_features, |
| 1208 | const CompilerOptions& compiler_options, |
| 1209 | OptimizingCompilerStats* stats) |
Nicolas Geoffray | 9889396 | 2015-01-21 12:32:32 +0000 | [diff] [blame] | 1210 | : CodeGenerator(graph, |
| 1211 | kNumberOfCpuRegisters, |
| 1212 | kNumberOfFloatRegisters, |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1213 | kNumberOfCpuRegisterPairs, |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 1214 | ComputeRegisterMask(reinterpret_cast<const int*>(kCoreCalleeSaves), |
| 1215 | arraysize(kCoreCalleeSaves)) |
Nicolas Geoffray | 4597b5b | 2015-01-23 21:51:55 +0000 | [diff] [blame] | 1216 | | (1 << kFakeReturnRegister), |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 1217 | ComputeRegisterMask(reinterpret_cast<const int*>(kFpuCalleeSaves), |
| 1218 | arraysize(kFpuCalleeSaves)), |
Serban Constantinescu | ecc4366 | 2015-08-13 13:33:12 +0100 | [diff] [blame] | 1219 | compiler_options, |
| 1220 | stats), |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 1221 | block_labels_(nullptr), |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1222 | location_builder_(graph, this), |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 1223 | instruction_visitor_(graph, this), |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 1224 | move_resolver_(graph->GetArena(), this), |
Vladimir Marko | 93205e3 | 2016-04-13 11:59:46 +0100 | [diff] [blame] | 1225 | assembler_(graph->GetArena()), |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 1226 | isa_features_(isa_features), |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 1227 | constant_area_start_(0), |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 1228 | pc_relative_dex_cache_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 1229 | string_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 1230 | boot_image_type_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 1231 | type_bss_entry_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 1232 | fixups_to_jump_tables_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 1233 | jit_string_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 1234 | jit_class_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)) { |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1235 | AddAllocatedRegister(Location::RegisterLocation(kFakeReturnRegister)); |
| 1236 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1237 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1238 | InstructionCodeGeneratorX86_64::InstructionCodeGeneratorX86_64(HGraph* graph, |
| 1239 | CodeGeneratorX86_64* codegen) |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 1240 | : InstructionCodeGenerator(graph, codegen), |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1241 | assembler_(codegen->GetAssembler()), |
| 1242 | codegen_(codegen) {} |
| 1243 | |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 1244 | void CodeGeneratorX86_64::SetupBlockedRegisters() const { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1245 | // Stack register is always reserved. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 1246 | blocked_core_registers_[RSP] = true; |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1247 | |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 1248 | // Block the register used as TMP. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 1249 | blocked_core_registers_[TMP] = true; |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1250 | } |
| 1251 | |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1252 | static dwarf::Reg DWARFReg(Register reg) { |
David Srbecky | 9d8606d | 2015-04-12 09:35:32 +0100 | [diff] [blame] | 1253 | return dwarf::Reg::X86_64Core(static_cast<int>(reg)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1254 | } |
David Srbecky | 9d8606d | 2015-04-12 09:35:32 +0100 | [diff] [blame] | 1255 | |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1256 | static dwarf::Reg DWARFReg(FloatRegister reg) { |
David Srbecky | 9d8606d | 2015-04-12 09:35:32 +0100 | [diff] [blame] | 1257 | return dwarf::Reg::X86_64Fp(static_cast<int>(reg)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1258 | } |
| 1259 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1260 | void CodeGeneratorX86_64::GenerateFrameEntry() { |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1261 | __ cfi().SetCurrentCFAOffset(kX86_64WordSize); // return address |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 1262 | __ Bind(&frame_entry_label_); |
Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 1263 | bool skip_overflow_check = IsLeafMethod() |
Dave Allison | 648d711 | 2014-07-25 16:15:27 -0700 | [diff] [blame] | 1264 | && !FrameNeedsStackCheck(GetFrameSize(), InstructionSet::kX86_64); |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1265 | DCHECK(GetCompilerOptions().GetImplicitStackOverflowChecks()); |
Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 1266 | |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1267 | if (!skip_overflow_check) { |
Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 1268 | __ testq(CpuRegister(RAX), Address( |
| 1269 | CpuRegister(RSP), -static_cast<int32_t>(GetStackOverflowReservedBytes(kX86_64)))); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1270 | RecordPcInfo(nullptr, 0); |
Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 1271 | } |
Nicolas Geoffray | a26369a | 2015-01-22 08:46:05 +0000 | [diff] [blame] | 1272 | |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1273 | if (HasEmptyFrame()) { |
| 1274 | return; |
| 1275 | } |
| 1276 | |
Nicolas Geoffray | 9889396 | 2015-01-21 12:32:32 +0000 | [diff] [blame] | 1277 | for (int i = arraysize(kCoreCalleeSaves) - 1; i >= 0; --i) { |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1278 | Register reg = kCoreCalleeSaves[i]; |
Nicolas Geoffray | 4597b5b | 2015-01-23 21:51:55 +0000 | [diff] [blame] | 1279 | if (allocated_registers_.ContainsCoreRegister(reg)) { |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1280 | __ pushq(CpuRegister(reg)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1281 | __ cfi().AdjustCFAOffset(kX86_64WordSize); |
| 1282 | __ cfi().RelOffset(DWARFReg(reg), 0); |
Nicolas Geoffray | 9889396 | 2015-01-21 12:32:32 +0000 | [diff] [blame] | 1283 | } |
| 1284 | } |
Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 1285 | |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1286 | int adjust = GetFrameSize() - GetCoreSpillSize(); |
| 1287 | __ subq(CpuRegister(RSP), Immediate(adjust)); |
| 1288 | __ cfi().AdjustCFAOffset(adjust); |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1289 | uint32_t xmm_spill_location = GetFpuSpillStart(); |
| 1290 | size_t xmm_spill_slot_size = GetFloatingPointSpillSlotSize(); |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 1291 | |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1292 | for (int i = arraysize(kFpuCalleeSaves) - 1; i >= 0; --i) { |
| 1293 | if (allocated_registers_.ContainsFloatingPointRegister(kFpuCalleeSaves[i])) { |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1294 | int offset = xmm_spill_location + (xmm_spill_slot_size * i); |
| 1295 | __ movsd(Address(CpuRegister(RSP), offset), XmmRegister(kFpuCalleeSaves[i])); |
| 1296 | __ cfi().RelOffset(DWARFReg(kFpuCalleeSaves[i]), offset); |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1297 | } |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 1298 | } |
| 1299 | |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 1300 | if (GetGraph()->HasShouldDeoptimizeFlag()) { |
| 1301 | // Initialize should_deoptimize flag to 0. |
| 1302 | __ movl(Address(CpuRegister(RSP), xmm_spill_location - kShouldDeoptimizeFlagSize), |
| 1303 | Immediate(0)); |
| 1304 | } |
| 1305 | |
Nicolas Geoffray | 96eeb4e | 2016-10-12 22:03:31 +0100 | [diff] [blame] | 1306 | // Save the current method if we need it. Note that we do not |
| 1307 | // do this in HCurrentMethod, as the instruction might have been removed |
| 1308 | // in the SSA graph. |
| 1309 | if (RequiresCurrentMethod()) { |
| 1310 | __ movq(Address(CpuRegister(RSP), kCurrentMethodStackOffset), |
| 1311 | CpuRegister(kMethodRegisterArgument)); |
| 1312 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1313 | } |
| 1314 | |
| 1315 | void CodeGeneratorX86_64::GenerateFrameExit() { |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 1316 | __ cfi().RememberState(); |
| 1317 | if (!HasEmptyFrame()) { |
| 1318 | uint32_t xmm_spill_location = GetFpuSpillStart(); |
| 1319 | size_t xmm_spill_slot_size = GetFloatingPointSpillSlotSize(); |
| 1320 | for (size_t i = 0; i < arraysize(kFpuCalleeSaves); ++i) { |
| 1321 | if (allocated_registers_.ContainsFloatingPointRegister(kFpuCalleeSaves[i])) { |
| 1322 | int offset = xmm_spill_location + (xmm_spill_slot_size * i); |
| 1323 | __ movsd(XmmRegister(kFpuCalleeSaves[i]), Address(CpuRegister(RSP), offset)); |
| 1324 | __ cfi().Restore(DWARFReg(kFpuCalleeSaves[i])); |
| 1325 | } |
| 1326 | } |
| 1327 | |
| 1328 | int adjust = GetFrameSize() - GetCoreSpillSize(); |
| 1329 | __ addq(CpuRegister(RSP), Immediate(adjust)); |
| 1330 | __ cfi().AdjustCFAOffset(-adjust); |
| 1331 | |
| 1332 | for (size_t i = 0; i < arraysize(kCoreCalleeSaves); ++i) { |
| 1333 | Register reg = kCoreCalleeSaves[i]; |
| 1334 | if (allocated_registers_.ContainsCoreRegister(reg)) { |
| 1335 | __ popq(CpuRegister(reg)); |
| 1336 | __ cfi().AdjustCFAOffset(-static_cast<int>(kX86_64WordSize)); |
| 1337 | __ cfi().Restore(DWARFReg(reg)); |
| 1338 | } |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1339 | } |
| 1340 | } |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 1341 | __ ret(); |
| 1342 | __ cfi().RestoreState(); |
| 1343 | __ cfi().DefCFAOffset(GetFrameSize()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1344 | } |
| 1345 | |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 1346 | void CodeGeneratorX86_64::Bind(HBasicBlock* block) { |
| 1347 | __ Bind(GetLabelOf(block)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1348 | } |
| 1349 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1350 | void CodeGeneratorX86_64::Move(Location destination, Location source) { |
| 1351 | if (source.Equals(destination)) { |
| 1352 | return; |
| 1353 | } |
| 1354 | if (destination.IsRegister()) { |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1355 | CpuRegister dest = destination.AsRegister<CpuRegister>(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1356 | if (source.IsRegister()) { |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1357 | __ movq(dest, source.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1358 | } else if (source.IsFpuRegister()) { |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1359 | __ movd(dest, source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1360 | } else if (source.IsStackSlot()) { |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1361 | __ movl(dest, Address(CpuRegister(RSP), source.GetStackIndex())); |
| 1362 | } else if (source.IsConstant()) { |
| 1363 | HConstant* constant = source.GetConstant(); |
| 1364 | if (constant->IsLongConstant()) { |
| 1365 | Load64BitValue(dest, constant->AsLongConstant()->GetValue()); |
| 1366 | } else { |
| 1367 | Load32BitValue(dest, GetInt32ValueOf(constant)); |
| 1368 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1369 | } else { |
| 1370 | DCHECK(source.IsDoubleStackSlot()); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1371 | __ movq(dest, Address(CpuRegister(RSP), source.GetStackIndex())); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1372 | } |
| 1373 | } else if (destination.IsFpuRegister()) { |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1374 | XmmRegister dest = destination.AsFpuRegister<XmmRegister>(); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1375 | if (source.IsRegister()) { |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1376 | __ movd(dest, source.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1377 | } else if (source.IsFpuRegister()) { |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1378 | __ movaps(dest, source.AsFpuRegister<XmmRegister>()); |
| 1379 | } else if (source.IsConstant()) { |
| 1380 | HConstant* constant = source.GetConstant(); |
| 1381 | int64_t value = CodeGenerator::GetInt64ValueOf(constant); |
| 1382 | if (constant->IsFloatConstant()) { |
| 1383 | Load32BitValue(dest, static_cast<int32_t>(value)); |
| 1384 | } else { |
| 1385 | Load64BitValue(dest, value); |
| 1386 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1387 | } else if (source.IsStackSlot()) { |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1388 | __ movss(dest, Address(CpuRegister(RSP), source.GetStackIndex())); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1389 | } else { |
| 1390 | DCHECK(source.IsDoubleStackSlot()); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1391 | __ movsd(dest, Address(CpuRegister(RSP), source.GetStackIndex())); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1392 | } |
| 1393 | } else if (destination.IsStackSlot()) { |
| 1394 | if (source.IsRegister()) { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1395 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1396 | source.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1397 | } else if (source.IsFpuRegister()) { |
| 1398 | __ movss(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1399 | source.AsFpuRegister<XmmRegister>()); |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 1400 | } else if (source.IsConstant()) { |
| 1401 | HConstant* constant = source.GetConstant(); |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1402 | int32_t value = GetInt32ValueOf(constant); |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 1403 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), Immediate(value)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1404 | } else { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 1405 | DCHECK(source.IsStackSlot()) << source; |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 1406 | __ movl(CpuRegister(TMP), Address(CpuRegister(RSP), source.GetStackIndex())); |
| 1407 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), CpuRegister(TMP)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1408 | } |
| 1409 | } else { |
| 1410 | DCHECK(destination.IsDoubleStackSlot()); |
| 1411 | if (source.IsRegister()) { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1412 | __ movq(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1413 | source.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1414 | } else if (source.IsFpuRegister()) { |
| 1415 | __ movsd(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1416 | source.AsFpuRegister<XmmRegister>()); |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 1417 | } else if (source.IsConstant()) { |
| 1418 | HConstant* constant = source.GetConstant(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 1419 | DCHECK(constant->IsLongConstant() || constant->IsDoubleConstant()); |
| 1420 | int64_t value = GetInt64ValueOf(constant); |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 1421 | Store64BitValueToStack(destination, value); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1422 | } else { |
| 1423 | DCHECK(source.IsDoubleStackSlot()); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 1424 | __ movq(CpuRegister(TMP), Address(CpuRegister(RSP), source.GetStackIndex())); |
| 1425 | __ movq(Address(CpuRegister(RSP), destination.GetStackIndex()), CpuRegister(TMP)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1426 | } |
| 1427 | } |
| 1428 | } |
| 1429 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1430 | void CodeGeneratorX86_64::MoveConstant(Location location, int32_t value) { |
| 1431 | DCHECK(location.IsRegister()); |
| 1432 | Load64BitValue(location.AsRegister<CpuRegister>(), static_cast<int64_t>(value)); |
| 1433 | } |
| 1434 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1435 | void CodeGeneratorX86_64::MoveLocation( |
| 1436 | Location dst, Location src, Primitive::Type dst_type ATTRIBUTE_UNUSED) { |
| 1437 | Move(dst, src); |
| 1438 | } |
| 1439 | |
| 1440 | void CodeGeneratorX86_64::AddLocationAsTemp(Location location, LocationSummary* locations) { |
| 1441 | if (location.IsRegister()) { |
| 1442 | locations->AddTemp(location); |
| 1443 | } else { |
| 1444 | UNIMPLEMENTED(FATAL) << "AddLocationAsTemp not implemented for location " << location; |
| 1445 | } |
| 1446 | } |
| 1447 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1448 | void InstructionCodeGeneratorX86_64::HandleGoto(HInstruction* got, HBasicBlock* successor) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1449 | DCHECK(!successor->IsExitBlock()); |
| 1450 | |
| 1451 | HBasicBlock* block = got->GetBlock(); |
| 1452 | HInstruction* previous = got->GetPrevious(); |
| 1453 | |
| 1454 | HLoopInformation* info = block->GetLoopInformation(); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1455 | if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1456 | GenerateSuspendCheck(info->GetSuspendCheck(), successor); |
| 1457 | return; |
| 1458 | } |
| 1459 | |
| 1460 | if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) { |
| 1461 | GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr); |
| 1462 | } |
| 1463 | if (!codegen_->GoesToNextBlock(got->GetBlock(), successor)) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1464 | __ jmp(codegen_->GetLabelOf(successor)); |
| 1465 | } |
| 1466 | } |
| 1467 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1468 | void LocationsBuilderX86_64::VisitGoto(HGoto* got) { |
| 1469 | got->SetLocations(nullptr); |
| 1470 | } |
| 1471 | |
| 1472 | void InstructionCodeGeneratorX86_64::VisitGoto(HGoto* got) { |
| 1473 | HandleGoto(got, got->GetSuccessor()); |
| 1474 | } |
| 1475 | |
| 1476 | void LocationsBuilderX86_64::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 1477 | try_boundary->SetLocations(nullptr); |
| 1478 | } |
| 1479 | |
| 1480 | void InstructionCodeGeneratorX86_64::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 1481 | HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor(); |
| 1482 | if (!successor->IsExitBlock()) { |
| 1483 | HandleGoto(try_boundary, successor); |
| 1484 | } |
| 1485 | } |
| 1486 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1487 | void LocationsBuilderX86_64::VisitExit(HExit* exit) { |
| 1488 | exit->SetLocations(nullptr); |
| 1489 | } |
| 1490 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1491 | void InstructionCodeGeneratorX86_64::VisitExit(HExit* exit ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1492 | } |
| 1493 | |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1494 | template<class LabelType> |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1495 | void InstructionCodeGeneratorX86_64::GenerateFPJumps(HCondition* cond, |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1496 | LabelType* true_label, |
| 1497 | LabelType* false_label) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1498 | if (cond->IsFPConditionTrueIfNaN()) { |
| 1499 | __ j(kUnordered, true_label); |
| 1500 | } else if (cond->IsFPConditionFalseIfNaN()) { |
| 1501 | __ j(kUnordered, false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1502 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1503 | __ j(X86_64FPCondition(cond->GetCondition()), true_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1504 | } |
| 1505 | |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1506 | void InstructionCodeGeneratorX86_64::GenerateCompareTest(HCondition* condition) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1507 | LocationSummary* locations = condition->GetLocations(); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1508 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1509 | Location left = locations->InAt(0); |
| 1510 | Location right = locations->InAt(1); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1511 | Primitive::Type type = condition->InputAt(0)->GetType(); |
| 1512 | switch (type) { |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1513 | case Primitive::kPrimBoolean: |
| 1514 | case Primitive::kPrimByte: |
| 1515 | case Primitive::kPrimChar: |
| 1516 | case Primitive::kPrimShort: |
| 1517 | case Primitive::kPrimInt: |
| 1518 | case Primitive::kPrimNot: { |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 1519 | codegen_->GenerateIntCompare(left, right); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1520 | break; |
| 1521 | } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1522 | case Primitive::kPrimLong: { |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 1523 | codegen_->GenerateLongCompare(left, right); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1524 | break; |
| 1525 | } |
| 1526 | case Primitive::kPrimFloat: { |
| 1527 | if (right.IsFpuRegister()) { |
| 1528 | __ ucomiss(left.AsFpuRegister<XmmRegister>(), right.AsFpuRegister<XmmRegister>()); |
| 1529 | } else if (right.IsConstant()) { |
| 1530 | __ ucomiss(left.AsFpuRegister<XmmRegister>(), |
| 1531 | codegen_->LiteralFloatAddress( |
| 1532 | right.GetConstant()->AsFloatConstant()->GetValue())); |
| 1533 | } else { |
| 1534 | DCHECK(right.IsStackSlot()); |
| 1535 | __ ucomiss(left.AsFpuRegister<XmmRegister>(), |
| 1536 | Address(CpuRegister(RSP), right.GetStackIndex())); |
| 1537 | } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1538 | break; |
| 1539 | } |
| 1540 | case Primitive::kPrimDouble: { |
| 1541 | if (right.IsFpuRegister()) { |
| 1542 | __ ucomisd(left.AsFpuRegister<XmmRegister>(), right.AsFpuRegister<XmmRegister>()); |
| 1543 | } else if (right.IsConstant()) { |
| 1544 | __ ucomisd(left.AsFpuRegister<XmmRegister>(), |
| 1545 | codegen_->LiteralDoubleAddress( |
| 1546 | right.GetConstant()->AsDoubleConstant()->GetValue())); |
| 1547 | } else { |
| 1548 | DCHECK(right.IsDoubleStackSlot()); |
| 1549 | __ ucomisd(left.AsFpuRegister<XmmRegister>(), |
| 1550 | Address(CpuRegister(RSP), right.GetStackIndex())); |
| 1551 | } |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1552 | break; |
| 1553 | } |
| 1554 | default: |
| 1555 | LOG(FATAL) << "Unexpected condition type " << type; |
| 1556 | } |
| 1557 | } |
| 1558 | |
| 1559 | template<class LabelType> |
| 1560 | void InstructionCodeGeneratorX86_64::GenerateCompareTestAndBranch(HCondition* condition, |
| 1561 | LabelType* true_target_in, |
| 1562 | LabelType* false_target_in) { |
| 1563 | // Generated branching requires both targets to be explicit. If either of the |
| 1564 | // targets is nullptr (fallthrough) use and bind `fallthrough_target` instead. |
| 1565 | LabelType fallthrough_target; |
| 1566 | LabelType* true_target = true_target_in == nullptr ? &fallthrough_target : true_target_in; |
| 1567 | LabelType* false_target = false_target_in == nullptr ? &fallthrough_target : false_target_in; |
| 1568 | |
| 1569 | // Generate the comparison to set the CC. |
| 1570 | GenerateCompareTest(condition); |
| 1571 | |
| 1572 | // Now generate the correct jump(s). |
| 1573 | Primitive::Type type = condition->InputAt(0)->GetType(); |
| 1574 | switch (type) { |
| 1575 | case Primitive::kPrimLong: { |
| 1576 | __ j(X86_64IntegerCondition(condition->GetCondition()), true_target); |
| 1577 | break; |
| 1578 | } |
| 1579 | case Primitive::kPrimFloat: { |
| 1580 | GenerateFPJumps(condition, true_target, false_target); |
| 1581 | break; |
| 1582 | } |
| 1583 | case Primitive::kPrimDouble: { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1584 | GenerateFPJumps(condition, true_target, false_target); |
| 1585 | break; |
| 1586 | } |
| 1587 | default: |
| 1588 | LOG(FATAL) << "Unexpected condition type " << type; |
| 1589 | } |
| 1590 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1591 | if (false_target != &fallthrough_target) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1592 | __ jmp(false_target); |
| 1593 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1594 | |
| 1595 | if (fallthrough_target.IsLinked()) { |
| 1596 | __ Bind(&fallthrough_target); |
| 1597 | } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1598 | } |
| 1599 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1600 | static bool AreEflagsSetFrom(HInstruction* cond, HInstruction* branch) { |
| 1601 | // Moves may affect the eflags register (move zero uses xorl), so the EFLAGS |
| 1602 | // are set only strictly before `branch`. We can't use the eflags on long |
| 1603 | // conditions if they are materialized due to the complex branching. |
| 1604 | return cond->IsCondition() && |
| 1605 | cond->GetNext() == branch && |
| 1606 | !Primitive::IsFloatingPointType(cond->InputAt(0)->GetType()); |
| 1607 | } |
| 1608 | |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1609 | template<class LabelType> |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1610 | void InstructionCodeGeneratorX86_64::GenerateTestAndBranch(HInstruction* instruction, |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1611 | size_t condition_input_index, |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1612 | LabelType* true_target, |
| 1613 | LabelType* false_target) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1614 | HInstruction* cond = instruction->InputAt(condition_input_index); |
| 1615 | |
| 1616 | if (true_target == nullptr && false_target == nullptr) { |
| 1617 | // Nothing to do. The code always falls through. |
| 1618 | return; |
| 1619 | } else if (cond->IsIntConstant()) { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 1620 | // Constant condition, statically compared against "true" (integer value 1). |
| 1621 | if (cond->AsIntConstant()->IsTrue()) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1622 | if (true_target != nullptr) { |
| 1623 | __ jmp(true_target); |
Nicolas Geoffray | 18efde5 | 2014-09-22 15:51:11 +0100 | [diff] [blame] | 1624 | } |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1625 | } else { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 1626 | DCHECK(cond->AsIntConstant()->IsFalse()) << cond->AsIntConstant()->GetValue(); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1627 | if (false_target != nullptr) { |
| 1628 | __ jmp(false_target); |
| 1629 | } |
| 1630 | } |
| 1631 | return; |
| 1632 | } |
| 1633 | |
| 1634 | // The following code generates these patterns: |
| 1635 | // (1) true_target == nullptr && false_target != nullptr |
| 1636 | // - opposite condition true => branch to false_target |
| 1637 | // (2) true_target != nullptr && false_target == nullptr |
| 1638 | // - condition true => branch to true_target |
| 1639 | // (3) true_target != nullptr && false_target != nullptr |
| 1640 | // - condition true => branch to true_target |
| 1641 | // - branch to false_target |
| 1642 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
| 1643 | if (AreEflagsSetFrom(cond, instruction)) { |
| 1644 | if (true_target == nullptr) { |
| 1645 | __ j(X86_64IntegerCondition(cond->AsCondition()->GetOppositeCondition()), false_target); |
| 1646 | } else { |
| 1647 | __ j(X86_64IntegerCondition(cond->AsCondition()->GetCondition()), true_target); |
| 1648 | } |
| 1649 | } else { |
| 1650 | // Materialized condition, compare against 0. |
| 1651 | Location lhs = instruction->GetLocations()->InAt(condition_input_index); |
| 1652 | if (lhs.IsRegister()) { |
| 1653 | __ testl(lhs.AsRegister<CpuRegister>(), lhs.AsRegister<CpuRegister>()); |
| 1654 | } else { |
| 1655 | __ cmpl(Address(CpuRegister(RSP), lhs.GetStackIndex()), Immediate(0)); |
| 1656 | } |
| 1657 | if (true_target == nullptr) { |
| 1658 | __ j(kEqual, false_target); |
| 1659 | } else { |
| 1660 | __ j(kNotEqual, true_target); |
| 1661 | } |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1662 | } |
| 1663 | } else { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1664 | // Condition has not been materialized, use its inputs as the |
| 1665 | // comparison and its condition as the branch condition. |
Mark Mendell | b8b9769 | 2015-05-22 16:58:19 -0400 | [diff] [blame] | 1666 | HCondition* condition = cond->AsCondition(); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1667 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1668 | // If this is a long or FP comparison that has been folded into |
| 1669 | // the HCondition, generate the comparison directly. |
| 1670 | Primitive::Type type = condition->InputAt(0)->GetType(); |
| 1671 | if (type == Primitive::kPrimLong || Primitive::IsFloatingPointType(type)) { |
| 1672 | GenerateCompareTestAndBranch(condition, true_target, false_target); |
| 1673 | return; |
| 1674 | } |
| 1675 | |
| 1676 | Location lhs = condition->GetLocations()->InAt(0); |
| 1677 | Location rhs = condition->GetLocations()->InAt(1); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 1678 | codegen_->GenerateIntCompare(lhs, rhs); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1679 | if (true_target == nullptr) { |
| 1680 | __ j(X86_64IntegerCondition(condition->GetOppositeCondition()), false_target); |
| 1681 | } else { |
Mark Mendell | b8b9769 | 2015-05-22 16:58:19 -0400 | [diff] [blame] | 1682 | __ j(X86_64IntegerCondition(condition->GetCondition()), true_target); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1683 | } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1684 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1685 | |
| 1686 | // If neither branch falls through (case 3), the conditional branch to `true_target` |
| 1687 | // was already emitted (case 2) and we need to emit a jump to `false_target`. |
| 1688 | if (true_target != nullptr && false_target != nullptr) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1689 | __ jmp(false_target); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1690 | } |
| 1691 | } |
| 1692 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1693 | void LocationsBuilderX86_64::VisitIf(HIf* if_instr) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1694 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(if_instr); |
| 1695 | if (IsBooleanValueOrMaterializedCondition(if_instr->InputAt(0))) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1696 | locations->SetInAt(0, Location::Any()); |
| 1697 | } |
| 1698 | } |
| 1699 | |
| 1700 | void InstructionCodeGeneratorX86_64::VisitIf(HIf* if_instr) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1701 | HBasicBlock* true_successor = if_instr->IfTrueSuccessor(); |
| 1702 | HBasicBlock* false_successor = if_instr->IfFalseSuccessor(); |
| 1703 | Label* true_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), true_successor) ? |
| 1704 | nullptr : codegen_->GetLabelOf(true_successor); |
| 1705 | Label* false_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), false_successor) ? |
| 1706 | nullptr : codegen_->GetLabelOf(false_successor); |
| 1707 | GenerateTestAndBranch(if_instr, /* condition_input_index */ 0, true_target, false_target); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1708 | } |
| 1709 | |
| 1710 | void LocationsBuilderX86_64::VisitDeoptimize(HDeoptimize* deoptimize) { |
| 1711 | LocationSummary* locations = new (GetGraph()->GetArena()) |
| 1712 | LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath); |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 1713 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1714 | if (IsBooleanValueOrMaterializedCondition(deoptimize->InputAt(0))) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1715 | locations->SetInAt(0, Location::Any()); |
| 1716 | } |
| 1717 | } |
| 1718 | |
| 1719 | void InstructionCodeGeneratorX86_64::VisitDeoptimize(HDeoptimize* deoptimize) { |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 1720 | SlowPathCode* slow_path = deopt_slow_paths_.NewSlowPath<DeoptimizationSlowPathX86_64>(deoptimize); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1721 | GenerateTestAndBranch<Label>(deoptimize, |
| 1722 | /* condition_input_index */ 0, |
| 1723 | slow_path->GetEntryLabel(), |
| 1724 | /* false_target */ nullptr); |
| 1725 | } |
| 1726 | |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 1727 | void LocationsBuilderX86_64::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) { |
| 1728 | LocationSummary* locations = new (GetGraph()->GetArena()) |
| 1729 | LocationSummary(flag, LocationSummary::kNoCall); |
| 1730 | locations->SetOut(Location::RequiresRegister()); |
| 1731 | } |
| 1732 | |
| 1733 | void InstructionCodeGeneratorX86_64::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) { |
| 1734 | __ movl(flag->GetLocations()->Out().AsRegister<CpuRegister>(), |
| 1735 | Address(CpuRegister(RSP), codegen_->GetStackOffsetOfShouldDeoptimizeFlag())); |
| 1736 | } |
| 1737 | |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1738 | static bool SelectCanUseCMOV(HSelect* select) { |
| 1739 | // There are no conditional move instructions for XMMs. |
| 1740 | if (Primitive::IsFloatingPointType(select->GetType())) { |
| 1741 | return false; |
| 1742 | } |
| 1743 | |
| 1744 | // A FP condition doesn't generate the single CC that we need. |
| 1745 | HInstruction* condition = select->GetCondition(); |
| 1746 | if (condition->IsCondition() && |
| 1747 | Primitive::IsFloatingPointType(condition->InputAt(0)->GetType())) { |
| 1748 | return false; |
| 1749 | } |
| 1750 | |
| 1751 | // We can generate a CMOV for this Select. |
| 1752 | return true; |
| 1753 | } |
| 1754 | |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1755 | void LocationsBuilderX86_64::VisitSelect(HSelect* select) { |
| 1756 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(select); |
| 1757 | if (Primitive::IsFloatingPointType(select->GetType())) { |
| 1758 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1759 | locations->SetInAt(1, Location::Any()); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1760 | } else { |
| 1761 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1762 | if (SelectCanUseCMOV(select)) { |
Mark Mendell | dee1b9a | 2016-02-12 14:36:51 -0500 | [diff] [blame] | 1763 | if (select->InputAt(1)->IsConstant()) { |
| 1764 | locations->SetInAt(1, Location::RequiresRegister()); |
| 1765 | } else { |
| 1766 | locations->SetInAt(1, Location::Any()); |
| 1767 | } |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1768 | } else { |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1769 | locations->SetInAt(1, Location::Any()); |
| 1770 | } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1771 | } |
| 1772 | if (IsBooleanValueOrMaterializedCondition(select->GetCondition())) { |
| 1773 | locations->SetInAt(2, Location::RequiresRegister()); |
| 1774 | } |
| 1775 | locations->SetOut(Location::SameAsFirstInput()); |
| 1776 | } |
| 1777 | |
| 1778 | void InstructionCodeGeneratorX86_64::VisitSelect(HSelect* select) { |
| 1779 | LocationSummary* locations = select->GetLocations(); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1780 | if (SelectCanUseCMOV(select)) { |
| 1781 | // If both the condition and the source types are integer, we can generate |
| 1782 | // a CMOV to implement Select. |
| 1783 | CpuRegister value_false = locations->InAt(0).AsRegister<CpuRegister>(); |
Mark Mendell | dee1b9a | 2016-02-12 14:36:51 -0500 | [diff] [blame] | 1784 | Location value_true_loc = locations->InAt(1); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1785 | DCHECK(locations->InAt(0).Equals(locations->Out())); |
| 1786 | |
| 1787 | HInstruction* select_condition = select->GetCondition(); |
| 1788 | Condition cond = kNotEqual; |
| 1789 | |
| 1790 | // Figure out how to test the 'condition'. |
| 1791 | if (select_condition->IsCondition()) { |
| 1792 | HCondition* condition = select_condition->AsCondition(); |
| 1793 | if (!condition->IsEmittedAtUseSite()) { |
| 1794 | // This was a previously materialized condition. |
| 1795 | // Can we use the existing condition code? |
| 1796 | if (AreEflagsSetFrom(condition, select)) { |
| 1797 | // Materialization was the previous instruction. Condition codes are right. |
| 1798 | cond = X86_64IntegerCondition(condition->GetCondition()); |
| 1799 | } else { |
| 1800 | // No, we have to recreate the condition code. |
| 1801 | CpuRegister cond_reg = locations->InAt(2).AsRegister<CpuRegister>(); |
| 1802 | __ testl(cond_reg, cond_reg); |
| 1803 | } |
| 1804 | } else { |
| 1805 | GenerateCompareTest(condition); |
| 1806 | cond = X86_64IntegerCondition(condition->GetCondition()); |
| 1807 | } |
| 1808 | } else { |
Roland Levillain | 5e8d5f0 | 2016-10-18 18:03:43 +0100 | [diff] [blame] | 1809 | // Must be a Boolean condition, which needs to be compared to 0. |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1810 | CpuRegister cond_reg = locations->InAt(2).AsRegister<CpuRegister>(); |
| 1811 | __ testl(cond_reg, cond_reg); |
| 1812 | } |
| 1813 | |
| 1814 | // If the condition is true, overwrite the output, which already contains false. |
| 1815 | // Generate the correct sized CMOV. |
Mark Mendell | dee1b9a | 2016-02-12 14:36:51 -0500 | [diff] [blame] | 1816 | bool is_64_bit = Primitive::Is64BitType(select->GetType()); |
| 1817 | if (value_true_loc.IsRegister()) { |
| 1818 | __ cmov(cond, value_false, value_true_loc.AsRegister<CpuRegister>(), is_64_bit); |
| 1819 | } else { |
| 1820 | __ cmov(cond, |
| 1821 | value_false, |
| 1822 | Address(CpuRegister(RSP), value_true_loc.GetStackIndex()), is_64_bit); |
| 1823 | } |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1824 | } else { |
| 1825 | NearLabel false_target; |
| 1826 | GenerateTestAndBranch<NearLabel>(select, |
| 1827 | /* condition_input_index */ 2, |
| 1828 | /* true_target */ nullptr, |
| 1829 | &false_target); |
| 1830 | codegen_->MoveLocation(locations->Out(), locations->InAt(1), select->GetType()); |
| 1831 | __ Bind(&false_target); |
| 1832 | } |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1833 | } |
| 1834 | |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 1835 | void LocationsBuilderX86_64::VisitNativeDebugInfo(HNativeDebugInfo* info) { |
| 1836 | new (GetGraph()->GetArena()) LocationSummary(info); |
| 1837 | } |
| 1838 | |
David Srbecky | d28f4a0 | 2016-03-14 17:14:24 +0000 | [diff] [blame] | 1839 | void InstructionCodeGeneratorX86_64::VisitNativeDebugInfo(HNativeDebugInfo*) { |
| 1840 | // MaybeRecordNativeDebugInfo is already called implicitly in CodeGenerator::Compile. |
David Srbecky | c7098ff | 2016-02-09 14:30:11 +0000 | [diff] [blame] | 1841 | } |
| 1842 | |
| 1843 | void CodeGeneratorX86_64::GenerateNop() { |
| 1844 | __ nop(); |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 1845 | } |
| 1846 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1847 | void LocationsBuilderX86_64::HandleCondition(HCondition* cond) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1848 | LocationSummary* locations = |
Roland Levillain | 0d37cd0 | 2015-05-27 16:39:19 +0100 | [diff] [blame] | 1849 | new (GetGraph()->GetArena()) LocationSummary(cond, LocationSummary::kNoCall); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1850 | // Handle the long/FP comparisons made in instruction simplification. |
| 1851 | switch (cond->InputAt(0)->GetType()) { |
| 1852 | case Primitive::kPrimLong: |
| 1853 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1854 | locations->SetInAt(1, Location::Any()); |
| 1855 | break; |
| 1856 | case Primitive::kPrimFloat: |
| 1857 | case Primitive::kPrimDouble: |
| 1858 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1859 | locations->SetInAt(1, Location::Any()); |
| 1860 | break; |
| 1861 | default: |
| 1862 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1863 | locations->SetInAt(1, Location::Any()); |
| 1864 | break; |
| 1865 | } |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 1866 | if (!cond->IsEmittedAtUseSite()) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1867 | locations->SetOut(Location::RequiresRegister()); |
| 1868 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1869 | } |
| 1870 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1871 | void InstructionCodeGeneratorX86_64::HandleCondition(HCondition* cond) { |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 1872 | if (cond->IsEmittedAtUseSite()) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1873 | return; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1874 | } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1875 | |
| 1876 | LocationSummary* locations = cond->GetLocations(); |
| 1877 | Location lhs = locations->InAt(0); |
| 1878 | Location rhs = locations->InAt(1); |
| 1879 | CpuRegister reg = locations->Out().AsRegister<CpuRegister>(); |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1880 | NearLabel true_label, false_label; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1881 | |
| 1882 | switch (cond->InputAt(0)->GetType()) { |
| 1883 | default: |
| 1884 | // Integer case. |
| 1885 | |
| 1886 | // Clear output register: setcc only sets the low byte. |
| 1887 | __ xorl(reg, reg); |
| 1888 | |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 1889 | codegen_->GenerateIntCompare(lhs, rhs); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1890 | __ setcc(X86_64IntegerCondition(cond->GetCondition()), reg); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1891 | return; |
| 1892 | case Primitive::kPrimLong: |
| 1893 | // Clear output register: setcc only sets the low byte. |
| 1894 | __ xorl(reg, reg); |
| 1895 | |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 1896 | codegen_->GenerateLongCompare(lhs, rhs); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1897 | __ setcc(X86_64IntegerCondition(cond->GetCondition()), reg); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1898 | return; |
| 1899 | case Primitive::kPrimFloat: { |
| 1900 | XmmRegister lhs_reg = lhs.AsFpuRegister<XmmRegister>(); |
| 1901 | if (rhs.IsConstant()) { |
| 1902 | float value = rhs.GetConstant()->AsFloatConstant()->GetValue(); |
| 1903 | __ ucomiss(lhs_reg, codegen_->LiteralFloatAddress(value)); |
| 1904 | } else if (rhs.IsStackSlot()) { |
| 1905 | __ ucomiss(lhs_reg, Address(CpuRegister(RSP), rhs.GetStackIndex())); |
| 1906 | } else { |
| 1907 | __ ucomiss(lhs_reg, rhs.AsFpuRegister<XmmRegister>()); |
| 1908 | } |
| 1909 | GenerateFPJumps(cond, &true_label, &false_label); |
| 1910 | break; |
| 1911 | } |
| 1912 | case Primitive::kPrimDouble: { |
| 1913 | XmmRegister lhs_reg = lhs.AsFpuRegister<XmmRegister>(); |
| 1914 | if (rhs.IsConstant()) { |
| 1915 | double value = rhs.GetConstant()->AsDoubleConstant()->GetValue(); |
| 1916 | __ ucomisd(lhs_reg, codegen_->LiteralDoubleAddress(value)); |
| 1917 | } else if (rhs.IsDoubleStackSlot()) { |
| 1918 | __ ucomisd(lhs_reg, Address(CpuRegister(RSP), rhs.GetStackIndex())); |
| 1919 | } else { |
| 1920 | __ ucomisd(lhs_reg, rhs.AsFpuRegister<XmmRegister>()); |
| 1921 | } |
| 1922 | GenerateFPJumps(cond, &true_label, &false_label); |
| 1923 | break; |
| 1924 | } |
| 1925 | } |
| 1926 | |
| 1927 | // Convert the jumps into the result. |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 1928 | NearLabel done_label; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1929 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1930 | // False case: result = 0. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1931 | __ Bind(&false_label); |
| 1932 | __ xorl(reg, reg); |
| 1933 | __ jmp(&done_label); |
| 1934 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1935 | // True case: result = 1. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1936 | __ Bind(&true_label); |
| 1937 | __ movl(reg, Immediate(1)); |
| 1938 | __ Bind(&done_label); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1939 | } |
| 1940 | |
| 1941 | void LocationsBuilderX86_64::VisitEqual(HEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1942 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1943 | } |
| 1944 | |
| 1945 | void InstructionCodeGeneratorX86_64::VisitEqual(HEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1946 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1947 | } |
| 1948 | |
| 1949 | void LocationsBuilderX86_64::VisitNotEqual(HNotEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1950 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1951 | } |
| 1952 | |
| 1953 | void InstructionCodeGeneratorX86_64::VisitNotEqual(HNotEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1954 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1955 | } |
| 1956 | |
| 1957 | void LocationsBuilderX86_64::VisitLessThan(HLessThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1958 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1959 | } |
| 1960 | |
| 1961 | void InstructionCodeGeneratorX86_64::VisitLessThan(HLessThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1962 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1963 | } |
| 1964 | |
| 1965 | void LocationsBuilderX86_64::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1966 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1967 | } |
| 1968 | |
| 1969 | void InstructionCodeGeneratorX86_64::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1970 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1971 | } |
| 1972 | |
| 1973 | void LocationsBuilderX86_64::VisitGreaterThan(HGreaterThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1974 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1975 | } |
| 1976 | |
| 1977 | void InstructionCodeGeneratorX86_64::VisitGreaterThan(HGreaterThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1978 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1979 | } |
| 1980 | |
| 1981 | void LocationsBuilderX86_64::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1982 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1983 | } |
| 1984 | |
| 1985 | void InstructionCodeGeneratorX86_64::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1986 | HandleCondition(comp); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1987 | } |
| 1988 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1989 | void LocationsBuilderX86_64::VisitBelow(HBelow* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1990 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1991 | } |
| 1992 | |
| 1993 | void InstructionCodeGeneratorX86_64::VisitBelow(HBelow* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1994 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1995 | } |
| 1996 | |
| 1997 | void LocationsBuilderX86_64::VisitBelowOrEqual(HBelowOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1998 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1999 | } |
| 2000 | |
| 2001 | void InstructionCodeGeneratorX86_64::VisitBelowOrEqual(HBelowOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2002 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2003 | } |
| 2004 | |
| 2005 | void LocationsBuilderX86_64::VisitAbove(HAbove* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2006 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2007 | } |
| 2008 | |
| 2009 | void InstructionCodeGeneratorX86_64::VisitAbove(HAbove* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2010 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2011 | } |
| 2012 | |
| 2013 | void LocationsBuilderX86_64::VisitAboveOrEqual(HAboveOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2014 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2015 | } |
| 2016 | |
| 2017 | void InstructionCodeGeneratorX86_64::VisitAboveOrEqual(HAboveOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2018 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2019 | } |
| 2020 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 2021 | void LocationsBuilderX86_64::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2022 | LocationSummary* locations = |
| 2023 | new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2024 | switch (compare->InputAt(0)->GetType()) { |
Roland Levillain | a5c4a40 | 2016-03-15 15:02:50 +0000 | [diff] [blame] | 2025 | case Primitive::kPrimBoolean: |
| 2026 | case Primitive::kPrimByte: |
| 2027 | case Primitive::kPrimShort: |
| 2028 | case Primitive::kPrimChar: |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 2029 | case Primitive::kPrimInt: |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2030 | case Primitive::kPrimLong: { |
| 2031 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2032 | locations->SetInAt(1, Location::Any()); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2033 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2034 | break; |
| 2035 | } |
| 2036 | case Primitive::kPrimFloat: |
| 2037 | case Primitive::kPrimDouble: { |
| 2038 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2039 | locations->SetInAt(1, Location::Any()); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2040 | locations->SetOut(Location::RequiresRegister()); |
| 2041 | break; |
| 2042 | } |
| 2043 | default: |
| 2044 | LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType(); |
| 2045 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 2046 | } |
| 2047 | |
| 2048 | void InstructionCodeGeneratorX86_64::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 2049 | LocationSummary* locations = compare->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2050 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2051 | Location left = locations->InAt(0); |
| 2052 | Location right = locations->InAt(1); |
| 2053 | |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2054 | NearLabel less, greater, done; |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2055 | Primitive::Type type = compare->InputAt(0)->GetType(); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 2056 | Condition less_cond = kLess; |
| 2057 | |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2058 | switch (type) { |
Roland Levillain | a5c4a40 | 2016-03-15 15:02:50 +0000 | [diff] [blame] | 2059 | case Primitive::kPrimBoolean: |
| 2060 | case Primitive::kPrimByte: |
| 2061 | case Primitive::kPrimShort: |
| 2062 | case Primitive::kPrimChar: |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 2063 | case Primitive::kPrimInt: { |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 2064 | codegen_->GenerateIntCompare(left, right); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 2065 | break; |
| 2066 | } |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2067 | case Primitive::kPrimLong: { |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 2068 | codegen_->GenerateLongCompare(left, right); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 2069 | break; |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2070 | } |
| 2071 | case Primitive::kPrimFloat: { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2072 | XmmRegister left_reg = left.AsFpuRegister<XmmRegister>(); |
| 2073 | if (right.IsConstant()) { |
| 2074 | float value = right.GetConstant()->AsFloatConstant()->GetValue(); |
| 2075 | __ ucomiss(left_reg, codegen_->LiteralFloatAddress(value)); |
| 2076 | } else if (right.IsStackSlot()) { |
| 2077 | __ ucomiss(left_reg, Address(CpuRegister(RSP), right.GetStackIndex())); |
| 2078 | } else { |
| 2079 | __ ucomiss(left_reg, right.AsFpuRegister<XmmRegister>()); |
| 2080 | } |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2081 | __ j(kUnordered, compare->IsGtBias() ? &greater : &less); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 2082 | less_cond = kBelow; // ucomis{s,d} sets CF |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2083 | break; |
| 2084 | } |
| 2085 | case Primitive::kPrimDouble: { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2086 | XmmRegister left_reg = left.AsFpuRegister<XmmRegister>(); |
| 2087 | if (right.IsConstant()) { |
| 2088 | double value = right.GetConstant()->AsDoubleConstant()->GetValue(); |
| 2089 | __ ucomisd(left_reg, codegen_->LiteralDoubleAddress(value)); |
| 2090 | } else if (right.IsDoubleStackSlot()) { |
| 2091 | __ ucomisd(left_reg, Address(CpuRegister(RSP), right.GetStackIndex())); |
| 2092 | } else { |
| 2093 | __ ucomisd(left_reg, right.AsFpuRegister<XmmRegister>()); |
| 2094 | } |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2095 | __ j(kUnordered, compare->IsGtBias() ? &greater : &less); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 2096 | less_cond = kBelow; // ucomis{s,d} sets CF |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2097 | break; |
| 2098 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 2099 | default: |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2100 | LOG(FATAL) << "Unexpected compare type " << type; |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 2101 | } |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 2102 | |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2103 | __ movl(out, Immediate(0)); |
Calin Juravle | 91debbc | 2014-11-26 19:01:09 +0000 | [diff] [blame] | 2104 | __ j(kEqual, &done); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 2105 | __ j(less_cond, &less); |
Calin Juravle | fd86124 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2106 | |
Calin Juravle | 91debbc | 2014-11-26 19:01:09 +0000 | [diff] [blame] | 2107 | __ Bind(&greater); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2108 | __ movl(out, Immediate(1)); |
| 2109 | __ jmp(&done); |
| 2110 | |
| 2111 | __ Bind(&less); |
| 2112 | __ movl(out, Immediate(-1)); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 2113 | |
| 2114 | __ Bind(&done); |
| 2115 | } |
| 2116 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2117 | void LocationsBuilderX86_64::VisitIntConstant(HIntConstant* constant) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2118 | LocationSummary* locations = |
| 2119 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2120 | locations->SetOut(Location::ConstantLocation(constant)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2121 | } |
| 2122 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2123 | void InstructionCodeGeneratorX86_64::VisitIntConstant(HIntConstant* constant ATTRIBUTE_UNUSED) { |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 2124 | // Will be generated at use site. |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2125 | } |
| 2126 | |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 2127 | void LocationsBuilderX86_64::VisitNullConstant(HNullConstant* constant) { |
| 2128 | LocationSummary* locations = |
| 2129 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 2130 | locations->SetOut(Location::ConstantLocation(constant)); |
| 2131 | } |
| 2132 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2133 | void InstructionCodeGeneratorX86_64::VisitNullConstant(HNullConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 2134 | // Will be generated at use site. |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 2135 | } |
| 2136 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2137 | void LocationsBuilderX86_64::VisitLongConstant(HLongConstant* constant) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2138 | LocationSummary* locations = |
| 2139 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2140 | locations->SetOut(Location::ConstantLocation(constant)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2141 | } |
| 2142 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2143 | void InstructionCodeGeneratorX86_64::VisitLongConstant(HLongConstant* constant ATTRIBUTE_UNUSED) { |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 2144 | // Will be generated at use site. |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2145 | } |
| 2146 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2147 | void LocationsBuilderX86_64::VisitFloatConstant(HFloatConstant* constant) { |
| 2148 | LocationSummary* locations = |
| 2149 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 2150 | locations->SetOut(Location::ConstantLocation(constant)); |
| 2151 | } |
| 2152 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2153 | void InstructionCodeGeneratorX86_64::VisitFloatConstant(HFloatConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2154 | // Will be generated at use site. |
| 2155 | } |
| 2156 | |
| 2157 | void LocationsBuilderX86_64::VisitDoubleConstant(HDoubleConstant* 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::VisitDoubleConstant( |
| 2164 | HDoubleConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2165 | // Will be generated at use site. |
| 2166 | } |
| 2167 | |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 2168 | void LocationsBuilderX86_64::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 2169 | memory_barrier->SetLocations(nullptr); |
| 2170 | } |
| 2171 | |
| 2172 | void InstructionCodeGeneratorX86_64::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 2173 | codegen_->GenerateMemoryBarrier(memory_barrier->GetBarrierKind()); |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 2174 | } |
| 2175 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2176 | void LocationsBuilderX86_64::VisitReturnVoid(HReturnVoid* ret) { |
| 2177 | ret->SetLocations(nullptr); |
| 2178 | } |
| 2179 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2180 | void InstructionCodeGeneratorX86_64::VisitReturnVoid(HReturnVoid* ret ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2181 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2182 | } |
| 2183 | |
| 2184 | void LocationsBuilderX86_64::VisitReturn(HReturn* ret) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2185 | LocationSummary* locations = |
| 2186 | new (GetGraph()->GetArena()) LocationSummary(ret, LocationSummary::kNoCall); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2187 | switch (ret->InputAt(0)->GetType()) { |
| 2188 | case Primitive::kPrimBoolean: |
| 2189 | case Primitive::kPrimByte: |
| 2190 | case Primitive::kPrimChar: |
| 2191 | case Primitive::kPrimShort: |
| 2192 | case Primitive::kPrimInt: |
| 2193 | case Primitive::kPrimNot: |
| 2194 | case Primitive::kPrimLong: |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2195 | locations->SetInAt(0, Location::RegisterLocation(RAX)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2196 | break; |
| 2197 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2198 | case Primitive::kPrimFloat: |
| 2199 | case Primitive::kPrimDouble: |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2200 | locations->SetInAt(0, Location::FpuRegisterLocation(XMM0)); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2201 | break; |
| 2202 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2203 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2204 | LOG(FATAL) << "Unexpected return type " << ret->InputAt(0)->GetType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2205 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2206 | } |
| 2207 | |
| 2208 | void InstructionCodeGeneratorX86_64::VisitReturn(HReturn* ret) { |
| 2209 | if (kIsDebugBuild) { |
| 2210 | switch (ret->InputAt(0)->GetType()) { |
| 2211 | case Primitive::kPrimBoolean: |
| 2212 | case Primitive::kPrimByte: |
| 2213 | case Primitive::kPrimChar: |
| 2214 | case Primitive::kPrimShort: |
| 2215 | case Primitive::kPrimInt: |
| 2216 | case Primitive::kPrimNot: |
| 2217 | case Primitive::kPrimLong: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2218 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsRegister<CpuRegister>().AsRegister(), RAX); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2219 | break; |
| 2220 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2221 | case Primitive::kPrimFloat: |
| 2222 | case Primitive::kPrimDouble: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2223 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsFpuRegister<XmmRegister>().AsFloatRegister(), |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2224 | XMM0); |
| 2225 | break; |
| 2226 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2227 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2228 | LOG(FATAL) << "Unexpected return type " << ret->InputAt(0)->GetType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2229 | } |
| 2230 | } |
| 2231 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2232 | } |
| 2233 | |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 2234 | Location InvokeDexCallingConventionVisitorX86_64::GetReturnLocation(Primitive::Type type) const { |
| 2235 | switch (type) { |
| 2236 | case Primitive::kPrimBoolean: |
| 2237 | case Primitive::kPrimByte: |
| 2238 | case Primitive::kPrimChar: |
| 2239 | case Primitive::kPrimShort: |
| 2240 | case Primitive::kPrimInt: |
| 2241 | case Primitive::kPrimNot: |
| 2242 | case Primitive::kPrimLong: |
| 2243 | return Location::RegisterLocation(RAX); |
| 2244 | |
| 2245 | case Primitive::kPrimVoid: |
| 2246 | return Location::NoLocation(); |
| 2247 | |
| 2248 | case Primitive::kPrimDouble: |
| 2249 | case Primitive::kPrimFloat: |
| 2250 | return Location::FpuRegisterLocation(XMM0); |
| 2251 | } |
Nicolas Geoffray | 0d1652e | 2015-06-03 12:12:19 +0100 | [diff] [blame] | 2252 | |
| 2253 | UNREACHABLE(); |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 2254 | } |
| 2255 | |
| 2256 | Location InvokeDexCallingConventionVisitorX86_64::GetMethodLocation() const { |
| 2257 | return Location::RegisterLocation(kMethodRegisterArgument); |
| 2258 | } |
| 2259 | |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 2260 | Location InvokeDexCallingConventionVisitorX86_64::GetNextLocation(Primitive::Type type) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2261 | switch (type) { |
| 2262 | case Primitive::kPrimBoolean: |
| 2263 | case Primitive::kPrimByte: |
| 2264 | case Primitive::kPrimChar: |
| 2265 | case Primitive::kPrimShort: |
| 2266 | case Primitive::kPrimInt: |
| 2267 | case Primitive::kPrimNot: { |
| 2268 | uint32_t index = gp_index_++; |
| 2269 | stack_index_++; |
| 2270 | if (index < calling_convention.GetNumberOfRegisters()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2271 | return Location::RegisterLocation(calling_convention.GetRegisterAt(index)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2272 | } else { |
| 2273 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 1)); |
| 2274 | } |
| 2275 | } |
| 2276 | |
| 2277 | case Primitive::kPrimLong: { |
| 2278 | uint32_t index = gp_index_; |
| 2279 | stack_index_ += 2; |
| 2280 | if (index < calling_convention.GetNumberOfRegisters()) { |
| 2281 | gp_index_ += 1; |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2282 | return Location::RegisterLocation(calling_convention.GetRegisterAt(index)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2283 | } else { |
| 2284 | gp_index_ += 2; |
| 2285 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 2)); |
| 2286 | } |
| 2287 | } |
| 2288 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2289 | case Primitive::kPrimFloat: { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 2290 | uint32_t index = float_index_++; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2291 | stack_index_++; |
| 2292 | if (index < calling_convention.GetNumberOfFpuRegisters()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2293 | return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(index)); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2294 | } else { |
| 2295 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 1)); |
| 2296 | } |
| 2297 | } |
| 2298 | |
| 2299 | case Primitive::kPrimDouble: { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 2300 | uint32_t index = float_index_++; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2301 | stack_index_ += 2; |
| 2302 | if (index < calling_convention.GetNumberOfFpuRegisters()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2303 | return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(index)); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2304 | } else { |
| 2305 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 2)); |
| 2306 | } |
| 2307 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2308 | |
| 2309 | case Primitive::kPrimVoid: |
| 2310 | LOG(FATAL) << "Unexpected parameter type " << type; |
| 2311 | break; |
| 2312 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2313 | return Location::NoLocation(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2314 | } |
| 2315 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 2316 | void LocationsBuilderX86_64::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 2317 | // The trampoline uses the same calling convention as dex calling conventions, |
| 2318 | // except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain |
| 2319 | // the method_idx. |
| 2320 | HandleInvoke(invoke); |
| 2321 | } |
| 2322 | |
| 2323 | void InstructionCodeGeneratorX86_64::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 2324 | codegen_->GenerateInvokeUnresolvedRuntimeCall(invoke); |
| 2325 | } |
| 2326 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 2327 | void LocationsBuilderX86_64::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 2328 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 2329 | // art::PrepareForRegisterAllocation. |
| 2330 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 2331 | |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 2332 | IntrinsicLocationsBuilderX86_64 intrinsic(codegen_); |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 2333 | if (intrinsic.TryDispatch(invoke)) { |
| 2334 | return; |
| 2335 | } |
| 2336 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2337 | HandleInvoke(invoke); |
| 2338 | } |
| 2339 | |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 2340 | static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorX86_64* codegen) { |
| 2341 | if (invoke->GetLocations()->Intrinsified()) { |
| 2342 | IntrinsicCodeGeneratorX86_64 intrinsic(codegen); |
| 2343 | intrinsic.Dispatch(invoke); |
| 2344 | return true; |
| 2345 | } |
| 2346 | return false; |
| 2347 | } |
| 2348 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 2349 | void InstructionCodeGeneratorX86_64::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 2350 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 2351 | // art::PrepareForRegisterAllocation. |
| 2352 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 2353 | |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 2354 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 2355 | return; |
| 2356 | } |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2357 | |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 2358 | LocationSummary* locations = invoke->GetLocations(); |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 2359 | codegen_->GenerateStaticOrDirectCall( |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 2360 | invoke, locations->HasTemps() ? locations->GetTemp(0) : Location::NoLocation()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 2361 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2362 | } |
| 2363 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2364 | void LocationsBuilderX86_64::HandleInvoke(HInvoke* invoke) { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 2365 | InvokeDexCallingConventionVisitorX86_64 calling_convention_visitor; |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 2366 | CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2367 | } |
| 2368 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2369 | void LocationsBuilderX86_64::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 2370 | IntrinsicLocationsBuilderX86_64 intrinsic(codegen_); |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 2371 | if (intrinsic.TryDispatch(invoke)) { |
| 2372 | return; |
| 2373 | } |
| 2374 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2375 | HandleInvoke(invoke); |
| 2376 | } |
| 2377 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2378 | void InstructionCodeGeneratorX86_64::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 2379 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 2380 | return; |
| 2381 | } |
| 2382 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 2383 | codegen_->GenerateVirtualCall(invoke, invoke->GetLocations()->GetTemp(0)); |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 2384 | DCHECK(!codegen_->IsLeafMethod()); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2385 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2386 | } |
| 2387 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2388 | void LocationsBuilderX86_64::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 2389 | HandleInvoke(invoke); |
| 2390 | // Add the hidden argument. |
| 2391 | invoke->GetLocations()->AddTemp(Location::RegisterLocation(RAX)); |
| 2392 | } |
| 2393 | |
| 2394 | void InstructionCodeGeneratorX86_64::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 2395 | // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2396 | LocationSummary* locations = invoke->GetLocations(); |
| 2397 | CpuRegister temp = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 2398 | CpuRegister hidden_reg = locations->GetTemp(1).AsRegister<CpuRegister>(); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2399 | Location receiver = locations->InAt(0); |
| 2400 | size_t class_offset = mirror::Object::ClassOffset().SizeValue(); |
| 2401 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2402 | // Set the hidden argument. This is safe to do this here, as RAX |
| 2403 | // won't be modified thereafter, before the `call` instruction. |
| 2404 | DCHECK_EQ(RAX, hidden_reg.AsRegister()); |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 2405 | codegen_->Load64BitValue(hidden_reg, invoke->GetDexMethodIndex()); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2406 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2407 | if (receiver.IsStackSlot()) { |
| 2408 | __ movl(temp, Address(CpuRegister(RSP), receiver.GetStackIndex())); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2409 | // /* HeapReference<Class> */ temp = temp->klass_ |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2410 | __ movl(temp, Address(temp, class_offset)); |
| 2411 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2412 | // /* HeapReference<Class> */ temp = receiver->klass_ |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2413 | __ movl(temp, Address(receiver.AsRegister<CpuRegister>(), class_offset)); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2414 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 2415 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2416 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 2417 | // emit a read barrier for the previous class reference load. |
| 2418 | // However this is not required in practice, as this is an |
| 2419 | // intermediate/temporary reference and because the current |
| 2420 | // concurrent copying collector keeps the from-space memory |
| 2421 | // intact/accessible until the end of the marking phase (the |
| 2422 | // concurrent copying collector may not in the future). |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2423 | __ MaybeUnpoisonHeapReference(temp); |
Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 2424 | // temp = temp->GetAddressOfIMT() |
| 2425 | __ movq(temp, |
| 2426 | Address(temp, mirror::Class::ImtPtrOffset(kX86_64PointerSize).Uint32Value())); |
| 2427 | // temp = temp->GetImtEntryAt(method_offset); |
| 2428 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 2429 | invoke->GetImtIndex(), kX86_64PointerSize)); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2430 | // temp = temp->GetImtEntryAt(method_offset); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 2431 | __ movq(temp, Address(temp, method_offset)); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2432 | // call temp->GetEntryPoint(); |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 2433 | __ call(Address( |
| 2434 | temp, ArtMethod::EntryPointFromQuickCompiledCodeOffset(kX86_64PointerSize).SizeValue())); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2435 | |
| 2436 | DCHECK(!codegen_->IsLeafMethod()); |
| 2437 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 2438 | } |
| 2439 | |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 2440 | void LocationsBuilderX86_64::VisitInvokePolymorphic(HInvokePolymorphic* invoke) { |
| 2441 | HandleInvoke(invoke); |
| 2442 | } |
| 2443 | |
| 2444 | void InstructionCodeGeneratorX86_64::VisitInvokePolymorphic(HInvokePolymorphic* invoke) { |
| 2445 | codegen_->GenerateInvokePolymorphicCall(invoke); |
| 2446 | } |
| 2447 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2448 | void LocationsBuilderX86_64::VisitNeg(HNeg* neg) { |
| 2449 | LocationSummary* locations = |
| 2450 | new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall); |
| 2451 | switch (neg->GetResultType()) { |
| 2452 | case Primitive::kPrimInt: |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 2453 | case Primitive::kPrimLong: |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2454 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2455 | locations->SetOut(Location::SameAsFirstInput()); |
| 2456 | break; |
| 2457 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2458 | case Primitive::kPrimFloat: |
| 2459 | case Primitive::kPrimDouble: |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2460 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2461 | locations->SetOut(Location::SameAsFirstInput()); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2462 | locations->AddTemp(Location::RequiresFpuRegister()); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2463 | break; |
| 2464 | |
| 2465 | default: |
| 2466 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 2467 | } |
| 2468 | } |
| 2469 | |
| 2470 | void InstructionCodeGeneratorX86_64::VisitNeg(HNeg* neg) { |
| 2471 | LocationSummary* locations = neg->GetLocations(); |
| 2472 | Location out = locations->Out(); |
| 2473 | Location in = locations->InAt(0); |
| 2474 | switch (neg->GetResultType()) { |
| 2475 | case Primitive::kPrimInt: |
| 2476 | DCHECK(in.IsRegister()); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2477 | DCHECK(in.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2478 | __ negl(out.AsRegister<CpuRegister>()); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2479 | break; |
| 2480 | |
| 2481 | case Primitive::kPrimLong: |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 2482 | DCHECK(in.IsRegister()); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2483 | DCHECK(in.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2484 | __ negq(out.AsRegister<CpuRegister>()); |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 2485 | break; |
| 2486 | |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2487 | case Primitive::kPrimFloat: { |
| 2488 | DCHECK(in.Equals(out)); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2489 | XmmRegister mask = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2490 | // Implement float negation with an exclusive or with value |
| 2491 | // 0x80000000 (mask for bit 31, representing the sign of a |
| 2492 | // single-precision floating-point number). |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2493 | __ movss(mask, codegen_->LiteralInt32Address(0x80000000)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2494 | __ xorps(out.AsFpuRegister<XmmRegister>(), mask); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2495 | break; |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2496 | } |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2497 | |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2498 | case Primitive::kPrimDouble: { |
| 2499 | DCHECK(in.Equals(out)); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2500 | XmmRegister mask = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2501 | // Implement double negation with an exclusive or with value |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2502 | // 0x8000000000000000 (mask for bit 63, representing the sign of |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2503 | // a double-precision floating-point number). |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2504 | __ movsd(mask, codegen_->LiteralInt64Address(INT64_C(0x8000000000000000))); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2505 | __ xorpd(out.AsFpuRegister<XmmRegister>(), mask); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2506 | break; |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2507 | } |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2508 | |
| 2509 | default: |
| 2510 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 2511 | } |
| 2512 | } |
| 2513 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2514 | void LocationsBuilderX86_64::VisitTypeConversion(HTypeConversion* conversion) { |
| 2515 | LocationSummary* locations = |
| 2516 | new (GetGraph()->GetArena()) LocationSummary(conversion, LocationSummary::kNoCall); |
| 2517 | Primitive::Type result_type = conversion->GetResultType(); |
| 2518 | Primitive::Type input_type = conversion->GetInputType(); |
Nicolas Geoffray | 01fcc9e | 2014-12-01 14:16:20 +0000 | [diff] [blame] | 2519 | DCHECK_NE(result_type, input_type); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2520 | |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 2521 | // The Java language does not allow treating boolean as an integral type but |
| 2522 | // our bit representation makes it safe. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2523 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2524 | switch (result_type) { |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2525 | case Primitive::kPrimByte: |
| 2526 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2527 | case Primitive::kPrimLong: |
| 2528 | // Type conversion from long to byte is a result of code transformations. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2529 | case Primitive::kPrimBoolean: |
| 2530 | // Boolean input is a result of code transformations. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2531 | case Primitive::kPrimShort: |
| 2532 | case Primitive::kPrimInt: |
| 2533 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2534 | // Processing a Dex `int-to-byte' instruction. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2535 | locations->SetInAt(0, Location::Any()); |
| 2536 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2537 | break; |
| 2538 | |
| 2539 | default: |
| 2540 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2541 | << " to " << result_type; |
| 2542 | } |
| 2543 | break; |
| 2544 | |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2545 | case Primitive::kPrimShort: |
| 2546 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2547 | case Primitive::kPrimLong: |
| 2548 | // Type conversion from long to short is a result of code transformations. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2549 | case Primitive::kPrimBoolean: |
| 2550 | // Boolean input is a result of code transformations. |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2551 | case Primitive::kPrimByte: |
| 2552 | case Primitive::kPrimInt: |
| 2553 | case Primitive::kPrimChar: |
| 2554 | // Processing a Dex `int-to-short' instruction. |
| 2555 | locations->SetInAt(0, Location::Any()); |
| 2556 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2557 | break; |
| 2558 | |
| 2559 | default: |
| 2560 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2561 | << " to " << result_type; |
| 2562 | } |
| 2563 | break; |
| 2564 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2565 | case Primitive::kPrimInt: |
| 2566 | switch (input_type) { |
| 2567 | case Primitive::kPrimLong: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2568 | // Processing a Dex `long-to-int' instruction. |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2569 | locations->SetInAt(0, Location::Any()); |
| 2570 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2571 | break; |
| 2572 | |
| 2573 | case Primitive::kPrimFloat: |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2574 | // Processing a Dex `float-to-int' instruction. |
| 2575 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2576 | locations->SetOut(Location::RequiresRegister()); |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2577 | break; |
| 2578 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2579 | case Primitive::kPrimDouble: |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2580 | // Processing a Dex `double-to-int' instruction. |
| 2581 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2582 | locations->SetOut(Location::RequiresRegister()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2583 | break; |
| 2584 | |
| 2585 | default: |
| 2586 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2587 | << " to " << result_type; |
| 2588 | } |
| 2589 | break; |
| 2590 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2591 | case Primitive::kPrimLong: |
| 2592 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2593 | case Primitive::kPrimBoolean: |
| 2594 | // Boolean input is a result of code transformations. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2595 | case Primitive::kPrimByte: |
| 2596 | case Primitive::kPrimShort: |
| 2597 | case Primitive::kPrimInt: |
Roland Levillain | 666c732 | 2014-11-10 13:39:43 +0000 | [diff] [blame] | 2598 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2599 | // Processing a Dex `int-to-long' instruction. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2600 | // TODO: We would benefit from a (to-be-implemented) |
| 2601 | // Location::RegisterOrStackSlot requirement for this input. |
| 2602 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2603 | locations->SetOut(Location::RequiresRegister()); |
| 2604 | break; |
| 2605 | |
| 2606 | case Primitive::kPrimFloat: |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2607 | // Processing a Dex `float-to-long' instruction. |
| 2608 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2609 | locations->SetOut(Location::RequiresRegister()); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2610 | break; |
| 2611 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2612 | case Primitive::kPrimDouble: |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2613 | // Processing a Dex `double-to-long' instruction. |
| 2614 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2615 | locations->SetOut(Location::RequiresRegister()); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2616 | break; |
| 2617 | |
| 2618 | default: |
| 2619 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2620 | << " to " << result_type; |
| 2621 | } |
| 2622 | break; |
| 2623 | |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2624 | case Primitive::kPrimChar: |
| 2625 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2626 | case Primitive::kPrimLong: |
| 2627 | // Type conversion from long to char is a result of code transformations. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2628 | case Primitive::kPrimBoolean: |
| 2629 | // Boolean input is a result of code transformations. |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2630 | case Primitive::kPrimByte: |
| 2631 | case Primitive::kPrimShort: |
| 2632 | case Primitive::kPrimInt: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2633 | // Processing a Dex `int-to-char' instruction. |
| 2634 | locations->SetInAt(0, Location::Any()); |
| 2635 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2636 | break; |
| 2637 | |
| 2638 | default: |
| 2639 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2640 | << " to " << result_type; |
| 2641 | } |
| 2642 | break; |
| 2643 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2644 | case Primitive::kPrimFloat: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2645 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2646 | case Primitive::kPrimBoolean: |
| 2647 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2648 | case Primitive::kPrimByte: |
| 2649 | case Primitive::kPrimShort: |
| 2650 | case Primitive::kPrimInt: |
| 2651 | case Primitive::kPrimChar: |
| 2652 | // Processing a Dex `int-to-float' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2653 | locations->SetInAt(0, Location::Any()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2654 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2655 | break; |
| 2656 | |
| 2657 | case Primitive::kPrimLong: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2658 | // Processing a Dex `long-to-float' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2659 | locations->SetInAt(0, Location::Any()); |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2660 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2661 | break; |
| 2662 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2663 | case Primitive::kPrimDouble: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2664 | // Processing a Dex `double-to-float' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2665 | locations->SetInAt(0, Location::Any()); |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2666 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2667 | break; |
| 2668 | |
| 2669 | default: |
| 2670 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2671 | << " to " << result_type; |
| 2672 | }; |
| 2673 | break; |
| 2674 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2675 | case Primitive::kPrimDouble: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2676 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2677 | case Primitive::kPrimBoolean: |
| 2678 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2679 | case Primitive::kPrimByte: |
| 2680 | case Primitive::kPrimShort: |
| 2681 | case Primitive::kPrimInt: |
| 2682 | case Primitive::kPrimChar: |
| 2683 | // Processing a Dex `int-to-double' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2684 | locations->SetInAt(0, Location::Any()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2685 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2686 | break; |
| 2687 | |
| 2688 | case Primitive::kPrimLong: |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2689 | // Processing a Dex `long-to-double' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2690 | locations->SetInAt(0, Location::Any()); |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2691 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2692 | break; |
| 2693 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2694 | case Primitive::kPrimFloat: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2695 | // Processing a Dex `float-to-double' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2696 | locations->SetInAt(0, Location::Any()); |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2697 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2698 | break; |
| 2699 | |
| 2700 | default: |
| 2701 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2702 | << " to " << result_type; |
| 2703 | } |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2704 | break; |
| 2705 | |
| 2706 | default: |
| 2707 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2708 | << " to " << result_type; |
| 2709 | } |
| 2710 | } |
| 2711 | |
| 2712 | void InstructionCodeGeneratorX86_64::VisitTypeConversion(HTypeConversion* conversion) { |
| 2713 | LocationSummary* locations = conversion->GetLocations(); |
| 2714 | Location out = locations->Out(); |
| 2715 | Location in = locations->InAt(0); |
| 2716 | Primitive::Type result_type = conversion->GetResultType(); |
| 2717 | Primitive::Type input_type = conversion->GetInputType(); |
Nicolas Geoffray | 01fcc9e | 2014-12-01 14:16:20 +0000 | [diff] [blame] | 2718 | DCHECK_NE(result_type, input_type); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2719 | switch (result_type) { |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2720 | case Primitive::kPrimByte: |
| 2721 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2722 | case Primitive::kPrimLong: |
| 2723 | // Type conversion from long to byte is a result of code transformations. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2724 | case Primitive::kPrimBoolean: |
| 2725 | // Boolean input is a result of code transformations. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2726 | case Primitive::kPrimShort: |
| 2727 | case Primitive::kPrimInt: |
| 2728 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2729 | // Processing a Dex `int-to-byte' instruction. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2730 | if (in.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2731 | __ movsxb(out.AsRegister<CpuRegister>(), in.AsRegister<CpuRegister>()); |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2732 | } else if (in.IsStackSlot() || in.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2733 | __ movsxb(out.AsRegister<CpuRegister>(), |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2734 | Address(CpuRegister(RSP), in.GetStackIndex())); |
| 2735 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2736 | __ movl(out.AsRegister<CpuRegister>(), |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2737 | Immediate(static_cast<int8_t>(Int64FromConstant(in.GetConstant())))); |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2738 | } |
| 2739 | break; |
| 2740 | |
| 2741 | default: |
| 2742 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2743 | << " to " << result_type; |
| 2744 | } |
| 2745 | break; |
| 2746 | |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2747 | case Primitive::kPrimShort: |
| 2748 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2749 | case Primitive::kPrimLong: |
| 2750 | // Type conversion from long to short is a result of code transformations. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2751 | case Primitive::kPrimBoolean: |
| 2752 | // Boolean input is a result of code transformations. |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2753 | case Primitive::kPrimByte: |
| 2754 | case Primitive::kPrimInt: |
| 2755 | case Primitive::kPrimChar: |
| 2756 | // Processing a Dex `int-to-short' instruction. |
| 2757 | if (in.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2758 | __ movsxw(out.AsRegister<CpuRegister>(), in.AsRegister<CpuRegister>()); |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2759 | } else if (in.IsStackSlot() || in.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2760 | __ movsxw(out.AsRegister<CpuRegister>(), |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2761 | Address(CpuRegister(RSP), in.GetStackIndex())); |
| 2762 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2763 | __ movl(out.AsRegister<CpuRegister>(), |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2764 | Immediate(static_cast<int16_t>(Int64FromConstant(in.GetConstant())))); |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2765 | } |
| 2766 | break; |
| 2767 | |
| 2768 | default: |
| 2769 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2770 | << " to " << result_type; |
| 2771 | } |
| 2772 | break; |
| 2773 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2774 | case Primitive::kPrimInt: |
| 2775 | switch (input_type) { |
| 2776 | case Primitive::kPrimLong: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2777 | // Processing a Dex `long-to-int' instruction. |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2778 | if (in.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2779 | __ movl(out.AsRegister<CpuRegister>(), in.AsRegister<CpuRegister>()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2780 | } else if (in.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2781 | __ movl(out.AsRegister<CpuRegister>(), |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2782 | Address(CpuRegister(RSP), in.GetStackIndex())); |
| 2783 | } else { |
| 2784 | DCHECK(in.IsConstant()); |
| 2785 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 2786 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2787 | __ movl(out.AsRegister<CpuRegister>(), Immediate(static_cast<int32_t>(value))); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2788 | } |
| 2789 | break; |
| 2790 | |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2791 | case Primitive::kPrimFloat: { |
| 2792 | // Processing a Dex `float-to-int' instruction. |
| 2793 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 2794 | CpuRegister output = out.AsRegister<CpuRegister>(); |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2795 | NearLabel done, nan; |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2796 | |
| 2797 | __ movl(output, Immediate(kPrimIntMax)); |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 2798 | // if input >= (float)INT_MAX goto done |
| 2799 | __ comiss(input, codegen_->LiteralFloatAddress(kPrimIntMax)); |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2800 | __ j(kAboveEqual, &done); |
| 2801 | // if input == NaN goto nan |
| 2802 | __ j(kUnordered, &nan); |
| 2803 | // output = float-to-int-truncate(input) |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2804 | __ cvttss2si(output, input, false); |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2805 | __ jmp(&done); |
| 2806 | __ Bind(&nan); |
| 2807 | // output = 0 |
| 2808 | __ xorl(output, output); |
| 2809 | __ Bind(&done); |
| 2810 | break; |
| 2811 | } |
| 2812 | |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2813 | case Primitive::kPrimDouble: { |
| 2814 | // Processing a Dex `double-to-int' instruction. |
| 2815 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 2816 | CpuRegister output = out.AsRegister<CpuRegister>(); |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2817 | NearLabel done, nan; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2818 | |
| 2819 | __ movl(output, Immediate(kPrimIntMax)); |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 2820 | // if input >= (double)INT_MAX goto done |
| 2821 | __ comisd(input, codegen_->LiteralDoubleAddress(kPrimIntMax)); |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2822 | __ j(kAboveEqual, &done); |
| 2823 | // if input == NaN goto nan |
| 2824 | __ j(kUnordered, &nan); |
| 2825 | // output = double-to-int-truncate(input) |
| 2826 | __ cvttsd2si(output, input); |
| 2827 | __ jmp(&done); |
| 2828 | __ Bind(&nan); |
| 2829 | // output = 0 |
| 2830 | __ xorl(output, output); |
| 2831 | __ Bind(&done); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2832 | break; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2833 | } |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2834 | |
| 2835 | default: |
| 2836 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2837 | << " to " << result_type; |
| 2838 | } |
| 2839 | break; |
| 2840 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2841 | case Primitive::kPrimLong: |
| 2842 | switch (input_type) { |
| 2843 | DCHECK(out.IsRegister()); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2844 | case Primitive::kPrimBoolean: |
| 2845 | // Boolean input is a result of code transformations. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2846 | case Primitive::kPrimByte: |
| 2847 | case Primitive::kPrimShort: |
| 2848 | case Primitive::kPrimInt: |
Roland Levillain | 666c732 | 2014-11-10 13:39:43 +0000 | [diff] [blame] | 2849 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2850 | // Processing a Dex `int-to-long' instruction. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2851 | DCHECK(in.IsRegister()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2852 | __ movsxd(out.AsRegister<CpuRegister>(), in.AsRegister<CpuRegister>()); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2853 | break; |
| 2854 | |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2855 | case Primitive::kPrimFloat: { |
| 2856 | // Processing a Dex `float-to-long' instruction. |
| 2857 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 2858 | CpuRegister output = out.AsRegister<CpuRegister>(); |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2859 | NearLabel done, nan; |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2860 | |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 2861 | codegen_->Load64BitValue(output, kPrimLongMax); |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 2862 | // if input >= (float)LONG_MAX goto done |
| 2863 | __ comiss(input, codegen_->LiteralFloatAddress(kPrimLongMax)); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2864 | __ j(kAboveEqual, &done); |
| 2865 | // if input == NaN goto nan |
| 2866 | __ j(kUnordered, &nan); |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2867 | // output = float-to-long-truncate(input) |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2868 | __ cvttss2si(output, input, true); |
| 2869 | __ jmp(&done); |
| 2870 | __ Bind(&nan); |
| 2871 | // output = 0 |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 2872 | __ xorl(output, output); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2873 | __ Bind(&done); |
| 2874 | break; |
| 2875 | } |
| 2876 | |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2877 | case Primitive::kPrimDouble: { |
| 2878 | // Processing a Dex `double-to-long' instruction. |
| 2879 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 2880 | CpuRegister output = out.AsRegister<CpuRegister>(); |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2881 | NearLabel done, nan; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2882 | |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 2883 | codegen_->Load64BitValue(output, kPrimLongMax); |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 2884 | // if input >= (double)LONG_MAX goto done |
| 2885 | __ comisd(input, codegen_->LiteralDoubleAddress(kPrimLongMax)); |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2886 | __ j(kAboveEqual, &done); |
| 2887 | // if input == NaN goto nan |
| 2888 | __ j(kUnordered, &nan); |
| 2889 | // output = double-to-long-truncate(input) |
| 2890 | __ cvttsd2si(output, input, true); |
| 2891 | __ jmp(&done); |
| 2892 | __ Bind(&nan); |
| 2893 | // output = 0 |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 2894 | __ xorl(output, output); |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2895 | __ Bind(&done); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2896 | break; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2897 | } |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2898 | |
| 2899 | default: |
| 2900 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2901 | << " to " << result_type; |
| 2902 | } |
| 2903 | break; |
| 2904 | |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2905 | case Primitive::kPrimChar: |
| 2906 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2907 | case Primitive::kPrimLong: |
| 2908 | // Type conversion from long to char is a result of code transformations. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2909 | case Primitive::kPrimBoolean: |
| 2910 | // Boolean input is a result of code transformations. |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2911 | case Primitive::kPrimByte: |
| 2912 | case Primitive::kPrimShort: |
| 2913 | case Primitive::kPrimInt: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2914 | // Processing a Dex `int-to-char' instruction. |
| 2915 | if (in.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2916 | __ movzxw(out.AsRegister<CpuRegister>(), in.AsRegister<CpuRegister>()); |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2917 | } else if (in.IsStackSlot() || in.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2918 | __ movzxw(out.AsRegister<CpuRegister>(), |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2919 | Address(CpuRegister(RSP), in.GetStackIndex())); |
| 2920 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2921 | __ movl(out.AsRegister<CpuRegister>(), |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2922 | Immediate(static_cast<uint16_t>(Int64FromConstant(in.GetConstant())))); |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2923 | } |
| 2924 | break; |
| 2925 | |
| 2926 | default: |
| 2927 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2928 | << " to " << result_type; |
| 2929 | } |
| 2930 | break; |
| 2931 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2932 | case Primitive::kPrimFloat: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2933 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2934 | case Primitive::kPrimBoolean: |
| 2935 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2936 | case Primitive::kPrimByte: |
| 2937 | case Primitive::kPrimShort: |
| 2938 | case Primitive::kPrimInt: |
| 2939 | case Primitive::kPrimChar: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2940 | // Processing a Dex `int-to-float' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2941 | if (in.IsRegister()) { |
| 2942 | __ cvtsi2ss(out.AsFpuRegister<XmmRegister>(), in.AsRegister<CpuRegister>(), false); |
| 2943 | } else if (in.IsConstant()) { |
| 2944 | int32_t v = in.GetConstant()->AsIntConstant()->GetValue(); |
| 2945 | XmmRegister dest = out.AsFpuRegister<XmmRegister>(); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 2946 | codegen_->Load32BitValue(dest, static_cast<float>(v)); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2947 | } else { |
| 2948 | __ cvtsi2ss(out.AsFpuRegister<XmmRegister>(), |
| 2949 | Address(CpuRegister(RSP), in.GetStackIndex()), false); |
| 2950 | } |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2951 | break; |
| 2952 | |
| 2953 | case Primitive::kPrimLong: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2954 | // Processing a Dex `long-to-float' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2955 | if (in.IsRegister()) { |
| 2956 | __ cvtsi2ss(out.AsFpuRegister<XmmRegister>(), in.AsRegister<CpuRegister>(), true); |
| 2957 | } else if (in.IsConstant()) { |
| 2958 | int64_t v = in.GetConstant()->AsLongConstant()->GetValue(); |
| 2959 | XmmRegister dest = out.AsFpuRegister<XmmRegister>(); |
Pavel Vyssotski | 4c858cd | 2016-03-16 13:59:53 +0600 | [diff] [blame] | 2960 | codegen_->Load32BitValue(dest, static_cast<float>(v)); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2961 | } else { |
| 2962 | __ cvtsi2ss(out.AsFpuRegister<XmmRegister>(), |
| 2963 | Address(CpuRegister(RSP), in.GetStackIndex()), true); |
| 2964 | } |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2965 | break; |
| 2966 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2967 | case Primitive::kPrimDouble: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2968 | // Processing a Dex `double-to-float' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2969 | if (in.IsFpuRegister()) { |
| 2970 | __ cvtsd2ss(out.AsFpuRegister<XmmRegister>(), in.AsFpuRegister<XmmRegister>()); |
| 2971 | } else if (in.IsConstant()) { |
| 2972 | double v = in.GetConstant()->AsDoubleConstant()->GetValue(); |
| 2973 | XmmRegister dest = out.AsFpuRegister<XmmRegister>(); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 2974 | codegen_->Load32BitValue(dest, static_cast<float>(v)); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2975 | } else { |
| 2976 | __ cvtsd2ss(out.AsFpuRegister<XmmRegister>(), |
| 2977 | Address(CpuRegister(RSP), in.GetStackIndex())); |
| 2978 | } |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2979 | break; |
| 2980 | |
| 2981 | default: |
| 2982 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2983 | << " to " << result_type; |
| 2984 | }; |
| 2985 | break; |
| 2986 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2987 | case Primitive::kPrimDouble: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2988 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2989 | case Primitive::kPrimBoolean: |
| 2990 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2991 | case Primitive::kPrimByte: |
| 2992 | case Primitive::kPrimShort: |
| 2993 | case Primitive::kPrimInt: |
| 2994 | case Primitive::kPrimChar: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2995 | // Processing a Dex `int-to-double' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2996 | if (in.IsRegister()) { |
| 2997 | __ cvtsi2sd(out.AsFpuRegister<XmmRegister>(), in.AsRegister<CpuRegister>(), false); |
| 2998 | } else if (in.IsConstant()) { |
| 2999 | int32_t v = in.GetConstant()->AsIntConstant()->GetValue(); |
| 3000 | XmmRegister dest = out.AsFpuRegister<XmmRegister>(); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 3001 | codegen_->Load64BitValue(dest, static_cast<double>(v)); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 3002 | } else { |
| 3003 | __ cvtsi2sd(out.AsFpuRegister<XmmRegister>(), |
| 3004 | Address(CpuRegister(RSP), in.GetStackIndex()), false); |
| 3005 | } |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3006 | break; |
| 3007 | |
| 3008 | case Primitive::kPrimLong: |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 3009 | // Processing a Dex `long-to-double' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 3010 | if (in.IsRegister()) { |
| 3011 | __ cvtsi2sd(out.AsFpuRegister<XmmRegister>(), in.AsRegister<CpuRegister>(), true); |
| 3012 | } else if (in.IsConstant()) { |
| 3013 | int64_t v = in.GetConstant()->AsLongConstant()->GetValue(); |
| 3014 | XmmRegister dest = out.AsFpuRegister<XmmRegister>(); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 3015 | codegen_->Load64BitValue(dest, static_cast<double>(v)); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 3016 | } else { |
| 3017 | __ cvtsi2sd(out.AsFpuRegister<XmmRegister>(), |
| 3018 | Address(CpuRegister(RSP), in.GetStackIndex()), true); |
| 3019 | } |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 3020 | break; |
| 3021 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3022 | case Primitive::kPrimFloat: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 3023 | // Processing a Dex `float-to-double' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 3024 | if (in.IsFpuRegister()) { |
| 3025 | __ cvtss2sd(out.AsFpuRegister<XmmRegister>(), in.AsFpuRegister<XmmRegister>()); |
| 3026 | } else if (in.IsConstant()) { |
| 3027 | float v = in.GetConstant()->AsFloatConstant()->GetValue(); |
| 3028 | XmmRegister dest = out.AsFpuRegister<XmmRegister>(); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 3029 | codegen_->Load64BitValue(dest, static_cast<double>(v)); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 3030 | } else { |
| 3031 | __ cvtss2sd(out.AsFpuRegister<XmmRegister>(), |
| 3032 | Address(CpuRegister(RSP), in.GetStackIndex())); |
| 3033 | } |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3034 | break; |
| 3035 | |
| 3036 | default: |
| 3037 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3038 | << " to " << result_type; |
| 3039 | }; |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3040 | break; |
| 3041 | |
| 3042 | default: |
| 3043 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3044 | << " to " << result_type; |
| 3045 | } |
| 3046 | } |
| 3047 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3048 | void LocationsBuilderX86_64::VisitAdd(HAdd* add) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3049 | LocationSummary* locations = |
| 3050 | new (GetGraph()->GetArena()) LocationSummary(add, LocationSummary::kNoCall); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3051 | switch (add->GetResultType()) { |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 3052 | case Primitive::kPrimInt: { |
| 3053 | locations->SetInAt(0, Location::RequiresRegister()); |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 3054 | locations->SetInAt(1, Location::RegisterOrConstant(add->InputAt(1))); |
| 3055 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 3056 | break; |
| 3057 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3058 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3059 | case Primitive::kPrimLong: { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 3060 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 3061 | // 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] | 3062 | locations->SetInAt(1, Location::RegisterOrInt32Constant(add->InputAt(1))); |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 3063 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3064 | break; |
| 3065 | } |
| 3066 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3067 | case Primitive::kPrimDouble: |
| 3068 | case Primitive::kPrimFloat: { |
| 3069 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3070 | locations->SetInAt(1, Location::Any()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3071 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3072 | break; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3073 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3074 | |
| 3075 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3076 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3077 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3078 | } |
| 3079 | |
| 3080 | void InstructionCodeGeneratorX86_64::VisitAdd(HAdd* add) { |
| 3081 | LocationSummary* locations = add->GetLocations(); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3082 | Location first = locations->InAt(0); |
| 3083 | Location second = locations->InAt(1); |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 3084 | Location out = locations->Out(); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3085 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3086 | switch (add->GetResultType()) { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 3087 | case Primitive::kPrimInt: { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3088 | if (second.IsRegister()) { |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 3089 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 3090 | __ addl(out.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Mark Mendell | 33bf245 | 2015-05-27 10:08:24 -0400 | [diff] [blame] | 3091 | } else if (out.AsRegister<Register>() == second.AsRegister<Register>()) { |
| 3092 | __ addl(out.AsRegister<CpuRegister>(), first.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 3093 | } else { |
| 3094 | __ leal(out.AsRegister<CpuRegister>(), Address( |
| 3095 | first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>(), TIMES_1, 0)); |
| 3096 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3097 | } else if (second.IsConstant()) { |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 3098 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 3099 | __ addl(out.AsRegister<CpuRegister>(), |
| 3100 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
| 3101 | } else { |
| 3102 | __ leal(out.AsRegister<CpuRegister>(), Address( |
| 3103 | first.AsRegister<CpuRegister>(), second.GetConstant()->AsIntConstant()->GetValue())); |
| 3104 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 3105 | } else { |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 3106 | DCHECK(first.Equals(locations->Out())); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3107 | __ addl(first.AsRegister<CpuRegister>(), Address(CpuRegister(RSP), second.GetStackIndex())); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 3108 | } |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 3109 | break; |
| 3110 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3111 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3112 | case Primitive::kPrimLong: { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 3113 | if (second.IsRegister()) { |
| 3114 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 3115 | __ addq(out.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Mark Mendell | 33bf245 | 2015-05-27 10:08:24 -0400 | [diff] [blame] | 3116 | } else if (out.AsRegister<Register>() == second.AsRegister<Register>()) { |
| 3117 | __ addq(out.AsRegister<CpuRegister>(), first.AsRegister<CpuRegister>()); |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 3118 | } else { |
| 3119 | __ leaq(out.AsRegister<CpuRegister>(), Address( |
| 3120 | first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>(), TIMES_1, 0)); |
| 3121 | } |
| 3122 | } else { |
| 3123 | DCHECK(second.IsConstant()); |
| 3124 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 3125 | int32_t int32_value = Low32Bits(value); |
| 3126 | DCHECK_EQ(int32_value, value); |
| 3127 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 3128 | __ addq(out.AsRegister<CpuRegister>(), Immediate(int32_value)); |
| 3129 | } else { |
| 3130 | __ leaq(out.AsRegister<CpuRegister>(), Address( |
| 3131 | first.AsRegister<CpuRegister>(), int32_value)); |
| 3132 | } |
| 3133 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3134 | break; |
| 3135 | } |
| 3136 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3137 | case Primitive::kPrimFloat: { |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3138 | if (second.IsFpuRegister()) { |
| 3139 | __ addss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3140 | } else if (second.IsConstant()) { |
| 3141 | __ addss(first.AsFpuRegister<XmmRegister>(), |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 3142 | codegen_->LiteralFloatAddress( |
| 3143 | second.GetConstant()->AsFloatConstant()->GetValue())); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3144 | } else { |
| 3145 | DCHECK(second.IsStackSlot()); |
| 3146 | __ addss(first.AsFpuRegister<XmmRegister>(), |
| 3147 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 3148 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3149 | break; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3150 | } |
| 3151 | |
| 3152 | case Primitive::kPrimDouble: { |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3153 | if (second.IsFpuRegister()) { |
| 3154 | __ addsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3155 | } else if (second.IsConstant()) { |
| 3156 | __ addsd(first.AsFpuRegister<XmmRegister>(), |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 3157 | codegen_->LiteralDoubleAddress( |
| 3158 | second.GetConstant()->AsDoubleConstant()->GetValue())); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3159 | } else { |
| 3160 | DCHECK(second.IsDoubleStackSlot()); |
| 3161 | __ addsd(first.AsFpuRegister<XmmRegister>(), |
| 3162 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 3163 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3164 | break; |
| 3165 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3166 | |
| 3167 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3168 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3169 | } |
| 3170 | } |
| 3171 | |
| 3172 | void LocationsBuilderX86_64::VisitSub(HSub* sub) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3173 | LocationSummary* locations = |
| 3174 | new (GetGraph()->GetArena()) LocationSummary(sub, LocationSummary::kNoCall); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3175 | switch (sub->GetResultType()) { |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 3176 | case Primitive::kPrimInt: { |
| 3177 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3178 | locations->SetInAt(1, Location::Any()); |
| 3179 | locations->SetOut(Location::SameAsFirstInput()); |
| 3180 | break; |
| 3181 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3182 | case Primitive::kPrimLong: { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 3183 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 3184 | locations->SetInAt(1, Location::RegisterOrInt32Constant(sub->InputAt(1))); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 3185 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3186 | break; |
| 3187 | } |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3188 | case Primitive::kPrimFloat: |
| 3189 | case Primitive::kPrimDouble: { |
| 3190 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3191 | locations->SetInAt(1, Location::Any()); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3192 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3193 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3194 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3195 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3196 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3197 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3198 | } |
| 3199 | |
| 3200 | void InstructionCodeGeneratorX86_64::VisitSub(HSub* sub) { |
| 3201 | LocationSummary* locations = sub->GetLocations(); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3202 | Location first = locations->InAt(0); |
| 3203 | Location second = locations->InAt(1); |
| 3204 | DCHECK(first.Equals(locations->Out())); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3205 | switch (sub->GetResultType()) { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 3206 | case Primitive::kPrimInt: { |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3207 | if (second.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3208 | __ subl(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3209 | } else if (second.IsConstant()) { |
| 3210 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3211 | __ subl(first.AsRegister<CpuRegister>(), imm); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 3212 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3213 | __ subl(first.AsRegister<CpuRegister>(), Address(CpuRegister(RSP), second.GetStackIndex())); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 3214 | } |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 3215 | break; |
| 3216 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3217 | case Primitive::kPrimLong: { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 3218 | if (second.IsConstant()) { |
| 3219 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 3220 | DCHECK(IsInt<32>(value)); |
| 3221 | __ subq(first.AsRegister<CpuRegister>(), Immediate(static_cast<int32_t>(value))); |
| 3222 | } else { |
| 3223 | __ subq(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
| 3224 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3225 | break; |
| 3226 | } |
| 3227 | |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3228 | case Primitive::kPrimFloat: { |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3229 | if (second.IsFpuRegister()) { |
| 3230 | __ subss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3231 | } else if (second.IsConstant()) { |
| 3232 | __ subss(first.AsFpuRegister<XmmRegister>(), |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 3233 | codegen_->LiteralFloatAddress( |
| 3234 | second.GetConstant()->AsFloatConstant()->GetValue())); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3235 | } else { |
| 3236 | DCHECK(second.IsStackSlot()); |
| 3237 | __ subss(first.AsFpuRegister<XmmRegister>(), |
| 3238 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 3239 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3240 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3241 | } |
| 3242 | |
| 3243 | case Primitive::kPrimDouble: { |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3244 | if (second.IsFpuRegister()) { |
| 3245 | __ subsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3246 | } else if (second.IsConstant()) { |
| 3247 | __ subsd(first.AsFpuRegister<XmmRegister>(), |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 3248 | codegen_->LiteralDoubleAddress( |
| 3249 | second.GetConstant()->AsDoubleConstant()->GetValue())); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3250 | } else { |
| 3251 | DCHECK(second.IsDoubleStackSlot()); |
| 3252 | __ subsd(first.AsFpuRegister<XmmRegister>(), |
| 3253 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 3254 | } |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3255 | break; |
| 3256 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3257 | |
| 3258 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3259 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3260 | } |
| 3261 | } |
| 3262 | |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3263 | void LocationsBuilderX86_64::VisitMul(HMul* mul) { |
| 3264 | LocationSummary* locations = |
| 3265 | new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall); |
| 3266 | switch (mul->GetResultType()) { |
| 3267 | case Primitive::kPrimInt: { |
| 3268 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3269 | locations->SetInAt(1, Location::Any()); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3270 | if (mul->InputAt(1)->IsIntConstant()) { |
| 3271 | // Can use 3 operand multiply. |
| 3272 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3273 | } else { |
| 3274 | locations->SetOut(Location::SameAsFirstInput()); |
| 3275 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3276 | break; |
| 3277 | } |
| 3278 | case Primitive::kPrimLong: { |
| 3279 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3280 | locations->SetInAt(1, Location::Any()); |
| 3281 | if (mul->InputAt(1)->IsLongConstant() && |
| 3282 | IsInt<32>(mul->InputAt(1)->AsLongConstant()->GetValue())) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 3283 | // Can use 3 operand multiply. |
| 3284 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3285 | } else { |
| 3286 | locations->SetOut(Location::SameAsFirstInput()); |
| 3287 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3288 | break; |
| 3289 | } |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3290 | case Primitive::kPrimFloat: |
| 3291 | case Primitive::kPrimDouble: { |
| 3292 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3293 | locations->SetInAt(1, Location::Any()); |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3294 | locations->SetOut(Location::SameAsFirstInput()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3295 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3296 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3297 | |
| 3298 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3299 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3300 | } |
| 3301 | } |
| 3302 | |
| 3303 | void InstructionCodeGeneratorX86_64::VisitMul(HMul* mul) { |
| 3304 | LocationSummary* locations = mul->GetLocations(); |
| 3305 | Location first = locations->InAt(0); |
| 3306 | Location second = locations->InAt(1); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3307 | Location out = locations->Out(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3308 | switch (mul->GetResultType()) { |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3309 | case Primitive::kPrimInt: |
| 3310 | // The constant may have ended up in a register, so test explicitly to avoid |
| 3311 | // problems where the output may not be the same as the first operand. |
| 3312 | if (mul->InputAt(1)->IsIntConstant()) { |
| 3313 | Immediate imm(mul->InputAt(1)->AsIntConstant()->GetValue()); |
| 3314 | __ imull(out.AsRegister<CpuRegister>(), first.AsRegister<CpuRegister>(), imm); |
| 3315 | } else if (second.IsRegister()) { |
| 3316 | DCHECK(first.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3317 | __ imull(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3318 | } else { |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3319 | DCHECK(first.Equals(out)); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3320 | DCHECK(second.IsStackSlot()); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 3321 | __ imull(first.AsRegister<CpuRegister>(), |
| 3322 | Address(CpuRegister(RSP), second.GetStackIndex())); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3323 | } |
| 3324 | break; |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3325 | case Primitive::kPrimLong: { |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3326 | // The constant may have ended up in a register, so test explicitly to avoid |
| 3327 | // problems where the output may not be the same as the first operand. |
| 3328 | if (mul->InputAt(1)->IsLongConstant()) { |
| 3329 | int64_t value = mul->InputAt(1)->AsLongConstant()->GetValue(); |
| 3330 | if (IsInt<32>(value)) { |
| 3331 | __ imulq(out.AsRegister<CpuRegister>(), first.AsRegister<CpuRegister>(), |
| 3332 | Immediate(static_cast<int32_t>(value))); |
| 3333 | } else { |
| 3334 | // Have to use the constant area. |
| 3335 | DCHECK(first.Equals(out)); |
| 3336 | __ imulq(first.AsRegister<CpuRegister>(), codegen_->LiteralInt64Address(value)); |
| 3337 | } |
| 3338 | } else if (second.IsRegister()) { |
| 3339 | DCHECK(first.Equals(out)); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 3340 | __ imulq(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3341 | } else { |
| 3342 | DCHECK(second.IsDoubleStackSlot()); |
| 3343 | DCHECK(first.Equals(out)); |
| 3344 | __ imulq(first.AsRegister<CpuRegister>(), |
| 3345 | Address(CpuRegister(RSP), second.GetStackIndex())); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 3346 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3347 | break; |
| 3348 | } |
| 3349 | |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3350 | case Primitive::kPrimFloat: { |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3351 | DCHECK(first.Equals(out)); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3352 | if (second.IsFpuRegister()) { |
| 3353 | __ mulss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3354 | } else if (second.IsConstant()) { |
| 3355 | __ mulss(first.AsFpuRegister<XmmRegister>(), |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 3356 | codegen_->LiteralFloatAddress( |
| 3357 | second.GetConstant()->AsFloatConstant()->GetValue())); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3358 | } else { |
| 3359 | DCHECK(second.IsStackSlot()); |
| 3360 | __ mulss(first.AsFpuRegister<XmmRegister>(), |
| 3361 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 3362 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3363 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3364 | } |
| 3365 | |
| 3366 | case Primitive::kPrimDouble: { |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3367 | DCHECK(first.Equals(out)); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3368 | if (second.IsFpuRegister()) { |
| 3369 | __ mulsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3370 | } else if (second.IsConstant()) { |
| 3371 | __ mulsd(first.AsFpuRegister<XmmRegister>(), |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 3372 | codegen_->LiteralDoubleAddress( |
| 3373 | second.GetConstant()->AsDoubleConstant()->GetValue())); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3374 | } else { |
| 3375 | DCHECK(second.IsDoubleStackSlot()); |
| 3376 | __ mulsd(first.AsFpuRegister<XmmRegister>(), |
| 3377 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 3378 | } |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3379 | break; |
| 3380 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3381 | |
| 3382 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3383 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3384 | } |
| 3385 | } |
| 3386 | |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3387 | void InstructionCodeGeneratorX86_64::PushOntoFPStack(Location source, uint32_t temp_offset, |
| 3388 | uint32_t stack_adjustment, bool is_float) { |
| 3389 | if (source.IsStackSlot()) { |
| 3390 | DCHECK(is_float); |
| 3391 | __ flds(Address(CpuRegister(RSP), source.GetStackIndex() + stack_adjustment)); |
| 3392 | } else if (source.IsDoubleStackSlot()) { |
| 3393 | DCHECK(!is_float); |
| 3394 | __ fldl(Address(CpuRegister(RSP), source.GetStackIndex() + stack_adjustment)); |
| 3395 | } else { |
| 3396 | // Write the value to the temporary location on the stack and load to FP stack. |
| 3397 | if (is_float) { |
| 3398 | Location stack_temp = Location::StackSlot(temp_offset); |
| 3399 | codegen_->Move(stack_temp, source); |
| 3400 | __ flds(Address(CpuRegister(RSP), temp_offset)); |
| 3401 | } else { |
| 3402 | Location stack_temp = Location::DoubleStackSlot(temp_offset); |
| 3403 | codegen_->Move(stack_temp, source); |
| 3404 | __ fldl(Address(CpuRegister(RSP), temp_offset)); |
| 3405 | } |
| 3406 | } |
| 3407 | } |
| 3408 | |
| 3409 | void InstructionCodeGeneratorX86_64::GenerateRemFP(HRem *rem) { |
| 3410 | Primitive::Type type = rem->GetResultType(); |
| 3411 | bool is_float = type == Primitive::kPrimFloat; |
| 3412 | size_t elem_size = Primitive::ComponentSize(type); |
| 3413 | LocationSummary* locations = rem->GetLocations(); |
| 3414 | Location first = locations->InAt(0); |
| 3415 | Location second = locations->InAt(1); |
| 3416 | Location out = locations->Out(); |
| 3417 | |
| 3418 | // Create stack space for 2 elements. |
| 3419 | // TODO: enhance register allocator to ask for stack temporaries. |
| 3420 | __ subq(CpuRegister(RSP), Immediate(2 * elem_size)); |
| 3421 | |
| 3422 | // Load the values to the FP stack in reverse order, using temporaries if needed. |
| 3423 | PushOntoFPStack(second, elem_size, 2 * elem_size, is_float); |
| 3424 | PushOntoFPStack(first, 0, 2 * elem_size, is_float); |
| 3425 | |
| 3426 | // Loop doing FPREM until we stabilize. |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 3427 | NearLabel retry; |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3428 | __ Bind(&retry); |
| 3429 | __ fprem(); |
| 3430 | |
| 3431 | // Move FP status to AX. |
| 3432 | __ fstsw(); |
| 3433 | |
| 3434 | // And see if the argument reduction is complete. This is signaled by the |
| 3435 | // C2 FPU flag bit set to 0. |
| 3436 | __ andl(CpuRegister(RAX), Immediate(kC2ConditionMask)); |
| 3437 | __ j(kNotEqual, &retry); |
| 3438 | |
| 3439 | // We have settled on the final value. Retrieve it into an XMM register. |
| 3440 | // Store FP top of stack to real stack. |
| 3441 | if (is_float) { |
| 3442 | __ fsts(Address(CpuRegister(RSP), 0)); |
| 3443 | } else { |
| 3444 | __ fstl(Address(CpuRegister(RSP), 0)); |
| 3445 | } |
| 3446 | |
| 3447 | // Pop the 2 items from the FP stack. |
| 3448 | __ fucompp(); |
| 3449 | |
| 3450 | // Load the value from the stack into an XMM register. |
| 3451 | DCHECK(out.IsFpuRegister()) << out; |
| 3452 | if (is_float) { |
| 3453 | __ movss(out.AsFpuRegister<XmmRegister>(), Address(CpuRegister(RSP), 0)); |
| 3454 | } else { |
| 3455 | __ movsd(out.AsFpuRegister<XmmRegister>(), Address(CpuRegister(RSP), 0)); |
| 3456 | } |
| 3457 | |
| 3458 | // And remove the temporary stack space we allocated. |
| 3459 | __ addq(CpuRegister(RSP), Immediate(2 * elem_size)); |
| 3460 | } |
| 3461 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3462 | void InstructionCodeGeneratorX86_64::DivRemOneOrMinusOne(HBinaryOperation* instruction) { |
| 3463 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3464 | |
| 3465 | LocationSummary* locations = instruction->GetLocations(); |
| 3466 | Location second = locations->InAt(1); |
| 3467 | DCHECK(second.IsConstant()); |
| 3468 | |
| 3469 | CpuRegister output_register = locations->Out().AsRegister<CpuRegister>(); |
| 3470 | CpuRegister input_register = locations->InAt(0).AsRegister<CpuRegister>(); |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3471 | int64_t imm = Int64FromConstant(second.GetConstant()); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3472 | |
| 3473 | DCHECK(imm == 1 || imm == -1); |
| 3474 | |
| 3475 | switch (instruction->GetResultType()) { |
| 3476 | case Primitive::kPrimInt: { |
| 3477 | if (instruction->IsRem()) { |
| 3478 | __ xorl(output_register, output_register); |
| 3479 | } else { |
| 3480 | __ movl(output_register, input_register); |
| 3481 | if (imm == -1) { |
| 3482 | __ negl(output_register); |
| 3483 | } |
| 3484 | } |
| 3485 | break; |
| 3486 | } |
| 3487 | |
| 3488 | case Primitive::kPrimLong: { |
| 3489 | if (instruction->IsRem()) { |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 3490 | __ xorl(output_register, output_register); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3491 | } else { |
| 3492 | __ movq(output_register, input_register); |
| 3493 | if (imm == -1) { |
| 3494 | __ negq(output_register); |
| 3495 | } |
| 3496 | } |
| 3497 | break; |
| 3498 | } |
| 3499 | |
| 3500 | default: |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3501 | LOG(FATAL) << "Unexpected type for div by (-)1 " << instruction->GetResultType(); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3502 | } |
| 3503 | } |
| 3504 | |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3505 | void InstructionCodeGeneratorX86_64::DivByPowerOfTwo(HDiv* instruction) { |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3506 | LocationSummary* locations = instruction->GetLocations(); |
| 3507 | Location second = locations->InAt(1); |
| 3508 | |
| 3509 | CpuRegister output_register = locations->Out().AsRegister<CpuRegister>(); |
| 3510 | CpuRegister numerator = locations->InAt(0).AsRegister<CpuRegister>(); |
| 3511 | |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3512 | int64_t imm = Int64FromConstant(second.GetConstant()); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3513 | DCHECK(IsPowerOfTwo(AbsOrMin(imm))); |
| 3514 | uint64_t abs_imm = AbsOrMin(imm); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3515 | |
| 3516 | CpuRegister tmp = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 3517 | |
| 3518 | if (instruction->GetResultType() == Primitive::kPrimInt) { |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3519 | __ leal(tmp, Address(numerator, abs_imm - 1)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3520 | __ testl(numerator, numerator); |
| 3521 | __ cmov(kGreaterEqual, tmp, numerator); |
| 3522 | int shift = CTZ(imm); |
| 3523 | __ sarl(tmp, Immediate(shift)); |
| 3524 | |
| 3525 | if (imm < 0) { |
| 3526 | __ negl(tmp); |
| 3527 | } |
| 3528 | |
| 3529 | __ movl(output_register, tmp); |
| 3530 | } else { |
| 3531 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong); |
| 3532 | CpuRegister rdx = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 3533 | |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3534 | codegen_->Load64BitValue(rdx, abs_imm - 1); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3535 | __ addq(rdx, numerator); |
| 3536 | __ testq(numerator, numerator); |
| 3537 | __ cmov(kGreaterEqual, rdx, numerator); |
| 3538 | int shift = CTZ(imm); |
| 3539 | __ sarq(rdx, Immediate(shift)); |
| 3540 | |
| 3541 | if (imm < 0) { |
| 3542 | __ negq(rdx); |
| 3543 | } |
| 3544 | |
| 3545 | __ movq(output_register, rdx); |
| 3546 | } |
| 3547 | } |
| 3548 | |
| 3549 | void InstructionCodeGeneratorX86_64::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) { |
| 3550 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3551 | |
| 3552 | LocationSummary* locations = instruction->GetLocations(); |
| 3553 | Location second = locations->InAt(1); |
| 3554 | |
| 3555 | CpuRegister numerator = instruction->IsDiv() ? locations->GetTemp(1).AsRegister<CpuRegister>() |
| 3556 | : locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 3557 | CpuRegister eax = locations->InAt(0).AsRegister<CpuRegister>(); |
| 3558 | CpuRegister edx = instruction->IsDiv() ? locations->GetTemp(0).AsRegister<CpuRegister>() |
| 3559 | : locations->Out().AsRegister<CpuRegister>(); |
| 3560 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
| 3561 | |
| 3562 | DCHECK_EQ(RAX, eax.AsRegister()); |
| 3563 | DCHECK_EQ(RDX, edx.AsRegister()); |
| 3564 | if (instruction->IsDiv()) { |
| 3565 | DCHECK_EQ(RAX, out.AsRegister()); |
| 3566 | } else { |
| 3567 | DCHECK_EQ(RDX, out.AsRegister()); |
| 3568 | } |
| 3569 | |
| 3570 | int64_t magic; |
| 3571 | int shift; |
| 3572 | |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3573 | // TODO: can these branches be written as one? |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3574 | if (instruction->GetResultType() == Primitive::kPrimInt) { |
| 3575 | int imm = second.GetConstant()->AsIntConstant()->GetValue(); |
| 3576 | |
| 3577 | CalculateMagicAndShiftForDivRem(imm, false /* is_long */, &magic, &shift); |
| 3578 | |
| 3579 | __ movl(numerator, eax); |
| 3580 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3581 | __ movl(eax, Immediate(magic)); |
| 3582 | __ imull(numerator); |
| 3583 | |
| 3584 | if (imm > 0 && magic < 0) { |
| 3585 | __ addl(edx, numerator); |
| 3586 | } else if (imm < 0 && magic > 0) { |
| 3587 | __ subl(edx, numerator); |
| 3588 | } |
| 3589 | |
| 3590 | if (shift != 0) { |
| 3591 | __ sarl(edx, Immediate(shift)); |
| 3592 | } |
| 3593 | |
| 3594 | __ movl(eax, edx); |
| 3595 | __ shrl(edx, Immediate(31)); |
| 3596 | __ addl(edx, eax); |
| 3597 | |
| 3598 | if (instruction->IsRem()) { |
| 3599 | __ movl(eax, numerator); |
| 3600 | __ imull(edx, Immediate(imm)); |
| 3601 | __ subl(eax, edx); |
| 3602 | __ movl(edx, eax); |
| 3603 | } else { |
| 3604 | __ movl(eax, edx); |
| 3605 | } |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3606 | } else { |
| 3607 | int64_t imm = second.GetConstant()->AsLongConstant()->GetValue(); |
| 3608 | |
| 3609 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong); |
| 3610 | |
| 3611 | CpuRegister rax = eax; |
| 3612 | CpuRegister rdx = edx; |
| 3613 | |
| 3614 | CalculateMagicAndShiftForDivRem(imm, true /* is_long */, &magic, &shift); |
| 3615 | |
| 3616 | // Save the numerator. |
| 3617 | __ movq(numerator, rax); |
| 3618 | |
| 3619 | // RAX = magic |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 3620 | codegen_->Load64BitValue(rax, magic); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3621 | |
| 3622 | // RDX:RAX = magic * numerator |
| 3623 | __ imulq(numerator); |
| 3624 | |
| 3625 | if (imm > 0 && magic < 0) { |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3626 | // RDX += numerator |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3627 | __ addq(rdx, numerator); |
| 3628 | } else if (imm < 0 && magic > 0) { |
| 3629 | // RDX -= numerator |
| 3630 | __ subq(rdx, numerator); |
| 3631 | } |
| 3632 | |
| 3633 | // Shift if needed. |
| 3634 | if (shift != 0) { |
| 3635 | __ sarq(rdx, Immediate(shift)); |
| 3636 | } |
| 3637 | |
| 3638 | // RDX += 1 if RDX < 0 |
| 3639 | __ movq(rax, rdx); |
| 3640 | __ shrq(rdx, Immediate(63)); |
| 3641 | __ addq(rdx, rax); |
| 3642 | |
| 3643 | if (instruction->IsRem()) { |
| 3644 | __ movq(rax, numerator); |
| 3645 | |
| 3646 | if (IsInt<32>(imm)) { |
| 3647 | __ imulq(rdx, Immediate(static_cast<int32_t>(imm))); |
| 3648 | } else { |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 3649 | __ imulq(rdx, codegen_->LiteralInt64Address(imm)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3650 | } |
| 3651 | |
| 3652 | __ subq(rax, rdx); |
| 3653 | __ movq(rdx, rax); |
| 3654 | } else { |
| 3655 | __ movq(rax, rdx); |
| 3656 | } |
| 3657 | } |
| 3658 | } |
| 3659 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3660 | void InstructionCodeGeneratorX86_64::GenerateDivRemIntegral(HBinaryOperation* instruction) { |
| 3661 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3662 | Primitive::Type type = instruction->GetResultType(); |
| 3663 | DCHECK(type == Primitive::kPrimInt || Primitive::kPrimLong); |
| 3664 | |
| 3665 | bool is_div = instruction->IsDiv(); |
| 3666 | LocationSummary* locations = instruction->GetLocations(); |
| 3667 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3668 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
| 3669 | Location second = locations->InAt(1); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3670 | |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3671 | DCHECK_EQ(RAX, locations->InAt(0).AsRegister<CpuRegister>().AsRegister()); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3672 | DCHECK_EQ(is_div ? RAX : RDX, out.AsRegister()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3673 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3674 | if (second.IsConstant()) { |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3675 | int64_t imm = Int64FromConstant(second.GetConstant()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3676 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3677 | if (imm == 0) { |
| 3678 | // Do not generate anything. DivZeroCheck would prevent any code to be executed. |
| 3679 | } else if (imm == 1 || imm == -1) { |
| 3680 | DivRemOneOrMinusOne(instruction); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3681 | } else if (instruction->IsDiv() && IsPowerOfTwo(AbsOrMin(imm))) { |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3682 | DivByPowerOfTwo(instruction->AsDiv()); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3683 | } else { |
| 3684 | DCHECK(imm <= -2 || imm >= 2); |
| 3685 | GenerateDivRemWithAnyConstant(instruction); |
| 3686 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3687 | } else { |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 3688 | SlowPathCode* slow_path = |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3689 | new (GetGraph()->GetArena()) DivRemMinusOneSlowPathX86_64( |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 3690 | instruction, out.AsRegister(), type, is_div); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3691 | codegen_->AddSlowPath(slow_path); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3692 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3693 | CpuRegister second_reg = second.AsRegister<CpuRegister>(); |
| 3694 | // 0x80000000(00000000)/-1 triggers an arithmetic exception! |
| 3695 | // Dividing by -1 is actually negation and -0x800000000(00000000) = 0x80000000(00000000) |
| 3696 | // so it's safe to just use negl instead of more complex comparisons. |
| 3697 | if (type == Primitive::kPrimInt) { |
| 3698 | __ cmpl(second_reg, Immediate(-1)); |
| 3699 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3700 | // edx:eax <- sign-extended of eax |
| 3701 | __ cdq(); |
| 3702 | // eax = quotient, edx = remainder |
| 3703 | __ idivl(second_reg); |
| 3704 | } else { |
| 3705 | __ cmpq(second_reg, Immediate(-1)); |
| 3706 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3707 | // rdx:rax <- sign-extended of rax |
| 3708 | __ cqo(); |
| 3709 | // rax = quotient, rdx = remainder |
| 3710 | __ idivq(second_reg); |
| 3711 | } |
| 3712 | __ Bind(slow_path->GetExitLabel()); |
| 3713 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3714 | } |
| 3715 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3716 | void LocationsBuilderX86_64::VisitDiv(HDiv* div) { |
| 3717 | LocationSummary* locations = |
| 3718 | new (GetGraph()->GetArena()) LocationSummary(div, LocationSummary::kNoCall); |
| 3719 | switch (div->GetResultType()) { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3720 | case Primitive::kPrimInt: |
| 3721 | case Primitive::kPrimLong: { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3722 | locations->SetInAt(0, Location::RegisterLocation(RAX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3723 | locations->SetInAt(1, Location::RegisterOrConstant(div->InputAt(1))); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3724 | locations->SetOut(Location::SameAsFirstInput()); |
| 3725 | // Intel uses edx:eax as the dividend. |
| 3726 | locations->AddTemp(Location::RegisterLocation(RDX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3727 | // We need to save the numerator while we tweak rax and rdx. As we are using imul in a way |
| 3728 | // which enforces results to be in RAX and RDX, things are simpler if we use RDX also as |
| 3729 | // output and request another temp. |
| 3730 | if (div->InputAt(1)->IsConstant()) { |
| 3731 | locations->AddTemp(Location::RequiresRegister()); |
| 3732 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3733 | break; |
| 3734 | } |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3735 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3736 | case Primitive::kPrimFloat: |
| 3737 | case Primitive::kPrimDouble: { |
| 3738 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3739 | locations->SetInAt(1, Location::Any()); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3740 | locations->SetOut(Location::SameAsFirstInput()); |
| 3741 | break; |
| 3742 | } |
| 3743 | |
| 3744 | default: |
| 3745 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 3746 | } |
| 3747 | } |
| 3748 | |
| 3749 | void InstructionCodeGeneratorX86_64::VisitDiv(HDiv* div) { |
| 3750 | LocationSummary* locations = div->GetLocations(); |
| 3751 | Location first = locations->InAt(0); |
| 3752 | Location second = locations->InAt(1); |
| 3753 | DCHECK(first.Equals(locations->Out())); |
| 3754 | |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3755 | Primitive::Type type = div->GetResultType(); |
| 3756 | switch (type) { |
| 3757 | case Primitive::kPrimInt: |
| 3758 | case Primitive::kPrimLong: { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3759 | GenerateDivRemIntegral(div); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3760 | break; |
| 3761 | } |
| 3762 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3763 | case Primitive::kPrimFloat: { |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3764 | if (second.IsFpuRegister()) { |
| 3765 | __ divss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3766 | } else if (second.IsConstant()) { |
| 3767 | __ divss(first.AsFpuRegister<XmmRegister>(), |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 3768 | codegen_->LiteralFloatAddress( |
| 3769 | second.GetConstant()->AsFloatConstant()->GetValue())); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3770 | } else { |
| 3771 | DCHECK(second.IsStackSlot()); |
| 3772 | __ divss(first.AsFpuRegister<XmmRegister>(), |
| 3773 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 3774 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3775 | break; |
| 3776 | } |
| 3777 | |
| 3778 | case Primitive::kPrimDouble: { |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3779 | if (second.IsFpuRegister()) { |
| 3780 | __ divsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3781 | } else if (second.IsConstant()) { |
| 3782 | __ divsd(first.AsFpuRegister<XmmRegister>(), |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 3783 | codegen_->LiteralDoubleAddress( |
| 3784 | second.GetConstant()->AsDoubleConstant()->GetValue())); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3785 | } else { |
| 3786 | DCHECK(second.IsDoubleStackSlot()); |
| 3787 | __ divsd(first.AsFpuRegister<XmmRegister>(), |
| 3788 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 3789 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3790 | break; |
| 3791 | } |
| 3792 | |
| 3793 | default: |
| 3794 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 3795 | } |
| 3796 | } |
| 3797 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3798 | void LocationsBuilderX86_64::VisitRem(HRem* rem) { |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3799 | Primitive::Type type = rem->GetResultType(); |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3800 | LocationSummary* locations = |
| 3801 | new (GetGraph()->GetArena()) LocationSummary(rem, LocationSummary::kNoCall); |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3802 | |
| 3803 | switch (type) { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3804 | case Primitive::kPrimInt: |
| 3805 | case Primitive::kPrimLong: { |
| 3806 | locations->SetInAt(0, Location::RegisterLocation(RAX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3807 | locations->SetInAt(1, Location::RegisterOrConstant(rem->InputAt(1))); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3808 | // Intel uses rdx:rax as the dividend and puts the remainder in rdx |
| 3809 | locations->SetOut(Location::RegisterLocation(RDX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3810 | // We need to save the numerator while we tweak eax and edx. As we are using imul in a way |
| 3811 | // which enforces results to be in RAX and RDX, things are simpler if we use EAX also as |
| 3812 | // output and request another temp. |
| 3813 | if (rem->InputAt(1)->IsConstant()) { |
| 3814 | locations->AddTemp(Location::RequiresRegister()); |
| 3815 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3816 | break; |
| 3817 | } |
| 3818 | |
| 3819 | case Primitive::kPrimFloat: |
| 3820 | case Primitive::kPrimDouble: { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3821 | locations->SetInAt(0, Location::Any()); |
| 3822 | locations->SetInAt(1, Location::Any()); |
| 3823 | locations->SetOut(Location::RequiresFpuRegister()); |
| 3824 | locations->AddTemp(Location::RegisterLocation(RAX)); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3825 | break; |
| 3826 | } |
| 3827 | |
| 3828 | default: |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3829 | LOG(FATAL) << "Unexpected rem type " << type; |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3830 | } |
| 3831 | } |
| 3832 | |
| 3833 | void InstructionCodeGeneratorX86_64::VisitRem(HRem* rem) { |
| 3834 | Primitive::Type type = rem->GetResultType(); |
| 3835 | switch (type) { |
| 3836 | case Primitive::kPrimInt: |
| 3837 | case Primitive::kPrimLong: { |
| 3838 | GenerateDivRemIntegral(rem); |
| 3839 | break; |
| 3840 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3841 | case Primitive::kPrimFloat: |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3842 | case Primitive::kPrimDouble: { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3843 | GenerateRemFP(rem); |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3844 | break; |
| 3845 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3846 | default: |
| 3847 | LOG(FATAL) << "Unexpected rem type " << rem->GetResultType(); |
| 3848 | } |
| 3849 | } |
| 3850 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3851 | void LocationsBuilderX86_64::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 3852 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3853 | locations->SetInAt(0, Location::Any()); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3854 | } |
| 3855 | |
| 3856 | void InstructionCodeGeneratorX86_64::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 3857 | SlowPathCode* slow_path = |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3858 | new (GetGraph()->GetArena()) DivZeroCheckSlowPathX86_64(instruction); |
| 3859 | codegen_->AddSlowPath(slow_path); |
| 3860 | |
| 3861 | LocationSummary* locations = instruction->GetLocations(); |
| 3862 | Location value = locations->InAt(0); |
| 3863 | |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3864 | switch (instruction->GetType()) { |
Nicolas Geoffray | e567161 | 2016-03-16 11:03:54 +0000 | [diff] [blame] | 3865 | case Primitive::kPrimBoolean: |
Serguei Katkov | 8c0676c | 2015-08-03 13:55:33 +0600 | [diff] [blame] | 3866 | case Primitive::kPrimByte: |
| 3867 | case Primitive::kPrimChar: |
| 3868 | case Primitive::kPrimShort: |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3869 | case Primitive::kPrimInt: { |
| 3870 | if (value.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3871 | __ testl(value.AsRegister<CpuRegister>(), value.AsRegister<CpuRegister>()); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3872 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3873 | } else if (value.IsStackSlot()) { |
| 3874 | __ cmpl(Address(CpuRegister(RSP), value.GetStackIndex()), Immediate(0)); |
| 3875 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3876 | } else { |
| 3877 | DCHECK(value.IsConstant()) << value; |
| 3878 | if (value.GetConstant()->AsIntConstant()->GetValue() == 0) { |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 3879 | __ jmp(slow_path->GetEntryLabel()); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3880 | } |
| 3881 | } |
| 3882 | break; |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3883 | } |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3884 | case Primitive::kPrimLong: { |
| 3885 | if (value.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3886 | __ testq(value.AsRegister<CpuRegister>(), value.AsRegister<CpuRegister>()); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3887 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3888 | } else if (value.IsDoubleStackSlot()) { |
| 3889 | __ cmpq(Address(CpuRegister(RSP), value.GetStackIndex()), Immediate(0)); |
| 3890 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3891 | } else { |
| 3892 | DCHECK(value.IsConstant()) << value; |
| 3893 | if (value.GetConstant()->AsLongConstant()->GetValue() == 0) { |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 3894 | __ jmp(slow_path->GetEntryLabel()); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3895 | } |
| 3896 | } |
| 3897 | break; |
| 3898 | } |
| 3899 | default: |
| 3900 | LOG(FATAL) << "Unexpected type for HDivZeroCheck " << instruction->GetType(); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3901 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3902 | } |
| 3903 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3904 | void LocationsBuilderX86_64::HandleShift(HBinaryOperation* op) { |
| 3905 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 3906 | |
| 3907 | LocationSummary* locations = |
| 3908 | new (GetGraph()->GetArena()) LocationSummary(op, LocationSummary::kNoCall); |
| 3909 | |
| 3910 | switch (op->GetResultType()) { |
| 3911 | case Primitive::kPrimInt: |
| 3912 | case Primitive::kPrimLong: { |
| 3913 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3914 | // The shift count needs to be in CL. |
| 3915 | locations->SetInAt(1, Location::ByteRegisterOrConstant(RCX, op->InputAt(1))); |
| 3916 | locations->SetOut(Location::SameAsFirstInput()); |
| 3917 | break; |
| 3918 | } |
| 3919 | default: |
| 3920 | LOG(FATAL) << "Unexpected operation type " << op->GetResultType(); |
| 3921 | } |
| 3922 | } |
| 3923 | |
| 3924 | void InstructionCodeGeneratorX86_64::HandleShift(HBinaryOperation* op) { |
| 3925 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 3926 | |
| 3927 | LocationSummary* locations = op->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3928 | CpuRegister first_reg = locations->InAt(0).AsRegister<CpuRegister>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3929 | Location second = locations->InAt(1); |
| 3930 | |
| 3931 | switch (op->GetResultType()) { |
| 3932 | case Primitive::kPrimInt: { |
| 3933 | if (second.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3934 | CpuRegister second_reg = second.AsRegister<CpuRegister>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3935 | if (op->IsShl()) { |
| 3936 | __ shll(first_reg, second_reg); |
| 3937 | } else if (op->IsShr()) { |
| 3938 | __ sarl(first_reg, second_reg); |
| 3939 | } else { |
| 3940 | __ shrl(first_reg, second_reg); |
| 3941 | } |
| 3942 | } else { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 3943 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue() & kMaxIntShiftDistance); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3944 | if (op->IsShl()) { |
| 3945 | __ shll(first_reg, imm); |
| 3946 | } else if (op->IsShr()) { |
| 3947 | __ sarl(first_reg, imm); |
| 3948 | } else { |
| 3949 | __ shrl(first_reg, imm); |
| 3950 | } |
| 3951 | } |
| 3952 | break; |
| 3953 | } |
| 3954 | case Primitive::kPrimLong: { |
| 3955 | if (second.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3956 | CpuRegister second_reg = second.AsRegister<CpuRegister>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3957 | if (op->IsShl()) { |
| 3958 | __ shlq(first_reg, second_reg); |
| 3959 | } else if (op->IsShr()) { |
| 3960 | __ sarq(first_reg, second_reg); |
| 3961 | } else { |
| 3962 | __ shrq(first_reg, second_reg); |
| 3963 | } |
| 3964 | } else { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 3965 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue() & kMaxLongShiftDistance); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3966 | if (op->IsShl()) { |
| 3967 | __ shlq(first_reg, imm); |
| 3968 | } else if (op->IsShr()) { |
| 3969 | __ sarq(first_reg, imm); |
| 3970 | } else { |
| 3971 | __ shrq(first_reg, imm); |
| 3972 | } |
| 3973 | } |
| 3974 | break; |
| 3975 | } |
| 3976 | default: |
| 3977 | LOG(FATAL) << "Unexpected operation type " << op->GetResultType(); |
Vladimir Marko | 351dddf | 2015-12-11 16:34:46 +0000 | [diff] [blame] | 3978 | UNREACHABLE(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3979 | } |
| 3980 | } |
| 3981 | |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 3982 | void LocationsBuilderX86_64::VisitRor(HRor* ror) { |
| 3983 | LocationSummary* locations = |
| 3984 | new (GetGraph()->GetArena()) LocationSummary(ror, LocationSummary::kNoCall); |
| 3985 | |
| 3986 | switch (ror->GetResultType()) { |
| 3987 | case Primitive::kPrimInt: |
| 3988 | case Primitive::kPrimLong: { |
| 3989 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3990 | // The shift count needs to be in CL (unless it is a constant). |
| 3991 | locations->SetInAt(1, Location::ByteRegisterOrConstant(RCX, ror->InputAt(1))); |
| 3992 | locations->SetOut(Location::SameAsFirstInput()); |
| 3993 | break; |
| 3994 | } |
| 3995 | default: |
| 3996 | LOG(FATAL) << "Unexpected operation type " << ror->GetResultType(); |
| 3997 | UNREACHABLE(); |
| 3998 | } |
| 3999 | } |
| 4000 | |
| 4001 | void InstructionCodeGeneratorX86_64::VisitRor(HRor* ror) { |
| 4002 | LocationSummary* locations = ror->GetLocations(); |
| 4003 | CpuRegister first_reg = locations->InAt(0).AsRegister<CpuRegister>(); |
| 4004 | Location second = locations->InAt(1); |
| 4005 | |
| 4006 | switch (ror->GetResultType()) { |
| 4007 | case Primitive::kPrimInt: |
| 4008 | if (second.IsRegister()) { |
| 4009 | CpuRegister second_reg = second.AsRegister<CpuRegister>(); |
| 4010 | __ rorl(first_reg, second_reg); |
| 4011 | } else { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4012 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue() & kMaxIntShiftDistance); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4013 | __ rorl(first_reg, imm); |
| 4014 | } |
| 4015 | break; |
| 4016 | case Primitive::kPrimLong: |
| 4017 | if (second.IsRegister()) { |
| 4018 | CpuRegister second_reg = second.AsRegister<CpuRegister>(); |
| 4019 | __ rorq(first_reg, second_reg); |
| 4020 | } else { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4021 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue() & kMaxLongShiftDistance); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4022 | __ rorq(first_reg, imm); |
| 4023 | } |
| 4024 | break; |
| 4025 | default: |
| 4026 | LOG(FATAL) << "Unexpected operation type " << ror->GetResultType(); |
| 4027 | UNREACHABLE(); |
| 4028 | } |
| 4029 | } |
| 4030 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4031 | void LocationsBuilderX86_64::VisitShl(HShl* shl) { |
| 4032 | HandleShift(shl); |
| 4033 | } |
| 4034 | |
| 4035 | void InstructionCodeGeneratorX86_64::VisitShl(HShl* shl) { |
| 4036 | HandleShift(shl); |
| 4037 | } |
| 4038 | |
| 4039 | void LocationsBuilderX86_64::VisitShr(HShr* shr) { |
| 4040 | HandleShift(shr); |
| 4041 | } |
| 4042 | |
| 4043 | void InstructionCodeGeneratorX86_64::VisitShr(HShr* shr) { |
| 4044 | HandleShift(shr); |
| 4045 | } |
| 4046 | |
| 4047 | void LocationsBuilderX86_64::VisitUShr(HUShr* ushr) { |
| 4048 | HandleShift(ushr); |
| 4049 | } |
| 4050 | |
| 4051 | void InstructionCodeGeneratorX86_64::VisitUShr(HUShr* ushr) { |
| 4052 | HandleShift(ushr); |
| 4053 | } |
| 4054 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4055 | void LocationsBuilderX86_64::VisitNewInstance(HNewInstance* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4056 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 4057 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
Nicolas Geoffray | 9ae0daa | 2014-09-30 22:40:23 +0100 | [diff] [blame] | 4058 | InvokeRuntimeCallingConvention calling_convention; |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4059 | if (instruction->IsStringAlloc()) { |
| 4060 | locations->AddTemp(Location::RegisterLocation(kMethodRegisterArgument)); |
| 4061 | } else { |
| 4062 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4063 | } |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4064 | locations->SetOut(Location::RegisterLocation(RAX)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4065 | } |
| 4066 | |
| 4067 | void InstructionCodeGeneratorX86_64::VisitNewInstance(HNewInstance* instruction) { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4068 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 4069 | // of poisoning the reference. |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4070 | if (instruction->IsStringAlloc()) { |
| 4071 | // String is allocated through StringFactory. Call NewEmptyString entry point. |
| 4072 | CpuRegister temp = instruction->GetLocations()->GetTemp(0).AsRegister<CpuRegister>(); |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 4073 | MemberOffset code_offset = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kX86_64PointerSize); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4074 | __ gs()->movq(temp, Address::Absolute(QUICK_ENTRY_POINT(pNewEmptyString), /* no_rip */ true)); |
| 4075 | __ call(Address(temp, code_offset.SizeValue())); |
| 4076 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
| 4077 | } else { |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 4078 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), instruction, instruction->GetDexPc()); |
Nicolas Geoffray | 0d3998b | 2017-01-12 15:35:12 +0000 | [diff] [blame] | 4079 | CheckEntrypointTypes<kQuickAllocObjectWithChecks, void*, mirror::Class*>(); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4080 | DCHECK(!codegen_->IsLeafMethod()); |
| 4081 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4082 | } |
| 4083 | |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4084 | void LocationsBuilderX86_64::VisitNewArray(HNewArray* instruction) { |
| 4085 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 4086 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4087 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4088 | locations->SetOut(Location::RegisterLocation(RAX)); |
Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 4089 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 4090 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4091 | } |
| 4092 | |
| 4093 | void InstructionCodeGeneratorX86_64::VisitNewArray(HNewArray* instruction) { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4094 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 4095 | // of poisoning the reference. |
Nicolas Geoffray | b048cb7 | 2017-01-23 22:50:24 +0000 | [diff] [blame] | 4096 | QuickEntrypointEnum entrypoint = |
| 4097 | CodeGenerator::GetArrayAllocationEntrypoint(instruction->GetLoadClass()->GetClass()); |
| 4098 | codegen_->InvokeRuntime(entrypoint, instruction, instruction->GetDexPc()); |
Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 4099 | CheckEntrypointTypes<kQuickAllocArrayResolved, void*, mirror::Class*, int32_t>(); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4100 | DCHECK(!codegen_->IsLeafMethod()); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4101 | } |
| 4102 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4103 | void LocationsBuilderX86_64::VisitParameterValue(HParameterValue* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4104 | LocationSummary* locations = |
| 4105 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4106 | Location location = parameter_visitor_.GetNextLocation(instruction->GetType()); |
| 4107 | if (location.IsStackSlot()) { |
| 4108 | location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 4109 | } else if (location.IsDoubleStackSlot()) { |
| 4110 | location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 4111 | } |
| 4112 | locations->SetOut(location); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4113 | } |
| 4114 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4115 | void InstructionCodeGeneratorX86_64::VisitParameterValue( |
| 4116 | HParameterValue* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4117 | // Nothing to do, the parameter is already at its location. |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4118 | } |
| 4119 | |
| 4120 | void LocationsBuilderX86_64::VisitCurrentMethod(HCurrentMethod* instruction) { |
| 4121 | LocationSummary* locations = |
| 4122 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 4123 | locations->SetOut(Location::RegisterLocation(kMethodRegisterArgument)); |
| 4124 | } |
| 4125 | |
| 4126 | void InstructionCodeGeneratorX86_64::VisitCurrentMethod( |
| 4127 | HCurrentMethod* instruction ATTRIBUTE_UNUSED) { |
| 4128 | // Nothing to do, the method is already at its location. |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4129 | } |
| 4130 | |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4131 | void LocationsBuilderX86_64::VisitClassTableGet(HClassTableGet* instruction) { |
| 4132 | LocationSummary* locations = |
| 4133 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 4134 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4135 | locations->SetOut(Location::RequiresRegister()); |
| 4136 | } |
| 4137 | |
| 4138 | void InstructionCodeGeneratorX86_64::VisitClassTableGet(HClassTableGet* instruction) { |
| 4139 | LocationSummary* locations = instruction->GetLocations(); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4140 | if (instruction->GetTableKind() == HClassTableGet::TableKind::kVTable) { |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 4141 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4142 | instruction->GetIndex(), kX86_64PointerSize).SizeValue(); |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 4143 | __ movq(locations->Out().AsRegister<CpuRegister>(), |
| 4144 | Address(locations->InAt(0).AsRegister<CpuRegister>(), method_offset)); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4145 | } else { |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 4146 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 4147 | instruction->GetIndex(), kX86_64PointerSize)); |
Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 4148 | __ movq(locations->Out().AsRegister<CpuRegister>(), |
| 4149 | Address(locations->InAt(0).AsRegister<CpuRegister>(), |
| 4150 | mirror::Class::ImtPtrOffset(kX86_64PointerSize).Uint32Value())); |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 4151 | __ movq(locations->Out().AsRegister<CpuRegister>(), |
| 4152 | Address(locations->Out().AsRegister<CpuRegister>(), method_offset)); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4153 | } |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4154 | } |
| 4155 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4156 | void LocationsBuilderX86_64::VisitNot(HNot* not_) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4157 | LocationSummary* locations = |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4158 | new (GetGraph()->GetArena()) LocationSummary(not_, LocationSummary::kNoCall); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 4159 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4160 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4161 | } |
| 4162 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4163 | void InstructionCodeGeneratorX86_64::VisitNot(HNot* not_) { |
| 4164 | LocationSummary* locations = not_->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4165 | DCHECK_EQ(locations->InAt(0).AsRegister<CpuRegister>().AsRegister(), |
| 4166 | locations->Out().AsRegister<CpuRegister>().AsRegister()); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4167 | Location out = locations->Out(); |
Nicolas Geoffray | d8ef2e9 | 2015-02-24 16:02:06 +0000 | [diff] [blame] | 4168 | switch (not_->GetResultType()) { |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4169 | case Primitive::kPrimInt: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4170 | __ notl(out.AsRegister<CpuRegister>()); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4171 | break; |
| 4172 | |
| 4173 | case Primitive::kPrimLong: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4174 | __ notq(out.AsRegister<CpuRegister>()); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4175 | break; |
| 4176 | |
| 4177 | default: |
| 4178 | LOG(FATAL) << "Unimplemented type for not operation " << not_->GetResultType(); |
| 4179 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4180 | } |
| 4181 | |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4182 | void LocationsBuilderX86_64::VisitBooleanNot(HBooleanNot* bool_not) { |
| 4183 | LocationSummary* locations = |
| 4184 | new (GetGraph()->GetArena()) LocationSummary(bool_not, LocationSummary::kNoCall); |
| 4185 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4186 | locations->SetOut(Location::SameAsFirstInput()); |
| 4187 | } |
| 4188 | |
| 4189 | void InstructionCodeGeneratorX86_64::VisitBooleanNot(HBooleanNot* bool_not) { |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4190 | LocationSummary* locations = bool_not->GetLocations(); |
| 4191 | DCHECK_EQ(locations->InAt(0).AsRegister<CpuRegister>().AsRegister(), |
| 4192 | locations->Out().AsRegister<CpuRegister>().AsRegister()); |
| 4193 | Location out = locations->Out(); |
| 4194 | __ xorl(out.AsRegister<CpuRegister>(), Immediate(1)); |
| 4195 | } |
| 4196 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4197 | void LocationsBuilderX86_64::VisitPhi(HPhi* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4198 | LocationSummary* locations = |
| 4199 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 4200 | for (size_t i = 0, e = locations->GetInputCount(); i < e; ++i) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4201 | locations->SetInAt(i, Location::Any()); |
| 4202 | } |
| 4203 | locations->SetOut(Location::Any()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4204 | } |
| 4205 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4206 | void InstructionCodeGeneratorX86_64::VisitPhi(HPhi* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4207 | LOG(FATAL) << "Unimplemented"; |
| 4208 | } |
| 4209 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4210 | void CodeGeneratorX86_64::GenerateMemoryBarrier(MemBarrierKind kind) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4211 | /* |
Roland Levillain | 5e8d5f0 | 2016-10-18 18:03:43 +0100 | [diff] [blame] | 4212 | * 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] | 4213 | * 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] | 4214 | * For those cases, all we need to ensure is that there is a scheduling barrier in place. |
| 4215 | */ |
| 4216 | switch (kind) { |
| 4217 | case MemBarrierKind::kAnyAny: { |
Mark P Mendell | 17077d8 | 2015-12-16 19:15:59 +0000 | [diff] [blame] | 4218 | MemoryFence(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4219 | break; |
| 4220 | } |
| 4221 | case MemBarrierKind::kAnyStore: |
| 4222 | case MemBarrierKind::kLoadAny: |
| 4223 | case MemBarrierKind::kStoreStore: { |
| 4224 | // nop |
| 4225 | break; |
| 4226 | } |
Mark Mendell | 7aa04a1 | 2016-01-27 22:39:07 -0500 | [diff] [blame] | 4227 | case MemBarrierKind::kNTStoreStore: |
| 4228 | // Non-Temporal Store/Store needs an explicit fence. |
| 4229 | MemoryFence(/* non-temporal */ true); |
| 4230 | break; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4231 | } |
| 4232 | } |
| 4233 | |
| 4234 | void LocationsBuilderX86_64::HandleFieldGet(HInstruction* instruction) { |
| 4235 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
| 4236 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4237 | bool object_field_get_with_read_barrier = |
| 4238 | kEmitCompilerReadBarrier && (instruction->GetType() == Primitive::kPrimNot); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4239 | LocationSummary* locations = |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4240 | new (GetGraph()->GetArena()) LocationSummary(instruction, |
| 4241 | object_field_get_with_read_barrier ? |
| 4242 | LocationSummary::kCallOnSlowPath : |
| 4243 | LocationSummary::kNoCall); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 4244 | if (object_field_get_with_read_barrier && kUseBakerReadBarrier) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 4245 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 4246 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4247 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4248 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 4249 | locations->SetOut(Location::RequiresFpuRegister()); |
| 4250 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4251 | // The output overlaps for an object field get when read barriers |
| 4252 | // are enabled: we do not want the move to overwrite the object's |
| 4253 | // location, as we need it to emit the read barrier. |
| 4254 | locations->SetOut( |
| 4255 | Location::RequiresRegister(), |
| 4256 | object_field_get_with_read_barrier ? Location::kOutputOverlap : Location::kNoOutputOverlap); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4257 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4258 | } |
| 4259 | |
| 4260 | void InstructionCodeGeneratorX86_64::HandleFieldGet(HInstruction* instruction, |
| 4261 | const FieldInfo& field_info) { |
| 4262 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
| 4263 | |
| 4264 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4265 | Location base_loc = locations->InAt(0); |
| 4266 | CpuRegister base = base_loc.AsRegister<CpuRegister>(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4267 | Location out = locations->Out(); |
| 4268 | bool is_volatile = field_info.IsVolatile(); |
| 4269 | Primitive::Type field_type = field_info.GetFieldType(); |
| 4270 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
| 4271 | |
| 4272 | switch (field_type) { |
| 4273 | case Primitive::kPrimBoolean: { |
| 4274 | __ movzxb(out.AsRegister<CpuRegister>(), Address(base, offset)); |
| 4275 | break; |
| 4276 | } |
| 4277 | |
| 4278 | case Primitive::kPrimByte: { |
| 4279 | __ movsxb(out.AsRegister<CpuRegister>(), Address(base, offset)); |
| 4280 | break; |
| 4281 | } |
| 4282 | |
| 4283 | case Primitive::kPrimShort: { |
| 4284 | __ movsxw(out.AsRegister<CpuRegister>(), Address(base, offset)); |
| 4285 | break; |
| 4286 | } |
| 4287 | |
| 4288 | case Primitive::kPrimChar: { |
| 4289 | __ movzxw(out.AsRegister<CpuRegister>(), Address(base, offset)); |
| 4290 | break; |
| 4291 | } |
| 4292 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4293 | case Primitive::kPrimInt: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4294 | __ movl(out.AsRegister<CpuRegister>(), Address(base, offset)); |
| 4295 | break; |
| 4296 | } |
| 4297 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4298 | case Primitive::kPrimNot: { |
| 4299 | // /* HeapReference<Object> */ out = *(base + offset) |
| 4300 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4301 | // Note that a potential implicit null check is handled in this |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 4302 | // CodeGeneratorX86_64::GenerateFieldLoadWithBakerReadBarrier call. |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4303 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 4304 | instruction, out, base, offset, /* needs_null_check */ true); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4305 | if (is_volatile) { |
| 4306 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4307 | } |
| 4308 | } else { |
| 4309 | __ movl(out.AsRegister<CpuRegister>(), Address(base, offset)); |
| 4310 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4311 | if (is_volatile) { |
| 4312 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4313 | } |
| 4314 | // If read barriers are enabled, emit read barriers other than |
| 4315 | // Baker's using a slow path (and also unpoison the loaded |
| 4316 | // reference, if heap poisoning is enabled). |
| 4317 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out, out, base_loc, offset); |
| 4318 | } |
| 4319 | break; |
| 4320 | } |
| 4321 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4322 | case Primitive::kPrimLong: { |
| 4323 | __ movq(out.AsRegister<CpuRegister>(), Address(base, offset)); |
| 4324 | break; |
| 4325 | } |
| 4326 | |
| 4327 | case Primitive::kPrimFloat: { |
| 4328 | __ movss(out.AsFpuRegister<XmmRegister>(), Address(base, offset)); |
| 4329 | break; |
| 4330 | } |
| 4331 | |
| 4332 | case Primitive::kPrimDouble: { |
| 4333 | __ movsd(out.AsFpuRegister<XmmRegister>(), Address(base, offset)); |
| 4334 | break; |
| 4335 | } |
| 4336 | |
| 4337 | case Primitive::kPrimVoid: |
| 4338 | LOG(FATAL) << "Unreachable type " << field_type; |
| 4339 | UNREACHABLE(); |
| 4340 | } |
| 4341 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4342 | if (field_type == Primitive::kPrimNot) { |
| 4343 | // Potential implicit null checks, in the case of reference |
| 4344 | // fields, are handled in the previous switch statement. |
| 4345 | } else { |
| 4346 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4347 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4348 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4349 | if (is_volatile) { |
| 4350 | if (field_type == Primitive::kPrimNot) { |
| 4351 | // Memory barriers, in the case of references, are also handled |
| 4352 | // in the previous switch statement. |
| 4353 | } else { |
| 4354 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4355 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4356 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4357 | } |
| 4358 | |
| 4359 | void LocationsBuilderX86_64::HandleFieldSet(HInstruction* instruction, |
| 4360 | const FieldInfo& field_info) { |
| 4361 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 4362 | |
| 4363 | LocationSummary* locations = |
| 4364 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4365 | Primitive::Type field_type = field_info.GetFieldType(); |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4366 | bool is_volatile = field_info.IsVolatile(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4367 | bool needs_write_barrier = |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4368 | CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1)); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4369 | |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 4370 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4371 | if (Primitive::IsFloatingPointType(instruction->InputAt(1)->GetType())) { |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4372 | if (is_volatile) { |
| 4373 | // In order to satisfy the semantics of volatile, this must be a single instruction store. |
| 4374 | locations->SetInAt(1, Location::FpuRegisterOrInt32Constant(instruction->InputAt(1))); |
| 4375 | } else { |
| 4376 | locations->SetInAt(1, Location::FpuRegisterOrConstant(instruction->InputAt(1))); |
| 4377 | } |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4378 | } else { |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4379 | if (is_volatile) { |
| 4380 | // In order to satisfy the semantics of volatile, this must be a single instruction store. |
| 4381 | locations->SetInAt(1, Location::RegisterOrInt32Constant(instruction->InputAt(1))); |
| 4382 | } else { |
| 4383 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 4384 | } |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4385 | } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4386 | if (needs_write_barrier) { |
Nicolas Geoffray | 9ae0daa | 2014-09-30 22:40:23 +0100 | [diff] [blame] | 4387 | // Temporary registers for the write barrier. |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4388 | locations->AddTemp(Location::RequiresRegister()); // Possibly used for reference poisoning too. |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 4389 | locations->AddTemp(Location::RequiresRegister()); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4390 | } else if (kPoisonHeapReferences && field_type == Primitive::kPrimNot) { |
| 4391 | // Temporary register for the reference poisoning. |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 4392 | locations->AddTemp(Location::RequiresRegister()); |
| 4393 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4394 | } |
| 4395 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4396 | void InstructionCodeGeneratorX86_64::HandleFieldSet(HInstruction* instruction, |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4397 | const FieldInfo& field_info, |
| 4398 | bool value_can_be_null) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4399 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 4400 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4401 | LocationSummary* locations = instruction->GetLocations(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4402 | CpuRegister base = locations->InAt(0).AsRegister<CpuRegister>(); |
| 4403 | Location value = locations->InAt(1); |
| 4404 | bool is_volatile = field_info.IsVolatile(); |
| 4405 | Primitive::Type field_type = field_info.GetFieldType(); |
| 4406 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
| 4407 | |
| 4408 | if (is_volatile) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4409 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyStore); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4410 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4411 | |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4412 | bool maybe_record_implicit_null_check_done = false; |
| 4413 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4414 | switch (field_type) { |
| 4415 | case Primitive::kPrimBoolean: |
| 4416 | case Primitive::kPrimByte: { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4417 | if (value.IsConstant()) { |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4418 | int8_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4419 | __ movb(Address(base, offset), Immediate(v)); |
| 4420 | } else { |
| 4421 | __ movb(Address(base, offset), value.AsRegister<CpuRegister>()); |
| 4422 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4423 | break; |
| 4424 | } |
| 4425 | |
| 4426 | case Primitive::kPrimShort: |
| 4427 | case Primitive::kPrimChar: { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4428 | if (value.IsConstant()) { |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4429 | int16_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4430 | __ movw(Address(base, offset), Immediate(v)); |
| 4431 | } else { |
| 4432 | __ movw(Address(base, offset), value.AsRegister<CpuRegister>()); |
| 4433 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4434 | break; |
| 4435 | } |
| 4436 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4437 | case Primitive::kPrimInt: |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4438 | case Primitive::kPrimNot: { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4439 | if (value.IsConstant()) { |
| 4440 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4441 | // `field_type == Primitive::kPrimNot` implies `v == 0`. |
| 4442 | DCHECK((field_type != Primitive::kPrimNot) || (v == 0)); |
| 4443 | // Note: if heap poisoning is enabled, no need to poison |
| 4444 | // (negate) `v` if it is a reference, as it would be null. |
Roland Levillain | 06b66d0 | 2015-07-01 12:47:25 +0100 | [diff] [blame] | 4445 | __ movl(Address(base, offset), Immediate(v)); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4446 | } else { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4447 | if (kPoisonHeapReferences && field_type == Primitive::kPrimNot) { |
| 4448 | CpuRegister temp = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 4449 | __ movl(temp, value.AsRegister<CpuRegister>()); |
| 4450 | __ PoisonHeapReference(temp); |
| 4451 | __ movl(Address(base, offset), temp); |
| 4452 | } else { |
| 4453 | __ movl(Address(base, offset), value.AsRegister<CpuRegister>()); |
| 4454 | } |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4455 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4456 | break; |
| 4457 | } |
| 4458 | |
| 4459 | case Primitive::kPrimLong: { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4460 | if (value.IsConstant()) { |
| 4461 | int64_t v = value.GetConstant()->AsLongConstant()->GetValue(); |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4462 | codegen_->MoveInt64ToAddress(Address(base, offset), |
| 4463 | Address(base, offset + sizeof(int32_t)), |
| 4464 | v, |
| 4465 | instruction); |
| 4466 | maybe_record_implicit_null_check_done = true; |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4467 | } else { |
| 4468 | __ movq(Address(base, offset), value.AsRegister<CpuRegister>()); |
| 4469 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4470 | break; |
| 4471 | } |
| 4472 | |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4473 | case Primitive::kPrimFloat: { |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4474 | if (value.IsConstant()) { |
| 4475 | int32_t v = |
| 4476 | bit_cast<int32_t, float>(value.GetConstant()->AsFloatConstant()->GetValue()); |
| 4477 | __ movl(Address(base, offset), Immediate(v)); |
| 4478 | } else { |
| 4479 | __ movss(Address(base, offset), value.AsFpuRegister<XmmRegister>()); |
| 4480 | } |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4481 | break; |
| 4482 | } |
| 4483 | |
| 4484 | case Primitive::kPrimDouble: { |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4485 | if (value.IsConstant()) { |
| 4486 | int64_t v = |
| 4487 | bit_cast<int64_t, double>(value.GetConstant()->AsDoubleConstant()->GetValue()); |
| 4488 | codegen_->MoveInt64ToAddress(Address(base, offset), |
| 4489 | Address(base, offset + sizeof(int32_t)), |
| 4490 | v, |
| 4491 | instruction); |
| 4492 | maybe_record_implicit_null_check_done = true; |
| 4493 | } else { |
| 4494 | __ movsd(Address(base, offset), value.AsFpuRegister<XmmRegister>()); |
| 4495 | } |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4496 | break; |
| 4497 | } |
| 4498 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4499 | case Primitive::kPrimVoid: |
| 4500 | LOG(FATAL) << "Unreachable type " << field_type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 4501 | UNREACHABLE(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4502 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4503 | |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4504 | if (!maybe_record_implicit_null_check_done) { |
| 4505 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4506 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4507 | |
| 4508 | if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) { |
| 4509 | CpuRegister temp = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 4510 | CpuRegister card = locations->GetTemp(1).AsRegister<CpuRegister>(); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4511 | codegen_->MarkGCCard(temp, card, base, value.AsRegister<CpuRegister>(), value_can_be_null); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4512 | } |
| 4513 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4514 | if (is_volatile) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4515 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyAny); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4516 | } |
| 4517 | } |
| 4518 | |
| 4519 | void LocationsBuilderX86_64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
| 4520 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 4521 | } |
| 4522 | |
| 4523 | void InstructionCodeGeneratorX86_64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4524 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4525 | } |
| 4526 | |
| 4527 | void LocationsBuilderX86_64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4528 | HandleFieldGet(instruction); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4529 | } |
| 4530 | |
| 4531 | void InstructionCodeGeneratorX86_64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4532 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 4533 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4534 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4535 | void LocationsBuilderX86_64::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 4536 | HandleFieldGet(instruction); |
| 4537 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4538 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4539 | void InstructionCodeGeneratorX86_64::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 4540 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 4541 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4542 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4543 | void LocationsBuilderX86_64::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
| 4544 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 4545 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4546 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4547 | void InstructionCodeGeneratorX86_64::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4548 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4549 | } |
| 4550 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 4551 | void LocationsBuilderX86_64::VisitUnresolvedInstanceFieldGet( |
| 4552 | HUnresolvedInstanceFieldGet* instruction) { |
| 4553 | FieldAccessCallingConventionX86_64 calling_convention; |
| 4554 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4555 | instruction, instruction->GetFieldType(), calling_convention); |
| 4556 | } |
| 4557 | |
| 4558 | void InstructionCodeGeneratorX86_64::VisitUnresolvedInstanceFieldGet( |
| 4559 | HUnresolvedInstanceFieldGet* instruction) { |
| 4560 | FieldAccessCallingConventionX86_64 calling_convention; |
| 4561 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4562 | instruction->GetFieldType(), |
| 4563 | instruction->GetFieldIndex(), |
| 4564 | instruction->GetDexPc(), |
| 4565 | calling_convention); |
| 4566 | } |
| 4567 | |
| 4568 | void LocationsBuilderX86_64::VisitUnresolvedInstanceFieldSet( |
| 4569 | HUnresolvedInstanceFieldSet* instruction) { |
| 4570 | FieldAccessCallingConventionX86_64 calling_convention; |
| 4571 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4572 | instruction, instruction->GetFieldType(), calling_convention); |
| 4573 | } |
| 4574 | |
| 4575 | void InstructionCodeGeneratorX86_64::VisitUnresolvedInstanceFieldSet( |
| 4576 | HUnresolvedInstanceFieldSet* 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::VisitUnresolvedStaticFieldGet( |
| 4586 | HUnresolvedStaticFieldGet* instruction) { |
| 4587 | FieldAccessCallingConventionX86_64 calling_convention; |
| 4588 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4589 | instruction, instruction->GetFieldType(), calling_convention); |
| 4590 | } |
| 4591 | |
| 4592 | void InstructionCodeGeneratorX86_64::VisitUnresolvedStaticFieldGet( |
| 4593 | HUnresolvedStaticFieldGet* 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::VisitUnresolvedStaticFieldSet( |
| 4603 | HUnresolvedStaticFieldSet* instruction) { |
| 4604 | FieldAccessCallingConventionX86_64 calling_convention; |
| 4605 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4606 | instruction, instruction->GetFieldType(), calling_convention); |
| 4607 | } |
| 4608 | |
| 4609 | void InstructionCodeGeneratorX86_64::VisitUnresolvedStaticFieldSet( |
| 4610 | HUnresolvedStaticFieldSet* instruction) { |
| 4611 | FieldAccessCallingConventionX86_64 calling_convention; |
| 4612 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4613 | instruction->GetFieldType(), |
| 4614 | instruction->GetFieldIndex(), |
| 4615 | instruction->GetDexPc(), |
| 4616 | calling_convention); |
| 4617 | } |
| 4618 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4619 | void LocationsBuilderX86_64::VisitNullCheck(HNullCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 4620 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
| 4621 | Location loc = codegen_->GetCompilerOptions().GetImplicitNullChecks() |
| 4622 | ? Location::RequiresRegister() |
| 4623 | : Location::Any(); |
| 4624 | locations->SetInAt(0, loc); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4625 | } |
| 4626 | |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 4627 | void CodeGeneratorX86_64::GenerateImplicitNullCheck(HNullCheck* instruction) { |
| 4628 | if (CanMoveNullCheckToUser(instruction)) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4629 | return; |
| 4630 | } |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4631 | LocationSummary* locations = instruction->GetLocations(); |
| 4632 | Location obj = locations->InAt(0); |
| 4633 | |
| 4634 | __ testl(CpuRegister(RAX), Address(obj.AsRegister<CpuRegister>(), 0)); |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 4635 | RecordPcInfo(instruction, instruction->GetDexPc()); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4636 | } |
| 4637 | |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 4638 | void CodeGeneratorX86_64::GenerateExplicitNullCheck(HNullCheck* instruction) { |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 4639 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathX86_64(instruction); |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 4640 | AddSlowPath(slow_path); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4641 | |
| 4642 | LocationSummary* locations = instruction->GetLocations(); |
| 4643 | Location obj = locations->InAt(0); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4644 | |
| 4645 | if (obj.IsRegister()) { |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 4646 | __ testl(obj.AsRegister<CpuRegister>(), obj.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4647 | } else if (obj.IsStackSlot()) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4648 | __ cmpl(Address(CpuRegister(RSP), obj.GetStackIndex()), Immediate(0)); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4649 | } else { |
| 4650 | DCHECK(obj.IsConstant()) << obj; |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 4651 | DCHECK(obj.GetConstant()->IsNullConstant()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4652 | __ jmp(slow_path->GetEntryLabel()); |
| 4653 | return; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4654 | } |
| 4655 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 4656 | } |
| 4657 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4658 | void InstructionCodeGeneratorX86_64::VisitNullCheck(HNullCheck* instruction) { |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 4659 | codegen_->GenerateNullCheck(instruction); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4660 | } |
| 4661 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4662 | void LocationsBuilderX86_64::VisitArrayGet(HArrayGet* instruction) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4663 | bool object_array_get_with_read_barrier = |
| 4664 | kEmitCompilerReadBarrier && (instruction->GetType() == Primitive::kPrimNot); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4665 | LocationSummary* locations = |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4666 | new (GetGraph()->GetArena()) LocationSummary(instruction, |
| 4667 | object_array_get_with_read_barrier ? |
| 4668 | LocationSummary::kCallOnSlowPath : |
| 4669 | LocationSummary::kNoCall); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 4670 | if (object_array_get_with_read_barrier && kUseBakerReadBarrier) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 4671 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 4672 | } |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 4673 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4674 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4675 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 4676 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 4677 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4678 | // The output overlaps for an object array get when read barriers |
| 4679 | // are enabled: we do not want the move to overwrite the array's |
| 4680 | // location, as we need it to emit the read barrier. |
| 4681 | locations->SetOut( |
| 4682 | Location::RequiresRegister(), |
| 4683 | object_array_get_with_read_barrier ? Location::kOutputOverlap : Location::kNoOutputOverlap); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4684 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4685 | } |
| 4686 | |
| 4687 | void InstructionCodeGeneratorX86_64::VisitArrayGet(HArrayGet* instruction) { |
| 4688 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4689 | Location obj_loc = locations->InAt(0); |
| 4690 | CpuRegister obj = obj_loc.AsRegister<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4691 | Location index = locations->InAt(1); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4692 | Location out_loc = locations->Out(); |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 4693 | uint32_t data_offset = CodeGenerator::GetArrayDataOffset(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4694 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4695 | Primitive::Type type = instruction->GetType(); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4696 | switch (type) { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4697 | case Primitive::kPrimBoolean: { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4698 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 4699 | __ movzxb(out, CodeGeneratorX86_64::ArrayAddress(obj, index, TIMES_1, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4700 | break; |
| 4701 | } |
| 4702 | |
| 4703 | case Primitive::kPrimByte: { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4704 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 4705 | __ movsxb(out, CodeGeneratorX86_64::ArrayAddress(obj, index, TIMES_1, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4706 | break; |
| 4707 | } |
| 4708 | |
| 4709 | case Primitive::kPrimShort: { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4710 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 4711 | __ movsxw(out, CodeGeneratorX86_64::ArrayAddress(obj, index, TIMES_2, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4712 | break; |
| 4713 | } |
| 4714 | |
| 4715 | case Primitive::kPrimChar: { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4716 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 4717 | if (mirror::kUseStringCompression && instruction->IsStringCharAt()) { |
| 4718 | // Branch cases into compressed and uncompressed for each index's type. |
| 4719 | uint32_t count_offset = mirror::String::CountOffset().Uint32Value(); |
| 4720 | NearLabel done, not_compressed; |
Vladimir Marko | 3c89d42 | 2017-02-17 11:30:23 +0000 | [diff] [blame] | 4721 | __ testb(Address(obj, count_offset), Immediate(1)); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 4722 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 4723 | static_assert(static_cast<uint32_t>(mirror::StringCompressionFlag::kCompressed) == 0u, |
| 4724 | "Expecting 0=compressed, 1=uncompressed"); |
| 4725 | __ j(kNotZero, ¬_compressed); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 4726 | __ movzxb(out, CodeGeneratorX86_64::ArrayAddress(obj, index, TIMES_1, data_offset)); |
| 4727 | __ jmp(&done); |
| 4728 | __ Bind(¬_compressed); |
| 4729 | __ movzxw(out, CodeGeneratorX86_64::ArrayAddress(obj, index, TIMES_2, data_offset)); |
| 4730 | __ Bind(&done); |
| 4731 | } else { |
| 4732 | __ movzxw(out, CodeGeneratorX86_64::ArrayAddress(obj, index, TIMES_2, data_offset)); |
| 4733 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4734 | break; |
| 4735 | } |
| 4736 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4737 | case Primitive::kPrimInt: { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4738 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 4739 | __ movl(out, CodeGeneratorX86_64::ArrayAddress(obj, index, TIMES_4, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4740 | break; |
| 4741 | } |
| 4742 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4743 | case Primitive::kPrimNot: { |
| 4744 | static_assert( |
| 4745 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 4746 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4747 | // /* HeapReference<Object> */ out = |
| 4748 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
| 4749 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4750 | // Note that a potential implicit null check is handled in this |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 4751 | // CodeGeneratorX86_64::GenerateArrayLoadWithBakerReadBarrier call. |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4752 | codegen_->GenerateArrayLoadWithBakerReadBarrier( |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 4753 | instruction, out_loc, obj, data_offset, index, /* needs_null_check */ true); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4754 | } else { |
| 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)); |
| 4757 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4758 | // If read barriers are enabled, emit read barriers other than |
| 4759 | // Baker's using a slow path (and also unpoison the loaded |
| 4760 | // reference, if heap poisoning is enabled). |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4761 | if (index.IsConstant()) { |
| 4762 | uint32_t offset = |
| 4763 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4764 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out_loc, out_loc, obj_loc, offset); |
| 4765 | } else { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4766 | codegen_->MaybeGenerateReadBarrierSlow( |
| 4767 | instruction, out_loc, out_loc, obj_loc, data_offset, index); |
| 4768 | } |
| 4769 | } |
| 4770 | break; |
| 4771 | } |
| 4772 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4773 | case Primitive::kPrimLong: { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4774 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 4775 | __ movq(out, CodeGeneratorX86_64::ArrayAddress(obj, index, TIMES_8, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4776 | break; |
| 4777 | } |
| 4778 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4779 | case Primitive::kPrimFloat: { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4780 | XmmRegister out = out_loc.AsFpuRegister<XmmRegister>(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 4781 | __ movss(out, CodeGeneratorX86_64::ArrayAddress(obj, index, TIMES_4, data_offset)); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4782 | break; |
| 4783 | } |
| 4784 | |
| 4785 | case Primitive::kPrimDouble: { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4786 | XmmRegister out = out_loc.AsFpuRegister<XmmRegister>(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 4787 | __ movsd(out, CodeGeneratorX86_64::ArrayAddress(obj, index, TIMES_8, data_offset)); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4788 | break; |
| 4789 | } |
| 4790 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4791 | case Primitive::kPrimVoid: |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4792 | LOG(FATAL) << "Unreachable type " << type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 4793 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4794 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4795 | |
| 4796 | if (type == Primitive::kPrimNot) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4797 | // Potential implicit null checks, in the case of reference |
| 4798 | // arrays, are handled in the previous switch statement. |
| 4799 | } else { |
| 4800 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4801 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4802 | } |
| 4803 | |
| 4804 | void LocationsBuilderX86_64::VisitArraySet(HArraySet* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4805 | Primitive::Type value_type = instruction->GetComponentType(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4806 | |
| 4807 | bool needs_write_barrier = |
| 4808 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 4809 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4810 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4811 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary( |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4812 | instruction, |
Vladimir Marko | 8d49fd7 | 2016-08-25 15:20:47 +0100 | [diff] [blame] | 4813 | may_need_runtime_call_for_type_check ? |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4814 | LocationSummary::kCallOnSlowPath : |
| 4815 | LocationSummary::kNoCall); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4816 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4817 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4818 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 4819 | if (Primitive::IsFloatingPointType(value_type)) { |
| 4820 | locations->SetInAt(2, Location::FpuRegisterOrConstant(instruction->InputAt(2))); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4821 | } else { |
| 4822 | locations->SetInAt(2, Location::RegisterOrConstant(instruction->InputAt(2))); |
| 4823 | } |
| 4824 | |
| 4825 | if (needs_write_barrier) { |
| 4826 | // Temporary registers for the write barrier. |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 4827 | locations->AddTemp(Location::RequiresRegister()); // Possibly used for ref. poisoning too. |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4828 | locations->AddTemp(Location::RequiresRegister()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4829 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4830 | } |
| 4831 | |
| 4832 | void InstructionCodeGeneratorX86_64::VisitArraySet(HArraySet* instruction) { |
| 4833 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4834 | Location array_loc = locations->InAt(0); |
| 4835 | CpuRegister array = array_loc.AsRegister<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4836 | Location index = locations->InAt(1); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4837 | Location value = locations->InAt(2); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4838 | Primitive::Type value_type = instruction->GetComponentType(); |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 4839 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4840 | bool needs_write_barrier = |
| 4841 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4842 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 4843 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 4844 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4845 | |
| 4846 | switch (value_type) { |
| 4847 | case Primitive::kPrimBoolean: |
| 4848 | case Primitive::kPrimByte: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4849 | uint32_t offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 4850 | Address address = CodeGeneratorX86_64::ArrayAddress(array, index, TIMES_1, offset); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4851 | if (value.IsRegister()) { |
| 4852 | __ movb(address, value.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4853 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4854 | __ movb(address, Immediate(value.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4855 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4856 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4857 | break; |
| 4858 | } |
| 4859 | |
| 4860 | case Primitive::kPrimShort: |
| 4861 | case Primitive::kPrimChar: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4862 | uint32_t offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 4863 | Address address = CodeGeneratorX86_64::ArrayAddress(array, index, TIMES_2, offset); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4864 | if (value.IsRegister()) { |
| 4865 | __ movw(address, value.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4866 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4867 | DCHECK(value.IsConstant()) << value; |
| 4868 | __ movw(address, Immediate(value.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4869 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4870 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4871 | break; |
| 4872 | } |
| 4873 | |
| 4874 | case Primitive::kPrimNot: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4875 | uint32_t offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 4876 | Address address = CodeGeneratorX86_64::ArrayAddress(array, index, TIMES_4, offset); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4877 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4878 | if (!value.IsRegister()) { |
| 4879 | // Just setting null. |
| 4880 | DCHECK(instruction->InputAt(2)->IsNullConstant()); |
| 4881 | DCHECK(value.IsConstant()) << value; |
| 4882 | __ movl(address, Immediate(0)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4883 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4884 | DCHECK(!needs_write_barrier); |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 4885 | DCHECK(!may_need_runtime_call_for_type_check); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4886 | break; |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4887 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4888 | |
| 4889 | DCHECK(needs_write_barrier); |
| 4890 | CpuRegister register_value = value.AsRegister<CpuRegister>(); |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 4891 | // We cannot use a NearLabel for `done`, as its range may be too |
| 4892 | // short when Baker read barriers are enabled. |
| 4893 | Label done; |
| 4894 | NearLabel not_null, do_put; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4895 | SlowPathCode* slow_path = nullptr; |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 4896 | Location temp_loc = locations->GetTemp(0); |
| 4897 | CpuRegister temp = temp_loc.AsRegister<CpuRegister>(); |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 4898 | if (may_need_runtime_call_for_type_check) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4899 | slow_path = new (GetGraph()->GetArena()) ArraySetSlowPathX86_64(instruction); |
| 4900 | codegen_->AddSlowPath(slow_path); |
| 4901 | if (instruction->GetValueCanBeNull()) { |
| 4902 | __ testl(register_value, register_value); |
| 4903 | __ j(kNotEqual, ¬_null); |
| 4904 | __ movl(address, Immediate(0)); |
| 4905 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4906 | __ jmp(&done); |
| 4907 | __ Bind(¬_null); |
| 4908 | } |
| 4909 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 4910 | // Note that when Baker read barriers are enabled, the type |
| 4911 | // checks are performed without read barriers. This is fine, |
| 4912 | // even in the case where a class object is in the from-space |
| 4913 | // after the flip, as a comparison involving such a type would |
| 4914 | // not produce a false positive; it may of course produce a |
| 4915 | // false negative, in which case we would take the ArraySet |
| 4916 | // slow path. |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 4917 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 4918 | // /* HeapReference<Class> */ temp = array->klass_ |
| 4919 | __ movl(temp, Address(array, class_offset)); |
| 4920 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4921 | __ MaybeUnpoisonHeapReference(temp); |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 4922 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 4923 | // /* HeapReference<Class> */ temp = temp->component_type_ |
| 4924 | __ movl(temp, Address(temp, component_offset)); |
| 4925 | // If heap poisoning is enabled, no need to unpoison `temp` |
| 4926 | // nor the object reference in `register_value->klass`, as |
| 4927 | // we are comparing two poisoned references. |
| 4928 | __ cmpl(temp, Address(register_value, class_offset)); |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 4929 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 4930 | if (instruction->StaticTypeOfArrayIsObjectArray()) { |
| 4931 | __ j(kEqual, &do_put); |
| 4932 | // If heap poisoning is enabled, the `temp` reference has |
| 4933 | // not been unpoisoned yet; unpoison it now. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4934 | __ MaybeUnpoisonHeapReference(temp); |
| 4935 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 4936 | // If heap poisoning is enabled, no need to unpoison the |
| 4937 | // heap reference loaded below, as it is only used for a |
| 4938 | // comparison with null. |
| 4939 | __ cmpl(Address(temp, super_offset), Immediate(0)); |
| 4940 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 4941 | __ Bind(&do_put); |
| 4942 | } else { |
| 4943 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4944 | } |
| 4945 | } |
| 4946 | |
| 4947 | if (kPoisonHeapReferences) { |
| 4948 | __ movl(temp, register_value); |
| 4949 | __ PoisonHeapReference(temp); |
| 4950 | __ movl(address, temp); |
| 4951 | } else { |
| 4952 | __ movl(address, register_value); |
| 4953 | } |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 4954 | if (!may_need_runtime_call_for_type_check) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4955 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4956 | } |
| 4957 | |
| 4958 | CpuRegister card = locations->GetTemp(1).AsRegister<CpuRegister>(); |
| 4959 | codegen_->MarkGCCard( |
| 4960 | temp, card, array, value.AsRegister<CpuRegister>(), instruction->GetValueCanBeNull()); |
| 4961 | __ Bind(&done); |
| 4962 | |
| 4963 | if (slow_path != nullptr) { |
| 4964 | __ Bind(slow_path->GetExitLabel()); |
| 4965 | } |
| 4966 | |
| 4967 | break; |
| 4968 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4969 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4970 | case Primitive::kPrimInt: { |
| 4971 | uint32_t offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 4972 | Address address = CodeGeneratorX86_64::ArrayAddress(array, index, TIMES_4, offset); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4973 | if (value.IsRegister()) { |
| 4974 | __ movl(address, value.AsRegister<CpuRegister>()); |
| 4975 | } else { |
| 4976 | DCHECK(value.IsConstant()) << value; |
| 4977 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
| 4978 | __ movl(address, Immediate(v)); |
| 4979 | } |
| 4980 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4981 | break; |
| 4982 | } |
| 4983 | |
| 4984 | case Primitive::kPrimLong: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4985 | uint32_t offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 4986 | Address address = CodeGeneratorX86_64::ArrayAddress(array, index, TIMES_8, offset); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4987 | if (value.IsRegister()) { |
| 4988 | __ movq(address, value.AsRegister<CpuRegister>()); |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4989 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4990 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4991 | int64_t v = value.GetConstant()->AsLongConstant()->GetValue(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 4992 | Address address_high = |
| 4993 | CodeGeneratorX86_64::ArrayAddress(array, index, TIMES_8, offset + sizeof(int32_t)); |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4994 | codegen_->MoveInt64ToAddress(address, address_high, v, instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4995 | } |
| 4996 | break; |
| 4997 | } |
| 4998 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4999 | case Primitive::kPrimFloat: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5000 | uint32_t offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5001 | Address address = CodeGeneratorX86_64::ArrayAddress(array, index, TIMES_4, offset); |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 5002 | if (value.IsFpuRegister()) { |
| 5003 | __ movss(address, value.AsFpuRegister<XmmRegister>()); |
| 5004 | } else { |
| 5005 | DCHECK(value.IsConstant()); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5006 | int32_t v = bit_cast<int32_t, float>(value.GetConstant()->AsFloatConstant()->GetValue()); |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 5007 | __ movl(address, Immediate(v)); |
| 5008 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5009 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5010 | break; |
| 5011 | } |
| 5012 | |
| 5013 | case Primitive::kPrimDouble: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5014 | uint32_t offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5015 | Address address = CodeGeneratorX86_64::ArrayAddress(array, index, TIMES_8, offset); |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 5016 | if (value.IsFpuRegister()) { |
| 5017 | __ movsd(address, value.AsFpuRegister<XmmRegister>()); |
| 5018 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5019 | } else { |
| 5020 | int64_t v = |
| 5021 | bit_cast<int64_t, double>(value.GetConstant()->AsDoubleConstant()->GetValue()); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5022 | Address address_high = |
| 5023 | CodeGeneratorX86_64::ArrayAddress(array, index, TIMES_8, offset + sizeof(int32_t)); |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 5024 | codegen_->MoveInt64ToAddress(address, address_high, v, instruction); |
| 5025 | } |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5026 | break; |
| 5027 | } |
| 5028 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5029 | case Primitive::kPrimVoid: |
| 5030 | LOG(FATAL) << "Unreachable type " << instruction->GetType(); |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 5031 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5032 | } |
| 5033 | } |
| 5034 | |
| 5035 | void LocationsBuilderX86_64::VisitArrayLength(HArrayLength* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5036 | LocationSummary* locations = |
| 5037 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 5038 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 5039 | if (!instruction->IsEmittedAtUseSite()) { |
| 5040 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 5041 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5042 | } |
| 5043 | |
| 5044 | void InstructionCodeGeneratorX86_64::VisitArrayLength(HArrayLength* instruction) { |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 5045 | if (instruction->IsEmittedAtUseSite()) { |
| 5046 | return; |
| 5047 | } |
| 5048 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5049 | LocationSummary* locations = instruction->GetLocations(); |
Vladimir Marko | dce016e | 2016-04-28 13:10:02 +0100 | [diff] [blame] | 5050 | uint32_t offset = CodeGenerator::GetArrayLengthOffset(instruction); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5051 | CpuRegister obj = locations->InAt(0).AsRegister<CpuRegister>(); |
| 5052 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5053 | __ movl(out, Address(obj, offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5054 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5055 | // Mask out most significant bit in case the array is String's array of char. |
| 5056 | if (mirror::kUseStringCompression && instruction->IsStringLength()) { |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 5057 | __ shrl(out, Immediate(1)); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5058 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5059 | } |
| 5060 | |
| 5061 | void LocationsBuilderX86_64::VisitBoundsCheck(HBoundsCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 5062 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 5063 | InvokeRuntimeCallingConvention calling_convention; |
| 5064 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 5065 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 5066 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction, caller_saves); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 5067 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 5068 | HInstruction* length = instruction->InputAt(1); |
| 5069 | if (!length->IsEmittedAtUseSite()) { |
| 5070 | locations->SetInAt(1, Location::RegisterOrConstant(length)); |
| 5071 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5072 | } |
| 5073 | |
| 5074 | void InstructionCodeGeneratorX86_64::VisitBoundsCheck(HBoundsCheck* instruction) { |
| 5075 | LocationSummary* locations = instruction->GetLocations(); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 5076 | Location index_loc = locations->InAt(0); |
| 5077 | Location length_loc = locations->InAt(1); |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 5078 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) BoundsCheckSlowPathX86_64(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5079 | |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 5080 | if (length_loc.IsConstant()) { |
| 5081 | int32_t length = CodeGenerator::GetInt32ValueOf(length_loc.GetConstant()); |
| 5082 | if (index_loc.IsConstant()) { |
| 5083 | // BCE will remove the bounds check if we are guarenteed to pass. |
| 5084 | int32_t index = CodeGenerator::GetInt32ValueOf(index_loc.GetConstant()); |
| 5085 | if (index < 0 || index >= length) { |
| 5086 | codegen_->AddSlowPath(slow_path); |
| 5087 | __ jmp(slow_path->GetEntryLabel()); |
| 5088 | } else { |
| 5089 | // Some optimization after BCE may have generated this, and we should not |
| 5090 | // generate a bounds check if it is a valid range. |
| 5091 | } |
| 5092 | return; |
| 5093 | } |
| 5094 | |
| 5095 | // We have to reverse the jump condition because the length is the constant. |
| 5096 | CpuRegister index_reg = index_loc.AsRegister<CpuRegister>(); |
| 5097 | __ cmpl(index_reg, Immediate(length)); |
| 5098 | codegen_->AddSlowPath(slow_path); |
| 5099 | __ j(kAboveEqual, slow_path->GetEntryLabel()); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 5100 | } else { |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 5101 | HInstruction* array_length = instruction->InputAt(1); |
| 5102 | if (array_length->IsEmittedAtUseSite()) { |
| 5103 | // Address the length field in the array. |
| 5104 | DCHECK(array_length->IsArrayLength()); |
| 5105 | uint32_t len_offset = CodeGenerator::GetArrayLengthOffset(array_length->AsArrayLength()); |
| 5106 | Location array_loc = array_length->GetLocations()->InAt(0); |
| 5107 | Address array_len(array_loc.AsRegister<CpuRegister>(), len_offset); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5108 | if (mirror::kUseStringCompression && instruction->IsStringCharAt()) { |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 5109 | // TODO: if index_loc.IsConstant(), compare twice the index (to compensate for |
| 5110 | // the string compression flag) with the in-memory length and avoid the temporary. |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5111 | CpuRegister length_reg = CpuRegister(TMP); |
| 5112 | __ movl(length_reg, array_len); |
| 5113 | codegen_->MaybeRecordImplicitNullCheck(array_length); |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 5114 | __ shrl(length_reg, Immediate(1)); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5115 | codegen_->GenerateIntCompare(length_reg, index_loc); |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 5116 | } else { |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5117 | // Checking the bound for general case: |
| 5118 | // Array of char or String's array when the compression feature off. |
| 5119 | if (index_loc.IsConstant()) { |
| 5120 | int32_t value = CodeGenerator::GetInt32ValueOf(index_loc.GetConstant()); |
| 5121 | __ cmpl(array_len, Immediate(value)); |
| 5122 | } else { |
| 5123 | __ cmpl(array_len, index_loc.AsRegister<CpuRegister>()); |
| 5124 | } |
| 5125 | codegen_->MaybeRecordImplicitNullCheck(array_length); |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 5126 | } |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 5127 | } else { |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5128 | codegen_->GenerateIntCompare(length_loc, index_loc); |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 5129 | } |
| 5130 | codegen_->AddSlowPath(slow_path); |
| 5131 | __ j(kBelowEqual, slow_path->GetEntryLabel()); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 5132 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5133 | } |
| 5134 | |
| 5135 | void CodeGeneratorX86_64::MarkGCCard(CpuRegister temp, |
| 5136 | CpuRegister card, |
| 5137 | CpuRegister object, |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5138 | CpuRegister value, |
| 5139 | bool value_can_be_null) { |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 5140 | NearLabel is_null; |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5141 | if (value_can_be_null) { |
| 5142 | __ testl(value, value); |
| 5143 | __ j(kEqual, &is_null); |
| 5144 | } |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 5145 | __ gs()->movq(card, Address::Absolute(Thread::CardTableOffset<kX86_64PointerSize>().Int32Value(), |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5146 | /* no_rip */ true)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5147 | __ movq(temp, object); |
| 5148 | __ shrq(temp, Immediate(gc::accounting::CardTable::kCardShift)); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5149 | __ movb(Address(temp, card, TIMES_1, 0), card); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5150 | if (value_can_be_null) { |
| 5151 | __ Bind(&is_null); |
| 5152 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5153 | } |
| 5154 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5155 | void LocationsBuilderX86_64::VisitParallelMove(HParallelMove* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 5156 | LOG(FATAL) << "Unimplemented"; |
| 5157 | } |
| 5158 | |
| 5159 | void InstructionCodeGeneratorX86_64::VisitParallelMove(HParallelMove* instruction) { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5160 | codegen_->GetMoveResolver()->EmitNativeCode(instruction); |
| 5161 | } |
| 5162 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5163 | void LocationsBuilderX86_64::VisitSuspendCheck(HSuspendCheck* instruction) { |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5164 | LocationSummary* locations = |
| 5165 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath); |
Aart Bik | b13c65b | 2017-03-21 20:14:07 -0700 | [diff] [blame] | 5166 | // In suspend check slow path, usually there are no caller-save registers at all. |
| 5167 | // If SIMD instructions are present, however, we force spilling all live SIMD |
| 5168 | // registers in full width (since the runtime only saves/restores lower part). |
Aart Bik | 5576f37 | 2017-03-23 16:17:37 -0700 | [diff] [blame^] | 5169 | locations->SetCustomSlowPathCallerSaves( |
| 5170 | GetGraph()->HasSIMD() ? RegisterSet::AllFpu() : RegisterSet::Empty()); |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5171 | } |
| 5172 | |
| 5173 | void InstructionCodeGeneratorX86_64::VisitSuspendCheck(HSuspendCheck* instruction) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 5174 | HBasicBlock* block = instruction->GetBlock(); |
| 5175 | if (block->GetLoopInformation() != nullptr) { |
| 5176 | DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction); |
| 5177 | // The back edge will generate the suspend check. |
| 5178 | return; |
| 5179 | } |
| 5180 | if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) { |
| 5181 | // The goto will generate the suspend check. |
| 5182 | return; |
| 5183 | } |
| 5184 | GenerateSuspendCheck(instruction, nullptr); |
| 5185 | } |
| 5186 | |
| 5187 | void InstructionCodeGeneratorX86_64::GenerateSuspendCheck(HSuspendCheck* instruction, |
| 5188 | HBasicBlock* successor) { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5189 | SuspendCheckSlowPathX86_64* slow_path = |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 5190 | down_cast<SuspendCheckSlowPathX86_64*>(instruction->GetSlowPath()); |
| 5191 | if (slow_path == nullptr) { |
| 5192 | slow_path = new (GetGraph()->GetArena()) SuspendCheckSlowPathX86_64(instruction, successor); |
| 5193 | instruction->SetSlowPath(slow_path); |
| 5194 | codegen_->AddSlowPath(slow_path); |
| 5195 | if (successor != nullptr) { |
| 5196 | DCHECK(successor->IsLoopHeader()); |
| 5197 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(instruction); |
| 5198 | } |
| 5199 | } else { |
| 5200 | DCHECK_EQ(slow_path->GetSuccessor(), successor); |
| 5201 | } |
| 5202 | |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 5203 | __ gs()->cmpw(Address::Absolute(Thread::ThreadFlagsOffset<kX86_64PointerSize>().Int32Value(), |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5204 | /* no_rip */ true), |
| 5205 | Immediate(0)); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 5206 | if (successor == nullptr) { |
| 5207 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 5208 | __ Bind(slow_path->GetReturnLabel()); |
| 5209 | } else { |
| 5210 | __ j(kEqual, codegen_->GetLabelOf(successor)); |
| 5211 | __ jmp(slow_path->GetEntryLabel()); |
| 5212 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5213 | } |
| 5214 | |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5215 | X86_64Assembler* ParallelMoveResolverX86_64::GetAssembler() const { |
| 5216 | return codegen_->GetAssembler(); |
| 5217 | } |
| 5218 | |
| 5219 | void ParallelMoveResolverX86_64::EmitMove(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5220 | MoveOperands* move = moves_[index]; |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5221 | Location source = move->GetSource(); |
| 5222 | Location destination = move->GetDestination(); |
| 5223 | |
| 5224 | if (source.IsRegister()) { |
| 5225 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5226 | __ movq(destination.AsRegister<CpuRegister>(), source.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5227 | } else if (destination.IsStackSlot()) { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5228 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5229 | source.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5230 | } else { |
| 5231 | DCHECK(destination.IsDoubleStackSlot()); |
| 5232 | __ movq(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5233 | source.AsRegister<CpuRegister>()); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5234 | } |
| 5235 | } else if (source.IsStackSlot()) { |
| 5236 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5237 | __ movl(destination.AsRegister<CpuRegister>(), |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5238 | Address(CpuRegister(RSP), source.GetStackIndex())); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5239 | } else if (destination.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5240 | __ movss(destination.AsFpuRegister<XmmRegister>(), |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5241 | Address(CpuRegister(RSP), source.GetStackIndex())); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5242 | } else { |
| 5243 | DCHECK(destination.IsStackSlot()); |
| 5244 | __ movl(CpuRegister(TMP), Address(CpuRegister(RSP), source.GetStackIndex())); |
| 5245 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), CpuRegister(TMP)); |
| 5246 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5247 | } else if (source.IsDoubleStackSlot()) { |
| 5248 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5249 | __ movq(destination.AsRegister<CpuRegister>(), |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5250 | Address(CpuRegister(RSP), source.GetStackIndex())); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5251 | } else if (destination.IsFpuRegister()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 5252 | __ movsd(destination.AsFpuRegister<XmmRegister>(), |
| 5253 | Address(CpuRegister(RSP), source.GetStackIndex())); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5254 | } else { |
Nicolas Geoffray | c8147a7 | 2014-10-21 16:06:20 +0100 | [diff] [blame] | 5255 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5256 | __ movq(CpuRegister(TMP), Address(CpuRegister(RSP), source.GetStackIndex())); |
| 5257 | __ movq(Address(CpuRegister(RSP), destination.GetStackIndex()), CpuRegister(TMP)); |
| 5258 | } |
Aart Bik | 5576f37 | 2017-03-23 16:17:37 -0700 | [diff] [blame^] | 5259 | } else if (source.IsSIMDStackSlot()) { |
| 5260 | DCHECK(destination.IsFpuRegister()); |
| 5261 | __ movups(destination.AsFpuRegister<XmmRegister>(), |
| 5262 | Address(CpuRegister(RSP), source.GetStackIndex())); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5263 | } else if (source.IsConstant()) { |
| 5264 | HConstant* constant = source.GetConstant(); |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 5265 | if (constant->IsIntConstant() || constant->IsNullConstant()) { |
| 5266 | int32_t value = CodeGenerator::GetInt32ValueOf(constant); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5267 | if (destination.IsRegister()) { |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 5268 | if (value == 0) { |
| 5269 | __ xorl(destination.AsRegister<CpuRegister>(), destination.AsRegister<CpuRegister>()); |
| 5270 | } else { |
| 5271 | __ movl(destination.AsRegister<CpuRegister>(), Immediate(value)); |
| 5272 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5273 | } else { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5274 | DCHECK(destination.IsStackSlot()) << destination; |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 5275 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), Immediate(value)); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5276 | } |
| 5277 | } else if (constant->IsLongConstant()) { |
| 5278 | int64_t value = constant->AsLongConstant()->GetValue(); |
| 5279 | if (destination.IsRegister()) { |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 5280 | codegen_->Load64BitValue(destination.AsRegister<CpuRegister>(), value); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5281 | } else { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5282 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 5283 | codegen_->Store64BitValueToStack(destination, value); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5284 | } |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5285 | } else if (constant->IsFloatConstant()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5286 | float fp_value = constant->AsFloatConstant()->GetValue(); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5287 | if (destination.IsFpuRegister()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5288 | XmmRegister dest = destination.AsFpuRegister<XmmRegister>(); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 5289 | codegen_->Load32BitValue(dest, fp_value); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5290 | } else { |
| 5291 | DCHECK(destination.IsStackSlot()) << destination; |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 5292 | Immediate imm(bit_cast<int32_t, float>(fp_value)); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5293 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), imm); |
| 5294 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5295 | } else { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5296 | DCHECK(constant->IsDoubleConstant()) << constant->DebugName(); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5297 | double fp_value = constant->AsDoubleConstant()->GetValue(); |
Roland Levillain | da4d79b | 2015-03-24 14:36:11 +0000 | [diff] [blame] | 5298 | int64_t value = bit_cast<int64_t, double>(fp_value); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5299 | if (destination.IsFpuRegister()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5300 | XmmRegister dest = destination.AsFpuRegister<XmmRegister>(); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 5301 | codegen_->Load64BitValue(dest, fp_value); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5302 | } else { |
| 5303 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 5304 | codegen_->Store64BitValueToStack(destination, value); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5305 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5306 | } |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5307 | } else if (source.IsFpuRegister()) { |
| 5308 | if (destination.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5309 | __ movaps(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5310 | } else if (destination.IsStackSlot()) { |
| 5311 | __ movss(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5312 | source.AsFpuRegister<XmmRegister>()); |
Aart Bik | 5576f37 | 2017-03-23 16:17:37 -0700 | [diff] [blame^] | 5313 | } else if (destination.IsDoubleStackSlot()) { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5314 | __ movsd(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5315 | source.AsFpuRegister<XmmRegister>()); |
Aart Bik | 5576f37 | 2017-03-23 16:17:37 -0700 | [diff] [blame^] | 5316 | } else { |
| 5317 | DCHECK(destination.IsSIMDStackSlot()); |
| 5318 | __ movups(Address(CpuRegister(RSP), destination.GetStackIndex()), |
| 5319 | source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5320 | } |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5321 | } |
| 5322 | } |
| 5323 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5324 | void ParallelMoveResolverX86_64::Exchange32(CpuRegister reg, int mem) { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5325 | __ movl(CpuRegister(TMP), Address(CpuRegister(RSP), mem)); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5326 | __ movl(Address(CpuRegister(RSP), mem), reg); |
| 5327 | __ movl(reg, CpuRegister(TMP)); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5328 | } |
| 5329 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5330 | void ParallelMoveResolverX86_64::Exchange32(int mem1, int mem2) { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5331 | ScratchRegisterScope ensure_scratch( |
| 5332 | this, TMP, RAX, codegen_->GetNumberOfCoreRegisters()); |
| 5333 | |
| 5334 | int stack_offset = ensure_scratch.IsSpilled() ? kX86_64WordSize : 0; |
| 5335 | __ movl(CpuRegister(TMP), Address(CpuRegister(RSP), mem1 + stack_offset)); |
| 5336 | __ movl(CpuRegister(ensure_scratch.GetRegister()), |
| 5337 | Address(CpuRegister(RSP), mem2 + stack_offset)); |
| 5338 | __ movl(Address(CpuRegister(RSP), mem2 + stack_offset), CpuRegister(TMP)); |
| 5339 | __ movl(Address(CpuRegister(RSP), mem1 + stack_offset), |
| 5340 | CpuRegister(ensure_scratch.GetRegister())); |
| 5341 | } |
| 5342 | |
Mark Mendell | 8a1c728 | 2015-06-29 15:41:28 -0400 | [diff] [blame] | 5343 | void ParallelMoveResolverX86_64::Exchange64(CpuRegister reg1, CpuRegister reg2) { |
| 5344 | __ movq(CpuRegister(TMP), reg1); |
| 5345 | __ movq(reg1, reg2); |
| 5346 | __ movq(reg2, CpuRegister(TMP)); |
| 5347 | } |
| 5348 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5349 | void ParallelMoveResolverX86_64::Exchange64(CpuRegister reg, int mem) { |
| 5350 | __ movq(CpuRegister(TMP), Address(CpuRegister(RSP), mem)); |
| 5351 | __ movq(Address(CpuRegister(RSP), mem), reg); |
| 5352 | __ movq(reg, CpuRegister(TMP)); |
| 5353 | } |
| 5354 | |
| 5355 | void ParallelMoveResolverX86_64::Exchange64(int mem1, int mem2) { |
| 5356 | ScratchRegisterScope ensure_scratch( |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5357 | this, TMP, RAX, codegen_->GetNumberOfCoreRegisters()); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5358 | |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5359 | int stack_offset = ensure_scratch.IsSpilled() ? kX86_64WordSize : 0; |
| 5360 | __ movq(CpuRegister(TMP), Address(CpuRegister(RSP), mem1 + stack_offset)); |
| 5361 | __ movq(CpuRegister(ensure_scratch.GetRegister()), |
| 5362 | Address(CpuRegister(RSP), mem2 + stack_offset)); |
| 5363 | __ movq(Address(CpuRegister(RSP), mem2 + stack_offset), CpuRegister(TMP)); |
| 5364 | __ movq(Address(CpuRegister(RSP), mem1 + stack_offset), |
| 5365 | CpuRegister(ensure_scratch.GetRegister())); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5366 | } |
| 5367 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5368 | void ParallelMoveResolverX86_64::Exchange32(XmmRegister reg, int mem) { |
| 5369 | __ movl(CpuRegister(TMP), Address(CpuRegister(RSP), mem)); |
| 5370 | __ movss(Address(CpuRegister(RSP), mem), reg); |
| 5371 | __ movd(reg, CpuRegister(TMP)); |
| 5372 | } |
| 5373 | |
| 5374 | void ParallelMoveResolverX86_64::Exchange64(XmmRegister reg, int mem) { |
| 5375 | __ movq(CpuRegister(TMP), Address(CpuRegister(RSP), mem)); |
| 5376 | __ movsd(Address(CpuRegister(RSP), mem), reg); |
| 5377 | __ movd(reg, CpuRegister(TMP)); |
| 5378 | } |
| 5379 | |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5380 | void ParallelMoveResolverX86_64::EmitSwap(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5381 | MoveOperands* move = moves_[index]; |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5382 | Location source = move->GetSource(); |
| 5383 | Location destination = move->GetDestination(); |
| 5384 | |
| 5385 | if (source.IsRegister() && destination.IsRegister()) { |
Mark Mendell | 8a1c728 | 2015-06-29 15:41:28 -0400 | [diff] [blame] | 5386 | Exchange64(source.AsRegister<CpuRegister>(), destination.AsRegister<CpuRegister>()); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5387 | } else if (source.IsRegister() && destination.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5388 | Exchange32(source.AsRegister<CpuRegister>(), destination.GetStackIndex()); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5389 | } else if (source.IsStackSlot() && destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5390 | Exchange32(destination.AsRegister<CpuRegister>(), source.GetStackIndex()); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5391 | } else if (source.IsStackSlot() && destination.IsStackSlot()) { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5392 | Exchange32(destination.GetStackIndex(), source.GetStackIndex()); |
| 5393 | } else if (source.IsRegister() && destination.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5394 | Exchange64(source.AsRegister<CpuRegister>(), destination.GetStackIndex()); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5395 | } else if (source.IsDoubleStackSlot() && destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5396 | Exchange64(destination.AsRegister<CpuRegister>(), source.GetStackIndex()); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5397 | } else if (source.IsDoubleStackSlot() && destination.IsDoubleStackSlot()) { |
| 5398 | Exchange64(destination.GetStackIndex(), source.GetStackIndex()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5399 | } else if (source.IsFpuRegister() && destination.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5400 | __ movd(CpuRegister(TMP), source.AsFpuRegister<XmmRegister>()); |
| 5401 | __ movaps(source.AsFpuRegister<XmmRegister>(), destination.AsFpuRegister<XmmRegister>()); |
| 5402 | __ movd(destination.AsFpuRegister<XmmRegister>(), CpuRegister(TMP)); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5403 | } else if (source.IsFpuRegister() && destination.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5404 | Exchange32(source.AsFpuRegister<XmmRegister>(), destination.GetStackIndex()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5405 | } else if (source.IsStackSlot() && destination.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5406 | Exchange32(destination.AsFpuRegister<XmmRegister>(), source.GetStackIndex()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5407 | } else if (source.IsFpuRegister() && destination.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5408 | Exchange64(source.AsFpuRegister<XmmRegister>(), destination.GetStackIndex()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5409 | } else if (source.IsDoubleStackSlot() && destination.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5410 | Exchange64(destination.AsFpuRegister<XmmRegister>(), source.GetStackIndex()); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5411 | } else { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5412 | LOG(FATAL) << "Unimplemented swap between " << source << " and " << destination; |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5413 | } |
| 5414 | } |
| 5415 | |
| 5416 | |
| 5417 | void ParallelMoveResolverX86_64::SpillScratch(int reg) { |
| 5418 | __ pushq(CpuRegister(reg)); |
| 5419 | } |
| 5420 | |
| 5421 | |
| 5422 | void ParallelMoveResolverX86_64::RestoreScratch(int reg) { |
| 5423 | __ popq(CpuRegister(reg)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 5424 | } |
| 5425 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5426 | void InstructionCodeGeneratorX86_64::GenerateClassInitializationCheck( |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 5427 | SlowPathCode* slow_path, CpuRegister class_reg) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5428 | __ cmpl(Address(class_reg, mirror::Class::StatusOffset().Int32Value()), |
| 5429 | Immediate(mirror::Class::kStatusInitialized)); |
| 5430 | __ j(kLess, slow_path->GetEntryLabel()); |
| 5431 | __ Bind(slow_path->GetExitLabel()); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5432 | // No need for memory fence, thanks to the x86-64 memory model. |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5433 | } |
| 5434 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5435 | HLoadClass::LoadKind CodeGeneratorX86_64::GetSupportedLoadClassKind( |
| 5436 | HLoadClass::LoadKind desired_class_load_kind) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5437 | switch (desired_class_load_kind) { |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 5438 | case HLoadClass::LoadKind::kInvalid: |
| 5439 | LOG(FATAL) << "UNREACHABLE"; |
| 5440 | UNREACHABLE(); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5441 | case HLoadClass::LoadKind::kReferrersClass: |
| 5442 | break; |
| 5443 | case HLoadClass::LoadKind::kBootImageLinkTimeAddress: |
| 5444 | DCHECK(!GetCompilerOptions().GetCompilePic()); |
| 5445 | // We prefer the always-available RIP-relative address for the x86-64 boot image. |
| 5446 | return HLoadClass::LoadKind::kBootImageLinkTimePcRelative; |
| 5447 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: |
| 5448 | DCHECK(GetCompilerOptions().GetCompilePic()); |
| 5449 | break; |
| 5450 | case HLoadClass::LoadKind::kBootImageAddress: |
| 5451 | break; |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5452 | case HLoadClass::LoadKind::kBssEntry: |
| 5453 | DCHECK(!Runtime::Current()->UseJitCompilation()); |
| 5454 | break; |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 5455 | case HLoadClass::LoadKind::kJitTableAddress: |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5456 | DCHECK(Runtime::Current()->UseJitCompilation()); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5457 | break; |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5458 | case HLoadClass::LoadKind::kDexCacheViaMethod: |
| 5459 | break; |
| 5460 | } |
| 5461 | return desired_class_load_kind; |
| 5462 | } |
| 5463 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5464 | void LocationsBuilderX86_64::VisitLoadClass(HLoadClass* cls) { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5465 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
| 5466 | if (load_kind == HLoadClass::LoadKind::kDexCacheViaMethod) { |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 5467 | // Custom calling convention: RAX serves as both input and output. |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5468 | CodeGenerator::CreateLoadClassRuntimeCallLocationSummary( |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5469 | cls, |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 5470 | Location::RegisterLocation(RAX), |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5471 | Location::RegisterLocation(RAX)); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5472 | return; |
| 5473 | } |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5474 | DCHECK(!cls->NeedsAccessCheck()); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5475 | |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5476 | const bool requires_read_barrier = kEmitCompilerReadBarrier && !cls->IsInBootImage(); |
| 5477 | LocationSummary::CallKind call_kind = (cls->NeedsEnvironment() || requires_read_barrier) |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5478 | ? LocationSummary::kCallOnSlowPath |
| 5479 | : LocationSummary::kNoCall; |
| 5480 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(cls, call_kind); |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5481 | if (kUseBakerReadBarrier && requires_read_barrier && !cls->NeedsEnvironment()) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 5482 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5483 | } |
| 5484 | |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5485 | if (load_kind == HLoadClass::LoadKind::kReferrersClass) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5486 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5487 | } |
| 5488 | locations->SetOut(Location::RequiresRegister()); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 5489 | if (load_kind == HLoadClass::LoadKind::kBssEntry) { |
| 5490 | if (!kUseReadBarrier || kUseBakerReadBarrier) { |
| 5491 | // Rely on the type resolution and/or initialization to save everything. |
| 5492 | // Custom calling convention: RAX serves as both input and output. |
| 5493 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 5494 | caller_saves.Add(Location::RegisterLocation(RAX)); |
| 5495 | locations->SetCustomSlowPathCallerSaves(caller_saves); |
| 5496 | } else { |
| 5497 | // For non-Baker read barrier we have a temp-clobbering call. |
| 5498 | } |
| 5499 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5500 | } |
| 5501 | |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 5502 | Label* CodeGeneratorX86_64::NewJitRootClassPatch(const DexFile& dex_file, |
| 5503 | dex::TypeIndex dex_index, |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 5504 | Handle<mirror::Class> handle) { |
| 5505 | jit_class_roots_.Overwrite( |
| 5506 | TypeReference(&dex_file, dex_index), reinterpret_cast64<uint64_t>(handle.GetReference())); |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 5507 | // Add a patch entry and return the label. |
| 5508 | jit_class_patches_.emplace_back(dex_file, dex_index.index_); |
| 5509 | PatchInfo<Label>* info = &jit_class_patches_.back(); |
| 5510 | return &info->label; |
| 5511 | } |
| 5512 | |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 5513 | // NO_THREAD_SAFETY_ANALYSIS as we manipulate handles whose internal object we know does not |
| 5514 | // move. |
| 5515 | void InstructionCodeGeneratorX86_64::VisitLoadClass(HLoadClass* cls) NO_THREAD_SAFETY_ANALYSIS { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5516 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
| 5517 | if (load_kind == HLoadClass::LoadKind::kDexCacheViaMethod) { |
| 5518 | codegen_->GenerateLoadClassRuntimeCall(cls); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 5519 | return; |
| 5520 | } |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5521 | DCHECK(!cls->NeedsAccessCheck()); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 5522 | |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5523 | LocationSummary* locations = cls->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5524 | Location out_loc = locations->Out(); |
| 5525 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5526 | |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 5527 | const ReadBarrierOption read_barrier_option = cls->IsInBootImage() |
| 5528 | ? kWithoutReadBarrier |
| 5529 | : kCompilerReadBarrierOption; |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5530 | bool generate_null_check = false; |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5531 | switch (load_kind) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5532 | case HLoadClass::LoadKind::kReferrersClass: { |
| 5533 | DCHECK(!cls->CanCallRuntime()); |
| 5534 | DCHECK(!cls->MustGenerateClinitCheck()); |
| 5535 | // /* GcRoot<mirror::Class> */ out = current_method->declaring_class_ |
| 5536 | CpuRegister current_method = locations->InAt(0).AsRegister<CpuRegister>(); |
| 5537 | GenerateGcRootFieldLoad( |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5538 | cls, |
| 5539 | out_loc, |
| 5540 | Address(current_method, ArtMethod::DeclaringClassOffset().Int32Value()), |
Roland Levillain | 00468f3 | 2016-10-27 18:02:48 +0100 | [diff] [blame] | 5541 | /* fixup_label */ nullptr, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 5542 | read_barrier_option); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5543 | break; |
| 5544 | } |
| 5545 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5546 | DCHECK(codegen_->GetCompilerOptions().IsBootImage()); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 5547 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5548 | __ leal(out, Address::Absolute(CodeGeneratorX86_64::kDummy32BitOffset, /* no_rip */ false)); |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 5549 | codegen_->RecordBootTypePatch(cls); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5550 | break; |
| 5551 | case HLoadClass::LoadKind::kBootImageAddress: { |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 5552 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 5553 | uint32_t address = dchecked_integral_cast<uint32_t>( |
| 5554 | reinterpret_cast<uintptr_t>(cls->GetClass().Get())); |
| 5555 | DCHECK_NE(address, 0u); |
Colin Cross | 0bd9717 | 2017-03-15 16:33:27 -0700 | [diff] [blame] | 5556 | __ movl(out, Immediate(static_cast<int32_t>(address))); // Zero-extended. |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5557 | break; |
| 5558 | } |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5559 | case HLoadClass::LoadKind::kBssEntry: { |
| 5560 | Address address = Address::Absolute(CodeGeneratorX86_64::kDummy32BitOffset, |
| 5561 | /* no_rip */ false); |
| 5562 | Label* fixup_label = codegen_->NewTypeBssEntryPatch(cls); |
| 5563 | // /* GcRoot<mirror::Class> */ out = *address /* PC-relative */ |
| 5564 | GenerateGcRootFieldLoad(cls, out_loc, address, fixup_label, read_barrier_option); |
| 5565 | generate_null_check = true; |
| 5566 | break; |
| 5567 | } |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 5568 | case HLoadClass::LoadKind::kJitTableAddress: { |
| 5569 | Address address = Address::Absolute(CodeGeneratorX86_64::kDummy32BitOffset, |
| 5570 | /* no_rip */ true); |
| 5571 | Label* fixup_label = |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 5572 | codegen_->NewJitRootClassPatch(cls->GetDexFile(), cls->GetTypeIndex(), cls->GetClass()); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5573 | // /* GcRoot<mirror::Class> */ out = *address |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 5574 | GenerateGcRootFieldLoad(cls, out_loc, address, fixup_label, read_barrier_option); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5575 | break; |
| 5576 | } |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5577 | default: |
| 5578 | LOG(FATAL) << "Unexpected load kind: " << cls->GetLoadKind(); |
| 5579 | UNREACHABLE(); |
| 5580 | } |
| 5581 | |
| 5582 | if (generate_null_check || cls->MustGenerateClinitCheck()) { |
| 5583 | DCHECK(cls->CanCallRuntime()); |
| 5584 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathX86_64( |
| 5585 | cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck()); |
| 5586 | codegen_->AddSlowPath(slow_path); |
| 5587 | if (generate_null_check) { |
| 5588 | __ testl(out, out); |
| 5589 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 5590 | } |
| 5591 | if (cls->MustGenerateClinitCheck()) { |
| 5592 | GenerateClassInitializationCheck(slow_path, out); |
| 5593 | } else { |
| 5594 | __ Bind(slow_path->GetExitLabel()); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5595 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5596 | } |
| 5597 | } |
| 5598 | |
| 5599 | void LocationsBuilderX86_64::VisitClinitCheck(HClinitCheck* check) { |
| 5600 | LocationSummary* locations = |
| 5601 | new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath); |
| 5602 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5603 | if (check->HasUses()) { |
| 5604 | locations->SetOut(Location::SameAsFirstInput()); |
| 5605 | } |
| 5606 | } |
| 5607 | |
| 5608 | void InstructionCodeGeneratorX86_64::VisitClinitCheck(HClinitCheck* check) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5609 | // We assume the class to not be null. |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 5610 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathX86_64( |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5611 | check->GetLoadClass(), check, check->GetDexPc(), true); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5612 | codegen_->AddSlowPath(slow_path); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 5613 | GenerateClassInitializationCheck(slow_path, |
| 5614 | check->GetLocations()->InAt(0).AsRegister<CpuRegister>()); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5615 | } |
| 5616 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5617 | HLoadString::LoadKind CodeGeneratorX86_64::GetSupportedLoadStringKind( |
| 5618 | HLoadString::LoadKind desired_string_load_kind) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5619 | switch (desired_string_load_kind) { |
| 5620 | case HLoadString::LoadKind::kBootImageLinkTimeAddress: |
| 5621 | DCHECK(!GetCompilerOptions().GetCompilePic()); |
| 5622 | // We prefer the always-available RIP-relative address for the x86-64 boot image. |
| 5623 | return HLoadString::LoadKind::kBootImageLinkTimePcRelative; |
| 5624 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: |
| 5625 | DCHECK(GetCompilerOptions().GetCompilePic()); |
| 5626 | break; |
| 5627 | case HLoadString::LoadKind::kBootImageAddress: |
| 5628 | break; |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5629 | case HLoadString::LoadKind::kBssEntry: |
Calin Juravle | ffc8707 | 2016-04-20 14:22:09 +0100 | [diff] [blame] | 5630 | DCHECK(!Runtime::Current()->UseJitCompilation()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5631 | break; |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 5632 | case HLoadString::LoadKind::kJitTableAddress: |
| 5633 | DCHECK(Runtime::Current()->UseJitCompilation()); |
| 5634 | break; |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5635 | case HLoadString::LoadKind::kDexCacheViaMethod: |
| 5636 | break; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5637 | } |
| 5638 | return desired_string_load_kind; |
| 5639 | } |
| 5640 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5641 | void LocationsBuilderX86_64::VisitLoadString(HLoadString* load) { |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 5642 | LocationSummary::CallKind call_kind = CodeGenerator::GetLoadStringCallKind(load); |
Nicolas Geoffray | 917d016 | 2015-11-24 18:25:35 +0000 | [diff] [blame] | 5643 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(load, call_kind); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5644 | if (load->GetLoadKind() == HLoadString::LoadKind::kDexCacheViaMethod) { |
Christina Wadsworth | abb341b | 2016-08-31 16:29:44 -0700 | [diff] [blame] | 5645 | locations->SetOut(Location::RegisterLocation(RAX)); |
| 5646 | } else { |
| 5647 | locations->SetOut(Location::RequiresRegister()); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 5648 | if (load->GetLoadKind() == HLoadString::LoadKind::kBssEntry) { |
| 5649 | if (!kUseReadBarrier || kUseBakerReadBarrier) { |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 5650 | // Rely on the pResolveString to save everything. |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 5651 | // Custom calling convention: RAX serves as both input and output. |
| 5652 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 5653 | caller_saves.Add(Location::RegisterLocation(RAX)); |
| 5654 | locations->SetCustomSlowPathCallerSaves(caller_saves); |
| 5655 | } else { |
| 5656 | // For non-Baker read barrier we have a temp-clobbering call. |
| 5657 | } |
| 5658 | } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5659 | } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5660 | } |
| 5661 | |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 5662 | Label* CodeGeneratorX86_64::NewJitRootStringPatch(const DexFile& dex_file, |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 5663 | dex::StringIndex dex_index, |
| 5664 | Handle<mirror::String> handle) { |
| 5665 | jit_string_roots_.Overwrite( |
| 5666 | StringReference(&dex_file, dex_index), reinterpret_cast64<uint64_t>(handle.GetReference())); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 5667 | // Add a patch entry and return the label. |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 5668 | jit_string_patches_.emplace_back(dex_file, dex_index.index_); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 5669 | PatchInfo<Label>* info = &jit_string_patches_.back(); |
| 5670 | return &info->label; |
| 5671 | } |
| 5672 | |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 5673 | // NO_THREAD_SAFETY_ANALYSIS as we manipulate handles whose internal object we know does not |
| 5674 | // move. |
| 5675 | void InstructionCodeGeneratorX86_64::VisitLoadString(HLoadString* load) NO_THREAD_SAFETY_ANALYSIS { |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 5676 | LocationSummary* locations = load->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5677 | Location out_loc = locations->Out(); |
| 5678 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5679 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5680 | switch (load->GetLoadKind()) { |
| 5681 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: { |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5682 | DCHECK(codegen_->GetCompilerOptions().IsBootImage()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5683 | __ leal(out, Address::Absolute(CodeGeneratorX86_64::kDummy32BitOffset, /* no_rip */ false)); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5684 | codegen_->RecordBootStringPatch(load); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5685 | return; // No dex cache slow path. |
| 5686 | } |
| 5687 | case HLoadString::LoadKind::kBootImageAddress: { |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 5688 | uint32_t address = dchecked_integral_cast<uint32_t>( |
| 5689 | reinterpret_cast<uintptr_t>(load->GetString().Get())); |
| 5690 | DCHECK_NE(address, 0u); |
Colin Cross | 0bd9717 | 2017-03-15 16:33:27 -0700 | [diff] [blame] | 5691 | __ movl(out, Immediate(static_cast<int32_t>(address))); // Zero-extended. |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5692 | return; // No dex cache slow path. |
| 5693 | } |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5694 | case HLoadString::LoadKind::kBssEntry: { |
| 5695 | Address address = Address::Absolute(CodeGeneratorX86_64::kDummy32BitOffset, |
| 5696 | /* no_rip */ false); |
| 5697 | Label* fixup_label = codegen_->NewStringBssEntryPatch(load); |
| 5698 | // /* GcRoot<mirror::Class> */ out = *address /* PC-relative */ |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 5699 | GenerateGcRootFieldLoad(load, out_loc, address, fixup_label, kCompilerReadBarrierOption); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5700 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) LoadStringSlowPathX86_64(load); |
| 5701 | codegen_->AddSlowPath(slow_path); |
| 5702 | __ testl(out, out); |
| 5703 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 5704 | __ Bind(slow_path->GetExitLabel()); |
| 5705 | return; |
| 5706 | } |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 5707 | case HLoadString::LoadKind::kJitTableAddress: { |
| 5708 | Address address = Address::Absolute(CodeGeneratorX86_64::kDummy32BitOffset, |
| 5709 | /* no_rip */ true); |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 5710 | Label* fixup_label = codegen_->NewJitRootStringPatch( |
| 5711 | load->GetDexFile(), load->GetStringIndex(), load->GetString()); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 5712 | // /* GcRoot<mirror::String> */ out = *address |
| 5713 | GenerateGcRootFieldLoad(load, out_loc, address, fixup_label, kCompilerReadBarrierOption); |
| 5714 | return; |
| 5715 | } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5716 | default: |
Christina Wadsworth | bf44e0e | 2016-08-18 10:37:42 -0700 | [diff] [blame] | 5717 | break; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5718 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5719 | |
Christina Wadsworth | bf44e0e | 2016-08-18 10:37:42 -0700 | [diff] [blame] | 5720 | // 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] | 5721 | // Custom calling convention: RAX serves as both input and output. |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 5722 | __ movl(CpuRegister(RAX), Immediate(load->GetStringIndex().index_)); |
Christina Wadsworth | abb341b | 2016-08-31 16:29:44 -0700 | [diff] [blame] | 5723 | codegen_->InvokeRuntime(kQuickResolveString, |
| 5724 | load, |
| 5725 | load->GetDexPc()); |
| 5726 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5727 | } |
| 5728 | |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 5729 | static Address GetExceptionTlsAddress() { |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 5730 | return Address::Absolute(Thread::ExceptionOffset<kX86_64PointerSize>().Int32Value(), |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5731 | /* no_rip */ true); |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 5732 | } |
| 5733 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5734 | void LocationsBuilderX86_64::VisitLoadException(HLoadException* load) { |
| 5735 | LocationSummary* locations = |
| 5736 | new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall); |
| 5737 | locations->SetOut(Location::RequiresRegister()); |
| 5738 | } |
| 5739 | |
| 5740 | void InstructionCodeGeneratorX86_64::VisitLoadException(HLoadException* load) { |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 5741 | __ gs()->movl(load->GetLocations()->Out().AsRegister<CpuRegister>(), GetExceptionTlsAddress()); |
| 5742 | } |
| 5743 | |
| 5744 | void LocationsBuilderX86_64::VisitClearException(HClearException* clear) { |
| 5745 | new (GetGraph()->GetArena()) LocationSummary(clear, LocationSummary::kNoCall); |
| 5746 | } |
| 5747 | |
| 5748 | void InstructionCodeGeneratorX86_64::VisitClearException(HClearException* clear ATTRIBUTE_UNUSED) { |
| 5749 | __ gs()->movl(GetExceptionTlsAddress(), Immediate(0)); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5750 | } |
| 5751 | |
| 5752 | void LocationsBuilderX86_64::VisitThrow(HThrow* instruction) { |
| 5753 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 5754 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5755 | InvokeRuntimeCallingConvention calling_convention; |
| 5756 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 5757 | } |
| 5758 | |
| 5759 | void InstructionCodeGeneratorX86_64::VisitThrow(HThrow* instruction) { |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 5760 | codegen_->InvokeRuntime(kQuickDeliverException, instruction, instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 5761 | CheckEntrypointTypes<kQuickDeliverException, void, mirror::Object*>(); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5762 | } |
| 5763 | |
Nicolas Geoffray | 53b07bd | 2016-11-05 15:09:19 +0000 | [diff] [blame] | 5764 | static bool CheckCastTypeCheckNeedsATemporary(TypeCheckKind type_check_kind) { |
| 5765 | if (type_check_kind == TypeCheckKind::kInterfaceCheck && !kPoisonHeapReferences) { |
Mathieu Chartier | cdba73b | 2016-11-03 19:23:06 -0700 | [diff] [blame] | 5766 | // We need a temporary for holding the iftable length. |
| 5767 | return true; |
| 5768 | } |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5769 | return kEmitCompilerReadBarrier && |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 5770 | !kUseBakerReadBarrier && |
| 5771 | (type_check_kind == TypeCheckKind::kAbstractClassCheck || |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5772 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 5773 | type_check_kind == TypeCheckKind::kArrayObjectCheck); |
| 5774 | } |
| 5775 | |
Nicolas Geoffray | 53b07bd | 2016-11-05 15:09:19 +0000 | [diff] [blame] | 5776 | static bool InstanceOfTypeCheckNeedsATemporary(TypeCheckKind type_check_kind) { |
| 5777 | return kEmitCompilerReadBarrier && |
| 5778 | !kUseBakerReadBarrier && |
| 5779 | (type_check_kind == TypeCheckKind::kAbstractClassCheck || |
| 5780 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 5781 | type_check_kind == TypeCheckKind::kArrayObjectCheck); |
| 5782 | } |
| 5783 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5784 | void LocationsBuilderX86_64::VisitInstanceOf(HInstanceOf* instruction) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5785 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5786 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5787 | bool baker_read_barrier_slow_path = false; |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5788 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5789 | case TypeCheckKind::kExactCheck: |
| 5790 | case TypeCheckKind::kAbstractClassCheck: |
| 5791 | case TypeCheckKind::kClassHierarchyCheck: |
| 5792 | case TypeCheckKind::kArrayObjectCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5793 | call_kind = |
| 5794 | kEmitCompilerReadBarrier ? LocationSummary::kCallOnSlowPath : LocationSummary::kNoCall; |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5795 | baker_read_barrier_slow_path = kUseBakerReadBarrier; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5796 | break; |
| 5797 | case TypeCheckKind::kArrayCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5798 | case TypeCheckKind::kUnresolvedCheck: |
| 5799 | case TypeCheckKind::kInterfaceCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5800 | call_kind = LocationSummary::kCallOnSlowPath; |
| 5801 | break; |
| 5802 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5803 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5804 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5805 | if (baker_read_barrier_slow_path) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 5806 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5807 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5808 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5809 | locations->SetInAt(1, Location::Any()); |
| 5810 | // Note that TypeCheckSlowPathX86_64 uses this "out" register too. |
| 5811 | locations->SetOut(Location::RequiresRegister()); |
| 5812 | // When read barriers are enabled, we need a temporary register for |
| 5813 | // some cases. |
Nicolas Geoffray | 53b07bd | 2016-11-05 15:09:19 +0000 | [diff] [blame] | 5814 | if (InstanceOfTypeCheckNeedsATemporary(type_check_kind)) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5815 | locations->AddTemp(Location::RequiresRegister()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5816 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5817 | } |
| 5818 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5819 | void InstructionCodeGeneratorX86_64::VisitInstanceOf(HInstanceOf* instruction) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5820 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5821 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5822 | Location obj_loc = locations->InAt(0); |
| 5823 | CpuRegister obj = obj_loc.AsRegister<CpuRegister>(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5824 | Location cls = locations->InAt(1); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5825 | Location out_loc = locations->Out(); |
| 5826 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
Nicolas Geoffray | 53b07bd | 2016-11-05 15:09:19 +0000 | [diff] [blame] | 5827 | Location maybe_temp_loc = InstanceOfTypeCheckNeedsATemporary(type_check_kind) ? |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5828 | locations->GetTemp(0) : |
| 5829 | Location::NoLocation(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5830 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5831 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 5832 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 5833 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 5834 | SlowPathCode* slow_path = nullptr; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5835 | NearLabel done, zero; |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5836 | |
| 5837 | // Return 0 if `obj` is null. |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 5838 | // Avoid null check if we know obj is not null. |
| 5839 | if (instruction->MustDoNullCheck()) { |
| 5840 | __ testl(obj, obj); |
| 5841 | __ j(kEqual, &zero); |
| 5842 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5843 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5844 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5845 | case TypeCheckKind::kExactCheck: { |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 5846 | // /* HeapReference<Class> */ out = obj->klass_ |
| 5847 | GenerateReferenceLoadTwoRegisters(instruction, |
| 5848 | out_loc, |
| 5849 | obj_loc, |
| 5850 | class_offset, |
| 5851 | kCompilerReadBarrierOption); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5852 | if (cls.IsRegister()) { |
| 5853 | __ cmpl(out, cls.AsRegister<CpuRegister>()); |
| 5854 | } else { |
| 5855 | DCHECK(cls.IsStackSlot()) << cls; |
| 5856 | __ cmpl(out, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 5857 | } |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 5858 | if (zero.IsLinked()) { |
| 5859 | // Classes must be equal for the instanceof to succeed. |
| 5860 | __ j(kNotEqual, &zero); |
| 5861 | __ movl(out, Immediate(1)); |
| 5862 | __ jmp(&done); |
| 5863 | } else { |
| 5864 | __ setcc(kEqual, out); |
| 5865 | // setcc only sets the low byte. |
| 5866 | __ andl(out, Immediate(1)); |
| 5867 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5868 | break; |
| 5869 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5870 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5871 | case TypeCheckKind::kAbstractClassCheck: { |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 5872 | // /* HeapReference<Class> */ out = obj->klass_ |
| 5873 | GenerateReferenceLoadTwoRegisters(instruction, |
| 5874 | out_loc, |
| 5875 | obj_loc, |
| 5876 | class_offset, |
| 5877 | kCompilerReadBarrierOption); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5878 | // If the class is abstract, we eagerly fetch the super class of the |
| 5879 | // object to avoid doing a comparison we know will fail. |
| 5880 | NearLabel loop, success; |
| 5881 | __ Bind(&loop); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5882 | // /* HeapReference<Class> */ out = out->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 5883 | GenerateReferenceLoadOneRegister(instruction, |
| 5884 | out_loc, |
| 5885 | super_offset, |
| 5886 | maybe_temp_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 5887 | kCompilerReadBarrierOption); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5888 | __ testl(out, out); |
| 5889 | // If `out` is null, we use it for the result, and jump to `done`. |
| 5890 | __ j(kEqual, &done); |
| 5891 | if (cls.IsRegister()) { |
| 5892 | __ cmpl(out, cls.AsRegister<CpuRegister>()); |
| 5893 | } else { |
| 5894 | DCHECK(cls.IsStackSlot()) << cls; |
| 5895 | __ cmpl(out, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 5896 | } |
| 5897 | __ j(kNotEqual, &loop); |
| 5898 | __ movl(out, Immediate(1)); |
| 5899 | if (zero.IsLinked()) { |
| 5900 | __ jmp(&done); |
| 5901 | } |
| 5902 | break; |
| 5903 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5904 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5905 | case TypeCheckKind::kClassHierarchyCheck: { |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 5906 | // /* HeapReference<Class> */ out = obj->klass_ |
| 5907 | GenerateReferenceLoadTwoRegisters(instruction, |
| 5908 | out_loc, |
| 5909 | obj_loc, |
| 5910 | class_offset, |
| 5911 | kCompilerReadBarrierOption); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5912 | // Walk over the class hierarchy to find a match. |
| 5913 | NearLabel loop, success; |
| 5914 | __ Bind(&loop); |
| 5915 | if (cls.IsRegister()) { |
| 5916 | __ cmpl(out, cls.AsRegister<CpuRegister>()); |
| 5917 | } else { |
| 5918 | DCHECK(cls.IsStackSlot()) << cls; |
| 5919 | __ cmpl(out, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 5920 | } |
| 5921 | __ j(kEqual, &success); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5922 | // /* HeapReference<Class> */ out = out->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 5923 | GenerateReferenceLoadOneRegister(instruction, |
| 5924 | out_loc, |
| 5925 | super_offset, |
| 5926 | maybe_temp_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 5927 | kCompilerReadBarrierOption); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5928 | __ testl(out, out); |
| 5929 | __ j(kNotEqual, &loop); |
| 5930 | // If `out` is null, we use it for the result, and jump to `done`. |
| 5931 | __ jmp(&done); |
| 5932 | __ Bind(&success); |
| 5933 | __ movl(out, Immediate(1)); |
| 5934 | if (zero.IsLinked()) { |
| 5935 | __ jmp(&done); |
| 5936 | } |
| 5937 | break; |
| 5938 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5939 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5940 | case TypeCheckKind::kArrayObjectCheck: { |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 5941 | // /* HeapReference<Class> */ out = obj->klass_ |
| 5942 | GenerateReferenceLoadTwoRegisters(instruction, |
| 5943 | out_loc, |
| 5944 | obj_loc, |
| 5945 | class_offset, |
| 5946 | kCompilerReadBarrierOption); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 5947 | // Do an exact check. |
| 5948 | NearLabel exact_check; |
| 5949 | if (cls.IsRegister()) { |
| 5950 | __ cmpl(out, cls.AsRegister<CpuRegister>()); |
| 5951 | } else { |
| 5952 | DCHECK(cls.IsStackSlot()) << cls; |
| 5953 | __ cmpl(out, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 5954 | } |
| 5955 | __ j(kEqual, &exact_check); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5956 | // 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] | 5957 | // /* HeapReference<Class> */ out = out->component_type_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 5958 | GenerateReferenceLoadOneRegister(instruction, |
| 5959 | out_loc, |
| 5960 | component_offset, |
| 5961 | maybe_temp_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 5962 | kCompilerReadBarrierOption); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5963 | __ testl(out, out); |
| 5964 | // If `out` is null, we use it for the result, and jump to `done`. |
| 5965 | __ j(kEqual, &done); |
| 5966 | __ cmpw(Address(out, primitive_offset), Immediate(Primitive::kPrimNot)); |
| 5967 | __ j(kNotEqual, &zero); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 5968 | __ Bind(&exact_check); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5969 | __ movl(out, Immediate(1)); |
| 5970 | __ jmp(&done); |
| 5971 | break; |
| 5972 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5973 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5974 | case TypeCheckKind::kArrayCheck: { |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 5975 | // No read barrier since the slow path will retry upon failure. |
| 5976 | // /* HeapReference<Class> */ out = obj->klass_ |
| 5977 | GenerateReferenceLoadTwoRegisters(instruction, |
| 5978 | out_loc, |
| 5979 | obj_loc, |
| 5980 | class_offset, |
| 5981 | kWithoutReadBarrier); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5982 | if (cls.IsRegister()) { |
| 5983 | __ cmpl(out, cls.AsRegister<CpuRegister>()); |
| 5984 | } else { |
| 5985 | DCHECK(cls.IsStackSlot()) << cls; |
| 5986 | __ cmpl(out, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 5987 | } |
| 5988 | DCHECK(locations->OnlyCallsOnSlowPath()); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5989 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathX86_64(instruction, |
| 5990 | /* is_fatal */ false); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5991 | codegen_->AddSlowPath(slow_path); |
| 5992 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 5993 | __ movl(out, Immediate(1)); |
| 5994 | if (zero.IsLinked()) { |
| 5995 | __ jmp(&done); |
| 5996 | } |
| 5997 | break; |
| 5998 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5999 | |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 6000 | case TypeCheckKind::kUnresolvedCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6001 | case TypeCheckKind::kInterfaceCheck: { |
| 6002 | // 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] | 6003 | // into the slow path for the unresolved and interface check |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6004 | // cases. |
| 6005 | // |
| 6006 | // We cannot directly call the InstanceofNonTrivial runtime |
| 6007 | // entry point without resorting to a type checking slow path |
| 6008 | // here (i.e. by calling InvokeRuntime directly), as it would |
| 6009 | // require to assign fixed registers for the inputs of this |
| 6010 | // HInstanceOf instruction (following the runtime calling |
| 6011 | // convention), which might be cluttered by the potential first |
| 6012 | // read barrier emission at the beginning of this method. |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6013 | // |
| 6014 | // TODO: Introduce a new runtime entry point taking the object |
| 6015 | // to test (instead of its class) as argument, and let it deal |
| 6016 | // with the read barrier issues. This will let us refactor this |
| 6017 | // case of the `switch` code as it was previously (with a direct |
| 6018 | // call to the runtime not using a type checking slow path). |
| 6019 | // This should also be beneficial for the other cases above. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6020 | DCHECK(locations->OnlyCallsOnSlowPath()); |
| 6021 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathX86_64(instruction, |
| 6022 | /* is_fatal */ false); |
| 6023 | codegen_->AddSlowPath(slow_path); |
| 6024 | __ jmp(slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6025 | if (zero.IsLinked()) { |
| 6026 | __ jmp(&done); |
| 6027 | } |
| 6028 | break; |
| 6029 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6030 | } |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6031 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6032 | if (zero.IsLinked()) { |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6033 | __ Bind(&zero); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6034 | __ xorl(out, out); |
| 6035 | } |
| 6036 | |
| 6037 | if (done.IsLinked()) { |
| 6038 | __ Bind(&done); |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6039 | } |
| 6040 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6041 | if (slow_path != nullptr) { |
| 6042 | __ Bind(slow_path->GetExitLabel()); |
| 6043 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6044 | } |
| 6045 | |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6046 | static bool IsTypeCheckSlowPathFatal(TypeCheckKind type_check_kind, bool throws_into_catch) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6047 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6048 | case TypeCheckKind::kExactCheck: |
| 6049 | case TypeCheckKind::kAbstractClassCheck: |
| 6050 | case TypeCheckKind::kClassHierarchyCheck: |
| 6051 | case TypeCheckKind::kArrayObjectCheck: |
Andreas Gampe | b5f3d81 | 2016-11-04 19:25:20 -0700 | [diff] [blame] | 6052 | return !throws_into_catch && !kEmitCompilerReadBarrier; |
Nicolas Geoffray | 53b07bd | 2016-11-05 15:09:19 +0000 | [diff] [blame] | 6053 | case TypeCheckKind::kInterfaceCheck: |
| 6054 | return !throws_into_catch && !kEmitCompilerReadBarrier && !kPoisonHeapReferences; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6055 | case TypeCheckKind::kArrayCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6056 | case TypeCheckKind::kUnresolvedCheck: |
Andreas Gampe | b5f3d81 | 2016-11-04 19:25:20 -0700 | [diff] [blame] | 6057 | return false; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6058 | } |
Andreas Gampe | b5f3d81 | 2016-11-04 19:25:20 -0700 | [diff] [blame] | 6059 | LOG(FATAL) << "Unreachable"; |
| 6060 | UNREACHABLE(); |
| 6061 | } |
| 6062 | |
| 6063 | void LocationsBuilderX86_64::VisitCheckCast(HCheckCast* instruction) { |
| 6064 | bool throws_into_catch = instruction->CanThrowIntoCatchBlock(); |
| 6065 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| 6066 | bool is_fatal_slow_path = IsTypeCheckSlowPathFatal(type_check_kind, throws_into_catch); |
| 6067 | LocationSummary::CallKind call_kind = is_fatal_slow_path |
| 6068 | ? LocationSummary::kNoCall |
| 6069 | : LocationSummary::kCallOnSlowPath; |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6070 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
| 6071 | locations->SetInAt(0, Location::RequiresRegister()); |
Mathieu Chartier | cdba73b | 2016-11-03 19:23:06 -0700 | [diff] [blame] | 6072 | if (type_check_kind == TypeCheckKind::kInterfaceCheck) { |
| 6073 | // Require a register for the interface check since there is a loop that compares the class to |
| 6074 | // a memory address. |
| 6075 | locations->SetInAt(1, Location::RequiresRegister()); |
| 6076 | } else { |
| 6077 | locations->SetInAt(1, Location::Any()); |
| 6078 | } |
| 6079 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6080 | // Note that TypeCheckSlowPathX86_64 uses this "temp" register too. |
| 6081 | locations->AddTemp(Location::RequiresRegister()); |
| 6082 | // When read barriers are enabled, we need an additional temporary |
| 6083 | // register for some cases. |
Nicolas Geoffray | 53b07bd | 2016-11-05 15:09:19 +0000 | [diff] [blame] | 6084 | if (CheckCastTypeCheckNeedsATemporary(type_check_kind)) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6085 | locations->AddTemp(Location::RequiresRegister()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6086 | } |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6087 | } |
| 6088 | |
| 6089 | void InstructionCodeGeneratorX86_64::VisitCheckCast(HCheckCast* instruction) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6090 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6091 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6092 | Location obj_loc = locations->InAt(0); |
| 6093 | CpuRegister obj = obj_loc.AsRegister<CpuRegister>(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6094 | Location cls = locations->InAt(1); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6095 | Location temp_loc = locations->GetTemp(0); |
| 6096 | CpuRegister temp = temp_loc.AsRegister<CpuRegister>(); |
Nicolas Geoffray | 53b07bd | 2016-11-05 15:09:19 +0000 | [diff] [blame] | 6097 | Location maybe_temp2_loc = CheckCastTypeCheckNeedsATemporary(type_check_kind) ? |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6098 | locations->GetTemp(1) : |
| 6099 | Location::NoLocation(); |
Mathieu Chartier | cdba73b | 2016-11-03 19:23:06 -0700 | [diff] [blame] | 6100 | const uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 6101 | const uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 6102 | const uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 6103 | const uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
| 6104 | const uint32_t iftable_offset = mirror::Class::IfTableOffset().Uint32Value(); |
| 6105 | const uint32_t array_length_offset = mirror::Array::LengthOffset().Uint32Value(); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6106 | const uint32_t object_array_data_offset = |
| 6107 | mirror::Array::DataOffset(kHeapReferenceSize).Uint32Value(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6108 | |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6109 | // Always false for read barriers since we may need to go to the entrypoint for non-fatal cases |
| 6110 | // from false negatives. The false negatives may come from avoiding read barriers below. Avoiding |
| 6111 | // read barriers is done for performance and code size reasons. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6112 | bool is_type_check_slow_path_fatal = |
Andreas Gampe | b5f3d81 | 2016-11-04 19:25:20 -0700 | [diff] [blame] | 6113 | IsTypeCheckSlowPathFatal(type_check_kind, instruction->CanThrowIntoCatchBlock()); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6114 | SlowPathCode* type_check_slow_path = |
| 6115 | new (GetGraph()->GetArena()) TypeCheckSlowPathX86_64(instruction, |
| 6116 | is_type_check_slow_path_fatal); |
| 6117 | codegen_->AddSlowPath(type_check_slow_path); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6118 | |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6119 | |
| 6120 | NearLabel done; |
| 6121 | // Avoid null check if we know obj is not null. |
| 6122 | if (instruction->MustDoNullCheck()) { |
| 6123 | __ testl(obj, obj); |
| 6124 | __ j(kEqual, &done); |
| 6125 | } |
| 6126 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6127 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6128 | case TypeCheckKind::kExactCheck: |
| 6129 | case TypeCheckKind::kArrayCheck: { |
Roland Levillain | 8650378 | 2016-02-11 19:07:30 +0000 | [diff] [blame] | 6130 | // /* HeapReference<Class> */ temp = obj->klass_ |
Mathieu Chartier | cdba73b | 2016-11-03 19:23:06 -0700 | [diff] [blame] | 6131 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6132 | temp_loc, |
| 6133 | obj_loc, |
| 6134 | class_offset, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6135 | kWithoutReadBarrier); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6136 | if (cls.IsRegister()) { |
| 6137 | __ cmpl(temp, cls.AsRegister<CpuRegister>()); |
| 6138 | } else { |
| 6139 | DCHECK(cls.IsStackSlot()) << cls; |
| 6140 | __ cmpl(temp, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 6141 | } |
| 6142 | // Jump to slow path for throwing the exception or doing a |
| 6143 | // more involved array check. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6144 | __ j(kNotEqual, type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6145 | break; |
| 6146 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6147 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6148 | case TypeCheckKind::kAbstractClassCheck: { |
Roland Levillain | 8650378 | 2016-02-11 19:07:30 +0000 | [diff] [blame] | 6149 | // /* HeapReference<Class> */ temp = obj->klass_ |
Mathieu Chartier | cdba73b | 2016-11-03 19:23:06 -0700 | [diff] [blame] | 6150 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6151 | temp_loc, |
| 6152 | obj_loc, |
| 6153 | class_offset, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6154 | kWithoutReadBarrier); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6155 | // If the class is abstract, we eagerly fetch the super class of the |
| 6156 | // object to avoid doing a comparison we know will fail. |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 6157 | NearLabel loop; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6158 | __ Bind(&loop); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6159 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6160 | GenerateReferenceLoadOneRegister(instruction, |
| 6161 | temp_loc, |
| 6162 | super_offset, |
| 6163 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6164 | kWithoutReadBarrier); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6165 | |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 6166 | // If the class reference currently in `temp` is null, jump to the slow path to throw the |
| 6167 | // exception. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6168 | __ testl(temp, temp); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 6169 | // Otherwise, compare the classes. |
| 6170 | __ j(kZero, type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6171 | if (cls.IsRegister()) { |
| 6172 | __ cmpl(temp, cls.AsRegister<CpuRegister>()); |
| 6173 | } else { |
| 6174 | DCHECK(cls.IsStackSlot()) << cls; |
| 6175 | __ cmpl(temp, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 6176 | } |
| 6177 | __ j(kNotEqual, &loop); |
| 6178 | break; |
| 6179 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6180 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6181 | case TypeCheckKind::kClassHierarchyCheck: { |
Roland Levillain | 8650378 | 2016-02-11 19:07:30 +0000 | [diff] [blame] | 6182 | // /* HeapReference<Class> */ temp = obj->klass_ |
Mathieu Chartier | cdba73b | 2016-11-03 19:23:06 -0700 | [diff] [blame] | 6183 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6184 | temp_loc, |
| 6185 | obj_loc, |
| 6186 | class_offset, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6187 | kWithoutReadBarrier); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6188 | // Walk over the class hierarchy to find a match. |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6189 | NearLabel loop; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6190 | __ Bind(&loop); |
| 6191 | if (cls.IsRegister()) { |
| 6192 | __ cmpl(temp, cls.AsRegister<CpuRegister>()); |
| 6193 | } else { |
| 6194 | DCHECK(cls.IsStackSlot()) << cls; |
| 6195 | __ cmpl(temp, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 6196 | } |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6197 | __ j(kEqual, &done); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6198 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6199 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6200 | GenerateReferenceLoadOneRegister(instruction, |
| 6201 | temp_loc, |
| 6202 | super_offset, |
| 6203 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6204 | kWithoutReadBarrier); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6205 | |
| 6206 | // If the class reference currently in `temp` is not null, jump |
| 6207 | // back at the beginning of the loop. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6208 | __ testl(temp, temp); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 6209 | __ j(kNotZero, &loop); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6210 | // Otherwise, jump to the slow path to throw the exception. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6211 | __ jmp(type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6212 | break; |
| 6213 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6214 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6215 | case TypeCheckKind::kArrayObjectCheck: { |
Roland Levillain | 8650378 | 2016-02-11 19:07:30 +0000 | [diff] [blame] | 6216 | // /* HeapReference<Class> */ temp = obj->klass_ |
Mathieu Chartier | cdba73b | 2016-11-03 19:23:06 -0700 | [diff] [blame] | 6217 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6218 | temp_loc, |
| 6219 | obj_loc, |
| 6220 | class_offset, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6221 | kWithoutReadBarrier); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6222 | // Do an exact check. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6223 | NearLabel check_non_primitive_component_type; |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6224 | if (cls.IsRegister()) { |
| 6225 | __ cmpl(temp, cls.AsRegister<CpuRegister>()); |
| 6226 | } else { |
| 6227 | DCHECK(cls.IsStackSlot()) << cls; |
| 6228 | __ cmpl(temp, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 6229 | } |
| 6230 | __ j(kEqual, &done); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6231 | |
| 6232 | // 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] | 6233 | // /* HeapReference<Class> */ temp = temp->component_type_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6234 | GenerateReferenceLoadOneRegister(instruction, |
| 6235 | temp_loc, |
| 6236 | component_offset, |
| 6237 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6238 | kWithoutReadBarrier); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6239 | |
| 6240 | // If the component type is not null (i.e. the object is indeed |
| 6241 | // an array), jump to label `check_non_primitive_component_type` |
| 6242 | // to further check that this component type is not a primitive |
| 6243 | // type. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6244 | __ testl(temp, temp); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6245 | // Otherwise, jump to the slow path to throw the exception. |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 6246 | __ j(kZero, type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6247 | __ cmpw(Address(temp, primitive_offset), Immediate(Primitive::kPrimNot)); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 6248 | __ j(kNotEqual, type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6249 | break; |
| 6250 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6251 | |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6252 | case TypeCheckKind::kUnresolvedCheck: { |
Mathieu Chartier | cdba73b | 2016-11-03 19:23:06 -0700 | [diff] [blame] | 6253 | // 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] | 6254 | // |
| 6255 | // We cannot directly call the CheckCast runtime entry point |
| 6256 | // without resorting to a type checking slow path here (i.e. by |
| 6257 | // calling InvokeRuntime directly), as it would require to |
| 6258 | // assign fixed registers for the inputs of this HInstanceOf |
| 6259 | // instruction (following the runtime calling convention), which |
| 6260 | // might be cluttered by the potential first read barrier |
| 6261 | // emission at the beginning of this method. |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6262 | __ jmp(type_check_slow_path->GetEntryLabel()); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6263 | break; |
| 6264 | } |
| 6265 | |
| 6266 | case TypeCheckKind::kInterfaceCheck: |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6267 | // Fast path for the interface check. We always go slow path for heap poisoning since |
| 6268 | // unpoisoning cls would require an extra temp. |
| 6269 | if (!kPoisonHeapReferences) { |
Mathieu Chartier | cdba73b | 2016-11-03 19:23:06 -0700 | [diff] [blame] | 6270 | // Try to avoid read barriers to improve the fast path. We can not get false positives by |
| 6271 | // doing this. |
| 6272 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 6273 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6274 | temp_loc, |
| 6275 | obj_loc, |
| 6276 | class_offset, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6277 | kWithoutReadBarrier); |
Mathieu Chartier | cdba73b | 2016-11-03 19:23:06 -0700 | [diff] [blame] | 6278 | |
| 6279 | // /* HeapReference<Class> */ temp = temp->iftable_ |
| 6280 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6281 | temp_loc, |
| 6282 | temp_loc, |
| 6283 | iftable_offset, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6284 | kWithoutReadBarrier); |
Mathieu Chartier | 6beced4 | 2016-11-15 15:51:31 -0800 | [diff] [blame] | 6285 | // Iftable is never null. |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6286 | __ movl(maybe_temp2_loc.AsRegister<CpuRegister>(), Address(temp, array_length_offset)); |
Mathieu Chartier | 6beced4 | 2016-11-15 15:51:31 -0800 | [diff] [blame] | 6287 | // Loop through the iftable and check if any class matches. |
Mathieu Chartier | cdba73b | 2016-11-03 19:23:06 -0700 | [diff] [blame] | 6288 | NearLabel start_loop; |
| 6289 | __ Bind(&start_loop); |
Mathieu Chartier | 6beced4 | 2016-11-15 15:51:31 -0800 | [diff] [blame] | 6290 | // Need to subtract first to handle the empty array case. |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6291 | __ subl(maybe_temp2_loc.AsRegister<CpuRegister>(), Immediate(2)); |
Mathieu Chartier | 6beced4 | 2016-11-15 15:51:31 -0800 | [diff] [blame] | 6292 | __ j(kNegative, type_check_slow_path->GetEntryLabel()); |
| 6293 | // Go to next interface if the classes do not match. |
| 6294 | __ cmpl(cls.AsRegister<CpuRegister>(), |
| 6295 | CodeGeneratorX86_64::ArrayAddress(temp, |
| 6296 | maybe_temp2_loc, |
| 6297 | TIMES_4, |
| 6298 | object_array_data_offset)); |
| 6299 | __ j(kNotEqual, &start_loop); // Return if same class. |
| 6300 | } else { |
| 6301 | __ jmp(type_check_slow_path->GetEntryLabel()); |
Mathieu Chartier | cdba73b | 2016-11-03 19:23:06 -0700 | [diff] [blame] | 6302 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6303 | break; |
| 6304 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6305 | |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6306 | if (done.IsLinked()) { |
| 6307 | __ Bind(&done); |
| 6308 | } |
| 6309 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6310 | __ Bind(type_check_slow_path->GetExitLabel()); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6311 | } |
| 6312 | |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6313 | void LocationsBuilderX86_64::VisitMonitorOperation(HMonitorOperation* instruction) { |
| 6314 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 6315 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6316 | InvokeRuntimeCallingConvention calling_convention; |
| 6317 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 6318 | } |
| 6319 | |
| 6320 | void InstructionCodeGeneratorX86_64::VisitMonitorOperation(HMonitorOperation* instruction) { |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 6321 | codegen_->InvokeRuntime(instruction->IsEnter() ? kQuickLockObject : kQuickUnlockObject, |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 6322 | instruction, |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 6323 | instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 6324 | if (instruction->IsEnter()) { |
| 6325 | CheckEntrypointTypes<kQuickLockObject, void, mirror::Object*>(); |
| 6326 | } else { |
| 6327 | CheckEntrypointTypes<kQuickUnlockObject, void, mirror::Object*>(); |
| 6328 | } |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6329 | } |
| 6330 | |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6331 | void LocationsBuilderX86_64::VisitAnd(HAnd* instruction) { HandleBitwiseOperation(instruction); } |
| 6332 | void LocationsBuilderX86_64::VisitOr(HOr* instruction) { HandleBitwiseOperation(instruction); } |
| 6333 | void LocationsBuilderX86_64::VisitXor(HXor* instruction) { HandleBitwiseOperation(instruction); } |
| 6334 | |
| 6335 | void LocationsBuilderX86_64::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 6336 | LocationSummary* locations = |
| 6337 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 6338 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt |
| 6339 | || instruction->GetResultType() == Primitive::kPrimLong); |
| 6340 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 6341 | locations->SetInAt(1, Location::Any()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6342 | locations->SetOut(Location::SameAsFirstInput()); |
| 6343 | } |
| 6344 | |
| 6345 | void InstructionCodeGeneratorX86_64::VisitAnd(HAnd* instruction) { |
| 6346 | HandleBitwiseOperation(instruction); |
| 6347 | } |
| 6348 | |
| 6349 | void InstructionCodeGeneratorX86_64::VisitOr(HOr* instruction) { |
| 6350 | HandleBitwiseOperation(instruction); |
| 6351 | } |
| 6352 | |
| 6353 | void InstructionCodeGeneratorX86_64::VisitXor(HXor* instruction) { |
| 6354 | HandleBitwiseOperation(instruction); |
| 6355 | } |
| 6356 | |
| 6357 | void InstructionCodeGeneratorX86_64::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 6358 | LocationSummary* locations = instruction->GetLocations(); |
| 6359 | Location first = locations->InAt(0); |
| 6360 | Location second = locations->InAt(1); |
| 6361 | DCHECK(first.Equals(locations->Out())); |
| 6362 | |
| 6363 | if (instruction->GetResultType() == Primitive::kPrimInt) { |
| 6364 | if (second.IsRegister()) { |
| 6365 | if (instruction->IsAnd()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6366 | __ andl(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6367 | } else if (instruction->IsOr()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6368 | __ orl(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6369 | } else { |
| 6370 | DCHECK(instruction->IsXor()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6371 | __ xorl(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6372 | } |
| 6373 | } else if (second.IsConstant()) { |
| 6374 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue()); |
| 6375 | if (instruction->IsAnd()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6376 | __ andl(first.AsRegister<CpuRegister>(), imm); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6377 | } else if (instruction->IsOr()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6378 | __ orl(first.AsRegister<CpuRegister>(), imm); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6379 | } else { |
| 6380 | DCHECK(instruction->IsXor()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6381 | __ xorl(first.AsRegister<CpuRegister>(), imm); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6382 | } |
| 6383 | } else { |
| 6384 | Address address(CpuRegister(RSP), second.GetStackIndex()); |
| 6385 | if (instruction->IsAnd()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6386 | __ andl(first.AsRegister<CpuRegister>(), address); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6387 | } else if (instruction->IsOr()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6388 | __ orl(first.AsRegister<CpuRegister>(), address); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6389 | } else { |
| 6390 | DCHECK(instruction->IsXor()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6391 | __ xorl(first.AsRegister<CpuRegister>(), address); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6392 | } |
| 6393 | } |
| 6394 | } else { |
| 6395 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6396 | CpuRegister first_reg = first.AsRegister<CpuRegister>(); |
| 6397 | bool second_is_constant = false; |
| 6398 | int64_t value = 0; |
| 6399 | if (second.IsConstant()) { |
| 6400 | second_is_constant = true; |
| 6401 | value = second.GetConstant()->AsLongConstant()->GetValue(); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6402 | } |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 6403 | bool is_int32_value = IsInt<32>(value); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6404 | |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6405 | if (instruction->IsAnd()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6406 | if (second_is_constant) { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 6407 | if (is_int32_value) { |
| 6408 | __ andq(first_reg, Immediate(static_cast<int32_t>(value))); |
| 6409 | } else { |
| 6410 | __ andq(first_reg, codegen_->LiteralInt64Address(value)); |
| 6411 | } |
| 6412 | } else if (second.IsDoubleStackSlot()) { |
| 6413 | __ andq(first_reg, Address(CpuRegister(RSP), second.GetStackIndex())); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6414 | } else { |
| 6415 | __ andq(first_reg, second.AsRegister<CpuRegister>()); |
| 6416 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6417 | } else if (instruction->IsOr()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6418 | if (second_is_constant) { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 6419 | if (is_int32_value) { |
| 6420 | __ orq(first_reg, Immediate(static_cast<int32_t>(value))); |
| 6421 | } else { |
| 6422 | __ orq(first_reg, codegen_->LiteralInt64Address(value)); |
| 6423 | } |
| 6424 | } else if (second.IsDoubleStackSlot()) { |
| 6425 | __ orq(first_reg, Address(CpuRegister(RSP), second.GetStackIndex())); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6426 | } else { |
| 6427 | __ orq(first_reg, second.AsRegister<CpuRegister>()); |
| 6428 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6429 | } else { |
| 6430 | DCHECK(instruction->IsXor()); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6431 | if (second_is_constant) { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 6432 | if (is_int32_value) { |
| 6433 | __ xorq(first_reg, Immediate(static_cast<int32_t>(value))); |
| 6434 | } else { |
| 6435 | __ xorq(first_reg, codegen_->LiteralInt64Address(value)); |
| 6436 | } |
| 6437 | } else if (second.IsDoubleStackSlot()) { |
| 6438 | __ xorq(first_reg, Address(CpuRegister(RSP), second.GetStackIndex())); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6439 | } else { |
| 6440 | __ xorq(first_reg, second.AsRegister<CpuRegister>()); |
| 6441 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6442 | } |
| 6443 | } |
| 6444 | } |
| 6445 | |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6446 | void InstructionCodeGeneratorX86_64::GenerateReferenceLoadOneRegister( |
| 6447 | HInstruction* instruction, |
| 6448 | Location out, |
| 6449 | uint32_t offset, |
| 6450 | Location maybe_temp, |
| 6451 | ReadBarrierOption read_barrier_option) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6452 | CpuRegister out_reg = out.AsRegister<CpuRegister>(); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6453 | if (read_barrier_option == kWithReadBarrier) { |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6454 | CHECK(kEmitCompilerReadBarrier); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6455 | if (kUseBakerReadBarrier) { |
| 6456 | // Load with fast path based Baker's read barrier. |
| 6457 | // /* HeapReference<Object> */ out = *(out + offset) |
| 6458 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 6459 | instruction, out, out_reg, offset, /* needs_null_check */ false); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6460 | } else { |
| 6461 | // Load with slow path based read barrier. |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6462 | // Save the value of `out` into `maybe_temp` before overwriting it |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6463 | // in the following move operation, as we will need it for the |
| 6464 | // read barrier below. |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 6465 | DCHECK(maybe_temp.IsRegister()) << maybe_temp; |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6466 | __ movl(maybe_temp.AsRegister<CpuRegister>(), out_reg); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6467 | // /* HeapReference<Object> */ out = *(out + offset) |
| 6468 | __ movl(out_reg, Address(out_reg, offset)); |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6469 | codegen_->GenerateReadBarrierSlow(instruction, out, out, maybe_temp, offset); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6470 | } |
| 6471 | } else { |
| 6472 | // Plain load with no read barrier. |
| 6473 | // /* HeapReference<Object> */ out = *(out + offset) |
| 6474 | __ movl(out_reg, Address(out_reg, offset)); |
| 6475 | __ MaybeUnpoisonHeapReference(out_reg); |
| 6476 | } |
| 6477 | } |
| 6478 | |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6479 | void InstructionCodeGeneratorX86_64::GenerateReferenceLoadTwoRegisters( |
| 6480 | HInstruction* instruction, |
| 6481 | Location out, |
| 6482 | Location obj, |
| 6483 | uint32_t offset, |
| 6484 | ReadBarrierOption read_barrier_option) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6485 | CpuRegister out_reg = out.AsRegister<CpuRegister>(); |
| 6486 | CpuRegister obj_reg = obj.AsRegister<CpuRegister>(); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6487 | if (read_barrier_option == kWithReadBarrier) { |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6488 | CHECK(kEmitCompilerReadBarrier); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6489 | if (kUseBakerReadBarrier) { |
| 6490 | // Load with fast path based Baker's read barrier. |
| 6491 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 6492 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 6493 | instruction, out, obj_reg, offset, /* needs_null_check */ false); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6494 | } else { |
| 6495 | // Load with slow path based read barrier. |
| 6496 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 6497 | __ movl(out_reg, Address(obj_reg, offset)); |
| 6498 | codegen_->GenerateReadBarrierSlow(instruction, out, out, obj, offset); |
| 6499 | } |
| 6500 | } else { |
| 6501 | // Plain load with no read barrier. |
| 6502 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 6503 | __ movl(out_reg, Address(obj_reg, offset)); |
| 6504 | __ MaybeUnpoisonHeapReference(out_reg); |
| 6505 | } |
| 6506 | } |
| 6507 | |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6508 | void InstructionCodeGeneratorX86_64::GenerateGcRootFieldLoad( |
| 6509 | HInstruction* instruction, |
| 6510 | Location root, |
| 6511 | const Address& address, |
| 6512 | Label* fixup_label, |
| 6513 | ReadBarrierOption read_barrier_option) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6514 | CpuRegister root_reg = root.AsRegister<CpuRegister>(); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6515 | if (read_barrier_option == kWithReadBarrier) { |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 6516 | DCHECK(kEmitCompilerReadBarrier); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6517 | if (kUseBakerReadBarrier) { |
| 6518 | // Fast path implementation of art::ReadBarrier::BarrierForRoot when |
| 6519 | // Baker's read barrier are used: |
| 6520 | // |
Roland Levillain | d966ce7 | 2017-02-09 16:20:14 +0000 | [diff] [blame] | 6521 | // root = obj.field; |
| 6522 | // temp = Thread::Current()->pReadBarrierMarkReg ## root.reg() |
| 6523 | // if (temp != null) { |
| 6524 | // root = temp(root) |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6525 | // } |
| 6526 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6527 | // /* GcRoot<mirror::Object> */ root = *address |
| 6528 | __ movl(root_reg, address); |
| 6529 | if (fixup_label != nullptr) { |
| 6530 | __ Bind(fixup_label); |
| 6531 | } |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6532 | static_assert( |
| 6533 | sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(GcRoot<mirror::Object>), |
| 6534 | "art::mirror::CompressedReference<mirror::Object> and art::GcRoot<mirror::Object> " |
| 6535 | "have different sizes."); |
| 6536 | static_assert(sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(int32_t), |
| 6537 | "art::mirror::CompressedReference<mirror::Object> and int32_t " |
| 6538 | "have different sizes."); |
| 6539 | |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 6540 | // Slow path marking the GC root `root`. |
| 6541 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) ReadBarrierMarkSlowPathX86_64( |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 6542 | instruction, root, /* unpoison_ref_before_marking */ false); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6543 | codegen_->AddSlowPath(slow_path); |
| 6544 | |
Roland Levillain | d966ce7 | 2017-02-09 16:20:14 +0000 | [diff] [blame] | 6545 | // Test the `Thread::Current()->pReadBarrierMarkReg ## root.reg()` entrypoint. |
| 6546 | const int32_t entry_point_offset = |
| 6547 | CodeGenerator::GetReadBarrierMarkEntryPointsOffset<kX86_64PointerSize>(root.reg()); |
| 6548 | __ gs()->cmpl(Address::Absolute(entry_point_offset, /* no_rip */ true), Immediate(0)); |
| 6549 | // The entrypoint is null when the GC is not marking. |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6550 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 6551 | __ Bind(slow_path->GetExitLabel()); |
| 6552 | } else { |
| 6553 | // GC root loaded through a slow path for read barriers other |
| 6554 | // than Baker's. |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6555 | // /* GcRoot<mirror::Object>* */ root = address |
| 6556 | __ leaq(root_reg, address); |
| 6557 | if (fixup_label != nullptr) { |
| 6558 | __ Bind(fixup_label); |
| 6559 | } |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6560 | // /* mirror::Object* */ root = root->Read() |
| 6561 | codegen_->GenerateReadBarrierForRootSlow(instruction, root, root); |
| 6562 | } |
| 6563 | } else { |
| 6564 | // Plain GC root load with no read barrier. |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6565 | // /* GcRoot<mirror::Object> */ root = *address |
| 6566 | __ movl(root_reg, address); |
| 6567 | if (fixup_label != nullptr) { |
| 6568 | __ Bind(fixup_label); |
| 6569 | } |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 6570 | // Note that GC roots are not affected by heap poisoning, thus we |
| 6571 | // do not have to unpoison `root_reg` here. |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6572 | } |
| 6573 | } |
| 6574 | |
| 6575 | void CodeGeneratorX86_64::GenerateFieldLoadWithBakerReadBarrier(HInstruction* instruction, |
| 6576 | Location ref, |
| 6577 | CpuRegister obj, |
| 6578 | uint32_t offset, |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6579 | bool needs_null_check) { |
| 6580 | DCHECK(kEmitCompilerReadBarrier); |
| 6581 | DCHECK(kUseBakerReadBarrier); |
| 6582 | |
| 6583 | // /* HeapReference<Object> */ ref = *(obj + offset) |
| 6584 | Address src(obj, offset); |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 6585 | GenerateReferenceLoadWithBakerReadBarrier(instruction, ref, obj, src, needs_null_check); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6586 | } |
| 6587 | |
| 6588 | void CodeGeneratorX86_64::GenerateArrayLoadWithBakerReadBarrier(HInstruction* instruction, |
| 6589 | Location ref, |
| 6590 | CpuRegister obj, |
| 6591 | uint32_t data_offset, |
| 6592 | Location index, |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6593 | bool needs_null_check) { |
| 6594 | DCHECK(kEmitCompilerReadBarrier); |
| 6595 | DCHECK(kUseBakerReadBarrier); |
| 6596 | |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 6597 | static_assert( |
| 6598 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 6599 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6600 | // /* HeapReference<Object> */ ref = |
| 6601 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 6602 | Address src = CodeGeneratorX86_64::ArrayAddress(obj, index, TIMES_4, data_offset); |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 6603 | GenerateReferenceLoadWithBakerReadBarrier(instruction, ref, obj, src, needs_null_check); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6604 | } |
| 6605 | |
| 6606 | void CodeGeneratorX86_64::GenerateReferenceLoadWithBakerReadBarrier(HInstruction* instruction, |
| 6607 | Location ref, |
| 6608 | CpuRegister obj, |
| 6609 | const Address& src, |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 6610 | bool needs_null_check, |
| 6611 | bool always_update_field, |
| 6612 | CpuRegister* temp1, |
| 6613 | CpuRegister* temp2) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6614 | DCHECK(kEmitCompilerReadBarrier); |
| 6615 | DCHECK(kUseBakerReadBarrier); |
| 6616 | |
| 6617 | // In slow path based read barriers, the read barrier call is |
| 6618 | // inserted after the original load. However, in fast path based |
| 6619 | // Baker's read barriers, we need to perform the load of |
| 6620 | // mirror::Object::monitor_ *before* the original reference load. |
| 6621 | // This load-load ordering is required by the read barrier. |
| 6622 | // The fast path/slow path (for Baker's algorithm) should look like: |
| 6623 | // |
| 6624 | // uint32_t rb_state = Lockword(obj->monitor_).ReadBarrierState(); |
| 6625 | // lfence; // Load fence or artificial data dependency to prevent load-load reordering |
| 6626 | // HeapReference<Object> ref = *src; // Original reference load. |
Hiroshi Yamauchi | 12b58b2 | 2016-11-01 11:55:29 -0700 | [diff] [blame] | 6627 | // bool is_gray = (rb_state == ReadBarrier::GrayState()); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6628 | // if (is_gray) { |
| 6629 | // ref = ReadBarrier::Mark(ref); // Performed by runtime entrypoint slow path. |
| 6630 | // } |
| 6631 | // |
| 6632 | // Note: the original implementation in ReadBarrier::Barrier is |
| 6633 | // slightly more complex as: |
| 6634 | // - it implements the load-load fence using a data dependency on |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 6635 | // the high-bits of rb_state, which are expected to be all zeroes |
| 6636 | // (we use CodeGeneratorX86_64::GenerateMemoryBarrier instead |
| 6637 | // 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] | 6638 | // - it performs additional checks that we do not do here for |
| 6639 | // performance reasons. |
| 6640 | |
| 6641 | CpuRegister ref_reg = ref.AsRegister<CpuRegister>(); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6642 | uint32_t monitor_offset = mirror::Object::MonitorOffset().Int32Value(); |
| 6643 | |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 6644 | // 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] | 6645 | static_assert(ReadBarrier::WhiteState() == 0, "Expecting white to have value 0"); |
| 6646 | static_assert(ReadBarrier::GrayState() == 1, "Expecting gray to have value 1"); |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 6647 | constexpr uint32_t gray_byte_position = LockWord::kReadBarrierStateShift / kBitsPerByte; |
| 6648 | constexpr uint32_t gray_bit_position = LockWord::kReadBarrierStateShift % kBitsPerByte; |
| 6649 | constexpr int32_t test_value = static_cast<int8_t>(1 << gray_bit_position); |
| 6650 | |
Hiroshi Yamauchi | 12b58b2 | 2016-11-01 11:55:29 -0700 | [diff] [blame] | 6651 | // if (rb_state == ReadBarrier::GrayState()) |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 6652 | // ref = ReadBarrier::Mark(ref); |
| 6653 | // At this point, just do the "if" and make sure that flags are preserved until the branch. |
| 6654 | __ testb(Address(obj, monitor_offset + gray_byte_position), Immediate(test_value)); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6655 | if (needs_null_check) { |
| 6656 | MaybeRecordImplicitNullCheck(instruction); |
| 6657 | } |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6658 | |
| 6659 | // Load fence to prevent load-load reordering. |
| 6660 | // Note that this is a no-op, thanks to the x86-64 memory model. |
| 6661 | GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 6662 | |
| 6663 | // The actual reference load. |
| 6664 | // /* HeapReference<Object> */ ref = *src |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 6665 | __ movl(ref_reg, src); // Flags are unaffected. |
| 6666 | |
| 6667 | // Note: Reference unpoisoning modifies the flags, so we need to delay it after the branch. |
| 6668 | // Slow path marking the object `ref` when it is gray. |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 6669 | SlowPathCode* slow_path; |
| 6670 | if (always_update_field) { |
| 6671 | DCHECK(temp1 != nullptr); |
| 6672 | DCHECK(temp2 != nullptr); |
| 6673 | slow_path = new (GetGraph()->GetArena()) ReadBarrierMarkAndUpdateFieldSlowPathX86_64( |
| 6674 | instruction, ref, obj, src, /* unpoison_ref_before_marking */ true, *temp1, *temp2); |
| 6675 | } else { |
| 6676 | slow_path = new (GetGraph()->GetArena()) ReadBarrierMarkSlowPathX86_64( |
| 6677 | instruction, ref, /* unpoison_ref_before_marking */ true); |
| 6678 | } |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 6679 | AddSlowPath(slow_path); |
| 6680 | |
| 6681 | // We have done the "if" of the gray bit check above, now branch based on the flags. |
| 6682 | __ j(kNotZero, slow_path->GetEntryLabel()); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6683 | |
| 6684 | // Object* ref = ref_addr->AsMirrorPtr() |
| 6685 | __ MaybeUnpoisonHeapReference(ref_reg); |
| 6686 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6687 | __ Bind(slow_path->GetExitLabel()); |
| 6688 | } |
| 6689 | |
| 6690 | void CodeGeneratorX86_64::GenerateReadBarrierSlow(HInstruction* instruction, |
| 6691 | Location out, |
| 6692 | Location ref, |
| 6693 | Location obj, |
| 6694 | uint32_t offset, |
| 6695 | Location index) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6696 | DCHECK(kEmitCompilerReadBarrier); |
| 6697 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6698 | // Insert a slow path based read barrier *after* the reference load. |
| 6699 | // |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6700 | // If heap poisoning is enabled, the unpoisoning of the loaded |
| 6701 | // reference will be carried out by the runtime within the slow |
| 6702 | // path. |
| 6703 | // |
| 6704 | // Note that `ref` currently does not get unpoisoned (when heap |
| 6705 | // poisoning is enabled), which is alright as the `ref` argument is |
| 6706 | // not used by the artReadBarrierSlow entry point. |
| 6707 | // |
| 6708 | // TODO: Unpoison `ref` when it is used by artReadBarrierSlow. |
| 6709 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) |
| 6710 | ReadBarrierForHeapReferenceSlowPathX86_64(instruction, out, ref, obj, offset, index); |
| 6711 | AddSlowPath(slow_path); |
| 6712 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6713 | __ jmp(slow_path->GetEntryLabel()); |
| 6714 | __ Bind(slow_path->GetExitLabel()); |
| 6715 | } |
| 6716 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6717 | void CodeGeneratorX86_64::MaybeGenerateReadBarrierSlow(HInstruction* instruction, |
| 6718 | Location out, |
| 6719 | Location ref, |
| 6720 | Location obj, |
| 6721 | uint32_t offset, |
| 6722 | Location index) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6723 | if (kEmitCompilerReadBarrier) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6724 | // Baker's read barriers shall be handled by the fast path |
| 6725 | // (CodeGeneratorX86_64::GenerateReferenceLoadWithBakerReadBarrier). |
| 6726 | DCHECK(!kUseBakerReadBarrier); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6727 | // If heap poisoning is enabled, unpoisoning will be taken care of |
| 6728 | // by the runtime within the slow path. |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6729 | GenerateReadBarrierSlow(instruction, out, ref, obj, offset, index); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6730 | } else if (kPoisonHeapReferences) { |
| 6731 | __ UnpoisonHeapReference(out.AsRegister<CpuRegister>()); |
| 6732 | } |
| 6733 | } |
| 6734 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6735 | void CodeGeneratorX86_64::GenerateReadBarrierForRootSlow(HInstruction* instruction, |
| 6736 | Location out, |
| 6737 | Location root) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6738 | DCHECK(kEmitCompilerReadBarrier); |
| 6739 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6740 | // Insert a slow path based read barrier *after* the GC root load. |
| 6741 | // |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6742 | // Note that GC roots are not affected by heap poisoning, so we do |
| 6743 | // not need to do anything special for this here. |
| 6744 | SlowPathCode* slow_path = |
| 6745 | new (GetGraph()->GetArena()) ReadBarrierForRootSlowPathX86_64(instruction, out, root); |
| 6746 | AddSlowPath(slow_path); |
| 6747 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6748 | __ jmp(slow_path->GetEntryLabel()); |
| 6749 | __ Bind(slow_path->GetExitLabel()); |
| 6750 | } |
| 6751 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 6752 | void LocationsBuilderX86_64::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6753 | // Nothing to do, this should be removed during prepare for register allocator. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6754 | LOG(FATAL) << "Unreachable"; |
| 6755 | } |
| 6756 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 6757 | void InstructionCodeGeneratorX86_64::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6758 | // Nothing to do, this should be removed during prepare for register allocator. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6759 | LOG(FATAL) << "Unreachable"; |
| 6760 | } |
| 6761 | |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6762 | // Simple implementation of packed switch - generate cascaded compare/jumps. |
| 6763 | void LocationsBuilderX86_64::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 6764 | LocationSummary* locations = |
| 6765 | new (GetGraph()->GetArena()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
| 6766 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 6767 | locations->AddTemp(Location::RequiresRegister()); |
| 6768 | locations->AddTemp(Location::RequiresRegister()); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6769 | } |
| 6770 | |
| 6771 | void InstructionCodeGeneratorX86_64::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 6772 | int32_t lower_bound = switch_instr->GetStartValue(); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 6773 | uint32_t num_entries = switch_instr->GetNumEntries(); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6774 | LocationSummary* locations = switch_instr->GetLocations(); |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 6775 | CpuRegister value_reg_in = locations->InAt(0).AsRegister<CpuRegister>(); |
| 6776 | CpuRegister temp_reg = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 6777 | CpuRegister base_reg = locations->GetTemp(1).AsRegister<CpuRegister>(); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 6778 | HBasicBlock* default_block = switch_instr->GetDefaultBlock(); |
| 6779 | |
| 6780 | // Should we generate smaller inline compare/jumps? |
| 6781 | if (num_entries <= kPackedSwitchJumpTableThreshold) { |
| 6782 | // Figure out the correct compare values and jump conditions. |
| 6783 | // Handle the first compare/branch as a special case because it might |
| 6784 | // jump to the default case. |
| 6785 | DCHECK_GT(num_entries, 2u); |
| 6786 | Condition first_condition; |
| 6787 | uint32_t index; |
| 6788 | const ArenaVector<HBasicBlock*>& successors = switch_instr->GetBlock()->GetSuccessors(); |
| 6789 | if (lower_bound != 0) { |
| 6790 | first_condition = kLess; |
| 6791 | __ cmpl(value_reg_in, Immediate(lower_bound)); |
| 6792 | __ j(first_condition, codegen_->GetLabelOf(default_block)); |
| 6793 | __ j(kEqual, codegen_->GetLabelOf(successors[0])); |
| 6794 | |
| 6795 | index = 1; |
| 6796 | } else { |
| 6797 | // Handle all the compare/jumps below. |
| 6798 | first_condition = kBelow; |
| 6799 | index = 0; |
| 6800 | } |
| 6801 | |
| 6802 | // Handle the rest of the compare/jumps. |
| 6803 | for (; index + 1 < num_entries; index += 2) { |
| 6804 | int32_t compare_to_value = lower_bound + index + 1; |
| 6805 | __ cmpl(value_reg_in, Immediate(compare_to_value)); |
| 6806 | // Jump to successors[index] if value < case_value[index]. |
| 6807 | __ j(first_condition, codegen_->GetLabelOf(successors[index])); |
| 6808 | // Jump to successors[index + 1] if value == case_value[index + 1]. |
| 6809 | __ j(kEqual, codegen_->GetLabelOf(successors[index + 1])); |
| 6810 | } |
| 6811 | |
| 6812 | if (index != num_entries) { |
| 6813 | // There are an odd number of entries. Handle the last one. |
| 6814 | DCHECK_EQ(index + 1, num_entries); |
Nicolas Geoffray | 6ce0173 | 2015-12-30 14:10:13 +0000 | [diff] [blame] | 6815 | __ cmpl(value_reg_in, Immediate(static_cast<int32_t>(lower_bound + index))); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 6816 | __ j(kEqual, codegen_->GetLabelOf(successors[index])); |
| 6817 | } |
| 6818 | |
| 6819 | // And the default for any other value. |
| 6820 | if (!codegen_->GoesToNextBlock(switch_instr->GetBlock(), default_block)) { |
| 6821 | __ jmp(codegen_->GetLabelOf(default_block)); |
| 6822 | } |
| 6823 | return; |
| 6824 | } |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 6825 | |
| 6826 | // Remove the bias, if needed. |
| 6827 | Register value_reg_out = value_reg_in.AsRegister(); |
| 6828 | if (lower_bound != 0) { |
| 6829 | __ leal(temp_reg, Address(value_reg_in, -lower_bound)); |
| 6830 | value_reg_out = temp_reg.AsRegister(); |
| 6831 | } |
| 6832 | CpuRegister value_reg(value_reg_out); |
| 6833 | |
| 6834 | // Is the value in range? |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 6835 | __ cmpl(value_reg, Immediate(num_entries - 1)); |
| 6836 | __ j(kAbove, codegen_->GetLabelOf(default_block)); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6837 | |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 6838 | // We are in the range of the table. |
| 6839 | // Load the address of the jump table in the constant area. |
| 6840 | __ leaq(base_reg, codegen_->LiteralCaseTable(switch_instr)); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6841 | |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 6842 | // Load the (signed) offset from the jump table. |
| 6843 | __ movsxd(temp_reg, Address(base_reg, value_reg, TIMES_4, 0)); |
| 6844 | |
| 6845 | // Add the offset to the address of the table base. |
| 6846 | __ addq(temp_reg, base_reg); |
| 6847 | |
| 6848 | // And jump. |
| 6849 | __ jmp(temp_reg); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6850 | } |
| 6851 | |
Aart Bik | c5d4754 | 2016-01-27 17:00:35 -0800 | [diff] [blame] | 6852 | void CodeGeneratorX86_64::Load32BitValue(CpuRegister dest, int32_t value) { |
| 6853 | if (value == 0) { |
| 6854 | __ xorl(dest, dest); |
| 6855 | } else { |
| 6856 | __ movl(dest, Immediate(value)); |
| 6857 | } |
| 6858 | } |
| 6859 | |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 6860 | void CodeGeneratorX86_64::Load64BitValue(CpuRegister dest, int64_t value) { |
| 6861 | if (value == 0) { |
Aart Bik | c5d4754 | 2016-01-27 17:00:35 -0800 | [diff] [blame] | 6862 | // Clears upper bits too. |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 6863 | __ xorl(dest, dest); |
Vladimir Marko | ed00978 | 2016-02-22 16:54:39 +0000 | [diff] [blame] | 6864 | } else if (IsUint<32>(value)) { |
| 6865 | // 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] | 6866 | __ movl(dest, Immediate(static_cast<int32_t>(value))); |
| 6867 | } else { |
| 6868 | __ movq(dest, Immediate(value)); |
| 6869 | } |
| 6870 | } |
| 6871 | |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 6872 | void CodeGeneratorX86_64::Load32BitValue(XmmRegister dest, int32_t value) { |
| 6873 | if (value == 0) { |
| 6874 | __ xorps(dest, dest); |
| 6875 | } else { |
| 6876 | __ movss(dest, LiteralInt32Address(value)); |
| 6877 | } |
| 6878 | } |
| 6879 | |
| 6880 | void CodeGeneratorX86_64::Load64BitValue(XmmRegister dest, int64_t value) { |
| 6881 | if (value == 0) { |
| 6882 | __ xorpd(dest, dest); |
| 6883 | } else { |
| 6884 | __ movsd(dest, LiteralInt64Address(value)); |
| 6885 | } |
| 6886 | } |
| 6887 | |
| 6888 | void CodeGeneratorX86_64::Load32BitValue(XmmRegister dest, float value) { |
| 6889 | Load32BitValue(dest, bit_cast<int32_t, float>(value)); |
| 6890 | } |
| 6891 | |
| 6892 | void CodeGeneratorX86_64::Load64BitValue(XmmRegister dest, double value) { |
| 6893 | Load64BitValue(dest, bit_cast<int64_t, double>(value)); |
| 6894 | } |
| 6895 | |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 6896 | void CodeGeneratorX86_64::Compare32BitValue(CpuRegister dest, int32_t value) { |
| 6897 | if (value == 0) { |
| 6898 | __ testl(dest, dest); |
| 6899 | } else { |
| 6900 | __ cmpl(dest, Immediate(value)); |
| 6901 | } |
| 6902 | } |
| 6903 | |
| 6904 | void CodeGeneratorX86_64::Compare64BitValue(CpuRegister dest, int64_t value) { |
| 6905 | if (IsInt<32>(value)) { |
| 6906 | if (value == 0) { |
| 6907 | __ testq(dest, dest); |
| 6908 | } else { |
| 6909 | __ cmpq(dest, Immediate(static_cast<int32_t>(value))); |
| 6910 | } |
| 6911 | } else { |
| 6912 | // Value won't fit in an int. |
| 6913 | __ cmpq(dest, LiteralInt64Address(value)); |
| 6914 | } |
| 6915 | } |
| 6916 | |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 6917 | void CodeGeneratorX86_64::GenerateIntCompare(Location lhs, Location rhs) { |
| 6918 | CpuRegister lhs_reg = lhs.AsRegister<CpuRegister>(); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 6919 | GenerateIntCompare(lhs_reg, rhs); |
| 6920 | } |
| 6921 | |
| 6922 | void CodeGeneratorX86_64::GenerateIntCompare(CpuRegister lhs, Location rhs) { |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 6923 | if (rhs.IsConstant()) { |
| 6924 | int32_t value = CodeGenerator::GetInt32ValueOf(rhs.GetConstant()); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 6925 | Compare32BitValue(lhs, value); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 6926 | } else if (rhs.IsStackSlot()) { |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 6927 | __ cmpl(lhs, Address(CpuRegister(RSP), rhs.GetStackIndex())); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 6928 | } else { |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 6929 | __ cmpl(lhs, rhs.AsRegister<CpuRegister>()); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 6930 | } |
| 6931 | } |
| 6932 | |
| 6933 | void CodeGeneratorX86_64::GenerateLongCompare(Location lhs, Location rhs) { |
| 6934 | CpuRegister lhs_reg = lhs.AsRegister<CpuRegister>(); |
| 6935 | if (rhs.IsConstant()) { |
| 6936 | int64_t value = rhs.GetConstant()->AsLongConstant()->GetValue(); |
| 6937 | Compare64BitValue(lhs_reg, value); |
| 6938 | } else if (rhs.IsDoubleStackSlot()) { |
| 6939 | __ cmpq(lhs_reg, Address(CpuRegister(RSP), rhs.GetStackIndex())); |
| 6940 | } else { |
| 6941 | __ cmpq(lhs_reg, rhs.AsRegister<CpuRegister>()); |
| 6942 | } |
| 6943 | } |
| 6944 | |
| 6945 | Address CodeGeneratorX86_64::ArrayAddress(CpuRegister obj, |
| 6946 | Location index, |
| 6947 | ScaleFactor scale, |
| 6948 | uint32_t data_offset) { |
| 6949 | return index.IsConstant() ? |
| 6950 | Address(obj, (index.GetConstant()->AsIntConstant()->GetValue() << scale) + data_offset) : |
| 6951 | Address(obj, index.AsRegister<CpuRegister>(), scale, data_offset); |
| 6952 | } |
| 6953 | |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 6954 | void CodeGeneratorX86_64::Store64BitValueToStack(Location dest, int64_t value) { |
| 6955 | DCHECK(dest.IsDoubleStackSlot()); |
| 6956 | if (IsInt<32>(value)) { |
| 6957 | // Can move directly as an int32 constant. |
| 6958 | __ movq(Address(CpuRegister(RSP), dest.GetStackIndex()), |
| 6959 | Immediate(static_cast<int32_t>(value))); |
| 6960 | } else { |
| 6961 | Load64BitValue(CpuRegister(TMP), value); |
| 6962 | __ movq(Address(CpuRegister(RSP), dest.GetStackIndex()), CpuRegister(TMP)); |
| 6963 | } |
| 6964 | } |
| 6965 | |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 6966 | /** |
| 6967 | * Class to handle late fixup of offsets into constant area. |
| 6968 | */ |
| 6969 | class RIPFixup : public AssemblerFixup, public ArenaObject<kArenaAllocCodeGenerator> { |
| 6970 | public: |
| 6971 | RIPFixup(CodeGeneratorX86_64& codegen, size_t offset) |
| 6972 | : codegen_(&codegen), offset_into_constant_area_(offset) {} |
| 6973 | |
| 6974 | protected: |
| 6975 | void SetOffset(size_t offset) { offset_into_constant_area_ = offset; } |
| 6976 | |
| 6977 | CodeGeneratorX86_64* codegen_; |
| 6978 | |
| 6979 | private: |
| 6980 | void Process(const MemoryRegion& region, int pos) OVERRIDE { |
| 6981 | // Patch the correct offset for the instruction. We use the address of the |
| 6982 | // 'next' instruction, which is 'pos' (patch the 4 bytes before). |
| 6983 | int32_t constant_offset = codegen_->ConstantAreaStart() + offset_into_constant_area_; |
| 6984 | int32_t relative_position = constant_offset - pos; |
| 6985 | |
| 6986 | // Patch in the right value. |
| 6987 | region.StoreUnaligned<int32_t>(pos - 4, relative_position); |
| 6988 | } |
| 6989 | |
| 6990 | // Location in constant area that the fixup refers to. |
| 6991 | size_t offset_into_constant_area_; |
| 6992 | }; |
| 6993 | |
| 6994 | /** |
| 6995 | t * Class to handle late fixup of offsets to a jump table that will be created in the |
| 6996 | * constant area. |
| 6997 | */ |
| 6998 | class JumpTableRIPFixup : public RIPFixup { |
| 6999 | public: |
| 7000 | JumpTableRIPFixup(CodeGeneratorX86_64& codegen, HPackedSwitch* switch_instr) |
| 7001 | : RIPFixup(codegen, -1), switch_instr_(switch_instr) {} |
| 7002 | |
| 7003 | void CreateJumpTable() { |
| 7004 | X86_64Assembler* assembler = codegen_->GetAssembler(); |
| 7005 | |
| 7006 | // Ensure that the reference to the jump table has the correct offset. |
| 7007 | const int32_t offset_in_constant_table = assembler->ConstantAreaSize(); |
| 7008 | SetOffset(offset_in_constant_table); |
| 7009 | |
| 7010 | // Compute the offset from the start of the function to this jump table. |
| 7011 | const int32_t current_table_offset = assembler->CodeSize() + offset_in_constant_table; |
| 7012 | |
| 7013 | // Populate the jump table with the correct values for the jump table. |
| 7014 | int32_t num_entries = switch_instr_->GetNumEntries(); |
| 7015 | HBasicBlock* block = switch_instr_->GetBlock(); |
| 7016 | const ArenaVector<HBasicBlock*>& successors = block->GetSuccessors(); |
| 7017 | // The value that we want is the target offset - the position of the table. |
| 7018 | for (int32_t i = 0; i < num_entries; i++) { |
| 7019 | HBasicBlock* b = successors[i]; |
| 7020 | Label* l = codegen_->GetLabelOf(b); |
| 7021 | DCHECK(l->IsBound()); |
| 7022 | int32_t offset_to_block = l->Position() - current_table_offset; |
| 7023 | assembler->AppendInt32(offset_to_block); |
| 7024 | } |
| 7025 | } |
| 7026 | |
| 7027 | private: |
| 7028 | const HPackedSwitch* switch_instr_; |
| 7029 | }; |
| 7030 | |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 7031 | void CodeGeneratorX86_64::Finalize(CodeAllocator* allocator) { |
| 7032 | // Generate the constant area if needed. |
Mark Mendell | 39dcf55 | 2015-04-09 20:42:42 -0400 | [diff] [blame] | 7033 | X86_64Assembler* assembler = GetAssembler(); |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 7034 | if (!assembler->IsConstantAreaEmpty() || !fixups_to_jump_tables_.empty()) { |
| 7035 | // 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] | 7036 | assembler->Align(4, 0); |
| 7037 | constant_area_start_ = assembler->CodeSize(); |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 7038 | |
| 7039 | // Populate any jump tables. |
| 7040 | for (auto jump_table : fixups_to_jump_tables_) { |
| 7041 | jump_table->CreateJumpTable(); |
| 7042 | } |
| 7043 | |
| 7044 | // And now add the constant area to the generated code. |
Mark Mendell | 39dcf55 | 2015-04-09 20:42:42 -0400 | [diff] [blame] | 7045 | assembler->AddConstantArea(); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 7046 | } |
| 7047 | |
| 7048 | // And finish up. |
| 7049 | CodeGenerator::Finalize(allocator); |
| 7050 | } |
| 7051 | |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 7052 | Address CodeGeneratorX86_64::LiteralDoubleAddress(double v) { |
| 7053 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddDouble(v)); |
| 7054 | return Address::RIP(fixup); |
| 7055 | } |
| 7056 | |
| 7057 | Address CodeGeneratorX86_64::LiteralFloatAddress(float v) { |
| 7058 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddFloat(v)); |
| 7059 | return Address::RIP(fixup); |
| 7060 | } |
| 7061 | |
| 7062 | Address CodeGeneratorX86_64::LiteralInt32Address(int32_t v) { |
| 7063 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddInt32(v)); |
| 7064 | return Address::RIP(fixup); |
| 7065 | } |
| 7066 | |
| 7067 | Address CodeGeneratorX86_64::LiteralInt64Address(int64_t v) { |
| 7068 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddInt64(v)); |
| 7069 | return Address::RIP(fixup); |
| 7070 | } |
| 7071 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 7072 | // TODO: trg as memory. |
| 7073 | void CodeGeneratorX86_64::MoveFromReturnRegister(Location trg, Primitive::Type type) { |
| 7074 | if (!trg.IsValid()) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 7075 | DCHECK_EQ(type, Primitive::kPrimVoid); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 7076 | return; |
| 7077 | } |
| 7078 | |
| 7079 | DCHECK_NE(type, Primitive::kPrimVoid); |
| 7080 | |
| 7081 | Location return_loc = InvokeDexCallingConventionVisitorX86_64().GetReturnLocation(type); |
| 7082 | if (trg.Equals(return_loc)) { |
| 7083 | return; |
| 7084 | } |
| 7085 | |
| 7086 | // Let the parallel move resolver take care of all of this. |
| 7087 | HParallelMove parallel_move(GetGraph()->GetArena()); |
| 7088 | parallel_move.AddMove(return_loc, trg, type, nullptr); |
| 7089 | GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 7090 | } |
| 7091 | |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 7092 | Address CodeGeneratorX86_64::LiteralCaseTable(HPackedSwitch* switch_instr) { |
| 7093 | // Create a fixup to be used to create and address the jump table. |
| 7094 | JumpTableRIPFixup* table_fixup = |
| 7095 | new (GetGraph()->GetArena()) JumpTableRIPFixup(*this, switch_instr); |
| 7096 | |
| 7097 | // We have to populate the jump tables. |
| 7098 | fixups_to_jump_tables_.push_back(table_fixup); |
| 7099 | return Address::RIP(table_fixup); |
| 7100 | } |
| 7101 | |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 7102 | void CodeGeneratorX86_64::MoveInt64ToAddress(const Address& addr_low, |
| 7103 | const Address& addr_high, |
| 7104 | int64_t v, |
| 7105 | HInstruction* instruction) { |
| 7106 | if (IsInt<32>(v)) { |
| 7107 | int32_t v_32 = v; |
| 7108 | __ movq(addr_low, Immediate(v_32)); |
| 7109 | MaybeRecordImplicitNullCheck(instruction); |
| 7110 | } else { |
| 7111 | // Didn't fit in a register. Do it in pieces. |
| 7112 | int32_t low_v = Low32Bits(v); |
| 7113 | int32_t high_v = High32Bits(v); |
| 7114 | __ movl(addr_low, Immediate(low_v)); |
| 7115 | MaybeRecordImplicitNullCheck(instruction); |
| 7116 | __ movl(addr_high, Immediate(high_v)); |
| 7117 | } |
| 7118 | } |
| 7119 | |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 7120 | void CodeGeneratorX86_64::PatchJitRootUse(uint8_t* code, |
| 7121 | const uint8_t* roots_data, |
| 7122 | const PatchInfo<Label>& info, |
| 7123 | uint64_t index_in_table) const { |
| 7124 | uint32_t code_offset = info.label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
| 7125 | uintptr_t address = |
| 7126 | reinterpret_cast<uintptr_t>(roots_data) + index_in_table * sizeof(GcRoot<mirror::Object>); |
| 7127 | typedef __attribute__((__aligned__(1))) uint32_t unaligned_uint32_t; |
| 7128 | reinterpret_cast<unaligned_uint32_t*>(code + code_offset)[0] = |
| 7129 | dchecked_integral_cast<uint32_t>(address); |
| 7130 | } |
| 7131 | |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 7132 | void CodeGeneratorX86_64::EmitJitRootPatches(uint8_t* code, const uint8_t* roots_data) { |
| 7133 | for (const PatchInfo<Label>& info : jit_string_patches_) { |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 7134 | const auto& it = jit_string_roots_.find( |
| 7135 | StringReference(&info.dex_file, dex::StringIndex(info.index))); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 7136 | DCHECK(it != jit_string_roots_.end()); |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 7137 | PatchJitRootUse(code, roots_data, info, it->second); |
| 7138 | } |
| 7139 | |
| 7140 | for (const PatchInfo<Label>& info : jit_class_patches_) { |
| 7141 | const auto& it = jit_class_roots_.find( |
| 7142 | TypeReference(&info.dex_file, dex::TypeIndex(info.index))); |
| 7143 | DCHECK(it != jit_class_roots_.end()); |
| 7144 | PatchJitRootUse(code, roots_data, info, it->second); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 7145 | } |
| 7146 | } |
| 7147 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 7148 | #undef __ |
| 7149 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 7150 | } // namespace x86_64 |
| 7151 | } // namespace art |